Index: src/OFArray.m ================================================================== --- src/OFArray.m +++ src/OFArray.m @@ -379,21 +379,19 @@ if (![self isKindOfClass: [OFMutableArray class]]) return [OFSubarray arrayWithArray: self range: range]; - buffer = [self allocMemoryWithSize: sizeof(*buffer) - count: range.length]; - + buffer = of_malloc(range.length, sizeof(*buffer)); @try { [self getObjects: buffer inRange: range]; ret = [OFArray arrayWithObjects: buffer count: range.length]; } @finally { - [self freeMemory: buffer]; + free(buffer); } return ret; } @@ -856,12 +854,11 @@ #ifdef OF_HAVE_BLOCKS - (OFArray *)mappedArrayUsingBlock: (of_array_map_block_t)block { OFArray *ret; size_t count = self.count; - id *tmp = [self allocMemoryWithSize: sizeof(id) - count: count]; + id *tmp = of_malloc(count, sizeof(id)); @try { [self enumerateObjectsUsingBlock: ^ (id object, size_t idx, bool *stop) { tmp[idx] = block(object, idx); @@ -868,22 +865,21 @@ }]; ret = [OFArray arrayWithObjects: tmp count: count]; } @finally { - [self freeMemory: tmp]; + free(tmp); } return ret; } - (OFArray *)filteredArrayUsingBlock: (of_array_filter_block_t)block { OFArray *ret; size_t count = self.count; - id *tmp = [self allocMemoryWithSize: sizeof(id) - count: count]; + id *tmp = of_malloc(count, sizeof(id)); @try { __block size_t i = 0; [self enumerateObjectsUsingBlock: ^ (id object, size_t idx, @@ -893,11 +889,11 @@ }]; ret = [OFArray arrayWithObjects: tmp count: i]; } @finally { - [self freeMemory: tmp]; + free(tmp); } return ret; } Index: src/OFData.m ================================================================== --- src/OFData.m +++ src/OFData.m @@ -195,11 +195,11 @@ # if ULLONG_MAX > SIZE_MAX if (size > SIZE_MAX) @throw [OFOutOfRangeException exception]; # endif - buffer = of_malloc(1, (size_t)size); + buffer = of_malloc((size_t)size, 1); file = [[OFFile alloc] initWithPath: path mode: @"r"]; @try { [file readIntoBuffer: buffer exactLength: (size_t)size]; Index: src/OFHTTPClient.m ================================================================== --- src/OFHTTPClient.m +++ src/OFHTTPClient.m @@ -513,11 +513,11 @@ lineC = line.UTF8String; if ((tmp = strchr(lineC, ':')) == NULL) @throw [OFInvalidServerReplyException exception]; - keyC = of_malloc(1, tmp - lineC + 1); + keyC = of_malloc(tmp - lineC + 1, 1); memcpy(keyC, lineC, tmp - lineC); keyC[tmp - lineC] = '\0'; normalizeKey(keyC); @try { Index: src/OFMapTableDictionary.m ================================================================== --- src/OFMapTableDictionary.m +++ src/OFMapTableDictionary.m @@ -342,12 +342,11 @@ OFArray *ret; id *keys; size_t count; count = _mapTable.count; - keys = [self allocMemoryWithSize: sizeof(*keys) - count: count]; + keys = of_malloc(count, sizeof(*keys)); @try { void *pool = objc_autoreleasePoolPush(); OFMapTableEnumerator *enumerator; void **keyPtr; @@ -364,11 +363,11 @@ objc_autoreleasePoolPop(pool); ret = [OFArray arrayWithObjects: keys count: count]; } @finally { - [self freeMemory: keys]; + free(keys); } return ret; } @@ -377,12 +376,11 @@ OFArray *ret; id *objects; size_t count; count = _mapTable.count; - objects = [self allocMemoryWithSize: sizeof(*objects) - count: count]; + objects = of_malloc(count, sizeof(*objects)); @try { void *pool = objc_autoreleasePoolPush(); OFMapTableEnumerator *enumerator; void **objectPtr; @@ -399,11 +397,11 @@ objc_autoreleasePoolPop(pool); ret = [OFArray arrayWithObjects: objects count: count]; } @finally { - [self freeMemory: objects]; + free(objects); } return ret; } Index: src/OFMutableAdjacentArray.m ================================================================== --- src/OFMutableAdjacentArray.m +++ src/OFMutableAdjacentArray.m @@ -241,22 +241,21 @@ if (range.length > SIZE_MAX - range.location || range.location >= count || range.length > count - range.location) @throw [OFOutOfRangeException exception]; - copy = [self allocMemoryWithSize: sizeof(*copy) - count: range.length]; + copy = of_malloc(range.length, sizeof(*copy)); memcpy(copy, objects + range.location, range.length * sizeof(id)); @try { [_array removeItemsInRange: range]; _mutations++; for (size_t i = 0; i < range.length; i++) [copy[i] release]; } @finally { - [self freeMemory: copy]; + free(copy); } } - (void)removeLastObject { Index: src/OFMutableSet.m ================================================================== --- src/OFMutableSet.m +++ src/OFMutableSet.m @@ -170,13 +170,11 @@ { void *pool = objc_autoreleasePoolPush(); size_t count = self.count; id *cArray; - cArray = [self allocMemoryWithSize: sizeof(id) - count: count]; - + cArray = of_malloc(count, sizeof(id)); @try { size_t i; i = 0; for (id object in self) { @@ -186,11 +184,11 @@ for (i = 0; i < count; i++) if (![set containsObject: cArray[i]]) [self removeObject: cArray[i]]; } @finally { - [self freeMemory: cArray]; + free(cArray); } objc_autoreleasePoolPop(pool); } Index: src/OFMutableUTF8String.m ================================================================== --- src/OFMutableUTF8String.m +++ src/OFMutableUTF8String.m @@ -103,12 +103,11 @@ return; } unicodeLen = self.length; - unicodeString = [self allocMemoryWithSize: sizeof(of_unichar_t) - count: unicodeLen]; + unicodeString = of_malloc(unicodeLen, sizeof(of_unichar_t)); i = j = 0; newCStringLength = 0; while (i < _s->cStringLength) { @@ -127,11 +126,11 @@ cLen = of_string_utf8_decode(_s->cString + i, _s->cStringLength - i, &c); if (cLen <= 0 || c > 0x10FFFF) { - [self freeMemory: unicodeString]; + free(unicodeString); @throw [OFInvalidEncodingException exception]; } isStart = of_ascii_isspace(c); @@ -150,21 +149,21 @@ else if (c < 0x10000) newCStringLength += 3; else if (c < 0x110000) newCStringLength += 4; else { - [self freeMemory: unicodeString]; + free(unicodeString); @throw [OFInvalidEncodingException exception]; } i += cLen; } @try { newCString = [self allocMemoryWithSize: newCStringLength + 1]; } @catch (id e) { - [self freeMemory: unicodeString]; + free(unicodeString); @throw e; } j = 0; @@ -171,20 +170,20 @@ for (i = 0; i < unicodeLen; i++) { size_t d; if ((d = of_string_utf8_encode(unicodeString[i], newCString + j)) == 0) { - [self freeMemory: unicodeString]; + free(unicodeString); [self freeMemory: newCString]; @throw [OFInvalidEncodingException exception]; } j += d; } assert(j == newCStringLength); newCString[j] = 0; - [self freeMemory: unicodeString]; + free(unicodeString); [self freeMemory: _s->cString]; _s->hashed = false; _s->cString = newCString; _s->cStringLength = newCStringLength; @@ -383,13 +382,12 @@ } - (void)appendCharacters: (const of_unichar_t *)characters length: (size_t)length { - char *tmp; + char *tmp = of_malloc((length * 4) + 1, 1); - tmp = [self allocMemoryWithSize: (length * 4) + 1]; @try { size_t j = 0; bool isUTF8 = false; for (size_t i = 0; i < length; i++) { @@ -416,11 +414,11 @@ _s->length += length; if (isUTF8) _s->isUTF8 = true; } @finally { - [self freeMemory: tmp]; + free(tmp); } } - (void)appendFormat: (OFConstantString *)format arguments: (va_list)arguments Index: src/OFObject+KeyValueCoding.m ================================================================== --- src/OFObject+KeyValueCoding.m +++ src/OFObject+KeyValueCoding.m @@ -48,11 +48,11 @@ if ((keyLength = key.UTF8StringLength) < 1) { objc_autoreleasePoolPop(pool); return [self valueForUndefinedKey: key]; } - name = of_malloc(1, keyLength + 3); + name = of_malloc(keyLength + 3, 1); @try { memcpy(name, "is", 2); memcpy(name + 2, key.UTF8String, keyLength); name[keyLength + 2] = '\0'; @@ -160,11 +160,11 @@ [self setValue: value forUndefinedKey: key]; return; } - name = of_malloc(1, keyLength + 5); + name = of_malloc(keyLength + 5, 1); @try { memcpy(name, "set", 3); memcpy(name + 3, key.UTF8String, keyLength); memcpy(name + keyLength + 3, ":", 2); Index: src/OFStream.m ================================================================== --- src/OFStream.m +++ src/OFStream.m @@ -655,11 +655,11 @@ - (OFData *)readDataUntilEndOfStream { OFMutableData *data = [OFMutableData data]; size_t pageSize = [OFSystemInfo pageSize]; - char *buffer = [self allocMemoryWithSize: pageSize]; + char *buffer = of_malloc(1, pageSize); @try { while (!self.atEndOfStream) { size_t length; @@ -667,11 +667,11 @@ length: pageSize]; [data addItems: buffer count: length]; } } @finally { - [self freeMemory: buffer]; + free(buffer); } [data makeImmutable]; return data; @@ -685,38 +685,38 @@ - (OFString *)readStringWithLength: (size_t)length encoding: (of_string_encoding_t)encoding { OFString *ret; - char *buffer = [self allocMemoryWithSize: length + 1]; + char *buffer = of_malloc(length + 1, 1); buffer[length] = 0; @try { [self readIntoBuffer: buffer exactLength: length]; ret = [OFString stringWithCString: buffer encoding: encoding]; } @finally { - [self freeMemory: buffer]; + free(buffer); } return ret; } - (OFString *)tryReadLineWithEncoding: (of_string_encoding_t)encoding { - size_t pageSize, bufferLength, retLength; - char *retCString, *buffer, *readBuffer; + size_t pageSize, bufferLength; + char *buffer, *readBuffer; OFString *ret; /* Look if there's a line or \0 in our buffer */ if (!_waitingForDelimiter && _readBuffer != NULL) { for (size_t i = 0; i < _readBufferLength; i++) { if OF_UNLIKELY (_readBuffer[i] == '\n' || _readBuffer[i] == '\0') { - retLength = i; + size_t retLength = i; if (i > 0 && _readBuffer[i - 1] == '\r') retLength--; ret = [OFString stringWithCString: _readBuffer @@ -732,14 +732,16 @@ } } /* Read and see if we got a newline or \0 */ pageSize = [OFSystemInfo pageSize]; - buffer = [self allocMemoryWithSize: pageSize]; + buffer = of_malloc(1, pageSize); @try { if ([self lowlevelIsAtEndOfStream]) { + size_t retLength; + if (_readBuffer == NULL) { _waitingForDelimiter = false; return nil; } @@ -765,13 +767,12 @@ /* Look if there's a newline or \0 */ for (size_t i = 0; i < bufferLength; i++) { if OF_UNLIKELY (buffer[i] == '\n' || buffer[i] == '\0') { - retLength = _readBufferLength + i; - retCString = [self - allocMemoryWithSize: retLength]; + size_t retLength = _readBufferLength + i; + char *retCString = of_malloc(retLength, 1); if (_readBuffer != NULL) memcpy(retCString, _readBuffer, _readBufferLength); memcpy(retCString + _readBufferLength, @@ -780,17 +781,14 @@ if (retLength > 0 && retCString[retLength - 1] == '\r') retLength--; @try { - char *rcs = retCString; - size_t rl = retLength; - ret = [OFString - stringWithCString: rcs + stringWithCString: retCString encoding: encoding - length: rl]; + length: retLength]; } @catch (id e) { if (bufferLength > 0) { /* * Append data to _readBuffer * to prevent loss of data. @@ -814,11 +812,11 @@ bufferLength; } @throw e; } @finally { - [self freeMemory: retCString]; + free(retCString); } readBuffer = [self allocMemoryWithSize: bufferLength - i - 1]; if (readBuffer != NULL) @@ -846,11 +844,11 @@ [self freeMemory: _readBufferMemory]; _readBuffer = _readBufferMemory = readBuffer; _readBufferLength += bufferLength; } } @finally { - [self freeMemory: buffer]; + free(buffer); } _waitingForDelimiter = true; return nil; } @@ -938,12 +936,12 @@ - (OFString *)tryReadTillDelimiter: (OFString *)delimiter encoding: (of_string_encoding_t)encoding { const char *delimiterCString; - size_t j, delimiterLength, pageSize, bufferLength, retLength; - char *retCString, *buffer, *readBuffer; + size_t j, delimiterLength, pageSize, bufferLength; + char *buffer, *readBuffer; OFString *ret; delimiterCString = [delimiter cStringWithEncoding: encoding]; delimiterLength = [delimiter cStringLengthWithEncoding: encoding]; j = 0; @@ -975,11 +973,11 @@ } } /* Read and see if we got a delimiter or \0 */ pageSize = [OFSystemInfo pageSize]; - buffer = [self allocMemoryWithSize: pageSize]; + buffer = of_malloc(1, pageSize); @try { if ([self lowlevelIsAtEndOfStream]) { if (_readBuffer == NULL) { _waitingForDelimiter = false; @@ -1005,17 +1003,19 @@ for (size_t i = 0; i < bufferLength; i++) { if (buffer[i] != delimiterCString[j++]) j = 0; if (j == delimiterLength || buffer[i] == '\0') { + size_t retLength; + char *retCString; + if (buffer[i] == '\0') delimiterLength = 1; retLength = _readBufferLength + i + 1 - delimiterLength; - retCString = [self - allocMemoryWithSize: retLength]; + retCString = of_malloc(retLength, 1); if (_readBuffer != NULL && _readBufferLength <= retLength) memcpy(retCString, _readBuffer, _readBufferLength); @@ -1025,17 +1025,14 @@ if (i >= delimiterLength) memcpy(retCString + _readBufferLength, buffer, i + 1 - delimiterLength); @try { - char *rcs = retCString; - size_t rl = retLength; - ret = [OFString - stringWithCString: rcs + stringWithCString: retCString encoding: encoding - length: rl]; + length: retLength]; } @catch (id e) { if (bufferLength > 0) { /* * Append data to _readBuffer * to prevent loss of data. @@ -1059,11 +1056,11 @@ bufferLength; } @throw e; } @finally { - [self freeMemory: retCString]; + free(retCString); } readBuffer = [self allocMemoryWithSize: bufferLength - i - 1]; if (readBuffer != NULL) @@ -1091,11 +1088,11 @@ [self freeMemory: _readBufferMemory]; _readBuffer = _readBufferMemory = readBuffer; _readBufferLength += bufferLength; } } @finally { - [self freeMemory: buffer]; + free(buffer); } _waitingForDelimiter = true; return nil; } @@ -1336,21 +1333,20 @@ #ifdef OF_BIG_ENDIAN [self writeBuffer: buffer length: size]; #else - uint16_t *tmp = [self allocMemoryWithSize: sizeof(uint16_t) - count: count]; + uint16_t *tmp = of_malloc(count, sizeof(uint16_t)); @try { for (size_t i = 0; i < count; i++) tmp[i] = OF_BSWAP16(buffer[i]); [self writeBuffer: tmp length: size]; } @finally { - [self freeMemory: tmp]; + free(tmp); } #endif return size; } @@ -1367,21 +1363,20 @@ #ifdef OF_BIG_ENDIAN [self writeBuffer: buffer length: size]; #else - uint32_t *tmp = [self allocMemoryWithSize: sizeof(uint32_t) - count: count]; + uint32_t *tmp = of_malloc(count, sizeof(uint32_t)); @try { for (size_t i = 0; i < count; i++) tmp[i] = OF_BSWAP32(buffer[i]); [self writeBuffer: tmp length: size]; } @finally { - [self freeMemory: tmp]; + free(tmp); } #endif return size; } @@ -1398,21 +1393,20 @@ #ifdef OF_BIG_ENDIAN [self writeBuffer: buffer length: size]; #else - uint64_t *tmp = [self allocMemoryWithSize: sizeof(uint64_t) - count: count]; + uint64_t *tmp = of_malloc(count, sizeof(uint64_t)); @try { for (size_t i = 0; i < count; i++) tmp[i] = OF_BSWAP64(buffer[i]); [self writeBuffer: tmp length: size]; } @finally { - [self freeMemory: tmp]; + free(tmp); } #endif return size; } @@ -1429,21 +1423,20 @@ #ifdef OF_FLOAT_BIG_ENDIAN [self writeBuffer: buffer length: size]; #else - float *tmp = [self allocMemoryWithSize: sizeof(float) - count: count]; + float *tmp = of_malloc(count, sizeof(float)); @try { for (size_t i = 0; i < count; i++) tmp[i] = OF_BSWAP_FLOAT(buffer[i]); [self writeBuffer: tmp length: size]; } @finally { - [self freeMemory: tmp]; + free(tmp); } #endif return size; } @@ -1460,21 +1453,20 @@ #ifdef OF_FLOAT_BIG_ENDIAN [self writeBuffer: buffer length: size]; #else - double *tmp = [self allocMemoryWithSize: sizeof(double) - count: count]; + double *tmp = of_malloc(count, sizeof(double)); @try { for (size_t i = 0; i < count; i++) tmp[i] = OF_BSWAP_DOUBLE(buffer[i]); [self writeBuffer: tmp length: size]; } @finally { - [self freeMemory: tmp]; + free(tmp); } #endif return size; } @@ -1531,21 +1523,20 @@ #ifndef OF_BIG_ENDIAN [self writeBuffer: buffer length: size]; #else - uint16_t *tmp = [self allocMemoryWithSize: sizeof(uint16_t) - count: count]; + uint16_t *tmp = of_malloc(count, sizeof(uint16_t)); @try { for (size_t i = 0; i < count; i++) tmp[i] = OF_BSWAP16(buffer[i]); [self writeBuffer: tmp length: size]; } @finally { - [self freeMemory: tmp]; + free(tmp); } #endif return size; } @@ -1562,21 +1553,20 @@ #ifndef OF_BIG_ENDIAN [self writeBuffer: buffer length: size]; #else - uint32_t *tmp = [self allocMemoryWithSize: sizeof(uint32_t) - count: count]; + uint32_t *tmp = of_malloc(count, sizeof(uint32_t)); @try { for (size_t i = 0; i < count; i++) tmp[i] = OF_BSWAP32(buffer[i]); [self writeBuffer: tmp length: size]; } @finally { - [self freeMemory: tmp]; + free(tmp); } #endif return size; } @@ -1593,21 +1583,20 @@ #ifndef OF_BIG_ENDIAN [self writeBuffer: buffer length: size]; #else - uint64_t *tmp = [self allocMemoryWithSize: sizeof(uint64_t) - count: count]; + uint64_t *tmp = of_malloc(count, sizeof(uint64_t)); @try { for (size_t i = 0; i < count; i++) tmp[i] = OF_BSWAP64(buffer[i]); [self writeBuffer: tmp length: size]; } @finally { - [self freeMemory: tmp]; + free(tmp); } #endif return size; } @@ -1624,21 +1613,20 @@ #ifndef OF_FLOAT_BIG_ENDIAN [self writeBuffer: buffer length: size]; #else - float *tmp = [self allocMemoryWithSize: sizeof(float) - count: count]; + float *tmp = of_malloc(count, sizeof(float)); @try { for (size_t i = 0; i < count; i++) tmp[i] = OF_BSWAP_FLOAT(buffer[i]); [self writeBuffer: tmp length: size]; } @finally { - [self freeMemory: tmp]; + free(tmp); } #endif return size; } @@ -1655,21 +1643,20 @@ #ifndef OF_FLOAT_BIG_ENDIAN [self writeBuffer: buffer length: size]; #else - double *tmp = [self allocMemoryWithSize: sizeof(double) - count: count]; + double *tmp = of_malloc(count, sizeof(double)); @try { for (size_t i = 0; i < count; i++) tmp[i] = OF_BSWAP_DOUBLE(buffer[i]); [self writeBuffer: tmp length: size]; } @finally { - [self freeMemory: tmp]; + free(tmp); } #endif return size; } @@ -1729,21 +1716,21 @@ encoding: (of_string_encoding_t)encoding { size_t stringLength = [string cStringLengthWithEncoding: encoding]; char *buffer; - buffer = [self allocMemoryWithSize: stringLength + 1]; + buffer = of_malloc(stringLength + 1, 1); @try { memcpy(buffer, [string cStringWithEncoding: encoding], stringLength); buffer[stringLength] = '\n'; [self writeBuffer: buffer length: stringLength + 1]; } @finally { - [self freeMemory: buffer]; + free(buffer); } return stringLength + 1; } Index: src/OFString+JSONParsing.m ================================================================== --- src/OFString+JSONParsing.m +++ src/OFString+JSONParsing.m @@ -146,11 +146,11 @@ char delimiter = **pointer; if (++(*pointer) + 1 >= stop) return nil; - buffer = of_malloc(1, stop - *pointer); + buffer = of_malloc(stop - *pointer, 1); while (*pointer < stop) { /* Parse escape codes */ if (**pointer == '\\') { if (++(*pointer) >= stop) { @@ -292,11 +292,11 @@ parseIdentifier(const char **pointer, const char *stop) { char *buffer; size_t i = 0; - buffer = of_malloc(1, stop - *pointer); + buffer = of_malloc(stop - *pointer, 1); while (*pointer < stop) { if ((**pointer >= 'a' && **pointer <= 'z') || (**pointer >= 'A' && **pointer <= 'Z') || (**pointer >= '0' && **pointer <= '9') || Index: src/OFString+URLEncoding.m ================================================================== --- src/OFString+URLEncoding.m +++ src/OFString+URLEncoding.m @@ -87,11 +87,11 @@ char *retCString; char byte = 0; int state = 0; size_t i = 0; - retCString = of_malloc(1, length + 1); + retCString = of_malloc(length + 1, 1); while (length--) { char c = *string++; switch (state) { Index: src/OFString+XMLEscaping.m ================================================================== --- src/OFString+XMLEscaping.m +++ src/OFString+XMLEscaping.m @@ -40,15 +40,11 @@ string = self.UTF8String; length = self.UTF8StringLength; j = 0; retLength = length; - - /* - * We can't use allocMemoryWithSize: here as it might be a @"" literal - */ - retCString = of_malloc(1, retLength); + retCString = of_malloc(retLength, 1); for (size_t i = 0; i < length; i++) { switch (string[i]) { case '<': append = "<"; Index: src/OFString.m ================================================================== --- src/OFString.m +++ src/OFString.m @@ -1027,11 +1027,11 @@ * to use -[initWithUTF8StringNoCopy:length:freeWhenDone:]. */ if (SIZE_MAX - (size_t)fileSize < 1) @throw [OFOutOfRangeException exception]; - tmp = of_malloc(1, (size_t)fileSize + 1); + tmp = of_malloc((size_t)fileSize + 1, 1); @try { file = [[OFFile alloc] initWithPath: path mode: @"r"]; [file readIntoBuffer: tmp @@ -2166,12 +2166,11 @@ bool hasPrefix; if ((prefixLength = prefix.length) > self.length) return false; - tmp = [self allocMemoryWithSize: sizeof(of_unichar_t) - count: prefixLength]; + tmp = of_malloc(prefixLength, sizeof(of_unichar_t)); @try { void *pool = objc_autoreleasePoolPush(); [self getCharacters: tmp inRange: of_range(0, prefixLength)]; @@ -2179,11 +2178,11 @@ hasPrefix = (memcmp(tmp, prefix.characters, prefixLength * sizeof(of_unichar_t)) == 0); objc_autoreleasePoolPop(pool); } @finally { - [self freeMemory: tmp]; + free(tmp); } return hasPrefix; } @@ -2197,12 +2196,11 @@ if ((suffixLength = suffix.length) > self.length) return false; length = self.length; - tmp = [self allocMemoryWithSize: sizeof(of_unichar_t) - count: suffixLength]; + tmp = of_malloc(suffixLength, sizeof(of_unichar_t)); @try { void *pool = objc_autoreleasePoolPush(); [self getCharacters: tmp inRange: of_range(length - suffixLength, @@ -2212,11 +2210,11 @@ hasSuffix = (memcmp(tmp, suffixCharacters, suffixLength * sizeof(of_unichar_t)) == 0); objc_autoreleasePoolPop(pool); } @finally { - [self freeMemory: tmp]; + free(tmp); } return hasSuffix; } Index: src/OFWin32ConsoleStdIOStream.m ================================================================== --- src/OFWin32ConsoleStdIOStream.m +++ src/OFWin32ConsoleStdIOStream.m @@ -135,12 +135,11 @@ size_t j = 0; if (length > UINT32_MAX) @throw [OFOutOfRangeException exception]; - UTF16 = [self allocMemoryWithSize: sizeof(of_char16_t) - count: length]; + UTF16 = of_malloc(length, sizeof(of_char16_t)); @try { DWORD UTF16Len; OFMutableData *rest = nil; size_t i = 0; @@ -258,11 +257,11 @@ if (rest != nil) [self unreadFromBuffer: rest.items length: rest.count]; } @finally { - [self freeMemory: UTF16]; + free(UTF16); } objc_autoreleasePoolPop(pool); return j; @@ -363,12 +362,11 @@ _incompleteUTF8SurrogateLen = 0; i += toCopy; } - tmp = [self allocMemoryWithSize: sizeof(of_char16_t) - count: length * 2]; + tmp = of_malloc(length * 2, sizeof(of_char16_t)); @try { DWORD bytesWritten; while (i < length) { of_unichar_t c; @@ -443,11 +441,11 @@ exceptionWithObject: self requestedLength: j * 2 bytesWritten: bytesWritten * 2 errNo: 0]; } @finally { - [self freeMemory: tmp]; + free(tmp); } /* * We do not count in bytes when writing to the Win32 console. But * since any incomplete write is an exception here anyway, we can just Index: src/OFXMLComment.m ================================================================== --- src/OFXMLComment.m +++ src/OFXMLComment.m @@ -114,21 +114,20 @@ level: (unsigned int)level { OFString *ret; if (indentation > 0 && level > 0) { - char *whitespaces = [self allocMemoryWithSize: - (level * indentation) + 1]; + char *whitespaces = of_malloc((level * indentation) + 1, 1); memset(whitespaces, ' ', level * indentation); whitespaces[level * indentation] = 0; @try { ret = [OFString stringWithFormat: @"%s", whitespaces, _comment]; } @finally { - [self freeMemory: whitespaces]; + free(whitespaces); } } else ret = [OFString stringWithFormat: @"", _comment]; return ret; Index: src/OFXMLElement.m ================================================================== --- src/OFXMLElement.m +++ src/OFXMLElement.m @@ -46,13 +46,10 @@ _references_to_categories_of_OFXMLElement(void) { _OFXMLElement_Serialization_reference = 1; } -static Class charactersClass = Nil; -static Class CDATAClass = Nil; - @interface OFXMLElementElementBuilderDelegate: OFObject { @public OFXMLElement *_element; @@ -77,18 +74,10 @@ @implementation OFXMLElement @synthesize name = _name, namespace = _namespace; @synthesize defaultNamespace = _defaultNamespace; -+ (void)initialize -{ - if (self == [OFXMLElement class]) { - charactersClass = [OFXMLCharacters class]; - CDATAClass = [OFXMLCDATA class]; - } -} - + (instancetype)elementWithName: (OFString *)name { return [[[self alloc] initWithName: name] autorelease]; } @@ -424,11 +413,11 @@ return ret; } - (OFString *)of_XMLStringWithParent: (OFXMLElement *)parent - namespaces: (OFDictionary *)allNamespaces + namespaces: (OFDictionary *)allNS indentation: (unsigned int)indentation level: (unsigned int)level OF_DIRECT { void *pool; char *cString; @@ -437,33 +426,33 @@ OFString *ret; OFString *defaultNS; pool = objc_autoreleasePoolPush(); - parentPrefix = [allNamespaces objectForKey: + parentPrefix = [allNS objectForKey: (parent != nil && parent->_namespace != nil ? parent->_namespace : (OFString *)@"")]; /* Add the namespaces of the current element */ - if (allNamespaces != nil) { + if (allNS != nil) { OFEnumerator *keyEnumerator = [_namespaces keyEnumerator]; OFEnumerator *objectEnumerator = [_namespaces objectEnumerator]; OFMutableDictionary *tmp; OFString *key, *object; - tmp = [[allNamespaces mutableCopy] autorelease]; + tmp = [[allNS mutableCopy] autorelease]; while ((key = [keyEnumerator nextObject]) != nil && (object = [objectEnumerator nextObject]) != nil) [tmp setObject: object forKey: key]; - allNamespaces = tmp; + allNS = tmp; } else - allNamespaces = _namespaces; + allNS = _namespaces; - prefix = [allNamespaces objectForKey: + prefix = [allNS objectForKey: (_namespace != nil ? _namespace : (OFString *)@"")]; if (parent != nil && parent->_namespace != nil && parentPrefix == nil) defaultNS = parent->_namespace; else if (parent != nil && parent->_defaultNamespace != nil) @@ -471,198 +460,178 @@ else defaultNS = _defaultNamespace; i = 0; 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 && ![_namespace isEqual: defaultNS]) { - length += prefix.UTF8StringLength + 1; - @try { - cString = [self resizeMemory: cString - size: length]; - } @catch (id e) { - [self freeMemory: cString]; - @throw e; - } - - memcpy(cString + i, prefix.UTF8String, prefix.UTF8StringLength); - i += prefix.UTF8StringLength; - cString[i++] = ':'; - } - - memcpy(cString + i, _name.UTF8String, _name.UTF8StringLength); - i += _name.UTF8StringLength; - - /* xmlns if necessary */ - 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]; - @throw e; - } - - memcpy(cString + i, " xmlns='", 8); - i += 8; - memcpy(cString + i, _namespace.UTF8String, - _namespace.UTF8StringLength); - i += _namespace.UTF8StringLength; - cString[i++] = '\''; - } - - /* Attributes */ - for (OFXMLAttribute *attribute in _attributes) { - void *pool2 = objc_autoreleasePoolPush(); - const char *attributeNameCString = attribute->_name.UTF8String; - size_t attributeNameLength = attribute->_name.UTF8StringLength; - OFString *attributePrefix = nil; - OFString *tmp = attribute.stringValue.stringByXMLEscaping; - char delimiter = (attribute->_useDoubleQuotes ? '"' : '\''); - - if (attribute->_namespace != nil && - (attributePrefix = [allNamespaces objectForKey: - attribute->_namespace]) == nil) - @throw [OFUnboundNamespaceException - exceptionWithNamespace: [attribute namespace] - element: self]; - - length += attributeNameLength + (attributePrefix != nil - ? attributePrefix.UTF8StringLength + 1 : 0) + - tmp.UTF8StringLength + 4; - - @try { - cString = [self resizeMemory: cString - size: length]; - } @catch (id e) { - [self freeMemory: cString]; - @throw e; - } - - cString[i++] = ' '; - if (attributePrefix != nil) { - memcpy(cString + i, attributePrefix.UTF8String, - attributePrefix.UTF8StringLength); - i += attributePrefix.UTF8StringLength; - cString[i++] = ':'; - } - memcpy(cString + i, attributeNameCString, attributeNameLength); - i += attributeNameLength; - cString[i++] = '='; - cString[i++] = delimiter; - memcpy(cString + i, tmp.UTF8String, tmp.UTF8StringLength); - i += tmp.UTF8StringLength; - cString[i++] = delimiter; - - objc_autoreleasePoolPop(pool2); - } - - /* Children */ - if (_children != nil) { - OFMutableData *tmp = [OFMutableData data]; - bool indent; - - if (indentation > 0) { - indent = true; - - for (OFXMLNode *child in _children) { - if ([child isKindOfClass: charactersClass] || - [child isKindOfClass: CDATAClass]) { - indent = false; - break; - } - } - } else - indent = false; - - for (OFXMLNode *child in _children) { - OFString *childString; - unsigned int ind = (indent ? indentation : 0); - - if (ind) - [tmp addItem: "\n"]; - - if ([child isKindOfClass: [OFXMLElement class]]) - childString = [(OFXMLElement *)child - of_XMLStringWithParent: self - namespaces: allNamespaces - indentation: ind - level: level + 1]; - else - childString = [child - XMLStringWithIndentation: ind - level: level + 1]; - - [tmp addItems: childString.UTF8String - count: childString.UTF8StringLength]; - } - - if (indent) - [tmp addItem: "\n"]; - - length += tmp.count + _name.UTF8StringLength + 2 + - (indent ? level * indentation : 0); - @try { - cString = [self resizeMemory: cString - size: length]; - } @catch (id e) { - [self freeMemory: cString]; - @throw e; - } - - cString[i++] = '>'; - - memcpy(cString + i, tmp.items, tmp.count); - i += tmp.count; - - if (indent) { - memset(cString + i, ' ', level * indentation); - i += level * indentation; - } - - cString[i++] = '<'; - cString[i++] = '/'; - if (prefix != nil) { - length += prefix.UTF8StringLength + 1; - @try { - cString = [self resizeMemory: cString - size: length]; - } @catch (id e) { - [self freeMemory: cString]; - @throw e; - } + cString = of_malloc(length, 1); + + @try { + memset(cString + i, ' ', level * indentation); + i += level * indentation; + + /* Start of tag */ + cString[i++] = '<'; + + if (prefix != nil && ![_namespace isEqual: defaultNS]) { + length += prefix.UTF8StringLength + 1; + cString = of_realloc(cString, length, 1); memcpy(cString + i, prefix.UTF8String, prefix.UTF8StringLength); i += prefix.UTF8StringLength; cString[i++] = ':'; } + memcpy(cString + i, _name.UTF8String, _name.UTF8StringLength); i += _name.UTF8StringLength; - } else - cString[i++] = '/'; - - cString[i++] = '>'; - assert(i == length); - - objc_autoreleasePoolPop(pool); - - @try { + + /* xmlns if necessary */ + if (prefix == nil && ((_namespace != nil && + ![_namespace isEqual: defaultNS]) || + (_namespace == nil && defaultNS != nil))) { + length += _namespace.UTF8StringLength + 9; + cString = of_realloc(cString, length, 1); + + memcpy(cString + i, " xmlns='", 8); + i += 8; + memcpy(cString + i, _namespace.UTF8String, + _namespace.UTF8StringLength); + i += _namespace.UTF8StringLength; + cString[i++] = '\''; + } + + /* Attributes */ + for (OFXMLAttribute *attribute in _attributes) { + void *pool2 = objc_autoreleasePoolPush(); + const char *attributeNameCString = + attribute->_name.UTF8String; + size_t attributeNameLength = + attribute->_name.UTF8StringLength; + OFString *attributePrefix = nil; + OFString *tmp = + attribute.stringValue.stringByXMLEscaping; + char delimiter = (attribute->_useDoubleQuotes + ? '"' : '\''); + + if (attribute->_namespace != nil && + (attributePrefix = [allNS objectForKey: + attribute->_namespace]) == nil) + @throw [OFUnboundNamespaceException + exceptionWithNamespace: attribute.namespace + element: self]; + + length += attributeNameLength + (attributePrefix != nil + ? attributePrefix.UTF8StringLength + 1 : 0) + + tmp.UTF8StringLength + 4; + cString = of_realloc(cString, length, 1); + + cString[i++] = ' '; + if (attributePrefix != nil) { + memcpy(cString + i, attributePrefix.UTF8String, + attributePrefix.UTF8StringLength); + i += attributePrefix.UTF8StringLength; + cString[i++] = ':'; + } + memcpy(cString + i, attributeNameCString, + attributeNameLength); + i += attributeNameLength; + cString[i++] = '='; + cString[i++] = delimiter; + memcpy(cString + i, tmp.UTF8String, + tmp.UTF8StringLength); + i += tmp.UTF8StringLength; + cString[i++] = delimiter; + + objc_autoreleasePoolPop(pool2); + } + + /* Children */ + if (_children != nil) { + OFMutableData *tmp = [OFMutableData data]; + bool indent; + + if (indentation > 0) { + indent = true; + + for (OFXMLNode *child in _children) { + if ([child isKindOfClass: + [OFXMLCharacters class]] || + [child isKindOfClass: + [OFXMLCDATA class]]) { + indent = false; + break; + } + } + } else + indent = false; + + for (OFXMLNode *child in _children) { + OFString *childString; + unsigned int ind = (indent ? indentation : 0); + + if (ind) + [tmp addItem: "\n"]; + + if ([child isKindOfClass: [OFXMLElement class]]) + childString = [(OFXMLElement *)child + of_XMLStringWithParent: self + namespaces: allNS + indentation: ind + level: level + 1]; + else + childString = [child + XMLStringWithIndentation: ind + level: level + + 1]; + + [tmp addItems: childString.UTF8String + count: childString.UTF8StringLength]; + } + + if (indent) + [tmp addItem: "\n"]; + + length += tmp.count + _name.UTF8StringLength + 2 + + (indent ? level * indentation : 0); + cString = of_realloc(cString, length, 1); + + cString[i++] = '>'; + + memcpy(cString + i, tmp.items, tmp.count); + i += tmp.count; + + if (indent) { + memset(cString + i, ' ', level * indentation); + i += level * indentation; + } + + cString[i++] = '<'; + cString[i++] = '/'; + if (prefix != nil) { + length += prefix.UTF8StringLength + 1; + cString = of_realloc(cString, length, 1); + + memcpy(cString + i, prefix.UTF8String, + prefix.UTF8StringLength); + i += prefix.UTF8StringLength; + cString[i++] = ':'; + } + memcpy(cString + i, _name.UTF8String, + _name.UTF8StringLength); + i += _name.UTF8StringLength; + } else + cString[i++] = '/'; + + cString[i++] = '>'; + assert(i == length); + + objc_autoreleasePoolPop(pool); + ret = [OFString stringWithUTF8String: cString length: length]; } @finally { - [self freeMemory: cString]; + free(cString); } return ret; } - (OFString *)XMLString Index: src/OFXMLParser.m ================================================================== --- src/OFXMLParser.m +++ src/OFXMLParser.m @@ -276,11 +276,11 @@ } - (void)parseStream: (OFStream *)stream { size_t pageSize = [OFSystemInfo pageSize]; - char *buffer = [self allocMemoryWithSize: pageSize]; + char *buffer = of_malloc(1, pageSize); @try { while (!stream.atEndOfStream) { size_t length = [stream readIntoBuffer: buffer length: pageSize]; @@ -287,11 +287,11 @@ [self parseBuffer: buffer length: length]; } } @finally { - [self freeMemory: buffer]; + free(buffer); } } #ifdef OF_HAVE_FILES - (void)parseFile: (OFString *)path Index: src/OFXMLProcessingInstructions.m ================================================================== --- src/OFXMLProcessingInstructions.m +++ src/OFXMLProcessingInstructions.m @@ -115,20 +115,19 @@ level: (unsigned int)level { OFString *ret; if (indentation > 0 && level > 0) { - char *whitespaces = [self allocMemoryWithSize: - (level * indentation) + 1]; + char *whitespaces = of_malloc((level * indentation) + 1, 1); memset(whitespaces, ' ', level * indentation); whitespaces[level * indentation] = 0; @try { ret = [OFString stringWithFormat: @"%s", whitespaces, _processingInstructions]; } @finally { - [self freeMemory: whitespaces]; + free(whitespaces); } } else ret = [OFString stringWithFormat: @"", _processingInstructions]; Index: src/platform/windows/OFProcess.m ================================================================== --- src/platform/windows/OFProcess.m +++ src/platform/windows/OFProcess.m @@ -193,13 +193,11 @@ si.hStdOutput = _readPipe[1]; si.hStdError = GetStdHandle(STD_ERROR_HANDLE); si.dwFlags |= STARTF_USESTDHANDLES; length = argumentsString.UTF16StringLength; - argumentsCopy = [self - allocMemoryWithSize: sizeof(of_char16_t) - count: length + 1]; + argumentsCopy = of_malloc(length + 1, sizeof(of_char16_t)); memcpy(argumentsCopy, argumentsString.UTF16String, (length + 1) * 2); @try { if (!CreateProcessW(program.UTF16String, argumentsCopy, NULL, NULL, TRUE, @@ -207,11 +205,11 @@ [self of_wideEnvironmentForDictionary: environment], NULL, &si, &pi)) @throw [OFInitializationFailedException exceptionWithClass: self.class]; } @finally { - [self freeMemory: argumentsCopy]; + free(argumentsCopy); } } else { of_string_encoding_t encoding = [OFLocale encoding]; STARTUPINFO si;