Index: src/OFApplication.h ================================================================== --- src/OFApplication.h +++ src/OFApplication.h @@ -99,22 +99,22 @@ /*! * @brief Represents the application as an object. */ @interface OFApplication: OFObject { - OFString *programName; - OFMutableArray *arguments; - OFMutableDictionary *environment; - int *argc; - char ***argv; + OFString *_programName; + OFArray *_arguments; + OFDictionary *_environment; + int *_argc; + char ***_argv; @public - id delegate; - void (*SIGINTHandler)(id, SEL); + id _delegate; + void (*_SIGINTHandler)(id, SEL); #ifndef _WIN32 - void (*SIGHUPHandler)(id, SEL); - void (*SIGUSR1Handler)(id, SEL); - void (*SIGUSR2Handler)(id, SEL); + void (*_SIGHUPHandler)(id, SEL); + void (*_SIGUSR1Handler)(id, SEL); + void (*_SIGUSR2Handler)(id, SEL); #endif } #ifdef OF_HAVE_PROPERTIES @property (readonly, copy, nonatomic) OFString *programName; Index: src/OFApplication.m ================================================================== --- src/OFApplication.m +++ src/OFApplication.m @@ -53,18 +53,18 @@ id delegate = [app delegate]; if ([delegate respondsToSelector: @selector(applicationWillTerminate)]) [delegate applicationWillTerminate]; - [(id)delegate release]; + [delegate release]; } #define SIGNAL_HANDLER(sig) \ static void \ handle##sig(int signal) \ { \ - app->sig##Handler(app->delegate, \ + app->_##sig##Handler(app->_delegate, \ @selector(applicationDidReceive##sig)); \ } SIGNAL_HANDLER(SIGINT) #ifndef _WIN32 SIGNAL_HANDLER(SIGHUP) @@ -137,10 +137,11 @@ { self = [super init]; @try { void *pool; + OFMutableDictionary *environment; #if defined(__MACH__) && !defined(OF_IOS) char **env = *_NSGetEnviron(); #elif defined(__WIN32) uint16_t *env; #elif !defined(OF_IOS) @@ -267,29 +268,39 @@ objc_autoreleasePoolPop(pool); #endif [environment makeImmutable]; + _environment = environment; } @catch (id e) { [self release]; @throw e; } return self; } -- (void)OF_setArgumentCount: (int*)argc_ - andArgumentValues: (char***)argv_ +- (void)dealloc +{ + [_arguments release]; + [_environment release]; + + [super dealloc]; +} + +- (void)OF_setArgumentCount: (int*)argc + andArgumentValues: (char***)argv { #ifndef _WIN32 void *pool = objc_autoreleasePoolPush(); + OFMutableArray *arguments; int i; - argc = argc_; - argv = argv_; + _argc = argc; + _argv = argv; - programName = [[OFString alloc] + _programName = [[OFString alloc] initWithCString: (*argv)[0] encoding: OF_STRING_ENCODING_NATIVE]; arguments = [[OFMutableArray alloc] init]; for (i = 1; i < *argc; i++) @@ -296,73 +307,76 @@ [arguments addObject: [OFString stringWithCString: (*argv)[i] encoding: OF_STRING_ENCODING_NATIVE]]; [arguments makeImmutable]; - - objc_autoreleasePoolPop(pool); -#else - argc = argc_; - argv = argv_; -#endif -} - -#ifdef _WIN32 -- (void)OF_setArgumentCount: (int)argc_ - andWideArgumentValues: (wchar_t**)argv_ -{ - void *pool = objc_autoreleasePoolPush(); - int i; - - programName = [[OFString alloc] initWithUTF16String: argv_[0]]; - arguments = [[OFMutableArray alloc] init]; - - for (i = 1; i < argc_; i++) - [arguments addObject: - [OFString stringWithUTF16String: argv_[i]]]; - - [arguments makeImmutable]; - - objc_autoreleasePoolPop(pool); -} -#endif - -- (void)getArgumentCount: (int**)argc_ - andArgumentValues: (char****)argv_ -{ - *argc_ = argc; - *argv_ = argv; -} - -- (OFString*)programName -{ - OF_GETTER(programName, NO) -} - -- (OFArray*)arguments -{ - OF_GETTER(arguments, NO) -} - -- (OFDictionary*)environment -{ - OF_GETTER(environment, NO) -} - -- (id )delegate -{ - return delegate; -} - -- (void)setDelegate: (id )delegate_ -{ - delegate = delegate_; - -#define REGISTER_SIGNAL(sig) \ - if ([delegate respondsToSelector: \ - @selector(applicationDidReceive##sig)]) { \ - sig##Handler = (void(*)(id, SEL))[(id)delegate \ + _arguments = arguments; + + objc_autoreleasePoolPop(pool); +#else + _argc = argc; + _argv = argv; +#endif +} + +#ifdef _WIN32 +- (void)OF_setArgumentCount: (int)argc + andWideArgumentValues: (wchar_t**)argv +{ + void *pool = objc_autoreleasePoolPush(); + OFMutableArray *arguments; + int i; + + _programName = [[OFString alloc] initWithUTF16String: argv[0]]; + arguments = [[OFMutableArray alloc] init]; + + for (i = 1; i < argc; i++) + [arguments addObject: + [OFString stringWithUTF16String: argv[i]]]; + + [arguments makeImmutable]; + _arguments = arguments; + + objc_autoreleasePoolPop(pool); +} +#endif + +- (void)getArgumentCount: (int**)argc + andArgumentValues: (char****)argv +{ + *argc = _argc; + *argv = _argv; +} + +- (OFString*)programName +{ + OF_GETTER(_programName, NO) +} + +- (OFArray*)arguments +{ + OF_GETTER(_arguments, NO) +} + +- (OFDictionary*)environment +{ + OF_GETTER(_environment, NO) +} + +- (id )delegate +{ + return _delegate; +} + +- (void)setDelegate: (id )delegate +{ + _delegate = delegate; + +#define REGISTER_SIGNAL(sig) \ + if ([delegate respondsToSelector: \ + @selector(applicationDidReceive##sig)]) { \ + _##sig##Handler = (void(*)(id, SEL))[(id)delegate \ methodForSelector: \ @selector(applicationDidReceive##sig)]; \ signal(sig, handle##sig); \ } else \ signal(sig, SIG_DFL); @@ -389,12 +403,18 @@ [OFRunLoop OF_setMainRunLoop: runLoop]; objc_autoreleasePoolPop(pool); + /* + * Note: runLoop is still valid after the release of the pool, as + * OF_setMainRunLoop: retained it. However, we only have a weak + * reference to it now, whereas we had a strong reference before. + */ + pool = objc_autoreleasePoolPush(); - [delegate applicationDidFinishLaunching]; + [_delegate applicationDidFinishLaunching]; objc_autoreleasePoolPop(pool); [runLoop run]; } @@ -405,14 +425,6 @@ - (void)terminateWithStatus: (int)status { exit(status); } - -- (void)dealloc -{ - [arguments release]; - [environment release]; - - [super dealloc]; -} @end Index: src/OFArray_adjacent.h ================================================================== --- src/OFArray_adjacent.h +++ src/OFArray_adjacent.h @@ -18,8 +18,8 @@ @class OFDataArray; @interface OFArray_adjacent: OFArray { - OFDataArray *array; + OFDataArray *_array; } @end Index: src/OFArray_adjacent.m ================================================================== --- src/OFArray_adjacent.m +++ src/OFArray_adjacent.m @@ -36,11 +36,11 @@ - init { self = [super init]; @try { - array = [[OFDataArray alloc] initWithItemSize: sizeof(id)]; + _array = [[OFDataArray alloc] initWithItemSize: sizeof(id)]; } @catch (id e) { [self release]; @throw e; } @@ -54,11 +54,11 @@ @try { if (object == nil) @throw [OFInvalidArgumentException exceptionWithClass: [self class]]; - [array addItem: &object]; + [_array addItem: &object]; [object retain]; } @catch (id e) { [self release]; @throw e; } @@ -72,15 +72,15 @@ self = [self init]; @try { id object; - [array addItem: &firstObject]; + [_array addItem: &firstObject]; [firstObject retain]; while ((object = va_arg(arguments, id)) != nil) { - [array addItem: &object]; + [_array addItem: &object]; [object retain]; } } @catch (id e) { [self release]; @throw e; @@ -87,41 +87,41 @@ } return self; } -- initWithArray: (OFArray*)array_ +- initWithArray: (OFArray*)array { id *objects; size_t i, count; self = [self init]; - if (array_ == nil) + if (array == nil) return self; @try { - objects = [array_ objects]; - count = [array_ count]; + objects = [array objects]; + count = [array count]; } @catch (id e) { [self release]; @throw e; } @try { for (i = 0; i < count; i++) [objects[i] retain]; - [array addItems: objects - count: count]; + [_array addItems: objects + count: count]; } @catch (id e) { for (i = 0; i < count; i++) [objects[i] release]; /* Prevent double-release of objects */ - [array release]; - array = nil; + [_array release]; + _array = nil; [self release]; @throw e; } @@ -146,12 +146,12 @@ if (!ok) @throw [OFInvalidArgumentException exceptionWithClass: [self class]]; - [array addItems: objects - count: count]; + [_array addItems: objects + count: count]; } @catch (id e) { size_t i; for (i = 0; i < count; i++) [objects[i] release]; @@ -185,11 +185,11 @@ while ((child = [enumerator nextObject]) != nil) { void *pool2 = objc_autoreleasePoolPush(); id object; object = [child objectByDeserializing]; - [array addItem: &object]; + [_array addItem: &object]; [object retain]; objc_autoreleasePoolPop(pool2); } @@ -202,33 +202,33 @@ return self; } - (size_t)count { - return [array count]; + return [_array count]; } - (id*)objects { - return [array items]; + return [_array items]; } - (id)objectAtIndex: (size_t)index { - return *((id*)[array itemAtIndex: index]); + return *((id*)[_array itemAtIndex: index]); } - (id)objectAtIndexedSubscript: (size_t)index { - return *((id*)[array itemAtIndex: index]); + return *((id*)[_array itemAtIndex: index]); } - (void)getObjects: (id*)buffer inRange: (of_range_t)range { - id *objects = [array items]; - size_t i, count = [array count]; + id *objects = [_array items]; + size_t i, count = [_array count]; if (range.length > SIZE_MAX - range.location || range.location + range.length > count) @throw [OFOutOfRangeException exceptionWithClass: [self class]]; @@ -242,12 +242,12 @@ size_t i, count; if (object == nil) return OF_NOT_FOUND; - objects = [array items]; - count = [array count]; + objects = [_array items]; + count = [_array count]; for (i = 0; i < count; i++) if ([objects[i] isEqual: object]) return i; @@ -260,12 +260,12 @@ size_t i, count; if (object == nil) return OF_NOT_FOUND; - objects = [array items]; - count = [array count]; + objects = [_array items]; + count = [_array count]; for (i = 0; i < count; i++) if (objects[i] == object) return i; @@ -274,17 +274,17 @@ - (OFArray*)objectsInRange: (of_range_t)range { if (range.length > SIZE_MAX - range.location || - range.location + range.length > [array count]) + range.location + range.length > [_array count]) @throw [OFOutOfRangeException exceptionWithClass: [self class]]; if ([self isKindOfClass: [OFMutableArray class]]) return [OFArray - arrayWithObjects: (id*)[array items] + range.location + arrayWithObjects: (id*)[_array items] + range.location count: range.length]; return [OFArray_adjacentSubarray arrayWithArray: self range: range]; } @@ -300,16 +300,16 @@ [object class] != [OFArray_adjacentSubarray class]) return [super isEqual: object]; otherArray = object; - count = [array count]; + count = [_array count]; if (count != [otherArray count]) return NO; - objects = [array items]; + objects = [_array items]; otherObjects = [otherArray objects]; for (i = 0; i < count; i++) if (![objects[i] isEqual: otherObjects[i]]) return NO; @@ -317,12 +317,12 @@ return YES; } - (uint32_t)hash { - id *objects = [array items]; - size_t i, count = [array count]; + id *objects = [_array items]; + size_t i, count = [_array count]; uint32_t hash; OF_HASH_INIT(hash); for (i = 0; i < count; i++) @@ -334,27 +334,27 @@ } #ifdef OF_HAVE_BLOCKS - (void)enumerateObjectsUsingBlock: (of_array_enumeration_block_t)block { - id *objects = [array items]; - size_t i, count = [array count]; + id *objects = [_array items]; + size_t i, count = [_array count]; BOOL stop = NO; for (i = 0; i < count && !stop; i++) block(objects[i], i, &stop); } #endif - (void)dealloc { - id *objects = [array items]; - size_t i, count = [array count]; + id *objects = [_array items]; + size_t i, count = [_array count]; for (i = 0; i < count; i++) [objects[i] release]; - [array release]; + [_array release]; [super dealloc]; } @end Index: src/OFArray_adjacentSubarray.m ================================================================== --- src/OFArray_adjacentSubarray.m +++ src/OFArray_adjacentSubarray.m @@ -21,11 +21,11 @@ #import "OFMutableArray_adjacent.h" @implementation OFArray_adjacentSubarray - (id*)objects { - return [array objects] + range.location; + return [_array objects] + _range.location; } - (BOOL)isEqual: (id)object { OFArray *otherArray; @@ -37,17 +37,17 @@ [object class] != [OFArray_adjacentSubarray class]) return [super isEqual: object]; otherArray = object; - if (range.length != [otherArray count]) + if (_range.length != [otherArray count]) return NO; objects = [self objects]; otherObjects = [otherArray objects]; - for (i = 0; i < range.length; i++) + for (i = 0; i < _range.length; i++) if (![objects[i] isEqual: otherObjects[i]]) return NO; return YES; } @@ -57,10 +57,10 @@ { id *objects = [self objects]; size_t i; BOOL stop = NO; - for (i = 0; i < range.length && !stop; i++) + for (i = 0; i < _range.length && !stop; i++) block(objects[i], i, &stop); } #endif @end Index: src/OFArray_subarray.h ================================================================== --- src/OFArray_subarray.h +++ src/OFArray_subarray.h @@ -16,14 +16,14 @@ #import "OFArray.h" @interface OFArray_subarray: OFArray { - OFArray *array; - of_range_t range; + OFArray *_array; + of_range_t _range; } + (instancetype)arrayWithArray: (OFArray*)array range: (of_range_t)range; - initWithArray: (OFArray*)array range: (of_range_t)range; @end Index: src/OFArray_subarray.m ================================================================== --- src/OFArray_subarray.m +++ src/OFArray_subarray.m @@ -26,19 +26,19 @@ { return [[[self alloc] initWithArray: array range: range] autorelease]; } -- initWithArray: (OFArray*)array_ - range: (of_range_t)range_ +- initWithArray: (OFArray*)array + range: (of_range_t)range { self = [super init]; @try { /* Should usually be retain, as it's useless with a copy */ - array = [array_ copy]; - range = range_; + _array = [array copy]; + _range = range; } @catch (id e) { [self release]; @throw e; } @@ -45,77 +45,77 @@ return self; } - (void)dealloc { - [array release]; + [_array release]; [super dealloc]; } - (size_t)count { - return range.length; + return _range.length; } - (id)objectAtIndex: (size_t)index { - if (index >= range.length) + if (index >= _range.length) @throw [OFOutOfRangeException exceptionWithClass: [self class]]; - return [array objectAtIndex: index + range.location]; + return [_array objectAtIndex: index + _range.location]; } - (void)getObjects: (id*)buffer - inRange: (of_range_t)range_ + inRange: (of_range_t)range { - if (range_.length > SIZE_MAX - range_.location || - range_.location + range_.length > range.length) + if (range.length > SIZE_MAX - range.location || + range.location + range.length > _range.length) @throw [OFOutOfRangeException exceptionWithClass: [self class]]; - range_.location += range.location; + range.location += _range.location; - return [array getObjects: buffer - inRange: range_]; + return [_array getObjects: buffer + inRange: range]; } - (size_t)indexOfObject: (id)object { - size_t index = [array indexOfObject: object]; + size_t index = [_array indexOfObject: object]; - if (index < range.location) + if (index < _range.location) return OF_NOT_FOUND; - index -= range.location; + index -= _range.location; - if (index >= range.length) + if (index >= _range.length) return OF_NOT_FOUND; return index; } - (size_t)indexOfObjectIdenticalTo: (id)object { - size_t index = [array indexOfObjectIdenticalTo: object]; + size_t index = [_array indexOfObjectIdenticalTo: object]; - if (index < range.location) + if (index < _range.location) return OF_NOT_FOUND; - index -= range.location; + index -= _range.location; - if (index >= range.length) + if (index >= _range.length) return OF_NOT_FOUND; return index; } -- (OFArray*)objectsInRange: (of_range_t)range_ +- (OFArray*)objectsInRange: (of_range_t)range { - if (range_.length > SIZE_MAX - range_.location || - range_.location + range_.length > range.length) + if (range.length > SIZE_MAX - range.location || + range.location + range.length > _range.length) @throw [OFOutOfRangeException exceptionWithClass: [self class]]; - range_.location += range.location; + range.location += _range.location; - return [array objectsInRange: range_]; + return [_array objectsInRange: range]; } @end Index: src/OFAutoreleasePool.h ================================================================== --- src/OFAutoreleasePool.h +++ src/OFAutoreleasePool.h @@ -24,12 +24,12 @@ * * Every thread has its own stack of autorelease pools. */ @interface OFAutoreleasePool: OFObject { - void *pool; - BOOL ignoreRelease; + void *_pool; + BOOL _ignoreRelease; } /*! * @brief Adds an object to the autorelease pool at the top of the * thread-specific autorelease pool stack. Index: src/OFAutoreleasePool.m ================================================================== --- src/OFAutoreleasePool.m +++ src/OFAutoreleasePool.m @@ -82,11 +82,11 @@ - init { self = [super init]; @try { - pool = objc_autoreleasePoolPush(); + _pool = objc_autoreleasePoolPush(); _objc_rootAutorelease(self); } @catch (id e) { [self release]; @throw e; @@ -95,18 +95,18 @@ return self; } - (void)releaseObjects { - ignoreRelease = YES; + _ignoreRelease = YES; - objc_autoreleasePoolPop(pool); - pool = objc_autoreleasePoolPush(); + objc_autoreleasePoolPop(_pool); + _pool = objc_autoreleasePoolPush(); _objc_rootAutorelease(self); - ignoreRelease = NO; + _ignoreRelease = NO; } - (void)release { [self dealloc]; @@ -121,16 +121,16 @@ { #if !defined(OF_HAVE_COMPILER_TLS) && defined(OF_HAVE_THREADS) OFAutoreleasePool **cache = of_tlskey_get(cacheKey); #endif - if (ignoreRelease) + if (_ignoreRelease) return; - ignoreRelease = YES; + _ignoreRelease = YES; - objc_autoreleasePoolPop(pool); + objc_autoreleasePoolPop(_pool); if (cache == NULL) { cache = calloc(sizeof(OFAutoreleasePool*), MAX_CACHE_SIZE); #if !defined(OF_HAVE_COMPILER_TLS) && defined(OF_HAVE_THREADS) @@ -144,12 +144,12 @@ if (cache != NULL) { unsigned i; for (i = 0; i < MAX_CACHE_SIZE; i++) { if (cache[i] == NULL) { - pool = NULL; - ignoreRelease = NO; + _pool = NULL; + _ignoreRelease = NO; cache[i] = self; return; } Index: src/OFCondition.h ================================================================== --- src/OFCondition.h +++ src/OFCondition.h @@ -19,12 +19,12 @@ /*! * @brief A class implementing a condition variable for thread synchronization. */ @interface OFCondition: OFMutex { - of_condition_t condition; - BOOL conditionInitialized; + of_condition_t _condition; + BOOL _conditionInitialized; } /*! * @brief Creates a new condition. * Index: src/OFCondition.m ================================================================== --- src/OFCondition.m +++ src/OFCondition.m @@ -32,51 +32,51 @@ - init { self = [super init]; - if (!of_condition_new(&condition)) { + if (!of_condition_new(&_condition)) { Class c = [self class]; [self release]; @throw [OFInitializationFailedException exceptionWithClass: c]; } - conditionInitialized = YES; + _conditionInitialized = YES; return self; } + +- (void)dealloc +{ + if (_conditionInitialized) + if (!of_condition_free(&_condition)) + @throw [OFConditionStillWaitingException + exceptionWithClass: [self class] + condition: self]; + + [super dealloc]; +} - (void)wait { - if (!of_condition_wait(&condition, &mutex)) + if (!of_condition_wait(&_condition, &_mutex)) @throw [OFConditionWaitFailedException exceptionWithClass: [self class] condition: self]; } - (void)signal { - if (!of_condition_signal(&condition)) + if (!of_condition_signal(&_condition)) @throw [OFConditionSignalFailedException exceptionWithClass: [self class] condition: self]; } - (void)broadcast { - if (!of_condition_broadcast(&condition)) + if (!of_condition_broadcast(&_condition)) @throw [OFConditionBroadcastFailedException exceptionWithClass: [self class] condition: self]; } - -- (void)dealloc -{ - if (conditionInitialized) - if (!of_condition_free(&condition)) - @throw [OFConditionStillWaitingException - exceptionWithClass: [self class] - condition: self]; - - [super dealloc]; -} @end Index: src/OFConstantString.h ================================================================== --- src/OFConstantString.h +++ src/OFConstantString.h @@ -30,9 +30,9 @@ /*! * @brief A class for storing constant strings using the \@"" literal. */ @interface OFConstantString: OFString { - char *cString; - size_t cStringLength; + char *_cString; + size_t _cStringLength; } @end Index: src/OFConstantString.m ================================================================== --- src/OFConstantString.m +++ src/OFConstantString.m @@ -74,12 +74,12 @@ [self doesNotRecognizeSelector: _cmd]; abort(); } - (void*)resizeMemory: (void*)ptr - toNItems: (size_t)nitems - withSize: (size_t)size + size: (size_t)nitems + count: (size_t)size { [self doesNotRecognizeSelector: _cmd]; abort(); } @@ -151,12 +151,12 @@ if ((ivars = calloc(1, sizeof(*ivars))) == NULL) @throw [OFOutOfMemoryException exceptionWithClass: [self class] requestedSize: sizeof(*ivars)]; - ivars->cString = cString; - ivars->cStringLength = cStringLength; + ivars->cString = _cString; + ivars->cStringLength = _cStringLength; switch (of_string_utf8_check(ivars->cString, ivars->cStringLength, &ivars->length)) { case 1: ivars->isUTF8 = YES; @@ -165,11 +165,11 @@ free(ivars); @throw [OFInvalidEncodingException exceptionWithClass: [self class]]; } - cString = (char*)ivars; + _cString = (char*)ivars; object_setClass(self, [OFString_const class]); } + alloc { Index: src/OFCountedSet_hashtable.h ================================================================== --- src/OFCountedSet_hashtable.h +++ src/OFCountedSet_hashtable.h @@ -18,8 +18,8 @@ @class OFMapTable; @interface OFCountedSet_hashtable: OFCountedSet { - OFMapTable *mapTable; + OFMapTable *_mapTable; } @end Index: src/OFCountedSet_hashtable.m ================================================================== --- src/OFCountedSet_hashtable.m +++ src/OFCountedSet_hashtable.m @@ -166,12 +166,12 @@ @throw [OFInvalidFormatException exceptionWithClass: [self class]]; count = (size_t)[[count_ stringValue] decimalValue]; - [mapTable setValue: (void*)(uintptr_t)count - forKey: [object objectByDeserializing]]; + [_mapTable setValue: (void*)(uintptr_t)count + forKey: [object objectByDeserializing]]; objc_autoreleasePoolPop(pool2); } objc_autoreleasePoolPop(pool); @@ -183,19 +183,19 @@ return self; } - (size_t)countForObject: (id)object { - return (size_t)(uintptr_t)[mapTable valueForKey: object]; + return (size_t)(uintptr_t)[_mapTable valueForKey: object]; } #ifdef OF_HAVE_BLOCKS - (void)enumerateObjectsAndCountUsingBlock: (of_counted_set_enumeration_block_t)block { @try { - [mapTable enumerateKeysAndValuesUsingBlock: + [_mapTable enumerateKeysAndValuesUsingBlock: ^ (void *key, void *value, BOOL *stop) { block(key, (size_t)(uintptr_t)value, stop); }]; } @catch (OFEnumerationMutationException *e) { @throw [OFEnumerationMutationException @@ -205,34 +205,34 @@ } #endif - (void)addObject: (id)object { - size_t count = (size_t)(uintptr_t)[mapTable valueForKey: object]; + size_t count = (size_t)(uintptr_t)[_mapTable valueForKey: object]; if (SIZE_MAX - count < 1) @throw [OFOutOfRangeException exceptionWithClass: [self class]]; - [mapTable setValue: (void*)(uintptr_t)(count + 1) - forKey: object]; + [_mapTable setValue: (void*)(uintptr_t)(count + 1) + forKey: object]; } - (void)removeObject: (id)object { - size_t count = (size_t)(uintptr_t)[mapTable valueForKey: object]; + size_t count = (size_t)(uintptr_t)[_mapTable valueForKey: object]; if (count == 0) return; count--; if (count > 0) - [mapTable setValue: (void*)(uintptr_t)count - forKey: object]; + [_mapTable setValue: (void*)(uintptr_t)count + forKey: object]; else - [mapTable removeValueForKey: object]; + [_mapTable removeValueForKey: object]; } - (void)makeImmutable { } @end Index: src/OFDataArray+Hashing.m ================================================================== --- src/OFDataArray+Hashing.m +++ src/OFDataArray+Hashing.m @@ -32,12 +32,12 @@ OFMD5Hash *hash = [OFMD5Hash hash]; uint8_t *digest; char cString[OF_MD5_DIGEST_SIZE * 2]; size_t i; - [hash updateWithBuffer: items - length: count * itemSize]; + [hash updateWithBuffer: _items + length: _count * _itemSize]; digest = [hash digest]; for (i = 0; i < OF_MD5_DIGEST_SIZE; i++) { uint8_t high, low; @@ -61,12 +61,12 @@ OFSHA1Hash *hash = [OFSHA1Hash hash]; uint8_t *digest; char cString[OF_SHA1_DIGEST_SIZE * 2]; size_t i; - [hash updateWithBuffer: items - length: count * itemSize]; + [hash updateWithBuffer: _items + length: _count * _itemSize]; digest = [hash digest]; for (i = 0; i < OF_SHA1_DIGEST_SIZE; i++) { uint8_t high, low; Index: src/OFDataArray.h ================================================================== --- src/OFDataArray.h +++ src/OFDataArray.h @@ -29,13 +29,13 @@ * For security reasons, serialization and deserialization is only implemented * for OFDataArrays with item size 1. */ @interface OFDataArray: OFObject { - uint8_t *items; - size_t count; - size_t itemSize; + uint8_t *_items; + size_t _count; + size_t _itemSize; } #ifdef OF_HAVE_PROPERTIES @property (readonly) void *items; @property (readonly) size_t count; @@ -276,10 +276,10 @@ * and is designed to store large hunks of data. Therefore, it allocates * memory in pages rather than a chunk of memory for each item. */ @interface OFBigDataArray: OFDataArray { - size_t size; + size_t _size; } @end #import "OFDataArray+Hashing.h" Index: src/OFDataArray.m ================================================================== --- src/OFDataArray.m +++ src/OFDataArray.m @@ -82,27 +82,27 @@ - init { self = [super init]; - itemSize = 1; + _itemSize = 1; return self; } -- initWithItemSize: (size_t)itemSize_ +- initWithItemSize: (size_t)itemSize { self = [super init]; - if (itemSize_ == 0) { + if (itemSize == 0) { Class c = [self class]; [self release]; @throw [OFInvalidArgumentException exceptionWithClass: c selector: _cmd]; } - itemSize = itemSize_; + _itemSize = itemSize; return self; } - initWithContentsOfFile: (OFString*)path @@ -111,11 +111,11 @@ @try { OFFile *file = [[OFFile alloc] initWithPath: path mode: @"rb"]; - itemSize = 1; + _itemSize = 1; @try { size_t pageSize = [OFSystemInfo pageSize]; char *buffer = [self allocMemoryWithSize: pageSize]; @@ -190,24 +190,24 @@ @try { const char *cString; size_t i; - itemSize = 1; - count = [string + _itemSize = 1; + _count = [string cStringLengthWithEncoding: OF_STRING_ENCODING_ASCII]; - if (count & 1) + if (_count & 1) @throw [OFInvalidFormatException exceptionWithClass: [self class]]; - count >>= 1; + _count >>= 1; cString = [string cStringWithEncoding: OF_STRING_ENCODING_ASCII]; - items = [self allocMemoryWithSize: count]; + _items = [self allocMemoryWithSize: _count]; - for (i = 0; i < count; i++) { + for (i = 0; i < _count; i++) { uint8_t c1 = cString[2 * i]; uint8_t c2 = cString[2 * i + 1]; uint8_t byte; if (c1 >= '0' && c1 <= '9') @@ -228,11 +228,11 @@ byte |= c2 - 'A' + 10; else @throw [OFInvalidFormatException exceptionWithClass: [self class]]; - items[i] = byte; + _items[i] = byte; } } @catch (id e) { [self release]; @throw e; } @@ -243,11 +243,11 @@ - initWithBase64EncodedString: (OFString*)string { self = [super init]; @try { - itemSize = 1; + _itemSize = 1; if (!of_base64_decode(self, [string cStringWithEncoding: OF_STRING_ENCODING_ASCII], [string cStringLengthWithEncoding: OF_STRING_ENCODING_ASCII])) { Class c = [self class]; @@ -264,11 +264,11 @@ - initWithSerialization: (OFXMLElement*)element { self = [super init]; - itemSize = 1; + _itemSize = 1; @try { void *pool = objc_autoreleasePoolPush(); OFString *stringValue; @@ -296,59 +296,59 @@ return self; } - (size_t)count { - return count; + return _count; } - (size_t)itemSize { - return itemSize; + return _itemSize; } - (void*)items { - return items; + return _items; } - (void*)itemAtIndex: (size_t)index { - if (index >= count) + if (index >= _count) @throw [OFOutOfRangeException exceptionWithClass: [self class]]; - return items + index * itemSize; + return _items + index * _itemSize; } - (void*)firstItem { - if (items == NULL || count == 0) + if (_items == NULL || _count == 0) return NULL; - return items; + return _items; } - (void*)lastItem { - if (items == NULL || count == 0) + if (_items == NULL || _count == 0) return NULL; - return items + (count - 1) * itemSize; + return _items + (_count - 1) * _itemSize; } - (void)addItem: (const void*)item { - if (SIZE_MAX - count < 1) + if (SIZE_MAX - _count < 1) @throw [OFOutOfRangeException exceptionWithClass: [self class]]; - items = [self resizeMemory: items - size: itemSize - count: count + 1]; + _items = [self resizeMemory: _items + size: _itemSize + count: _count + 1]; - memcpy(items + count * itemSize, item, itemSize); + memcpy(_items + _count * _itemSize, item, _itemSize); - count++; + _count++; } - (void)insertItem: (const void*)item atIndex: (size_t)index { @@ -355,40 +355,40 @@ [self insertItems: item atIndex: index count: 1]; } -- (void)addItems: (const void*)items_ - count: (size_t)count_ +- (void)addItems: (const void*)items + count: (size_t)count { - if (count_ > SIZE_MAX - count) + if (count > SIZE_MAX - count) @throw [OFOutOfRangeException exceptionWithClass: [self class]]; - items = [self resizeMemory: items - size: itemSize - count: count + count_]; + _items = [self resizeMemory: _items + size: _itemSize + count: _count + count]; - memcpy(items + count * itemSize, items_, count_ * itemSize); - count += count_; + memcpy(_items + _count * _itemSize, items, count * _itemSize); + _count += count; } -- (void)insertItems: (const void*)items_ +- (void)insertItems: (const void*)items atIndex: (size_t)index - count: (size_t)count_ + count: (size_t)count { - if (count_ > SIZE_MAX - count || index > count) + if (count > SIZE_MAX - _count || index > _count) @throw [OFOutOfRangeException exceptionWithClass: [self class]]; - items = [self resizeMemory: items - size: itemSize - count: count + count_]; - - memmove(items + (index + count_) * itemSize, items + index * itemSize, - (count - index) * itemSize); - memcpy(items + index * itemSize, items_, count_ * itemSize); - - count += count_; + _items = [self resizeMemory: _items + size: _itemSize + count: _count + count]; + + memmove(_items + (index + count) * _itemSize, + _items + index * _itemSize, (_count - index) * _itemSize); + memcpy(_items + index * _itemSize, items, count * _itemSize); + + _count += count; } - (void)removeItemAtIndex: (size_t)index { [self removeItemsInRange: of_range(index, 1)]; @@ -395,104 +395,105 @@ } - (void)removeItemsInRange: (of_range_t)range { if (range.length > SIZE_MAX - range.location || - range.location + range.length > count) + range.location + range.length > _count) @throw [OFOutOfRangeException exceptionWithClass: [self class]]; - memmove(items + range.location * itemSize, - items + (range.location + range.length) * itemSize, - (count - range.location - range.length) * itemSize); + memmove(_items + range.location * _itemSize, + _items + (range.location + range.length) * _itemSize, + (_count - range.location - range.length) * _itemSize); - count -= range.length; + _count -= range.length; @try { - items = [self resizeMemory: items - size: itemSize - count: count]; + _items = [self resizeMemory: _items + size: _itemSize + count: _count]; } @catch (OFOutOfMemoryException *e) { /* We don't really care, as we only made it smaller */ } } - (void)removeLastItem { - if (count == 0) + if (_count == 0) return; - count--; + _count--; @try { - items = [self resizeMemory: items - size: itemSize - count: count]; + _items = [self resizeMemory: _items + size: _itemSize + count: _count]; } @catch (OFOutOfMemoryException *e) { /* We don't care, as we only made it smaller */ } } - (void)removeAllItems { - [self freeMemory: items]; + [self freeMemory: _items]; - items = NULL; - count = 0; + _items = NULL; + _count = 0; } - copy { - OFDataArray *copy = [[[self class] alloc] initWithItemSize: itemSize]; + OFDataArray *copy = [[[self class] alloc] initWithItemSize: _itemSize]; - [copy addItems: items - count: count]; + [copy addItems: _items + count: _count]; return copy; } - (BOOL)isEqual: (id)object { - OFDataArray *otherDataArray; + OFDataArray *dataArray; if (![object isKindOfClass: [OFDataArray class]]) return NO; - otherDataArray = object; + dataArray = object; - if ([otherDataArray count] != count || - [otherDataArray itemSize] != itemSize) + if ([dataArray count] != _count || + [dataArray itemSize] != _itemSize) return NO; - if (memcmp([otherDataArray items], items, count * itemSize)) + if (memcmp([dataArray items], _items, _count * _itemSize)) return NO; return YES; } - (of_comparison_result_t)compare: (id )object { - OFDataArray *otherDataArray; + OFDataArray *dataArray; int comparison; - size_t otherCount, minimumCount; + size_t count, minCount; if (![object isKindOfClass: [OFDataArray class]]) @throw [OFInvalidArgumentException exceptionWithClass: [self class] selector: _cmd]; - otherDataArray = (OFDataArray*)object; + dataArray = (OFDataArray*)object; - if ([otherDataArray itemSize] != itemSize) + if ([dataArray itemSize] != _itemSize) @throw [OFInvalidArgumentException exceptionWithClass: [self class] selector: _cmd]; - otherCount = [otherDataArray count]; - minimumCount = (count > otherCount ? otherCount : count); + count = [dataArray count]; + minCount = (_count > count ? count : _count); - if ((comparison = memcmp(items, [otherDataArray items], - minimumCount * itemSize)) == 0) { - if (count > otherCount) + if ((comparison = memcmp(_items, [dataArray items], + minCount * _itemSize)) == 0) { + if (_count > count) return OF_ORDERED_DESCENDING; - if (count < otherCount) + if (_count < count) return OF_ORDERED_ASCENDING; + return OF_ORDERED_SAME; } if (comparison > 0) return OF_ORDERED_DESCENDING; @@ -505,12 +506,12 @@ uint32_t hash; size_t i; OF_HASH_INIT(hash); - for (i = 0; i < count * itemSize; i++) - OF_HASH_ADD(hash, ((uint8_t*)items)[i]); + for (i = 0; i < _count * _itemSize; i++) + OF_HASH_ADD(hash, ((uint8_t*)_items)[i]); OF_HASH_FINALIZE(hash); return hash; } @@ -518,18 +519,18 @@ - (OFString*)description { OFMutableString *ret = [OFMutableString stringWithString: @"<"]; size_t i; - for (i = 0; i < count; i++) { + for (i = 0; i < _count; i++) { size_t j; if (i > 0) [ret appendString: @" "]; - for (j = 0; j < itemSize; j++) - [ret appendFormat: @"%02x", items[i * itemSize + j]]; + for (j = 0; j < _itemSize; j++) + [ret appendFormat: @"%02x", _items[i * _itemSize + j]]; } [ret appendString: @">"]; [ret makeImmutable]; @@ -539,31 +540,31 @@ - (OFString*)stringRepresentation { OFMutableString *ret = [OFMutableString string]; size_t i, j; - for (i = 0; i < count; i++) - for (j = 0; j < itemSize; j++) - [ret appendFormat: @"%02x", items[i * itemSize + j]]; + for (i = 0; i < _count; i++) + for (j = 0; j < _itemSize; j++) + [ret appendFormat: @"%02x", _items[i * _itemSize + j]]; [ret makeImmutable]; return ret; } - (OFString*)stringByBase64Encoding { - return of_base64_encode(items, count * itemSize); + return of_base64_encode(_items, _count * _itemSize); } - (void)writeToFile: (OFString*)path { OFFile *file = [[OFFile alloc] initWithPath: path mode: @"wb"]; @try { - [file writeBuffer: items - length: count * itemSize]; + [file writeBuffer: _items + length: _count * _itemSize]; } @finally { [file release]; } } @@ -570,19 +571,19 @@ - (OFXMLElement*)XMLElementBySerializing { void *pool; OFXMLElement *element; - if (itemSize != 1) + if (_itemSize != 1) @throw [OFInvalidArgumentException exceptionWithClass: [self class]]; pool = objc_autoreleasePoolPush(); element = [OFXMLElement elementWithName: [self className] namespace: OF_SERIALIZATION_NS - stringValue: of_base64_encode(items, count * itemSize)]; + stringValue: of_base64_encode(_items, _count * _itemSize)]; [element retain]; objc_autoreleasePoolPop(pool); @@ -591,135 +592,135 @@ @end @implementation OFBigDataArray - (void)addItem: (const void*)item { - size_t newSize, lastPageByte; - - if (SIZE_MAX - count < 1 || count + 1 > SIZE_MAX / itemSize) - @throw [OFOutOfRangeException exceptionWithClass: [self class]]; - - lastPageByte = [OFSystemInfo pageSize] - 1; - newSize = ((count + 1) * itemSize + lastPageByte) & ~lastPageByte; - - if (size != newSize) - items = [self resizeMemory: items - size: newSize]; - - memcpy(items + count * itemSize, item, itemSize); - - count++; - size = newSize; -} - -- (void)addItems: (const void*)items_ - count: (size_t)count_ -{ - size_t newSize, lastPageByte; - - if (count_ > SIZE_MAX - count || count + count_ > SIZE_MAX / itemSize) - @throw [OFOutOfRangeException exceptionWithClass: [self class]]; - - lastPageByte = [OFSystemInfo pageSize] - 1; - newSize = ((count + count_) * itemSize + lastPageByte) & ~lastPageByte; - - if (size != newSize) - items = [self resizeMemory: items - size: newSize]; - - memcpy(items + count * itemSize, items_, count_ * itemSize); - - count += count_; - size = newSize; -} - -- (void)insertItems: (const void*)items_ - atIndex: (size_t)index - count: (size_t)count_ -{ - size_t newSize, lastPageByte; - - if (count_ > SIZE_MAX - count || index > count || - count + count_ > SIZE_MAX / itemSize) - @throw [OFOutOfRangeException exceptionWithClass: [self class]]; - - lastPageByte = [OFSystemInfo pageSize] - 1; - newSize = ((count + count_) * itemSize + lastPageByte) & ~lastPageByte; - - if (size != newSize) - items = [self resizeMemory: items - size: newSize]; - - memmove(items + (index + count_) * itemSize, items + index * itemSize, - (count - index) * itemSize); - memcpy(items + index * itemSize, items_, count_ * itemSize); - - count += count_; - size = newSize; + size_t size, lastPageByte; + + if (SIZE_MAX - _count < 1 || _count + 1 > SIZE_MAX / _itemSize) + @throw [OFOutOfRangeException exceptionWithClass: [self class]]; + + lastPageByte = [OFSystemInfo pageSize] - 1; + size = ((_count + 1) * _itemSize + lastPageByte) & ~lastPageByte; + + if (_size != size) + _items = [self resizeMemory: _items + size: size]; + + memcpy(_items + _count * _itemSize, item, _itemSize); + + _count++; + _size = size; +} + +- (void)addItems: (const void*)items + count: (size_t)count +{ + size_t size, lastPageByte; + + if (count > SIZE_MAX - _count || _count + count > SIZE_MAX / _itemSize) + @throw [OFOutOfRangeException exceptionWithClass: [self class]]; + + lastPageByte = [OFSystemInfo pageSize] - 1; + size = ((_count + count) * _itemSize + lastPageByte) & ~lastPageByte; + + if (_size != size) + _items = [self resizeMemory: _items + size: size]; + + memcpy(_items + _count * _itemSize, items, count * _itemSize); + + _count += count; + _size = size; +} + +- (void)insertItems: (const void*)items + atIndex: (size_t)index + count: (size_t)count +{ + size_t size, lastPageByte; + + if (count > SIZE_MAX - _count || index > _count || + _count + count > SIZE_MAX / _itemSize) + @throw [OFOutOfRangeException exceptionWithClass: [self class]]; + + lastPageByte = [OFSystemInfo pageSize] - 1; + size = ((_count + count) * _itemSize + lastPageByte) & ~lastPageByte; + + if (_size != size) + _items = [self resizeMemory: _items + size: size]; + + memmove(_items + (index + count) * _itemSize, + _items + index * _itemSize, (_count - index) * _itemSize); + memcpy(_items + index * _itemSize, items, count * _itemSize); + + _count += count; + _size = size; } - (void)removeItemsInRange: (of_range_t)range { - size_t pageSize, newSize; + size_t pageSize, size; if (range.length > SIZE_MAX - range.location || - range.location + range.length > count) + range.location + range.length > _count) @throw [OFOutOfRangeException exceptionWithClass: [self class]]; - memmove(items + range.location * itemSize, - items + (range.location + range.length) * itemSize, - (count - range.location - range.length) * itemSize); + memmove(_items + range.location * _itemSize, + _items + (range.location + range.length) * _itemSize, + (_count - range.location - range.length) * _itemSize); - count -= range.length; + _count -= range.length; pageSize = [OFSystemInfo pageSize]; - newSize = (count * itemSize + pageSize - 1) & ~(pageSize - 1); + size = (_count * _itemSize + pageSize - 1) & ~(pageSize - 1); - if (size != newSize && newSize >= pageSize) { + if (_size != size && size >= pageSize) { @try { - items = [self resizeMemory: items - size: newSize]; + _items = [self resizeMemory: _items + size: size]; } @catch (OFOutOfMemoryException *e) { /* We don't care, as we only made it smaller */ } - size = newSize; + _size = size; } } - (void)removeLastItem { - size_t pageSize, newSize; + size_t pageSize, size; - if (count == 0) + if (_count == 0) return; - count--; - pageSize = [OFSystemInfo pageSize]; - newSize = (count * itemSize + pageSize - 1) & ~(pageSize - 1); - - if (size != newSize && newSize >= pageSize) { - @try { - items = [self resizeMemory: items - size: newSize]; + _count--; + pageSize = [OFSystemInfo pageSize]; + size = (_count * _itemSize + pageSize - 1) & ~(pageSize - 1); + + if (_size != size && size >= pageSize) { + @try { + _items = [self resizeMemory: _items + size: size]; } @catch (OFOutOfMemoryException *e) { /* We don't care, as we only made it smaller */ } - size = newSize; + _size = size; } } - (void)removeAllItems { size_t pageSize = [OFSystemInfo pageSize]; @try { - items = [self resizeMemory: items - size: pageSize]; - size = pageSize; + _items = [self resizeMemory: _items + size: pageSize]; + _size = pageSize; } @catch (OFOutOfMemoryException *e) { /* We don't care, as we only made it smaller */ } - count = 0; + _count = 0; } @end Index: src/OFDate.h ================================================================== --- src/OFDate.h +++ src/OFDate.h @@ -23,11 +23,11 @@ /*! * @brief A class for storing, accessing and comparing dates. */ @interface OFDate: OFObject { - double seconds; + double _seconds; } /*! * @brief Creates a new OFDate with the current date and time. * Index: src/OFDate.m ================================================================== --- src/OFDate.m +++ src/OFDate.m @@ -48,98 +48,98 @@ static OFMutex *mutex; #endif #ifdef HAVE_GMTIME_R # define GMTIME_RET(field) \ - time_t seconds_ = (time_t)seconds; \ + time_t seconds = (time_t)_seconds; \ struct tm tm; \ \ - if (seconds_ != floor(seconds)) \ + if (seconds != floor(_seconds)) \ @throw [OFOutOfRangeException \ exceptionWithClass: [self class]]; \ \ - if (gmtime_r(&seconds_, &tm) == NULL) \ + if (gmtime_r(&seconds, &tm) == NULL) \ @throw [OFOutOfRangeException \ exceptionWithClass: [self class]]; \ \ return tm.field; # define LOCALTIME_RET(field) \ - time_t seconds_ = (time_t)seconds; \ + time_t seconds = (time_t)_seconds; \ struct tm tm; \ \ - if (seconds_ != floor(seconds)) \ + if (seconds != floor(_seconds)) \ @throw [OFOutOfRangeException \ exceptionWithClass: [self class]]; \ \ - if (localtime_r(&seconds_, &tm) == NULL) \ + if (localtime_r(&seconds, &tm) == NULL) \ @throw [OFOutOfRangeException \ exceptionWithClass: [self class]]; \ \ return tm.field; #else # ifdef OF_HAVE_THREADS # define GMTIME_RET(field) \ - time_t seconds_ = (time_t)seconds; \ + time_t seconds = (time_t)_seconds; \ struct tm *tm; \ \ - if (seconds_ != floor(seconds)) \ + if (seconds != floor(_seconds)) \ @throw [OFOutOfRangeException \ exceptionWithClass: [self class]]; \ \ [mutex lock]; \ \ @try { \ - if ((tm = gmtime(&seconds_)) == NULL) \ + if ((tm = gmtime(&seconds)) == NULL) \ @throw [OFOutOfRangeException \ exceptionWithClass: [self class]]; \ \ return tm->field; \ } @finally { \ [mutex unlock]; \ } # define LOCALTIME_RET(field) \ - time_t seconds_ = (time_t)seconds; \ + time_t seconds = (time_t)_seconds; \ struct tm *tm; \ \ - if (seconds_ != floor(seconds)) \ + if (seconds != floor(_seconds)) \ @throw [OFOutOfRangeException \ exceptionWithClass: [self class]]; \ \ [mutex lock]; \ \ @try { \ - if ((tm = localtime(&seconds_)) == NULL) \ + if ((tm = localtime(&seconds)) == NULL) \ @throw [OFOutOfRangeException \ exceptionWithClass: [self class]]; \ \ return tm->field; \ } @finally { \ [mutex unlock]; \ } # else # define GMTIME_RET(field) \ - time_t seconds_ = (time_t)seconds; \ + time_t seconds = (time_t)_seconds; \ struct tm *tm; \ \ - if (seconds_ != floor(seconds)) \ + if (seconds != floor(_seconds)) \ @throw [OFOutOfRangeException \ exceptionWithClass: [self class]]; \ \ - if ((tm = gmtime(&seconds_)) == NULL) \ + if ((tm = gmtime(&seconds)) == NULL) \ @throw [OFOutOfRangeException \ exceptionWithClass: [self class]]; \ \ return tm->field; # define LOCALTIME_RET(field) \ - time_t seconds_ = (time_t)seconds; \ + time_t seconds = (time_t)_seconds; \ struct tm *tm; \ \ - if (seconds_ != floor(seconds)) \ + if (seconds != floor(_seconds)) \ @throw [OFOutOfRangeException \ exceptionWithClass: [self class]]; \ \ - if ((tm = localtime(&seconds_)) == NULL) \ + if ((tm = localtime(&seconds)) == NULL) \ @throw [OFOutOfRangeException \ exceptionWithClass: [self class]]; \ \ return tm->field; # endif @@ -217,32 +217,32 @@ { struct timeval t; self = [super init]; - OF_ENSURE(!gettimeofday(&t, NULL)); + OF_ENSURE(gettimeofday(&t, NULL) == 0); - seconds = t.tv_sec; - seconds += (double)t.tv_usec / 1000000; + _seconds = t.tv_sec; + _seconds += (double)t.tv_usec / 1000000; return self; } -- initWithTimeIntervalSince1970: (double)seconds_ +- initWithTimeIntervalSince1970: (double)seconds { self = [super init]; - seconds = seconds_; + _seconds = seconds; return self; } -- initWithTimeIntervalSinceNow: (double)seconds_ +- initWithTimeIntervalSinceNow: (double)seconds { self = [self init]; - seconds += seconds_; + _seconds += seconds; return self; } - initWithDateString: (OFString*)string @@ -259,33 +259,33 @@ &tm) == NULL) @throw [OFInvalidFormatException exceptionWithClass: [self class]]; /* Years */ - seconds = (int64_t)(tm.tm_year - 70) * 31536000; + _seconds = (int64_t)(tm.tm_year - 70) * 31536000; /* Days of leap years, excluding the year to look at */ - seconds += (((tm.tm_year + 1899) / 4) - 492) * 86400; - seconds -= (((tm.tm_year + 1899) / 100) - 19) * 86400; - seconds += (((tm.tm_year + 1899) / 400) - 4) * 86400; + _seconds += (((tm.tm_year + 1899) / 4) - 492) * 86400; + _seconds -= (((tm.tm_year + 1899) / 100) - 19) * 86400; + _seconds += (((tm.tm_year + 1899) / 400) - 4) * 86400; /* Leap day */ if (tm.tm_mon >= 2 && (((tm.tm_year + 1900) % 4 == 0 && (tm.tm_year + 1900) % 100 != 0) || (tm.tm_year + 1900) % 400 == 0)) - seconds += 86400; + _seconds += 86400; /* Months */ if (tm.tm_mon < 0 || tm.tm_mon > 12) @throw [OFInvalidFormatException exceptionWithClass: [self class]]; - seconds += month_to_day_of_year[tm.tm_mon] * 86400; + _seconds += month_to_day_of_year[tm.tm_mon] * 86400; /* Days */ - seconds += (tm.tm_mday - 1) * 86400; + _seconds += (tm.tm_mday - 1) * 86400; /* Hours */ - seconds += tm.tm_hour * 3600; + _seconds += tm.tm_hour * 3600; /* Minutes */ - seconds += tm.tm_min * 60; + _seconds += tm.tm_min * 60; /* Seconds */ - seconds += tm.tm_sec; + _seconds += tm.tm_sec; } @catch (id e) { [self release]; @throw e; } @@ -305,11 +305,11 @@ if (of_strptime([string UTF8String], [format UTF8String], &tm) == NULL) @throw [OFInvalidFormatException exceptionWithClass: [self class]]; - if ((seconds = mktime(&tm)) == -1) + if ((_seconds = mktime(&tm)) == -1) @throw [OFInvalidFormatException exceptionWithClass: [self class]]; } @catch (id e) { [self release]; @throw e; @@ -334,11 +334,11 @@ @throw [OFInvalidArgumentException exceptionWithClass: [self class] selector: _cmd]; d.u = (uint64_t)[element hexadecimalValue]; - seconds = d.d; + _seconds = d.d; objc_autoreleasePoolPop(pool); } @catch (id e) { [self release]; @throw e; @@ -354,11 +354,11 @@ if (![object isKindOfClass: [OFDate class]]) return NO; otherDate = object; - if (otherDate->seconds != seconds) + if (otherDate->_seconds != _seconds) return NO; return YES; } @@ -369,11 +369,11 @@ double d; uint8_t b[sizeof(double)]; } d; uint_fast8_t i; - d.d = OF_BSWAP_DOUBLE_IF_BE(seconds); + d.d = OF_BSWAP_DOUBLE_IF_BE(_seconds); OF_HASH_INIT(hash); for (i = 0; i < sizeof(double); i++) OF_HASH_ADD(hash, d.b[i]); @@ -397,13 +397,13 @@ exceptionWithClass: [self class] selector: _cmd]; otherDate = (OFDate*)object; - if (seconds < otherDate->seconds) + if (_seconds < otherDate->_seconds) return OF_ORDERED_ASCENDING; - if (seconds > otherDate->seconds) + if (_seconds > otherDate->_seconds) return OF_ORDERED_DESCENDING; return OF_ORDERED_SAME; } @@ -422,11 +422,11 @@ } d; element = [OFXMLElement elementWithName: [self className] namespace: OF_SERIALIZATION_NS]; - d.d = seconds; + d.d = _seconds; [element setStringValue: [OFString stringWithFormat: @"%016" PRIx64, d.u]]; [element retain]; @@ -435,11 +435,11 @@ return [element autorelease]; } - (uint32_t)microsecond { - return (uint32_t)rint((seconds - floor(seconds)) * 1000000); + return (uint32_t)rint((_seconds - floor(_seconds)) * 1000000); } - (uint8_t)second { GMTIME_RET(tm_sec) @@ -511,30 +511,30 @@ } - (OFString*)dateStringWithFormat: (OFConstantString*)format { OFString *ret; - time_t seconds_ = (time_t)seconds; + time_t seconds = (time_t)_seconds; struct tm tm; size_t pageSize; char *buffer; - if (seconds_ != floor(seconds)) + if (seconds != floor(_seconds)) @throw [OFOutOfRangeException exceptionWithClass: [self class]]; #ifdef HAVE_GMTIME_R - if (gmtime_r(&seconds_, &tm) == NULL) + if (gmtime_r(&seconds, &tm) == NULL) @throw [OFOutOfRangeException exceptionWithClass: [self class]]; #else # ifdef OF_HAVE_THREADS [mutex lock]; @try { # endif struct tm *tmp; - if ((tmp = gmtime(&seconds_)) == NULL) + if ((tmp = gmtime(&seconds)) == NULL) @throw [OFOutOfRangeException exceptionWithClass: [self class]]; tm = *tmp; # ifdef OF_HAVE_THREADS @@ -561,30 +561,30 @@ } - (OFString*)localDateStringWithFormat: (OFConstantString*)format { OFString *ret; - time_t seconds_ = (time_t)seconds; + time_t seconds = (time_t)_seconds; struct tm tm; size_t pageSize; char *buffer; - if (seconds_ != floor(seconds)) + if (seconds != floor(_seconds)) @throw [OFOutOfRangeException exceptionWithClass: [self class]]; #ifdef HAVE_LOCALTIME_R - if (localtime_r(&seconds_, &tm) == NULL) + if (localtime_r(&seconds, &tm) == NULL) @throw [OFOutOfRangeException exceptionWithClass: [self class]]; #else # ifdef OF_HAVE_THREADS [mutex lock]; @try { # endif struct tm *tmp; - if ((tmp = localtime(&seconds_)) == NULL) + if ((tmp = localtime(&seconds)) == NULL) @throw [OFOutOfRangeException exceptionWithClass: [self class]]; tm = *tmp; # ifdef OF_HAVE_THREADS @@ -632,31 +632,31 @@ return [[self retain] autorelease]; } - (double)timeIntervalSince1970 { - return seconds; + return _seconds; } - (double)timeIntervalSinceDate: (OFDate*)otherDate { - return seconds - otherDate->seconds; + return _seconds - otherDate->_seconds; } - (double)timeIntervalSinceNow { struct timeval t; - double seconds_; + double seconds; OF_ENSURE(!gettimeofday(&t, NULL)); - seconds_ = t.tv_sec; - seconds_ += (double)t.tv_usec / 1000000; + seconds = t.tv_sec; + seconds += (double)t.tv_usec / 1000000; - return seconds - seconds_; + return _seconds - seconds; } -- (OFDate*)dateByAddingTimeInterval: (double)seconds_ +- (OFDate*)dateByAddingTimeInterval: (double)seconds { - return [OFDate dateWithTimeIntervalSince1970: seconds + seconds_]; + return [OFDate dateWithTimeIntervalSince1970: _seconds + seconds]; } @end Index: src/OFDictionary_hashtable.h ================================================================== --- src/OFDictionary_hashtable.h +++ src/OFDictionary_hashtable.h @@ -19,10 +19,10 @@ @class OFMapTable; @class OFMapTableEnumerator; @interface OFDictionary_hashtable: OFDictionary { - OFMapTable *mapTable; + OFMapTable *_mapTable; } - initWithCapacity: (size_t)capacity; @end Index: src/OFDictionary_hashtable.m ================================================================== --- src/OFDictionary_hashtable.m +++ src/OFDictionary_hashtable.m @@ -83,11 +83,11 @@ - initWithCapacity: (size_t)capacity { self = [super init]; @try { - mapTable = [[OFMapTable alloc] + _mapTable = [[OFMapTable alloc] initWithKeyFunctions: keyFunctions valueFunctions: valueFunctions capacity: capacity]; } @catch (id e) { [self release]; @@ -110,11 +110,11 @@ @try { OFDictionary_hashtable *dictionary_ = (OFDictionary_hashtable*)dictionary; - mapTable = [dictionary_->mapTable copy]; + _mapTable = [dictionary_->_mapTable copy]; } @catch (id e) { [self release]; @throw e; } @@ -137,12 +137,12 @@ keyEnumerator = [dictionary keyEnumerator]; objectEnumerator = [dictionary objectEnumerator]; while ((key = [keyEnumerator nextObject]) != nil && (object = [objectEnumerator nextObject]) != nil) - [mapTable setValue: object - forKey: key]; + [_mapTable setValue: object + forKey: key]; objc_autoreleasePoolPop(pool); } @catch (id e) { [self release]; @throw e; @@ -155,12 +155,12 @@ forKey: (id)key { self = [self initWithCapacity: 1]; @try { - [mapTable setValue: object - forKey: key]; + [_mapTable setValue: object + forKey: key]; } @catch (id e) { [self release]; @throw e; } @@ -175,12 +175,12 @@ @try { size_t i; for (i = 0; i < count; i++) - [mapTable setValue: objects[i] - forKey: keys[i]]; + [_mapTable setValue: objects[i] + forKey: keys[i]]; } @catch (id e) { [self release]; @throw e; } @@ -213,17 +213,17 @@ count = 1; for (; va_arg(argumentsCopy, id) != nil; count++); count >>= 1; - mapTable = [[OFMapTable alloc] + _mapTable = [[OFMapTable alloc] initWithKeyFunctions: keyFunctions valueFunctions: valueFunctions capacity: count]; - [mapTable setValue: object - forKey: key]; + [_mapTable setValue: object + forKey: key]; for (i = 1; i < count; i++) { key = va_arg(arguments, id); object = va_arg(arguments, id); @@ -230,12 +230,12 @@ if (key == nil || object == nil) @throw [OFInvalidArgumentException exceptionWithClass: [self class] selector: _cmd]; - [mapTable setValue: object - forKey: key]; + [_mapTable setValue: object + forKey: key]; } } @catch (id e) { [self release]; @throw e; } @@ -260,11 +260,11 @@ if ([keys count] != [objects count]) @throw [OFInvalidFormatException exceptionWithClass: [self class]]; - mapTable = [[OFMapTable alloc] + _mapTable = [[OFMapTable alloc] initWithKeyFunctions: keyFunctions valueFunctions: valueFunctions capacity: [keys count]]; keyEnumerator = [keys objectEnumerator]; @@ -281,12 +281,12 @@ if (key == nil || object == nil) @throw [OFInvalidFormatException exceptionWithClass: [self class]]; - [mapTable setValue: [object objectByDeserializing] - forKey: [key objectByDeserializing]]; + [_mapTable setValue: [object objectByDeserializing] + forKey: [key objectByDeserializing]]; objc_autoreleasePoolPop(pool2); } objc_autoreleasePoolPop(pool); @@ -295,19 +295,26 @@ @throw e; } return self; } + +- (void)dealloc +{ + [_mapTable dealloc]; + + [super dealloc]; +} - (id)objectForKey: (id)key { - return [mapTable valueForKey: key]; + return [_mapTable valueForKey: key]; } - (size_t)count { - return [mapTable count]; + return [_mapTable count]; } - (BOOL)isEqual: (id)dictionary { OFDictionary_hashtable *dictionary_; @@ -316,30 +323,30 @@ [self class] != [OFMutableDictionary_hashtable class]) return [super isEqual: dictionary]; dictionary_ = (OFDictionary_hashtable*)dictionary; - return [dictionary_->mapTable isEqual: mapTable]; + return [dictionary_->_mapTable isEqual: _mapTable]; } - (BOOL)containsObject: (id)object { - return [mapTable containsValue: object]; + return [_mapTable containsValue: object]; } - (BOOL)containsObjectIdenticalTo: (id)object { - return [mapTable containsValueIdenticalTo: object]; + return [_mapTable containsValueIdenticalTo: object]; } - (OFArray*)allKeys { OFArray *ret; id *keys; size_t count; - count = [mapTable count]; + count = [_mapTable count]; keys = [self allocMemoryWithSize: sizeof(*keys) count: count]; @try { void *pool = objc_autoreleasePoolPush(); @@ -346,11 +353,11 @@ OFMapTableEnumerator *enumerator; id key; size_t i; i = 0; - enumerator = [mapTable keyEnumerator]; + enumerator = [_mapTable keyEnumerator]; while ((key = [enumerator nextValue]) != nil) { assert(i < count); keys[i++] = key; } @@ -370,11 +377,11 @@ { OFArray *ret; id *objects; size_t count; - count = [mapTable count]; + count = [_mapTable count]; objects = [self allocMemoryWithSize: sizeof(*objects) count: count]; @try { void *pool = objc_autoreleasePoolPush(); @@ -381,11 +388,11 @@ OFMapTableEnumerator *enumerator; id object; size_t i; i = 0; - enumerator = [mapTable valueEnumerator]; + enumerator = [_mapTable valueEnumerator]; while ((object = [enumerator nextValue]) != nil) { assert(i < count); objects[i++] = object; } @@ -402,36 +409,36 @@ } - (OFEnumerator*)keyEnumerator { return [[[OFMapTableEnumeratorWrapper alloc] - initWithEnumerator: [mapTable keyEnumerator] + initWithEnumerator: [_mapTable keyEnumerator] object: self] autorelease]; } - (OFEnumerator*)objectEnumerator { return [[[OFMapTableEnumeratorWrapper alloc] - initWithEnumerator: [mapTable valueEnumerator] + initWithEnumerator: [_mapTable valueEnumerator] object: self] autorelease]; } - (int)countByEnumeratingWithState: (of_fast_enumeration_state_t*)state objects: (id*)objects - count: (int)count_ + count: (int)count { - return [mapTable countByEnumeratingWithState: state - objects: objects - count: count_]; + return [_mapTable countByEnumeratingWithState: state + objects: objects + count: count]; } #ifdef OF_HAVE_BLOCKS - (void)enumerateKeysAndObjectsUsingBlock: (of_dictionary_enumeration_block_t)block { @try { - [mapTable enumerateKeysAndValuesUsingBlock: + [_mapTable enumerateKeysAndValuesUsingBlock: ^ (void *key, void *value, BOOL *stop) { block(key, value, stop); }]; } @catch (OFEnumerationMutationException *e) { @throw [OFEnumerationMutationException @@ -439,17 +446,10 @@ object: self]; } } #endif -- (void)dealloc -{ - [mapTable dealloc]; - - [super dealloc]; -} - - (uint32_t)hash { - return [mapTable hash]; + return [_mapTable hash]; } @end Index: src/OFFile.h ================================================================== --- src/OFFile.h +++ src/OFFile.h @@ -39,13 +39,13 @@ /*! * @brief A class which provides functions to read, write and manipulate files. */ @interface OFFile: OFSeekableStream { - int fd; - BOOL closable; - BOOL atEndOfStream; + int _fd; + BOOL _closable; + BOOL _atEndOfStream; } /*! * @brief Creates a new OFFile with the specified path and mode. * @@ -72,15 +72,15 @@ mode: (OFString*)mode; /*! * @brief Creates a new OFFile with the specified file descriptor. * - * @param fileDescriptor A file descriptor, returned from for example open(). - * It is not closed when the OFFile object is deallocated! + * @param fd A file descriptor, returned from for example open(). + * It is not closed when the OFFile object is deallocated! * @return A new autoreleased OFFile */ -+ (instancetype)fileWithFileDescriptor: (int)fileDescriptor; ++ (instancetype)fileWithFileDescriptor: (int)fd; /*! * @brief Returns the path fo the current working directory. * * @return The path of the current working directory @@ -262,14 +262,14 @@ mode: (OFString*)mode; /*! * @brief Initializes an already allocated OFFile. * - * @param fileDescriptor A file descriptor, returned from for example open(). - * It is not closed when the OFFile object is deallocated! + * @param fd A file descriptor, returned from for example open(). + * It is not closed when the OFFile object is deallocated! */ -- initWithFileDescriptor: (int)fileDescriptor; +- initWithFileDescriptor: (int)fd; @end #ifdef __cplusplus extern "C" { #endif Index: src/OFFile.m ================================================================== --- src/OFFile.m +++ src/OFFile.m @@ -549,12 +549,12 @@ #if !defined(_WIN32) && !defined(_PSP) if (!override) { struct stat s; - if (fstat(sourceFile->fd, &s) == 0) - fchmod(destinationFile->fd, s.st_mode); + if (fstat(sourceFile->_fd, &s) == 0) + fchmod(destinationFile->_fd, s.st_mode); } #else (void)override; #endif } @finally { @@ -683,104 +683,105 @@ @throw [OFInvalidArgumentException exceptionWithClass: [self class] selector: _cmd]; #ifndef _WIN32 - if ((fd = open([path cStringWithEncoding: + if ((_fd = open([path cStringWithEncoding: OF_STRING_ENCODING_NATIVE], flags, DEFAULT_MODE)) == -1) #else - if ((fd = _wopen([path UTF16String], flags, + if ((_fd = _wopen([path UTF16String], flags, DEFAULT_MODE)) == -1) #endif @throw [OFOpenFileFailedException exceptionWithClass: [self class] path: path mode: mode]; - closable = YES; + _closable = YES; } @catch (id e) { [self release]; @throw e; } return self; } -- initWithFileDescriptor: (int)fileDescriptor +- initWithFileDescriptor: (int)fd { self = [super init]; - fd = fileDescriptor; + _fd = fd; return self; } - (BOOL)lowlevelIsAtEndOfStream { - if (fd == -1) + if (_fd == -1) return YES; - return atEndOfStream; + return _atEndOfStream; } - (size_t)lowlevelReadIntoBuffer: (void*)buffer length: (size_t)length { ssize_t ret; - if (fd == -1 || atEndOfStream || (ret = read(fd, buffer, length)) < 0) + if (_fd == -1 || _atEndOfStream || + (ret = read(_fd, buffer, length)) < 0) @throw [OFReadFailedException exceptionWithClass: [self class] stream: self requestedLength: length]; if (ret == 0) - atEndOfStream = YES; + _atEndOfStream = YES; return ret; } - (void)lowlevelWriteBuffer: (const void*)buffer length: (size_t)length { - if (fd == -1 || atEndOfStream || write(fd, buffer, length) < length) + if (_fd == -1 || _atEndOfStream || write(_fd, buffer, length) < length) @throw [OFWriteFailedException exceptionWithClass: [self class] stream: self requestedLength: length]; } - (void)lowlevelSeekToOffset: (off_t)offset whence: (int)whence { - if (lseek(fd, offset, whence) == -1) + if (lseek(_fd, offset, whence) == -1) @throw [OFSeekFailedException exceptionWithClass: [self class] stream: self offset: offset whence: whence]; } - (int)fileDescriptorForReading { - return fd; + return _fd; } - (int)fileDescriptorForWriting { - return fd; + return _fd; } - (void)close { - if (fd != -1) - close(fd); + if (_fd != -1) + close(_fd); - fd = -1; + _fd = -1; } - (void)dealloc { - if (closable && fd != -1) - close(fd); + if (_closable && _fd != -1) + close(_fd); [super dealloc]; } @end Index: src/OFHTTPClient.h ================================================================== --- src/OFHTTPClient.h +++ src/OFHTTPClient.h @@ -87,12 +87,12 @@ /*! * @brief A class for performing HTTP requests. */ @interface OFHTTPClient: OFObject { - id delegate; - BOOL insecureRedirectsAllowed; + id _delegate; + BOOL _insecureRedirectsAllowed; } #ifdef OF_HAVE_PROPERTIES @property (assign) id delegate; @property BOOL insecureRedirectsAllowed; Index: src/OFHTTPClient.m ================================================================== --- src/OFHTTPClient.m +++ src/OFHTTPClient.m @@ -61,61 +61,61 @@ } } @interface OFHTTPClientReply: OFHTTPRequestReply { - OFTCPSocket *sock; - BOOL chunked, atEndOfStream; - size_t toRead; + OFTCPSocket *_socket; + BOOL _chunked, _atEndOfStream; + size_t _toRead; } -- initWithSocket: (OFTCPSocket*)sock; +- initWithSocket: (OFTCPSocket*)socket; @end @implementation OFHTTPClientReply -- initWithSocket: (OFTCPSocket*)sock_ +- initWithSocket: (OFTCPSocket*)socket { self = [super init]; - sock = [sock_ retain]; + _socket = [socket retain]; return self; } - (void)dealloc { - [sock release]; + [_socket release]; [super dealloc]; } -- (void)setHeaders: (OFDictionary*)headers_ +- (void)setHeaders: (OFDictionary*)headers { - [super setHeaders: headers_]; + [super setHeaders: headers]; - chunked = [[headers_ objectForKey: @"Transfer-Encoding"] + _chunked = [[headers objectForKey: @"Transfer-Encoding"] isEqual: @"chunked"]; } - (size_t)lowlevelReadIntoBuffer: (void*)buffer length: (size_t)length { - if (!chunked) - return [sock readIntoBuffer: buffer - length: length]; - - if (toRead > 0) { - if (length > toRead) - length = toRead; - - length = [sock readIntoBuffer: buffer - length: length]; - - toRead -= length; - - if (toRead == 0) - if ([[sock readLine] length] > 0) + if (!_chunked) + return [_socket readIntoBuffer: buffer + length: length]; + + if (_toRead > 0) { + if (length > _toRead) + length = _toRead; + + length = [_socket readIntoBuffer: buffer + length: length]; + + _toRead -= length; + + if (_toRead == 0) + if ([[_socket readLine] length] > 0) @throw [OFInvalidServerReplyException exceptionWithClass: [self class]]; return length; } else { @@ -122,11 +122,11 @@ void *pool = objc_autoreleasePoolPush(); OFString *line; of_range_t range; @try { - line = [sock readLine]; + line = [_socket readLine]; } @catch (OFInvalidEncodingException *e) { @throw [OFInvalidServerReplyException exceptionWithClass: [self class]]; } @@ -134,20 +134,20 @@ if (range.location != OF_NOT_FOUND) line = [line substringWithRange: of_range(0, range.location)]; @try { - toRead = + _toRead = (size_t)[line hexadecimalValue]; } @catch (OFInvalidFormatException *e) { @throw [OFInvalidServerReplyException exceptionWithClass: [self class]]; } - if (toRead == 0) { - [sock close]; - atEndOfStream = YES; + if (_toRead == 0) { + [_socket close]; + _atEndOfStream = YES; } objc_autoreleasePoolPop(pool); return 0; @@ -154,56 +154,56 @@ } } - (BOOL)lowlevelIsAtEndOfStream { - if (!chunked) - return [sock isAtEndOfStream]; + if (!_chunked) + return [_socket isAtEndOfStream]; - return atEndOfStream; + return _atEndOfStream; } - (int)fileDescriptorForReading { - return [sock fileDescriptorForReading]; + return [_socket fileDescriptorForReading]; } - (size_t)pendingBytes { - return [super pendingBytes] + [sock pendingBytes]; + return [super pendingBytes] + [_socket pendingBytes]; } - (void)close { - [sock close]; + [_socket close]; } @end @implementation OFHTTPClient + (instancetype)client { return [[[self alloc] init] autorelease]; } -- (void)setDelegate: (id )delegate_ +- (void)setDelegate: (id )delegate { - delegate = delegate_; + _delegate = delegate; } - (id )delegate { - return delegate; + return _delegate; } - (void)setInsecureRedirectsAllowed: (BOOL)allowed { - insecureRedirectsAllowed = allowed; + _insecureRedirectsAllowed = allowed; } - (BOOL)insecureRedirectsAllowed { - return insecureRedirectsAllowed; + return _insecureRedirectsAllowed; } - (OFHTTPRequestReply*)performRequest: (OFHTTPRequest*)request { return [self performRequest: request @@ -217,11 +217,11 @@ OFURL *URL = [request URL]; OFString *scheme = [URL scheme]; of_http_request_type_t requestType = [request requestType]; OFDictionary *headers = [request headers]; OFDataArray *POSTData = [request POSTData]; - OFTCPSocket *sock; + OFTCPSocket *socket; OFHTTPClientReply *reply; OFString *line, *path, *version; OFMutableDictionary *serverHeaders; OFEnumerator *keyEnumerator, *objectEnumerator; OFString *key, *object; @@ -232,34 +232,34 @@ @throw [OFUnsupportedProtocolException exceptionWithClass: [self class] URL: URL]; if ([scheme isEqual: @"http"]) - sock = [OFTCPSocket socket]; + socket = [OFTCPSocket socket]; else { if (of_tls_socket_class == Nil) @throw [OFUnsupportedProtocolException exceptionWithClass: [self class] URL: URL]; - sock = [[[of_tls_socket_class alloc] init] autorelease]; + socket = [[[of_tls_socket_class alloc] init] autorelease]; } - if ([delegate respondsToSelector: + if ([_delegate respondsToSelector: @selector(client:didCreateSocket:request:)]) - [delegate client: self - didCreateSocket: sock - request: request]; + [_delegate client: self + didCreateSocket: socket + request: request]; - [sock connectToHost: [URL host] - port: [URL port]]; + [socket connectToHost: [URL host] + port: [URL port]]; /* * Work around a bug with packet splitting in lighttpd when using * HTTPS. */ - [sock setWriteBufferEnabled: YES]; + [socket setWriteBufferEnabled: YES]; if (requestType == OF_HTTP_REQUEST_TYPE_GET) type = "GET"; if (requestType == OF_HTTP_REQUEST_TYPE_HEAD) type = "HEAD"; @@ -268,59 +268,59 @@ if ([(path = [URL path]) length] == 0) path = @"/"; if ([URL query] != nil) - [sock writeFormat: @"%s %@?%@ HTTP/%@\r\n", + [socket writeFormat: @"%s %@?%@ HTTP/%@\r\n", type, path, [URL query], [request protocolVersionString]]; else - [sock writeFormat: @"%s %@ HTTP/%@\r\n", + [socket writeFormat: @"%s %@ HTTP/%@\r\n", type, path, [request protocolVersionString]]; if ([URL port] == 80) - [sock writeFormat: @"Host: %@\r\n", [URL host]]; + [socket writeFormat: @"Host: %@\r\n", [URL host]]; else - [sock writeFormat: @"Host: %@:%d\r\n", [URL host], + [socket writeFormat: @"Host: %@:%d\r\n", [URL host], [URL port]]; - [sock writeString: @"Connection: close\r\n"]; + [socket writeString: @"Connection: close\r\n"]; if ([headers objectForKey: @"User-Agent"] == nil) - [sock writeString: @"User-Agent: Something using ObjFW " - @"\r\n"]; + [socket writeString: @"User-Agent: Something using ObjFW " + @"\r\n"]; keyEnumerator = [headers keyEnumerator]; objectEnumerator = [headers objectEnumerator]; while ((key = [keyEnumerator nextObject]) != nil && (object = [objectEnumerator nextObject]) != nil) - [sock writeFormat: @"%@: %@\r\n", key, object]; + [socket writeFormat: @"%@: %@\r\n", key, object]; if (requestType == OF_HTTP_REQUEST_TYPE_POST) { OFString *contentType = [request MIMEType]; if (contentType == nil) contentType = @"application/x-www-form-urlencoded; " @"charset=UTF-8\r\n"; - [sock writeFormat: @"Content-Type: %@\r\n", contentType]; - [sock writeFormat: @"Content-Length: %d\r\n", + [socket writeFormat: @"Content-Type: %@\r\n", contentType]; + [socket writeFormat: @"Content-Length: %d\r\n", [POSTData count] * [POSTData itemSize]]; } - [sock writeString: @"\r\n"]; + [socket writeString: @"\r\n"]; /* Work around a bug in lighttpd, see above */ - [sock flushWriteBuffer]; - [sock setWriteBufferEnabled: NO]; + [socket flushWriteBuffer]; + [socket setWriteBufferEnabled: NO]; if (requestType == OF_HTTP_REQUEST_TYPE_POST) - [sock writeBuffer: [POSTData items] - length: [POSTData count] * [POSTData itemSize]]; + [socket writeBuffer: [POSTData items] + length: [POSTData count] * [POSTData itemSize]]; @try { - line = [sock readLine]; + line = [socket readLine]; } @catch (OFInvalidEncodingException *e) { @throw [OFInvalidServerReplyException exceptionWithClass: [self class]]; } @@ -342,11 +342,11 @@ OFString *key, *value; const char *lineC, *tmp; char *keyC; @try { - line = [sock readLine]; + line = [socket readLine]; } @catch (OFInvalidEncodingException *e) { @throw [OFInvalidServerReplyException exceptionWithClass: [self class]]; } @@ -386,25 +386,25 @@ value = [OFString stringWithUTF8String: tmp]; if ((redirects > 0 && (status == 301 || status == 302 || status == 303 || status == 307) && - [key isEqual: @"Location"]) && (insecureRedirectsAllowed || + [key isEqual: @"Location"]) && (_insecureRedirectsAllowed || [scheme isEqual: @"http"] || ![value hasPrefix: @"http://"])) { OFURL *newURL; OFHTTPRequest *newRequest; BOOL follow = YES; newURL = [OFURL URLWithString: value relativeToURL: URL]; - if ([delegate respondsToSelector: + if ([_delegate respondsToSelector: @selector(client:shouldFollowRedirect:request:)]) - follow = [delegate client: self - shouldFollowRedirect: newURL - request: request]; + follow = [_delegate client: self + shouldFollowRedirect: newURL + request: request]; if (!follow) { [serverHeaders setObject: value forKey: key]; continue; @@ -435,18 +435,18 @@ forKey: key]; } [serverHeaders makeImmutable]; - if ([delegate respondsToSelector: + if ([_delegate respondsToSelector: @selector(client:didReceiveHeaders:statusCode:request:)]) - [delegate client: self + [_delegate client: self didReceiveHeaders: serverHeaders statusCode: status request: request]; - reply = [[OFHTTPClientReply alloc] initWithSocket: sock]; + reply = [[OFHTTPClientReply alloc] initWithSocket: socket]; [reply setProtocolVersionFromString: version]; [reply setStatusCode: status]; [reply setHeaders: serverHeaders]; objc_autoreleasePoolPop(pool); Index: src/OFHTTPRequest.h ================================================================== --- src/OFHTTPRequest.h +++ src/OFHTTPRequest.h @@ -48,17 +48,17 @@ /*! * @brief A class for storing HTTP requests. */ @interface OFHTTPRequest: OFObject { - OFURL *URL; - of_http_request_type_t requestType; - of_http_request_protocol_version_t protocolVersion; - OFDictionary *headers; - OFDataArray *POSTData; - OFString *MIMEType; - OFString *remoteAddress; + OFURL *_URL; + of_http_request_type_t _requestType; + of_http_request_protocol_version_t _protocolVersion; + OFDictionary *_headers; + OFDataArray *_POSTData; + OFString *_MIMEType; + OFString *_remoteAddress; } #ifdef OF_HAVE_PROPERTIES @property (copy) OFURL *URL; @property of_http_request_type_t requestType; Index: src/OFHTTPRequest.m ================================================================== --- src/OFHTTPRequest.m +++ src/OFHTTPRequest.m @@ -43,23 +43,23 @@ - init { self = [super init]; - requestType = OF_HTTP_REQUEST_TYPE_GET; - protocolVersion.major = 1; - protocolVersion.minor = 1; + _requestType = OF_HTTP_REQUEST_TYPE_GET; + _protocolVersion.major = 1; + _protocolVersion.minor = 1; return self; } -- initWithURL: (OFURL*)URL_ +- initWithURL: (OFURL*)URL { self = [self init]; @try { - [self setURL: URL_]; + [self setURL: URL]; } @catch (id e) { [self release]; @throw e; } @@ -66,62 +66,62 @@ return self; } - (void)dealloc { - [URL release]; - [headers release]; - [POSTData release]; - [MIMEType release]; - [remoteAddress release]; + [_URL release]; + [_headers release]; + [_POSTData release]; + [_MIMEType release]; + [_remoteAddress release]; [super dealloc]; } -- (void)setURL: (OFURL*)URL_ +- (void)setURL: (OFURL*)URL { - OF_SETTER(URL, URL_, YES, 1) + OF_SETTER(_URL, URL, YES, 1) } - (OFURL*)URL { - OF_GETTER(URL, YES) + OF_GETTER(_URL, YES) } -- (void)setRequestType: (of_http_request_type_t)requestType_ +- (void)setRequestType: (of_http_request_type_t)requestType { - requestType = requestType_; + _requestType = requestType; } - (of_http_request_type_t)requestType { - return requestType; + return _requestType; } -- (void)setProtocolVersion: (of_http_request_protocol_version_t)protocolVersion_ +- (void)setProtocolVersion: (of_http_request_protocol_version_t)protocolVersion { - if (protocolVersion_.major != 1 || protocolVersion.minor > 1) + if (protocolVersion.major != 1 || protocolVersion.minor > 1) @throw [OFUnsupportedVersionException exceptionWithClass: [self class] version: [OFString stringWithFormat: @"%u.%u", - protocolVersion_.major, - protocolVersion_.minor]]; + protocolVersion.major, + protocolVersion.minor]]; - protocolVersion = protocolVersion_; + _protocolVersion = protocolVersion; } - (of_http_request_protocol_version_t)protocolVersion { - return protocolVersion; + return _protocolVersion; } - (void)setProtocolVersionFromString: (OFString*)string { void *pool = objc_autoreleasePoolPush(); OFArray *components = [string componentsSeparatedByString: @"."]; intmax_t major, minor; - of_http_request_protocol_version_t protocolVersion_; + of_http_request_protocol_version_t protocolVersion; if ([components count] != 2) @throw [OFInvalidFormatException exceptionWithClass: [self class]]; @@ -129,71 +129,71 @@ minor = [[components lastObject] decimalValue]; if (major < 0 || major > UINT8_MAX || minor < 0 || minor > UINT8_MAX) @throw [OFOutOfRangeException exceptionWithClass: [self class]]; - protocolVersion_.major = (uint8_t)major; - protocolVersion_.minor = (uint8_t)minor; + protocolVersion.major = (uint8_t)major; + protocolVersion.minor = (uint8_t)minor; - [self setProtocolVersion: protocolVersion_]; + [self setProtocolVersion: protocolVersion]; objc_autoreleasePoolPop(pool); } - (OFString*)protocolVersionString { - return [OFString stringWithFormat: @"%u.%u", protocolVersion.major, - protocolVersion.minor]; + return [OFString stringWithFormat: @"%u.%u", _protocolVersion.major, + _protocolVersion.minor]; } -- (void)setHeaders: (OFDictionary*)headers_ +- (void)setHeaders: (OFDictionary*)headers { - OF_SETTER(headers, headers_, YES, 1) + OF_SETTER(_headers, headers, YES, 1) } - (OFDictionary*)headers { - OF_GETTER(headers, YES) + OF_GETTER(_headers, YES) } -- (void)setPOSTData: (OFDataArray*)POSTData_ +- (void)setPOSTData: (OFDataArray*)POSTData { - OF_SETTER(POSTData, POSTData_, YES, 0) + OF_SETTER(_POSTData, POSTData, YES, 0) } - (OFDataArray*)POSTData { - OF_GETTER(POSTData, YES) + OF_GETTER(_POSTData, YES) } -- (void)setMIMEType: (OFString*)MIMEType_ +- (void)setMIMEType: (OFString*)MIMEType { - OF_SETTER(MIMEType, MIMEType_, YES, 1) + OF_SETTER(_MIMEType, MIMEType, YES, 1) } - (OFString*)MIMEType { - OF_GETTER(MIMEType, YES) + OF_GETTER(_MIMEType, YES) } -- (void)setRemoteAddress: (OFString*)remoteAddress_ +- (void)setRemoteAddress: (OFString*)remoteAddress { - OF_SETTER(remoteAddress, remoteAddress_, YES, 1) + OF_SETTER(_remoteAddress, remoteAddress, YES, 1) } - (OFString*)remoteAddress { - OF_GETTER(remoteAddress, YES) + OF_GETTER(_remoteAddress, YES) } - (OFString*)description { void *pool = objc_autoreleasePoolPush(); const char *requestTypeStr = NULL; OFString *indentedHeaders, *indentedPOSTData, *ret; - switch (requestType) { + switch (_requestType) { case OF_HTTP_REQUEST_TYPE_GET: requestTypeStr = "GET"; break; case OF_HTTP_REQUEST_TYPE_POST: requestTypeStr = "POST"; @@ -201,14 +201,14 @@ case OF_HTTP_REQUEST_TYPE_HEAD: requestTypeStr = "HEAD"; break; } - indentedHeaders = [[headers description] + indentedHeaders = [[_headers description] stringByReplacingOccurrencesOfString: @"\n" withString: @"\n\t"]; - indentedPOSTData = [[POSTData description] + indentedPOSTData = [[_POSTData description] stringByReplacingOccurrencesOfString: @"\n" withString: @"\n\t"]; ret = [[OFString alloc] initWithFormat: @"<%@:\n\tURL = %@\n" @@ -216,13 +216,13 @@ @"\tHeaders = %@\n" @"\tPOST data = %@\n" @"\tPOST data MIME type = %@\n" @"\tRemote address = %@\n" @">", - [self class], URL, requestTypeStr, indentedHeaders, - indentedPOSTData, MIMEType, remoteAddress]; + [self class], _URL, requestTypeStr, indentedHeaders, + indentedPOSTData, _MIMEType, _remoteAddress]; objc_autoreleasePoolPop(pool); return [ret autorelease]; } @end Index: src/OFHTTPRequestReply.h ================================================================== --- src/OFHTTPRequestReply.h +++ src/OFHTTPRequestReply.h @@ -22,13 +22,13 @@ /*! * @brief A class for representing an HTTP request reply as a stream. */ @interface OFHTTPRequestReply: OFStream { - of_http_request_protocol_version_t protocolVersion; - short statusCode; - OFDictionary *headers; + of_http_request_protocol_version_t _protocolVersion; + short _statusCode; + OFDictionary *_headers; } #ifdef OF_HAVE_PROPERTIES @property of_http_request_protocol_version_t protocolVersion; @property short statusCode; Index: src/OFHTTPRequestReply.m ================================================================== --- src/OFHTTPRequestReply.m +++ src/OFHTTPRequestReply.m @@ -31,46 +31,46 @@ @implementation OFHTTPRequestReply - init { self = [super init]; - protocolVersion.major = 1; - protocolVersion.minor = 1; + _protocolVersion.major = 1; + _protocolVersion.minor = 1; return self; } - (void)dealloc { - [headers release]; + [_headers release]; [super dealloc]; } -- (void)setProtocolVersion: (of_http_request_protocol_version_t)protocolVersion_ +- (void)setProtocolVersion: (of_http_request_protocol_version_t)protocolVersion { - if (protocolVersion_.major != 1 || protocolVersion.minor > 1) + if (protocolVersion.major != 1 || protocolVersion.minor > 1) @throw [OFUnsupportedVersionException exceptionWithClass: [self class] version: [OFString stringWithFormat: @"%u.%u", - protocolVersion_.major, - protocolVersion_.minor]]; + protocolVersion.major, + protocolVersion.minor]]; - protocolVersion = protocolVersion_; + _protocolVersion = protocolVersion; } - (of_http_request_protocol_version_t)protocolVersion { - return protocolVersion; + return _protocolVersion; } - (void)setProtocolVersionFromString: (OFString*)string { void *pool = objc_autoreleasePoolPush(); OFArray *components = [string componentsSeparatedByString: @"."]; intmax_t major, minor; - of_http_request_protocol_version_t protocolVersion_; + of_http_request_protocol_version_t protocolVersion; if ([components count] != 2) @throw [OFInvalidFormatException exceptionWithClass: [self class]]; @@ -78,60 +78,60 @@ minor = [[components lastObject] decimalValue]; if (major < 0 || major > UINT8_MAX || minor < 0 || minor > UINT8_MAX) @throw [OFOutOfRangeException exceptionWithClass: [self class]]; - protocolVersion_.major = (uint8_t)major; - protocolVersion_.minor = (uint8_t)minor; + protocolVersion.major = (uint8_t)major; + protocolVersion.minor = (uint8_t)minor; - [self setProtocolVersion: protocolVersion_]; + [self setProtocolVersion: protocolVersion]; objc_autoreleasePoolPop(pool); } - (OFString*)protocolVersionString { - return [OFString stringWithFormat: @"%u.%u", protocolVersion.major, - protocolVersion.minor]; + return [OFString stringWithFormat: @"%u.%u", _protocolVersion.major, + _protocolVersion.minor]; } - (short)statusCode { - return statusCode; + return _statusCode; } -- (void)setStatusCode: (short)statusCode_ +- (void)setStatusCode: (short)statusCode { - statusCode = statusCode_; + _statusCode = statusCode; } - (OFDictionary*)headers { - OF_GETTER(headers, YES) + OF_GETTER(_headers, YES) } -- (void)setHeaders: (OFDictionary*)headers_ +- (void)setHeaders: (OFDictionary*)headers { - OF_SETTER(headers, headers_, YES, YES) + OF_SETTER(_headers, headers, YES, YES) } - (OFString*)description { void *pool = objc_autoreleasePoolPush(); OFString *indentedHeaders, *ret; - indentedHeaders = [[headers description] + indentedHeaders = [[_headers description] stringByReplacingOccurrencesOfString: @"\n" withString: @"\n\t"]; ret = [[OFString alloc] initWithFormat: @"<%@:\n" @"\tStatus code = %d\n" @"\tHeaders = %@\n" @">", - [self class], statusCode, indentedHeaders]; + [self class], _statusCode, indentedHeaders]; objc_autoreleasePoolPop(pool); return [ret autorelease]; } @end Index: src/OFHTTPServer.h ================================================================== --- src/OFHTTPServer.h +++ src/OFHTTPServer.h @@ -59,15 +59,15 @@ /*! * @brief A class for creating a simple HTTP server inside of applications. */ @interface OFHTTPServer: OFObject { - OFString *host; - uint16_t port; - id delegate; - OFString *name; - OFTCPSocket *listeningSocket; + OFString *_host; + uint16_t _port; + id _delegate; + OFString *_name; + OFTCPSocket *_listeningSocket; } #ifdef OF_HAVE_PROPERTIES @property (copy) OFString *host; @property uint16_t port; Index: src/OFHTTPServer.m ================================================================== --- src/OFHTTPServer.m +++ src/OFHTTPServer.m @@ -165,39 +165,39 @@ freeWhenDone: YES]; } @interface OFHTTPServerReply: OFHTTPRequestReply { - OFTCPSocket *sock; - OFHTTPServer *server; - BOOL chunked, headersSent, closed; + OFTCPSocket *_socket; + OFHTTPServer *_server; + BOOL _chunked, _headersSent, _closed; } -- initWithSocket: (OFTCPSocket*)sock +- initWithSocket: (OFTCPSocket*)socket server: (OFHTTPServer*)server; @end @implementation OFHTTPServerReply -- initWithSocket: (OFTCPSocket*)sock_ - server: (OFHTTPServer*)server_ +- initWithSocket: (OFTCPSocket*)socket + server: (OFHTTPServer*)server { self = [super init]; - statusCode = 500; - sock = [sock_ retain]; - server = [server_ retain]; + _statusCode = 500; + _socket = [socket retain]; + _server = [server retain]; return self; } - (void)dealloc { - if (!closed) + if (!_closed) [self close]; - [sock release]; - [server release]; + [_socket release]; + [_server release]; [super dealloc]; } - (void)sendHeaders @@ -206,28 +206,28 @@ OFString *date = [[OFDate date] dateStringWithFormat: @"%a, %d %b %Y %H:%M:%S GMT"]; OFEnumerator *keyEnumerator, *valueEnumerator; OFString *key, *value; - [sock writeFormat: @"HTTP/%@ %d %s\r\n" - @"Server: %@\r\n" - @"Date: %@\r\n", - [self protocolVersionString], statusCode, - status_code_to_string(statusCode), - [server name], date]; - - keyEnumerator = [headers keyEnumerator]; - valueEnumerator = [headers objectEnumerator]; + [_socket writeFormat: @"HTTP/%@ %d %s\r\n" + @"Server: %@\r\n" + @"Date: %@\r\n", + [self protocolVersionString], _statusCode, + status_code_to_string(_statusCode), + [_server name], date]; + + keyEnumerator = [_headers keyEnumerator]; + valueEnumerator = [_headers objectEnumerator]; while ((key = [keyEnumerator nextObject]) != nil && (value = [valueEnumerator nextObject]) != nil) if (![key isEqual: @"Server"] && ![key isEqual: @"Date"]) - [sock writeFormat: @"%@: %@\r\n", key, value]; + [_socket writeFormat: @"%@: %@\r\n", key, value]; - [sock writeString: @"\r\n"]; + [_socket writeString: @"\r\n"]; - headersSent = YES; - chunked = [[headers objectForKey: @"Transfer-Encoding"] + _headersSent = YES; + _chunked = [[_headers objectForKey: @"Transfer-Encoding"] isEqual: @"chunked"]; objc_autoreleasePoolPop(pool); } @@ -234,99 +234,99 @@ - (void)lowlevelWriteBuffer: (const void*)buffer length: (size_t)length { void *pool; - if (!headersSent) + if (!_headersSent) [self sendHeaders]; - if (!chunked) { - [sock writeBuffer: buffer - length: length]; + if (!_chunked) { + [_socket writeBuffer: buffer + length: length]; return; } pool = objc_autoreleasePoolPush(); - [sock writeString: [OFString stringWithFormat: @"%zx\r\n", length]]; + [_socket writeString: [OFString stringWithFormat: @"%zx\r\n", length]]; objc_autoreleasePoolPop(pool); - [sock writeBuffer: buffer - length: length]; - [sock writeBuffer: "\r\n" - length: 2]; + [_socket writeBuffer: buffer + length: length]; + [_socket writeBuffer: "\r\n" + length: 2]; } - (void)close { - if (!headersSent) + if (!_headersSent) [self sendHeaders]; - if (chunked) - [sock writeBuffer: "0\r\n\r\n" - length: 5]; + if (_chunked) + [_socket writeBuffer: "0\r\n\r\n" + length: 5]; - [sock close]; + [_socket close]; - closed = YES; + _closed = YES; } - (int)fileDescriptorForWriting { - return [sock fileDescriptorForWriting]; + return [_socket fileDescriptorForWriting]; } @end @interface OFHTTPServer_Connection: OFObject { - OFTCPSocket *sock; - OFHTTPServer *server; - OFTimer *timer; + OFTCPSocket *_socket; + OFHTTPServer *_server; + OFTimer *_timer; enum { AWAITING_PROLOG, PARSING_HEADERS, SEND_REPLY - } state; - uint8_t HTTPMinorVersion; - of_http_request_type_t requestType; - OFString *host, *path; - uint16_t port; - OFMutableDictionary *headers; - size_t contentLength; - OFDataArray *POSTData; + } _state; + uint8_t _HTTPMinorVersion; + of_http_request_type_t _requestType; + OFString *_host, *_path; + uint16_t _port; + OFMutableDictionary *_headers; + size_t _contentLength; + OFDataArray *_POSTData; } - initWithSocket: (OFTCPSocket*)socket server: (OFHTTPServer*)server; -- (BOOL)socket: (OFTCPSocket*)sock +- (BOOL)socket: (OFTCPSocket*)socket didReadLine: (OFString*)line exception: (OFException*)exception; - (BOOL)parseProlog: (OFString*)line; - (BOOL)parseHeaders: (OFString*)line; -- (BOOL)socket: (OFTCPSocket*)sock +- (BOOL)socket: (OFTCPSocket*)socket didReadIntoBuffer: (const char*)buffer length: (size_t)length exception: (OFException*)exception; - (BOOL)sendErrorAndClose: (short)statusCode; - (void)createReply; @end @implementation OFHTTPServer_Connection -- initWithSocket: (OFTCPSocket*)sock_ - server: (OFHTTPServer*)server_ +- initWithSocket: (OFTCPSocket*)socket + server: (OFHTTPServer*)server { self = [super init]; @try { - sock = [sock_ retain]; - server = [server_ retain]; - timer = [[OFTimer + _socket = [socket retain]; + _server = [server retain]; + _timer = [[OFTimer scheduledTimerWithTimeInterval: 10 - target: sock + target: socket selector: @selector( cancelAsyncRequests) repeats: NO] retain]; - state = AWAITING_PROLOG; + _state = AWAITING_PROLOG; } @catch (id e) { [self release]; @throw e; } @@ -333,40 +333,40 @@ return self; } - (void)dealloc { - [sock release]; - [server release]; - - [timer invalidate]; - [timer release]; - - [host release]; - [path release]; - [headers release]; - [POSTData release]; + [_socket release]; + [_server release]; + + [_timer invalidate]; + [_timer release]; + + [_host release]; + [_path release]; + [_headers release]; + [_POSTData release]; [super dealloc]; } -- (BOOL)socket: (OFTCPSocket*)sock_ +- (BOOL)socket: (OFTCPSocket*)socket didReadLine: (OFString*)line exception: (OFException*)exception { if (line == nil || exception != nil) return NO; @try { - switch (state) { + switch (_state) { case AWAITING_PROLOG: return [self parseProlog: line]; case PARSING_HEADERS: if (![self parseHeaders: line]) return NO; - if (state == SEND_REPLY) { + if (_state == SEND_REPLY) { [self createReply]; return NO; } return YES; @@ -395,11 +395,11 @@ tmp = [version characterAtIndex: 8]; if (tmp < '0' || tmp > '9') return [self sendErrorAndClose: 400]; - HTTPMinorVersion = (uint8_t)(tmp - '0'); + _HTTPMinorVersion = (uint8_t)(tmp - '0'); } @catch (OFOutOfRangeException *e) { return [self sendErrorAndClose: 400]; } pos = [line rangeOfString: @" "].location; @@ -406,31 +406,31 @@ if (pos == OF_NOT_FOUND) return [self sendErrorAndClose: 400]; type = [line substringWithRange: of_range(0, pos)]; if ([type isEqual: @"GET"]) - requestType = OF_HTTP_REQUEST_TYPE_GET; + _requestType = OF_HTTP_REQUEST_TYPE_GET; else if ([type isEqual: @"POST"]) - requestType = OF_HTTP_REQUEST_TYPE_POST; + _requestType = OF_HTTP_REQUEST_TYPE_POST; else if ([type isEqual: @"HEAD"]) - requestType = OF_HTTP_REQUEST_TYPE_HEAD; + _requestType = OF_HTTP_REQUEST_TYPE_HEAD; else return [self sendErrorAndClose: 501]; @try { - path = [line substringWithRange: + _path = [line substringWithRange: of_range(pos + 1, [line length] - pos - 10)]; } @catch (OFOutOfRangeException *e) { return [self sendErrorAndClose: 400]; } - path = [[path stringByDeletingEnclosingWhitespaces] retain]; + _path = [[_path stringByDeletingEnclosingWhitespaces] retain]; - if (![path hasPrefix: @"/"]) + if (![_path hasPrefix: @"/"]) return [self sendErrorAndClose: 400]; - headers = [[OFMutableDictionary alloc] init]; - state = PARSING_HEADERS; + _headers = [[OFMutableDictionary alloc] init]; + _state = PARSING_HEADERS; return YES; } - (BOOL)parseHeaders: (OFString*)line @@ -437,39 +437,39 @@ { OFString *key, *value; size_t pos; if ([line length] == 0) { - switch (requestType) { + switch (_requestType) { case OF_HTTP_REQUEST_TYPE_GET: case OF_HTTP_REQUEST_TYPE_HEAD: - state = SEND_REPLY; + _state = SEND_REPLY; break; case OF_HTTP_REQUEST_TYPE_POST:; OFString *tmp; char *buffer; - tmp = [headers objectForKey: @"Content-Length"]; + tmp = [_headers objectForKey: @"Content-Length"]; if (tmp == nil) return [self sendErrorAndClose: 411]; @try { - contentLength = (size_t)[tmp decimalValue]; + _contentLength = (size_t)[tmp decimalValue]; } @catch (OFInvalidFormatException *e) { return [self sendErrorAndClose: 400]; } buffer = [self allocMemoryWithSize: BUFFER_SIZE]; - POSTData = [[OFDataArray alloc] init]; - - [sock asyncReadIntoBuffer: buffer - length: BUFFER_SIZE - target: self - selector: @selector(socket: - didReadIntoBuffer: - length:exception:)]; - [timer setFireDate: + _POSTData = [[OFDataArray alloc] init]; + + [_socket asyncReadIntoBuffer: buffer + length: BUFFER_SIZE + target: self + selector: @selector(socket: + didReadIntoBuffer: + length:exception:)]; + [_timer setFireDate: [OFDate dateWithTimeIntervalSinceNow: 5]]; return NO; } @@ -485,21 +485,21 @@ of_range(pos + 1, [line length] - pos - 1)]; key = normalized_key([key stringByDeletingTrailingWhitespaces]); value = [value stringByDeletingLeadingWhitespaces]; - [headers setObject: value - forKey: key]; + [_headers setObject: value + forKey: key]; if ([key isEqual: @"Host"]) { pos = [value rangeOfString: @":" options: OF_STRING_SEARCH_BACKWARDS].location; if (pos != OF_NOT_FOUND) { - [host release]; - host = [[value substringWithRange: + [_host release]; + _host = [[value substringWithRange: of_range(0, pos)] retain]; @try { of_range_t range = of_range(pos + 1, [value length] - pos - 1); @@ -507,62 +507,62 @@ substringWithRange: range] decimalValue]; if (portTmp < 1 || portTmp > UINT16_MAX) return [self sendErrorAndClose: 400]; - port = (uint16_t)portTmp; + _port = (uint16_t)portTmp; } @catch (OFInvalidFormatException *e) { return [self sendErrorAndClose: 400]; } } else { - [host release]; - host = [value retain]; - port = 80; + [_host release]; + _host = [value retain]; + _port = 80; } } return YES; } -- (BOOL)socket: (OFTCPSocket*)sock_ +- (BOOL)socket: (OFTCPSocket*)socket didReadIntoBuffer: (const char*)buffer length: (size_t)length exception: (OFException*)exception { - if ([sock_ isAtEndOfStream] || exception != nil) + if ([socket isAtEndOfStream] || exception != nil) return NO; - [POSTData addItems: buffer - count: length]; + [_POSTData addItems: buffer + count: length]; - if ([POSTData count] >= contentLength) { + if ([_POSTData count] >= _contentLength) { @try { [self createReply]; } @catch (OFWriteFailedException *e) { return NO; } return NO; } - [timer setFireDate: [OFDate dateWithTimeIntervalSinceNow: 5]]; + [_timer setFireDate: [OFDate dateWithTimeIntervalSinceNow: 5]]; return YES; } - (BOOL)sendErrorAndClose: (short)statusCode { OFString *date = [[OFDate date] dateStringWithFormat: @"%a, %d %b %Y %H:%M:%S GMT"]; - [sock writeFormat: @"HTTP/1.1 %d %s\r\n" - @"Date: %@\r\n" - @"Server: %@\r\n" - @"\r\n", - statusCode, status_code_to_string(statusCode), date, - [server name]]; - [sock close]; + [_socket writeFormat: @"HTTP/1.1 %d %s\r\n" + @"Date: %@\r\n" + @"Server: %@\r\n" + @"\r\n", + statusCode, status_code_to_string(statusCode), + date, [_server name]]; + [_socket close]; return NO; } - (void)createReply @@ -570,56 +570,57 @@ OFURL *URL; OFHTTPRequest *request; OFHTTPServerReply *reply; size_t pos; - [timer invalidate]; - [timer release]; - timer = nil; + [_timer invalidate]; + [_timer release]; + _timer = nil; - if (host == nil || port == 0) { - if (HTTPMinorVersion > 0) { + if (_host == nil || _port == 0) { + if (_HTTPMinorVersion > 0) { [self sendErrorAndClose: 400]; return; } - host = [[server host] retain]; - port = [server port]; + [_host release]; + _host = [[_server host] retain]; + _port = [_server port]; } URL = [OFURL URL]; [URL setScheme: @"http"]; - [URL setHost: host]; - [URL setPort: port]; - - if ((pos = [path rangeOfString: @"?"].location) != OF_NOT_FOUND) { - OFString *path_, *query; - - path_ = [path substringWithRange: of_range(0, pos)]; - query = [path substringWithRange: + [URL setHost: _host]; + [URL setPort: _port]; + + if ((pos = [_path rangeOfString: @"?"].location) != OF_NOT_FOUND) { + OFString *path, *query; + + path = [_path substringWithRange: of_range(0, pos)]; + query = [_path substringWithRange: of_range(pos + 1, [path length] - pos - 1)]; - [URL setPath: path_]; + [URL setPath: path]; [URL setQuery: query]; } else - [URL setPath: path]; + [URL setPath: _path]; request = [OFHTTPRequest requestWithURL: URL]; - [request setRequestType: requestType]; + [request setRequestType: _requestType]; [request setProtocolVersion: - (of_http_request_protocol_version_t){ 1, HTTPMinorVersion }]; - [request setHeaders: headers]; - [request setPOSTData: POSTData]; - [request setRemoteAddress: [sock remoteAddress]]; + (of_http_request_protocol_version_t){ 1, _HTTPMinorVersion }]; + [request setHeaders: _headers]; + [request setPOSTData: _POSTData]; + [request setRemoteAddress: [_socket remoteAddress]]; reply = [[[OFHTTPServerReply alloc] - initWithSocket: sock - server: server] autorelease]; + initWithSocket: _socket + server: _server] autorelease]; - [[server delegate] server: server - didReceiveRequest: request - reply: reply]; + [[_server delegate] server: _server + didReceiveRequest: request + reply: reply]; } @end @implementation OFHTTPServer + (instancetype)server @@ -629,105 +630,105 @@ - init { self = [super init]; - name = @"OFHTTPServer (ObjFW's HTTP server class " + _name = @"OFHTTPServer (ObjFW's HTTP server class " @")"; return self; } - (void)dealloc { - [host release]; - [listeningSocket release]; - [name release]; + [_host release]; + [_listeningSocket release]; + [_name release]; [super dealloc]; } -- (void)setHost: (OFString*)host_ +- (void)setHost: (OFString*)host { - OF_SETTER(host, host_, YES, 1) + OF_SETTER(_host, host, YES, 1) } - (OFString*)host { - OF_GETTER(host, YES) + OF_GETTER(_host, YES) } -- (void)setPort: (uint16_t)port_ +- (void)setPort: (uint16_t)port { - port = port_; + _port = port; } - (uint16_t)port { - return port; + return _port; } -- (void)setDelegate: (id )delegate_ +- (void)setDelegate: (id )delegate { - delegate = delegate_; + _delegate = delegate; } - (id )delegate { - return delegate; + return _delegate; } -- (void)setName: (OFString*)name_ +- (void)setName: (OFString*)name { - OF_SETTER(name, name_, YES, 1) + OF_SETTER(_name, name, YES, 1) } - (OFString*)name { - OF_GETTER(name, YES) + OF_GETTER(_name, YES) } - (void)start { - if (host == nil || port == 0) + if (_host == nil || _port == 0) @throw [OFInvalidArgumentException exceptionWithClass: [self class] selector: _cmd]; - if (listeningSocket != nil) + if (_listeningSocket != nil) @throw [OFAlreadyConnectedException exceptionWithClass: [self class] - socket: listeningSocket]; - - listeningSocket = [[OFTCPSocket alloc] init]; - [listeningSocket bindToHost: host - port: port]; - [listeningSocket listen]; - - [listeningSocket asyncAcceptWithTarget: self - selector: @selector(OF_socket: - didAcceptSocket: - exception:)]; + socket: _listeningSocket]; + + _listeningSocket = [[OFTCPSocket alloc] init]; + [_listeningSocket bindToHost: _host + port: _port]; + [_listeningSocket listen]; + + [_listeningSocket asyncAcceptWithTarget: self + selector: @selector(OF_socket: + didAcceptSocket: + exception:)]; } - (void)stop { - [listeningSocket cancelAsyncRequests]; - [listeningSocket release]; - listeningSocket = nil; + [_listeningSocket cancelAsyncRequests]; + [_listeningSocket release]; + _listeningSocket = nil; } - (BOOL)OF_socket: (OFTCPSocket*)socket didAcceptSocket: (OFTCPSocket*)clientSocket exception: (OFException*)exception { OFHTTPServer_Connection *connection; if (exception != nil) { - if ([delegate respondsToSelector: + if ([_delegate respondsToSelector: @selector(server:didReceiveExceptionOnListeningSocket:)]) - return [delegate server: self + return [_delegate server: self didReceiveExceptionOnListeningSocket: exception]; return NO; } Index: src/OFHash.h ================================================================== --- src/OFHash.h +++ src/OFHash.h @@ -19,11 +19,11 @@ /*! * @brief A base class for classes providing hash functions. */ @interface OFHash: OFObject { - BOOL calculated; + BOOL _calculated; } #ifdef OF_HAVE_PROPERTIES @property (readonly, getter=isCalculated) BOOL calculated; #endif Index: src/OFHash.m ================================================================== --- src/OFHash.m +++ src/OFHash.m @@ -51,8 +51,8 @@ abort(); } - (BOOL)isCalculated { - return calculated; + return _calculated; } @end Index: src/OFIntrospection.h ================================================================== --- src/OFIntrospection.h +++ src/OFIntrospection.h @@ -23,13 +23,13 @@ /*! * @brief A class for describing a method. */ @interface OFMethod: OFObject { - SEL selector; - OFString *name; - const char *typeEncoding; + SEL _selector; + OFString *_name; + const char *_typeEncoding; } #ifdef OF_HAVE_PROPERTIES @property (readonly) SEL selector; @property (readonly, copy) OFString *name; @@ -61,13 +61,13 @@ /*! * @brief A class for describing an instance variable. */ @interface OFInstanceVariable: OFObject { - OFString *name; - const char *typeEncoding; - ptrdiff_t offset; + OFString *_name; + const char *_typeEncoding; + ptrdiff_t _offset; } #ifdef OF_HAVE_PROPERTIES @property (readonly, copy) OFString *name; @property (readonly) ptrdiff_t offset; @@ -99,15 +99,15 @@ /*! * @brief A class for introspecting classes. */ @interface OFIntrospection: OFObject { - OFMutableArray *classMethods; - OFMutableArray *instanceMethods; - OFMutableArray *instanceVariables; + OFMutableArray *_classMethods; + OFMutableArray *_instanceMethods; + OFMutableArray *_instanceVariables; #ifdef OF_HAVE_PROPERTIES - OFMutableArray *properties; + OFMutableArray *_properties; #endif } #ifdef OF_HAVE_PROPERTIES @property (readonly, copy) OFArray *classMethods; Index: src/OFIntrospection.m ================================================================== --- src/OFIntrospection.m +++ src/OFIntrospection.m @@ -35,14 +35,14 @@ - OF_initWithMethod: (struct objc_method*)method { self = [super init]; @try { - selector = (SEL)&method->sel; - name = [[OFString alloc] - initWithUTF8String: sel_getName(selector)]; - typeEncoding = method->sel.types; + _selector = (SEL)&method->sel; + _name = [[OFString alloc] + initWithUTF8String: sel_getName(_selector)]; + _typeEncoding = method->sel.types; } @catch (id e) { [self release]; @throw e; } @@ -52,14 +52,14 @@ - OF_initWithMethod: (Method)method { self = [super init]; @try { - selector = method_getName(method); - name = [[OFString alloc] - initWithUTF8String: sel_getName(selector)]; - typeEncoding = method_getTypeEncoding(method); + _selector = method_getName(method); + _name = [[OFString alloc] + initWithUTF8String: sel_getName(_selector)]; + _typeEncoding = method_getTypeEncoding(method); } @catch (id e) { [self release]; @throw e; } @@ -67,57 +67,57 @@ } #endif - (void)dealloc { - [name release]; + [_name release]; [super dealloc]; } - (SEL)selector { - return selector; + return _selector; } - (OFString*)name { - OF_GETTER(name, YES) + OF_GETTER(_name, YES) } - (const char*)typeEncoding { - return typeEncoding; + return _typeEncoding; } - (OFString*)description { return [OFString stringWithFormat: @"", - name, typeEncoding]; + _name, _typeEncoding]; } - (BOOL)isEqual: (id)object { - OFMethod *otherMethod; + OFMethod *method; if (![object isKindOfClass: [OFMethod class]]) return NO; - otherMethod = object; + method = object; + + if (!sel_isEqual(method->_selector, _selector)) + return NO; - if (!sel_isEqual(otherMethod->selector, selector)) + if (![method->_name isEqual: _name]) return NO; - if (![otherMethod->name isEqual: name]) + if ((method->_typeEncoding == NULL && _typeEncoding != NULL) || + (method->_typeEncoding != NULL && _typeEncoding == NULL)) return NO; - if ((otherMethod->typeEncoding == NULL && typeEncoding != NULL) || - (otherMethod->typeEncoding != NULL && typeEncoding == NULL)) - return NO; - - if (otherMethod->typeEncoding != NULL && typeEncoding != NULL && - strcmp(otherMethod->typeEncoding, typeEncoding)) + if (method->_typeEncoding != NULL && _typeEncoding != NULL && + strcmp(method->_typeEncoding, _typeEncoding)) return NO; return YES; } @@ -125,18 +125,18 @@ { uint32_t hash; OF_HASH_INIT(hash); - OF_HASH_ADD_HASH(hash, [name hash]); + OF_HASH_ADD_HASH(hash, [_name hash]); - if (typeEncoding != NULL) { + if (_typeEncoding != NULL) { size_t i, length; - length = strlen(typeEncoding); + length = strlen(_typeEncoding); for (i = 0; i < length; i++) - OF_HASH_ADD(hash, typeEncoding[i]); + OF_HASH_ADD(hash, _typeEncoding[i]); } OF_HASH_FINALIZE(hash); return hash; @@ -148,13 +148,13 @@ - OF_initWithIvar: (struct objc_ivar*)ivar { self = [super init]; @try { - name = [[OFString alloc] initWithUTF8String: ivar->name]; - typeEncoding = ivar->type; - offset = ivar->offset; + _name = [[OFString alloc] initWithUTF8String: ivar->name]; + _typeEncoding = ivar->type; + _offset = ivar->offset; } @catch (id e) { [self release]; @throw e; } @@ -164,14 +164,14 @@ - OF_initWithIvar: (Ivar)ivar { self = [super init]; @try { - name = [[OFString alloc] + _name = [[OFString alloc] initWithUTF8String: ivar_getName(ivar)]; - typeEncoding = ivar_getTypeEncoding(ivar); - offset = ivar_getOffset(ivar); + _typeEncoding = ivar_getTypeEncoding(ivar); + _offset = ivar_getOffset(ivar); } @catch (id e) { [self release]; @throw e; } @@ -179,35 +179,35 @@ } #endif - (void)dealloc { - [name release]; + [_name release]; [super dealloc]; } - (OFString*)name { - OF_GETTER(name, YES); + OF_GETTER(_name, YES); } - (ptrdiff_t)offset { - return offset; + return _offset; } - (const char*)typeEncoding { - return typeEncoding; + return _typeEncoding; } - (OFString*)description { return [OFString stringWithFormat: @"", - name, typeEncoding, offset]; + _name, _typeEncoding, _offset]; } @end @implementation OFIntrospection + (instancetype)introspectionWithClass: (Class)class @@ -226,13 +226,13 @@ Method *methodList; Ivar *ivarList; unsigned i, count; #endif - classMethods = [[OFMutableArray alloc] init]; - instanceMethods = [[OFMutableArray alloc] init]; - instanceVariables = [[OFMutableArray alloc] init]; + _classMethods = [[OFMutableArray alloc] init]; + _instanceMethods = [[OFMutableArray alloc] init]; + _instanceVariables = [[OFMutableArray alloc] init]; #if defined(OF_OBJFW_RUNTIME) for (methodList = object_getClass(class)->methodlist; methodList != NULL; methodList = methodList->next) { int i; @@ -239,11 +239,11 @@ for (i = 0; i < methodList->count; i++) { void *pool = objc_autoreleasePoolPush(); OFMethod *method = [[OFMethod alloc] OF_initWithMethod: &methodList->methods[i]]; - [classMethods addObject: [method autorelease]]; + [_classMethods addObject: [method autorelease]]; objc_autoreleasePoolPop(pool); } } for (methodList = class->methodlist; methodList != NULL; @@ -252,11 +252,11 @@ for (i = 0; i < methodList->count; i++) { void *pool = objc_autoreleasePoolPush(); OFMethod *method = [[OFMethod alloc] OF_initWithMethod: &methodList->methods[i]]; - [instanceMethods addObject: + [_instanceMethods addObject: [method autorelease]]; objc_autoreleasePoolPop(pool); } } @@ -267,11 +267,11 @@ void *pool = objc_autoreleasePoolPush(); OFInstanceVariable *ivar; ivar = [[OFInstanceVariable alloc] OF_initWithIvar: &class->ivars->ivars[i]]; - [instanceVariables addObject: + [_instanceVariables addObject: [ivar autorelease]]; objc_autoreleasePoolPop(pool); } } @@ -279,11 +279,11 @@ methodList = class_copyMethodList(object_getClass(class), &count); @try { for (i = 0; i < count; i++) { void *pool = objc_autoreleasePoolPush(); - [classMethods addObject: [[[OFMethod alloc] + [_classMethods addObject: [[[OFMethod alloc] OF_initWithMethod: methodList[i]] autorelease]]; objc_autoreleasePoolPop(pool); } } @finally { @@ -292,11 +292,11 @@ methodList = class_copyMethodList(class, &count); @try { for (i = 0; i < count; i++) { void *pool = objc_autoreleasePoolPush(); - [instanceMethods addObject: [[[OFMethod alloc] + [_instanceMethods addObject: [[[OFMethod alloc] OF_initWithMethod: methodList[i]] autorelease]]; objc_autoreleasePoolPop(pool); } } @finally { @@ -305,23 +305,23 @@ ivarList = class_copyIvarList(class, &count); @try { for (i = 0; i < count; i++) { void *pool = objc_autoreleasePoolPush(); - [instanceVariables addObject: + [_instanceVariables addObject: [[[OFInstanceVariable alloc] OF_initWithIvar: ivarList[i]] autorelease]]; objc_autoreleasePoolPop(pool); } } @finally { free(ivarList); } #endif - [classMethods makeImmutable]; - [instanceMethods makeImmutable]; - [instanceVariables makeImmutable]; + [_classMethods makeImmutable]; + [_instanceMethods makeImmutable]; + [_instanceVariables makeImmutable]; } @catch (id e) { [self release]; @throw e; } @@ -328,27 +328,27 @@ return self; } - (void)dealloc { - [classMethods release]; - [instanceMethods release]; - [instanceVariables release]; + [_classMethods release]; + [_instanceMethods release]; + [_instanceVariables release]; [super dealloc]; } - (OFArray*)classMethods { - OF_GETTER(classMethods, YES) + OF_GETTER(_classMethods, YES) } - (OFArray*)instanceMethods { - OF_GETTER(instanceMethods, YES) + OF_GETTER(_instanceMethods, YES) } - (OFArray*)instanceVariables { - OF_GETTER(instanceVariables, YES) + OF_GETTER(_instanceVariables, YES) } @end Index: src/OFList.h ================================================================== --- src/OFList.h +++ src/OFList.h @@ -38,14 +38,14 @@ /*! * @brief A class which provides easy to use double-linked lists. */ @interface OFList: OFObject { - of_list_object_t *firstListObject; - of_list_object_t *lastListObject; - size_t count; - unsigned long mutations; + of_list_object_t *_firstListObject; + of_list_object_t *_lastListObject; + size_t _count; + unsigned long _mutations; } #ifdef OF_HAVE_PROPERTIES @property (readonly) of_list_object_t *firstListObject; @property (readonly) of_list_object_t *lastListObject; @@ -160,14 +160,14 @@ - (void)removeAllObjects; @end @interface OFListEnumerator: OFEnumerator { - OFList *list; - of_list_object_t *current; - unsigned long mutations; - unsigned long *mutationsPtr; + OFList *_list; + of_list_object_t *_current; + unsigned long _mutations; + unsigned long *_mutationsPtr; } - initWithList: (OFList*)list mutationsPointer: (unsigned long*)mutationsPtr; @end Index: src/OFList.m ================================================================== --- src/OFList.m +++ src/OFList.m @@ -71,44 +71,44 @@ - (void)dealloc { of_list_object_t *iter; - for (iter = firstListObject; iter != NULL; iter = iter->next) + for (iter = _firstListObject; iter != NULL; iter = iter->next) [iter->object release]; [super dealloc]; } - (of_list_object_t*)firstListObject { - return firstListObject; + return _firstListObject; } - (of_list_object_t*)lastListObject { - return lastListObject; + return _lastListObject; } - (of_list_object_t*)appendObject: (id)object { of_list_object_t *listObject; listObject = [self allocMemoryWithSize: sizeof(of_list_object_t)]; listObject->object = [object retain]; listObject->next = NULL; - listObject->previous = lastListObject; - - if (lastListObject != NULL) - lastListObject->next = listObject; - - lastListObject = listObject; - if (firstListObject == NULL) - firstListObject = listObject; - - count++; - mutations++; + listObject->previous = _lastListObject; + + if (_lastListObject != NULL) + _lastListObject->next = listObject; + + _lastListObject = listObject; + if (_firstListObject == NULL) + _firstListObject = listObject; + + _count++; + _mutations++; return listObject; } - (of_list_object_t*)prependObject: (id)object @@ -115,22 +115,22 @@ { of_list_object_t *listObject; listObject = [self allocMemoryWithSize: sizeof(of_list_object_t)]; listObject->object = [object retain]; - listObject->next = firstListObject; + listObject->next = _firstListObject; listObject->previous = NULL; - if (firstListObject != NULL) - firstListObject->previous = listObject; - - firstListObject = listObject; - if (lastListObject == NULL) - lastListObject = listObject; - - count++; - mutations++; + if (_firstListObject != NULL) + _firstListObject->previous = listObject; + + _firstListObject = listObject; + if (_lastListObject == NULL) + _lastListObject = listObject; + + _count++; + _mutations++; return listObject; } - (of_list_object_t*)insertObject: (id)object @@ -146,15 +146,15 @@ if (listObject->previous != NULL) listObject->previous->next = newListObject; listObject->previous = newListObject; - if (listObject == firstListObject) - firstListObject = newListObject; + if (listObject == _firstListObject) + _firstListObject = newListObject; - count++; - mutations++; + _count++; + _mutations++; return newListObject; } - (of_list_object_t*)insertObject: (id)object @@ -170,15 +170,15 @@ if (listObject->next != NULL) listObject->next->previous = newListObject; listObject->next = newListObject; - if (listObject == lastListObject) - lastListObject = newListObject; + if (listObject == _lastListObject) + _lastListObject = newListObject; - count++; - mutations++; + _count++; + _mutations++; return newListObject; } - (void)removeListObject: (of_list_object_t*)listObject @@ -186,71 +186,71 @@ if (listObject->previous != NULL) listObject->previous->next = listObject->next; if (listObject->next != NULL) listObject->next->previous = listObject->previous; - if (firstListObject == listObject) - firstListObject = listObject->next; - if (lastListObject == listObject) - lastListObject = listObject->previous; + if (_firstListObject == listObject) + _firstListObject = listObject->next; + if (_lastListObject == listObject) + _lastListObject = listObject->previous; - count--; - mutations++; + _count--; + _mutations++; [listObject->object release]; [self freeMemory: listObject]; } - (id)firstObject { - return (firstListObject != NULL ? firstListObject->object : nil); + return (_firstListObject != NULL ? _firstListObject->object : nil); } - (id)lastObject { - return (lastListObject != NULL ? lastListObject->object : nil); + return (_lastListObject != NULL ? _lastListObject->object : nil); } - (size_t)count { - return count; + return _count; } - (BOOL)isEqual: (id)object { - OFList *otherList; + OFList *list; of_list_object_t *iter, *iter2; if (![object isKindOfClass: [OFList class]]) return NO; - otherList = object; + list = object; - if ([otherList count] != count) + if ([list count] != _count) return NO; - for (iter = firstListObject, iter2 = [otherList firstListObject]; + for (iter = _firstListObject, iter2 = [list firstListObject]; iter != NULL && iter2 != NULL; iter = iter->next, iter2 = iter2->next) if (![iter->object isEqual: iter2->object]) return NO; - /* One is bigger than the other although we checked the count */ + /* One is bigger than the other even though we checked the count */ assert(iter == NULL && iter2 == NULL); return YES; } - (BOOL)containsObject: (id)object { of_list_object_t *iter; - if (count == 0) + if (_count == 0) return NO; - for (iter = firstListObject; iter != NULL; iter = iter->next) + for (iter = _firstListObject; iter != NULL; iter = iter->next) if ([iter->object isEqual: object]) return YES; return NO; } @@ -257,14 +257,14 @@ - (BOOL)containsObjectIdenticalTo: (id)object { of_list_object_t *iter; - if (count == 0) + if (_count == 0) return NO; - for (iter = firstListObject; iter != NULL; iter = iter->next) + for (iter = _firstListObject; iter != NULL; iter = iter->next) if (iter->object == object) return YES; return NO; } @@ -271,20 +271,20 @@ - (void)removeAllObjects { of_list_object_t *iter, *next; - mutations++; + _mutations++; - for (iter = firstListObject; iter != NULL; iter = next) { + for (iter = _firstListObject; iter != NULL; iter = next) { next = iter->next; [iter->object release]; [self freeMemory: iter]; } - firstListObject = lastListObject = NULL; + _firstListObject = _lastListObject = NULL; } - copy { OFList *copy = [[[self class] alloc] init]; @@ -292,32 +292,32 @@ listObject = NULL; previous = NULL; @try { - for (iter = firstListObject; iter != NULL; iter = iter->next) { + for (iter = _firstListObject; iter != NULL; iter = iter->next) { listObject = [copy allocMemoryWithSize: sizeof(of_list_object_t)]; listObject->object = [iter->object retain]; listObject->next = NULL; listObject->previous = previous; - if (copy->firstListObject == NULL) - copy->firstListObject = listObject; + if (copy->_firstListObject == NULL) + copy->_firstListObject = listObject; if (previous != NULL) previous->next = listObject; - copy->count++; + copy->_count++; previous = listObject; } } @catch (id e) { [copy release]; @throw e; } - copy->lastListObject = listObject; + copy->_lastListObject = listObject; return copy; } - (uint32_t)hash @@ -325,11 +325,11 @@ of_list_object_t *iter; uint32_t hash; OF_HASH_INIT(hash); - for (iter = firstListObject; iter != NULL; iter = iter->next) + for (iter = _firstListObject; iter != NULL; iter = iter->next) OF_HASH_ADD_HASH(hash, [iter->object hash]); OF_HASH_FINALIZE(hash); return hash; @@ -338,16 +338,16 @@ - (OFString*)description { OFMutableString *ret; of_list_object_t *iter; - if (count == 0) + if (_count == 0) return @"[]"; ret = [OFMutableString stringWithString: @"[\n"]; - for (iter = firstListObject; iter != NULL; iter = iter->next) { + for (iter = _firstListObject; iter != NULL; iter = iter->next) { void *pool = objc_autoreleasePoolPush(); [ret appendString: [iter->object description]]; if (iter->next != NULL) @@ -370,11 +370,11 @@ of_list_object_t *iter; element = [OFXMLElement elementWithName: [self className] namespace: OF_SERIALIZATION_NS]; - for (iter = firstListObject; iter != NULL; iter = iter->next) { + for (iter = _firstListObject; iter != NULL; iter = iter->next) { void *pool = objc_autoreleasePoolPush(); [element addChild: [iter->object XMLElementBySerializing]]; objc_autoreleasePoolPop(pool); @@ -383,86 +383,86 @@ return element; } - (int)countByEnumeratingWithState: (of_fast_enumeration_state_t*)state objects: (id*)objects - count: (int)count_ + count: (int)count { of_list_object_t **listObject = (of_list_object_t**)&state->extra[0]; int i; state->itemsPtr = objects; - state->mutationsPtr = &mutations; + state->mutationsPtr = &_mutations; if (state->state == 0) { - *listObject = firstListObject; + *listObject = _firstListObject; state->state = 1; } - for (i = 0; i < count_; i++) { + for (i = 0; i < count; i++) { if (*listObject == NULL) return i; objects[i] = (*listObject)->object; *listObject = (*listObject)->next; } - return count_; + return count; } - (OFEnumerator*)objectEnumerator { return [[[OFListEnumerator alloc] initWithList: self - mutationsPointer: &mutations] autorelease]; + mutationsPointer: &_mutations] autorelease]; } @end @implementation OFListEnumerator -- initWithList: (OFList*)list_ - mutationsPointer: (unsigned long*)mutationsPtr_ +- initWithList: (OFList*)list + mutationsPointer: (unsigned long*)mutationsPtr { self = [super init]; - list = [list_ retain]; - current = [list firstListObject]; - mutations = *mutationsPtr_; - mutationsPtr = mutationsPtr_; + _list = [list retain]; + _current = [list firstListObject]; + _mutations = *mutationsPtr; + _mutationsPtr = mutationsPtr; return self; } - (void)dealloc { - [list release]; + [_list release]; [super dealloc]; } - (id)nextObject { id ret; - if (*mutationsPtr != mutations) + if (*_mutationsPtr != _mutations) @throw [OFEnumerationMutationException exceptionWithClass: [self class] - object: list]; + object: _list]; - if (current == NULL) + if (_current == NULL) return nil; - ret = current->object; - current = current->next; + ret = _current->object; + _current = _current->next; return ret; } - (void)reset { - if (*mutationsPtr != mutations) + if (*_mutationsPtr != _mutations) @throw [OFEnumerationMutationException exceptionWithClass: [self class] - object: list]; + object: _list]; - current = [list firstListObject]; + _current = [_list firstListObject]; } @end Index: src/OFMD5Hash.h ================================================================== --- src/OFMD5Hash.h +++ src/OFMD5Hash.h @@ -21,13 +21,13 @@ /*! * @brief A class which provides functions to create an MD5 hash. */ @interface OFMD5Hash: OFHash { - uint32_t buffer[4]; - uint32_t bits[2]; + uint32_t _buffer[4]; + uint32_t _bits[2]; union { uint8_t u8[64]; uint32_t u32[16]; - } in; + } _in; } @end Index: src/OFMD5Hash.m ================================================================== --- src/OFMD5Hash.m +++ src/OFMD5Hash.m @@ -144,118 +144,118 @@ - init { self = [super init]; - buffer[0] = 0x67452301; - buffer[1] = 0xEFCDAB89; - buffer[2] = 0x98BADCFE; - buffer[3] = 0x10325476; + _buffer[0] = 0x67452301; + _buffer[1] = 0xEFCDAB89; + _buffer[2] = 0x98BADCFE; + _buffer[3] = 0x10325476; return self; } -- (void)updateWithBuffer: (const void*)buffer__ +- (void)updateWithBuffer: (const void*)buffer_ length: (size_t)length { uint32_t t; - const char *buffer_ = buffer__; + const char *buffer = buffer_; if (length == 0) return; - if (calculated) + if (_calculated) @throw [OFHashAlreadyCalculatedException exceptionWithClass: [self class] hash: self]; /* Update bitcount */ - t = bits[0]; - if ((bits[0] = t + ((uint32_t)length << 3)) < t) + t = _bits[0]; + if ((_bits[0] = t + ((uint32_t)length << 3)) < t) /* Carry from low to high */ - bits[1]++; - bits[1] += (uint32_t)length >> 29; + _bits[1]++; + _bits[1] += (uint32_t)length >> 29; /* Bytes already in shsInfo->data */ t = (t >> 3) & 0x3F; /* Handle any leading odd-sized chunks */ if (t) { - uint8_t *p = in.u8 + t; + uint8_t *p = _in.u8 + t; t = 64 - t; if (length < t) { - memcpy(p, buffer_, length); + memcpy(p, buffer, length); return; } - memcpy(p, buffer_, t); + memcpy(p, buffer, t); BSWAP32_VEC_IF_BE(in.u32, 16); - md5_transform(buffer, in.u32); + md5_transform(_buffer, _in.u32); - buffer_ += t; + buffer += t; length -= t; } /* Process data in 64-byte chunks */ while (length >= 64) { - memcpy(in.u8, buffer_, 64); - BSWAP32_VEC_IF_BE(in.u32, 16); - md5_transform(buffer, in.u32); + memcpy(_in.u8, buffer, 64); + BSWAP32_VEC_IF_BE(_in.u32, 16); + md5_transform(_buffer, _in.u32); - buffer_ += 64; + buffer += 64; length -= 64; } /* Handle any remaining bytes of data. */ - memcpy(in.u8, buffer_, length); + memcpy(_in.u8, buffer, length); } - (uint8_t*)digest { uint8_t *p; - size_t count; + size_t count; - if (calculated) - return (uint8_t*)buffer; + if (_calculated) + return (uint8_t*)_buffer; /* Compute number of bytes mod 64 */ - count = (bits[0] >> 3) & 0x3F; + count = (_bits[0] >> 3) & 0x3F; /* * Set the first char of padding to 0x80. This is safe since there is * always at least one byte free */ - p = in.u8 + count; + p = _in.u8 + count; *p++ = 0x80; /* Bytes of padding needed to make 64 bytes */ count = 64 - 1 - count; /* Pad out to 56 mod 64 */ if (count < 8) { /* Two lots of padding: Pad the first block to 64 bytes */ memset(p, 0, count); - BSWAP32_VEC_IF_BE(in.u32, 16); - md5_transform(buffer, in.u32); + BSWAP32_VEC_IF_BE(_in.u32, 16); + md5_transform(_buffer, _in.u32); /* Now fill the next block with 56 bytes */ - memset(in.u8, 0, 56); + memset(_in.u8, 0, 56); } else { /* Pad block to 56 bytes */ memset(p, 0, count - 8); } BSWAP32_VEC_IF_BE(in.u32, 14); /* Append length in bits and transform */ - in.u32[14] = bits[0]; - in.u32[15] = bits[1]; - - md5_transform(buffer, in.u32); - BSWAP32_VEC_IF_BE(buffer, 4); - - calculated = YES; - - return (uint8_t*)buffer; + _in.u32[14] = _bits[0]; + _in.u32[15] = _bits[1]; + + md5_transform(_buffer, _in.u32); + BSWAP32_VEC_IF_BE(_buffer, 4); + + _calculated = YES; + + return (uint8_t*)_buffer; } @end Index: src/OFMapTable.h ================================================================== --- src/OFMapTable.h +++ src/OFMapTable.h @@ -44,15 +44,15 @@ * @brief A class similar to OFDictionary, but providing more options how keys * and values should be retained, released, compared and hashed. */ @interface OFMapTable: OFObject { - of_map_table_functions_t keyFunctions, valueFunctions; - struct of_map_table_bucket **buckets; - uint32_t minCapacity, capacity, count; - uint8_t rotate; - unsigned long mutations; + of_map_table_functions_t _keyFunctions, _valueFunctions; + struct of_map_table_bucket **_buckets; + uint32_t _minCapacity, _capacity, _count; + uint8_t _rotate; + unsigned long _mutations; } /*! * @brief Creates a new OFMapTable with the specified key and value functions. * @@ -210,22 +210,22 @@ * @brief A class which provides methods to enumerate through an OFMapTable's * keys or values. */ @interface OFMapTableEnumerator: OFObject { - OFMapTable *mapTable; - struct of_map_table_bucket **buckets; - uint32_t capacity; - unsigned long mutations; - unsigned long *mutationsPtr; - uint32_t position; + OFMapTable *_mapTable; + struct of_map_table_bucket **_buckets; + uint32_t _capacity; + unsigned long _mutations; + unsigned long *_mutationsPtr; + uint32_t _position; } -- OF_initWithMapTable: (OFMapTable*)mapTable_ - buckets: (struct of_map_table_bucket**)buckets_ - capacity: (uint32_t)capacity_ - mutationsPointer: (unsigned long*)mutationsPtr_; +- OF_initWithMapTable: (OFMapTable*)mapTable + buckets: (struct of_map_table_bucket**)buckets + capacity: (uint32_t)capacity + mutationsPointer: (unsigned long*)mutationsPtr; /*! * @brief Returns the next value. * * @return The next value @@ -239,12 +239,12 @@ - (void)reset; @end @interface OFMapTableEnumeratorWrapper: OFEnumerator { - OFMapTableEnumerator *enumerator; - id object; + OFMapTableEnumerator *_enumerator; + id _object; } - initWithEnumerator: (OFMapTableEnumerator*)enumerator object: (id)object; @end Index: src/OFMapTable.m ================================================================== --- src/OFMapTable.m +++ src/OFMapTable.m @@ -98,71 +98,71 @@ } abort(); } -- initWithKeyFunctions: (of_map_table_functions_t)keyFunctions_ - valueFunctions: (of_map_table_functions_t)valueFunctions_ +- initWithKeyFunctions: (of_map_table_functions_t)keyFunctions + valueFunctions: (of_map_table_functions_t)valueFunctions { - return [self initWithKeyFunctions: keyFunctions_ - valueFunctions: valueFunctions_ + return [self initWithKeyFunctions: keyFunctions + valueFunctions: valueFunctions capacity: 0]; } -- initWithKeyFunctions: (of_map_table_functions_t)keyFunctions_ - valueFunctions: (of_map_table_functions_t)valueFunctions_ - capacity: (size_t)capacity_ +- initWithKeyFunctions: (of_map_table_functions_t)keyFunctions + valueFunctions: (of_map_table_functions_t)valueFunctions + capacity: (size_t)capacity { self = [super init]; @try { - keyFunctions = keyFunctions_; - valueFunctions = valueFunctions_; + _keyFunctions = keyFunctions; + _valueFunctions = valueFunctions; #define SET_DEFAULT(var, value) \ if (var == NULL) \ var = value; - SET_DEFAULT(keyFunctions.retain, default_retain); - SET_DEFAULT(keyFunctions.release, default_release); - SET_DEFAULT(keyFunctions.hash, default_hash); - SET_DEFAULT(keyFunctions.equal, default_equal); - - SET_DEFAULT(valueFunctions.retain, default_retain); - SET_DEFAULT(valueFunctions.release, default_release); - SET_DEFAULT(valueFunctions.hash, default_hash); - SET_DEFAULT(valueFunctions.equal, default_equal); + SET_DEFAULT(_keyFunctions.retain, default_retain); + SET_DEFAULT(_keyFunctions.release, default_release); + SET_DEFAULT(_keyFunctions.hash, default_hash); + SET_DEFAULT(_keyFunctions.equal, default_equal); + + SET_DEFAULT(_valueFunctions.retain, default_retain); + SET_DEFAULT(_valueFunctions.release, default_release); + SET_DEFAULT(_valueFunctions.hash, default_hash); + SET_DEFAULT(_valueFunctions.equal, default_equal); #undef SET_DEFAULT - if (capacity_ > UINT32_MAX || - capacity_ > UINT32_MAX / sizeof(*buckets) || - capacity_ > UINT32_MAX / 8) + if (capacity > UINT32_MAX || + capacity > UINT32_MAX / sizeof(*_buckets) || + capacity > UINT32_MAX / 8) @throw [OFOutOfRangeException exceptionWithClass: [self class]]; - for (capacity = 1; capacity < capacity_; capacity <<= 1); - if (capacity_ * 8 / capacity >= 6) - capacity <<= 1; - - if (capacity < MIN_CAPACITY) - capacity = MIN_CAPACITY; - - minCapacity = capacity; - - buckets = [self allocMemoryWithSize: sizeof(*buckets) - count: capacity]; - - memset(buckets, 0, capacity * sizeof(*buckets)); + for (_capacity = 1; _capacity < capacity; _capacity <<= 1); + if (capacity * 8 / _capacity >= 6) + _capacity <<= 1; + + if (_capacity < MIN_CAPACITY) + _capacity = MIN_CAPACITY; + + _minCapacity = _capacity; + + _buckets = [self allocMemoryWithSize: sizeof(*_buckets) + count: _capacity]; + + memset(_buckets, 0, _capacity * sizeof(*_buckets)); if (of_hash_seed != 0) #if defined(HAVE_ARC4RANDOM) - rotate = arc4random() & 31; + _rotate = arc4random() & 31; #elif defined(HAVE_RANDOM) - rotate = random() & 31; + _rotate = random() & 31; #else - rotate = rand() & 31; + _rotate = rand() & 31; #endif } @catch (id e) { [self release]; @throw e; } @@ -172,40 +172,40 @@ - (void)dealloc { uint32_t i; - for (i = 0; i < capacity; i++) { - if (buckets[i] != NULL && buckets[i] != &deleted) { - keyFunctions.release(buckets[i]->key); - valueFunctions.release(buckets[i]->value); + for (i = 0; i < _capacity; i++) { + if (_buckets[i] != NULL && _buckets[i] != &deleted) { + _keyFunctions.release(_buckets[i]->key); + _valueFunctions.release(_buckets[i]->value); } } [super dealloc]; } -- (BOOL)isEqual: (id)mapTable_ +- (BOOL)isEqual: (id)object { OFMapTable *mapTable; uint32_t i; - if (![mapTable_ isKindOfClass: [OFMapTable class]]) - return NO; - - mapTable = mapTable_; - - if (mapTable->count != count || - mapTable->keyFunctions.equal != keyFunctions.equal || - mapTable->valueFunctions.equal != valueFunctions.equal) - return NO; - - for (i = 0; i < capacity; i++) { - if (buckets[i] != NULL && buckets[i] != &deleted) { - void *value = [mapTable valueForKey: buckets[i]->key]; - - if (!valueFunctions.equal(value, buckets[i]->value)) + if (![object isKindOfClass: [OFMapTable class]]) + return NO; + + mapTable = object; + + if (mapTable->_count != _count || + mapTable->_keyFunctions.equal != _keyFunctions.equal || + mapTable->_valueFunctions.equal != _valueFunctions.equal) + return NO; + + for (i = 0; i < _capacity; i++) { + if (_buckets[i] != NULL && _buckets[i] != &deleted) { + void *value = [mapTable valueForKey: _buckets[i]->key]; + + if (!_valueFunctions.equal(value, _buckets[i]->value)) return NO; } } return YES; @@ -213,49 +213,49 @@ - (uint32_t)hash { uint32_t i, hash = 0; - for (i = 0; i < capacity; i++) { - if (buckets[i] != NULL && buckets[i] != &deleted) { - hash += OF_ROR(buckets[i]->hash, rotate); - hash += valueFunctions.hash(buckets[i]->value); + for (i = 0; i < _capacity; i++) { + if (_buckets[i] != NULL && _buckets[i] != &deleted) { + hash += OF_ROR(_buckets[i]->hash, _rotate); + hash += _valueFunctions.hash(_buckets[i]->value); } } return hash; } - (id)copy { OFMapTable *copy = [[OFMapTable alloc] - initWithKeyFunctions: keyFunctions - valueFunctions: valueFunctions - capacity: capacity]; + initWithKeyFunctions: _keyFunctions + valueFunctions: _valueFunctions + capacity: _capacity]; @try { uint32_t i; - for (i = 0; i < capacity; i++) - if (buckets[i] != NULL && buckets[i] != &deleted) - [copy OF_setValue: buckets[i]->value - forKey: buckets[i]->key - hash: OF_ROR(buckets[i]->hash, - rotate)]; + for (i = 0; i < _capacity; i++) + if (_buckets[i] != NULL && _buckets[i] != &deleted) + [copy OF_setValue: _buckets[i]->value + forKey: _buckets[i]->key + hash: OF_ROR(_buckets[i]->hash, + _rotate)]; } @catch (id e) { [copy release]; @throw e; } - copy->minCapacity = MIN_CAPACITY; + copy->_minCapacity = MIN_CAPACITY; return copy; } - (size_t)count { - return count; + return _count; } - (void*)valueForKey: (void*)key { uint32_t i, hash, last; @@ -263,91 +263,91 @@ if (key == NULL) @throw [OFInvalidArgumentException exceptionWithClass: [self class] selector: _cmd]; - hash = OF_ROL(keyFunctions.hash(key), rotate); - last = capacity; + hash = OF_ROL(_keyFunctions.hash(key), _rotate); + last = _capacity; - for (i = hash & (capacity - 1); i < last && buckets[i] != NULL; i++) { - if (buckets[i] == &deleted) + for (i = hash & (_capacity - 1); i < last && _buckets[i] != NULL; i++) { + if (_buckets[i] == &deleted) continue; - if (keyFunctions.equal(buckets[i]->key, key)) - return buckets[i]->value; + if (_keyFunctions.equal(_buckets[i]->key, key)) + return _buckets[i]->value; } if (i < last) return nil; /* In case the last bucket is already used */ - last = hash & (capacity - 1); + last = hash & (_capacity - 1); - for (i = 0; i < last && buckets[i] != NULL; i++) { - if (buckets[i] == &deleted) + for (i = 0; i < last && _buckets[i] != NULL; i++) { + if (_buckets[i] == &deleted) continue; - if (keyFunctions.equal(buckets[i]->key, key)) - return buckets[i]->value; + if (_keyFunctions.equal(_buckets[i]->key, key)) + return _buckets[i]->value; } return NULL; } -- (void)OF_resizeForCount: (uint32_t)newCount +- (void)OF_resizeForCount: (uint32_t)count { - uint32_t i, fullness, newCapacity; - struct of_map_table_bucket **newBuckets; + uint32_t i, fullness, capacity; + struct of_map_table_bucket **buckets; - if (newCount > UINT32_MAX || newCount > UINT32_MAX / sizeof(*buckets) || - newCount > UINT32_MAX / 8) + if (count > UINT32_MAX || count > UINT32_MAX / sizeof(*_buckets) || + count > UINT32_MAX / 8) @throw [OFOutOfRangeException exceptionWithClass: [self class]]; - fullness = newCount * 8 / capacity; + fullness = count * 8 / _capacity; if (fullness >= 6) - newCapacity = capacity << 1; + capacity = _capacity << 1; else if (fullness <= 1) - newCapacity = capacity >> 1; + capacity = _capacity >> 1; else return; - if (newCapacity < capacity && newCapacity < minCapacity) + if (capacity < _capacity && capacity < _minCapacity) return; - newBuckets = [self allocMemoryWithSize: sizeof(*newBuckets) - count: newCapacity]; - - for (i = 0; i < newCapacity; i++) - newBuckets[i] = NULL; - - for (i = 0; i < capacity; i++) { - if (buckets[i] != NULL && buckets[i] != &deleted) { + buckets = [self allocMemoryWithSize: sizeof(*buckets) + count: capacity]; + + for (i = 0; i < capacity; i++) + buckets[i] = NULL; + + for (i = 0; i < _capacity; i++) { + if (_buckets[i] != NULL && _buckets[i] != &deleted) { uint32_t j, last; - last = newCapacity; + last = capacity; - j = buckets[i]->hash & (newCapacity - 1); - for (; j < last && newBuckets[j] != NULL; j++); + j = _buckets[i]->hash & (capacity - 1); + for (; j < last && buckets[j] != NULL; j++); /* In case the last bucket is already used */ if (j >= last) { - last = buckets[i]->hash & (newCapacity - 1); + last = _buckets[i]->hash & (capacity - 1); for (j = 0; j < last && - newBuckets[j] != NULL; j++); + buckets[j] != NULL; j++); } assert(j < last); - newBuckets[j] = buckets[i]; + buckets[j] = _buckets[i]; } } - [self freeMemory: buckets]; - buckets = newBuckets; - capacity = newCapacity; + [self freeMemory: _buckets]; + _buckets = buckets; + _capacity = capacity; } - (void)OF_setValue: (void*)value forKey: (void*)key hash: (uint32_t)hash @@ -358,95 +358,95 @@ if (key == NULL || value == NULL) @throw [OFInvalidArgumentException exceptionWithClass: [self class] selector: _cmd]; - hash = OF_ROL(hash, rotate); - last = capacity; + hash = OF_ROL(hash, _rotate); + last = _capacity; - for (i = hash & (capacity - 1); i < last && buckets[i] != NULL; i++) { - if (buckets[i] == &deleted) + for (i = hash & (_capacity - 1); i < last && _buckets[i] != NULL; i++) { + if (_buckets[i] == &deleted) continue; - if (keyFunctions.equal(buckets[i]->key, key)) + if (_keyFunctions.equal(_buckets[i]->key, key)) break; } /* In case the last bucket is already used */ if (i >= last) { - last = hash & (capacity - 1); + last = hash & (_capacity - 1); - for (i = 0; i < last && buckets[i] != NULL; i++) { - if (buckets[i] == &deleted) + for (i = 0; i < last && _buckets[i] != NULL; i++) { + if (_buckets[i] == &deleted) continue; - if (keyFunctions.equal(buckets[i]->key, key)) + if (_keyFunctions.equal(_buckets[i]->key, key)) break; } } /* Key not in dictionary */ - if (i >= last || buckets[i] == NULL || buckets[i] == &deleted || - !keyFunctions.equal(buckets[i]->key, key)) { + if (i >= last || _buckets[i] == NULL || _buckets[i] == &deleted || + !_keyFunctions.equal(_buckets[i]->key, key)) { struct of_map_table_bucket *bucket; - [self OF_resizeForCount: count + 1]; + [self OF_resizeForCount: _count + 1]; - mutations++; - last = capacity; + _mutations++; + last = _capacity; - for (i = hash & (capacity - 1); i < last && - buckets[i] != NULL && buckets[i] != &deleted; i++); + for (i = hash & (_capacity - 1); i < last && + _buckets[i] != NULL && _buckets[i] != &deleted; i++); /* In case the last bucket is already used */ if (i >= last) { - last = hash & (capacity - 1); + last = hash & (_capacity - 1); - for (i = 0; i < last && buckets[i] != NULL && - buckets[i] != &deleted; i++); + for (i = 0; i < last && _buckets[i] != NULL && + _buckets[i] != &deleted; i++); } if (i >= last) @throw [OFOutOfRangeException exceptionWithClass: [self class]]; bucket = [self allocMemoryWithSize: sizeof(*bucket)]; @try { - bucket->key = keyFunctions.retain(key); + bucket->key = _keyFunctions.retain(key); } @catch (id e) { [self freeMemory: bucket]; @throw e; } @try { - bucket->value = valueFunctions.retain(value); + bucket->value = _valueFunctions.retain(value); } @catch (id e) { - keyFunctions.release(key); + _keyFunctions.release(key); [self freeMemory: bucket]; @throw e; } bucket->hash = hash; - buckets[i] = bucket; - count++; + _buckets[i] = bucket; + _count++; return; } - old = buckets[i]->value; - buckets[i]->value = valueFunctions.retain(value); - valueFunctions.release(old); + old = _buckets[i]->value; + _buckets[i]->value = _valueFunctions.retain(value); + _valueFunctions.release(old); } - (void)setValue: (void*)value forKey: (void*)key { [self OF_setValue: value forKey: key - hash: keyFunctions.hash(key)]; + hash: _keyFunctions.hash(key)]; } - (void)removeValueForKey: (void*)key { uint32_t i, hash, last; @@ -454,52 +454,52 @@ if (key == NULL) @throw [OFInvalidArgumentException exceptionWithClass: [self class] selector: _cmd]; - hash = OF_ROL(keyFunctions.hash(key), rotate); - last = capacity; + hash = OF_ROL(_keyFunctions.hash(key), _rotate); + last = _capacity; - for (i = hash & (capacity - 1); i < last && buckets[i] != NULL; i++) { - if (buckets[i] == &deleted) + for (i = hash & (_capacity - 1); i < last && _buckets[i] != NULL; i++) { + if (_buckets[i] == &deleted) continue; - if (keyFunctions.equal(buckets[i]->key, key)) { - keyFunctions.release(buckets[i]->key); - valueFunctions.release(buckets[i]->value); - - [self freeMemory: buckets[i]]; - buckets[i] = &deleted; - - count--; - mutations++; - [self OF_resizeForCount: count]; + if (_keyFunctions.equal(_buckets[i]->key, key)) { + _keyFunctions.release(_buckets[i]->key); + _valueFunctions.release(_buckets[i]->value); + + [self freeMemory: _buckets[i]]; + _buckets[i] = &deleted; + + _count--; + _mutations++; + [self OF_resizeForCount: _count]; return; } } if (i < last) return; /* In case the last bucket is already used */ - last = hash & (capacity - 1); + last = hash & (_capacity - 1); - for (i = 0; i < last && buckets[i] != NULL; i++) { - if (buckets[i] == &deleted) + for (i = 0; i < last && _buckets[i] != NULL; i++) { + if (_buckets[i] == &deleted) continue; - if (keyFunctions.equal(buckets[i]->key, key)) { - keyFunctions.release(buckets[i]->key); - valueFunctions.release(buckets[i]->value); - - [self freeMemory: buckets[i]]; - buckets[i] = &deleted; - - count--; - mutations++; - [self OF_resizeForCount: count]; + if (_keyFunctions.equal(_buckets[i]->key, key)) { + _keyFunctions.release(_buckets[i]->key); + _valueFunctions.release(_buckets[i]->value); + + [self freeMemory: _buckets[i]]; + _buckets[i] = &deleted; + + _count--; + _mutations++; + [self OF_resizeForCount: _count]; return; } } } @@ -506,75 +506,75 @@ - (BOOL)containsValue: (void*)value { uint32_t i; - if (value == NULL || count == 0) + if (value == NULL || _count == 0) return NO; - for (i = 0; i < capacity; i++) - if (buckets[i] != NULL && buckets[i] != &deleted) - if (valueFunctions.equal(buckets[i]->value, value)) + for (i = 0; i < _capacity; i++) + if (_buckets[i] != NULL && _buckets[i] != &deleted) + if (_valueFunctions.equal(_buckets[i]->value, value)) return YES; return NO; } - (BOOL)containsValueIdenticalTo: (void*)value { uint32_t i; - if (value == NULL || count == 0) + if (value == NULL || _count == 0) return NO; - for (i = 0; i < capacity; i++) - if (buckets[i] != NULL && buckets[i] != &deleted) - if (buckets[i]->value == value) + for (i = 0; i < _capacity; i++) + if (_buckets[i] != NULL && _buckets[i] != &deleted) + if (_buckets[i]->value == value) return YES; return NO; } - (OFMapTableEnumerator*)keyEnumerator { return [[[OFMapTableKeyEnumerator alloc] OF_initWithMapTable: self - buckets: buckets - capacity: capacity - mutationsPointer: &mutations] autorelease]; + buckets: _buckets + capacity: _capacity + mutationsPointer: &_mutations] autorelease]; } - (OFMapTableEnumerator*)valueEnumerator { return [[[OFMapTableValueEnumerator alloc] OF_initWithMapTable: self - buckets: buckets - capacity: capacity - mutationsPointer: &mutations] autorelease]; + buckets: _buckets + capacity: _capacity + mutationsPointer: &_mutations] autorelease]; } - (int)countByEnumeratingWithState: (of_fast_enumeration_state_t*)state objects: (id*)objects - count: (int)count_ + count: (int)count { uint32_t j = (uint32_t)state->state; int i; - for (i = 0; i < count_; i++) { - for (; j < capacity && (buckets[j] == NULL || - buckets[j] == &deleted); j++); + for (i = 0; i < count; i++) { + for (; j < _capacity && (_buckets[j] == NULL || + _buckets[j] == &deleted); j++); - if (j < capacity) { - objects[i] = buckets[j]->key; + if (j < _capacity) { + objects[i] = _buckets[j]->key; j++; } else break; } state->state = j; state->itemsPtr = objects; - state->mutationsPtr = &mutations; + state->mutationsPtr = &_mutations; return i; } #ifdef OF_HAVE_BLOCKS @@ -581,60 +581,61 @@ - (void)enumerateKeysAndValuesUsingBlock: (of_map_table_enumeration_block_t)block { size_t i; BOOL stop = NO; - unsigned long mutations_ = mutations; + unsigned long mutations = _mutations; - for (i = 0; i < capacity && !stop; i++) { - if (mutations != mutations_) + for (i = 0; i < _capacity && !stop; i++) { + if (_mutations != mutations) @throw [OFEnumerationMutationException exceptionWithClass: [self class] object: self]; - if (buckets[i] != NULL && buckets[i] != &deleted) - block(buckets[i]->key, buckets[i]->value, &stop); + if (_buckets[i] != NULL && _buckets[i] != &deleted) + block(_buckets[i]->key, _buckets[i]->value, &stop); } } - (void)replaceValuesUsingBlock: (of_map_table_replace_block_t)block { size_t i; BOOL stop = NO; - unsigned long mutations_ = mutations; + unsigned long mutations = _mutations; - for (i = 0; i < capacity && !stop; i++) { - if (mutations != mutations_) + for (i = 0; i < _capacity && !stop; i++) { + if (_mutations != mutations) @throw [OFEnumerationMutationException exceptionWithClass: [self class] object: self]; - if (buckets[i] != NULL && buckets[i] != &deleted) { + if (_buckets[i] != NULL && _buckets[i] != &deleted) { void *old, *new; - new = block(buckets[i]->key, buckets[i]->value, &stop); + new = block(_buckets[i]->key, _buckets[i]->value, + &stop); if (new == NULL) @throw [OFInvalidArgumentException exceptionWithClass: [self class] selector: _cmd]; - old = buckets[i]->value; - buckets[i]->value = valueFunctions.retain(new); - valueFunctions.release(old); + old = _buckets[i]->value; + _buckets[i]->value = _valueFunctions.retain(new); + _valueFunctions.release(old); } } } #endif - (of_map_table_functions_t)keyFunctions { - return keyFunctions; + return _keyFunctions; } - (of_map_table_functions_t)valueFunctions { - return valueFunctions; + return _valueFunctions; } @end @implementation OFMapTableEnumerator - init @@ -647,29 +648,29 @@ } abort(); } -- OF_initWithMapTable: (OFMapTable*)mapTable_ - buckets: (struct of_map_table_bucket**)buckets_ - capacity: (uint32_t)capacity_ - mutationsPointer: (unsigned long*)mutationsPtr_ +- OF_initWithMapTable: (OFMapTable*)mapTable + buckets: (struct of_map_table_bucket**)buckets + capacity: (uint32_t)capacity + mutationsPointer: (unsigned long*)mutationsPtr { self = [super init]; - mapTable = [mapTable_ retain]; - buckets = buckets_; - capacity = capacity_; - mutations = *mutationsPtr_; - mutationsPtr = mutationsPtr_; + _mapTable = [mapTable retain]; + _buckets = buckets; + _capacity = capacity; + _mutations = *mutationsPtr; + _mutationsPtr = mutationsPtr; return self; } - (void)dealloc { - [mapTable release]; + [_mapTable release]; [super dealloc]; } - (void*)nextValue @@ -678,96 +679,96 @@ abort(); } - (void)reset { - if (*mutationsPtr != mutations) + if (*_mutationsPtr != _mutations) @throw [OFEnumerationMutationException - exceptionWithClass: [mapTable class] - object: mapTable]; + exceptionWithClass: [_mapTable class] + object: _mapTable]; - position = 0; + _position = 0; } @end @implementation OFMapTableKeyEnumerator - (void*)nextValue { - if (*mutationsPtr != mutations) + if (*_mutationsPtr != _mutations) @throw [OFEnumerationMutationException - exceptionWithClass: [mapTable class] - object: mapTable]; - - for (; position < capacity && (buckets[position] == NULL || - buckets[position] == &deleted); position++); - - if (position < capacity) - return buckets[position++]->key; + exceptionWithClass: [_mapTable class] + object: _mapTable]; + + for (; _position < _capacity && (_buckets[_position] == NULL || + _buckets[_position] == &deleted); _position++); + + if (_position < _capacity) + return _buckets[_position++]->key; else return NULL; } @end @implementation OFMapTableValueEnumerator - (void*)nextValue { - if (*mutationsPtr != mutations) + if (*_mutationsPtr != _mutations) @throw [OFEnumerationMutationException - exceptionWithClass: [mapTable class] - object: mapTable]; - - for (; position < capacity && (buckets[position] == NULL || - buckets[position] == &deleted); position++); - - if (position < capacity) - return buckets[position++]->value; + exceptionWithClass: [_mapTable class] + object: _mapTable]; + + for (; _position < _capacity && (_buckets[_position] == NULL || + _buckets[_position] == &deleted); _position++); + + if (_position < _capacity) + return _buckets[_position++]->value; else return NULL; } @end @implementation OFMapTableEnumeratorWrapper -- initWithEnumerator: (OFMapTableEnumerator*)enumerator_ - object: (id)object_ +- initWithEnumerator: (OFMapTableEnumerator*)enumerator + object: (id)object { self = [super init]; - enumerator = [enumerator_ retain]; - object = [object_ retain]; + _enumerator = [enumerator retain]; + _object = [object retain]; return self; } - (void)dealloc { - [enumerator release]; - [object release]; + [_enumerator release]; + [_object release]; [super dealloc]; } - (id)nextObject { id ret; @try { - ret = [enumerator nextValue]; + ret = [_enumerator nextValue]; } @catch (OFEnumerationMutationException *e) { @throw [OFEnumerationMutationException - exceptionWithClass: [object class] - object: object]; + exceptionWithClass: [_object class] + object: _object]; } return ret; } - (void)reset { @try { - [enumerator reset]; + [_enumerator reset]; } @catch (OFEnumerationMutationException *e) { @throw [OFEnumerationMutationException - exceptionWithClass: [object class] - object: object]; + exceptionWithClass: [_object class] + object: _object]; } } @end Index: src/OFMutableArray_adjacent.h ================================================================== --- src/OFMutableArray_adjacent.h +++ src/OFMutableArray_adjacent.h @@ -18,9 +18,9 @@ @class OFDataArray; @interface OFMutableArray_adjacent: OFMutableArray { - OFDataArray *array; - unsigned long mutations; + OFDataArray *_array; + unsigned long _mutations; } @end Index: src/OFMutableArray_adjacent.m ================================================================== --- src/OFMutableArray_adjacent.m +++ src/OFMutableArray_adjacent.m @@ -37,44 +37,44 @@ { if (object == nil) @throw [OFInvalidArgumentException exceptionWithClass: [self class]]; - [array addItem: &object]; + [_array addItem: &object]; [object retain]; - mutations++; + _mutations++; } - (void)insertObject: (id)object atIndex: (size_t)index { if (object == nil) @throw [OFInvalidArgumentException exceptionWithClass: [self class]]; - [array insertItem: &object - atIndex: index]; + [_array insertItem: &object + atIndex: index]; [object retain]; - mutations++; + _mutations++; } -- (void)insertObjectsFromArray: (OFArray*)array_ +- (void)insertObjectsFromArray: (OFArray*)array atIndex: (size_t)index { - id *objects = [array_ objects]; - size_t i, count = [array_ count]; + id *objects = [array objects]; + size_t i, count = [array count]; - [array insertItems: objects - atIndex: index - count: count]; + [_array insertItems: objects + atIndex: index + count: count]; for (i = 0; i < count; i++) [objects[i] retain]; - mutations++; + _mutations++; } - (void)replaceObject: (id)oldObject withObject: (id)newObject { @@ -83,12 +83,12 @@ if (oldObject == nil || newObject == nil) @throw [OFInvalidArgumentException exceptionWithClass: [self class]]; - objects = [array items]; - count = [array count]; + objects = [_array items]; + count = [_array count]; for (i = 0; i < count; i++) { if ([objects[i] isEqual: oldObject]) { [newObject retain]; [objects[i] release]; @@ -107,13 +107,13 @@ if (object == nil) @throw [OFInvalidArgumentException exceptionWithClass: [self class]]; - objects = [array items]; + objects = [_array items]; - if (index >= [array count]) + if (index >= [_array count]) @throw [OFOutOfRangeException exceptionWithClass: [self class]]; oldObject = objects[index]; objects[index] = [object retain]; [oldObject release]; @@ -127,12 +127,12 @@ if (oldObject == nil || newObject == nil) @throw [OFInvalidArgumentException exceptionWithClass: [self class]]; - objects = [array items]; - count = [array count]; + objects = [_array items]; + count = [_array count]; for (i = 0; i < count; i++) { if (objects[i] == oldObject) { [newObject retain]; [objects[i] release]; @@ -150,19 +150,19 @@ if (object == nil) @throw [OFInvalidArgumentException exceptionWithClass: [self class]]; - objects = [array items]; - count = [array count]; + objects = [_array items]; + count = [_array count]; for (i = 0; i < count; i++) { if ([objects[i] isEqual: object]) { object = objects[i]; - [array removeItemAtIndex: i]; - mutations++; + [_array removeItemAtIndex: i]; + _mutations++; [object release]; return; } @@ -176,17 +176,17 @@ if (object == nil) @throw [OFInvalidArgumentException exceptionWithClass: [self class]]; - objects = [array items]; - count = [array count]; + objects = [_array items]; + count = [_array count]; for (i = 0; i < count; i++) { if (objects[i] == object) { - [array removeItemAtIndex: i]; - mutations++; + [_array removeItemAtIndex: i]; + _mutations++; [object release]; return; } @@ -194,31 +194,31 @@ } - (void)removeObjectAtIndex: (size_t)index { id object = [self objectAtIndex: index]; - [array removeItemAtIndex: index]; + [_array removeItemAtIndex: index]; [object release]; - mutations++; + _mutations++; } - (void)removeAllObjects { - id *objects = [array items]; - size_t i, count = [array count]; + id *objects = [_array items]; + size_t i, count = [_array count]; for (i = 0; i < count; i++) [objects[i] release]; - [array removeAllItems]; + [_array removeAllItems]; } - (void)removeObjectsInRange: (of_range_t)range { - id *objects = [array items], *copy; - size_t i, count = [array count]; + id *objects = [_array items], *copy; + size_t i, count = [_array count]; if (range.length > SIZE_MAX - range.location || range.length > count - range.location) @throw [OFOutOfRangeException exceptionWithClass: [self class]]; @@ -225,12 +225,12 @@ copy = [self allocMemoryWithSize: sizeof(*copy) count: range.length]; memcpy(copy, objects + range.location, range.length * sizeof(id)); @try { - [array removeItemsInRange: range]; - mutations++; + [_array removeItemsInRange: range]; + _mutations++; for (i = 0; i < range.length; i++) [copy[i] release]; } @finally { [self freeMemory: copy]; @@ -237,28 +237,28 @@ } } - (void)removeLastObject { - size_t count = [array count]; + size_t count = [_array count]; id object; if (count == 0) return; object = [self objectAtIndex: count - 1]; - [array removeLastItem]; + [_array removeLastItem]; [object release]; - mutations++; + _mutations++; } - (void)exchangeObjectAtIndex: (size_t)index1 withObjectAtIndex: (size_t)index2 { - id *objects = [array items]; - size_t count = [array count]; + id *objects = [_array items]; + size_t count = [_array count]; id tmp; if (index1 >= count || index2 >= count) @throw [OFOutOfRangeException exceptionWithClass: [self class]]; @@ -267,12 +267,12 @@ objects[index2] = tmp; } - (void)reverse { - id *objects = [array items]; - size_t i, j, count = [array count]; + id *objects = [_array items]; + size_t i, j, count = [_array count]; if (count == 0 || count == 1) return; for (i = 0, j = count - 1; i < j; i++, j--) { @@ -293,32 +293,32 @@ */ int ret = [super countByEnumeratingWithState: state objects: objects count: count]; - state->mutationsPtr = &mutations; + state->mutationsPtr = &_mutations; return ret; } - (OFEnumerator*)objectEnumerator { return [[[OFArrayEnumerator alloc] initWithArray: self - mutationsPtr: &mutations] autorelease]; + mutationsPtr: &_mutations] autorelease]; } #ifdef OF_HAVE_BLOCKS - (void)enumerateObjectsUsingBlock: (of_array_enumeration_block_t)block { - id *objects = [array items]; - size_t i, count = [array count]; + id *objects = [_array items]; + size_t i, count = [_array count]; BOOL stop = NO; - unsigned long mutations_ = mutations; + unsigned long mutations = _mutations; for (i = 0; i < count && !stop; i++) { - if (mutations != mutations_) + if (_mutations != mutations) @throw [OFEnumerationMutationException exceptionWithClass: [self class] object: self]; block(objects[i], i, &stop); @@ -325,19 +325,19 @@ } } - (void)replaceObjectsUsingBlock: (of_array_replace_block_t)block { - id *objects = [array items]; - size_t i, count = [array count]; + id *objects = [_array items]; + size_t i, count = [_array count]; BOOL stop = NO; - unsigned long mutations_ = mutations; + unsigned long mutations = _mutations; for (i = 0; i < count && !stop; i++) { id newObject; - if (mutations != mutations_) + if (_mutations != mutations) @throw [OFEnumerationMutationException exceptionWithClass: [self class] object: self]; newObject = block(objects[i], i, &stop); Index: src/OFMutableDictionary_hashtable.h ================================================================== --- src/OFMutableDictionary_hashtable.h +++ src/OFMutableDictionary_hashtable.h @@ -18,8 +18,8 @@ @class OFMapTable; @interface OFMutableDictionary_hashtable: OFMutableDictionary { - OFMapTable *mapTable; + OFMapTable *_mapTable; } @end Index: src/OFMutableDictionary_hashtable.m ================================================================== --- src/OFMutableDictionary_hashtable.m +++ src/OFMutableDictionary_hashtable.m @@ -36,24 +36,24 @@ } - (void)setObject: (id)object forKey: (id)key { - [mapTable setValue: object - forKey: key]; + [_mapTable setValue: object + forKey: key]; } - (void)removeObjectForKey: (id)key { - [mapTable removeValueForKey: key]; + [_mapTable removeValueForKey: key]; } #ifdef OF_HAVE_BLOCKS - (void)replaceObjectsUsingBlock: (of_dictionary_replace_block_t)block { @try { - [mapTable replaceValuesUsingBlock: + [_mapTable replaceValuesUsingBlock: ^ void* (void *key, void *value, BOOL *stop) { return block(key, value, stop); }]; } @catch (OFEnumerationMutationException *e) { @throw [OFEnumerationMutationException Index: src/OFMutableSet_hashtable.h ================================================================== --- src/OFMutableSet_hashtable.h +++ src/OFMutableSet_hashtable.h @@ -18,8 +18,8 @@ @class OFMapTable; @interface OFMutableSet_hashtable: OFMutableSet { - OFMapTable *mapTable; + OFMapTable *_mapTable; } @end Index: src/OFMutableSet_hashtable.m ================================================================== --- src/OFMutableSet_hashtable.m +++ src/OFMutableSet_hashtable.m @@ -27,19 +27,19 @@ [self inheritMethodsFromClass: [OFSet_hashtable class]]; } - (void)addObject: (id)object { - [mapTable setValue: (void*)1 - forKey: object]; + [_mapTable setValue: (void*)1 + forKey: object]; } - (void)removeObject: (id)object { - [mapTable removeValueForKey: object]; + [_mapTable removeValueForKey: object]; } - (void)makeImmutable { object_setClass(self, [OFSet_hashtable class]); } @end Index: src/OFMutableString_UTF8.h ================================================================== --- src/OFMutableString_UTF8.h +++ src/OFMutableString_UTF8.h @@ -18,9 +18,9 @@ #import "OFString_UTF8.h" @interface OFMutableString_UTF8: OFMutableString { @public - struct of_string_utf8_ivars *restrict s; - struct of_string_utf8_ivars s_store; + struct of_string_utf8_ivars *restrict _s; + struct of_string_utf8_ivars _storage; } @end Index: src/OFMutableString_UTF8.m ================================================================== --- src/OFMutableString_UTF8.m +++ src/OFMutableString_UTF8.m @@ -66,25 +66,25 @@ size_t unicodeLen, newCStringLength; size_t i, j; char *newCString; BOOL isStart = YES; - if (!s->isUTF8) { + if (!_s->isUTF8) { uint8_t t; const of_unichar_t *const *table; assert(startTableSize >= 1 && middleTableSize >= 1); - s->hashed = NO; + _s->hashed = NO; - for (i = 0; i < s->cStringLength; i++) { + for (i = 0; i < _s->cStringLength; i++) { if (isStart) table = startTable; else table = middleTable; - switch (s->cString[i]) { + switch (_s->cString[i]) { case ' ': case '\t': case '\n': case '\r': isStart = YES; @@ -92,12 +92,12 @@ default: isStart = NO; break; } - if ((t = table[0][(uint8_t)s->cString[i]]) != 0) - s->cString[i] = t; + if ((t = table[0][(uint8_t)_s->cString[i]]) != 0) + _s->cString[i] = t; } return; } @@ -106,11 +106,11 @@ count: unicodeLen]; i = j = 0; newCStringLength = 0; - while (i < s->cStringLength) { + while (i < _s->cStringLength) { const of_unichar_t *const *table; size_t tableSize; of_unichar_t c; size_t cLen; @@ -120,12 +120,12 @@ } else { table = middleTable; tableSize = middleTableSize; } - cLen = of_string_utf8_decode(s->cString + i, - s->cStringLength - i, &c); + cLen = of_string_utf8_decode(_s->cString + i, + _s->cStringLength - i, &c); if (cLen == 0 || c > 0x10FFFF) { [self freeMemory: unicodeString]; @throw [OFInvalidEncodingException exceptionWithClass: [self class]]; @@ -192,14 +192,14 @@ assert(j == newCStringLength); newCString[j] = 0; [self freeMemory: unicodeString]; - [self freeMemory: s->cString]; - s->hashed = NO; - s->cString = newCString; - s->cStringLength = newCStringLength; + [self freeMemory: _s->cString]; + _s->hashed = NO; + _s->cString = newCString; + _s->cStringLength = newCStringLength; /* * Even though cStringLength can change, length cannot, therefore no * need to change it. */ @@ -210,66 +210,67 @@ { char buffer[4]; of_unichar_t c; size_t lenNew, lenOld; - if (s->isUTF8) - index = of_string_utf8_get_position(s->cString, index, - s->cStringLength); + if (_s->isUTF8) + index = of_string_utf8_get_position(_s->cString, index, + _s->cStringLength); - if (index > s->cStringLength) + if (index > _s->cStringLength) @throw [OFOutOfRangeException exceptionWithClass: [self class]]; /* Shortcut if old and new character both are ASCII */ - if (!(character & 0x80) && !(s->cString[index] & 0x80)) { - s->hashed = NO; - s->cString[index] = character; + if (!(character & 0x80) && !(_s->cString[index] & 0x80)) { + _s->hashed = NO; + _s->cString[index] = character; return; } if ((lenNew = of_string_utf8_encode(character, buffer)) == 0) @throw [OFInvalidEncodingException exceptionWithClass: [self class]]; - if ((lenOld = of_string_utf8_decode(s->cString + index, - s->cStringLength - index, &c)) == 0) + if ((lenOld = of_string_utf8_decode(_s->cString + index, + _s->cStringLength - index, &c)) == 0) @throw [OFInvalidEncodingException exceptionWithClass: [self class]]; - s->hashed = NO; + _s->hashed = NO; if (lenNew == lenOld) - memcpy(s->cString + index, buffer, lenNew); + memcpy(_s->cString + index, buffer, lenNew); else if (lenNew > lenOld) { - s->cString = [self resizeMemory: s->cString - size: s->cStringLength - - lenOld + lenNew + 1]; - - memmove(s->cString + index + lenNew, - s->cString + index + lenOld, - s->cStringLength - index - lenOld); - memcpy(s->cString + index, buffer, lenNew); - - s->cStringLength -= lenOld; - s->cStringLength += lenNew; - s->cString[s->cStringLength] = '\0'; + _s->cString = [self resizeMemory: _s->cString + size: _s->cStringLength - + lenOld + lenNew + 1]; + + memmove(_s->cString + index + lenNew, + _s->cString + index + lenOld, + _s->cStringLength - index - lenOld); + memcpy(_s->cString + index, buffer, lenNew); + + _s->cStringLength -= lenOld; + _s->cStringLength += lenNew; + _s->cString[_s->cStringLength] = '\0'; if (character & 0x80) - s->isUTF8 = YES; + _s->isUTF8 = YES; } else if (lenNew < lenOld) { - memmove(s->cString + index + lenNew, - s->cString + index + lenOld, - s->cStringLength - index - lenOld); - memcpy(s->cString + index, buffer, lenNew); - - s->cStringLength -= lenOld; - s->cStringLength += lenNew; - s->cString[s->cStringLength] = '\0'; + memmove(_s->cString + index + lenNew, + _s->cString + index + lenOld, + _s->cStringLength - index - lenOld); + memcpy(_s->cString + index, buffer, lenNew); + + _s->cStringLength -= lenOld; + _s->cStringLength += lenNew; + _s->cString[_s->cStringLength] = '\0'; @try { - s->cString = [self resizeMemory: s->cString - size: s->cStringLength + 1]; + _s->cString = [self + resizeMemory: _s->cString + size: _s->cStringLength + 1]; } @catch (OFOutOfMemoryException *e) { /* We don't really care, as we only made it smaller */ } } else assert(0); @@ -285,25 +286,26 @@ UTF8StringLength -= 3; } switch (of_string_utf8_check(UTF8String, UTF8StringLength, &length)) { case 1: - s->isUTF8 = YES; + _s->isUTF8 = YES; break; case -1: @throw [OFInvalidEncodingException exceptionWithClass: [self class]]; } - s->hashed = NO; - s->cString = [self resizeMemory: s->cString - size: s->cStringLength + - UTF8StringLength + 1]; - memcpy(s->cString + s->cStringLength, UTF8String, UTF8StringLength + 1); - - s->cStringLength += UTF8StringLength; - s->length += length; + _s->hashed = NO; + _s->cString = [self resizeMemory: _s->cString + size: _s->cStringLength + + UTF8StringLength + 1]; + memcpy(_s->cString + _s->cStringLength, UTF8String, + UTF8StringLength + 1); + + _s->cStringLength += UTF8StringLength; + _s->length += length; } - (void)appendUTF8String: (const char*)UTF8String length: (size_t)UTF8StringLength { @@ -314,27 +316,27 @@ UTF8StringLength -= 3; } switch (of_string_utf8_check(UTF8String, UTF8StringLength, &length)) { case 1: - s->isUTF8 = YES; + _s->isUTF8 = YES; break; case -1: @throw [OFInvalidEncodingException exceptionWithClass: [self class]]; } - s->hashed = NO; - s->cString = [self resizeMemory: s->cString - size: s->cStringLength + - UTF8StringLength + 1]; - memcpy(s->cString + s->cStringLength, UTF8String, UTF8StringLength); - - s->cStringLength += UTF8StringLength; - s->length += length; - - s->cString[s->cStringLength] = 0; + _s->hashed = NO; + _s->cString = [self resizeMemory: _s->cString + size: _s->cStringLength + + UTF8StringLength + 1]; + memcpy(_s->cString + _s->cStringLength, UTF8String, UTF8StringLength); + + _s->cStringLength += UTF8StringLength; + _s->length += length; + + _s->cString[_s->cStringLength] = 0; } - (void)appendCString: (const char*)cString encoding: (of_string_encoding_t)encoding { @@ -369,28 +371,28 @@ exceptionWithClass: [self class] selector: _cmd]; UTF8StringLength = [string UTF8StringLength]; - s->hashed = NO; - s->cString = [self resizeMemory: s->cString - size: s->cStringLength + - UTF8StringLength + 1]; - memcpy(s->cString + s->cStringLength, [string UTF8String], + _s->hashed = NO; + _s->cString = [self resizeMemory: _s->cString + size: _s->cStringLength + + UTF8StringLength + 1]; + memcpy(_s->cString + _s->cStringLength, [string UTF8String], UTF8StringLength); - s->cStringLength += UTF8StringLength; - s->length += [string length]; + _s->cStringLength += UTF8StringLength; + _s->length += [string length]; - s->cString[s->cStringLength] = 0; + _s->cString[_s->cStringLength] = 0; if ([string isKindOfClass: [OFString_UTF8 class]] || [string isKindOfClass: [OFMutableString_UTF8 class]]) { - if (((OFString_UTF8*)string)->s->isUTF8) - s->isUTF8 = YES; + if (((OFString_UTF8*)string)->_s->isUTF8) + _s->isUTF8 = YES; } else - s->isUTF8 = YES; + _s->isUTF8 = YES; } - (void)appendCharacters: (of_unichar_t*)characters length: (size_t)length { @@ -435,20 +437,20 @@ } } tmp[j] = '\0'; - s->hashed = NO; - s->cString = [self resizeMemory: s->cString - size: s->cStringLength + j + 1]; - memcpy(s->cString + s->cStringLength, tmp, j + 1); + _s->hashed = NO; + _s->cString = [self resizeMemory: _s->cString + size: _s->cStringLength + j + 1]; + memcpy(_s->cString + _s->cStringLength, tmp, j + 1); - s->cStringLength += j; - s->length += length; + _s->cStringLength += j; + _s->length += length; if (isUTF8) - s->isUTF8 = YES; + _s->isUTF8 = YES; } @finally { [self freeMemory: tmp]; } } @@ -478,80 +480,80 @@ - (void)reverse { size_t i, j; - s->hashed = NO; + _s->hashed = NO; /* We reverse all bytes and restore UTF-8 later, if necessary */ - for (i = 0, j = s->cStringLength - 1; i < s->cStringLength / 2; + for (i = 0, j = _s->cStringLength - 1; i < _s->cStringLength / 2; i++, j--) { - s->cString[i] ^= s->cString[j]; - s->cString[j] ^= s->cString[i]; - s->cString[i] ^= s->cString[j]; + _s->cString[i] ^= _s->cString[j]; + _s->cString[j] ^= _s->cString[i]; + _s->cString[i] ^= _s->cString[j]; } - if (!s->isUTF8) + if (!_s->isUTF8) return; - for (i = 0; i < s->cStringLength; i++) { + for (i = 0; i < _s->cStringLength; i++) { /* ASCII */ - if OF_LIKELY (!(s->cString[i] & 0x80)) + if OF_LIKELY (!(_s->cString[i] & 0x80)) continue; /* A start byte can't happen first as we reversed everything */ - if OF_UNLIKELY (s->cString[i] & 0x40) + if OF_UNLIKELY (_s->cString[i] & 0x40) @throw [OFInvalidEncodingException exceptionWithClass: [self class]]; /* Next byte must not be ASCII */ - if OF_UNLIKELY (s->cStringLength < i + 1 || - !(s->cString[i + 1] & 0x80)) + if OF_UNLIKELY (_s->cStringLength < i + 1 || + !(_s->cString[i + 1] & 0x80)) @throw [OFInvalidEncodingException exceptionWithClass: [self class]]; /* Next byte is the start byte */ - if OF_LIKELY (s->cString[i + 1] & 0x40) { - s->cString[i] ^= s->cString[i + 1]; - s->cString[i + 1] ^= s->cString[i]; - s->cString[i] ^= s->cString[i + 1]; + if OF_LIKELY (_s->cString[i + 1] & 0x40) { + _s->cString[i] ^= _s->cString[i + 1]; + _s->cString[i + 1] ^= _s->cString[i]; + _s->cString[i] ^= _s->cString[i + 1]; i++; continue; } /* Second next byte must not be ASCII */ - if OF_UNLIKELY (s->cStringLength < i + 2 || - !(s->cString[i + 2] & 0x80)) + if OF_UNLIKELY (_s->cStringLength < i + 2 || + !(_s->cString[i + 2] & 0x80)) @throw [OFInvalidEncodingException exceptionWithClass: [self class]]; /* Second next byte is the start byte */ - if OF_LIKELY (s->cString[i + 2] & 0x40) { - s->cString[i] ^= s->cString[i + 2]; - s->cString[i + 2] ^= s->cString[i]; - s->cString[i] ^= s->cString[i + 2]; + if OF_LIKELY (_s->cString[i + 2] & 0x40) { + _s->cString[i] ^= _s->cString[i + 2]; + _s->cString[i + 2] ^= _s->cString[i]; + _s->cString[i] ^= _s->cString[i + 2]; i += 2; continue; } /* Third next byte must not be ASCII */ - if OF_UNLIKELY (s->cStringLength < i + 3 || - !(s->cString[i + 3] & 0x80)) + if OF_UNLIKELY (_s->cStringLength < i + 3 || + !(_s->cString[i + 3] & 0x80)) @throw [OFInvalidEncodingException exceptionWithClass: [self class]]; /* Third next byte is the start byte */ - if OF_LIKELY (s->cString[i + 3] & 0x40) { - s->cString[i] ^= s->cString[i + 3]; - s->cString[i + 3] ^= s->cString[i]; - s->cString[i] ^= s->cString[i + 3]; - - s->cString[i + 1] ^= s->cString[i + 2]; - s->cString[i + 2] ^= s->cString[i + 1]; - s->cString[i + 1] ^= s->cString[i + 2]; + if OF_LIKELY (_s->cString[i + 3] & 0x40) { + _s->cString[i] ^= _s->cString[i + 3]; + _s->cString[i + 3] ^= _s->cString[i]; + _s->cString[i] ^= _s->cString[i + 3]; + + _s->cString[i + 1] ^= _s->cString[i + 2]; + _s->cString[i + 2] ^= _s->cString[i + 1]; + _s->cString[i + 1] ^= _s->cString[i + 2]; i += 3; continue; } @@ -564,64 +566,65 @@ - (void)insertString: (OFString*)string atIndex: (size_t)index { size_t newCStringLength; - if (index > s->length) + if (index > _s->length) @throw [OFOutOfRangeException exceptionWithClass: [self class]]; - if (s->isUTF8) - index = of_string_utf8_get_position(s->cString, index, - s->cStringLength); - - newCStringLength = s->cStringLength + [string UTF8StringLength]; - s->hashed = NO; - s->cString = [self resizeMemory: s->cString - size: newCStringLength + 1]; - - memmove(s->cString + index + [string UTF8StringLength], - s->cString + index, s->cStringLength - index); - memcpy(s->cString + index, [string UTF8String], + if (_s->isUTF8) + index = of_string_utf8_get_position(_s->cString, index, + _s->cStringLength); + + newCStringLength = _s->cStringLength + [string UTF8StringLength]; + _s->hashed = NO; + _s->cString = [self resizeMemory: _s->cString + size: newCStringLength + 1]; + + memmove(_s->cString + index + [string UTF8StringLength], + _s->cString + index, _s->cStringLength - index); + memcpy(_s->cString + index, [string UTF8String], [string UTF8StringLength]); - s->cString[newCStringLength] = '\0'; + _s->cString[newCStringLength] = '\0'; - s->cStringLength = newCStringLength; - s->length += [string length]; + _s->cStringLength = newCStringLength; + _s->length += [string length]; if ([string isKindOfClass: [OFString_UTF8 class]] || [string isKindOfClass: [OFMutableString_UTF8 class]]) { - if (((OFString_UTF8*)string)->s->isUTF8) - s->isUTF8 = YES; + if (((OFString_UTF8*)string)->_s->isUTF8) + _s->isUTF8 = YES; } else - s->isUTF8 = YES; + _s->isUTF8 = YES; } - (void)deleteCharactersInRange: (of_range_t)range { size_t start = range.location; size_t end = range.location + range.length; - if (range.length > SIZE_MAX - range.location || end > s->length) + if (range.length > SIZE_MAX - range.location || end > _s->length) @throw [OFOutOfRangeException exceptionWithClass: [self class]]; - if (s->isUTF8) { - start = of_string_utf8_get_position(s->cString, start, - s->cStringLength); - end = of_string_utf8_get_position(s->cString, end, - s->cStringLength); + if (_s->isUTF8) { + start = of_string_utf8_get_position(_s->cString, start, + _s->cStringLength); + end = of_string_utf8_get_position(_s->cString, end, + _s->cStringLength); } - memmove(s->cString + start, s->cString + end, s->cStringLength - end); - s->hashed = NO; - s->length -= range.length; - s->cStringLength -= end - start; - s->cString[s->cStringLength] = 0; + memmove(_s->cString + start, _s->cString + end, + _s->cStringLength - end); + _s->hashed = NO; + _s->length -= range.length; + _s->cStringLength -= end - start; + _s->cString[_s->cStringLength] = 0; @try { - s->cString = [self resizeMemory: s->cString - size: s->cStringLength + 1]; + _s->cString = [self resizeMemory: _s->cString + size: _s->cStringLength + 1]; } @catch (OFOutOfMemoryException *e) { /* We don't really care, as we only made it smaller */ } } @@ -630,36 +633,36 @@ { size_t start = range.location; size_t end = range.location + range.length; size_t newCStringLength, newLength; - if (range.length > SIZE_MAX - range.location || end > s->length) + if (range.length > SIZE_MAX - range.location || end > _s->length) @throw [OFOutOfRangeException exceptionWithClass: [self class]]; - newLength = s->length - range.length + [replacement length]; + newLength = _s->length - range.length + [replacement length]; - if (s->isUTF8) { - start = of_string_utf8_get_position(s->cString, start, - s->cStringLength); - end = of_string_utf8_get_position(s->cString, end, - s->cStringLength); + if (_s->isUTF8) { + start = of_string_utf8_get_position(_s->cString, start, + _s->cStringLength); + end = of_string_utf8_get_position(_s->cString, end, + _s->cStringLength); } - newCStringLength = s->cStringLength - (end - start) + + newCStringLength = _s->cStringLength - (end - start) + [replacement UTF8StringLength]; - s->hashed = NO; - s->cString = [self resizeMemory: s->cString - size: newCStringLength + 1]; + _s->hashed = NO; + _s->cString = [self resizeMemory: _s->cString + size: newCStringLength + 1]; - memmove(s->cString + start + [replacement UTF8StringLength], - s->cString + end, s->cStringLength - end); - memcpy(s->cString + start, [replacement UTF8String], + memmove(_s->cString + start + [replacement UTF8StringLength], + _s->cString + end, _s->cStringLength - end); + memcpy(_s->cString + start, [replacement UTF8String], [replacement UTF8StringLength]); - s->cString[newCStringLength] = '\0'; + _s->cString[newCStringLength] = '\0'; - s->cStringLength = newCStringLength; - s->length = newLength; + _s->cStringLength = newCStringLength; + _s->length = newLength; } - (void)replaceOccurrencesOfString: (OFString*)string withString: (OFString*)replacement options: (int)options @@ -674,28 +677,28 @@ if (range.length > SIZE_MAX - range.location || range.location + range.length > [self length]) @throw [OFOutOfRangeException exceptionWithClass: [self class]]; - if (s->isUTF8) { - range.location = of_string_utf8_get_position(s->cString, - range.location, s->cStringLength); + if (_s->isUTF8) { + range.location = of_string_utf8_get_position(_s->cString, + range.location, _s->cStringLength); range.length = of_string_utf8_get_position( - s->cString + range.location, range.length, - s->cStringLength - range.location); + _s->cString + range.location, range.length, + _s->cStringLength - range.location); } if ([string UTF8StringLength] > range.length) return; newCString = NULL; newCStringLength = 0; - newLength = s->length; + newLength = _s->length; last = 0; for (i = range.location; i <= range.length - searchLength; i++) { - if (memcmp(s->cString + i, searchString, searchLength)) + if (memcmp(_s->cString + i, searchString, searchLength)) continue; @try { newCString = [self resizeMemory: newCString @@ -703,11 +706,11 @@ replacementLength + 1]; } @catch (id e) { [self freeMemory: newCString]; @throw e; } - memcpy(newCString + newCStringLength, s->cString + last, + memcpy(newCString + newCStringLength, _s->cString + last, i - last); memcpy(newCString + newCStringLength + i - last, replacementString, replacementLength); newCStringLength += i - last + replacementLength; @@ -718,47 +721,47 @@ } @try { newCString = [self resizeMemory: newCString size: newCStringLength + - s->cStringLength - last + 1]; + _s->cStringLength - last + 1]; } @catch (id e) { [self freeMemory: newCString]; @throw e; } - memcpy(newCString + newCStringLength, s->cString + last, - s->cStringLength - last); - newCStringLength += s->cStringLength - last; + memcpy(newCString + newCStringLength, _s->cString + last, + _s->cStringLength - last); + newCStringLength += _s->cStringLength - last; newCString[newCStringLength] = 0; - [self freeMemory: s->cString]; - s->hashed = NO; - s->cString = newCString; - s->cStringLength = newCStringLength; - s->length = newLength; + [self freeMemory: _s->cString]; + _s->hashed = NO; + _s->cString = newCString; + _s->cStringLength = newCStringLength; + _s->length = newLength; } - (void)deleteLeadingWhitespaces { size_t i; - for (i = 0; i < s->cStringLength; i++) - if (s->cString[i] != ' ' && s->cString[i] != '\t' && - s->cString[i] != '\n' && s->cString[i] != '\r' && - s->cString[i] != '\f') + for (i = 0; i < _s->cStringLength; i++) + if (_s->cString[i] != ' ' && _s->cString[i] != '\t' && + _s->cString[i] != '\n' && _s->cString[i] != '\r' && + _s->cString[i] != '\f') break; - s->hashed = NO; - s->cStringLength -= i; - s->length -= i; + _s->hashed = NO; + _s->cStringLength -= i; + _s->length -= i; - memmove(s->cString, s->cString + i, s->cStringLength); - s->cString[s->cStringLength] = '\0'; + memmove(_s->cString, _s->cString + i, _s->cStringLength); + _s->cString[_s->cStringLength] = '\0'; @try { - s->cString = [self resizeMemory: s->cString - size: s->cStringLength + 1]; + _s->cString = [self resizeMemory: _s->cString + size: _s->cStringLength + 1]; } @catch (OFOutOfMemoryException *e) { /* We don't really care, as we only made it smaller */ } } @@ -765,28 +768,28 @@ - (void)deleteTrailingWhitespaces { size_t d; char *p; - s->hashed = NO; + _s->hashed = NO; d = 0; - for (p = s->cString + s->cStringLength - 1; p >= s->cString; p--) { + for (p = _s->cString + _s->cStringLength - 1; p >= _s->cString; p--) { if (*p != ' ' && *p != '\t' && *p != '\n' && *p != '\r' && *p != '\f') break; *p = '\0'; d++; } - s->cStringLength -= d; - s->length -= d; + _s->cStringLength -= d; + _s->length -= d; @try { - s->cString = [self resizeMemory: s->cString - size: s->cStringLength + 1]; + _s->cString = [self resizeMemory: _s->cString + size: _s->cStringLength + 1]; } @catch (OFOutOfMemoryException *e) { /* We don't really care, as we only made it smaller */ } } @@ -793,40 +796,40 @@ - (void)deleteEnclosingWhitespaces { size_t d, i; char *p; - s->hashed = NO; + _s->hashed = NO; d = 0; - for (p = s->cString + s->cStringLength - 1; p >= s->cString; p--) { + for (p = _s->cString + _s->cStringLength - 1; p >= _s->cString; p--) { if (*p != ' ' && *p != '\t' && *p != '\n' && *p != '\r' && *p != '\f') break; *p = '\0'; d++; } - s->cStringLength -= d; - s->length -= d; + _s->cStringLength -= d; + _s->length -= d; - for (i = 0; i < s->cStringLength; i++) - if (s->cString[i] != ' ' && s->cString[i] != '\t' && - s->cString[i] != '\n' && s->cString[i] != '\r' && - s->cString[i] != '\f') + for (i = 0; i < _s->cStringLength; i++) + if (_s->cString[i] != ' ' && _s->cString[i] != '\t' && + _s->cString[i] != '\n' && _s->cString[i] != '\r' && + _s->cString[i] != '\f') break; - s->cStringLength -= i; - s->length -= i; + _s->cStringLength -= i; + _s->length -= i; - memmove(s->cString, s->cString + i, s->cStringLength); - s->cString[s->cStringLength] = '\0'; + memmove(_s->cString, _s->cString + i, _s->cStringLength); + _s->cString[_s->cStringLength] = '\0'; @try { - s->cString = [self resizeMemory: s->cString - size: s->cStringLength + 1]; + _s->cString = [self resizeMemory: _s->cString + size: _s->cStringLength + 1]; } @catch (OFOutOfMemoryException *e) { /* We don't really care, as we only made it smaller */ } } Index: src/OFMutex.h ================================================================== --- src/OFMutex.h +++ src/OFMutex.h @@ -22,17 +22,17 @@ /*! * @brief A class for creating mutual exclusions. */ @interface OFMutex: OFObject { - of_mutex_t mutex; - BOOL initialized; - OFString *name; + of_mutex_t _mutex; + BOOL _initialized; + OFString *_name; } /*! * @brief Creates a new mutex. * * @return A new autoreleased mutex. */ + (instancetype)mutex; @end Index: src/OFMutex.m ================================================================== --- src/OFMutex.m +++ src/OFMutex.m @@ -34,66 +34,67 @@ - init { self = [super init]; - if (!of_mutex_new(&mutex)) { + if (!of_mutex_new(&_mutex)) { Class c = [self class]; [self release]; @throw [OFInitializationFailedException exceptionWithClass: c]; } - initialized = YES; + _initialized = YES; return self; } - (void)lock { - if (!of_mutex_lock(&mutex)) + if (!of_mutex_lock(&_mutex)) @throw [OFLockFailedException exceptionWithClass: [self class] lock: self]; } - (BOOL)tryLock { - return of_mutex_trylock(&mutex); + return of_mutex_trylock(&_mutex); } - (void)unlock { - if (!of_mutex_unlock(&mutex)) + if (!of_mutex_unlock(&_mutex)) @throw [OFUnlockFailedException exceptionWithClass: [self class] lock: self]; } -- (void)setName: (OFString*)name_ +- (void)setName: (OFString*)name { - OF_SETTER(name, name_, YES, 1) + OF_SETTER(_name, name, YES, 1) } - (OFString*)name { - OF_GETTER(name, YES) + OF_GETTER(_name, YES) } - (OFString*)description { - if (name == nil) + if (_name == nil) return [super description]; - return [OFString stringWithFormat: @"<%@: %@>", [self className], name]; + return [OFString stringWithFormat: @"<%@: %@>", + [self className], _name]; } - (void)dealloc { - if (initialized) - if (!of_mutex_free(&mutex)) + if (_initialized) + if (!of_mutex_free(&_mutex)) @throw [OFStillLockedException exceptionWithClass: [self class] lock: self]; - [name release]; + [_name release]; [super dealloc]; } @end Index: src/OFNumber.h ================================================================== --- src/OFNumber.h +++ src/OFNumber.h @@ -94,14 +94,14 @@ @interface OFNumber: OFObject { union of_number_value { BOOL bool_; - signed char char_; - signed short short_; - signed int int_; - signed long long_; + signed char schar; + signed short sshort; + signed int sint; + signed long slong; unsigned char uchar; unsigned short ushort; unsigned int uint; unsigned long ulong; int8_t int8; @@ -119,12 +119,12 @@ ptrdiff_t ptrdiff; intptr_t intptr; uintptr_t uintptr; float float_; double double_; - } value; - of_number_type_t type; + } _value; + of_number_type_t _type; } #ifdef OF_HAVE_PROPERTIES @property (readonly) of_number_type_t type; #endif @@ -138,38 +138,38 @@ + (instancetype)numberWithBool: (BOOL)bool_; /*! * @brief Creates a new OFNumber with the specified signed char. * - * @param char_ A signed char which the OFNumber should contain + * @param schar A signed char which the OFNumber should contain * @return A new autoreleased OFNumber */ -+ (instancetype)numberWithChar: (signed char)char_; ++ (instancetype)numberWithChar: (signed char)schar; /*! * @brief Creates a new OFNumber with the specified signed short. * - * @param short_ A signed short which the OFNumber should contain + * @param sshort A signed short which the OFNumber should contain * @return A new autoreleased OFNumber */ -+ (instancetype)numberWithShort: (signed short)short_; ++ (instancetype)numberWithShort: (signed short)sshort; /*! * @brief Creates a new OFNumber with the specified signed int. * - * @param int_ A signed int which the OFNumber should contain + * @param sint A signed int which the OFNumber should contain * @return A new autoreleased OFNumber */ -+ (instancetype)numberWithInt: (signed int)int_; ++ (instancetype)numberWithInt: (signed int)sint; /*! * @brief Creates a new OFNumber with the specified signed long. * - * @param long_ A signed long which the OFNumber should contain + * @param slong A signed long which the OFNumber should contain * @return A new autoreleased OFNumber */ -+ (instancetype)numberWithLong: (signed long)long_; ++ (instancetype)numberWithLong: (signed long)slong; /*! * @brief Creates a new OFNumber with the specified unsigned char. * * @param uchar An unsigned char which the OFNumber should contain @@ -347,41 +347,41 @@ /*! * @brief Initializes an already allocated OFNumber with the specified signed * char. * - * @param char_ A signed char which the OFNumber should contain + * @param schar A signed char which the OFNumber should contain * @return An initialized OFNumber */ -- initWithChar: (signed char)char_; +- initWithChar: (signed char)schar; /*! * @brief Initializes an already allocated OFNumber with the specified signed * short. * - * @param short_ A signed short which the OFNumber should contain + * @param sshort A signed short which the OFNumber should contain * @return An initialized OFNumber */ -- initWithShort: (signed short)short_; +- initWithShort: (signed short)sshort; /*! * @brief Initializes an already allocated OFNumber with the specified signed * int. * - * @param int_ A signed int which the OFNumber should contain + * @param sint A signed int which the OFNumber should contain * @return An initialized OFNumber */ -- initWithInt: (signed int)int_; +- initWithInt: (signed int)sint; /*! * @brief Initializes an already allocated OFNumber with the specified signed * long. * - * @param long_ A signed long which the OFNumber should contain + * @param slong A signed long which the OFNumber should contain * @return An initialized OFNumber */ -- initWithLong: (signed long)long_; +- initWithLong: (signed long)slong; /*! * @brief Initializes an already allocated OFNumber with the specified unsigned * char. * Index: src/OFNumber.m ================================================================== --- src/OFNumber.m +++ src/OFNumber.m @@ -30,225 +30,225 @@ #import "autorelease.h" #import "macros.h" #define RETURN_AS(t) \ - switch (type) { \ + switch (_type) { \ case OF_NUMBER_BOOL: \ - return (t)value.bool_; \ + return (t)_value.bool_; \ case OF_NUMBER_CHAR: \ - return (t)value.char_; \ + return (t)_value.schar; \ case OF_NUMBER_SHORT: \ - return (t)value.short_; \ + return (t)_value.sshort; \ case OF_NUMBER_INT: \ - return (t)value.int_; \ + return (t)_value.sint; \ case OF_NUMBER_LONG: \ - return (t)value.long_; \ + return (t)_value.slong; \ case OF_NUMBER_UCHAR: \ - return (t)value.uchar; \ + return (t)_value.uchar; \ case OF_NUMBER_USHORT: \ - return (t)value.ushort; \ + return (t)_value.ushort; \ case OF_NUMBER_UINT: \ - return (t)value.uint; \ + return (t)_value.uint; \ case OF_NUMBER_ULONG: \ - return (t)value.ulong; \ + return (t)_value.ulong; \ case OF_NUMBER_INT8: \ - return (t)value.int8; \ + return (t)_value.int8; \ case OF_NUMBER_INT16: \ - return (t)value.int16; \ + return (t)_value.int16; \ case OF_NUMBER_INT32: \ - return (t)value.int32; \ + return (t)_value.int32; \ case OF_NUMBER_INT64: \ - return (t)value.int64; \ + return (t)_value.int64; \ case OF_NUMBER_UINT8: \ - return (t)value.uint8; \ + return (t)_value.uint8; \ case OF_NUMBER_UINT16: \ - return (t)value.uint16; \ + return (t)_value.uint16; \ case OF_NUMBER_UINT32: \ - return (t)value.uint32; \ + return (t)_value.uint32; \ case OF_NUMBER_UINT64: \ - return (t)value.uint64; \ + return (t)_value.uint64; \ case OF_NUMBER_SIZE: \ - return (t)value.size; \ + return (t)_value.size; \ case OF_NUMBER_SSIZE: \ - return (t)value.ssize; \ + return (t)_value.ssize; \ case OF_NUMBER_INTMAX: \ - return (t)value.intmax; \ + return (t)_value.intmax; \ case OF_NUMBER_UINTMAX: \ - return (t)value.uintmax; \ + return (t)_value.uintmax; \ case OF_NUMBER_PTRDIFF: \ - return (t)value.ptrdiff; \ + return (t)_value.ptrdiff; \ case OF_NUMBER_INTPTR: \ - return (t)value.intptr; \ + return (t)_value.intptr; \ case OF_NUMBER_UINTPTR: \ - return (t)value.uintptr; \ + return (t)_value.uintptr; \ case OF_NUMBER_FLOAT: \ - return (t)value.float_; \ + return (t)_value.float_; \ case OF_NUMBER_DOUBLE: \ - return (t)value.double_; \ + return (t)_value.double_; \ default: \ @throw [OFInvalidFormatException \ exceptionWithClass: [self class]]; \ } #define CALCULATE(o, n) \ - switch (type) { \ + switch (_type) { \ case OF_NUMBER_BOOL: \ return [OFNumber numberWithBool: \ - value.bool_ o [n boolValue]]; \ + _value.bool_ o [n boolValue]]; \ case OF_NUMBER_CHAR: \ return [OFNumber numberWithChar: \ - value.char_ o [n charValue]]; \ + _value.schar o [n charValue]]; \ case OF_NUMBER_SHORT: \ return [OFNumber numberWithShort: \ - value.short_ o [n shortValue]]; \ + _value.sshort o [n shortValue]]; \ case OF_NUMBER_INT: \ return [OFNumber numberWithInt: \ - value.int_ o [n intValue]]; \ + _value.sint o [n intValue]]; \ case OF_NUMBER_LONG: \ return [OFNumber numberWithLong: \ - value.long_ o [n longValue]]; \ + _value.slong o [n longValue]]; \ case OF_NUMBER_UCHAR: \ return [OFNumber numberWithUnsignedChar: \ - value.uchar o [n unsignedCharValue]]; \ + _value.uchar o [n unsignedCharValue]]; \ case OF_NUMBER_USHORT: \ return [OFNumber numberWithUnsignedShort: \ - value.ushort o [n unsignedShortValue]]; \ + _value.ushort o [n unsignedShortValue]]; \ case OF_NUMBER_UINT: \ return [OFNumber numberWithUnsignedInt: \ - value.uint o [n unsignedIntValue]]; \ + _value.uint o [n unsignedIntValue]]; \ case OF_NUMBER_ULONG: \ return [OFNumber numberWithUnsignedLong: \ - value.ulong o [n unsignedLongValue]]; \ + _value.ulong o [n unsignedLongValue]]; \ case OF_NUMBER_INT8: \ return [OFNumber numberWithInt8: \ - value.int8 o [n int8Value]]; \ + _value.int8 o [n int8Value]]; \ case OF_NUMBER_INT16: \ return [OFNumber numberWithInt16: \ - value.int16 o [n int16Value]]; \ + _value.int16 o [n int16Value]]; \ case OF_NUMBER_INT32: \ return [OFNumber numberWithInt32: \ - value.int32 o [n int32Value]]; \ + _value.int32 o [n int32Value]]; \ case OF_NUMBER_INT64: \ return [OFNumber numberWithInt64: \ - value.int64 o [n int64Value]]; \ + _value.int64 o [n int64Value]]; \ case OF_NUMBER_UINT8: \ return [OFNumber numberWithUInt8: \ - value.uint8 o [n uInt8Value]]; \ + _value.uint8 o [n uInt8Value]]; \ case OF_NUMBER_UINT16: \ return [OFNumber numberWithUInt16: \ - value.uint16 o [n uInt16Value]]; \ + _value.uint16 o [n uInt16Value]]; \ case OF_NUMBER_UINT32: \ return [OFNumber numberWithUInt32: \ - value.uint32 o [n uInt32Value]]; \ + _value.uint32 o [n uInt32Value]]; \ case OF_NUMBER_UINT64: \ return [OFNumber numberWithUInt64: \ - value.uint64 o [n uInt64Value]]; \ + _value.uint64 o [n uInt64Value]]; \ case OF_NUMBER_SIZE: \ return [OFNumber numberWithSize: \ - value.size o [n sizeValue]]; \ + _value.size o [n sizeValue]]; \ case OF_NUMBER_SSIZE: \ return [OFNumber numberWithSSize: \ - value.ssize o [n sSizeValue]]; \ + _value.ssize o [n sSizeValue]]; \ case OF_NUMBER_INTMAX: \ return [OFNumber numberWithIntMax: \ - value.intmax o [n intMaxValue]]; \ + _value.intmax o [n intMaxValue]]; \ case OF_NUMBER_UINTMAX: \ return [OFNumber numberWithUIntMax: \ - value.uintmax o [n uIntMaxValue]]; \ + _value.uintmax o [n uIntMaxValue]]; \ case OF_NUMBER_PTRDIFF: \ return [OFNumber numberWithPtrDiff: \ - value.ptrdiff o [n ptrDiffValue]]; \ + _value.ptrdiff o [n ptrDiffValue]]; \ case OF_NUMBER_INTPTR: \ return [OFNumber numberWithIntPtr: \ - value.intptr o [n intPtrValue]]; \ + _value.intptr o [n intPtrValue]]; \ case OF_NUMBER_UINTPTR: \ return [OFNumber numberWithUIntPtr: \ - value.uintptr o [n uIntPtrValue]]; \ + _value.uintptr o [n uIntPtrValue]]; \ case OF_NUMBER_FLOAT: \ return [OFNumber numberWithFloat: \ - value.float_ o [n floatValue]]; \ + _value.float_ o [n floatValue]]; \ case OF_NUMBER_DOUBLE: \ return [OFNumber numberWithDouble: \ - value.double_ o [n doubleValue]]; \ + _value.double_ o [n doubleValue]]; \ default: \ @throw [OFInvalidFormatException \ exceptionWithClass: [self class]]; \ } #define CALCULATE2(o, n) \ - switch (type) { \ + switch (_type) { \ case OF_NUMBER_BOOL: \ return [OFNumber numberWithBool: \ - value.bool_ o [n boolValue]]; \ + _value.bool_ o [n boolValue]]; \ case OF_NUMBER_CHAR: \ return [OFNumber numberWithChar: \ - value.char_ o [n charValue]]; \ + _value.schar o [n charValue]]; \ case OF_NUMBER_SHORT: \ return [OFNumber numberWithShort: \ - value.short_ o [n shortValue]]; \ + _value.sshort o [n shortValue]]; \ case OF_NUMBER_INT: \ return [OFNumber numberWithInt: \ - value.int_ o [n intValue]]; \ + _value.sint o [n intValue]]; \ case OF_NUMBER_LONG: \ return [OFNumber numberWithLong: \ - value.long_ o [n longValue]]; \ + _value.slong o [n longValue]]; \ case OF_NUMBER_UCHAR: \ return [OFNumber numberWithUnsignedChar: \ - value.uchar o [n unsignedCharValue]]; \ + _value.uchar o [n unsignedCharValue]]; \ case OF_NUMBER_USHORT: \ return [OFNumber numberWithUnsignedShort: \ - value.ushort o [n unsignedShortValue]]; \ + _value.ushort o [n unsignedShortValue]]; \ case OF_NUMBER_UINT: \ return [OFNumber numberWithUnsignedInt: \ - value.uint o [n unsignedIntValue]]; \ + _value.uint o [n unsignedIntValue]]; \ case OF_NUMBER_ULONG: \ return [OFNumber numberWithUnsignedLong: \ - value.ulong o [n unsignedLongValue]]; \ + _value.ulong o [n unsignedLongValue]]; \ case OF_NUMBER_INT8: \ return [OFNumber numberWithInt8: \ - value.int8 o [n int8Value]]; \ + _value.int8 o [n int8Value]]; \ case OF_NUMBER_INT16: \ return [OFNumber numberWithInt16: \ - value.int16 o [n int16Value]]; \ + _value.int16 o [n int16Value]]; \ case OF_NUMBER_INT32: \ return [OFNumber numberWithInt32: \ - value.int32 o [n int32Value]]; \ + _value.int32 o [n int32Value]]; \ case OF_NUMBER_INT64: \ return [OFNumber numberWithInt64: \ - value.int64 o [n int64Value]]; \ + _value.int64 o [n int64Value]]; \ case OF_NUMBER_UINT8: \ return [OFNumber numberWithUInt8: \ - value.uint8 o [n uInt8Value]]; \ + _value.uint8 o [n uInt8Value]]; \ case OF_NUMBER_UINT16: \ return [OFNumber numberWithUInt16: \ - value.uint16 o [n uInt16Value]]; \ + _value.uint16 o [n uInt16Value]]; \ case OF_NUMBER_UINT32: \ return [OFNumber numberWithUInt32: \ - value.uint32 o [n uInt32Value]]; \ + _value.uint32 o [n uInt32Value]]; \ case OF_NUMBER_UINT64: \ return [OFNumber numberWithUInt64: \ - value.uint64 o [n uInt64Value]]; \ + _value.uint64 o [n uInt64Value]]; \ case OF_NUMBER_SIZE: \ return [OFNumber numberWithSize: \ - value.size o [n sizeValue]]; \ + _value.size o [n sizeValue]]; \ case OF_NUMBER_SSIZE: \ return [OFNumber numberWithSSize: \ - value.ssize o [n sSizeValue]]; \ + _value.ssize o [n sSizeValue]]; \ case OF_NUMBER_INTMAX: \ return [OFNumber numberWithIntMax: \ - value.intmax o [n intMaxValue]]; \ + _value.intmax o [n intMaxValue]]; \ case OF_NUMBER_UINTMAX: \ return [OFNumber numberWithUIntMax: \ - value.uintmax o [n uIntMaxValue]]; \ + _value.uintmax o [n uIntMaxValue]]; \ case OF_NUMBER_PTRDIFF: \ return [OFNumber numberWithPtrDiff: \ - value.ptrdiff o [n ptrDiffValue]]; \ + _value.ptrdiff o [n ptrDiffValue]]; \ case OF_NUMBER_INTPTR: \ return [OFNumber numberWithIntPtr: \ - value.intptr o [n intPtrValue]]; \ + _value.intptr o [n intPtrValue]]; \ case OF_NUMBER_UINTPTR: \ return [OFNumber numberWithUIntPtr: \ - value.uintptr o [n uIntPtrValue]]; \ + _value.uintptr o [n uIntPtrValue]]; \ case OF_NUMBER_FLOAT: \ case OF_NUMBER_DOUBLE: \ @throw [OFInvalidArgumentException \ exceptionWithClass: [self class] \ selector: _cmd]; \ @@ -255,66 +255,66 @@ default: \ @throw [OFInvalidFormatException \ exceptionWithClass: [self class]]; \ } #define CALCULATE3(o) \ - switch (type) { \ + switch (_type) { \ case OF_NUMBER_BOOL: \ - return [OFNumber numberWithBool: value.bool_ o]; \ + return [OFNumber numberWithBool: _value.bool_ o]; \ case OF_NUMBER_CHAR: \ - return [OFNumber numberWithChar: value.char_ o]; \ + return [OFNumber numberWithChar: _value.schar o]; \ case OF_NUMBER_SHORT: \ - return [OFNumber numberWithShort: value.short_ o]; \ + return [OFNumber numberWithShort: _value.sshort o]; \ case OF_NUMBER_INT: \ - return [OFNumber numberWithInt: value.int_ o]; \ + return [OFNumber numberWithInt: _value.sint o]; \ case OF_NUMBER_LONG: \ - return [OFNumber numberWithLong: value.long_ o]; \ + return [OFNumber numberWithLong: _value.slong o]; \ case OF_NUMBER_UCHAR: \ return [OFNumber numberWithUnsignedChar: \ - value.uchar o]; \ + _value.uchar o]; \ case OF_NUMBER_USHORT: \ return [OFNumber numberWithUnsignedShort: \ - value.ushort o]; \ + _value.ushort o]; \ case OF_NUMBER_UINT: \ - return [OFNumber numberWithUnsignedInt: value.uint o]; \ + return [OFNumber numberWithUnsignedInt: _value.uint o]; \ case OF_NUMBER_ULONG: \ return [OFNumber numberWithUnsignedLong: \ - value.ulong o]; \ + _value.ulong o]; \ case OF_NUMBER_INT8: \ - return [OFNumber numberWithInt8: value.int8 o]; \ + return [OFNumber numberWithInt8: _value.int8 o]; \ case OF_NUMBER_INT16: \ - return [OFNumber numberWithInt16: value.int16 o]; \ + return [OFNumber numberWithInt16: _value.int16 o]; \ case OF_NUMBER_INT32: \ - return [OFNumber numberWithInt32: value.int32 o]; \ + return [OFNumber numberWithInt32: _value.int32 o]; \ case OF_NUMBER_INT64: \ - return [OFNumber numberWithInt64: value.int64 o]; \ + return [OFNumber numberWithInt64: _value.int64 o]; \ case OF_NUMBER_UINT8: \ - return [OFNumber numberWithUInt8: value.uint8 o]; \ + return [OFNumber numberWithUInt8: _value.uint8 o]; \ case OF_NUMBER_UINT16: \ - return [OFNumber numberWithUInt16: value.uint16 o]; \ + return [OFNumber numberWithUInt16: _value.uint16 o]; \ case OF_NUMBER_UINT32: \ - return [OFNumber numberWithUInt32: value.uint32 o]; \ + return [OFNumber numberWithUInt32: _value.uint32 o]; \ case OF_NUMBER_UINT64: \ - return [OFNumber numberWithUInt64: value.uint64 o]; \ + return [OFNumber numberWithUInt64: _value.uint64 o]; \ case OF_NUMBER_SIZE: \ - return [OFNumber numberWithSize: value.size o]; \ + return [OFNumber numberWithSize: _value.size o]; \ case OF_NUMBER_SSIZE: \ - return [OFNumber numberWithSSize: value.ssize o]; \ + return [OFNumber numberWithSSize: _value.ssize o]; \ case OF_NUMBER_INTMAX: \ - return [OFNumber numberWithIntMax: value.intmax o]; \ + return [OFNumber numberWithIntMax: _value.intmax o]; \ case OF_NUMBER_UINTMAX: \ - return [OFNumber numberWithUIntMax: value.uintmax o]; \ + return [OFNumber numberWithUIntMax: _value.uintmax o]; \ case OF_NUMBER_PTRDIFF: \ - return [OFNumber numberWithPtrDiff: value.ptrdiff o]; \ + return [OFNumber numberWithPtrDiff: _value.ptrdiff o]; \ case OF_NUMBER_INTPTR: \ - return [OFNumber numberWithIntPtr: value.intptr o]; \ + return [OFNumber numberWithIntPtr: _value.intptr o]; \ case OF_NUMBER_UINTPTR: \ - return [OFNumber numberWithUIntPtr: value.uintptr o]; \ + return [OFNumber numberWithUIntPtr: _value.uintptr o]; \ case OF_NUMBER_FLOAT: \ - return [OFNumber numberWithFloat: value.float_ o]; \ + return [OFNumber numberWithFloat: _value.float_ o]; \ case OF_NUMBER_DOUBLE: \ - return [OFNumber numberWithDouble: value.double_ o]; \ + return [OFNumber numberWithDouble: _value.double_ o]; \ default: \ @throw [OFInvalidFormatException \ exceptionWithClass: [self class]]; \ } @@ -322,28 +322,28 @@ + (instancetype)numberWithBool: (BOOL)bool_ { return [[[self alloc] initWithBool: bool_] autorelease]; } -+ (instancetype)numberWithChar: (signed char)char_ -{ - return [[[self alloc] initWithChar: char_] autorelease]; -} - -+ (instancetype)numberWithShort: (signed short)short_ -{ - return [[[self alloc] initWithShort: short_] autorelease]; -} - -+ (instancetype)numberWithInt: (signed int)int_ -{ - return [[[self alloc] initWithInt: int_] autorelease]; -} - -+ (instancetype)numberWithLong: (signed long)long_ -{ - return [[[self alloc] initWithLong: long_] autorelease]; ++ (instancetype)numberWithChar: (signed char)schar +{ + return [[[self alloc] initWithChar: schar] autorelease]; +} + ++ (instancetype)numberWithShort: (signed short)sshort +{ + return [[[self alloc] initWithShort: sshort] autorelease]; +} + ++ (instancetype)numberWithInt: (signed int)sint +{ + return [[[self alloc] initWithInt: sint] autorelease]; +} + ++ (instancetype)numberWithLong: (signed long)slong +{ + return [[[self alloc] initWithLong: slong] autorelease]; } + (instancetype)numberWithUnsignedChar: (unsigned char)uchar { return [[[self alloc] initWithUnsignedChar: uchar] autorelease]; @@ -463,262 +463,262 @@ - initWithBool: (BOOL)bool_ { self = [super init]; - value.bool_ = (bool_ ? YES : NO); - type = OF_NUMBER_BOOL; - - return self; -} - -- initWithChar: (signed char)char_ -{ - self = [super init]; - - value.char_ = char_; - type = OF_NUMBER_CHAR; - - return self; -} - -- initWithShort: (signed short)short_ -{ - self = [super init]; - - value.short_ = short_; - type = OF_NUMBER_SHORT; - - return self; -} - -- initWithInt: (signed int)int_ -{ - self = [super init]; - - value.int_ = int_; - type = OF_NUMBER_INT; - - return self; -} - -- initWithLong: (signed long)long_ -{ - self = [super init]; - - value.long_ = long_; - type = OF_NUMBER_LONG; + _value.bool_ = (bool_ ? YES : NO); + _type = OF_NUMBER_BOOL; + + return self; +} + +- initWithChar: (signed char)schar +{ + self = [super init]; + + _value.schar = schar; + _type = OF_NUMBER_CHAR; + + return self; +} + +- initWithShort: (signed short)sshort +{ + self = [super init]; + + _value.sshort = sshort; + _type = OF_NUMBER_SHORT; + + return self; +} + +- initWithInt: (signed int)sint +{ + self = [super init]; + + _value.sint = sint; + _type = OF_NUMBER_INT; + + return self; +} + +- initWithLong: (signed long)slong +{ + self = [super init]; + + _value.slong = slong; + _type = OF_NUMBER_LONG; return self; } - initWithUnsignedChar: (unsigned char)uchar { self = [super init]; - value.uchar = uchar; - type = OF_NUMBER_UCHAR; + _value.uchar = uchar; + _type = OF_NUMBER_UCHAR; return self; } - initWithUnsignedShort: (unsigned short)ushort { self = [super init]; - value.ushort = ushort; - type = OF_NUMBER_USHORT; + _value.ushort = ushort; + _type = OF_NUMBER_USHORT; return self; } - initWithUnsignedInt: (unsigned int)uint { self = [super init]; - value.uint = uint; - type = OF_NUMBER_UINT; + _value.uint = uint; + _type = OF_NUMBER_UINT; return self; } - initWithUnsignedLong: (unsigned long)ulong { self = [super init]; - value.ulong = ulong; - type = OF_NUMBER_ULONG; + _value.ulong = ulong; + _type = OF_NUMBER_ULONG; return self; } - initWithInt8: (int8_t)int8 { self = [super init]; - value.int8 = int8; - type = OF_NUMBER_INT8; + _value.int8 = int8; + _type = OF_NUMBER_INT8; return self; } - initWithInt16: (int16_t)int16 { self = [super init]; - value.int16 = int16; - type = OF_NUMBER_INT16; + _value.int16 = int16; + _type = OF_NUMBER_INT16; return self; } - initWithInt32: (int32_t)int32 { self = [super init]; - value.int32 = int32; - type = OF_NUMBER_INT32; + _value.int32 = int32; + _type = OF_NUMBER_INT32; return self; } - initWithInt64: (int64_t)int64 { self = [super init]; - value.int64 = int64; - type = OF_NUMBER_INT64; + _value.int64 = int64; + _type = OF_NUMBER_INT64; return self; } - initWithUInt8: (uint8_t)uint8 { self = [super init]; - value.uint8 = uint8; - type = OF_NUMBER_UINT8; + _value.uint8 = uint8; + _type = OF_NUMBER_UINT8; return self; } - initWithUInt16: (uint16_t)uint16 { self = [super init]; - value.uint16 = uint16; - type = OF_NUMBER_UINT16; + _value.uint16 = uint16; + _type = OF_NUMBER_UINT16; return self; } - initWithUInt32: (uint32_t)uint32 { self = [super init]; - value.uint32 = uint32; - type = OF_NUMBER_UINT32; + _value.uint32 = uint32; + _type = OF_NUMBER_UINT32; return self; } - initWithUInt64: (uint64_t)uint64 { self = [super init]; - value.uint64 = uint64; - type = OF_NUMBER_UINT64; + _value.uint64 = uint64; + _type = OF_NUMBER_UINT64; return self; } - initWithSize: (size_t)size { self = [super init]; - value.size = size; - type = OF_NUMBER_SIZE; + _value.size = size; + _type = OF_NUMBER_SIZE; return self; } - initWithSSize: (ssize_t)ssize { self = [super init]; - value.ssize = ssize; - type = OF_NUMBER_SSIZE; + _value.ssize = ssize; + _type = OF_NUMBER_SSIZE; return self; } - initWithIntMax: (intmax_t)intmax { self = [super init]; - value.intmax = intmax; - type = OF_NUMBER_INTMAX; + _value.intmax = intmax; + _type = OF_NUMBER_INTMAX; return self; } - initWithUIntMax: (uintmax_t)uintmax { self = [super init]; - value.uintmax = uintmax; - type = OF_NUMBER_UINTMAX; + _value.uintmax = uintmax; + _type = OF_NUMBER_UINTMAX; return self; } - initWithPtrDiff: (ptrdiff_t)ptrdiff { self = [super init]; - value.ptrdiff = ptrdiff; - type = OF_NUMBER_PTRDIFF; + _value.ptrdiff = ptrdiff; + _type = OF_NUMBER_PTRDIFF; return self; } - initWithIntPtr: (intptr_t)intptr { self = [super init]; - value.intptr = intptr; - type = OF_NUMBER_INTPTR; + _value.intptr = intptr; + _type = OF_NUMBER_INTPTR; return self; } - initWithUIntPtr: (uintptr_t)uintptr { self = [super init]; - value.uintptr = uintptr; - type = OF_NUMBER_UINTPTR; + _value.uintptr = uintptr; + _type = OF_NUMBER_UINTPTR; return self; } - initWithFloat: (float)float_ { self = [super init]; - value.float_ = float_; - type = OF_NUMBER_FLOAT; + _value.float_ = float_; + _type = OF_NUMBER_FLOAT; return self; } - initWithDouble: (double)double_ { self = [super init]; - value.double_ = double_; - type = OF_NUMBER_DOUBLE; + _value.double_ = double_; + _type = OF_NUMBER_DOUBLE; return self; } - initWithSerialization: (OFXMLElement*)element @@ -736,50 +736,50 @@ selector: _cmd]; typeString = [[element attributeForName: @"type"] stringValue]; if ([typeString isEqual: @"boolean"]) { - type = OF_NUMBER_BOOL; + _type = OF_NUMBER_BOOL; if ([[element stringValue] isEqual: @"YES"]) - value.bool_ = YES; + _value.bool_ = YES; else if ([[element stringValue] isEqual: @"NO"]) - value.bool_ = NO; + _value.bool_ = NO; else @throw [OFInvalidArgumentException exceptionWithClass: [self class] selector: _cmd]; } else if ([typeString isEqual: @"unsigned"]) { /* * FIXME: This will fail if the value is bigger than * INTMAX_MAX! */ - type = OF_NUMBER_UINTMAX; - value.uintmax = [element decimalValue]; + _type = OF_NUMBER_UINTMAX; + _value.uintmax = [element decimalValue]; } else if ([typeString isEqual: @"signed"]) { - type = OF_NUMBER_INTMAX; - value.intmax = [element decimalValue]; + _type = OF_NUMBER_INTMAX; + _value.intmax = [element decimalValue]; } else if ([typeString isEqual: @"float"]) { union { float f; uint32_t u; } f; f.u = (uint32_t)[element hexadecimalValue]; - type = OF_NUMBER_FLOAT; - value.float_ = f.f; + _type = OF_NUMBER_FLOAT; + _value.float_ = f.f; } else if ([typeString isEqual: @"double"]) { union { double d; uint64_t u; } d; d.u = (uint64_t)[element hexadecimalValue]; - type = OF_NUMBER_DOUBLE; - value.double_ = d.d; + _type = OF_NUMBER_DOUBLE; + _value.double_ = d.d; } else @throw [OFInvalidArgumentException exceptionWithClass: [self class] selector: _cmd]; @@ -792,68 +792,68 @@ return self; } - (of_number_type_t)type { - return type; + return _type; } - (BOOL)boolValue { - switch (type) { + switch (_type) { case OF_NUMBER_BOOL: - return !!value.bool_; + return !!_value.bool_; case OF_NUMBER_CHAR: - return !!value.char_; + return !!_value.schar; case OF_NUMBER_SHORT: - return !!value.short_; + return !!_value.sshort; case OF_NUMBER_INT: - return !!value.int_; + return !!_value.sint; case OF_NUMBER_LONG: - return !!value.long_; + return !!_value.slong; case OF_NUMBER_UCHAR: - return !!value.uchar; + return !!_value.uchar; case OF_NUMBER_USHORT: - return !!value.ushort; + return !!_value.ushort; case OF_NUMBER_UINT: - return !!value.uint; + return !!_value.uint; case OF_NUMBER_ULONG: - return !!value.ulong; + return !!_value.ulong; case OF_NUMBER_INT8: - return !!value.int8; + return !!_value.int8; case OF_NUMBER_INT16: - return !!value.int16; + return !!_value.int16; case OF_NUMBER_INT32: - return !!value.int32; + return !!_value.int32; case OF_NUMBER_INT64: - return !!value.int64; + return !!_value.int64; case OF_NUMBER_UINT8: - return !!value.uint8; + return !!_value.uint8; case OF_NUMBER_UINT16: - return !!value.uint16; + return !!_value.uint16; case OF_NUMBER_UINT32: - return !!value.uint32; + return !!_value.uint32; case OF_NUMBER_UINT64: - return !!value.uint64; + return !!_value.uint64; case OF_NUMBER_SIZE: - return !!value.size; + return !!_value.size; case OF_NUMBER_SSIZE: - return !!value.ssize; + return !!_value.ssize; case OF_NUMBER_INTMAX: - return !!value.intmax; + return !!_value.intmax; case OF_NUMBER_UINTMAX: - return !!value.uintmax; + return !!_value.uintmax; case OF_NUMBER_PTRDIFF: - return !!value.ptrdiff; + return !!_value.ptrdiff; case OF_NUMBER_INTPTR: - return !!value.intptr; + return !!_value.intptr; case OF_NUMBER_UINTPTR: - return !!value.uintptr; + return !!_value.uintptr; case OF_NUMBER_FLOAT: - return !!value.float_; + return !!_value.float_; case OF_NUMBER_DOUBLE: - return !!value.double_; + return !!_value.double_; default: @throw [OFInvalidFormatException exceptionWithClass: [self class]]; } } @@ -990,14 +990,14 @@ if (![object isKindOfClass: [OFNumber class]]) return NO; number = object; - if (type & OF_NUMBER_FLOAT || number->type & OF_NUMBER_FLOAT) + if (_type & OF_NUMBER_FLOAT || number->_type & OF_NUMBER_FLOAT) return ([number doubleValue] == [self doubleValue]); - if (type & OF_NUMBER_SIGNED || number->type & OF_NUMBER_SIGNED) + if (_type & OF_NUMBER_SIGNED || number->_type & OF_NUMBER_SIGNED) return ([number intMaxValue] == [self intMaxValue]); return ([number uIntMaxValue] == [self uIntMaxValue]); } @@ -1010,21 +1010,22 @@ exceptionWithClass: [self class] selector: _cmd]; number = (OFNumber*)object; - if (type & OF_NUMBER_FLOAT || number->type & OF_NUMBER_FLOAT) { + if (_type & OF_NUMBER_FLOAT || number->_type & OF_NUMBER_FLOAT) { double double1 = [self doubleValue]; double double2 = [number doubleValue]; if (double1 > double2) return OF_ORDERED_DESCENDING; if (double1 < double2) return OF_ORDERED_ASCENDING; return OF_ORDERED_SAME; - } else if (type & OF_NUMBER_SIGNED || number->type & OF_NUMBER_SIGNED) { + } else if (_type & OF_NUMBER_SIGNED || + number->_type & OF_NUMBER_SIGNED) { intmax_t int1 = [self intMaxValue]; intmax_t int2 = [number intMaxValue]; if (int1 > int2) return OF_ORDERED_DESCENDING; @@ -1045,35 +1046,35 @@ } } - (uint32_t)hash { - of_number_type_t type_ = type; + of_number_type_t type = _type; uint32_t hash; /* Do we really need signed to represent this number? */ - if (type_ & OF_NUMBER_SIGNED && [self intMaxValue] >= 0) - type_ &= ~OF_NUMBER_SIGNED; + if (type & OF_NUMBER_SIGNED && [self intMaxValue] >= 0) + type &= ~OF_NUMBER_SIGNED; /* Do we really need floating point to represent this number? */ - if (type_ & OF_NUMBER_FLOAT) { + if (type & OF_NUMBER_FLOAT) { double v = [self doubleValue]; if (v < 0) { if (v == [self intMaxValue]) { - type_ &= ~OF_NUMBER_FLOAT; - type_ |= OF_NUMBER_SIGNED; + type &= ~OF_NUMBER_FLOAT; + type |= OF_NUMBER_SIGNED; } } else { if (v == [self uIntMaxValue]) - type_ &= ~OF_NUMBER_FLOAT; + type &= ~OF_NUMBER_FLOAT; } } OF_HASH_INIT(hash); - if (type_ & OF_NUMBER_FLOAT) { + if (type & OF_NUMBER_FLOAT) { union { double d; uint8_t b[sizeof(double)]; } d; uint_fast8_t i; @@ -1080,11 +1081,11 @@ d.d = OF_BSWAP_DOUBLE_IF_BE([self doubleValue]); for (i = 0; i < sizeof(double); i++) OF_HASH_ADD(hash, d.b[i]); - } else if (type_ & OF_NUMBER_SIGNED) { + } else if (type & OF_NUMBER_SIGNED) { intmax_t v = [self intMaxValue] * -1; while (v != 0) { OF_HASH_ADD(hash, v & 0xFF); v >>= 8; @@ -1160,88 +1161,89 @@ CALCULATE3(- 1) } - (OFNumber*)remainderOfDivisionWithNumber: (OFNumber*)number { - switch (type) { + switch (_type) { case OF_NUMBER_BOOL: return [OFNumber numberWithBool: - value.bool_ % [number boolValue]]; + _value.bool_ % [number boolValue]]; case OF_NUMBER_CHAR: return [OFNumber numberWithChar: - value.char_ % [number charValue]]; + _value.schar % [number charValue]]; case OF_NUMBER_SHORT: return [OFNumber numberWithShort: - value.short_ % [number shortValue]]; + _value.sshort % [number shortValue]]; case OF_NUMBER_INT: - return [OFNumber numberWithInt: value.int_ % [number intValue]]; + return [OFNumber numberWithInt: + _value.sint % [number intValue]]; case OF_NUMBER_LONG: return [OFNumber numberWithLong: - value.long_ % [number longValue]]; + _value.slong % [number longValue]]; case OF_NUMBER_UCHAR: return [OFNumber numberWithUnsignedChar: - value.uchar % [number unsignedCharValue]]; + _value.uchar % [number unsignedCharValue]]; case OF_NUMBER_USHORT: return [OFNumber numberWithUnsignedShort: - value.ushort % [number unsignedShortValue]]; + _value.ushort % [number unsignedShortValue]]; case OF_NUMBER_UINT: return [OFNumber numberWithUnsignedInt: - value.uint % [number unsignedIntValue]]; + _value.uint % [number unsignedIntValue]]; case OF_NUMBER_ULONG: return [OFNumber numberWithUnsignedLong: - value.ulong % [number unsignedLongValue]]; + _value.ulong % [number unsignedLongValue]]; case OF_NUMBER_INT8: return [OFNumber numberWithInt8: - value.int8 % [number int8Value]]; + _value.int8 % [number int8Value]]; case OF_NUMBER_INT16: return [OFNumber numberWithInt16: - value.int16 % [number int16Value]]; + _value.int16 % [number int16Value]]; case OF_NUMBER_INT32: return [OFNumber numberWithInt32: - value.int32 % [number int32Value]]; + _value.int32 % [number int32Value]]; case OF_NUMBER_INT64: return [OFNumber numberWithInt64: - value.int64 % [number int64Value]]; + _value.int64 % [number int64Value]]; case OF_NUMBER_UINT8: return [OFNumber numberWithUInt8: - value.uint8 % [number uInt8Value]]; + _value.uint8 % [number uInt8Value]]; case OF_NUMBER_UINT16: return [OFNumber numberWithUInt16: - value.uint16 % [number uInt16Value]]; + _value.uint16 % [number uInt16Value]]; case OF_NUMBER_UINT32: return [OFNumber numberWithUInt32: - value.uint32 % [number uInt32Value]]; + _value.uint32 % [number uInt32Value]]; case OF_NUMBER_UINT64: return [OFNumber numberWithUInt64: - value.uint64 % [number uInt64Value]]; + _value.uint64 % [number uInt64Value]]; case OF_NUMBER_SIZE: return [OFNumber numberWithSize: - value.size % [number sizeValue]]; + _value.size % [number sizeValue]]; case OF_NUMBER_SSIZE: return [OFNumber numberWithSSize: - value.ssize % [number sSizeValue]]; + _value.ssize % [number sSizeValue]]; case OF_NUMBER_INTMAX: return [OFNumber numberWithIntMax: - value.intmax % [number intMaxValue]]; + _value.intmax % [number intMaxValue]]; case OF_NUMBER_UINTMAX: return [OFNumber numberWithUIntMax: - value.uintmax % [number uIntMaxValue]]; + _value.uintmax % [number uIntMaxValue]]; case OF_NUMBER_PTRDIFF: return [OFNumber numberWithPtrDiff: - value.ptrdiff % [number ptrDiffValue]]; + _value.ptrdiff % [number ptrDiffValue]]; case OF_NUMBER_INTPTR: return [OFNumber numberWithIntPtr: - value.intptr % [number intPtrValue]]; + _value.intptr % [number intPtrValue]]; case OF_NUMBER_UINTPTR: return [OFNumber numberWithUIntPtr: - value.uintptr % [number uIntPtrValue]]; + _value.uintptr % [number uIntPtrValue]]; case OF_NUMBER_FLOAT: - return [OFNumber - numberWithFloat: fmodf(value.float_, [number floatValue])]; + return [OFNumber numberWithFloat: + fmodf(_value.float_, [number floatValue])]; case OF_NUMBER_DOUBLE: return [OFNumber numberWithDouble: - fmod(value.double_, [number doubleValue])]; + fmod(_value.double_, [number doubleValue])]; default: @throw [OFInvalidFormatException exceptionWithClass: [self class]]; } } @@ -1253,13 +1255,13 @@ - (OFString*)description { OFMutableString *ret; - switch (type) { + switch (_type) { case OF_NUMBER_BOOL: - return (value.bool_ ? @"YES" : @"NO"); + return (_value.bool_ ? @"YES" : @"NO"); case OF_NUMBER_UCHAR: case OF_NUMBER_USHORT: case OF_NUMBER_UINT: case OF_NUMBER_ULONG: case OF_NUMBER_UINT8: @@ -1282,20 +1284,21 @@ case OF_NUMBER_INTMAX: case OF_NUMBER_PTRDIFF: case OF_NUMBER_INTPTR: return [OFString stringWithFormat: @"%jd", [self intMaxValue]]; case OF_NUMBER_FLOAT: - ret = [OFMutableString stringWithFormat: @"%g", value.float_]; + ret = [OFMutableString stringWithFormat: @"%g", _value.float_]; if (![ret containsString: @"."]) [ret appendString: @".0"]; [ret makeImmutable]; return ret; case OF_NUMBER_DOUBLE: - ret = [OFMutableString stringWithFormat: @"%lg", value.double_]; + ret = [OFMutableString stringWithFormat: @"%lg", + _value.double_]; if (![ret containsString: @"."]) [ret appendString: @".0"]; [ret makeImmutable]; @@ -1314,11 +1317,11 @@ element = [OFXMLElement elementWithName: [self className] namespace: OF_SERIALIZATION_NS stringValue: [self description]]; - switch (type) { + switch (_type) { case OF_NUMBER_BOOL: [element addAttributeWithName: @"type" stringValue: @"boolean"]; break; case OF_NUMBER_UCHAR: @@ -1354,11 +1357,11 @@ union { float f; uint32_t u; } f; - f.f = value.float_; + f.f = _value.float_; [element addAttributeWithName: @"type" stringValue: @"float"]; [element setStringValue: [OFString stringWithFormat: @"%08" PRIx32, f.u]]; @@ -1368,11 +1371,11 @@ union { double d; uint64_t u; } d; - d.d = value.double_; + d.d = _value.double_; [element addAttributeWithName: @"type" stringValue: @"double"]; [element setStringValue: [OFString stringWithFormat: @"%016" PRIx64, d.u]]; @@ -1392,12 +1395,12 @@ - (OFString*)JSONRepresentation { double doubleValue; - if (type == OF_NUMBER_BOOL) - return (value.bool_ ? @"true" : @"false"); + if (_type == OF_NUMBER_BOOL) + return (_value.bool_ ? @"true" : @"false"); doubleValue = [self doubleValue]; if (isinf(doubleValue)) { if (doubleValue > 0) return @"Infinity"; Index: src/OFObject.h ================================================================== --- src/OFObject.h +++ src/OFObject.h @@ -344,11 +344,11 @@ * @brief The root class for all other classes inside ObjFW. */ @interface OFObject { @public - Class isa; + Class _isa; } /*! * @brief A method which is called once when the class is loaded into the * runtime. Index: src/OFPlugin.h ================================================================== --- src/OFPlugin.h +++ src/OFPlugin.h @@ -28,11 +28,11 @@ /*! * @brief Provides a system for loading plugins at runtime. */ @interface OFPlugin: OFObject { - of_plugin_handle_t handle; + of_plugin_handle_t _handle; } /*! * @brief Loads a plugin from a file. * Index: src/OFPlugin.m ================================================================== --- src/OFPlugin.m +++ src/OFPlugin.m @@ -61,11 +61,11 @@ dlclose(handle); @throw [OFInitializationFailedException exceptionWithClass: self]; } - plugin->handle = handle; + plugin->_handle = handle; return plugin; } - init { @@ -82,12 +82,12 @@ return [super init]; } - (void)dealloc { - of_plugin_handle_t h = handle; + of_plugin_handle_t h = _handle; [super dealloc]; dlclose(h); } @end Index: src/OFProcess.h ================================================================== --- src/OFProcess.h +++ src/OFProcess.h @@ -37,17 +37,17 @@ * @brief A class for stream-like communication with a newly created process. */ @interface OFProcess: OFStream { #ifndef _WIN32 - pid_t pid; - int readPipe[2], writePipe[2]; + pid_t _pid; + int _readPipe[2], _writePipe[2]; #else - HANDLE process, readPipe[2], writePipe[2]; + HANDLE _process, _readPipe[2], _writePipe[2]; #endif - int status; - BOOL atEndOfStream; + int _status; + BOOL _atEndOfStream; } /*! * @brief Creates a new OFProcess with the specified program and invokes the * program. Index: src/OFProcess.m ================================================================== --- src/OFProcess.m +++ src/OFProcess.m @@ -116,15 +116,15 @@ { self = [super init]; @try { #ifndef _WIN32 - if (pipe(readPipe) != 0 || pipe(writePipe) != 0) + if (pipe(_readPipe) != 0 || pipe(_writePipe) != 0) @throw [OFInitializationFailedException exceptionWithClass: [self class]]; - switch ((pid = fork())) { + switch ((_pid = fork())) { case 0:; OFString **objects = [arguments objects]; size_t i, count = [arguments count]; char **argv; @@ -149,25 +149,25 @@ environ = [self OF_environmentForDictionary: environment]; #endif } - close(readPipe[0]); - close(writePipe[1]); - dup2(writePipe[0], 0); - dup2(readPipe[1], 1); + close(_readPipe[0]); + close(_writePipe[1]); + dup2(_writePipe[0], 0); + dup2(_readPipe[1], 1); execvp([program cStringWithEncoding: OF_STRING_ENCODING_NATIVE], argv); @throw [OFInitializationFailedException exceptionWithClass: [self class]]; case -1: @throw [OFInitializationFailedException exceptionWithClass: [self class]]; default: - close(readPipe[1]); - close(writePipe[0]); + close(_readPipe[1]); + close(_writePipe[0]); break; } #else SECURITY_ATTRIBUTES sa; PROCESS_INFORMATION pi; @@ -181,32 +181,33 @@ sa.nLength = sizeof(sa); sa.bInheritHandle = TRUE; sa.lpSecurityDescriptor = NULL; - if (!CreatePipe(&readPipe[0], &readPipe[1], &sa, 0)) + if (!CreatePipe(&_readPipe[0], &_readPipe[1], &sa, 0)) + @throw [OFInitializationFailedException + exceptionWithClass: [self class]]; + + if (!SetHandleInformation(_readPipe[0], HANDLE_FLAG_INHERIT, 0)) @throw [OFInitializationFailedException exceptionWithClass: [self class]]; - if (!SetHandleInformation(readPipe[0], HANDLE_FLAG_INHERIT, 0)) + if (!CreatePipe(&_writePipe[0], &_writePipe[1], &sa, 0)) @throw [OFInitializationFailedException exceptionWithClass: [self class]]; - if (!CreatePipe(&writePipe[0], &writePipe[1], &sa, 0)) - @throw [OFInitializationFailedException - exceptionWithClass: [self class]]; - - if (!SetHandleInformation(writePipe[1], HANDLE_FLAG_INHERIT, 0)) + if (!SetHandleInformation(_writePipe[1], + HANDLE_FLAG_INHERIT, 0)) @throw [OFInitializationFailedException exceptionWithClass: [self class]]; memset(&pi, 0, sizeof(pi)); memset(&si, 0, sizeof(si)); si.cb = sizeof(si); - si.hStdInput = writePipe[0]; - si.hStdOutput = readPipe[1]; + si.hStdInput = _writePipe[0]; + si.hStdOutput = _readPipe[1]; si.hStdError = GetStdHandle(STD_ERROR_HANDLE); si.dwFlags |= STARTF_USESTDHANDLES; pool = objc_autoreleasePoolPush(); @@ -261,23 +262,30 @@ [self freeMemory: argumentsCopy]; } objc_autoreleasePoolPop(pool); - process = pi.hProcess; + _process = pi.hProcess; CloseHandle(pi.hThread); - CloseHandle(readPipe[1]); - CloseHandle(writePipe[0]); + CloseHandle(_readPipe[1]); + CloseHandle(_writePipe[0]); #endif } @catch (id e) { [self release]; @throw e; } return self; } + +- (void)dealloc +{ + [self close]; + + [super dealloc]; +} #ifndef _WIN32 - (char**)OF_environmentForDictionary: (OFDictionary*)environment { OFEnumerator *keyEnumerator, *objectEnumerator; @@ -352,17 +360,17 @@ #endif - (BOOL)lowlevelIsAtEndOfStream { #ifndef _WIN32 - if (readPipe[0] == -1) + if (_readPipe[0] == -1) #else - if (readPipe[0] == NULL) + if (_readPipe[0] == NULL) #endif return YES; - return atEndOfStream; + return _atEndOfStream; } - (size_t)lowlevelReadIntoBuffer: (void*)buffer length: (size_t)length { @@ -371,17 +379,17 @@ #else DWORD ret; #endif #ifndef _WIN32 - if (readPipe[0] == -1 || atEndOfStream || - (ret = read(readPipe[0], buffer, length)) < 0) { + if (_readPipe[0] == -1 || _atEndOfStream || + (ret = read(_readPipe[0], buffer, length)) < 0) { #else - if (readPipe[0] == NULL || atEndOfStream || - !ReadFile(readPipe[0], buffer, length, &ret, NULL)) { + if (_readPipe[0] == NULL || _atEndOfStream || + !ReadFile(_readPipe[0], buffer, length, &ret, NULL)) { if (GetLastError() == ERROR_BROKEN_PIPE) { - atEndOfStream = YES; + _atEndOfStream = YES; return 0; } #endif @throw [OFReadFailedException exceptionWithClass: [self class] @@ -388,103 +396,96 @@ stream: self requestedLength: length]; } if (ret == 0) - atEndOfStream = YES; + _atEndOfStream = YES; return ret; } - (void)lowlevelWriteBuffer: (const void*)buffer length: (size_t)length { #ifndef _WIN32 - if (writePipe[1] == -1 || atEndOfStream || - write(writePipe[1], buffer, length) < length) + if (_writePipe[1] == -1 || _atEndOfStream || + write(_writePipe[1], buffer, length) < length) #else DWORD ret; - if (writePipe[1] == NULL || atEndOfStream || - !WriteFile(writePipe[1], buffer, length, &ret, NULL) || + if (_writePipe[1] == NULL || _atEndOfStream || + !WriteFile(_writePipe[1], buffer, length, &ret, NULL) || ret < length) #endif @throw [OFWriteFailedException exceptionWithClass: [self class] stream: self requestedLength: length]; } -- (void)dealloc -{ - [self close]; - - [super dealloc]; -} - - (int)fileDescriptorForReading { #ifndef _WIN32 - return readPipe[0]; + return _readPipe[0]; #else [self doesNotRecognizeSelector: _cmd]; abort(); #endif } - (int)fileDescriptorForWriting { #ifndef _WIN32 - return writePipe[1]; + return _writePipe[1]; #else [self doesNotRecognizeSelector: _cmd]; abort(); #endif } - (void)closeForWriting { #ifndef _WIN32 - if (writePipe[1] != -1) - close(writePipe[1]); + if (_writePipe[1] != -1) + close(_writePipe[1]); - writePipe[1] = -1; + _writePipe[1] = -1; #else - if (writePipe[1] != NULL) - CloseHandle(writePipe[1]); + if (_writePipe[1] != NULL) + CloseHandle(_writePipe[1]); - writePipe[1] = NULL; + _writePipe[1] = NULL; #endif } - (void)close { #ifndef _WIN32 - if (readPipe[0] != -1) - close(readPipe[0]); - if (writePipe[1] != -1) - close(writePipe[1]); - - if (pid != -1) { - kill(pid, SIGKILL); - waitpid(pid, &status, WNOHANG); - } - - pid = -1; - readPipe[0] = -1; - writePipe[1] = -1; -#else - if (readPipe[0] != NULL) - CloseHandle(readPipe[0]); - if (writePipe[1] != NULL) - CloseHandle(writePipe[1]); - - if (process != INVALID_HANDLE_VALUE) { - TerminateProcess(process, 0); - CloseHandle(process); - } - - process = INVALID_HANDLE_VALUE; - readPipe[0] = NULL; - writePipe[1] = NULL; + if (_readPipe[0] != -1) + close(_readPipe[0]); + if (_writePipe[1] != -1) + close(_writePipe[1]); + + if (_pid != -1) { + kill(_pid, SIGKILL); + waitpid(_pid, &_status, WNOHANG); + } + + _pid = -1; + _readPipe[0] = -1; + _writePipe[1] = -1; +#else + if (_readPipe[0] != NULL) + CloseHandle(_readPipe[0]); + if (_writePipe[1] != NULL) + CloseHandle(_writePipe[1]); + + if (_process != INVALID_HANDLE_VALUE) { + TerminateProcess(_process, 0); + CloseHandle(_process); + } + + _process = INVALID_HANDLE_VALUE; + _readPipe[0] = NULL; + _writePipe[1] = NULL; #endif } @end Index: src/OFRecursiveMutex.h ================================================================== --- src/OFRecursiveMutex.h +++ src/OFRecursiveMutex.h @@ -23,17 +23,17 @@ * @brief A class for creating mutual exclusions which can be entered * recursively. */ @interface OFRecursiveMutex: OFObject { - of_rmutex_t rmutex; - BOOL initialized; - OFString *name; + of_rmutex_t _rmutex; + BOOL _initialized; + OFString *_name; } /*! * @brief Creates a new recursive mutex. * * @return A new autoreleased recursive mutex. */ + (instancetype)mutex; @end Index: src/OFRecursiveMutex.m ================================================================== --- src/OFRecursiveMutex.m +++ src/OFRecursiveMutex.m @@ -34,66 +34,67 @@ - init { self = [super init]; - if (!of_rmutex_new(&rmutex)) { + if (!of_rmutex_new(&_rmutex)) { Class c = [self class]; [self release]; @throw [OFInitializationFailedException exceptionWithClass: c]; } - initialized = YES; + _initialized = YES; return self; } - (void)lock { - if (!of_rmutex_lock(&rmutex)) + if (!of_rmutex_lock(&_rmutex)) @throw [OFLockFailedException exceptionWithClass: [self class] lock: self]; } - (BOOL)tryLock { - return of_rmutex_trylock(&rmutex); + return of_rmutex_trylock(&_rmutex); } - (void)unlock { - if (!of_rmutex_unlock(&rmutex)) + if (!of_rmutex_unlock(&_rmutex)) @throw [OFUnlockFailedException exceptionWithClass: [self class] lock: self]; } -- (void)setName: (OFString*)name_ +- (void)setName: (OFString*)name { - OF_SETTER(name, name_, YES, 1) + OF_SETTER(_name, name, YES, 1) } - (OFString*)name { - OF_GETTER(name, YES) + OF_GETTER(_name, YES) } - (OFString*)description { - if (name == nil) + if (_name == nil) return [super description]; - return [OFString stringWithFormat: @"<%@: %@>", [self className], name]; + return [OFString stringWithFormat: @"<%@: %@>", + [self className], _name]; } - (void)dealloc { - if (initialized) - if (!of_rmutex_free(&rmutex)) + if (_initialized) + if (!of_rmutex_free(&_rmutex)) @throw [OFStillLockedException exceptionWithClass: [self class] lock: self]; - [name release]; + [_name release]; [super dealloc]; } @end Index: src/OFRunLoop.h ================================================================== --- src/OFRunLoop.h +++ src/OFRunLoop.h @@ -29,17 +29,17 @@ /*! * @brief A class providing a run loop for the application and its processes. */ @interface OFRunLoop: OFObject { - OFSortedList *timersQueue; + OFSortedList *_timersQueue; #ifdef OF_HAVE_THREADS - OFMutex *timersQueueLock; + OFMutex *_timersQueueLock; #endif - OFStreamObserver *streamObserver; - OFMutableDictionary *readQueues; - volatile BOOL running; + OFStreamObserver *_streamObserver; + OFMutableDictionary *_readQueues; + volatile BOOL _running; } /*! * @brief Returns the main run loop. * Index: src/OFRunLoop.m ================================================================== --- src/OFRunLoop.m +++ src/OFRunLoop.m @@ -31,105 +31,110 @@ #import "autorelease.h" #import "macros.h" static OFRunLoop *mainRunLoop = nil; -@interface OFRunLoop_ReadQueueItem: OFObject -{ -@public - void *buffer; - size_t length; - id target; - SEL selector; -#ifdef OF_HAVE_BLOCKS - of_stream_async_read_block_t block; -#endif -} -@end - -@interface OFRunLoop_ExactReadQueueItem: OFObject -{ -@public - void *buffer; - size_t exactLength, readLength; - id target; - SEL selector; -#ifdef OF_HAVE_BLOCKS - of_stream_async_read_block_t block; -#endif -} -@end - -@interface OFRunLoop_ReadLineQueueItem: OFObject -{ -@public - of_string_encoding_t encoding; - id target; - SEL selector; -#ifdef OF_HAVE_BLOCKS - of_stream_async_read_line_block_t block; -#endif -} -@end - -@interface OFRunLoop_AcceptQueueItem: OFObject -{ -@public - id target; - SEL selector; -#ifdef OF_HAVE_BLOCKS - of_tcpsocket_async_accept_block_t block; -#endif +@interface OFRunLoop_QueueItem: OFObject +{ +@public + id _target; + SEL _selector; +} +@end + +@interface OFRunLoop_ReadQueueItem: OFRunLoop_QueueItem +{ +@public +#ifdef OF_HAVE_BLOCKS + of_stream_async_read_block_t _block; +#endif + void *_buffer; + size_t _length; +} +@end + +@interface OFRunLoop_ExactReadQueueItem: OFRunLoop_QueueItem +{ +@public +#ifdef OF_HAVE_BLOCKS + of_stream_async_read_block_t _block; +#endif + void *_buffer; + size_t _exactLength, _readLength; +} +@end + +@interface OFRunLoop_ReadLineQueueItem: OFRunLoop_QueueItem +{ +@public +#ifdef OF_HAVE_BLOCKS + of_stream_async_read_line_block_t _block; +#endif + of_string_encoding_t _encoding; +} +@end + +@interface OFRunLoop_AcceptQueueItem: OFRunLoop_QueueItem +{ +@public +#ifdef OF_HAVE_BLOCKS + of_tcpsocket_async_accept_block_t _block; +#endif +} +@end + +@implementation OFRunLoop_QueueItem +- (void)dealloc +{ + [_target release]; + + [super dealloc]; } @end @implementation OFRunLoop_ReadQueueItem +#ifdef OF_HAVE_BLOCKS - (void)dealloc { - [target release]; -#ifdef OF_HAVE_BLOCKS - [block release]; -#endif + [_block release]; [super dealloc]; } +#endif @end @implementation OFRunLoop_ExactReadQueueItem +#ifdef OF_HAVE_BLOCKS - (void)dealloc { - [target release]; -#ifdef OF_HAVE_BLOCKS - [block release]; -#endif + [_block release]; [super dealloc]; } +#endif @end @implementation OFRunLoop_ReadLineQueueItem +#ifdef OF_HAVE_BLOCKS - (void)dealloc { - [target release]; -#ifdef OF_HAVE_BLOCKS - [block release]; -#endif + [_block release]; [super dealloc]; } +#endif @end @implementation OFRunLoop_AcceptQueueItem +#ifdef OF_HAVE_BLOCKS - (void)dealloc { - [target release]; -#ifdef OF_HAVE_BLOCKS - [block release]; -#endif + [_block release]; [super dealloc]; } +#endif @end @implementation OFRunLoop + (OFRunLoop*)mainRunLoop { @@ -151,21 +156,21 @@ } #define ADD(type, code) \ void *pool = objc_autoreleasePoolPush(); \ OFRunLoop *runLoop = [self currentRunLoop]; \ - OFList *queue = [runLoop->readQueues objectForKey: stream]; \ + OFList *queue = [runLoop->_readQueues objectForKey: stream]; \ type *queueItem; \ \ if (queue == nil) { \ queue = [OFList list]; \ - [runLoop->readQueues setObject: queue \ - forKey: stream]; \ + [runLoop->_readQueues setObject: queue \ + forKey: stream]; \ } \ \ if ([queue count] == 0) \ - [runLoop->streamObserver addStreamForReading: stream]; \ + [runLoop->_streamObserver addStreamForReading: stream]; \ \ queueItem = [[[type alloc] init] autorelease]; \ code \ [queue appendObject: queueItem]; \ \ @@ -176,14 +181,14 @@ length: (size_t)length target: (id)target selector: (SEL)selector { ADD(OFRunLoop_ReadQueueItem, { - queueItem->buffer = buffer; - queueItem->length = length; - queueItem->target = [target retain]; - queueItem->selector = selector; + queueItem->_target = [target retain]; + queueItem->_selector = selector; + queueItem->_buffer = buffer; + queueItem->_length = length; }) } + (void)OF_addAsyncReadForStream: (OFStream*)stream buffer: (void*)buffer @@ -190,36 +195,36 @@ exactLength: (size_t)exactLength target: (id)target selector: (SEL)selector { ADD(OFRunLoop_ExactReadQueueItem, { - queueItem->buffer = buffer; - queueItem->exactLength = exactLength; - queueItem->target = [target retain]; - queueItem->selector = selector; + queueItem->_target = [target retain]; + queueItem->_selector = selector; + queueItem->_buffer = buffer; + queueItem->_exactLength = exactLength; }) } + (void)OF_addAsyncReadLineForStream: (OFStream*)stream encoding: (of_string_encoding_t)encoding target: (id)target selector: (SEL)selector { ADD(OFRunLoop_ReadLineQueueItem, { - queueItem->encoding = encoding; - queueItem->target = [target retain]; - queueItem->selector = selector; + queueItem->_target = [target retain]; + queueItem->_selector = selector; + queueItem->_encoding = encoding; }) } + (void)OF_addAsyncAcceptForTCPSocket: (OFTCPSocket*)stream target: (id)target selector: (SEL)selector { ADD(OFRunLoop_AcceptQueueItem, { - queueItem->target = [target retain]; - queueItem->selector = selector; + queueItem->_target = [target retain]; + queueItem->_selector = selector; }) } #ifdef OF_HAVE_BLOCKS + (void)OF_addAsyncReadForStream: (OFStream*)stream @@ -226,43 +231,43 @@ buffer: (void*)buffer length: (size_t)length block: (of_stream_async_read_block_t)block { ADD(OFRunLoop_ReadQueueItem, { - queueItem->buffer = buffer; - queueItem->length = length; - queueItem->block = [block copy]; + queueItem->_block = [block copy]; + queueItem->_buffer = buffer; + queueItem->_length = length; }) } + (void)OF_addAsyncReadForStream: (OFStream*)stream buffer: (void*)buffer exactLength: (size_t)exactLength block: (of_stream_async_read_block_t)block { ADD(OFRunLoop_ExactReadQueueItem, { - queueItem->buffer = buffer; - queueItem->exactLength = exactLength; - queueItem->block = [block copy]; + queueItem->_block = [block copy]; + queueItem->_buffer = buffer; + queueItem->_exactLength = exactLength; }) } + (void)OF_addAsyncReadLineForStream: (OFStream*)stream encoding: (of_string_encoding_t)encoding block: (of_stream_async_read_line_block_t)block { ADD(OFRunLoop_ReadLineQueueItem, { - queueItem->encoding = encoding; - queueItem->block = [block copy]; + queueItem->_block = [block copy]; + queueItem->_encoding = encoding; }) } + (void)OF_addAsyncAcceptForTCPSocket: (OFTCPSocket*)stream block: (of_tcpsocket_async_accept_block_t)block { ADD(OFRunLoop_AcceptQueueItem, { - queueItem->block = [block copy]; + queueItem->_block = [block copy]; }) } #endif #undef ADD @@ -271,15 +276,15 @@ { void *pool = objc_autoreleasePoolPush(); OFRunLoop *runLoop = [self currentRunLoop]; OFList *queue; - if ((queue = [runLoop->readQueues objectForKey: stream]) != nil) { + if ((queue = [runLoop->_readQueues objectForKey: stream]) != nil) { assert([queue count] > 0); - [runLoop->streamObserver removeStreamForReading: stream]; - [runLoop->readQueues removeObjectForKey: stream]; + [runLoop->_streamObserver removeStreamForReading: stream]; + [runLoop->_readQueues removeObjectForKey: stream]; } objc_autoreleasePoolPop(pool); } @@ -286,19 +291,19 @@ - init { self = [super init]; @try { - timersQueue = [[OFSortedList alloc] init]; + _timersQueue = [[OFSortedList alloc] init]; #ifdef OF_HAVE_THREADS - timersQueueLock = [[OFMutex alloc] init]; + _timersQueueLock = [[OFMutex alloc] init]; #endif - streamObserver = [[OFStreamObserver alloc] init]; - [streamObserver setDelegate: self]; + _streamObserver = [[OFStreamObserver alloc] init]; + [_streamObserver setDelegate: self]; - readQueues = [[OFMutableDictionary alloc] init]; + _readQueues = [[OFMutableDictionary alloc] init]; } @catch (id e) { [self release]; @throw e; } @@ -305,63 +310,63 @@ return self; } - (void)dealloc { - [timersQueue release]; + [_timersQueue release]; #ifdef OF_HAVE_THREADS - [timersQueueLock release]; + [_timersQueueLock release]; #endif - [streamObserver release]; - [readQueues release]; + [_streamObserver release]; + [_readQueues release]; [super dealloc]; } - (void)addTimer: (OFTimer*)timer { #ifdef OF_HAVE_THREADS - [timersQueueLock lock]; + [_timersQueueLock lock]; @try { #endif - [timersQueue insertObject: timer]; + [_timersQueue insertObject: timer]; #ifdef OF_HAVE_THREADS } @finally { - [timersQueueLock unlock]; + [_timersQueueLock unlock]; } #endif [timer OF_setInRunLoop: self]; - [streamObserver cancel]; + [_streamObserver cancel]; } - (void)OF_removeTimer: (OFTimer*)timer { #ifdef OF_HAVE_THREADS - [timersQueueLock lock]; + [_timersQueueLock lock]; @try { #endif of_list_object_t *iter; - for (iter = [timersQueue firstListObject]; iter != NULL; + for (iter = [_timersQueue firstListObject]; iter != NULL; iter = iter->next) { if ([iter->object isEqual: timer]) { - [timersQueue removeListObject: iter]; + [_timersQueue removeListObject: iter]; break; } } #ifdef OF_HAVE_THREADS } @finally { - [timersQueueLock unlock]; + [_timersQueueLock unlock]; } #endif } - (void)streamIsReadyForReading: (OFStream*)stream { - OFList *queue = [readQueues objectForKey: stream]; + OFList *queue = [_readQueues objectForKey: stream]; of_list_object_t *listObject; OF_ENSURE(queue != nil); listObject = [queue firstListObject]; @@ -371,45 +376,47 @@ OFRunLoop_ReadQueueItem *queueItem = listObject->object; size_t length; OFException *exception = nil; @try { - length = [stream readIntoBuffer: queueItem->buffer - length: queueItem->length]; + length = [stream readIntoBuffer: queueItem->_buffer + length: queueItem->_length]; } @catch (OFException *e) { length = 0; exception = e; } #ifdef OF_HAVE_BLOCKS - if (queueItem->block != NULL) { - if (!queueItem->block(stream, queueItem->buffer, + if (queueItem->_block != NULL) { + if (!queueItem->_block(stream, queueItem->_buffer, length, exception)) { [queue removeListObject: listObject]; if ([queue count] == 0) { - [streamObserver + [_streamObserver removeStreamForReading: stream]; - [readQueues removeObjectForKey: stream]; + [_readQueues + removeObjectForKey: stream]; } } } else { #endif BOOL (*func)(id, SEL, OFStream*, void*, size_t, OFException*) = (BOOL(*)(id, SEL, OFStream*, void*, size_t, OFException*)) - [queueItem->target methodForSelector: - queueItem->selector]; + [queueItem->_target methodForSelector: + queueItem->_selector]; - if (!func(queueItem->target, queueItem->selector, - stream, queueItem->buffer, length, exception)) { + if (!func(queueItem->_target, queueItem->_selector, + stream, queueItem->_buffer, length, exception)) { [queue removeListObject: listObject]; if ([queue count] == 0) { - [streamObserver + [_streamObserver removeStreamForReading: stream]; - [readQueues removeObjectForKey: stream]; + [_readQueues + removeObjectForKey: stream]; } } #ifdef OF_HAVE_BLOCKS } #endif @@ -419,59 +426,60 @@ size_t length; OFException *exception = nil; @try { length = [stream - readIntoBuffer: (char*)queueItem->buffer + - queueItem->readLength - length: queueItem->exactLength - - queueItem->readLength]; + readIntoBuffer: (char*)queueItem->_buffer + + queueItem->_readLength + length: queueItem->_exactLength - + queueItem->_readLength]; } @catch (OFException *e) { length = 0; exception = e; } - queueItem->readLength += length; - if (queueItem->readLength == queueItem->exactLength || + queueItem->_readLength += length; + if (queueItem->_readLength == queueItem->_exactLength || [stream isAtEndOfStream] || exception != nil) { #ifdef OF_HAVE_BLOCKS - if (queueItem->block != NULL) { - if (queueItem->block(stream, queueItem->buffer, - queueItem->readLength, exception)) - queueItem->readLength = 0; + if (queueItem->_block != NULL) { + if (queueItem->_block(stream, + queueItem->_buffer, queueItem->_readLength, + exception)) + queueItem->_readLength = 0; else { [queue removeListObject: listObject]; if ([queue count] == 0) { - [streamObserver + [_streamObserver removeStreamForReading: stream]; - [readQueues + [_readQueues removeObjectForKey: stream]; } } } else { #endif BOOL (*func)(id, SEL, OFStream*, void*, size_t, OFException*) = (BOOL(*)(id, SEL, OFStream*, void*, size_t, OFException*)) - [queueItem->target - methodForSelector: queueItem->selector]; + [queueItem->_target + methodForSelector: queueItem->_selector]; - if (func(queueItem->target, - queueItem->selector, stream, - queueItem->buffer, queueItem->readLength, + if (func(queueItem->_target, + queueItem->_selector, stream, + queueItem->_buffer, queueItem->_readLength, exception)) - queueItem->readLength = 0; + queueItem->_readLength = 0; else { [queue removeListObject: listObject]; if ([queue count] == 0) { - [streamObserver + [_streamObserver removeStreamForReading: stream]; - [readQueues + [_readQueues removeObjectForKey: stream]; } } #ifdef OF_HAVE_BLOCKS } @@ -483,50 +491,50 @@ OFString *line; OFException *exception = nil; @try { line = [stream - tryReadLineWithEncoding: queueItem->encoding]; + tryReadLineWithEncoding: queueItem->_encoding]; } @catch (OFException *e) { line = nil; exception = e; } if (line != nil || [stream isAtEndOfStream] || exception != nil) { #ifdef OF_HAVE_BLOCKS - if (queueItem->block != NULL) { - if (!queueItem->block(stream, line, + if (queueItem->_block != NULL) { + if (!queueItem->_block(stream, line, exception)) { [queue removeListObject: listObject]; if ([queue count] == 0) { - [streamObserver + [_streamObserver removeStreamForReading: stream]; - [readQueues + [_readQueues removeObjectForKey: stream]; } } } else { #endif BOOL (*func)(id, SEL, OFStream*, OFString*, OFException*) = (BOOL(*)(id, SEL, OFStream*, OFString*, OFException*)) - [queueItem->target methodForSelector: - queueItem->selector]; + [queueItem->_target methodForSelector: + queueItem->_selector]; - if (!func(queueItem->target, - queueItem->selector, stream, line, + if (!func(queueItem->_target, + queueItem->_selector, stream, line, exception)) { [queue removeListObject: listObject]; if ([queue count] == 0) { - [streamObserver + [_streamObserver removeStreamForReading: stream]; - [readQueues + [_readQueues removeObjectForKey: stream]; } } #ifdef OF_HAVE_BLOCKS } @@ -544,38 +552,40 @@ newSocket = nil; exception = e; } #ifdef OF_HAVE_BLOCKS - if (queueItem->block != NULL) { - if (!queueItem->block((OFTCPSocket*)stream, + if (queueItem->_block != NULL) { + if (!queueItem->_block((OFTCPSocket*)stream, newSocket, exception)) { [queue removeListObject: listObject]; if ([queue count] == 0) { - [streamObserver + [_streamObserver removeStreamForReading: stream]; - [readQueues removeObjectForKey: stream]; + [_readQueues + removeObjectForKey: stream]; } } } else { #endif BOOL (*func)(id, SEL, OFTCPSocket*, OFTCPSocket*, OFException*) = (BOOL(*)(id, SEL, OFTCPSocket*, OFTCPSocket*, OFException*)) - [queueItem->target methodForSelector: - queueItem->selector]; + [queueItem->_target methodForSelector: + queueItem->_selector]; - if (!func(queueItem->target, queueItem->selector, + if (!func(queueItem->_target, queueItem->_selector, (OFTCPSocket*)stream, newSocket, exception)) { [queue removeListObject: listObject]; if ([queue count] == 0) { - [streamObserver + [_streamObserver removeStreamForReading: stream]; - [readQueues removeObjectForKey: stream]; + [_readQueues + removeObjectForKey: stream]; } } #ifdef OF_HAVE_BLOCKS } #endif @@ -583,76 +593,76 @@ OF_ENSURE(0); } - (void)run { - running = YES; + _running = YES; - while (running) { + while (_running) { void *pool = objc_autoreleasePoolPush(); OFDate *now = [OFDate date]; OFTimer *timer; OFDate *nextTimer; #ifdef OF_HAVE_THREADS - [timersQueueLock lock]; + [_timersQueueLock lock]; @try { #endif of_list_object_t *listObject = - [timersQueue firstListObject]; + [_timersQueue firstListObject]; if (listObject != NULL && [[listObject->object fireDate] compare: now] != OF_ORDERED_DESCENDING) { timer = [[listObject->object retain] autorelease]; - [timersQueue removeListObject: listObject]; + [_timersQueue removeListObject: listObject]; [timer OF_setInRunLoop: nil]; } else timer = nil; #ifdef OF_HAVE_THREADS } @finally { - [timersQueueLock unlock]; + [_timersQueueLock unlock]; } #endif if ([timer isValid]) [timer fire]; #ifdef OF_HAVE_THREADS - [timersQueueLock lock]; + [_timersQueueLock lock]; @try { #endif - nextTimer = [[timersQueue firstObject] fireDate]; + nextTimer = [[_timersQueue firstObject] fireDate]; #ifdef OF_HAVE_THREADS } @finally { - [timersQueueLock unlock]; + [_timersQueueLock unlock]; } #endif /* Watch for stream events until the next timer is due */ if (nextTimer != nil) { double timeout = [nextTimer timeIntervalSinceNow]; if (timeout > 0) - [streamObserver observeWithTimeout: timeout]; + [_streamObserver observeWithTimeout: timeout]; } else { /* * No more timers: Just watch for streams until we get * an event. If a timer is added by another thread, it * cancels the observe. */ - [streamObserver observe]; + [_streamObserver observe]; } objc_autoreleasePoolPop(pool); } } - (void)stop { - running = NO; - [streamObserver cancel]; + _running = NO; + [_streamObserver cancel]; } @end Index: src/OFSHA1Hash.h ================================================================== --- src/OFSHA1Hash.h +++ src/OFSHA1Hash.h @@ -21,11 +21,11 @@ /*! * @brief A class which provides functions to create an SHA1 hash. */ @interface OFSHA1Hash: OFHash { - uint32_t state[5]; - uint64_t count; - char buffer[64]; - uint8_t digest[OF_SHA1_DIGEST_SIZE]; + uint32_t _state[5]; + uint64_t _count; + char _buffer[64]; + uint8_t _digest[OF_SHA1_DIGEST_SIZE]; } @end Index: src/OFSHA1Hash.m ================================================================== --- src/OFSHA1Hash.m +++ src/OFSHA1Hash.m @@ -141,55 +141,55 @@ - init { self = [super init]; - state[0] = 0x67452301; - state[1] = 0xEFCDAB89; - state[2] = 0x98BADCFE; - state[3] = 0x10325476; - state[4] = 0xC3D2E1F0; + _state[0] = 0x67452301; + _state[1] = 0xEFCDAB89; + _state[2] = 0x98BADCFE; + _state[3] = 0x10325476; + _state[4] = 0xC3D2E1F0; return self; } -- (void)updateWithBuffer: (const void*)buffer_ +- (void)updateWithBuffer: (const void*)buffer length: (size_t)length { if (length == 0) return; - if (calculated) + if (_calculated) @throw [OFHashAlreadyCalculatedException exceptionWithClass: [self class] hash: self]; - sha1_update(state, &count, buffer, buffer_, length); + sha1_update(_state, &_count, _buffer, buffer, length); } - (uint8_t*)digest { size_t i; - char finalcount[8]; + char finalcount[8]; - if (calculated) - return digest; + if (_calculated) + return _digest; for (i = 0; i < 8; i++) /* Endian independent */ - finalcount[i] = (char)((count >> ((7 - (i & 7)) * 8)) & 255); - sha1_update(state, &count, buffer, "\200", 1); + finalcount[i] = (char)((_count >> ((7 - (i & 7)) * 8)) & 255); + sha1_update(_state, &_count, _buffer, "\200", 1); - while ((count & 504) != 448) - sha1_update(state, &count, buffer, "\0", 1); + while ((_count & 504) != 448) + sha1_update(_state, &_count, _buffer, "\0", 1); /* Should cause a sha1_transform() */ - sha1_update(state, &count, buffer, finalcount, 8); + sha1_update(_state, &_count, _buffer, finalcount, 8); for (i = 0; i < OF_SHA1_DIGEST_SIZE; i++) - digest[i] = (char)((state[i >> 2] >> + _digest[i] = (char)((_state[i >> 2] >> ((3 - (i & 3)) * 8)) & 255); - calculated = YES; + _calculated = YES; - return digest; + return _digest; } @end Index: src/OFSeekableStream.m ================================================================== --- src/OFSeekableStream.m +++ src/OFSeekableStream.m @@ -32,10 +32,10 @@ whence: (int)whence { [self lowlevelSeekToOffset: offset whence: whence]; - [self freeMemory: cache]; - cache = NULL; - cacheLength = 0; + [self freeMemory: _cache]; + _cache = NULL; + _cacheLength = 0; } @end Index: src/OFSet_hashtable.h ================================================================== --- src/OFSet_hashtable.h +++ src/OFSet_hashtable.h @@ -18,10 +18,10 @@ @class OFMapTable; @interface OFSet_hashtable: OFSet { - OFMapTable *mapTable; + OFMapTable *_mapTable; } - initWithCapacity: (size_t)capacity; @end Index: src/OFSet_hashtable.m ================================================================== --- src/OFSet_hashtable.m +++ src/OFSet_hashtable.m @@ -70,11 +70,11 @@ - initWithCapacity: (size_t)capacity { self = [super init]; @try { - mapTable = [[OFMapTable alloc] + _mapTable = [[OFMapTable alloc] initWithKeyFunctions: keyFunctions valueFunctions: valueFunctions capacity: capacity]; } @catch (id e) { [self release]; @@ -105,12 +105,12 @@ OFEnumerator *enumerator; id object; enumerator = [set objectEnumerator]; while ((object = [enumerator nextObject]) != nil) - [mapTable setValue: (void*)1 - forKey: object]; + [_mapTable setValue: (void*)1 + forKey: object]; objc_autoreleasePoolPop(pool); } @catch (id e) { [self release]; @throw e; @@ -140,12 +140,12 @@ OFEnumerator *enumerator; id object; enumerator = [array objectEnumerator]; while ((object = [enumerator nextObject]) != nil) - [mapTable setValue: (void*)1 - forKey: object]; + [_mapTable setValue: (void*)1 + forKey: object]; objc_autoreleasePoolPop(pool); } @catch (id e) { [self release]; @throw e; @@ -161,12 +161,12 @@ @try { size_t i; for (i = 0; i < count; i++) - [mapTable setValue: (void*)1 - forKey: objects[i]]; + [_mapTable setValue: (void*)1 + forKey: objects[i]]; } @catch (id e) { [self release]; @throw e; } @@ -185,21 +185,21 @@ va_copy(argumentsCopy, arguments); for (count = 1; va_arg(argumentsCopy, id) != nil; count++); - mapTable = [[OFMapTable alloc] + _mapTable = [[OFMapTable alloc] initWithKeyFunctions: keyFunctions valueFunctions: valueFunctions capacity: count]; - [mapTable setValue: (void*)1 - forKey: firstObject]; + [_mapTable setValue: (void*)1 + forKey: firstObject]; while ((object = va_arg(arguments, id)) != nil) - [mapTable setValue: (void*)1 - forKey: object]; + [_mapTable setValue: (void*)1 + forKey: object]; } @catch (id e) { [self release]; @throw e; } @@ -225,12 +225,12 @@ enumerator = [[element elementsForNamespace: OF_SERIALIZATION_NS] objectEnumerator]; while ((child = [enumerator nextObject]) != nil) { void *pool2 = objc_autoreleasePoolPush(); - [mapTable setValue: (void*)1 - forKey: [child objectByDeserializing]]; + [_mapTable setValue: (void*)1 + forKey: [child objectByDeserializing]]; objc_autoreleasePoolPop(pool2); } objc_autoreleasePoolPop(pool); @@ -242,63 +242,63 @@ return self; } - (void)dealloc { - [mapTable release]; + [_mapTable release]; [super dealloc]; } - (size_t)count { - return [mapTable count]; + return [_mapTable count]; } - (BOOL)containsObject: (id)object { if (object == nil) return NO; - return ([mapTable valueForKey: object] != nil); + return ([_mapTable valueForKey: object] != nil); } - (BOOL)isEqual: (id)object { - OFSet_hashtable *otherSet; + OFSet_hashtable *set; if (![object isKindOfClass: [OFSet_hashtable class]] && ![object isKindOfClass: [OFMutableSet_hashtable class]] && ![object isKindOfClass: [OFCountedSet_hashtable class]]) return [super isEqual: object]; - otherSet = object; + set = object; - return [otherSet->mapTable isEqual: mapTable]; + return [set->_mapTable isEqual: _mapTable]; } - (OFEnumerator*)objectEnumerator { return [[[OFMapTableEnumeratorWrapper alloc] - initWithEnumerator: [mapTable keyEnumerator] + initWithEnumerator: [_mapTable keyEnumerator] object: self] autorelease]; } - (int)countByEnumeratingWithState: (of_fast_enumeration_state_t*)state objects: (id*)objects count: (int)count { - return [mapTable countByEnumeratingWithState: state - objects: objects - count: count]; + return [_mapTable countByEnumeratingWithState: state + objects: objects + count: count]; } #ifdef OF_HAVE_BLOCKS - (void)enumerateObjectsUsingBlock: (of_set_enumeration_block_t)block { @try { - [mapTable enumerateKeysAndValuesUsingBlock: + [_mapTable enumerateKeysAndValuesUsingBlock: ^ (void *key, void *value, BOOL *stop) { block(key, stop); }]; } @catch (OFEnumerationMutationException *e) { @throw [OFEnumerationMutationException Index: src/OFSortedList.m ================================================================== --- src/OFSortedList.m +++ src/OFSortedList.m @@ -49,14 +49,14 @@ - (of_list_object_t*)insertObject: (id )object { of_list_object_t *iter; - for (iter = lastListObject; iter != NULL; iter = iter->previous) { + for (iter = _lastListObject; iter != NULL; iter = iter->previous) { if ([object compare: iter->object] != OF_ORDERED_ASCENDING) return [super insertObject: object afterListObject: iter]; } return [super prependObject: object]; } @end Index: src/OFStream.h ================================================================== --- src/OFStream.h +++ src/OFStream.h @@ -55,15 +55,15 @@ * override these methods without the lowlevel prefix, you *will* break * caching and get broken results! */ @interface OFStream: OFObject { - char *cache; - char *writeBuffer; - size_t cacheLength, writeBufferLength; - BOOL writeBufferEnabled; - BOOL blocking, waitingForDelimiter; + char *_cache; + char *_writeBuffer; + size_t _cacheLength, _writeBufferLength; + BOOL _writeBufferEnabled; + BOOL _blocking, _waitingForDelimiter; } #ifdef OF_HAVE_PROPERTIES @property (getter=isWriteBufferEnabled) BOOL writeBufferEnabled; @property (getter=isBlocking) BOOL blocking; Index: src/OFStream.m ================================================================== --- src/OFStream.m +++ src/OFStream.m @@ -66,13 +66,11 @@ } } self = [super init]; - cache = NULL; - writeBuffer = NULL; - blocking = YES; + _blocking = YES; return self; } - (BOOL)lowlevelIsAtEndOfStream @@ -100,41 +98,41 @@ return [self retain]; } - (BOOL)isAtEndOfStream { - if (cacheLength > 0) + if (_cacheLength > 0) return NO; return [self lowlevelIsAtEndOfStream]; } - (size_t)readIntoBuffer: (void*)buffer length: (size_t)length { - if (cacheLength == 0) + if (_cacheLength == 0) return [self lowlevelReadIntoBuffer: buffer length: length]; - if (length >= cacheLength) { - size_t ret = cacheLength; - memcpy(buffer, cache, cacheLength); + if (length >= _cacheLength) { + size_t ret = _cacheLength; + memcpy(buffer, _cache, _cacheLength); - [self freeMemory: cache]; - cache = NULL; - cacheLength = 0; + [self freeMemory: _cache]; + _cache = NULL; + _cacheLength = 0; return ret; } else { - char *tmp = [self allocMemoryWithSize: cacheLength - length]; - memcpy(tmp, cache + length, cacheLength - length); - - memcpy(buffer, cache, length); - - [self freeMemory: cache]; - cache = tmp; - cacheLength -= length; + char *tmp = [self allocMemoryWithSize: _cacheLength - length]; + memcpy(tmp, _cache + length, _cacheLength - length); + + memcpy(buffer, _cache, length); + + [self freeMemory: _cache]; + _cache = tmp; + _cacheLength -= length; return length; } } @@ -570,33 +568,34 @@ size_t i, pageSize, bufferLength, retLength; char *retCString, *buffer, *newCache; OFString *ret; /* Look if there's a line or \0 in our cache */ - if (!waitingForDelimiter && cache != NULL) { - for (i = 0; i < cacheLength; i++) { - if OF_UNLIKELY (cache[i] == '\n' || cache[i] == '\0') { + if (!_waitingForDelimiter && _cache != NULL) { + for (i = 0; i < _cacheLength; i++) { + if OF_UNLIKELY (_cache[i] == '\n' || + _cache[i] == '\0') { retLength = i; - if (i > 0 && cache[i - 1] == '\r') + if (i > 0 && _cache[i - 1] == '\r') retLength--; - ret = [OFString stringWithCString: cache + ret = [OFString stringWithCString: _cache encoding: encoding length: retLength]; newCache = [self - allocMemoryWithSize: cacheLength - i - 1]; + allocMemoryWithSize: _cacheLength - i - 1]; if (newCache != NULL) - memcpy(newCache, cache + i + 1, - cacheLength - i - 1); - - [self freeMemory: cache]; - cache = newCache; - cacheLength -= i + 1; - - waitingForDelimiter = NO; + memcpy(newCache, _cache + i + 1, + _cacheLength - i - 1); + + [self freeMemory: _cache]; + _cache = newCache; + _cacheLength -= i + 1; + + _waitingForDelimiter = NO; return ret; } } } @@ -604,29 +603,29 @@ pageSize = [OFSystemInfo pageSize]; buffer = [self allocMemoryWithSize: pageSize]; @try { if ([self lowlevelIsAtEndOfStream]) { - if (cache == NULL) { - waitingForDelimiter = NO; + if (_cache == NULL) { + _waitingForDelimiter = NO; return nil; } - retLength = cacheLength; + retLength = _cacheLength; - if (retLength > 0 && cache[retLength - 1] == '\r') + if (retLength > 0 && _cache[retLength - 1] == '\r') retLength--; - ret = [OFString stringWithCString: cache + ret = [OFString stringWithCString: _cache encoding: encoding length: retLength]; - [self freeMemory: cache]; - cache = NULL; - cacheLength = 0; + [self freeMemory: _cache]; + _cache = NULL; + _cacheLength = 0; - waitingForDelimiter = NO; + _waitingForDelimiter = NO; return ret; } bufferLength = [self lowlevelReadIntoBuffer: buffer length: pageSize]; @@ -633,17 +632,18 @@ /* Look if there's a newline or \0 */ for (i = 0; i < bufferLength; i++) { if OF_UNLIKELY (buffer[i] == '\n' || buffer[i] == '\0') { - retLength = cacheLength + i; + retLength = _cacheLength + i; retCString = [self allocMemoryWithSize: retLength]; - if (cache != NULL) - memcpy(retCString, cache, cacheLength); - memcpy(retCString + cacheLength, buffer, i); + if (_cache != NULL) + memcpy(retCString, _cache, + _cacheLength); + memcpy(retCString + _cacheLength, buffer, i); if (retLength > 0 && retCString[retLength - 1] == '\r') retLength--; @@ -658,20 +658,20 @@ } @catch (id e) { /* * Append data to cache to prevent loss * of data due to wrong encoding. */ - cache = [self - resizeMemory: cache - size: cacheLength + + _cache = [self + resizeMemory: _cache + size: _cacheLength + bufferLength]; - if (cache != NULL) - memcpy(cache + cacheLength, + if (_cache != NULL) + memcpy(_cache + _cacheLength, buffer, bufferLength); - cacheLength += bufferLength; + _cacheLength += bufferLength; @throw e; } @finally { [self freeMemory: retCString]; } @@ -680,36 +680,36 @@ bufferLength - i - 1]; if (newCache != NULL) memcpy(newCache, buffer + i + 1, bufferLength - i - 1); - [self freeMemory: cache]; - cache = newCache; - cacheLength = bufferLength - i - 1; + [self freeMemory: _cache]; + _cache = newCache; + _cacheLength = bufferLength - i - 1; - waitingForDelimiter = NO; + _waitingForDelimiter = NO; return ret; } } /* There was no newline or \0 */ - cache = [self resizeMemory: cache - size: cacheLength + bufferLength]; + _cache = [self resizeMemory: _cache + size: _cacheLength + bufferLength]; /* - * It's possible that cacheLen + len is 0 and thus cache was - * set to NULL by resizeMemory:size:. + * It's possible that _cacheLength + bufferLength is 0 and thus + * _cache was set to NULL by resizeMemory:size:. */ - if (cache != NULL) - memcpy(cache + cacheLength, buffer, bufferLength); + if (_cache != NULL) + memcpy(_cache + _cacheLength, buffer, bufferLength); - cacheLength += bufferLength; + _cacheLength += bufferLength; } @finally { [self freeMemory: buffer]; } - waitingForDelimiter = YES; + _waitingForDelimiter = YES; return nil; } - (OFString*)readLine { @@ -782,35 +782,35 @@ @throw [OFInvalidArgumentException exceptionWithClass: [self class] selector: _cmd]; /* Look if there's something in our cache */ - if (!waitingForDelimiter && cache != NULL) { - for (i = 0; i < cacheLength; i++) { - if (cache[i] != delimiterCString[j++]) + if (!_waitingForDelimiter && _cache != NULL) { + for (i = 0; i < _cacheLength; i++) { + if (_cache[i] != delimiterCString[j++]) j = 0; - if (j == delimiterLength || cache[i] == '\0') { - if (cache[i] == '\0') + if (j == delimiterLength || _cache[i] == '\0') { + if (_cache[i] == '\0') delimiterLength = 1; ret = [OFString - stringWithCString: cache + stringWithCString: _cache encoding: encoding length: i + 1 - delimiterLength]; newCache = [self allocMemoryWithSize: - cacheLength - i - 1]; + _cacheLength - i - 1]; if (newCache != NULL) - memcpy(newCache, cache + i + 1, - cacheLength - i - 1); - - [self freeMemory: cache]; - cache = newCache; - cacheLength -= i + 1; - - waitingForDelimiter = NO; + memcpy(newCache, _cache + i + 1, + _cacheLength - i - 1); + + [self freeMemory: _cache]; + _cache = newCache; + _cacheLength -= i + 1; + + _waitingForDelimiter = NO; return ret; } } } @@ -818,24 +818,24 @@ pageSize = [OFSystemInfo pageSize]; buffer = [self allocMemoryWithSize: pageSize]; @try { if ([self lowlevelIsAtEndOfStream]) { - if (cache == NULL) { - waitingForDelimiter = NO; + if (_cache == NULL) { + _waitingForDelimiter = NO; return nil; } - ret = [OFString stringWithCString: cache + ret = [OFString stringWithCString: _cache encoding: encoding - length: cacheLength]; + length: _cacheLength]; - [self freeMemory: cache]; - cache = NULL; - cacheLength = 0; + [self freeMemory: _cache]; + _cache = NULL; + _cacheLength = 0; - waitingForDelimiter = NO; + _waitingForDelimiter = NO; return ret; } bufferLength = [self lowlevelReadIntoBuffer: buffer length: pageSize]; @@ -847,21 +847,22 @@ if (j == delimiterLength || buffer[i] == '\0') { if (buffer[i] == '\0') delimiterLength = 1; - retLength = cacheLength + i + 1 - + retLength = _cacheLength + i + 1 - delimiterLength; retCString = [self allocMemoryWithSize: retLength]; - if (cache != NULL && cacheLength <= retLength) - memcpy(retCString, cache, cacheLength); - else if (cache != NULL) - memcpy(retCString, cache, retLength); + if (_cache != NULL && _cacheLength <= retLength) + memcpy(retCString, _cache, + _cacheLength); + else if (_cache != NULL) + memcpy(retCString, _cache, retLength); if (i >= delimiterLength) - memcpy(retCString + cacheLength, + memcpy(retCString + _cacheLength, buffer, i + 1 - delimiterLength); @try { char *rcs = retCString; size_t rl = retLength; @@ -878,37 +879,36 @@ bufferLength - i - 1]; if (newCache != NULL) memcpy(newCache, buffer + i + 1, bufferLength - i - 1); - [self freeMemory: cache]; - cache = newCache; - cacheLength = bufferLength - i - 1; + [self freeMemory: _cache]; + _cache = newCache; + _cacheLength = bufferLength - i - 1; - waitingForDelimiter = NO; + _waitingForDelimiter = NO; return ret; } } /* Neither the delimiter nor \0 was found */ - cache = [self resizeMemory: cache - size: cacheLength + bufferLength]; + _cache = [self resizeMemory: _cache + size: _cacheLength + bufferLength]; /* - * It's possible that cacheLen + len is 0 and thus cache was - * set to NULL by resizeMemory:size:. + * It's possible that _cacheLength + bufferLength is 0 and thus + * _cache was set to NULL by resizeMemory:size:. */ - if (cache != NULL) - memcpy(cache + cacheLength, buffer, - bufferLength); + if (_cache != NULL) + memcpy(_cache + _cacheLength, buffer, bufferLength); - cacheLength += bufferLength; + _cacheLength += bufferLength; } @finally { [self freeMemory: buffer]; } - waitingForDelimiter = YES; + _waitingForDelimiter = YES; return nil; } - (OFString*)readTillDelimiter: (OFString*)delimiter @@ -937,42 +937,42 @@ encoding: OF_STRING_ENCODING_UTF_8]; } - (BOOL)isWriteBufferEnabled { - return writeBufferEnabled; + return _writeBufferEnabled; } - (void)setWriteBufferEnabled: (BOOL)enable { - writeBufferEnabled = enable; + _writeBufferEnabled = enable; } - (void)flushWriteBuffer { - if (writeBuffer == NULL) + if (_writeBuffer == NULL) return; - [self lowlevelWriteBuffer: writeBuffer - length: writeBufferLength]; + [self lowlevelWriteBuffer: _writeBuffer + length: _writeBufferLength]; - [self freeMemory: writeBuffer]; - writeBuffer = NULL; - writeBufferLength = 0; + [self freeMemory: _writeBuffer]; + _writeBuffer = NULL; + _writeBufferLength = 0; } - (void)writeBuffer: (const void*)buffer length: (size_t)length { - if (!writeBufferEnabled) + if (!_writeBufferEnabled) [self lowlevelWriteBuffer: buffer length: length]; else { - writeBuffer = [self resizeMemory: writeBuffer - size: writeBufferLength + length]; - memcpy(writeBuffer + writeBufferLength, buffer, length); - writeBufferLength += length; + _writeBuffer = [self resizeMemory: _writeBuffer + size: _writeBufferLength + length]; + memcpy(_writeBuffer + _writeBufferLength, buffer, length); + _writeBufferLength += length; } } - (void)writeInt8: (uint8_t)int8 { @@ -1454,16 +1454,16 @@ return length; } - (size_t)pendingBytes { - return cacheLength; + return _cacheLength; } - (BOOL)isBlocking { - return blocking; + return _blocking; } - (void)setBlocking: (BOOL)enable { #ifndef _WIN32 @@ -1521,10 +1521,12 @@ if (!readImplemented && !writeImplemented) @throw [OFNotImplementedException exceptionWithClass: [self class] selector: _cmd]; + + _blocking = enable; #else [self doesNotRecognizeSelector: _cmd]; abort(); #endif } @@ -1552,8 +1554,8 @@ abort(); } - (BOOL)OF_isWaitingForDelimiter { - return waitingForDelimiter; + return _waitingForDelimiter; } @end Index: src/OFStreamObserver.h ================================================================== --- src/OFStreamObserver.h +++ src/OFStreamObserver.h @@ -75,23 +75,23 @@ * * @note Currently, Win32 can only observe sockets and not files! */ @interface OFStreamObserver: OFObject { - OFMutableArray *readStreams; - OFMutableArray *writeStreams; - __unsafe_unretained OFStream **FDToStream; - size_t maxFD; - OFMutableArray *queue; - OFDataArray *queueInfo, *queueFDs; - id delegate; - int cancelFD[2]; + OFMutableArray *_readStreams; + OFMutableArray *_writeStreams; + __unsafe_unretained OFStream **_FDToStream; + size_t _maxFD; + OFMutableArray *_queue; + OFDataArray *_queueInfo, *_queueFDs; + id _delegate; + int _cancelFD[2]; #ifdef _WIN32 - struct sockaddr_in cancelAddr; + struct sockaddr_in _cancelAddr; #endif #ifdef OF_HAVE_THREADS - OFMutex *mutex; + OFMutex *_mutex; #endif } #ifdef OF_HAVE_PROPERTIES @property (assign) id delegate; Index: src/OFStreamObserver.m ================================================================== --- src/OFStreamObserver.m +++ src/OFStreamObserver.m @@ -100,58 +100,59 @@ #ifdef _WIN32 struct sockaddr_in cancelAddr2; socklen_t cancelAddrLen; #endif - readStreams = [[OFMutableArray alloc] init]; - writeStreams = [[OFMutableArray alloc] init]; - queue = [[OFMutableArray alloc] init]; - queueInfo = [[OFDataArray alloc] initWithItemSize: sizeof(int)]; - queueFDs = [[OFDataArray alloc] initWithItemSize: sizeof(int)]; + _readStreams = [[OFMutableArray alloc] init]; + _writeStreams = [[OFMutableArray alloc] init]; + _queue = [[OFMutableArray alloc] init]; + _queueInfo = [[OFDataArray alloc] + initWithItemSize: sizeof(int)]; + _queueFDs = [[OFDataArray alloc] initWithItemSize: sizeof(int)]; #ifndef _WIN32 - if (pipe(cancelFD)) + if (pipe(_cancelFD)) @throw [OFInitializationFailedException exceptionWithClass: [self class]]; #else /* Make sure WSAStartup has been called */ [OFTCPSocket class]; - cancelFD[0] = socket(AF_INET, SOCK_DGRAM, 0); - cancelFD[1] = socket(AF_INET, SOCK_DGRAM, 0); + _cancelFD[0] = socket(AF_INET, SOCK_DGRAM, 0); + _cancelFD[1] = socket(AF_INET, SOCK_DGRAM, 0); - if (cancelFD[0] == INVALID_SOCKET || - cancelFD[1] == INVALID_SOCKET) + if (_cancelFD[0] == INVALID_SOCKET || + _cancelFD[1] == INVALID_SOCKET) @throw [OFInitializationFailedException exceptionWithClass: [self class]]; - cancelAddr.sin_family = AF_INET; - cancelAddr.sin_port = 0; - cancelAddr.sin_addr.s_addr = inet_addr("127.0.0.1"); - cancelAddr2 = cancelAddr; + _cancelAddr.sin_family = AF_INET; + _cancelAddr.sin_port = 0; + _cancelAddr.sin_addr.s_addr = inet_addr("127.0.0.1"); + cancelAddr2 = _cancelAddr; - if (bind(cancelFD[0], (struct sockaddr*)&cancelAddr, - sizeof(cancelAddr)) || bind(cancelFD[1], + if (bind(_cancelFD[0], (struct sockaddr*)&_cancelAddr, + sizeof(_cancelAddr)) || bind(_cancelFD[1], (struct sockaddr*)&cancelAddr2, sizeof(cancelAddr2))) @throw [OFInitializationFailedException exceptionWithClass: [self class]]; - cancelAddrLen = sizeof(cancelAddr); + cancelAddrLen = sizeof(_cancelAddr); - if (getsockname(cancelFD[0], (struct sockaddr*)&cancelAddr, + if (getsockname(_cancelFD[0], (struct sockaddr*)&_cancelAddr, &cancelAddrLen)) @throw [OFInitializationFailedException exceptionWithClass: [self class]]; #endif - maxFD = cancelFD[0]; - FDToStream = [self allocMemoryWithSize: sizeof(OFStream*) - count: maxFD + 1]; - FDToStream[cancelFD[0]] = nil; + _maxFD = _cancelFD[0]; + _FDToStream = [self allocMemoryWithSize: sizeof(OFStream*) + count: _maxFD + 1]; + _FDToStream[_cancelFD[0]] = nil; #ifdef OF_HAVE_THREADS - mutex = [[OFMutex alloc] init]; + _mutex = [[OFMutex alloc] init]; #endif } @catch (id e) { [self release]; @throw e; } @@ -159,127 +160,117 @@ return self; } - (void)dealloc { - close(cancelFD[0]); - close(cancelFD[1]); - - [readStreams release]; - [writeStreams release]; - [queue release]; - [queueInfo release]; - [queueFDs release]; + close(_cancelFD[0]); + close(_cancelFD[1]); + + [_readStreams release]; + [_writeStreams release]; + [_queue release]; + [_queueInfo release]; + [_queueFDs release]; #ifdef OF_HAVE_THREADS - [mutex release]; + [_mutex release]; #endif [super dealloc]; } - (id )delegate { - return delegate; + return _delegate; } -- (void)setDelegate: (id )delegate_ +- (void)setDelegate: (id )delegate { - delegate = delegate_; + _delegate = delegate; } - (void)addStreamForReading: (OFStream*)stream { #ifdef OF_HAVE_THREADS - [mutex lock]; + [_mutex lock]; #endif @try { int qi = QUEUE_ADD | QUEUE_READ; int fd = [stream fileDescriptorForReading]; - [queue addObject: stream]; - [queueInfo addItem: &qi]; - [queueFDs addItem: &fd]; + [_queue addObject: stream]; + [_queueInfo addItem: &qi]; + [_queueFDs addItem: &fd]; } @finally { #ifdef OF_HAVE_THREADS - [mutex unlock]; + [_mutex unlock]; #endif } [self cancel]; } - (void)addStreamForWriting: (OFStream*)stream { #ifdef OF_HAVE_THREADS - [mutex lock]; + [_mutex lock]; #endif @try { int qi = QUEUE_ADD | QUEUE_WRITE; int fd = [stream fileDescriptorForWriting]; - [queue addObject: stream]; - [queueInfo addItem: &qi]; - [queueFDs addItem: &fd]; + [_queue addObject: stream]; + [_queueInfo addItem: &qi]; + [_queueFDs addItem: &fd]; } @finally { #ifdef OF_HAVE_THREADS - [mutex unlock]; + [_mutex unlock]; #endif } [self cancel]; } - (void)removeStreamForReading: (OFStream*)stream { #ifdef OF_HAVE_THREADS - [mutex lock]; + [_mutex lock]; #endif @try { int qi = QUEUE_REMOVE | QUEUE_READ; int fd = [stream fileDescriptorForReading]; - [queue addObject: stream]; - [queueInfo addItem: &qi]; - [queueFDs addItem: &fd]; + [_queue addObject: stream]; + [_queueInfo addItem: &qi]; + [_queueFDs addItem: &fd]; } @finally { #ifdef OF_HAVE_THREADS - [mutex unlock]; + [_mutex unlock]; #endif } -#ifndef _WIN32 - OF_ENSURE(write(cancelFD[1], "", 1) > 0); -#else - OF_ENSURE(sendto(cancelFD[1], "", 1, 0, (struct sockaddr*)&cancelAddr, - sizeof(cancelAddr)) > 0); -#endif + [self cancel]; } - (void)removeStreamForWriting: (OFStream*)stream { #ifdef OF_HAVE_THREADS - [mutex lock]; + [_mutex lock]; #endif @try { int qi = QUEUE_REMOVE | QUEUE_WRITE; int fd = [stream fileDescriptorForWriting]; - [queue addObject: stream]; - [queueInfo addItem: &qi]; - [queueFDs addItem: &fd]; + [_queue addObject: stream]; + [_queueInfo addItem: &qi]; + [_queueFDs addItem: &fd]; } @finally { #ifdef OF_HAVE_THREADS - [mutex unlock]; + [_mutex unlock]; #endif } -#ifndef _WIN32 - OF_ENSURE(write(cancelFD[1], "", 1) > 0); -#else - OF_ENSURE(sendto(cancelFD[1], "", 1, 0, (struct sockaddr*)&cancelAddr, - sizeof(cancelAddr)) > 0); -#endif + [self cancel]; } - (void)OF_addFileDescriptorForReading: (int)fd { [self doesNotRecognizeSelector: _cmd]; @@ -305,76 +296,76 @@ } - (void)OF_processQueue { #ifdef OF_HAVE_THREADS - [mutex lock]; + [_mutex lock]; #endif @try { - OFStream **queueObjects = [queue objects]; - int *queueInfoItems = [queueInfo items]; - int *queueFDsItems = [queueFDs items]; - size_t i, count = [queue count]; + OFStream **queueObjects = [_queue objects]; + int *queueInfoItems = [_queueInfo items]; + int *queueFDsItems = [_queueFDs items]; + size_t i, count = [_queue count]; for (i = 0; i < count; i++) { OFStream *stream = queueObjects[i]; int action = queueInfoItems[i]; int fd = queueFDsItems[i]; if ((action & QUEUE_ACTION) == QUEUE_ADD) { - if (fd > maxFD) { - maxFD = fd; - FDToStream = [self - resizeMemory: FDToStream + if (fd > _maxFD) { + _maxFD = fd; + _FDToStream = [self + resizeMemory: _FDToStream size: sizeof(OFStream*) - count: maxFD + 1]; + count: _maxFD + 1]; } - FDToStream[fd] = stream; + _FDToStream[fd] = stream; } if ((action & QUEUE_ACTION) == QUEUE_REMOVE) { /* FIXME: Maybe downsize? */ - FDToStream[fd] = nil; + _FDToStream[fd] = nil; } switch (action) { case QUEUE_ADD | QUEUE_READ: - [readStreams addObject: stream]; + [_readStreams addObject: stream]; [self OF_addFileDescriptorForReading: fd]; break; case QUEUE_ADD | QUEUE_WRITE: - [writeStreams addObject: stream]; + [_writeStreams addObject: stream]; [self OF_addFileDescriptorForWriting: fd]; break; case QUEUE_REMOVE | QUEUE_READ: - [readStreams removeObjectIdenticalTo: stream]; + [_readStreams removeObjectIdenticalTo: stream]; [self OF_removeFileDescriptorForReading: fd]; break; case QUEUE_REMOVE | QUEUE_WRITE: - [writeStreams removeObjectIdenticalTo: stream]; + [_writeStreams removeObjectIdenticalTo: stream]; [self OF_removeFileDescriptorForWriting: fd]; break; default: assert(0); } } - [queue removeAllObjects]; - [queueInfo removeAllItems]; - [queueFDs removeAllItems]; + [_queue removeAllObjects]; + [_queueInfo removeAllItems]; + [_queueFDs removeAllItems]; } @finally { #ifdef OF_HAVE_THREADS - [mutex unlock]; + [_mutex unlock]; #endif } } - (void)observe @@ -389,32 +380,31 @@ } - (void)cancel { #ifndef _WIN32 - OF_ENSURE(write(cancelFD[1], "", 1) > 0); + OF_ENSURE(write(_cancelFD[1], "", 1) > 0); #else - OF_ENSURE(sendto(cancelFD[1], "", 1, 0, (struct sockaddr*)&cancelAddr, - sizeof(cancelAddr)) > 0); + OF_ENSURE(sendto(_cancelFD[1], "", 1, 0, (struct sockaddr*)&_cancelAddr, + sizeof(_cancelAddr)) > 0); #endif } - (BOOL)OF_processCache { - OFStream **objects = [readStreams objects]; - size_t i, count = [readStreams count]; + OFStream **objects = [_readStreams objects]; + size_t i, count = [_readStreams count]; BOOL foundInCache = NO; - for (i = 0; i < count; i++) { if ([objects[i] pendingBytes] > 0 && ![objects[i] OF_isWaitingForDelimiter]) { void *pool = objc_autoreleasePoolPush(); - if ([delegate respondsToSelector: + if ([_delegate respondsToSelector: @selector(streamIsReadyForReading:)]) - [delegate streamIsReadyForReading: objects[i]]; + [_delegate streamIsReadyForReading: objects[i]]; foundInCache = YES; objc_autoreleasePoolPop(pool); } Index: src/OFStreamObserver_kqueue.h ================================================================== --- src/OFStreamObserver_kqueue.h +++ src/OFStreamObserver_kqueue.h @@ -18,9 +18,9 @@ @class OFDataArray; @interface OFStreamObserver_kqueue: OFStreamObserver { - int kernelQueue; - OFDataArray *changeList; + int _kernelQueue; + OFDataArray *_changeList; } @end Index: src/OFStreamObserver_kqueue.m ================================================================== --- src/OFStreamObserver_kqueue.m +++ src/OFStreamObserver_kqueue.m @@ -41,18 +41,18 @@ - init { self = [super init]; @try { - if ((kernelQueue = kqueue()) == -1) + if ((_kernelQueue = kqueue()) == -1) @throw [OFInitializationFailedException exceptionWithClass: [self class]]; - changeList = [[OFDataArray alloc] initWithItemSize: + _changeList = [[OFDataArray alloc] initWithItemSize: sizeof(struct kevent)]; - [self OF_addFileDescriptorForReading: cancelFD[0]]; + [self OF_addFileDescriptorForReading: _cancelFD[0]]; } @catch (id e) { [self release]; @throw e; } @@ -59,52 +59,52 @@ return self; } - (void)dealloc { - close(kernelQueue); - [changeList release]; + close(_kernelQueue); + [_changeList release]; [super dealloc]; } - (void)OF_addFileDescriptorForReading: (int)fd { struct kevent event; - if ([changeList count] >= INT_MAX) + if ([_changeList count] >= INT_MAX) @throw [OFOutOfRangeException exceptionWithClass: [self class]]; EV_SET(&event, fd, EVFILT_READ, EV_ADD, 0, 0, 0); - [changeList addItem: &event]; + [_changeList addItem: &event]; } - (void)OF_addFileDescriptorForWriting: (int)fd { struct kevent event; - if ([changeList count] >= INT_MAX) + if ([_changeList count] >= INT_MAX) @throw [OFOutOfRangeException exceptionWithClass: [self class]]; EV_SET(&event, fd, EVFILT_WRITE, EV_ADD, 0, 0, 0); - [changeList addItem: &event]; + [_changeList addItem: &event]; } - (void)OF_removeFileDescriptorForReading: (int)fd { struct kevent event; EV_SET(&event, fd, EVFILT_READ, EV_DELETE, 0, 0, 0); - [changeList addItem: &event]; + [_changeList addItem: &event]; } - (void)OF_removeFileDescriptorForWriting: (int)fd { struct kevent event; EV_SET(&event, fd, EVFILT_WRITE, EV_DELETE, 0, 0, 0); - [changeList addItem: &event]; + [_changeList addItem: &event]; } - (BOOL)observeWithTimeout: (double)timeout { void *pool = objc_autoreleasePoolPush(); @@ -122,57 +122,57 @@ return YES; } objc_autoreleasePoolPop(pool); - events = kevent(kernelQueue, [changeList items], - (int)[changeList count], eventList, EVENTLIST_SIZE, + events = kevent(_kernelQueue, [_changeList items], + (int)[_changeList count], eventList, EVENTLIST_SIZE, (timeout == -1 ? NULL : ×pec)); if (events < 0) return NO; - [changeList removeAllItems]; + [_changeList removeAllItems]; if (events == 0) return NO; for (i = 0; i < events; i++) { - if (eventList[i].ident == cancelFD[0]) { + if (eventList[i].ident == _cancelFD[0]) { char buffer; - OF_ENSURE(read(cancelFD[0], &buffer, 1) > 0); + OF_ENSURE(read(_cancelFD[0], &buffer, 1) > 0); continue; } realEvents++; pool = objc_autoreleasePoolPush(); if (eventList[i].flags & EV_ERROR) { - if ([delegate respondsToSelector: + if ([_delegate respondsToSelector: @selector(streamDidReceiveException:)]) - [delegate streamDidReceiveException: - FDToStream[eventList[i].ident]]; + [_delegate streamDidReceiveException: + _FDToStream[eventList[i].ident]]; objc_autoreleasePoolPop(pool); continue; } switch (eventList[i].filter) { case EVFILT_READ: - if ([delegate respondsToSelector: + if ([_delegate respondsToSelector: @selector(streamIsReadyForReading:)]) - [delegate streamIsReadyForReading: - FDToStream[eventList[i].ident]]; + [_delegate streamIsReadyForReading: + _FDToStream[eventList[i].ident]]; break; case EVFILT_WRITE: - if ([delegate respondsToSelector: + if ([_delegate respondsToSelector: @selector(streamIsReadyForWriting:)]) - [delegate streamIsReadyForWriting: - FDToStream[eventList[i].ident]]; + [_delegate streamIsReadyForWriting: + _FDToStream[eventList[i].ident]]; break; default: assert(0); } Index: src/OFStreamObserver_poll.h ================================================================== --- src/OFStreamObserver_poll.h +++ src/OFStreamObserver_poll.h @@ -18,8 +18,8 @@ @class OFDataArray; @interface OFStreamObserver_poll: OFStreamObserver { - OFDataArray *FDs; + OFDataArray *_FDs; } @end Index: src/OFStreamObserver_poll.m ================================================================== --- src/OFStreamObserver_poll.m +++ src/OFStreamObserver_poll.m @@ -35,15 +35,15 @@ self = [super init]; @try { struct pollfd p = { 0, POLLIN, 0 }; - FDs = [[OFDataArray alloc] initWithItemSize: + _FDs = [[OFDataArray alloc] initWithItemSize: sizeof(struct pollfd)]; - p.fd = cancelFD[0]; - [FDs addItem: &p]; + p.fd = _cancelFD[0]; + [_FDs addItem: &p]; } @catch (id e) { [self release]; @throw e; } @@ -50,48 +50,48 @@ return self; } - (void)dealloc { - [FDs release]; + [_FDs release]; [super dealloc]; } - (void)OF_addFileDescriptor: (int)fd withEvents: (short)events { - struct pollfd *FDs_ = [FDs items]; - size_t i, count = [FDs count]; + struct pollfd *FDs = [_FDs items]; + size_t i, count = [_FDs count]; BOOL found = NO; for (i = 0; i < count; i++) { - if (FDs_[i].fd == fd) { - FDs_[i].events |= events; + if (FDs[i].fd == fd) { + FDs[i].events |= events; found = YES; break; } } if (!found) { struct pollfd p = { fd, events | POLLERR, 0 }; - [FDs addItem: &p]; + [_FDs addItem: &p]; } } - (void)OF_removeFileDescriptor: (int)fd withEvents: (short)events { - struct pollfd *FDs_ = [FDs items]; - size_t i, nFDs = [FDs count]; + struct pollfd *FDs = [_FDs items]; + size_t i, nFDs = [_FDs count]; for (i = 0; i < nFDs; i++) { - if (FDs_[i].fd == fd) { - FDs_[i].events &= ~events; + if (FDs[i].fd == fd) { + FDs[i].events &= ~events; - if ((FDs_[i].events & ~POLLERR) == 0) - [FDs removeItemAtIndex: i]; + if ((FDs[i].events & ~POLLERR) == 0) + [_FDs removeItemAtIndex: i]; break; } } } @@ -121,11 +121,11 @@ } - (BOOL)observeWithTimeout: (double)timeout { void *pool = objc_autoreleasePoolPush(); - struct pollfd *FDs_; + struct pollfd *FDs; size_t i, nFDs, realEvents = 0; [self OF_processQueue]; if ([self OF_processCache]) { @@ -133,63 +133,63 @@ return YES; } objc_autoreleasePoolPop(pool); - FDs_ = [FDs items]; - nFDs = [FDs count]; + FDs = [_FDs items]; + nFDs = [_FDs count]; #ifdef OPEN_MAX if (nFDs > OPEN_MAX) @throw [OFOutOfRangeException exceptionWithClass: [self class]]; #endif - if (poll(FDs_, (nfds_t)nFDs, + if (poll(FDs, (nfds_t)nFDs, (int)(timeout != -1 ? timeout * 1000 : -1)) < 1) return NO; for (i = 0; i < nFDs; i++) { pool = objc_autoreleasePoolPush(); - if (FDs_[i].revents & POLLIN) { - if (FDs_[i].fd == cancelFD[0]) { + if (FDs[i].revents & POLLIN) { + if (FDs[i].fd == _cancelFD[0]) { char buffer; - OF_ENSURE(read(cancelFD[0], &buffer, 1) > 0); - FDs_[i].revents = 0; + OF_ENSURE(read(_cancelFD[0], &buffer, 1) > 0); + FDs[i].revents = 0; objc_autoreleasePoolPop(pool); continue; } - if ([delegate respondsToSelector: + if ([_delegate respondsToSelector: @selector(streamIsReadyForReading:)]) - [delegate streamIsReadyForReading: - FDToStream[FDs_[i].fd]]; + [_delegate streamIsReadyForReading: + _FDToStream[FDs[i].fd]]; + + realEvents++; + } + + if (FDs[i].revents & POLLOUT) { + if ([_delegate respondsToSelector: + @selector(streamIsReadyForWriting:)]) + [_delegate streamIsReadyForWriting: + _FDToStream[FDs[i].fd]]; realEvents++; } - if (FDs_[i].revents & POLLOUT) { - if ([delegate respondsToSelector: - @selector(streamIsReadyForWriting:)]) - [delegate streamIsReadyForWriting: - FDToStream[FDs_[i].fd]]; + if (FDs[i].revents & POLLERR) { + if ([_delegate respondsToSelector: + @selector(streamDidReceiveException:)]) + [_delegate streamDidReceiveException: + _FDToStream[FDs[i].fd]]; realEvents++; } - if (FDs_[i].revents & POLLERR) { - if ([delegate respondsToSelector: - @selector(streamDidReceiveException:)]) - [delegate streamDidReceiveException: - FDToStream[FDs_[i].fd]]; - - realEvents++; - } - - FDs_[i].revents = 0; + FDs[i].revents = 0; objc_autoreleasePoolPop(pool); } if (realEvents == 0) Index: src/OFStreamObserver_select.h ================================================================== --- src/OFStreamObserver_select.h +++ src/OFStreamObserver_select.h @@ -27,10 +27,8 @@ #import "OFStreamObserver.h" @interface OFStreamObserver_select: OFStreamObserver { - fd_set readFDs; - fd_set writeFDs; - fd_set exceptFDs; + fd_set _readFDs, _writeFDs, _exceptFDs; } @end Index: src/OFStreamObserver_select.m ================================================================== --- src/OFStreamObserver_select.m +++ src/OFStreamObserver_select.m @@ -33,53 +33,53 @@ @implementation OFStreamObserver_select - init { self = [super init]; - FD_ZERO(&readFDs); - FD_ZERO(&writeFDs); + FD_ZERO(&_readFDs); + FD_ZERO(&_writeFDs); - FD_SET(cancelFD[0], &readFDs); + FD_SET(_cancelFD[0], &_readFDs); return self; } - (void)OF_addFileDescriptorForReading: (int)fd { - FD_SET(fd, &readFDs); - FD_SET(fd, &exceptFDs); + FD_SET(fd, &_readFDs); + FD_SET(fd, &_exceptFDs); } - (void)OF_addFileDescriptorForWriting: (int)fd { - FD_SET(fd, &writeFDs); - FD_SET(fd, &exceptFDs); + FD_SET(fd, &_writeFDs); + FD_SET(fd, &_exceptFDs); } - (void)OF_removeFileDescriptorForReading: (int)fd { - FD_CLR(fd, &readFDs); + FD_CLR(fd, &_readFDs); - if (!FD_ISSET(fd, &writeFDs)) - FD_CLR(fd, &exceptFDs); + if (!FD_ISSET(fd, &_writeFDs)) + FD_CLR(fd, &_exceptFDs); } - (void)OF_removeFileDescriptorForWriting: (int)fd { - FD_CLR(fd, &writeFDs); + FD_CLR(fd, &_writeFDs); - if (!FD_ISSET(fd, &readFDs)) - FD_CLR(fd, &exceptFDs); + if (!FD_ISSET(fd, &_readFDs)) + FD_CLR(fd, &_exceptFDs); } - (BOOL)observeWithTimeout: (double)timeout { void *pool = objc_autoreleasePoolPush(); OFStream **objects; - fd_set readFDs_; - fd_set writeFDs_; - fd_set exceptFDs_; + fd_set readFDs; + fd_set writeFDs; + fd_set exceptFDs; struct timeval time; size_t i, count, realEvents = 0; [self OF_processQueue]; @@ -89,17 +89,17 @@ } objc_autoreleasePoolPop(pool); #ifdef FD_COPY - FD_COPY(&readFDs, &readFDs_); - FD_COPY(&writeFDs, &writeFDs_); - FD_COPY(&exceptFDs, &exceptFDs_); + FD_COPY(&_readFDs, &readFDs); + FD_COPY(&_writeFDs, &writeFDs); + FD_COPY(&_exceptFDs, &exceptFDs); #else - readFDs_ = readFDs; - writeFDs_ = writeFDs; - exceptFDs_ = exceptFDs; + readFDs = _readFDs; + writeFDs = _writeFDs; + exceptFDs = _exceptFDs; #endif /* * We cast to int before assigning to tv_usec in order to avoid a * warning with Apple GCC on PPC. POSIX defines this as suseconds_t, @@ -107,77 +107,78 @@ * satisfy the required range, we just cast to int. */ time.tv_sec = (time_t)timeout; time.tv_usec = (int)((timeout - time.tv_sec) * 1000); - if (select((int)maxFD + 1, &readFDs_, &writeFDs_, &exceptFDs_, + if (select((int)_maxFD + 1, &readFDs, &writeFDs, &exceptFDs, (timeout != -1 ? &time : NULL)) < 1) return NO; - if (FD_ISSET(cancelFD[0], &readFDs_)) { + if (FD_ISSET(_cancelFD[0], &readFDs)) { char buffer; #ifndef _WIN32 - OF_ENSURE(read(cancelFD[0], &buffer, 1) > 0); + OF_ENSURE(read(_cancelFD[0], &buffer, 1) > 0); #else - OF_ENSURE(recvfrom(cancelFD[0], &buffer, 1, 0, NULL, NULL) > 0); + OF_ENSURE(recvfrom(_cancelFD[0], &buffer, 1, 0, NULL, + NULL) > 0); #endif } - objects = [readStreams objects]; - count = [readStreams count]; + objects = [_readStreams objects]; + count = [_readStreams count]; for (i = 0; i < count; i++) { int fd = [objects[i] fileDescriptorForReading]; pool = objc_autoreleasePoolPush(); - if (FD_ISSET(fd, &readFDs_)) { - if ([delegate respondsToSelector: + if (FD_ISSET(fd, &readFDs)) { + if ([_delegate respondsToSelector: @selector(streamIsReadyForReading:)]) - [delegate streamIsReadyForReading: objects[i]]; + [_delegate streamIsReadyForReading: objects[i]]; realEvents++; } - if (FD_ISSET(fd, &exceptFDs_)) { - if ([delegate respondsToSelector: + if (FD_ISSET(fd, &exceptFDs)) { + if ([_delegate respondsToSelector: @selector(streamDidReceiveException:)]) - [delegate streamDidReceiveException: + [_delegate streamDidReceiveException: objects[i]]; /* * Prevent calling it twice in case the FD is in both * sets. */ - FD_CLR(fd, &exceptFDs_); + FD_CLR(fd, &exceptFDs); realEvents++; } objc_autoreleasePoolPop(pool); } - objects = [writeStreams objects]; - count = [writeStreams count]; + objects = [_writeStreams objects]; + count = [_writeStreams count]; for (i = 0; i < count; i++) { int fd = [objects[i] fileDescriptorForWriting]; pool = objc_autoreleasePoolPush(); - if (FD_ISSET(fd, &writeFDs_)) { - if ([delegate respondsToSelector: + if (FD_ISSET(fd, &writeFDs)) { + if ([_delegate respondsToSelector: @selector(streamIsReadyForWriting:)]) - [delegate streamIsReadyForWriting: objects[i]]; + [_delegate streamIsReadyForWriting: objects[i]]; realEvents++; } - if (FD_ISSET(fd, &exceptFDs_)) { - if ([delegate respondsToSelector: + if (FD_ISSET(fd, &exceptFDs)) { + if ([_delegate respondsToSelector: @selector(streamDidReceiveException:)]) - [delegate streamDidReceiveException: + [_delegate streamDidReceiveException: objects[i]]; realEvents++; } Index: src/OFStreamSocket.h ================================================================== --- src/OFStreamSocket.h +++ src/OFStreamSocket.h @@ -26,16 +26,16 @@ /*! * @brief A class which provides functions to create and use stream sockets. */ @interface OFStreamSocket: OFStream { - int sock; - BOOL atEndOfStream; + int _socket; + BOOL _atEndOfStream; } /*! * @brief Returns a new, autoreleased OFTCPSocket. * * @return A new, autoreleased OFTCPSocket */ + (instancetype)socket; @end Index: src/OFStreamSocket.m ================================================================== --- src/OFStreamSocket.m +++ src/OFStreamSocket.m @@ -65,114 +65,114 @@ return [[[self alloc] init] autorelease]; } - (BOOL)lowlevelIsAtEndOfStream { - return atEndOfStream; + return _atEndOfStream; } - (size_t)lowlevelReadIntoBuffer: (void*)buffer length: (size_t)length { ssize_t ret; - if (sock == INVALID_SOCKET) + if (_socket == INVALID_SOCKET) @throw [OFNotConnectedException exceptionWithClass: [self class] socket: self]; - if (atEndOfStream) { + if (_atEndOfStream) { OFReadFailedException *e; e = [OFReadFailedException exceptionWithClass: [self class] stream: self requestedLength: length]; #ifndef _WIN32 - e->errNo = ENOTCONN; + e->_errNo = ENOTCONN; #else - e->errNo = WSAENOTCONN; + e->_errNo = WSAENOTCONN; #endif @throw e; } - if ((ret = recv(sock, buffer, length, 0)) < 0) + if ((ret = recv(_socket, buffer, length, 0)) < 0) @throw [OFReadFailedException exceptionWithClass: [self class] stream: self requestedLength: length]; if (ret == 0) - atEndOfStream = YES; + _atEndOfStream = YES; return ret; } - (void)lowlevelWriteBuffer: (const void*)buffer length: (size_t)length { - if (sock == INVALID_SOCKET) + if (_socket == INVALID_SOCKET) @throw [OFNotConnectedException exceptionWithClass: [self class] socket: self]; - if (atEndOfStream) { + if (_atEndOfStream) { OFWriteFailedException *e; e = [OFWriteFailedException exceptionWithClass: [self class] stream: self requestedLength: length]; #ifndef _WIN32 - e->errNo = ENOTCONN; + e->_errNo = ENOTCONN; #else - e->errNo = WSAENOTCONN; + e->_errNo = WSAENOTCONN; #endif @throw e; } - if (send(sock, buffer, length, 0) < length) + if (send(_socket, buffer, length, 0) < length) @throw [OFWriteFailedException exceptionWithClass: [self class] stream: self requestedLength: length]; } #ifdef _WIN32 - (void)setBlocking: (BOOL)enable { u_long v = enable; - blocking = enable; + _blocking = enable; - if (ioctlsocket(sock, FIONBIO, &v) == SOCKET_ERROR) + if (ioctlsocket(_socket, FIONBIO, &v) == SOCKET_ERROR) @throw [OFSetOptionFailedException exceptionWithClass: [self class] stream: self]; } #endif - (int)fileDescriptorForReading { - return sock; + return _socket; } - (int)fileDescriptorForWriting { - return sock; + return _socket; } - (void)close { - if (sock == INVALID_SOCKET) + if (_socket == INVALID_SOCKET) @throw [OFNotConnectedException exceptionWithClass: [self class] socket: self]; - close(sock); + close(_socket); + _socket = INVALID_SOCKET; - sock = INVALID_SOCKET; - atEndOfStream = NO; + _atEndOfStream = NO; } - (void)dealloc { - if (sock != INVALID_SOCKET) + if (_socket != INVALID_SOCKET) [self close]; [super dealloc]; } @end Index: src/OFString_UTF8.h ================================================================== --- src/OFString_UTF8.h +++ src/OFString_UTF8.h @@ -20,24 +20,24 @@ { @public /* * A pointer to the actual data. * - * Since constant strings don't have s_store, they have to malloc it on - * the first access. Strings created at runtime just set the pointer to - * &s_store. + * Since constant strings don't have _storage, they have to malloc it + * on the first access. Strings created at runtime just set the pointer + * to &_storage. */ struct of_string_utf8_ivars { char *cString; size_t cStringLength; BOOL isUTF8; size_t length; BOOL hashed; uint32_t hash; char *freeWhenDone; - } *restrict s; - struct of_string_utf8_ivars s_store; + } *restrict _s; + struct of_string_utf8_ivars _storage; } - OF_initWithUTF8String: (const char*)UTF8String length: (size_t)UTF8StringLength storage: (char*)storage; Index: src/OFString_UTF8.m ================================================================== --- src/OFString_UTF8.m +++ src/OFString_UTF8.m @@ -153,14 +153,14 @@ - init { self = [super init]; @try { - s = &s_store; + _s = &_storage; - s->cString = [self allocMemoryWithSize: 1]; - s->cString[0] = '\0'; + _s->cString = [self allocMemoryWithSize: 1]; + _s->cString[0] = '\0'; } @catch (id e) { [self release]; @throw e; } @@ -178,27 +178,27 @@ !memcmp(UTF8String, "\xEF\xBB\xBF", 3)) { UTF8String += 3; UTF8StringLength -= 3; } - s = &s_store; + _s = &_storage; - s->cString = storage; - s->cStringLength = UTF8StringLength; + _s->cString = storage; + _s->cStringLength = UTF8StringLength; switch (of_string_utf8_check(UTF8String, UTF8StringLength, - &s->length)) { + &_s->length)) { case 1: - s->isUTF8 = YES; + _s->isUTF8 = YES; break; case -1: @throw [OFInvalidEncodingException exceptionWithClass: [self class]]; } - memcpy(s->cString, UTF8String, UTF8StringLength); - s->cString[UTF8StringLength] = 0; + memcpy(_s->cString, UTF8String, UTF8StringLength); + _s->cString[UTF8StringLength] = 0; } @catch (id e) { [self release]; @throw e; } @@ -219,68 +219,68 @@ cStringLength >= 3 && !memcmp(cString, "\xEF\xBB\xBF", 3)) { cString += 3; cStringLength -= 3; } - s = &s_store; + _s = &_storage; - s->cString = [self allocMemoryWithSize: cStringLength + 1]; - s->cStringLength = cStringLength; + _s->cString = [self allocMemoryWithSize: cStringLength + 1]; + _s->cStringLength = cStringLength; if (encoding == OF_STRING_ENCODING_UTF_8 || encoding == OF_STRING_ENCODING_ASCII) { switch (of_string_utf8_check(cString, cStringLength, - &s->length)) { + &_s->length)) { case 1: if (encoding == OF_STRING_ENCODING_ASCII) @throw [OFInvalidEncodingException exceptionWithClass: [self class]]; - s->isUTF8 = YES; + _s->isUTF8 = YES; break; case -1: @throw [OFInvalidEncodingException exceptionWithClass: [self class]]; } - memcpy(s->cString, cString, cStringLength); - s->cString[cStringLength] = 0; + memcpy(_s->cString, cString, cStringLength); + _s->cString[cStringLength] = 0; return self; } /* All other encodings we support are single byte encodings */ - s->length = cStringLength; + _s->length = cStringLength; if (encoding == OF_STRING_ENCODING_ISO_8859_1) { for (i = j = 0; i < cStringLength; i++) { char buffer[4]; size_t bytes; if (!(cString[i] & 0x80)) { - s->cString[j++] = cString[i]; + _s->cString[j++] = cString[i]; continue; } - s->isUTF8 = YES; + _s->isUTF8 = YES; bytes = of_string_utf8_encode( (uint8_t)cString[i], buffer); if (bytes == 0) @throw [OFInvalidEncodingException exceptionWithClass: [self class]]; - s->cStringLength += bytes - 1; - s->cString = [self - resizeMemory: s->cString - size: s->cStringLength + 1]; + _s->cStringLength += bytes - 1; + _s->cString = [self + resizeMemory: _s->cString + size: _s->cStringLength + 1]; - memcpy(s->cString + j, buffer, bytes); + memcpy(_s->cString + j, buffer, bytes); j += bytes; } - s->cString[s->cStringLength] = 0; + _s->cString[_s->cStringLength] = 0; return self; } switch (encoding) { @@ -299,37 +299,38 @@ char buffer[4]; of_unichar_t character; size_t characterBytes; if (!(cString[i] & 0x80)) { - s->cString[j++] = cString[i]; + _s->cString[j++] = cString[i]; continue; } character = table[(uint8_t)cString[i]]; if (character == 0xFFFD) @throw [OFInvalidEncodingException exceptionWithClass: [self class]]; - s->isUTF8 = YES; + _s->isUTF8 = YES; characterBytes = of_string_utf8_encode(character, buffer); if (characterBytes == 0) @throw [OFInvalidEncodingException exceptionWithClass: [self class]]; - s->cStringLength += characterBytes - 1; - s->cString = [self resizeMemory: s->cString - size: s->cStringLength + 1]; + _s->cStringLength += characterBytes - 1; + _s->cString = [self + resizeMemory: _s->cString + size: _s->cStringLength + 1]; - memcpy(s->cString + j, buffer, characterBytes); + memcpy(_s->cString + j, buffer, characterBytes); j += characterBytes; } - s->cString[s->cStringLength] = 0; + _s->cString[_s->cStringLength] = 0; } @catch (id e) { [self release]; @throw e; } @@ -348,22 +349,22 @@ !memcmp(UTF8String, "\xEF\xBB\xBF", 3)) { UTF8String += 3; UTF8StringLength -= 3; } - s = &s_store; + _s = &_storage; - s->cString = (char*)UTF8String; - s->cStringLength = UTF8StringLength; + _s->cString = (char*)UTF8String; + _s->cStringLength = UTF8StringLength; if (freeWhenDone) - s->freeWhenDone = UTF8String; + _s->freeWhenDone = UTF8String; switch (of_string_utf8_check(UTF8String, UTF8StringLength, - &s->length)) { + &_s->length)) { case 1: - s->isUTF8 = YES; + _s->isUTF8 = YES; break; case -1: @throw [OFInvalidEncodingException exceptionWithClass: [self class]]; } @@ -378,24 +379,24 @@ - initWithString: (OFString*)string { self = [super init]; @try { - s = &s_store; + _s = &_storage; - s->cStringLength = [string UTF8StringLength]; + _s->cStringLength = [string UTF8StringLength]; if ([string isKindOfClass: [OFString_UTF8 class]] || [string isKindOfClass: [OFMutableString_UTF8 class]]) - s->isUTF8 = ((OFString_UTF8*)string)->s->isUTF8; + _s->isUTF8 = ((OFString_UTF8*)string)->_s->isUTF8; else - s->isUTF8 = YES; + _s->isUTF8 = YES; - s->length = [string length]; + _s->length = [string length]; - s->cString = [self allocMemoryWithSize: s->cStringLength + 1]; - memcpy(s->cString, [string UTF8String], s->cStringLength + 1); + _s->cString = [self allocMemoryWithSize: _s->cStringLength + 1]; + memcpy(_s->cString, [string UTF8String], _s->cStringLength + 1); } @catch (id e) { [self release]; @throw e; } @@ -408,45 +409,45 @@ self = [super init]; @try { size_t i, j = 0; - s = &s_store; + _s = &_storage; - s->cString = [self allocMemoryWithSize: (length * 4) + 1]; - s->length = length; + _s->cString = [self allocMemoryWithSize: (length * 4) + 1]; + _s->length = length; for (i = 0; i < length; i++) { char buffer[4]; size_t len = of_string_utf8_encode(characters[i], buffer); switch (len) { case 1: - s->cString[j++] = buffer[0]; + _s->cString[j++] = buffer[0]; break; case 2: case 3: case 4: - s->isUTF8 = YES; + _s->isUTF8 = YES; - memcpy(s->cString + j, buffer, len); + memcpy(_s->cString + j, buffer, len); j += len; break; default: @throw [OFInvalidEncodingException exceptionWithClass: [self class]]; } } - s->cString[j] = '\0'; - s->cStringLength = j; + _s->cString[j] = '\0'; + _s->cStringLength = j; @try { - s->cString = [self resizeMemory: s->cString - size: j + 1]; + _s->cString = [self resizeMemory: _s->cString + size: j + 1]; } @catch (OFOutOfMemoryException *e) { /* We don't care, as we only tried to make it smaller */ } } @catch (id e) { [self release]; @@ -474,14 +475,14 @@ string++; length--; } else if (byteOrder != OF_BYTE_ORDER_NATIVE) swap = YES; - s = &s_store; + _s = &_storage; - s->cString = [self allocMemoryWithSize: (length * 4) + 1]; - s->length = length; + _s->cString = [self allocMemoryWithSize: (length * 4) + 1]; + _s->length = length; for (i = 0; i < length; i++) { char buffer[4]; of_unichar_t character = (swap ? OF_BSWAP16(string[i]) : string[i]); @@ -509,40 +510,40 @@ character = (((character & 0x3FF) << 10) | (nextCharacter & 0x3FF)) + 0x10000; i++; - s->length--; + _s->length--; } len = of_string_utf8_encode(character, buffer); switch (len) { case 1: - s->cString[j++] = buffer[0]; + _s->cString[j++] = buffer[0]; break; case 2: case 3: case 4: - s->isUTF8 = YES; + _s->isUTF8 = YES; - memcpy(s->cString + j, buffer, len); + memcpy(_s->cString + j, buffer, len); j += len; break; default: @throw [OFInvalidEncodingException exceptionWithClass: [self class]]; } } - s->cString[j] = '\0'; - s->cStringLength = j; + _s->cString[j] = '\0'; + _s->cStringLength = j; @try { - s->cString = [self resizeMemory: s->cString - size: j + 1]; + _s->cString = [self resizeMemory: _s->cString + size: j + 1]; } @catch (OFOutOfMemoryException *e) { /* We don't care, as we only tried to make it smaller */ } } @catch (id e) { [self release]; @@ -570,46 +571,46 @@ characters++; length--; } else if (byteOrder != OF_BYTE_ORDER_NATIVE) swap = YES; - s = &s_store; + _s = &_storage; - s->cString = [self allocMemoryWithSize: (length * 4) + 1]; - s->length = length; + _s->cString = [self allocMemoryWithSize: (length * 4) + 1]; + _s->length = length; for (i = 0; i < length; i++) { char buffer[4]; size_t len = of_string_utf8_encode( (swap ? OF_BSWAP32(characters[i]) : characters[i]), buffer); switch (len) { case 1: - s->cString[j++] = buffer[0]; + _s->cString[j++] = buffer[0]; break; case 2: case 3: case 4: - s->isUTF8 = YES; + _s->isUTF8 = YES; - memcpy(s->cString + j, buffer, len); + memcpy(_s->cString + j, buffer, len); j += len; break; default: @throw [OFInvalidEncodingException exceptionWithClass: [self class]]; } } - s->cString[j] = '\0'; - s->cStringLength = j; + _s->cString[j] = '\0'; + _s->cStringLength = j; @try { - s->cString = [self resizeMemory: s->cString - size: j + 1]; + _s->cString = [self resizeMemory: _s->cString + size: j + 1]; } @catch (OFOutOfMemoryException *e) { /* We don't care, as we only tried to make it smaller */ } } @catch (id e) { [self release]; @@ -631,33 +632,33 @@ if (format == nil) @throw [OFInvalidArgumentException exceptionWithClass: [self class] selector: _cmd]; - s = &s_store; + _s = &_storage; if ((cStringLength = of_vasprintf(&tmp, [format UTF8String], arguments)) == -1) @throw [OFInvalidFormatException exceptionWithClass: [self class]]; - s->cStringLength = cStringLength; + _s->cStringLength = cStringLength; @try { switch (of_string_utf8_check(tmp, cStringLength, - &s->length)) { + &_s->length)) { case 1: - s->isUTF8 = YES; + _s->isUTF8 = YES; break; case -1: @throw [OFInvalidEncodingException exceptionWithClass: [self class]]; } - s->cString = [self + _s->cString = [self allocMemoryWithSize: cStringLength + 1]; - memcpy(s->cString, tmp, cStringLength + 1); + memcpy(_s->cString, tmp, cStringLength + 1); } @finally { free(tmp); } } @catch (id e) { [self release]; @@ -675,55 +676,56 @@ @try { OFString *component; size_t i, cStringLength; va_list argumentsCopy; - s = &s_store; + _s = &_storage; - s->cStringLength = [firstComponent UTF8StringLength]; + _s->cStringLength = [firstComponent UTF8StringLength]; if ([firstComponent isKindOfClass: [OFString_UTF8 class]] || [firstComponent isKindOfClass: [OFMutableString_UTF8 class]]) - s->isUTF8 = ((OFString_UTF8*)firstComponent)->s->isUTF8; + _s->isUTF8 = + ((OFString_UTF8*)firstComponent)->_s->isUTF8; else - s->isUTF8 = YES; + _s->isUTF8 = YES; - s->length = [firstComponent length]; + _s->length = [firstComponent length]; /* Calculate length and see if we need UTF-8 */ va_copy(argumentsCopy, arguments); while ((component = va_arg(argumentsCopy, OFString*)) != nil) { - s->cStringLength += 1 + [component UTF8StringLength]; - s->length += 1 + [component length]; + _s->cStringLength += 1 + [component UTF8StringLength]; + _s->length += 1 + [component length]; if ([component isKindOfClass: [OFString_UTF8 class]] || [component isKindOfClass: [OFMutableString_UTF8 class]]) - s->isUTF8 = - ((OFString_UTF8*)component)->s->isUTF8; + _s->isUTF8 = + ((OFString_UTF8*)component)->_s->isUTF8; else - s->isUTF8 = YES; + _s->isUTF8 = YES; } - s->cString = [self allocMemoryWithSize: s->cStringLength + 1]; + _s->cString = [self allocMemoryWithSize: _s->cStringLength + 1]; cStringLength = [firstComponent UTF8StringLength]; - memcpy(s->cString, [firstComponent UTF8String], cStringLength); + memcpy(_s->cString, [firstComponent UTF8String], cStringLength); i = cStringLength; while ((component = va_arg(arguments, OFString*)) != nil) { cStringLength = [component UTF8StringLength]; - s->cString[i] = OF_PATH_DELIMITER; - memcpy(s->cString + i + 1, [component UTF8String], + _s->cString[i] = OF_PATH_DELIMITER; + memcpy(_s->cString + i + 1, [component UTF8String], cStringLength); i += 1 + cStringLength; } - s->cString[i] = '\0'; + _s->cString[i] = '\0'; } @catch (id e) { [self release]; @throw e; } @@ -730,12 +732,12 @@ return self; } - (void)dealloc { - if (s != NULL && s->freeWhenDone != NULL) - free(s->freeWhenDone); + if (_s != NULL && _s->freeWhenDone != NULL) + free(_s->freeWhenDone); [super dealloc]; } - (size_t)getCString: (char*)cString @@ -742,22 +744,22 @@ maxLength: (size_t)maxLength encoding: (of_string_encoding_t)encoding { switch (encoding) { case OF_STRING_ENCODING_ASCII: - if (s->isUTF8) + if (_s->isUTF8) @throw [OFInvalidEncodingException exceptionWithClass: [self class]]; /* intentional fall-through */ case OF_STRING_ENCODING_UTF_8: - if (s->cStringLength + 1 > maxLength) + if (_s->cStringLength + 1 > maxLength) @throw [OFOutOfRangeException exceptionWithClass: [self class]]; - memcpy(cString, s->cString, s->cStringLength + 1); + memcpy(cString, _s->cString, _s->cStringLength + 1); - return s->cStringLength; + return _s->cStringLength; default: return [super getCString: cString maxLength: maxLength encoding: encoding]; } @@ -765,45 +767,45 @@ - (const char*)cStringWithEncoding: (of_string_encoding_t)encoding { switch (encoding) { case OF_STRING_ENCODING_ASCII: - if (s->isUTF8) + if (_s->isUTF8) @throw [OFInvalidEncodingException exceptionWithClass: [self class]]; /* intentional fall-through */ case OF_STRING_ENCODING_UTF_8: - return s->cString; + return _s->cString; default: return [super cStringWithEncoding: encoding]; } } - (const char*)UTF8String { - return s->cString; + return _s->cString; } - (size_t)length { - return s->length; + return _s->length; } - (size_t)cStringLengthWithEncoding: (of_string_encoding_t)encoding { switch (encoding) { case OF_STRING_ENCODING_UTF_8: case OF_STRING_ENCODING_ASCII: - return s->cStringLength; + return _s->cStringLength; default: return [super cStringLengthWithEncoding: encoding]; } } - (size_t)UTF8StringLength { - return s->cStringLength; + return _s->cStringLength; } - (BOOL)isEqual: (id)object { OFString_UTF8 *otherString; @@ -814,21 +816,21 @@ if (![object isKindOfClass: [OFString class]]) return NO; otherString = object; - if ([otherString UTF8StringLength] != s->cStringLength || - [otherString length] != s->length) + if ([otherString UTF8StringLength] != _s->cStringLength || + [otherString length] != _s->length) return NO; if (([otherString isKindOfClass: [OFString_UTF8 class]] || [otherString isKindOfClass: [OFMutableString_UTF8 class]]) && - s->hashed && otherString->s->hashed && - s->hash != otherString->s->hash) + _s->hashed && otherString->_s->hashed && + _s->hash != otherString->_s->hash) return NO; - if (strcmp(s->cString, [otherString UTF8String])) + if (strcmp(_s->cString, [otherString UTF8String])) return NO; return YES; } @@ -846,18 +848,18 @@ exceptionWithClass: [self class] selector: _cmd]; otherString = (OFString*)object; otherCStringLength = [otherString UTF8StringLength]; - minimumCStringLength = (s->cStringLength > otherCStringLength - ? otherCStringLength : s->cStringLength); + minimumCStringLength = (_s->cStringLength > otherCStringLength + ? otherCStringLength : _s->cStringLength); - if ((compare = memcmp(s->cString, [otherString UTF8String], + if ((compare = memcmp(_s->cString, [otherString UTF8String], minimumCStringLength)) == 0) { - if (s->cStringLength > otherCStringLength) + if (_s->cStringLength > otherCStringLength) return OF_ORDERED_DESCENDING; - if (s->cStringLength < otherCStringLength) + if (_s->cStringLength < otherCStringLength) return OF_ORDERED_ASCENDING; return OF_ORDERED_SAME; } if (compare > 0) @@ -881,19 +883,19 @@ selector: _cmd]; otherCString = [otherString UTF8String]; otherCStringLength = [otherString UTF8StringLength]; - if (!s->isUTF8) { - minimumCStringLength = (s->cStringLength > otherCStringLength - ? otherCStringLength : s->cStringLength); + if (!_s->isUTF8) { + minimumCStringLength = (_s->cStringLength > otherCStringLength + ? otherCStringLength : _s->cStringLength); - if ((compare = memcasecmp(s->cString, otherCString, + if ((compare = memcasecmp(_s->cString, otherCString, minimumCStringLength)) == 0) { - if (s->cStringLength > otherCStringLength) + if (_s->cStringLength > otherCStringLength) return OF_ORDERED_DESCENDING; - if (s->cStringLength < otherCStringLength) + if (_s->cStringLength < otherCStringLength) return OF_ORDERED_ASCENDING; return OF_ORDERED_SAME; } if (compare > 0) @@ -902,16 +904,16 @@ return OF_ORDERED_ASCENDING; } i = j = 0; - while (i < s->cStringLength && j < otherCStringLength) { + while (i < _s->cStringLength && j < otherCStringLength) { of_unichar_t c1, c2; size_t l1, l2; - l1 = of_string_utf8_decode(s->cString + i, - s->cStringLength - i, &c1); + l1 = of_string_utf8_decode(_s->cString + i, + _s->cStringLength - i, &c1); l2 = of_string_utf8_decode(otherCString + j, otherCStringLength - j, &c2); if (l1 == 0 || l2 == 0 || c1 > 0x10FFFF || c2 > 0x10FFFF) @throw [OFInvalidEncodingException @@ -940,13 +942,13 @@ i += l1; j += l2; } - if (s->cStringLength - i > otherCStringLength - j) + if (_s->cStringLength - i > otherCStringLength - j) return OF_ORDERED_DESCENDING; - else if (s->cStringLength - i < otherCStringLength - j) + else if (_s->cStringLength - i < otherCStringLength - j) return OF_ORDERED_ASCENDING; return OF_ORDERED_SAME; } @@ -953,21 +955,21 @@ - (uint32_t)hash { size_t i; uint32_t hash; - if (s->hashed) - return s->hash; + if (_s->hashed) + return _s->hash; OF_HASH_INIT(hash); - for (i = 0; i < s->cStringLength; i++) { + for (i = 0; i < _s->cStringLength; i++) { of_unichar_t c; size_t length; - if ((length = of_string_utf8_decode(s->cString + i, - s->cStringLength - i, &c)) == 0) + if ((length = of_string_utf8_decode(_s->cString + i, + _s->cStringLength - i, &c)) == 0) @throw [OFInvalidEncodingException exceptionWithClass: [self class]]; OF_HASH_ADD(hash, (c & 0xFF0000) >> 16); OF_HASH_ADD(hash, (c & 0x00FF00) >> 8); @@ -976,31 +978,31 @@ i += length - 1; } OF_HASH_FINALIZE(hash); - s->hash = hash; - s->hashed = YES; + _s->hash = hash; + _s->hashed = YES; return hash; } - (of_unichar_t)characterAtIndex: (size_t)index { of_unichar_t character; - if (index >= s->length) + if (index >= _s->length) @throw [OFOutOfRangeException exceptionWithClass: [self class]]; - if (!s->isUTF8) - return s->cString[index]; - - index = of_string_utf8_get_position(s->cString, index, - s->cStringLength); - - if (!of_string_utf8_decode(s->cString + index, s->cStringLength - index, - &character)) + if (!_s->isUTF8) + return _s->cString[index]; + + index = of_string_utf8_get_position(_s->cString, index, + _s->cStringLength); + + if (!of_string_utf8_decode(_s->cString + index, + _s->cStringLength - index, &character)) @throw [OFInvalidEncodingException exceptionWithClass: [self class]]; return character; } @@ -1011,11 +1013,11 @@ /* TODO: Could be slightly optimized */ void *pool = objc_autoreleasePoolPush(); const of_unichar_t *characters = [self characters]; if (range.length > SIZE_MAX - range.location || - range.location + range.length > s->length) + range.location + range.length > _s->length) @throw [OFOutOfRangeException exceptionWithClass: [self class]]; memcpy(buffer, characters + range.location, range.length * sizeof(of_unichar_t)); @@ -1029,19 +1031,19 @@ const char *cString = [string UTF8String]; size_t i, cStringLength = [string UTF8StringLength]; size_t rangeLocation, rangeLength; if (range.length > SIZE_MAX - range.location || - range.location + range.length > s->length) + range.location + range.length > _s->length) @throw [OFOutOfRangeException exceptionWithClass: [self class]]; - if (s->isUTF8) { + if (_s->isUTF8) { rangeLocation = of_string_utf8_get_position( - s->cString, range.location, s->cStringLength); + _s->cString, range.location, _s->cStringLength); rangeLength = of_string_utf8_get_position( - s->cString + rangeLocation, range.length, - s->cStringLength - rangeLocation); + _s->cString + rangeLocation, range.length, + _s->cStringLength - rangeLocation); } else { rangeLocation = range.location; rangeLength = range.length; } @@ -1051,14 +1053,14 @@ if (cStringLength > rangeLength) return of_range(OF_NOT_FOUND, 0); if (options & OF_STRING_SEARCH_BACKWARDS) { for (i = rangeLength - cStringLength;; i--) { - if (!memcmp(s->cString + rangeLocation + i, cString, + if (!memcmp(_s->cString + rangeLocation + i, cString, cStringLength)) { range.location += of_string_utf8_get_index( - s->cString + rangeLocation, i); + _s->cString + rangeLocation, i); range.length = [string length]; return range; } @@ -1066,14 +1068,14 @@ if (i == 0) return of_range(OF_NOT_FOUND, 0); } } else { for (i = 0; i <= rangeLength - cStringLength; i++) { - if (!memcmp(s->cString + rangeLocation + i, cString, + if (!memcmp(_s->cString + rangeLocation + i, cString, cStringLength)) { range.location += of_string_utf8_get_index( - s->cString + rangeLocation, i); + _s->cString + rangeLocation, i); range.length = [string length]; return range; } } @@ -1088,15 +1090,15 @@ size_t i, cStringLength = [string UTF8StringLength]; if (cStringLength == 0) return YES; - if (cStringLength > s->cStringLength) + if (cStringLength > _s->cStringLength) return NO; - for (i = 0; i <= s->cStringLength - cStringLength; i++) - if (!memcmp(s->cString + i, cString, cStringLength)) + for (i = 0; i <= _s->cStringLength - cStringLength; i++) + if (!memcmp(_s->cString + i, cString, cStringLength)) return YES; return NO; } @@ -1103,42 +1105,42 @@ - (OFString*)substringWithRange: (of_range_t)range { size_t start = range.location; size_t end = range.location + range.length; - if (range.length > SIZE_MAX - range.location || end > s->length) + if (range.length > SIZE_MAX - range.location || end > _s->length) @throw [OFOutOfRangeException exceptionWithClass: [self class]]; - if (s->isUTF8) { - start = of_string_utf8_get_position(s->cString, start, - s->cStringLength); - end = of_string_utf8_get_position(s->cString, end, - s->cStringLength); + if (_s->isUTF8) { + start = of_string_utf8_get_position(_s->cString, start, + _s->cStringLength); + end = of_string_utf8_get_position(_s->cString, end, + _s->cStringLength); } - return [OFString stringWithUTF8String: s->cString + start + return [OFString stringWithUTF8String: _s->cString + start length: end - start]; } - (BOOL)hasPrefix: (OFString*)prefix { size_t cStringLength = [prefix UTF8StringLength]; - if (cStringLength > s->cStringLength) + if (cStringLength > _s->cStringLength) return NO; - return !memcmp(s->cString, [prefix UTF8String], cStringLength); + return !memcmp(_s->cString, [prefix UTF8String], cStringLength); } - (BOOL)hasSuffix: (OFString*)suffix { size_t cStringLength = [suffix UTF8StringLength]; - if (cStringLength > s->cStringLength) + if (cStringLength > _s->cStringLength) return NO; - return !memcmp(s->cString + (s->cStringLength - cStringLength), + return !memcmp(_s->cString + (_s->cStringLength - cStringLength), [suffix UTF8String], cStringLength); } - (OFArray*)componentsSeparatedByString: (OFString*)delimiter options: (int)options @@ -1152,30 +1154,30 @@ OFString *component; array = [OFMutableArray array]; pool = objc_autoreleasePoolPush(); - if (cStringLength > s->cStringLength) { + if (cStringLength > _s->cStringLength) { [array addObject: [[self copy] autorelease]]; objc_autoreleasePoolPop(pool); return array; } - for (i = 0, last = 0; i <= s->cStringLength - cStringLength; i++) { - if (memcmp(s->cString + i, cString, cStringLength)) + for (i = 0, last = 0; i <= _s->cStringLength - cStringLength; i++) { + if (memcmp(_s->cString + i, cString, cStringLength)) continue; - component = [OFString stringWithUTF8String: s->cString + last + component = [OFString stringWithUTF8String: _s->cString + last length: i - last]; if (!skipEmpty || [component length] > 0) [array addObject: component]; i += cStringLength - 1; last = i + 1; } - component = [OFString stringWithUTF8String: s->cString + last]; + component = [OFString stringWithUTF8String: _s->cString + last]; if (!skipEmpty || [component length] > 0) [array addObject: component]; [array makeImmutable]; @@ -1186,41 +1188,41 @@ - (OFArray*)pathComponents { OFMutableArray *ret; void *pool; - size_t i, last = 0, pathCStringLength = s->cStringLength; + size_t i, last = 0, pathCStringLength = _s->cStringLength; ret = [OFMutableArray array]; if (pathCStringLength == 0) return ret; pool = objc_autoreleasePoolPush(); #ifndef _WIN32 - if (s->cString[pathCStringLength - 1] == OF_PATH_DELIMITER) + if (_s->cString[pathCStringLength - 1] == OF_PATH_DELIMITER) #else - if (s->cString[pathCStringLength - 1] == '/' || - s->cString[pathCStringLength - 1] == '\\') + if (_s->cString[pathCStringLength - 1] == '/' || + _s->cString[pathCStringLength - 1] == '\\') #endif pathCStringLength--; for (i = 0; i < pathCStringLength; i++) { #ifndef _WIN32 - if (s->cString[i] == OF_PATH_DELIMITER) { + if (_s->cString[i] == OF_PATH_DELIMITER) { #else - if (s->cString[i] == '/' || s->cString[i] == '\\') { + if (_s->cString[i] == '/' || _s->cString[i] == '\\') { #endif [ret addObject: - [OFString stringWithUTF8String: s->cString + last + [OFString stringWithUTF8String: _s->cString + last length: i - last]]; last = i + 1; } } - [ret addObject: [OFString stringWithUTF8String: s->cString + last + [ret addObject: [OFString stringWithUTF8String: _s->cString + last length: i - last]]; [ret makeImmutable]; objc_autoreleasePoolPop(pool); @@ -1228,29 +1230,29 @@ return ret; } - (OFString*)lastPathComponent { - size_t pathCStringLength = s->cStringLength; + size_t pathCStringLength = _s->cStringLength; ssize_t i; if (pathCStringLength == 0) return @""; #ifndef _WIN32 - if (s->cString[pathCStringLength - 1] == OF_PATH_DELIMITER) + if (_s->cString[pathCStringLength - 1] == OF_PATH_DELIMITER) #else - if (s->cString[pathCStringLength - 1] == '/' || - s->cString[pathCStringLength - 1] == '\\') + if (_s->cString[pathCStringLength - 1] == '/' || + _s->cString[pathCStringLength - 1] == '\\') #endif pathCStringLength--; for (i = pathCStringLength - 1; i >= 0; i--) { #ifndef _WIN32 - if (s->cString[i] == OF_PATH_DELIMITER) { + if (_s->cString[i] == OF_PATH_DELIMITER) { #else - if (s->cString[i] == '/' || s->cString[i] == '\\') { + if (_s->cString[i] == '/' || _s->cString[i] == '\\') { #endif i++; break; } } @@ -1260,48 +1262,48 @@ * removed, so return a new string anyway. */ if (i < 0) i = 0; - return [OFString stringWithUTF8String: s->cString + i + return [OFString stringWithUTF8String: _s->cString + i length: pathCStringLength - i]; } - (OFString*)stringByDeletingLastPathComponent { - size_t i, pathCStringLength = s->cStringLength; + size_t i, pathCStringLength = _s->cStringLength; if (pathCStringLength == 0) return @""; #ifndef _WIN32 - if (s->cString[pathCStringLength - 1] == OF_PATH_DELIMITER) + if (_s->cString[pathCStringLength - 1] == OF_PATH_DELIMITER) #else - if (s->cString[pathCStringLength - 1] == '/' || - s->cString[pathCStringLength - 1] == '\\') + if (_s->cString[pathCStringLength - 1] == '/' || + _s->cString[pathCStringLength - 1] == '\\') #endif pathCStringLength--; if (pathCStringLength == 0) - return [OFString stringWithUTF8String: s->cString + return [OFString stringWithUTF8String: _s->cString length: 1]; for (i = pathCStringLength - 1; i >= 1; i--) #ifndef _WIN32 - if (s->cString[i] == OF_PATH_DELIMITER) + if (_s->cString[i] == OF_PATH_DELIMITER) #else - if (s->cString[i] == '/' || s->cString[i] == '\\') + if (_s->cString[i] == '/' || _s->cString[i] == '\\') #endif - return [OFString stringWithUTF8String: s->cString + return [OFString stringWithUTF8String: _s->cString length: i]; #ifndef _WIN32 - if (s->cString[0] == OF_PATH_DELIMITER) + if (_s->cString[0] == OF_PATH_DELIMITER) #else - if (s->cString[0] == '/' || s->cString[0] == '\\') + if (_s->cString[0] == '/' || _s->cString[0] == '\\') #endif - return [OFString stringWithUTF8String: s->cString + return [OFString stringWithUTF8String: _s->cString length: 1]; return @"."; } @@ -1310,20 +1312,20 @@ OFObject *object = [[[OFObject alloc] init] autorelease]; of_unichar_t *ret; size_t i, j; ret = [object allocMemoryWithSize: sizeof(of_unichar_t) - count: s->length]; + count: _s->length]; i = j = 0; - while (i < s->cStringLength) { + while (i < _s->cStringLength) { of_unichar_t c; size_t cLen; - cLen = of_string_utf8_decode(s->cString + i, - s->cStringLength - i, &c); + cLen = of_string_utf8_decode(_s->cString + i, + _s->cStringLength - i, &c); if (cLen == 0 || c > 0x10FFFF) @throw [OFInvalidEncodingException exceptionWithClass: [self class]]; @@ -1339,20 +1341,20 @@ OFObject *object = [[[OFObject alloc] init] autorelease]; of_char32_t *ret; size_t i, j; ret = [object allocMemoryWithSize: sizeof(of_unichar_t) - count: s->length + 1]; + count: _s->length + 1]; i = j = 0; - while (i < s->cStringLength) { + while (i < _s->cStringLength) { of_unichar_t c; size_t cLen; - cLen = of_string_utf8_decode(s->cString + i, - s->cStringLength - i, &c); + cLen = of_string_utf8_decode(_s->cString + i, + _s->cStringLength - i, &c); if (cLen == 0 || c > 0x10FFFF) @throw [OFInvalidEncodingException exceptionWithClass: [self class]]; @@ -1370,11 +1372,11 @@ #ifdef OF_HAVE_BLOCKS - (void)enumerateLinesUsingBlock: (of_string_line_enumeration_block_t)block { void *pool; - const char *cString = s->cString; + const char *cString = _s->cString; const char *last = cString; BOOL stop = NO, lastCarriageReturn = NO; while (!stop && *cString != 0) { if (lastCarriageReturn && *cString == '\n') { Index: src/OFTCPSocket.h ================================================================== --- src/OFTCPSocket.h +++ src/OFTCPSocket.h @@ -48,15 +48,15 @@ * To connect to a server, create a socket and connect it. * To create a server, create a socket, bind it and listen on it. */ @interface OFTCPSocket: OFStreamSocket { - BOOL listening; - struct sockaddr_storage *sockAddr; - socklen_t sockAddrLen; - OFString *SOCKS5Host; - uint16_t SOCKS5Port; + BOOL _listening; + struct sockaddr_storage *_sockAddr; + socklen_t _sockAddrLen; + OFString *_SOCKS5Host; + uint16_t _SOCKS5Port; } #ifdef OF_HAVE_PROPERTIES @property (readonly, getter=isListening) BOOL listening; @property (copy) OFString *SOCKS5Host; @@ -64,13 +64,14 @@ #endif /*! * @brief Sets the global SOCKS5 proxy host to use when creating a new socket * - * @param host The host to use as a SOCKS5 proxy when creating a new socket + * @param SOCKS5Host The host to use as a SOCKS5 proxy when creating a new + * socket */ -+ (void)setSOCKS5Host: (OFString*)host; ++ (void)setSOCKS5Host: (OFString*)SOCKS5Host; /*! * @brief Returns the host to use as a SOCKS5 proxy when creating a new socket * * @return The host to use as a SOCKS5 proxy when creating a new socket @@ -78,13 +79,13 @@ + (OFString*)SOCKS5Host; /*! * @brief Sets the global SOCKS5 proxy port to use when creating a new socket * - * @param port The port to use as a SOCKS5 proxy when creating a new socket + * @param SOCKS5Port The port to use as a SOCKS5 proxy when creating a new socket */ -+ (void)setSOCKS5Port: (uint16_t)port; ++ (void)setSOCKS5Port: (uint16_t)SOCKS5Port; /*! * @brief Returns the port to use as a SOCKS5 proxy when creating a new socket * * @return The port to use as a SOCKS5 proxy when creating a new socket Index: src/OFTCPSocket.m ================================================================== --- src/OFTCPSocket.m +++ src/OFTCPSocket.m @@ -91,20 +91,20 @@ static uint16_t defaultSOCKS5Port = 1080; #ifdef OF_HAVE_THREADS @interface OFTCPSocket_ConnectThread: OFThread { - OFThread *sourceThread; - OFTCPSocket *sock; - OFString *host; - uint16_t port; - id target; - SEL selector; + OFThread *_sourceThread; + OFTCPSocket *_socket; + OFString *_host; + uint16_t _port; + id _target; + SEL _selector; # ifdef OF_HAVE_BLOCKS - of_tcpsocket_async_connect_block_t connectBlock; + of_tcpsocket_async_connect_block_t _connectBlock; # endif - OFException *exception; + OFException *_exception; } - initWithSourceThread: (OFThread*)sourceThread socket: (OFTCPSocket*)socket host: (OFString*)host @@ -119,49 +119,49 @@ block: (of_tcpsocket_async_connect_block_t)block; # endif @end @implementation OFTCPSocket_ConnectThread -- initWithSourceThread: (OFThread*)sourceThread_ - socket: (OFTCPSocket*)sock_ - host: (OFString*)host_ - port: (uint16_t)port_ - target: (id)target_ - selector: (SEL)selector_ +- initWithSourceThread: (OFThread*)sourceThread + socket: (OFTCPSocket*)socket + host: (OFString*)host + port: (uint16_t)port + target: (id)target + selector: (SEL)selector { self = [super init]; @try { - sourceThread = [sourceThread_ retain]; - sock = [sock_ retain]; - host = [host_ copy]; - port = port_; - target = [target_ retain]; - selector = selector_; + _sourceThread = [sourceThread retain]; + _socket = [socket retain]; + _host = [host copy]; + _port = port; + _target = [target retain]; + _selector = selector; } @catch (id e) { [self release]; @throw e; } return self; } # ifdef OF_HAVE_BLOCKS -- initWithSourceThread: (OFThread*)sourceThread_ - socket: (OFTCPSocket*)sock_ - host: (OFString*)host_ - port: (uint16_t)port_ - block: (of_tcpsocket_async_connect_block_t)block_ +- initWithSourceThread: (OFThread*)sourceThread + socket: (OFTCPSocket*)socket + host: (OFString*)host + port: (uint16_t)port + block: (of_tcpsocket_async_connect_block_t)block { self = [super init]; @try { - sourceThread = [sourceThread_ retain]; - sock = [sock_ retain]; - host = [host_ copy]; - port = port_; - connectBlock = [block_ copy]; + _sourceThread = [sourceThread retain]; + _socket = [socket retain]; + _host = [host copy]; + _port = port; + _connectBlock = [block copy]; } @catch (id e) { [self release]; @throw e; } @@ -169,36 +169,36 @@ } # endif - (void)dealloc { - [sourceThread release]; - [sock release]; - [host release]; - [target release]; + [_sourceThread release]; + [_socket release]; + [_host release]; + [_target release]; # ifdef OF_HAVE_BLOCKS - [connectBlock release]; + [_connectBlock release]; # endif - [exception release]; + [_exception release]; [super dealloc]; } - (void)didConnect { [self join]; # ifdef OF_HAVE_BLOCKS - if (connectBlock != NULL) - connectBlock(sock, exception); + if (_connectBlock != NULL) + _connectBlock(_socket, _exception); else { # endif void (*func)(id, SEL, OFTCPSocket*, OFException*) = - (void(*)(id, SEL, OFTCPSocket*, OFException*))[target - methodForSelector: selector]; + (void(*)(id, SEL, OFTCPSocket*, OFException*))[_target + methodForSelector: _selector]; - func(target, selector, sock, exception); + func(_target, _selector, _socket, _exception); # ifdef OF_HAVE_BLOCKS } # endif } @@ -205,18 +205,18 @@ - (id)main { void *pool = objc_autoreleasePoolPush(); @try { - [sock connectToHost: host - port: port]; + [_socket connectToHost: _host + port: _port]; } @catch (OFException *e) { - exception = [[e retain] autorelease]; + _exception = [[e retain] autorelease]; } [self performSelector: @selector(didConnect) - onThread: sourceThread + onThread: _sourceThread waitUntilDone: NO]; objc_autoreleasePoolPop(pool); return nil; @@ -258,14 +258,14 @@ - init { self = [super init]; @try { - sock = INVALID_SOCKET; - sockAddr = NULL; - SOCKS5Host = [defaultSOCKS5Host copy]; - SOCKS5Port = defaultSOCKS5Port; + _socket = INVALID_SOCKET; + _sockAddr = NULL; + _SOCKS5Host = [defaultSOCKS5Host copy]; + _SOCKS5Port = defaultSOCKS5Port; } @catch (id e) { [self release]; @throw e; } @@ -272,50 +272,50 @@ return self; } - (void)dealloc { - [SOCKS5Host release]; + [_SOCKS5Host release]; [super dealloc]; } -- (void)setSOCKS5Host: (OFString*)host +- (void)setSOCKS5Host: (OFString*)SOCKS5Host { - OF_SETTER(SOCKS5Host, host, YES, 1) + OF_SETTER(_SOCKS5Host, SOCKS5Host, YES, 1) } - (OFString*)SOCKS5Host { - OF_GETTER(SOCKS5Host, YES) + OF_GETTER(_SOCKS5Host, YES) } -- (void)setSOCKS5Port: (uint16_t)port +- (void)setSOCKS5Port: (uint16_t)SOCKS5Port { - SOCKS5Port = port; + _SOCKS5Port = SOCKS5Port; } - (uint16_t)SOCKS5Port { - return SOCKS5Port; + return _SOCKS5Port; } - (void)connectToHost: (OFString*)host port: (uint16_t)port { OFString *destinationHost = host; uint16_t destinationPort = port; - if (sock != INVALID_SOCKET) + if (_socket != INVALID_SOCKET) @throw [OFAlreadyConnectedException exceptionWithClass: [self class] socket: self]; - if (SOCKS5Host != nil) { + if (_SOCKS5Host != nil) { /* Connect to the SOCKS5 proxy instead */ - host = SOCKS5Host; - port = SOCKS5Port; + host = _SOCKS5Host; + port = _SOCKS5Port; } #ifdef HAVE_THREADSAFE_GETADDRINFO struct addrinfo hints, *res, *res0; char portCString[7]; @@ -332,17 +332,17 @@ exceptionWithClass: [self class] socket: self host: host]; for (res = res0; res != NULL; res = res->ai_next) { - if ((sock = socket(res->ai_family, res->ai_socktype, + if ((_socket = socket(res->ai_family, res->ai_socktype, res->ai_protocol)) == INVALID_SOCKET) continue; - if (connect(sock, res->ai_addr, res->ai_addrlen) == -1) { - close(sock); - sock = INVALID_SOCKET; + if (connect(_socket, res->ai_addr, res->ai_addrlen) == -1) { + close(_socket); + _socket = INVALID_SOCKET; continue; } break; } @@ -375,20 +375,20 @@ memset(&addr, 0, sizeof(addr)); addr.sin_family = AF_INET; addr.sin_port = OF_BSWAP16_IF_LE(port); if (he->h_addrtype != AF_INET || - (sock = socket(AF_INET, SOCK_STREAM, 0)) == INVALID_SOCKET) { + (_socket = socket(AF_INET, SOCK_STREAM, 0)) == INVALID_SOCKET) { # ifdef OF_HAVE_THREADS [addrlist release]; [mutex unlock]; # endif @throw [OFConnectionFailedException exceptionWithClass: [self class] socket: self - host: host - port: port]; + host: host + port: port]; } # ifdef OF_HAVE_THREADS @try { for (ip = he->h_addr_list; *ip != NULL; ip++) @@ -407,11 +407,12 @@ # else for (ip = he->h_addr_list; *ip != NULL; ip++) { # endif memcpy(&addr.sin_addr.s_addr, *ip, he->h_length); - if (connect(sock, (struct sockaddr*)&addr, sizeof(addr)) == -1) + if (connect(_socket, (struct sockaddr*)&addr, + sizeof(addr)) == -1) continue; connected = YES; break; } @@ -419,23 +420,23 @@ # ifdef OF_HAVE_THREADS [addrlist release]; # endif if (!connected) { - close(sock); - sock = INVALID_SOCKET; + close(_socket); + _socket = INVALID_SOCKET; } #endif - if (sock == INVALID_SOCKET) + if (_socket == INVALID_SOCKET) @throw [OFConnectionFailedException exceptionWithClass: [self class] socket: self host: host port: port]; - if (SOCKS5Host != nil) + if (_SOCKS5Host != nil) [self OF_SOCKS5ConnectToHost: destinationHost port: destinationPort]; } #ifdef OF_HAVE_THREADS @@ -485,16 +486,16 @@ struct sockaddr_in in; struct sockaddr_in6 in6; } addr; socklen_t addrLen; - if (sock != INVALID_SOCKET) + if (_socket != INVALID_SOCKET) @throw [OFAlreadyConnectedException exceptionWithClass: [self class] socket: self]; - if (SOCKS5Host != nil) + if (_SOCKS5Host != nil) @throw [OFNotImplementedException exceptionWithClass: [self class] selector: _cmd]; #ifdef HAVE_THREADSAFE_GETADDRINFO @@ -512,26 +513,27 @@ @throw [OFAddressTranslationFailedException exceptionWithClass: [self class] socket: self host: host]; - if ((sock = socket(res->ai_family, SOCK_STREAM, 0)) == INVALID_SOCKET) + if ((_socket = socket(res->ai_family, SOCK_STREAM, + 0)) == INVALID_SOCKET) @throw [OFBindFailedException exceptionWithClass: [self class] socket: self host: host port: port]; - if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (const char*)&one, + if (setsockopt(_socket, SOL_SOCKET, SO_REUSEADDR, (const char*)&one, sizeof(one))) @throw [OFSetOptionFailedException exceptionWithClass: [self class] stream: self]; - if (bind(sock, res->ai_addr, res->ai_addrlen) == -1) { + if (bind(_socket, res->ai_addr, res->ai_addrlen) == -1) { freeaddrinfo(res); - close(sock); - sock = INVALID_SOCKET; + close(_socket); + _socket = INVALID_SOCKET; @throw [OFBindFailedException exceptionWithClass: [self class] socket: self host: host port: port]; } @@ -572,25 +574,25 @@ memcpy(&addr.in.sin_addr.s_addr, he->h_addr_list[0], he->h_length); # ifdef OF_HAVE_THREADS [mutex unlock]; # endif - if ((sock = socket(AF_INET, SOCK_STREAM, 0)) == INVALID_SOCKET) + if ((_socket = socket(AF_INET, SOCK_STREAM, 0)) == INVALID_SOCKET) @throw [OFBindFailedException exceptionWithClass: [self class] socket: self host: host port: port]; - if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (const char*)&one, + if (setsockopt(_socket, SOL_SOCKET, SO_REUSEADDR, (const char*)&one, sizeof(one))) @throw [OFSetOptionFailedException exceptionWithClass: [self class] stream: self]; - if (bind(sock, (struct sockaddr*)&addr.in, sizeof(addr.in)) == -1) { - close(sock); - sock = INVALID_SOCKET; + if (bind(_socket, (struct sockaddr*)&addr.in, sizeof(addr.in)) == -1) { + close(_socket); + _socket = INVALID_SOCKET; @throw [OFBindFailedException exceptionWithClass: [self class] socket: self host: host port: port]; } @@ -598,13 +600,13 @@ if (port > 0) return port; addrLen = sizeof(addr.storage); - if (getsockname(sock, (struct sockaddr*)&addr, &addrLen)) { - close(sock); - sock = INVALID_SOCKET; + if (getsockname(_socket, (struct sockaddr*)&addr, &addrLen)) { + close(_socket); + _socket = INVALID_SOCKET; @throw [OFBindFailedException exceptionWithClass: [self class] socket: self host: host port: port]; } @@ -612,58 +614,58 @@ if (addr.storage.ss_family == AF_INET) return OF_BSWAP16_IF_LE(addr.in.sin_port); if (addr.storage.ss_family == AF_INET6) return OF_BSWAP16_IF_LE(addr.in6.sin6_port); - close(sock); - sock = INVALID_SOCKET; + close(_socket); + _socket = INVALID_SOCKET; @throw [OFBindFailedException exceptionWithClass: [self class] socket: self host: host port: port]; } - (void)listenWithBackLog: (int)backLog { - if (sock == INVALID_SOCKET) + if (_socket == INVALID_SOCKET) @throw [OFNotConnectedException exceptionWithClass: [self class] socket: self]; - if (listen(sock, backLog) == -1) + if (listen(_socket, backLog) == -1) @throw [OFListenFailedException exceptionWithClass: [self class] socket: self backLog: backLog]; - listening = YES; + _listening = YES; } - (void)listen { [self listenWithBackLog: SOMAXCONN]; } - (OFTCPSocket*)accept { - OFTCPSocket *newSocket; + OFTCPSocket *client; struct sockaddr_storage *addr; socklen_t addrLen; - int newSock; + int socket; - newSocket = [[[[self class] alloc] init] autorelease]; + client = [[[[self class] alloc] init] autorelease]; addrLen = sizeof(*addr); - addr = [newSocket allocMemoryWithSize: addrLen]; + addr = [client allocMemoryWithSize: addrLen]; - if ((newSock = accept(sock, (struct sockaddr*)addr, + if ((socket = accept(_socket, (struct sockaddr*)addr, &addrLen)) == INVALID_SOCKET) @throw [OFAcceptFailedException exceptionWithClass: [self class] socket: self]; - newSocket->sock = newSock; - newSocket->sockAddr = addr; - newSocket->sockAddrLen = addrLen; + client->_socket = socket; + client->_sockAddr = addr; + client->_sockAddrLen = addrLen; - return newSocket; + return client; } - (void)asyncAcceptWithTarget: (id)target selector: (SEL)selector { @@ -682,30 +684,30 @@ - (void)setKeepAlivesEnabled: (BOOL)enable { int v = enable; - if (setsockopt(sock, SOL_SOCKET, SO_KEEPALIVE, (char*)&v, sizeof(v))) + if (setsockopt(_socket, SOL_SOCKET, SO_KEEPALIVE, (char*)&v, sizeof(v))) @throw [OFSetOptionFailedException exceptionWithClass: [self class] stream: self]; } - (OFString*)remoteAddress { char *host; - if (sockAddr == NULL || sockAddrLen == 0) + if (_sockAddr == NULL || _sockAddrLen == 0) @throw [OFInvalidArgumentException exceptionWithClass: [self class] selector: _cmd]; #ifdef HAVE_THREADSAFE_GETADDRINFO host = [self allocMemoryWithSize: NI_MAXHOST]; @try { - if (getnameinfo((struct sockaddr*)sockAddr, sockAddrLen, host, + if (getnameinfo((struct sockaddr*)_sockAddr, _sockAddrLen, host, NI_MAXHOST, NULL, 0, NI_NUMERICHOST | NI_NUMERICSERV)) @throw [OFAddressTranslationFailedException exceptionWithClass: [self class]]; return [OFString stringWithCString: host @@ -717,11 +719,11 @@ # ifdef OF_HAVE_THREADS [mutex lock]; @try { # endif - host = inet_ntoa(((struct sockaddr_in*)sockAddr)->sin_addr); + host = inet_ntoa(((struct sockaddr_in*)_sockAddr)->sin_addr); if (host == NULL) @throw [OFAddressTranslationFailedException exceptionWithClass: [self class]]; @@ -738,18 +740,18 @@ assert(0); } - (BOOL)isListening { - return listening; + return _listening; } - (void)close { [super close]; - listening = NO; - [self freeMemory: sockAddr]; - sockAddr = NULL; - sockAddrLen = 0; + _listening = NO; + [self freeMemory: _sockAddr]; + _sockAddr = NULL; + _sockAddrLen = 0; } @end Index: src/OFTLSKey.h ================================================================== --- src/OFTLSKey.h +++ src/OFTLSKey.h @@ -28,15 +28,15 @@ * @brief A class for Thread Local Storage keys. */ @interface OFTLSKey: OFObject { @public - of_tlskey_t key; + of_tlskey_t _key; @protected - void (*destructor)(id); - of_list_object_t *listObject; - BOOL initialized; + void (*_destructor)(id); + of_list_object_t *_listObject; + BOOL _initialized; } /*! * @brief Creates a new Thread Local Storage key * Index: src/OFTLSKey.m ================================================================== --- src/OFTLSKey.m +++ src/OFTLSKey.m @@ -46,60 +46,61 @@ @synchronized (TLSKeys) { for (iter = [TLSKeys firstListObject]; iter != NULL; iter = iter->next) { OFTLSKey *key = (OFTLSKey*)iter->object; - if (key->destructor != NULL) - key->destructor(iter->object); + if (key->_destructor != NULL) + key->_destructor(iter->object); } } } - init { self = [super init]; @try { - if (!of_tlskey_new(&key)) + if (!of_tlskey_new(&_key)) @throw [OFInitializationFailedException exceptionWithClass: [self class]]; - initialized = YES; + _initialized = YES; @synchronized (TLSKeys) { - listObject = [TLSKeys appendObject: self]; + _listObject = [TLSKeys appendObject: self]; } } @catch (id e) { [self release]; @throw e; } return self; } -- initWithDestructor: (void(*)(id))destructor_ +- initWithDestructor: (void(*)(id))destructor { self = [self init]; - destructor = destructor_; + _destructor = destructor; return self; } - (void)dealloc { - if (destructor != NULL) - destructor(self); + if (_initialized) { + if (_destructor != NULL) + _destructor(self); - if (initialized) - of_tlskey_free(key); + of_tlskey_free(_key); + } /* In case we called [self release] in init */ - if (listObject != NULL) { + if (_listObject != NULL) { @synchronized (TLSKeys) { - [TLSKeys removeListObject: listObject]; + [TLSKeys removeListObject: _listObject]; } } [super dealloc]; } @end Index: src/OFThread.h ================================================================== --- src/OFThread.h +++ src/OFThread.h @@ -48,22 +48,22 @@ #ifdef OF_THREAD_M @public #else @private #endif - of_thread_t thread; + of_thread_t _thread; enum { OF_THREAD_NOT_RUNNING, OF_THREAD_RUNNING, OF_THREAD_WAITING_FOR_JOIN - } running; + } _running; #ifdef OF_HAVE_BLOCKS - of_thread_block_t block; + of_thread_block_t _block; #endif - id returnValue; - OFRunLoop *runLoop; - OFString *name; + id _returnValue; + OFRunLoop *_runLoop; + OFString *_name; } #ifdef OF_HAVE_PROPERTIES # ifdef OF_HAVE_BLOCKS @property (copy) of_thread_block_t block; Index: src/OFThread.m ================================================================== --- src/OFThread.m +++ src/OFThread.m @@ -72,19 +72,19 @@ /* * Nasty workaround for thread implementations which can't return a * value on join. */ #ifdef OF_HAVE_BLOCKS - if (thread->block != NULL) - thread->returnValue = [thread->block() retain]; + if (thread->_block != NULL) + thread->_returnValue = [thread->_block() retain]; else #endif - thread->returnValue = [[thread main] retain]; + thread->_returnValue = [[thread main] retain]; [thread handleTermination]; - thread->running = OF_THREAD_WAITING_FOR_JOIN; + thread->_running = OF_THREAD_WAITING_FOR_JOIN; [OFTLSKey OF_callAllDestructors]; #ifdef OF_OBJFW_RUNTIME /* * As the values returned by objc_autoreleasePoolPush() in the ObjFW @@ -101,11 +101,11 @@ static void set_thread_name(OFThread *thread) { #ifdef __HAIKU__ - OFString *name = thread->name; + OFString *name = thread->_name; if (name == nil) name = [thread className]; rename_thread(get_pthread_thread_id(thread->thread), [name UTF8String]); @@ -112,11 +112,11 @@ #endif } @implementation OFThread #if defined(OF_HAVE_PROPERTIES) && defined(OF_HAVE_BLOCKS) -@synthesize block; +@synthesize block = _block; #endif + (void)initialize { if (self != [OFThread class]) @@ -140,22 +140,22 @@ #endif + (void)setObject: (id)object forTLSKey: (OFTLSKey*)key { - id oldObject = of_tlskey_get(key->key); + id oldObject = of_tlskey_get(key->_key); - if (!of_tlskey_set(key->key, [object retain])) + if (!of_tlskey_set(key->_key, [object retain])) @throw [OFInvalidArgumentException exceptionWithClass: self selector: _cmd]; [oldObject release]; } + (id)objectForTLSKey: (OFTLSKey*)key { - return [[(id)of_tlskey_get(key->key) retain] autorelease]; + return [[(id)of_tlskey_get(key->_key) retain] autorelease]; } + (OFThread*)currentThread { return [[(id)of_tlskey_get(threadSelfKey) retain] autorelease]; @@ -220,15 +220,15 @@ + (void)terminateWithObject: (id)object { OFThread *thread = of_tlskey_get(threadSelfKey); if (thread != nil) { - thread->returnValue = [object retain]; + thread->_returnValue = [object retain]; [thread handleTermination]; - thread->running = OF_THREAD_WAITING_FOR_JOIN; + thread->_running = OF_THREAD_WAITING_FOR_JOIN; } [OFTLSKey OF_callAllDestructors]; #ifdef OF_OBJFW_RUNTIME /* @@ -245,24 +245,24 @@ } + (void)OF_createMainThread { mainThread = [[OFThread alloc] init]; - mainThread->thread = of_thread_current(); + mainThread->_thread = of_thread_current(); if (!of_tlskey_set(threadSelfKey, mainThread)) @throw [OFInitializationFailedException exceptionWithClass: self]; } #ifdef OF_HAVE_BLOCKS -- initWithBlock: (of_thread_block_t)block_ +- initWithBlock: (of_thread_block_t)block { self = [super init]; @try { - block = [block_ copy]; + _block = [block copy]; } @catch (id e) { [self release]; @throw e; } @@ -277,32 +277,32 @@ return nil; } - (void)handleTermination { - OFRunLoop *oldRunLoop = runLoop; - runLoop = nil; + OFRunLoop *oldRunLoop = _runLoop; + _runLoop = nil; [oldRunLoop release]; } - (void)start { - if (running == OF_THREAD_RUNNING) + if (_running == OF_THREAD_RUNNING) @throw [OFThreadStillRunningException exceptionWithClass: [self class] thread: self]; - if (running == OF_THREAD_WAITING_FOR_JOIN) { - of_thread_detach(thread); - [returnValue release]; + if (_running == OF_THREAD_WAITING_FOR_JOIN) { + of_thread_detach(_thread); + [_returnValue release]; } [self retain]; - running = OF_THREAD_RUNNING; + _running = OF_THREAD_RUNNING; - if (!of_thread_new(&thread, call_main, self)) { + if (!of_thread_new(&_thread, call_main, self)) { [self release]; @throw [OFThreadStartFailedException exceptionWithClass: [self class] thread: self]; } @@ -310,18 +310,18 @@ set_thread_name(self); } - (id)join { - if (running == OF_THREAD_NOT_RUNNING || !of_thread_join(thread)) + if (_running == OF_THREAD_NOT_RUNNING || !of_thread_join(_thread)) @throw [OFThreadJoinFailedException exceptionWithClass: [self class] thread: self]; - running = OF_THREAD_NOT_RUNNING; + _running = OF_THREAD_NOT_RUNNING; - return returnValue; + return _returnValue; } - copy { return [self retain]; @@ -328,54 +328,54 @@ } - (OFRunLoop*)runLoop { #ifdef OF_HAVE_ATOMIC_OPS - if (runLoop == nil) { + if (_runLoop == nil) { OFRunLoop *tmp = [[OFRunLoop alloc] init]; - if (!of_atomic_cmpswap_ptr((void**)&runLoop, nil, tmp)) + if (!of_atomic_cmpswap_ptr((void**)&_runLoop, nil, tmp)) [tmp release]; } #else @synchronized (self) { - if (runLoop == nil) - runLoop = [[OFRunLoop alloc] init]; + if (_runLoop == nil) + _runLoop = [[OFRunLoop alloc] init]; } #endif - return [[runLoop retain] autorelease]; + return [[_runLoop retain] autorelease]; } - (OFString*)name { - OF_GETTER(name, YES) + OF_GETTER(_name, YES) } -- (void)setName: (OFString*)name_ +- (void)setName: (OFString*)name { - OF_SETTER(name, name_, YES, 1) + OF_SETTER(_name, name, YES, 1) - if (running == OF_THREAD_RUNNING) + if (_running == OF_THREAD_RUNNING) set_thread_name(self); } - (void)dealloc { - if (running == OF_THREAD_RUNNING) + if (_running == OF_THREAD_RUNNING) @throw [OFThreadStillRunningException exceptionWithClass: [self class] thread: self]; /* * We should not be running anymore, but call detach in order to free * the resources. */ - if (running == OF_THREAD_WAITING_FOR_JOIN) - of_thread_detach(thread); + if (_running == OF_THREAD_WAITING_FOR_JOIN) + of_thread_detach(_thread); - [returnValue release]; - [runLoop release]; + [_returnValue release]; + [_runLoop release]; [super dealloc]; } @end Index: src/OFThreadPool.h ================================================================== --- src/OFThreadPool.h +++ src/OFThreadPool.h @@ -31,18 +31,18 @@ * @note When the thread pool is released, all threads will terminate after * they finish the job they are currently processing. */ @interface OFThreadPool: OFObject { - size_t size; - OFMutableArray *threads; - volatile int count; + size_t _size; + OFMutableArray *_threads; + volatile int _count; @public - OFList *queue; - OFCondition *queueCondition; - volatile int doneCount; - OFCondition *countCondition; + OFList *_queue; + OFCondition *_queueCondition; + volatile int _doneCount; + OFCondition *_countCondition; } /*! * @brief Returns a new thread pool with one thread for each core in the system. * Index: src/OFThreadPool.m ================================================================== --- src/OFThreadPool.m +++ src/OFThreadPool.m @@ -25,15 +25,15 @@ #import "autorelease.h" @interface OFThreadPoolJob: OFObject { - id target; - SEL selector; - id object; + id _target; + SEL _selector; + id _object; #ifdef OF_HAVE_BLOCKS - of_thread_pool_block_t block; + of_thread_pool_block_t _block; #endif } + (instancetype)jobWithTarget: (id)target selector: (SEL)selector @@ -66,35 +66,35 @@ return [[(OFThreadPoolJob*)[self alloc] initWithBlock: block] autorelease]; } #endif -- initWithTarget: (id)target_ - selector: (SEL)selector_ - object: (id)object_ +- initWithTarget: (id)target + selector: (SEL)selector + object: (id)object { self = [super init]; @try { - target = [target_ retain]; - selector = selector_; - object = [object_ retain]; + _target = [target retain]; + _selector = selector; + _object = [object retain]; } @catch (id e) { [self release]; @throw e; } return self; } #ifdef OF_HAVE_BLOCKS -- initWithBlock: (of_thread_pool_block_t)block_ +- initWithBlock: (of_thread_pool_block_t)block { self = [super init]; @try { - block = [block_ copy]; + _block = [block copy]; } @catch (id e) { [self release]; @throw e; } @@ -102,38 +102,38 @@ } #endif - (void)dealloc { - [target release]; - [object release]; + [_target release]; + [_object release]; #ifdef OF_HAVE_BLOCKS - [block release]; + [_block release]; #endif [super dealloc]; } - (void)perform { #ifdef OF_HAVE_BLOCKS - if (block != NULL) - block(); + if (_block != NULL) + _block(); else #endif - [object performSelector: selector - withObject: object]; + [_target performSelector: _selector + withObject: _object]; } @end @interface OFThreadPoolThread: OFThread { - OFList *queue; - OFCondition *queueCondition, *countCondition; + OFList *_queue; + OFCondition *_queueCondition, *_countCondition; @public - volatile BOOL terminate; - volatile int *doneCount; + volatile BOOL _terminate; + volatile int *_doneCount; } + (instancetype)threadWithThreadPool: (OFThreadPool*)threadPool; - initWithThreadPool: (OFThreadPool*)threadPool; @end @@ -147,14 +147,14 @@ - initWithThreadPool: (OFThreadPool*)threadPool { self = [super init]; @try { - queue = [threadPool->queue retain]; - queueCondition = [threadPool->queueCondition retain]; - countCondition = [threadPool->countCondition retain]; - doneCount = &threadPool->doneCount; + _queue = [threadPool->_queue retain]; + _queueCondition = [threadPool->_queueCondition retain]; + _countCondition = [threadPool->_countCondition retain]; + _doneCount = &threadPool->_doneCount; } @catch (id e) { [self release]; @throw e; } @@ -161,84 +161,84 @@ return self; } - (void)dealloc { - [queue release]; - [queueCondition release]; - [countCondition release]; + [_queue release]; + [_queueCondition release]; + [_countCondition release]; [super dealloc]; } - (id)main { void *pool; - if (terminate) + if (_terminate) return nil; pool = objc_autoreleasePoolPush(); for (;;) { OFThreadPoolJob *job; - [queueCondition lock]; - @try { - of_list_object_t *listObject; - - if (terminate) { - objc_autoreleasePoolPop(pool); - return nil; - } - - listObject = [queue firstListObject]; - - while (listObject == NULL) { - [queueCondition wait]; - - if (terminate) { - objc_autoreleasePoolPop(pool); - return nil; - } - - listObject = [queue firstListObject]; - } - - job = [[listObject->object retain] autorelease]; - [queue removeListObject: listObject]; - } @finally { - [queueCondition unlock]; - } - - if (terminate) { + [_queueCondition lock]; + @try { + of_list_object_t *listObject; + + if (_terminate) { + objc_autoreleasePoolPop(pool); + return nil; + } + + listObject = [_queue firstListObject]; + + while (listObject == NULL) { + [_queueCondition wait]; + + if (_terminate) { + objc_autoreleasePoolPop(pool); + return nil; + } + + listObject = [_queue firstListObject]; + } + + job = [[listObject->object retain] autorelease]; + [_queue removeListObject: listObject]; + } @finally { + [_queueCondition unlock]; + } + + if (_terminate) { objc_autoreleasePoolPop(pool); return nil; } [job perform]; - if (terminate) { + if (_terminate) { objc_autoreleasePoolPop(pool); return nil; } objc_autoreleasePoolPop(pool); pool = objc_autoreleasePoolPush(); - [countCondition lock]; + [_countCondition lock]; @try { - if (terminate) { + if (_terminate) { objc_autoreleasePoolPop(pool); return nil; } - (*doneCount)++; + (*_doneCount)++; - [countCondition signal]; + [_countCondition signal]; } @finally { - [countCondition unlock]; + [_countCondition unlock]; } } } @end @@ -256,43 +256,40 @@ - init { return [self initWithSize: [OFSystemInfo numberOfCPUs]]; } -- initWithSize: (size_t)size_ +- initWithSize: (size_t)size { self = [super init]; @try { size_t i; - size = size_; - threads = [[OFMutableArray alloc] init]; - queue = [[OFList alloc] init]; - queueCondition = [[OFCondition alloc] init]; - countCondition = [[OFCondition alloc] init]; + _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]; + [_threads addObject: thread]; 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. */ - for (i = 0; i < size; i++) { - OFThreadPoolThread *thread = [threads objectAtIndex: i]; - - [thread start]; - } + for (i = 0; i < size; i++) + [[_threads objectAtIndex: i] start]; } @catch (id e) { [self release]; @throw e; } @@ -300,63 +297,63 @@ } - (void)dealloc { void *pool = objc_autoreleasePoolPush(); - [queueCondition lock]; + [_queueCondition lock]; @try { - [countCondition lock]; + [_countCondition lock]; @try { - OFEnumerator *enumerator = [threads objectEnumerator]; + OFEnumerator *enumerator = [_threads objectEnumerator]; OFThreadPoolThread *thread; while ((thread = [enumerator nextObject]) != nil) - thread->terminate = YES; + thread->_terminate = YES; } @finally { - [countCondition unlock]; + [_countCondition unlock]; } - [queueCondition broadcast]; + [_queueCondition broadcast]; } @finally { - [queueCondition unlock]; + [_queueCondition unlock]; } objc_autoreleasePoolPop(pool); - [threads release]; - [queue release]; - [queueCondition release]; - [countCondition release]; + [_threads release]; + [_queue release]; + [_queueCondition release]; + [_countCondition release]; [super dealloc]; } - (void)OF_dispatchJob: (OFThreadPoolJob*)job { - [countCondition lock]; - count++; - [countCondition unlock]; + [_countCondition lock]; + _count++; + [_countCondition unlock]; - [queueCondition lock]; + [_queueCondition lock]; @try { - [queue appendObject: job]; - [queueCondition signal]; + [_queue appendObject: job]; + [_queueCondition signal]; } @finally { - [queueCondition unlock]; + [_queueCondition unlock]; } } - (void)waitUntilDone { for (;;) { - [countCondition lock]; + [_countCondition lock]; @try { - if (doneCount == count) + if (_doneCount == _count) return; - [countCondition wait]; + [_countCondition wait]; } @finally { - [countCondition unlock]; + [_countCondition unlock]; } } } - (void)dispatchWithTarget: (id)target @@ -375,8 +372,8 @@ } #endif - (size_t)size { - return size; + return _size; } @end Index: src/OFTimer.h ================================================================== --- src/OFTimer.h +++ src/OFTimer.h @@ -30,25 +30,25 @@ /*! * @brief A class for creating and firing timers. */ @interface OFTimer: OFObject { - OFDate *fireDate; - double interval; - id target, object1, object2; - SEL selector; - uint8_t arguments; - BOOL repeats; + OFDate *_fireDate; + double _interval; + id _target, _object1, _object2; + SEL _selector; + uint8_t _arguments; + BOOL _repeats; #ifdef OF_HAVE_BLOCKS - of_timer_block_t block; + of_timer_block_t _block; #endif - BOOL isValid; + BOOL _valid; #ifdef OF_HAVE_THREADS - OFCondition *condition; - BOOL done; + OFCondition *_condition; + BOOL _done; #endif - OFRunLoop *inRunLoop; + OFRunLoop *_inRunLoop; } #ifdef OF_HAVE_PROPERTIES @property (retain) OFDate *fireDate; #endif Index: src/OFTimer.m ================================================================== --- src/OFTimer.m +++ src/OFTimer.m @@ -215,109 +215,109 @@ } abort(); } -- OF_initWithFireDate: (OFDate*)fireDate_ - interval: (double)interval_ - target: (id)target_ - selector: (SEL)selector_ - object: (id)object1_ - object: (id)object2_ - arguments: (uint8_t)arguments_ - repeats: (BOOL)repeats_ +- OF_initWithFireDate: (OFDate*)fireDate + interval: (double)interval + target: (id)target + selector: (SEL)selector + object: (id)object1 + object: (id)object2 + arguments: (uint8_t)arguments + repeats: (BOOL)repeats { self = [super init]; @try { - fireDate = [fireDate_ retain]; - interval = interval_; - target = [target_ retain]; - selector = selector_; - object1 = [object1_ retain]; - object2 = [object2_ retain]; - arguments = arguments_; - repeats = repeats_; - isValid = YES; + _fireDate = [fireDate retain]; + _interval = interval; + _target = [target retain]; + _selector = selector; + _object1 = [object1 retain]; + _object2 = [object2 retain]; + _arguments = arguments; + _repeats = repeats; + _valid = YES; #ifdef OF_HAVE_THREADS - condition = [[OFCondition alloc] init]; + _condition = [[OFCondition alloc] init]; #endif } @catch (id e) { [self release]; @throw e; } return self; } -- initWithFireDate: (OFDate*)fireDate_ - interval: (double)interval_ - target: (id)target_ - selector: (SEL)selector_ - repeats: (BOOL)repeats_ -{ - return [self OF_initWithFireDate: fireDate_ - interval: interval_ - target: target_ - selector: selector_ +- initWithFireDate: (OFDate*)fireDate + interval: (double)interval + target: (id)target + selector: (SEL)selector + repeats: (BOOL)repeats +{ + return [self OF_initWithFireDate: fireDate + interval: interval + target: target + selector: selector object: nil object: nil arguments: 0 - repeats: repeats_]; + repeats: repeats]; } -- initWithFireDate: (OFDate*)fireDate_ - interval: (double)interval_ - target: (id)target_ - selector: (SEL)selector_ +- initWithFireDate: (OFDate*)fireDate + interval: (double)interval + target: (id)target + selector: (SEL)selector object: (id)object - repeats: (BOOL)repeats_ + repeats: (BOOL)repeats { - return [self OF_initWithFireDate: fireDate_ - interval: interval_ - target: target_ - selector: selector_ + return [self OF_initWithFireDate: fireDate + interval: interval + target: target + selector: selector object: object object: nil arguments: 1 - repeats: repeats_]; -} - -- initWithFireDate: (OFDate*)fireDate_ - interval: (double)interval_ - target: (id)target_ - selector: (SEL)selector_ - object: (id)object1_ - object: (id)object2_ - repeats: (BOOL)repeats_ -{ - return [self OF_initWithFireDate: fireDate_ - interval: interval_ - target: target_ - selector: selector_ - object: object1_ - object: object2_ + repeats: repeats]; +} + +- initWithFireDate: (OFDate*)fireDate + interval: (double)interval + target: (id)target + selector: (SEL)selector + object: (id)object1 + object: (id)object2 + repeats: (BOOL)repeats +{ + return [self OF_initWithFireDate: fireDate + interval: interval + target: target + selector: selector + object: object1 + object: object2 arguments: 2 - repeats: repeats_]; + repeats: repeats]; } #ifdef OF_HAVE_BLOCKS -- initWithFireDate: (OFDate*)fireDate_ - interval: (double)interval_ - repeats: (BOOL)repeats_ - block: (of_timer_block_t)block_ +- initWithFireDate: (OFDate*)fireDate + interval: (double)interval + repeats: (BOOL)repeats + block: (of_timer_block_t)block { self = [super init]; @try { - fireDate = [fireDate_ retain]; - interval = interval_; - repeats = repeats_; - block = [block_ copy]; - isValid = YES; + _fireDate = [fireDate retain]; + _interval = interval; + _repeats = repeats; + _block = [block copy]; + _valid = YES; # ifdef OF_HAVE_THREADS - condition = [[OFCondition alloc] init]; + _condition = [[OFCondition alloc] init]; # endif } @catch (id e) { [self release]; @throw e; } @@ -330,144 +330,144 @@ { /* * The run loop references the timer, so it should never be deallocated * if it is still in a run loop. */ - assert(inRunLoop == nil); + assert(_inRunLoop == nil); - [fireDate release]; - [target release]; - [object1 release]; - [object2 release]; + [_fireDate release]; + [_target release]; + [_object1 release]; + [_object2 release]; #ifdef OF_HAVE_BLOCKS - [block release]; + [_block release]; #endif #ifdef OF_HAVE_THREADS - [condition release]; + [_condition release]; #endif [super dealloc]; } -- (of_comparison_result_t)compare: (id )object_ +- (of_comparison_result_t)compare: (id )object { - OFTimer *otherTimer; + OFTimer *timer; - if (![object_ isKindOfClass: [OFTimer class]]) + if (![object isKindOfClass: [OFTimer class]]) @throw[OFInvalidArgumentException exceptionWithClass: [self class] selector: _cmd]; - otherTimer = (OFTimer*)object_; + timer = (OFTimer*)object; - return [fireDate compare: otherTimer->fireDate]; + return [_fireDate compare: timer->_fireDate]; } - (void)fire { - OF_ENSURE(arguments <= 2); + OF_ENSURE(_arguments <= 2); #ifdef OF_HAVE_BLOCKS - if (block != NULL) - block(self); + if (_block != NULL) + _block(self); else { #endif - switch (arguments) { + switch (_arguments) { case 0: - [target performSelector: selector]; + [_target performSelector: _selector]; break; case 1: - [target performSelector: selector - withObject: object1]; + [_target performSelector: _selector + withObject: _object1]; break; case 2: - [target performSelector: selector - withObject: object1 - withObject: object2]; + [_target performSelector: _selector + withObject: _object1 + withObject: _object2]; break; } #ifdef OF_HAVE_BLOCKS } #endif #ifdef OF_HAVE_THREADS - [condition lock]; + [_condition lock]; @try { - done = YES; - [condition signal]; + _done = YES; + [_condition signal]; } @finally { - [condition unlock]; + [_condition unlock]; } #endif - if (repeats && isValid) { - OFDate *old = fireDate; - fireDate = [[OFDate alloc] - initWithTimeIntervalSinceNow: interval]; + if (_repeats && _valid) { + OFDate *old = _fireDate; + _fireDate = [[OFDate alloc] + initWithTimeIntervalSinceNow: _interval]; [old release]; [[OFRunLoop currentRunLoop] addTimer: self]; } else [self invalidate]; } - (OFDate*)fireDate { - OF_GETTER(fireDate, YES) + OF_GETTER(_fireDate, YES) } -- (void)setFireDate: (OFDate*)fireDate_ +- (void)setFireDate: (OFDate*)fireDate { [self retain]; @try { @synchronized (self) { - [inRunLoop OF_removeTimer: self]; + [_inRunLoop OF_removeTimer: self]; - OF_SETTER(fireDate, fireDate_, YES, 0) + OF_SETTER(_fireDate, fireDate, YES, 0) - [inRunLoop addTimer: self]; + [_inRunLoop addTimer: self]; } } @finally { [self release]; } } - (double)timeInterval { - return interval; + return _interval; } - (void)invalidate { - isValid = NO; + _valid = NO; - [target release]; - target = nil; + [_target release]; + _target = nil; } - (BOOL)isValid { - return isValid; + return _valid; } #ifdef OF_HAVE_THREADS - (void)waitUntilDone { - [condition lock]; + [_condition lock]; @try { - if (done) { - done = NO; + if (_done) { + _done = NO; return; } - [condition wait]; + [_condition wait]; } @finally { - [condition unlock]; + [_condition unlock]; } } #endif -- (void)OF_setInRunLoop: (OFRunLoop*)inRunLoop_ +- (void)OF_setInRunLoop: (OFRunLoop*)inRunLoop { - OF_SETTER(inRunLoop, inRunLoop_, YES, 0) + OF_SETTER(_inRunLoop, inRunLoop, YES, 0) } @end Index: src/OFURL.h ================================================================== --- src/OFURL.h +++ src/OFURL.h @@ -22,19 +22,13 @@ /*! * @brief A class for parsing URLs and accessing parts of it. */ @interface OFURL: OFObject { - OFString *scheme; - OFString *host; - uint16_t port; - OFString *user; - OFString *password; - OFString *path; - OFString *parameters; - OFString *query; - OFString *fragment; + OFString *_scheme, *_host; + uint16_t _port; + OFString *_user, *_password, *_path, *_parameters, *_query, *_fragment; } #ifdef OF_HAVE_PROPERTIES @property (copy) OFString *scheme; @property (copy) OFString *host; Index: src/OFURL.m ================================================================== --- src/OFURL.m +++ src/OFURL.m @@ -65,19 +65,19 @@ requestedSize: [string UTF8StringLength]]; UTF8String = UTF8String2; if (!strncmp(UTF8String, "file://", 7)) { - scheme = @"file"; - path = [[OFString alloc] + _scheme = @"file"; + _path = [[OFString alloc] initWithUTF8String: UTF8String + 7]; return self; } else if (!strncmp(UTF8String, "http://", 7)) { - scheme = @"http"; + _scheme = @"http"; UTF8String += 7; } else if (!strncmp(UTF8String, "https://", 8)) { - scheme = @"https"; + _scheme = @"https"; UTF8String += 8; } else @throw [OFInvalidFormatException exceptionWithClass: [self class]]; @@ -94,16 +94,16 @@ if ((tmp3 = strchr(UTF8String, ':')) != NULL) { *tmp3 = '\0'; tmp3++; - user = [[OFString alloc] + _user = [[OFString alloc] initWithUTF8String: UTF8String]; - password = [[OFString alloc] + _password = [[OFString alloc] initWithUTF8String: tmp3]; } else - user = [[OFString alloc] + _user = [[OFString alloc] initWithUTF8String: UTF8String]; UTF8String = tmp2; } @@ -112,64 +112,64 @@ OFString *portString; *tmp2 = '\0'; tmp2++; - host = [[OFString alloc] + _host = [[OFString alloc] initWithUTF8String: UTF8String]; pool = objc_autoreleasePoolPush(); portString = [OFString stringWithUTF8String: tmp2]; if ([portString decimalValue] > 65535) @throw [OFInvalidFormatException exceptionWithClass: [self class]]; - port = [portString decimalValue]; + _port = [portString decimalValue]; - if (port == 0) - port = 80; + if (_port == 0) + _port = 80; objc_autoreleasePoolPop(pool); } else { - host = [[OFString alloc] + _host = [[OFString alloc] initWithUTF8String: UTF8String]; - if ([scheme isEqual: @"http"]) - port = 80; - else if ([scheme isEqual: @"https"]) - port = 443; + if ([_scheme isEqual: @"http"]) + _port = 80; + else if ([_scheme isEqual: @"https"]) + _port = 443; else assert(0); } if ((UTF8String = tmp) != NULL) { if ((tmp = strchr(UTF8String, '#')) != NULL) { *tmp = '\0'; - fragment = [[OFString alloc] + _fragment = [[OFString alloc] initWithUTF8String: tmp + 1]; } if ((tmp = strchr(UTF8String, '?')) != NULL) { *tmp = '\0'; - query = [[OFString alloc] + _query = [[OFString alloc] initWithUTF8String: tmp + 1]; } if ((tmp = strchr(UTF8String, ';')) != NULL) { *tmp = '\0'; - parameters = [[OFString alloc] + _parameters = [[OFString alloc] initWithUTF8String: tmp + 1]; } - path = [[OFString alloc] initWithFormat: @"/%s", - UTF8String]; + _path = [[OFString alloc] initWithFormat: @"/%s", + UTF8String]; } else - path = @""; + _path = @""; } @catch (id e) { [self release]; @throw e; } @finally { free(UTF8String2); @@ -189,15 +189,15 @@ self = [super init]; @try { char *tmp; - scheme = [URL->scheme copy]; - host = [URL->host copy]; - port = URL->port; - user = [URL->user copy]; - password = [URL->password copy]; + _scheme = [URL->_scheme copy]; + _host = [URL->_host copy]; + _port = URL->_port; + _user = [URL->_user copy]; + _password = [URL->_password copy]; if ((UTF8String2 = strdup([string UTF8String])) == NULL) @throw [OFOutOfMemoryException exceptionWithClass: [self class] requestedSize: [string UTF8StringLength]]; @@ -204,44 +204,44 @@ UTF8String = UTF8String2; if ((tmp = strchr(UTF8String, '#')) != NULL) { *tmp = '\0'; - fragment = [[OFString alloc] + _fragment = [[OFString alloc] initWithUTF8String: tmp + 1]; } if ((tmp = strchr(UTF8String, '?')) != NULL) { *tmp = '\0'; - query = [[OFString alloc] initWithUTF8String: tmp + 1]; + _query = [[OFString alloc] initWithUTF8String: tmp + 1]; } if ((tmp = strchr(UTF8String, ';')) != NULL) { *tmp = '\0'; - parameters = [[OFString alloc] + _parameters = [[OFString alloc] initWithUTF8String: tmp + 1]; } if (*UTF8String == '/') - path = [[OFString alloc] + _path = [[OFString alloc] initWithUTF8String: UTF8String]; else { void *pool; OFString *s; pool = objc_autoreleasePoolPush(); - if ([URL->path hasSuffix: @"/"]) + if ([URL->_path hasSuffix: @"/"]) s = [OFString stringWithFormat: @"%@%s", - URL->path, + URL->_path, UTF8String]; else s = [OFString stringWithFormat: @"%@/../%s", - URL->path, + URL->_path, UTF8String]; - path = [[s stringByStandardizingURLPath] copy]; + _path = [[s stringByStandardizingURLPath] copy]; objc_autoreleasePoolPop(pool); } } @catch (id e) { [self release]; @@ -275,52 +275,52 @@ return self; } - (void)dealloc { - [scheme release]; - [host release]; - [user release]; - [password release]; - [path release]; - [parameters release]; - [query release]; - [fragment release]; + [_scheme release]; + [_host release]; + [_user release]; + [_password release]; + [_path release]; + [_parameters release]; + [_query release]; + [_fragment release]; [super dealloc]; } - (BOOL)isEqual: (id)object { - OFURL *otherURL; + OFURL *URL; if (![object isKindOfClass: [OFURL class]]) return NO; - otherURL = object; - - if (![otherURL->scheme isEqual: scheme]) - return NO; - if (![otherURL->host isEqual: host]) - return NO; - if (otherURL->port != port) - return NO; - if (otherURL->user != user && ![otherURL->user isEqual: user]) - return NO; - if (otherURL->password != password && - ![otherURL->password isEqual: password]) - return NO; - if (![otherURL->path isEqual: path]) - return NO; - if (otherURL->parameters != parameters && - ![otherURL->parameters isEqual: parameters]) - return NO; - if (otherURL->query != query && - ![otherURL->query isEqual: query]) - return NO; - if (otherURL->fragment != fragment && - ![otherURL->fragment isEqual: fragment]) + URL = object; + + if (![URL->_scheme isEqual: _scheme]) + return NO; + if (![URL->_host isEqual: _host]) + return NO; + if (URL->_port != _port) + return NO; + if (URL->_user != _user && ![URL->_user isEqual: _user]) + return NO; + if (URL->_password != _password && + ![URL->_password isEqual: _password]) + return NO; + if (![URL->_path isEqual: _path]) + return NO; + if (URL->_parameters != _parameters && + ![URL->_parameters isEqual: _parameters]) + return NO; + if (URL->_query != _query && + ![URL->_query isEqual: _query]) + return NO; + if (URL->_fragment != _fragment && + ![URL->_fragment isEqual: _fragment]) return NO; return YES; } @@ -328,20 +328,20 @@ { uint32_t hash; OF_HASH_INIT(hash); - OF_HASH_ADD_HASH(hash, [scheme hash]); - OF_HASH_ADD_HASH(hash, [host hash]); - OF_HASH_ADD(hash, (port & 0xFF00) >> 8); - OF_HASH_ADD(hash, port & 0xFF); - OF_HASH_ADD_HASH(hash, [user hash]); - OF_HASH_ADD_HASH(hash, [password hash]); - OF_HASH_ADD_HASH(hash, [path hash]); - OF_HASH_ADD_HASH(hash, [parameters hash]); - OF_HASH_ADD_HASH(hash, [query hash]); - OF_HASH_ADD_HASH(hash, [fragment hash]); + OF_HASH_ADD_HASH(hash, [_scheme hash]); + OF_HASH_ADD_HASH(hash, [_host hash]); + OF_HASH_ADD(hash, (_port & 0xFF00) >> 8); + OF_HASH_ADD(hash, _port & 0xFF); + OF_HASH_ADD_HASH(hash, [_user hash]); + OF_HASH_ADD_HASH(hash, [_password hash]); + OF_HASH_ADD_HASH(hash, [_path hash]); + OF_HASH_ADD_HASH(hash, [_parameters hash]); + OF_HASH_ADD_HASH(hash, [_query hash]); + OF_HASH_ADD_HASH(hash, [_fragment hash]); OF_HASH_FINALIZE(hash); return hash; } @@ -349,19 +349,19 @@ - copy { OFURL *copy = [[[self class] alloc] init]; @try { - copy->scheme = [scheme copy]; - copy->host = [host copy]; - copy->port = port; - copy->user = [user copy]; - copy->password = [password copy]; - copy->path = [path copy]; - copy->parameters = [parameters copy]; - copy->query = [query copy]; - copy->fragment = [fragment copy]; + copy->_scheme = [_scheme copy]; + copy->_host = [_host copy]; + copy->_port = _port; + copy->_user = [_user copy]; + copy->_password = [_password copy]; + copy->_path = [_path copy]; + copy->_parameters = [_parameters copy]; + copy->_query = [_query copy]; + copy->_fragment = [_fragment copy]; } @catch (id e) { [copy release]; @throw e; } @@ -368,148 +368,144 @@ return copy; } - (OFString*)scheme { - OF_GETTER(scheme, YES) + OF_GETTER(_scheme, YES) } -- (void)setScheme: (OFString*)scheme_ +- (void)setScheme: (OFString*)scheme { - if (![scheme_ isEqual: @"http"] && ![scheme_ isEqual: @"https"]) + if (![scheme isEqual: @"http"] && ![scheme isEqual: @"https"]) @throw [OFInvalidArgumentException exceptionWithClass: [self class] selector: _cmd]; - OF_SETTER(scheme, scheme_, YES, 1) + OF_SETTER(_scheme, scheme, YES, 1) } - (OFString*)host { - OF_GETTER(host, YES) + OF_GETTER(_host, YES) } -- (void)setHost: (OFString*)host_ +- (void)setHost: (OFString*)host { - OF_SETTER(host, host_, YES, 1) + OF_SETTER(_host, host, YES, 1) } - (uint16_t)port { - return port; + return _port; } -- (void)setPort: (uint16_t)port_ +- (void)setPort: (uint16_t)port { - port = port_; + _port = port; } - (OFString*)user { - OF_GETTER(user, YES) + OF_GETTER(_user, YES) } -- (void)setUser: (OFString*)user_ +- (void)setUser: (OFString*)user { - OF_SETTER(user, user_, YES, 1) + OF_SETTER(_user, user, YES, 1) } - (OFString*)password { - OF_GETTER(password, YES) + OF_GETTER(_password, YES) } -- (void)setPassword: (OFString*)password_ +- (void)setPassword: (OFString*)password { - OF_SETTER(password, password_, YES, 1) + OF_SETTER(_password, password, YES, 1) } - (OFString*)path { - OF_GETTER(path, YES) + OF_GETTER(_path, YES) } -- (void)setPath: (OFString*)path_ +- (void)setPath: (OFString*)path { - if (([scheme isEqual: @"http"] || [scheme isEqual: @"https"]) && - ![path_ hasPrefix: @"/"]) + if (([_scheme isEqual: @"http"] || [_scheme isEqual: @"https"]) && + ![path hasPrefix: @"/"]) @throw [OFInvalidArgumentException exceptionWithClass: [self class] selector: _cmd]; - OF_SETTER(path, path_, YES, 1) + OF_SETTER(_path, path, YES, 1) } - (OFString*)parameters { - OF_GETTER(parameters, YES) + OF_GETTER(_parameters, YES) } -- (void)setParameters: (OFString*)parameters_ +- (void)setParameters: (OFString*)parameters { - OF_SETTER(parameters, parameters_, YES, 1) + OF_SETTER(_parameters, parameters, YES, 1) } - (OFString*)query { - OF_GETTER(query, YES) + OF_GETTER(_query, YES) } -- (void)setQuery: (OFString*)query_ +- (void)setQuery: (OFString*)query { - OF_SETTER(query, query_, YES, 1) + OF_SETTER(_query, query, YES, 1) } - (OFString*)fragment { - OF_GETTER(fragment, YES) + OF_GETTER(_fragment, YES) } -- (void)setFragment: (OFString*)fragment_ +- (void)setFragment: (OFString*)fragment { - OF_SETTER(fragment, fragment_, YES, 1) + OF_SETTER(_fragment, fragment, YES, 1) } - (OFString*)string { OFMutableString *ret = [OFMutableString stringWithFormat: @"%@://", - scheme]; - BOOL needPort = YES; + _scheme]; - if ([scheme isEqual: @"file"]) { - if (path != nil) - [ret appendString: path]; + if ([_scheme isEqual: @"file"]) { + if (_path != nil) + [ret appendString: _path]; return ret; } - if (user != nil && password != nil) - [ret appendFormat: @"%@:%@@", user, password]; - else if (user != nil) - [ret appendFormat: @"%@@", user]; - - if (host != nil) - [ret appendString: host]; - - if (([scheme isEqual: @"http"] && port == 80) || - ([scheme isEqual: @"https"] && port == 443)) - needPort = NO; - - if (needPort) - [ret appendFormat: @":%d", port]; - - if (path != nil) - [ret appendString: path]; - - if (parameters != nil) - [ret appendFormat: @";%@", parameters]; - - if (query != nil) - [ret appendFormat: @"?%@", query]; - - if (fragment != nil) - [ret appendFormat: @"#%@", fragment]; + if (_user != nil && _password != nil) + [ret appendFormat: @"%@:%@@", _user, _password]; + else if (_user != nil) + [ret appendFormat: @"%@@", _user]; + + if (_host != nil) + [ret appendString: _host]; + + if (([_scheme isEqual: @"http"] && _port != 80) || + ([_scheme isEqual: @"https"] && _port != 443)) + [ret appendFormat: @":%u", _port]; + + if (_path != nil) + [ret appendString: _path]; + + if (_parameters != nil) + [ret appendFormat: @";%@", _parameters]; + + if (_query != nil) + [ret appendFormat: @"?%@", _query]; + + if (_fragment != nil) + [ret appendFormat: @"#%@", _fragment]; [ret makeImmutable]; return ret; } Index: src/OFXMLAttribute.h ================================================================== --- src/OFXMLAttribute.h +++ src/OFXMLAttribute.h @@ -22,19 +22,15 @@ * @brief A representation of an attribute of an XML element as an object. */ @interface OFXMLAttribute: OFXMLNode { @public - OFString *name; - OFString *ns; - OFString *stringValue; + OFString *_name, *_namespace, *_stringValue; } #ifdef OF_HAVE_PROPERTIES -@property (readonly, copy) OFString *name; -@property (readonly, copy, getter=namespace) OFString *ns; -@property (readonly, copy) OFString *stringValue; +@property (readonly, copy) OFString *name, *namespace, *stringValue; #endif /*! * @brief Creates a new XML attribute. * @@ -47,16 +43,16 @@ /*! * @brief Creates a new XML attribute. * * @param name The name of the attribute - * @param ns The namespace of the attribute + * @param namespace_ The namespace of the attribute * @param stringValue The string value of the attribute * @return A new autoreleased OFXMLAttribute with the specified parameters */ + (instancetype)attributeWithName: (OFString*)name - namespace: (OFString*)ns + namespace: (OFString*)namespace_ stringValue: (OFString*)stringValue; /*! * @brief Initializes an already allocated OFXMLAttribute. * @@ -69,16 +65,16 @@ /*! * @brief Initializes an already allocated OFXMLAttribute. * * @param name The name of the attribute - * @param ns The namespace of the attribute + * @param namespace_ The namespace of the attribute * @param stringValue The string value of the attribute * @return An initialized OFXMLAttribute with the specified parameters */ - initWithName: (OFString*)name - namespace: (OFString*)ns + namespace: (OFString*)namespace_ stringValue: (OFString*)stringValue; /*! * @brief Returns the name of the attribute as an autoreleased OFString. * Index: src/OFXMLAttribute.m ================================================================== --- src/OFXMLAttribute.m +++ src/OFXMLAttribute.m @@ -26,15 +26,15 @@ #import "autorelease.h" #import "macros.h" @implementation OFXMLAttribute + (instancetype)attributeWithName: (OFString*)name - namespace: (OFString*)ns + namespace: (OFString*)namespace stringValue: (OFString*)stringValue { return [[[self alloc] initWithName: name - namespace: ns + namespace: namespace stringValue: stringValue] autorelease]; } + (instancetype)attributeWithName: (OFString*)name stringValue: (OFString*)stringValue @@ -41,28 +41,28 @@ { return [[[self alloc] initWithName: name stringValue: stringValue] autorelease]; } -- initWithName: (OFString*)name_ - stringValue: (OFString*)stringValue_ +- initWithName: (OFString*)name + stringValue: (OFString*)stringValue { - return [self initWithName: name_ + return [self initWithName: name namespace: nil - stringValue: stringValue_]; + stringValue: stringValue]; } -- initWithName: (OFString*)name_ - namespace: (OFString*)ns_ - stringValue: (OFString*)stringValue_ +- initWithName: (OFString*)name + namespace: (OFString*)namespace + stringValue: (OFString*)stringValue { self = [super init]; @try { - name = [name_ copy]; - ns = [ns_ copy]; - stringValue = [stringValue_ copy]; + _name = [name copy]; + _namespace = [namespace copy]; + _stringValue = [stringValue copy]; } @catch (id e) { [self release]; @throw e; } @@ -80,15 +80,15 @@ ![[element namespace] isEqual: OF_SERIALIZATION_NS]) @throw [OFInvalidArgumentException exceptionWithClass: [self class] selector: _cmd]; - name = [[[element attributeForName: @"name"] stringValue] - copy]; - ns = [[[element attributeForName: @"namespace"] stringValue] - copy]; - stringValue = [[[element attributeForName: @"stringValue"] + _name = [[[element attributeForName: @"name"] + stringValue] copy]; + _namespace = [[[element attributeForName: @"namespace"] + stringValue] copy]; + _stringValue = [[[element attributeForName: @"stringValue"] stringValue] copy]; objc_autoreleasePoolPop(pool); } @catch (id e) { [self release]; @@ -98,46 +98,47 @@ return self; } - (void)dealloc { - [name release]; - [ns release]; - [stringValue release]; + [_name release]; + [_namespace release]; + [_stringValue release]; [super dealloc]; } - (OFString*)name { - OF_GETTER(name, YES) + OF_GETTER(_name, YES) } - (OFString*)namespace { - OF_GETTER(ns, YES) + OF_GETTER(_namespace, YES) } - (OFString*)stringValue { - OF_GETTER(stringValue, YES) + OF_GETTER(_stringValue, YES) } - (BOOL)isEqual: (id)object { - OFXMLAttribute *otherAttribute; + OFXMLAttribute *attribute; if (![object isKindOfClass: [OFXMLAttribute class]]) return NO; - otherAttribute = object; + attribute = object; - if (![otherAttribute->name isEqual: name]) + if (![attribute->_name isEqual: _name]) + return NO; + if (attribute->_namespace != _namespace && + ![attribute->_namespace isEqual: _namespace]) return NO; - if (otherAttribute->ns != ns && ![otherAttribute->ns isEqual: ns]) - return NO; - if (![otherAttribute->stringValue isEqual: stringValue]) + if (![attribute->_stringValue isEqual: _stringValue]) return NO; return YES; } @@ -145,13 +146,13 @@ { uint32_t hash; OF_HASH_INIT(hash); - OF_HASH_ADD_HASH(hash, [name hash]); - OF_HASH_ADD_HASH(hash, [ns hash]); - OF_HASH_ADD_HASH(hash, [stringValue hash]); + OF_HASH_ADD_HASH(hash, [_name hash]); + OF_HASH_ADD_HASH(hash, [_namespace hash]); + OF_HASH_ADD_HASH(hash, [_stringValue hash]); OF_HASH_FINALIZE(hash); return hash; } @@ -163,18 +164,18 @@ element = [OFXMLElement elementWithName: [self className] namespace: OF_SERIALIZATION_NS]; [element addAttributeWithName: @"name" - stringValue: name]; + stringValue: _name]; - if (ns != nil) + if (_namespace != nil) [element addAttributeWithName: @"namespace" - stringValue: ns]; + stringValue: _namespace]; [element addAttributeWithName: @"stringValue" - stringValue: stringValue]; + stringValue: _stringValue]; [element retain]; objc_autoreleasePoolPop(pool); @@ -183,8 +184,8 @@ - (OFString*)description { return [OFString stringWithFormat: @"", - name, ns, stringValue]; + _name, _namespace, _stringValue]; } @end Index: src/OFXMLCDATA.h ================================================================== --- src/OFXMLCDATA.h +++ src/OFXMLCDATA.h @@ -19,11 +19,11 @@ /*! * @brief A class representing XML CDATA. */ @interface OFXMLCDATA: OFXMLNode { - OFString *CDATA; + OFString *_CDATA; } /*! * @brief Creates a new OFXMLCDATA with the specified string. * Index: src/OFXMLCDATA.m ================================================================== --- src/OFXMLCDATA.m +++ src/OFXMLCDATA.m @@ -33,11 +33,11 @@ - initWithString: (OFString*)string { self = [super init]; @try { - CDATA = [string copy]; + _CDATA = [string copy]; } @catch (id e) { [self release]; @throw e; } @@ -55,11 +55,11 @@ ![[element namespace] isEqual: OF_SERIALIZATION_NS]) @throw [OFInvalidArgumentException exceptionWithClass: [self class] selector: _cmd]; - CDATA = [[element stringValue] copy]; + _CDATA = [[element stringValue] copy]; objc_autoreleasePoolPop(pool); } @catch (id e) { [self release]; @throw e; @@ -68,49 +68,50 @@ return self; } - (BOOL)isEqual: (id)object { - OFXMLCDATA *otherCDATA; + OFXMLCDATA *CDATA; if (![object isKindOfClass: [OFXMLCDATA class]]) return NO; - otherCDATA = object; + CDATA = object; - return ([otherCDATA->CDATA isEqual: CDATA]); + return ([CDATA->_CDATA isEqual: _CDATA]); } - (uint32_t)hash { - return [CDATA hash]; + return [_CDATA hash]; } - (OFString*)stringValue { - return [[CDATA copy] autorelease]; + return [[_CDATA copy] autorelease]; } - (OFString*)XMLString { - return [OFString stringWithFormat: @"", CDATA]; + /* FIXME: What to do about ]]>? */ + return [OFString stringWithFormat: @"", _CDATA]; } - (OFString*)XMLStringWithIndentation: (unsigned int)indentation { - return [OFString stringWithFormat: @"", CDATA]; + return [self XMLString]; } - (OFString*)XMLStringWithIndentation: (unsigned int)indentation level: (unsigned int)level { - return [OFString stringWithFormat: @"", CDATA]; + return [self XMLString]; } - (OFString*)description { - return [OFString stringWithFormat: @"", CDATA]; + return [self XMLString]; } - (OFXMLElement*)XMLElementBySerializing { OFXMLElement *element = Index: src/OFXMLCharacters.h ================================================================== --- src/OFXMLCharacters.h +++ src/OFXMLCharacters.h @@ -19,11 +19,11 @@ /*! * @brief A class representing XML characters. */ @interface OFXMLCharacters: OFXMLNode { - OFString *characters; + OFString *_characters; } /*! * @brief Creates a new OFXMLCharacters with the specified string. * Index: src/OFXMLCharacters.m ================================================================== --- src/OFXMLCharacters.m +++ src/OFXMLCharacters.m @@ -33,11 +33,11 @@ - initWithString: (OFString*)string { self = [super init]; @try { - characters = [string copy]; + _characters = [string copy]; } @catch (id e) { [self release]; @throw e; } @@ -55,11 +55,11 @@ ![[element namespace] isEqual: OF_SERIALIZATION_NS]) @throw [OFInvalidArgumentException exceptionWithClass: [self class] selector: _cmd]; - characters = [[element stringValue] copy]; + _characters = [[element stringValue] copy]; objc_autoreleasePoolPop(pool); } @catch (id e) { [self release]; @throw e; @@ -68,53 +68,53 @@ return self; } - (BOOL)isEqual: (id)object { - OFXMLCharacters *otherCharacters; + OFXMLCharacters *characters; if (![object isKindOfClass: [OFXMLCharacters class]]) return NO; - otherCharacters = object; + characters = object; - return ([otherCharacters->characters isEqual: characters]); + return ([characters->_characters isEqual: _characters]); } - (uint32_t)hash { - return [characters hash]; + return [_characters hash]; } - (OFString*)stringValue { - return [[characters copy] autorelease]; + return [[_characters copy] autorelease]; } - (OFString*)XMLString { - return [characters stringByXMLEscaping]; + return [_characters stringByXMLEscaping]; } - (OFString*)XMLStringWithIndentation: (unsigned int)indentation { - return [characters stringByXMLEscaping]; + return [_characters stringByXMLEscaping]; } - (OFString*)XMLStringWithIndentation: (unsigned int)indentation level: (unsigned int)level { - return [characters stringByXMLEscaping]; + return [_characters stringByXMLEscaping]; } - (OFString*)description { - return [characters stringByXMLEscaping]; + return [_characters stringByXMLEscaping]; } - (OFXMLElement*)XMLElementBySerializing { return [OFXMLElement elementWithName: [self className] namespace: OF_SERIALIZATION_NS - stringValue: characters]; + stringValue: _characters]; } @end Index: src/OFXMLComment.h ================================================================== --- src/OFXMLComment.h +++ src/OFXMLComment.h @@ -19,11 +19,11 @@ /*! * @brief A class for representing XML comments. */ @interface OFXMLComment: OFXMLNode { - OFString *comment; + OFString *_comment; } /*! * @brief Creates a new OFXMLComment with the specified string. * Index: src/OFXMLComment.m ================================================================== --- src/OFXMLComment.m +++ src/OFXMLComment.m @@ -35,11 +35,11 @@ - initWithString: (OFString*)string { self = [super init]; @try { - comment = [string copy]; + _comment = [string copy]; } @catch (id e) { [self release]; @throw e; } @@ -57,11 +57,11 @@ ![[element namespace] isEqual: OF_SERIALIZATION_NS]) @throw [OFInvalidArgumentException exceptionWithClass: [self class] selector: _cmd]; - comment = [[element stringValue] copy]; + _comment = [[element stringValue] copy]; objc_autoreleasePoolPop(pool); } @catch (id e) { [self release]; @throw e; @@ -70,38 +70,38 @@ return self; } - (BOOL)isEqual: (id)object { - OFXMLComment *otherComment; + OFXMLComment *comment; if (![object isKindOfClass: [OFXMLComment class]]) return NO; - otherComment = object; + comment = object; - return ([otherComment->comment isEqual: comment]); + return ([comment->_comment isEqual: _comment]); } - (uint32_t)hash { - return [comment hash]; + return [_comment hash]; } - (OFString*)stringValue { return @""; } - (OFString*)XMLString { - return [OFString stringWithFormat: @"", comment]; + return [OFString stringWithFormat: @"", _comment]; } - (OFString*)XMLStringWithIndentation: (unsigned int)indentation { - return [OFString stringWithFormat: @"", comment]; + return [OFString stringWithFormat: @"", _comment]; } - (OFString*)XMLStringWithIndentation: (unsigned int)indentation level: (unsigned int)level { @@ -114,27 +114,27 @@ whitespaces[level * indentation] = 0; @try { ret = [OFString stringWithFormat: @"%s", whitespaces, - comment]; + _comment]; } @finally { [self freeMemory: whitespaces]; } } else - ret = [OFString stringWithFormat: @"", comment]; + ret = [OFString stringWithFormat: @"", _comment]; return ret; } - (OFString*)description { - return [OFString stringWithFormat: @"", comment]; + return [OFString stringWithFormat: @"", _comment]; } - (OFXMLElement*)XMLElementBySerializing { return [OFXMLElement elementWithName: [self className] namespace: OF_SERIALIZATION_NS - stringValue: comment]; + stringValue: _comment]; } @end Index: src/OFXMLElement+Serialization.m ================================================================== --- src/OFXMLElement+Serialization.m +++ src/OFXMLElement+Serialization.m @@ -33,11 +33,11 @@ { void *pool = objc_autoreleasePoolPush(); Class class; id object; - if ((class = objc_getClass([name cStringWithEncoding: + if ((class = objc_getClass([_name cStringWithEncoding: OF_STRING_ENCODING_ASCII])) == Nil) @throw [OFInvalidArgumentException exceptionWithClass: [self class]]; if (![class conformsToProtocol: @protocol(OFSerialization)]) Index: src/OFXMLElement.h ================================================================== --- src/OFXMLElement.h +++ src/OFXMLElement.h @@ -26,24 +26,20 @@ /*! * @brief A class which stores an XML element. */ @interface OFXMLElement: OFXMLNode { - OFString *name; - OFString *ns; - OFString *defaultNamespace; - OFMutableArray *attributes; - OFMutableDictionary *namespaces; - OFMutableArray *children; + OFString *_name, *_namespace, *_defaultNamespace; + OFMutableArray *_attributes; + OFMutableDictionary *_namespaces; + OFMutableArray *_children; } #ifdef OF_HAVE_PROPERTIES -@property (copy) OFString *name; -@property (copy, getter=namespace, setter=setNamespace:) OFString *ns; -@property (copy) OFString *defaultNamespace; +@property (copy) OFString *name, *namespace, *defaultNamespace; @property (readonly, copy) OFArray *attributes; -@property (readonly, copy) OFArray *children; +@property (copy) OFArray *children; #endif /*! * @brief Creates a new XML element with the specified name. * @@ -65,29 +61,29 @@ /*! * @brief Creates a new XML element with the specified name and namespace. * * @param name The name for the element - * @param ns The namespace for the element + * @param namespace The namespace for the element * @return A new autoreleased OFXMLElement with the specified element name and * namespace */ + (instancetype)elementWithName: (OFString*)name - namespace: (OFString*)ns; + namespace: (OFString*)namespace; /*! * @brief Creates a new XML element with the specified name, namespace and * string value. * * @param name The name for the element - * @param ns The namespace for the element + * @param namespace The namespace for the element * @param stringValue The value for the element * @return A new autoreleased OFXMLElement with the specified element name, * namespace and value */ + (instancetype)elementWithName: (OFString*)name - namespace: (OFString*)ns + namespace: (OFString*)namespace stringValue: (OFString*)stringValue; /*! * @brief Creates a new element with the specified element. * @@ -137,29 +133,29 @@ /*! * @brief Initializes an already allocated OFXMLElement with the specified name * and namespace. * * @param name The name for the element - * @param ns The namespace for the element + * @param namespace The namespace for the element * @return An initialized OFXMLElement with the specified element name and * namespace */ - initWithName: (OFString*)name - namespace: (OFString*)ns; + namespace: (OFString*)namespace; /*! * @brief Initializes an already allocated OFXMLElement with the specified name, * namespace and value. * * @param name The name for the element - * @param ns The namespace for the element + * @param namespace The namespace for the element * @param stringValue The value for the element * @return An initialized OFXMLElement with the specified element name, * namespace and value */ - initWithName: (OFString*)name - namespace: (OFString*)ns + namespace: (OFString*)namespace stringValue: (OFString*)stringValue; /*! * @brief Initializes an already allocated OFXMLElement with the specified * element. @@ -203,13 +199,13 @@ - (OFString*)name; /*! * @brief Sets the namespace of the element. * - * @param ns The new namespace + * @param namespace The new namespace */ -- (void)setNamespace: (OFString*)ns; +- (void)setNamespace: (OFString*)namespace; /*! * @brief Returns the namespace of the element. * * @return The namespace of the element @@ -273,15 +269,15 @@ * * If an attribute with the same name and namespace already exists, it is not * added. * * @param name The name of the attribute - * @param ns The namespace of the attribute + * @param namespace The namespace of the attribute * @param stringValue The value of the attribute */ - (void)addAttributeWithName: (OFString*)name - namespace: (OFString*)ns + namespace: (OFString*)namespace stringValue: (OFString*)stringValue; /*! * @brief Returns the attribute with the specified name. * @@ -318,31 +314,31 @@ /*! * @brief Sets a prefix for a namespace. * * @param prefix The prefix for the namespace - * @param ns The namespace for which the prefix is set + * @param namespace The namespace for which the prefix is set */ - (void)setPrefix: (OFString*)prefix - forNamespace: (OFString*)ns; + forNamespace: (OFString*)namespace; /*! * @brief Binds a prefix for a namespace. * * @param prefix The prefix for the namespace - * @param ns The namespace for which the prefix is bound + * @param namespace The namespace for which the prefix is bound */ - (void)bindPrefix: (OFString*)prefix - forNamespace: (OFString*)ns; + forNamespace: (OFString*)namespace; /*! * @brief Sets the default namespace for the element to be used if there is no * parent. * - * @param ns The default namespace for the element + * @param defaultNamespace The default namespace for the element */ -- (void)setDefaultNamespace: (OFString*)ns; +- (void)setDefaultNamespace: (OFString*)defaultNamespace; /*! * @brief Adds a child to the OFXMLElement. * * @param child An OFXMLNode which is added as a child Index: src/OFXMLElement.m ================================================================== --- src/OFXMLElement.m +++ src/OFXMLElement.m @@ -50,25 +50,25 @@ static Class CDATAClass = Nil; @interface OFXMLElement_OFXMLElementBuilderDelegate: OFObject { @public - OFXMLElement *element; + OFXMLElement *_element; } @end @implementation OFXMLElement_OFXMLElementBuilderDelegate - (void)elementBuilder: (OFXMLElementBuilder*)builder - didBuildElement: (OFXMLElement*)element_ + didBuildElement: (OFXMLElement*)element { - if (element == nil) - element = [element_ retain]; + if (_element == nil) + _element = [element retain]; } - (void)dealloc { - [element release]; + [_element release]; [super dealloc]; } @end @@ -134,49 +134,49 @@ } abort(); } -- initWithName: (OFString*)name_ +- initWithName: (OFString*)name { - return [self initWithName: name_ + return [self initWithName: name namespace: nil stringValue: nil]; } -- initWithName: (OFString*)name_ +- initWithName: (OFString*)name stringValue: (OFString*)stringValue { - return [self initWithName: name_ + return [self initWithName: name namespace: nil stringValue: stringValue]; } -- initWithName: (OFString*)name_ - namespace: (OFString*)ns_ +- initWithName: (OFString*)name + namespace: (OFString*)namespace { - return [self initWithName: name_ - namespace: ns_ + return [self initWithName: name + namespace: namespace stringValue: nil]; } -- initWithName: (OFString*)name_ - namespace: (OFString*)ns_ +- initWithName: (OFString*)name + namespace: (OFString*)namespace stringValue: (OFString*)stringValue { self = [super init]; @try { - if (name_ == nil) + if (name == nil) @throw [OFInvalidArgumentException exceptionWithClass: [self class] selector: _cmd]; - name = [name_ copy]; - ns = [ns_ copy]; + _name = [name copy]; + _namespace = [namespace copy]; - namespaces = [[OFMutableDictionary alloc] + _namespaces = [[OFMutableDictionary alloc] initWithKeysAndObjects: @"http://www.w3.org/XML/1998/namespace", @"xml", @"http://www.w3.org/2000/xmlns/", @"xmlns", nil]; if (stringValue != nil) @@ -197,16 +197,16 @@ if (element == nil) @throw [OFInvalidArgumentException exceptionWithClass: [self class] selector: _cmd]; - name = [element->name copy]; - ns = [element->ns copy]; - defaultNamespace = [element->defaultNamespace copy]; - attributes = [element->attributes mutableCopy]; - namespaces = [element->namespaces mutableCopy]; - children = [element->children mutableCopy]; + _name = [element->_name copy]; + _namespace = [element->_namespace copy]; + _defaultNamespace = [element->_defaultNamespace copy]; + _attributes = [element->_attributes mutableCopy]; + _namespaces = [element->_namespaces mutableCopy]; + _children = [element->_children mutableCopy]; } @catch (id e) { [self release]; @throw e; } @@ -242,11 +242,11 @@ if (![parser finishedParsing]) @throw [OFMalformedXMLException exceptionWithClass: c parser: parser]; - self = [delegate->element retain]; + self = [delegate->_element retain]; objc_autoreleasePoolPop(pool); return self; } @@ -276,11 +276,11 @@ if (![parser finishedParsing]) @throw [OFMalformedXMLException exceptionWithClass: c parser: parser]; - self = [delegate->element retain]; + self = [delegate->_element retain]; objc_autoreleasePoolPop(pool); return self; } @@ -300,14 +300,15 @@ ![[element namespace] isEqual: OF_SERIALIZATION_NS]) @throw [OFInvalidArgumentException exceptionWithClass: [self class] selector: _cmd]; - name = [[[element attributeForName: @"name"] stringValue] copy]; - ns = [[[element attributeForName: @"namespace"] stringValue] - copy]; - defaultNamespace = [[[element attributeForName: + _name = [[[element attributeForName: @"name"] + stringValue] copy]; + _namespace = [[[element attributeForName: @"namespace"] + stringValue] copy]; + _defaultNamespace = [[[element attributeForName: @"defaultNamespace"] stringValue] copy]; attributesElement = [[[element elementForName: @"attributes" namespace: OF_SERIALIZATION_NS] elementsForNamespace: @@ -319,61 +320,61 @@ childrenElement = [[[element elementForName: @"children" namespace: OF_SERIALIZATION_NS] elementsForNamespace: OF_SERIALIZATION_NS] firstObject]; - attributes = [[attributesElement objectByDeserializing] + _attributes = [[attributesElement objectByDeserializing] mutableCopy]; - namespaces = [[namespacesElement objectByDeserializing] + _namespaces = [[namespacesElement objectByDeserializing] mutableCopy]; - children = [[childrenElement objectByDeserializing] + _children = [[childrenElement objectByDeserializing] mutableCopy]; /* Sanity checks */ - if ((attributes != nil && - ![attributes isKindOfClass: [OFMutableArray class]]) || - (namespaces != nil && - ![namespaces isKindOfClass: [OFMutableDictionary class]]) || - (children != nil && - ![children isKindOfClass: [OFMutableArray class]])) + if ((_attributes != nil && ![_attributes isKindOfClass: + [OFMutableArray class]]) || (_namespaces != nil && + ![_namespaces isKindOfClass: + [OFMutableDictionary class]]) || (_children != nil && + ![_children isKindOfClass: [OFMutableArray class]])) @throw [OFInvalidArgumentException exceptionWithClass: [self class] selector: _cmd]; - objectEnumerator = [attributes objectEnumerator]; + objectEnumerator = [_attributes objectEnumerator]; while ((object = [objectEnumerator nextObject]) != nil) if (![object isKindOfClass: [OFXMLAttribute class]]) @throw [OFInvalidArgumentException exceptionWithClass: [self class] selector: _cmd]; - keyEnumerator = [namespaces keyEnumerator]; - objectEnumerator = [namespaces objectEnumerator]; + keyEnumerator = [_namespaces keyEnumerator]; + objectEnumerator = [_namespaces objectEnumerator]; while ((key = [keyEnumerator nextObject]) != nil && (object = [objectEnumerator nextObject]) != nil) if (![key isKindOfClass: [OFString class]] || ![object isKindOfClass: [OFString class]]) @throw [OFInvalidArgumentException exceptionWithClass: [self class] selector: _cmd]; - objectEnumerator = [children objectEnumerator]; + objectEnumerator = [_children objectEnumerator]; while ((object = [objectEnumerator nextObject]) != nil) if (![object isKindOfClass: [OFXMLNode class]]) @throw [OFInvalidArgumentException exceptionWithClass: [self class] selector: _cmd]; - if (namespaces == nil) - namespaces = [[OFMutableDictionary alloc] init]; - - [namespaces setObject: @"xml" - forKey: @"http://www.w3.org/XML/1998/namespace"]; - [namespaces setObject: @"xmlns" - forKey: @"http://www.w3.org/2000/xmlns/"]; - - if (name == nil) + if (_namespaces == nil) + _namespaces = [[OFMutableDictionary alloc] init]; + + [_namespaces + setObject: @"xml" + forKey: @"http://www.w3.org/XML/1998/namespace"]; + [_namespaces setObject: @"xmlns" + forKey: @"http://www.w3.org/2000/xmlns/"]; + + if (_name == nil) @throw [OFInvalidArgumentException exceptionWithClass: [self class] selector: _cmd]; objc_autoreleasePoolPop(pool); @@ -383,48 +384,60 @@ } return self; } -- (void)setName: (OFString*)name_ +- (void)dealloc +{ + [_name release]; + [_namespace release]; + [_defaultNamespace release]; + [_attributes release]; + [_namespaces release]; + [_children release]; + + [super dealloc]; +} + +- (void)setName: (OFString*)name { - if (name_ == nil) + if (name == nil) @throw [OFInvalidArgumentException exceptionWithClass: [self class] selector: _cmd]; - OF_SETTER(name, name_, YES, 1) + OF_SETTER(_name, name, YES, 1) } - (OFString*)name { - OF_GETTER(name, YES) + OF_GETTER(_name, YES) } -- (void)setNamespace: (OFString*)ns_ +- (void)setNamespace: (OFString*)namespace { - OF_SETTER(ns, ns_, YES, 1) + OF_SETTER(_namespace, namespace, YES, 1) } - (OFString*)namespace { - OF_GETTER(ns, YES) + OF_GETTER(_namespace, YES) } - (OFArray*)attributes { - OF_GETTER(attributes, YES) + OF_GETTER(_attributes, YES) } -- (void)setChildren: (OFArray*)children_ +- (void)setChildren: (OFArray*)children { - OF_SETTER(children, children_, YES, 2) + OF_SETTER(_children, children, YES, 2) } - (OFArray*)children { - OF_GETTER(children, YES) + OF_GETTER(_children, YES) } - (void)setStringValue: (OFString*)stringValue { void *pool = objc_autoreleasePoolPush(); @@ -437,17 +450,17 @@ - (OFString*)stringValue { OFMutableString *ret; OFXMLElement **objects; - size_t i, count = [children count]; + size_t i, count = [_children count]; if (count == 0) return @""; ret = [OFMutableString string]; - objects = [children objects]; + objects = [_children objects]; for (i = 0; i < count; i++) { void *pool = objc_autoreleasePoolPush(); [ret appendString: [objects[i] stringValue]]; @@ -474,16 +487,17 @@ OFString *defaultNS; pool = objc_autoreleasePoolPush(); parentPrefix = [allNamespaces objectForKey: - (parent != nil && parent->ns != nil ? parent->ns : (OFString*)@"")]; + (parent != nil && parent->_namespace != nil + ? parent->_namespace : (OFString*)@"")]; /* Add the namespaces of the current element */ if (allNamespaces != nil) { - OFEnumerator *keyEnumerator = [namespaces keyEnumerator]; - OFEnumerator *objectEnumerator = [namespaces objectEnumerator]; + OFEnumerator *keyEnumerator = [_namespaces keyEnumerator]; + OFEnumerator *objectEnumerator = [_namespaces objectEnumerator]; OFMutableDictionary *tmp; id key, object; tmp = [[allNamespaces mutableCopy] autorelease]; @@ -492,33 +506,33 @@ [tmp setObject: object forKey: key]; allNamespaces = tmp; } else - allNamespaces = namespaces; + allNamespaces = _namespaces; prefix = [allNamespaces objectForKey: - (ns != nil ? ns : (OFString*)@"")]; + (_namespace != nil ? _namespace : (OFString*)@"")]; - if (parent != nil && parent->ns != nil && parentPrefix == nil) - defaultNS = parent->ns; - else if (parent != nil && parent->defaultNamespace != nil) - defaultNS = parent->defaultNamespace; + if (parent != nil && parent->_namespace != nil && parentPrefix == nil) + defaultNS = parent->_namespace; + else if (parent != nil && parent->_defaultNamespace != nil) + defaultNS = parent->_defaultNamespace; else - defaultNS = defaultNamespace; + defaultNS = _defaultNamespace; i = 0; - length = [name UTF8StringLength] + 3 + (level * indentation); + length = [_name UTF8StringLength] + 3 + (level * indentation); cString = [self allocMemoryWithSize: length]; memset(cString + i, ' ', level * indentation); i += level * indentation; /* Start of tag */ cString[i++] = '<'; - if (prefix != nil && ![ns isEqual: defaultNS]) { + if (prefix != nil && ![_namespace isEqual: defaultNS]) { length += [prefix UTF8StringLength] + 1; @try { cString = [self resizeMemory: cString size: length]; } @catch (id e) { @@ -530,17 +544,18 @@ [prefix UTF8StringLength]); i += [prefix UTF8StringLength]; cString[i++] = ':'; } - memcpy(cString + i, [name UTF8String], [name UTF8StringLength]); - i += [name UTF8StringLength]; + memcpy(cString + i, [_name UTF8String], [_name UTF8StringLength]); + i += [_name UTF8StringLength]; /* xmlns if necessary */ - if (prefix == nil && ((ns != nil && ![ns isEqual: defaultNS]) || - (ns == nil && defaultNS != nil))) { - length += [ns UTF8StringLength] + 9; + if (prefix == nil && ((_namespace != nil && + ![_namespace isEqual: defaultNS]) || + (_namespace == nil && defaultNS != nil))) { + length += [_namespace UTF8StringLength] + 9; @try { cString = [self resizeMemory: cString size: length]; } @catch (id e) { [self freeMemory: cString]; @@ -547,18 +562,19 @@ @throw e; } memcpy(cString + i, " xmlns='", 8); i += 8; - memcpy(cString + i, [ns UTF8String], [ns UTF8StringLength]); - i += [ns UTF8StringLength]; + memcpy(cString + i, [_namespace UTF8String], + [_namespace UTF8StringLength]); + i += [_namespace UTF8StringLength]; cString[i++] = '\''; } /* Attributes */ - attributesObjects = [attributes objects]; - attributesCount = [attributes count]; + attributesObjects = [_attributes objects]; + attributesCount = [_attributes count]; for (j = 0; j < attributesCount; j++) { void *pool2 = objc_autoreleasePoolPush(); OFString *attributeName = [attributesObjects[j] name]; OFString *attributePrefix = nil; @@ -604,13 +620,13 @@ objc_autoreleasePoolPop(pool2); } /* Childen */ - if (children != nil) { - OFXMLElement **childrenObjects = [children objects]; - size_t childrenCount = [children count]; + if (_children != nil) { + OFXMLElement **childrenObjects = [_children objects]; + size_t childrenCount = [_children count]; OFDataArray *tmp = [OFDataArray dataArray]; BOOL indent; if (indentation > 0) { indent = YES; @@ -650,11 +666,11 @@ } if (indent) [tmp addItem: "\n"]; - length += [tmp count] + [name UTF8StringLength] + 2 + + length += [tmp count] + [_name UTF8StringLength] + 2 + (indent ? level * indentation : 0); @try { cString = [self resizeMemory: cString size: length]; } @catch (id e) { @@ -687,12 +703,13 @@ memcpy(cString + i, [prefix UTF8String], [prefix UTF8StringLength]); i += [prefix UTF8StringLength]; cString[i++] = ':'; } - memcpy(cString + i, [name UTF8String], [name UTF8StringLength]); - i += [name UTF8StringLength]; + memcpy(cString + i, [_name UTF8String], + [_name UTF8StringLength]); + i += [_name UTF8StringLength]; } else cString[i++] = '/'; cString[i++] = '>'; assert(i == length); @@ -739,37 +756,37 @@ OFXMLElement *element; element = [OFXMLElement elementWithName: [self className] namespace: OF_SERIALIZATION_NS]; - if (name != nil) + if (_name != nil) [element addAttributeWithName: @"name" - stringValue: name]; + stringValue: _name]; - if (ns != nil) + if (_namespace != nil) [element addAttributeWithName: @"namespace" - stringValue: ns]; + stringValue: _namespace]; - if (defaultNamespace != nil) + if (_defaultNamespace != nil) [element addAttributeWithName: @"defaultNamespace" - stringValue: defaultNamespace]; + stringValue: _defaultNamespace]; - if (attributes != nil) { + if (_attributes != nil) { OFXMLElement *attributesElement; attributesElement = [OFXMLElement elementWithName: @"attributes" namespace: OF_SERIALIZATION_NS]; [attributesElement addChild: - [attributes XMLElementBySerializing]]; + [_attributes XMLElementBySerializing]]; [element addChild: attributesElement]; } - if (namespaces != nil) { + if (_namespaces != nil) { OFXMLElement *namespacesElement; OFMutableDictionary *namespacesCopy = - [[namespaces mutableCopy] autorelease]; + [[_namespaces mutableCopy] autorelease]; [namespacesCopy removeObjectForKey: @"http://www.w3.org/XML/1998/namespace"]; [namespacesCopy removeObjectForKey: @"http://www.w3.org/2000/xmlns/"]; @@ -782,17 +799,17 @@ [namespacesCopy XMLElementBySerializing]]; [element addChild: namespacesElement]; } } - if (children != nil) { + if (_children != nil) { OFXMLElement *childrenElement; childrenElement = [OFXMLElement elementWithName: @"children" namespace: OF_SERIALIZATION_NS]; - [childrenElement addChild: [children XMLElementBySerializing]]; + [childrenElement addChild: [_children XMLElementBySerializing]]; [element addChild: childrenElement]; } [element retain]; @@ -801,47 +818,47 @@ return [element autorelease]; } - (void)addAttribute: (OFXMLAttribute*)attribute { - if (attributes == nil) - attributes = [[OFMutableArray alloc] init]; + if (_attributes == nil) + _attributes = [[OFMutableArray alloc] init]; - if ([self attributeForName: attribute->name - namespace: attribute->ns] == nil) - [attributes addObject: attribute]; + if ([self attributeForName: attribute->_name + namespace: attribute->_namespace] == nil) + [_attributes addObject: attribute]; } -- (void)addAttributeWithName: (OFString*)name_ +- (void)addAttributeWithName: (OFString*)name stringValue: (OFString*)stringValue { - [self addAttributeWithName: name_ + [self addAttributeWithName: name namespace: nil stringValue: stringValue]; } -- (void)addAttributeWithName: (OFString*)name_ - namespace: (OFString*)ns_ +- (void)addAttributeWithName: (OFString*)name + namespace: (OFString*)namespace stringValue: (OFString*)stringValue { void *pool = objc_autoreleasePoolPush(); - [self addAttribute: [OFXMLAttribute attributeWithName: name_ - namespace: ns_ + [self addAttribute: [OFXMLAttribute attributeWithName: name + namespace: namespace stringValue: stringValue]]; objc_autoreleasePoolPop(pool); } - (OFXMLAttribute*)attributeForName: (OFString*)attributeName { - OFXMLAttribute **objects = [attributes objects]; - size_t i, count = [attributes count]; + OFXMLAttribute **objects = [_attributes objects]; + size_t i, count = [_attributes count]; for (i = 0; i < count; i++) - if (objects[i]->ns == nil && - [objects[i]->name isEqual: attributeName]) + if (objects[i]->_namespace == nil && + [objects[i]->_name isEqual: attributeName]) return [[objects[i] retain] autorelease]; return nil; } @@ -852,30 +869,30 @@ size_t i, count; if (attributeNS == nil) return [self attributeForName: attributeName]; - objects = [attributes objects]; - count = [attributes count]; + objects = [_attributes objects]; + count = [_attributes count]; for (i = 0; i < count; i++) - if ([objects[i]->ns isEqual: attributeNS] && - [objects[i]->name isEqual: attributeName]) + if ([objects[i]->_namespace isEqual: attributeNS] && + [objects[i]->_name isEqual: attributeName]) return [[objects[i] retain] autorelease]; return nil; } - (void)removeAttributeForName: (OFString*)attributeName { - OFXMLAttribute **objects = [attributes objects]; - size_t i, count = [attributes count]; + OFXMLAttribute **objects = [_attributes objects]; + size_t i, count = [_attributes count]; for (i = 0; i < count; i++) { - if (objects[i]->ns == nil && - [objects[i]->name isEqual: attributeName]) { - [attributes removeObjectAtIndex: i]; + if (objects[i]->_namespace == nil && + [objects[i]->_name isEqual: attributeName]) { + [_attributes removeObjectAtIndex: i]; return; } } } @@ -887,67 +904,67 @@ size_t i, count; if (attributeNS == nil) return [self removeAttributeForName: attributeName]; - objects = [attributes objects]; - count = [attributes count]; + objects = [_attributes objects]; + count = [_attributes count]; for (i = 0; i < count; i++) { - if ([objects[i]->ns isEqual: attributeNS] && - [objects[i]->name isEqual: attributeName]) { - [attributes removeObjectAtIndex: i]; + if ([objects[i]->_namespace isEqual: attributeNS] && + [objects[i]->_name isEqual: attributeName]) { + [_attributes removeObjectAtIndex: i]; return; } } } - (void)setPrefix: (OFString*)prefix - forNamespace: (OFString*)ns_ + forNamespace: (OFString*)namespace { if ([prefix length] == 0) @throw [OFInvalidArgumentException exceptionWithClass: [self class] selector: _cmd]; - if (ns_ == nil) - ns_ = @""; + if (namespace == nil) + namespace = @""; - [namespaces setObject: prefix - forKey: ns_]; + [_namespaces setObject: prefix + forKey: namespace]; } - (void)bindPrefix: (OFString*)prefix - forNamespace: (OFString*)ns_ + forNamespace: (OFString*)namespace { [self setPrefix: prefix - forNamespace: ns_]; + forNamespace: namespace]; [self addAttributeWithName: prefix namespace: @"http://www.w3.org/2000/xmlns/" - stringValue: ns_]; + stringValue: namespace]; } - (OFString*)defaultNamespace { - OF_GETTER(defaultNamespace, YES) + OF_GETTER(_defaultNamespace, YES) } -- (void)setDefaultNamespace: (OFString*)ns_ +- (void)setDefaultNamespace: (OFString*)defaultNamespace { - OF_SETTER(defaultNamespace, ns_, YES, 1) + OF_SETTER(_defaultNamespace, defaultNamespace, YES, 1) } - (void)addChild: (OFXMLNode*)child { if ([child isKindOfClass: [OFXMLAttribute class]]) @throw [OFInvalidArgumentException exceptionWithClass: [self class] selector: _cmd]; - if (children == nil) - children = [[OFMutableArray alloc] init]; + if (_children == nil) + _children = [[OFMutableArray alloc] init]; - [children addObject: child]; + [_children addObject: child]; } - (void)insertChild: (OFXMLNode*)child atIndex: (size_t)index { @@ -954,32 +971,32 @@ if ([child isKindOfClass: [OFXMLAttribute class]]) @throw [OFInvalidArgumentException exceptionWithClass: [self class] selector: _cmd]; - if (children == nil) - children = [[OFMutableArray alloc] init]; + if (_children == nil) + _children = [[OFMutableArray alloc] init]; - [children insertObject: child - atIndex: index]; + [_children insertObject: child + atIndex: index]; } -- (void)insertChildren: (OFArray*)children_ +- (void)insertChildren: (OFArray*)children atIndex: (size_t)index { void *pool = objc_autoreleasePoolPush(); - OFEnumerator *enumerator = [children_ objectEnumerator]; + OFEnumerator *enumerator = [children objectEnumerator]; OFXMLNode *node; while ((node = [enumerator nextObject]) != nil) if ([node isKindOfClass: [OFXMLAttribute class]]) @throw [OFInvalidArgumentException exceptionWithClass: [self class] selector: _cmd]; - [children insertObjectsFromArray: children_ - atIndex: index]; + [_children insertObjectsFromArray: children + atIndex: index]; objc_autoreleasePoolPop(pool); } - (void)removeChild: (OFXMLNode*)child @@ -987,16 +1004,16 @@ if ([child isKindOfClass: [OFXMLAttribute class]]) @throw [OFInvalidArgumentException exceptionWithClass: [self class] selector: _cmd]; - [children removeObject: child]; + [_children removeObject: child]; } - (void)removeChildAtIndex: (size_t)index { - [children removeObjectAtIndex: index]; + [_children removeObjectAtIndex: index]; } - (void)replaceChild: (OFXMLNode*)child withNode: (OFXMLNode*)node { @@ -1004,12 +1021,12 @@ [child isKindOfClass: [OFXMLAttribute class]]) @throw [OFInvalidArgumentException exceptionWithClass: [self class] selector: _cmd]; - [children replaceObject: child - withObject: node]; + [_children replaceObject: child + withObject: node]; } - (void)replaceChildAtIndex: (size_t)index withNode: (OFXMLNode*)node { @@ -1016,12 +1033,12 @@ if ([node isKindOfClass: [OFXMLAttribute class]]) @throw [OFInvalidArgumentException exceptionWithClass: [self class] selector: _cmd]; - [children replaceObjectAtIndex: index - withObject: node]; + [_children replaceObjectAtIndex: index + withObject: node]; } - (OFXMLElement*)elementForName: (OFString*)elementName { return [[self elementsForName: elementName] firstObject]; @@ -1035,12 +1052,12 @@ } - (OFArray*)elements { OFMutableArray *ret = [OFMutableArray array]; - OFXMLElement **objects = [children objects]; - size_t i, count = [children count]; + OFXMLElement **objects = [_children objects]; + size_t i, count = [_children count]; for (i = 0; i < count; i++) if ([objects[i] isKindOfClass: [OFXMLElement class]]) [ret addObject: objects[i]]; @@ -1050,17 +1067,17 @@ } - (OFArray*)elementsForName: (OFString*)elementName { OFMutableArray *ret = [OFMutableArray array]; - OFXMLElement **objects = [children objects]; - size_t i, count = [children count]; + OFXMLElement **objects = [_children objects]; + size_t i, count = [_children count]; for (i = 0; i < count; i++) if ([objects[i] isKindOfClass: [OFXMLElement class]] && - objects[i]->ns == nil && - [objects[i]->name isEqual: elementName]) + objects[i]->_namespace == nil && + [objects[i]->_name isEqual: elementName]) [ret addObject: objects[i]]; [ret makeImmutable]; return ret; @@ -1067,17 +1084,17 @@ } - (OFArray*)elementsForNamespace: (OFString*)elementNS { OFMutableArray *ret = [OFMutableArray array]; - OFXMLElement **objects = [children objects]; - size_t i, count = [children count]; + OFXMLElement **objects = [_children objects]; + size_t i, count = [_children count]; for (i = 0; i < count; i++) if ([objects[i] isKindOfClass: [OFXMLElement class]] && - objects[i]->name != nil && - [objects[i]->ns isEqual: elementNS]) + objects[i]->_name != nil && + [objects[i]->_namespace isEqual: elementNS]) [ret addObject: objects[i]]; [ret makeImmutable]; return ret; @@ -1092,48 +1109,49 @@ if (elementNS == nil) return [self elementsForName: elementName]; ret = [OFMutableArray array]; - objects = [children objects]; - count = [children count]; + objects = [_children objects]; + count = [_children count]; for (i = 0; i < count; i++) if ([objects[i] isKindOfClass: [OFXMLElement class]] && - [objects[i]->ns isEqual: elementNS] && - [objects[i]->name isEqual: elementName]) + [objects[i]->_namespace isEqual: elementNS] && + [objects[i]->_name isEqual: elementName]) [ret addObject: objects[i]]; [ret makeImmutable]; return ret; } - (BOOL)isEqual: (id)object { - OFXMLElement *otherElement; + OFXMLElement *element; if (![object isKindOfClass: [OFXMLElement class]]) return NO; - otherElement = object; - - if (otherElement->name != name && ![otherElement->name isEqual: name]) - return NO; - if (otherElement->ns != ns && ![otherElement->ns isEqual: ns]) - return NO; - if (otherElement->defaultNamespace != defaultNamespace && - ![otherElement->defaultNamespace isEqual: defaultNamespace]) - return NO; - if (otherElement->attributes != attributes && - ![otherElement->attributes isEqual: attributes]) - return NO; - if (otherElement->namespaces != namespaces && - ![otherElement->namespaces isEqual: namespaces]) - return NO; - if (otherElement->children != children && - ![otherElement->children isEqual: children]) + element = object; + + if (element->_name != _name && ![element->_name isEqual: _name]) + return NO; + if (element->_namespace != _namespace && + ![element->_namespace isEqual: _namespace]) + return NO; + if (element->_defaultNamespace != _defaultNamespace && + ![element->_defaultNamespace isEqual: _defaultNamespace]) + return NO; + if (element->_attributes != _attributes && + ![element->_attributes isEqual: _attributes]) + return NO; + if (element->_namespaces != _namespaces && + ![element->_namespaces isEqual: _namespaces]) + return NO; + if (element->_children != _children && + ![element->_children isEqual: _children]) return NO; return YES; } @@ -1141,16 +1159,16 @@ { uint32_t hash; OF_HASH_INIT(hash); - OF_HASH_ADD_HASH(hash, [name hash]); - OF_HASH_ADD_HASH(hash, [ns hash]); - OF_HASH_ADD_HASH(hash, [defaultNamespace hash]); - OF_HASH_ADD_HASH(hash, [attributes hash]); - OF_HASH_ADD_HASH(hash, [namespaces hash]); - OF_HASH_ADD_HASH(hash, [children hash]); + OF_HASH_ADD_HASH(hash, [_name hash]); + OF_HASH_ADD_HASH(hash, [_namespace hash]); + OF_HASH_ADD_HASH(hash, [_defaultNamespace hash]); + OF_HASH_ADD_HASH(hash, [_attributes hash]); + OF_HASH_ADD_HASH(hash, [_namespaces hash]); + OF_HASH_ADD_HASH(hash, [_children hash]); OF_HASH_FINALIZE(hash); return hash; } @@ -1157,18 +1175,6 @@ - copy { return [[[self class] alloc] initWithElement: self]; } - -- (void)dealloc -{ - [name release]; - [ns release]; - [defaultNamespace release]; - [attributes release]; - [namespaces release]; - [children release]; - - [super dealloc]; -} @end Index: src/OFXMLElementBuilder.h ================================================================== --- src/OFXMLElementBuilder.h +++ src/OFXMLElementBuilder.h @@ -70,16 +70,16 @@ * an OFMalformedXMLException. * * @param builder The builder which did not expect the close tag * @param name The name of the close tag * @param prefix The prefix of the close tag - * @param ns The namespace of the close tag + * @param namespace The namespace of the close tag */ - (void)elementBuilder: (OFXMLElementBuilder*)builder didNotExpectCloseTag: (OFString*)name prefix: (OFString*)prefix - namespace: (OFString*)ns; + namespace: (OFString*)namespace; /*! * @brief This callback is called when the XML parser for the element builder * found an unknown entity. * @@ -99,12 +99,12 @@ * first parsing stuff using the OFXMLParser with another delegate and then * setting the OFXMLElementBuilder as delegate for the parser. */ @interface OFXMLElementBuilder: OFObject { - OFMutableArray *stack; - id delegate; + OFMutableArray *_stack; + id _delegate; } #ifdef OF_HAVE_PROPERTIES @property (assign) id delegate; #endif Index: src/OFXMLElementBuilder.m ================================================================== --- src/OFXMLElementBuilder.m +++ src/OFXMLElementBuilder.m @@ -39,11 +39,11 @@ - init { self = [super init]; @try { - stack = [[OFMutableArray alloc] init]; + _stack = [[OFMutableArray alloc] init]; } @catch (id e) { [self release]; @throw e; } @@ -50,52 +50,52 @@ return self; } - (void)dealloc { - [stack release]; + [_stack release]; [super dealloc]; } - (id )delegate { - return delegate; + return _delegate; } -- (void)setDelegate: (id )delegate_ +- (void)setDelegate: (id )delegate { - delegate = delegate_; + _delegate = delegate; } - (void)parser: (OFXMLParser*)parser foundProcessingInstructions: (OFString*)pi { OFXMLProcessingInstructions *node = [OFXMLProcessingInstructions processingInstructionsWithString: pi]; - OFXMLElement *parent = [stack lastObject]; + OFXMLElement *parent = [_stack lastObject]; if (parent != nil) [parent addChild: node]; - else if ([delegate respondsToSelector: + else if ([_delegate respondsToSelector: @selector(elementBuilder:didBuildParentlessNode:)]) - [delegate elementBuilder: self - didBuildParentlessNode: node]; + [_delegate elementBuilder: self + didBuildParentlessNode: node]; } - (void)parser: (OFXMLParser*)parser didStartElement: (OFString*)name prefix: (OFString*)prefix - namespace: (OFString*)ns + namespace: (OFString*)namespace attributes: (OFArray*)attributes { OFXMLElement *element; OFXMLAttribute **objects; size_t i, count; element = [OFXMLElement elementWithName: name - namespace: ns]; + namespace: namespace]; objects = [attributes objects]; count = [attributes count]; for (i = 0; i < count; i++) { @@ -109,92 +109,92 @@ forNamespace: [objects[i] stringValue]]; [element addAttribute: objects[i]]; } - [[stack lastObject] addChild: element]; - [stack addObject: element]; + [[_stack lastObject] addChild: element]; + [_stack addObject: element]; } - (void)parser: (OFXMLParser*)parser didEndElement: (OFString*)name prefix: (OFString*)prefix - namespace: (OFString*)ns + namespace: (OFString*)namespace { - switch ([stack count]) { + switch ([_stack count]) { case 0: - if ([delegate respondsToSelector: @selector(elementBuilder: + if ([_delegate respondsToSelector: @selector(elementBuilder: didNotExpectCloseTag:prefix:namespace:)]) - [delegate elementBuilder: self - didNotExpectCloseTag: name - prefix: prefix - namespace: ns]; + [_delegate elementBuilder: self + didNotExpectCloseTag: name + prefix: prefix + namespace: namespace]; else @throw [OFMalformedXMLException exceptionWithClass: [self class]]; return; case 1: - [delegate elementBuilder: self - didBuildElement: [stack firstObject]]; + [_delegate elementBuilder: self + didBuildElement: [_stack firstObject]]; break; } - [stack removeLastObject]; + [_stack removeLastObject]; } - (void)parser: (OFXMLParser*)parser foundCharacters: (OFString*)characters { OFXMLCharacters *node; OFXMLElement *parent; node = [OFXMLCharacters charactersWithString: characters]; - parent = [stack lastObject]; + parent = [_stack lastObject]; if (parent != nil) [parent addChild: node]; - else if ([delegate respondsToSelector: + else if ([_delegate respondsToSelector: @selector(elementBuilder:didBuildParentlessNode:)]) - [delegate elementBuilder: self + [_delegate elementBuilder: self didBuildParentlessNode: node]; } - (void)parser: (OFXMLParser*)parser foundCDATA: (OFString*)CDATA { OFXMLCDATA *node = [OFXMLCDATA CDATAWithString: CDATA]; - OFXMLElement *parent = [stack lastObject]; + OFXMLElement *parent = [_stack lastObject]; if (parent != nil) [parent addChild: node]; - else if ([delegate respondsToSelector: + else if ([_delegate respondsToSelector: @selector(elementBuilder:didBuildParentlessNode:)]) - [delegate elementBuilder: self - didBuildParentlessNode: node]; + [_delegate elementBuilder: self + didBuildParentlessNode: node]; } - (void)parser: (OFXMLParser*)parser foundComment: (OFString*)comment { OFXMLComment *node = [OFXMLComment commentWithString: comment]; - OFXMLElement *parent = [stack lastObject]; + OFXMLElement *parent = [_stack lastObject]; if (parent != nil) [parent addChild: node]; - else if ([delegate respondsToSelector: + else if ([_delegate respondsToSelector: @selector(elementBuilder:didBuildParentlessNode:)]) - [delegate elementBuilder: self - didBuildParentlessNode: node]; + [_delegate elementBuilder: self + didBuildParentlessNode: node]; } - (OFString*)parser: (OFXMLParser*)parser foundUnknownEntityNamed: (OFString*)entity { - if ([delegate respondsToSelector: + if ([_delegate respondsToSelector: @selector(elementBuilder:foundUnknownEntityNamed:)]) - return [delegate elementBuilder: self - foundUnknownEntityNamed: entity]; + return [_delegate elementBuilder: self + foundUnknownEntityNamed: entity]; return nil; } @end Index: src/OFXMLParser.h ================================================================== --- src/OFXMLParser.h +++ src/OFXMLParser.h @@ -123,11 +123,11 @@ * OFXMLParser is an event-based XML parser which calls the delegate's callbacks * as soon asit finds something, thus suitable for streams as well. */ @interface OFXMLParser: OFObject { - id delegate; + id _delegate; enum { OF_XMLPARSER_OUTSIDE_TAG, OF_XMLPARSER_TAG_OPENED, OF_XMLPARSER_IN_PROCESSING_INSTRUCTIONS, OF_XMLPARSER_IN_TAG_NAME, @@ -145,27 +145,23 @@ OF_XMLPARSER_IN_COMMENT_OPENING, OF_XMLPARSER_IN_COMMENT_1, OF_XMLPARSER_IN_COMMENT_2, OF_XMLPARSER_IN_DOCTYPE, OF_XMLPARSER_NUM_STATES - } state; - OFDataArray *cache; - OFString *name; - OFString *prefix; - OFMutableArray *namespaces; - OFMutableArray *attributes; - OFString *attributeName; - OFString *attributePrefix; - char delimiter; - OFMutableArray *previous; - size_t level; - BOOL acceptProlog; - size_t lineNumber; - BOOL lastCarriageReturn; - BOOL finishedParsing; - of_string_encoding_t encoding; - size_t depthLimit; + } _state; + OFDataArray *_cache; + OFString *_name, *_prefix; + OFMutableArray *_namespaces, *_attributes; + OFString *_attributeName, *_attributePrefix; + char _delimiter; + OFMutableArray *_previous; + size_t _level; + BOOL _acceptProlog; + size_t _lineNumber; + BOOL _lastCarriageReturn, _finishedParsing; + of_string_encoding_t _encoding; + size_t _depthLimit; } #ifdef OF_HAVE_PROPERTIES @property (assign) id delegate; @property size_t depthLimit; Index: src/OFXMLParser.m ================================================================== --- src/OFXMLParser.m +++ src/OFXMLParser.m @@ -116,11 +116,11 @@ static OF_INLINE void resolve_attribute_namespace(OFXMLAttribute *attribute, OFArray *namespaces, OFXMLParser *self) { OFString *attributeNS; - OFString *attributePrefix = attribute->ns; + OFString *attributePrefix = attribute->_namespace; if (attributePrefix == nil) return; attributeNS = namespace_for_prefix(attributePrefix, namespaces); @@ -128,12 +128,12 @@ if ((attributePrefix != nil && attributeNS == nil)) @throw [OFUnboundNamespaceException exceptionWithClass: [self class] prefix: attributePrefix]; - [attribute->ns release]; - attribute->ns = [attributeNS retain]; + [attribute->_namespace release]; + attribute->_namespace = [attributeNS retain]; } @implementation OFXMLParser + (void)initialize { @@ -183,25 +183,25 @@ @try { void *pool; OFMutableDictionary *dict; - cache = [[OFBigDataArray alloc] init]; - previous = [[OFMutableArray alloc] init]; - namespaces = [[OFMutableArray alloc] init]; - attributes = [[OFMutableArray alloc] init]; + _cache = [[OFBigDataArray alloc] init]; + _previous = [[OFMutableArray alloc] init]; + _namespaces = [[OFMutableArray alloc] init]; + _attributes = [[OFMutableArray 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]; + [_namespaces addObject: dict]; - acceptProlog = YES; - lineNumber = 1; - encoding = OF_STRING_ENCODING_UTF_8; - depthLimit = 32; + _acceptProlog = YES; + _lineNumber = 1; + _encoding = OF_STRING_ENCODING_UTF_8; + _depthLimit = 32; objc_autoreleasePoolPop(pool); } @catch (id e) { [self release]; @throw e; @@ -210,40 +210,40 @@ return self; } - (void)dealloc { - [cache release]; - [name release]; - [prefix release]; - [namespaces release]; - [attributes release]; - [attributeName release]; - [attributePrefix release]; - [previous release]; + [_cache release]; + [_name release]; + [_prefix release]; + [_namespaces release]; + [_attributes release]; + [_attributeName release]; + [_attributePrefix release]; + [_previous release]; [super dealloc]; } - (id )delegate { - return delegate; + return _delegate; } -- (void)setDelegate: (id )delegate_ +- (void)setDelegate: (id )delegate { - delegate = delegate_; + _delegate = delegate; } - (size_t)depthLimit { - return depthLimit; + return _depthLimit; } -- (void)setDepthLimit: (size_t)depthLimit_ +- (void)setDepthLimit: (size_t)depthLimit { - depthLimit = depthLimit_; + _depthLimit = depthLimit; } - (void)parseBuffer: (const char*)buffer length: (size_t)length { @@ -250,26 +250,26 @@ size_t i, last = 0; for (i = 0; i < length; i++) { size_t j = i; - lookupTable[state](self, selectors[state], buffer, &i, &last); + lookupTable[_state](self, selectors[_state], buffer, &i, &last); /* Ensure we don't count this character twice */ if (i != j) continue; if (buffer[i] == '\r' || (buffer[i] == '\n' && - !lastCarriageReturn)) - lineNumber++; + !_lastCarriageReturn)) + _lineNumber++; - lastCarriageReturn = (buffer[i] == '\r'); + _lastCarriageReturn = (buffer[i] == '\r'); } /* In OF_XMLPARSER_IN_TAG, there can be only spaces */ - if (length - last > 0 && state != OF_XMLPARSER_IN_TAG) - cache_append(cache, buffer + last, encoding, length - last); + if (length - last > 0 && _state != OF_XMLPARSER_IN_TAG) + cache_append(_cache, buffer + last, _encoding, length - last); } - (void)parseString: (OFString*)string { [self parseBuffer: [string UTF8String] @@ -317,73 +317,73 @@ i: (size_t*)i last: (size_t*)last { size_t length; - if ((finishedParsing || [previous count] < 1) && buffer[*i] != ' ' && + if ((_finishedParsing || [_previous count] < 1) && buffer[*i] != ' ' && buffer[*i] != '\t' && buffer[*i] != '\n' && buffer[*i] != '\r' && buffer[*i] != '<') @throw [OFMalformedXMLException exceptionWithClass: [self class] parser: self]; if (buffer[*i] != '<') return; if ((length = *i - *last) > 0) - cache_append(cache, buffer + *last, encoding, length); + cache_append(_cache, buffer + *last, _encoding, length); - if ([cache count] > 0) { + if ([_cache count] > 0) { void *pool = objc_autoreleasePoolPush(); - OFString *characters = transform_string(cache, 0, YES, self); + OFString *characters = transform_string(_cache, 0, YES, self); - if ([delegate respondsToSelector: + if ([_delegate respondsToSelector: @selector(parser:foundCharacters:)]) - [delegate parser: self - foundCharacters: characters]; + [_delegate parser: self + foundCharacters: characters]; objc_autoreleasePoolPop(pool); } - [cache removeAllItems]; + [_cache removeAllItems]; *last = *i + 1; - state = OF_XMLPARSER_TAG_OPENED; + _state = OF_XMLPARSER_TAG_OPENED; } /* Tag was just opened */ - (void)OF_parseTagOpenedWithBuffer: (const char*)buffer i: (size_t*)i last: (size_t*)last { - if (finishedParsing && buffer[*i] != '!' && buffer[*i] != '?') + if (_finishedParsing && buffer[*i] != '!' && buffer[*i] != '?') @throw [OFMalformedXMLException exceptionWithClass: [self class] parser: self]; switch (buffer[*i]) { case '?': *last = *i + 1; - state = OF_XMLPARSER_IN_PROCESSING_INSTRUCTIONS; - level = 0; + _state = OF_XMLPARSER_IN_PROCESSING_INSTRUCTIONS; + _level = 0; break; case '/': *last = *i + 1; - state = OF_XMLPARSER_IN_CLOSE_TAG_NAME; - acceptProlog = NO; + _state = OF_XMLPARSER_IN_CLOSE_TAG_NAME; + _acceptProlog = NO; break; case '!': *last = *i + 1; - state = OF_XMLPARSER_IN_EXCLAMATIONMARK; - acceptProlog = NO; + _state = OF_XMLPARSER_IN_EXCLAMATIONMARK; + _acceptProlog = NO; break; default: - if (depthLimit > 0 && [previous count] >= depthLimit) + if (_depthLimit > 0 && [_previous count] >= _depthLimit) @throw [OFMalformedXMLException exceptionWithClass: [self class] parser: self]; - state = OF_XMLPARSER_IN_TAG_NAME; - acceptProlog = NO; + _state = OF_XMLPARSER_IN_TAG_NAME; + _acceptProlog = NO; (*i)--; break; } } @@ -390,35 +390,35 @@ /* */ - (BOOL)OF_parseXMLProcessingInstructions: (OFString*)pi { const char *cString; size_t i, last, length; - int piState = 0; + int PIState = 0; OFString *attribute = nil; OFMutableString *value = nil; char piDelimiter = 0; - if (!acceptProlog) + if (!_acceptProlog) return NO; - acceptProlog = NO; + _acceptProlog = NO; pi = [pi substringWithRange: of_range(3, [pi length] - 3)]; pi = [pi stringByDeletingEnclosingWhitespaces]; cString = [pi UTF8String]; length = [pi UTF8StringLength]; for (i = last = 0; i < length; i++) { - switch (piState) { + switch (PIState) { case 0: if (cString[i] == ' ' || cString[i] == '\t' || cString[i] == '\r' || cString[i] == '\n') continue; last = i; - piState = 1; + PIState = 1; i--; break; case 1: if (cString[i] != '=') @@ -426,20 +426,20 @@ attribute = [OFString stringWithUTF8String: cString + last length: i - last]; last = i + 1; - piState = 2; + PIState = 2; break; case 2: if (cString[i] != '\'' && cString[i] != '"') return NO; piDelimiter = cString[i]; last = i + 1; - piState = 3; + PIState = 3; break; case 3: if (cString[i] != piDelimiter) continue; @@ -454,32 +454,32 @@ if ([attribute isEqual: @"encoding"]) { [value lowercase]; if ([value isEqual: @"utf-8"]) - encoding = OF_STRING_ENCODING_UTF_8; + _encoding = OF_STRING_ENCODING_UTF_8; else if ([value isEqual: @"iso-8859-1"]) - encoding = + _encoding = OF_STRING_ENCODING_ISO_8859_1; else if ([value isEqual: @"iso-8859-15"]) - encoding = + _encoding = OF_STRING_ENCODING_ISO_8859_15; else if ([value isEqual: @"windows-1252"]) - encoding = + _encoding = OF_STRING_ENCODING_WINDOWS_1252; else return NO; } last = i + 1; - piState = 0; + PIState = 0; break; } } - if (piState != 0) + if (PIState != 0) return NO; return YES; } @@ -487,39 +487,39 @@ - (void)OF_parseInProcessingInstructionsWithBuffer: (const char*)buffer i: (size_t*)i last: (size_t*)last { if (buffer[*i] == '?') - level = 1; - else if (level == 1 && buffer[*i] == '>') { + _level = 1; + else if (_level == 1 && buffer[*i] == '>') { void *pool = objc_autoreleasePoolPush(); - OFString *pi; - - cache_append(cache, buffer + *last, encoding, *i - *last); - pi = transform_string(cache, 1, NO, nil); - - if ([pi isEqual: @"xml"] || [pi hasPrefix: @"xml "] || - [pi hasPrefix: @"xml\t"] || [pi hasPrefix: @"xml\r"] || - [pi hasPrefix: @"xml\n"]) - if (![self OF_parseXMLProcessingInstructions: pi]) + OFString *PI; + + cache_append(_cache, buffer + *last, _encoding, *i - *last); + PI = transform_string(_cache, 1, NO, nil); + + if ([PI isEqual: @"xml"] || [PI hasPrefix: @"xml "] || + [PI hasPrefix: @"xml\t"] || [PI hasPrefix: @"xml\r"] || + [PI hasPrefix: @"xml\n"]) + if (![self OF_parseXMLProcessingInstructions: PI]) @throw [OFMalformedXMLException exceptionWithClass: [self class] parser: self]; - if ([delegate respondsToSelector: + if ([_delegate respondsToSelector: @selector(parser:foundProcessingInstructions:)]) - [delegate parser: self - foundProcessingInstructions: pi]; + [_delegate parser: self + foundProcessingInstructions: PI]; objc_autoreleasePoolPop(pool); - [cache removeAllItems]; + [_cache removeAllItems]; *last = *i + 1; - state = OF_XMLPARSER_OUTSIDE_TAG; + _state = OF_XMLPARSER_OUTSIDE_TAG; } else - level = 0; + _level = 0; } /* Inside a tag, no name yet */ - (void)OF_parseInTagNameWithBuffer: (const char*)buffer i: (size_t*)i @@ -533,78 +533,78 @@ if (buffer[*i] != ' ' && buffer[*i] != '\t' && buffer[*i] != '\n' && buffer[*i] != '\r' && buffer[*i] != '>' && buffer[*i] != '/') return; if ((length = *i - *last) > 0) - cache_append(cache, buffer + *last, encoding, length); + cache_append(_cache, buffer + *last, _encoding, length); pool = objc_autoreleasePoolPush(); - cacheCString = [cache items]; - cacheLength = [cache count]; + cacheCString = [_cache items]; + cacheLength = [_cache count]; cacheString = [OFString stringWithUTF8String: cacheCString length: cacheLength]; if ((tmp = memchr(cacheCString, ':', cacheLength)) != NULL) { - name = [[OFString alloc] + _name = [[OFString alloc] initWithUTF8String: tmp + 1 length: cacheLength - (tmp - cacheCString) - 1]; - prefix = [[OFString alloc] + _prefix = [[OFString alloc] initWithUTF8String: cacheCString length: tmp - cacheCString]; } else { - name = [cacheString copy]; - prefix = nil; + _name = [cacheString copy]; + _prefix = nil; } if (buffer[*i] == '>' || buffer[*i] == '/') { - OFString *ns; + OFString *namespace; - ns = namespace_for_prefix(prefix, namespaces); + namespace = namespace_for_prefix(_prefix, _namespaces); - if (prefix != nil && ns == nil) + if (_prefix != nil && namespace == nil) @throw [OFUnboundNamespaceException exceptionWithClass: [self class] - prefix: prefix]; + prefix: _prefix]; - if ([delegate respondsToSelector: @selector(parser: + if ([_delegate respondsToSelector: @selector(parser: didStartElement:prefix:namespace:attributes:)]) - [delegate parser: self - didStartElement: name - prefix: prefix - namespace: ns - attributes: nil]; + [_delegate parser: self + didStartElement: _name + prefix: _prefix + namespace: namespace + attributes: nil]; if (buffer[*i] == '/') { - if ([delegate respondsToSelector: + if ([_delegate respondsToSelector: @selector(parser:didEndElement:prefix:namespace:)]) - [delegate parser: self - didEndElement: name - prefix: prefix - namespace: ns]; + [_delegate parser: self + didEndElement: _name + prefix: _prefix + namespace: namespace]; - if ([previous count] == 0) - finishedParsing = YES; + if ([_previous count] == 0) + _finishedParsing = YES; } else - [previous addObject: cacheString]; + [_previous addObject: cacheString]; - [name release]; - [prefix release]; - name = prefix = nil; + [_name release]; + [_prefix release]; + _name = _prefix = nil; - state = (buffer[*i] == '/' + _state = (buffer[*i] == '/' ? OF_XMLPARSER_EXPECT_CLOSE : OF_XMLPARSER_OUTSIDE_TAG); } else - state = OF_XMLPARSER_IN_TAG; + _state = OF_XMLPARSER_IN_TAG; if (buffer[*i] != '/') - [namespaces addObject: [OFMutableDictionary dictionary]]; + [_namespaces addObject: [OFMutableDictionary dictionary]]; objc_autoreleasePoolPop(pool); - [cache removeAllItems]; + [_cache removeAllItems]; *last = *i + 1; } /* Inside a close tag, no name yet */ - (void)OF_parseInCloseTagNameWithBuffer: (const char*)buffer @@ -612,149 +612,148 @@ last: (size_t*)last { void *pool; const char *cacheCString, *tmp; size_t length, cacheLength; - OFString *cacheString; - OFString *ns; + OFString *cacheString, *namespace; if (buffer[*i] != ' ' && buffer[*i] != '\t' && buffer[*i] != '\n' && buffer[*i] != '\r' && buffer[*i] != '>') return; if ((length = *i - *last) > 0) - cache_append(cache, buffer + *last, encoding, length); + cache_append(_cache, buffer + *last, _encoding, length); pool = objc_autoreleasePoolPush(); - cacheCString = [cache items]; - cacheLength = [cache count]; + cacheCString = [_cache items]; + cacheLength = [_cache count]; cacheString = [OFString stringWithUTF8String: cacheCString length: cacheLength]; if ((tmp = memchr(cacheCString, ':', cacheLength)) != NULL) { - name = [[OFString alloc] + _name = [[OFString alloc] initWithUTF8String: tmp + 1 length: cacheLength - (tmp - cacheCString) - 1]; - prefix = [[OFString alloc] + _prefix = [[OFString alloc] initWithUTF8String: cacheCString length: tmp - cacheCString]; } else { - name = [cacheString copy]; - prefix = nil; + _name = [cacheString copy]; + _prefix = nil; } - if (![[previous lastObject] isEqual: cacheString]) + if (![[_previous lastObject] isEqual: cacheString]) @throw [OFMalformedXMLException exceptionWithClass: [self class] parser: self]; - [previous removeLastObject]; + [_previous removeLastObject]; - [cache removeAllItems]; + [_cache removeAllItems]; - ns = namespace_for_prefix(prefix, namespaces); - if (prefix != nil && ns == nil) + namespace = namespace_for_prefix(_prefix, _namespaces); + if (_prefix != nil && namespace == nil) @throw [OFUnboundNamespaceException exceptionWithClass: [self class] - prefix: prefix]; + prefix: _prefix]; - if ([delegate respondsToSelector: + if ([_delegate respondsToSelector: @selector(parser:didEndElement:prefix:namespace:)]) - [delegate parser: self - didEndElement: name - prefix: prefix - namespace: ns]; + [_delegate parser: self + didEndElement: _name + prefix: _prefix + namespace: namespace]; objc_autoreleasePoolPop(pool); - [namespaces removeLastObject]; - [name release]; - [prefix release]; - name = prefix = nil; + [_namespaces removeLastObject]; + [_name release]; + [_prefix release]; + _name = _prefix = nil; *last = *i + 1; - state = (buffer[*i] == '>' + _state = (buffer[*i] == '>' ? OF_XMLPARSER_OUTSIDE_TAG : OF_XMLPARSER_EXPECT_SPACE_OR_CLOSE); - if ([previous count] == 0) - finishedParsing = YES; + if ([_previous count] == 0) + _finishedParsing = YES; } /* Inside a tag, name found */ - (void)OF_parseInTagWithBuffer: (const char*)buffer i: (size_t*)i last: (size_t*)last { void *pool; - OFString *ns; + OFString *namespace; OFXMLAttribute **attributesObjects; size_t j, attributesCount; if (buffer[*i] != '>' && buffer[*i] != '/') { if (buffer[*i] != ' ' && buffer[*i] != '\t' && buffer[*i] != '\n' && buffer[*i] != '\r') { *last = *i; - state = OF_XMLPARSER_IN_ATTR_NAME; + _state = OF_XMLPARSER_IN_ATTR_NAME; (*i)--; } return; } - attributesObjects = [attributes objects]; - attributesCount = [attributes count]; + attributesObjects = [_attributes objects]; + attributesCount = [_attributes count]; - ns = namespace_for_prefix(prefix, namespaces); + namespace = namespace_for_prefix(_prefix, _namespaces); - if (prefix != nil && ns == nil) + if (_prefix != nil && namespace == nil) @throw [OFUnboundNamespaceException exceptionWithClass: [self class] - prefix: prefix]; + prefix: _prefix]; for (j = 0; j < attributesCount; j++) - resolve_attribute_namespace(attributesObjects[j], namespaces, + resolve_attribute_namespace(attributesObjects[j], _namespaces, self); pool = objc_autoreleasePoolPush(); - if ([delegate respondsToSelector: + if ([_delegate respondsToSelector: @selector(parser:didStartElement:prefix:namespace:attributes:)]) - [delegate parser: self - didStartElement: name - prefix: prefix - namespace: ns - attributes: attributes]; + [_delegate parser: self + didStartElement: _name + prefix: _prefix + namespace: namespace + attributes: _attributes]; if (buffer[*i] == '/') { - if ([delegate respondsToSelector: + if ([_delegate respondsToSelector: @selector(parser:didEndElement:prefix:namespace:)]) - [delegate parser: self - didEndElement: name - prefix: prefix - namespace: ns]; - - if ([previous count] == 0) - finishedParsing = YES; - - [namespaces removeLastObject]; - } else if (prefix != nil) { + [_delegate parser: self + didEndElement: _name + prefix: _prefix + namespace: namespace]; + + if ([_previous count] == 0) + _finishedParsing = YES; + + [_namespaces removeLastObject]; + } else if (_prefix != nil) { OFString *str = [OFString stringWithFormat: @"%@:%@", - prefix, name]; - [previous addObject: str]; + _prefix, _name]; + [_previous addObject: str]; } else - [previous addObject: name]; + [_previous addObject: _name]; objc_autoreleasePoolPop(pool); - [name release]; - [prefix release]; - [attributes removeAllObjects]; - name = prefix = nil; + [_name release]; + [_prefix release]; + [_attributes removeAllObjects]; + _name = _prefix = nil; *last = *i + 1; - state = (buffer[*i] == '/' + _state = (buffer[*i] == '/' ? OF_XMLPARSER_EXPECT_CLOSE : OF_XMLPARSER_OUTSIDE_TAG); } /* Looking for attribute name */ @@ -769,41 +768,41 @@ if (buffer[*i] != '=') return; if ((length = *i - *last) > 0) - cache_append(cache, buffer + *last, encoding, length); + cache_append(_cache, buffer + *last, _encoding, length); pool = objc_autoreleasePoolPush(); - cacheString = [OFMutableString stringWithUTF8String: [cache items] - length: [cache count]]; + cacheString = [OFMutableString stringWithUTF8String: [_cache items] + length: [_cache count]]; [cacheString deleteEnclosingWhitespaces]; /* Prevent a useless copy later */ [cacheString makeImmutable]; cacheCString = [cacheString UTF8String]; cacheLength = [cacheString UTF8StringLength]; if ((tmp = memchr(cacheCString, ':', cacheLength)) != NULL) { - attributeName = [[OFString alloc] + _attributeName = [[OFString alloc] initWithUTF8String: tmp + 1 length: cacheLength - (tmp - cacheCString) - 1]; - attributePrefix = [[OFString alloc] + _attributePrefix = [[OFString alloc] initWithUTF8String: cacheCString length: tmp - cacheCString]; } else { - attributeName = [cacheString copy]; - attributePrefix = nil; + _attributeName = [cacheString copy]; + _attributePrefix = nil; } objc_autoreleasePoolPop(pool); - [cache removeAllItems]; + [_cache removeAllItems]; *last = *i + 1; - state = OF_XMLPARSER_EXPECT_DELIM; + _state = OF_XMLPARSER_EXPECT_DELIM; } /* Expecting delimiter */ - (void)OF_parseExpectDelimiterWithBuffer: (const char*)buffer i: (size_t*)i @@ -817,12 +816,12 @@ if (buffer[*i] != '\'' && buffer[*i] != '"') @throw [OFMalformedXMLException exceptionWithClass: [self class] parser: self]; - delimiter = buffer[*i]; - state = OF_XMLPARSER_IN_ATTR_VALUE; + _delimiter = buffer[*i]; + _state = OF_XMLPARSER_IN_ATTR_VALUE; } /* Looking for attribute value */ - (void)OF_parseInAttributeValueWithBuffer: (const char*)buffer i: (size_t*)i @@ -830,50 +829,50 @@ { void *pool; OFString *attributeValue; size_t length; - if (buffer[*i] != delimiter) + if (buffer[*i] != _delimiter) return; if ((length = *i - *last) > 0) - cache_append(cache, buffer + *last, encoding, length); + cache_append(_cache, buffer + *last, _encoding, length); pool = objc_autoreleasePoolPush(); - attributeValue = transform_string(cache, 0, YES, self); - - if (attributePrefix == nil && [attributeName isEqual: @"xmlns"]) - [[namespaces lastObject] setObject: attributeValue - forKey: @""]; - if ([attributePrefix isEqual: @"xmlns"]) - [[namespaces lastObject] setObject: attributeValue - forKey: attributeName]; - - [attributes addObject: - [OFXMLAttribute attributeWithName: attributeName - namespace: attributePrefix + attributeValue = transform_string(_cache, 0, YES, self); + + if (_attributePrefix == nil && [_attributeName isEqual: @"xmlns"]) + [[_namespaces lastObject] setObject: attributeValue + forKey: @""]; + if ([_attributePrefix isEqual: @"xmlns"]) + [[_namespaces lastObject] setObject: attributeValue + forKey: _attributeName]; + + [_attributes addObject: + [OFXMLAttribute attributeWithName: _attributeName + namespace: _attributePrefix stringValue: attributeValue]]; objc_autoreleasePoolPop(pool); - [cache removeAllItems]; - [attributeName release]; - [attributePrefix release]; - attributeName = attributePrefix = nil; + [_cache removeAllItems]; + [_attributeName release]; + [_attributePrefix release]; + _attributeName = _attributePrefix = nil; *last = *i + 1; - state = OF_XMLPARSER_IN_TAG; + _state = OF_XMLPARSER_IN_TAG; } /* Expecting closing '>' */ - (void)OF_parseExpectCloseWithBuffer: (const char*)buffer i: (size_t*)i last: (size_t*)last { if (buffer[*i] == '>') { *last = *i + 1; - state = OF_XMLPARSER_OUTSIDE_TAG; + _state = OF_XMLPARSER_OUTSIDE_TAG; } else @throw [OFMalformedXMLException exceptionWithClass: [self class] parser: self]; } @@ -882,11 +881,11 @@ i: (size_t*)i last: (size_t*)last { if (buffer[*i] == '>') { *last = *i + 1; - state = OF_XMLPARSER_OUTSIDE_TAG; + _state = OF_XMLPARSER_OUTSIDE_TAG; } else if (buffer[*i] != ' ' && buffer[*i] != '\t' && buffer[*i] != '\n' && buffer[*i] != '\r') @throw [OFMalformedXMLException exceptionWithClass: [self class] parser: self]; } @@ -894,22 +893,22 @@ /* In ') { - state = OF_XMLPARSER_IN_CDATA_1; - level = (buffer[*i] == ']' ? 1 : 0); + _state = OF_XMLPARSER_IN_CDATA_1; + _level = (buffer[*i] == ']' ? 1 : 0); return; } pool = objc_autoreleasePoolPush(); - cache_append(cache, buffer + *last, encoding, *i - *last); - CDATA = transform_string(cache, 2, NO, nil); + cache_append(_cache, buffer + *last, _encoding, *i - *last); + CDATA = transform_string(_cache, 2, NO, nil); - if ([delegate respondsToSelector: @selector(parser:foundCDATA:)]) - [delegate parser: self - foundCDATA: CDATA]; + if ([_delegate respondsToSelector: @selector(parser:foundCDATA:)]) + [_delegate parser: self + foundCDATA: CDATA]; objc_autoreleasePoolPop(pool); - [cache removeAllItems]; + [_cache removeAllItems]; *last = *i + 1; - state = OF_XMLPARSER_OUTSIDE_TAG; + _state = OF_XMLPARSER_OUTSIDE_TAG; } /* Comment */ - (void)OF_parseInCommentOpeningWithBuffer: (const char*)buffer i: (size_t*)i @@ -984,25 +983,25 @@ if (buffer[*i] != '-') @throw [OFMalformedXMLException exceptionWithClass: [self class] parser: self]; *last = *i + 1; - state = OF_XMLPARSER_IN_COMMENT_1; - level = 0; + _state = OF_XMLPARSER_IN_COMMENT_1; + _level = 0; } - (void)OF_parseInComment1WithBuffer: (const char*)buffer i: (size_t*)i last: (size_t*)last { if (buffer[*i] == '-') - level++; + _level++; else - level = 0; + _level = 0; - if (level == 2) - state = OF_XMLPARSER_IN_COMMENT_2; + if (_level == 2) + _state = OF_XMLPARSER_IN_COMMENT_2; } - (void)OF_parseInComment2WithBuffer: (const char*)buffer i: (size_t*)i last: (size_t*)last @@ -1014,65 +1013,65 @@ @throw [OFMalformedXMLException exceptionWithClass: [self class] parser: self]; pool = objc_autoreleasePoolPush(); - cache_append(cache, buffer + *last, encoding, *i - *last); - comment = transform_string(cache, 2, NO, nil); + cache_append(_cache, buffer + *last, _encoding, *i - *last); + comment = transform_string(_cache, 2, NO, nil); - if ([delegate respondsToSelector: @selector(parser:foundComment:)]) - [delegate parser: self - foundComment: comment]; + if ([_delegate respondsToSelector: @selector(parser:foundComment:)]) + [_delegate parser: self + foundComment: comment]; objc_autoreleasePoolPop(pool); - [cache removeAllItems]; + [_cache removeAllItems]; *last = *i + 1; - state = OF_XMLPARSER_OUTSIDE_TAG; + _state = OF_XMLPARSER_OUTSIDE_TAG; } /* In */ - (void)OF_parseInDoctypeWithBuffer: (const char*)buffer i: (size_t*)i last: (size_t*)last { - if ((level < 6 && buffer[*i] != "OCTYPE"[level]) || - (level == 6 && buffer[*i] != ' ' && buffer[*i] != '\t' && + if ((_level < 6 && buffer[*i] != "OCTYPE"[_level]) || + (_level == 6 && buffer[*i] != ' ' && buffer[*i] != '\t' && buffer[*i] != '\n' && buffer[*i] != '\r')) @throw [OFMalformedXMLException exceptionWithClass: [self class] parser: self]; - if (level < 7 || buffer[*i] == '<') - level++; + if (_level < 7 || buffer[*i] == '<') + _level++; if (buffer[*i] == '>') { - if (level == 7) - state = OF_XMLPARSER_OUTSIDE_TAG; + if (_level == 7) + _state = OF_XMLPARSER_OUTSIDE_TAG; else - level--; + _level--; } *last = *i + 1; } - (size_t)lineNumber { - return lineNumber; + return _lineNumber; } - (BOOL)finishedParsing { - return finishedParsing; + return _finishedParsing; } - (OFString*)string: (OFString*)string containsUnknownEntityNamed: (OFString*)entity { - if ([delegate respondsToSelector: + if ([_delegate respondsToSelector: @selector(parser:foundUnknownEntityNamed:)]) - return [delegate parser: self - foundUnknownEntityNamed: entity]; + return [_delegate parser: self + foundUnknownEntityNamed: entity]; return nil; } @end Index: src/OFXMLProcessingInstructions.h ================================================================== --- src/OFXMLProcessingInstructions.h +++ src/OFXMLProcessingInstructions.h @@ -19,11 +19,11 @@ /*! * @brief A class for representing XML processing instructions. */ @interface OFXMLProcessingInstructions: OFXMLNode { - OFString *processingInstructions; + OFString *_processingInstructions; } /*! * @brief Creates a new OFXMLProcessingInstructions with the specified string. * Index: src/OFXMLProcessingInstructions.m ================================================================== --- src/OFXMLProcessingInstructions.m +++ src/OFXMLProcessingInstructions.m @@ -35,11 +35,11 @@ - initWithString: (OFString*)string { self = [super init]; @try { - processingInstructions = [string copy]; + _processingInstructions = [string copy]; } @catch (id e) { [self release]; @throw e; } @@ -57,11 +57,11 @@ ![[element namespace] isEqual: OF_SERIALIZATION_NS]) @throw [OFInvalidArgumentException exceptionWithClass: [self class] selector: _cmd]; - processingInstructions = [[element stringValue] copy]; + _processingInstructions = [[element stringValue] copy]; objc_autoreleasePoolPop(pool); } @catch (id e) { [self release]; @throw e; @@ -70,39 +70,39 @@ return self; } - (BOOL)isEqual: (id)object { - OFXMLProcessingInstructions *otherProcessingInstructions; + OFXMLProcessingInstructions *processingInstructions; if (![object isKindOfClass: [OFXMLProcessingInstructions class]]) return NO; - otherProcessingInstructions = object; + processingInstructions = object; - return ([otherProcessingInstructions->processingInstructions - isEqual: processingInstructions]); + return ([processingInstructions->_processingInstructions + isEqual: _processingInstructions]); } - (uint32_t)hash { - return [processingInstructions hash]; + return [_processingInstructions hash]; } - (OFString*)stringValue { return @""; } - (OFString*)XMLString { - return [OFString stringWithFormat: @"", processingInstructions]; + return [OFString stringWithFormat: @"", _processingInstructions]; } - (OFString*)XMLStringWithIndentation: (unsigned int)indentation { - return [OFString stringWithFormat: @"", processingInstructions]; + return [OFString stringWithFormat: @"", _processingInstructions]; } - (OFString*)XMLStringWithIndentation: (unsigned int)indentation level: (unsigned int)level { @@ -114,30 +114,28 @@ memset(whitespaces, ' ', level * indentation); whitespaces[level * indentation] = 0; @try { ret = [OFString stringWithFormat: - @"%s", - whitespaces, - processingInstructions]; + @"%s", whitespaces, _processingInstructions]; } @finally { [self freeMemory: whitespaces]; } } else ret = [OFString stringWithFormat: @"", - processingInstructions]; + _processingInstructions]; return ret; } - (OFString*)description { - return [OFString stringWithFormat: @"", processingInstructions]; + return [OFString stringWithFormat: @"", _processingInstructions]; } - (OFXMLElement*)XMLElementBySerializing { return [OFXMLElement elementWithName: [self className] namespace: OF_SERIALIZATION_NS - stringValue: processingInstructions]; + stringValue: _processingInstructions]; } @end Index: src/bridge/NSArray_OFArray.h ================================================================== --- src/bridge/NSArray_OFArray.h +++ src/bridge/NSArray_OFArray.h @@ -18,10 +18,10 @@ @class OFArray; @interface NSArray_OFArray: NSArray { - OFArray *array; + OFArray *_array; } - initWithOFArray: (OFArray*)array; @end Index: src/bridge/NSArray_OFArray.m ================================================================== --- src/bridge/NSArray_OFArray.m +++ src/bridge/NSArray_OFArray.m @@ -19,15 +19,15 @@ #import "OFBridging.h" #import "OFOutOfRangeException.h" @implementation NSArray_OFArray -- initWithOFArray: (OFArray*)array_ +- initWithOFArray: (OFArray*)array { if ((self = [super init]) != nil) { @try { - array = [array_ retain]; + _array = [array retain]; } @catch (id e) { return nil; } } @@ -34,23 +34,23 @@ return self; } - (id)objectAtIndex: (NSUInteger)index { - id object = [array objectAtIndex: index]; + id object = [_array objectAtIndex: index]; if ([object conformsToProtocol: @protocol(OFBridging)]) return [object NSObject]; return object; } - (NSUInteger)count { - size_t count = [array count]; + size_t count = [_array count]; if (count > NSUIntegerMax) @throw [OFOutOfRangeException exceptionWithClass: [self class]]; return (NSUInteger)count; } @end Index: src/bridge/NSDictionary_OFDictionary.h ================================================================== --- src/bridge/NSDictionary_OFDictionary.h +++ src/bridge/NSDictionary_OFDictionary.h @@ -18,10 +18,10 @@ @class OFDictionary; @interface NSDictionary_OFDictionary: NSDictionary { - OFDictionary *dictionary; + OFDictionary *_dictionary; } - initWithOFDictionary: (OFDictionary*)dictionary; @end Index: src/bridge/NSDictionary_OFDictionary.m ================================================================== --- src/bridge/NSDictionary_OFDictionary.m +++ src/bridge/NSDictionary_OFDictionary.m @@ -21,15 +21,15 @@ #import "OFBridging.h" #import "OFOutOfRangeException.h" @implementation NSDictionary_OFDictionary -- initWithOFDictionary: (OFDictionary*)dictionary_ +- initWithOFDictionary: (OFDictionary*)dictionary { if ((self = [super init]) != nil) { @try { - dictionary = [dictionary_ retain]; + _dictionary = [dictionary retain]; } @catch (id e) { return nil; } } @@ -41,23 +41,23 @@ id object; if ([key conformsToProtocol: @protocol(NSBridging)]) key = [key OFObject]; - object = [dictionary objectForKey: key]; + object = [_dictionary objectForKey: key]; if ([object conformsToProtocol: @protocol(OFBridging)]) return [object NSObject]; return object; } - (NSUInteger)count { - size_t count = [dictionary count]; + size_t count = [_dictionary count]; if (count > NSUIntegerMax) @throw [OFOutOfRangeException exceptionWithClass: [self class]]; return (NSUInteger)count; } @end Index: src/bridge/OFArray_NSArray.h ================================================================== --- src/bridge/OFArray_NSArray.h +++ src/bridge/OFArray_NSArray.h @@ -18,10 +18,10 @@ @class NSArray; @interface OFArray_NSArray: OFArray { - NSArray *array; + NSArray *_array; } - initWithNSArray: (NSArray*)array; @end Index: src/bridge/OFArray_NSArray.m ================================================================== --- src/bridge/OFArray_NSArray.m +++ src/bridge/OFArray_NSArray.m @@ -21,20 +21,20 @@ #import "OFInitializationFailedException.h" #import "OFOutOfRangeException.h" @implementation OFArray_NSArray -- initWithNSArray: (NSArray*)array_ +- initWithNSArray: (NSArray*)array { self = [super init]; @try { - array = [array_ retain]; - if (array == nil) @throw [OFInitializationFailedException - exceptionWithClass: isa]; + exceptionWithClass: [self class]]; + + _array = [array retain]; } @catch (id e) { [self release]; @throw e; } @@ -46,18 +46,18 @@ id object; if (index > NSUIntegerMax) @throw [OFOutOfRangeException exceptionWithClass: [self class]]; - object = [array objectAtIndex: index]; + object = [_array objectAtIndex: index]; if ([object conformsToProtocol: @protocol(NSBridging)]) return [object OFObject]; return object; } - (size_t)count { - return [array count]; + return [_array count]; } @end Index: src/bridge/OFDictionary_NSDictionary.h ================================================================== --- src/bridge/OFDictionary_NSDictionary.h +++ src/bridge/OFDictionary_NSDictionary.h @@ -18,10 +18,10 @@ @class NSDictionary; @interface OFDictionary_NSDictionary: OFDictionary { - NSDictionary *dictionary; + NSDictionary *_dictionary; } - initWithNSDictionary: (NSDictionary*)dictionary; @end Index: src/bridge/OFDictionary_NSDictionary.m ================================================================== --- src/bridge/OFDictionary_NSDictionary.m +++ src/bridge/OFDictionary_NSDictionary.m @@ -22,20 +22,20 @@ #import "OFBridging.h" #import "OFInitializationFailedException.h" @implementation OFDictionary_NSDictionary -- initWithNSDictionary: (NSDictionary*)dictionary_ +- initWithNSDictionary: (NSDictionary*)dictionary { self = [super init]; @try { - dictionary = [dictionary_ retain]; - if (dictionary == nil) @throw [OFInitializationFailedException - exceptionWithClass: isa]; + exceptionWithClass: [self class]]; + + _dictionary = [dictionary retain]; } @catch (id e) { [self release]; @throw e; } @@ -47,18 +47,18 @@ id object; if ([key conformsToProtocol: @protocol(OFBridging)]) key = [key NSObject]; - object = [dictionary objectForKey: key]; + object = [_dictionary objectForKey: key]; if ([object conformsToProtocol: @protocol(NSBridging)]) return [object OFObject]; return object; } - (size_t)count { - return [dictionary count]; + return [_dictionary count]; } @end Index: src/exceptions/OFAcceptFailedException.h ================================================================== --- src/exceptions/OFAcceptFailedException.h +++ src/exceptions/OFAcceptFailedException.h @@ -21,12 +21,12 @@ /*! * @brief An exception indicating that accepting a connection failed. */ @interface OFAcceptFailedException: OFException { - OFTCPSocket *socket; - int errNo; + OFTCPSocket *_socket; + int _errNo; } #ifdef OF_HAVE_PROPERTIES @property (readonly, retain, nonatomic) OFTCPSocket *socket; @property (readonly) int errNo; Index: src/exceptions/OFAcceptFailedException.m ================================================================== --- src/exceptions/OFAcceptFailedException.m +++ src/exceptions/OFAcceptFailedException.m @@ -23,18 +23,18 @@ #import "OFTCPSocket.h" #import "common.h" @implementation OFAcceptFailedException -+ (instancetype)exceptionWithClass: (Class)class_ ++ (instancetype)exceptionWithClass: (Class)class socket: (OFTCPSocket*)socket { - return [[[self alloc] initWithClass: class_ + return [[[self alloc] initWithClass: class socket: socket] autorelease]; } -- initWithClass: (Class)class_ +- initWithClass: (Class)class { @try { [self doesNotRecognizeSelector: _cmd]; } @catch (id e) { [self release]; @@ -42,45 +42,45 @@ } abort(); } -- initWithClass: (Class)class_ - socket: (OFTCPSocket*)socket_ +- initWithClass: (Class)class + socket: (OFTCPSocket*)socket { - self = [super initWithClass: class_]; + self = [super initWithClass: class]; - socket = [socket_ retain]; - errNo = GET_SOCK_ERRNO; + _socket = [socket retain]; + _errNo = GET_SOCK_ERRNO; return self; } - (void)dealloc { - [socket release]; + [_socket release]; [super dealloc]; } - (OFString*)description { - if (description != nil) - return description; + if (_description != nil) + return _description; - description = [[OFString alloc] initWithFormat: + _description = [[OFString alloc] initWithFormat: @"Failed to accept connection in socket of type %@! " ERRFMT, - inClass, ERRPARAM]; + _inClass, ERRPARAM]; - return description; + return _description; } - (OFTCPSocket*)socket { - OF_GETTER(socket, NO) + OF_GETTER(_socket, NO) } - (int)errNo { - return errNo; + return _errNo; } @end Index: src/exceptions/OFAddressTranslationFailedException.h ================================================================== --- src/exceptions/OFAddressTranslationFailedException.h +++ src/exceptions/OFAddressTranslationFailedException.h @@ -21,13 +21,13 @@ /*! * @brief An exception indicating the translation of an address failed. */ @interface OFAddressTranslationFailedException: OFException { - OFTCPSocket *socket; - OFString *host; - int errNo; + OFTCPSocket *_socket; + OFString *_host; + int _errNo; } #ifdef OF_HAVE_PROPERTIES @property (readonly, retain, nonatomic) OFTCPSocket *socket; @property (readonly, copy, nonatomic) OFString *host; Index: src/exceptions/OFAddressTranslationFailedException.m ================================================================== --- src/exceptions/OFAddressTranslationFailedException.m +++ src/exceptions/OFAddressTranslationFailedException.m @@ -21,38 +21,38 @@ #import "OFTCPSocket.h" #import "common.h" @implementation OFAddressTranslationFailedException -+ (instancetype)exceptionWithClass: (Class)class_ ++ (instancetype)exceptionWithClass: (Class)class socket: (OFTCPSocket*)socket host: (OFString*)host { - return [[[self alloc] initWithClass: class_ + return [[[self alloc] initWithClass: class socket: socket host: host] autorelease]; } -- initWithClass: (Class)class_ +- initWithClass: (Class)class { - self = [super initWithClass: class_]; + self = [super initWithClass: class]; - errNo = GET_AT_ERRNO; + _errNo = GET_AT_ERRNO; return self; } -- initWithClass: (Class)class_ - socket: (OFTCPSocket*)socket_ - host: (OFString*)host_ +- initWithClass: (Class)class + socket: (OFTCPSocket*)socket + host: (OFString*)host { - self = [super initWithClass: class_]; + self = [super initWithClass: class]; @try { - socket = [socket_ retain]; - host = [host_ copy]; - errNo = GET_AT_ERRNO; + _socket = [socket retain]; + _host = [host copy]; + _errNo = GET_AT_ERRNO; } @catch (id e) { [self release]; @throw e; } @@ -59,46 +59,46 @@ return self; } - (void)dealloc { - [socket release]; - [host release]; + [_socket release]; + [_host release]; [super dealloc]; } - (OFString*)description { - if (description != nil) - return description; + if (_description != nil) + return _description; - if (host != nil) - description = [[OFString alloc] initWithFormat: + if (_host != nil) + _description = [[OFString alloc] initWithFormat: @"The host %@ could not be translated to an address in " @"class %@. This means that either the host was not found, " @"there was a problem with the name server, there was a " @"problem with your network connection or you specified an " - @"invalid host. " ERRFMT, host, inClass, AT_ERRPARAM]; + @"invalid host. " ERRFMT, _host, _inClass, AT_ERRPARAM]; else - description = [[OFString alloc] initWithFormat: + _description = [[OFString alloc] initWithFormat: @"An address translation failed in class %@! " ERRFMT, - inClass, AT_ERRPARAM]; + _inClass, AT_ERRPARAM]; - return description; + return _description; } - (OFTCPSocket*)socket { - OF_GETTER(socket, NO) + OF_GETTER(_socket, NO) } - (OFString*)host { - return host; + OF_GETTER(_host, NO) } - (int)errNo { - return errNo; + return _errNo; } @end Index: src/exceptions/OFAlreadyConnectedException.h ================================================================== --- src/exceptions/OFAlreadyConnectedException.h +++ src/exceptions/OFAlreadyConnectedException.h @@ -22,11 +22,11 @@ * @brief An exception indicating an attempt to connect or bind an already * connected or bound socket. */ @interface OFAlreadyConnectedException: OFException { - OFTCPSocket *socket; + OFTCPSocket *_socket; } #ifdef OF_HAVE_PROPERTIES @property (readonly, retain, nonatomic) OFTCPSocket *socket; #endif Index: src/exceptions/OFAlreadyConnectedException.m ================================================================== --- src/exceptions/OFAlreadyConnectedException.m +++ src/exceptions/OFAlreadyConnectedException.m @@ -23,18 +23,18 @@ #import "OFTCPSocket.h" #import "common.h" @implementation OFAlreadyConnectedException -+ (instancetype)exceptionWithClass: (Class)class_ ++ (instancetype)exceptionWithClass: (Class)class socket: (OFTCPSocket*)socket { - return [[[self alloc] initWithClass: class_ + return [[[self alloc] initWithClass: class socket: socket] autorelease]; } -- initWithClass: (Class)class_ +- initWithClass: (Class)class { @try { [self doesNotRecognizeSelector: _cmd]; } @catch (id e) { [self release]; @@ -42,39 +42,39 @@ } abort(); } -- initWithClass: (Class)class_ - socket: (OFTCPSocket*)socket_ +- initWithClass: (Class)class + socket: (OFTCPSocket*)socket { - self = [super initWithClass: class_]; + self = [super initWithClass: class]; - socket = [socket_ retain]; + _socket = [socket retain]; return self; } - (void)dealloc { - [socket release]; + [_socket release]; [super dealloc]; } - (OFString*)description { - if (description != nil) - return description; + if (_description != nil) + return _description; - description = [[OFString alloc] initWithFormat: + _description = [[OFString alloc] initWithFormat: @"The socket of type %@ is already connected or bound and thus " - @"can't be connected or bound again!", inClass]; + @"can't be connected or bound again!", _inClass]; - return description; + return _description; } - (OFTCPSocket*)socket { - OF_GETTER(socket, NO) + OF_GETTER(_socket, NO) } @end Index: src/exceptions/OFBindFailedException.h ================================================================== --- src/exceptions/OFBindFailedException.h +++ src/exceptions/OFBindFailedException.h @@ -21,14 +21,14 @@ /*! * @brief An exception indicating that binding a socket failed. */ @interface OFBindFailedException: OFException { - OFTCPSocket *socket; - OFString *host; - uint16_t port; - int errNo; + OFTCPSocket *_socket; + OFString *_host; + uint16_t _port; + int _errNo; } #ifdef OF_HAVE_PROPERTIES @property (readonly, retain, nonatomic) OFTCPSocket *socket; @property (readonly, copy, nonatomic) OFString *host; Index: src/exceptions/OFBindFailedException.m ================================================================== --- src/exceptions/OFBindFailedException.m +++ src/exceptions/OFBindFailedException.m @@ -23,22 +23,22 @@ #import "OFTCPSocket.h" #import "common.h" @implementation OFBindFailedException -+ (instancetype)exceptionWithClass: (Class)class_ ++ (instancetype)exceptionWithClass: (Class)class socket: (OFTCPSocket*)socket host: (OFString*)host port: (uint16_t)port { - return [[[self alloc] initWithClass: class_ + return [[[self alloc] initWithClass: class socket: socket host: host port: port] autorelease]; } -- initWithClass: (Class)class_ +- initWithClass: (Class)class { @try { [self doesNotRecognizeSelector: _cmd]; } @catch (id e) { [self release]; @@ -46,22 +46,22 @@ } abort(); } -- initWithClass: (Class)class_ - socket: (OFTCPSocket*)socket_ - host: (OFString*)host_ - port: (uint16_t)port_ +- initWithClass: (Class)class + socket: (OFTCPSocket*)socket + host: (OFString*)host + port: (uint16_t)port { - self = [super initWithClass: class_]; + self = [super initWithClass: class]; @try { - socket = [socket_ retain]; - host = [host_ copy]; - port = port_; - errNo = GET_SOCK_ERRNO; + _socket = [socket retain]; + _host = [host copy]; + _port = port; + _errNo = GET_SOCK_ERRNO; } @catch (id e) { [self release]; @throw e; } @@ -68,43 +68,43 @@ return self; } - (void)dealloc { - [socket release]; - [host release]; + [_socket release]; + [_host release]; [super dealloc]; } - (OFString*)description { - if (description != nil) - return description; + if (_description != nil) + return _description; - description = [[OFString alloc] initWithFormat: + _description = [[OFString alloc] initWithFormat: @"Binding to port %" @PRIu16 @" on host %@ failed in class %@! " - ERRFMT, port, host, inClass, ERRPARAM]; + ERRFMT, _port, _host, _inClass, ERRPARAM]; - return description; + return _description; } - (OFTCPSocket*)socket { - OF_GETTER(socket, NO) + OF_GETTER(_socket, NO) } - (OFString*)host { - OF_GETTER(host, NO) + OF_GETTER(_host, NO) } - (uint16_t)port { - return port; + return _port; } - (int)errNo { - return errNo; + return _errNo; } @end Index: src/exceptions/OFChangeDirectoryFailedException.h ================================================================== --- src/exceptions/OFChangeDirectoryFailedException.h +++ src/exceptions/OFChangeDirectoryFailedException.h @@ -19,12 +19,12 @@ /*! * @brief An exception indicating changing to a directory failed */ @interface OFChangeDirectoryFailedException: OFException { - OFString *path; - int errNo; + OFString *_path; + int _errNo; } #ifdef OF_HAVE_PROPERTIES @property (readonly, copy, nonatomic) OFString *path; @property (readonly) int errNo; Index: src/exceptions/OFChangeDirectoryFailedException.m ================================================================== --- src/exceptions/OFChangeDirectoryFailedException.m +++ src/exceptions/OFChangeDirectoryFailedException.m @@ -22,18 +22,18 @@ #import "OFString.h" #import "common.h" @implementation OFChangeDirectoryFailedException -+ (instancetype)exceptionWithClass: (Class)class_ - path: (OFString*)path_ ++ (instancetype)exceptionWithClass: (Class)class + path: (OFString*)path { - return [[[self alloc] initWithClass: class_ - path: path_] autorelease]; + return [[[self alloc] initWithClass: class + path: path] autorelease]; } -- initWithClass: (Class)class_ +- initWithClass: (Class)class { @try { [self doesNotRecognizeSelector: _cmd]; } @catch (id e) { [self release]; @@ -41,18 +41,18 @@ } abort(); } -- initWithClass: (Class)class_ - path: (OFString*)path_ +- initWithClass: (Class)class + path: (OFString*)path { - self = [super initWithClass: class_]; + self = [super initWithClass: class]; @try { - path = [path_ copy]; - errNo = GET_ERRNO; + _path = [path copy]; + _errNo = GET_ERRNO; } @catch (id e) { [self release]; @throw e; } @@ -59,32 +59,32 @@ return self; } - (void)dealloc { - [path release]; + [_path release]; [super dealloc]; } - (OFString*)description { - if (description != nil) - return description; - - description = [[OFString alloc] initWithFormat: - @"Failed to change to directory %@ in class %@! " ERRFMT, path, - inClass, ERRPARAM]; - - return description; + if (_description != nil) + return _description; + + _description = [[OFString alloc] initWithFormat: + @"Failed to change to directory %@ in class %@! " ERRFMT, _path, + _inClass, ERRPARAM]; + + return _description; } - (int)errNo { - return errNo; + return _errNo; } - (OFString*)path { - OF_GETTER(path, NO) + OF_GETTER(_path, NO) } @end Index: src/exceptions/OFChangeFileModeFailedException.h ================================================================== --- src/exceptions/OFChangeFileModeFailedException.h +++ src/exceptions/OFChangeFileModeFailedException.h @@ -21,13 +21,13 @@ /*! * @brief An exception indicating that changing the mode of a file failed. */ @interface OFChangeFileModeFailedException: OFException { - OFString *path; - mode_t mode; - int errNo; + OFString *_path; + mode_t _mode; + int _errNo; } #ifdef OF_HAVE_PROPERTIES @property (readonly, copy, nonatomic) OFString *path; @property (readonly) mode_t mode; Index: src/exceptions/OFChangeFileModeFailedException.m ================================================================== --- src/exceptions/OFChangeFileModeFailedException.m +++ src/exceptions/OFChangeFileModeFailedException.m @@ -22,20 +22,20 @@ #import "OFString.h" #import "common.h" @implementation OFChangeFileModeFailedException -+ (instancetype)exceptionWithClass: (Class)class_ ++ (instancetype)exceptionWithClass: (Class)class path: (OFString*)path mode: (mode_t)mode { - return [[[self alloc] initWithClass: class_ + return [[[self alloc] initWithClass: class path: path mode: mode] autorelease]; } -- initWithClass: (Class)class_ +- initWithClass: (Class)class { @try { [self doesNotRecognizeSelector: _cmd]; } @catch (id e) { [self release]; @@ -43,20 +43,20 @@ } abort(); } -- initWithClass: (Class)class_ - path: (OFString*)path_ - mode: (mode_t)mode_ +- initWithClass: (Class)class + path: (OFString*)path + mode: (mode_t)mode { - self = [super initWithClass: class_]; + self = [super initWithClass: class]; @try { - path = [path_ copy]; - mode = mode_; - errNo = GET_ERRNO; + _path = [path copy]; + _mode = mode; + _errNo = GET_ERRNO; } @catch (id e) { [self release]; @throw e; } @@ -63,37 +63,37 @@ return self; } - (void)dealloc { - [path release]; + [_path release]; [super dealloc]; } - (OFString*)description { - if (description != nil) - return description; + if (_description != nil) + return _description; - description = [[OFString alloc] initWithFormat: + _description = [[OFString alloc] initWithFormat: @"Failed to change mode for file %@ to %d in class %@! " ERRFMT, - path, mode, inClass, ERRPARAM]; + _path, _mode, _inClass, ERRPARAM]; - return description; + return _description; } - (int)errNo { - return errNo; + return _errNo; } - (OFString*)path { - OF_GETTER(path, NO) + OF_GETTER(_path, NO) } - (mode_t)mode { - return mode; + return _mode; } @end Index: src/exceptions/OFChangeFileOwnerFailedException.h ================================================================== --- src/exceptions/OFChangeFileOwnerFailedException.h +++ src/exceptions/OFChangeFileOwnerFailedException.h @@ -20,20 +20,16 @@ /*! * @brief An exception indicating that changing the owner of a file failed. */ @interface OFChangeFileOwnerFailedException: OFException { - OFString *path; - OFString *owner; - OFString *group; - int errNo; + OFString *_path, *_owner, *_group; + int _errNo; } #ifdef OF_HAVE_PROPERTIES -@property (readonly, copy, nonatomic) OFString *path; -@property (readonly, copy, nonatomic) OFString *owner; -@property (readonly, copy, nonatomic) OFString *group; +@property (readonly, copy, nonatomic) OFString *path, *owner, *group; @property (readonly) int errNo; #endif /*! * @brief Creates a new, autoreleased change file owner failed exception. Index: src/exceptions/OFChangeFileOwnerFailedException.m ================================================================== --- src/exceptions/OFChangeFileOwnerFailedException.m +++ src/exceptions/OFChangeFileOwnerFailedException.m @@ -23,22 +23,22 @@ #import "common.h" #ifndef _WIN32 @implementation OFChangeFileOwnerFailedException -+ (instancetype)exceptionWithClass: (Class)class_ ++ (instancetype)exceptionWithClass: (Class)class path: (OFString*)path owner: (OFString*)owner group: (OFString*)group { - return [[[self alloc] initWithClass: class_ + return [[[self alloc] initWithClass: class path: path owner: owner group: group] autorelease]; } -- initWithClass: (Class)class_ +- initWithClass: (Class)class { @try { [self doesNotRecognizeSelector: _cmd]; } @catch (id e) { [self release]; @@ -46,22 +46,22 @@ } abort(); } -- initWithClass: (Class)class_ - path: (OFString*)path_ - owner: (OFString*)owner_ - group: (OFString*)group_ +- initWithClass: (Class)class + path: (OFString*)path + owner: (OFString*)owner + group: (OFString*)group { - self = [super initWithClass: class_]; + self = [super initWithClass: class]; @try { - path = [path_ copy]; - owner = [owner_ copy]; - group = [group_ copy]; - errNo = GET_ERRNO; + _path = [path copy]; + _owner = [owner copy]; + _group = [group copy]; + _errNo = GET_ERRNO; } @catch (id e) { [self release]; @throw e; } @@ -68,54 +68,54 @@ return self; } - (void)dealloc { - [path release]; - [owner release]; - [group release]; + [_path release]; + [_owner release]; + [_group release]; [super dealloc]; } - (OFString*)description { - if (description != nil) - return description; + if (_description != nil) + return _description; - if (group == nil) - description = [[OFString alloc] initWithFormat: + if (_group == nil) + _description = [[OFString alloc] initWithFormat: @"Failed to change owner for file %@ to %@ in class %@! " - ERRFMT, path, owner, inClass, ERRPARAM]; - else if (owner == nil) - description = [[OFString alloc] initWithFormat: + ERRFMT, _path, _owner, _inClass, ERRPARAM]; + else if (_owner == nil) + _description = [[OFString alloc] initWithFormat: @"Failed to change group for file %@ to %@ in class %@! " - ERRFMT, path, group, inClass, ERRPARAM]; + ERRFMT, _path, _group, _inClass, ERRPARAM]; else - description = [[OFString alloc] initWithFormat: + _description = [[OFString alloc] initWithFormat: @"Failed to change owner for file %@ to %@:%@ in class %@! " - ERRFMT, path, owner, group, inClass, ERRPARAM]; + ERRFMT, _path, _owner, _group, _inClass, ERRPARAM]; - return description; + return _description; } - (int)errNo { - return errNo; + return _errNo; } - (OFString*)path { - OF_GETTER(path, NO) + OF_GETTER(_path, NO) } - (OFString*)owner { - OF_GETTER(owner, NO) + OF_GETTER(_owner, NO) } - (OFString*)group { - OF_GETTER(group, NO) + OF_GETTER(_group, NO) } @end #endif Index: src/exceptions/OFConditionBroadcastFailedException.h ================================================================== --- src/exceptions/OFConditionBroadcastFailedException.h +++ src/exceptions/OFConditionBroadcastFailedException.h @@ -21,11 +21,11 @@ /*! * @brief An exception indicating broadcasting a condition failed. */ @interface OFConditionBroadcastFailedException: OFException { - OFCondition *condition; + OFCondition *_condition; } #ifdef OF_HAVE_PROPERTIES @property (readonly, retain, nonatomic) OFCondition *condition; #endif Index: src/exceptions/OFConditionBroadcastFailedException.m ================================================================== --- src/exceptions/OFConditionBroadcastFailedException.m +++ src/exceptions/OFConditionBroadcastFailedException.m @@ -21,18 +21,18 @@ #import "OFConditionBroadcastFailedException.h" #import "OFString.h" #import "OFCondition.h" @implementation OFConditionBroadcastFailedException -+ (instancetype)exceptionWithClass: (Class)class_ ++ (instancetype)exceptionWithClass: (Class)class condition: (OFCondition*)condition { - return [[[self alloc] initWithClass: class_ + return [[[self alloc] initWithClass: class condition: condition] autorelease]; } -- initWithClass: (Class)class_ +- initWithClass: (Class)class { @try { [self doesNotRecognizeSelector: _cmd]; } @catch (id e) { [self release]; @@ -40,38 +40,38 @@ } abort(); } -- initWithClass: (Class)class_ - condition: (OFCondition*)condition_ +- initWithClass: (Class)class + condition: (OFCondition*)condition { - self = [super initWithClass: class_]; + self = [super initWithClass: class]; - condition = [condition_ retain]; + _condition = [condition retain]; return self; } - (void)dealloc { - [condition release]; + [_condition release]; [super dealloc]; } - (OFString*)description { - if (description != nil) - return description; + if (_description != nil) + return _description; - description = [[OFString alloc] initWithFormat: - @"Broadcasting a condition of type %@ failed!", inClass]; + _description = [[OFString alloc] initWithFormat: + @"Broadcasting a condition of type %@ failed!", _inClass]; - return description; + return _description; } - (OFCondition*)condition { - OF_GETTER(condition, NO) + OF_GETTER(_condition, NO) } @end Index: src/exceptions/OFConditionSignalFailedException.h ================================================================== --- src/exceptions/OFConditionSignalFailedException.h +++ src/exceptions/OFConditionSignalFailedException.h @@ -21,11 +21,11 @@ /*! * @brief An exception indicating signaling a condition failed. */ @interface OFConditionSignalFailedException: OFException { - OFCondition *condition; + OFCondition *_condition; } #ifdef OF_HAVE_PROPERTIES @property (readonly, retain, nonatomic) OFCondition *condition; #endif Index: src/exceptions/OFConditionSignalFailedException.m ================================================================== --- src/exceptions/OFConditionSignalFailedException.m +++ src/exceptions/OFConditionSignalFailedException.m @@ -21,18 +21,18 @@ #import "OFConditionSignalFailedException.h" #import "OFString.h" #import "OFCondition.h" @implementation OFConditionSignalFailedException -+ (instancetype)exceptionWithClass: (Class)class_ ++ (instancetype)exceptionWithClass: (Class)class condition: (OFCondition*)condition { - return [[[self alloc] initWithClass: class_ + return [[[self alloc] initWithClass: class condition: condition] autorelease]; } -- initWithClass: (Class)class_ +- initWithClass: (Class)class { @try { [self doesNotRecognizeSelector: _cmd]; } @catch (id e) { [self release]; @@ -40,38 +40,38 @@ } abort(); } -- initWithClass: (Class)class_ - condition: (OFCondition*)condition_ +- initWithClass: (Class)class + condition: (OFCondition*)condition { - self = [super initWithClass: class_]; + self = [super initWithClass: class]; - condition = [condition_ retain]; + _condition = [condition retain]; return self; } - (void)dealloc { - [condition release]; + [_condition release]; [super dealloc]; } - (OFString*)description { - if (description != nil) - return description; + if (_description != nil) + return _description; - description = [[OFString alloc] initWithFormat: - @"Signaling a condition of type %@ failed!", inClass]; + _description = [[OFString alloc] initWithFormat: + @"Signaling a condition of type %@ failed!", _inClass]; - return description; + return _description; } - (OFCondition*)condition { - OF_GETTER(condition, NO) + OF_GETTER(_condition, NO) } @end Index: src/exceptions/OFConditionStillWaitingException.h ================================================================== --- src/exceptions/OFConditionStillWaitingException.h +++ src/exceptions/OFConditionStillWaitingException.h @@ -22,11 +22,11 @@ * @brief An exception indicating that a thread is still waiting for a * condition. */ @interface OFConditionStillWaitingException: OFException { - OFCondition *condition; + OFCondition *_condition; } #ifdef OF_HAVE_PROPERTIES @property (readonly, retain, nonatomic) OFCondition *condition; #endif Index: src/exceptions/OFConditionStillWaitingException.m ================================================================== --- src/exceptions/OFConditionStillWaitingException.m +++ src/exceptions/OFConditionStillWaitingException.m @@ -21,18 +21,18 @@ #import "OFConditionStillWaitingException.h" #import "OFString.h" #import "OFCondition.h" @implementation OFConditionStillWaitingException -+ (instancetype)exceptionWithClass: (Class)class_ ++ (instancetype)exceptionWithClass: (Class)class condition: (OFCondition*)condition { - return [[[self alloc] initWithClass: class_ + return [[[self alloc] initWithClass: class condition: condition] autorelease]; } -- initWithClass: (Class)class_ +- initWithClass: (Class)class { @try { [self doesNotRecognizeSelector: _cmd]; } @catch (id e) { [self release]; @@ -40,39 +40,39 @@ } abort(); } -- initWithClass: (Class)class_ - condition: (OFCondition*)condition_ +- initWithClass: (Class)class + condition: (OFCondition*)condition { - self = [super initWithClass: class_]; + self = [super initWithClass: class]; - condition = [condition_ retain]; + _condition = [condition retain]; return self; } - (void)dealloc { - [condition release]; + [_condition release]; [super dealloc]; } - (OFString*)description { - if (description != nil) - return description; + if (_description != nil) + return _description; - description = [[OFString alloc] initWithFormat: + _description = [[OFString alloc] initWithFormat: @"Deallocation of a condition of type %@ was tried, even though a " - @"thread was still waiting for it!", inClass]; + @"thread was still waiting for it!", _inClass]; - return description; + return _description; } - (OFCondition*)condition { - OF_GETTER(condition, NO) + OF_GETTER(_condition, NO) } @end Index: src/exceptions/OFConditionWaitFailedException.h ================================================================== --- src/exceptions/OFConditionWaitFailedException.h +++ src/exceptions/OFConditionWaitFailedException.h @@ -21,11 +21,11 @@ /*! * @brief An exception indicating waiting for a condition failed. */ @interface OFConditionWaitFailedException: OFException { - OFCondition *condition; + OFCondition *_condition; } #ifdef OF_HAVE_PROPERTIES @property (readonly, retain, nonatomic) OFCondition *condition; #endif Index: src/exceptions/OFConditionWaitFailedException.m ================================================================== --- src/exceptions/OFConditionWaitFailedException.m +++ src/exceptions/OFConditionWaitFailedException.m @@ -21,18 +21,18 @@ #import "OFConditionWaitFailedException.h" #import "OFString.h" #import "OFCondition.h" @implementation OFConditionWaitFailedException -+ (instancetype)exceptionWithClass: (Class)class_ ++ (instancetype)exceptionWithClass: (Class)class condition: (OFCondition*)condition { - return [[[self alloc] initWithClass: class_ + return [[[self alloc] initWithClass: class condition: condition] autorelease]; } -- initWithClass: (Class)class_ +- initWithClass: (Class)class { @try { [self doesNotRecognizeSelector: _cmd]; } @catch (id e) { [self release]; @@ -40,38 +40,38 @@ } abort(); } -- initWithClass: (Class)class_ - condition: (OFCondition*)condition_ +- initWithClass: (Class)class + condition: (OFCondition*)condition { - self = [super initWithClass: class_]; + self = [super initWithClass: class]; - condition = [condition_ retain]; + _condition = [condition retain]; return self; } - (void)dealloc { - [condition release]; + [_condition release]; [super dealloc]; } - (OFString*)description { - if (description != nil) - return description; + if (_description != nil) + return _description; - description = [[OFString alloc] initWithFormat: - @"Waiting for a condition of type %@ failed!", inClass]; + _description = [[OFString alloc] initWithFormat: + @"Waiting for a condition of type %@ failed!", _inClass]; - return description; + return _description; } - (OFCondition*)condition { - OF_GETTER(condition, NO) + OF_GETTER(_condition, NO) } @end Index: src/exceptions/OFConnectionFailedException.h ================================================================== --- src/exceptions/OFConnectionFailedException.h +++ src/exceptions/OFConnectionFailedException.h @@ -21,14 +21,14 @@ /*! * @brief An exception indicating that a connection could not be established. */ @interface OFConnectionFailedException: OFException { - OFTCPSocket *socket; - OFString *host; - uint16_t port; - int errNo; + OFTCPSocket *_socket; + OFString *_host; + uint16_t _port; + int _errNo; } #ifdef OF_HAVE_PROPERTIES @property (readonly, retain, nonatomic) OFTCPSocket *socket; @property (readonly, copy, nonatomic) OFString *host; Index: src/exceptions/OFConnectionFailedException.m ================================================================== --- src/exceptions/OFConnectionFailedException.m +++ src/exceptions/OFConnectionFailedException.m @@ -23,22 +23,22 @@ #import "OFTCPSocket.h" #import "common.h" @implementation OFConnectionFailedException -+ (instancetype)exceptionWithClass: (Class)class_ ++ (instancetype)exceptionWithClass: (Class)class socket: (OFTCPSocket*)socket host: (OFString*)host port: (uint16_t)port { - return [[[self alloc] initWithClass: class_ + return [[[self alloc] initWithClass: class socket: socket host: host port: port] autorelease]; } -- initWithClass: (Class)class_ +- initWithClass: (Class)class { @try { [self doesNotRecognizeSelector: _cmd]; } @catch (id e) { [self release]; @@ -46,22 +46,22 @@ } abort(); } -- initWithClass: (Class)class_ - socket: (OFTCPSocket*)socket_ - host: (OFString*)host_ - port: (uint16_t)port_ +- initWithClass: (Class)class + socket: (OFTCPSocket*)socket + host: (OFString*)host + port: (uint16_t)port { - self = [super initWithClass: class_]; + self = [super initWithClass: class]; @try { - socket = [socket_ retain]; - host = [host_ copy]; - port = port_; - errNo = GET_SOCK_ERRNO; + _socket = [socket retain]; + _host = [host copy]; + _port = port; + _errNo = GET_SOCK_ERRNO; } @catch (id e) { [self release]; @throw e; } @@ -68,43 +68,44 @@ return self; } - (void)dealloc { - [socket release]; - [host release]; + [_socket release]; + [_host release]; [super dealloc]; } - (OFString*)description { - if (description != nil) - return description; + if (_description != nil) + return _description; - description = [[OFString alloc] initWithFormat: + _description = [[OFString alloc] initWithFormat: @"A connection to %@ on port %" @PRIu16 @" could not be " - @"established in class %@! " ERRFMT, host, port, inClass, ERRPARAM]; + @"established in class %@! " ERRFMT, _host, _port, _inClass, + ERRPARAM]; - return description; + return _description; } - (OFTCPSocket*)socket { - OF_GETTER(socket, NO) + OF_GETTER(_socket, NO) } - (OFString*)host { - OF_GETTER(host, NO) + OF_GETTER(_host, NO) } - (uint16_t)port { - return port; + return _port; } - (int)errNo { - return errNo; + return _errNo; } @end Index: src/exceptions/OFCopyFileFailedException.h ================================================================== --- src/exceptions/OFCopyFileFailedException.h +++ src/exceptions/OFCopyFileFailedException.h @@ -19,13 +19,12 @@ /*! * @brief An exception indicating that copying a file failed. */ @interface OFCopyFileFailedException: OFException { - OFString *sourcePath; - OFString *destinationPath; - int errNo; + OFString *_sourcePath, *_destinationPath; + int _errNo; } #ifdef OF_HAVE_PROPERTIES @property (readonly, copy, nonatomic) OFString *sourcePath; @property (readonly, copy, nonatomic) OFString *destinationPath; @@ -34,29 +33,29 @@ /*! * @brief Creates a new, autoreleased copy file failed exception. * * @param class_ The class of the object which caused the exception - * @param source The original path - * @param destination The new path + * @param sourcePath The original path + * @param destinationPath The new path * @return A new, autoreleased copy file failed exception */ + (instancetype)exceptionWithClass: (Class)class_ - sourcePath: (OFString*)source - destinationPath: (OFString*)destination; + sourcePath: (OFString*)sourcePath + destinationPath: (OFString*)destinationPath; /*! * @brief Initializes an already allocated copy file failed exception. * * @param class_ The class of the object which caused the exception - * @param source The original path - * @param destination The new path + * @param sourcePath The original path + * @param destinationPath The new path * @return An initialized copy file failed exception */ - initWithClass: (Class)class_ - sourcePath: (OFString*)source - destinationPath: (OFString*)destination; + sourcePath: (OFString*)sourcePath + destinationPath: (OFString*)destinationPath; /*! * @brief Returns the errno from when the exception was created. * * @return The errno from when the exception was created Index: src/exceptions/OFCopyFileFailedException.m ================================================================== --- src/exceptions/OFCopyFileFailedException.m +++ src/exceptions/OFCopyFileFailedException.m @@ -22,20 +22,20 @@ #import "OFString.h" #import "common.h" @implementation OFCopyFileFailedException -+ (instancetype)exceptionWithClass: (Class)class_ - sourcePath: (OFString*)source - destinationPath: (OFString*)destination ++ (instancetype)exceptionWithClass: (Class)class + sourcePath: (OFString*)sourcePath + destinationPath: (OFString*)destinationPath { - return [[[self alloc] initWithClass: class_ - sourcePath: source - destinationPath: destination] autorelease]; + return [[[self alloc] initWithClass: class + sourcePath: sourcePath + destinationPath: destinationPath] autorelease]; } -- initWithClass: (Class)class_ +- initWithClass: (Class)class { @try { [self doesNotRecognizeSelector: _cmd]; } @catch (id e) { [self release]; @@ -43,20 +43,20 @@ } abort(); } -- initWithClass: (Class)class_ - sourcePath: (OFString*)source - destinationPath: (OFString*)destination +- initWithClass: (Class)class + sourcePath: (OFString*)sourcePath + destinationPath: (OFString*)destinationPath { - self = [super initWithClass: class_]; + self = [super initWithClass: class]; @try { - sourcePath = [source copy]; - destinationPath = [destination copy]; - errNo = GET_ERRNO; + _sourcePath = [sourcePath copy]; + _destinationPath = [destinationPath copy]; + _errNo = GET_ERRNO; } @catch (id e) { [self release]; @throw e; } @@ -63,38 +63,38 @@ return self; } - (void)dealloc { - [sourcePath release]; - [destinationPath release]; + [_sourcePath release]; + [_destinationPath release]; [super dealloc]; } - (OFString*)description { - if (description != nil) - return description; + if (_description != nil) + return _description; - description = [[OFString alloc] initWithFormat: + _description = [[OFString alloc] initWithFormat: @"Failed to copy file %@ to %@ in class %@! " ERRFMT, - sourcePath, destinationPath, inClass, ERRPARAM]; + _sourcePath, _destinationPath, _inClass, ERRPARAM]; - return description; + return _description; } - (int)errNo { - return errNo; + return _errNo; } - (OFString*)sourcePath { - OF_GETTER(sourcePath, NO) + OF_GETTER(_sourcePath, NO) } - (OFString*)destinationPath { - OF_GETTER(destinationPath, NO) + OF_GETTER(_destinationPath, NO) } @end Index: src/exceptions/OFCreateDirectoryFailedException.h ================================================================== --- src/exceptions/OFCreateDirectoryFailedException.h +++ src/exceptions/OFCreateDirectoryFailedException.h @@ -19,12 +19,12 @@ /*! * @brief An exception indicating a directory couldn't be created. */ @interface OFCreateDirectoryFailedException: OFException { - OFString *path; - int errNo; + OFString *_path; + int _errNo; } #ifdef OF_HAVE_PROPERTIES @property (readonly, copy, nonatomic) OFString *path; @property (readonly) int errNo; Index: src/exceptions/OFCreateDirectoryFailedException.m ================================================================== --- src/exceptions/OFCreateDirectoryFailedException.m +++ src/exceptions/OFCreateDirectoryFailedException.m @@ -22,18 +22,18 @@ #import "OFString.h" #import "common.h" @implementation OFCreateDirectoryFailedException -+ (instancetype)exceptionWithClass: (Class)class_ - path: (OFString*)path_ ++ (instancetype)exceptionWithClass: (Class)class + path: (OFString*)path { - return [[[self alloc] initWithClass: class_ - path: path_] autorelease]; + return [[[self alloc] initWithClass: class + path: path] autorelease]; } -- initWithClass: (Class)class_ +- initWithClass: (Class)class { @try { [self doesNotRecognizeSelector: _cmd]; } @catch (id e) { [self release]; @@ -41,18 +41,18 @@ } abort(); } -- initWithClass: (Class)class_ - path: (OFString*)path_ +- initWithClass: (Class)class + path: (OFString*)path { - self = [super initWithClass: class_]; + self = [super initWithClass: class]; @try { - path = [path_ copy]; - errNo = GET_ERRNO; + _path = [path copy]; + _errNo = GET_ERRNO; } @catch (id e) { [self release]; @throw e; } @@ -59,32 +59,32 @@ return self; } - (void)dealloc { - [path release]; + [_path release]; [super dealloc]; } - (OFString*)description { - if (description != nil) - return description; - - description = [[OFString alloc] initWithFormat: - @"Failed to create directory %@ in class %@! " ERRFMT, path, - inClass, ERRPARAM]; - - return description; + if (_description != nil) + return _description; + + _description = [[OFString alloc] initWithFormat: + @"Failed to create directory %@ in class %@! " ERRFMT, _path, + _inClass, ERRPARAM]; + + return _description; } - (int)errNo { - return errNo; + return _errNo; } - (OFString*)path { - OF_GETTER(path, NO) + OF_GETTER(_path, NO) } @end Index: src/exceptions/OFDeleteDirectoryFailedException.h ================================================================== --- src/exceptions/OFDeleteDirectoryFailedException.h +++ src/exceptions/OFDeleteDirectoryFailedException.h @@ -19,12 +19,12 @@ /*! * @brief An exception indicating that deleting a directory failed. */ @interface OFDeleteDirectoryFailedException: OFException { - OFString *path; - int errNo; + OFString *_path; + int _errNo; } #ifdef OF_HAVE_PROPERTIES @property (readonly, copy, nonatomic) OFString *path; @property (readonly) int errNo; Index: src/exceptions/OFDeleteDirectoryFailedException.m ================================================================== --- src/exceptions/OFDeleteDirectoryFailedException.m +++ src/exceptions/OFDeleteDirectoryFailedException.m @@ -22,18 +22,18 @@ #import "OFString.h" #import "common.h" @implementation OFDeleteDirectoryFailedException -+ (instancetype)exceptionWithClass: (Class)class_ ++ (instancetype)exceptionWithClass: (Class)class path: (OFString*)path_ { - return [[[self alloc] initWithClass: class_ + return [[[self alloc] initWithClass: class path: path_] autorelease]; } -- initWithClass: (Class)class_ +- initWithClass: (Class)class { @try { [self doesNotRecognizeSelector: _cmd]; } @catch (id e) { [self release]; @@ -41,18 +41,18 @@ } abort(); } -- initWithClass: (Class)class_ - path: (OFString*)path_ +- initWithClass: (Class)class + path: (OFString*)path { - self = [super initWithClass: class_]; + self = [super initWithClass: class]; @try { - path = [path_ copy]; - errNo = GET_ERRNO; + _path = [path copy]; + _errNo = GET_ERRNO; } @catch (id e) { [self release]; @throw e; } @@ -59,32 +59,32 @@ return self; } - (void)dealloc { - [path release]; + [_path release]; [super dealloc]; } - (OFString*)description { - if (description != nil) - return description; - - description = [[OFString alloc] initWithFormat: - @"Failed to delete directory %@ in class %@! " ERRFMT, path, - inClass, ERRPARAM]; - - return description; + if (_description != nil) + return _description; + + _description = [[OFString alloc] initWithFormat: + @"Failed to delete directory %@ in class %@! " ERRFMT, _path, + _inClass, ERRPARAM]; + + return _description; } - (int)errNo { - return errNo; + return _errNo; } - (OFString*)path { - OF_GETTER(path, NO) + OF_GETTER(_path, NO) } @end Index: src/exceptions/OFDeleteFileFailedException.h ================================================================== --- src/exceptions/OFDeleteFileFailedException.h +++ src/exceptions/OFDeleteFileFailedException.h @@ -19,12 +19,12 @@ /*! * @brief An exception indicating that deleting a file failed. */ @interface OFDeleteFileFailedException: OFException { - OFString *path; - int errNo; + OFString *_path; + int _errNo; } #ifdef OF_HAVE_PROPERTIES @property (readonly, copy, nonatomic) OFString *path; @property (readonly) int errNo; Index: src/exceptions/OFDeleteFileFailedException.m ================================================================== --- src/exceptions/OFDeleteFileFailedException.m +++ src/exceptions/OFDeleteFileFailedException.m @@ -22,18 +22,18 @@ #import "OFString.h" #import "common.h" @implementation OFDeleteFileFailedException -+ (instancetype)exceptionWithClass: (Class)class_ - path: (OFString*)path_ ++ (instancetype)exceptionWithClass: (Class)class + path: (OFString*)path { - return [[[self alloc] initWithClass: class_ - path: path_] autorelease]; + return [[[self alloc] initWithClass: class + path: path] autorelease]; } -- initWithClass: (Class)class_ +- initWithClass: (Class)class { @try { [self doesNotRecognizeSelector: _cmd]; } @catch (id e) { [self release]; @@ -41,18 +41,18 @@ } abort(); } -- initWithClass: (Class)class_ - path: (OFString*)path_ +- initWithClass: (Class)class + path: (OFString*)path { - self = [super initWithClass: class_]; + self = [super initWithClass: class]; @try { - path = [path_ copy]; - errNo = GET_ERRNO; + _path = [path copy]; + _errNo = GET_ERRNO; } @catch (id e) { [self release]; @throw e; } @@ -59,32 +59,32 @@ return self; } - (void)dealloc { - [path release]; + [_path release]; [super dealloc]; } - (OFString*)description { - if (description != nil) - return description; + if (_description != nil) + return _description; - description = [[OFString alloc] initWithFormat: - @"Failed to delete file %@ in class %@! " ERRFMT, path, inClass, + _description = [[OFString alloc] initWithFormat: + @"Failed to delete file %@ in class %@! " ERRFMT, _path, _inClass, ERRPARAM]; - return description; + return _description; } - (int)errNo { - return errNo; + return _errNo; } - (OFString*)path { - OF_GETTER(path, NO) + OF_GETTER(_path, NO) } @end Index: src/exceptions/OFEnumerationMutationException.h ================================================================== --- src/exceptions/OFEnumerationMutationException.h +++ src/exceptions/OFEnumerationMutationException.h @@ -20,11 +20,11 @@ * @brief An exception indicating that a mutation was detected during * enumeration. */ @interface OFEnumerationMutationException: OFException { - id object; + id _object; } #ifdef OF_HAVE_PROPERTIES @property (readonly, retain, nonatomic) id object; #endif Index: src/exceptions/OFEnumerationMutationException.m ================================================================== --- src/exceptions/OFEnumerationMutationException.m +++ src/exceptions/OFEnumerationMutationException.m @@ -22,18 +22,18 @@ #import "OFString.h" #import "common.h" @implementation OFEnumerationMutationException -+ (instancetype)exceptionWithClass: (Class)class_ ++ (instancetype)exceptionWithClass: (Class)class object: (id)object { - return [[[self alloc] initWithClass: class_ + return [[[self alloc] initWithClass: class object: object] autorelease]; } -- initWithClass: (Class)class_ +- initWithClass: (Class)class { @try { [self doesNotRecognizeSelector: _cmd]; } @catch (id e) { [self release]; @@ -41,38 +41,38 @@ } abort(); } -- initWithClass: (Class)class_ - object: (id)object_ +- initWithClass: (Class)class + object: (id)object { - self = [super initWithClass: class_]; + self = [super initWithClass: class]; - object = [object_ retain]; + _object = [object retain]; return self; } - (void)dealloc { - [object release]; + [_object release]; [super dealloc]; } - (OFString*)description { - if (description != nil) - return description; + if (_description != nil) + return _description; - description = [[OFString alloc] initWithFormat: - @"Object of class %@ was mutated during enumeration!", inClass]; + _description = [[OFString alloc] initWithFormat: + @"Object of class %@ was mutated during enumeration!", _inClass]; - return description; + return _description; } - (id)object { - OF_GETTER(object, NO) + OF_GETTER(_object, NO) } @end Index: src/exceptions/OFException.h ================================================================== --- src/exceptions/OFException.h +++ src/exceptions/OFException.h @@ -24,12 +24,12 @@ * The OFException class is the base class for all exceptions in ObjFW, except * the OFAllocFailedException. */ @interface OFException: OFObject { - Class inClass; - OFString *description; + Class _inClass; + OFString *_description; } #ifdef OF_HAVE_PROPERTIES @property (readonly) Class inClass; #endif Index: src/exceptions/OFException.m ================================================================== --- src/exceptions/OFException.m +++ src/exceptions/OFException.m @@ -20,13 +20,13 @@ #import "OFException.h" #import "OFString.h" @implementation OFException -+ (instancetype)exceptionWithClass: (Class)class_ ++ (instancetype)exceptionWithClass: (Class)class { - return [[[self alloc] initWithClass: class_] autorelease]; + return [[[self alloc] initWithClass: class] autorelease]; } - init { @try { @@ -37,38 +37,38 @@ } abort(); } -- initWithClass: (Class)class_ +- initWithClass: (Class)class { self = [super init]; - inClass = class_; + _inClass = class; return self; } - (void)dealloc { - [description release]; + [_description release]; [super dealloc]; } - (Class)inClass { - return inClass; + return _inClass; } - (OFString*)description { - if (description != nil) - return description; + if (_description != nil) + return _description; - description = [[OFString alloc] initWithFormat: + _description = [[OFString alloc] initWithFormat: @"An exception of class %@ occurred in class %@!", - object_getClass(self), inClass]; + object_getClass(self), _inClass]; - return description; + return _description; } @end Index: src/exceptions/OFHTTPRequestFailedException.h ================================================================== --- src/exceptions/OFHTTPRequestFailedException.h +++ src/exceptions/OFHTTPRequestFailedException.h @@ -22,12 +22,12 @@ /*! * @brief An exception indicating that a HTTP request failed. */ @interface OFHTTPRequestFailedException: OFException { - OFHTTPRequest *request; - OFHTTPRequestReply *reply; + OFHTTPRequest *_request; + OFHTTPRequestReply *_reply; } #ifdef OF_HAVE_PROPERTIES @property (readonly, retain, nonatomic) OFHTTPRequest *request; @property (readonly, retain, nonatomic) OFHTTPRequestReply *reply; Index: src/exceptions/OFHTTPRequestFailedException.m ================================================================== --- src/exceptions/OFHTTPRequestFailedException.m +++ src/exceptions/OFHTTPRequestFailedException.m @@ -25,20 +25,20 @@ #import "autorelease.h" #import "common.h" @implementation OFHTTPRequestFailedException -+ (instancetype)exceptionWithClass: (Class)class_ ++ (instancetype)exceptionWithClass: (Class)class request: (OFHTTPRequest*)request reply: (OFHTTPRequestReply*)reply { - return [[[self alloc] initWithClass: class_ + return [[[self alloc] initWithClass: class request: request reply: reply] autorelease]; } -- initWithClass: (Class)class_ +- initWithClass: (Class)class { @try { [self doesNotRecognizeSelector: _cmd]; } @catch (id e) { [self release]; @@ -46,39 +46,39 @@ } abort(); } -- initWithClass: (Class)class_ - request: (OFHTTPRequest*)request_ - reply: (OFHTTPRequestReply*)reply_ -{ - self = [super initWithClass: class_]; - - request = [request_ retain]; - reply = [reply_ retain]; +- initWithClass: (Class)class + request: (OFHTTPRequest*)request + reply: (OFHTTPRequestReply*)reply +{ + self = [super initWithClass: class]; + + _request = [request retain]; + _reply = [reply retain]; return self; } - (void)dealloc { - [request release]; - [reply release]; + [_request release]; + [_reply release]; [super dealloc]; } - (OFString*)description { void *pool; const char *type = "(unknown)"; - if (description != nil) - return description; + if (_description != nil) + return _description; - switch ([request requestType]) { + switch ([_request requestType]) { case OF_HTTP_REQUEST_TYPE_GET: type = "GET"; break; case OF_HTTP_REQUEST_TYPE_HEAD: type = "HEAD"; @@ -88,24 +88,24 @@ break; } pool = objc_autoreleasePoolPush(); - description = [[OFString alloc] initWithFormat: + _description = [[OFString alloc] initWithFormat: @"A HTTP %s request in class %@ with URL %@ failed with code %d", - type, inClass, [request URL], [reply statusCode]]; + type, _inClass, [_request URL], [_reply statusCode]]; objc_autoreleasePoolPop(pool); - return description; + return _description; } - (OFHTTPRequest*)request { - OF_GETTER(request, NO) + OF_GETTER(_request, NO) } - (OFHTTPRequestReply*)reply { - OF_GETTER(reply, NO) + OF_GETTER(_reply, NO) } @end Index: src/exceptions/OFHashAlreadyCalculatedException.h ================================================================== --- src/exceptions/OFHashAlreadyCalculatedException.h +++ src/exceptions/OFHashAlreadyCalculatedException.h @@ -21,11 +21,11 @@ /*! * @brief An exception indicating that the hash has already been calculated. */ @interface OFHashAlreadyCalculatedException: OFException { - OFHash *hashObject; + OFHash *_hashObject; } #ifdef OF_HAVE_PROPERTIES @property (readonly, retain, nonatomic) OFHash *hashObject; #endif @@ -32,28 +32,28 @@ /*! * @brief Creates a new, autoreleased hash already calculated exception. * * @param class_ The class of the object which caused the exception - * @param hash The hash which has already been calculated + * @param hashObject The hash which has already been calculated * @return A new, autoreleased hash already calculated exception */ + (instancetype)exceptionWithClass: (Class)class_ - hash: (OFHash*)hash; + hash: (OFHash*)hashObject; /*! * @brief Initializes an already allocated hash already calculated exception. * * @param class_ The class of the object which caused the exception - * @param hash The hash which has already been calculated + * @param hashObject The hash which has already been calculated * @return An initialized hash already calculated exception */ - initWithClass: (Class)class_ - hash: (OFHash*)hash; + hash: (OFHash*)hashObject; /*! * @brief Returns the hash which has already been calculated. * * @return The hash which has already been calculated */ - (OFHash*)hashObject; @end Index: src/exceptions/OFHashAlreadyCalculatedException.m ================================================================== --- src/exceptions/OFHashAlreadyCalculatedException.m +++ src/exceptions/OFHashAlreadyCalculatedException.m @@ -23,18 +23,18 @@ #import "OFHash.h" #import "common.h" @implementation OFHashAlreadyCalculatedException -+ (instancetype)exceptionWithClass: (Class)class_ ++ (instancetype)exceptionWithClass: (Class)class hash: (OFHash*)hash { - return [[[self alloc] initWithClass: class_ + return [[[self alloc] initWithClass: class hash: hash] autorelease]; } -- initWithClass: (Class)class_ +- initWithClass: (Class)class { @try { [self doesNotRecognizeSelector: _cmd]; } @catch (id e) { [self release]; @@ -42,39 +42,39 @@ } abort(); } -- initWithClass: (Class)class_ - hash: (OFHash*)hash +- initWithClass: (Class)class + hash: (OFHash*)hashObject { - self = [super initWithClass: class_]; + self = [super initWithClass: class]; - hashObject = [hash retain]; + _hashObject = [hashObject retain]; return self; } - (void)dealloc { - [hashObject release]; + [_hashObject release]; [super dealloc]; } - (OFString*)description { - if (description != nil) - return description; + if (_description != nil) + return _description; - description = [[OFString alloc] initWithFormat: + _description = [[OFString alloc] initWithFormat: @"The hash has already been calculated in class %@ and thus no new " - @"data can be added", inClass]; + @"data can be added", _inClass]; - return description; + return _description; } - (OFHash*)hashObject { - OF_GETTER(hashObject, NO) + OF_GETTER(_hashObject, NO) } @end Index: src/exceptions/OFInitializationFailedException.m ================================================================== --- src/exceptions/OFInitializationFailedException.m +++ src/exceptions/OFInitializationFailedException.m @@ -20,14 +20,14 @@ #import "OFString.h" @implementation OFInitializationFailedException - (OFString*)description { - if (description != nil) - return description; + if (_description != nil) + return _description; - description = [[OFString alloc] initWithFormat: - @"Initialization failed for or in class %@!", inClass]; + _description = [[OFString alloc] initWithFormat: + @"Initialization failed for or in class %@!", _inClass]; - return description; + return _description; } @end Index: src/exceptions/OFInvalidArgumentException.h ================================================================== --- src/exceptions/OFInvalidArgumentException.h +++ src/exceptions/OFInvalidArgumentException.h @@ -19,11 +19,11 @@ /*! * @brief An exception indicating that the argument is invalid for this method. */ @interface OFInvalidArgumentException: OFException { - SEL selector; + SEL _selector; } #ifdef OF_HAVE_PROPERTIES @property (readonly) SEL selector; #endif Index: src/exceptions/OFInvalidArgumentException.m ================================================================== --- src/exceptions/OFInvalidArgumentException.m +++ src/exceptions/OFInvalidArgumentException.m @@ -22,18 +22,18 @@ #import "OFString.h" #import "common.h" @implementation OFInvalidArgumentException -+ (instancetype)exceptionWithClass: (Class)class_ - selector: (SEL)selector_ ++ (instancetype)exceptionWithClass: (Class)class + selector: (SEL)selector { - return [[[self alloc] initWithClass: class_ - selector: selector_] autorelease]; + return [[[self alloc] initWithClass: class + selector: selector] autorelease]; } -- initWithClass: (Class)class_ +- initWithClass: (Class)class { @try { [self doesNotRecognizeSelector: _cmd]; } @catch (id e) { [self release]; @@ -41,32 +41,32 @@ } abort(); } -- initWithClass: (Class)class_ - selector: (SEL)selector_ +- initWithClass: (Class)class + selector: (SEL)selector { - self = [super initWithClass: class_]; + self = [super initWithClass: class]; - selector = selector_; + _selector = selector; return self; } - (OFString*)description { - if (description != nil) - return description; + if (_description != nil) + return _description; - description = [[OFString alloc] initWithFormat: + _description = [[OFString alloc] initWithFormat: @"The argument or receiver for method %s of class %@ is invalid!", - sel_getName(selector), inClass]; + sel_getName(_selector), _inClass]; - return description; + return _description; } - (SEL)selector { - return selector; + return _selector; } @end Index: src/exceptions/OFInvalidEncodingException.m ================================================================== --- src/exceptions/OFInvalidEncodingException.m +++ src/exceptions/OFInvalidEncodingException.m @@ -20,14 +20,14 @@ #import "OFString.h" @implementation OFInvalidEncodingException - (OFString*)description { - if (description != nil) - return description; + if (_description != nil) + return _description; - description = [[OFString alloc] initWithFormat: - @"The encoding is invalid for class %@!", inClass]; + _description = [[OFString alloc] initWithFormat: + @"The encoding is invalid for class %@!", _inClass]; - return description; + return _description; } @end Index: src/exceptions/OFInvalidFormatException.m ================================================================== --- src/exceptions/OFInvalidFormatException.m +++ src/exceptions/OFInvalidFormatException.m @@ -20,14 +20,14 @@ #import "OFString.h" @implementation OFInvalidFormatException - (OFString*)description { - if (description != nil) - return description; + if (_description != nil) + return _description; - description = [[OFString alloc] initWithFormat: - @"The format is invalid for class %@!", inClass]; + _description = [[OFString alloc] initWithFormat: + @"The format is invalid for class %@!", _inClass]; - return description; + return _description; } @end Index: src/exceptions/OFInvalidJSONException.h ================================================================== --- src/exceptions/OFInvalidJSONException.h +++ src/exceptions/OFInvalidJSONException.h @@ -19,11 +19,11 @@ /*! * @brief An exception indicating a JSON representation is invalid. */ @interface OFInvalidJSONException: OFException { - size_t line; + size_t _line; } #ifdef OF_HAVE_PROPERTIES @property (readonly) size_t line; #endif Index: src/exceptions/OFInvalidJSONException.m ================================================================== --- src/exceptions/OFInvalidJSONException.m +++ src/exceptions/OFInvalidJSONException.m @@ -20,14 +20,14 @@ #import "OFInvalidJSONException.h" #import "OFString.h" @implementation OFInvalidJSONException -+ (instancetype)exceptionWithClass: (Class)class_ ++ (instancetype)exceptionWithClass: (Class)class line: (size_t)line { - return [[[self alloc] initWithClass: class_ + return [[[self alloc] initWithClass: class line: line] autorelease]; } - init { @@ -39,32 +39,32 @@ } abort(); } -- initWithClass: (Class)class_ - line: (size_t)line_ +- initWithClass: (Class)class + line: (size_t)line { - self = [super initWithClass: class_]; + self = [super initWithClass: class]; - line = line_; + _line = line; return self; } - (OFString*)description { - if (description != nil) - return description; + if (_description != nil) + return _description; - description = [[OFString alloc] initWithFormat: + _description = [[OFString alloc] initWithFormat: @"The JSON representation class %@ tried to parse is invalid in " - @"line %zd!", inClass, line]; + @"line %zd!", _inClass, _line]; - return description; + return _description; } - (size_t)line { - return line; + return _line; } @end Index: src/exceptions/OFInvalidServerReplyException.m ================================================================== --- src/exceptions/OFInvalidServerReplyException.m +++ src/exceptions/OFInvalidServerReplyException.m @@ -20,14 +20,14 @@ #import "OFString.h" @implementation OFInvalidServerReplyException - (OFString*)description { - if (description != nil) - return description; + if (_description != nil) + return _description; - description = [[OFString alloc] initWithFormat: - @"Got an invalid reply from the server in class %@", inClass]; + _description = [[OFString alloc] initWithFormat: + @"Got an invalid reply from the server in class %@", _inClass]; - return description; + return _description; } @end Index: src/exceptions/OFLinkFailedException.h ================================================================== --- src/exceptions/OFLinkFailedException.h +++ src/exceptions/OFLinkFailedException.h @@ -20,44 +20,42 @@ /*! * @brief An exception indicating that creating a link failed. */ @interface OFLinkFailedException: OFException { - OFString *sourcePath; - OFString *destinationPath; - int errNo; + OFString *_sourcePath, *_destinationPath; + int _errNo; } # ifdef OF_HAVE_PROPERTIES -@property (readonly, copy, nonatomic) OFString *sourcePath; -@property (readonly, copy, nonatomic) OFString *destinationPath; +@property (readonly, copy, nonatomic) OFString *sourcePath, *destinationPath; @property (readonly) int errNo; # endif /*! * @brief Creates a new, autoreleased link failed exception. * * @param class_ The class of the object which caused the exception - * @param source The source for the link - * @param destination The destination for the link + * @param sourcePath The source for the link + * @param destinationPath The destination for the link * @return A new, autoreleased link failed exception */ + (instancetype)exceptionWithClass: (Class)class_ - sourcePath: (OFString*)source - destinationPath: (OFString*)destination; + sourcePath: (OFString*)sourcePath + destinationPath: (OFString*)destinationPath; /*! * @brief Initializes an already allocated link failed exception. * * @param class_ The class of the object which caused the exception - * @param source The source for the link - * @param destination The destination for the link + * @param sourcePath The source for the link + * @param destinationPath The destination for the link * @return An initialized link failed exception */ - initWithClass: (Class)class_ - sourcePath: (OFString*)source - destinationPath: (OFString*)destination; + sourcePath: (OFString*)sourcePath + destinationPath: (OFString*)destinationPath; /*! * @brief Returns the errno from when the exception was created. * * @return The errno from when the exception was created Index: src/exceptions/OFLinkFailedException.m ================================================================== --- src/exceptions/OFLinkFailedException.m +++ src/exceptions/OFLinkFailedException.m @@ -23,20 +23,20 @@ #import "common.h" #ifndef _WIN32 @implementation OFLinkFailedException -+ (instancetype)exceptionWithClass: (Class)class_ - sourcePath: (OFString*)source - destinationPath: (OFString*)destination ++ (instancetype)exceptionWithClass: (Class)class + sourcePath: (OFString*)sourcePath + destinationPath: (OFString*)destinationPath { - return [[[self alloc] initWithClass: class_ - sourcePath: source - destinationPath: destination] autorelease]; + return [[[self alloc] initWithClass: class + sourcePath: sourcePath + destinationPath: destinationPath] autorelease]; } -- initWithClass: (Class)class_ +- initWithClass: (Class)class { @try { [self doesNotRecognizeSelector: _cmd]; } @catch (id e) { [self release]; @@ -44,20 +44,20 @@ } abort(); } -- initWithClass: (Class)class_ - sourcePath: (OFString*)source - destinationPath: (OFString*)destination +- initWithClass: (Class)class + sourcePath: (OFString*)sourcePath + destinationPath: (OFString*)destinationPath { - self = [super initWithClass: class_]; + self = [super initWithClass: class]; @try { - sourcePath = [source copy]; - destinationPath = [destination copy]; - errNo = GET_ERRNO; + _sourcePath = [sourcePath copy]; + _destinationPath = [destinationPath copy]; + _errNo = GET_ERRNO; } @catch (id e) { [self release]; @throw e; } @@ -64,39 +64,39 @@ return self; } - (void)dealloc { - [sourcePath release]; - [destinationPath release]; + [_sourcePath release]; + [_destinationPath release]; [super dealloc]; } - (OFString*)description { - if (description != nil) - return description; - - description = [[OFString alloc] initWithFormat: - @"Failed to link file %@ to %@ in class %@! " ERRFMT, sourcePath, - destinationPath, inClass, ERRPARAM]; - - return description; + if (_description != nil) + return _description; + + _description = [[OFString alloc] initWithFormat: + @"Failed to link file %@ to %@ in class %@! " ERRFMT, _sourcePath, + _destinationPath, _inClass, ERRPARAM]; + + return _description; } - (int)errNo { - return errNo; + return _errNo; } - (OFString*)sourcePath { - OF_GETTER(sourcePath, NO) + OF_GETTER(_sourcePath, NO) } - (OFString*)destinationPath { - OF_GETTER(destinationPath, NO) + OF_GETTER(_destinationPath, NO) } @end #endif Index: src/exceptions/OFListenFailedException.h ================================================================== --- src/exceptions/OFListenFailedException.h +++ src/exceptions/OFListenFailedException.h @@ -21,44 +21,42 @@ /*! * @brief An exception indicating that listening on the socket failed. */ @interface OFListenFailedException: OFException { - OFTCPSocket *socket; - int backLog; - int errNo; + OFTCPSocket *_socket; + int _backLog, _errNo; } #ifdef OF_HAVE_PROPERTIES @property (readonly, retain, nonatomic) OFTCPSocket *socket; -@property (readonly) int backLog; -@property (readonly) int errNo; +@property (readonly) int backLog, errNo; #endif /*! * @brief Creates a new, autoreleased listen failed exception. * * @param class_ The class of the object which caused the exception * @param socket The socket which failed to listen - * @param backlog The requested size of the back log + * @param backLog The requested size of the back log * @return A new, autoreleased listen failed exception */ + (instancetype)exceptionWithClass: (Class)class_ socket: (OFTCPSocket*)socket - backLog: (int)backlog; + backLog: (int)backLog; /*! * @brief Initializes an already allocated listen failed exception * * @param class_ The class of the object which caused the exception * @param socket The socket which failed to listen - * @param backlog The requested size of the back log + * @param backLog The requested size of the back log * @return An initialized listen failed exception */ - initWithClass: (Class)class_ socket: (OFTCPSocket*)socket - backLog: (int)backlog; + backLog: (int)backLog; /*! * @brief Returns the socket which failed to listen. * * @return The socket which failed to listen Index: src/exceptions/OFListenFailedException.m ================================================================== --- src/exceptions/OFListenFailedException.m +++ src/exceptions/OFListenFailedException.m @@ -23,20 +23,20 @@ #import "OFTCPSocket.h" #import "common.h" @implementation OFListenFailedException -+ (instancetype)exceptionWithClass: (Class)class_ ++ (instancetype)exceptionWithClass: (Class)class socket: (OFTCPSocket*)socket - backLog: (int)backlog + backLog: (int)backLog { - return [[[self alloc] initWithClass: class_ + return [[[self alloc] initWithClass: class socket: socket - backLog: backlog] autorelease]; + backLog: backLog] autorelease]; } -- initWithClass: (Class)class_ +- initWithClass: (Class)class { @try { [self doesNotRecognizeSelector: _cmd]; } @catch (id e) { [self release]; @@ -44,52 +44,52 @@ } abort(); } -- initWithClass: (Class)class_ - socket: (OFTCPSocket*)socket_ - backLog: (int)backlog -{ - self = [super initWithClass: class_]; - - socket = [socket_ retain]; - backLog = backlog; - errNo = GET_SOCK_ERRNO; +- initWithClass: (Class)class + socket: (OFTCPSocket*)socket + backLog: (int)backLog +{ + self = [super initWithClass: class]; + + _socket = [socket retain]; + _backLog = backLog; + _errNo = GET_SOCK_ERRNO; return self; } - (void)dealloc { - [socket release]; + [_socket release]; [super dealloc]; } - (OFString*)description { - if (description != nil) - return description; + if (_description != nil) + return _description; - description = [[OFString alloc] initWithFormat: + _description = [[OFString alloc] initWithFormat: @"Failed to listen in socket of type %@ with a back log of %d! " - ERRFMT, inClass, backLog, ERRPARAM]; + ERRFMT, _inClass, _backLog, ERRPARAM]; - return description; + return _description; } - (OFTCPSocket*)socket { - OF_GETTER(socket, NO) + OF_GETTER(_socket, NO) } - (int)backLog { - return backLog; + return _backLog; } - (int)errNo { - return errNo; + return _errNo; } @end Index: src/exceptions/OFLockFailedException.h ================================================================== --- src/exceptions/OFLockFailedException.h +++ src/exceptions/OFLockFailedException.h @@ -20,11 +20,11 @@ /*! * @brief An exception indicating that locking a lock failed. */ @interface OFLockFailedException: OFException { - id lock; + id _lock; } #ifdef OF_HAVE_PROPERTIES @property (readonly, retain, nonatomic) id lock; #endif Index: src/exceptions/OFLockFailedException.m ================================================================== --- src/exceptions/OFLockFailedException.m +++ src/exceptions/OFLockFailedException.m @@ -20,46 +20,46 @@ #import "OFString.h" #import "macros.h" @implementation OFLockFailedException -+ (instancetype)exceptionWithClass: (Class)class_ ++ (instancetype)exceptionWithClass: (Class)class lock: (id )lock { - return [[[self alloc] initWithClass: class_ + return [[[self alloc] initWithClass: class lock: lock] autorelease]; } -- initWithClass: (Class)class_ - lock: (id )lock_ +- initWithClass: (Class)class + lock: (id )lock { - self = [super initWithClass: class_]; + self = [super initWithClass: class]; - lock = [lock_ retain]; + _lock = [lock retain]; return self; } - (void)dealloc { - [lock release]; + [_lock release]; [super dealloc]; } - (OFString*)description { - if (description != nil) - return description; + if (_description != nil) + return _description; - description = [[OFString alloc] initWithFormat: + _description = [[OFString alloc] initWithFormat: @"A lock of type %@ could not be locked in class %@!", - [(id)lock className], inClass]; + [_lock class], _inClass]; - return description; + return _description; } - (id )lock { - OF_GETTER(lock, NO) + OF_GETTER(_lock, NO) } @end Index: src/exceptions/OFMalformedXMLException.h ================================================================== --- src/exceptions/OFMalformedXMLException.h +++ src/exceptions/OFMalformedXMLException.h @@ -21,11 +21,11 @@ /*! * @brief An exception indicating that a parser encountered malformed XML. */ @interface OFMalformedXMLException: OFException { - OFXMLParser *parser; + OFXMLParser *_parser; } #ifdef OF_HAVE_PROPERTIES @property (readonly, retain, nonatomic) OFXMLParser *parser; #endif Index: src/exceptions/OFMalformedXMLException.m ================================================================== --- src/exceptions/OFMalformedXMLException.m +++ src/exceptions/OFMalformedXMLException.m @@ -21,49 +21,49 @@ #import "OFXMLParser.h" #import "common.h" @implementation OFMalformedXMLException -+ (instancetype)exceptionWithClass: (Class)class_ ++ (instancetype)exceptionWithClass: (Class)class parser: (OFXMLParser*)parser { - return [[[self alloc] initWithClass: class_ + return [[[self alloc] initWithClass: class parser: parser] autorelease]; } -- initWithClass: (Class)class_ - parser: (OFXMLParser*)parser_ +- initWithClass: (Class)class + parser: (OFXMLParser*)parser { - self = [super initWithClass: class_]; + self = [super initWithClass: class]; - parser = [parser_ retain]; + _parser = [parser retain]; return self; } - (void)dealloc { - [parser release]; + [_parser release]; [super dealloc]; } - (OFString*)description { - if (description != nil) - return description; + if (_description != nil) + return _description; - if (parser != nil) - description = [[OFString alloc] initWithFormat: - @"The parser in class %@ encountered malformed XML!", - inClass]; + if (_parser != nil) + _description = [[OFString alloc] initWithFormat: + @"The XML parser in class %@ encountered malformed XML!", + _inClass]; else - description = @"A parser encountered malformed XML!"; + _description = @"An XML parser encountered malformed XML!"; - return description; + return _description; } - (OFXMLParser*)parser { - OF_GETTER(parser, NO) + OF_GETTER(_parser, NO) } @end Index: src/exceptions/OFMemoryNotPartOfObjectException.h ================================================================== --- src/exceptions/OFMemoryNotPartOfObjectException.h +++ src/exceptions/OFMemoryNotPartOfObjectException.h @@ -19,11 +19,11 @@ /*! * @brief An exception indicating the given memory is not part of the object. */ @interface OFMemoryNotPartOfObjectException: OFException { - void *pointer; + void *_pointer; } #ifdef OF_HAVE_PROPERTIES @property (readonly) void *pointer; #endif @@ -30,28 +30,28 @@ /*! * @brief Creates a new, autoreleased memory not part of object exception. * * @param class_ The class of the object which caused the exception - * @param ptr A pointer to the memory that is not part of the object + * @param pointer A pointer to the memory that is not part of the object * @return A new, autoreleased memory not part of object exception */ + (instancetype)exceptionWithClass: (Class)class_ - pointer: (void*)ptr; + pointer: (void*)pointer; /*! * @brief Initializes an already allocated memory not part of object exception. * * @param class_ The class of the object which caused the exception - * @param ptr A pointer to the memory that is not part of the object + * @param pointer A pointer to the memory that is not part of the object * @return An initialized memory not part of object exception */ - initWithClass: (Class)class_ - pointer: (void*)ptr; + pointer: (void*)pointer; /*! * @brief Returns a pointer to the memory which is not part of the object. * * @return A pointer to the memory which is not part of the object */ - (void*)pointer; @end Index: src/exceptions/OFMemoryNotPartOfObjectException.m ================================================================== --- src/exceptions/OFMemoryNotPartOfObjectException.m +++ src/exceptions/OFMemoryNotPartOfObjectException.m @@ -20,18 +20,18 @@ #import "OFMemoryNotPartOfObjectException.h" #import "OFString.h" @implementation OFMemoryNotPartOfObjectException -+ (instancetype)exceptionWithClass: (Class)class_ - pointer: (void*)ptr ++ (instancetype)exceptionWithClass: (Class)class + pointer: (void*)pointer { - return [[[self alloc] initWithClass: class_ - pointer: ptr] autorelease]; + return [[[self alloc] initWithClass: class + pointer: pointer] autorelease]; } -- initWithClass: (Class)class_ +- initWithClass: (Class)class { @try { [self doesNotRecognizeSelector: _cmd]; } @catch (id e) { [self release]; @@ -39,34 +39,34 @@ } abort(); } -- initWithClass: (Class)class_ - pointer: (void*)ptr +- initWithClass: (Class)class + pointer: (void*)pointer { - self = [super initWithClass: class_]; + self = [super initWithClass: class]; - pointer = ptr; + _pointer = pointer; return self; } - (OFString*)description { - if (description != nil) - return description; + if (_description != nil) + return _description; - description = [[OFString alloc] initWithFormat: + _description = [[OFString alloc] initWithFormat: @"Memory at %p was not allocated as part of object of class %@, " @"thus the memory allocation was not changed! It is also possible " @"that there was an attempt to free the same memory twice.", - pointer, inClass]; + _pointer, _inClass]; - return description; + return _description; } - (void*)pointer { - return pointer; + return _pointer; } @end Index: src/exceptions/OFNotConnectedException.h ================================================================== --- src/exceptions/OFNotConnectedException.h +++ src/exceptions/OFNotConnectedException.h @@ -21,11 +21,11 @@ /*! * @brief An exception indicating a socket is not connected or bound. */ @interface OFNotConnectedException: OFException { - OFStreamSocket *socket; + OFStreamSocket *_socket; } #ifdef OF_HAVE_PROPERTIES @property (readonly, retain, nonatomic) OFStreamSocket *socket; #endif Index: src/exceptions/OFNotConnectedException.m ================================================================== --- src/exceptions/OFNotConnectedException.m +++ src/exceptions/OFNotConnectedException.m @@ -23,18 +23,18 @@ #import "OFTCPSocket.h" #import "common.h" @implementation OFNotConnectedException -+ (instancetype)exceptionWithClass: (Class)class_ ++ (instancetype)exceptionWithClass: (Class)class socket: (OFStreamSocket*)socket { - return [[[self alloc] initWithClass: class_ + return [[[self alloc] initWithClass: class socket: socket] autorelease]; } -- initWithClass: (Class)class_ +- initWithClass: (Class)class { @try { [self doesNotRecognizeSelector: _cmd]; } @catch (id e) { [self release]; @@ -42,38 +42,38 @@ } abort(); } -- initWithClass: (Class)class_ - socket: (OFStreamSocket*)socket_ +- initWithClass: (Class)class + socket: (OFStreamSocket*)socket { - self = [super initWithClass: class_]; + self = [super initWithClass: class]; - socket = [socket_ retain]; + _socket = [socket retain]; return self; } - (void)dealloc { - [socket release]; + [_socket release]; [super dealloc]; } - (OFString*)description { - if (description != nil) - return description; + if (_description != nil) + return _description; - description = [[OFString alloc] initWithFormat: - @"The socket of type %@ is not connected or bound!", inClass]; + _description = [[OFString alloc] initWithFormat: + @"The socket of type %@ is not connected or bound!", _inClass]; - return description; + return _description; } - (OFStreamSocket*)socket { - OF_GETTER(socket, NO) + OF_GETTER(_socket, NO) } @end Index: src/exceptions/OFNotImplementedException.h ================================================================== --- src/exceptions/OFNotImplementedException.h +++ src/exceptions/OFNotImplementedException.h @@ -20,11 +20,11 @@ * @brief An exception indicating that a method or part of it is not * implemented. */ @interface OFNotImplementedException: OFException { - SEL selector; + SEL _selector; } #ifdef OF_HAVE_PROPERTIES @property (readonly) SEL selector; #endif Index: src/exceptions/OFNotImplementedException.m ================================================================== --- src/exceptions/OFNotImplementedException.m +++ src/exceptions/OFNotImplementedException.m @@ -22,18 +22,18 @@ #import "OFString.h" #import "common.h" @implementation OFNotImplementedException -+ (instancetype)exceptionWithClass: (Class)class_ ++ (instancetype)exceptionWithClass: (Class)class selector: (SEL)selector { - return [[[self alloc] initWithClass: class_ + return [[[self alloc] initWithClass: class selector: selector] autorelease]; } -- initWithClass: (Class)class_ +- initWithClass: (Class)class { @try { [self doesNotRecognizeSelector: _cmd]; } @catch (id e) { [self release]; @@ -41,32 +41,32 @@ } abort(); } -- initWithClass: (Class)class_ - selector: (SEL)selector_ +- initWithClass: (Class)class + selector: (SEL)selector { - self = [super initWithClass: class_]; + self = [super initWithClass: class]; - selector = selector_; + _selector = selector; return self; } - (OFString*)description { - if (description != nil) - return description; + if (_description != nil) + return _description; - description = [[OFString alloc] initWithFormat: + _description = [[OFString alloc] initWithFormat: @"The selector %s is not understood by class %@ or not (fully) " - @"implemented!", sel_getName(selector), inClass]; + @"implemented!", sel_getName(_selector), _inClass]; - return description; + return _description; } - (SEL)selector { - return selector; + return _selector; } @end Index: src/exceptions/OFOpenFileFailedException.h ================================================================== --- src/exceptions/OFOpenFileFailedException.h +++ src/exceptions/OFOpenFileFailedException.h @@ -19,18 +19,16 @@ /*! * @brief An exception indicating a file couldn't be opened. */ @interface OFOpenFileFailedException: OFException { - OFString *path; - OFString *mode; - int errNo; + OFString *_path, *_mode; + int _errNo; } #ifdef OF_HAVE_PROPERTIES -@property (readonly, copy, nonatomic) OFString *path; -@property (readonly, copy, nonatomic) OFString *mode; +@property (readonly, copy, nonatomic) OFString *path, *mode; @property (readonly) int errNo; #endif /*! * @brief Creates a new, autoreleased open file failed exception. Index: src/exceptions/OFOpenFileFailedException.m ================================================================== --- src/exceptions/OFOpenFileFailedException.m +++ src/exceptions/OFOpenFileFailedException.m @@ -22,20 +22,20 @@ #import "OFString.h" #import "common.h" @implementation OFOpenFileFailedException -+ (instancetype)exceptionWithClass: (Class)class_ ++ (instancetype)exceptionWithClass: (Class)class path: (OFString*)path mode: (OFString*)mode { - return [[[self alloc] initWithClass: class_ + return [[[self alloc] initWithClass: class path: path mode: mode] autorelease]; } -- initWithClass: (Class)class_ +- initWithClass: (Class)class { @try { [self doesNotRecognizeSelector: _cmd]; } @catch (id e) { [self release]; @@ -43,20 +43,20 @@ } abort(); } -- initWithClass: (Class)class_ - path: (OFString*)path_ - mode: (OFString*)mode_ +- initWithClass: (Class)class + path: (OFString*)path + mode: (OFString*)mode { - self = [super initWithClass: class_]; + self = [super initWithClass: class]; @try { - path = [path_ copy]; - mode = [mode_ copy]; - errNo = GET_ERRNO; + _path = [path copy]; + _mode = [mode copy]; + _errNo = GET_ERRNO; } @catch (id e) { [self release]; @throw e; } @@ -63,38 +63,38 @@ return self; } - (void)dealloc { - [path release]; - [mode release]; + [_path release]; + [_mode release]; [super dealloc]; } - (OFString*)description { - if (description != nil) - return description; - - description = [[OFString alloc] initWithFormat: - @"Failed to open file %@ with mode %@ in class %@! " ERRFMT, path, - mode, inClass, ERRPARAM]; - - return description; + if (_description != nil) + return _description; + + _description = [[OFString alloc] initWithFormat: + @"Failed to open file %@ with mode %@ in class %@! " ERRFMT, _path, + _mode, _inClass, ERRPARAM]; + + return _description; } - (int)errNo { - return errNo; + return _errNo; } - (OFString*)path { - OF_GETTER(path, NO) + OF_GETTER(_path, NO) } - (OFString*)mode { - OF_GETTER(mode, NO) + OF_GETTER(_mode, NO) } @end Index: src/exceptions/OFOutOfMemoryException.h ================================================================== --- src/exceptions/OFOutOfMemoryException.h +++ src/exceptions/OFOutOfMemoryException.h @@ -19,11 +19,11 @@ /*! * @brief An exception indicating there is not enough memory available. */ @interface OFOutOfMemoryException: OFException { - size_t requestedSize; + size_t _requestedSize; } #ifdef OF_HAVE_PROPERTIES @property (readonly) size_t requestedSize; #endif @@ -30,28 +30,28 @@ /*! * @brief Creates a new, autoreleased no memory exception. * * @param class_ The class of the object which caused the exception - * @param size The size of the memory that couldn't be allocated + * @param requestedSize The size of the memory that couldn't be allocated * @return A new, autoreleased no memory exception */ + (instancetype)exceptionWithClass: (Class)class_ - requestedSize: (size_t)size; + requestedSize: (size_t)requestedSize; /*! * @brief Initializes an already allocated no memory exception. * * @param class_ The class of the object which caused the exception - * @param size The size of the memory that couldn't be allocated + * @param requestedSize The size of the memory that couldn't be allocated * @return An initialized no memory exception */ - initWithClass: (Class)class_ - requestedSize: (size_t)size; + requestedSize: (size_t)requestedSize; /*! * @brief Returns the size of the memoory that couldn't be allocated. * * @return The size of the memoory that couldn't be allocated */ - (size_t)requestedSize; @end Index: src/exceptions/OFOutOfMemoryException.m ================================================================== --- src/exceptions/OFOutOfMemoryException.m +++ src/exceptions/OFOutOfMemoryException.m @@ -18,43 +18,43 @@ #import "OFOutOfMemoryException.h" #import "OFString.h" @implementation OFOutOfMemoryException -+ (instancetype)exceptionWithClass: (Class)class_ - requestedSize: (size_t)size ++ (instancetype)exceptionWithClass: (Class)class + requestedSize: (size_t)requestedSize { - return [[[self alloc] initWithClass: class_ - requestedSize: size] autorelease]; + return [[[self alloc] initWithClass: class + requestedSize: requestedSize] autorelease]; } -- initWithClass: (Class)class_ - requestedSize: (size_t)size +- initWithClass: (Class)class + requestedSize: (size_t)requestedSize { - self = [super initWithClass: class_]; + self = [super initWithClass: class]; - requestedSize = size; + _requestedSize = requestedSize; return self; } - (OFString*)description { - if (description != nil) - return description; + if (_description != nil) + return _description; - if (requestedSize != 0) - description = [[OFString alloc] initWithFormat: - @"Could not allocate %zu bytes in class %@!", requestedSize, - inClass]; + if (_requestedSize != 0) + _description = [[OFString alloc] initWithFormat: + @"Could not allocate %zu bytes in class %@!", + _requestedSize, _inClass]; else - description = [[OFString alloc] initWithFormat: - @"Could not allocate enough memory in class %@!", inClass]; + _description = [[OFString alloc] initWithFormat: + @"Could not allocate enough memory in class %@!", _inClass]; - return description; + return _description; } - (size_t)requestedSize { - return requestedSize; + return _requestedSize; } @end Index: src/exceptions/OFOutOfRangeException.m ================================================================== --- src/exceptions/OFOutOfRangeException.m +++ src/exceptions/OFOutOfRangeException.m @@ -20,14 +20,14 @@ #import "OFString.h" @implementation OFOutOfRangeException - (OFString*)description { - if (description != nil) - return description; + if (_description != nil) + return _description; - description = [[OFString alloc] initWithFormat: - @"Value out of range in class %@!", inClass]; + _description = [[OFString alloc] initWithFormat: + @"Value out of range in class %@!", _inClass]; - return description; + return _description; } @end Index: src/exceptions/OFReadFailedException.m ================================================================== --- src/exceptions/OFReadFailedException.m +++ src/exceptions/OFReadFailedException.m @@ -22,15 +22,15 @@ #import "common.h" @implementation OFReadFailedException - (OFString*)description { - if (description != nil) - return description; - - description = [[OFString alloc] initWithFormat: - @"Failed to read %zu bytes in class %@! " ERRFMT, requestedLength, - inClass, ERRPARAM]; - - return description; + if (_description != nil) + return _description; + + _description = [[OFString alloc] initWithFormat: + @"Failed to read %zu bytes in class %@! " ERRFMT, _requestedLength, + _inClass, ERRPARAM]; + + return _description; } @end Index: src/exceptions/OFReadOrWriteFailedException.h ================================================================== --- src/exceptions/OFReadOrWriteFailedException.h +++ src/exceptions/OFReadOrWriteFailedException.h @@ -21,14 +21,14 @@ /*! * @brief An exception indicating a read or write to a stream failed. */ @interface OFReadOrWriteFailedException: OFException { - OFStream *stream; - size_t requestedLength; + OFStream *_stream; + size_t _requestedLength; @public - int errNo; + int _errNo; } #ifdef OF_HAVE_PROPERTIES @property (readonly, retain, nonatomic) OFStream *stream; @property (readonly) size_t requestedLength; @@ -38,30 +38,30 @@ /*! * @brief Creates a new, autoreleased read or write failed exception. * * @param class_ The class of the object which caused the exception * @param stream The stream which caused the read or write failed exception - * @param length The requested length of the data that couldn't be read / - * written + * @param requestedLength The requested length of the data that couldn't be + * read / written * @return A new, autoreleased read or write failed exception */ + (instancetype)exceptionWithClass: (Class)class_ stream: (OFStream*)stream - requestedLength: (size_t)length; + requestedLength: (size_t)requestedLength; /*! * @brief Initializes an already allocated read or write failed exception. * * @param class_ The class of the object which caused the exception * @param stream The stream which caused the read or write failed exception - * @param length The requested length of the data that couldn't be read / - * written + * @param requestedLength The requested length of the data that couldn't be + * read / written * @return A new open file failed exception */ - initWithClass: (Class)class_ stream: (OFStream*)stream - requestedLength: (size_t)length; + requestedLength: (size_t)requestedLength; /*! * @brief Returns the stream which caused the read or write failed exception. * * @return The stream which caused the read or write failed exception Index: src/exceptions/OFReadOrWriteFailedException.m ================================================================== --- src/exceptions/OFReadOrWriteFailedException.m +++ src/exceptions/OFReadOrWriteFailedException.m @@ -23,20 +23,20 @@ #import "OFStreamSocket.h" #import "common.h" @implementation OFReadOrWriteFailedException -+ (instancetype)exceptionWithClass: (Class)class_ ++ (instancetype)exceptionWithClass: (Class)class stream: (OFStream*)stream - requestedLength: (size_t)length + requestedLength: (size_t)requestedLength { - return [[[self alloc] initWithClass: class_ + return [[[self alloc] initWithClass: class stream: stream - requestedLength: length] autorelease]; + requestedLength: requestedLength] autorelease]; } -- initWithClass: (Class)class_ +- initWithClass: (Class)class { @try { [self doesNotRecognizeSelector: _cmd]; } @catch (id e) { [self release]; @@ -44,44 +44,44 @@ } abort(); } -- initWithClass: (Class)class_ - stream: (OFStream*)stream_ - requestedLength: (size_t)length -{ - self = [super initWithClass: class_]; - - stream = [stream_ retain]; - requestedLength = length; - - if ([class_ isSubclassOfClass: [OFStreamSocket class]]) - errNo = GET_SOCK_ERRNO; - else - errNo = GET_ERRNO; +- initWithClass: (Class)class + stream: (OFStream*)stream + requestedLength: (size_t)requestedLength +{ + self = [super initWithClass: class]; + + _stream = [stream retain]; + _requestedLength = requestedLength; + + if ([class isSubclassOfClass: [OFStreamSocket class]]) + _errNo = GET_SOCK_ERRNO; + else + _errNo = GET_ERRNO; return self; } - (void)dealloc { - [stream release]; + [_stream release]; [super dealloc]; } - (OFStream*)stream { - OF_GETTER(stream, NO) + OF_GETTER(_stream, NO) } - (size_t)requestedLength { - return requestedLength; + return _requestedLength; } - (int)errNo { - return errNo; + return _errNo; } @end Index: src/exceptions/OFRenameFileFailedException.h ================================================================== --- src/exceptions/OFRenameFileFailedException.h +++ src/exceptions/OFRenameFileFailedException.h @@ -19,44 +19,42 @@ /*! * @brief An exception indicating that renaming a file failed. */ @interface OFRenameFileFailedException: OFException { - OFString *sourcePath; - OFString *destinationPath; - int errNo; + OFString *_sourcePath, *_destinationPath; + int _errNo; } #ifdef OF_HAVE_PROPERTIES -@property (readonly, copy, nonatomic) OFString *sourcePath; -@property (readonly, copy, nonatomic) OFString *destinationPath; +@property (readonly, copy, nonatomic) OFString *sourcePath, *destinationPath; @property (readonly) int errNo; #endif /*! * @brief Creates a new, autoreleased rename file failed exception. * * @param class_ The class of the object which caused the exception - * @param source The original path - * @param destination The new path + * @param sourcePath The original path + * @param destinationPath The new path * @return A new, autoreleased rename file failed exception */ + (instancetype)exceptionWithClass: (Class)class_ - sourcePath: (OFString*)source - destinationPath: (OFString*)destination; + sourcePath: (OFString*)sourcePath + destinationPath: (OFString*)destinationPath; /*! * @brief Initializes an already allocated rename failed exception. * * @param class_ The class of the object which caused the exception - * @param source The original path - * @param destination The new path + * @param sourcePath The original path + * @param destinationPath The new path * @return An initialized rename file failed exception */ - initWithClass: (Class)class_ - sourcePath: (OFString*)source - destinationPath: (OFString*)destination; + sourcePath: (OFString*)sourcePath + destinationPath: (OFString*)destinationPath; /*! * @brief Returns the errno from when the exception was created. * * @return The errno from when the exception was created Index: src/exceptions/OFRenameFileFailedException.m ================================================================== --- src/exceptions/OFRenameFileFailedException.m +++ src/exceptions/OFRenameFileFailedException.m @@ -22,20 +22,20 @@ #import "OFString.h" #import "common.h" @implementation OFRenameFileFailedException -+ (instancetype)exceptionWithClass: (Class)class_ - sourcePath: (OFString*)source - destinationPath: (OFString*)destination ++ (instancetype)exceptionWithClass: (Class)class + sourcePath: (OFString*)sourcePath + destinationPath: (OFString*)destinationPath { - return [[[self alloc] initWithClass: class_ - sourcePath: source - destinationPath: destination] autorelease]; + return [[[self alloc] initWithClass: class + sourcePath: sourcePath + destinationPath: destinationPath] autorelease]; } -- initWithClass: (Class)class_ +- initWithClass: (Class)class { @try { [self doesNotRecognizeSelector: _cmd]; } @catch (id e) { [self release]; @@ -43,20 +43,20 @@ } abort(); } -- initWithClass: (Class)class_ - sourcePath: (OFString*)source - destinationPath: (OFString*)destination +- initWithClass: (Class)class + sourcePath: (OFString*)sourcePath + destinationPath: (OFString*)destinationPath { - self = [super initWithClass: class_]; + self = [super initWithClass: class]; @try { - sourcePath = [source copy]; - destinationPath = [destination copy]; - errNo = GET_ERRNO; + _sourcePath = [sourcePath copy]; + _destinationPath = [destinationPath copy]; + _errNo = GET_ERRNO; } @catch (id e) { [self release]; @throw e; } @@ -63,38 +63,38 @@ return self; } - (void)dealloc { - [sourcePath release]; - [destinationPath release]; + [_sourcePath release]; + [_destinationPath release]; [super dealloc]; } - (OFString*)description { - if (description != nil) - return description; - - description = [[OFString alloc] initWithFormat: - @"Failed to rename file %@ to %@ in class %@! " ERRFMT, sourcePath, - destinationPath, inClass, ERRPARAM]; - - return description; + if (_description != nil) + return _description; + + _description = [[OFString alloc] initWithFormat: + @"Failed to rename file %@ to %@ in class %@! " ERRFMT, + _sourcePath, _destinationPath, _inClass, ERRPARAM]; + + return _description; } - (int)errNo { - return errNo; + return _errNo; } - (OFString*)sourcePath { - OF_GETTER(sourcePath, NO) + OF_GETTER(_sourcePath, NO) } - (OFString*)destinationPath { - OF_GETTER(destinationPath, NO) + OF_GETTER(_destinationPath, NO) } @end Index: src/exceptions/OFSeekFailedException.h ================================================================== --- src/exceptions/OFSeekFailedException.h +++ src/exceptions/OFSeekFailedException.h @@ -23,21 +23,19 @@ /*! * @brief An exception indicating that seeking in a stream failed. */ @interface OFSeekFailedException: OFException { - OFSeekableStream *stream; - off_t offset; - int whence; - int errNo; + OFSeekableStream *_stream; + off_t _offset; + int _whence, _errNo; } #ifdef OF_HAVE_PROPERTIES @property (readonly, retain, nonatomic) OFSeekableStream *stream; @property (readonly) off_t offset; -@property (readonly) int whence; -@property (readonly) int errNo; +@property (readonly) int whence, errNo; #endif /*! * @brief Creates a new, autoreleased seek failed exception. * Index: src/exceptions/OFSeekFailedException.m ================================================================== --- src/exceptions/OFSeekFailedException.m +++ src/exceptions/OFSeekFailedException.m @@ -23,22 +23,22 @@ #import "OFSeekableStream.h" #import "common.h" @implementation OFSeekFailedException -+ (instancetype)exceptionWithClass: (Class)class_ ++ (instancetype)exceptionWithClass: (Class)class stream: (OFSeekableStream*)stream offset: (off_t)offset whence: (int)whence { - return [[[self alloc] initWithClass: class_ + return [[[self alloc] initWithClass: class stream: stream offset: offset whence: whence] autorelease]; } -- initWithClass: (Class)class_ +- initWithClass: (Class)class { @try { [self doesNotRecognizeSelector: _cmd]; } @catch (id e) { [self release]; @@ -46,58 +46,58 @@ } abort(); } -- initWithClass: (Class)class_ - stream: (OFSeekableStream*)stream_ - offset: (off_t)offset_ - whence: (int)whence_ -{ - self = [super initWithClass: class_]; - - stream = [stream_ retain]; - offset = offset_; - whence = whence_; - errNo = GET_ERRNO; +- initWithClass: (Class)class + stream: (OFSeekableStream*)stream + offset: (off_t)offset + whence: (int)whence +{ + self = [super initWithClass: class]; + + _stream = [stream retain]; + _offset = offset; + _whence = whence; + _errNo = GET_ERRNO; return self; } - (void)dealloc { - [stream release]; + [_stream release]; [super dealloc]; } - (OFString*)description { - if (description != nil) - return description; + if (_description != nil) + return _description; - description = [[OFString alloc] initWithFormat: - @"Seeking failed in class %@! " ERRFMT, inClass, ERRPARAM]; + _description = [[OFString alloc] initWithFormat: + @"Seeking failed in class %@! " ERRFMT, _inClass, ERRPARAM]; - return description; + return _description; } - (OFSeekableStream*)stream { - OF_GETTER(stream, NO) + OF_GETTER(_stream, NO) } - (off_t)offset { - return offset; + return _offset; } - (int)whence { - return whence; + return _whence; } - (int)errNo { - return errNo; + return _errNo; } @end Index: src/exceptions/OFSetOptionFailedException.h ================================================================== --- src/exceptions/OFSetOptionFailedException.h +++ src/exceptions/OFSetOptionFailedException.h @@ -21,11 +21,11 @@ /*! * @brief An exception indicating that setting an option for a stream failed. */ @interface OFSetOptionFailedException: OFException { - OFStream *stream; + OFStream *_stream; } #ifdef OF_HAVE_PROPERTIES @property (readonly, retain, nonatomic) OFStream *stream; #endif Index: src/exceptions/OFSetOptionFailedException.m ================================================================== --- src/exceptions/OFSetOptionFailedException.m +++ src/exceptions/OFSetOptionFailedException.m @@ -23,18 +23,18 @@ #import "OFStream.h" #import "common.h" @implementation OFSetOptionFailedException -+ (instancetype)exceptionWithClass: (Class)class_ ++ (instancetype)exceptionWithClass: (Class)class stream: (OFStream*)stream { - return [[[self alloc] initWithClass: class_ + return [[[self alloc] initWithClass: class stream: stream] autorelease]; } -- initWithClass: (Class)class_ +- initWithClass: (Class)class { @try { [self doesNotRecognizeSelector: _cmd]; } @catch (id e) { [self release]; @@ -42,38 +42,38 @@ } abort(); } -- initWithClass: (Class)class_ - stream: (OFStream*)stream_ +- initWithClass: (Class)class + stream: (OFStream*)stream { - self = [super initWithClass: class_]; + self = [super initWithClass: class]; - stream = [stream_ retain]; + _stream = [stream retain]; return self; } - (void)dealloc { - [stream release]; + [_stream release]; [super dealloc]; } - (OFString*)description { - if (description != nil) - return description; + if (_description != nil) + return _description; - description = [[OFString alloc] initWithFormat: - @"Setting an option in class %@ failed!", inClass]; + _description = [[OFString alloc] initWithFormat: + @"Setting an option in class %@ failed!", _inClass]; - return description; + return _description; } - (OFStream*)stream { - OF_GETTER(stream, NO) + OF_GETTER(_stream, NO) } @end Index: src/exceptions/OFStillLockedException.h ================================================================== --- src/exceptions/OFStillLockedException.h +++ src/exceptions/OFStillLockedException.h @@ -20,11 +20,11 @@ /*! * @brief An exception indicating that a lock is still locked. */ @interface OFStillLockedException: OFException { - id lock; + id _lock; } #ifdef OF_HAVE_PROPERTIES @property (readonly, retain, nonatomic) id lock; #endif Index: src/exceptions/OFStillLockedException.m ================================================================== --- src/exceptions/OFStillLockedException.m +++ src/exceptions/OFStillLockedException.m @@ -20,46 +20,46 @@ #import "OFString.h" #import "macros.h" @implementation OFStillLockedException -+ (instancetype)exceptionWithClass: (Class)class_ ++ (instancetype)exceptionWithClass: (Class)class lock: (id )lock { - return [[[self alloc] initWithClass: class_ + return [[[self alloc] initWithClass: class lock: lock] autorelease]; } -- initWithClass: (Class)class_ - lock: (id )lock_ +- initWithClass: (Class)class + lock: (id )lock { - self = [super initWithClass: class_]; + self = [super initWithClass: class]; - lock = [lock_ retain]; + _lock = [lock retain]; return self; } - (void)dealloc { - [lock release]; + [_lock release]; [super dealloc]; } - (OFString*)description { - if (description != nil) - return description; + if (_description != nil) + return _description; - description = [[OFString alloc] initWithFormat: + _description = [[OFString alloc] initWithFormat: @"Deallocation of a lock of type %@ was tried in class %@, even " - @"though it was still locked!", [(id)lock className], inClass]; + @"though it was still locked!", [_lock class], _inClass]; - return description; + return _description; } - (id )lock { - OF_GETTER(lock, NO) + OF_GETTER(_lock, NO) } @end Index: src/exceptions/OFSymlinkFailedException.h ================================================================== --- src/exceptions/OFSymlinkFailedException.h +++ src/exceptions/OFSymlinkFailedException.h @@ -20,44 +20,42 @@ /*! * @brief An exception indicating that creating a symlink failed. */ @interface OFSymlinkFailedException: OFException { - OFString *sourcePath; - OFString *destinationPath; - int errNo; + OFString *_sourcePath, *_destinationPath; + int _errNo; } #ifdef OF_HAVE_PROPERTIES -@property (readonly, copy, nonatomic) OFString *sourcePath; -@property (readonly, copy, nonatomic) OFString *destinationPath; +@property (readonly, copy, nonatomic) OFString *sourcePath, *destinationPath; @property (readonly) int errNo; #endif /*! * @brief Creates a new, autoreleased symlink failed exception. * * @param class_ The class of the object which caused the exception - * @param source The source for the symlink - * @param destination The destination for the symlink + * @param sourcePath The source for the symlink + * @param destinationPath The destination for the symlink * @return A new, autoreleased symlink failed exception */ + (instancetype)exceptionWithClass: (Class)class_ - sourcePath: (OFString*)source - destinationPath: (OFString*)destination; + sourcePath: (OFString*)sourcePath + destinationPath: (OFString*)destinationPath; /*! * @brief Initializes an already allocated symlink failed exception. * * @param class_ The class of the object which caused the exception - * @param source The source for the symlink - * @param destination The destination for the symlink + * @param sourcePath The source for the symlink + * @param destinationPath The destination for the symlink * @return An initialized symlink failed exception */ - initWithClass: (Class)class_ - sourcePath: (OFString*)source - destinationPath: (OFString*)destination; + sourcePath: (OFString*)sourcePath + destinationPath: (OFString*)destinationPath; /*! * @brief Returns the errno from when the exception was created. * * @return The errno from when the exception was created Index: src/exceptions/OFSymlinkFailedException.m ================================================================== --- src/exceptions/OFSymlinkFailedException.m +++ src/exceptions/OFSymlinkFailedException.m @@ -23,20 +23,20 @@ #import "common.h" #ifndef _WIN32 @implementation OFSymlinkFailedException -+ (instancetype)exceptionWithClass: (Class)class_ - sourcePath: (OFString*)source - destinationPath: (OFString*)destination ++ (instancetype)exceptionWithClass: (Class)class + sourcePath: (OFString*)sourcePath + destinationPath: (OFString*)destinationPath { - return [[[self alloc] initWithClass: class_ - sourcePath: source - destinationPath: destination] autorelease]; + return [[[self alloc] initWithClass: class + sourcePath: sourcePath + destinationPath: destinationPath] autorelease]; } -- initWithClass: (Class)class_ +- initWithClass: (Class)class { @try { [self doesNotRecognizeSelector: _cmd]; } @catch (id e) { [self release]; @@ -44,20 +44,20 @@ } abort(); } -- initWithClass: (Class)class_ - sourcePath: (OFString*)source - destinationPath: (OFString*)destination +- initWithClass: (Class)class + sourcePath: (OFString*)sourcePath + destinationPath: (OFString*)destinationPath { - self = [super initWithClass: class_]; + self = [super initWithClass: class]; @try { - sourcePath = [source copy]; - destinationPath = [destination copy]; - errNo = GET_ERRNO; + _sourcePath = [sourcePath copy]; + _destinationPath = [destinationPath copy]; + _errNo = GET_ERRNO; } @catch (id e) { [self release]; @throw e; } @@ -64,39 +64,39 @@ return self; } - (void)dealloc { - [sourcePath release]; - [destinationPath release]; + [_sourcePath release]; + [_destinationPath release]; [super dealloc]; } - (OFString*)description { - if (description != nil) - return description; - - description = [[OFString alloc] initWithFormat: - @"Failed to symlink file %@ to %@ in class %@! " ERRFMT, sourcePath, - destinationPath, inClass, ERRPARAM]; - - return description; + if (_description != nil) + return _description; + + _description = [[OFString alloc] initWithFormat: + @"Failed to symlink file %@ to %@ in class %@! " ERRFMT, + _sourcePath, _destinationPath, _inClass, ERRPARAM]; + + return _description; } - (int)errNo { - return errNo; + return _errNo; } - (OFString*)sourcePath { - OF_GETTER(sourcePath, NO) + OF_GETTER(_sourcePath, NO) } - (OFString*)destinationPath { - OF_GETTER(destinationPath, NO) + OF_GETTER(_destinationPath, NO) } @end #endif Index: src/exceptions/OFThreadJoinFailedException.h ================================================================== --- src/exceptions/OFThreadJoinFailedException.h +++ src/exceptions/OFThreadJoinFailedException.h @@ -21,11 +21,11 @@ /*! * @brief An exception indicating that joining a thread failed. */ @interface OFThreadJoinFailedException: OFException { - OFThread *thread; + OFThread *_thread; } #ifdef OF_HAVE_PROPERTIES @property (readonly, retain, nonatomic) OFThread *thread; #endif Index: src/exceptions/OFThreadJoinFailedException.m ================================================================== --- src/exceptions/OFThreadJoinFailedException.m +++ src/exceptions/OFThreadJoinFailedException.m @@ -21,18 +21,18 @@ #import "OFThreadJoinFailedException.h" #import "OFString.h" #import "OFThread.h" @implementation OFThreadJoinFailedException -+ (instancetype)exceptionWithClass: (Class)class_ ++ (instancetype)exceptionWithClass: (Class)class thread: (OFThread*)thread { - return [[[self alloc] initWithClass: class_ + return [[[self alloc] initWithClass: class thread: thread] autorelease]; } -- initWithClass: (Class)class_ +- initWithClass: (Class)class { @try { [self doesNotRecognizeSelector: _cmd]; } @catch (id e) { [self release]; @@ -40,39 +40,39 @@ } abort(); } -- initWithClass: (Class)class_ - thread: (OFThread*)thread_ +- initWithClass: (Class)class + thread: (OFThread*)thread { - self = [super initWithClass: class_]; + self = [super initWithClass: class]; - thread = [thread_ retain]; + _thread = [thread retain]; return self; } - (void)dealloc { - [thread release]; + [_thread release]; [super dealloc]; } - (OFString*)description { - if (description != nil) - return description; + if (_description != nil) + return _description; - description = [[OFString alloc] initWithFormat: + _description = [[OFString alloc] initWithFormat: @"Joining a thread of class %@ failed! Most likely, another thread " - @"already waits for the thread to join.", inClass]; + @"already waits for the thread to join.", _inClass]; - return description; + return _description; } - (OFThread*)thread { - OF_GETTER(thread, NO) + OF_GETTER(_thread, NO) } @end Index: src/exceptions/OFThreadStartFailedException.h ================================================================== --- src/exceptions/OFThreadStartFailedException.h +++ src/exceptions/OFThreadStartFailedException.h @@ -21,11 +21,11 @@ /*! * @brief An exception indicating that starting a thread failed. */ @interface OFThreadStartFailedException: OFException { - OFThread *thread; + OFThread *_thread; } #ifdef OF_HAVE_PROPERTIES @property (readonly, retain, nonatomic) OFThread *thread; #endif Index: src/exceptions/OFThreadStartFailedException.m ================================================================== --- src/exceptions/OFThreadStartFailedException.m +++ src/exceptions/OFThreadStartFailedException.m @@ -21,18 +21,18 @@ #import "OFThreadStartFailedException.h" #import "OFString.h" #import "OFThread.h" @implementation OFThreadStartFailedException -+ (instancetype)exceptionWithClass: (Class)class_ ++ (instancetype)exceptionWithClass: (Class)class thread: (OFThread*)thread { - return [[[self alloc] initWithClass: class_ + return [[[self alloc] initWithClass: class thread: thread] autorelease]; } -- initWithClass: (Class)class_ +- initWithClass: (Class)class { @try { [self doesNotRecognizeSelector: _cmd]; } @catch (id e) { [self release]; @@ -40,38 +40,38 @@ } abort(); } -- initWithClass: (Class)class_ - thread: (OFThread*)thread_ +- initWithClass: (Class)class + thread: (OFThread*)thread { - self = [super initWithClass: class_]; + self = [super initWithClass: class]; - thread = [thread_ retain]; + _thread = [thread retain]; return self; } - (void)dealloc { - [thread release]; + [_thread release]; [super dealloc]; } - (OFString*)description { - if (description != nil) - return description; + if (_description != nil) + return _description; - description = [[OFString alloc] initWithFormat: - @"Starting a thread of class %@ failed!", inClass]; + _description = [[OFString alloc] initWithFormat: + @"Starting a thread of class %@ failed!", _inClass]; - return description; + return _description; } - (OFThread*)thread { - OF_GETTER(thread, NO) + OF_GETTER(_thread, NO) } @end Index: src/exceptions/OFThreadStillRunningException.h ================================================================== --- src/exceptions/OFThreadStillRunningException.h +++ src/exceptions/OFThreadStillRunningException.h @@ -21,11 +21,11 @@ /*! * @brief An exception indicating that a thread is still running. */ @interface OFThreadStillRunningException: OFException { - OFThread *thread; + OFThread *_thread; } #ifdef OF_HAVE_PROPERTIES @property (readonly, retain, nonatomic) OFThread *thread; #endif Index: src/exceptions/OFThreadStillRunningException.m ================================================================== --- src/exceptions/OFThreadStillRunningException.m +++ src/exceptions/OFThreadStillRunningException.m @@ -21,18 +21,18 @@ #import "OFThreadStillRunningException.h" #import "OFString.h" #import "OFThread.h" @implementation OFThreadStillRunningException -+ (instancetype)exceptionWithClass: (Class)class_ ++ (instancetype)exceptionWithClass: (Class)class thread: (OFThread*)thread { - return [[[self alloc] initWithClass: class_ + return [[[self alloc] initWithClass: class thread: thread] autorelease]; } -- initWithClass: (Class)class_ +- initWithClass: (Class)class { @try { [self doesNotRecognizeSelector: _cmd]; } @catch (id e) { [self release]; @@ -40,39 +40,39 @@ } abort(); } -- initWithClass: (Class)class_ - thread: (OFThread*)thread_ +- initWithClass: (Class)class + thread: (OFThread*)thread { - self = [super initWithClass: class_]; + self = [super initWithClass: class]; - thread = [thread_ retain]; + _thread = [thread retain]; return self; } - (void)dealloc { - [thread release]; + [_thread release]; [super dealloc]; } - (OFString*)description { - if (description != nil) - return description; + if (_description != nil) + return _description; - description = [[OFString alloc] initWithFormat: + _description = [[OFString alloc] initWithFormat: @"Deallocation of a thread of type %@ was tried, even though it " - @"was still running!", inClass]; + @"was still running!", _inClass]; - return description; + return _description; } - (OFThread*)thread { - OF_GETTER(thread, NO) + OF_GETTER(_thread, NO) } @end Index: src/exceptions/OFTruncatedDataException.m ================================================================== --- src/exceptions/OFTruncatedDataException.m +++ src/exceptions/OFTruncatedDataException.m @@ -20,15 +20,15 @@ #import "OFString.h" @implementation OFTruncatedDataException - (OFString*)description { - if (description != nil) - return description; + if (_description != nil) + return _description; - description = [[OFString alloc] initWithFormat: + _description = [[OFString alloc] initWithFormat: @"Truncated data was received or produced in class %@ while it " - @"should not have been truncated!", inClass]; + @"should not have been truncated!", _inClass]; - return description; + return _description; } @end Index: src/exceptions/OFUnboundNamespaceException.h ================================================================== --- src/exceptions/OFUnboundNamespaceException.h +++ src/exceptions/OFUnboundNamespaceException.h @@ -19,28 +19,26 @@ /*! * @brief An exception indicating an attempt to use an unbound namespace. */ @interface OFUnboundNamespaceException: OFException { - OFString *ns; - OFString *prefix; + OFString *_namespace, *_prefix; } #ifdef OF_HAVE_PROPERTIES -@property (readonly, copy, nonatomic, getter=namespace) OFString *ns; -@property (readonly, copy, nonatomic) OFString *prefix; +@property (readonly, copy, nonatomic) OFString *namespace, *prefix; #endif /*! * @brief Creates a new, autoreleased unbound namespace exception. * * @param class_ The class of the object which caused the exception - * @param ns The namespace which is unbound + * @param namespace The namespace which is unbound * @return A new, autoreleased unbound namespace exception */ + (instancetype)exceptionWithClass: (Class)class_ - namespace: (OFString*)ns; + namespace: (OFString*)namespace; /*! * @brief Creates a new, autoreleased unbound namespace exception. * * @param class_ The class of the object which caused the exception @@ -52,15 +50,15 @@ /*! * @brief Initializes an already allocated unbound namespace exception. * * @param class_ The class of the object which caused the exception - * @param ns The namespace which is unbound + * @param namespace The namespace which is unbound * @return An initialized unbound namespace exception */ - initWithClass: (Class)class_ - namespace: (OFString*)ns; + namespace: (OFString*)namespace; /*! * @brief Initializes an already allocated unbound namespace exception. * * @param class_ The class of the object which caused the exception Index: src/exceptions/OFUnboundNamespaceException.m ================================================================== --- src/exceptions/OFUnboundNamespaceException.m +++ src/exceptions/OFUnboundNamespaceException.m @@ -22,25 +22,25 @@ #import "OFString.h" #import "common.h" @implementation OFUnboundNamespaceException -+ (instancetype)exceptionWithClass: (Class)class_ - namespace: (OFString*)ns ++ (instancetype)exceptionWithClass: (Class)class + namespace: (OFString*)namespace { - return [[[self alloc] initWithClass: class_ - namespace: ns] autorelease]; + return [[[self alloc] initWithClass: class + namespace: namespace] autorelease]; } -+ (instancetype)exceptionWithClass: (Class)class_ ++ (instancetype)exceptionWithClass: (Class)class prefix: (OFString*)prefix { - return [[[self alloc] initWithClass: class_ + return [[[self alloc] initWithClass: class prefix: prefix] autorelease]; } -- initWithClass: (Class)class_ +- initWithClass: (Class)class { @try { [self doesNotRecognizeSelector: _cmd]; } @catch (id e) { [self release]; @@ -48,32 +48,32 @@ } abort(); } -- initWithClass: (Class)class_ - namespace: (OFString*)ns_ +- initWithClass: (Class)class + namespace: (OFString*)namespace { - self = [super initWithClass: class_]; + self = [super initWithClass: class]; @try { - ns = [ns_ copy]; + _namespace = [namespace copy]; } @catch (id e) { [self release]; @throw e; } return self; } -- initWithClass: (Class)class_ - prefix: (OFString*)prefix_ +- initWithClass: (Class)class + prefix: (OFString*)prefix { - self = [super initWithClass: class_]; + self = [super initWithClass: class]; @try { - prefix = [prefix_ copy]; + _prefix = [prefix copy]; } @catch (id e) { [self release]; @throw e; } @@ -80,37 +80,38 @@ return self; } - (void)dealloc { - [ns release]; - [prefix release]; + [_namespace release]; + [_prefix release]; [super dealloc]; } - (OFString*)description { - if (description != nil) - return description; - - if (ns != nil) - description = [[OFString alloc] initWithFormat: - @"The namespace %@ is not bound in class %@", ns, inClass]; - else if (prefix != nil) - description = [[OFString alloc] initWithFormat: + if (_description != nil) + return _description; + + if (_namespace != nil) + _description = [[OFString alloc] initWithFormat: + @"The namespace %@ is not bound in class %@", _namespace, + _inClass]; + else if (_prefix != nil) + _description = [[OFString alloc] initWithFormat: @"The prefix %@ is not bound to any namespace in class %@", - prefix, inClass]; + _prefix, _inClass]; - return description; + return _description; } - (OFString*)namespace { - OF_GETTER(ns, NO) + OF_GETTER(_namespace, NO) } - (OFString*)prefix { - OF_GETTER(prefix, NO) + OF_GETTER(_prefix, NO) } @end Index: src/exceptions/OFUnlockFailedException.h ================================================================== --- src/exceptions/OFUnlockFailedException.h +++ src/exceptions/OFUnlockFailedException.h @@ -20,11 +20,11 @@ /*! * @brief An exception indicating that unlocking a lock failed. */ @interface OFUnlockFailedException: OFException { - id lock; + id _lock; } #ifdef OF_HAVE_PROPERTIES @property (readonly, retain, nonatomic) id lock; #endif Index: src/exceptions/OFUnlockFailedException.m ================================================================== --- src/exceptions/OFUnlockFailedException.m +++ src/exceptions/OFUnlockFailedException.m @@ -20,46 +20,46 @@ #import "OFString.h" #import "macros.h" @implementation OFUnlockFailedException -+ (instancetype)exceptionWithClass: (Class)class_ ++ (instancetype)exceptionWithClass: (Class)class lock: (id )lock { - return [[[self alloc] initWithClass: class_ + return [[[self alloc] initWithClass: class lock: lock] autorelease]; } -- initWithClass: (Class)class_ - lock: (id )lock_ +- initWithClass: (Class)class + lock: (id )lock { - self = [super initWithClass: class_]; + self = [super initWithClass: class]; - lock = [lock_ retain]; + _lock = [lock retain]; return self; } - (void)dealloc { - [lock release]; + [_lock release]; [super dealloc]; } - (OFString*)description { - if (description != nil) - return description; + if (_description != nil) + return _description; - description = [[OFString alloc] initWithFormat: + _description = [[OFString alloc] initWithFormat: @"A lock of class %@ could not be unlocked in class %@!", - [(id)lock className], inClass]; + [_lock class], _inClass]; - return description; + return _description; } - (id )lock { - OF_GETTER(lock, NO) + OF_GETTER(_lock, NO) } @end Index: src/exceptions/OFUnsupportedProtocolException.h ================================================================== --- src/exceptions/OFUnsupportedProtocolException.h +++ src/exceptions/OFUnsupportedProtocolException.h @@ -22,11 +22,11 @@ * @brief An exception indicating that the protocol specified by the URL is not * supported. */ @interface OFUnsupportedProtocolException: OFException { - OFURL *URL; + OFURL *_URL; } #ifdef OF_HAVE_PROPERTIES @property (readonly, retain, nonatomic) OFURL *URL; #endif @@ -33,28 +33,28 @@ /*! * @brief Creates a new, autoreleased unsupported protocol exception. * * @param class_ The class of the object which caused the exception - * @param url The URL whose protocol is unsupported + * @param URL The URL whose protocol is unsupported * @return A new, autoreleased unsupported protocol exception */ + (instancetype)exceptionWithClass: (Class)class_ - URL: (OFURL*)url; + URL: (OFURL*)URL; /*! * @brief Initializes an already allocated unsupported protocol exception * * @param class_ The class of the object which caused the exception - * @param url The URL whose protocol is unsupported + * @param URL The URL whose protocol is unsupported * @return An initialized unsupported protocol exception */ - initWithClass: (Class)class_ - URL: (OFURL*)url; + URL: (OFURL*)URL; /*! * @brief Returns the URL whose protocol is unsupported. * * @return The URL whose protocol is unsupported */ - (OFURL*)URL; @end Index: src/exceptions/OFUnsupportedProtocolException.m ================================================================== --- src/exceptions/OFUnsupportedProtocolException.m +++ src/exceptions/OFUnsupportedProtocolException.m @@ -23,18 +23,18 @@ #import "OFURL.h" #import "common.h" @implementation OFUnsupportedProtocolException -+ (instancetype)exceptionWithClass: (Class)class_ ++ (instancetype)exceptionWithClass: (Class)class URL: (OFURL*)url { - return [[[self alloc] initWithClass: class_ + return [[[self alloc] initWithClass: class URL: url] autorelease]; } -- initWithClass: (Class)class_ +- initWithClass: (Class)class { @try { [self doesNotRecognizeSelector: _cmd]; } @catch (id e) { [self release]; @@ -42,17 +42,17 @@ } abort(); } -- initWithClass: (Class)class_ - URL: (OFURL*)url +- initWithClass: (Class)class + URL: (OFURL*)URL { - self = [super initWithClass: class_]; + self = [super initWithClass: class]; @try { - URL = [url copy]; + _URL = [URL copy]; } @catch (id e) { [self release]; @throw e; } @@ -59,27 +59,27 @@ return self; } - (void)dealloc { - [URL release]; + [_URL release]; [super dealloc]; } - (OFString*)description { - if (description != nil) - return description; - - description = [[OFString alloc] initWithFormat: - @"The protocol of URL %@ is not supported by class %@", URL, - inClass]; - - return description; + if (_description != nil) + return _description; + + _description = [[OFString alloc] initWithFormat: + @"The protocol of URL %@ is not supported by class %@", _URL, + _inClass]; + + return _description; } - (OFURL*)URL { - OF_GETTER(URL, NO) + OF_GETTER(_URL, NO) } @end Index: src/exceptions/OFUnsupportedVersionException.h ================================================================== --- src/exceptions/OFUnsupportedVersionException.h +++ src/exceptions/OFUnsupportedVersionException.h @@ -20,11 +20,11 @@ * @brief An exception indicating that the specified version of the format or * protocol is not supported. */ @interface OFUnsupportedVersionException: OFException { - OFString *version; + OFString *_version; } #ifdef OF_HAVE_PROPERTIES @property (readonly, copy, nonatomic) OFString *version; #endif Index: src/exceptions/OFUnsupportedVersionException.m ================================================================== --- src/exceptions/OFUnsupportedVersionException.m +++ src/exceptions/OFUnsupportedVersionException.m @@ -22,18 +22,18 @@ #import "OFString.h" #import "common.h" @implementation OFUnsupportedVersionException -+ (instancetype)exceptionWithClass: (Class)class_ ++ (instancetype)exceptionWithClass: (Class)class version: (OFString*)version { - return [[[self alloc] initWithClass: class_ + return [[[self alloc] initWithClass: class version: version] autorelease]; } -- initWithClass: (Class)class_ +- initWithClass: (Class)class { @try { [self doesNotRecognizeSelector: _cmd]; } @catch (id e) { [self release]; @@ -41,17 +41,17 @@ } abort(); } -- initWithClass: (Class)class_ - version: (OFString*)version_ +- initWithClass: (Class)class + version: (OFString*)version { - self = [super initWithClass: class_]; + self = [super initWithClass: class]; @try { - version = [version_ copy]; + _version = [version copy]; } @catch (id e) { [self release]; @throw e; } @@ -58,27 +58,27 @@ return self; } - (void)dealloc { - [version release]; + [_version release]; [super dealloc]; } - (OFString*)description { - if (description != nil) - return description; + if (_description != nil) + return _description; - description = [[OFString alloc] initWithFormat: + _description = [[OFString alloc] initWithFormat: @"Version %@ of the format or protocol is not supported by class " - @"%@", version, inClass]; + @"%@", _version, _inClass]; - return description; + return _description; } - (OFString*)version { - OF_GETTER(version, NO) + OF_GETTER(_version, NO) } @end Index: src/exceptions/OFWriteFailedException.m ================================================================== --- src/exceptions/OFWriteFailedException.m +++ src/exceptions/OFWriteFailedException.m @@ -22,15 +22,15 @@ #import "common.h" @implementation OFWriteFailedException - (OFString*)description { - if (description != nil) - return description; - - description = [[OFString alloc] initWithFormat: - @"Failed to write %zu bytes in class %@! " ERRFMT, requestedLength, - inClass, ERRPARAM]; - - return description; + if (_description != nil) + return _description; + + _description = [[OFString alloc] initWithFormat: + @"Failed to write %zu bytes in class %@! " ERRFMT, _requestedLength, + _inClass, ERRPARAM]; + + return _description; } @end Index: src/exceptions/common.h ================================================================== --- src/exceptions/common.h +++ src/exceptions/common.h @@ -17,32 +17,32 @@ #include #import "macros.h" #ifndef _WIN32 -#if !defined(HAVE_THREADSAFE_GETADDRINFO) && !defined(_PSP) -# include -#endif +# if !defined(HAVE_THREADSAFE_GETADDRINFO) && !defined(_PSP) +# include +# endif # include # define GET_ERRNO errno # ifndef HAVE_THREADSAFE_GETADDRINFO # define GET_AT_ERRNO h_errno # else # define GET_AT_ERRNO errno # endif # define GET_SOCK_ERRNO errno # define ERRFMT "Error string was: %s" -# define ERRPARAM strerror(errNo) +# define ERRPARAM strerror(_errNo) # if !defined(HAVE_THREADSAFE_GETADDRINFO) && !defined(_PSP) -# define AT_ERRPARAM hstrerror(errNo) +# define AT_ERRPARAM hstrerror(_errNo) # else -# define AT_ERRPARAM strerror(errNo) +# define AT_ERRPARAM strerror(_errNo) # endif #else # include # define GET_ERRNO GetLastError() # define GET_AT_ERRNO WSAGetLastError() # define GET_SOCK_ERRNO WSAGetLastError() # define ERRFMT "Error code was: %d" -# define ERRPARAM errNo -# define AT_ERRPARAM errNo +# define ERRPARAM _errNo +# define AT_ERRPARAM _errNo #endif Index: tests/TestsAppDelegate.h ================================================================== --- tests/TestsAppDelegate.h +++ tests/TestsAppDelegate.h @@ -26,11 +26,11 @@ [self outputSuccess: test \ inModule: module]; \ else { \ [self outputFailure: test \ inModule: module]; \ - fails++; \ + _fails++; \ } \ } #define EXPECT_EXCEPTION(test, exception, code) \ { \ BOOL caught = NO; \ @@ -48,20 +48,20 @@ [self outputSuccess: test \ inModule: module]; \ else { \ [self outputFailure: test \ inModule: module]; \ - fails++; \ + _fails++; \ } \ } #define R(x) (x, 1) @class OFString; @interface TestsAppDelegate: OFObject { - int fails; + int _fails; } - (void)outputString: (OFString*)str withColor: (int)color; - (void)outputTesting: (OFString*)test Index: tests/TestsAppDelegate.m ================================================================== --- tests/TestsAppDelegate.m +++ tests/TestsAppDelegate.m @@ -154,8 +154,8 @@ [self forwardingTests]; #ifdef OF_HAVE_PROPERTIES [self propertiesTests]; #endif - [OFApplication terminateWithStatus: fails]; + [OFApplication terminateWithStatus: _fails]; } @end