In iconv case, only expand the buffer when we really need more space. Correctly handle all output when flushing iconv.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@17172 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
alexm 2003-07-08 01:50:42 +00:00
parent 98fc078d86
commit 86a8fd6a23
2 changed files with 14 additions and 24 deletions

View file

@ -1,3 +1,9 @@
2003-07-08 03:44 Alexander Malmberg <alexander@malmberg.org>
* Source/Additions/Unicode.m (GSToUnicode, GSFromUnicode): In iconv
case, only try to expand the buffer when we really need extra space.
Correctly handle all output from flushing iconv.
2003-07-08 03:03 Alexander Malmberg <alexander@malmberg.org> 2003-07-08 03:03 Alexander Malmberg <alexander@malmberg.org>
* Source/NSConnection.m (-locateLocalTarget:): The targetToCached * Source/NSConnection.m (-locateLocalTarget:): The targetToCached

View file

@ -1268,19 +1268,11 @@ tables:
inbytesleft = slen; inbytesleft = slen;
outbuf = (char*)ptr; outbuf = (char*)ptr;
outbytesleft = bsize * sizeof(unichar); outbytesleft = bsize * sizeof(unichar);
while (done == NO) do
{ {
if (dpos >= bsize)
{
unsigned old = bsize;
GROW();
outbuf = (char*)&ptr[dpos];
outbytesleft += (bsize - old) * sizeof(unichar);
}
if (inbytesleft == 0) if (inbytesleft == 0)
{ {
done = YES; // Flush iconv, then terminate. done = YES; // Flush iconv
rval = iconv(cd, 0, 0, &outbuf, &outbytesleft); rval = iconv(cd, 0, 0, &outbuf, &outbytesleft);
} }
else else
@ -1305,7 +1297,7 @@ tables:
break; break;
} }
} }
} } while (!done || rval != 0);
// close the converter // close the converter
iconv_close(cd); iconv_close(cd);
} }
@ -1537,7 +1529,7 @@ GSFromUnicode(unsigned char **dst, unsigned int *size, const unichar *src,
unsigned ltsize = 0; unsigned ltsize = 0;
BOOL swapped = NO; BOOL swapped = NO;
BOOL result = YES; BOOL result = YES;
if (options & GSUniBOM) if (options & GSUniBOM)
{ {
if (slen == 0) if (slen == 0)
@ -1858,19 +1850,11 @@ tables:
inbytesleft = slen * sizeof(unichar); inbytesleft = slen * sizeof(unichar);
outbuf = (char*)ptr; outbuf = (char*)ptr;
outbytesleft = bsize; outbytesleft = bsize;
while (done == NO) do
{ {
if (dpos >= bsize)
{
unsigned old = bsize;
GROW();
outbuf = (char*)&ptr[dpos];
outbytesleft += (bsize - old);
}
if (inbytesleft == 0) if (inbytesleft == 0)
{ {
done = YES; // Flush buffer, then terminate. done = YES; // Flush buffer
rval = iconv(cd, 0, 0, &outbuf, &outbytesleft); rval = iconv(cd, 0, 0, &outbuf, &outbytesleft);
} }
else else
@ -1927,11 +1911,11 @@ tables:
break; break;
} }
} }
} } while (!done || rval != 0);
// close the converter // close the converter
iconv_close(cd); iconv_close(cd);
} }
#else #else
result = NO; result = NO;
break; break;
#endif #endif