mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-20 20:26:42 +00:00
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:
parent
b9fe4e75e2
commit
11d14c597d
6 changed files with 88 additions and 32 deletions
|
@ -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>
|
Fri Oct 29 10:08:00 1999 Richard Frith-Macdonald <richard@brainstorm.co.uk>
|
||||||
|
|
||||||
* Source/NSInvocation.m: ([-initWithTarget:selector:]) possible fix
|
* Source/NSInvocation.m: ([-initWithTarget:selector:]) possible fix
|
||||||
|
|
|
@ -877,8 +877,14 @@ static NSString *indentStrings[] = {
|
||||||
|
|
||||||
- (void) removeObjectIdenticalTo: (id)anObject
|
- (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)
|
if (i > 0)
|
||||||
{
|
{
|
||||||
IMP rem = 0;
|
IMP rem = 0;
|
||||||
|
@ -900,13 +906,22 @@ static NSString *indentStrings[] = {
|
||||||
|
|
||||||
- (void) removeObject: (id)anObject inRange: (NSRange)aRange
|
- (void) removeObject: (id)anObject inRange: (NSRange)aRange
|
||||||
{
|
{
|
||||||
unsigned c = [self count];
|
unsigned c;
|
||||||
unsigned s = aRange.location;
|
unsigned s;
|
||||||
unsigned i = aRange.location + aRange.length;
|
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)
|
if (i > c)
|
||||||
i = c;
|
{
|
||||||
|
i = c;
|
||||||
|
}
|
||||||
if (i > s)
|
if (i > s)
|
||||||
{
|
{
|
||||||
IMP rem = 0;
|
IMP rem = 0;
|
||||||
|
@ -930,13 +945,22 @@ static NSString *indentStrings[] = {
|
||||||
|
|
||||||
- (void) removeObjectIdenticalTo: (id)anObject inRange: (NSRange)aRange
|
- (void) removeObjectIdenticalTo: (id)anObject inRange: (NSRange)aRange
|
||||||
{
|
{
|
||||||
unsigned c = [self count];
|
unsigned c;
|
||||||
unsigned s = aRange.location;
|
unsigned s;
|
||||||
unsigned i = aRange.location + aRange.length;
|
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)
|
if (i > c)
|
||||||
i = c;
|
{
|
||||||
|
i = c;
|
||||||
|
}
|
||||||
if (i > s)
|
if (i > s)
|
||||||
{
|
{
|
||||||
IMP rem = 0;
|
IMP rem = 0;
|
||||||
|
@ -958,8 +982,14 @@ static NSString *indentStrings[] = {
|
||||||
|
|
||||||
- (void) removeObject: (id)anObject
|
- (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)
|
if (i > 0)
|
||||||
{
|
{
|
||||||
IMP rem = 0;
|
IMP rem = 0;
|
||||||
|
|
|
@ -421,9 +421,15 @@ static SEL eqSel = @selector(isEqual:);
|
||||||
|
|
||||||
- (void) removeObject: (id)anObject
|
- (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);
|
BOOL (*imp)(id,SEL,id);
|
||||||
|
|
||||||
|
@ -470,8 +476,14 @@ static SEL eqSel = @selector(isEqual:);
|
||||||
|
|
||||||
- (void) removeObjectIdenticalTo: (id)anObject
|
- (void) removeObjectIdenticalTo: (id)anObject
|
||||||
{
|
{
|
||||||
unsigned index = _count;
|
unsigned index;
|
||||||
|
|
||||||
|
if (anObject == nil)
|
||||||
|
{
|
||||||
|
NSLog(@"attempt to remove nil object");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
index = _count;
|
||||||
while (index-- > 0)
|
while (index-- > 0)
|
||||||
{
|
{
|
||||||
if (_contents_array[index] == anObject)
|
if (_contents_array[index] == anObject)
|
||||||
|
|
|
@ -254,23 +254,25 @@
|
||||||
|
|
||||||
- (void) removeObject: (NSObject*)anObject
|
- (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);
|
node = GSIMapNodeForKeyInBucket(bucket, (GSIMapKey)anObject);
|
||||||
if (bucket)
|
if (node != 0)
|
||||||
{
|
{
|
||||||
GSIMapNode node;
|
if (--node->value.uint == 0)
|
||||||
|
|
||||||
node = GSIMapNodeForKeyInBucket(bucket, (GSIMapKey)anObject);
|
|
||||||
if (node)
|
|
||||||
{
|
{
|
||||||
if (--node->value.uint == 0)
|
GSIMapRemoveNodeFromMap(&map, bucket, node);
|
||||||
{
|
GSIMapFreeNode(&map, node);
|
||||||
GSIMapRemoveNodeFromMap(&map, bucket, node);
|
|
||||||
GSIMapFreeNode(&map, node);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -381,10 +381,12 @@ myEqual(id self, id other)
|
||||||
|
|
||||||
- (void) removeObjectForKey: (id)aKey
|
- (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
|
@end
|
||||||
|
|
|
@ -234,10 +234,12 @@
|
||||||
|
|
||||||
- (void) removeObject: (NSObject *)anObject
|
- (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
|
- (void) removeAllObjects
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue