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

@ -159,11 +159,7 @@ static SEL objSel;
[aCoder decodeValueOfObjCType: @encode(unsigned)
at: &count];
#if GS_WITH_GC
GSIMapInitWithZoneAndCapacity(&map, GSIMapStrongKeyAndVal, count);
#else
GSIMapInitWithZoneAndCapacity(&map, GSObjCZone(self), count);
#endif
while (count-- > 0)
{
(*imp)(aCoder, sel, type, &key);
@ -179,12 +175,7 @@ static SEL objSel;
{
unsigned int i;
#if GS_WITH_GC
GSIMapInitWithZoneAndCapacity(&map, GSIMapStrongKeyAndVal, c);
#else
GSIMapInitWithZoneAndCapacity(&map, GSObjCZone(self), c);
#endif
for (i = 0; i < c; i++)
{
GSIMapNode node;
@ -226,12 +217,7 @@ static SEL objSel;
NSZone *z = GSObjCZone(self);
unsigned c = [other count];
#if GS_WITH_GC
GSIMapInitWithZoneAndCapacity(&map, GSIMapStrongKeyAndVal, c);
#else
GSIMapInitWithZoneAndCapacity(&map, z, c);
#endif
if (c > 0)
{
NSEnumerator *e = [other keyEnumerator];
@ -382,11 +368,7 @@ static SEL objSel;
/* Designated initialiser */
- (id) initWithCapacity: (unsigned)cap
{
#if GS_WITH_GC
GSIMapInitWithZoneAndCapacity(&map, GSIMapStrongKeyAndVal, cap);
#else
GSIMapInitWithZoneAndCapacity(&map, GSObjCZone(self), cap);
#endif
return self;
}

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");

View file

@ -105,6 +105,13 @@ static NSDictionary *blank;
#define GSI_MAP_VTYPES GSUNION_INT
#define GSI_MAP_NOCLEAN 1
#if GS_WITH_GC
#include <gc_typed.h>
static GC_descr nodeDesc; // Type descriptor for map node.
#define GSI_MAP_NODES(M, X) \
(GSIMapNode)GC_calloc_explicitly_typed(X, sizeof(GSIMapNode_t), nodeDesc)
#endif
#include "GNUstepBase/GSIMap.h"
static NSLock *attrLock = nil;
@ -276,10 +283,14 @@ static void _setup(void)
NSDictionary *d;
#if GS_WITH_GC
GSIMapInitWithZoneAndCapacity(&attrMap, GSIMapStrongKeyAndVal, 32);
#else
GSIMapInitWithZoneAndCapacity(&attrMap, NSDefaultMallocZone(), 32);
/* We create a typed memory descriptor for map nodes.
* Only the pointer to the key needs to be scanned.
*/
GC_word w[GC_BITMAP_SIZE(GSIMapNode_t)] = {0};
GC_set_bit(w, GC_WORD_OFFSET(GSIMapNode_t, key));
nodeDesc = GC_make_descriptor(w, GC_WORD_LEN(GSIMapNode_t));
#endif
GSIMapInitWithZoneAndCapacity(&attrMap, NSDefaultMallocZone(), 32);
infSel = @selector(newWithZone:value:at:);
addSel = @selector(addObject:);

View file

@ -37,6 +37,13 @@
#define GSI_MAP_KTYPES GSUNION_OBJ
#define GSI_MAP_VTYPES GSUNION_INT
#if GS_WITH_GC
#include <gc_typed.h>
static GC_descr nodeDesc; // Type descriptor for map node.
#define GSI_MAP_NODES(M, X) \
(GSIMapNode)GC_calloc_explicitly_typed(X, sizeof(GSIMapNode_t), nodeDesc)
#endif
#include "GNUstepBase/GSIMap.h"
@interface GSCountedSet : NSCountedSet
@ -93,6 +100,14 @@
{
if (self == [GSCountedSet class])
{
#if GS_WITH_GC
/* We create a typed memory descriptor for map nodes.
* Only the pointer to the key needs to be scanned.
*/
GC_word w[GC_BITMAP_SIZE(GSIMapNode_t)] = {0};
GC_set_bit(w, GC_WORD_OFFSET(GSIMapNode_t, key));
nodeDesc = GC_make_descriptor(w, GC_WORD_LEN(GSIMapNode_t));
#endif
}
}
@ -183,11 +198,7 @@
/* Designated initialiser */
- (id) initWithCapacity: (unsigned)cap
{
#if GS_WITH_GC
GSIMapInitWithZoneAndCapacity(&map, GSIMapStrongKeyAndVal, cap);
#else
GSIMapInitWithZoneAndCapacity(&map, [self zone], cap);
#endif
return self;
}
@ -203,11 +214,7 @@
(*imp)(aCoder, sel, utype, &count);
#if GS_WITH_GC
GSIMapInitWithZoneAndCapacity(&map, GSIMapStrongKeyAndVal, count);
#else
GSIMapInitWithZoneAndCapacity(&map, [self zone], count);
#endif
while (count-- > 0)
{
(*imp)(aCoder, sel, otype, &value);

View file

@ -47,6 +47,13 @@
#define GSI_MAP_RETAIN_KEY(M, X) ((X).obj) = \
[((id)(X).obj) copyWithZone: map->zone]
#if GS_WITH_GC
#include <gc_typed.h>
static GC_descr nodeDesc; // Type descriptor for map node.
#define GSI_MAP_NODES(M, X) \
(GSIMapNode)GC_calloc_explicitly_typed(X, sizeof(GSIMapNode_t), nodeDesc)
#endif
#include "GNUstepBase/GSIMap.h"
@interface GSDictionary : NSDictionary
@ -82,6 +89,15 @@ static SEL objSel;
{
if (self == [GSDictionary class])
{
#if GS_WITH_GC
/* We create a typed memory descriptor for map nodes.
* The pointers to the key and value need to be scanned.
*/
GC_word w[GC_BITMAP_SIZE(GSIMapNode_t)] = {0};
GC_set_bit(w, GC_WORD_OFFSET(GSIMapNode_t, key));
GC_set_bit(w, GC_WORD_OFFSET(GSIMapNode_t, value));
nodeDesc = GC_make_descriptor(w, GC_WORD_LEN(GSIMapNode_t));
#endif
nxtSel = @selector(nextObject);
objSel = @selector(objectForKey:);
}
@ -156,11 +172,7 @@ static SEL objSel;
[aCoder decodeValueOfObjCType: @encode(unsigned)
at: &count];
#if GS_WITH_GC
GSIMapInitWithZoneAndCapacity(&map, GSIMapStrongKeyAndVal, count);
#else
GSIMapInitWithZoneAndCapacity(&map, GSObjCZone(self), count);
#endif
while (count-- > 0)
{
(*imp)(aCoder, sel, type, &key);
@ -176,11 +188,7 @@ static SEL objSel;
{
unsigned int i;
#if GS_WITH_GC
GSIMapInitWithZoneAndCapacity(&map, GSIMapStrongKeyAndVal, c);
#else
GSIMapInitWithZoneAndCapacity(&map, GSObjCZone(self), c);
#endif
for (i = 0; i < c; i++)
{
GSIMapNode node;
@ -222,12 +230,7 @@ static SEL objSel;
NSZone *z = GSObjCZone(self);
unsigned c = [other count];
#if GS_WITH_GC
GSIMapInitWithZoneAndCapacity(&map, GSIMapStrongKeyAndVal, c);
#else
GSIMapInitWithZoneAndCapacity(&map, z, c);
#endif
if (c > 0)
{
NSEnumerator *e = [other keyEnumerator];
@ -378,11 +381,7 @@ static SEL objSel;
/* Designated initialiser */
- (id) initWithCapacity: (unsigned)cap
{
#if GS_WITH_GC
GSIMapInitWithZoneAndCapacity(&map, GSIMapStrongKeyAndVal, cap);
#else
GSIMapInitWithZoneAndCapacity(&map, GSObjCZone(self), cap);
#endif
return self;
}

View file

@ -514,5 +514,8 @@ GSPrivateUnloadModule(FILE *errorStream,
- (void) protect;
@end
NSZone*
GSAtomicMallocZone (void);
#endif /* _GSPrivate_h_ */

View file

@ -40,6 +40,13 @@
#define GSI_MAP_HAS_VALUE 0
#define GSI_MAP_KTYPES GSUNION_OBJ
#if GS_WITH_GC
#include <gc_typed.h>
static GC_descr nodeDesc; // Type descriptor for map node.
#define GSI_MAP_NODES(M, X) \
(GSIMapNode)GC_calloc_explicitly_typed(X, sizeof(GSIMapNode_t), nodeDesc)
#endif
#include "GNUstepBase/GSIMap.h"
@ -114,6 +121,14 @@ static Class mutableSetClass;
setClass = [GSSet class];
mutableSetClass = [GSMutableSet class];
memberSel = @selector(member:);
#if GS_WITH_GC
/* We create a typed memory descriptor for map nodes.
* Only the pointer to the key needs to be scanned.
*/
GC_word w[GC_BITMAP_SIZE(GSIMapNode_t)] = {0};
GC_set_bit(w, GC_WORD_OFFSET(GSIMapNode_t, key));
nodeDesc = GC_make_descriptor(w, GC_WORD_LEN(GSIMapNode_t));
#endif
}
}
@ -227,11 +242,7 @@ static Class mutableSetClass;
(*imp)(aCoder, sel, @encode(unsigned), &count);
#if GS_WITH_GC
GSIMapInitWithZoneAndCapacity(&map, GSIMapStrongKeyAndVal, count);
#else
GSIMapInitWithZoneAndCapacity(&map, [self zone], count);
#endif
while (count-- > 0)
{
(*imp)(aCoder, sel, type, &value);
@ -246,11 +257,7 @@ static Class mutableSetClass;
{
unsigned i;
#if GS_WITH_GC
GSIMapInitWithZoneAndCapacity(&map, GSIMapStrongKeyAndVal, c);
#else
GSIMapInitWithZoneAndCapacity(&map, [self zone], c);
#endif
for (i = 0; i < c; i++)
{
GSIMapNode node;
@ -584,11 +591,7 @@ static Class mutableSetClass;
/* Designated initialiser */
- (id) initWithCapacity: (unsigned)cap
{
#if GS_WITH_GC
GSIMapInitWithZoneAndCapacity(&map, GSIMapStrongKeyAndVal, cap);
#else
GSIMapInitWithZoneAndCapacity(&map, [self zone], cap);
#endif
return self;
}

View file

@ -36,6 +36,11 @@
#define GSI_MAP_HASH(M, X) ((X).uint)
#define GSI_MAP_EQUAL(M, X,Y) ((X).ptr == (Y).ptr)
#define GSI_MAP_NOCLEAN 1
#if GS_WITH_GC
#define GSI_MAP_NODES(M, X) \
(GSIMapNode)NSAllocateCollectable(X * sizeof(GSIMapNode_t), 0)
#endif
#include "GNUstepBase/GSIMap.h"
@ -138,9 +143,11 @@ static Class NSMutableDataMallocClass;
* Set up map tables.
*/
#if GS_WITH_GC
zone = GSIMapStrongKeyAndVal;
#endif
_clsMap = (GSIMapTable)NSAllocateCollectable(sizeof(GSIMapTable_t)*6,
NSScannedOption);
#else
_clsMap = (GSIMapTable)NSZoneMalloc(zone, sizeof(GSIMapTable_t)*6);
#endif
_cIdMap = &_clsMap[1];
_uIdMap = &_clsMap[2];
_ptrMap = &_clsMap[3];

View file

@ -48,6 +48,14 @@
#define GSI_MAP_HASH(M, X) ((X).uint ^ ((X).uint >> 3))
#define GSI_MAP_EQUAL(M, X,Y) ((X).ptr == (Y).ptr)
#define GSI_MAP_NOCLEAN 1
#if GS_WITH_GC
// FIXME ...
#include <gc_typed.h>
static GC_descr nodeDesc; // Type descriptor for map node.
#define GSI_MAP_NODES(M, X) \
(GSIMapNode)GC_calloc_explicitly_typed(X, sizeof(GSIMapNode_t), nodeDesc)
#endif
#include "GNUstepBase/GSIMap.h"
@ -546,6 +554,16 @@ static NSLock *cached_proxies_gate = nil;
NSNotificationCenter *nc;
GSMakeWeakPointer(self, "delegate");
#if GS_WITH_GC
/* We create a typed memory descriptor for map nodes.
* FIXME
*/
GC_word w[GC_BITMAP_SIZE(GSIMapNode_t)] = {0};
GC_set_bit(w, GC_WORD_OFFSET(GSIMapNode_t, key));
GC_set_bit(w, GC_WORD_OFFSET(GSIMapNode_t, value));
nodeDesc = GC_make_descriptor(w, GC_WORD_LEN(GSIMapNode_t));
#endif
connectionClass = self;
dateClass = [NSDate class];
distantObjectClass = [NSDistantObject class];
@ -949,14 +967,16 @@ static NSLock *cached_proxies_gate = nil;
*/
_requestQueue = [NSMutableArray new];
#if GS_WITH_GC
z = GSIMapStrongKeyAndVal;
#endif
/*
* This maps request sequence numbers to the NSPortCoder objects representing
* replies arriving from the remote connection.
*/
#if GS_WITH_GC
_replyMap = (GSIMapTable)NSAllocateCollectable(sizeof(GSIMapTable_t),
NSScannedOption);
#else
_replyMap = (GSIMapTable)NSZoneMalloc(z, sizeof(GSIMapTable_t));
#endif
GSIMapInitWithZoneAndCapacity(_replyMap, z, 4);
/*
@ -964,19 +984,34 @@ static NSLock *cached_proxies_gate = nil;
* We use this instead of an NSHashTable because we only care about
* the object's address, and don't want to send the -hash message to it.
*/
#if GS_WITH_GC
_localObjects= (GSIMapTable)NSAllocateCollectable(sizeof(GSIMapTable_t),
NSScannedOption);
#else
_localObjects = (GSIMapTable)NSZoneMalloc(z, sizeof(GSIMapTable_t));
#endif
GSIMapInitWithZoneAndCapacity(_localObjects, z, 4);
/*
* This maps handles for local objects to their local proxies.
*/
#if GS_WITH_GC
_localTargets = (GSIMapTable)NSAllocateCollectable(sizeof(GSIMapTable_t),
NSScannedOption);
#else
_localTargets = (GSIMapTable)NSZoneMalloc(z, sizeof(GSIMapTable_t));
#endif
GSIMapInitWithZoneAndCapacity(_localTargets, z, 4);
/*
* This maps targets to remote proxies.
*/
#if GS_WITH_GC
_remoteProxies = (GSIMapTable)NSAllocateCollectable(sizeof(GSIMapTable_t),
NSScannedOption);
#else
_remoteProxies = (GSIMapTable)NSZoneMalloc(z, sizeof(GSIMapTable_t));
#endif
GSIMapInitWithZoneAndCapacity(_remoteProxies, z, 4);
_requestDepth = 0;

View file

@ -57,8 +57,32 @@
(M->extra.retain)((NSHashTable*)M, X.ptr)
#define GSI_MAP_ENUMERATOR NSHashEnumerator
#if GS_WITH_GC
#include <gc_typed.h>
static GC_descr nodeStrong = 0;
static GC_descr nodeWeak = 0;
#define GSI_MAP_NODES(M, X) (GSIMapNode)GC_calloc_explicitly_typed(X, sizeof(GSIMapNode_t), (GC_descr)M->zone)
#endif
#include "GNUstepBase/GSIMap.h"
#if GS_WITH_GC
static inline void
initialize()
{
if (nodeStrong == 0)
{
/* We create a typed memory descriptor for map nodes.
* Only the pointer to the key needs to be scanned.
*/
GC_word w[GC_BITMAP_SIZE(GSIMapNode_t)] = {0};
nodeWeak = GC_make_descriptor(w, GC_WORD_LEN(GSIMapNode_t));
GC_set_bit(w, GC_WORD_OFFSET(GSIMapNode_t, key));
nodeStrong = GC_make_descriptor(w, GC_WORD_LEN(GSIMapNode_t));
}
}
#endif
/**
* Returns an array of all the objects in the table.
* NB. The table <em>must</em> contain objects, not pointers or integers.
@ -156,9 +180,9 @@ NSCopyHashTableWithZone(NSHashTable *table, NSZone *zone)
}
#if GS_WITH_GC
zone = GSIMapStrongKeyAndVal;
t = (GSIMapTable)NSAllocateCollectable(sizeof(GSIMapTable_t),
NSScannedOption);
zone = ((GSIMapTable)table)->zone;
#else
t = (GSIMapTable)NSZoneMalloc(zone, sizeof(GSIMapTable_t));
#endif
@ -220,9 +244,10 @@ NSCreateHashTableWithZone(
GSIMapTable table;
#if GS_WITH_GC
zone = GSIMapStrongKeyAndVal;
initialize();
table = (GSIMapTable)NSAllocateCollectable(sizeof(GSIMapTable_t),
NSScannedOption);
zone = (NSZone*)nodeStrong;
#else
table = (GSIMapTable)NSZoneMalloc(zone, sizeof(GSIMapTable_t));
#endif

View file

@ -37,13 +37,23 @@
/*
* Setup for inline operation of pointer map tables.
*/
#define GSI_MAP_RETAIN_KEY(M, X) RETAIN(X.obj)
#define GSI_MAP_RELEASE_KEY(M, X) RELEASE(X.obj)
#define GSI_MAP_RETAIN_VAL(M, X)
#define GSI_MAP_RELEASE_VAL(M, X)
#define GSI_MAP_HASH(M, X) ((X).uint)
#define GSI_MAP_EQUAL(M, X,Y) ((X).ptr == (Y).ptr)
#undef GSI_MAP_NOCLEAN
#if GS_WITH_GC
#include <gc_typed.h>
static GC_descr nodeDesc; // Type descriptor for map node.
#define GSI_MAP_NODES(M, X) \
(GSIMapNode)GC_calloc_explicitly_typed(X, sizeof(GSIMapNode_t), nodeDesc)
#define GSI_MAP_RETAIN_KEY(M, X)
#define GSI_MAP_RELEASE_KEY(M, X)
#else
#define GSI_MAP_RETAIN_KEY(M, X) RETAIN(X.obj)
#define GSI_MAP_RELEASE_KEY(M, X) RELEASE(X.obj)
#endif
#include "GNUstepBase/GSIMap.h"
@ -473,6 +483,14 @@ static NSDictionary *makeReference(unsigned ref)
{
GSMakeWeakPointer(self, "delegate");
#if GS_WITH_GC
/* We create a typed memory descriptor for map nodes.
*/
GC_word w[GC_BITMAP_SIZE(GSIMapNode_t)] = {0};
GC_set_bit(w, GC_WORD_OFFSET(GSIMapNode_t, key));
GC_set_bit(w, GC_WORD_OFFSET(GSIMapNode_t, value));
nodeDesc = GC_make_descriptor(w, GC_WORD_LEN(GSIMapNode_t));
#endif
if (globalClassMap == 0)
{
globalClassMap =
@ -817,9 +835,11 @@ static NSDictionary *makeReference(unsigned ref)
* Set up map tables.
*/
#if GS_WITH_GC
zone = GSIMapStrongKeyAndVal;
#endif
_cIdMap = (GSIMapTable)NSAllocateCollectable(sizeof(GSIMapTable_t)*5,
NSScannedOption);
#else
_cIdMap = (GSIMapTable)NSZoneMalloc(zone, sizeof(GSIMapTable_t)*5);
#endif
_uIdMap = &_cIdMap[1];
_repMap = &_cIdMap[2];
GSIMapInitWithZoneAndCapacity(_cIdMap, zone, 10);

View file

@ -37,8 +37,13 @@
/*
* Setup for inline operation of arrays.
*/
#define GSI_ARRAY_RETAIN(A, X) RETAIN((X).obj)
#define GSI_ARRAY_RELEASE(A, X) RELEASE((X).obj)
#if GS_WITH_GC
#define GSI_ARRAY_RETAIN(A, X)
#define GSI_ARRAY_RELEASE(A, X)
#else
#define GSI_ARRAY_RETAIN(A, X) [(X).obj retain]
#define GSI_ARRAY_RELEASE(A, X) [(X).obj release]
#endif
#define GSI_ARRAY_TYPES GSUNION_OBJ

View file

@ -67,8 +67,40 @@ typedef struct {
(M->extra.v.retain)((NSMapTable*)M, X.ptr)
#define GSI_MAP_ENUMERATOR NSMapEnumerator
#if GS_WITH_GC
#include <gc_typed.h>
static GC_descr nodeSS = 0;
static GC_descr nodeSW = 0;
static GC_descr nodeWS = 0;
static GC_descr nodeWW = 0;
#define GSI_MAP_NODES(M, X) \
(GSIMapNode)GC_calloc_explicitly_typed(X, sizeof(GSIMapNode_t), (GC_descr)M->zone)
#endif
#include "GNUstepBase/GSIMap.h"
#if GS_WITH_GC
static void
initialize()
{
/* We create a typed memory descriptor for map nodes.
*/
if (nodeSS == 0)
{
GC_word w[GC_BITMAP_SIZE(GSIMapNode_t)] = {0};
nodeWW = GC_make_descriptor(w, GC_WORD_LEN(GSIMapNode_t));
GC_set_bit(w, GC_WORD_OFFSET(GSIMapNode_t, key));
nodeSW = GC_make_descriptor(w, GC_WORD_LEN(GSIMapNode_t));
GC_set_bit(w, GC_WORD_OFFSET(GSIMapNode_t, value));
nodeSS = GC_make_descriptor(w, GC_WORD_LEN(GSIMapNode_t));
memset(&w[0], '\0', sizeof(w));
GC_set_bit(w, GC_WORD_OFFSET(GSIMapNode_t, value));
nodeWS = GC_make_descriptor(w, GC_WORD_LEN(GSIMapNode_t));
}
}
#endif
/**** Function Implementations ****/
/**
@ -208,9 +240,9 @@ NSCopyMapTableWithZone(NSMapTable *table, NSZone *zone)
}
#if GS_WITH_GC
zone = GSIMapStrongKeyAndVal;
t = (GSIMapTable)NSAllocateCollectable(sizeof(GSIMapTable_t),
NSScannedOption);
zone = ((GSIMapTable)table)->zone;
#else
t = (GSIMapTable)NSZoneMalloc(zone, sizeof(GSIMapTable_t));
#endif
@ -277,9 +309,10 @@ NSCreateMapTableWithZone(
GSIMapTable table;
#if GS_WITH_GC
zone = GSIMapStrongKeyAndVal;
initialize();
table = (GSIMapTable)NSAllocateCollectable(sizeof(GSIMapTable_t),
NSScannedOption);
zone = (NSZone*)nodeSS;
#else
table = (GSIMapTable)NSZoneMalloc(zone, sizeof(GSIMapTable_t));
#endif
@ -355,10 +388,14 @@ NSFreeMapTable(NSMapTable *table)
}
else
{
#if GS_WITH_GC
GSIMapEmptyMap((GSIMapTable)table);
#else
NSZone *z = ((GSIMapTable)table)->zone;
GSIMapEmptyMap((GSIMapTable)table);
NSZoneFree(z, table);
#endif
}
}

View file

@ -212,6 +212,13 @@ static void obsFree(Observation *o);
#define GSI_MAP_VEXTRA Observation*
#define GSI_MAP_EXTRA void*
#if GS_WITH_GC
#include <gc_typed.h>
static GC_descr nodeDesc; // Type descriptor for map node.
#define GSI_MAP_NODES(M, X) \
(GSIMapNode)GC_calloc_explicitly_typed(X, sizeof(GSIMapNode_t), nodeDesc)
#endif
#include "GNUstepBase/GSIMap.h"
@class GSLazyRecursiveLock;
@ -285,7 +292,7 @@ static Observation *obsNew(NCTable* t)
size = CHUNKSIZE * sizeof(Observation);
#if GS_WITH_GC
t->chunks[t->numChunks - 1]
= (Observation*)NSZoneMalloc(GSAtomicMallocZone(), size);
= (Observation*)NSAllocateCollectable(size, 0);
#else
t->chunks[t->numChunks - 1]
= (Observation*)NSZoneMalloc(NSDefaultMallocZone(), size);
@ -313,11 +320,10 @@ static GSIMapTable mapNew(NCTable *t)
#if GS_WITH_GC
m = NSAllocateCollectable(sizeof(GSIMapTable_t), NSScannedOption);
GSIMapInitWithZoneAndCapacity(m, GSIMapStrongKeyAndVal, 2);
#else
m = NSZoneMalloc(_zone, sizeof(GSIMapTable_t));
GSIMapInitWithZoneAndCapacity(m, _zone, 2);
#endif
GSIMapInitWithZoneAndCapacity(m, _zone, 2);
return m;
}
}
@ -623,7 +629,12 @@ static NSNotificationCenter *default_center = nil;
if (self == [NSNotificationCenter class])
{
#if GS_WITH_GC
_zone = GSIMapStrongKeyAndVal;
/* We create a typed memory descriptor for map nodes.
*/
GC_word w[GC_BITMAP_SIZE(GSIMapNode_t)] = {0};
GC_set_bit(w, GC_WORD_OFFSET(GSIMapNode_t, key));
GC_set_bit(w, GC_WORD_OFFSET(GSIMapNode_t, value));
nodeDesc = GC_make_descriptor(w, GC_WORD_LEN(GSIMapNode_t));
#else
_zone = NSDefaultMallocZone();
#endif

View file

@ -61,6 +61,13 @@
#define GSI_MAP_EQUAL(M, X,Y) ((X).ptr == (Y).ptr)
#define GSI_MAP_NOCLEAN 1
#if GS_WITH_GC
#include <gc_typed.h>
static GC_descr nodeDesc; // Type descriptor for map node.
#define GSI_MAP_NODES(M, X) \
(GSIMapNode)GC_calloc_explicitly_typed(X, sizeof(GSIMapNode_t), nodeDesc)
#endif
#include "GNUstepBase/GSIMap.h"
/*
@ -360,6 +367,14 @@ static IMP _xRefImp; /* Serialize a crossref. */
_eTagImp = [mutableDataClass instanceMethodForSelector: eTagSel];
_xRefImp = [mutableDataClass instanceMethodForSelector: xRefSel];
mutableDictionaryClass = [NSMutableDictionary class];
#if GS_WITH_GC
/* We create a typed memory descriptor for map nodes.
*/
GC_word w[GC_BITMAP_SIZE(GSIMapNode_t)] = {0};
GC_set_bit(w, GC_WORD_OFFSET(GSIMapNode_t, key));
GC_set_bit(w, GC_WORD_OFFSET(GSIMapNode_t, value));
nodeDesc = GC_make_descriptor(w, GC_WORD_LEN(GSIMapNode_t));
#endif
}
}
@ -1739,14 +1754,17 @@ static IMP _xRefImp; /* Serialize a crossref. */
_eObjImp = [self methodForSelector: eObjSel];
_eValImp = [self methodForSelector: eValSel];
#if GS_WITH_GC
_zone = GSIMapStrongKeyAndVal;
#endif
/*
* Set up map tables.
*/
#if GS_WITH_GC
_clsMap
= (GSIMapTable)NSAllocateCollectable(sizeof(GSIMapTable_t)*4,
NSScannedOption);
#else
_clsMap
= (GSIMapTable)NSZoneMalloc(_zone, sizeof(GSIMapTable_t)*4);
#endif
_cIdMap = &_clsMap[1];
_uIdMap = &_clsMap[2];
_ptrMap = &_clsMap[3];

View file

@ -746,7 +746,7 @@ static inline BOOL timerInvalidated(NSTimer *t)
NSObjectMapValueCallBacks, 0);
_timedPerformers = [[NSMutableArray alloc] initWithCapacity: 8];
#ifdef HAVE_POLL_F
_extra = objc_malloc(sizeof(pollextra));
_extra = NSZoneMalloc(NSDefaultMallocZone(), sizeof(pollextra));
memset(_extra, '\0', sizeof(pollextra));
#endif
}
@ -767,8 +767,8 @@ static inline BOOL timerInvalidated(NSTimer *t)
pollextra *e = (pollextra*)_extra;
if (e->index != 0)
objc_free(e->index);
objc_free(e);
NSZoneFree(NSDefaultMallocZone(), e->index);
NSZoneFree(NSDefaultMallocZone(), e);
}
#endif
RELEASE(_contextStack);

View file

@ -63,6 +63,11 @@
#define GSI_MAP_EQUAL(M, X,Y) [(X).obj isEqualToString: (Y).obj]
#define GSI_MAP_NOCLEAN 1
#if GS_WITH_GC
#define GSI_MAP_NODES(M, X) \
(GSIMapNode)NSAllocateCollectable(X * sizeof(GSIMapNode_t), 0)
#endif
#include "GNUstepBase/GSIMap.h"
/*
@ -157,11 +162,7 @@ initSerializerInfo(_NSSerializerInfo* info, NSMutableData *d, BOOL u)
(*info->appImp)(d, appSel, &info->shouldUnique, 1);
if (u)
{
#if GS_WITH_GC
GSIMapInitWithZoneAndCapacity(&info->map, GSIMapStrongKeyAndVal, 16);
#else
GSIMapInitWithZoneAndCapacity(&info->map, NSDefaultMallocZone(), 16);
#endif
info->count = 0;
}
}

View file

@ -142,7 +142,11 @@ static char *buildURL(parsedURL *base, parsedURL *rel, BOOL standardize)
len += strlen(rel->fragment) + 1; // #fragment
}
ptr = buf = (char*)NSZoneMalloc(GSAtomicMallocZone(), len);
#if GS_WITH_GC
ptr = buf = (char*)NSAllocateCollectable(len, 0);
#else
ptr = buf = (char*)NSZoneMalloc(NSDefaultMallocZone(), len);
#endif
if (rel->scheme != 0)
{
@ -698,7 +702,11 @@ static unsigned urlAlign;
BOOL canBeGeneric = YES;
size += sizeof(parsedURL) + urlAlign + 1;
buf = _data = (parsedURL*)NSZoneMalloc(GSAtomicMallocZone(), size);
#if GS_WITH_GC
buf = _data = (parsedURL*)NSAllocateCollectable(size, 0);
#else
buf = _data = (parsedURL*)NSZoneMalloc(NSDefaultMallocZone(), size);
#endif
memset(buf, '\0', size);
start = end = ptr = (char*)&buf[1];
[_urlString getCString: start

View file

@ -1780,10 +1780,12 @@ NSAllocateCollectable(NSUInteger size, NSUInteger options)
if (options & NSCollectorDisabledOption)
{
ptr = (void*)GC_MALLOC_UNCOLLECTABLE(size);
memset(ptr, '\0', size);
}
else
{
ptr = (void*)GC_MALLOC(size);
memset(ptr, '\0', size);
}
}
else
@ -1795,6 +1797,7 @@ NSAllocateCollectable(NSUInteger size, NSUInteger options)
else
{
ptr = (void*)GC_MALLOC_ATOMIC(size);
memset(ptr, '\0', size);
}
}
return ptr;
@ -1940,6 +1943,7 @@ NSZoneCalloc (NSZone *zone, NSUInteger elems, NSUInteger bytes)
if (zone == &atomic_zone)
{
ptr = (void*)GC_MALLOC_ATOMIC(size);
memset(ptr, '\0', size);
}
else
{

View file

@ -98,7 +98,7 @@ static const NSMapTableValueCallBacks WatcherMapValueCallBacks =
#ifdef HAVE_POLL_F
if (pollfds != 0)
{
objc_free(pollfds);
NSZoneFree(NSDefaultMallocZone(), pollfds);
}
#endif
[super dealloc];
@ -175,16 +175,18 @@ static const NSMapTableValueCallBacks WatcherMapValueCallBacks =
self = [super init];
if (self != nil)
{
NSZone *z = [self zone];
NSZone *z;
mode = [theMode copy];
extra = e;
#if GS_WITH_GC
z = (NSZone*)1;
performers = NSAllocateCollectable(sizeof(GSIArray_t), NSScannedOption);
timers = NSAllocateCollectable(sizeof(GSIArray_t), NSScannedOption);
watchers = NSAllocateCollectable(sizeof(GSIArray_t), NSScannedOption);
_trigger = NSAllocateCollectable(sizeof(GSIArray_t), NSScannedOption);
#else
z = [self zone];
performers = NSZoneMalloc(z, sizeof(GSIArray_t));
timers = NSZoneMalloc(z, sizeof(GSIArray_t));
watchers = NSZoneMalloc(z, sizeof(GSIArray_t));
@ -224,7 +226,8 @@ static void setPollfd(int fd, int event, GSRunLoopCtxt *ctxt)
pe->index
= NSAllocateCollectable(pe->limit * sizeof(*(pe->index)), 0);
#else
pe->index = objc_malloc(pe->limit * sizeof(*(pe->index)));
pe->index = NSZoneMalloc(NSDefaultMallocZone(),
pe->limit * sizeof(*(pe->index)));
#endif
}
else
@ -233,7 +236,8 @@ static void setPollfd(int fd, int event, GSRunLoopCtxt *ctxt)
pe->index = NSReallocateCollectable(pe->index,
pe->limit * sizeof(*(pe->index)), 0);
#else
pe->index = objc_realloc(pe->index, pe->limit * sizeof(*(pe->index)));
pe->index = NSZoneRealloc(NSDefaultMallocZone(),
pe->index, pe->limit * sizeof(*(pe->index)));
#endif
}
do
@ -252,8 +256,8 @@ static void setPollfd(int fd, int event, GSRunLoopCtxt *ctxt)
pollfds = NSReallocateCollectable(pollfds,
ctxt->pollfds_capacity * sizeof (*pollfds), 0);
#else
pollfds =
objc_realloc(pollfds, ctxt->pollfds_capacity * sizeof (*pollfds));
pollfds = NSZoneRealloc(NSDefaultMallocZone(),
pollfds, ctxt->pollfds_capacity * sizeof (*pollfds));
#endif
ctxt->pollfds = pollfds;
}
@ -307,7 +311,8 @@ static void setPollfd(int fd, int event, GSRunLoopCtxt *ctxt)
pollfds
= NSAllocateCollectable(pollfds_capacity * sizeof(*pollfds), 0);
#else
pollfds = objc_malloc(pollfds_capacity * sizeof(*pollfds));
pollfds = NSZoneMalloc(NSDefaultMallocZone(),
pollfds_capacity * sizeof(*pollfds));
#endif
}
else
@ -316,7 +321,8 @@ static void setPollfd(int fd, int event, GSRunLoopCtxt *ctxt)
pollfds = NSReallocateCollectable(pollfds,
pollfds_capacity * sizeof(*pollfds), 0);
#else
pollfds = objc_realloc(pollfds, pollfds_capacity * sizeof(*pollfds));
pollfds = NSZoneRealloc(NSDefaultMallocZone(),
pollfds, pollfds_capacity * sizeof(*pollfds));
#endif
}
}

View file

@ -147,16 +147,18 @@ static const NSMapTableValueCallBacks WatcherMapValueCallBacks =
self = [super init];
if (self != nil)
{
NSZone *z = [self zone];
NSZone *z;
mode = [theMode copy];
extra = e;
#if GS_WITH_GC
z = (NSZone*)1;
performers = NSAllocateCollectable(sizeof(GSIArray_t), NSScannedOption);
timers = NSAllocateCollectable(sizeof(GSIArray_t), NSScannedOption);
watchers = NSAllocateCollectable(sizeof(GSIArray_t), NSScannedOption);
_trigger = NSAllocateCollectable(sizeof(GSIArray_t), NSScannedOption);
#else
z = [self zone];
performers = NSZoneMalloc(z, sizeof(GSIArray_t));
timers = NSZoneMalloc(z, sizeof(GSIArray_t));
watchers = NSZoneMalloc(z, sizeof(GSIArray_t));