Index: src/OFApplication.m ================================================================== --- src/OFApplication.m +++ src/OFApplication.m @@ -89,45 +89,50 @@ exit(status); } - init { - OFAutoreleasePool *pool; - char **env; - self = [super init]; - environment = [[OFMutableDictionary alloc] init]; + @try { + OFAutoreleasePool *pool; + char **env; + + environment = [[OFMutableDictionary alloc] init]; - atexit(atexit_handler); + atexit(atexit_handler); #ifdef __MACH__ - env = *_NSGetEnviron(); + env = *_NSGetEnviron(); #else - env = environ; + env = environ; #endif - pool = [[OFAutoreleasePool alloc] init]; - for (; *env != NULL; env++) { - OFString *key; - OFString *value; - char *sep; - - if ((sep = strchr(*env, '=')) == NULL) { - fprintf(stderr, "Warning: Invalid environment " - "variable: %s\n", *env); - continue; - } - - key = [OFString stringWithCString: *env - length: sep - *env]; - value = [OFString stringWithCString: sep + 1]; - [environment setObject: value - forKey: key]; - - [pool releaseObjects]; - } - [pool release]; + pool = [[OFAutoreleasePool alloc] init]; + for (; *env != NULL; env++) { + OFString *key; + OFString *value; + char *sep; + + if ((sep = strchr(*env, '=')) == NULL) { + fprintf(stderr, "Warning: Invalid environment " + "variable: %s\n", *env); + continue; + } + + key = [OFString stringWithCString: *env + length: sep - *env]; + value = [OFString stringWithCString: sep + 1]; + [environment setObject: value + forKey: key]; + + [pool releaseObjects]; + } + [pool release]; + } @catch (id e) { + [self release]; + @throw e; + } return self; } - (void)setArgumentCount: (int*)argc_ Index: src/OFArray.m ================================================================== --- src/OFArray.m +++ src/OFArray.m @@ -59,16 +59,12 @@ { self = [super init]; @try { array = [[OFDataArray alloc] initWithItemSize: sizeof(id)]; - } @catch (OFException *e) { - /* - * We can't use [super dealloc] on OS X here. Compiler bug? - * [self dealloc] will do here as we check for nil in dealloc. - */ - [self dealloc]; + } @catch (id e) { + [self release]; @throw e; } return self; } @@ -77,17 +73,16 @@ { self = [self init]; @try { [array addItem: &obj]; - } @catch (OFException *e) { - [self dealloc]; + [obj retain]; + } @catch (id e) { + [self release]; @throw e; } - [obj retain]; - return self; } - initWithObjects: (id)first, ... { @@ -103,74 +98,76 @@ } - initWithObject: (id)first argList: (va_list)args { - id obj; - self = [self init]; @try { + id obj; + [array addItem: &first]; while ((obj = va_arg(args, id)) != nil) { [array addItem: &obj]; [obj retain]; } - } @catch (OFException *e) { - [self dealloc]; + } @catch (id e) { + [self release]; @throw e; } return self; } - initWithCArray: (id*)objs { - id *obj; - size_t count; - self = [self init]; - count = 0; - - for (obj = objs; *obj != nil; obj++) { - [*obj retain]; - count++; - } - @try { + id *obj; + size_t count = 0; + + for (obj = objs; *obj != nil; obj++) { + [*obj retain]; + count++; + } + [array addNItems: count fromCArray: objs]; - } @catch (OFException *e) { + } @catch (id e) { + id *obj; + for (obj = objs; *obj != nil; obj++) [*obj release]; - [self dealloc]; + [self release]; @throw e; } return self; } - initWithCArray: (id*)objs length: (size_t)len { - size_t i; - self = [self init]; - for (i = 0; i < len; i++) - [objs[i] retain]; - @try { + size_t i; + + for (i = 0; i < len; i++) + [objs[i] retain]; + [array addNItems: len fromCArray: objs]; - } @catch (OFException *e) { + } @catch (id e) { + size_t i; + for (i = 0; i < len; i++) [objs[i] release]; - [self dealloc]; + [self release]; @throw e; } return self; } Index: src/OFAutoreleasePool.m ================================================================== --- src/OFAutoreleasePool.m +++ src/OFAutoreleasePool.m @@ -46,11 +46,11 @@ #endif if (last == nil) { @try { [[self alloc] init]; - } @catch (OFException *e) { + } @catch (id e) { [obj release]; @throw e; } #ifdef OF_THREADS @@ -63,11 +63,11 @@ @throw [OFInitializationFailedException newWithClass: self]; } @try { [last addObject: obj]; - } @catch (OFException *e) { + } @catch (id e) { [obj release]; @throw e; } } @@ -80,55 +80,45 @@ #endif } - init { -#ifdef OF_THREADS - id first; -#endif - self = [super init]; -#ifdef OF_THREADS - first = of_tlskey_get(first_key); - prev = of_tlskey_get(last_key); - - if (!of_tlskey_set(last_key, self)) { - Class c = isa; - [super dealloc]; - @throw [OFInitializationFailedException newWithClass: c]; - } -#else - prev = last; - last = self; -#endif - - if (first == nil) { -#ifdef OF_THREADS - if (!of_tlskey_set(first_key, self)) { - Class c = isa; - - of_tlskey_set(last_key, prev); - - [super dealloc]; - @throw [OFInitializationFailedException - newWithClass: c]; - } -#else - first = self; -#endif - } - - if (prev != nil) - prev->next = self; - - size = GROW_SIZE; - @try { + @try { +#ifdef OF_THREADS + id first = of_tlskey_get(first_key); + prev = of_tlskey_get(last_key); + + if (!of_tlskey_set(last_key, self)) + @throw [OFInitializationFailedException + newWithClass: isa]; +#else + prev = last; + last = self; +#endif + + if (first == nil) { +#ifdef OF_THREADS + if (!of_tlskey_set(first_key, self)) { + of_tlskey_set(last_key, prev); + @throw [OFInitializationFailedException + newWithClass: isa]; + } +#else + first = self; +#endif + } + + if (prev != nil) + prev->next = self; + + size = GROW_SIZE; objects = [self allocMemoryForNItems: GROW_SIZE withSize: sizeof(id)]; - } @catch (OFException *e) { - [self dealloc]; + } @catch (id e) { + [self release]; @throw e; } return self; } Index: src/OFDataArray.m ================================================================== --- src/OFDataArray.m +++ src/OFDataArray.m @@ -25,29 +25,31 @@ return [[[self alloc] initWithItemSize: is] autorelease]; } - init { - @throw [OFNotImplementedException newWithClass: isa + Class c = isa; + [self release]; + @throw [OFNotImplementedException newWithClass: c selector: _cmd]; } - initWithItemSize: (size_t)is { - Class c; - self = [super init]; - if (is == 0) { - c = isa; - [super dealloc]; - @throw [OFInvalidArgumentException newWithClass: c - selector: _cmd]; - } - - data = NULL; - itemSize = is; + @try { + if (is == 0) + @throw [OFInvalidArgumentException newWithClass: isa + selector: _cmd]; + + data = NULL; + itemSize = is; + } @catch (id e) { + [self release]; + @throw e; + } return self; } - (size_t)count Index: src/OFDictionary.m ================================================================== --- src/OFDictionary.m +++ src/OFDictionary.m @@ -65,271 +65,227 @@ - init { self = [super init]; - size = 1; - @try { data = [self allocMemoryWithSize: sizeof(BUCKET*)]; - } @catch (OFException *e) { - /* - * We can't use [super dealloc] on OS X here. Compiler bug? - * Anyway, set size to 0 so that [self dealloc] works. - */ - size = 0; - [self dealloc]; + size = 1; + data[0] = NULL; + } @catch (id e) { + [self release]; @throw e; } - data[0] = NULL; return self; } - initWithDictionary: (OFDictionary*)dict { - uint32_t i; - self = [super init]; - if (dict == nil) { - Class c = isa; - size = 0; - [self dealloc]; - @throw [OFInvalidArgumentException newWithClass: c - selector: _cmd]; - } - @try { + uint32_t i; + + if (dict == nil) + @throw [OFInvalidArgumentException newWithClass: isa + selector: _cmd]; + data = [self allocMemoryForNItems: dict->size withSize: sizeof(BUCKET*)]; for (i = 0; i < dict->size; i++) data[i] = NULL; - } @catch (OFException *e) { - /* - * We can't use [super dealloc] on OS X here. Compiler bug? - * Anyway, we didn't do anything yet anyway, so [self dealloc] - * works. - */ - [self dealloc]; - @throw e; - } - - size = dict->size; - count = dict->count; - - for (i = 0; i < size; i++) { - id key; - BUCKET *b; - - if (dict->data[i] == NULL || dict->data[i] == DELETED) - continue; - - @try { + + size = dict->size; + count = dict->count; + + for (i = 0; i < size; i++) { + id key; + BUCKET *b; + + if (dict->data[i] == NULL || dict->data[i] == DELETED) + continue; + b = [self allocMemoryWithSize: sizeof(BUCKET)]; key = [dict->data[i]->key copy]; - } @catch (OFException *e) { - [self dealloc]; - @throw e; - } - - @try { - [dict->data[i]->object retain]; - } @catch (OFException *e) { - [(id)key release]; - [self dealloc]; - @throw e; - } - - b->key = key; - b->object = dict->data[i]->object; - b->hash = dict->data[i]->hash; - data[i] = b; + + @try { + [dict->data[i]->object retain]; + } @catch (id e) { + [(id)key release]; + @throw e; + } + + b->key = key; + b->object = dict->data[i]->object; + b->hash = dict->data[i]->hash; + + data[i] = b; + } + } @catch (id e) { + [self release]; + @throw e; } return self; } - initWithObject: (id)obj forKey: (id )key { - uint32_t i; - BUCKET *b; - - self = [self init]; + self = [super init]; @try { + uint32_t i; + BUCKET *b; + data = [self allocMemoryForNItems: 2 withSize: sizeof(BUCKET*)]; size = 2; for (i = 0; i < size; i++) data[i] = NULL; - } @catch (OFException *e) { - /* - * We can't use [super dealloc] on OS X here. Compiler bug? - * Anyway, we didn't do anything yet anyway, so [self dealloc] - * works. - */ - [self dealloc]; - @throw e; - } - - i = [(id)key hash] & 1; - - @try { - b = [self allocMemoryWithSize: sizeof(BUCKET)]; - key = [key copy]; - } @catch (OFException *e) { - [self dealloc]; - @throw e; - } - - @try { - [obj retain]; - } @catch (OFException *e) { - [(id)key release]; - [self dealloc]; - @throw e; - } - - b->key = key; - b->object = obj; - b->hash = [(id)key hash]; - data[i] = b; - count = 1; + + i = [(id)key hash] & 1; + b = [self allocMemoryWithSize: sizeof(BUCKET)]; + key = [key copy]; + + @try { + [obj retain]; + } @catch (id e) { + [(id)key release]; + @throw e; + } + + b->key = key; + b->object = obj; + b->hash = [(id)key hash]; + + data[i] = b; + count = 1; + } @catch (id e) { + [self release]; + @throw e; + } return self; } - initWithObjects: (OFArray*)objs forKeys: (OFArray*)keys { - id *objs_carray, *keys_carray; - size_t i; - self = [super init]; @try { + id *objs_carray, *keys_carray; + size_t i, nsize; uint32_t j; keys_carray = [keys cArray]; objs_carray = [objs cArray]; count = [keys count]; if (count > UINT32_MAX) @throw [OFOutOfRangeException newWithClass: isa]; - for (size = 1; size < count; size <<= 1); - - if (size == 0) - @throw [OFOutOfRangeException newWithClass: isa]; - - data = [self allocMemoryForNItems: size - withSize: sizeof(BUCKET*)]; - - for (j = 0; j < size; j++) - data[j] = NULL; - } @catch (OFException *e) { - /* - * We can't use [super dealloc] on OS X here. Compiler bug? - * Anyway, set size to 0 so that [self dealloc] works. - */ - size = 0; - [self dealloc]; - @throw e; - } - - for (i = 0; i < count; i++) { - uint32_t j, hash, last; - - hash = [keys_carray[i] hash]; - last = size; - - for (j = hash & (size - 1); j < last && data[j] != NULL; j++) - if ([(id)data[j]->key isEqual: keys_carray[i]]) - break; - - /* In case the last bucket is already used */ - if (j >= last) { - last = hash & (size - 1); - - for (j = 0; j < last && data[j] != NULL; j++) - if ([(id)data[j]->key isEqual: keys_carray[i]]) - break; - } - - /* Key not in dictionary */ - if (j >= last || data[j] == NULL || - ![(id)data[j]->key isEqual: keys_carray[i]]) { - BUCKET *b; - id key; - - last = size; - - j = hash & (size - 1); - for (; j < last && data[j] != NULL; j++); - - /* In case the last bucket is already used */ - if (j >= last) { - last = hash & (size - 1); - - for (j = 0; j < last && data[j] != NULL; j++); - } - - if (j >= last) { - Class c = isa; - [self dealloc]; - @throw [OFOutOfRangeException newWithClass: c]; - } - - @try { - b = [self allocMemoryWithSize: sizeof(BUCKET)]; - key = [keys_carray[i] copy]; - } @catch (OFException *e) { - [self dealloc]; - @throw e; - } - - @try { - [objs_carray[i] retain]; - } @catch (OFException *e) { - [(id)key release]; - [self dealloc]; - @throw e; - } - - b->key = key; - b->object = objs_carray[i]; - b->hash = hash; - data[j] = b; - - continue; - } - - /* - * They key is already in the dictionary. However, we just - * replace it so that the programmer gets the same behavior - * as if he'd call setObject:forKey: for each key/object pair. - */ - @try { - [objs_carray[i] retain]; - } @catch (OFException *e) { - [self dealloc]; - @throw e; - } - - @try { - [data[j]->object release]; - } @catch (OFException *e) { - [objs_carray[i] release]; - [self dealloc]; - @throw e; - } - - data[j]->object = objs_carray[i]; + for (nsize = 1; nsize < count; nsize <<= 1); + + if (nsize == 0) + @throw [OFOutOfRangeException newWithClass: isa]; + + data = [self allocMemoryForNItems: nsize + withSize: sizeof(BUCKET*)]; + + for (j = 0; j < nsize; j++) + data[j] = NULL; + + size = nsize; + + for (i = 0; i < count; i++) { + uint32_t hash, last; + + hash = [keys_carray[i] hash]; + last = size; + + for (j = hash & (size - 1); j < last && data[j] != NULL; + j++) + if ([(id)data[j]->key isEqual: keys_carray[i]]) + break; + + /* In case the last bucket is already used */ + if (j >= last) { + last = hash & (size - 1); + + for (j = 0; j < last && data[j] != NULL; j++) + if ([(id)data[j]->key + isEqual: keys_carray[i]]) + break; + } + + /* Key not in dictionary */ + if (j >= last || data[j] == NULL || + ![(id)data[j]->key isEqual: keys_carray[i]]) { + BUCKET *b; + id key; + + last = size; + + j = hash & (size - 1); + for (; j < last && data[j] != NULL; j++); + + /* In case the last bucket is already used */ + if (j >= last) { + last = hash & (size - 1); + + for (j = 0; j < last && data[j] != NULL; + j++); + } + + if (j >= last) + @throw [OFOutOfRangeException + newWithClass: isa]; + + b = [self allocMemoryWithSize: sizeof(BUCKET)]; + key = [keys_carray[i] copy]; + + @try { + [objs_carray[i] retain]; + } @catch (id e) { + [(id)key release]; + @throw e; + } + + b->key = key; + b->object = objs_carray[i]; + b->hash = hash; + + data[j] = b; + + continue; + } + + /* + * The key is already in the dictionary. However, we + * just replace it so that the programmer gets the same + * behavior as if he'd call setObject:forKey: for each + * key/object pair. + */ + [objs_carray[i] retain]; + + @try { + [data[j]->object release]; + } @catch (id e) { + [objs_carray[i] release]; + @throw e; + } + + data[j]->object = objs_carray[i]; + } + } @catch (id e) { + [self release]; + @throw e; } return self; } @@ -347,187 +303,156 @@ } - initWithKey: (id )key argList: (va_list)args { - BUCKET *b; - id obj; - size_t i; - uint32_t j, hash; - va_list args2; - - self = [super init]; - - count = 1; - for (va_copy(args2, args); va_arg(args2, id) != nil; count++); - count >>= 1; - - if (count > UINT32_MAX) { - Class c = isa; - [self dealloc]; - @throw [OFOutOfRangeException newWithClass: c]; - } - - for (size = 1; size < count; size <<= 1); - - if (size == 0) { - Class c = isa; - [self dealloc]; - @throw [OFOutOfRangeException newWithClass: c]; - } - - @try { - data = [self allocMemoryForNItems: size - withSize: sizeof(BUCKET*)]; - - for (j = 0; j < size; j++) - data[j] = NULL; - } @catch (OFException *e) { - /* - * We can't use [super dealloc] on OS X here. Compiler bug? - * Anyway, set size to 0 so that [self dealloc] works. - * */ - size = 0; - [self dealloc]; - @throw e; - } - - if (key == nil) { - Class c = isa; - size = 0; - [self dealloc]; - @throw [OFInvalidArgumentException newWithClass: c - selector: _cmd]; - } - - if ((obj = va_arg(args, id)) == nil) { - Class c = isa; - [self dealloc]; - @throw [OFInvalidArgumentException newWithClass: c - selector: _cmd]; - } - - /* Add first key / object pair */ - hash = [(id)key hash]; - j = hash & (size - 1); - - @try { - b = [self allocMemoryWithSize: sizeof(BUCKET)]; - key = [key copy]; - } @catch (OFException *e) { - [self dealloc]; - @throw e; - } - - @try { - [obj retain]; - } @catch (OFException *e) { - [(id)key release]; - [self dealloc]; - @throw e; - } - - b->key = key; - b->object = obj; - b->hash = hash; - data[j] = b; - - for (i = 1; i < count; i++) { - uint32_t last; - - key = va_arg(args, id ); - obj = va_arg(args, id); - - if (key == nil || obj == nil) { - Class c = isa; - [self dealloc]; - @throw [OFInvalidArgumentException newWithClass: c - selector: _cmd]; - } - - hash = [(id)key hash]; - last = size; - - for (j = hash & (size - 1); j < last && data[j] != NULL; j++) - if ([(id)data[j]->key isEqual: key]) - break; - - /* In case the last bucket is already used */ - if (j >= last) { - last = hash & (size - 1); - - for (j = 0; j < last && data[j] != NULL; j++) - if ([(id)data[j]->key isEqual: key]) - break; - } - - /* Key not in dictionary */ - if (j >= last || data[j] == NULL || - ![(id)data[j]->key isEqual: key]) { - last = size; - - j = hash & (size - 1); - for (; j < last && data[j] != NULL; j++); - - /* In case the last bucket is already used */ - if (j >= last) { - last = hash & (size - 1); - - for (j = 0; j < last && data[j] != NULL; j++); - } - - if (j >= last) { - Class c = isa; - [self dealloc]; - @throw [OFOutOfRangeException newWithClass: c]; - } - - @try { - b = [self allocMemoryWithSize: sizeof(BUCKET)]; - key = [key copy]; - } @catch (OFException *e) { - [self dealloc]; - @throw e; - } - - @try { - [obj retain]; - } @catch (OFException *e) { - [(id)key release]; - [self dealloc]; - @throw e; - } - - b->key = key; - b->object = obj; - b->hash = hash; - data[j] = b; - - continue; - } - - /* - * They key is already in the dictionary. However, we just - * replace it so that the programmer gets the same behavior - * as if he'd call setObject:forKey: for each key/object pair. - */ - @try { - [obj retain]; - } @catch (OFException *e) { - [self dealloc]; - @throw e; - } - - @try { - [data[j]->object release]; - } @catch (OFException *e) { - [obj release]; - [self dealloc]; - @throw e; - } - - data[j]->object = obj; + self = [super init]; + + @try { + id obj; + size_t i, nsize; + uint32_t j, hash; + va_list args2; + BUCKET *b; + + va_copy(args2, args); + + if (key == nil) + @throw [OFInvalidArgumentException newWithClass: isa + selector: _cmd]; + + if ((obj = va_arg(args, id)) == nil) + @throw [OFInvalidArgumentException newWithClass: isa + selector: _cmd]; + + count = 1; + for (; va_arg(args2, id) != nil; count++); + count >>= 1; + + if (count > UINT32_MAX) + @throw [OFOutOfRangeException newWithClass: isa]; + + for (nsize = 1; nsize < count; nsize <<= 1); + + if (nsize == 0) + @throw [OFOutOfRangeException newWithClass: isa]; + + data = [self allocMemoryForNItems: nsize + withSize: sizeof(BUCKET*)]; + + for (j = 0; j < nsize; j++) + data[j] = NULL; + + size = nsize; + + /* Add first key / object pair */ + hash = [(id)key hash]; + j = hash & (size - 1); + + b = [self allocMemoryWithSize: sizeof(BUCKET)]; + key = [key copy]; + + @try { + [obj retain]; + } @catch (id e) { + [(id)key release]; + @throw e; + } + + b->key = key; + b->object = obj; + b->hash = hash; + + data[j] = b; + + for (i = 1; i < count; i++) { + uint32_t last; + + key = va_arg(args, id ); + obj = va_arg(args, id); + + if (key == nil || obj == nil) + @throw [OFInvalidArgumentException + newWithClass: isa + selector: _cmd]; + + hash = [(id)key hash]; + last = size; + + for (j = hash & (size - 1); j < last && data[j] != NULL; + j++) + if ([(id)data[j]->key isEqual: key]) + break; + + /* In case the last bucket is already used */ + if (j >= last) { + last = hash & (size - 1); + + for (j = 0; j < last && data[j] != NULL; j++) + if ([(id)data[j]->key isEqual: key]) + break; + } + + /* Key not in dictionary */ + if (j >= last || data[j] == NULL || + ![(id)data[j]->key isEqual: key]) { + last = size; + + j = hash & (size - 1); + for (; j < last && data[j] != NULL; j++); + + /* In case the last bucket is already used */ + if (j >= last) { + last = hash & (size - 1); + + for (j = 0; j < last && data[j] != NULL; + j++); + } + + if (j >= last) + @throw [OFOutOfRangeException + newWithClass: isa]; + + b = [self allocMemoryWithSize: sizeof(BUCKET)]; + key = [key copy]; + + @try { + [obj retain]; + } @catch (id e) { + [(id)key release]; + @throw e; + } + + b->key = key; + b->object = obj; + b->hash = hash; + + data[j] = b; + + continue; + } + + /* + * The key is already in the dictionary. However, we + * just replace it so that the programmer gets the same + * behavior as if he'd call setObject:forKey: for each + * key/object pair. + */ + [obj retain]; + + @try { + [data[j]->object release]; + } @catch (id e) { + [obj release]; + @throw e; + } + + data[j]->object = obj; + } + } @catch (id e) { + [self release]; + @throw e; } return self; } Index: src/OFEnumerator.m ================================================================== --- src/OFEnumerator.m +++ src/OFEnumerator.m @@ -15,13 +15,16 @@ #import "OFExceptions.h" @implementation OFEnumerator - init { - if (isa == [OFEnumerator class]) - @throw [OFNotImplementedException newWithClass: isa + if (isa == [OFEnumerator class]) { + Class c = isa; + [self release]; + @throw [OFNotImplementedException newWithClass: c selector: _cmd]; + } return [super init]; } - (id)nextObject Index: src/OFExceptions.m ================================================================== --- src/OFExceptions.m +++ src/OFExceptions.m @@ -149,11 +149,13 @@ return [[self alloc] initWithClass: class_]; } - init { - @throw [OFNotImplementedException newWithClass: isa + Class c = isa; + [self release]; + @throw [OFNotImplementedException newWithClass: c selector: _cmd]; } - initWithClass: (Class)class_ { @@ -251,11 +253,13 @@ pointer: ptr]; } - initWithClass: (Class)class_ { - @throw [OFNotImplementedException newWithClass: isa + Class c = isa; + [self release]; + @throw [OFNotImplementedException newWithClass: c selector: _cmd]; } - initWithClass: (Class)class_ pointer: (void*)ptr @@ -295,11 +299,13 @@ selector: selector]; } - initWithClass: (Class)class_ { - @throw [OFNotImplementedException newWithClass: isa + Class c = isa; + [self release]; + @throw [OFNotImplementedException newWithClass: c selector: _cmd]; } - initWithClass: (Class)class_ selector: (SEL)selector_ @@ -350,11 +356,13 @@ selector: selector_]; } - initWithClass: (Class)class_ { - @throw [OFNotImplementedException newWithClass: isa + Class c = isa; + [self release]; + @throw [OFNotImplementedException newWithClass: c selector: _cmd]; } - initWithClass: (Class)class_ selector: (SEL)selector_ @@ -447,23 +455,30 @@ mode: mode]; } - initWithClass: (Class)class_ { - @throw [OFNotImplementedException newWithClass: isa + Class c = isa; + [self release]; + @throw [OFNotImplementedException newWithClass: c selector: _cmd]; } - initWithClass: (Class)class_ path: (OFString*)path_ mode: (OFString*)mode_ { self = [super initWithClass: class_]; - path = [path_ copy]; - mode = [mode_ copy]; - errNo = GET_ERRNO; + @try { + path = [path_ copy]; + mode = [mode_ copy]; + errNo = GET_ERRNO; + } @catch (id e) { + [self release]; + @throw e; + } return self; } - (void)dealloc @@ -510,11 +525,13 @@ size: size]; } - initWithClass: (Class)class_ { - @throw [OFNotImplementedException newWithClass: isa + Class c = isa; + [self release]; + @throw [OFNotImplementedException newWithClass: c selector: _cmd]; } - initWithClass: (Class)class_ size: (size_t)size @@ -606,21 +623,28 @@ path: path_]; } - initWithClass: (Class)class_ { - @throw [OFNotImplementedException newWithClass: isa + Class c = isa; + [self release]; + @throw [OFNotImplementedException newWithClass: c selector: _cmd]; } - initWithClass: (Class)class_ path: (OFString*)path_ { self = [super initWithClass: class_]; - path = [path_ copy]; - errNo = GET_ERRNO; + @try { + path = [path_ copy]; + errNo = GET_ERRNO; + } @catch (id e) { + [self release]; + @throw e; + } return self; } - (void)dealloc @@ -664,23 +688,30 @@ mode: mode]; } - initWithClass: (Class)class_ { - @throw [OFNotImplementedException newWithClass: isa + Class c = isa; + [self release]; + @throw [OFNotImplementedException newWithClass: c selector: _cmd]; } - initWithClass: (Class)class_ path: (OFString*)path_ mode: (mode_t)mode_ { self = [super initWithClass: class_]; - path = [path_ copy]; - mode = mode_; - errNo = GET_ERRNO; + @try { + path = [path_ copy]; + mode = mode_; + errNo = GET_ERRNO; + } @catch (id e) { + [self release]; + @throw e; + } return self; } - (void)dealloc @@ -731,11 +762,13 @@ group: group]; } - initWithClass: (Class)class_ { - @throw [OFNotImplementedException newWithClass: isa + Class c = isa; + [self release]; + @throw [OFNotImplementedException newWithClass: c selector: _cmd]; } - initWithClass: (Class)class_ path: (OFString*)path_ @@ -742,14 +775,19 @@ owner: (uid_t)owner_ group: (gid_t)group_ { self = [super initWithClass: class_]; - path = [path_ copy]; - owner = owner_; - group = group_; - errNo = GET_ERRNO; + @try { + path = [path_ copy]; + owner = owner_; + group = group_; + errNo = GET_ERRNO; + } @catch (id e) { + [self release]; + @throw e; + } return self; } - (void)dealloc @@ -803,23 +841,30 @@ destinationPath: dst]; } - initWithClass: (Class)class_ { - @throw [OFNotImplementedException newWithClass: isa + Class c = isa; + [self release]; + @throw [OFNotImplementedException newWithClass: c selector: _cmd]; } - initWithClass: (Class)class_ sourcePath: (OFString*)src destinationPath: (OFString*)dst { self = [super initWithClass: class_]; - sourcePath = [src copy]; - destinationPath = [dst copy]; - errNo = GET_ERRNO; + @try { + sourcePath = [src copy]; + destinationPath = [dst copy]; + errNo = GET_ERRNO; + } @catch (id e) { + [self release]; + @throw e; + } return self; } - (void)dealloc @@ -869,23 +914,30 @@ destinationPath: dst]; } - initWithClass: (Class)class_ { - @throw [OFNotImplementedException newWithClass: isa + Class c = isa; + [self release]; + @throw [OFNotImplementedException newWithClass: c selector: _cmd]; } - initWithClass: (Class)class_ sourcePath: (OFString*)src destinationPath: (OFString*)dst { self = [super initWithClass: class_]; - sourcePath = [src copy]; - destinationPath = [dst copy]; - errNo = GET_ERRNO; + @try { + sourcePath = [src copy]; + destinationPath = [dst copy]; + errNo = GET_ERRNO; + } @catch (id e) { + [self release]; + @throw e; + } return self; } - (void)dealloc @@ -933,21 +985,28 @@ path: path_]; } - initWithClass: (Class)class_ { - @throw [OFNotImplementedException newWithClass: isa + Class c = isa; + [self release]; + @throw [OFNotImplementedException newWithClass: c selector: _cmd]; } - initWithClass: (Class)class_ path: (OFString*)path_ { self = [super initWithClass: class_]; - path = [path_ copy]; - errNo = GET_ERRNO; + @try { + path = [path_ copy]; + errNo = GET_ERRNO; + } @catch (id e) { + [self release]; + @throw e; + } return self; } - (void)dealloc @@ -988,21 +1047,28 @@ path: path_]; } - initWithClass: (Class)class_ { - @throw [OFNotImplementedException newWithClass: isa + Class c = isa; + [self release]; + @throw [OFNotImplementedException newWithClass: c selector: _cmd]; } - initWithClass: (Class)class_ path: (OFString*)path_ { self = [super initWithClass: class_]; - path = [path_ copy]; - errNo = GET_ERRNO; + @try { + path = [path_ copy]; + errNo = GET_ERRNO; + } @catch (id e) { + [self release]; + @throw e; + } return self; } - (void)dealloc @@ -1046,11 +1112,13 @@ destinationPath: dest]; } - initWithClass: (Class)class_ { - @throw [OFNotImplementedException newWithClass: isa + Class c = isa; + [self release]; + @throw [OFNotImplementedException newWithClass: c selector: _cmd]; } - initWithClass: (Class)class_ sourcePath: (OFString*)src @@ -1112,11 +1180,13 @@ destinationPath: dest]; } - initWithClass: (Class)class_ { - @throw [OFNotImplementedException newWithClass: isa + Class c = isa; + [self release]; + @throw [OFNotImplementedException newWithClass: c selector: _cmd]; } - initWithClass: (Class)class_ sourcePath: (OFString*)src @@ -1233,13 +1303,18 @@ node: (OFString*)node_ service: (OFString*)service_ { self = [super initWithClass: class_]; - node = [node_ copy]; - service = [service_ copy]; - errNo = GET_AT_ERRNO; + @try { + node = [node_ copy]; + service = [service_ copy]; + errNo = GET_AT_ERRNO; + } @catch (id e) { + [self release]; + @throw e; + } return self; } - (void)dealloc @@ -1298,23 +1373,30 @@ service: service]; } - initWithClass: (Class)class_ { - @throw [OFNotImplementedException newWithClass: isa + Class c = isa; + [self release]; + @throw [OFNotImplementedException newWithClass: c selector: _cmd]; } - initWithClass: (Class)class_ node: (OFString*)node_ service: (OFString*)service_ { self = [super initWithClass: class_]; - node = [node_ copy]; - service = [service_ copy]; - errNo = GET_SOCK_ERRNO; + @try { + node = [node_ copy]; + service = [service_ copy]; + errNo = GET_SOCK_ERRNO; + } @catch (id e) { + [self release]; + @throw e; + } return self; } - (void)dealloc @@ -1366,11 +1448,13 @@ family: family]; } - initWithClass: (Class)class_ { - @throw [OFNotImplementedException newWithClass: isa + Class c = isa; + [self release]; + @throw [OFNotImplementedException newWithClass: c selector: _cmd]; } - initWithClass: (Class)class_ node: (OFString*)node_ @@ -1377,14 +1461,19 @@ service: (OFString*)service_ family: (int)family_ { self = [super initWithClass: class_]; - node = [node_ copy]; - service = [service_ copy]; - family = family_; - errNo = GET_SOCK_ERRNO; + @try { + node = [node_ copy]; + service = [service_ copy]; + family = family_; + errNo = GET_SOCK_ERRNO; + } @catch (id e) { + [self release]; + @throw e; + } return self; } - (void)dealloc @@ -1437,11 +1526,13 @@ backLog: backlog]; } - initWithClass: (Class)class_ { - @throw [OFNotImplementedException newWithClass: isa + Class c = isa; + [self release]; + @throw [OFNotImplementedException newWithClass: c selector: _cmd]; } - initWithClass: (Class)class_ backLog: (int)backlog @@ -1601,30 +1692,42 @@ prefix: prefix]; } - initWithClass: (Class)class_ { - @throw [OFNotImplementedException newWithClass: isa + Class c = isa; + [self release]; + @throw [OFNotImplementedException newWithClass: c selector: _cmd]; } - initWithClass: (Class)class_ namespace: (OFString*)ns_ { self = [super initWithClass: class_]; - ns = [ns_ copy]; + @try { + ns = [ns_ copy]; + } @catch (id e) { + [self release]; + @throw e; + } return self; } - initWithClass: (Class)class_ prefix: (OFString*)prefix_ { self = [super initWithClass: class_]; - prefix = [prefix_ copy]; + @try { + prefix = [prefix_ copy]; + } @catch (id e) { + [self release]; + @throw e; + } return self; } - (void)dealloc Index: src/OFFile.m ================================================================== --- src/OFFile.m +++ src/OFFile.m @@ -414,38 +414,38 @@ } #endif - init { - @throw [OFNotImplementedException newWithClass: isa + Class c = isa; + [self release]; + @throw [OFNotImplementedException newWithClass: c selector: _cmd]; } - initWithPath: (OFString*)path mode: (OFString*)mode { - Class c; - int flags; - self = [super init]; - if ((flags = parse_mode([mode cString])) == -1) { - c = isa; - [super dealloc]; - @throw [OFInvalidArgumentException newWithClass: c - selector: _cmd]; - } - - if ((fd = open([path cString], flags, DEFAULT_MODE)) == -1) { - c = isa; - [super dealloc]; - @throw [OFOpenFileFailedException newWithClass: c - path: path - mode: mode]; - } - - closable = YES; + @try { + int flags; + + if ((flags = parse_mode([mode cString])) == -1) + @throw [OFInvalidArgumentException newWithClass: isa + selector: _cmd]; + + if ((fd = open([path cString], flags, DEFAULT_MODE)) == -1) + @throw [OFOpenFileFailedException newWithClass: isa + path: path + mode: mode]; + + closable = YES; + } @catch (id e) { + [self release]; + @throw e; + } return self; } - initWithFileDescriptor: (int)fd_ @@ -541,11 +541,13 @@ /// \cond internal @implementation OFFileSingleton - initWithPath: (OFString*)path mode: (OFString*)mode { - @throw [OFNotImplementedException newWithClass: isa + Class c = isa; + [self release]; + @throw [OFNotImplementedException newWithClass: c selector: _cmd]; } - autorelease { Index: src/OFList.m ================================================================== --- src/OFList.m +++ src/OFList.m @@ -224,11 +224,11 @@ [o->object retain]; prev = o; } - } @catch (OFException *e) { + } @catch (id e) { [new release]; @throw e; } new->lastListObject = o; Index: src/OFMutableDictionary.m ================================================================== --- src/OFMutableDictionary.m +++ src/OFMutableDictionary.m @@ -139,17 +139,18 @@ b = [self allocMemoryWithSize: sizeof(BUCKET)]; @try { key = [key copy]; - } @catch (OFException *e) { + } @catch (id e) { [self freeMemory: b]; + @throw e; } @try { [obj retain]; - } @catch (OFException *e) { + } @catch (id e) { [self freeMemory: b]; [(id)key release]; @throw e; } Index: src/OFMutableString.m ================================================================== --- src/OFMutableString.m +++ src/OFMutableString.m @@ -94,11 +94,11 @@ i += clen; } @try { nstr = [self allocMemoryWithSize: nlen + 1]; - } @catch (OFException *e) { + } @catch (id e) { [self freeMemory: ustr]; @throw e; } j = 0; @@ -470,11 +470,11 @@ @try { tmp = [self resizeMemory: tmp toSize: tmp_len + i - last + repl_len + 1]; - } @catch (OFException *e) { + } @catch (id e) { [self freeMemory: tmp]; @throw e; } memcpy(tmp + tmp_len, string + last, i - last); memcpy(tmp + tmp_len + i - last, repl_c, repl_len); @@ -484,11 +484,11 @@ } @try { tmp = [self resizeMemory: tmp toSize: tmp_len + length - last + 1]; - } @catch (OFException *e) { + } @catch (id e) { [self freeMemory: tmp]; @throw e; } memcpy(tmp + tmp_len, string + last, length - last); tmp_len += length - last; Index: src/OFPlugin.m ================================================================== --- src/OFPlugin.m +++ src/OFPlugin.m @@ -57,13 +57,16 @@ return plugin; } - init { - if (isa == [OFPlugin class]) - @throw [OFNotImplementedException newWithClass: isa + if (isa == [OFPlugin class]) { + Class c = isa; + [self release]; + @throw [OFNotImplementedException newWithClass: c selector: _cmd]; + } return [super init]; } - (void)dealloc Index: src/OFStream.m ================================================================== --- src/OFStream.m +++ src/OFStream.m @@ -28,15 +28,18 @@ #import "asprintf.h" @implementation OFStream - init { - self = [super init]; - - if (isa == [OFStream class]) - @throw [OFNotImplementedException newWithClass: isa + if (isa == [OFStream class]) { + Class c = isa; + [self release]; + @throw [OFNotImplementedException newWithClass: c selector: _cmd]; + } + + self = [super init]; cache = NULL; wBuffer = NULL; return self; @@ -314,11 +317,11 @@ @try { ret = [OFString stringWithCString: ret_c encoding: encoding length: ret_len]; - } @catch (OFException *e) { + } @catch (id e) { /* * Append data to cache to * prevent loss of data due to * wrong encoding. */ Index: src/OFStreamObserver.m ================================================================== --- src/OFStreamObserver.m +++ src/OFStreamObserver.m @@ -45,12 +45,12 @@ fdToStream = [[OFMutableDictionary alloc] init]; #else FD_ZERO(&readfds); FD_ZERO(&writefds); #endif - } @catch (OFException *e) { - [self dealloc]; + } @catch (id e) { + [self release]; @throw e; } return self; } Index: src/OFString.h ================================================================== --- src/OFString.h +++ src/OFString.h @@ -133,17 +133,10 @@ * \return A new autoreleased OFString */ + stringWithContentsOfFile: (OFString*)path encoding: (enum of_string_encoding)encoding; -/** - * Initializes an already allocated OFString. - * - * \return An initialized OFString - */ -- init; - /** * Initializes an already allocated OFString from a UTF-8 encoded C string. * * \param str A UTF-8 encoded C string to initialize the OFString with * \return An initialized OFString Index: src/OFString.m ================================================================== --- src/OFString.m +++ src/OFString.m @@ -300,19 +300,10 @@ { return [[[self alloc] initWithContentsOfFile: path encoding: encoding] autorelease]; } -- init -{ - [super init]; - - string = NULL; - - return self; -} - - initWithCString: (const char*)str { return [self initWithCString: str encoding: OF_STRING_ENCODING_UTF_8 length: strlen(str)]; @@ -328,145 +319,112 @@ - initWithCString: (const char*)str encoding: (enum of_string_encoding)encoding length: (size_t)len { - size_t i, j; - - self = [super init]; - - length = len; - - @try { - string = [self allocMemoryWithSize: length + 1]; - } @catch (OFException *e) { - /* - * We can't use [super dealloc] on OS X here. - * Compiler bug? Anyway, [self dealloc] will do here as we - * don't reimplement dealloc. - */ - [self dealloc]; - @throw e; - } - - switch (encoding) { - case OF_STRING_ENCODING_UTF_8: - switch (of_string_check_utf8(str, length)) { - case 1: - isUTF8 = YES; - break; - case -1:; - /* - * We can't use [super dealloc] on OS X here. - * Compiler bug? Anyway, [self dealloc] will do here as - * we don't reimplement dealloc. - */ - Class c = isa; - [self dealloc]; - @throw [OFInvalidEncodingException newWithClass: c]; - } - - memcpy(string, str, length); - string[length] = 0; - - break; - case OF_STRING_ENCODING_ISO_8859_1: - case OF_STRING_ENCODING_ISO_8859_15: - case OF_STRING_ENCODING_WINDOWS_1252: - for (i = j = 0; i < len; i++) { - if (!(str[i] & 0x80)) - string[j++] = str[i]; - else { - char buf[4]; - of_unichar_t chr; - size_t chr_bytes; - - switch (encoding) { - case OF_STRING_ENCODING_ISO_8859_1: - chr = (uint8_t)str[i]; - break; - case OF_STRING_ENCODING_ISO_8859_15: - chr = of_iso_8859_15[(uint8_t)str[i]]; - break; - case OF_STRING_ENCODING_WINDOWS_1252: - chr = of_windows_1252[(uint8_t)str[i]]; - break; - default:; - /* - * We can't use [super dealloc] on OS X - * here. Compiler bug? Anyway, - * [self dealloc] will do here as we - * don't reimplement dealloc. - */ - Class c = isa; - [self dealloc]; - @throw [OFInvalidEncodingException - newWithClass: c]; - } - - if (chr == 0xFFFD) { - /* - * We can't use [super dealloc] on OS X - * here. Compiler bug? Anyway, - * [self dealloc] will do here as we - * don't reimplement dealloc. - */ - Class c = isa; - [self dealloc]; - @throw [OFInvalidEncodingException - newWithClass: c]; - } - - isUTF8 = YES; - chr_bytes = of_string_unicode_to_utf8(chr, buf); - - if (chr_bytes == 0) { - /* - * We can't use [super dealloc] on OS X - * here. Compiler bug? Anyway, - * [self dealloc] will do here as we - * don't reimplement dealloc. - */ - Class c = isa; - [self dealloc]; - @throw [OFInvalidEncodingException - newWithClass: c]; - } - - length += chr_bytes - 1; - @try { - string = [self resizeMemory: string - toSize: length + - 1]; - } @catch (OFException *e) { - /* - * We can't use [super dealloc] on OS X - * here. Compiler bug? Anyway, - * [self dealloc] will do here as we - * don't reimplement dealloc. - */ - [self dealloc]; - @throw e; - } - - memcpy(string + j, buf, chr_bytes); - j += chr_bytes; - } - } - - string[length] = 0; - - break; - default:; - /* - * We can't use [super dealloc] on OS X here. - * Compiler bug? Anyway, [self dealloc] will do here as we - * don't reimplement dealloc. - */ - Class c = isa; - [self dealloc]; - @throw [OFInvalidEncodingException newWithClass: c]; + self = [super init]; + + @try { + size_t i, j; + const uint16_t *table; + + string = [self allocMemoryWithSize: len + 1]; + length = len; + + if (encoding == OF_STRING_ENCODING_UTF_8) { + switch (of_string_check_utf8(str, length)) { + case 1: + isUTF8 = YES; + break; + case -1: + @throw [OFInvalidEncodingException + newWithClass: isa]; + } + + memcpy(string, str, length); + string[length] = 0; + + return self; + } + + if (encoding == OF_STRING_ENCODING_ISO_8859_1) { + for (i = j = 0; i < len; i++) { + char buf[4]; + size_t bytes; + + if (!(str[i] & 0x80)) { + string[j++] = str[i]; + continue; + } + + isUTF8 = YES; + bytes = of_string_unicode_to_utf8( + (uint8_t)str[i], buf); + + if (bytes == 0) + @throw [OFInvalidEncodingException + newWithClass: isa]; + + length += bytes - 1; + string = [self resizeMemory: string + toSize: length + 1]; + + memcpy(string + j, buf, bytes); + j += bytes; + } + + string[length] = 0; + + return self; + } + + switch (encoding) { + case OF_STRING_ENCODING_ISO_8859_15: + table = of_iso_8859_15; + break; + case OF_STRING_ENCODING_WINDOWS_1252: + table = of_windows_1252; + break; + default: + @throw [OFInvalidEncodingException newWithClass: isa]; + } + + for (i = j = 0; i < len; i++) { + char buf[4]; + of_unichar_t chr; + size_t chr_bytes; + + if (!(str[i] & 0x80)) { + string[j++] = str[i]; + continue; + } + + chr = table[(uint8_t)str[i]]; + + if (chr == 0xFFFD) + @throw [OFInvalidEncodingException + newWithClass: isa]; + + isUTF8 = YES; + chr_bytes = of_string_unicode_to_utf8(chr, buf); + + if (chr_bytes == 0) + @throw [OFInvalidEncodingException + newWithClass: isa]; + + length += chr_bytes - 1; + string = [self resizeMemory: string + toSize: length + 1]; + + memcpy(string + j, buf, chr_bytes); + j += chr_bytes; + } + + string[length] = 0; + } @catch (id e) { + [self release]; + @throw e; } return self; } @@ -492,48 +450,45 @@ } - initWithFormat: (OFString*)fmt arguments: (va_list)args { - int t; - self = [super init]; - if (fmt == nil) { - Class c = isa; - [super dealloc]; - @throw [OFInvalidArgumentException newWithClass: c - selector: _cmd]; - } - - if ((t = vasprintf(&string, [fmt cString], args)) == -1) { - Class c = isa; - [super dealloc]; - - /* - * This is only the most likely error to happen. Unfortunately, - * there is no good way to check what really happened. - */ - @throw [OFOutOfMemoryException newWithClass: c]; - } - length = t; - - switch (of_string_check_utf8(string, length)) { - case 1: - isUTF8 = YES; - break; - case -1:; - Class c = isa; - free(string); - [super dealloc]; - @throw [OFInvalidEncodingException newWithClass: c]; - } - @try { - [self addMemoryToPool: string]; - } @catch (OFException *e) { - free(string); + int t; + + if (fmt == nil) + @throw [OFInvalidArgumentException newWithClass: isa + selector: _cmd]; + + if ((t = vasprintf(&string, [fmt cString], args)) == -1) + /* + * This is only the most likely error to happen. + * Unfortunately, there is no good way to check what + * really happened. + */ + @throw [OFOutOfMemoryException newWithClass: isa]; + + @try { + length = t; + + switch (of_string_check_utf8(string, length)) { + case 1: + isUTF8 = YES; + break; + case -1: + @throw [OFInvalidEncodingException + newWithClass: isa]; + } + + [self addMemoryToPool: string]; + } @catch (id e) { + free(string); + } + } @catch (id e) { + [self release]; @throw e; } return self; } @@ -552,102 +507,96 @@ } - initWithPath: (OFString*)first arguments: (va_list)args { - OFString *component; - size_t len, i; - va_list args2; - Class c; - - self = [super init]; - - len = [first cStringLength]; - switch (of_string_check_utf8([first cString], len)) { - case 1: - isUTF8 = YES; - break; - case -1: - c = isa; - [self dealloc]; - @throw [OFInvalidEncodingException newWithClass: c]; - } - length += len; - - va_copy(args2, args); - while ((component = va_arg(args2, OFString*)) != nil) { - len = [component cStringLength]; - length += 1 + len; - - switch (of_string_check_utf8([component cString], len)) { - case 1: - isUTF8 = YES; - break; - case -1: - c = isa; - [self dealloc]; - @throw [OFInvalidEncodingException newWithClass: c]; - } - } - - @try { - string = [self allocMemoryWithSize: length + 1]; - } @catch (OFException *e) { - [self dealloc]; - @throw e; - } - - len = [first cStringLength]; - memcpy(string, [first cString], len); - i = len; - - while ((component = va_arg(args, OFString*)) != nil) { - len = [component cStringLength]; - string[i] = OF_PATH_DELIM; - memcpy(string + i + 1, [component cString], len); - i += len + 1; - } - - string[i] = '\0'; + self = [super init]; + + @try { + OFString *component; + size_t len, i; + va_list args2; + + length = [first cStringLength]; + + switch (of_string_check_utf8([first cString], length)) { + case 1: + isUTF8 = YES; + break; + case -1: + @throw [OFInvalidEncodingException newWithClass: isa]; + } + + /* Calculate length */ + va_copy(args2, args); + while ((component = va_arg(args2, OFString*)) != nil) { + len = [component cStringLength]; + length += 1 + len; + + switch (of_string_check_utf8([component cString], + len)) { + case 1: + isUTF8 = YES; + break; + case -1: + @throw [OFInvalidEncodingException + newWithClass: isa]; + } + } + + string = [self allocMemoryWithSize: length + 1]; + + len = [first cStringLength]; + memcpy(string, [first cString], len); + i = len; + + while ((component = va_arg(args, OFString*)) != nil) { + len = [component cStringLength]; + string[i] = OF_PATH_DELIM; + memcpy(string + i + 1, [component cString], len); + i += len + 1; + } + + string[i] = '\0'; + } @catch (id e) { + [self release]; + @throw e; + } return self; } - initWithString: (OFString*)str { self = [super init]; - string = (char*)[str cString]; - length = [str cStringLength]; - - switch (of_string_check_utf8(string, length)) { - case 1: - isUTF8 = YES; - break; - case -1:; - Class c = isa; - [self dealloc]; - @throw [OFInvalidEncodingException newWithClass: c]; - } - - if ((string = strdup(string)) == NULL) { - Class c = isa; - [self dealloc]; - @throw [OFOutOfMemoryException newWithClass: c - size: length + 1]; - } - @try { - [self addMemoryToPool: string]; - } @catch (OFException *e) { - /* - * We can't use [super dealloc] on OS X here. - * Compiler bug? Anyway, [self dealloc] will do here as we - * don't reimplement dealloc. - */ - free(string); - [self dealloc]; + /* We have no -[dealloc], so this is ok */ + string = (char*)[str cString]; + length = [str cStringLength]; + + switch (of_string_check_utf8(string, length)) { + case 1: + isUTF8 = YES; + break; + case -1:; + @throw [OFInvalidEncodingException newWithClass: isa]; + } + + if ((string = strdup(string)) == NULL) + @throw [OFOutOfMemoryException newWithClass: isa + size: length + + 1]; + + @try { + [self addMemoryToPool: string]; + } @catch (id e) { + free(string); + @throw e; + } + } @catch (id e) { + [self release]; @throw e; } return self; } @@ -659,46 +608,38 @@ } - initWithContentsOfFile: (OFString*)path encoding: (enum of_string_encoding)encoding { - OFFile *file = nil; - char *tmp; - struct stat s; - - if (stat([path cString], &s) == -1) { - Class c = isa; - [super dealloc]; - @throw [OFInitializationFailedException newWithClass: c]; - } - - if ((tmp = malloc(s.st_size)) == NULL) { - Class c = isa; - [super dealloc]; - @throw [OFOutOfMemoryException newWithClass: c - size: s.st_size]; - } + self = [super init]; @try { - file = [[OFFile alloc] initWithPath: path - mode: @"rb"]; + OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; + OFFile *file; + char *tmp; + struct stat s; + + if (stat([path cString], &s) == -1) + @throw [OFInitializationFailedException + newWithClass: isa]; + + tmp = [self allocMemoryWithSize: s.st_size]; + file = [OFFile fileWithPath: path + mode: @"rb"]; [file readExactlyNBytes: s.st_size intoBuffer: tmp]; - } @catch (OFException *e) { - free(tmp); - [super dealloc]; - @throw e; - } @finally { - [file release]; - } - - @try { + self = [self initWithCString: tmp encoding: encoding length: s.st_size]; - } @finally { - free(tmp); + + [self freeMemory: tmp]; + + [pool release]; + } @catch (id e) { + [self release]; + @throw e; } return self; } Index: src/OFTCPSocket.m ================================================================== --- src/OFTCPSocket.m +++ src/OFTCPSocket.m @@ -156,11 +156,11 @@ for (ip = he->h_addr_list; *ip != NULL; ip++) [addrlist addItem: ip]; /* Add the terminating NULL */ [addrlist addItem: ip]; - } @catch (OFException *e) { + } @catch (id e) { [addrlist release]; @throw e; } @finally { [mutex unlock]; } @@ -344,11 +344,11 @@ newsock = [OFTCPSocket socket]; addrlen = sizeof(struct sockaddr); @try { addr = [newsock allocMemoryWithSize: sizeof(struct sockaddr)]; - } @catch (OFException *e) { + } @catch (id e) { [newsock dealloc]; @throw e; } if ((s = accept(sock, addr, &addrlen)) == INVALID_SOCKET) { Index: src/OFThread.m ================================================================== --- src/OFThread.m +++ src/OFThread.m @@ -133,19 +133,26 @@ of_thread_exit(); } - init { - @throw [OFNotImplementedException newWithClass: isa + Class c = isa; + [self release]; + @throw [OFNotImplementedException newWithClass: c selector: _cmd]; } - initWithObject: (id)obj { self = [super init]; - object = [obj retain]; + @try { + object = [obj retain]; + } @catch (id e) { + [self release]; + @throw e; + } return self; } - (id)main @@ -227,31 +234,23 @@ - init { self = [super init]; - if (!of_tlskey_new(&key)) { - Class c = isa; - [super dealloc]; - @throw [OFInitializationFailedException newWithClass: c]; - } - - destructor = NULL; - - @synchronized (tlskeys) { - @try { + @try { + if (!of_tlskey_new(&key)) + @throw [OFInitializationFailedException + newWithClass: isa]; + + destructor = NULL; + + @synchronized (tlskeys) { listobj = [tlskeys appendObject: self]; - } @catch (OFException *e) { - /* - * We can't use [super dealloc] on OS X here. - * Compiler bug? Anyway, [self dealloc] will do here - * as we check listobj != NULL in dealloc. - */ - listobj = NULL; - [self dealloc]; - @throw e; - } + } + } @catch (id e) { + [self release]; + @throw e; } return self; } @@ -269,14 +268,15 @@ if (destructor != NULL) destructor(self); of_tlskey_free(key); - @synchronized (tlskeys) { - /* In case we called [self dealloc] in init */ - if (listobj != NULL) + /* In case we called [self release] in init */ + if (listobj != NULL) { + @synchronized (tlskeys) { [tlskeys removeListObject: listobj]; + } } [super dealloc]; } @end @@ -291,11 +291,11 @@ { self = [super init]; if (!of_mutex_new(&mutex)) { Class c = isa; - [self dealloc]; + [self release]; @throw [OFInitializationFailedException newWithClass: c]; } return self; } Index: src/OFXMLAttribute.m ================================================================== --- src/OFXMLAttribute.m +++ src/OFXMLAttribute.m @@ -29,13 +29,18 @@ namespace: (OFString*)ns_ stringValue: (OFString*)value { self = [super init]; - name = [name_ copy]; - ns = [ns_ copy]; - stringValue = [value copy]; + @try { + name = [name_ copy]; + ns = [ns_ copy]; + stringValue = [value copy]; + } @catch (id e) { + [self release]; + @throw e; + } return self; } - (void)dealloc Index: src/OFXMLElement.m ================================================================== --- src/OFXMLElement.m +++ src/OFXMLElement.m @@ -66,11 +66,13 @@ return [[[self alloc] initWithComment: comment] autorelease]; } - init { - @throw [OFNotImplementedException newWithClass: isa + Class c = isa; + [self release]; + @throw [OFNotImplementedException newWithClass: c selector: _cmd]; } - initWithName: (OFString*)name_ { @@ -99,50 +101,73 @@ namespace: (OFString*)ns_ stringValue: (OFString*)stringval { self = [super init]; - name = [name_ copy]; - ns = [ns_ copy]; - - if (stringval != nil) { - OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];; - [self addChild: - [OFXMLElement elementWithCharacters: stringval]]; - [pool release]; - } - - namespaces = [[OFMutableDictionary alloc] initWithKeysAndObjects: - @"http://www.w3.org/XML/1998/namespace", @"xml", - @"http://www.w3.org/2000/xmlns/", @"xmlns", nil]; + @try { + name = [name_ copy]; + ns = [ns_ copy]; + + if (stringval != nil) { + OFAutoreleasePool *pool; + + pool = [[OFAutoreleasePool alloc] init];; + [self addChild: + [OFXMLElement elementWithCharacters: stringval]]; + [pool release]; + } + + namespaces = [[OFMutableDictionary alloc] + initWithKeysAndObjects: + @"http://www.w3.org/XML/1998/namespace", @"xml", + @"http://www.w3.org/2000/xmlns/", @"xmlns", nil]; + } @catch (id e) { + [self release]; + @throw e; + } return self; } - initWithCharacters: (OFString*)chars { self = [super init]; - characters = [chars copy]; + @try { + characters = [chars copy]; + } @catch (id e) { + [self release]; + @throw e; + } return self; } - initWithCDATA: (OFString*)cdata_ { self = [super init]; - cdata = [cdata_ copy]; + @try { + cdata = [cdata_ copy]; + } @catch (id e) { + [self release]; + @throw e; + } return self; } - initWithComment: (OFString*)comment_ { self = [super init]; - comment = [comment_ copy]; + @try { + comment = [comment_ copy]; + } @catch (id e) { + [self release]; + @throw e; + } return self; } - (OFString*)name @@ -227,11 +252,11 @@ namespace: ns]; len += [prefix cStringLength] + 1; @try { str_c = [self resizeMemory: str_c toSize: len]; - } @catch (OFException *e) { + } @catch (id e) { [self freeMemory: str_c]; @throw e; } memcpy(str_c + i, [prefix cString], @@ -265,11 +290,11 @@ [tmp cStringLength] + 4; @try { str_c = [self resizeMemory: str_c toSize: len]; - } @catch (OFException *e) { + } @catch (id e) { [self freeMemory: str_c]; @throw e; } str_c[i++] = ' '; @@ -310,11 +335,11 @@ len += [tmp cStringLength] + [name cStringLength] + 2; @try { str_c = [self resizeMemory: str_c toSize: len]; - } @catch (OFException *e) { + } @catch (id e) { [self freeMemory: str_c]; @throw e; } str_c[i++] = '>'; @@ -325,11 +350,11 @@ if (prefix != nil) { len += [prefix cStringLength] + 1; @try { str_c = [self resizeMemory: str_c toSize: len]; - } @catch (OFException *e) { + } @catch (id e) { [self freeMemory: str_c]; @throw e; } memcpy(str_c + i, [prefix cString], Index: src/OFXMLElementBuilder.m ================================================================== --- src/OFXMLElementBuilder.m +++ src/OFXMLElementBuilder.m @@ -25,11 +25,16 @@ - init { self = [super init]; - stack = [[OFMutableArray alloc] init]; + @try { + stack = [[OFMutableArray alloc] init]; + } @catch (id e) { + [self release]; + @throw e; + } return self; } - (void)dealloc Index: src/OFXMLParser.m ================================================================== --- src/OFXMLParser.m +++ src/OFXMLParser.m @@ -142,12 +142,12 @@ dict = [OFMutableDictionary dictionaryWithKeysAndObjects: @"xml", @"http://www.w3.org/XML/1998/namespace", @"xmlns", @"http://www.w3.org/2000/xmlns/", nil]; [namespaces addObject: dict]; [pool release]; - } @catch (OFException *e) { - [self dealloc]; + } @catch (id e) { + [self release]; @throw e; } return self; }