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/OFArray_adjacent.m ================================================================== --- src/OFArray_adjacent.m +++ src/OFArray_adjacent.m @@ -102,12 +102,12 @@ @try { for (i = 0; i < count; i++) [objects[i] retain]; - [array addNItems: count - fromCArray: objects]; + [array addItemsFromCArray: objects + count: count]; } @catch (id e) { for (i = 0; i < count; i++) [objects[i] release]; /* Prevent double-release of objects */ @@ -130,12 +130,12 @@ size_t i; for (i = 0; i < count; i++) [objects[i] retain]; - [array addNItems: count - fromCArray: objects]; + [array addItemsFromCArray: objects + count: count]; } @catch (id e) { size_t i; for (i = 0; i < count; i++) [objects[i] release]; 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.h ================================================================== --- src/OFDataArray.h +++ src/OFDataArray.h @@ -186,55 +186,46 @@ * \brief Adds an item to the OFDataArray at the specified index. * * \param item A pointer to an arbitrary item * \param index The index where the item should be added */ -- (void)addItem: (const void*)item - atIndex: (size_t)index; +- (void)insertItem: (const void*)item + atIndex: (size_t)index; /** * \brief Adds items from a C array to the OFDataArray. * - * \param nItems The number of items to add + * \param count The number of items to add * \param cArray A C array containing the items to add */ -- (void)addNItems: (size_t)nItems - fromCArray: (const void*)cArray; +- (void)addItemsFromCArray: (const void*)cArray + count: (size_t)count; /** * \brief Adds items from a C array to the OFDataArray at the specified index. * - * \param nItems The number of items to add * \param cArray A C array containing the items to add * \param index The index where the items should be added + * \param count The number of items to add */ -- (void)addNItems: (size_t)nItems - fromCArray: (const void*)cArray - atIndex: (size_t)index; +- (void)insertItemsFromCArray: (const void*)cArray + atIndex: (size_t)index + count: (size_t)count; /** * \brief Removes the item at the specified index. * * \param index The index of the item to remove */ - (void)removeItemAtIndex: (size_t)index; -/** - * \brief Removes the specified amount of items from the end of the OFDataArray. - * - * \param nItems The number of items to remove - */ -- (void)removeNItems: (size_t)nItems; - /** * \brief Removes the specified amount of items at the specified index. * - * \param nItems The number of items to remove - * \param index The index at which the items are removed + * \param range The range of items to remove */ -- (void)removeNItems: (size_t)nItems - atIndex: (size_t)index; +- (void)removeItemsInRange: (of_range_t)range; /** * \brief Removes the last item. */ - (void)removeLastItem; Index: src/OFDataArray.m ================================================================== --- src/OFDataArray.m +++ src/OFDataArray.m @@ -111,12 +111,12 @@ while (![file isAtEndOfStream]) { size_t length; length = [file readNBytes: of_pagesize intoBuffer: buffer]; - [self addNItems: length - fromCArray: buffer]; + [self addItemsFromCArray: buffer + count: length]; } [self freeMemory: buffer]; } @finally { [file release]; @@ -255,50 +255,50 @@ { 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++; } -- (void)addItem: (const void*)item - atIndex: (size_t)index +- (void)insertItem: (const void*)item + atIndex: (size_t)index { - [self addNItems: 1 - fromCArray: item - atIndex: index]; + [self insertItemsFromCArray: item + atIndex: index + count: 1]; } -- (void)addNItems: (size_t)nItems - fromCArray: (const void*)cArray +- (void)addItemsFromCArray: (const void*)cArray + count: (size_t)nItems { 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; } -- (void)addNItems: (size_t)nItems - fromCArray: (const void*)cArray - atIndex: (size_t)index +- (void)insertItemsFromCArray: (const void*)cArray + atIndex: (size_t)index + count: (size_t)nItems { - if (nItems > SIZE_MAX - count) + 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); @@ -305,44 +305,27 @@ count += nItems; } - (void)removeItemAtIndex: (size_t)index { - [self removeNItems: 1 - atIndex: index]; -} - -- (void)removeNItems: (size_t)nItems -{ - if (nItems > count) - @throw [OFOutOfRangeException exceptionWithClass: isa]; - - - count -= nItems; - @try { - data = [self resizeMemory: data - toNItems: count - ofSize: itemSize]; - } @catch (OFOutOfMemoryException *e) { - /* We don't really care, as we only made it smaller */ - } -} - -- (void)removeNItems: (size_t)nItems - atIndex: (size_t)index -{ - if (nItems > count) - @throw [OFOutOfRangeException exceptionWithClass: isa]; - - memmove(data + index * itemSize, data + (index + nItems) * itemSize, - (count - index - nItems) * itemSize); - - count -= nItems; - @try { - data = [self resizeMemory: data - toNItems: count - ofSize: itemSize]; + [self removeItemsInRange: of_range(index, 1)]; +} + +- (void)removeItemsInRange: (of_range_t)range +{ + if (range.start + range.length > count) + @throw [OFOutOfRangeException exceptionWithClass: isa]; + + memmove(data + range.start * itemSize, + data + (range.start + range.length) * itemSize, + (count - range.start - range.length) * itemSize); + + count -= range.length; + @try { + data = [self resizeMemory: data + itemSize: itemSize + count: count]; } @catch (OFOutOfMemoryException *e) { /* We don't really care, as we only made it smaller */ } } @@ -352,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 */ } } @@ -371,12 +354,12 @@ - copy { OFDataArray *copy = [[isa alloc] initWithItemSize: itemSize]; - [copy addNItems: count - fromCArray: data]; + [copy addItemsFromCArray: data + count: count]; return copy; } - (BOOL)isEqual: (id)object @@ -503,12 +486,12 @@ count++; size = newSize; } -- (void)addNItems: (size_t)nItems - fromCArray: (const void*)cArray +- (void)addItemsFromCArray: (const void*)cArray + count: (size_t)nItems { size_t newSize, lastPageByte; if (nItems > SIZE_MAX - count || count + nItems > SIZE_MAX / itemSize) @throw [OFOutOfRangeException exceptionWithClass: isa]; @@ -524,17 +507,18 @@ count += nItems; size = newSize; } -- (void)addNItems: (size_t)nItems - fromCArray: (const void*)cArray - atIndex: (size_t)index +- (void)insertItemsFromCArray: (const void*)cArray + atIndex: (size_t)index + count: (size_t)nItems { size_t newSize, lastPageByte; - if (nItems > SIZE_MAX - count || count + nItems > SIZE_MAX / itemSize) + if (nItems > SIZE_MAX - count || index > count || + count + nItems > SIZE_MAX / itemSize) @throw [OFOutOfRangeException exceptionWithClass: isa]; lastPageByte = of_pagesize - 1; newSize = ((count + nItems) * itemSize + lastPageByte) & ~lastPageByte; @@ -548,39 +532,22 @@ count += nItems; size = newSize; } -- (void)removeNItems: (size_t)nItems -{ - size_t newSize, lastPageByte; - - if (nItems > count) - @throw [OFOutOfRangeException exceptionWithClass: isa]; - - count -= nItems; - lastPageByte = of_pagesize - 1; - newSize = (count * itemSize + lastPageByte) & ~lastPageByte; - - if (size != newSize) - data = [self resizeMemory: data - toSize: newSize]; - size = newSize; -} - -- (void)removeNItems: (size_t)nItems - atIndex: (size_t)index -{ - size_t newSize, lastPageByte; - - if (nItems > count) - @throw [OFOutOfRangeException exceptionWithClass: isa]; - - memmove(data + index * itemSize, data + (index + nItems) * itemSize, - (count - index - nItems) * itemSize); - - count -= nItems; +- (void)removeItemsInRange: (of_range_t)range +{ + size_t newSize, lastPageByte; + + if (range.start + range.length > count) + @throw [OFOutOfRangeException exceptionWithClass: isa]; + + memmove(data + range.start * itemSize, + data + (range.start + range.length) * itemSize, + (count - range.start - range.length) * itemSize); + + count -= range.length; lastPageByte = of_pagesize - 1; newSize = (count * itemSize + lastPageByte) & ~lastPageByte; if (size != newSize) data = [self resizeMemory: data @@ -600,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/OFHTTPRequest.m ================================================================== --- src/OFHTTPRequest.m +++ src/OFHTTPRequest.m @@ -429,12 +429,12 @@ didReceiveData: buffer withLength: length]; [pool2 releaseObjects]; bytesReceived += length; - [data addNItems: length - fromCArray: buffer]; + [data addItemsFromCArray: buffer + count: length]; toRead -= length; } @try { @@ -459,12 +459,12 @@ didReceiveData: buffer withLength: length]; [pool2 releaseObjects]; bytesReceived += length; - [data addNItems: length - fromCArray: buffer]; + [data addItemsFromCArray: buffer + count: length]; if (contentLengthHeader != nil && bytesReceived >= contentLength) break; } Index: src/OFMutableArray.h ================================================================== --- src/OFMutableArray.h +++ src/OFMutableArray.h @@ -24,24 +24,24 @@ * \brief An abstract class for storing, adding and removing objects in anr * array. */ @interface OFMutableArray: OFArray /** - * \brief Adds an object to the OFArray. + * \brief Adds an object to the end of the array. * * \param object An object to add */ - (void)addObject: (id)object; /** - * \brief Adds an object to the OFArray at the specified index. + * \brief Inserts an object to the OFArray at the specified index. * * \param object An object to add - * \param index The index where the object should be added + * \param index The index where the object should be inserted */ -- (void)addObject: (id)object - atIndex: (size_t)index; +- (void)insertObject: (id)object + atIndex: (size_t)index; /** * \brief Replaces the first object equivalent to the specified object with the * other specified object. * @@ -92,17 +92,10 @@ * * \param index The index of the object to remove */ - (void)removeObjectAtIndex: (size_t)index; -/** - * \brief Removes the specified amount of objects from the end of the OFArray. - * - * \param nObjects The number of objects to remove - */ -- (void)removeNObjects: (size_t)nObjects; - /** * \brief Removes the object in the specified range. * * \param range The range of the objects to remove */ @@ -126,17 +119,17 @@ */ - (void)replaceObjectsUsingBlock: (of_array_replace_block_t)block; #endif /** - * \brief Swaps the objects at the specified indices. + * \brief Exchange the objects at the specified indices. * - * \param index1 The index of the first object to swap - * \param index2 The index of the second object to swap + * \param index1 The index of the first object to exchange + * \param index2 The index of the second object to exchange */ -- (void)swapObjectAtIndex: (size_t)index1 - withObjectAtIndex: (size_t)index2; +- (void)exchangeObjectAtIndex: (size_t)index1 + withObjectAtIndex: (size_t)index2; /** * \brief Sorts the array. */ - (void)sort; Index: src/OFMutableArray.m ================================================================== --- src/OFMutableArray.m +++ src/OFMutableArray.m @@ -15,10 +15,12 @@ */ #include "config.h" #include + +#include #import "OFMutableArray.h" #import "OFMutableArray_adjacent.h" #import "OFAutoreleasePool.h" @@ -57,17 +59,17 @@ while ([[array objectAtIndex: j] compare: pivot] != OF_ORDERED_ASCENDING && j > left) j--; if (i < j) - [array swapObjectAtIndex: i - withObjectAtIndex: j]; + [array exchangeObjectAtIndex: i + withObjectAtIndex: j]; } while (i < j); if ([[array objectAtIndex: i] compare: pivot] == OF_ORDERED_DESCENDING) - [array swapObjectAtIndex: i - withObjectAtIndex: right]; + [array exchangeObjectAtIndex: i + withObjectAtIndex: right]; if (i > 0) quicksort(array, left, i - 1); quicksort(array, i + 1, right); } @@ -175,16 +177,16 @@ return [[OFArray alloc] initWithArray: self]; } - (void)addObject: (id)object { - [self addObject: object - atIndex: [self count]]; + [self insertObject: object + atIndex: [self count]]; } -- (void)addObject: (id)object - atIndex: (size_t)index +- (void)insertObject: (id)object + atIndex: (size_t)index { @throw [OFNotImplementedException exceptionWithClass: isa selector: _cmd]; } @@ -261,17 +263,10 @@ return; } } } -- (void)removeNObjects: (size_t)nObjects -{ - size_t count = [self count]; - - [self removeObjectsInRange: of_range(count - nObjects, nObjects)]; -} - - (void)removeObjectsInRange: (of_range_t)range { size_t i; for (i = 0; i < range.length; i++) @@ -278,16 +273,19 @@ [self removeObjectAtIndex: range.start]; } - (void)removeLastObject { - [self removeNObjects: 1]; + size_t count = [self count]; + + if (count > 0) + [self removeObjectAtIndex: count - 1]; } - (void)removeAllObjects { - [self removeNObjects: [self count]]; + [self removeObjectsInRange: of_range(0, [self count])]; } #ifdef OF_HAVE_BLOCKS - (void)replaceObjectsUsingBlock: (of_array_replace_block_t)block { @@ -297,12 +295,12 @@ withObject: block(object, index, stop)]; }]; } #endif -- (void)swapObjectAtIndex: (size_t)index1 - withObjectAtIndex: (size_t)index2 +- (void)exchangeObjectAtIndex: (size_t)index1 + withObjectAtIndex: (size_t)index2 { id object1 = [self objectAtIndex: index1]; id object2 = [self objectAtIndex: index2]; [object1 retain]; @@ -332,13 +330,13 @@ if (count == 0 || count == 1) return; for (i = 0, j = count - 1; i < j; i++, j--) - [self swapObjectAtIndex: i - withObjectAtIndex: j]; + [self exchangeObjectAtIndex: i + withObjectAtIndex: j]; } - (void)makeImmutable { } @end Index: src/OFMutableArray_adjacent.m ================================================================== --- src/OFMutableArray_adjacent.m +++ src/OFMutableArray_adjacent.m @@ -40,15 +40,15 @@ [object retain]; mutations++; } -- (void)addObject: (id)object - atIndex: (size_t)index +- (void)insertObject: (id)object + atIndex: (size_t)index { - [array addItem: &object - atIndex: index]; + [array insertItem: &object + atIndex: index]; [object retain]; mutations++; } @@ -143,33 +143,10 @@ [object release]; mutations++; } -- (void)removeNObjects: (size_t)nObjects -{ - id *objects = [array cArray], *copy; - size_t i, count = [array count]; - - if (nObjects > count) - @throw [OFOutOfRangeException exceptionWithClass: isa]; - - copy = [self allocMemoryForNItems: nObjects - ofSize: sizeof(id)]; - memcpy(copy, objects + (count - nObjects), nObjects * sizeof(id)); - - @try { - [array removeNItems: nObjects]; - mutations++; - - for (i = 0; i < nObjects; i++) - [copy[i] release]; - } @finally { - [self freeMemory: copy]; - } -} - - (void)removeAllObjects { id *objects = [array cArray]; size_t i, count = [array count]; @@ -185,17 +162,16 @@ 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 removeNItems: range.length - atIndex: range.start]; + [array removeItemsInRange: range]; mutations++; for (i = 0; i < range.length; i++) [copy[i] release]; } @finally { @@ -210,12 +186,12 @@ [object release]; mutations++; } -- (void)swapObjectAtIndex: (size_t)index1 - withObjectAtIndex: (size_t)index2 +- (void)exchangeObjectAtIndex: (size_t)index1 + withObjectAtIndex: (size_t)index2 { id *objects = [array cArray]; size_t count = [array count]; id tmp; 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 @@ -608,20 +608,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 { @@ -660,27 +660,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) @@ -837,12 +837,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]; } @@ -852,12 +852,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 @@ -440,28 +440,28 @@ } - (OFDataArray*)readDataArrayWithItemSize: (size_t)itemSize andNItems: (size_t)nItems { - OFDataArray *da; + OFDataArray *dataArray; char *tmp; - da = [OFDataArray dataArrayWithItemSize: itemSize]; - tmp = [self allocMemoryForNItems: nItems - ofSize: itemSize]; + dataArray = [OFDataArray dataArrayWithItemSize: itemSize]; + tmp = [self allocMemoryWithItemSize: itemSize + count: nItems]; @try { [self readExactlyNBytes: nItems * itemSize intoBuffer: tmp]; - [da addNItems: nItems - fromCArray: tmp]; + [dataArray addItemsFromCArray: tmp + count: nItems]; } @finally { [self freeMemory: tmp]; } - return da; + return dataArray; } - (OFDataArray*)readDataArrayTillEndOfStream { OFDataArray *dataArray; @@ -474,12 +474,12 @@ while (![self isAtEndOfStream]) { size_t length; length = [self readNBytes: of_pagesize intoBuffer: buffer]; - [dataArray addNItems: length - fromCArray: buffer]; + [dataArray addItemsFromCArray: buffer + count: length]; } } @finally { [self freeMemory: buffer]; } @@ -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; } @@ -352,13 +352,13 @@ default: assert(0); } } - [queue removeNObjects: count]; - [queueInfo removeNItems: count]; - [queueFDs removeNItems: count]; + [queue removeAllObjects]; + [queueInfo removeAllItems]; + [queueFDs removeAllItems]; } @finally { [mutex unlock]; } } Index: src/OFStreamObserver_kqueue.m ================================================================== --- src/OFStreamObserver_kqueue.m +++ src/OFStreamObserver_kqueue.m @@ -125,11 +125,11 @@ default: assert(0); } } - [changeList removeNItems: [changeList count]]; + [changeList removeAllItems]; if (events == 0) { [pool release]; return NO; } Index: src/OFString+JSONValue.h ================================================================== --- src/OFString+JSONValue.h +++ src/OFString+JSONValue.h @@ -26,9 +26,21 @@ @interface OFString (JSONValue) /** * \brief Creates an object from the JSON value of the string. * + * \note This also allows parsing JSON5, an extension of JSON. See + * http://json5.org/ for more details. + * + * \warning Although not specified by the JSON specification, this can also + * return primitives like strings and numbers. The rationale behind + * this is that most JSON parsers allow JSON data just consisting of a + * single primitive, leading to realworld JSON files sometimes only + * consisting of a single primitive. Therefore, you should not make any + * assumptions about the object returned by this method if you don't + * want your program to terminate due to a message not understood, but + * instead check the returned object using -[isKindOfClass:]. + * * \return An object */ - (id)JSONValue; @end Index: src/OFString+JSONValue.m ================================================================== --- src/OFString+JSONValue.m +++ src/OFString+JSONValue.m @@ -128,10 +128,11 @@ static inline OFString* parseString(const char *restrict *pointer, const char *stop) { char *buffer; size_t i = 0; + char delimiter = **pointer; if (++(*pointer) + 1 >= stop) return nil; if ((buffer = malloc(stop - *pointer)) == NULL) @@ -192,11 +193,10 @@ /* Normal character */ if ((c1 & 0xFC00) != 0xD800) { l = of_string_unicode_to_utf8(c1, buffer + i); - if (l == 0) { free(buffer); return nil; } @@ -219,45 +219,158 @@ c = (((c1 & 0x3FF) << 10) | (c2 & 0x3FF)) + 0x10000; l = of_string_unicode_to_utf8(c, buffer + i); - if (l == 0) { free(buffer); return nil; } i += l; *pointer += 11; break; + case '\r': + (*pointer)++; + + if (*pointer < stop && **pointer == '\n') + (*pointer)++; + + break; + case '\n': + (*pointer)++; + break; default: - free(buffer); - return nil; + free(buffer); + return nil; } /* End of string found */ - } else if (**pointer == '"') { + } else if (**pointer == delimiter) { + OFString *ret; + + @try { + ret = [OFString stringWithUTF8String: buffer + length: i]; + } @finally { + free(buffer); + } + + (*pointer)++; + + return ret; + /* Newlines in strings are disallowed */ + } else if (**pointer == '\n' || **pointer == '\r') { + free(buffer); + return nil; + } else { + buffer[i++] = **pointer; + (*pointer)++; + } + } + + free(buffer); + return nil; +} + +static inline OFString* +parseIdentifier(const char *restrict *pointer, const char *stop) +{ + char *buffer; + size_t i = 0; + + if ((buffer = malloc(stop - *pointer)) == NULL) + return nil; + + while (*pointer < stop) { + if ((**pointer >= 'a' && **pointer <= 'z') || + (**pointer >= 'A' && **pointer <= 'Z') || + (**pointer >= '0' && **pointer <= '9') || + **pointer == '_' || **pointer == '$' || + (**pointer & 0x80)) { + buffer[i++] = **pointer; + (*pointer)++; + } else if (**pointer == '\\') { + uint16_t c1, c2; + of_unichar_t c; + size_t l; + + if (++(*pointer) >= stop || **pointer != 'u') { + free(buffer); + return nil; + } + + c1 = parseUnicodeEscape(*pointer - 1, stop); + if (c1 == 0xFFFF) { + free(buffer); + return nil; + } + + /* Low surrogate */ + if ((c1 & 0xFC00) == 0xDC00) { + free(buffer); + return nil; + } + + /* Normal character */ + if ((c1 & 0xFC00) != 0xD800) { + l = of_string_unicode_to_utf8(c1, buffer + i); + if (l == 0) { + free(buffer); + return nil; + } + + i += l; + *pointer += 5; + + continue; + } + + /* + * If we are still here, we only got one UTF-16 + * surrogate and now need to get the other one in order + * to produce UTF-8 and not CESU-8. + */ + c2 = parseUnicodeEscape(*pointer + 5, stop); + if (c2 == 0xFFFF) { + free(buffer); + return nil; + } + + c = (((c1 & 0x3FF) << 10) | (c2 & 0x3FF)) + 0x10000; + + l = of_string_unicode_to_utf8(c, buffer + i); + if (l == 0) { + free(buffer); + return nil; + } + + i += l; + *pointer += 11; + } else { OFString *ret; + + if (i == 0 || (buffer[0] >= '0' && buffer[0] <= '9')) { + free(buffer); + return nil; + } @try { ret = [OFString stringWithUTF8String: buffer length: i]; } @finally { free(buffer); } - (*pointer)++; - return ret; - } else { - buffer[i++] = **pointer; - (*pointer)++; } } - free(buffer); + /* + * It is never possible to end with an identifier, thus we should never + * reach stop. + */ return nil; } static inline OFMutableArray* parseArray(const char *restrict *pointer, const char *stop) @@ -274,10 +387,20 @@ if (*pointer >= stop) return nil; if (**pointer == ']') break; + + if (**pointer == ',') { + (*pointer)++; + skipWhitespacesAndComments(pointer, stop); + + if (*pointer >= stop || **pointer != ']') + return nil; + + break; + } if ((object = nextObject(pointer, stop)) == nil) return nil; [array addObject: object]; @@ -317,11 +440,32 @@ return nil; if (**pointer == '}') break; - if ((key = nextObject(pointer, stop)) == nil) + if (**pointer == ',') { + (*pointer)++; + skipWhitespacesAndComments(pointer, stop); + + if (*pointer >= stop || **pointer != '}') + return nil; + + break; + } + + skipWhitespacesAndComments(pointer, stop); + if (*pointer + 1 >= stop) + return nil; + + if ((**pointer >= 'a' && **pointer <= 'z') || + (**pointer >= 'A' && **pointer <= 'Z') || + **pointer == '_' || **pointer == '$' || **pointer == '\\') + key = parseIdentifier(pointer, stop); + else + key = nextObject(pointer, stop); + + if (key == nil) return nil; skipWhitespacesAndComments(pointer, stop); if (*pointer + 1 >= stop || **pointer != ':') return nil; @@ -354,16 +498,17 @@ } static inline OFNumber* parseNumber(const char *restrict *pointer, const char *stop) { + BOOL isHex = (*pointer + 1 < stop && (*pointer)[1] == 'x'); BOOL hasDecimal = NO; size_t i; OFString *string; OFNumber *number; - for (i = 1; *pointer + i < stop; i++) { + for (i = 0; *pointer + i < stop; i++) { if ((*pointer)[i] == '.') hasDecimal = YES; if ((*pointer)[i] == ' ' || (*pointer)[i] == '\t' || (*pointer)[i] == '\r' || (*pointer)[i] == '\n' || @@ -378,10 +523,13 @@ @try { if (hasDecimal) number = [OFNumber numberWithDouble: [string doubleValue]]; + else if (isHex) + number = [OFNumber numberWithIntMax: + [string hexadecimalValue]]; else number = [OFNumber numberWithIntMax: [string decimalValue]]; } @finally { [string release]; @@ -398,10 +546,11 @@ if (*pointer >= stop) return nil; switch (**pointer) { case '"': + case '\'': return parseString(pointer, stop); case '[': return parseArray(pointer, stop); case '{': return parseDictionary(pointer, stop); @@ -444,10 +593,11 @@ case '6': case '7': case '8': case '9': case '-': + case '.': return parseNumber(pointer, stop); default: return nil; } } Index: src/OFString.h ================================================================== --- src/OFString.h +++ src/OFString.h @@ -632,14 +632,22 @@ /** * \brief Creates a new string by appending another string. * * \param string The string to append - * \return A new autoreleased OFString with the specified string appended + * \return A new, autoreleased OFString with the specified string appended */ - (OFString*)stringByAppendingString: (OFString*)string; +/** + * \brief Creates a new string by appending a path component. + * + * \param component The path component to append + * \return A new, autoreleased OFString with the path component appended + */ +- (OFString*)stringByAppendingPathComponent: (OFString*)component; + /** * \brief Creates a new string by prepending another string. * * \param string The string to prepend * \return A new autoreleased OFString with the specified string prepended Index: src/OFString.m ================================================================== --- src/OFString.m +++ src/OFString.m @@ -1411,10 +1411,15 @@ [new makeImmutable]; return new; } + +- (OFString*)stringByAppendingPathComponent: (OFString*)component +{ + return [OFString stringWithPath: self, component, nil]; +} - (OFString*)stringByPrependingString: (OFString*)string { OFMutableString *new = [[string mutableCopy] autorelease]; @@ -1516,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)]; @@ -1550,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, @@ -1952,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; @@ -1971,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]; @@ -1995,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) { Index: src/OFThreadPool.h ================================================================== --- src/OFThreadPool.h +++ src/OFThreadPool.h @@ -120,6 +120,13 @@ /** * \brief Waits until all threads have finished. */ - (void)waitUntilFinished; + +/** + * \brief Returns the size of the thread pool. + * + * \return The size of the thread pool + */ +- (size_t)size; @end Index: src/OFThreadPool.m ================================================================== --- src/OFThreadPool.m +++ src/OFThreadPool.m @@ -381,6 +381,11 @@ { [self _dispatchJob: [OFThreadPoolJob jobWithBlock: block object: object]]; } #endif + +- (size_t)size +{ + return size; +} @end Index: src/OFXMLElement.m ================================================================== --- src/OFXMLElement.m +++ src/OFXMLElement.m @@ -638,12 +638,12 @@ else child = [childrenObjects[j] XMLStringWithIndentation: ind level: level + 1]; - [tmp addNItems: [child UTF8StringLength] - fromCArray: [child UTF8String]]; + [tmp addItemsFromCArray: [child UTF8String] + count: [child UTF8StringLength]]; } if (indent) [tmp addItem: "\n"]; Index: src/OFXMLParser.m ================================================================== --- src/OFXMLParser.m +++ src/OFXMLParser.m @@ -43,19 +43,19 @@ static OF_INLINE void cache_append(OFDataArray *cache, const char *string, of_string_encoding_t encoding, size_t length) { if (OF_LIKELY(encoding == OF_STRING_ENCODING_UTF_8)) - [cache addNItems: length - fromCArray: string]; + [cache addItemsFromCArray: string + count: length]; else { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; OFString *tmp = [OFString stringWithCString: string encoding: encoding length: length]; - [cache addNItems: [tmp UTF8StringLength] - fromCArray: [tmp UTF8String]]; + [cache addItemsFromCArray: [tmp UTF8String] + count: [tmp UTF8StringLength]]; [pool release]; } } static OFString* Index: src/atomic.h ================================================================== --- src/atomic.h +++ src/atomic.h @@ -637,13 +637,12 @@ __asm__ ( "xorl %0, %0\n\t" "lock\n\t" "cmpxchg %2, %3\n\t" - "jne 0\n\t" - "incl %0\n" - "0:" + "sete %b0\n\t" + "movzbl %b0, %0" : "=&r"(r) : "a"(o), "r"(n), "m"(*p) ); return r; @@ -669,13 +668,12 @@ __asm__ ( "xorl %0, %0\n\t" "lock\n\t" "cmpxchg %2, %3\n\t" - "jne 0\n\t" - "incl %0\n" - "0:" + "sete %b0\n\t" + "movzbl %b0, %0" : "=&r"(r) : "a"(o), "r"(n), "m"(*p) ); return r; @@ -701,13 +699,12 @@ __asm__ ( "xorl %0, %0\n\t" "lock\n\t" "cmpxchg %2, %3\n\t" - "jne 0\n\t" - "incl %0\n" - "0:" + "sete %b0\n\t" + "movzbl %b0, %0" : "=&r"(r) : "a"(o), "r"(n), "m"(*p) ); return r; Index: src/base64.m ================================================================== --- src/base64.m +++ src/base64.m @@ -148,11 +148,11 @@ db[0] = (sb & 0xFF0000) >> 16; db[1] = (sb & 0x00FF00) >> 8; db[2] = sb & 0x0000FF; - [data addNItems: count - fromCArray: db]; + [data addItemsFromCArray: db + count: count]; } return YES; } Index: tests/OFArrayTests.m ================================================================== --- tests/OFArrayTests.m +++ tests/OFArrayTests.m @@ -57,12 +57,12 @@ [[a[0] description ]isEqual: @"(\n\tFoo,\n\tBar,\n\tBaz\n)"]) TEST(@"-[addObject:]", R([m[0] addObject: c_ary[0]]) && R([m[0] addObject: c_ary[2]])) - TEST(@"-[addObject:atIndex:]", R([m[0] addObject: c_ary[1] - atIndex: 1])) + TEST(@"-[insertObject:atIndex:]", R([m[0] insertObject: c_ary[1] + atIndex: 1])) TEST(@"-[count]", [m[0] count] == 3 && [a[0] count] == 3 && [a[1] count] == 3) TEST(@"-[isEqual:]", [m[0] isEqual: a[0]] && [a[0] isEqual: a[1]]) @@ -121,15 +121,10 @@ R([m[0] removeObject: c_ary[0]]) && [m[0] count] == 2) TEST(@"-[removeObjectIdenticalTo:]", R([m[0] removeObjectIdenticalTo: c_ary[2]]) && [m[0] count] == 1) - [m[0] addObject: c_ary[0]]; - [m[0] addObject: c_ary[1]]; - TEST(@"-[removeNObjects:]", R([m[0] removeNObjects: 2]) && - [m[0] count] == 1 && [[m[0] objectAtIndex: 0] isEqual: c_ary[0]]) - m[1] = [[a[0] mutableCopy] autorelease]; TEST(@"-[removeObjectAtIndex:]", R([m[1] removeObjectAtIndex: 1]) && [m[1] count] == 2 && [[m[1] objectAtIndex: 1] isEqual: c_ary[2]]) m[1] = [[a[0] mutableCopy] autorelease]; @@ -159,12 +154,13 @@ @"0", @"Bar", @"Baz", @"Foo", @"z", nil])]) EXPECT_EXCEPTION(@"Detect out of range in -[objectAtIndex:]", OFOutOfRangeException, [a[0] objectAtIndex: [a[0] count]]) - EXPECT_EXCEPTION(@"Detect out of range in -[removeNObjects:]", - OFOutOfRangeException, [m[0] removeNObjects: [m[0] count] + 1]) + EXPECT_EXCEPTION(@"Detect out of range in -[removeObjectsInRange:]", + OFOutOfRangeException, [m[0] removeObjectsInRange: + of_range(0, [m[0] count] + 1)]) TEST(@"-[componentsJoinedByString:]", (a[1] = [OFArray arrayWithObjects: @"foo", @"bar", @"baz", nil]) && [[a[1] componentsJoinedByString: @" "] isEqual: @"foo bar baz"] && (a[1] = [OFArray arrayWithObject: @"foo"]) && @@ -232,11 +228,11 @@ ok = YES; } TEST(@"Detection of mutation during Fast Enumeration", ok) - [m[0] removeNObjects: 1]; + [m[0] removeLastObject]; #endif #ifdef OF_HAVE_BLOCKS { __block BOOL ok = YES; Index: tests/OFDataArrayTests.m ================================================================== --- tests/OFDataArrayTests.m +++ tests/OFDataArrayTests.m @@ -57,14 +57,14 @@ other = (class == [OFDataArray class] ? [OFBigDataArray class] : [OFDataArray class]); TEST(@"-[isEqual:]", (array[1] = [other dataArrayWithItemSize: 4096]) && - R([array[1] addNItems: [array[0] count] - fromCArray: [array[0] cArray]]) && + R([array[1] addItemsFromCArray: [array[0] cArray] + count: [array[0] count]]) && [array[1] isEqual: array[0]] && - R([array[1] removeNItems: 1]) && ![array[0] isEqual: array[1]]) + R([array[1] removeLastItem]) && ![array[0] isEqual: array[1]]) TEST(@"-[copy]", (array[1] = [[array[0] copy] autorelease]) && [array[0] isEqual: array[1]]) array[2] = [OFDataArray dataArray]; @@ -71,34 +71,33 @@ array[3] = [OFDataArray dataArray]; [array[2] addItem: "a"]; [array[2] addItem: "a"]; [array[3] addItem: "z"]; TEST(@"-[compare]", [array[0] compare: array[1]] == 0 && - R([array[1] removeNItems: 1]) && + R([array[1] removeLastItem]) && [array[0] compare: array[1]] == OF_ORDERED_DESCENDING && [array[1] compare: array[0]] == OF_ORDERED_ASCENDING && [array[2] compare: array[3]] == OF_ORDERED_ASCENDING) TEST(@"-[hash]", [array[0] hash] == 0x634A529F) array[0] = [class dataArray]; - [array[0] addNItems: 6 - fromCArray: "abcdef"]; + [array[0] addItemsFromCArray: "abcdef" + count: 6]; - TEST(@"-[removeNItems:]", R([array[0] removeNItems: 1]) && + TEST(@"-[removeLastItem]", R([array[0] removeLastItem]) && [array[0] count] == 5 && !memcmp([array[0] cArray], "abcde", 5)) - TEST(@"-[removeNItems:atIndex:]", - R([array[0] removeNItems: 2 - atIndex: 1]) && [array[0] count] == 3 && - !memcmp([array[0] cArray], "ade", 3)) - - TEST(@"-[addNItems:atIndex:]", - R([array[0] addNItems: 2 - fromCArray: "bc" - atIndex: 1]) && [array[0] count] == 5 && + TEST(@"-[removeItemsInRange:]", + R([array[0] removeItemsInRange: of_range(1, 2)]) && + [array[0] count] == 3 && !memcmp([array[0] cArray], "ade", 3)) + + TEST(@"-[insertItemsFromCArray:atIndex:count:]", + R([array[0] insertItemsFromCArray: "bc" + atIndex: 1 + count: 2]) && [array[0] count] == 5 && !memcmp([array[0] cArray], "abcde", 5)) TEST(@"-[MD5Hash]", [[array[0] MD5Hash] isEqual: [@"abcde" MD5Hash]]) TEST(@"-[SHA1Hash]", [[array[0] SHA1Hash] isEqual: [@"abcde" SHA1Hash]]) @@ -110,24 +109,25 @@ !memcmp([[class dataArrayWithBase64EncodedString: @"YWJjZGU="] cArray], "abcde", 5)) TEST(@"Building strings", (array[0] = [class dataArray]) && - R([array[0] addNItems: 6 - fromCArray: (void*)str]) && R([array[0] addItem: ""]) && + R([array[0] addItemsFromCArray: (void*)str + count: 6]) && R([array[0] addItem: ""]) && !strcmp([array[0] cArray], str)) EXPECT_EXCEPTION(@"Detect out of range in -[itemAtIndex:]", OFOutOfRangeException, [array[0] itemAtIndex: [array[0] count]]) - EXPECT_EXCEPTION(@"Detect out of range in -[addNItems:fromCArray:]", - OFOutOfRangeException, [array[0] addNItems: SIZE_MAX - fromCArray: NULL]) + EXPECT_EXCEPTION(@"Detect out of range in " + @"-[addItemsFromCArray:count:]", + OFOutOfRangeException, [array[0] addItemsFromCArray: NULL + count: SIZE_MAX]) - EXPECT_EXCEPTION(@"Detect out of range in -[removeNItems:]", + EXPECT_EXCEPTION(@"Detect out of range in -[removeItemsInRange:]", OFOutOfRangeException, - [array[0] removeNItems: [array[0] count] + 1]) + [array[0] removeItemsInRange: of_range([array[0] count], 1)]) } - (void)dataArrayTests { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; Index: tests/OFJSONTests.m ================================================================== --- tests/OFJSONTests.m +++ tests/OFJSONTests.m @@ -31,26 +31,27 @@ @implementation TestsAppDelegate (JSONTests) - (void)JSONTests { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; - OFString *s = @"{\"foo\"\t:\"bar\", \"x\":/*fooo*/ [7.5\r,null//bar\n" + OFString *s = @"{\"foo\"\t:'ba\\r', \"x\":/*foo*/ [.5\r,0xF,null//bar\n" @",\"foo\",false]}"; OFDictionary *d = [OFDictionary dictionaryWithKeysAndObjects: - @"foo", @"bar", + @"foo", @"ba\r", @"x", [OFArray arrayWithObjects: - [OFNumber numberWithFloat: 7.5f], + [OFNumber numberWithFloat: .5f], + [OFNumber numberWithInt: 0xF], [OFNull null], @"foo", [OFNumber numberWithBool: NO], nil], nil]; TEST(@"-[JSONValue #1]", [[s JSONValue] isEqual: d]) TEST(@"-[JSONRepresentation]", [[d JSONRepresentation] isEqual: - @"{\"foo\":\"bar\",\"x\":[7.5,null,\"foo\",false]}"]) + @"{\"foo\":\"ba\\r\",\"x\":[0.5,15,null,\"foo\",false]}"]) EXPECT_EXCEPTION(@"-[JSONValue #2]", OFInvalidEncodingException, [@"{" JSONValue]) EXPECT_EXCEPTION(@"-[JSONValue #3]", OFInvalidEncodingException, [@"]" JSONValue]) Index: tests/OFSerializationTests.m ================================================================== --- tests/OFSerializationTests.m +++ tests/OFSerializationTests.m @@ -65,12 +65,12 @@ [OFCountedSet setWithObjects: @"foo", @"foo", @"bar", nil]]; [d setObject: @"list" forKey: l]; - [da addNItems: 39 - fromCArray: "0123456789:;