Encourage better coding by warning about attempts to remove nil objects

from arrays.


git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@5131 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-MacDonald 1999-11-04 10:42:20 +00:00
parent 19c6525085
commit 00df0a12c7
6 changed files with 88 additions and 32 deletions

View file

@ -1,3 +1,11 @@
Thu Nov 4 10:52:00 1999 Richard Frith-Macdonald <richard@brainstorm.co.uk>
* Source/NSArray.m: use NSLog() to warn about attempts to remove nil.
* Source/NSGArray.m: ditto
* Source/NSGCountedSet.m: ditto
* Source/NSGDictionary.m: ditto
* Source/NSGSet.m: ditto
Fri Oct 29 10:08:00 1999 Richard Frith-Macdonald <richard@brainstorm.co.uk>
* Source/NSInvocation.m: ([-initWithTarget:selector:]) possible fix

View file

@ -877,8 +877,14 @@ static NSString *indentStrings[] = {
- (void) removeObjectIdenticalTo: (id)anObject
{
unsigned i = [self count];
unsigned i;
if (anObject == nil)
{
NSLog(@"attempt to remove nil object");
return;
}
i = [self count];
if (i > 0)
{
IMP rem = 0;
@ -900,13 +906,22 @@ static NSString *indentStrings[] = {
- (void) removeObject: (id)anObject inRange: (NSRange)aRange
{
unsigned c = [self count];
unsigned s = aRange.location;
unsigned i = aRange.location + aRange.length;
unsigned c;
unsigned s;
unsigned i;
if (anObject == nil)
{
NSLog(@"attempt to remove nil object");
return;
}
c = [self count];
s = aRange.location;
i = aRange.location + aRange.length;
if (i > c)
i = c;
{
i = c;
}
if (i > s)
{
IMP rem = 0;
@ -930,13 +945,22 @@ static NSString *indentStrings[] = {
- (void) removeObjectIdenticalTo: (id)anObject inRange: (NSRange)aRange
{
unsigned c = [self count];
unsigned s = aRange.location;
unsigned i = aRange.location + aRange.length;
unsigned c;
unsigned s;
unsigned i;
if (anObject == nil)
{
NSLog(@"attempt to remove nil object");
return;
}
c = [self count];
s = aRange.location;
i = aRange.location + aRange.length;
if (i > c)
i = c;
{
i = c;
}
if (i > s)
{
IMP rem = 0;
@ -958,8 +982,14 @@ static NSString *indentStrings[] = {
- (void) removeObject: (id)anObject
{
unsigned i = [self count];
unsigned i;
if (anObject == nil)
{
NSLog(@"attempt to remove nil object");
return;
}
i = [self count];
if (i > 0)
{
IMP rem = 0;

View file

@ -421,9 +421,15 @@ static SEL eqSel = @selector(isEqual:);
- (void) removeObject: (id)anObject
{
unsigned index = _count;
unsigned index;
if (index > 0 && anObject)
if (anObject == nil)
{
NSLog(@"attempt to remove nil object");
return;
}
index = _count;
if (index > 0)
{
BOOL (*imp)(id,SEL,id);
@ -470,8 +476,14 @@ static SEL eqSel = @selector(isEqual:);
- (void) removeObjectIdenticalTo: (id)anObject
{
unsigned index = _count;
unsigned index;
if (anObject == nil)
{
NSLog(@"attempt to remove nil object");
return;
}
index = _count;
while (index-- > 0)
{
if (_contents_array[index] == anObject)

View file

@ -254,23 +254,25 @@
- (void) removeObject: (NSObject*)anObject
{
if (anObject)
GSIMapBucket bucket;
if (anObject == nil)
{
GSIMapBucket bucket;
NSLog(@"attempt to remove nil object");
return;
}
bucket = GSIMapBucketForKey(&map, (GSIMapKey)anObject);
if (bucket != 0)
{
GSIMapNode node;
bucket = GSIMapBucketForKey(&map, (GSIMapKey)anObject);
if (bucket)
node = GSIMapNodeForKeyInBucket(bucket, (GSIMapKey)anObject);
if (node != 0)
{
GSIMapNode node;
node = GSIMapNodeForKeyInBucket(bucket, (GSIMapKey)anObject);
if (node)
if (--node->value.uint == 0)
{
if (--node->value.uint == 0)
{
GSIMapRemoveNodeFromMap(&map, bucket, node);
GSIMapFreeNode(&map, node);
}
GSIMapRemoveNodeFromMap(&map, bucket, node);
GSIMapFreeNode(&map, node);
}
}
}

View file

@ -381,10 +381,12 @@ myEqual(id self, id other)
- (void) removeObjectForKey: (id)aKey
{
if (aKey)
if (aKey == nil)
{
GSIMapRemoveKey(&map, (GSIMapKey)aKey);
NSLog(@"attempt to remove nil key");
return;
}
GSIMapRemoveKey(&map, (GSIMapKey)aKey);
}
@end

View file

@ -234,10 +234,12 @@
- (void) removeObject: (NSObject *)anObject
{
if (anObject)
if (anObject == nil)
{
GSIMapRemoveKey(&map, (GSIMapKey)anObject);
NSLog(@"attempt to remove nil object");
return;
}
GSIMapRemoveKey(&map, (GSIMapKey)anObject);
}
- (void) removeAllObjects