Fix initialising mutable array.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@15107 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-Macdonald 2002-11-26 09:15:11 +00:00
parent bc50d72e6c
commit 62b716613d
2 changed files with 36 additions and 37 deletions

View file

@ -2,6 +2,7 @@
* Source/Additions/GCObject.m: Attempt to make garbage collecting
thread-safe.
* Source/Additions/GCArray.m: Fix count initialising mutable array.
2002-11-25 Richard Frith-Macdonald <rfm@gnu.org>

View file

@ -128,15 +128,13 @@ static Class gcClass = 0;
- (id) initWithObjects: (id*)objects count: (unsigned int)count
{
unsigned int i;
_contents = NSZoneMalloc([self zone], count * (sizeof(id) + sizeof(BOOL)));
_isGCObject = (BOOL*)&_contents[count];
_count = count;
for (i = 0; i < count; i++)
_count = 0;
while (_count < count)
{
_contents[i] = [objects[i] retain];
if (_contents[i] == nil)
_contents[_count] = [objects[_count] retain];
if (_contents[_count] == nil)
{
[self release];
[NSException raise: NSInvalidArgumentException
@ -144,24 +142,25 @@ static Class gcClass = 0;
}
else
{
_isGCObject[i] = [objects[i] isKindOfClass: gcClass];
_isGCObject[_count] = [objects[_count] isKindOfClass: gcClass];
}
_count++;
}
return self;
}
- (id) initWithArray: (NSArray*)anotherArray
{
unsigned int i;
unsigned int count = [anotherArray count];
_contents = NSZoneMalloc([self zone], count * (sizeof(id) + sizeof(BOOL)));
_isGCObject = (BOOL*)&_contents[count];
_count = count;
for (i = 0; i < _count; i++)
_count = 0;
while (_count < count)
{
_contents[i] = [[anotherArray objectAtIndex: i] retain];
_isGCObject[i] = [_contents[i] isKindOfClass: gcClass];
_contents[_count] = [[anotherArray objectAtIndex: _count] retain];
_isGCObject[_count] = [_contents[_count] isKindOfClass: gcClass];
_count++;
}
return self;
}
@ -236,13 +235,31 @@ static Class gcClass = 0;
return [self initWithCapacity: 1];
}
- (id) initWithArray: (NSArray*)anotherArray
{
unsigned int count = [anotherArray count];
self = [self initWithCapacity: count];
if (self != nil)
{
while (_count < count)
{
_contents[_count] = [[anotherArray objectAtIndex: _count] retain];
_isGCObject[_count] = [_contents[_count] isKindOfClass: gcClass];
_count++;
}
}
return self;
}
- (id) initWithCapacity: (unsigned int)aNumItems
{
if (aNumItems < 1)
{
aNumItems = 1;
}
_contents = NSZoneMalloc([self zone], aNumItems * (sizeof(id) + sizeof(BOOL)));
_contents = NSZoneMalloc([self zone],
aNumItems * (sizeof(id) + sizeof(BOOL)));
_isGCObject = (BOOL*)&_contents[aNumItems];
_maxCount = aNumItems;
_count = 0;
@ -254,12 +271,10 @@ static Class gcClass = 0;
self = [self initWithCapacity: count];
if (self != nil)
{
unsigned int i;
for (i = 0; i < count; i++)
while (_count < count)
{
_contents[i] = [objects[i] retain];
if (_contents[i] == nil)
_contents[_count] = [objects[_count] retain];
if (_contents[_count] == nil)
{
[self release];
[NSException raise: NSInvalidArgumentException
@ -267,26 +282,9 @@ static Class gcClass = 0;
}
else
{
_isGCObject[i] = [objects[i] isKindOfClass: gcClass];
_isGCObject[_count] = [objects[_count] isKindOfClass: gcClass];
}
}
}
return self;
}
- (id) initWithArray: (NSArray*)anotherArray
{
unsigned int count = [anotherArray count];
self = [self initWithCapacity: count];
if (self != nil)
{
unsigned int i;
for (i = 0; i < _count; i++)
{
_contents[i] = [[anotherArray objectAtIndex: i] retain];
_isGCObject[i] = [_contents[i] isKindOfClass: gcClass];
_count++;
}
}
return self;