@@ -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 {