Index: generators/unicode/TableGenerator.m ================================================================== --- generators/unicode/TableGenerator.m +++ generators/unicode/TableGenerator.m @@ -30,14 +30,14 @@ #import "OFOutOfRangeException.h" #import "TableGenerator.h" #import "copyright.h" -#define UNICODE_DATA_URL \ - @"http://www.unicode.org/Public/UNIDATA/UnicodeData.txt" -#define CASE_FOLDING_URL \ - @"http://www.unicode.org/Public/UNIDATA/CaseFolding.txt" +static OFString *const unicodeDataURL = + @"http://www.unicode.org/Public/UNIDATA/UnicodeData.txt"; +static OFString *const caseFoldingURL = + @"http://www.unicode.org/Public/UNIDATA/CaseFolding.txt"; OF_APPLICATION_DELEGATE(TableGenerator) @implementation TableGenerator - (instancetype)init @@ -67,11 +67,11 @@ OFHTTPRequest *request; [OFStdOut writeString: @"Downloading UnicodeData.txt…"]; _state = STATE_UNICODE_DATA; request = [OFHTTPRequest requestWithURL: - [OFURL URLWithString: UNICODE_DATA_URL]]; + [OFURL URLWithString: unicodeDataURL]]; [_HTTPClient asyncPerformRequest: request]; } - (void)client: (OFHTTPClient *)client didPerformRequest: (OFHTTPRequest *)request @@ -167,11 +167,11 @@ [OFStdOut writeLine: @" done"]; [OFStdOut writeString: @"Downloading CaseFolding.txt…"]; _state = STATE_CASE_FOLDING; request = [OFHTTPRequest requestWithURL: - [OFURL URLWithString: CASE_FOLDING_URL]]; + [OFURL URLWithString: caseFoldingURL]]; [_HTTPClient asyncPerformRequest: request]; } - (void)parseCaseFolding: (OFHTTPResponse *)response { Index: src/OFASPrintF.m ================================================================== --- src/OFASPrintF.m +++ src/OFASPrintF.m @@ -39,11 +39,11 @@ #import "OFString.h" #import "OFLocale.h" #import "OFInitializationFailedException.h" -#define MAX_SUBFORMAT_LEN 64 +#define maxSubformatLen 64 #ifndef HAVE_ASPRINTF /* * (v)asprintf might be declared, but HAVE_ASPRINTF not defined because * configure determined it is broken. In this case, we must make sure there is @@ -54,11 +54,11 @@ #endif struct context { const char *format; size_t formatLen; - char subformat[MAX_SUBFORMAT_LEN + 1]; + char subformat[maxSubformatLen + 1]; size_t subformatLen; va_list arguments; char *buffer; size_t bufferLen; size_t i, last; @@ -169,11 +169,11 @@ static bool appendSubformat(struct context *ctx, const char *subformat, size_t subformatLen) { - if (ctx->subformatLen + subformatLen > MAX_SUBFORMAT_LEN) + if (ctx->subformatLen + subformatLen > maxSubformatLen) return false; memcpy(ctx->subformat + ctx->subformatLen, subformat, subformatLen); ctx->subformatLen += subformatLen; ctx->subformat[ctx->subformatLen] = 0; @@ -718,11 +718,11 @@ } free(tmp); } - memset(ctx->subformat, 0, MAX_SUBFORMAT_LEN); + memset(ctx->subformat, 0, maxSubformatLen); ctx->subformatLen = 0; ctx->lengthModifier = LengthModifierNone; ctx->useLocale = false; ctx->last = ctx->i + 1; @@ -744,11 +744,11 @@ { struct context ctx; ctx.format = format; ctx.formatLen = strlen(format); - memset(ctx.subformat, 0, MAX_SUBFORMAT_LEN + 1); + memset(ctx.subformat, 0, maxSubformatLen + 1); ctx.subformatLen = 0; va_copy(ctx.arguments, arguments); ctx.bufferLen = 0; ctx.last = 0; ctx.state = StateString; Index: src/OFBlock.m ================================================================== --- src/OFBlock.m +++ src/OFBlock.m @@ -164,14 +164,14 @@ static struct { Class isa; } alloc_failed_exception; #ifndef OF_HAVE_ATOMIC_OPS -# define NUM_SPINLOCKS 8 /* needs to be a power of 2 */ -# define SPINLOCK_HASH(p) ((uintptr_t)p >> 4) & (NUM_SPINLOCKS - 1) -static OFSpinlock blockSpinlocks[NUM_SPINLOCKS]; -static OFSpinlock byrefSpinlocks[NUM_SPINLOCKS]; +# define numSpinlocks 8 /* needs to be a power of 2 */ +# define SPINLOCK_HASH(p) ((uintptr_t)p >> 4) & (numSpinlocks - 1) +static OFSpinlock blockSpinlocks[numSpinlocks]; +static OFSpinlock byrefSpinlocks[numSpinlocks]; #endif void * _Block_copy(const void *block_) { @@ -372,11 +372,11 @@ @implementation OFBlock + (void)load { #ifndef OF_HAVE_ATOMIC_OPS - for (size_t i = 0; i < NUM_SPINLOCKS; i++) + for (size_t i = 0; i < numSpinlocks; i++) if (OFSpinlockNew(&blockSpinlocks[i]) != 0 || OFSpinlockNew(&byrefSpinlocks[i]) != 0) @throw [OFInitializationFailedException exceptionWithClass: self]; #endif Index: src/OFCRC16.m ================================================================== --- src/OFCRC16.m +++ src/OFCRC16.m @@ -15,21 +15,21 @@ #include "config.h" #import "OFCRC16.h" -#define CRC16_MAGIC 0xA001 +static const uint16_t CRC16Magic = 0xA001; uint16_t -OFCRC16(uint16_t crc, const void *bytes_, size_t length) +OFCRC16(uint16_t CRC, const void *bytes_, size_t length) { const unsigned char *bytes = bytes_; for (size_t i = 0; i < length; i++) { - crc ^= bytes[i]; + CRC ^= bytes[i]; for (uint8_t j = 0; j < 8; j++) - crc = (crc >> 1) ^ (CRC16_MAGIC & (~(crc & 1) + 1)); + CRC = (CRC >> 1) ^ (CRC16Magic & (~(CRC & 1) + 1)); } - return crc; + return CRC; } Index: src/OFCRC32.m ================================================================== --- src/OFCRC32.m +++ src/OFCRC32.m @@ -15,21 +15,21 @@ #include "config.h" #import "OFCRC32.h" -#define CRC32_MAGIC 0xEDB88320 +static const uint32_t CRC32Magic = 0xEDB88320; uint32_t -OFCRC32(uint32_t crc, const void *bytes_, size_t length) +OFCRC32(uint32_t CRC, const void *bytes_, size_t length) { const unsigned char *bytes = bytes_; for (size_t i = 0; i < length; i++) { - crc ^= bytes[i]; + CRC ^= bytes[i]; for (uint8_t j = 0; j < 8; j++) - crc = (crc >> 1) ^ (CRC32_MAGIC & (~(crc & 1) + 1)); + CRC = (CRC >> 1) ^ (CRC32Magic & (~(CRC & 1) + 1)); } - return crc; + return CRC; } Index: src/OFDate.m ================================================================== --- src/OFDate.m +++ src/OFDate.m @@ -114,11 +114,11 @@ [mutex release]; } #endif #ifdef OF_WINDOWS -static __time64_t (*func__mktime64)(struct tm *); +static __time64_t (*_mktime64FuncPtr)(struct tm *); #endif #ifdef HAVE_GMTIME_R # define GMTIME_RET(field) \ OFTimeInterval timeInterval = self.timeIntervalSince1970; \ @@ -352,11 +352,11 @@ atexit(releaseMutex); #endif #ifdef OF_WINDOWS if ((module = LoadLibrary("msvcrt.dll")) != NULL) - func__mktime64 = (__time64_t (*)(struct tm *)) + _mktime64FuncPtr = (__time64_t (*)(struct tm *)) GetProcAddress(module, "_mktime64"); #endif #if defined(OF_OBJFW_RUNTIME) && UINTPTR_MAX == UINT64_MAX dateTag = objc_registerTaggedPointerClass([OFTaggedPointerDate class]); @@ -475,12 +475,12 @@ UTF8String + string.UTF8StringLength) @throw [OFInvalidFormatException exception]; if (tz == SHRT_MAX) { #ifdef OF_WINDOWS - if (func__mktime64 != NULL) { - if ((seconds = func__mktime64(&tm)) == -1) + if (_mktime64FuncPtr != NULL) { + if ((seconds = _mktime64FuncPtr(&tm)) == -1) @throw [OFInvalidFormatException exception]; } else { #endif if ((seconds = mktime(&tm)) == -1) @throw [OFInvalidFormatException exception]; Index: src/OFEpollKernelEventObserver.m ================================================================== --- src/OFEpollKernelEventObserver.m +++ src/OFEpollKernelEventObserver.m @@ -31,11 +31,11 @@ #import "OFNull.h" #import "OFInitializationFailedException.h" #import "OFObserveFailedException.h" -#define EVENTLIST_SIZE 64 +#define eventListSize 64 static const OFMapTableFunctions mapFunctions = { NULL }; @implementation OFEpollKernelEventObserver - (instancetype)init @@ -188,17 +188,17 @@ } - (void)observeForTimeInterval: (OFTimeInterval)timeInterval { OFNull *nullObject = [OFNull null]; - struct epoll_event eventList[EVENTLIST_SIZE]; + struct epoll_event eventList[eventListSize]; int events; if ([self of_processReadBuffers]) return; - events = epoll_wait(_epfd, eventList, EVENTLIST_SIZE, + events = epoll_wait(_epfd, eventList, eventListSize, (timeInterval != -1 ? timeInterval * 1000 : -1)); if (events < 0) @throw [OFObserveFailedException exceptionWithObserver: self errNo: errno]; Index: src/OFFileURLHandler.m ================================================================== --- src/OFFileURLHandler.m +++ src/OFFileURLHandler.m @@ -93,15 +93,15 @@ # ifdef OF_WINDOWS # define HAVE_STRUCT_STAT_ST_BIRTHTIME OFTimeInterval st_birthtime; DWORD fileAttributes; # endif -} of_stat_t; +} Stat; #elif defined(HAVE_STAT64) -typedef struct stat64 of_stat_t; +typedef struct stat64 Stat; #else -typedef struct stat of_stat_t; +typedef struct stat Stat; #endif #ifdef OF_WINDOWS # define S_IFLNK 0x10000 # define S_ISLNK(mode) (mode & S_IFLNK) @@ -125,13 +125,13 @@ [readdirMutex release]; } #endif #ifdef OF_WINDOWS -static int (*func__wutime64)(const wchar_t *, struct __utimbuf64 *); -static WINAPI BOOLEAN (*func_CreateSymbolicLinkW)(LPCWSTR, LPCWSTR, DWORD); -static WINAPI BOOLEAN (*func_CreateHardLinkW)(LPCWSTR, LPCWSTR, +static int (*_wutime64FuncPtr)(const wchar_t *, struct __utimbuf64 *); +static WINAPI BOOLEAN (*createSymbolicLinkWFuncPtr)(LPCWSTR, LPCWSTR, DWORD); +static WINAPI BOOLEAN (*createHardLinkWFuncPtr)(LPCWSTR, LPCWSTR, LPSECURITY_ATTRIBUTES); #endif #ifdef OF_WINDOWS static OFTimeInterval @@ -194,11 +194,11 @@ } } #endif static int -of_stat(OFString *path, of_stat_t *buffer) +statWrapper(OFString *path, Stat *buffer) { #if defined(OF_WINDOWS) WIN32_FILE_ATTRIBUTE_DATA data; bool success; @@ -337,11 +337,11 @@ return 0; #endif } static int -of_lstat(OFString *path, of_stat_t *buffer) +lstatWrapper(OFString *path, Stat *buffer) { #if defined(HAVE_LSTAT) && !defined(OF_WINDOWS) && !defined(OF_AMIGAOS) && \ !defined(OF_NINTENDO_3DS) && !defined(OF_WII) # ifdef HAVE_LSTAT64 if (lstat64([path cStringWithEncoding: [OFLocale encoding]], @@ -352,16 +352,16 @@ return errno; # endif return 0; #else - return of_stat(path, buffer); + return statWrapper(path, buffer); #endif } static void -setTypeAttribute(OFMutableFileAttributes attributes, of_stat_t *s) +setTypeAttribute(OFMutableFileAttributes attributes, Stat *s) { if (S_ISREG(s->st_mode)) [attributes setObject: OFFileTypeRegular forKey: OFFileType]; else if (S_ISDIR(s->st_mode)) [attributes setObject: OFFileTypeDirectory forKey: OFFileType]; @@ -389,11 +389,11 @@ [attributes setObject: OFFileTypeSocket forKey: OFFileType]; #endif } static void -setDateAttributes(OFMutableFileAttributes attributes, of_stat_t *s) +setDateAttributes(OFMutableFileAttributes attributes, Stat *s) { /* FIXME: We could be more precise on some OSes */ [attributes setObject: [OFDate dateWithTimeIntervalSince1970: s->st_atime] forKey: OFFileLastAccessDate]; @@ -409,11 +409,11 @@ forKey: OFFileCreationDate]; #endif } static void -setOwnerAndGroupAttributes(OFMutableFileAttributes attributes, of_stat_t *s) +setOwnerAndGroupAttributes(OFMutableFileAttributes attributes, Stat *s) { #ifdef OF_FILE_MANAGER_SUPPORTS_OWNER [attributes setObject: [NSNumber numberWithUnsignedLong: s->st_uid] forKey: OFFileOwnerAccountID]; [attributes setObject: [NSNumber numberWithUnsignedLong: s->st_gid] @@ -480,11 +480,11 @@ forKey: OFFileSymbolicLinkDestination]; # else HANDLE handle; OFString *destination; - if (func_CreateSymbolicLinkW == NULL) + if (createSymbolicLinkWFuncPtr == NULL) return; if ((handle = CreateFileW(path.UTF16String, 0, (FILE_SHARE_READ | FILE_SHARE_WRITE), NULL, OPEN_EXISTING, FILE_FLAG_OPEN_REPARSE_POINT, NULL)) == INVALID_HANDLE_VALUE) @@ -552,18 +552,18 @@ atexit(releaseReaddirMutex); #endif #ifdef OF_WINDOWS if ((module = LoadLibrary("msvcrt.dll")) != NULL) - func__wutime64 = (int (*)(const wchar_t *, + _wutime64FuncPtr = (int (*)(const wchar_t *, struct __utimbuf64 *))GetProcAddress(module, "_wutime64"); if ((module = LoadLibrary("kernel32.dll")) != NULL) { - func_CreateSymbolicLinkW = + createSymbolicLinkWFuncPtr = (WINAPI BOOLEAN (*)(LPCWSTR, LPCWSTR, DWORD)) GetProcAddress(module, "CreateSymbolicLinkW"); - func_CreateHardLinkW = + createHardLinkWFuncPtr = (WINAPI BOOLEAN (*)(LPCWSTR, LPCWSTR, LPSECURITY_ATTRIBUTES)) GetProcAddress(module, "CreateHardLinkW"); } #endif @@ -575,13 +575,13 @@ [OFFile class]; } + (bool)of_directoryExistsAtPath: (OFString *)path { - of_stat_t s; + Stat s; - if (of_stat(path, &s) != 0) + if (statWrapper(path, &s) != 0) return false; return S_ISDIR(s.st_mode); } @@ -601,21 +601,21 @@ { OFMutableFileAttributes ret = [OFMutableDictionary dictionary]; void *pool = objc_autoreleasePoolPush(); OFString *path; int error; - of_stat_t s; + Stat s; if (URL == nil) @throw [OFInvalidArgumentException exception]; if (![[URL scheme] isEqual: _scheme]) @throw [OFInvalidArgumentException exception]; path = URL.fileSystemRepresentation; - if ((error = of_lstat(path, &s)) != 0) + if ((error = lstatWrapper(path, &s)) != 0) @throw [OFRetrieveItemAttributesFailedException exceptionWithURL: URL errNo: error]; if (s.st_size < 0) @@ -655,19 +655,19 @@ lastAccessDate = modificationDate; if (modificationDate == nil) modificationDate = lastAccessDate; #if defined(OF_WINDOWS) - if (func__wutime64 != NULL) { + if (_wutime64FuncPtr != NULL) { struct __utimbuf64 times = { .actime = (__time64_t)lastAccessDate.timeIntervalSince1970, .modtime = (__time64_t)modificationDate.timeIntervalSince1970 }; - if (func__wutime64([path UTF16String], ×) != 0) + if (_wutime64FuncPtr([path UTF16String], ×) != 0) @throw [OFSetItemAttributesFailedException exceptionWithURL: URL attributes: attributes failedAttribute: attributeKey errNo: errno]; @@ -907,20 +907,20 @@ } - (bool)fileExistsAtURL: (OFURL *)URL { void *pool = objc_autoreleasePoolPush(); - of_stat_t s; + Stat s; bool ret; if (URL == nil) @throw [OFInvalidArgumentException exception]; if (![URL.scheme isEqual: _scheme]) @throw [OFInvalidArgumentException exception]; - if (of_stat(URL.fileSystemRepresentation, &s) != 0) { + if (statWrapper(URL.fileSystemRepresentation, &s) != 0) { objc_autoreleasePoolPop(pool); return false; } ret = S_ISREG(s.st_mode); @@ -931,20 +931,20 @@ } - (bool)directoryExistsAtURL: (OFURL *)URL { void *pool = objc_autoreleasePoolPush(); - of_stat_t s; + Stat s; bool ret; if (URL == nil) @throw [OFInvalidArgumentException exception]; if (![URL.scheme isEqual: _scheme]) @throw [OFInvalidArgumentException exception]; - if (of_stat(URL.fileSystemRepresentation, &s) != 0) { + if (statWrapper(URL.fileSystemRepresentation, &s) != 0) { objc_autoreleasePoolPop(pool); return false; } ret = S_ISDIR(s.st_mode); @@ -1243,21 +1243,21 @@ - (void)removeItemAtURL: (OFURL *)URL { void *pool = objc_autoreleasePoolPush(); OFString *path; int error; - of_stat_t s; + Stat s; if (URL == nil) @throw [OFInvalidArgumentException exception]; if (![URL.scheme isEqual: _scheme]) @throw [OFInvalidArgumentException exception]; path = URL.fileSystemRepresentation; - if ((error = of_lstat(path, &s)) != 0) + if ((error = lstatWrapper(path, &s)) != 0) @throw [OFRemoveItemFailedException exceptionWithURL: URL errNo: error]; if (S_ISDIR(s.st_mode)) { OFArray OF_GENERIC(OFURL *) *contents; @@ -1355,15 +1355,15 @@ @throw [OFLinkFailedException exceptionWithSourceURL: source destinationURL: destination errNo: errno]; # else - if (func_CreateHardLinkW == NULL) + if (createHardLinkWFuncPtr == NULL) @throw [OFNotImplementedException exceptionWithSelector: _cmd object: self]; - if (!func_CreateHardLinkW(destinationPath.UTF16String, + if (!createHardLinkWFuncPtr(destinationPath.UTF16String, sourcePath.UTF16String, NULL)) @throw [OFLinkFailedException exceptionWithSourceURL: source destinationURL: destination errNo: retrieveError()]; @@ -1396,15 +1396,16 @@ @throw [OFCreateSymbolicLinkFailedException exceptionWithURL: URL target: target errNo: errno]; # else - if (func_CreateSymbolicLinkW == NULL) + if (createSymbolicLinkWFuncPtr == NULL) @throw [OFNotImplementedException exceptionWithSelector: _cmd object: self]; - if (!func_CreateSymbolicLinkW(path.UTF16String, target.UTF16String, 0)) + if (!createSymbolicLinkWFuncPtr(path.UTF16String, target.UTF16String, + 0)) @throw [OFCreateSymbolicLinkFailedException exceptionWithURL: URL target: target errNo: retrieveError()]; # endif Index: src/OFHTTPClient.m ================================================================== --- src/OFHTTPClient.m +++ src/OFHTTPClient.m @@ -46,11 +46,11 @@ #import "OFTruncatedDataException.h" #import "OFUnsupportedProtocolException.h" #import "OFUnsupportedVersionException.h" #import "OFWriteFailedException.h" -#define REDIRECTS_DEFAULT 10 +static const unsigned int defaultRedirects = 10; OF_DIRECT_MEMBERS @interface OFHTTPClientRequestHandler: OFObject { @public @@ -1203,11 +1203,11 @@ [super dealloc]; } - (OFHTTPResponse *)performRequest: (OFHTTPRequest *)request { - return [self performRequest: request redirects: REDIRECTS_DEFAULT]; + return [self performRequest: request redirects: defaultRedirects]; } - (OFHTTPResponse *)performRequest: (OFHTTPRequest *)request redirects: (unsigned int)redirects { @@ -1225,11 +1225,11 @@ return [response autorelease]; } - (void)asyncPerformRequest: (OFHTTPRequest *)request { - [self asyncPerformRequest: request redirects: REDIRECTS_DEFAULT]; + [self asyncPerformRequest: request redirects: defaultRedirects]; } - (void)asyncPerformRequest: (OFHTTPRequest *)request redirects: (unsigned int)redirects { Index: src/OFHTTPServer.m ================================================================== --- src/OFHTTPServer.m +++ src/OFHTTPServer.m @@ -42,12 +42,10 @@ #import "OFOutOfRangeException.h" #import "OFTruncatedDataException.h" #import "OFUnsupportedProtocolException.h" #import "OFWriteFailedException.h" -#define BUFFER_SIZE 1024 - /* * FIXME: Key normalization replaces headers like "DNT" with "Dnt". * FIXME: Errors are not reported to the user. */ Index: src/OFHuffmanTree.m ================================================================== --- src/OFHuffmanTree.m +++ src/OFHuffmanTree.m @@ -34,11 +34,11 @@ return tree; } static void -insertTree(OFHuffmanTree *tree, uint16_t code, uint8_t length, uint16_t value) +treeInsert(OFHuffmanTree *tree, uint16_t code, uint8_t length, uint16_t value) { while (length > 0) { uint8_t bit; length--; @@ -96,11 +96,11 @@ for (uint16_t i = 0; i <= maxCode; i++) { uint8_t length = lengths[i]; if (length > 0) - insertTree(tree, nextCode[length]++, length, i); + treeInsert(tree, nextCode[length]++, length, i); } } @finally { OFFreeMemory(lengthCount); OFFreeMemory(nextCode); } Index: src/OFKqueueKernelEventObserver.m ================================================================== --- src/OFKqueueKernelEventObserver.m +++ src/OFKqueueKernelEventObserver.m @@ -32,11 +32,11 @@ #import "OFInitializationFailedException.h" #import "OFObserveFailedException.h" #import "OFOutOfRangeException.h" -#define EVENTLIST_SIZE 64 +#define eventListSize 64 @implementation OFKqueueKernelEventObserver - (instancetype)init { self = [super init]; @@ -154,20 +154,20 @@ } - (void)observeForTimeInterval: (OFTimeInterval)timeInterval { struct timespec timeout; - struct kevent eventList[EVENTLIST_SIZE]; + struct kevent eventList[eventListSize]; int events; if ([self of_processReadBuffers]) return; timeout.tv_sec = (time_t)timeInterval; timeout.tv_nsec = (long)((timeInterval - timeout.tv_sec) * 1000000000); - events = kevent(_kernelQueue, NULL, 0, eventList, EVENTLIST_SIZE, + events = kevent(_kernelQueue, NULL, 0, eventList, eventListSize, (timeInterval != -1 ? &timeout : NULL)); if (events < 0) @throw [OFObserveFailedException exceptionWithObserver: self errNo: errno]; Index: src/OFMD5Hash.m ================================================================== --- src/OFMD5Hash.m +++ src/OFMD5Hash.m @@ -21,12 +21,12 @@ #import "OFSecureData.h" #import "OFHashAlreadyCalculatedException.h" #import "OFOutOfRangeException.h" -#define DIGEST_SIZE 16 -#define BLOCK_SIZE 64 +static const size_t digestSize = 16; +static const size_t blockSize = 64; OF_DIRECT_MEMBERS @interface OFMD5Hash () - (void)of_resetState; @end @@ -126,16 +126,16 @@ @synthesize calculated = _calculated; @synthesize allowsSwappableMemory = _allowsSwappableMemory; + (size_t)digestSize { - return DIGEST_SIZE; + return digestSize; } + (size_t)blockSize { - return BLOCK_SIZE; + return blockSize; } + (instancetype)hashWithAllowsSwappableMemory: (bool)allowsSwappableMemory { return [[[self alloc] initWithAllowsSwappableMemory: @@ -179,16 +179,16 @@ [super dealloc]; } - (size_t)digestSize { - return DIGEST_SIZE; + return digestSize; } - (size_t)blockSize { - return BLOCK_SIZE; + return blockSize; } - (id)copy { OFMD5Hash *copy = [[OFMD5Hash alloc] of_init]; Index: src/OFMapTable.m ================================================================== --- src/OFMapTable.m +++ src/OFMapTable.m @@ -26,17 +26,17 @@ #import "OFEnumerationMutationException.h" #import "OFInvalidArgumentException.h" #import "OFOutOfRangeException.h" -#define MIN_CAPACITY 16 +static const unsigned long minCapacity = 16; struct OFMapTableBucket { void *key, *object; unsigned long hash; }; -static struct OFMapTableBucket deleted = { 0 }; +static struct OFMapTableBucket deletedBucket = { 0 }; static void * defaultRetain(void *object) { return object; @@ -147,12 +147,12 @@ if (capacity * 8 / _capacity >= 6) if (_capacity <= ULONG_MAX / 2) _capacity *= 2; - if (_capacity < MIN_CAPACITY) - _capacity = MIN_CAPACITY; + if (_capacity < minCapacity) + _capacity = minCapacity; _buckets = OFAllocZeroedMemory(_capacity, sizeof(*_buckets)); if (OFHashSeed != 0) _rotate = OFRandom16() & 31; @@ -165,11 +165,11 @@ } - (void)dealloc { for (unsigned long i = 0; i < _capacity; i++) { - if (_buckets[i] != NULL && _buckets[i] != &deleted) { + if (_buckets[i] != NULL && _buckets[i] != &deletedBucket) { _keyFunctions.release(_buckets[i]->key); _objectFunctions.release(_buckets[i]->object); OFFreeMemory(_buckets[i]); } @@ -205,18 +205,18 @@ /* * Don't downsize if we have an initial capacity or if we would fall * below the minimum capacity. */ if ((capacity < self->_capacity && count > self->_count) || - capacity < MIN_CAPACITY) + capacity < minCapacity) return; buckets = OFAllocZeroedMemory(capacity, sizeof(*buckets)); for (unsigned long i = 0; i < self->_capacity; i++) { if (self->_buckets[i] != NULL && - self->_buckets[i] != &deleted) { + self->_buckets[i] != &deletedBucket) { unsigned long j, last; last = capacity; for (j = self->_buckets[i]->hash & (capacity - 1); @@ -255,11 +255,11 @@ hash = OFRotateLeft(hash, self->_rotate); last = self->_capacity; for (i = hash & (self->_capacity - 1); i < last && self->_buckets[i] != NULL; i++) { - if (self->_buckets[i] == &deleted) + if (self->_buckets[i] == &deletedBucket) continue; if (self->_keyFunctions.equal(self->_buckets[i]->key, key)) break; } @@ -267,11 +267,11 @@ /* In case the last bucket is already used */ if (i >= last) { last = hash & (self->_capacity - 1); for (i = 0; i < last && self->_buckets[i] != NULL; i++) { - if (self->_buckets[i] == &deleted) + if (self->_buckets[i] == &deletedBucket) continue; if (self->_keyFunctions.equal( self->_buckets[i]->key, key)) break; @@ -278,29 +278,29 @@ } } /* Key not in map table */ if (i >= last || self->_buckets[i] == NULL || - self->_buckets[i] == &deleted || + self->_buckets[i] == &deletedBucket || !self->_keyFunctions.equal(self->_buckets[i]->key, key)) { struct OFMapTableBucket *bucket; resizeForCount(self, self->_count + 1); self->_mutations++; last = self->_capacity; for (i = hash & (self->_capacity - 1); i < last && - self->_buckets[i] != NULL && self->_buckets[i] != &deleted; - i++); + self->_buckets[i] != NULL && + self->_buckets[i] != &deletedBucket; i++); /* In case the last bucket is already used */ if (i >= last) { last = hash & (self->_capacity - 1); for (i = 0; i < last && self->_buckets[i] != NULL && - self->_buckets[i] != &deleted; i++); + self->_buckets[i] != &deletedBucket; i++); } if (i >= last) @throw [OFOutOfRangeException exception]; @@ -350,11 +350,11 @@ mapTable->_keyFunctions.equal != _keyFunctions.equal || mapTable->_objectFunctions.equal != _objectFunctions.equal) return false; for (unsigned long i = 0; i < _capacity; i++) { - if (_buckets[i] != NULL && _buckets[i] != &deleted) { + if (_buckets[i] != NULL && _buckets[i] != &deletedBucket) { void *objectIter = [mapTable objectForKey: _buckets[i]->key]; if (!_objectFunctions.equal(objectIter, _buckets[i]->object)) @@ -368,11 +368,11 @@ - (unsigned long)hash { unsigned long hash = 0; for (unsigned long i = 0; i < _capacity; i++) { - if (_buckets[i] != NULL && _buckets[i] != &deleted) { + if (_buckets[i] != NULL && _buckets[i] != &deletedBucket) { hash ^= OFRotateRight(_buckets[i]->hash, _rotate); hash ^= _objectFunctions.hash(_buckets[i]->object); } } @@ -386,11 +386,12 @@ objectFunctions: _objectFunctions capacity: _capacity]; @try { for (unsigned long i = 0; i < _capacity; i++) - if (_buckets[i] != NULL && _buckets[i] != &deleted) + if (_buckets[i] != NULL && + _buckets[i] != &deletedBucket) setObject(copy, _buckets[i]->key, _buckets[i]->object, OFRotateRight(_buckets[i]->hash, _rotate)); } @catch (id e) { [copy release]; @@ -414,11 +415,11 @@ hash = OFRotateLeft(_keyFunctions.hash(key), _rotate); last = _capacity; for (i = hash & (_capacity - 1); i < last && _buckets[i] != NULL; i++) { - if (_buckets[i] == &deleted) + if (_buckets[i] == &deletedBucket) continue; if (_keyFunctions.equal(_buckets[i]->key, key)) return _buckets[i]->object; } @@ -428,11 +429,11 @@ /* In case the last bucket is already used */ last = hash & (_capacity - 1); for (i = 0; i < last && _buckets[i] != NULL; i++) { - if (_buckets[i] == &deleted) + if (_buckets[i] == &deletedBucket) continue; if (_keyFunctions.equal(_buckets[i]->key, key)) return _buckets[i]->object; } @@ -454,21 +455,21 @@ hash = OFRotateLeft(_keyFunctions.hash(key), _rotate); last = _capacity; for (i = hash & (_capacity - 1); i < last && _buckets[i] != NULL; i++) { - if (_buckets[i] == &deleted) + if (_buckets[i] == &deletedBucket) continue; if (_keyFunctions.equal(_buckets[i]->key, key)) { _mutations++; _keyFunctions.release(_buckets[i]->key); _objectFunctions.release(_buckets[i]->object); OFFreeMemory(_buckets[i]); - _buckets[i] = &deleted; + _buckets[i] = &deletedBucket; _count--; resizeForCount(self, _count); return; @@ -480,19 +481,19 @@ /* In case the last bucket is already used */ last = hash & (_capacity - 1); for (i = 0; i < last && _buckets[i] != NULL; i++) { - if (_buckets[i] == &deleted) + if (_buckets[i] == &deletedBucket) continue; if (_keyFunctions.equal(_buckets[i]->key, key)) { _keyFunctions.release(_buckets[i]->key); _objectFunctions.release(_buckets[i]->object); OFFreeMemory(_buckets[i]); - _buckets[i] = &deleted; + _buckets[i] = &deletedBucket; _count--; _mutations++; resizeForCount(self, _count); @@ -503,11 +504,11 @@ - (void)removeAllObjects { for (unsigned long i = 0; i < _capacity; i++) { if (_buckets[i] != NULL) { - if (_buckets[i] == &deleted) { + if (_buckets[i] == &deletedBucket) { _buckets[i] = NULL; continue; } _keyFunctions.release(_buckets[i]->key); @@ -517,11 +518,11 @@ _buckets[i] = NULL; } } _count = 0; - _capacity = MIN_CAPACITY; + _capacity = minCapacity; _buckets = OFResizeMemory(_buckets, _capacity, sizeof(*_buckets)); /* * Get a new random value for _rotate, so that it is not less secure * than creating a new hash map. @@ -534,11 +535,11 @@ { if (object == NULL || _count == 0) return false; for (unsigned long i = 0; i < _capacity; i++) - if (_buckets[i] != NULL && _buckets[i] != &deleted) + if (_buckets[i] != NULL && _buckets[i] != &deletedBucket) if (_objectFunctions.equal(_buckets[i]->object, object)) return true; return false; } @@ -547,11 +548,11 @@ { if (object == NULL || _count == 0) return false; for (unsigned long i = 0; i < _capacity; i++) - if (_buckets[i] != NULL && _buckets[i] != &deleted) + if (_buckets[i] != NULL && _buckets[i] != &deletedBucket) if (_buckets[i]->object == object) return true; return false; } @@ -581,11 +582,11 @@ unsigned long j = state->state; int i; for (i = 0; i < count; i++) { for (; j < _capacity && (_buckets[j] == NULL || - _buckets[j] == &deleted); j++); + _buckets[j] == &deletedBucket); j++); if (j < _capacity) { objects[i] = _buckets[j]->key; j++; } else @@ -608,11 +609,11 @@ for (size_t i = 0; i < _capacity && !stop; i++) { if (_mutations != mutations) @throw [OFEnumerationMutationException exceptionWithObject: self]; - if (_buckets[i] != NULL && _buckets[i] != &deleted) + if (_buckets[i] != NULL && _buckets[i] != &deletedBucket) block(_buckets[i]->key, _buckets[i]->object, &stop); } } - (void)replaceObjectsUsingBlock: (OFMapTableReplaceBlock)block @@ -622,11 +623,11 @@ for (size_t i = 0; i < _capacity; i++) { if (_mutations != mutations) @throw [OFEnumerationMutationException exceptionWithObject: self]; - if (_buckets[i] != NULL && _buckets[i] != &deleted) { + if (_buckets[i] != NULL && _buckets[i] != &deletedBucket) { void *new; new = block(_buckets[i]->key, _buckets[i]->object); if (new == NULL) @throw [OFInvalidArgumentException exception]; @@ -683,11 +684,11 @@ if (*_mutationsPtr != _mutations) @throw [OFEnumerationMutationException exceptionWithObject: _mapTable]; for (; _position < _capacity && (_buckets[_position] == NULL || - _buckets[_position] == &deleted); _position++); + _buckets[_position] == &deletedBucket); _position++); if (_position < _capacity) return &_buckets[_position++]->key; else return NULL; @@ -700,11 +701,11 @@ if (*_mutationsPtr != _mutations) @throw [OFEnumerationMutationException exceptionWithObject: _mapTable]; for (; _position < _capacity && (_buckets[_position] == NULL || - _buckets[_position] == &deleted); _position++); + _buckets[_position] == &deletedBucket); _position++); if (_position < _capacity) return &_buckets[_position++]->object; else return NULL; Index: src/OFObject.m ================================================================== --- src/OFObject.m +++ src/OFObject.m @@ -76,20 +76,20 @@ #else # define OFForward OFMethodNotFound # define OFForward_stret OFMethodNotFound_stret #endif -struct pre_ivar { +struct PreIvars { int retainCount; #if !defined(OF_HAVE_ATOMIC_OPS) && !defined(OF_AMIGAOS) OFSpinlock retainCountSpinlock; #endif }; -#define PRE_IVARS_ALIGN ((sizeof(struct pre_ivar) + \ +#define PRE_IVARS_ALIGN ((sizeof(struct PreIvars) + \ (OF_BIGGEST_ALIGNMENT - 1)) & ~(OF_BIGGEST_ALIGNMENT - 1)) -#define PRE_IVARS ((struct pre_ivar *)(void *)((char *)self - PRE_IVARS_ALIGN)) +#define PRE_IVARS ((struct PreIvars *)(void *)((char *)self - PRE_IVARS_ALIGN)) static struct { Class isa; } allocFailedException; @@ -308,15 +308,15 @@ if OF_UNLIKELY (instance == nil) { allocFailedException.isa = [OFAllocFailedException class]; @throw (id)&allocFailedException; } - ((struct pre_ivar *)instance)->retainCount = 1; + ((struct PreIvars *)instance)->retainCount = 1; #if !defined(OF_HAVE_ATOMIC_OPS) && !defined(OF_AMIGAOS) if OF_UNLIKELY (OFSpinlockNew( - &((struct pre_ivar *)instance)->retainCountSpinlock) != 0) { + &((struct PreIvars *)instance)->retainCountSpinlock) != 0) { free(instance); @throw [OFInitializationFailedException exceptionWithClass: class]; } #endif Index: src/OFPlugin.m ================================================================== --- src/OFPlugin.m +++ src/OFPlugin.m @@ -28,11 +28,11 @@ #import "OFSystemInfo.h" #import "OFInitializationFailedException.h" #import "OFLoadPluginFailedException.h" -typedef OFPlugin *(*init_plugin_t)(void); +typedef OFPlugin *(*PluginInit)(void); OFPluginHandle OFDLOpen(OFString *path, OFDLOpenFlags flags) { #ifndef OF_WINDOWS @@ -83,11 +83,11 @@ @implementation OFPlugin + (id)pluginWithPath: (OFString *)path { void *pool = objc_autoreleasePoolPush(); OFPluginHandle handle; - init_plugin_t initPlugin; + PluginInit initPlugin; OFPlugin *plugin; #if defined(OF_MACOS) path = [path stringByAppendingFormat: @".bundle/Contents/MacOS/%@", path.lastPathComponent]; @@ -103,12 +103,12 @@ exceptionWithPath: path error: OFDLError()]; objc_autoreleasePoolPop(pool); - initPlugin = (init_plugin_t)(uintptr_t)OFDLSym(handle, "init_plugin"); - if (initPlugin == (init_plugin_t)0 || (plugin = initPlugin()) == nil) { + initPlugin = (PluginInit)(uintptr_t)OFDLSym(handle, "OFPluginInit"); + if (initPlugin == (PluginInit)0 || (plugin = initPlugin()) == nil) { OFDLClose(handle); @throw [OFInitializationFailedException exceptionWithClass: self]; } Index: src/OFRIPEMD160Hash.m ================================================================== --- src/OFRIPEMD160Hash.m +++ src/OFRIPEMD160Hash.m @@ -21,12 +21,12 @@ #import "OFSecureData.h" #import "OFHashAlreadyCalculatedException.h" #import "OFOutOfRangeException.h" -#define DIGEST_SIZE 20 -#define BLOCK_SIZE 64 +static const size_t digestSize = 20; +static const size_t blockSize = 64; OF_DIRECT_MEMBERS @interface OFRIPEMD160Hash () - (void)of_resetState; @end @@ -139,16 +139,16 @@ @synthesize calculated = _calculated; @synthesize allowsSwappableMemory = _allowsSwappableMemory; + (size_t)digestSize { - return DIGEST_SIZE; + return digestSize; } + (size_t)blockSize { - return BLOCK_SIZE; + return blockSize; } + (instancetype)hashWithAllowsSwappableMemory: (bool)allowsSwappableMemory { return [[[self alloc] initWithAllowsSwappableMemory: @@ -192,16 +192,16 @@ [super dealloc]; } - (size_t)digestSize { - return DIGEST_SIZE; + return digestSize; } - (size_t)blockSize { - return BLOCK_SIZE; + return blockSize; } - (id)copy { OFRIPEMD160Hash *copy = [[OFRIPEMD160Hash alloc] of_init]; Index: src/OFSHA1Hash.m ================================================================== --- src/OFSHA1Hash.m +++ src/OFSHA1Hash.m @@ -21,12 +21,12 @@ #import "OFSecureData.h" #import "OFHashAlreadyCalculatedException.h" #import "OFOutOfRangeException.h" -#define DIGEST_SIZE 20 -#define BLOCK_SIZE 64 +static const size_t digestSize = 20; +static const size_t blockSize = 64; OF_DIRECT_MEMBERS @interface OFSHA1Hash () - (void)of_resetState; @end @@ -99,16 +99,16 @@ @synthesize calculated = _calculated; @synthesize allowsSwappableMemory = _allowsSwappableMemory; + (size_t)digestSize { - return DIGEST_SIZE; + return digestSize; } + (size_t)blockSize { - return BLOCK_SIZE; + return blockSize; } + (instancetype)hashWithAllowsSwappableMemory: (bool)allowsSwappableMemory { return [[[self alloc] initWithAllowsSwappableMemory: @@ -152,16 +152,16 @@ [super dealloc]; } - (size_t)digestSize { - return DIGEST_SIZE; + return digestSize; } - (size_t)blockSize { - return BLOCK_SIZE; + return blockSize; } - (id)copy { OFSHA1Hash *copy = [[OFSHA1Hash alloc] of_init]; Index: src/OFSHA224Hash.m ================================================================== --- src/OFSHA224Hash.m +++ src/OFSHA224Hash.m @@ -15,21 +15,21 @@ #include "config.h" #import "OFSHA224Hash.h" -#define DIGEST_SIZE 28 +static const size_t digestSize = 28; @implementation OFSHA224Hash + (size_t)digestSize { - return DIGEST_SIZE; + return digestSize; } - (size_t)digestSize { - return DIGEST_SIZE; + return digestSize; } - (void)of_resetState { _iVars->state[0] = 0xC1059ED8; Index: src/OFSHA224Or256Hash.m ================================================================== --- src/OFSHA224Or256Hash.m +++ src/OFSHA224Or256Hash.m @@ -22,11 +22,11 @@ #import "OFSecureData.h" #import "OFHashAlreadyCalculatedException.h" #import "OFOutOfRangeException.h" -#define BLOCK_SIZE 64 +static const size_t blockSize = 64; @interface OFSHA224Or256Hash () - (void)of_resetState; @end @@ -124,11 +124,11 @@ OF_UNRECOGNIZED_SELECTOR } + (size_t)blockSize { - return BLOCK_SIZE; + return blockSize; } + (instancetype)hashWithAllowsSwappableMemory: (bool)allowsSwappableMemory { return [[[self alloc] initWithAllowsSwappableMemory: @@ -182,11 +182,11 @@ OF_UNRECOGNIZED_SELECTOR } - (size_t)blockSize { - return BLOCK_SIZE; + return blockSize; } - (id)copy { OFSHA224Or256Hash *copy = [[[self class] alloc] of_init]; Index: src/OFSHA256Hash.m ================================================================== --- src/OFSHA256Hash.m +++ src/OFSHA256Hash.m @@ -15,21 +15,21 @@ #include "config.h" #import "OFSHA256Hash.h" -#define DIGEST_SIZE 32 +static const size_t digestSize = 32; @implementation OFSHA256Hash + (size_t)digestSize { - return DIGEST_SIZE; + return digestSize; } - (size_t)digestSize { - return DIGEST_SIZE; + return digestSize; } - (void)of_resetState { _iVars->state[0] = 0x6A09E667; Index: src/OFSHA384Hash.m ================================================================== --- src/OFSHA384Hash.m +++ src/OFSHA384Hash.m @@ -15,21 +15,21 @@ #include "config.h" #import "OFSHA384Hash.h" -#define DIGEST_SIZE 48 +static const size_t digestSize = 48; @implementation OFSHA384Hash + (size_t)digestSize { - return DIGEST_SIZE; + return digestSize; } - (size_t)digestSize { - return DIGEST_SIZE; + return digestSize; } - (void)of_resetState { _iVars->state[0] = 0xCBBB9D5DC1059ED8; Index: src/OFSHA384Or512Hash.m ================================================================== --- src/OFSHA384Or512Hash.m +++ src/OFSHA384Or512Hash.m @@ -22,11 +22,11 @@ #import "OFSecureData.h" #import "OFHashAlreadyCalculatedException.h" #import "OFOutOfRangeException.h" -#define BLOCK_SIZE 128 +static const size_t blockSize = 128; @interface OFSHA384Or512Hash () - (void)of_resetState; @end @@ -135,11 +135,11 @@ OF_UNRECOGNIZED_SELECTOR } + (size_t)blockSize { - return BLOCK_SIZE; + return blockSize; } + (instancetype)hashWithAllowsSwappableMemory: (bool)allowsSwappableMemory { return [[[self alloc] initWithAllowsSwappableMemory: @@ -193,11 +193,11 @@ OF_UNRECOGNIZED_SELECTOR } - (size_t)blockSize { - return BLOCK_SIZE; + return blockSize; } - (id)copy { OFSHA384Or512Hash *copy = [[[self class] alloc] of_init]; Index: src/OFSHA512Hash.m ================================================================== --- src/OFSHA512Hash.m +++ src/OFSHA512Hash.m @@ -15,21 +15,21 @@ #include "config.h" #import "OFSHA512Hash.h" -#define DIGEST_SIZE 64 +static const size_t digestSize = 64; @implementation OFSHA512Hash + (size_t)digestSize { - return DIGEST_SIZE; + return digestSize; } - (size_t)digestSize { - return DIGEST_SIZE; + return digestSize; } - (void)of_resetState { _iVars->state[0] = 0x6A09E667F3BCC908; Index: src/OFSecureData.m ================================================================== --- src/OFSecureData.m +++ src/OFSecureData.m @@ -33,11 +33,11 @@ #import "OFInvalidArgumentException.h" #import "OFNotImplementedException.h" #import "OFOutOfMemoryException.h" #import "OFOutOfRangeException.h" -#define CHUNK_SIZE 16 +static const size_t chunkSize = 16; #if defined(HAVE_MMAP) && defined(HAVE_MLOCK) && defined(MAP_ANON) struct page { struct page *next, *previous; void *map; @@ -96,11 +96,11 @@ static struct page * addPage(bool allowPreallocated) { size_t pageSize = [OFSystemInfo pageSize]; - size_t mapSize = OFRoundUpToPowerOf2(CHAR_BIT, pageSize / CHUNK_SIZE) / + size_t mapSize = OFRoundUpToPowerOf2(CHAR_BIT, pageSize / chunkSize) / CHAR_BIT; struct page *page; # if !defined(OF_HAVE_COMPILER_TLS) && defined(OF_HAVE_THREADS) struct page *lastPage; # endif @@ -182,11 +182,11 @@ static void removePageIfEmpty(struct page *page) { unsigned char *map = page->map; size_t pageSize = [OFSystemInfo pageSize]; - size_t mapSize = OFRoundUpToPowerOf2(CHAR_BIT, pageSize / CHUNK_SIZE) / + size_t mapSize = OFRoundUpToPowerOf2(CHAR_BIT, pageSize / chunkSize) / CHAR_BIT; for (size_t i = 0; i < mapSize; i++) if (map[i] != 0) return; @@ -217,16 +217,16 @@ static void * allocateMemory(struct page *page, size_t bytes) { size_t chunks, chunksLeft, pageSize, i, firstChunk; - bytes = OFRoundUpToPowerOf2(CHUNK_SIZE, bytes); - chunks = chunksLeft = bytes / CHUNK_SIZE; + bytes = OFRoundUpToPowerOf2(chunkSize, bytes); + chunks = chunksLeft = bytes / chunkSize; firstChunk = 0; pageSize = [OFSystemInfo pageSize]; - for (i = 0; i < pageSize / CHUNK_SIZE; i++) { + for (i = 0; i < pageSize / chunkSize; i++) { if (OFBitsetIsSet(page->map, i)) { chunksLeft = chunks; firstChunk = i + 1; continue; } @@ -237,11 +237,11 @@ if (chunksLeft == 0) { for (size_t j = firstChunk; j < firstChunk + chunks; j++) OFBitsetSet(page->map, j); - return page->page + (CHUNK_SIZE * firstChunk); + return page->page + (chunkSize * firstChunk); } return NULL; } @@ -248,13 +248,13 @@ static void freeMemory(struct page *page, void *pointer, size_t bytes) { size_t chunks, chunkIndex; - bytes = OFRoundUpToPowerOf2(CHUNK_SIZE, bytes); - chunks = bytes / CHUNK_SIZE; - chunkIndex = ((uintptr_t)pointer - (uintptr_t)page->page) / CHUNK_SIZE; + bytes = OFRoundUpToPowerOf2(chunkSize, bytes); + chunks = bytes / chunkSize; + chunkIndex = ((uintptr_t)pointer - (uintptr_t)page->page) / chunkSize; OFZeroMemory(pointer, bytes); for (size_t i = 0; i < chunks; i++) OFBitsetClear(page->map, chunkIndex + i); Index: src/OFStream.m ================================================================== --- src/OFStream.m +++ src/OFStream.m @@ -54,11 +54,11 @@ #import "OFOutOfRangeException.h" #import "OFSetOptionFailedException.h" #import "OFTruncatedDataException.h" #import "OFWriteFailedException.h" -#define MIN_READ_SIZE 512 +#define minReadSize 512 @implementation OFStream @synthesize buffersWrites = _buffersWrites; @synthesize of_waitingForDelimiter = _waitingForDelimiter, delegate = _delegate; @@ -131,17 +131,16 @@ /* * For small sizes, it is cheaper to read more and cache the * remainder - even if that means more copying of data - than * to do a syscall for every read. */ - if (length < MIN_READ_SIZE) { - char tmp[MIN_READ_SIZE], *readBuffer; + if (length < minReadSize) { + char tmp[minReadSize], *readBuffer; size_t bytesRead; - bytesRead = [self - lowlevelReadIntoBuffer: tmp - length: MIN_READ_SIZE]; + bytesRead = [self lowlevelReadIntoBuffer: tmp + length: minReadSize]; if (bytesRead > length) { memcpy(buffer, tmp, length); readBuffer = OFAllocMemory(bytesRead - length, Index: src/OFString.m ================================================================== --- src/OFString.m +++ src/OFString.m @@ -2445,28 +2445,28 @@ OFString *decimalPoint = [OFLocale decimalPoint]; const char *UTF8String = [self stringByReplacingOccurrencesOfString: @"." withString: decimalPoint].UTF8String; #endif - char *endPointer = NULL; + char *endPtr = NULL; float value; errno = 0; #ifdef HAVE_STRTOF_L - value = strtof_l(UTF8String, &endPointer, cLocale); + value = strtof_l(UTF8String, &endPtr, cLocale); #else - value = strtof(UTF8String, &endPointer); + value = strtof(UTF8String, &endPtr); #endif if (value == HUGE_VALF && errno == ERANGE) @throw [OFOutOfRangeException exception]; /* Check if there are any invalid chars left */ - if (endPointer != NULL) - for (; *endPointer != '\0'; endPointer++) + if (endPtr != NULL) + for (; *endPtr != '\0'; endPtr++) /* Use isspace since strtof uses the same. */ - if (!isspace((unsigned char)*endPointer)) + if (!isspace((unsigned char)*endPtr)) @throw [OFInvalidFormatException exception]; objc_autoreleasePoolPop(pool); return value; @@ -2498,28 +2498,28 @@ OFString *decimalPoint = [OFLocale decimalPoint]; const char *UTF8String = [self stringByReplacingOccurrencesOfString: @"." withString: decimalPoint].UTF8String; #endif - char *endPointer = NULL; + char *endPtr = NULL; double value; errno = 0; #ifdef HAVE_STRTOD_L - value = strtod_l(UTF8String, &endPointer, cLocale); + value = strtod_l(UTF8String, &endPtr, cLocale); #else - value = strtod(UTF8String, &endPointer); + value = strtod(UTF8String, &endPtr); #endif if (value == HUGE_VAL && errno == ERANGE) @throw [OFOutOfRangeException exception]; /* Check if there are any invalid chars left */ - if (endPointer != NULL) - for (; *endPointer != '\0'; endPointer++) + if (endPtr != NULL) + for (; *endPtr != '\0'; endPtr++) /* Use isspace since strtod uses the same. */ - if (!isspace((unsigned char)*endPointer)) + if (!isspace((unsigned char)*endPtr)) @throw [OFInvalidFormatException exception]; objc_autoreleasePoolPop(pool); return value; Index: src/OFSystemInfo.m ================================================================== --- src/OFSystemInfo.m +++ src/OFSystemInfo.m @@ -88,11 +88,11 @@ extern NSSearchPathEnumerationState NSGetNextSearchPathEnumeration( NSSearchPathEnumerationState, char *); #endif #if defined(OF_X86_64) || defined(OF_X86) -struct x86_regs { +struct X86Regs { uint32_t eax, ebx, ecx, edx; }; #endif static size_t pageSize = 4096; @@ -234,14 +234,14 @@ encoding: [OFLocale encoding]]; #endif } #if defined(OF_X86_64) || defined(OF_X86) -static OF_INLINE struct x86_regs OF_CONST_FUNC -x86_cpuid(uint32_t eax, uint32_t ecx) +static OF_INLINE struct X86Regs OF_CONST_FUNC +x86CPUID(uint32_t eax, uint32_t ecx) { - struct x86_regs regs; + struct X86Regs regs; # if defined(OF_X86_64) && defined(__GNUC__) __asm__ ( "cpuid" : "=a"(regs.eax), "=b"(regs.ebx), "=c"(regs.ecx), "=d"(regs.edx) @@ -527,11 +527,11 @@ #endif + (OFString *)CPUVendor { #if (defined(OF_X86_64) || defined(OF_X86)) && defined(__GNUC__) - struct x86_regs regs = x86_cpuid(0, 0); + struct X86Regs regs = x86CPUID(0, 0); uint32_t buffer[3]; if (regs.eax == 0) return nil; @@ -553,11 +553,11 @@ uint32_t buffer[12]; size_t i; i = 0; for (uint32_t eax = 0x80000002; eax <= 0x80000004; eax++) { - struct x86_regs regs = x86_cpuid(eax, 0); + struct X86Regs regs = x86CPUID(eax, 0); buffer[i++] = regs.eax; buffer[i++] = regs.ebx; buffer[i++] = regs.ecx; buffer[i++] = regs.edx; @@ -582,61 +582,61 @@ } #if defined(OF_X86_64) || defined(OF_X86) + (bool)supportsMMX { - return (x86_cpuid(1, 0).edx & (1u << 23)); + return (x86CPUID(1, 0).edx & (1u << 23)); } + (bool)supportsSSE { - return (x86_cpuid(1, 0).edx & (1u << 25)); + return (x86CPUID(1, 0).edx & (1u << 25)); } + (bool)supportsSSE2 { - return (x86_cpuid(1, 0).edx & (1u << 26)); + return (x86CPUID(1, 0).edx & (1u << 26)); } + (bool)supportsSSE3 { - return (x86_cpuid(1, 0).ecx & (1u << 0)); + return (x86CPUID(1, 0).ecx & (1u << 0)); } + (bool)supportsSSSE3 { - return (x86_cpuid(1, 0).ecx & (1u << 9)); + return (x86CPUID(1, 0).ecx & (1u << 9)); } + (bool)supportsSSE41 { - return (x86_cpuid(1, 0).ecx & (1u << 19)); + return (x86CPUID(1, 0).ecx & (1u << 19)); } + (bool)supportsSSE42 { - return (x86_cpuid(1, 0).ecx & (1u << 20)); + return (x86CPUID(1, 0).ecx & (1u << 20)); } + (bool)supportsAVX { - return (x86_cpuid(1, 0).ecx & (1u << 28)); + return (x86CPUID(1, 0).ecx & (1u << 28)); } + (bool)supportsAVX2 { - return x86_cpuid(0, 0).eax >= 7 && (x86_cpuid(7, 0).ebx & (1u << 5)); + return x86CPUID(0, 0).eax >= 7 && (x86CPUID(7, 0).ebx & (1u << 5)); } + (bool)supportsAESNI { - return (x86_cpuid(1, 0).ecx & (1u << 25)); + return (x86CPUID(1, 0).ecx & (1u << 25)); } + (bool)supportsSHAExtensions { - return (x86_cpuid(7, 0).ebx & (1u << 29)); + return (x86CPUID(7, 0).ebx & (1u << 29)); } #endif #if defined(OF_POWERPC) || defined(OF_POWERPC64) + (bool)supportsAltiVec Index: src/OFWin32ConsoleStdIOStream.h ================================================================== --- src/OFWin32ConsoleStdIOStream.h +++ src/OFWin32ConsoleStdIOStream.h @@ -11,12 +11,10 @@ * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ -#define OF_STDIO_STREAM_WIN32CONSOLE_H - #import "OFStdIOStream.h" OF_ASSUME_NONNULL_BEGIN @interface OFWin32ConsoleStdIOStream: OFStdIOStream Index: src/OFWin32ConsoleStdIOStream.m ================================================================== --- src/OFWin32ConsoleStdIOStream.m +++ src/OFWin32ConsoleStdIOStream.m @@ -35,12 +35,10 @@ * In order to not do this when redirecting input / output to a file (as the * file would then be read / written in the wrong encoding and break reading / * writing binary), it checks that the handle is indeed a console. */ -#define OF_STDIO_STREAM_WIN32_CONSOLE_M - #include "config.h" #include #include #include Index: src/OFXMLParser.m ================================================================== --- src/OFXMLParser.m +++ src/OFXMLParser.m @@ -61,12 +61,12 @@ static void inCDATAState(OFXMLParser *); static void inCommentOpeningState(OFXMLParser *); static void inCommentState1(OFXMLParser *); static void inCommentState2(OFXMLParser *); static void inDOCTYPEState(OFXMLParser *); -typedef void (*state_function_t)(OFXMLParser *); -static state_function_t lookupTable[] = { +typedef void (*StateFunction)(OFXMLParser *); +static StateFunction lookupTable[] = { [OFXMLParserStateInByteOrderMark] = inByteOrderMarkState, [OFXMLParserStateOutsideTag] = outsideTagState, [OFXMLParserStateTagOpened] = tagOpenedState, [OFXMLParserStateInProcessingInstruction] = inProcessingInstructionState, Index: src/exceptions/OFException.h ================================================================== --- src/exceptions/OFException.h +++ src/exceptions/OFException.h @@ -23,11 +23,11 @@ @class OFArray OF_GENERIC(ObjectType); @class OFMutableArray OF_GENERIC(ObjectType); @class OFString; -#define OF_BACKTRACE_SIZE 16 +#define OFBacktraceSize 16 #if defined(OF_WINDOWS) && defined(OF_HAVE_SOCKETS) # ifndef EADDRINUSE # define EADDRINUSE WSAEADDRINUSE # endif @@ -143,11 +143,11 @@ * The OFException class is the base class for all exceptions in ObjFW, except * the OFAllocFailedException. */ @interface OFException: OFObject { - void *_backtrace[OF_BACKTRACE_SIZE]; + void *_backtrace[OFBacktraceSize]; } /** * @brief Creates a new, autoreleased exception. * Index: src/exceptions/OFException.m ================================================================== --- src/exceptions/OFException.m +++ src/exceptions/OFException.m @@ -49,11 +49,11 @@ typedef enum { _URC_OK = 0, _URC_END_OF_STACK = 5 }_Unwind_Reason_Code; -struct backtrace_ctx { +struct BacktraceCtx { void **backtrace; uint8_t i; }; #ifdef HAVE__UNWIND_BACKTRACE @@ -252,15 +252,15 @@ } #endif #ifdef HAVE__UNWIND_BACKTRACE static _Unwind_Reason_Code -backtrace_callback(struct _Unwind_Context *ctx, void *data) +backtraceCallback(struct _Unwind_Context *ctx, void *data) { - struct backtrace_ctx *bt = data; + struct BacktraceCtx *bt = data; - if (bt->i < OF_BACKTRACE_SIZE) { + if (bt->i < OFBacktraceSize) { # ifndef HAVE_ARM_EHABI_EXCEPTIONS bt->backtrace[bt->i++] = (void *)_Unwind_GetIP(ctx); # else uintptr_t ip; @@ -281,17 +281,17 @@ } #ifdef HAVE__UNWIND_BACKTRACE - (instancetype)init { - struct backtrace_ctx ctx; + struct BacktraceCtx ctx; self = [super init]; ctx.backtrace = _backtrace; ctx.i = 0; - _Unwind_Backtrace(backtrace_callback, &ctx); + _Unwind_Backtrace(backtraceCallback, &ctx); return self; } #endif @@ -306,12 +306,11 @@ #ifdef HAVE__UNWIND_BACKTRACE OFMutableArray OF_GENERIC(OFString *) *backtrace = [OFMutableArray array]; void *pool = objc_autoreleasePoolPush(); - for (uint8_t i = 0; - i < OF_BACKTRACE_SIZE && _backtrace[i] != NULL; i++) { + for (uint8_t i = 0; i < OFBacktraceSize && _backtrace[i] != NULL; i++) { # ifdef HAVE_DLADDR Dl_info info; if (dladdr(_backtrace[i], &info)) { OFString *frame; Index: tests/plugin/TestPlugin.m ================================================================== --- tests/plugin/TestPlugin.m +++ tests/plugin/TestPlugin.m @@ -43,9 +43,9 @@ return num * 2; } @end id -init_plugin(void) +OFPluginInit(void) { return [[[TestPlugin alloc] init] autorelease]; } Index: utils/ofarc/OFArc.m ================================================================== --- utils/ofarc/OFArc.m +++ utils/ofarc/OFArc.m @@ -40,11 +40,11 @@ #import "OFOpenItemFailedException.h" #import "OFReadFailedException.h" #import "OFSeekFailedException.h" #import "OFWriteFailedException.h" -#define BUFFER_SIZE 4096 +#define bufferSize 4096 OF_APPLICATION_DELEGATE(OFArc) static void help(OFStream *stream, bool full, int status) @@ -685,15 +685,15 @@ - (ssize_t)copyBlockFromStream: (OFStream *)input toStream: (OFStream *)output fileName: (OFString *)fileName { - char buffer[BUFFER_SIZE]; + char buffer[bufferSize]; size_t length; @try { - length = [input readIntoBuffer: buffer length: BUFFER_SIZE]; + length = [input readIntoBuffer: buffer length: bufferSize]; } @catch (OFReadFailedException *e) { OFString *error = [OFString stringWithCString: strerror(e.errNo) encoding: [OFLocale encoding]]; [OFStdOut writeString: @"\r"]; Index: utils/ofhttp/ProgressBar.m ================================================================== --- utils/ofhttp/ProgressBar.m +++ utils/ofhttp/ProgressBar.m @@ -22,15 +22,15 @@ #import "OFTimer.h" #import "OFLocale.h" #import "ProgressBar.h" -#define GIBIBYTE (1024 * 1024 * 1024) -#define MEBIBYTE (1024 * 1024) -#define KIBIBYTE (1024) +static const float oneKibibyte = 1024; +static const float oneMebibyte = 1024 * oneKibibyte; +static const float oneGibibyte = 1024 * oneMebibyte; -#define UPDATE_INTERVAL 0.1 +static const OFTimeInterval updateInterval = 0.1; #ifndef HAVE_TRUNCF # define truncf(x) trunc(x) #endif @@ -48,11 +48,11 @@ _length = length; _resumedFrom = resumedFrom; _startDate = [[OFDate alloc] init]; _lastReceivedDate = [[OFDate alloc] init]; _drawTimer = [[OFTimer - scheduledTimerWithTimeInterval: UPDATE_INTERVAL + scheduledTimerWithTimeInterval: updateInterval target: self selector: @selector(draw) repeats: true] retain]; _BPSTimer = [[OFTimer scheduledTimerWithTimeInterval: 1.0 @@ -177,25 +177,25 @@ } else [OFStdOut writeFormat: @"%2u:%02u:%02u ", (uint8_t)(_ETA / 3600), (uint8_t)(_ETA / 60) % 60, (uint8_t)_ETA % 60]; - if (_BPS >= GIBIBYTE) { + if (_BPS >= oneGibibyte) { OFString *num = [OFString stringWithFormat: - @"%,7.2f", _BPS / GIBIBYTE]; + @"%,7.2f", _BPS / oneGibibyte]; [OFStdOut writeString: OF_LOCALIZED(@"progress_gibs", @"%[num] GiB/s", @"num", num)]; - } else if (_BPS >= MEBIBYTE) { + } else if (_BPS >= oneMebibyte) { OFString *num = [OFString stringWithFormat: - @"%,7.2f", _BPS / MEBIBYTE]; + @"%,7.2f", _BPS / oneMebibyte]; [OFStdOut writeString: OF_LOCALIZED(@"progress_mibs", @"%[num] MiB/s", @"num", num)]; - } else if (_BPS >= KIBIBYTE) { + } else if (_BPS >= oneKibibyte) { OFString *num = [OFString stringWithFormat: - @"%,7.2f", _BPS / KIBIBYTE]; + @"%,7.2f", _BPS / oneKibibyte]; [OFStdOut writeString: OF_LOCALIZED(@"progress_kibs", @"%[num] KiB/s", @"num", num)]; } else { OFString *num = [OFString stringWithFormat: @@ -208,25 +208,25 @@ - (void)_drawReceived { [OFStdOut writeString: @"\r "]; - if (_resumedFrom + _received >= GIBIBYTE) { + if (_resumedFrom + _received >= oneGibibyte) { OFString *num = [OFString stringWithFormat: - @"%,7.2f", (float)(_resumedFrom + _received) / GIBIBYTE]; + @"%,7.2f", (float)(_resumedFrom + _received) / oneGibibyte]; [OFStdOut writeString: OF_LOCALIZED(@"progress_gib", @"%[num] GiB", @"num", num)]; - } else if (_resumedFrom + _received >= MEBIBYTE) { + } else if (_resumedFrom + _received >= oneMebibyte) { OFString *num = [OFString stringWithFormat: - @"%,7.2f", (float)(_resumedFrom + _received) / MEBIBYTE]; + @"%,7.2f", (float)(_resumedFrom + _received) / oneMebibyte]; [OFStdOut writeString: OF_LOCALIZED(@"progress_mib", @"%[num] MiB", @"num", num)]; - } else if (_resumedFrom + _received >= KIBIBYTE) { + } else if (_resumedFrom + _received >= oneKibibyte) { OFString *num = [OFString stringWithFormat: - @"%,7.2f", (float)(_resumedFrom + _received) / KIBIBYTE]; + @"%,7.2f", (float)(_resumedFrom + _received) / oneKibibyte]; [OFStdOut writeString: OF_LOCALIZED(@"progress_kib", @"%[num] KiB", @"num", num)]; } else { OFString *num = [OFString stringWithFormat: @@ -245,25 +245,25 @@ if (_stopped) _BPS = (float)_received / -(float)_startDate.timeIntervalSinceNow; - if (_BPS >= GIBIBYTE) { + if (_BPS >= oneGibibyte) { OFString *num = [OFString stringWithFormat: - @"%,7.2f", _BPS / GIBIBYTE]; + @"%,7.2f", _BPS / oneGibibyte]; [OFStdOut writeString: OF_LOCALIZED(@"progress_gibs", @"%[num] GiB/s", @"num", num)]; - } else if (_BPS >= MEBIBYTE) { + } else if (_BPS >= oneMebibyte) { OFString *num = [OFString stringWithFormat: - @"%,7.2f", _BPS / MEBIBYTE]; + @"%,7.2f", _BPS / oneMebibyte]; [OFStdOut writeString: OF_LOCALIZED(@"progress_mibs", @"%[num] MiB/s", @"num", num)]; - } else if (_BPS >= KIBIBYTE) { + } else if (_BPS >= oneKibibyte) { OFString *num = [OFString stringWithFormat: - @"%,7.2f", _BPS / KIBIBYTE]; + @"%,7.2f", _BPS / oneKibibyte]; [OFStdOut writeString: OF_LOCALIZED(@"progress_kibs", @"%[num] KiB/s", @"num", num)]; } else { OFString *num = [OFString stringWithFormat: