Index: src/OFArray.m ================================================================== --- src/OFArray.m +++ src/OFArray.m @@ -244,12 +244,12 @@ size_t count; id *buffer; container = [[[OFObject alloc] init] autorelease]; count = [self count]; - buffer = [container allocMemoryForNItems: [self count] - ofSize: sizeof(*buffer)]; + buffer = [container allocMemoryWithItemSize: sizeof(*buffer) + count: [self count]]; [self getObjects: buffer inRange: of_range(0, count)]; return buffer; @@ -333,12 +333,12 @@ if (![self isKindOfClass: [OFMutableArray class]]) return [OFArray_subarray arrayWithArray: self range: range]; - buffer = [self allocMemoryForNItems: range.length - ofSize: sizeof(*buffer)]; + buffer = [self allocMemoryWithItemSize: sizeof(*buffer) + count: range.length]; @try { [self getObjects: buffer inRange: range]; @@ -607,12 +607,12 @@ #ifdef OF_HAVE_BLOCKS - (OFArray*)mappedArrayUsingBlock: (of_array_map_block_t)block { OFArray *ret; size_t count = [self count]; - id *tmp = [self allocMemoryForNItems: count - ofSize: sizeof(id)]; + id *tmp = [self allocMemoryWithItemSize: sizeof(id) + count: count]; @try { [self enumerateObjectsUsingBlock: ^ (id object, size_t index, BOOL *stop) { tmp[index] = block(object, index); @@ -629,12 +629,12 @@ - (OFArray*)filteredArrayUsingBlock: (of_array_filter_block_t)block { OFArray *ret; size_t count = [self count]; - id *tmp = [self allocMemoryForNItems: count - ofSize: sizeof(id)]; + id *tmp = [self allocMemoryWithItemSize: sizeof(id) + count: count]; @try { __block size_t i = 0; [self enumerateObjectsUsingBlock: ^ (id object, size_t index, Index: src/OFAutoreleasePool.m ================================================================== --- src/OFAutoreleasePool.m +++ src/OFAutoreleasePool.m @@ -119,12 +119,12 @@ if (previousPool != nil) previousPool->nextPool = self; size = GROW_SIZE; - objects = [self allocMemoryForNItems: GROW_SIZE - ofSize: sizeof(id)]; + objects = [self allocMemoryWithItemSize: sizeof(id) + count: GROW_SIZE]; } @catch (id e) { [self release]; @throw e; } @@ -133,12 +133,12 @@ - (void)_addObject: (id)object { if (count + 1 > size) { objects = [self resizeMemory: objects - toNItems: size + GROW_SIZE - ofSize: sizeof(id)]; + itemSize: sizeof(id) + count: size + GROW_SIZE]; size += GROW_SIZE; } objects[count] = object; count++; Index: src/OFDataArray.m ================================================================== --- src/OFDataArray.m +++ src/OFDataArray.m @@ -255,12 +255,12 @@ { if (SIZE_MAX - count < 1) @throw [OFOutOfRangeException exceptionWithClass: isa]; data = [self resizeMemory: data - toNItems: count + 1 - ofSize: itemSize]; + itemSize: itemSize + count: count + 1]; memcpy(data + count * itemSize, item, itemSize); count++; } @@ -278,12 +278,12 @@ { if (nItems > SIZE_MAX - count) @throw [OFOutOfRangeException exceptionWithClass: isa]; data = [self resizeMemory: data - toNItems: count + nItems - ofSize: itemSize]; + itemSize: itemSize + count: count + nItems]; memcpy(data + count * itemSize, cArray, nItems * itemSize); count += nItems; } @@ -293,12 +293,12 @@ { if (nItems > SIZE_MAX - count || index > count) @throw [OFOutOfRangeException exceptionWithClass: isa]; data = [self resizeMemory: data - toNItems: count + nItems - ofSize: itemSize]; + itemSize: itemSize + count: count + nItems]; memmove(data + (index + nItems) * itemSize, data + index * itemSize, (count - index) * itemSize); memcpy(data + index * itemSize, cArray, nItems * itemSize); @@ -320,12 +320,12 @@ (count - range.start - range.length) * itemSize); count -= range.length; @try { data = [self resizeMemory: data - toNItems: count - ofSize: itemSize]; + itemSize: itemSize + count: count]; } @catch (OFOutOfMemoryException *e) { /* We don't really care, as we only made it smaller */ } } @@ -335,12 +335,12 @@ @throw [OFOutOfRangeException exceptionWithClass: isa]; count--; @try { data = [self resizeMemory: data - toNItems: count - ofSize: itemSize]; + itemSize: itemSize + count: count]; } @catch (OFOutOfMemoryException *e) { /* We don't care, as we only made it smaller */ } } @@ -567,12 +567,11 @@ newSize = (count * itemSize + lastPageByte) & ~lastPageByte; if (size != newSize) { @try { data = [self resizeMemory: data - toNItems: count - ofSize: newSize]; + toSize: newSize]; } @catch (OFOutOfMemoryException *e) { /* We don't care, as we only made it smaller */ } size = newSize; Index: src/OFDictionary.m ================================================================== --- src/OFDictionary.m +++ src/OFDictionary.m @@ -350,12 +350,12 @@ } - (OFArray*)allKeys { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; - id *keys = [self allocMemoryForNItems: [self count] - ofSize: sizeof(id)]; + id *keys = [self allocMemoryWithItemSize: sizeof(id) + count: [self count]]; OFArray *ret; OFEnumerator *enumerator; id key; size_t i = 0; @@ -380,12 +380,12 @@ } - (OFArray*)allObjects { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; - id *objects = [self allocMemoryForNItems: [self count] - ofSize: sizeof(id)]; + id *objects = [self allocMemoryWithItemSize: sizeof(id) + count: [self count]]; OFArray *ret; OFEnumerator *enumerator; id object; size_t i = 0; Index: src/OFDictionary_hashtable.m ================================================================== --- src/OFDictionary_hashtable.m +++ src/OFDictionary_hashtable.m @@ -79,12 +79,12 @@ exceptionWithClass: isa selector: _cmd]; hashtable = (OFDictionary_hashtable*)dictionary; - data = [self allocMemoryForNItems: hashtable->size - ofSize: sizeof(*data)]; + data = [self allocMemoryWithItemSize: sizeof(*data) + count: hashtable->size]; for (i = 0; i < hashtable->size; i++) data[i] = NULL; size = hashtable->size; @@ -139,12 +139,12 @@ newSize <<= 1; if (newSize == 0) @throw [OFOutOfRangeException exceptionWithClass: isa]; - data = [self allocMemoryForNItems: newSize - ofSize: sizeof(*data)]; + data = [self allocMemoryWithItemSize: sizeof(*data) + count: newSize]; for (i = 0; i < newSize; i++) data[i] = NULL; size = newSize; @@ -206,12 +206,12 @@ if (key == nil || object == nil) @throw [OFInvalidArgumentException exceptionWithClass: isa selector: _cmd]; - data = [self allocMemoryForNItems: 2 - ofSize: sizeof(*data)]; + data = [self allocMemoryWithItemSize: sizeof(*data) + count: 2]; size = 2; for (i = 0; i < size; i++) data[i] = NULL; @@ -272,12 +272,12 @@ newSize <<= 1; if (newSize == 0) @throw [OFOutOfRangeException exceptionWithClass: isa]; - data = [self allocMemoryForNItems: newSize - ofSize: sizeof(*data)]; + data = [self allocMemoryWithItemSize: sizeof(*data) + count: newSize]; for (j = 0; j < newSize; j++) data[j] = NULL; size = newSize; @@ -393,12 +393,12 @@ newSize <<= 1; if (newSize == 0) @throw [OFOutOfRangeException exceptionWithClass: isa]; - data = [self allocMemoryForNItems: newSize - ofSize: sizeof(*data)]; + data = [self allocMemoryWithItemSize: sizeof(*data) + count: newSize]; for (j = 0; j < newSize; j++) data[j] = NULL; size = newSize; @@ -646,12 +646,12 @@ } - (OFArray*)allKeys { OFArray *ret; - id *keys = [self allocMemoryForNItems: count - ofSize: sizeof(id)]; + id *keys = [self allocMemoryWithItemSize: sizeof(*keys) + count: count]; size_t i, j; for (i = j = 0; i < size; i++) if (data[i] != NULL && data[i] != DELETED) keys[j++] = data[i]->key; @@ -669,12 +669,12 @@ } - (OFArray*)allObjects { OFArray *ret; - id *objects = [self allocMemoryForNItems: count - ofSize: sizeof(id)]; + id *objects = [self allocMemoryWithItemSize: sizeof(*objects) + count: count]; size_t i, j; for (i = j = 0; i < size; i++) if (data[i] != NULL && data[i] != DELETED) objects[j++] = data[i]->object; Index: src/OFMutableArray_adjacent.m ================================================================== --- src/OFMutableArray_adjacent.m +++ src/OFMutableArray_adjacent.m @@ -162,12 +162,12 @@ size_t i, count = [array count]; if (range.length > count - range.start) @throw [OFOutOfRangeException exceptionWithClass: isa]; - copy = [self allocMemoryForNItems: range.length - ofSize: sizeof(id)]; + copy = [self allocMemoryWithItemSize: sizeof(*copy) + count: range.length]; memcpy(copy, objects + range.start, range.length * sizeof(id)); @try { [array removeItemsInRange: range]; mutations++; Index: src/OFMutableDictionary_hashtable.m ================================================================== --- src/OFMutableDictionary_hashtable.m +++ src/OFMutableDictionary_hashtable.m @@ -58,12 +58,12 @@ return; if (newSize == 0) @throw [OFOutOfRangeException exceptionWithClass: isa]; - newData = [self allocMemoryForNItems: newSize - ofSize: sizeof(*newData)]; + newData = [self allocMemoryWithItemSize: sizeof(*newData) + count: newSize]; for (i = 0; i < newSize; i++) newData[i] = NULL; for (i = 0; i < size; i++) { Index: src/OFMutableSet.m ================================================================== --- src/OFMutableSet.m +++ src/OFMutableSet.m @@ -157,12 +157,12 @@ { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; size_t count = [self count]; id *cArray; - cArray = [self allocMemoryForNItems: count - ofSize: sizeof(id)]; + cArray = [self allocMemoryWithItemSize: sizeof(id) + count: count]; @try { OFEnumerator *enumerator = [self objectEnumerator]; id object; size_t i = 0; Index: src/OFMutableString_UTF8.m ================================================================== --- src/OFMutableString_UTF8.m +++ src/OFMutableString_UTF8.m @@ -67,12 +67,12 @@ return; } unicodeLen = [self length]; - unicodeString = [self allocMemoryForNItems: unicodeLen - ofSize: sizeof(of_unichar_t)]; + unicodeString = [self allocMemoryWithItemSize: sizeof(of_unichar_t) + count: unicodeLen]; i = j = 0; newCStringLength = 0; while (i < s->cStringLength) { Index: src/OFObject.h ================================================================== --- src/OFObject.h +++ src/OFObject.h @@ -499,16 +499,16 @@ * \brief Allocates memory for the specified number of items and stores it in * the object's memory pool. * * It will be free'd automatically when the object is deallocated. * - * \param nItems The number of items to allocate - * \param size The size of each item to allocate + * \param itemSize The size of each item to allocate + * \param count The number of items to allocate * \return A pointer to the allocated memory */ -- (void*)allocMemoryForNItems: (size_t)nItems - ofSize: (size_t)size; +- (void*)allocMemoryWithItemSize: (size_t)itemSize + count: (size_t)count; /** * \brief Resizes memory in the object's memory pool to the specified size. * * If the pointer is NULL, this is equivalent to allocating memory. @@ -527,17 +527,17 @@ * * If the pointer is NULL, this is equivalent to allocating memory. * If the size or number of items is 0, this is equivalent to freeing memory. * * \param pointer A pointer to the already allocated memory - * \param nItems The number of items to resize to - * \param size The size of each item to resize to + * \param itemSize The size of each item to resize to + * \param count The number of items to resize to * \return A pointer to the resized memory chunk */ - (void*)resizeMemory: (void*)pointer - toNItems: (size_t)nItems - ofSize: (size_t)size; + itemSize: (size_t)itemSize + count: (size_t)count; /** * \brief Frees allocated memory and removes it from the object's memory pool. * * Does nothing if the pointer is NULL. Index: src/OFObject.m ================================================================== --- src/OFObject.m +++ src/OFObject.m @@ -801,20 +801,20 @@ PRE_IVAR->lastMem = preMem; return (char*)pointer + PRE_MEM_ALIGN; } -- (void*)allocMemoryForNItems: (size_t)nItems - ofSize: (size_t)size +- (void*)allocMemoryWithItemSize: (size_t)itemSize + count: (size_t)count { - if (nItems == 0 || size == 0) + if (itemSize == 0 || count == 0) return NULL; - if (nItems > SIZE_MAX / size) + if (count > SIZE_MAX / itemSize) @throw [OFOutOfRangeException exceptionWithClass: isa]; - return [self allocMemoryWithSize: nItems * size]; + return [self allocMemoryWithSize: itemSize * count]; } - (void*)resizeMemory: (void*)pointer toSize: (size_t)size { @@ -853,27 +853,27 @@ return (char*)new + PRE_MEM_ALIGN; } - (void*)resizeMemory: (void*)pointer - toNItems: (size_t)nItems - ofSize: (size_t)size + itemSize: (size_t)itemSize + count: (size_t)count { if (pointer == NULL) - return [self allocMemoryForNItems: nItems - ofSize: size]; + return [self allocMemoryWithItemSize: itemSize + count: count]; - if (nItems == 0 || size == 0) { + if (itemSize == 0 || count == 0) { [self freeMemory: pointer]; return NULL; } - if (nItems > SIZE_MAX / size) + if (count > SIZE_MAX / itemSize) @throw [OFOutOfRangeException exceptionWithClass: isa]; return [self resizeMemory: pointer - toSize: nItems * size]; + toSize: itemSize * count]; } - (void)freeMemory: (void*)pointer { if (pointer == NULL) @@ -1030,12 +1030,12 @@ { @throw [OFNotImplementedException exceptionWithClass: self selector: _cmd]; } -+ (void*)allocMemoryForNItems: (size_t)nItems - ofSize: (size_t)size ++ (void*)allocMemoryWithItemSize: (size_t)itemSize + count: (size_t)count { @throw [OFNotImplementedException exceptionWithClass: self selector: _cmd]; } @@ -1045,12 +1045,12 @@ @throw [OFNotImplementedException exceptionWithClass: self selector: _cmd]; } + (void*)resizeMemory: (void*)pointer - toNItems: (size_t)nItems - ofSize: (size_t)size + itemSize: (size_t)itemSize + count: (size_t)count { @throw [OFNotImplementedException exceptionWithClass: self selector: _cmd]; } Index: src/OFProcess.m ================================================================== --- src/OFProcess.m +++ src/OFProcess.m @@ -89,12 +89,12 @@ case 0:; OFString **objects = [arguments objects]; size_t i, count = [arguments count]; char **argv; - argv = [self allocMemoryForNItems: count + 2 - ofSize: sizeof(char*)]; + argv = [self allocMemoryWithItemSize: sizeof(char*) + count: count + 2]; argv[0] = (char*)[programName cStringWithEncoding: OF_STRING_ENCODING_NATIVE]; for (i = 0; i < count; i++) Index: src/OFStream.m ================================================================== --- src/OFStream.m +++ src/OFStream.m @@ -444,12 +444,12 @@ { OFDataArray *dataArray; char *tmp; dataArray = [OFDataArray dataArrayWithItemSize: itemSize]; - tmp = [self allocMemoryForNItems: nItems - ofSize: itemSize]; + tmp = [self allocMemoryWithItemSize: itemSize + count: nItems]; @try { [self readExactlyNBytes: nItems * itemSize intoBuffer: tmp]; @@ -941,12 +941,12 @@ [self writeNBytes: size fromBuffer: buffer]; #else uint16_t *tmp; - tmp = [self allocMemoryForNItems: nInt16s - ofSize: sizeof(uint16_t)]; + tmp = [self allocMemoryWithItemSize: sizeof(uint16_t) + count: nInt16s]; @try { size_t i; for (i = 0; i < nInt16s; i++) @@ -971,12 +971,12 @@ [self writeNBytes: size fromBuffer: buffer]; #else uint32_t *tmp; - tmp = [self allocMemoryForNItems: nInt32s - ofSize: sizeof(uint32_t)]; + tmp = [self allocMemoryWithItemSize: sizeof(uint32_t) + count: nInt32s]; @try { size_t i; for (i = 0; i < nInt32s; i++) @@ -1001,12 +1001,12 @@ [self writeNBytes: size fromBuffer: buffer]; #else uint64_t *tmp; - tmp = [self allocMemoryForNItems: nInt64s - ofSize: sizeof(uint64_t)]; + tmp = [self allocMemoryWithItemSize: sizeof(uint64_t) + count: nInt64s]; @try { size_t i; for (i = 0; i < nInt64s; i++) @@ -1031,12 +1031,12 @@ [self writeNBytes: size fromBuffer: buffer]; #else float *tmp; - tmp = [self allocMemoryForNItems: nFloats - ofSize: sizeof(float)]; + tmp = [self allocMemoryWithItemSize: sizeof(float) + count: nFloats]; @try { size_t i; for (i = 0; i < nFloats; i++) @@ -1061,12 +1061,12 @@ [self writeNBytes: size fromBuffer: buffer]; #else double *tmp; - tmp = [self allocMemoryForNItems: nDoubles - ofSize: sizeof(double)]; + tmp = [self allocMemoryWithItemSize: sizeof(double) + count: nDoubles]; @try { size_t i; for (i = 0; i < nDoubles; i++) @@ -1131,12 +1131,12 @@ [self writeNBytes: size fromBuffer: buffer]; #else uint16_t *tmp; - tmp = [self allocMemoryForNItems: nInt16s - ofSize: sizeof(uint16_t)]; + tmp = [self allocMemoryWithItemSize: sizeof(uint16_t) + count: nInt16s]; @try { size_t i; for (i = 0; i < nInt16s; i++) @@ -1161,12 +1161,12 @@ [self writeNBytes: size fromBuffer: buffer]; #else uint32_t *tmp; - tmp = [self allocMemoryForNItems: nInt32s - ofSize: sizeof(uint32_t)]; + tmp = [self allocMemoryWithItemSize: sizeof(uint32_t) + count: nInt32s]; @try { size_t i; for (i = 0; i < nInt32s; i++) @@ -1191,12 +1191,12 @@ [self writeNBytes: size fromBuffer: buffer]; #else uint64_t *tmp; - tmp = [self allocMemoryForNItems: nInt64s - ofSize: sizeof(uint64_t)]; + tmp = [self allocMemoryWithItemSize: sizeof(uint64_t) + count: nInt64s]; @try { size_t i; for (i = 0; i < nInt64s; i++) @@ -1221,12 +1221,12 @@ [self writeNBytes: size fromBuffer: buffer]; #else float *tmp; - tmp = [self allocMemoryForNItems: nFloats - ofSize: sizeof(float)]; + tmp = [self allocMemoryWithItemSize: sizeof(float) + count: nFloats]; @try { size_t i; for (i = 0; i < nFloats; i++) @@ -1251,12 +1251,12 @@ [self writeNBytes: size fromBuffer: buffer]; #else double *tmp; - tmp = [self allocMemoryForNItems: nDoubles - ofSize: sizeof(double)]; + tmp = [self allocMemoryWithItemSize: sizeof(double) + count: nDoubles]; @try { size_t i; for (i = 0; i < nDoubles; i++) Index: src/OFStreamObserver.m ================================================================== --- src/OFStreamObserver.m +++ src/OFStreamObserver.m @@ -137,12 +137,12 @@ @throw [OFInitializationFailedException exceptionWithClass: isa]; #endif maxFD = cancelFD[0]; - FDToStream = [self allocMemoryForNItems: maxFD + 1 - ofSize: sizeof(OFStream*)]; + FDToStream = [self allocMemoryWithItemSize: sizeof(OFStream*) + count: maxFD + 1]; FDToStream[cancelFD[0]] = nil; #ifdef OF_THREADS mutex = [[OFMutex alloc] init]; #endif @@ -310,12 +310,12 @@ if ((action & QUEUE_ACTION) == QUEUE_ADD) { if (fd > maxFD) { maxFD = fd; FDToStream = [self resizeMemory: FDToStream - toNItems: maxFD + 1 - ofSize: sizeof(OFStream*)]; + itemSize: sizeof(OFStream*) + count: maxFD + 1]; } FDToStream[fd] = stream; } Index: src/OFString.m ================================================================== --- src/OFString.m +++ src/OFString.m @@ -1521,12 +1521,12 @@ int compare; if ((prefixLength = [prefix length]) > [self length]) return NO; - tmp = [self allocMemoryForNItems: prefixLength - ofSize: sizeof(of_unichar_t)]; + tmp = [self allocMemoryWithItemSize: sizeof(of_unichar_t) + count: prefixLength]; @try { OFAutoreleasePool *pool; [self getCharacters: tmp inRange: of_range(0, prefixLength)]; @@ -1555,12 +1555,12 @@ if ((suffixLength = [suffix length]) > [self length]) return NO; length = [self length]; - tmp = [self allocMemoryForNItems: suffixLength - ofSize: sizeof(of_unichar_t)]; + tmp = [self allocMemoryWithItemSize: sizeof(of_unichar_t) + count: suffixLength]; @try { OFAutoreleasePool *pool; [self getCharacters: tmp inRange: of_range(length - suffixLength, @@ -1957,12 +1957,12 @@ { OFObject *object = [[[OFObject alloc] init] autorelease]; size_t length = [self length]; of_unichar_t *ret; - ret = [object allocMemoryForNItems: length + 1 - ofSize: sizeof(of_unichar_t)]; + ret = [object allocMemoryWithItemSize: sizeof(of_unichar_t) + count: length + 1]; [self getCharacters: ret inRange: of_range(0, length)]; ret[length] = 0; return ret; @@ -1976,12 +1976,12 @@ size_t length = [self length]; uint16_t *ret; size_t i, j; /* Allocate memory for the worst case */ - ret = [object allocMemoryForNItems: length * 2 + 1 - ofSize: sizeof(uint16_t)]; + ret = [object allocMemoryWithItemSize: sizeof(uint16_t) + count: length * 2 + 1]; j = 0; for (i = 0; i < length; i++) { of_unichar_t c = unicodeString[i]; @@ -2000,12 +2000,12 @@ ret[j] = 0; @try { ret = [object resizeMemory: ret - toNItems: j + 1 - ofSize: sizeof(uint16_t)]; + itemSize: sizeof(uint16_t) + count: j + 1]; } @catch (OFOutOfMemoryException *e) { /* We don't care, as we only tried to make it smaller */ } [pool release]; Index: src/OFString_UTF8.m ================================================================== --- src/OFString_UTF8.m +++ src/OFString_UTF8.m @@ -1092,12 +1092,12 @@ { OFObject *object = [[[OFObject alloc] init] autorelease]; of_unichar_t *ret; size_t i, j; - ret = [object allocMemoryForNItems: s->length + 1 - ofSize: sizeof(of_unichar_t)]; + ret = [object allocMemoryWithItemSize: sizeof(of_unichar_t) + count: s->length + 1]; i = 0; j = 0; while (i < s->cStringLength) {