Some error trapping code.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@3078 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-MacDonald 1998-10-17 06:47:46 +00:00
parent d841db9f24
commit 476d0a407f
4 changed files with 80 additions and 33 deletions

View file

@ -1,3 +1,9 @@
Thu Oct 17 08:15:00 1998 Richard Frith-Macdonald <richard@brainstorm.co.uk>
src/NSGDictionary.m: Added checks for invalid parameters.
src/NSGSet.m: Added checks for invalid parameters.
src/NSGCountedSet.m: Added checks for invalid parameters.
Thu Oct 15 08:13:12 1998 Masatake Yamato <masata-y@is.aist-nara.ac.jp>
* src/NSString.m ([NSString

View file

@ -23,8 +23,9 @@
#include <config.h>
#include <Foundation/NSSet.h>
//#include <Foundation/NSGSet.h>
#include <gnustep/base/behavior.h>
#include <Foundation/NSAutoreleasePool.h>
#include <Foundation/NSException.h>
#include <Foundation/NSUtilities.h>
#include <Foundation/NSString.h>
#include <Foundation/NSPortCoder.h>
@ -57,9 +58,11 @@
- initWithSet: (NSSet*)d
{
[super init];
set = [(NSGCountedSet*)d retain];
node = set->map.firstNode;
self = [super init];
if (self) {
set = [(NSGCountedSet*)d retain];
node = set->map.firstNode;
}
return self;
}
@ -168,8 +171,14 @@
return nil;
}
for (i = 0; i < c; i++) {
FastMapNode node = FastMapNodeForKey(&map, (FastMapItem)objs[i]);
FastMapNode node;
if (objs[i] == nil) {
[self autorelease];
[NSException raise: NSInvalidArgumentException
format: @"Tried to init counted set with nil value"];
}
node = FastMapNodeForKey(&map, (FastMapItem)objs[i]);
if (node == 0) {
FastMapAddPair(&map,(FastMapItem)objs[i],(FastMapItem)(unsigned)1);
}
@ -182,8 +191,14 @@
- (void) addObject: (NSObject*)anObject
{
FastMapNode node = FastMapNodeForKey(&map, (FastMapItem)anObject);
FastMapNode node;
if (anObject == nil) {
[NSException raise: NSInvalidArgumentException
format: @"Tried to nil value to counted set"];
}
node = FastMapNodeForKey(&map, (FastMapItem)anObject);
if (node == 0) {
FastMapAddPair(&map,(FastMapItem)anObject,(FastMapItem)(unsigned)1);
}
@ -199,22 +214,26 @@
- (unsigned) countForObject: (id)anObject
{
FastMapNode node = FastMapNodeForKey(&map, (FastMapItem)anObject);
if (anObject) {
FastMapNode node = FastMapNodeForKey(&map, (FastMapItem)anObject);
if (node == 0) {
return 0;
if (node) {
return node->value.u;
}
}
return node->value.u;
return 0;
}
- (id) member: (id)anObject
{
FastMapNode node = FastMapNodeForKey(&map, (FastMapItem)anObject);
if (anObject) {
FastMapNode node = FastMapNodeForKey(&map, (FastMapItem)anObject);
if (node == 0) {
return nil;
if (node) {
return node->key.o;
}
}
return node->key.o;
return nil;
}
- (NSEnumerator*) objectEnumerator
@ -224,17 +243,19 @@
- (void) removeObject: (NSObject*)anObject
{
FastMapBucket bucket;
if (anObject) {
FastMapBucket bucket;
bucket = FastMapBucketForKey(&map, (FastMapItem)anObject);
if (bucket) {
FastMapNode node;
bucket = FastMapBucketForKey(&map, (FastMapItem)anObject);
if (bucket) {
FastMapNode node;
node = FastMapNodeForKeyInBucket(bucket, (FastMapItem)anObject);
if (node) {
if (--node->value.u == 0) {
FastMapRemoveNodeFromMap(&map, bucket, node);
FastMapFreeNode(&map, node);
node = FastMapNodeForKeyInBucket(bucket, (FastMapItem)anObject);
if (node) {
if (--node->value.u == 0) {
FastMapRemoveNodeFromMap(&map, bucket, node);
FastMapFreeNode(&map, node);
}
}
}
}

View file

@ -24,6 +24,7 @@
#include <config.h>
#include <Foundation/NSDictionary.h>
#include <Foundation/NSAutoreleasePool.h>
#include <Foundation/NSUtilities.h>
#include <Foundation/NSString.h>
#include <Foundation/NSException.h>
@ -205,10 +206,12 @@ myEqual(NSObject *self, NSObject *other)
FastMapNode node = FastMapNodeForKey(&map, (FastMapItem)keys[i]);
if (keys[i] == nil) {
[self autorelease];
[NSException raise: NSInvalidArgumentException
format: @"Tried to init dictionary with nil key"];
}
if (objs[i] == nil) {
[self autorelease];
[NSException raise: NSInvalidArgumentException
format: @"Tried to init dictionary with nil value"];
}
@ -243,8 +246,9 @@ myEqual(NSObject *self, NSObject *other)
if (aKey != nil) {
FastMapNode node = FastMapNodeForKey(&map, (FastMapItem)aKey);
if (node)
if (node) {
return node->value.o;
}
}
return nil;
}

View file

@ -24,8 +24,9 @@
#include <config.h>
#include <Foundation/NSSet.h>
//#include <Foundation/NSGSet.h>
#include <gnustep/base/behavior.h>
#include <Foundation/NSAutoreleasePool.h>
#include <Foundation/NSException.h>
#include <Foundation/NSUtilities.h>
#include <Foundation/NSString.h>
#include <Foundation/NSPortCoder.h>
@ -159,8 +160,14 @@
int i;
FastMapInitWithZoneAndCapacity(&map, [self zone], c);
for (i = 0; i < c; i++) {
FastMapNode node = FastMapNodeForKey(&map, (FastMapItem)objs[i]);
FastMapNode node;
if (objs[i] == nil) {
[self autorelease];
[NSException raise: NSInvalidArgumentException
format: @"Tried to init set with nil value"];
}
node = FastMapNodeForKey(&map, (FastMapItem)objs[i]);
if (node == 0) {
FastMapAddKey(&map, (FastMapItem)objs[i]);
}
@ -170,12 +177,14 @@
- (id) member: (id)anObject
{
FastMapNode node = FastMapNodeForKey(&map, (FastMapItem)anObject);
if (anObject) {
FastMapNode node = FastMapNodeForKey(&map, (FastMapItem)anObject);
if (node == 0) {
return nil;
if (node) {
return node->key.o;
}
}
return node->key.o;
return nil;
}
- (NSEnumerator*) objectEnumerator
@ -204,8 +213,13 @@
- (void) addObject: (NSObject*)anObject
{
FastMapNode node = FastMapNodeForKey(&map, (FastMapItem)anObject);
FastMapNode node;
if (anObject == nil) {
[NSException raise: NSInvalidArgumentException
format: @"Tried to add nil to set"];
}
node = FastMapNodeForKey(&map, (FastMapItem)anObject);
if (node == 0) {
FastMapAddKey(&map, (FastMapItem)anObject);
}
@ -213,7 +227,9 @@
- (void) removeObject: (NSObject *)anObject
{
FastMapRemoveKey(&map, (FastMapItem)anObject);
if (anObject) {
FastMapRemoveKey(&map, (FastMapItem)anObject);
}
}
- (void) removeAllObjects