mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-31 08:41:03 +00:00
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:
parent
0554ecb6dd
commit
72684b745c
4 changed files with 80 additions and 33 deletions
|
@ -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>
|
Thu Oct 15 08:13:12 1998 Masatake Yamato <masata-y@is.aist-nara.ac.jp>
|
||||||
|
|
||||||
* src/NSString.m ([NSString
|
* src/NSString.m ([NSString
|
||||||
|
|
|
@ -23,8 +23,9 @@
|
||||||
|
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
#include <Foundation/NSSet.h>
|
#include <Foundation/NSSet.h>
|
||||||
//#include <Foundation/NSGSet.h>
|
|
||||||
#include <gnustep/base/behavior.h>
|
#include <gnustep/base/behavior.h>
|
||||||
|
#include <Foundation/NSAutoreleasePool.h>
|
||||||
|
#include <Foundation/NSException.h>
|
||||||
#include <Foundation/NSUtilities.h>
|
#include <Foundation/NSUtilities.h>
|
||||||
#include <Foundation/NSString.h>
|
#include <Foundation/NSString.h>
|
||||||
#include <Foundation/NSPortCoder.h>
|
#include <Foundation/NSPortCoder.h>
|
||||||
|
@ -57,9 +58,11 @@
|
||||||
|
|
||||||
- initWithSet: (NSSet*)d
|
- initWithSet: (NSSet*)d
|
||||||
{
|
{
|
||||||
[super init];
|
self = [super init];
|
||||||
set = [(NSGCountedSet*)d retain];
|
if (self) {
|
||||||
node = set->map.firstNode;
|
set = [(NSGCountedSet*)d retain];
|
||||||
|
node = set->map.firstNode;
|
||||||
|
}
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -168,8 +171,14 @@
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
for (i = 0; i < c; i++) {
|
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) {
|
if (node == 0) {
|
||||||
FastMapAddPair(&map,(FastMapItem)objs[i],(FastMapItem)(unsigned)1);
|
FastMapAddPair(&map,(FastMapItem)objs[i],(FastMapItem)(unsigned)1);
|
||||||
}
|
}
|
||||||
|
@ -182,8 +191,14 @@
|
||||||
|
|
||||||
- (void) addObject: (NSObject*)anObject
|
- (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) {
|
if (node == 0) {
|
||||||
FastMapAddPair(&map,(FastMapItem)anObject,(FastMapItem)(unsigned)1);
|
FastMapAddPair(&map,(FastMapItem)anObject,(FastMapItem)(unsigned)1);
|
||||||
}
|
}
|
||||||
|
@ -199,22 +214,26 @@
|
||||||
|
|
||||||
- (unsigned) countForObject: (id)anObject
|
- (unsigned) countForObject: (id)anObject
|
||||||
{
|
{
|
||||||
FastMapNode node = FastMapNodeForKey(&map, (FastMapItem)anObject);
|
if (anObject) {
|
||||||
|
FastMapNode node = FastMapNodeForKey(&map, (FastMapItem)anObject);
|
||||||
|
|
||||||
if (node == 0) {
|
if (node) {
|
||||||
return 0;
|
return node->value.u;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return node->value.u;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (id) member: (id)anObject
|
- (id) member: (id)anObject
|
||||||
{
|
{
|
||||||
FastMapNode node = FastMapNodeForKey(&map, (FastMapItem)anObject);
|
if (anObject) {
|
||||||
|
FastMapNode node = FastMapNodeForKey(&map, (FastMapItem)anObject);
|
||||||
|
|
||||||
if (node == 0) {
|
if (node) {
|
||||||
return nil;
|
return node->key.o;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return node->key.o;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSEnumerator*) objectEnumerator
|
- (NSEnumerator*) objectEnumerator
|
||||||
|
@ -224,17 +243,19 @@
|
||||||
|
|
||||||
- (void) removeObject: (NSObject*)anObject
|
- (void) removeObject: (NSObject*)anObject
|
||||||
{
|
{
|
||||||
FastMapBucket bucket;
|
if (anObject) {
|
||||||
|
FastMapBucket bucket;
|
||||||
|
|
||||||
|
bucket = FastMapBucketForKey(&map, (FastMapItem)anObject);
|
||||||
|
if (bucket) {
|
||||||
|
FastMapNode node;
|
||||||
|
|
||||||
bucket = FastMapBucketForKey(&map, (FastMapItem)anObject);
|
node = FastMapNodeForKeyInBucket(bucket, (FastMapItem)anObject);
|
||||||
if (bucket) {
|
if (node) {
|
||||||
FastMapNode node;
|
if (--node->value.u == 0) {
|
||||||
|
FastMapRemoveNodeFromMap(&map, bucket, node);
|
||||||
node = FastMapNodeForKeyInBucket(bucket, (FastMapItem)anObject);
|
FastMapFreeNode(&map, node);
|
||||||
if (node) {
|
}
|
||||||
if (--node->value.u == 0) {
|
|
||||||
FastMapRemoveNodeFromMap(&map, bucket, node);
|
|
||||||
FastMapFreeNode(&map, node);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
|
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
#include <Foundation/NSDictionary.h>
|
#include <Foundation/NSDictionary.h>
|
||||||
|
#include <Foundation/NSAutoreleasePool.h>
|
||||||
#include <Foundation/NSUtilities.h>
|
#include <Foundation/NSUtilities.h>
|
||||||
#include <Foundation/NSString.h>
|
#include <Foundation/NSString.h>
|
||||||
#include <Foundation/NSException.h>
|
#include <Foundation/NSException.h>
|
||||||
|
@ -205,10 +206,12 @@ myEqual(NSObject *self, NSObject *other)
|
||||||
FastMapNode node = FastMapNodeForKey(&map, (FastMapItem)keys[i]);
|
FastMapNode node = FastMapNodeForKey(&map, (FastMapItem)keys[i]);
|
||||||
|
|
||||||
if (keys[i] == nil) {
|
if (keys[i] == nil) {
|
||||||
|
[self autorelease];
|
||||||
[NSException raise: NSInvalidArgumentException
|
[NSException raise: NSInvalidArgumentException
|
||||||
format: @"Tried to init dictionary with nil key"];
|
format: @"Tried to init dictionary with nil key"];
|
||||||
}
|
}
|
||||||
if (objs[i] == nil) {
|
if (objs[i] == nil) {
|
||||||
|
[self autorelease];
|
||||||
[NSException raise: NSInvalidArgumentException
|
[NSException raise: NSInvalidArgumentException
|
||||||
format: @"Tried to init dictionary with nil value"];
|
format: @"Tried to init dictionary with nil value"];
|
||||||
}
|
}
|
||||||
|
@ -243,8 +246,9 @@ myEqual(NSObject *self, NSObject *other)
|
||||||
if (aKey != nil) {
|
if (aKey != nil) {
|
||||||
FastMapNode node = FastMapNodeForKey(&map, (FastMapItem)aKey);
|
FastMapNode node = FastMapNodeForKey(&map, (FastMapItem)aKey);
|
||||||
|
|
||||||
if (node)
|
if (node) {
|
||||||
return node->value.o;
|
return node->value.o;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,8 +24,9 @@
|
||||||
|
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
#include <Foundation/NSSet.h>
|
#include <Foundation/NSSet.h>
|
||||||
//#include <Foundation/NSGSet.h>
|
|
||||||
#include <gnustep/base/behavior.h>
|
#include <gnustep/base/behavior.h>
|
||||||
|
#include <Foundation/NSAutoreleasePool.h>
|
||||||
|
#include <Foundation/NSException.h>
|
||||||
#include <Foundation/NSUtilities.h>
|
#include <Foundation/NSUtilities.h>
|
||||||
#include <Foundation/NSString.h>
|
#include <Foundation/NSString.h>
|
||||||
#include <Foundation/NSPortCoder.h>
|
#include <Foundation/NSPortCoder.h>
|
||||||
|
@ -159,8 +160,14 @@
|
||||||
int i;
|
int i;
|
||||||
FastMapInitWithZoneAndCapacity(&map, [self zone], c);
|
FastMapInitWithZoneAndCapacity(&map, [self zone], c);
|
||||||
for (i = 0; i < c; i++) {
|
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) {
|
if (node == 0) {
|
||||||
FastMapAddKey(&map, (FastMapItem)objs[i]);
|
FastMapAddKey(&map, (FastMapItem)objs[i]);
|
||||||
}
|
}
|
||||||
|
@ -170,12 +177,14 @@
|
||||||
|
|
||||||
- (id) member: (id)anObject
|
- (id) member: (id)anObject
|
||||||
{
|
{
|
||||||
FastMapNode node = FastMapNodeForKey(&map, (FastMapItem)anObject);
|
if (anObject) {
|
||||||
|
FastMapNode node = FastMapNodeForKey(&map, (FastMapItem)anObject);
|
||||||
|
|
||||||
if (node == 0) {
|
if (node) {
|
||||||
return nil;
|
return node->key.o;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return node->key.o;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSEnumerator*) objectEnumerator
|
- (NSEnumerator*) objectEnumerator
|
||||||
|
@ -204,8 +213,13 @@
|
||||||
|
|
||||||
- (void) addObject: (NSObject*)anObject
|
- (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) {
|
if (node == 0) {
|
||||||
FastMapAddKey(&map, (FastMapItem)anObject);
|
FastMapAddKey(&map, (FastMapItem)anObject);
|
||||||
}
|
}
|
||||||
|
@ -213,7 +227,9 @@
|
||||||
|
|
||||||
- (void) removeObject: (NSObject *)anObject
|
- (void) removeObject: (NSObject *)anObject
|
||||||
{
|
{
|
||||||
FastMapRemoveKey(&map, (FastMapItem)anObject);
|
if (anObject) {
|
||||||
|
FastMapRemoveKey(&map, (FastMapItem)anObject);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) removeAllObjects
|
- (void) removeAllObjects
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue