Index: src/OFAutoreleasePool.m ================================================================== --- src/OFAutoreleasePool.m +++ src/OFAutoreleasePool.m @@ -41,24 +41,18 @@ pool_list_key = [[OFTLSKey alloc] initWithDestructor: release_list]; } + (void)addToPool: (OFObject*)obj { - OFList *pool_list; + OFList *pool_list = [OFThread objectForTLSKey: pool_list_key]; - @try { - pool_list = [OFThread objectForTLSKey: pool_list_key]; - } @catch (OFNotInSetException *e) { - [e dealloc]; + if (pool_list == nil || [pool_list last] == NULL) { [[self alloc] init]; pool_list = [OFThread objectForTLSKey: pool_list_key]; } - if ([pool_list last] == NULL) - [[self alloc] init]; - - if ([pool_list last] == NULL) + if (pool_list == nil || [pool_list last] == NULL) @throw [OFInitializationFailedException newWithClass: self]; [[pool_list last]->object addToPool: obj]; } @@ -68,14 +62,11 @@ self = [super init]; objects = nil; - @try { - pool_list = [OFThread objectForTLSKey: pool_list_key]; - } @catch (OFNotInSetException *e) { - [e dealloc]; + if ((pool_list = [OFThread objectForTLSKey: pool_list_key]) == nil) { pool_list = [[OFList alloc] initWithoutRetainAndRelease]; [OFThread setObject: pool_list forTLSKey: pool_list_key]; [pool_list release]; } Index: src/OFDataArray.m ================================================================== --- src/OFDataArray.m +++ src/OFDataArray.m @@ -41,11 +41,12 @@ self = [super init]; if (is == 0) { c = isa; [super dealloc]; - @throw [OFInvalidArgumentException newWithClass: c]; + @throw [OFInvalidArgumentException newWithClass: c + andSelector: _cmd]; } data = NULL; itemsize = is; count = 0; Index: src/OFDictionary.h ================================================================== --- src/OFDictionary.h +++ src/OFDictionary.h @@ -60,11 +60,11 @@ - set: (OFObject*)key to: (OFObject*)obj; /** * \param key The key whose object should be returned - * \return The object for the given key + * \return The object for the given key or nil if the key was not found */ - (id)get: (OFObject*)key; /** * Remove the object with the given key from the dictionary. Index: src/OFDictionary.m ================================================================== --- src/OFDictionary.m +++ src/OFDictionary.m @@ -101,11 +101,12 @@ { uint32_t hash; of_list_object_t *iter; if (key == nil || obj == nil) - @throw [OFInvalidArgumentException newWithClass: isa]; + @throw [OFInvalidArgumentException newWithClass: isa + andSelector: _cmd]; hash = [key hash] & (size - 1); if (data[hash] == nil) data[hash] = [[OFList alloc] init]; @@ -130,36 +131,38 @@ { uint32_t hash; of_list_object_t *iter; if (key == nil) - @throw [OFInvalidArgumentException newWithClass: isa]; + @throw [OFInvalidArgumentException newWithClass: isa + andSelector: _cmd]; hash = [key hash] & (size - 1); if (data[hash] == nil) - @throw [OFNotInSetException newWithClass: isa]; + return nil; for (iter = [data[hash] first]; iter != NULL; iter = iter->next->next) if ([iter->object isEqual: key]) return iter->next->object; - @throw [OFNotInSetException newWithClass: isa]; + return nil; } - remove: (OFObject*)key { uint32_t hash; of_list_object_t *iter; if (key == nil) - @throw [OFInvalidArgumentException newWithClass: isa]; + @throw [OFInvalidArgumentException newWithClass: isa + andSelector: _cmd]; hash = [key hash] & (size - 1); if (data[hash] == nil) - @throw [OFNotInSetException newWithClass: isa]; + return self; for (iter = [data[hash] first]; iter != NULL; iter = iter->next->next) { if ([iter->object isEqual: key]) { [data[hash] remove: iter->next]; [data[hash] remove: iter]; @@ -171,11 +174,11 @@ return self; } } - @throw [OFNotInSetException newWithClass: isa]; + return self; } - (float)averageItemsPerBucket { size_t items, buckets, i; Index: src/OFExceptions.h ================================================================== --- src/OFExceptions.h +++ src/OFExceptions.h @@ -214,16 +214,10 @@ * An OFException indicating that initializing something failed. */ @interface OFInitializationFailedException: OFException {} @end -/** - * An OFException indicating that the requested key is not in the set. - */ -@interface OFNotInSetException: OFException {} -@end - /** * An OFException indicating the file couldn't be opened. */ @interface OFOpenFileFailedException: OFException { Index: src/OFExceptions.m ================================================================== --- src/OFExceptions.m +++ src/OFExceptions.m @@ -267,23 +267,10 @@ if (string != NULL) return string; asprintf(&string, "Initialization failed for class %s!", [class name]); - return string; -} -@end - -@implementation OFNotInSetException -- (const char*)cString -{ - if (string != NULL) - return string; - - asprintf(&string, "The requested key is not in the set of type %s!", - [class name]); - return string; } @end @implementation OFOpenFileFailedException Index: src/OFIterator.m ================================================================== --- src/OFIterator.m +++ src/OFIterator.m @@ -33,12 +33,11 @@ - (id)nextObject { if (last == NULL) { for (; pos < size && data[pos] == nil; pos++); if (pos == size) - @throw [OFNotInSetException - newWithClass: [OFDictionary class]]; + return nil; return (last = [data[pos++] first])->object; } if ((last = last->next) != NULL) Index: src/OFString.m ================================================================== --- src/OFString.m +++ src/OFString.m @@ -88,11 +88,12 @@ } - (int)compare: (id)obj { if (![obj isKindOf: [OFString class]]) - @throw [OFInvalidArgumentException newWithClass: isa]; + @throw [OFInvalidArgumentException newWithClass: isa + andSelector: _cmd]; return strcmp(string, [obj cString]); } - (uint32_t)hash Index: src/OFThread.m ================================================================== --- src/OFThread.m +++ src/OFThread.m @@ -46,26 +46,20 @@ } + setObject: (id)obj forTLSKey: (OFTLSKey*)key { - id old; - - @try { - old = [self objectForTLSKey: key]; - } @catch (OFNotInSetException *e) { - [e dealloc]; - old = nil; - } + id old = [self objectForTLSKey: key]; #ifndef _WIN32 if (pthread_setspecific(key->key, obj)) #else if (!TlsSetValue(key->key, obj)) #endif /* FIXME: Maybe another exception would be better */ - @throw [OFNotInSetException newWithClass: self]; + @throw [OFInvalidArgumentException newWithClass: self + andSelector: _cmd]; if (obj != nil) [obj retain]; if (old != nil) [old release]; @@ -86,12 +80,12 @@ /* * NULL and nil might be different on some platforms. NULL is returned * if the key is missing, nil can be returned if it was explicitly set * to nil to release the old object. */ - if (ret == NULL || (id)ret == nil) - @throw [OFNotInSetException newWithClass: self]; + if (ret == NULL) + return nil; return (id)ret; } - initWithObject: (id)obj Index: tests/OFAutoreleasePool/OFAutoreleasePool.m ================================================================== --- tests/OFAutoreleasePool/OFAutoreleasePool.m +++ tests/OFAutoreleasePool/OFAutoreleasePool.m @@ -96,7 +96,9 @@ pool2 = [[OFAutoreleasePool alloc] init]; o3 = [[[OFObject alloc] init] autorelease]; [pool1 release]; - return (inits == 20 && retains == 5 && releases == 16 ? 0 : 1); + printf("inits: %02d\nretains: %02d\nreleases: %02d\n", + inits, retains, releases); + return (inits == 17 && retains == 5 && releases == 16 ? 0 : 1); } Index: tests/OFDictionary/OFDictionary.m ================================================================== --- tests/OFDictionary/OFDictionary.m +++ tests/OFDictionary/OFDictionary.m @@ -22,12 +22,10 @@ #import "OFExceptions.h" int main() { - BOOL caught; - OFDictionary *dict = [OFDictionary dictionaryWithHashSize: 16]; OFIterator *iter = [dict iterator]; OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; OFString *key1 = [OFString stringWithCString: "key1"]; @@ -40,75 +38,51 @@ [dict set: key2 to: value2]; [pool release]; if (strcmp([[dict get: @"key1"] cString], "value1")) { - puts("\033[K\033[1;31mTest 1/8 failed!\033[m"); + puts("\033[K\033[1;31mTest 1/7 failed!\033[m"); return 1; } if (strcmp([[dict get: key2] cString], "value2")) { - puts("\033[K\033[1;31mTest 2/8 failed!\033[m"); + puts("\033[K\033[1;31mTest 2/7 failed!\033[m"); return 1; } if (![[iter nextObject] isEqual: @"key2"] || ![[iter nextObject] isEqual: @"value2"] || ![[iter nextObject] isEqual: @"key1"] || ![[iter nextObject] isEqual: @"value1"]) { - puts("\033[K\033[1;31mTest 3/8 failed!\033[m"); + puts("\033[K\033[1;31mTest 3/7 failed!\033[m"); return 1; } [dict changeHashSize: 8]; iter = [dict iterator]; if (![[iter nextObject] isEqual: @"key1"] || ![[iter nextObject] isEqual: @"value1"] || ![[iter nextObject] isEqual: @"key2"] || ![[iter nextObject] isEqual: @"value2"]) { - puts("\033[K\033[1;31mTest 4/8 failed!\033[m"); + puts("\033[K\033[1;31mTest 4/7 failed!\033[m"); return 1; } if ([dict averageItemsPerBucket] != 1.0) { - puts("\033[K\033[1;31mTest 5/8 failed!\033[m"); - return 1; - } - - caught = NO; - @try { - [iter nextObject]; - } @catch (OFNotInSetException *e) { - caught = YES; - } - if (!caught) { - puts("\033[K\033[1;31mTest 6/8 failed!\033[m"); - return 1; - } - - caught = NO; - @try { - [dict get: @"key3"]; - } @catch (OFNotInSetException *e) { - caught = YES; - } - if (!caught) { - puts("\033[K\033[1;31mTest 7/8 failed!\033[m"); - return 1; - } - - [dict remove: @"key2"]; - caught = NO; - @try { - [dict remove: @"key2"]; - } @catch (OFNotInSetException *e) { - caught = YES; - } - if (!caught) { - puts("\033[K\033[1;31mTest 8/8 failed!\033[m"); - return 1; - } - - puts("\033[1;32mTests successful: 8/8\033[0m"); + puts("\033[K\033[1;31mTest 5/7 failed!\033[m"); + return 1; + } + + if ([iter nextObject] != nil) { + puts("\033[K\033[1;31mTest 6/7 failed!\033[m"); + return 1; + } + + if ([dict get: @"key3"] != nil) { + puts("\033[K\033[1;31mTest 7/7 failed!\033[m"); + return 1; + } + + puts("\033[1;32mTests successful: 7/7\033[0m"); return 0; }