@@ -44,11 +44,11 @@ freeWhenDone: (bool)freeWhenDone { self = [self initWithUTF8String: UTF8String]; if (freeWhenDone) - free(UTF8String); + OFFreeMemory(UTF8String); return self; } - (instancetype)initWithUTF8StringNoCopy: (char *)UTF8String @@ -56,11 +56,11 @@ freeWhenDone: (bool)freeWhenDone { self = [self initWithUTF8String: UTF8String length: UTF8StringLength]; if (freeWhenDone) - free(UTF8String); + OFFreeMemory(UTF8String); return self; } #ifdef OF_HAVE_UNICODE_TABLES @@ -97,11 +97,11 @@ return; } unicodeLen = self.length; - unicodeString = of_alloc(unicodeLen, sizeof(OFUnichar)); + unicodeString = OFAllocMemory(unicodeLen, sizeof(OFUnichar)); i = j = 0; newCStringLength = 0; while (i < _s->cStringLength) { @@ -120,11 +120,11 @@ cLen = of_string_utf8_decode(_s->cString + i, _s->cStringLength - i, &c); if (cLen <= 0 || c > 0x10FFFF) { - free(unicodeString); + OFFreeMemory(unicodeString); @throw [OFInvalidEncodingException exception]; } isStart = of_ascii_isspace(c); @@ -143,21 +143,21 @@ else if (c < 0x10000) newCStringLength += 3; else if (c < 0x110000) newCStringLength += 4; else { - free(unicodeString); + OFFreeMemory(unicodeString); @throw [OFInvalidEncodingException exception]; } i += cLen; } @try { - newCString = of_alloc(newCStringLength + 1, 1); + newCString = OFAllocMemory(newCStringLength + 1, 1); } @catch (id e) { - free(unicodeString); + OFFreeMemory(unicodeString); @throw e; } j = 0; @@ -164,22 +164,22 @@ for (i = 0; i < unicodeLen; i++) { size_t d; if ((d = of_string_utf8_encode(unicodeString[i], newCString + j)) == 0) { - free(unicodeString); - free(newCString); + OFFreeMemory(unicodeString); + OFFreeMemory(newCString); @throw [OFInvalidEncodingException exception]; } j += d; } assert(j == newCStringLength); newCString[j] = 0; - free(unicodeString); + OFFreeMemory(unicodeString); - free(_s->cString); + OFFreeMemory(_s->cString); _s->hashed = false; _s->cString = newCString; _s->cStringLength = newCStringLength; /* @@ -220,11 +220,11 @@ _s->hashed = false; if (lenNew == (size_t)lenOld) memcpy(_s->cString + idx, buffer, lenNew); else if (lenNew > (size_t)lenOld) { - _s->cString = of_realloc(_s->cString, + _s->cString = OFResizeMemory(_s->cString, _s->cStringLength - lenOld + lenNew + 1, 1); memmove(_s->cString + idx + lenNew, _s->cString + idx + lenOld, _s->cStringLength - idx - lenOld); memcpy(_s->cString + idx, buffer, lenNew); @@ -246,11 +246,11 @@ if (character >= 0x80) _s->isUTF8 = true; @try { - _s->cString = of_realloc(_s->cString, + _s->cString = OFResizeMemory(_s->cString, _s->cStringLength + 1, 1); } @catch (OFOutOfMemoryException *e) { /* We don't really care, as we only made it smaller */ } } @@ -274,11 +274,11 @@ case -1: @throw [OFInvalidEncodingException exception]; } _s->hashed = false; - _s->cString = of_realloc(_s->cString, + _s->cString = OFResizeMemory(_s->cString, _s->cStringLength + UTF8StringLength + 1, 1); memcpy(_s->cString + _s->cStringLength, UTF8String, UTF8StringLength + 1); _s->cStringLength += UTF8StringLength; @@ -303,11 +303,11 @@ case -1: @throw [OFInvalidEncodingException exception]; } _s->hashed = false; - _s->cString = of_realloc(_s->cString, + _s->cString = OFResizeMemory(_s->cString, _s->cStringLength + UTF8StringLength + 1, 1); memcpy(_s->cString + _s->cStringLength, UTF8String, UTF8StringLength); _s->cStringLength += UTF8StringLength; _s->length += length; @@ -349,11 +349,11 @@ @throw [OFInvalidArgumentException exception]; UTF8StringLength = string.UTF8StringLength; _s->hashed = false; - _s->cString = of_realloc(_s->cString, + _s->cString = OFResizeMemory(_s->cString, _s->cStringLength + UTF8StringLength + 1, 1); memcpy(_s->cString + _s->cStringLength, string.UTF8String, UTF8StringLength); _s->cStringLength += UTF8StringLength; @@ -367,14 +367,13 @@ _s->isUTF8 = true; } else _s->isUTF8 = true; } -- (void)appendCharacters: (const OFUnichar *)characters - length: (size_t)length +- (void)appendCharacters: (const OFUnichar *)characters length: (size_t)length { - char *tmp = of_alloc((length * 4) + 1, 1); + char *tmp = OFAllocMemory((length * 4) + 1, 1); @try { size_t j = 0; bool isUTF8 = false; @@ -392,21 +391,21 @@ } tmp[j] = '\0'; _s->hashed = false; - _s->cString = of_realloc(_s->cString, + _s->cString = OFResizeMemory(_s->cString, _s->cStringLength + j + 1, 1); memcpy(_s->cString + _s->cStringLength, tmp, j + 1); _s->cStringLength += j; _s->length += length; if (isUTF8) _s->isUTF8 = true; } @finally { - free(tmp); + OFFreeMemory(tmp); } } - (void)appendFormat: (OFConstantString *)format arguments: (va_list)arguments { @@ -518,11 +517,11 @@ idx = of_string_utf8_get_position(_s->cString, idx, _s->cStringLength); newCStringLength = _s->cStringLength + string.UTF8StringLength; _s->hashed = false; - _s->cString = of_realloc(_s->cString, newCStringLength + 1, 1); + _s->cString = OFResizeMemory(_s->cString, newCStringLength + 1, 1); memmove(_s->cString + idx + string.UTF8StringLength, _s->cString + idx, _s->cStringLength - idx); memcpy(_s->cString + idx, string.UTF8String, string.UTF8StringLength); @@ -560,11 +559,12 @@ _s->length -= range.length; _s->cStringLength -= end - start; _s->cString[_s->cStringLength] = 0; @try { - _s->cString = of_realloc(_s->cString, _s->cStringLength + 1, 1); + _s->cString = OFResizeMemory(_s->cString, _s->cStringLength + 1, + 1); } @catch (OFOutOfMemoryException *e) { /* We don't really care, as we only made it smaller */ } } @@ -601,11 +601,12 @@ * We must not resize the string if the new string is smaller, because * then we can't memmove() the rest of the string forward as the rest is * lost due to the resize! */ if (newCStringLength > _s->cStringLength) - _s->cString = of_realloc(_s->cString, newCStringLength + 1, 1); + _s->cString = OFResizeMemory(_s->cString, newCStringLength + 1, + 1); memmove(_s->cString + start + replacement.UTF8StringLength, _s->cString + end, _s->cStringLength - end); memcpy(_s->cString + start, replacement.UTF8String, replacement.UTF8StringLength); @@ -614,11 +615,12 @@ /* * If the new string is smaller, we can safely resize it now as we're * done with memmove(). */ if (newCStringLength < _s->cStringLength) - _s->cString = of_realloc(_s->cString, newCStringLength + 1, 1); + _s->cString = OFResizeMemory(_s->cString, newCStringLength + 1, + 1); _s->cStringLength = newCStringLength; _s->length = newLength; if ([replacement isKindOfClass: [OFUTF8String class]] || @@ -667,15 +669,15 @@ for (size_t i = range.location; i <= range.length - searchLength; i++) { if (memcmp(_s->cString + i, searchString, searchLength) != 0) continue; @try { - newCString = of_realloc(newCString, + newCString = OFResizeMemory(newCString, newCStringLength + i - last + replacementLength + 1, 1); } @catch (id e) { - free(newCString); + OFFreeMemory(newCString); @throw e; } memcpy(newCString + newCStringLength, _s->cString + last, i - last); memcpy(newCString + newCStringLength + i - last, @@ -687,22 +689,22 @@ i += searchLength - 1; last = i + 1; } @try { - newCString = of_realloc(newCString, + newCString = OFResizeMemory(newCString, newCStringLength + _s->cStringLength - last + 1, 1); } @catch (id e) { - free(newCString); + OFFreeMemory(newCString); @throw e; } memcpy(newCString + newCStringLength, _s->cString + last, _s->cStringLength - last); newCStringLength += _s->cStringLength - last; newCString[newCStringLength] = 0; - free(_s->cString); + OFFreeMemory(_s->cString); _s->hashed = false; _s->cString = newCString; _s->cStringLength = newCStringLength; _s->length = newLength; @@ -728,11 +730,12 @@ memmove(_s->cString, _s->cString + i, _s->cStringLength); _s->cString[_s->cStringLength] = '\0'; @try { - _s->cString = of_realloc(_s->cString, _s->cStringLength + 1, 1); + _s->cString = OFResizeMemory(_s->cString, _s->cStringLength + 1, + 1); } @catch (OFOutOfMemoryException *e) { /* We don't really care, as we only made it smaller */ } } @@ -754,11 +757,12 @@ _s->cStringLength -= d; _s->length -= d; @try { - _s->cString = of_realloc(_s->cString, _s->cStringLength + 1, 1); + _s->cString = OFResizeMemory(_s->cString, _s->cStringLength + 1, + 1); } @catch (OFOutOfMemoryException *e) { /* We don't really care, as we only made it smaller */ } } @@ -790,11 +794,12 @@ memmove(_s->cString, _s->cString + i, _s->cStringLength); _s->cString[_s->cStringLength] = '\0'; @try { - _s->cString = of_realloc(_s->cString, _s->cStringLength + 1, 1); + _s->cString = OFResizeMemory(_s->cString, _s->cStringLength + 1, + 1); } @catch (OFOutOfMemoryException *e) { /* We don't really care, as we only made it smaller */ } }