More GC tidyups

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@4953 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-MacDonald 1999-09-28 11:10:34 +00:00
parent c315156563
commit 11ef04f603
12 changed files with 72 additions and 57 deletions

View file

@ -261,7 +261,7 @@ static SEL rlSel = @selector(removeLastObject);
/* Do initial allocation. */
prevSize = 3;
curSize = 5;
OBJC_MALLOC(objsArray, id, curSize);
objsArray = (id*)NSZoneMalloc(NSDefaultMallocZone(), sizeof(id) * curSize);
tmpId = firstObject;
/* Loop through adding objects to array until a nil is
@ -283,7 +283,8 @@ static SEL rlSel = @selector(removeLastObject);
curSize = newSize;
/* Reallocate object array. */
OBJC_REALLOC(objsArray, id, curSize);
objsArray = (id*)NSZoneRealloc(NSDefaultMallocZone(), objsArray,
sizeof(id) * curSize);
}
tmpId = va_arg(ap, id);
}
@ -291,7 +292,7 @@ static SEL rlSel = @selector(removeLastObject);
/* Put object ids into NSArray. */
self = [self initWithObjects: objsArray count: i];
OBJC_FREE( objsArray );
NSZoneFree(NSDefaultMallocZone(), objsArray);
return( self );
}

View file

@ -69,7 +69,8 @@ init_pool_cache (struct autorelease_thread_vars *tv)
{
tv->pool_cache_size = 32;
tv->pool_cache_count = 0;
OBJC_MALLOC (tv->pool_cache, id, tv->pool_cache_size);
tv->pool_cache = (id*)NSZoneMalloc(NSDefaultMallocZone(),
sizeof(id) * tv->pool_cache_size);
}
static void
@ -80,7 +81,8 @@ push_pool_to_cache (struct autorelease_thread_vars *tv, id p)
else if (tv->pool_cache_count == tv->pool_cache_size)
{
tv->pool_cache_size *= 2;
OBJC_REALLOC (tv->pool_cache, id, tv->pool_cache_size);
tv->pool_cache = (id*)NSZoneRealloc(NSDefaultMallocZone(),
tv->pool_cache, sizeof(id) * tv->pool_cache_size);
}
tv->pool_cache[tv->pool_cache_count++] = p;
}
@ -123,7 +125,7 @@ static IMP initImp;
return (*initImp)(arp, @selector(init));
}
- init
- (id) init
{
if (!_released_head)
{
@ -131,8 +133,9 @@ static IMP initImp;
[self methodForSelector: @selector(addObject:)];
/* Allocate the array that will be the new head of the list of arrays. */
_released = (struct autorelease_array_list*)
objc_malloc (sizeof(struct autorelease_array_list) +
(BEGINNING_POOL_SIZE * sizeof(id)));
NSZoneMalloc(NSDefaultMallocZone(),
sizeof(struct autorelease_array_list)
+ (BEGINNING_POOL_SIZE * sizeof(id)));
/* Currently no NEXT array in the list, so NEXT == NULL. */
_released->next = NULL;
_released->size = BEGINNING_POOL_SIZE;
@ -270,8 +273,8 @@ static IMP initImp;
unsigned new_size = _released->size * 2;
new_released = (struct autorelease_array_list*)
objc_malloc (sizeof(struct autorelease_array_list) +
(new_size * sizeof(id)));
NSZoneMalloc(NSDefaultMallocZone(),
sizeof(struct autorelease_array_list) + (new_size * sizeof(id)));
new_released->next = NULL;
new_released->size = new_size;
new_released->count = 0;
@ -374,7 +377,7 @@ static IMP initImp;
for (a = _released_head; a; )
{
void *n = a->next;
objc_free (a);
NSZoneFree(NSDefaultMallocZone(), a);
a = n;
}
[super dealloc];
@ -407,7 +410,7 @@ static IMP initImp;
}
if (tv->pool_cache)
OBJC_FREE(tv->pool_cache);
NSZoneFree(NSDefaultMallocZone(), tv->pool_cache);
}
+ (void) resetTotalAutoreleasedObjects

View file

