Index: src/OFArray.m ================================================================== --- src/OFArray.m +++ src/OFArray.m @@ -167,11 +167,11 @@ return new; } - (id)objectAtIndex: (size_t)index { - return *((OFObject**)[array itemAtIndex: index]); + return [[*((OFObject**)[array itemAtIndex: index]) retain] autorelease]; } - (size_t)indexOfObject: (OFObject*)obj { id *objs = [array cArray]; @@ -204,18 +204,18 @@ - (id)firstObject { id *first = [array firstItem]; - return (first != NULL ? *first : nil); + return (first != NULL ? [[*first retain] autorelease] : nil); } - (id)lastObject { id *last = [array lastItem]; - return (last != NULL ? *last : nil); + return (last != NULL ? [[*last retain] autorelease] : nil); } - (OFString*)componentsJoinedByString: (OFString*)separator { OFString *str; @@ -222,27 +222,22 @@ OFString **objs = [array cArray]; size_t i, count = [array count]; IMP append; if (count == 0) - return [OFString string]; - - str = [[OFMutableString alloc] init]; - @try { - append = [str methodForSelector: @selector(appendString:)]; - - for (i = 0; i < count - 1; i++) { - append(str, @selector(appendString:), objs[i]); - append(str, @selector(appendString:), separator); - } - append(str, @selector(appendString:), objs[i]); - } @catch (OFException *e) { - [str release]; - @throw e; - } - - return [str autorelease]; + return @""; + + str = [OFMutableString string]; + append = [str methodForSelector: @selector(appendString:)]; + + for (i = 0; i < count - 1; i++) { + append(str, @selector(appendString:), objs[i]); + append(str, @selector(appendString:), separator); + } + append(str, @selector(appendString:), objs[i]); + + return str; } - (BOOL)isEqual: (OFObject*)obj { OFObject **objs, **objs2; Index: src/OFDictionary.m ================================================================== --- src/OFDictionary.m +++ src/OFDictionary.m @@ -473,11 +473,11 @@ /* Key not in dictionary */ if (i >= size || ![data[i].key isEqual: key]) return nil; - return data[i].object; + return [[data[i].object retain] autorelease]; } - (size_t)count { return count; Index: src/OFMutableArray.m ================================================================== --- src/OFMutableArray.m +++ src/OFMutableArray.m @@ -8,10 +8,12 @@ * Q Public License 1.0, which can be found in the file LICENSE included in * the packaging of this file. */ #include "config.h" + +#include #import "OFMutableArray.h" #import "OFExceptions.h" @implementation OFMutableArray @@ -105,12 +107,13 @@ OFObject **objs = [array cArray]; size_t i, count = [array count]; for (i = 0; i < count; i++) { if ([objs[i] isEqual: obj]) { - [objs[i] release]; + OFObject *obj = objs[i]; [array removeItemAtIndex: i]; + [obj release]; } } return self; } @@ -120,12 +123,12 @@ OFObject **objs = [array cArray]; size_t i, count = [array count]; for (i = 0; i < count; i++) { if (objs[i] == obj) { - [obj release]; [array removeItemAtIndex: i]; + [obj release]; } } return self; } @@ -136,37 +139,53 @@ atIndex: index]; } - removeNObjects: (size_t)nobjects { - OFObject **objs = [array cArray]; + OFObject **objs = [array cArray], **copy; size_t i, count = [array count]; if (nobjects > count) @throw [OFOutOfRangeException newWithClass: isa]; - for (i = count - nobjects; i < count; i++) - [objs[i] release]; + copy = [self allocMemoryForNItems: nobjects + withSize: sizeof(OFObject*)]; + memcpy(copy, objs + (count - nobjects), nobjects * sizeof(OFObject*)); + + @try { + [array removeNItems: nobjects]; - [array removeNItems: nobjects]; + for (i = 0; i < nobjects; i++) + [copy[i] release]; + } @finally { + [self freeMemory: copy]; + } return self; } - removeNObjects: (size_t)nobjects atIndex: (size_t)index { - OFObject **objs = [array cArray]; + OFObject **objs = [array cArray], **copy; size_t i, count = [array count]; - if (nobjects > count) + if (nobjects > count - index) @throw [OFOutOfRangeException newWithClass: isa]; - for (i = index; i < count && i < index + nobjects; i++) - [objs[i] release]; + copy = [self allocMemoryForNItems: nobjects + withSize: sizeof(OFObject*)]; + memcpy(copy, objs + index, nobjects * sizeof(OFObject*)); + + @try { + [array removeNItems: nobjects + atIndex: index]; - [array removeNItems: nobjects - atIndex: index]; + for (i = 0; i < nobjects; i++) + [copy[i] release]; + } @finally { + [self freeMemory: copy]; + } return self; } @end Index: src/OFObject.m ================================================================== --- src/OFObject.m +++ src/OFObject.m @@ -554,7 +554,9 @@ { } + (void)dealloc { + @throw [OFNotImplementedException newWithClass: self + selector: _cmd]; } @end Index: src/OFStream.m ================================================================== --- src/OFStream.m +++ src/OFStream.m @@ -11,10 +11,11 @@ #include "config.h" #include #include +#include #import "OFStream.h" #import "OFExceptions.h" #import "OFMacros.h" @@ -135,103 +136,90 @@ } /* Read until we get a newline or \0 */ tmp = [self allocMemoryWithSize: pagesize]; - for (;;) { - if ([self atEndOfStreamWithoutCache]) { - [self freeMemory: tmp]; - - if (cache == NULL) - return nil; - - ret = [OFString stringWithCString: cache - encoding: encoding - length: cache_len]; - - [self freeMemory: cache]; - cache = NULL; - cache_len = 0; - - return ret; - } - - @try { + @try { + for (;;) { + if ([self atEndOfStreamWithoutCache]) { + if (cache == NULL) + return nil; + + ret = [OFString stringWithCString: cache + encoding: encoding + length: cache_len]; + + [self freeMemory: cache]; + cache = NULL; + cache_len = 0; + + return ret; + } + len = [self readNBytesWithoutCache: pagesize intoBuffer: tmp]; - } @catch (OFException *e) { - [self freeMemory: tmp]; - @throw e; - } - - /* Look if there's a newline or \0 */ - for (i = 0; i < len; i++) { - if (OF_UNLIKELY(tmp[i] == '\n' || tmp[i] == '\0')) { - ret_len = cache_len + i; - @try { + + /* Look if there's a newline or \0 */ + for (i = 0; i < len; i++) { + if (OF_UNLIKELY(tmp[i] == '\n' || + tmp[i] == '\0')) { + ret_len = cache_len + i; ret_c = [self allocMemoryWithSize: ret_len]; - } @catch (OFException *e) { - [self freeMemory: tmp]; - @throw e; - } - if (cache != NULL) - memcpy(ret_c, cache, cache_len); - memcpy(ret_c + cache_len, tmp, i); - - if (i < len) { + + if (cache != NULL) + memcpy(ret_c, cache, cache_len); + memcpy(ret_c + cache_len, tmp, i); + @try { + ret = [OFString + stringWithCString: ret_c + encoding: encoding + length: ret_len]; + } @finally { + [self freeMemory: ret_c]; + } + + if (i < len) { tmp2 = [self allocMemoryWithSize: len - i - 1]; - } @catch (OFException *e) { - [self freeMemory: ret_c]; - [self freeMemory: tmp]; - @throw e; - } - memcpy(tmp2, tmp + i + 1, len - i - 1); - - [self freeMemory: cache]; - cache = tmp2; - cache_len = len - i - 1; - } else { - [self freeMemory: cache]; - cache = NULL; - cache_len = 0; - } - [self freeMemory: tmp]; - - @try { - ret = [OFString - stringWithCString: ret_c - encoding: encoding - length: ret_len]; - } @finally { - [self freeMemory: ret_c]; - } - return ret; - } - } - - /* There was no newline or \0 */ - @try { + memcpy(tmp2, tmp + i + 1, + len - i - 1); + + [self freeMemory: cache]; + cache = tmp2; + cache_len = len - i - 1; + } else { + [self freeMemory: cache]; + cache = NULL; + cache_len = 0; + } + + return ret; + } + } + + /* There was no newline or \0 */ cache = [self resizeMemory: cache toSize: cache_len + len]; - } @catch (OFException *e) { - [self freeMemory: tmp]; - @throw e; - } - - /* - * It's possible that cache_len + len is 0 and thus cache was - * set to NULL by resizeMemory:toSize:. - */ - if (cache != NULL) - memcpy(cache + cache_len, tmp, len); - - cache_len += len; - } + + /* + * It's possible that cache_len + len is 0 and thus + * cache was set to NULL by resizeMemory:toSize:. + */ + if (cache != NULL) + memcpy(cache + cache_len, tmp, len); + + cache_len += len; + } + } @finally { + [self freeMemory: tmp]; + } + + /* Get rid of a warning, never reached anyway */ + assert(0); } - (size_t)writeNBytes: (size_t)size fromBuffer: (const char*)buf {