Index: src/OFApplication.m ================================================================== --- src/OFApplication.m +++ src/OFApplication.m @@ -26,13 +26,14 @@ #import "OFApplication.h" #import "OFString.h" #import "OFArray.h" #import "OFDictionary.h" -#import "OFAutoreleasePool.h" #import "OFNotImplementedException.h" + +#import "autorelease.h" #if defined(__MACH__) && !defined(OF_IOS) # include #elif !defined(OF_IOS) extern char **environ; @@ -118,11 +119,11 @@ - init { self = [super init]; @try { - OFAutoreleasePool *pool; + void *pool; #if defined(__MACH__) && !defined(OF_IOS) char **env = *_NSGetEnviron(); #elif !defined(OF_IOS) char **env = environ; #else @@ -130,17 +131,17 @@ #endif environment = [[OFMutableDictionary alloc] init]; atexit(atexit_handler); - - pool = [[OFAutoreleasePool alloc] init]; #ifndef OF_IOS for (; *env != NULL; env++) { OFString *key; OFString *value; char *sep; + + pool = objc_autoreleasePoolPush(); if ((sep = strchr(*env, '=')) == NULL) { fprintf(stderr, "Warning: Invalid environment " "variable: %s\n", *env); continue; @@ -154,19 +155,21 @@ stringWithCString: sep + 1 encoding: OF_STRING_ENCODING_NATIVE]; [environment setObject: value forKey: key]; - [pool releaseObjects]; + objc_autoreleasePoolPop(pool); } #else /* * iOS does not provide environ and Apple does not allow using * _NSGetEnviron on iOS. Therefore, we just get a few common * variables from the environment which applications might * expect. */ + pool = objc_autoreleasePoolPush(); + if ((env = getenv("HOME")) != NULL) [environment setObject: [OFString stringWithUTF8String: env] forKey: @"HOME"]; if ((env = getenv("PATH")) != NULL) @@ -183,12 +186,13 @@ forKey: @"TMPDIR"]; if ((env = getenv("USER")) != NULL) [environment setObject: [OFString stringWithUTF8String: env] forKey: @"USER"]; + + objc_autoreleasePoolPop(pool); #endif - [pool release]; [environment makeImmutable]; } @catch (id e) { [self release]; @throw e; @@ -198,11 +202,11 @@ } - (void)setArgumentCount: (int*)argc_ andArgumentValues: (char***)argv_ { - OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; + void *pool = objc_autoreleasePoolPush(); int i; [programName release]; [arguments release]; @@ -219,11 +223,11 @@ [OFString stringWithCString: (*argv)[i] encoding: OF_STRING_ENCODING_NATIVE]]; [arguments makeImmutable]; - [pool release]; + objc_autoreleasePoolPop(pool); } - (void)getArgumentCount: (int**)argc_ andArgumentValues: (char****)argv_ { Index: src/OFArray.m ================================================================== --- src/OFArray.m +++ src/OFArray.m @@ -21,17 +21,17 @@ #import "OFArray.h" #import "OFArray_subarray.h" #import "OFArray_adjacent.h" #import "OFString.h" #import "OFXMLElement.h" -#import "OFAutoreleasePool.h" #import "OFEnumerationMutationException.h" #import "OFInvalidArgumentException.h" #import "OFNotImplementedException.h" #import "OFOutOfRangeException.h" +#import "autorelease.h" #import "macros.h" static struct { Class isa; } placeholder; @@ -358,11 +358,11 @@ } - (OFString*)componentsJoinedByString: (OFString*)separator usingSelector: (SEL)selector { - OFAutoreleasePool *pool, *pool2; + void *pool; OFMutableString *ret; id *objects; size_t i, count = [self count]; IMP append; @@ -372,28 +372,28 @@ return [[self firstObject] performSelector: selector]; ret = [OFMutableString string]; append = [ret methodForSelector: @selector(appendString:)]; - pool = [[OFAutoreleasePool alloc] init]; + pool = objc_autoreleasePoolPush(); objects = [self objects]; - pool2 = [[OFAutoreleasePool alloc] init]; - for (i = 0; i < count - 1; i++) { + void *pool2 = objc_autoreleasePoolPush(); + append(ret, @selector(appendString:), [objects[i] performSelector: selector]); append(ret, @selector(appendString:), separator); - [pool2 releaseObjects]; + objc_autoreleasePoolPop(pool2); } append(ret, @selector(appendString:), [objects[i] performSelector: selector]); [ret makeImmutable]; - [pool release]; + objc_autoreleasePoolPop(pool); return ret; } - (BOOL)isEqual: (id)object @@ -442,17 +442,17 @@ return hash; } - (OFString*)description { - OFAutoreleasePool *pool; + void *pool; OFMutableString *ret; if ([self count] == 0) return @"()"; - pool = [[OFAutoreleasePool alloc] init]; + pool = objc_autoreleasePoolPush(); ret = [[self componentsJoinedByString: @",\n"] mutableCopy]; @try { [ret prependString: @"(\n"]; [ret replaceOccurrencesOfString: @"\n" @@ -461,22 +461,20 @@ } @catch (id e) { [ret release]; @throw e; } - [pool release]; + objc_autoreleasePoolPop(pool); [ret makeImmutable]; - [ret autorelease]; - return ret; + return [ret autorelease]; } - (OFXMLElement*)XMLElementBySerializing { - OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; - OFAutoreleasePool *pool2; + void *pool = objc_autoreleasePoolPush(); OFXMLElement *element; id *objects = [self objects]; size_t i, count = [self count]; if ([self isKindOfClass: [OFMutableArray class]]) @@ -484,42 +482,42 @@ namespace: OF_SERIALIZATION_NS]; else element = [OFXMLElement elementWithName: @"OFArray" namespace: OF_SERIALIZATION_NS]; - pool2 = [[OFAutoreleasePool alloc] init]; - for (i = 0; i < count; i++) { + void *pool2 = objc_autoreleasePoolPush(); + [element addChild: [objects[i] XMLElementBySerializing]]; - [pool2 releaseObjects]; + objc_autoreleasePoolPop(pool2); } [element retain]; - [pool release]; - [element autorelease]; + + objc_autoreleasePoolPop(pool); - return element; + return [element autorelease]; } - (OFString*)JSONRepresentation { - OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; + void *pool = objc_autoreleasePoolPush(); OFMutableString *JSON; JSON = [[self componentsJoinedByString: @"," usingSelector: @selector(JSONRepresentation)] mutableCopy]; - [pool release]; - [JSON autorelease]; [JSON prependString: @"["]; [JSON appendString: @"]"]; [JSON makeImmutable]; - return JSON; + objc_autoreleasePoolPop(pool); + + return [JSON autorelease]; } - (void)makeObjectsPerformSelector: (SEL)selector { id *objects = [self objects]; Index: src/OFArray_adjacent.m ================================================================== --- src/OFArray_adjacent.m +++ src/OFArray_adjacent.m @@ -22,16 +22,16 @@ #import "OFMutableArray_adjacent.h" #import "OFArray_adjacentSubarray.h" #import "OFDataArray.h" #import "OFString.h" #import "OFXMLElement.h" -#import "OFAutoreleasePool.h" #import "OFEnumerationMutationException.h" #import "OFInvalidArgumentException.h" #import "OFOutOfRangeException.h" +#import "autorelease.h" #import "macros.h" @implementation OFArray_adjacent - init { @@ -150,36 +150,36 @@ - initWithSerialization: (OFXMLElement*)element { self = [self init]; @try { - OFAutoreleasePool *pool, *pool2; + void *pool = objc_autoreleasePoolPush(); OFEnumerator *enumerator; OFXMLElement *child; - pool = [[OFAutoreleasePool alloc] init]; - if ((![[element name] isEqual: @"OFArray"] && ![[element name] isEqual: @"OFMutableArray"]) || ![[element namespace] isEqual: OF_SERIALIZATION_NS]) @throw [OFInvalidArgumentException exceptionWithClass: [self class] selector: _cmd]; enumerator = [[element elementsForNamespace: OF_SERIALIZATION_NS] objectEnumerator]; - pool2 = [[OFAutoreleasePool alloc] init]; while ((child = [enumerator nextObject]) != nil) { - id object = [child objectByDeserializing]; + void *pool2 = objc_autoreleasePoolPush(); + id object; + + object = [child objectByDeserializing]; [array addItem: &object]; [object retain]; - [pool2 releaseObjects]; + objc_autoreleasePoolPop(pool2); } - [pool release]; + objc_autoreleasePoolPop(pool); } @catch (id e) { [self release]; @throw e; } Index: src/OFCountedSet.m ================================================================== --- src/OFCountedSet.m +++ src/OFCountedSet.m @@ -19,13 +19,14 @@ #import "OFCountedSet.h" #import "OFCountedSet_hashtable.h" #import "OFNumber.h" #import "OFString.h" #import "OFXMLElement.h" -#import "OFAutoreleasePool.h" #import "OFNotImplementedException.h" + +#import "autorelease.h" static struct { Class isa; } placeholder; @@ -138,41 +139,42 @@ } - (OFString*)description { OFMutableString *ret; - OFAutoreleasePool *pool, *pool2; + void *pool; OFEnumerator *enumerator; size_t i, count = [self count]; id object; if (count == 0) return @"{()}"; ret = [OFMutableString stringWithString: @"{(\n"]; - pool = [[OFAutoreleasePool alloc] init]; - enumerator = [self objectEnumerator]; + + pool = objc_autoreleasePoolPush(); + enumerator = [self objectEnumerator]; i = 0; - pool2 = [[OFAutoreleasePool alloc] init]; - while ((object = [enumerator nextObject]) != nil) { + void *pool2 = objc_autoreleasePoolPush(); + [ret appendString: object]; [ret appendFormat: @": %zu", [self countForObject: object]]; if (++i < count) [ret appendString: @",\n"]; - [pool2 releaseObjects]; + objc_autoreleasePoolPop(pool2); } [ret replaceOccurrencesOfString: @"\n" withString: @"\n\t"]; [ret appendString: @"\n)}"]; [ret makeImmutable]; - [pool release]; + objc_autoreleasePoolPop(pool); return ret; } - copy @@ -185,23 +187,23 @@ return [[OFCountedSet alloc] initWithSet: self]; } - (OFXMLElement*)XMLElementBySerializing { - OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; - OFAutoreleasePool *pool2; + void *pool = objc_autoreleasePoolPush(); OFXMLElement *element; OFEnumerator *enumerator; id object; element = [OFXMLElement elementWithName: @"OFCountedSet" namespace: OF_SERIALIZATION_NS]; enumerator = [self objectEnumerator]; - pool2 = [[OFAutoreleasePool alloc] init]; while ((object = [enumerator nextObject]) != nil) { + void *pool2 = objc_autoreleasePoolPush(); + OFXMLElement *objectElement; OFString *count; count = [OFString stringWithFormat: @"%zu", @@ -213,18 +215,18 @@ [objectElement addAttributeWithName: @"count" stringValue: count]; [objectElement addChild: [object XMLElementBySerializing]]; [element addChild: objectElement]; - [pool2 releaseObjects]; + objc_autoreleasePoolPop(pool2); } [element retain]; - [pool release]; - [element autorelease]; + + objc_autoreleasePoolPop(pool); - return element; + return [element autorelease]; } #ifdef OF_HAVE_BLOCKS - (void)enumerateObjectsAndCountUsingBlock: (of_counted_set_enumeration_block_t)block @@ -235,11 +237,11 @@ } #endif - (void)minusSet: (OFSet*)set { - OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; + void *pool = objc_autoreleasePoolPush(); if ([set isKindOfClass: [OFCountedSet class]]) { OFCountedSet *countedSet = (OFCountedSet*)set; OFEnumerator *enumerator = [countedSet objectEnumerator]; id object; @@ -256,16 +258,16 @@ while ((object = [enumerator nextObject]) != nil) [self removeObject: object]; } - [pool release]; + objc_autoreleasePoolPop(pool); } - (void)unionSet: (OFSet*)set { - OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; + void *pool = objc_autoreleasePoolPush(); if ([set isKindOfClass: [OFCountedSet class]]) { OFCountedSet *countedSet = (OFCountedSet*)set; OFEnumerator *enumerator = [countedSet objectEnumerator]; id object; @@ -282,8 +284,8 @@ while ((object = [enumerator nextObject]) != nil) [self addObject: object]; } - [pool release]; + objc_autoreleasePoolPop(pool); } @end Index: src/OFCountedSet_hashtable.m ================================================================== --- src/OFCountedSet_hashtable.m +++ src/OFCountedSet_hashtable.m @@ -24,14 +24,15 @@ #import "OFString.h" #import "OFNumber.h" #import "OFArray.h" #import "OFXMLElement.h" #import "OFXMLAttribute.h" -#import "OFAutoreleasePool.h" #import "OFInvalidArgumentException.h" #import "OFInvalidFormatException.h" + +#import "autorelease.h" @implementation OFCountedSet_hashtable + (void)initialize { if (self == [OFCountedSet_hashtable class]) @@ -41,11 +42,11 @@ - initWithSet: (OFSet*)set { self = [self init]; @try { - OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; + void *pool = objc_autoreleasePoolPush(); if ([set isKindOfClass: [OFCountedSet class]]) { OFCountedSet *countedSet = (OFCountedSet*)countedSet; OFEnumerator *enumerator = [countedSet objectEnumerator]; @@ -65,11 +66,11 @@ while ((object = [enumerator nextObject]) != nil) [self addObject: object]; } - [pool release]; + objc_autoreleasePoolPop(pool); } @catch (id e) { [self release]; @throw e; } @@ -135,12 +136,11 @@ - initWithSerialization: (OFXMLElement*)element { self = [self init]; @try { - OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; - OFAutoreleasePool *pool2; + void *pool = objc_autoreleasePoolPush(); OFArray *objects; OFEnumerator *enumerator; OFXMLElement *objectElement; if (![[element name] isEqual: @"OFCountedSet"] || @@ -151,13 +151,12 @@ objects = [element elementsForName: @"object" namespace: OF_SERIALIZATION_NS]; enumerator = [objects objectEnumerator]; - pool2 = [[OFAutoreleasePool alloc] init]; - while ((objectElement = [enumerator nextObject]) != nil) { + void *pool2 = objc_autoreleasePoolPush(); OFXMLElement *object; OFXMLAttribute *count; OFNumber *number; object = [[objectElement elementsForNamespace: @@ -173,14 +172,14 @@ [dictionary _setObject: number forKey: [object objectByDeserializing] copyKey: NO]; - [pool2 releaseObjects]; + objc_autoreleasePoolPop(pool2); } - [pool release]; + objc_autoreleasePoolPop(pool); } @catch (id e) { [self release]; @throw e; } @@ -203,11 +202,11 @@ } #endif - (void)addObject: (id)object { - OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; + void *pool = objc_autoreleasePoolPush(); OFNumber *count; count = [[dictionary objectForKey: object] numberByIncreasing]; if (count == nil) @@ -217,22 +216,22 @@ forKey: object copyKey: NO]; mutations++; - [pool release]; + objc_autoreleasePoolPop(pool); } - (void)removeObject: (id)object { OFNumber *count = [dictionary objectForKey: object]; - OFAutoreleasePool *pool; + void *pool; if (count == nil) return; - pool = [[OFAutoreleasePool alloc] init]; + pool = objc_autoreleasePoolPush(); count = [count numberByDecreasing]; if ([count sizeValue] > 0) [dictionary _setObject: count forKey: object @@ -240,12 +239,12 @@ else [dictionary removeObjectForKey: object]; mutations++; - [pool release]; + objc_autoreleasePoolPop(pool); } - (void)makeImmutable { } @end Index: src/OFDataArray+Hashing.m ================================================================== --- src/OFDataArray+Hashing.m +++ src/OFDataArray+Hashing.m @@ -18,18 +18,19 @@ #import "OFDataArray.h" #import "OFString.h" #import "OFMD5Hash.h" #import "OFSHA1Hash.h" -#import "OFAutoreleasePool.h" + +#import "autorelease.h" int _OFDataArray_Hashing_reference; @implementation OFDataArray (Hashing) - (OFString*)MD5Hash { - OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; + void *pool = objc_autoreleasePoolPush(); OFMD5Hash *hash = [OFMD5Hash hash]; uint8_t *digest; char cString[OF_MD5_DIGEST_SIZE * 2]; size_t i; @@ -45,20 +46,20 @@ cString[i * 2] = (high > 9 ? high - 10 + 'a' : high + '0'); cString[i * 2 + 1] = (low > 9 ? low - 10 + 'a' : low + '0'); } - [pool release]; + objc_autoreleasePoolPop(pool); return [OFString stringWithCString: cString encoding: OF_STRING_ENCODING_ASCII length: 32]; } - (OFString*)SHA1Hash { - OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; + void *pool = objc_autoreleasePoolPush(); OFMD5Hash *hash = [OFSHA1Hash hash]; uint8_t *digest; char cString[OF_SHA1_DIGEST_SIZE * 2]; size_t i; @@ -74,12 +75,12 @@ cString[i * 2] = (high > 9 ? high - 10 + 'a' : high + '0'); cString[i * 2 + 1] = (low > 9 ? low - 10 + 'a' : low + '0'); } - [pool release]; + objc_autoreleasePoolPop(pool); return [OFString stringWithCString: cString encoding: OF_STRING_ENCODING_ASCII length: 40]; } @end Index: src/OFDataArray.m ================================================================== --- src/OFDataArray.m +++ src/OFDataArray.m @@ -24,19 +24,19 @@ #import "OFString.h" #import "OFFile.h" #import "OFURL.h" #import "OFHTTPRequest.h" #import "OFXMLElement.h" -#import "OFAutoreleasePool.h" #import "OFHTTPRequestFailedException.h" #import "OFInvalidArgumentException.h" #import "OFInvalidEncodingException.h" #import "OFNotImplementedException.h" #import "OFOutOfMemoryException.h" #import "OFOutOfRangeException.h" +#import "autorelease.h" #import "base64.h" #import "macros.h" /* References for static linking */ void _references_to_categories_of_OFDataArray(void) @@ -129,23 +129,23 @@ return self; } - initWithContentsOfURL: (OFURL*)URL { - OFAutoreleasePool *pool; + void *pool; OFHTTPRequest *request; OFHTTPRequestResult *result; Class c; c = [self class]; [self release]; - pool = [[OFAutoreleasePool alloc] init]; + pool = objc_autoreleasePoolPush(); if ([[URL scheme] isEqual: @"file"]) { self = [[c alloc] initWithContentsOfFile: [URL path]]; - [pool release]; + objc_autoreleasePoolPop(pool); return self; } request = [OFHTTPRequest requestWithURL: URL]; result = [request perform]; @@ -155,11 +155,11 @@ exceptionWithClass: [request class] HTTPRequest: request result: result]; self = [[result data] retain]; - [pool release]; + objc_autoreleasePoolPop(pool); return self; } - initWithBase64EncodedString: (OFString*)string { @@ -183,11 +183,11 @@ self = [super init]; itemSize = 1; @try { - OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; + void *pool = objc_autoreleasePoolPush(); OFString *stringValue; if (![[element name] isEqual: [self className]] || ![[element namespace] isEqual: OF_SERIALIZATION_NS]) @throw [OFInvalidArgumentException @@ -201,11 +201,11 @@ [stringValue cStringLengthWithEncoding: OF_STRING_ENCODING_ASCII])) @throw [OFInvalidEncodingException exceptionWithClass: [self class]]; - [pool release]; + objc_autoreleasePoolPop(pool); } @catch (id e) { [self release]; @throw e; } @@ -446,29 +446,29 @@ } } - (OFXMLElement*)XMLElementBySerializing { - OFAutoreleasePool *pool; + void *pool; OFXMLElement *element; if (itemSize != 1) @throw [OFNotImplementedException exceptionWithClass: [self class] selector: _cmd]; - pool = [[OFAutoreleasePool alloc] init]; + pool = objc_autoreleasePoolPush(); element = [OFXMLElement elementWithName: [self className] namespace: OF_SERIALIZATION_NS stringValue: of_base64_encode(data, count * itemSize)]; [element retain]; - [pool release]; - [element autorelease]; + + objc_autoreleasePoolPop(pool); - return element; + return [element autorelease]; } @end @implementation OFBigDataArray - (void)addItem: (const void*)item Index: src/OFDate.m ================================================================== --- src/OFDate.m +++ src/OFDate.m @@ -27,20 +27,20 @@ #import "OFDate.h" #import "OFString.h" #import "OFDictionary.h" #import "OFXMLElement.h" -#import "OFAutoreleasePool.h" #ifdef OF_THREADS # import "OFThread.h" #endif #import "OFInitializationFailedException.h" #import "OFInvalidArgumentException.h" #import "OFInvalidFormatException.h" #import "OFOutOfRangeException.h" +#import "autorelease.h" #import "macros.h" #import "of_strptime.h" #if (!defined(HAVE_GMTIME_R) || !defined(HAVE_LOCALTIME_R)) && \ defined(OF_THREADS) @@ -320,11 +320,11 @@ - initWithSerialization: (OFXMLElement*)element { self = [super init]; @try { - OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; + void *pool = objc_autoreleasePoolPush(); union { double d; uint64_t u; } d; @@ -335,11 +335,11 @@ selector: _cmd]; d.u = (uint64_t)[element hexadecimalValue]; seconds = of_bswap_double_if_le(d.d); - [pool release]; + objc_autoreleasePoolPop(pool); } @catch (id e) { [self release]; @throw e; } @@ -411,11 +411,11 @@ return [self dateStringWithFormat: @"%Y-%m-%dT%H:%M:%SZ"]; } - (OFXMLElement*)XMLElementBySerializing { - OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; + void *pool = objc_autoreleasePoolPush(); OFXMLElement *element; union { double d; uint64_t u; } d; @@ -426,14 +426,14 @@ d.d = of_bswap_double_if_le(seconds); [element setStringValue: [OFString stringWithFormat: @"%016" PRIx64, d.u]]; [element retain]; - [pool release]; - [element autorelease]; + + objc_autoreleasePoolPop(pool); - return element; + return [element autorelease]; } - (uint32_t)microsecond { return (uint32_t)rint((seconds - floor(seconds)) * 1000000); Index: src/OFDictionary.m ================================================================== --- src/OFDictionary.m +++ src/OFDictionary.m @@ -21,13 +21,14 @@ #import "OFDictionary.h" #import "OFDictionary_hashtable.h" #import "OFArray.h" #import "OFString.h" #import "OFXMLElement.h" -#import "OFAutoreleasePool.h" #import "OFNotImplementedException.h" + +#import "autorelease.h" static struct { Class isa; } placeholder; @@ -282,11 +283,11 @@ } - (BOOL)isEqual: (id)object { OFDictionary *otherDictionary; - OFAutoreleasePool *pool; + void *pool; OFEnumerator *enumerator; id key; if (![object isKindOfClass: [OFDictionary class]]) return NO; @@ -294,83 +295,81 @@ otherDictionary = object; if ([otherDictionary count] != [self count]) return NO; - pool = [[OFAutoreleasePool alloc] init]; + pool = objc_autoreleasePoolPush(); enumerator = [self keyEnumerator]; while ((key = [enumerator nextObject]) != nil) { id object = [otherDictionary objectForKey: key]; if (object == nil || ![object isEqual: [self objectForKey: key]]) { - [pool release]; + objc_autoreleasePoolPop(pool); return NO; } } - [pool release]; + objc_autoreleasePoolPop(pool); return YES; } - (BOOL)containsObject: (id)object { - OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; + void *pool = objc_autoreleasePoolPush(); OFEnumerator *enumerator = [self objectEnumerator]; id currentObject; while ((currentObject = [enumerator nextObject]) != nil) { if ([currentObject isEqual: object]) { - [pool release]; + objc_autoreleasePoolPop(pool); return YES; } } - [pool release]; + objc_autoreleasePoolPop(pool); return NO; } - (BOOL)containsObjectIdenticalTo: (id)object { - OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; + void *pool = objc_autoreleasePoolPush(); OFEnumerator *enumerator = [self objectEnumerator]; id currentObject; while ((currentObject = [enumerator nextObject]) != nil) { if (currentObject == object) { - [pool release]; + objc_autoreleasePoolPop(pool); return YES; } } - [pool release]; + objc_autoreleasePoolPop(pool); return NO; } - (OFArray*)allKeys { - OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; + void *pool = objc_autoreleasePoolPush(); id *keys = [self allocMemoryWithSize: sizeof(id) count: [self count]]; OFArray *ret; OFEnumerator *enumerator; id key; size_t i = 0; - pool = [[OFAutoreleasePool alloc] init]; enumerator = [self keyEnumerator]; - while ((key = [enumerator nextObject]) != nil) keys[i++] = key; assert(i == [self count]); - [pool release]; + objc_autoreleasePoolPop(pool); @try { ret = [OFArray arrayWithObjects: keys count: [self count]]; } @finally { @@ -380,27 +379,25 @@ return ret; } - (OFArray*)allObjects { - OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; + void *pool = objc_autoreleasePoolPush(); id *objects = [self allocMemoryWithSize: sizeof(id) count: [self count]]; OFArray *ret; OFEnumerator *enumerator; id object; size_t i = 0; - pool = [[OFAutoreleasePool alloc] init]; enumerator = [self objectEnumerator]; - while ((object = [enumerator nextObject]) != nil) objects[i++] = object; assert(i == [self count]); - [pool release]; + objc_autoreleasePoolPop(pool); @try { ret = [OFArray arrayWithObjects: objects count: [self count]]; } @finally { @@ -479,70 +476,69 @@ } #endif - (uint32_t)hash { - OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; + void *pool = objc_autoreleasePoolPush(); OFEnumerator *enumerator = [self keyEnumerator]; id key; uint32_t hash = 0; while ((key = [enumerator nextObject]) != nil) { hash += [key hash]; hash += [[self objectForKey: key] hash]; } - [pool release]; + objc_autoreleasePoolPop(pool); return hash; } - (OFString*)description { OFMutableString *ret; - OFAutoreleasePool *pool, *pool2; + void *pool; OFEnumerator *keyEnumerator, *objectEnumerator; id key, object; size_t i, count = [self count]; if (count == 0) return @"{}"; ret = [OFMutableString stringWithString: @"{\n"]; - pool = [[OFAutoreleasePool alloc] init]; + pool = objc_autoreleasePoolPush(); keyEnumerator = [self keyEnumerator]; objectEnumerator = [self objectEnumerator]; i = 0; - pool2 = [[OFAutoreleasePool alloc] init]; - while ((key = [keyEnumerator nextObject]) != nil && (object = [objectEnumerator nextObject]) != nil) { + void *pool2 = objc_autoreleasePoolPush(); + [ret appendString: [key description]]; [ret appendString: @" = "]; [ret appendString: [object description]]; if (++i < count) [ret appendString: @";\n"]; - [pool2 releaseObjects]; + objc_autoreleasePoolPop(pool2); } [ret replaceOccurrencesOfString: @"\n" withString: @"\n\t"]; [ret appendString: @";\n}"]; [ret makeImmutable]; - [pool release]; + objc_autoreleasePoolPop(pool); return ret; } - (OFXMLElement*)XMLElementBySerializing { - OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; - OFAutoreleasePool *pool2; + void *pool = objc_autoreleasePoolPush(); OFXMLElement *element; OFEnumerator *keyEnumerator, *objectEnumerator; id key, object; if ([self isKindOfClass: [OFMutableDictionary class]]) @@ -552,14 +548,13 @@ element = [OFXMLElement elementWithName: @"OFDictionary" namespace: OF_SERIALIZATION_NS]; keyEnumerator = [self keyEnumerator]; objectEnumerator = [self objectEnumerator]; - pool2 = [[OFAutoreleasePool alloc] init]; - while ((key = [keyEnumerator nextObject]) != nil && (object = [objectEnumerator nextObject]) != nil) { + void *pool2 = objc_autoreleasePoolPush(); OFXMLElement *keyElement, *objectElement; keyElement = [OFXMLElement elementWithName: @"key" namespace: OF_SERIALIZATION_NS]; @@ -571,47 +566,47 @@ [objectElement addChild: [object XMLElementBySerializing]]; [element addChild: keyElement]; [element addChild: objectElement]; - [pool2 releaseObjects]; + objc_autoreleasePoolPop(pool2); } [element retain]; - [pool release]; - [element autorelease]; + + objc_autoreleasePoolPop(pool); - return element; + return [element autorelease]; } - (OFString*)JSONRepresentation { OFMutableString *JSON = [OFMutableString stringWithString: @"{"]; - OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init], *pool2; + void *pool = objc_autoreleasePoolPush(); OFEnumerator *keyEnumerator = [self keyEnumerator]; OFEnumerator *objectEnumerator = [self objectEnumerator]; size_t i = 0, count = [self count]; OFString *key; OFString *object; - pool2 = [[OFAutoreleasePool alloc] init]; - while ((key = [keyEnumerator nextObject]) != nil && (object = [objectEnumerator nextObject]) != nil) { + void *pool2 = objc_autoreleasePoolPush(); + [JSON appendString: [key JSONRepresentation]]; [JSON appendString: @":"]; [JSON appendString: [object JSONRepresentation]]; if (++i < count) [JSON appendString: @","]; - [pool2 releaseObjects]; + objc_autoreleasePoolPop(pool2); } - [pool release]; - [JSON appendString: @"}"]; [JSON makeImmutable]; + + objc_autoreleasePoolPop(pool); return JSON; } @end Index: src/OFDictionary_hashtable.m ================================================================== --- src/OFDictionary_hashtable.m +++ src/OFDictionary_hashtable.m @@ -24,18 +24,18 @@ #import "OFMutableDictionary_hashtable.h" #import "OFEnumerator.h" #import "OFArray.h" #import "OFString.h" #import "OFXMLElement.h" -#import "OFAutoreleasePool.h" #import "OFEnumerationMutationException.h" #import "OFInvalidArgumentException.h" #import "OFInvalidFormatException.h" #import "OFNotImplementedException.h" #import "OFOutOfRangeException.h" +#import "autorelease.h" #import "macros.h" struct of_dictionary_hashtable_bucket of_dictionary_hashtable_deleted_bucket = {}; #define DELETED &of_dictionary_hashtable_deleted_bucket @@ -122,11 +122,11 @@ copyKeys: YES]; self = [super init]; @try { - OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; + void *pool; OFEnumerator *enumerator; id key; uint32_t i, newSize; count = [dictionary count]; @@ -149,13 +149,13 @@ for (i = 0; i < newSize; i++) data[i] = NULL; size = newSize; - pool = [[OFAutoreleasePool alloc] init]; + pool = objc_autoreleasePoolPush(); + enumerator = [dictionary keyEnumerator]; - while ((key = [enumerator nextObject]) != nil) { uint32_t hash, last; struct of_dictionary_hashtable_bucket *bucket; id object; @@ -185,11 +185,11 @@ bucket->hash = hash; data[i] = bucket; } - [pool release]; + objc_autoreleasePoolPop(pool); } @catch (id e) { [self release]; @throw e; } @@ -499,12 +499,11 @@ } - initWithSerialization: (OFXMLElement*)element { @try { - OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; - OFAutoreleasePool *pool2; + void *pool = objc_autoreleasePoolPush(); OFMutableDictionary *dictionary; OFArray *keys, *objects; OFEnumerator *keyEnumerator, *objectEnumerator; OFXMLElement *keyElement, *objectElement; @@ -526,14 +525,13 @@ @throw [OFInvalidFormatException exceptionWithClass: [self class]]; keyEnumerator = [keys objectEnumerator]; objectEnumerator = [objects objectEnumerator]; - pool2 = [[OFAutoreleasePool alloc] init]; - while ((keyElement = [keyEnumerator nextObject]) != nil && (objectElement = [objectEnumerator nextObject]) != nil) { + void *pool2 = objc_autoreleasePoolPush(); OFXMLElement *key, *object; key = [[keyElement elementsForNamespace: OF_SERIALIZATION_NS] firstObject]; object = [[objectElement elementsForNamespace: @@ -544,16 +542,16 @@ exceptionWithClass: [self class]]; [dictionary setObject: [object objectByDeserializing] forKey: [key objectByDeserializing]]; - [pool2 releaseObjects]; + objc_autoreleasePoolPop(pool2); } self = [self initWithDictionary: dictionary]; - [pool release]; + objc_autoreleasePoolPop(pool); } @catch (id e) { [self release]; @throw e; } Index: src/OFFile.m ================================================================== --- src/OFFile.m +++ src/OFFile.m @@ -46,11 +46,10 @@ #ifdef OF_THREADS # import "threading.h" #endif #import "OFDate.h" #import "OFApplication.h" -#import "OFAutoreleasePool.h" #import "OFChangeDirectoryFailedException.h" #import "OFChangeFileModeFailedException.h" #import "OFChangeFileOwnerFailedException.h" #import "OFCreateDirectoryFailedException.h" @@ -68,10 +67,11 @@ #import "OFRenameFileFailedException.h" #import "OFSeekFailedException.h" #import "OFSymlinkFailedException.h" #import "OFWriteFailedException.h" +#import "autorelease.h" #import "macros.h" #ifdef _WIN32 # import #endif @@ -135,11 +135,11 @@ } void of_log(OFConstantString *format, ...) { - OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; + void *pool = objc_autoreleasePoolPush(); OFDate *date; OFString *dateString, *me, *msg; va_list arguments; date = [OFDate date]; @@ -152,11 +152,11 @@ va_end(arguments); [of_stderr writeFormat: @"[%@.%03d %@(%d)] %@\n", dateString, [date microsecond] / 1000, me, getpid(), msg]; - [pool release]; + objc_autoreleasePoolPop(pool); } @interface OFFileSingleton: OFFile @end @@ -243,26 +243,27 @@ } + (void)createDirectoryAtPath: (OFString*)path createParents: (BOOL)createParents { - OFAutoreleasePool *pool, *pool2; + void *pool; OFArray *pathComponents; OFString *currentPath = nil, *component; OFEnumerator *enumerator; if (!createParents) { [OFFile createDirectoryAtPath: path]; return; } - pool = [[OFAutoreleasePool alloc] init]; + pool = objc_autoreleasePoolPush(); pathComponents = [path pathComponents]; enumerator = [pathComponents objectEnumerator]; - pool2 = [[OFAutoreleasePool alloc] init]; while ((component = [enumerator nextObject]) != nil) { + void *pool2 = objc_autoreleasePoolPush(); + if (currentPath != nil) currentPath = [OFString stringWithPath: currentPath, component, nil]; else currentPath = component; @@ -270,20 +271,21 @@ if (![currentPath isEqual: @""] && ![OFFile directoryExistsAtPath: currentPath]) [OFFile createDirectoryAtPath: currentPath]; [currentPath retain]; - [pool2 releaseObjects]; + + objc_autoreleasePoolPop(pool2); + [currentPath autorelease]; } - [pool release]; + objc_autoreleasePoolPop(pool); } + (OFArray*)filesInDirectoryAtPath: (OFString*)path { - OFAutoreleasePool *pool; OFMutableArray *files = [OFMutableArray array]; #ifndef _WIN32 DIR *dir; struct dirent *dirent; @@ -293,13 +295,12 @@ @throw [OFOpenFileFailedException exceptionWithClass: self path: path mode: @"r"]; @try { - pool = [[OFAutoreleasePool alloc] init]; - while ((dirent = readdir(dir)) != NULL) { + void *pool = objc_autoreleasePoolPush(); OFString *file; if (!strcmp(dirent->d_name, ".") || !strcmp(dirent->d_name, "..")) continue; @@ -307,34 +308,31 @@ file = [OFString stringWithCString: dirent->d_name encoding: OF_STRING_ENCODING_NATIVE]; [files addObject: file]; - [pool releaseObjects]; + objc_autoreleasePoolPop(pool); } - - [pool release]; } @finally { closedir(dir); } #else + void *pool = objc_autoreleasePoolPush(); HANDLE handle; WIN32_FIND_DATA fd; - pool = [[OFAutoreleasePool alloc] init]; path = [path stringByAppendingString: @"\\*"]; if ((handle = FindFirstFile([path cStringWithEncoding: OF_STRING_ENCODING_NATIVE], &fd)) == INVALID_HANDLE_VALUE) @throw [OFOpenFileFailedException exceptionWithClass: self path: path mode: @"r"]; @try { - OFAutoreleasePool *pool2 = [[OFAutoreleasePool alloc] init]; - do { + void *pool2 = objc_autoreleasePoolPush(); OFString *file; if (!strcmp(fd.cFileName, ".") || !strcmp(fd.cFileName, "..")) continue; @@ -342,19 +340,17 @@ file = [OFString stringWithCString: fd.cFileName encoding: OF_STRING_ENCODING_NATIVE]; [files addObject: file]; - [pool2 releaseObjects]; + objc_autoreleasePoolPop(pool2); } while (FindNextFile(handle, &fd)); - - [pool2 release]; } @finally { FindClose(handle); } - [pool release]; + objc_autoreleasePoolPop(pool); #endif [files makeImmutable]; return files; @@ -498,11 +494,11 @@ #endif + (void)copyFileAtPath: (OFString*)source toPath: (OFString*)destination { - OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; + void *pool = objc_autoreleasePoolPush(); BOOL override; OFFile *sourceFile = nil; OFFile *destinationFile = nil; char *buffer; @@ -548,17 +544,17 @@ [sourceFile close]; [destinationFile close]; free(buffer); } - [pool release]; + objc_autoreleasePoolPop(pool); } + (void)renameFileAtPath: (OFString*)source toPath: (OFString*)destination { - OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; + void *pool = objc_autoreleasePoolPush(); if ([self directoryExistsAtPath: destination]) { OFString *filename = [source lastPathComponent]; destination = [OFString stringWithPath: destination, filename, nil]; @@ -574,11 +570,11 @@ @throw [OFRenameFileFailedException exceptionWithClass: self sourcePath: source destinationPath: destination]; - [pool release]; + objc_autoreleasePoolPop(pool); } + (void)deleteFileAtPath: (OFString*)path { #ifndef _WIN32 @@ -600,11 +596,11 @@ #ifndef _WIN32 + (void)linkFileAtPath: (OFString*)source toPath: (OFString*)destination { - OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; + void *pool = objc_autoreleasePoolPush(); if ([self directoryExistsAtPath: destination]) { OFString *filename = [source lastPathComponent]; destination = [OFString stringWithPath: destination, filename, nil]; @@ -614,19 +610,19 @@ [destination cStringWithEncoding: OF_STRING_ENCODING_NATIVE]) != 0) @throw [OFLinkFailedException exceptionWithClass: self sourcePath: source destinationPath: destination]; - [pool release]; + objc_autoreleasePoolPop(pool); } #endif #if !defined(_WIN32) && !defined(_PSP) + (void)symlinkFileAtPath: (OFString*)source toPath: (OFString*)destination { - OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; + void *pool = objc_autoreleasePoolPush(); if ([self directoryExistsAtPath: destination]) { OFString *filename = [source lastPathComponent]; destination = [OFString stringWithPath: destination, filename, nil]; @@ -637,11 +633,11 @@ @throw [OFSymlinkFailedException exceptionWithClass: self sourcePath: source destinationPath: destination]; - [pool release]; + objc_autoreleasePoolPop(pool); } #endif - init { Index: src/OFHTTPRequest.m ================================================================== --- src/OFHTTPRequest.m +++ src/OFHTTPRequest.m @@ -25,11 +25,10 @@ #import "OFString.h" #import "OFURL.h" #import "OFTCPSocket.h" #import "OFDictionary.h" #import "OFDataArray.h" -#import "OFAutoreleasePool.h" #import "OFHTTPRequestFailedException.h" #import "OFInvalidEncodingException.h" #import "OFInvalidFormatException.h" #import "OFInvalidServerReplyException.h" @@ -36,10 +35,11 @@ #import "OFOutOfRangeException.h" #import "OFTruncatedDataException.h" #import "OFUnsupportedProtocolException.h" #import "OFUnsupportedVersionException.h" +#import "autorelease.h" #import "macros.h" Class of_http_request_tls_socket_class = Nil; static OF_INLINE void @@ -185,11 +185,11 @@ return [self performWithRedirects: 10]; } - (OFHTTPRequestResult*)performWithRedirects: (size_t)redirects { - OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; + void *pool = objc_autoreleasePoolPush(); OFString *scheme = [URL scheme]; OFTCPSocket *sock; OFHTTPRequestResult *result; OFString *line, *path, *version; OFMutableDictionary *serverHeaders; @@ -365,11 +365,11 @@ requestType = OF_HTTP_REQUEST_TYPE_GET; [queryString release]; queryString = nil; } - [pool release]; + objc_autoreleasePoolPop(pool); return [self performWithRedirects: redirects - 1]; } [serverHeaders setObject: value @@ -395,14 +395,13 @@ } buffer = [self allocMemoryWithSize: of_pagesize]; bytesReceived = 0; @try { - OFAutoreleasePool *pool2 = [[OFAutoreleasePool alloc] init]; - if (chunked) { for (;;) { + void *pool2 = objc_autoreleasePoolPush(); size_t pos, toRead; @try { line = [sock readLine]; } @catch (OFInvalidEncodingException *e) { @@ -437,11 +436,13 @@ length: length]; [delegate request: self didReceiveData: buffer withLength: length]; - [pool2 releaseObjects]; + + objc_autoreleasePoolPop(pool2); + pool2 = objc_autoreleasePoolPush(); bytesReceived += length; [data addItemsFromCArray: buffer count: length]; @@ -457,22 +458,25 @@ if (![line isEqual: @""]) @throw [OFInvalidServerReplyException exceptionWithClass: [self class]]; - [pool2 releaseObjects]; + objc_autoreleasePoolPop(pool2); } } else { size_t length; while ((length = [sock readIntoBuffer: buffer length: of_pagesize]) > 0) { + void *pool2 = objc_autoreleasePoolPush(); + [delegate request: self didReceiveData: buffer withLength: length]; - [pool2 releaseObjects]; + + objc_autoreleasePoolPop(pool2); bytesReceived += length; [data addItemsFromCArray: buffer count: length]; @@ -479,12 +483,10 @@ if (contentLengthHeader != nil && bytesReceived >= contentLength) break; } } - - [pool2 release]; } @finally { [self freeMemory: buffer]; } [sock close]; @@ -518,11 +520,11 @@ exceptionWithClass: [self class] HTTPRequest: self result: result]; } - [pool release]; + objc_autoreleasePoolPop(pool); return [result autorelease]; } @end Index: src/OFIntrospection.m ================================================================== --- src/OFIntrospection.m +++ src/OFIntrospection.m @@ -23,12 +23,12 @@ #endif #import "OFIntrospection.h" #import "OFString.h" #import "OFArray.h" -#import "OFAutoreleasePool.h" +#import "autorelease.h" #import "macros.h" @implementation OFMethod #if defined(OF_OBJFW_RUNTIME) - _initWithMethod: (struct objc_method*)method @@ -217,11 +217,10 @@ - initWithClass: (Class)class { self = [super init]; @try { - OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; #if defined(OF_OBJFW_RUNTIME) struct objc_method_list *methodList; #elif defined(OF_APPLE_RUNTIME) Method *methodList; Ivar *ivarList; @@ -242,91 +241,99 @@ for (methodList = object_getClass(class)->methodlist; methodList != NULL; methodList = methodList->next) { int i; for (i = 0; i < methodList->count; i++) { + void *pool = objc_autoreleasePoolPush(); OFMethod *method = [[OFMethod alloc] _initWithMethod: &methodList->methods[i]]; [classMethods addObject: [method autorelease]]; - [pool releaseObjects]; + objc_autoreleasePoolPop(pool); } } for (methodList = class->methodlist; methodList != NULL; methodList = methodList->next) { int i; for (i = 0; i < methodList->count; i++) { + void *pool = objc_autoreleasePoolPush(); OFMethod *method = [[OFMethod alloc] _initWithMethod: &methodList->methods[i]]; [instanceMethods addObject: [method autorelease]]; - [pool releaseObjects]; + objc_autoreleasePoolPop(pool); } } if (class->ivars != NULL) { unsigned i; for (i = 0; i < class->ivars->count; i++) { + void *pool = objc_autoreleasePoolPush(); OFInstanceVariable *ivar; ivar = [[OFInstanceVariable alloc] _initWithIvar: &class->ivars->ivars[i]]; [instanceVariables addObject: [ivar autorelease]]; - [pool releaseObjects]; + + objc_autoreleasePoolPop(pool); } } /* TODO: properties */ #elif defined(OF_APPLE_RUNTIME) methodList = class_copyMethodList(object_getClass(class), &count); @try { for (i = 0; i < count; i++) { + void *pool = objc_autoreleasePoolPush(); [classMethods addObject: [[[OFMethod alloc] _initWithMethod: methodList[i]] autorelease]]; - [pool releaseObjects]; + objc_autoreleasePoolPop(pool); } } @finally { free(methodList); } methodList = class_copyMethodList(class, &count); @try { for (i = 0; i < count; i++) { + void *pool = objc_autoreleasePoolPush(); [instanceMethods addObject: [[[OFMethod alloc] _initWithMethod: methodList[i]] autorelease]]; - [pool releaseObjects]; + objc_autoreleasePoolPop(pool); } } @finally { free(methodList); } ivarList = class_copyIvarList(class, &count); @try { for (i = 0; i < count; i++) { + void *pool = objc_autoreleasePoolPush(); [instanceVariables addObject: [[[OFInstanceVariable alloc] _initWithIvar: ivarList[i]] autorelease]]; - [pool releaseObjects]; + objc_autoreleasePoolPop(pool); } } @finally { free(ivarList); } propertyList = class_copyPropertyList(class, &count); @try { for (i = 0; i < count; i++) { + void *pool = objc_autoreleasePoolPush(); [properties addObject: [[[OFProperty alloc] _initWithProperty: propertyList[i]] autorelease]]; - [pool releaseObjects]; + objc_autoreleasePoolPop(pool); } } @finally { free(propertyList); } #endif @@ -335,12 +342,10 @@ [instanceMethods makeImmutable]; [instanceVariables makeImmutable]; #ifdef OF_HAVE_PROPERTIES [properties makeImmutable]; #endif - - [pool release]; } @catch (id e) { [self release]; @throw e; } Index: src/OFList.m ================================================================== --- src/OFList.m +++ src/OFList.m @@ -20,15 +20,15 @@ #import "OFList.h" #import "OFString.h" #import "OFXMLElement.h" #import "OFArray.h" -#import "OFAutoreleasePool.h" #import "OFEnumerationMutationException.h" #import "OFInvalidArgumentException.h" +#import "autorelease.h" #import "macros.h" @implementation OFList + list { @@ -38,12 +38,11 @@ - initWithSerialization: (OFXMLElement*)element { self = [self init]; @try { - OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; - OFAutoreleasePool *pool2; + void *pool = objc_autoreleasePoolPush(); OFEnumerator *enumerator; OFXMLElement *child; if (![[element name] isEqual: [self className]] || ![[element namespace] isEqual: OF_SERIALIZATION_NS]) @@ -51,19 +50,19 @@ exceptionWithClass: [self class] selector: _cmd]; enumerator = [[element elementsForNamespace: OF_SERIALIZATION_NS] objectEnumerator]; - pool2 = [[OFAutoreleasePool alloc] init]; - while ((child = [enumerator nextObject]) != nil) { + void *pool2 = objc_autoreleasePoolPush(); + [self appendObject: [child objectByDeserializing]]; - [pool2 releaseObjects]; + objc_autoreleasePoolPop(pool2); } - [pool release]; + objc_autoreleasePoolPop(pool); } @catch (id e) { [self release]; @throw e; } @@ -327,60 +326,52 @@ } - (OFString*)description { OFMutableString *ret; - OFAutoreleasePool *pool; of_list_object_t *iter; if (count == 0) return @"[]"; ret = [OFMutableString stringWithString: @"[\n"]; - pool = [[OFAutoreleasePool alloc] init]; for (iter = firstListObject; iter != NULL; iter = iter->next) { + void *pool = objc_autoreleasePoolPush(); + [ret appendString: [iter->object description]]; if (iter->next != NULL) [ret appendString: @",\n"]; - [pool releaseObjects]; + objc_autoreleasePoolPop(pool); } [ret replaceOccurrencesOfString: @"\n" withString: @"\n\t"]; [ret appendString: @"\n]"]; [ret makeImmutable]; - [pool release]; - return ret; } - (OFXMLElement*)XMLElementBySerializing { - OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; - OFAutoreleasePool *pool2; OFXMLElement *element; of_list_object_t *iter; element = [OFXMLElement elementWithName: [self className] namespace: OF_SERIALIZATION_NS]; - pool2 = [[OFAutoreleasePool alloc] init]; - for (iter = firstListObject; iter != NULL; iter = iter->next) { + void *pool = objc_autoreleasePoolPush(); + [element addChild: [iter->object XMLElementBySerializing]]; - [pool2 releaseObjects]; + objc_autoreleasePoolPop(pool); } - [element retain]; - [pool release]; - [element autorelease]; - return element; } - (int)countByEnumeratingWithState: (of_fast_enumeration_state_t*)state objects: (id*)objects Index: src/OFMutableArray.m ================================================================== --- src/OFMutableArray.m +++ src/OFMutableArray.m @@ -20,17 +20,17 @@ #include #import "OFMutableArray.h" #import "OFMutableArray_adjacent.h" -#import "OFAutoreleasePool.h" #import "OFEnumerationMutationException.h" #import "OFInvalidArgumentException.h" #import "OFNotImplementedException.h" #import "OFOutOfRangeException.h" +#import "autorelease.h" #import "macros.h" static struct { Class isa; } placeholder; @@ -198,11 +198,11 @@ } - (void)insertObjectsFromArray: (OFArray*)array atIndex: (size_t)index { - OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; + void *pool = objc_autoreleasePoolPush(); OFEnumerator *enumerator = [array objectEnumerator]; size_t i, count = [array count]; for (i = 0; i < count; i++) { id object = [enumerator nextObject]; @@ -211,11 +211,11 @@ [self insertObject: object atIndex: index + i]; } - [pool release]; + objc_autoreleasePoolPop(pool); } - (void)replaceObjectAtIndex: (size_t)index withObject: (id)object { Index: src/OFMutableArray_adjacent.m ================================================================== --- src/OFMutableArray_adjacent.m +++ src/OFMutableArray_adjacent.m @@ -19,11 +19,10 @@ #include #import "OFMutableArray_adjacent.h" #import "OFArray_adjacent.h" #import "OFDataArray.h" -#import "OFAutoreleasePool.h" #import "OFEnumerationMutationException.h" #import "OFInvalidArgumentException.h" #import "OFOutOfRangeException.h" Index: src/OFMutableDictionary.m ================================================================== --- src/OFMutableDictionary.m +++ src/OFMutableDictionary.m @@ -15,11 +15,10 @@ */ #include "config.h" #import "OFMutableDictionary_hashtable.h" -#import "OFAutoreleasePool.h" #import "OFNotImplementedException.h" static struct { Class isa; Index: src/OFMutableDictionary_hashtable.m ================================================================== --- src/OFMutableDictionary_hashtable.m +++ src/OFMutableDictionary_hashtable.m @@ -18,11 +18,10 @@ #include #import "OFMutableDictionary_hashtable.h" #import "OFDictionary_hashtable.h" -#import "OFAutoreleasePool.h" #import "OFEnumerationMutationException.h" #import "OFInvalidArgumentException.h" #import "OFOutOfRangeException.h" Index: src/OFMutableSet.m ================================================================== --- src/OFMutableSet.m +++ src/OFMutableSet.m @@ -18,13 +18,14 @@ #include #import "OFMutableSet.h" #import "OFMutableSet_hashtable.h" -#import "OFAutoreleasePool.h" #import "OFNotImplementedException.h" + +#import "autorelease.h" static struct { Class isa; } placeholder; @@ -142,23 +143,23 @@ selector: _cmd]; } - (void)minusSet: (OFSet*)set { - OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; + void *pool = objc_autoreleasePoolPush(); OFEnumerator *enumerator = [set objectEnumerator]; id object; while ((object = [enumerator nextObject]) != nil) [self removeObject: object]; - [pool release]; + objc_autoreleasePoolPop(pool); } - (void)intersectSet: (OFSet*)set { - OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; + void *pool = objc_autoreleasePoolPush(); size_t count = [self count]; id *cArray; cArray = [self allocMemoryWithSize: sizeof(id) count: count]; @@ -178,24 +179,24 @@ [self removeObject: cArray[i]]; } @finally { [self freeMemory: cArray]; } - [pool release]; + objc_autoreleasePoolPop(pool); } - (void)unionSet: (OFSet*)set { - OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; + void *pool = objc_autoreleasePoolPush(); OFEnumerator *enumerator = [set objectEnumerator]; id object; while ((object = [enumerator nextObject]) != nil) [self addObject: object]; - [pool release]; + objc_autoreleasePoolPop(pool); } - (void)makeImmutable { } @end Index: src/OFMutableSet_hashtable.m ================================================================== --- src/OFMutableSet_hashtable.m +++ src/OFMutableSet_hashtable.m @@ -20,11 +20,10 @@ #import "OFSet_hashtable.h" #import "OFMutableSet_hashtable.h" #import "OFMutableDictionary_hashtable.h" #import "OFNumber.h" -#import "OFAutoreleasePool.h" @implementation OFMutableSet_hashtable + (void)initialize { if (self == [OFMutableSet_hashtable class]) Index: src/OFMutableString.m ================================================================== --- src/OFMutableString.m +++ src/OFMutableString.m @@ -22,17 +22,17 @@ #include #import "OFString.h" #import "OFMutableString_UTF8.h" -#import "OFAutoreleasePool.h" #import "OFInvalidArgumentException.h" #import "OFInvalidFormatException.h" #import "OFNotImplementedException.h" #import "OFOutOfRangeException.h" +#import "autorelease.h" #import "macros.h" #import "of_asprintf.h" #import "unicode.h" @@ -258,11 +258,11 @@ - (void)_convertWithWordStartTable: (const of_unichar_t *const[])startTable wordMiddleTable: (const of_unichar_t *const[])middleTable wordStartTableSize: (size_t)startTableSize wordMiddleTableSize: (size_t)middleTableSize { - OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; + void *pool = objc_autoreleasePoolPush(); const of_unichar_t *string = [self unicodeString]; size_t i, length = [self length]; BOOL isStart = YES; for (i = 0; i < length; i++) { @@ -293,11 +293,11 @@ isStart = NO; break; } } - [pool release]; + objc_autoreleasePoolPop(pool); } - (void)setCharacter: (of_unichar_t)character atIndex: (size_t)index { @@ -305,50 +305,50 @@ selector: _cmd]; } - (void)appendUTF8String: (const char*)UTF8String { - OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; + void *pool = objc_autoreleasePoolPush(); [self appendString: [OFString stringWithUTF8String: UTF8String]]; - [pool release]; + objc_autoreleasePoolPop(pool); } - (void)appendUTF8String: (const char*)UTF8String withLength: (size_t)UTF8StringLength { - OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; + void *pool = objc_autoreleasePoolPush(); [self appendString: [OFString stringWithUTF8String: UTF8String length: UTF8StringLength]]; - [pool release]; + objc_autoreleasePoolPop(pool); } - (void)appendCString: (const char*)cString withEncoding: (of_string_encoding_t)encoding { - OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; + void *pool = objc_autoreleasePoolPush(); [self appendString: [OFString stringWithCString: cString encoding: encoding]]; - [pool release]; + objc_autoreleasePoolPop(pool); } - (void)appendCString: (const char*)cString withEncoding: (of_string_encoding_t)encoding length: (size_t)cStringLength { - OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; + void *pool = objc_autoreleasePoolPush(); [self appendString: [OFString stringWithCString: cString encoding: encoding length: cStringLength]]; - [pool release]; + objc_autoreleasePoolPop(pool); } - (void)appendString: (OFString*)string { return [self insertString: string @@ -463,11 +463,11 @@ - (void)replaceOccurrencesOfString: (OFString*)string withString: (OFString*)replacement inRange: (of_range_t)range { - OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init], *pool2; + void *pool = objc_autoreleasePoolPush(), *pool2; const of_unichar_t *unicodeString; const of_unichar_t *searchString = [string unicodeString]; size_t searchLength = [string length]; size_t replacementLength = [replacement length]; size_t i; @@ -474,15 +474,15 @@ if (range.start + range.length > [self length]) @throw [OFOutOfRangeException exceptionWithClass: [self class]]; if (searchLength > range.length) { - [pool release]; + objc_autoreleasePoolPop(pool); return; } - pool2 = [[OFAutoreleasePool alloc] init]; + pool2 = objc_autoreleasePoolPush(); unicodeString = [self unicodeString]; for (i = range.start; i <= range.length - searchLength; i++) { if (memcmp(unicodeString + i, searchString, searchLength * sizeof(of_unichar_t))) @@ -494,16 +494,17 @@ range.length -= searchLength; range.length += replacementLength; i += replacementLength - 1; - [pool2 releaseObjects]; + objc_autoreleasePoolPop(pool2); + pool2 = objc_autoreleasePoolPush(); unicodeString = [self unicodeString]; } - [pool release]; + objc_autoreleasePoolPop(pool); } - (void)deleteLeadingWhitespaces { size_t i, length = [self length]; Index: src/OFMutableString_UTF8.m ================================================================== --- src/OFMutableString_UTF8.m +++ src/OFMutableString_UTF8.m @@ -22,18 +22,18 @@ #include #import "OFString.h" #import "OFString_UTF8.h" #import "OFMutableString_UTF8.h" -#import "OFAutoreleasePool.h" #import "OFInvalidArgumentException.h" #import "OFInvalidEncodingException.h" #import "OFInvalidFormatException.h" #import "OFOutOfMemoryException.h" #import "OFOutOfRangeException.h" +#import "autorelease.h" #import "macros.h" #import "of_asprintf.h" #import "unicode.h" @@ -342,16 +342,16 @@ { if (encoding == OF_STRING_ENCODING_UTF_8) [self appendUTF8String: cString withLength: cStringLength]; else { - OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; + void *pool = objc_autoreleasePoolPush(); [self appendString: [OFString stringWithCString: cString encoding: encoding length: cStringLength]]; - [pool release]; + objc_autoreleasePoolPop(pool); } } - (void)appendString: (OFString*)string { Index: src/OFNull.m ================================================================== --- src/OFNull.m +++ src/OFNull.m @@ -17,14 +17,15 @@ #include "config.h" #import "OFNull.h" #import "OFString.h" #import "OFXMLElement.h" -#import "OFAutoreleasePool.h" #import "OFInvalidArgumentException.h" #import "OFNotImplementedException.h" + +#import "autorelease.h" static OFNull *null = nil; @implementation OFNull + null @@ -37,23 +38,23 @@ return null; } - initWithSerialization: (OFXMLElement*)element { - OFAutoreleasePool *pool; + void *pool; [self release]; - pool = [[OFAutoreleasePool alloc] init]; + pool = objc_autoreleasePoolPush(); if (![[element name] isEqual: [self className]] || ![[element namespace] isEqual: OF_SERIALIZATION_NS]) @throw [OFInvalidArgumentException exceptionWithClass: [self class] selector: _cmd]; - [pool release]; + objc_autoreleasePoolPop(pool); return [OFNull null]; } - (OFString*)description @@ -66,21 +67,21 @@ return self; } - (OFXMLElement*)XMLElementBySerializing { - OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; + void *pool = objc_autoreleasePoolPush(); OFXMLElement *element; element = [OFXMLElement elementWithName: [self className] namespace: OF_SERIALIZATION_NS]; [element retain]; - [pool release]; - [element autorelease]; + + objc_autoreleasePoolPop(pool); - return element; + return [element autorelease]; } - (OFString*)JSONRepresentation { return @"null"; Index: src/OFNumber.m ================================================================== --- src/OFNumber.m +++ src/OFNumber.m @@ -20,16 +20,16 @@ #import "OFNumber.h" #import "OFString.h" #import "OFXMLElement.h" #import "OFXMLAttribute.h" -#import "OFAutoreleasePool.h" #import "OFInvalidArgumentException.h" #import "OFInvalidFormatException.h" #import "OFNotImplementedException.h" +#import "autorelease.h" #import "macros.h" #define RETURN_AS(t) \ switch (type) { \ case OF_NUMBER_BOOL: \ @@ -717,11 +717,11 @@ - initWithSerialization: (OFXMLElement*)element { self = [super init]; @try { - OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; + void *pool = objc_autoreleasePoolPush(); OFString *typeString; if (![[element name] isEqual: [self className]] || ![[element namespace] isEqual: OF_SERIALIZATION_NS]) @throw [OFInvalidArgumentException @@ -774,11 +774,11 @@ } else @throw [OFInvalidArgumentException exceptionWithClass: [self class] selector: _cmd]; - [pool release]; + objc_autoreleasePoolPop(pool); } @catch (id e) { [self release]; @throw e; } @@ -1209,11 +1209,11 @@ } } - (OFXMLElement*)XMLElementBySerializing { - OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; + void *pool = objc_autoreleasePoolPush(); OFXMLElement *element; element = [OFXMLElement elementWithName: [self className] namespace: OF_SERIALIZATION_NS stringValue: [self description]]; @@ -1284,14 +1284,14 @@ @throw [OFInvalidFormatException exceptionWithClass: [self class]]; } [element retain]; - [pool release]; - [element autorelease]; + + objc_autoreleasePoolPop(pool); - return element; + return [element autorelease]; } - (OFString*)JSONRepresentation { if (type == OF_NUMBER_BOOL) Index: src/OFObject+Serialization.m ================================================================== --- src/OFObject+Serialization.m +++ src/OFObject+Serialization.m @@ -19,30 +19,31 @@ #import "OFObject.h" #import "OFObject+Serialization.h" #import "OFSerialization.h" #import "OFString.h" #import "OFXMLElement.h" -#import "OFAutoreleasePool.h" #import "OFNotImplementedException.h" + +#import "autorelease.h" int _OFObject_Serialization_reference; @implementation OFObject (Serialization) - (OFString*)stringBySerializing { - OFAutoreleasePool *pool; + void *pool; OFXMLElement *element; OFXMLElement *root; OFString *ret; if (![self conformsToProtocol: @protocol(OFSerialization)]) @throw [OFNotImplementedException exceptionWithClass: [self class] selector: @selector(stringBySerializing)]; - pool = [[OFAutoreleasePool alloc] init]; + pool = objc_autoreleasePoolPush(); element = [(id)self XMLElementBySerializing]; root = [OFXMLElement elementWithName: @"serialization" namespace: OF_SERIALIZATION_NS]; [root addAttributeWithName: @"version" @@ -51,11 +52,11 @@ ret = [@"\n" stringByAppendingString: [root XMLStringWithIndentation: 2]]; [ret retain]; - [pool release]; - [ret autorelease]; + + objc_autoreleasePoolPop(pool); - return ret; + return [ret autorelease]; } @end Index: src/OFObject.m ================================================================== --- src/OFObject.m +++ src/OFObject.m @@ -29,11 +29,10 @@ #ifdef __QNX__ # include #endif #import "OFObject.h" -#import "OFAutoreleasePool.h" #import "OFAllocFailedException.h" #import "OFEnumerationMutationException.h" #import "OFInitializationFailedException.h" #import "OFInvalidArgumentException.h" @@ -40,10 +39,11 @@ #import "OFMemoryNotPartOfObjectException.h" #import "OFNotImplementedException.h" #import "OFOutOfMemoryException.h" #import "OFOutOfRangeException.h" +#import "autorelease.h" #import "macros.h" #if defined(OF_APPLE_RUNTIME) && __OBJC2__ # import #elif defined(OF_OBJFW_RUNTIME) @@ -84,11 +84,10 @@ #define PRE_MEM(mem) ((struct pre_mem*)(void*)((char*)mem - PRE_MEM_ALIGN)) static struct { Class isa; } alloc_failed_exception; -static Class autoreleasePool = Nil; static SEL cxx_construct = NULL; static SEL cxx_destruct = NULL; size_t of_pagesize; @@ -811,18 +810,11 @@ #endif } - autorelease { - /* - * Cache OFAutoreleasePool since class lookups are expensive with the - * GNU ABI used by GCC. - */ - if (autoreleasePool == Nil) - autoreleasePool = [OFAutoreleasePool class]; - - return [autoreleasePool addObject: self]; + return _objc_rootAutorelease(self); } - self { return self; Index: src/OFPlugin.m ================================================================== --- src/OFPlugin.m +++ src/OFPlugin.m @@ -23,14 +23,15 @@ #include #endif #import "OFPlugin.h" #import "OFString.h" -#import "OFAutoreleasePool.h" #import "OFInitializationFailedException.h" #import "OFNotImplementedException.h" + +#import "autorelease.h" #ifdef _WIN32 # define dlopen(file, mode) LoadLibrary(file) # define dlsym(handle, symbol) GetProcAddress(handle, symbol) # define dlclose(handle) FreeLibrary(handle) @@ -37,26 +38,25 @@ #endif @implementation OFPlugin + (id)pluginFromFile: (OFString*)path { - OFAutoreleasePool *pool; + void *pool = objc_autoreleasePoolPush(); OFMutableString *file; of_plugin_handle_t handle; OFPlugin *(*initPlugin)(void); OFPlugin *plugin; - pool = [[OFAutoreleasePool alloc] init]; file = [OFMutableString stringWithString: path]; [file appendString: @PLUGIN_SUFFIX]; if ((handle = dlopen([file cStringWithEncoding: OF_STRING_ENCODING_NATIVE], RTLD_LAZY)) == NULL) @throw [OFInitializationFailedException exceptionWithClass: self]; - [pool release]; + objc_autoreleasePoolPop(pool); *(void**)&initPlugin = dlsym(handle, "init_plugin"); if (initPlugin == NULL || (plugin = initPlugin()) == nil) { dlclose(handle); @throw [OFInitializationFailedException Index: src/OFProcess.m ================================================================== --- src/OFProcess.m +++ src/OFProcess.m @@ -24,19 +24,20 @@ #endif #import "OFProcess.h" #import "OFString.h" #import "OFArray.h" -#import "OFAutoreleasePool.h" #import "OFInitializationFailedException.h" #import "OFReadFailedException.h" #import "OFWriteFailedException.h" #ifdef _WIN32 # include #endif + +#import "autorelease.h" @implementation OFProcess + processWithProgram: (OFString*)program { return [[[self alloc] initWithProgram: program] autorelease]; @@ -123,11 +124,11 @@ } #else SECURITY_ATTRIBUTES sa; PROCESS_INFORMATION pi; STARTUPINFO si; - OFAutoreleasePool *pool; + void *pool; OFMutableString *argumentsString; OFEnumerator *enumerator; OFString *argument; char *argumentsCString; @@ -158,11 +159,11 @@ si.hStdInput = writePipe[0]; si.hStdOutput = readPipe[1]; si.hStdError = GetStdHandle(STD_ERROR_HANDLE); si.dwFlags |= STARTF_USESTDHANDLES; - pool = [[OFAutoreleasePool alloc] init]; + pool = objc_autoreleasePoolPush(); argumentsString = [OFMutableString stringWithString: programName]; [argumentsString replaceOccurrencesOfString: @"\\\"" withString: @"\\\\\""]; @@ -206,11 +207,11 @@ exceptionWithClass: [self class]]; } @finally { free(argumentsString); } - [pool release]; + objc_autoreleasePoolPop(pool); CloseHandle(pi.hProcess); CloseHandle(pi.hThread); CloseHandle(readPipe[1]); Index: src/OFSet.m ================================================================== --- src/OFSet.m +++ src/OFSet.m @@ -18,13 +18,14 @@ #import "OFSet.h" #import "OFSet_hashtable.h" #import "OFString.h" #import "OFXMLElement.h" -#import "OFAutoreleasePool.h" #import "OFNotImplementedException.h" + +#import "autorelease.h" static struct { Class isa; } placeholder; @@ -259,56 +260,57 @@ return [otherSet isSubsetOfSet: self]; } - (uint32_t)hash { - OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; + void *pool = objc_autoreleasePoolPush(); OFEnumerator *enumerator = [self objectEnumerator]; id object; uint32_t hash = 0; while ((object = [enumerator nextObject]) != nil) hash += [object hash]; - [pool release]; + objc_autoreleasePoolPop(pool); return hash; } - (OFString*)description { + void *pool; OFMutableString *ret; - OFAutoreleasePool *pool, *pool2; OFEnumerator *enumerator; size_t i, count = [self count]; id object; if (count == 0) return @"{()}"; ret = [OFMutableString stringWithString: @"{(\n"]; - pool = [[OFAutoreleasePool alloc] init]; + + pool = objc_autoreleasePoolPush(); enumerator = [self objectEnumerator]; i = 0; - pool2 = [[OFAutoreleasePool alloc] init]; - while ((object = [enumerator nextObject]) != nil) { + void *pool2 = objc_autoreleasePoolPush(); + [ret appendString: [object description]]; if (++i < count) [ret appendString: @",\n"]; - [pool2 releaseObjects]; + objc_autoreleasePoolPop(pool2); } [ret replaceOccurrencesOfString: @"\n" withString: @"\n\t"]; [ret appendString: @"\n)}"]; [ret makeImmutable]; - [pool release]; + objc_autoreleasePoolPop(pool); return ret; } - copy @@ -321,48 +323,47 @@ return [[OFMutableSet alloc] initWithSet: self]; } - (BOOL)isSubsetOfSet: (OFSet*)set { - OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; + void *pool = objc_autoreleasePoolPush(); OFEnumerator *enumerator = [self objectEnumerator]; id object; while ((object = [enumerator nextObject]) != nil) { if (![set containsObject: object]) { - [pool release]; + objc_autoreleasePoolPop(pool); return NO; } } - [pool release]; + objc_autoreleasePoolPop(pool); return YES; } - (BOOL)intersectsSet: (OFSet*)set { - OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; + void *pool = objc_autoreleasePoolPush(); OFEnumerator *enumerator = [self objectEnumerator]; id object; while ((object = [enumerator nextObject]) != nil) { if ([set containsObject: object]) { - [pool release]; + objc_autoreleasePoolPop(pool); return YES; } } - [pool release]; + objc_autoreleasePoolPop(pool); return NO; } - (OFXMLElement*)XMLElementBySerializing { - OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; - OFAutoreleasePool *pool2; + void *pool = objc_autoreleasePoolPush(); OFXMLElement *element; OFEnumerator *enumerator; id object; if ([self isKindOfClass: [OFMutableSet class]]) @@ -372,22 +373,23 @@ element = [OFXMLElement elementWithName: @"OFSet" namespace: OF_SERIALIZATION_NS]; enumerator = [self objectEnumerator]; - pool2 = [[OFAutoreleasePool alloc] init]; while ((object = [enumerator nextObject]) != nil) { + void *pool2 = objc_autoreleasePoolPush(); + [element addChild: [object XMLElementBySerializing]]; - [pool2 releaseObjects]; + objc_autoreleasePoolPop(pool2); } [element retain]; - [pool release]; - [element autorelease]; + + objc_autoreleasePoolPop(pool); - return element; + return [element autorelease]; } #if defined(OF_HAVE_BLOCKS) && defined(OF_HAVE_FAST_ENUMERATION) - (void)enumerateObjectsUsingBlock: (of_set_enumeration_block_t)block { Index: src/OFSet_hashtable.m ================================================================== --- src/OFSet_hashtable.m +++ src/OFSet_hashtable.m @@ -24,13 +24,14 @@ #import "OFMutableDictionary_hashtable.h" #import "OFArray.h" #import "OFString.h" #import "OFNumber.h" #import "OFXMLElement.h" -#import "OFAutoreleasePool.h" #import "OFInvalidArgumentException.h" + +#import "autorelease.h" @implementation OFSet_hashtable - init { self = [super init]; @@ -48,11 +49,11 @@ - initWithSet: (OFSet*)set { self = [self init]; @try { - OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; + void *pool = objc_autoreleasePoolPush(); OFNumber *one = [OFNumber numberWithSize: 1]; OFEnumerator *enumerator = [set objectEnumerator]; id object; /* @@ -62,11 +63,11 @@ while ((object = [enumerator nextObject]) != nil) [dictionary _setObject: one forKey: object copyKey: NO]; - [pool release]; + objc_autoreleasePoolPop(pool); } @catch (id e) { [self release]; @throw e; } @@ -76,21 +77,21 @@ - initWithArray: (OFArray*)array { self = [self init]; @try { - OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; + void *pool = objc_autoreleasePoolPush(); OFNumber *one = [OFNumber numberWithSize: 1]; id *objects = [array objects]; size_t i, count = [array count]; for (i = 0; i < count; i++) [dictionary _setObject: one forKey: objects[i] copyKey: NO]; - [pool release]; + objc_autoreleasePoolPop(pool); } @catch (id e) { [self release]; @throw e; } @@ -101,20 +102,20 @@ count: (size_t)count { self = [self init]; @try { - OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; + void *pool = objc_autoreleasePoolPush(); OFNumber *one = [OFNumber numberWithSize: 1]; size_t i; for (i = 0; i < count; i++) [dictionary _setObject: one forKey: objects[i] copyKey: NO]; - [pool release]; + objc_autoreleasePoolPop(pool); } @catch (id e) { [self release]; @throw e; } @@ -125,11 +126,11 @@ arguments: (va_list)arguments { self = [self init]; @try { - OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; + void *pool = objc_autoreleasePoolPush(); OFNumber *one = [OFNumber numberWithSize: 1]; id object; [dictionary _setObject: one forKey: firstObject @@ -138,11 +139,11 @@ while ((object = va_arg(arguments, id)) != nil) [dictionary _setObject: one forKey: object copyKey: NO]; - [pool release]; + objc_autoreleasePoolPop(pool); } @catch (id e) { [self release]; @throw e; } @@ -152,17 +153,15 @@ - initWithSerialization: (OFXMLElement*)element { self = [self init]; @try { - OFAutoreleasePool *pool, *pool2; + void *pool = objc_autoreleasePoolPush(); OFNumber *one; OFEnumerator *enumerator; OFXMLElement *child; - pool = [[OFAutoreleasePool alloc] init]; - if ((![[element name] isEqual: @"OFSet"] && ![[element name] isEqual: @"OFMutableSet"]) || ![[element namespace] isEqual: OF_SERIALIZATION_NS]) @throw [OFInvalidArgumentException exceptionWithClass: [self class] @@ -170,21 +169,21 @@ one = [OFNumber numberWithSize: 1]; enumerator = [[element elementsForNamespace: OF_SERIALIZATION_NS] objectEnumerator]; - pool2 = [[OFAutoreleasePool alloc] init]; - while ((child = [enumerator nextObject]) != nil) { + void *pool2 = objc_autoreleasePoolPush(); + [dictionary _setObject: one forKey: [child objectByDeserializing] copyKey: NO]; - [pool2 releaseObjects]; + objc_autoreleasePoolPop(pool2); } - [pool release]; + objc_autoreleasePoolPop(pool); } @catch (id e) { [self release]; @throw e; } Index: src/OFStreamObserver.m ================================================================== --- src/OFStreamObserver.m +++ src/OFStreamObserver.m @@ -30,11 +30,10 @@ #import "OFDataArray.h" #ifdef _WIN32 # import "OFTCPSocket.h" #endif #import "OFThread.h" -#import "OFAutoreleasePool.h" #ifdef HAVE_KQUEUE # import "OFStreamObserver_kqueue.h" #endif #ifdef HAVE_POLL_H @@ -46,10 +45,11 @@ #import "OFInitializationFailedException.h" #import "OFNotImplementedException.h" #import "OFOutOfRangeException.h" +#import "autorelease.h" #import "macros.h" enum { QUEUE_ADD = 0, QUEUE_REMOVE = 1, @@ -376,28 +376,26 @@ selector: _cmd]; } - (BOOL)_processCache { - OFAutoreleasePool *pool; OFStream **objects = [readStreams objects]; size_t i, count = [readStreams count]; BOOL foundInCache = NO; - pool = [[OFAutoreleasePool alloc] init]; for (i = 0; i < count; i++) { + if ([objects[i] pendingBytes] > 0 && ![objects[i] _isWaitingForDelimiter]) { + void *pool = objc_autoreleasePoolPush(); [delegate streamIsReadyForReading: objects[i]]; foundInCache = YES; - [pool releaseObjects]; + objc_autoreleasePoolPop(pool); } } - [pool release]; - /* * As long as we have data in the cache for any stream, we don't want * to block. */ if (foundInCache) Index: src/OFStreamObserver_kqueue.m ================================================================== --- src/OFStreamObserver_kqueue.m +++ src/OFStreamObserver_kqueue.m @@ -25,15 +25,15 @@ #include #include #import "OFStreamObserver_kqueue.h" #import "OFDataArray.h" -#import "OFAutoreleasePool.h" #import "OFInitializationFailedException.h" #import "OFOutOfMemoryException.h" +#import "autorelease.h" #import "macros.h" #define EVENTLIST_SIZE 64 @implementation OFStreamObserver_kqueue @@ -98,80 +98,77 @@ [changeList addItem: &event]; } - (BOOL)observeWithTimeout: (int)timeout { - OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; + void *pool = objc_autoreleasePoolPush(); struct timespec timespec = { timeout, 0 }; struct kevent eventList[EVENTLIST_SIZE]; int i, events; [self _processQueue]; if ([self _processCache]) { - [pool release]; + objc_autoreleasePoolPop(pool); return YES; } + + objc_autoreleasePoolPop(pool); events = kevent(kernelQueue, [changeList cArray], (int)[changeList count], eventList, EVENTLIST_SIZE, (timeout == -1 ? NULL : ×pec)); if (events == -1) { switch (errno) { case EINTR: - [pool release]; return NO; case ENOMEM: - [pool release]; @throw [OFOutOfMemoryException exceptionWithClass: [self class]]; default: assert(0); } } [changeList removeAllItems]; - if (events == 0) { - [pool release]; + if (events == 0) return NO; - } for (i = 0; i < events; i++) { if (eventList[i].ident == cancelFD[0]) { char buffer; OF_ENSURE(read(cancelFD[0], &buffer, 1) > 0); continue; } + + pool = objc_autoreleasePoolPush(); if (eventList[i].flags & EV_ERROR) { [delegate streamDidReceiveException: FDToStream[eventList[i].ident]]; - [pool releaseObjects]; + objc_autoreleasePoolPop(pool); continue; } switch (eventList[i].filter) { case EVFILT_READ: [delegate streamIsReadyForReading: FDToStream[eventList[i].ident]]; - [pool releaseObjects]; break; case EVFILT_WRITE: [delegate streamIsReadyForWriting: FDToStream[eventList[i].ident]]; - [pool releaseObjects]; break; default: assert(0); } + objc_autoreleasePoolPop(pool); } - [pool release]; - return YES; } @end Index: src/OFStreamObserver_poll.m ================================================================== --- src/OFStreamObserver_poll.m +++ src/OFStreamObserver_poll.m @@ -21,14 +21,14 @@ #include #include #import "OFStreamObserver_poll.h" #import "OFDataArray.h" -#import "OFAutoreleasePool.h" #import "OFOutOfRangeException.h" +#import "autorelease.h" #import "macros.h" @implementation OFStreamObserver_poll - init { @@ -120,65 +120,65 @@ withEvents: POLLOUT]; } - (BOOL)observeWithTimeout: (int)timeout { - OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; + void *pool = objc_autoreleasePoolPush(); struct pollfd *FDsCArray; size_t i, nFDs; [self _processQueue]; if ([self _processCache]) { - [pool release]; + objc_autoreleasePoolPop(pool); return YES; } + + objc_autoreleasePoolPop(pool); FDsCArray = [FDs cArray]; nFDs = [FDs count]; #ifdef OPEN_MAX if (nFDs > OPEN_MAX) @throw [OFOutOfRangeException exceptionWithClass: [self class]]; #endif - if (poll(FDsCArray, (nfds_t)nFDs, timeout) < 1) { - [pool release]; + if (poll(FDsCArray, (nfds_t)nFDs, timeout) < 1) return NO; - } for (i = 0; i < nFDs; i++) { + pool = objc_autoreleasePoolPush(); + if (FDsCArray[i].revents & POLLIN) { if (FDsCArray[i].fd == cancelFD[0]) { char buffer; OF_ENSURE(read(cancelFD[0], &buffer, 1) > 0); FDsCArray[i].revents = 0; + objc_autoreleasePoolPop(pool); continue; } [delegate streamIsReadyForReading: FDToStream[FDsCArray[i].fd]]; - [pool releaseObjects]; } if (FDsCArray[i].revents & POLLOUT) { [delegate streamIsReadyForWriting: FDToStream[FDsCArray[i].fd]]; - [pool releaseObjects]; } if (FDsCArray[i].revents & POLLERR) { [delegate streamDidReceiveException: FDToStream[FDsCArray[i].fd]]; - [pool releaseObjects]; } FDsCArray[i].revents = 0; - } - [pool release]; + objc_autoreleasePoolPop(pool); + } return YES; } @end Index: src/OFStreamObserver_select.m ================================================================== --- src/OFStreamObserver_select.m +++ src/OFStreamObserver_select.m @@ -22,12 +22,12 @@ #include #import "OFStreamObserver_select.h" #import "OFStream.h" #import "OFArray.h" -#import "OFAutoreleasePool.h" +#import "autorelease.h" #import "macros.h" @implementation OFStreamObserver_select - init { @@ -69,11 +69,11 @@ FD_CLR(fd, &exceptFDs); } - (BOOL)observeWithTimeout: (int)timeout { - OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; + void *pool = objc_autoreleasePoolPush(); OFStream **objects; fd_set readFDs_; fd_set writeFDs_; fd_set exceptFDs_; struct timeval time; @@ -80,13 +80,15 @@ size_t i, count; [self _processQueue]; if ([self _processCache]) { - [pool release]; + objc_autoreleasePoolPop(pool); return YES; } + + objc_autoreleasePoolPop(pool); #ifdef FD_COPY FD_COPY(&readFDs, &readFDs_); FD_COPY(&writeFDs, &writeFDs_); FD_COPY(&exceptFDs, &exceptFDs_); @@ -98,14 +100,12 @@ time.tv_sec = timeout / 1000; time.tv_usec = (timeout % 1000) * 1000; if (select((int)maxFD + 1, &readFDs_, &writeFDs_, &exceptFDs_, - (timeout != -1 ? &time : NULL)) < 1) { - [pool release]; + (timeout != -1 ? &time : NULL)) < 1) return NO; - } if (FD_ISSET(cancelFD[0], &readFDs_)) { char buffer; #ifndef _WIN32 OF_ENSURE(read(cancelFD[0], &buffer, 1) > 0); @@ -118,44 +118,43 @@ count = [readStreams count]; for (i = 0; i < count; i++) { int fileDescriptor = [objects[i] fileDescriptor]; - if (FD_ISSET(fileDescriptor, &readFDs_)) { + pool = objc_autoreleasePoolPush(); + + if (FD_ISSET(fileDescriptor, &readFDs_)) [delegate streamIsReadyForReading: objects[i]]; - [pool releaseObjects]; - } if (FD_ISSET(fileDescriptor, &exceptFDs_)) { [delegate streamDidReceiveException: objects[i]]; - [pool releaseObjects]; /* * Prevent calling it twice in case the FD is in both * sets. */ FD_CLR(fileDescriptor, &exceptFDs_); } + + objc_autoreleasePoolPop(pool); } objects = [writeStreams objects]; count = [writeStreams count]; for (i = 0; i < count; i++) { int fileDescriptor = [objects[i] fileDescriptor]; - if (FD_ISSET(fileDescriptor, &writeFDs_)) { + pool = objc_autoreleasePoolPush(); + + if (FD_ISSET(fileDescriptor, &writeFDs_)) [delegate streamIsReadyForWriting: objects[i]]; - [pool releaseObjects]; - } - if (FD_ISSET(fileDescriptor, &exceptFDs_)) { + if (FD_ISSET(fileDescriptor, &exceptFDs_)) [delegate streamDidReceiveException: objects[i]]; - [pool releaseObjects]; - } - } - [pool release]; + objc_autoreleasePoolPop(pool); + } return YES; } @end Index: src/OFString+Hashing.m ================================================================== --- src/OFString+Hashing.m +++ src/OFString+Hashing.m @@ -17,18 +17,19 @@ #include "config.h" #import "OFString.h" #import "OFMD5Hash.h" #import "OFSHA1Hash.h" -#import "OFAutoreleasePool.h" + +#import "autorelease.h" int _OFString_Hashing_reference; @implementation OFString (Hashing) - (OFString*)MD5Hash { - OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; + void *pool = objc_autoreleasePoolPush(); OFMD5Hash *hash = [OFMD5Hash hash]; uint8_t *digest; char ret[OF_MD5_DIGEST_SIZE * 2]; size_t i; @@ -44,20 +45,20 @@ ret[i * 2] = (high > 9 ? high - 10 + 'a' : high + '0'); ret[i * 2 + 1] = (low > 9 ? low - 10 + 'a' : low + '0'); } - [pool release]; + objc_autoreleasePoolPop(pool); return [OFString stringWithCString: ret encoding: OF_STRING_ENCODING_ASCII length: 32]; } - (OFString*)SHA1Hash { - OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; + void *pool = objc_autoreleasePoolPush(); OFMD5Hash *hash = [OFSHA1Hash hash]; uint8_t *digest; char ret[OF_SHA1_DIGEST_SIZE * 2]; size_t i; @@ -73,12 +74,12 @@ ret[i * 2] = (high > 9 ? high - 10 + 'a' : high + '0'); ret[i * 2 + 1] = (low > 9 ? low - 10 + 'a' : low + '0'); } - [pool release]; + objc_autoreleasePoolPop(pool); return [OFString stringWithCString: ret encoding: OF_STRING_ENCODING_ASCII length: 40]; } @end Index: src/OFString+Serialization.m ================================================================== --- src/OFString+Serialization.m +++ src/OFString+Serialization.m @@ -20,23 +20,24 @@ #import "OFString+Serialization.h" #import "OFSerialization.h" #import "OFArray.h" #import "OFXMLElement.h" #import "OFXMLAttribute.h" -#import "OFAutoreleasePool.h" #import "OFInvalidArgumentException.h" #import "OFMalformedXMLException.h" #import "OFUnboundNamespaceException.h" #import "OFUnsupportedVersionException.h" + +#import "autorelease.h" int _OFString_Serialization_reference; @implementation OFString (Serialization) - (id)objectByDeserializing { - OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; + void *pool = objc_autoreleasePoolPush(); OFXMLElement *root; OFString *version; OFArray *elements; id object; @@ -68,14 +69,12 @@ if ([elements count] != 1) @throw [OFInvalidArgumentException exceptionWithClass: [self class] selector: _cmd]; - object = [[elements firstObject] objectByDeserializing]; + object = [[[elements firstObject] objectByDeserializing] retain]; + + objc_autoreleasePoolPop(pool); - [object retain]; - [pool release]; - [object autorelease]; - - return object; + return [object autorelease]; } @end Index: src/OFString+XMLUnescaping.m ================================================================== --- src/OFString+XMLUnescaping.m +++ src/OFString+XMLUnescaping.m @@ -17,14 +17,14 @@ #include "config.h" #include #import "OFString.h" -#import "OFAutoreleasePool.h" #import "OFInvalidEncodingException.h" +#import "autorelease.h" #import "macros.h" int _OFString_XMLUnescaping_reference; static OF_INLINE OFString* @@ -129,28 +129,28 @@ else if (entityLength == 3 && !memcmp(entity, "amp", 3)) [ret appendCString: "&" withEncoding: OF_STRING_ENCODING_ASCII length: 1]; else if (entity[0] == '#') { - OFAutoreleasePool *pool; + void *pool; OFString *tmp; - pool = [[OFAutoreleasePool alloc] init]; + pool = objc_autoreleasePoolPush(); tmp = parse_numeric_entity(entity, entityLength); if (tmp == nil) @throw [OFInvalidEncodingException exceptionWithClass: [self class]]; [ret appendString: tmp]; - [pool release]; + objc_autoreleasePoolPop(pool); } else if (delegate != nil) { - OFAutoreleasePool *pool; + void *pool; OFString *n, *tmp; - pool = [[OFAutoreleasePool alloc] init]; + pool = objc_autoreleasePoolPush(); n = [OFString stringWithUTF8String: entity length: entityLength]; tmp = [delegate string: self @@ -159,11 +159,11 @@ if (tmp == nil) @throw [OFInvalidEncodingException exceptionWithClass: [self class]]; [ret appendString: tmp]; - [pool release]; + objc_autoreleasePoolPop(pool); } else @throw [OFInvalidEncodingException exceptionWithClass: [self class]]; last = i + 1; @@ -232,28 +232,28 @@ else if (entityLength == 3 && !memcmp(entity, "amp", 3)) [ret appendCString: "&" withEncoding: OF_STRING_ENCODING_ASCII length: 1]; else if (entity[0] == '#') { - OFAutoreleasePool *pool; + void *pool; OFString *tmp; - pool = [[OFAutoreleasePool alloc] init]; + pool = objc_autoreleasePoolPush(); tmp = parse_numeric_entity(entity, entityLength); if (tmp == nil) @throw [OFInvalidEncodingException exceptionWithClass: [self class]]; [ret appendString: tmp]; - [pool release]; + objc_autoreleasePoolPop(pool); } else { - OFAutoreleasePool *pool; + void *pool; OFString *entityString, *tmp; - pool = [[OFAutoreleasePool alloc] init]; + pool = objc_autoreleasePoolPush(); entityString = [OFString stringWithUTF8String: entity length: entityLength]; tmp = block(self, entityString); @@ -261,11 +261,11 @@ if (tmp == nil) @throw [OFInvalidEncodingException exceptionWithClass: [self class]]; [ret appendString: tmp]; - [pool release]; + objc_autoreleasePoolPop(pool); } last = i + 1; inEntity = NO; } Index: src/OFString.m ================================================================== --- src/OFString.m +++ src/OFString.m @@ -29,11 +29,10 @@ #import "OFFile.h" #import "OFURL.h" #import "OFHTTPRequest.h" #import "OFDataArray.h" #import "OFXMLElement.h" -#import "OFAutoreleasePool.h" #import "OFHTTPRequestFailedException.h" #import "OFInitializationFailedException.h" #import "OFInvalidArgumentException.h" #import "OFInvalidEncodingException.h" @@ -41,10 +40,11 @@ #import "OFNotImplementedException.h" #import "OFOpenFileFailedException.h" #import "OFOutOfMemoryException.h" #import "OFOutOfRangeException.h" +#import "autorelease.h" #import "macros.h" #import "of_asprintf.h" #import "unicode.h" /* @@ -871,28 +871,28 @@ } - initWithContentsOfURL: (OFURL*)URL encoding: (of_string_encoding_t)encoding { - OFAutoreleasePool *pool; + void *pool; OFHTTPRequest *request; OFHTTPRequestResult *result; OFString *contentType; Class c; c = [self class]; [self release]; - pool = [[OFAutoreleasePool alloc] init]; + pool = objc_autoreleasePoolPush(); if ([[URL scheme] isEqual: @"file"]) { if (encoding == OF_STRING_ENCODING_AUTODETECT) encoding = OF_STRING_ENCODING_UTF_8; self = [[c alloc] initWithContentsOfFile: [URL path] encoding: encoding]; - [pool release]; + objc_autoreleasePoolPop(pool); return self; } request = [OFHTTPRequest requestWithURL: URL]; result = [request perform]; @@ -922,18 +922,18 @@ self = [[c alloc] initWithCString: (char*)[[result data] cArray] encoding: encoding length: [[result data] count]]; - [pool release]; + objc_autoreleasePoolPop(pool); return self; } - initWithSerialization: (OFXMLElement*)element { @try { - OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; + void *pool = objc_autoreleasePoolPush(); if (![[element namespace] isEqual: OF_SERIALIZATION_NS]) @throw [OFInvalidArgumentException exceptionWithClass: [self class] selector: _cmd]; @@ -950,11 +950,11 @@ selector: _cmd]; } self = [self initWithString: [element stringValue]]; - [pool release]; + objc_autoreleasePoolPop(pool); } @catch (id e) { [self release]; @throw e; } @@ -1082,11 +1082,11 @@ buffer[i] = [self characterAtIndex: range.start + i]; } - (BOOL)isEqual: (id)object { - OFAutoreleasePool *pool; + void *pool; OFString *otherString; const of_unichar_t *unicodeString, *otherUnicodeString; size_t length; if (object == self) @@ -1099,22 +1099,22 @@ length = [self length]; if ([otherString length] != length) return NO; - pool = [[OFAutoreleasePool alloc] init]; + pool = objc_autoreleasePoolPush(); unicodeString = [self unicodeString]; otherUnicodeString = [otherString unicodeString]; if (memcmp(unicodeString, otherUnicodeString, length * sizeof(of_unichar_t))) { - [pool release]; + objc_autoreleasePoolPop(pool); return NO; } - [pool release]; + objc_autoreleasePoolPop(pool); return YES; } - copy @@ -1127,11 +1127,11 @@ return [[OFMutableString alloc] initWithString: self]; } - (of_comparison_result_t)compare: (id)object { - OFAutoreleasePool *pool; + void *pool; OFString *otherString; const of_unichar_t *unicodeString, *otherUnicodeString; size_t i, minimumLength; if (object == self) @@ -1144,28 +1144,28 @@ otherString = object; minimumLength = ([self length] > [otherString length] ? [otherString length] : [self length]); - pool = [[OFAutoreleasePool alloc] init]; + pool = objc_autoreleasePoolPush(); unicodeString = [self unicodeString]; otherUnicodeString = [otherString unicodeString]; for (i = 0; i < minimumLength; i++) { if (unicodeString[i] > otherUnicodeString[i]) { - [pool release]; + objc_autoreleasePoolPop(pool); return OF_ORDERED_DESCENDING; } if (unicodeString[i] < otherUnicodeString[i]) { - [pool release]; + objc_autoreleasePoolPop(pool); return OF_ORDERED_ASCENDING; } } - [pool release]; + objc_autoreleasePoolPop(pool); if ([self length] > [otherString length]) return OF_ORDERED_DESCENDING; if ([self length] < [otherString length]) return OF_ORDERED_ASCENDING; @@ -1173,11 +1173,11 @@ return OF_ORDERED_SAME; } - (of_comparison_result_t)caseInsensitiveCompare: (OFString*)otherString { - OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; + void *pool = objc_autoreleasePoolPush(); const of_unichar_t *string, *otherUnicodeString; size_t i, length, otherLength, minimumLength; if (otherString == self) return OF_ORDERED_SAME; @@ -1208,20 +1208,20 @@ if (tc) oc = tc; } if (c > oc) { - [pool release]; + objc_autoreleasePoolPop(pool); return OF_ORDERED_DESCENDING; } if (c < oc) { - [pool release]; + objc_autoreleasePoolPop(pool); return OF_ORDERED_ASCENDING; } } - [pool release]; + objc_autoreleasePoolPop(pool); if (length > otherLength) return OF_ORDERED_DESCENDING; if (length < otherLength) return OF_ORDERED_ASCENDING; @@ -1255,11 +1255,11 @@ return [[self copy] autorelease]; } - (OFXMLElement*)XMLElementBySerializing { - OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; + void *pool = objc_autoreleasePoolPush(); OFXMLElement *element; OFString *className; if ([self isKindOfClass: [OFMutableString class]]) className = @"OFMutableString"; @@ -1269,14 +1269,14 @@ element = [OFXMLElement elementWithName: className namespace: OF_SERIALIZATION_NS stringValue: self]; [element retain]; - [pool release]; - [element autorelease]; - return element; + objc_autoreleasePoolPop(pool); + + return [element autorelease]; } - (OFString*)JSONRepresentation { OFMutableString *JSON = [[self mutableCopy] autorelease]; @@ -1305,116 +1305,116 @@ return JSON; } - (size_t)indexOfFirstOccurrenceOfString: (OFString*)string { - OFAutoreleasePool *pool; + void *pool; const of_unichar_t *unicodeString, *searchString; size_t i, length, searchLength; if ((searchLength = [string length]) == 0) return [self length]; if (searchLength > (length = [self length])) return OF_INVALID_INDEX; - pool = [[OFAutoreleasePool alloc] init]; + pool = objc_autoreleasePoolPush(); unicodeString = [self unicodeString]; searchString = [string unicodeString]; for (i = 0; i <= length - searchLength; i++) { if (!memcmp(unicodeString + i, searchString, searchLength * sizeof(of_unichar_t))) { - [pool release]; + objc_autoreleasePoolPop(pool); return i; } } - [pool release]; + objc_autoreleasePoolPop(pool); return OF_INVALID_INDEX; } - (size_t)indexOfLastOccurrenceOfString: (OFString*)string { - OFAutoreleasePool *pool; + void *pool; const of_unichar_t *unicodeString, *searchString; size_t i, length, searchLength; if ((searchLength = [string length]) == 0) return [self length]; if (searchLength > (length = [self length])) return OF_INVALID_INDEX; - pool = [[OFAutoreleasePool alloc] init]; + pool = objc_autoreleasePoolPush(); unicodeString = [self unicodeString]; searchString = [string unicodeString]; for (i = length - searchLength;; i--) { if (!memcmp(unicodeString + i, searchString, searchLength * sizeof(of_unichar_t))) { - [pool release]; + objc_autoreleasePoolPop(pool); return i; } /* Did not match and we're at the last character */ if (i == 0) break; } - [pool release]; + objc_autoreleasePoolPop(pool); return OF_INVALID_INDEX; } - (BOOL)containsString: (OFString*)string { - OFAutoreleasePool *pool; + void *pool; const of_unichar_t *unicodeString, *searchString; size_t i, length, searchLength; if ((searchLength = [string length]) == 0) return YES; if (searchLength > (length = [self length])) return NO; - pool = [[OFAutoreleasePool alloc] init]; + pool = objc_autoreleasePoolPush(); unicodeString = [self unicodeString]; searchString = [string unicodeString]; for (i = 0; i <= length - searchLength; i++) { if (!memcmp(unicodeString + i, searchString, searchLength * sizeof(of_unichar_t))) { - [pool release]; + objc_autoreleasePoolPop(pool); return YES; } } - [pool release]; + objc_autoreleasePoolPop(pool); return NO; } - (OFString*)substringWithRange: (of_range_t)range { - OFAutoreleasePool *pool; + void *pool; OFString *ret; if (range.start + range.length > [self length]) @throw [OFOutOfRangeException exceptionWithClass: [self class]]; - pool = [[OFAutoreleasePool alloc] init]; + pool = objc_autoreleasePoolPush(); ret = [[OFString alloc] initWithUnicodeString: [self unicodeString] + range.start length: range.length]; - [pool release]; + objc_autoreleasePoolPop(pool); return [ret autorelease]; } - (OFString*)stringByAppendingString: (OFString*)string @@ -1550,22 +1550,20 @@ return NO; tmp = [self allocMemoryWithSize: sizeof(of_unichar_t) count: prefixLength]; @try { - OFAutoreleasePool *pool; + void *pool = objc_autoreleasePoolPush(); [self getCharacters: tmp inRange: of_range(0, prefixLength)]; - pool = [[OFAutoreleasePool alloc] init]; - prefixString = [prefix unicodeString]; compare = memcmp(tmp, prefixString, prefixLength * sizeof(of_unichar_t)); - [pool release]; + objc_autoreleasePoolPop(pool); } @finally { [self freeMemory: tmp]; } return !compare; @@ -1584,23 +1582,21 @@ length = [self length]; tmp = [self allocMemoryWithSize: sizeof(of_unichar_t) count: suffixLength]; @try { - OFAutoreleasePool *pool; + void *pool = objc_autoreleasePoolPush(); [self getCharacters: tmp inRange: of_range(length - suffixLength, suffixLength)]; - pool = [[OFAutoreleasePool alloc] init]; - suffixString = [suffix unicodeString]; compare = memcmp(tmp, suffixString, suffixLength * sizeof(of_unichar_t)); - [pool release]; + objc_autoreleasePoolPop(pool); } @finally { [self freeMemory: tmp]; } return !compare; @@ -1613,28 +1609,28 @@ } - (OFArray*)componentsSeparatedByString: (OFString*)delimiter skipEmpty: (BOOL)skipEmpty { - OFAutoreleasePool *pool; + void *pool; OFMutableArray *array = [OFMutableArray array]; const of_unichar_t *string, *delimiterString; size_t length = [self length]; size_t delimiterLength = [delimiter length]; size_t i, last; OFString *component; - pool = [[OFAutoreleasePool alloc] init]; + pool = objc_autoreleasePoolPush(); string = [self unicodeString]; delimiterString = [delimiter unicodeString]; if (delimiterLength > length) { [array addObject: [[self copy] autorelease]]; [array makeImmutable]; - [pool release]; + objc_autoreleasePoolPop(pool); return array; } for (i = 0, last = 0; i <= length - delimiterLength; i++) { @@ -1653,28 +1649,28 @@ if (!skipEmpty || ![component isEqual: @""]) [array addObject: component]; [array makeImmutable]; - [pool release]; + objc_autoreleasePoolPop(pool); return array; } - (OFArray*)pathComponents { OFMutableArray *ret; - OFAutoreleasePool *pool; + void *pool; const of_unichar_t *string; size_t i, last = 0, length = [self length]; ret = [OFMutableArray array]; if (length == 0) return ret; - pool = [[OFAutoreleasePool alloc] init]; + pool = objc_autoreleasePoolPush(); string = [self unicodeString]; #ifndef _WIN32 if (string[length - 1] == OF_PATH_DELIMITER) @@ -1698,26 +1694,26 @@ [ret addObject: [self substringWithRange: of_range(last, i - last)]]; [ret makeImmutable]; - [pool release]; + objc_autoreleasePoolPop(pool); return ret; } - (OFString*)lastPathComponent { - OFAutoreleasePool *pool; + void *pool; const of_unichar_t *string; size_t length = [self length]; ssize_t i; if (length == 0) return @""; - pool = [[OFAutoreleasePool alloc] init]; + pool = objc_autoreleasePoolPush(); string = [self unicodeString]; #ifndef _WIN32 if (string[length - 1] == OF_PATH_DELIMITER) @@ -1735,11 +1731,11 @@ i++; break; } } - [pool release]; + objc_autoreleasePoolPop(pool); /* * Only one component, but the trailing delimiter might have been * removed, so return a new string anyway. */ @@ -1749,18 +1745,18 @@ return [self substringWithRange: of_range(i, length - i)]; } - (OFString*)stringByDeletingLastPathComponent { - OFAutoreleasePool *pool; + void *pool; const of_unichar_t *string; size_t i, length = [self length]; if (length == 0) return @""; - pool = [[OFAutoreleasePool alloc] init]; + pool = objc_autoreleasePoolPush(); string = [self unicodeString]; #ifndef _WIN32 if (string[length - 1] == OF_PATH_DELIMITER) @@ -1768,42 +1764,42 @@ if (string[length - 1] == '/' || string[length - 1] == '\\') #endif length--; if (length == 0) { - [pool release]; + objc_autoreleasePoolPop(pool); return [self substringWithRange: of_range(0, 1)]; } for (i = length - 1; i >= 1; i--) { #ifndef _WIN32 if (string[i] == OF_PATH_DELIMITER) { #else if (string[i] == '/' || string[i] == '\\') { #endif - [pool release]; + objc_autoreleasePoolPop(pool); return [self substringWithRange: of_range(0, i)]; } } #ifndef _WIN32 if (string[0] == OF_PATH_DELIMITER) { #else if (string[0] == '/' || string[0] == '\\') { #endif - [pool release]; + objc_autoreleasePoolPop(pool); return [self substringWithRange: of_range(0, 1)]; } - [pool release]; + objc_autoreleasePoolPop(pool); return @"."; } - (intmax_t)decimalValue { - OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; + void *pool = objc_autoreleasePoolPush(); const of_unichar_t *string = [self unicodeString]; size_t length = [self length]; int i = 0; intmax_t value = 0; BOOL expectWhitespace = NO; @@ -1813,11 +1809,11 @@ string++; length--; } if (length == 0) { - [pool release]; + objc_autoreleasePoolPop(pool); return 0; } if (string[0] == '-' || string[0] == '+') i++; @@ -1849,18 +1845,18 @@ } if (string[0] == '-') value *= -1; - [pool release]; + objc_autoreleasePoolPop(pool); return value; } - (uintmax_t)hexadecimalValue { - OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; + void *pool = objc_autoreleasePoolPush(); const of_unichar_t *string = [self unicodeString]; size_t length = [self length]; int i = 0; uintmax_t value = 0; BOOL expectWhitespace = NO, foundValue = NO; @@ -1870,11 +1866,11 @@ string++; length--; } if (length == 0) { - [pool release]; + objc_autoreleasePoolPop(pool); return 0; } if (length >= 2 && string[0] == '0' && string[1] == 'x') i = 2; @@ -1920,18 +1916,18 @@ if (!foundValue) @throw [OFInvalidFormatException exceptionWithClass: [self class]]; - [pool release]; + objc_autoreleasePoolPop(pool); return value; } - (float)floatValue { - OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; + void *pool = objc_autoreleasePoolPush(); const char *cString = [self UTF8String]; char *endPointer = NULL; float value; while (*cString == ' ' || *cString == '\t' || *cString == '\n' || @@ -1947,18 +1943,18 @@ *endPointer != '\n' && *endPointer != '\r' && *endPointer != '\f') @throw [OFInvalidFormatException exceptionWithClass: [self class]]; - [pool release]; + objc_autoreleasePoolPop(pool); return value; } - (double)doubleValue { - OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; + void *pool = objc_autoreleasePoolPush(); const char *cString = [self UTF8String]; char *endPointer = NULL; double value; while (*cString == ' ' || *cString == '\t' || *cString == '\n' || @@ -1974,11 +1970,11 @@ *endPointer != '\n' && *endPointer != '\r' && *endPointer != '\f') @throw [OFInvalidFormatException exceptionWithClass: [self class]]; - [pool release]; + objc_autoreleasePoolPop(pool); return value; } - (const of_unichar_t*)unicodeString @@ -1997,11 +1993,11 @@ } - (const uint16_t*)UTF16String { OFObject *object = [[[OFObject alloc] init] autorelease]; - OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; + void *pool = objc_autoreleasePoolPush(); const of_unichar_t *unicodeString = [self unicodeString]; size_t length = [self length]; uint16_t *ret; size_t i, j; @@ -2034,59 +2030,59 @@ count: j + 1]; } @catch (OFOutOfMemoryException *e) { /* We don't care, as we only tried to make it smaller */ } - [pool release]; + objc_autoreleasePoolPop(pool); return ret; } - (void)writeToFile: (OFString*)path { - OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; + void *pool = objc_autoreleasePoolPush(); OFFile *file; file = [OFFile fileWithPath: path mode: @"wb"]; [file writeString: self]; - [pool release]; + objc_autoreleasePoolPop(pool); } #ifdef OF_HAVE_BLOCKS - (void)enumerateLinesUsingBlock: (of_string_line_enumeration_block_t)block { - OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init], *pool2; + void *pool = objc_autoreleasePoolPush(); const of_unichar_t *string = [self unicodeString]; size_t i, last = 0, length = [self length]; BOOL stop = NO, lastCarriageReturn = NO; - pool2 = [[OFAutoreleasePool alloc] init]; - for (i = 0; i < length && !stop; i++) { if (lastCarriageReturn && string[i] == '\n') { lastCarriageReturn = NO; last++; continue; } if (string[i] == '\n' || string[i] == '\r') { + void *pool2 = objc_autoreleasePoolPush(); + block([self substringWithRange: of_range(last, i - last)], &stop); last = i + 1; - [pool2 releaseObjects]; + objc_autoreleasePoolPop(pool2); } lastCarriageReturn = (string[i] == '\r'); } if (!stop) block([self substringWithRange: of_range(last, i - last)], &stop); - [pool release]; + objc_autoreleasePoolPop(pool); } #endif @end Index: src/OFString_UTF8.m ================================================================== --- src/OFString_UTF8.m +++ src/OFString_UTF8.m @@ -24,20 +24,20 @@ #include #import "OFString_UTF8.h" #import "OFMutableString_UTF8.h" #import "OFArray.h" -#import "OFAutoreleasePool.h" #import "OFInitializationFailedException.h" #import "OFInvalidArgumentException.h" #import "OFInvalidEncodingException.h" #import "OFInvalidFormatException.h" #import "OFNotImplementedException.h" #import "OFOutOfMemoryException.h" #import "OFOutOfRangeException.h" +#import "autorelease.h" #import "macros.h" #import "of_asprintf.h" #import "unicode.h" extern const uint16_t of_iso_8859_15[256]; @@ -820,17 +820,17 @@ - (void)getCharacters: (of_unichar_t*)buffer inRange: (of_range_t)range { /* TODO: Could be slightly optimized */ - OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; + void *pool = objc_autoreleasePoolPush(); const of_unichar_t *unicodeString = [self unicodeString]; memcpy(buffer, unicodeString + range.start, range.length * sizeof(of_unichar_t)); - [pool release]; + objc_autoreleasePoolPop(pool); } - (size_t)indexOfFirstOccurrenceOfString: (OFString*)string { const char *cString = [string UTF8String]; @@ -930,23 +930,23 @@ } - (OFArray*)componentsSeparatedByString: (OFString*)delimiter skipEmpty: (BOOL)skipEmpty { - OFAutoreleasePool *pool; + void *pool; OFMutableArray *array; const char *cString = [delimiter UTF8String]; size_t cStringLength = [delimiter UTF8StringLength]; size_t i, last; OFString *component; array = [OFMutableArray array]; - pool = [[OFAutoreleasePool alloc] init]; + pool = objc_autoreleasePoolPush(); if (cStringLength > s->cStringLength) { [array addObject: [[self copy] autorelease]]; - [pool release]; + objc_autoreleasePoolPop(pool); return array; } for (i = 0, last = 0; i <= s->cStringLength - cStringLength; i++) { @@ -965,27 +965,27 @@ if (!skipEmpty || ![component isEqual: @""]) [array addObject: component]; [array makeImmutable]; - [pool release]; + objc_autoreleasePoolPop(pool); return array; } - (OFArray*)pathComponents { OFMutableArray *ret; - OFAutoreleasePool *pool; + void *pool; size_t i, last = 0, pathCStringLength = s->cStringLength; ret = [OFMutableArray array]; if (pathCStringLength == 0) return ret; - pool = [[OFAutoreleasePool alloc] init]; + pool = objc_autoreleasePoolPush(); #ifndef _WIN32 if (s->cString[pathCStringLength - 1] == OF_PATH_DELIMITER) #else if (s->cString[pathCStringLength - 1] == '/' || @@ -1009,11 +1009,11 @@ [ret addObject: [OFString stringWithUTF8String: s->cString + last length: i - last]]; [ret makeImmutable]; - [pool release]; + objc_autoreleasePoolPop(pool); return ret; } - (OFString*)lastPathComponent @@ -1126,11 +1126,11 @@ } #ifdef OF_HAVE_BLOCKS - (void)enumerateLinesUsingBlock: (of_string_line_enumeration_block_t)block { - OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; + void *pool; const char *cString = s->cString; const char *last = cString; BOOL stop = NO, lastCarriageReturn = NO; while (!stop && *cString != 0) { @@ -1142,25 +1142,29 @@ continue; } if (*cString == '\n' || *cString == '\r') { + pool = objc_autoreleasePoolPush(); + block([OFString stringWithUTF8String: last length: cString - last], &stop); last = cString + 1; - [pool releaseObjects]; + objc_autoreleasePoolPop(pool); } lastCarriageReturn = (*cString == '\r'); cString++; } + pool = objc_autoreleasePoolPush(); + if (!stop) block([OFString stringWithUTF8String: last length: cString - last], &stop); - [pool release]; + objc_autoreleasePoolPop(pool); } #endif @end Index: src/OFThreadPool.m ================================================================== --- src/OFThreadPool.m +++ src/OFThreadPool.m @@ -18,11 +18,12 @@ #import "OFThreadPool.h" #import "OFArray.h" #import "OFList.h" #import "OFThread.h" -#import "OFAutoreleasePool.h" + +#import "autorelease.h" @interface OFThreadPoolJob: OFObject { id target; SEL selector; @@ -173,36 +174,36 @@ [super dealloc]; } - (id)main { - OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; + void *pool; - if (terminate) { - [pool release]; + if (terminate) return nil; - } + + pool = objc_autoreleasePoolPush(); for (;;) { OFThreadPoolJob *job; [queueCondition lock]; @try { of_list_object_t *listObject; if (terminate) { - [pool release]; + objc_autoreleasePoolPop(pool); return nil; } listObject = [queue firstListObject]; while (listObject == NULL) { [queueCondition wait]; if (terminate) { - [pool release]; + objc_autoreleasePoolPop(pool); return nil; } listObject = [queue firstListObject]; } @@ -212,27 +213,28 @@ } @finally { [queueCondition unlock]; } if (terminate) { - [pool release]; + objc_autoreleasePoolPop(pool); return nil; } [job perform]; if (terminate) { - [pool release]; + objc_autoreleasePoolPop(pool); return nil; } - [pool releaseObjects]; + objc_autoreleasePoolPop(pool); + pool = objc_autoreleasePoolPush(); [countCondition lock]; @try { if (terminate) { - [pool release]; + objc_autoreleasePoolPop(pool); return nil; } (*doneCount)++; @@ -263,26 +265,27 @@ - initWithSize: (size_t)size_ { self = [super init]; @try { - OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; size_t i; size = size_; threads = [[OFMutableArray alloc] init]; queue = [[OFList alloc] init]; queueCondition = [[OFCondition alloc] init]; countCondition = [[OFCondition alloc] init]; for (i = 0; i < size; i++) { + void *pool = objc_autoreleasePoolPush(); + OFThreadPoolThread *thread = [OFThreadPoolThread threadWithThreadPool: self]; [threads addObject: thread]; - [pool releaseObjects]; + objc_autoreleasePoolPop(pool); } /* * We need to start the threads in a separate loop to make sure * threads is not modified anymore to prevent a race condition. @@ -290,12 +293,10 @@ for (i = 0; i < size; i++) { OFThreadPoolThread *thread = [threads objectAtIndex: i]; [thread start]; } - - [pool release]; } @catch (id e) { [self release]; @throw e; } @@ -302,11 +303,11 @@ return self; } - (void)dealloc { - OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; + void *pool = objc_autoreleasePoolPush(); [queueCondition lock]; @try { [countCondition lock]; @try { OFEnumerator *enumerator = [threads objectEnumerator]; @@ -320,11 +321,11 @@ [queueCondition broadcast]; } @finally { [queueCondition unlock]; } - [pool release]; + objc_autoreleasePoolPop(pool); [threads release]; [queue release]; [queueCondition release]; [countCondition release]; Index: src/OFURL.m ================================================================== --- src/OFURL.m +++ src/OFURL.m @@ -22,22 +22,22 @@ #import "OFURL.h" #import "OFString.h" #import "OFArray.h" #import "OFXMLElement.h" -#import "OFAutoreleasePool.h" #import "OFInvalidArgumentException.h" #import "OFInvalidFormatException.h" #import "OFOutOfMemoryException.h" +#import "autorelease.h" #import "macros.h" static OF_INLINE OFString* resolve_relative_path(OFString *path) { - OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; + void *pool = objc_autoreleasePoolPush(); OFMutableArray *array; OFString *ret; BOOL done = NO; array = [[[path componentsSeparatedByString: @"/"] mutableCopy] @@ -70,11 +70,11 @@ } } ret = [[array componentsJoinedByString: @"/"] retain]; - [pool release]; + objc_autoreleasePoolPop(pool); return [ret autorelease]; } @implementation OFURL @@ -146,29 +146,29 @@ UTF8String = tmp2; } if ((tmp2 = strchr(UTF8String, ':')) != NULL) { - OFAutoreleasePool *pool; + void *pool; OFString *portString; *tmp2 = '\0'; tmp2++; host = [[OFString alloc] initWithUTF8String: UTF8String]; - pool = [[OFAutoreleasePool alloc] init]; + pool = objc_autoreleasePoolPush(); portString = [OFString stringWithUTF8String: tmp2]; if ([portString decimalValue] > 65535) @throw [OFInvalidFormatException exceptionWithClass: [self class]]; port = [portString decimalValue]; - [pool release]; + objc_autoreleasePoolPop(pool); } else { host = [[OFString alloc] initWithUTF8String: UTF8String]; if ([scheme isEqual: @"http"]) @@ -260,14 +260,14 @@ if (*UTF8String == '/') path = [[OFString alloc] initWithUTF8String: UTF8String]; else { - OFAutoreleasePool *pool; + void *pool; OFString *s; - pool = [[OFAutoreleasePool alloc] init]; + pool = objc_autoreleasePoolPush(); if ([URL->path hasSuffix: @"/"]) s = [OFString stringWithFormat: @"%@%s", URL->path, UTF8String]; @@ -276,11 +276,11 @@ URL->path, UTF8String]; path = [resolve_relative_path(s) copy]; - [pool release]; + objc_autoreleasePoolPop(pool); } } @catch (id e) { [self release]; @throw e; } @finally { @@ -291,21 +291,21 @@ } - initWithSerialization: (OFXMLElement*)element { @try { - OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; + void *pool = objc_autoreleasePoolPush(); if (![[element name] isEqual: [self className]] || ![[element namespace] isEqual: OF_SERIALIZATION_NS]) @throw [OFInvalidArgumentException exceptionWithClass: [self class] selector: _cmd]; self = [self initWithString: [element stringValue]]; - [pool release]; + objc_autoreleasePoolPop(pool); } @catch (id e) { [self release]; @throw e; } @@ -552,19 +552,19 @@ return [self string]; } - (OFXMLElement*)XMLElementBySerializing { - OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; + void *pool = objc_autoreleasePoolPush(); OFXMLElement *element; element = [OFXMLElement elementWithName: [self className] namespace: OF_SERIALIZATION_NS stringValue: [self string]]; [element retain]; - [pool release]; - [element autorelease]; + + objc_autoreleasePoolPop(pool); - return element; + return [element autorelease]; } @end Index: src/OFXMLAttribute.m ================================================================== --- src/OFXMLAttribute.m +++ src/OFXMLAttribute.m @@ -18,14 +18,14 @@ #import "OFXMLAttribute.h" #import "OFString.h" #import "OFDictionary.h" #import "OFXMLElement.h" -#import "OFAutoreleasePool.h" #import "OFInvalidArgumentException.h" +#import "autorelease.h" #import "macros.h" @implementation OFXMLAttribute + attributeWithName: (OFString*)name namespace: (OFString*)ns @@ -57,11 +57,11 @@ - initWithSerialization: (OFXMLElement*)element { self = [super init]; @try { - OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; + void *pool = objc_autoreleasePoolPush(); if (![[element name] isEqual: [self className]] || ![[element namespace] isEqual: OF_SERIALIZATION_NS]) @throw [OFInvalidArgumentException exceptionWithClass: [self class] @@ -72,11 +72,11 @@ ns = [[[element attributeForName: @"namespace"] stringValue] copy]; stringValue = [[[element attributeForName: @"stringValue"] stringValue] copy]; - [pool release]; + objc_autoreleasePoolPop(pool); } @catch (id e) { [self release]; @throw e; } @@ -141,11 +141,11 @@ return hash; } - (OFXMLElement*)XMLElementBySerializing { - OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; + void *pool = objc_autoreleasePoolPush(); OFXMLElement *element; element = [OFXMLElement elementWithName: [self className] namespace: OF_SERIALIZATION_NS]; @@ -158,18 +158,18 @@ [element addAttributeWithName: @"stringValue" stringValue: stringValue]; [element retain]; - [pool release]; - [element autorelease]; + + objc_autoreleasePoolPop(pool); - return element; + return [element autorelease]; } - (OFString*)description { return [OFString stringWithFormat: @"", name, ns, stringValue]; } @end Index: src/OFXMLCDATA.m ================================================================== --- src/OFXMLCDATA.m +++ src/OFXMLCDATA.m @@ -17,13 +17,14 @@ #include "config.h" #import "OFXMLCDATA.h" #import "OFString.h" #import "OFXMLElement.h" -#import "OFAutoreleasePool.h" #import "OFInvalidArgumentException.h" + +#import "autorelease.h" @implementation OFXMLCDATA + CDATAWithString: (OFString*)string { return [[[self alloc] initWithString: string] autorelease]; @@ -46,21 +47,21 @@ - initWithSerialization: (OFXMLElement*)element { self = [super init]; @try { - OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; + void *pool = objc_autoreleasePoolPush(); if (![[element name] isEqual: [self className]] || ![[element namespace] isEqual: OF_SERIALIZATION_NS]) @throw [OFInvalidArgumentException exceptionWithClass: [self class] selector: _cmd]; CDATA = [[element stringValue] copy]; - [pool release]; + objc_autoreleasePoolPop(pool); } @catch (id e) { [self release]; @throw e; } Index: src/OFXMLCharacters.m ================================================================== --- src/OFXMLCharacters.m +++ src/OFXMLCharacters.m @@ -17,13 +17,14 @@ #include "config.h" #import "OFXMLCharacters.h" #import "OFString.h" #import "OFXMLElement.h" -#import "OFAutoreleasePool.h" #import "OFInvalidArgumentException.h" + +#import "autorelease.h" @implementation OFXMLCharacters + charactersWithString: (OFString*)string { return [[[self alloc] initWithString: string] autorelease]; @@ -46,21 +47,21 @@ - initWithSerialization: (OFXMLElement*)element { self = [super init]; @try { - OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; + void *pool = objc_autoreleasePoolPush(); if (![[element name] isEqual: [self className]] || ![[element namespace] isEqual: OF_SERIALIZATION_NS]) @throw [OFInvalidArgumentException exceptionWithClass: [self class] selector: _cmd]; characters = [[element stringValue] copy]; - [pool release]; + objc_autoreleasePoolPop(pool); } @catch (id e) { [self release]; @throw e; } Index: src/OFXMLComment.m ================================================================== --- src/OFXMLComment.m +++ src/OFXMLComment.m @@ -19,13 +19,14 @@ #include #import "OFXMLComment.h" #import "OFString.h" #import "OFXMLElement.h" -#import "OFAutoreleasePool.h" #import "OFInvalidArgumentException.h" + +#import "autorelease.h" @implementation OFXMLComment + commentWithString: (OFString*)string { return [[[self alloc] initWithString: string] autorelease]; @@ -48,21 +49,21 @@ - initWithSerialization: (OFXMLElement*)element { self = [super init]; @try { - OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; + void *pool = objc_autoreleasePoolPush(); if (![[element name] isEqual: [self className]] || ![[element namespace] isEqual: OF_SERIALIZATION_NS]) @throw [OFInvalidArgumentException exceptionWithClass: [self class] selector: _cmd]; comment = [[element stringValue] copy]; - [pool release]; + objc_autoreleasePoolPop(pool); } @catch (id e) { [self release]; @throw e; } Index: src/OFXMLElement+Serialization.m ================================================================== --- src/OFXMLElement+Serialization.m +++ src/OFXMLElement+Serialization.m @@ -18,28 +18,26 @@ #import "OFXMLElement.h" #import "OFXMLElement+Serialization.h" #import "OFSerialization.h" #import "OFString.h" -#import "OFAutoreleasePool.h" #import "OFInvalidArgumentException.h" #import "OFNotImplementedException.h" +#import "autorelease.h" #import "macros.h" int _OFXMLElement_Serialization_reference; @implementation OFXMLElement (Serialization) - (id)objectByDeserializing { - OFAutoreleasePool *pool; + void *pool = objc_autoreleasePoolPush(); Class class; id object; - pool = [[OFAutoreleasePool alloc] init]; - if ((class = objc_lookUpClass([name cStringWithEncoding: OF_STRING_ENCODING_ASCII])) == Nil) @throw [OFNotImplementedException exceptionWithClass: Nil]; if (![class conformsToProtocol: @protocol(OFSerialization)]) @@ -47,10 +45,10 @@ exceptionWithClass: class selector: @selector(initWithSerialization:)]; object = [[class alloc] initWithSerialization: self]; - [pool release]; + objc_autoreleasePoolPop(pool); return [object autorelease]; } @end Index: src/OFXMLElement.m ================================================================== --- src/OFXMLElement.m +++ src/OFXMLElement.m @@ -27,18 +27,18 @@ #import "OFXMLAttribute.h" #import "OFXMLCharacters.h" #import "OFXMLCDATA.h" #import "OFXMLParser.h" #import "OFXMLElementBuilder.h" -#import "OFAutoreleasePool.h" #import "OFInvalidArgumentException.h" #import "OFInvalidFormatException.h" #import "OFMalformedXMLException.h" #import "OFNotImplementedException.h" #import "OFUnboundNamespaceException.h" +#import "autorelease.h" #import "macros.h" /* References for static linking */ void _references_to_categories_of_OFXMLElement(void) { @@ -208,11 +208,11 @@ return self; } - initWithXMLString: (OFString*)string { - OFAutoreleasePool *pool; + void *pool; OFXMLParser *parser; OFXMLElementBuilder *builder; OFXMLElement_OFXMLElementBuilderDelegate *delegate; Class c; @@ -221,11 +221,11 @@ if (string == nil) @throw [OFInvalidArgumentException exceptionWithClass: c selector: _cmd]; - pool = [[OFAutoreleasePool alloc] init]; + pool = objc_autoreleasePoolPush(); parser = [OFXMLParser parser]; builder = [OFXMLElementBuilder elementBuilder]; delegate = [[[OFXMLElement_OFXMLElementBuilderDelegate alloc] init] autorelease]; @@ -239,27 +239,27 @@ @throw [OFMalformedXMLException exceptionWithClass: c parser: parser]; self = [delegate->element retain]; - [pool release]; + objc_autoreleasePoolPop(pool); return self; } - initWithFile: (OFString*)path { - OFAutoreleasePool *pool; + void *pool; OFXMLParser *parser; OFXMLElementBuilder *builder; OFXMLElement_OFXMLElementBuilderDelegate *delegate; Class c; c = [self class]; [self release]; - pool = [[OFAutoreleasePool alloc] init]; + pool = objc_autoreleasePoolPush(); parser = [OFXMLParser parser]; builder = [OFXMLElementBuilder elementBuilder]; delegate = [[[OFXMLElement_OFXMLElementBuilderDelegate alloc] init] autorelease]; @@ -273,21 +273,21 @@ @throw [OFMalformedXMLException exceptionWithClass: c parser: parser]; self = [delegate->element retain]; - [pool release]; + objc_autoreleasePoolPop(pool); return self; } - initWithSerialization: (OFXMLElement*)element { self = [super init]; @try { - OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; + void *pool = objc_autoreleasePoolPush(); OFXMLElement *attributesElement, *namespacesElement; OFXMLElement *childrenElement; OFEnumerator *keyEnumerator, *objectEnumerator; id key, object; @@ -369,11 +369,11 @@ if (name == nil) @throw [OFInvalidArgumentException exceptionWithClass: [self class] selector: _cmd]; - [pool release]; + objc_autoreleasePoolPop(pool); } @catch (id e) { [self release]; @throw e; } @@ -420,58 +420,57 @@ OF_GETTER(children, YES) } - (void)setStringValue: (OFString*)stringValue { - OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; + void *pool = objc_autoreleasePoolPush(); [self setChildren: [OFArray arrayWithObject: [OFXMLCharacters charactersWithString: stringValue]]]; - [pool release]; + objc_autoreleasePoolPop(pool); } - (OFString*)stringValue { - OFAutoreleasePool *pool; OFMutableString *ret; OFXMLElement **objects; size_t i, count = [children count]; if (count == 0) return @""; ret = [OFMutableString string]; objects = [children objects]; - pool = [[OFAutoreleasePool alloc] init]; for (i = 0; i < count; i++) { + void *pool = objc_autoreleasePoolPush(); + [ret appendString: [objects[i] stringValue]]; - [pool releaseObjects]; + + objc_autoreleasePoolPop(pool); } [ret makeImmutable]; - [pool release]; - return ret; } - (OFString*)_XMLStringWithParent: (OFXMLElement*)parent namespaces: (OFDictionary*)allNamespaces indentation: (unsigned int)indentation level: (unsigned int)level { - OFAutoreleasePool *pool, *pool2; + void *pool; char *cString; size_t length, i, j, attributesCount; OFString *prefix, *parentPrefix; OFXMLAttribute **attributesObjects; OFString *ret; OFString *defaultNS; - pool = [[OFAutoreleasePool alloc] init]; + pool = objc_autoreleasePoolPush(); parentPrefix = [allNamespaces objectForKey: (parent != nil && parent->ns != nil ? parent->ns : (OFString*)@"")]; /* Add the namespaces of the current element */ @@ -552,12 +551,12 @@ /* Attributes */ attributesObjects = [attributes objects]; attributesCount = [attributes count]; - pool2 = [[OFAutoreleasePool alloc] init]; for (j = 0; j < attributesCount; j++) { + void *pool2 = objc_autoreleasePoolPush(); OFString *attributeName = [attributesObjects[j] name]; OFString *attributePrefix = nil; OFString *tmp = [[attributesObjects[j] stringValue] stringByXMLEscaping]; @@ -596,11 +595,11 @@ cString[i++] = '\''; memcpy(cString + i, [tmp UTF8String], [tmp UTF8StringLength]); i += [tmp UTF8StringLength]; cString[i++] = '\''; - [pool2 releaseObjects]; + objc_autoreleasePoolPop(pool2); } /* Childen */ if (children != nil) { OFXMLElement **childrenObjects = [children objects]; @@ -691,11 +690,11 @@ cString[i++] = '/'; cString[i++] = '>'; assert(i == length); - [pool release]; + objc_autoreleasePoolPop(pool); @try { ret = [OFString stringWithUTF8String: cString length: length]; } @finally { @@ -729,11 +728,11 @@ level: level]; } - (OFXMLElement*)XMLElementBySerializing { - OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; + void *pool = objc_autoreleasePoolPush(); OFXMLElement *element; element = [OFXMLElement elementWithName: [self className] namespace: OF_SERIALIZATION_NS]; @@ -789,14 +788,14 @@ [childrenElement addChild: [children XMLElementBySerializing]]; [element addChild: childrenElement]; } [element retain]; - [pool release]; - [element autorelease]; + + objc_autoreleasePoolPop(pool); - return element; + return [element autorelease]; } - (void)addAttribute: (OFXMLAttribute*)attribute { if (attributes == nil) @@ -817,17 +816,17 @@ - (void)addAttributeWithName: (OFString*)name_ namespace: (OFString*)ns_ stringValue: (OFString*)stringValue { - OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; + void *pool = objc_autoreleasePoolPush(); [self addAttribute: [OFXMLAttribute attributeWithName: name_ namespace: ns_ stringValue: stringValue]]; - [pool release]; + objc_autoreleasePoolPop(pool); } - (OFXMLAttribute*)attributeForName: (OFString*)attributeName { OFXMLAttribute **objects = [attributes objects]; Index: src/OFXMLParser.m ================================================================== --- src/OFXMLParser.m +++ src/OFXMLParser.m @@ -28,15 +28,16 @@ #import "OFDictionary.h" #import "OFDataArray.h" #import "OFXMLAttribute.h" #import "OFStream.h" #import "OFFile.h" -#import "OFAutoreleasePool.h" #import "OFInitializationFailedException.h" #import "OFMalformedXMLException.h" #import "OFUnboundNamespaceException.h" + +#import "autorelease.h" typedef void (*state_function)(id, SEL, const char*, size_t*, size_t*); static SEL selectors[OF_XMLPARSER_NUM_STATES]; static state_function lookupTable[OF_XMLPARSER_NUM_STATES]; @@ -46,17 +47,17 @@ { if (OF_LIKELY(encoding == OF_STRING_ENCODING_UTF_8)) [cache addItemsFromCArray: string count: length]; else { - OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; + void *pool = objc_autoreleasePoolPush(); OFString *tmp = [OFString stringWithCString: string encoding: encoding length: length]; [cache addItemsFromCArray: [tmp UTF8String] count: [tmp UTF8StringLength]]; - [pool release]; + objc_autoreleasePoolPop(pool); } } static OFString* transform_string(OFDataArray *cache, size_t cut, BOOL unescape, @@ -181,29 +182,29 @@ - init { self = [super init]; @try { - OFAutoreleasePool *pool; + void *pool; OFMutableDictionary *dict; cache = [[OFBigDataArray alloc] init]; previous = [[OFMutableArray alloc] init]; namespaces = [[OFMutableArray alloc] init]; attributes = [[OFMutableArray alloc] init]; - pool = [[OFAutoreleasePool alloc] init]; + pool = objc_autoreleasePoolPush(); dict = [OFMutableDictionary dictionaryWithKeysAndObjects: @"xml", @"http://www.w3.org/XML/1998/namespace", @"xmlns", @"http://www.w3.org/2000/xmlns/", nil]; [namespaces addObject: dict]; acceptProlog = YES; lineNumber = 1; encoding = OF_STRING_ENCODING_UTF_8; - [pool release]; + objc_autoreleasePoolPop(pool); } @catch (id e) { [self release]; @throw e; } @@ -319,20 +320,17 @@ if ((length = *i - *last) > 0) cache_append(cache, buffer + *last, encoding, length); if ([cache count] > 0) { - OFString *characters; - OFAutoreleasePool *pool; - - pool = [[OFAutoreleasePool alloc] init]; - characters = transform_string(cache, 0, YES, self); + void *pool = objc_autoreleasePoolPush(); + OFString *characters = transform_string(cache, 0, YES, self); [delegate parser: self foundCharacters: characters]; - [pool release]; + objc_autoreleasePoolPop(pool); } [cache removeAllItems]; *last = *i + 1; @@ -474,11 +472,11 @@ last: (size_t*)last { if (buffer[*i] == '?') level = 1; else if (level == 1 && buffer[*i] == '>') { - OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; + void *pool = objc_autoreleasePoolPush(); OFString *pi; cache_append(cache, buffer + *last, encoding, *i - *last); pi = transform_string(cache, 1, NO, nil); @@ -491,11 +489,11 @@ parser: self]; [delegate parser: self foundProcessingInstructions: pi]; - [pool release]; + objc_autoreleasePoolPop(pool); [cache removeAllItems]; *last = *i + 1; state = OF_XMLPARSER_OUTSIDE_TAG; @@ -506,11 +504,11 @@ /* Inside a tag, no name yet */ - (void)_parseInTagNameWithBuffer: (const char*)buffer i: (size_t*)i last: (size_t*)last { - OFAutoreleasePool *pool; + void *pool; const char *cacheCString, *tmp; size_t length, cacheLength; OFString *cacheString; if (buffer[*i] != ' ' && buffer[*i] != '\t' && buffer[*i] != '\n' && @@ -518,11 +516,11 @@ return; if ((length = *i - *last) > 0) cache_append(cache, buffer + *last, encoding, length); - pool = [[OFAutoreleasePool alloc] init]; + pool = objc_autoreleasePoolPush(); cacheCString = [cache cArray]; cacheLength = [cache count]; cacheString = [OFString stringWithUTF8String: cacheCString length: cacheLength]; @@ -538,22 +536,19 @@ name = [cacheString copy]; prefix = nil; } if (buffer[*i] == '>' || buffer[*i] == '/') { - OFAutoreleasePool *pool2; OFString *ns; ns = namespace_for_prefix(prefix, namespaces); if (prefix != nil && ns == nil) @throw [OFUnboundNamespaceException exceptionWithClass: [self class] prefix: prefix]; - pool2 = [[OFAutoreleasePool alloc] init]; - [delegate parser: self didStartElement: name withPrefix: prefix namespace: ns attributes: nil]; @@ -567,12 +562,10 @@ if ([previous count] == 0) finishedParsing = YES; } else [previous addObject: cacheString]; - [pool2 release]; - [name release]; [prefix release]; name = prefix = nil; state = (buffer[*i] == '/' @@ -579,17 +572,14 @@ ? OF_XMLPARSER_EXPECT_CLOSE : OF_XMLPARSER_OUTSIDE_TAG); } else state = OF_XMLPARSER_IN_TAG; - [pool release]; - - if (buffer[*i] != '/') { - pool = [[OFAutoreleasePool alloc] init]; + if (buffer[*i] != '/') [namespaces addObject: [OFMutableDictionary dictionary]]; - [pool release]; - } + + objc_autoreleasePoolPop(pool); [cache removeAllItems]; *last = *i + 1; } @@ -596,11 +586,11 @@ /* Inside a close tag, no name yet */ - (void)_parseInCloseTagNameWithBuffer: (const char*)buffer i: (size_t*)i last: (size_t*)last { - OFAutoreleasePool *pool; + void *pool; const char *cacheCString, *tmp; size_t length, cacheLength; OFString *cacheString; OFString *ns; @@ -609,11 +599,11 @@ return; if ((length = *i - *last) > 0) cache_append(cache, buffer + *last, encoding, length); - pool = [[OFAutoreleasePool alloc] init]; + pool = objc_autoreleasePoolPush(); cacheCString = [cache cArray]; cacheLength = [cache count]; cacheString = [OFString stringWithUTF8String: cacheCString length: cacheLength]; @@ -647,11 +637,11 @@ [delegate parser: self didEndElement: name withPrefix: prefix namespace: ns]; - [pool release]; + objc_autoreleasePoolPop(pool); [namespaces removeLastObject]; [name release]; [prefix release]; name = prefix = nil; @@ -668,11 +658,11 @@ /* Inside a tag, name found */ - (void)_parseInTagWithBuffer: (const char*)buffer i: (size_t*)i last: (size_t*)last { - OFAutoreleasePool *pool; + void *pool; OFString *ns; OFXMLAttribute **attributesObjects; size_t j, attributesCount; if (buffer[*i] != '>' && buffer[*i] != '/') { @@ -698,11 +688,11 @@ for (j = 0; j < attributesCount; j++) resolve_attribute_namespace(attributesObjects[j], namespaces, self); - pool = [[OFAutoreleasePool alloc] init]; + pool = objc_autoreleasePoolPush(); [delegate parser: self didStartElement: name withPrefix: prefix namespace: ns @@ -723,11 +713,11 @@ prefix, name]; [previous addObject: str]; } else [previous addObject: name]; - [pool release]; + objc_autoreleasePoolPop(pool); [name release]; [prefix release]; [attributes removeAllObjects]; name = prefix = nil; @@ -741,11 +731,11 @@ /* Looking for attribute name */ - (void)_parseInAttributeNameWithBuffer: (const char*)buffer i: (size_t*)i last: (size_t*)last { - OFAutoreleasePool *pool; + void *pool; OFMutableString *cacheString; const char *cacheCString, *tmp; size_t length, cacheLength; if (buffer[*i] != '=') @@ -752,11 +742,11 @@ return; if ((length = *i - *last) > 0) cache_append(cache, buffer + *last, encoding, length); - pool = [[OFAutoreleasePool alloc] init]; + pool = objc_autoreleasePoolPush(); cacheString = [OFMutableString stringWithUTF8String: [cache cArray] length: [cache count]]; [cacheString deleteEnclosingWhitespaces]; /* Prevent a useless copy later */ @@ -775,11 +765,11 @@ } else { attributeName = [cacheString copy]; attributePrefix = nil; } - [pool release]; + objc_autoreleasePoolPop(pool); [cache removeAllItems]; *last = *i + 1; state = OF_XMLPARSER_EXPECT_DELIM; @@ -807,21 +797,21 @@ /* Looking for attribute value */ - (void)_parseInAttributeValueWithBuffer: (const char*)buffer i: (size_t*)i last: (size_t*)last { - OFAutoreleasePool *pool; + void *pool; OFString *attributeValue; size_t length; if (buffer[*i] != delimiter) return; if ((length = *i - *last) > 0) cache_append(cache, buffer + *last, encoding, length); - pool = [[OFAutoreleasePool alloc] init]; + pool = objc_autoreleasePoolPush(); attributeValue = transform_string(cache, 0, YES, self); if (attributePrefix == nil && [attributeName isEqual: @"xmlns"]) [[namespaces lastObject] setObject: attributeValue forKey: @""]; @@ -832,11 +822,11 @@ [attributes addObject: [OFXMLAttribute attributeWithName: attributeName namespace: attributePrefix stringValue: attributeValue]]; - [pool release]; + objc_autoreleasePoolPop(pool); [cache removeAllItems]; [attributeName release]; [attributePrefix release]; attributeName = attributePrefix = nil; @@ -928,29 +918,29 @@ - (void)_parseInCDATA2WithBuffer: (const char*)buffer i: (size_t*)i last: (size_t*)last { - OFAutoreleasePool *pool; + void *pool; OFString *CDATA; if (buffer[*i] != '>') { state = OF_XMLPARSER_IN_CDATA_1; level = (buffer[*i] == ']' ? 1 : 0); return; } - pool = [[OFAutoreleasePool alloc] init]; + pool = objc_autoreleasePoolPush(); cache_append(cache, buffer + *last, encoding, *i - *last); CDATA = transform_string(cache, 2, NO, nil); [delegate parser: self foundCDATA: CDATA]; - [pool release]; + objc_autoreleasePoolPop(pool); [cache removeAllItems]; *last = *i + 1; state = OF_XMLPARSER_OUTSIDE_TAG; @@ -985,26 +975,26 @@ - (void)_parseInComment2WithBuffer: (const char*)buffer i: (size_t*)i last: (size_t*)last { - OFAutoreleasePool *pool; + void *pool; OFString *comment; if (buffer[*i] != '>') @throw [OFMalformedXMLException exceptionWithClass: [self class] parser: self]; - pool = [[OFAutoreleasePool alloc] init]; + pool = objc_autoreleasePoolPush(); cache_append(cache, buffer + *last, encoding, *i - *last); comment = transform_string(cache, 2, NO, nil); [delegate parser: self foundComment: comment]; - [pool release]; + objc_autoreleasePoolPop(pool); [cache removeAllItems]; *last = *i + 1; state = OF_XMLPARSER_OUTSIDE_TAG; Index: src/OFXMLProcessingInstructions.m ================================================================== --- src/OFXMLProcessingInstructions.m +++ src/OFXMLProcessingInstructions.m @@ -19,13 +19,14 @@ #include #import "OFXMLProcessingInstructions.h" #import "OFString.h" #import "OFXMLElement.h" -#import "OFAutoreleasePool.h" #import "OFInvalidArgumentException.h" + +#import "autorelease.h" @implementation OFXMLProcessingInstructions + processingInstructionsWithString: (OFString*)string { return [[[self alloc] initWithString: string] autorelease]; @@ -48,21 +49,21 @@ - initWithSerialization: (OFXMLElement*)element { self = [super init]; @try { - OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; + void *pool = objc_autoreleasePoolPush(); if (![[element name] isEqual: [self className]] || ![[element namespace] isEqual: OF_SERIALIZATION_NS]) @throw [OFInvalidArgumentException exceptionWithClass: [self class] selector: _cmd]; processingInstructions = [[element stringValue] copy]; - [pool release]; + objc_autoreleasePoolPop(pool); } @catch (id e) { [self release]; @throw e; }