@ -229,7 +229,7 @@
// Find the order of date elements
// and translate format string into scanf ready string
order = 1;
newf = objc_malloc(lf+1);
newf = NSZoneMalloc(NSDefaultMallocZone(), lf+1);
for (i = 0;i < lf; ++i)
{
newf[i] = f[i];
@ -461,7 +461,7 @@
tz = [NSTimeZone localTimeZone];
}
free(newf);
NSZoneFree(NSDefaultMallocZone(), newf);
return [self initWithYear: yd month: md day: dd hour: hd
minute: mnd second: sd

View file

@ -181,7 +181,7 @@
(*imp)(self, @selector(decodeValueOfObjCType:at:),
@encode(unsigned), &count);
*l = count;
array = objc_malloc(count);
array = NSZoneMalloc(NSDefaultMallocZone(), count);
where = array;
while (count-- > 0)
(*imp)(self, @selector(decodeValueOfObjCType:at:), type, where++);

View file

@ -81,7 +81,9 @@ GSDebugAllocationAdd(Class c)
if (num_classes >= table_size)
{
int more = table_size + 128;
table_entry* tmp = objc_malloc(more * sizeof(table_entry));
table_entry *tmp;
tmp = NSZoneMalloc(NSDefaultMallocZone(), more * sizeof(table_entry));
if (tmp == 0)
{
@ -90,7 +92,7 @@ GSDebugAllocationAdd(Class c)
if (the_table)
{
memcpy(tmp, the_table, num_classes * sizeof(table_entry));
objc_free(the_table);
NSZoneFree(NSDefaultMallocZone(), the_table);
}
the_table = tmp;
}
@ -170,9 +172,9 @@ GSDebugAllocationList(BOOL difference)
siz = pos;
if (buf)
{
objc_free(buf);
NSZoneFree(NSDefaultMallocZone(), buf);
}
buf = objc_malloc(siz);
buf = NSZoneMalloc(NSDefaultMallocZone(), siz);
}
if (buf)
@ -234,9 +236,9 @@ GSDebugAllocationListAll()
siz = pos;
if (buf)
{
objc_free(buf);
NSZoneFree(NSDefaultMallocZone(), buf);
}
buf = objc_malloc(siz);
buf = NSZoneMalloc(NSDefaultMallocZone(), siz);
}
if (buf)

View file

@ -212,8 +212,8 @@ static SEL appSel = @selector(appendString:);
}
/* Gather all the arguments in a simple array, in preparation for
calling the designated initializer. */
OBJC_MALLOC (objects, id, capacity);
OBJC_MALLOC (keys, id, capacity);
objects = (id*)NSZoneMalloc(NSDefaultMallocZone(), sizeof(id) * capacity);
keys = (id*)NSZoneMalloc(NSDefaultMallocZone(), sizeof(id) * capacity);
objects[num_pairs] = firstObject;
/* Keep grabbing arguments until we get a nil... */
@ -223,8 +223,10 @@ static SEL appSel = @selector(appendString:);
{
/* Must increase capacity in order to fit additional ARG's. */
capacity *= 2;
OBJC_REALLOC (objects, id, capacity);
OBJC_REALLOC (keys, id, capacity);
objects = (id*)NSZoneRealloc(NSDefaultMallocZone(), objects,
sizeof(id) * capacity);
keys = (id*)NSZoneRealloc(NSDefaultMallocZone(), keys,
sizeof(id) * capacity);
}
/* ...and alternately dump them into OBJECTS and KEYS */
if (argi++ % 2 == 0)
@ -237,14 +239,14 @@ static SEL appSel = @selector(appendString:);
}
if (argi %2 != 0)
{
OBJC_FREE(objects);
OBJC_FREE(keys);
NSZoneFree(NSDefaultMallocZone(), objects);
NSZoneFree(NSDefaultMallocZone(), keys);
[NSException raise: NSInvalidArgumentException
format: @"init dictionary with nil key"];
}
self = [self initWithObjects: objects forKeys: keys count: num_pairs];
OBJC_FREE(objects);
OBJC_FREE(keys);
NSZoneFree(NSDefaultMallocZone(), objects);
NSZoneFree(NSDefaultMallocZone(), keys);
return self;
}
@ -261,8 +263,8 @@ static SEL appSel = @selector(appendString:);
va_start (ap, firstObject);
/* Gather all the arguments in a simple array, in preparation for
calling the designated initializer. */
OBJC_MALLOC (objects, id, capacity);
OBJC_MALLOC (keys, id, capacity);
objects = (id*)NSZoneMalloc(NSDefaultMallocZone(), sizeof(id) * capacity);
keys = (id*)NSZoneMalloc(NSDefaultMallocZone(), sizeof(id) * capacity);
if (firstObject != nil)
{
NSDictionary *d;
@ -274,8 +276,10 @@ static SEL appSel = @selector(appendString:);
{
/* Must increase capacity in order to fit additional ARG's. */
capacity *= 2;
OBJC_REALLOC (objects, id, capacity);
OBJC_REALLOC (keys, id, capacity);
objects = (id*)NSZoneRealloc(NSDefaultMallocZone(), objects,
sizeof(id) * capacity);
keys = (id*)NSZoneRealloc(NSDefaultMallocZone(), keys,
sizeof(id) * capacity);
}
/* ...and alternately dump them into OBJECTS and KEYS */
if (argi++ % 2 == 0)
@ -289,8 +293,8 @@ static SEL appSel = @selector(appendString:);
NSAssert (argi % 2 == 0, NSInvalidArgumentException);
d = AUTORELEASE([[self allocWithZone: NSDefaultMallocZone()]
initWithObjects: objects forKeys: keys count: num_pairs]);
OBJC_FREE(objects);
OBJC_FREE(keys);
NSZoneFree(NSDefaultMallocZone(), objects);
NSZoneFree(NSDefaultMallocZone(), keys);
return d;
}
/* FIRSTOBJECT was nil; just return an empty NSDictionary object. */

