More moves towards OSX 10.5 GC compatibility.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@28054 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-MacDonald 2009-03-09 15:11:51 +00:00
parent 00e2bbb843
commit bc9468c45f
25 changed files with 553 additions and 282 deletions

View file

@ -771,6 +771,63 @@ GSUnicode(const unichar *chars, unsigned length,
return i;
}
#if GS_WITH_GC
#define GROW() \
if (dst == 0) \
{ \
/* \
* Data is just being discarded anyway, so we can \
* reset the offset into the local buffer on the \
* stack and pretend the buffer has grown. \
*/ \
ptr = buf - dpos; \
bsize = dpos + BUFSIZ; \
if (extra != 0) \
{ \
bsize--; \
} \
} \
else if (zone == 0) \
{ \
result = NO; /* No buffer growth possible ... fail. */ \
goto done; \
} \
else \
{ \
unsigned grow = slen; \
\
if (grow < bsize + BUFSIZ) \
{ \
grow = bsize + BUFSIZ; \
} \
grow *= sizeof(unichar); \
\
if (ptr == buf || ptr == *dst) \
{ \
unichar *tmp; \
\
tmp = NSAllocateCollectable(grow + extra, 0); \
if (tmp != 0) \
{ \
memcpy(tmp, ptr, bsize * sizeof(unichar)); \
} \
ptr = tmp; \
} \
else \
{ \
ptr = NSReallocateCollectable(ptr, grow + extra, 0); \
} \
if (ptr == 0) \
{ \
result = NO; /* Not enough memory */ \
break; \
} \
bsize = grow / sizeof(unichar); \
}
#else /* GS_WITH_GC */
#define GROW() \
if (dst == 0) \
{ \
@ -824,6 +881,8 @@ else \
bsize = grow / sizeof(unichar); \
}
#endif /* GS_WITH_GC */
/**
* Function to convert from 8-bit data to 16-bit unicode characters.
* <p>The dst argument is a pointer to a pointer to a buffer in which the
@ -852,7 +911,10 @@ else \
* allocate a buffer to return data in.
* If this is nul, the function will fail if the originally supplied buffer
* is not big enough (unless dst is a null pointer ... indicating that
* converted data is to be discarded).
* converted data is to be discarded).<br />
* If the library is built for garbage collecting, the zone argument is used
* only as a marker to say whether the function may allocate memory (zone
* is non-null) or not (zone is null).
* </p>
* The options argument controls some special behavior.
* <list>
@ -1234,12 +1296,17 @@ done:
/*
* Temporary string was requested ... make one.
*/
#if GS_WITH_GC
r = NSAllocateCollectable(bytes, 0);
memcpy(r, ptr, bytes);
#else
r = GSAutoreleasedBuffer(bytes);
memcpy(r, ptr, bytes);
if (ptr != buf && (dst == 0 || ptr != *dst))
{
NSZoneFree(zone, ptr);
}
#endif
ptr = r;
*dst = ptr;
}
@ -1255,7 +1322,11 @@ done:
{
unichar *tmp;
#if GS_WITH_GC
tmp = NSAllocateCollectable(bytes, 0);
#else
tmp = NSZoneMalloc(zone, bytes);
#endif
if (tmp != 0)
{
memcpy(tmp, ptr, bytes);
@ -1264,7 +1335,11 @@ done:
}
else
{
#if GS_WITH_GC
ptr = NSReallocateCollectable(ptr, bytes, 0);
#else
ptr = NSZoneRealloc(zone, ptr, bytes);
#endif
}
*dst = ptr;
}
@ -1278,10 +1353,12 @@ done:
*dst = ptr;
}
}
#if !GS_WITH_GC
else if (ptr != buf && dst != 0 && ptr != *dst)
{
NSZoneFree(zone, ptr);
}
#endif
if (dst)
NSCAssert(*dst != buf, @"attempted to pass out pointer to internal buffer");
@ -1292,6 +1369,62 @@ done:
#undef GROW
#if GS_WITH_GC
#define GROW() \
if (dst == 0) \
{ \
/* \
* Data is just being discarded anyway, so we can \
* reset the offset into the local buffer on the \
* stack and pretend the buffer has grown. \
*/ \
ptr = buf - dpos; \
bsize = dpos + BUFSIZ; \
if (extra != 0) \
{ \
bsize--; \
} \
} \
else if (zone == 0) \
{ \
result = NO; /* No buffer growth possible ... fail. */ \
goto done; \
} \
else \
{ \
unsigned grow = slen; \
\
if (grow < bsize + BUFSIZ) \
{ \
grow = bsize + BUFSIZ; \
} \
\
if (ptr == buf || ptr == *dst) \
{ \
unsigned char *tmp; \
\
tmp = NSAllocateCollectable(grow + extra, 0); \
if (tmp != 0) \
{ \
memcpy(tmp, ptr, bsize); \
} \
ptr = tmp; \
} \
else \
{ \
ptr = NSReallocateCollectable(ptr, grow + extra, 0); \
} \
if (ptr == 0) \
{ \
result = NO; /* Not enough memory */ \
break; \
} \
bsize = grow; \
}
#else /* GS_WITH_GC */
#define GROW() \
if (dst == 0) \
{ \
@ -1344,6 +1477,7 @@ else \
bsize = grow; \
}
#endif /* GS_WITH_GC */
static inline int chop(unichar c, _ucc_ *table, int hi)
{
@ -1397,7 +1531,10 @@ static inline int chop(unichar c, _ucc_ *table, int hi)
* allocate a buffer to return data in.
* If this is nul, the function will fail if the originally supplied buffer
* is not big enough (unless dst is a null pointer ... indicating that
* converted data is to be discarded).
* converted data is to be discarded).<br />
* If the library is built for garbage collecting, the zone argument is used
* only as a marker to say whether the function may allocate memory (zone
* is non-null) or not (zone is null).
* </p>
* The options argument controls some special behavior.
* <list>
@ -1969,12 +2106,17 @@ iconv_start:
/*
* Temporary string was requested ... make one.
*/
#if GS_WITH_GC
r = NSAllocateCollectable(bytes, 0);
memcpy(r, ptr, bytes);
#else
r = GSAutoreleasedBuffer(bytes);
memcpy(r, ptr, bytes);
if (ptr != buf && (dst == 0 || ptr != *dst))
{
NSZoneFree(zone, ptr);
}
#endif
ptr = r;
*dst = ptr;
}
@ -1990,7 +2132,11 @@ iconv_start:
{
unsigned char *tmp;
#if GS_WITH_GC
tmp = NSAllocateCollectable(bytes, 0);
#else
tmp = NSZoneMalloc(zone, bytes);
#endif
if (tmp != 0)
{
memcpy(tmp, ptr, bytes);
@ -1999,7 +2145,11 @@ iconv_start:
}
else
{
#if GS_WITH_GC
ptr = NSReallocateCollectable(ptr, bytes, 0);
#else
ptr = NSZoneRealloc(zone, ptr, bytes);
#endif
}
*dst = ptr;
}
@ -2013,10 +2163,12 @@ iconv_start:
*dst = ptr;
}
}
#if !GS_WITH_GC
else if (ptr != buf && dst != 0 && ptr != *dst)
{
NSZoneFree(zone, ptr);
}
#endif
if (dst)
NSCAssert(*dst != buf, @"attempted to pass out pointer to internal buffer");