View file

@ -55,7 +55,7 @@
char *str;
mframe_get_arg(_argframe, &_info[i], &str);
objc_free(str);
NSZoneFree(NSDefaultMallocZone(), str);
}
else if (*_info[i].type == _C_ID)
{
@ -73,7 +73,7 @@
}
if (_retval)
{
objc_free(_retval);
NSZoneFree(NSDefaultMallocZone(), _retval);
}
RELEASE(_sig);
[super dealloc];
@ -181,14 +181,15 @@
}
else
{
char *tmp = objc_malloc(strlen(newstr)+1);
char *tmp;
tmp = NSZoneMalloc(NSDefaultMallocZone(), strlen(newstr)+1);
strcpy(tmp, newstr);
mframe_set_arg(_argframe, &_info[i], tmp);
}
if (oldstr != 0)
{
objc_free(oldstr);
NSZoneFree(NSDefaultMallocZone(), oldstr);
}
}
}
@ -283,8 +284,9 @@
mframe_get_arg(_argframe, &_info[i], &str);
if (str != 0)
{
char *tmp = objc_malloc(strlen(str)+1);
char *tmp;
tmp = NSZoneMalloc(NSDefaultMallocZone(), strlen(str)+1);
strcpy(tmp, str);
mframe_set_arg(_argframe, &_info[i], &tmp);
}
@ -525,7 +527,7 @@
_argframe = mframe_create_argframe([_sig methodType], &_retval);
if (_retval == 0 && _info[0].size > 0)
{
_retval = objc_malloc(_info[0].size);
_retval = NSZoneMalloc(NSDefaultMallocZone(), _info[0].size);
}
return self;
}
@ -572,8 +574,9 @@
if (old != 0)
{
char *tmp = objc_malloc(strlen(old)+1);
char *tmp;
tmp = NSZoneMalloc(NSDefaultMallocZone(),strlen(old)+1);
strcpy(tmp, old);
*(char**)datum = tmp;
}

View file

@ -112,9 +112,9 @@
- (void) dealloc
{
if (_methodTypes)
objc_free((void*)_methodTypes);
NSZoneFree(NSDefaultMallocZone(), (void*)_methodTypes);
if (_info)
objc_free((void*)_info);
NSZoneFree(NSDefaultMallocZone(), (void*)_info);
[super dealloc];
}
@ -128,7 +128,8 @@
const char *types = _methodTypes;
int i;
_info = objc_malloc(sizeof(NSArgumentInfo)*(_numArgs+1));
_info = NSZoneMalloc(NSDefaultMallocZone(),
sizeof(NSArgumentInfo)*(_numArgs+1));
for (i = 0; i <= _numArgs; i++)
{
types = mframe_next_arg(types, &_info[i]);

View file

@ -430,7 +430,7 @@ deserializeFromInfo(_NSDeserializerInfo* info)
case ST_CSTRING:
{
NSGCString *s;
char *b = objc_malloc(size);
char *b = NSZoneMalloc(NSDefaultMallocZone(), size);
(*info->debImp)(info->data, debSel, b, size, info->cursor);
s = (NSGCString*)NSAllocateObject(CSCls, 0, NSDefaultMallocZone());
@ -468,7 +468,7 @@ deserializeFromInfo(_NSDeserializerInfo* info)
case ST_STRING:
{
NSGString *s;
unichar *b = objc_malloc(size*2);
unichar *b = NSZoneMalloc(NSDefaultMallocZone(), size*2);
(*info->debImp)(info->data, debSel, b, size*2, info->cursor);
s = (NSGString*)NSAllocateObject(USCls, 0, NSDefaultMallocZone());
@ -603,7 +603,7 @@ deserializeFromInfo(_NSDeserializerInfo* info)
case ST_DATA:
{
NSData *d;
void *b = objc_malloc(size);
void *b = NSZoneMalloc(NSDefaultMallocZone(), size);
(*info->debImp)(info->data, debSel, b, size, info->cursor);
d = (NSData*)NSAllocateObject(DCls, 0, NSDefaultMallocZone());

View file

@ -186,7 +186,7 @@ static Class NSMutableSet_concrete_class;
/* Do initial allocation. */
prevSize = 3;
curSize = 5;
OBJC_MALLOC(objsArray, id, curSize);
objsArray = (id*)NSZoneMalloc(NSDefaultMallocZone(), sizeof(id) * curSize);
tmpId = firstObject;
/* Loop through adding objects to array until a nil is
@ -208,7 +208,8 @@ static Class NSMutableSet_concrete_class;
curSize = newSize;
/* Reallocate object array. */
OBJC_REALLOC(objsArray, id, curSize);
objsArray = (id*)NSZoneRealloc(NSDefaultMallocZone(), objsArray,
sizeof(id) * curSize);
}
tmpId = va_arg(ap, id);
}
@ -216,7 +217,7 @@ static Class NSMutableSet_concrete_class;
/* Put object ids into NSSet. */
self = [self initWithObjects: objsArray count: i];
OBJC_FREE( objsArray );
NSZoneFree(NSDefaultMallocZone(), objsArray);
return( self );
}

View file

@ -128,11 +128,11 @@ NSHomeDirectoryForUser(NSString *login_name)
if (n > 1024)
{
/* Buffer not big enough, so dynamically allocate it */
nb = (char *)objc_malloc(sizeof(char)*(n+1));
nb = (char *)NSZoneMalloc(NSDefaultMallocZone(), sizeof(char)*(n+1));
n = GetEnvironmentVariable("HOMEPATH", nb, n+1);
nb[n] = '\0';
s = [NSString stringWithCString: nb];
free(nb);
NSZoneFree(NSDefaultMallocZone(), nb);
return s;
}
else

View file

@ -165,7 +165,7 @@ mframe_build_signature(const char *typePtr, int *size, int *narg, char *buf)
*/
if (doMalloc)
{
char *tmp = objc_malloc(dest - buf + 1);
char *tmp = NSZoneMalloc(NSDefaultMallocZone(), dest - buf + 1);
strcpy(tmp, buf);
buf = tmp;
@ -1355,7 +1355,7 @@ mframe_build_return_opts (arglist_t argframe,
retLength = objc_sizeof_type(tmptype);
/* Allocate memory to hold the value we're pointing to. */
*(void**)retframe =
objc_malloc (retLength);
NSZoneMalloc(NSDefaultMallocZone(), retLength);
/* We are responsible for making sure this memory gets free'd
eventually. Ask NSData class to autorelease it. */
[NSData dataWithBytesNoCopy: *(void**)retframe
@ -1559,9 +1559,9 @@ mframe_destroy_argframe(const char *types, arglist_t argframe)
if (stack_argsize)
{
objc_free(argframe->arg_ptr);
NSZoneFree(NSDefaultMallocZone(), argframe->arg_ptr);
}
objc_free(argframe);
NSZoneFree(NSDefaultMallocZone(), argframe);
}