Comment: | Slightly change the memory management API.
Also fix a bug where OFBigDataArray would waste memory. |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
f7576a66ce8f3b5841cc52203f73bbdb |
User & Date: | js on 2012-06-06 13:47:52 |
Other Links: | manifest | tags |
2012-06-06
| ||
17:16 | Rename -[OFXMLParser parseBuffer:withLength:]. check-in: 7a42ee8f11 user: js tags: trunk | |
14:05 | Merge branch 'master' into runtime check-in: 050ac82798 user: js tags: runtime | |
13:47 | Slightly change the memory management API. check-in: f7576a66ce user: js tags: trunk | |
13:14 | Remove -[OFMutableArray removeNObjects:]. check-in: 6f0ef1c5e1 user: js tags: trunk | |
Modified src/OFArray.m from [006ecd6265] to [5ae87127d9].
︙ | ︙ | |||
242 243 244 245 246 247 248 | { OFObject *container; size_t count; id *buffer; container = [[[OFObject alloc] init] autorelease]; count = [self count]; | | | | 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 | { OFObject *container; size_t count; id *buffer; container = [[[OFObject alloc] init] autorelease]; count = [self count]; buffer = [container allocMemoryWithItemSize: sizeof(*buffer) count: [self count]]; [self getObjects: buffer inRange: of_range(0, count)]; return buffer; } |
︙ | ︙ | |||
331 332 333 334 335 336 337 | OFArray *ret; id *buffer; if (![self isKindOfClass: [OFMutableArray class]]) return [OFArray_subarray arrayWithArray: self range: range]; | | | | 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 | OFArray *ret; id *buffer; if (![self isKindOfClass: [OFMutableArray class]]) return [OFArray_subarray arrayWithArray: self range: range]; buffer = [self allocMemoryWithItemSize: sizeof(*buffer) count: range.length]; @try { [self getObjects: buffer inRange: range]; ret = [OFArray arrayWithObjects: buffer count: range.length]; |
︙ | ︙ | |||
605 606 607 608 609 610 611 | #endif #ifdef OF_HAVE_BLOCKS - (OFArray*)mappedArrayUsingBlock: (of_array_map_block_t)block { OFArray *ret; size_t count = [self count]; | | | | | | 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 | #endif #ifdef OF_HAVE_BLOCKS - (OFArray*)mappedArrayUsingBlock: (of_array_map_block_t)block { OFArray *ret; size_t count = [self count]; id *tmp = [self allocMemoryWithItemSize: sizeof(id) count: count]; @try { [self enumerateObjectsUsingBlock: ^ (id object, size_t index, BOOL *stop) { tmp[index] = block(object, index); }]; ret = [OFArray arrayWithObjects: tmp count: count]; } @finally { [self freeMemory: tmp]; } return ret; } - (OFArray*)filteredArrayUsingBlock: (of_array_filter_block_t)block { OFArray *ret; size_t count = [self count]; id *tmp = [self allocMemoryWithItemSize: sizeof(id) count: count]; @try { __block size_t i = 0; [self enumerateObjectsUsingBlock: ^ (id object, size_t index, BOOL *stop) { if (block(object, index)) |
︙ | ︙ |
Modified src/OFAutoreleasePool.m from [9f23f6d996] to [bc3a0d2a2f].
︙ | ︙ | |||
117 118 119 120 121 122 123 | #endif } if (previousPool != nil) previousPool->nextPool = self; size = GROW_SIZE; | | | < | > | 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 | #endif } if (previousPool != nil) previousPool->nextPool = self; size = GROW_SIZE; objects = [self allocMemoryWithItemSize: sizeof(id) count: GROW_SIZE]; } @catch (id e) { [self release]; @throw e; } return self; } - (void)_addObject: (id)object { if (count + 1 > size) { objects = [self resizeMemory: objects itemSize: sizeof(id) count: size + GROW_SIZE]; size += GROW_SIZE; } objects[count] = object; count++; } |
︙ | ︙ |
Modified src/OFDataArray.m from [490fab954b] to [1c8a76eb56].
︙ | ︙ | |||
253 254 255 256 257 258 259 | - (void)addItem: (const void*)item { if (SIZE_MAX - count < 1) @throw [OFOutOfRangeException exceptionWithClass: isa]; data = [self resizeMemory: data | < | > | 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 | - (void)addItem: (const void*)item { if (SIZE_MAX - count < 1) @throw [OFOutOfRangeException exceptionWithClass: isa]; data = [self resizeMemory: data itemSize: itemSize count: count + 1]; memcpy(data + count * itemSize, item, itemSize); count++; } - (void)insertItem: (const void*)item |
︙ | ︙ | |||
276 277 278 279 280 281 282 | - (void)addItemsFromCArray: (const void*)cArray count: (size_t)nItems { if (nItems > SIZE_MAX - count) @throw [OFOutOfRangeException exceptionWithClass: isa]; data = [self resizeMemory: data | < | > < | > | 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 | - (void)addItemsFromCArray: (const void*)cArray count: (size_t)nItems { if (nItems > SIZE_MAX - count) @throw [OFOutOfRangeException exceptionWithClass: isa]; data = [self resizeMemory: data itemSize: itemSize count: count + nItems]; memcpy(data + count * itemSize, cArray, nItems * itemSize); count += nItems; } - (void)insertItemsFromCArray: (const void*)cArray atIndex: (size_t)index count: (size_t)nItems { if (nItems > SIZE_MAX - count || index > count) @throw [OFOutOfRangeException exceptionWithClass: isa]; data = [self resizeMemory: data itemSize: itemSize count: count + nItems]; memmove(data + (index + nItems) * itemSize, data + index * itemSize, (count - index) * itemSize); memcpy(data + index * itemSize, cArray, nItems * itemSize); count += nItems; } |
︙ | ︙ | |||
318 319 320 321 322 323 324 | 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 | < | > < | > | 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 | 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 */ } } - (void)removeLastItem { if (count < 1) @throw [OFOutOfRangeException exceptionWithClass: isa]; count--; @try { data = [self resizeMemory: data itemSize: itemSize count: count]; } @catch (OFOutOfMemoryException *e) { /* We don't care, as we only made it smaller */ } } - (void)removeAllItems { |
︙ | ︙ | |||
565 566 567 568 569 570 571 | count--; lastPageByte = of_pagesize - 1; newSize = (count * itemSize + lastPageByte) & ~lastPageByte; if (size != newSize) { @try { data = [self resizeMemory: data | < | | 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 | count--; lastPageByte = of_pagesize - 1; newSize = (count * itemSize + lastPageByte) & ~lastPageByte; if (size != newSize) { @try { data = [self resizeMemory: data toSize: newSize]; } @catch (OFOutOfMemoryException *e) { /* We don't care, as we only made it smaller */ } size = newSize; } } |
︙ | ︙ |
Modified src/OFDictionary.m from [7004ce02ac] to [170550a25e].
︙ | ︙ | |||
348 349 350 351 352 353 354 | return NO; } - (OFArray*)allKeys { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; | | | | 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 | return NO; } - (OFArray*)allKeys { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; id *keys = [self allocMemoryWithItemSize: sizeof(id) count: [self count]]; OFArray *ret; OFEnumerator *enumerator; id key; size_t i = 0; pool = [[OFAutoreleasePool alloc] init]; enumerator = [self keyEnumerator]; |
︙ | ︙ | |||
378 379 380 381 382 383 384 | return ret; } - (OFArray*)allObjects { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; | | | | 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 | return ret; } - (OFArray*)allObjects { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; id *objects = [self allocMemoryWithItemSize: sizeof(id) count: [self count]]; OFArray *ret; OFEnumerator *enumerator; id object; size_t i = 0; pool = [[OFAutoreleasePool alloc] init]; enumerator = [self objectEnumerator]; |
︙ | ︙ |
Modified src/OFDictionary_hashtable.m from [2511a02b50] to [c77b46c66d].
︙ | ︙ | |||
77 78 79 80 81 82 83 | [OFMutableDictionary_hashtable class]]) @throw [OFInvalidArgumentException exceptionWithClass: isa selector: _cmd]; hashtable = (OFDictionary_hashtable*)dictionary; | | | | 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 | [OFMutableDictionary_hashtable class]]) @throw [OFInvalidArgumentException exceptionWithClass: isa selector: _cmd]; hashtable = (OFDictionary_hashtable*)dictionary; data = [self allocMemoryWithItemSize: sizeof(*data) count: hashtable->size]; for (i = 0; i < hashtable->size; i++) data[i] = NULL; size = hashtable->size; count = hashtable->count; |
︙ | ︙ | |||
137 138 139 140 141 142 143 | for (newSize = 1; newSize < count; newSize <<= 1); if (count * 4 / newSize >= 3) newSize <<= 1; if (newSize == 0) @throw [OFOutOfRangeException exceptionWithClass: isa]; | | | | 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 | for (newSize = 1; newSize < count; newSize <<= 1); if (count * 4 / newSize >= 3) newSize <<= 1; if (newSize == 0) @throw [OFOutOfRangeException exceptionWithClass: isa]; data = [self allocMemoryWithItemSize: sizeof(*data) count: newSize]; for (i = 0; i < newSize; i++) data[i] = NULL; size = newSize; pool = [[OFAutoreleasePool alloc] init]; |
︙ | ︙ | |||
204 205 206 207 208 209 210 | struct of_dictionary_hashtable_bucket *bucket; if (key == nil || object == nil) @throw [OFInvalidArgumentException exceptionWithClass: isa selector: _cmd]; | | | | 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 | struct of_dictionary_hashtable_bucket *bucket; if (key == nil || object == nil) @throw [OFInvalidArgumentException exceptionWithClass: isa selector: _cmd]; data = [self allocMemoryWithItemSize: sizeof(*data) count: 2]; size = 2; for (i = 0; i < size; i++) data[i] = NULL; i = [key hash] & 1; |
︙ | ︙ | |||
270 271 272 273 274 275 276 | for (newSize = 1; newSize < count; newSize <<= 1); if (count * 4 / newSize >= 3) newSize <<= 1; if (newSize == 0) @throw [OFOutOfRangeException exceptionWithClass: isa]; | | | | 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 | for (newSize = 1; newSize < count; newSize <<= 1); if (count * 4 / newSize >= 3) newSize <<= 1; if (newSize == 0) @throw [OFOutOfRangeException exceptionWithClass: isa]; data = [self allocMemoryWithItemSize: sizeof(*data) count: newSize]; for (j = 0; j < newSize; j++) data[j] = NULL; size = newSize; for (i = 0; i < count; i++) { |
︙ | ︙ | |||
391 392 393 394 395 396 397 | for (newSize = 1; newSize < count; newSize <<= 1); if (count * 4 / newSize >= 3) newSize <<= 1; if (newSize == 0) @throw [OFOutOfRangeException exceptionWithClass: isa]; | | | | 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 | for (newSize = 1; newSize < count; newSize <<= 1); if (count * 4 / newSize >= 3) newSize <<= 1; if (newSize == 0) @throw [OFOutOfRangeException exceptionWithClass: isa]; data = [self allocMemoryWithItemSize: sizeof(*data) count: newSize]; for (j = 0; j < newSize; j++) data[j] = NULL; size = newSize; /* Add first key / object pair */ |
︙ | ︙ | |||
644 645 646 647 648 649 650 | return NO; } - (OFArray*)allKeys { OFArray *ret; | | | | 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 | return NO; } - (OFArray*)allKeys { OFArray *ret; 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; assert(j == count); |
︙ | ︙ | |||
667 668 669 670 671 672 673 | return ret; } - (OFArray*)allObjects { OFArray *ret; | | | | 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 | return ret; } - (OFArray*)allObjects { OFArray *ret; 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; assert(j == count); |
︙ | ︙ |
Modified src/OFMutableArray_adjacent.m from [50b79cf523] to [489af893ca].
︙ | ︙ | |||
160 161 162 163 164 165 166 | { id *objects = [array cArray], *copy; size_t i, count = [array count]; if (range.length > count - range.start) @throw [OFOutOfRangeException exceptionWithClass: isa]; | | | | 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 | { id *objects = [array cArray], *copy; size_t i, count = [array count]; if (range.length > count - range.start) @throw [OFOutOfRangeException exceptionWithClass: isa]; copy = [self allocMemoryWithItemSize: sizeof(*copy) count: range.length]; memcpy(copy, objects + range.start, range.length * sizeof(id)); @try { [array removeItemsInRange: range]; mutations++; for (i = 0; i < range.length; i++) |
︙ | ︙ |
Modified src/OFMutableDictionary_hashtable.m from [13d8064ed3] to [959d2e2496].
︙ | ︙ | |||
56 57 58 59 60 61 62 | newSize = size >> 1; else return; if (newSize == 0) @throw [OFOutOfRangeException exceptionWithClass: isa]; | | | | 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | newSize = size >> 1; else return; if (newSize == 0) @throw [OFOutOfRangeException exceptionWithClass: isa]; newData = [self allocMemoryWithItemSize: sizeof(*newData) count: newSize]; for (i = 0; i < newSize; i++) newData[i] = NULL; for (i = 0; i < size; i++) { if (data[i] != NULL && data[i] != DELETED) { uint32_t j, last; |
︙ | ︙ |
Modified src/OFMutableSet.m from [112af5c677] to [f111a1faac].
︙ | ︙ | |||
155 156 157 158 159 160 161 | - (void)intersectSet: (OFSet*)set { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; size_t count = [self count]; id *cArray; | | | | 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 | - (void)intersectSet: (OFSet*)set { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; size_t count = [self count]; id *cArray; cArray = [self allocMemoryWithItemSize: sizeof(id) count: count]; @try { OFEnumerator *enumerator = [self objectEnumerator]; id object; size_t i = 0; while ((object = [enumerator nextObject]) != nil) { |
︙ | ︙ |
Modified src/OFMutableString_UTF8.m from [6763734ad5] to [3f21e1777e].
︙ | ︙ | |||
65 66 67 68 69 70 71 | if ((t = table[0][*p]) != 0) *p = t; return; } unicodeLen = [self length]; | | | | 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 | if ((t = table[0][*p]) != 0) *p = t; return; } unicodeLen = [self length]; unicodeString = [self allocMemoryWithItemSize: sizeof(of_unichar_t) count: unicodeLen]; i = j = 0; newCStringLength = 0; while (i < s->cStringLength) { cLen = of_string_utf8_to_unicode(s->cString + i, s->cStringLength - i, &c); |
︙ | ︙ |
Modified src/OFObject.h from [34ca0c3322] to [08ae6bde87].
︙ | ︙ | |||
497 498 499 500 501 502 503 | /** * \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. * | < | > | | | 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 | /** * \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 itemSize The size of each item to allocate * \param count The number of items to allocate * \return A pointer to the allocated memory */ - (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. * If the size is 0, this is equivalent to freeing memory. * |
︙ | ︙ | |||
525 526 527 528 529 530 531 | * \brief Resizes memory in the object's memory pool to the specific number of * items of the specified size. * * 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 | < | > | | | 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 | * \brief Resizes memory in the object's memory pool to the specific number of * items of the specified size. * * 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 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 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. * * \param pointer A pointer to the allocated memory |
︙ | ︙ |
Modified src/OFObject.m from [708e72ca3d] to [51c24d6468].
︙ | ︙ | |||
799 800 801 802 803 804 805 | PRE_IVAR->lastMem->next = preMem; PRE_IVAR->lastMem = preMem; return (char*)pointer + PRE_MEM_ALIGN; } | | | | | | | 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 | PRE_IVAR->lastMem->next = preMem; PRE_IVAR->lastMem = preMem; return (char*)pointer + PRE_MEM_ALIGN; } - (void*)allocMemoryWithItemSize: (size_t)itemSize count: (size_t)count { if (itemSize == 0 || count == 0) return NULL; if (count > SIZE_MAX / itemSize) @throw [OFOutOfRangeException exceptionWithClass: isa]; return [self allocMemoryWithSize: itemSize * count]; } - (void*)resizeMemory: (void*)pointer toSize: (size_t)size { void *new; struct pre_mem *preMem; |
︙ | ︙ | |||
851 852 853 854 855 856 857 | PRE_IVAR->lastMem = preMem; } return (char*)new + PRE_MEM_ALIGN; } - (void*)resizeMemory: (void*)pointer | | | | | | | | | 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 | PRE_IVAR->lastMem = preMem; } return (char*)new + PRE_MEM_ALIGN; } - (void*)resizeMemory: (void*)pointer itemSize: (size_t)itemSize count: (size_t)count { if (pointer == NULL) return [self allocMemoryWithItemSize: itemSize count: count]; if (itemSize == 0 || count == 0) { [self freeMemory: pointer]; return NULL; } if (count > SIZE_MAX / itemSize) @throw [OFOutOfRangeException exceptionWithClass: isa]; return [self resizeMemory: pointer toSize: itemSize * count]; } - (void)freeMemory: (void*)pointer { if (pointer == NULL) return; |
︙ | ︙ | |||
1028 1029 1030 1031 1032 1033 1034 | */ + (void*)allocMemoryWithSize: (size_t)size { @throw [OFNotImplementedException exceptionWithClass: self selector: _cmd]; } | | | | | | 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 | */ + (void*)allocMemoryWithSize: (size_t)size { @throw [OFNotImplementedException exceptionWithClass: self selector: _cmd]; } + (void*)allocMemoryWithItemSize: (size_t)itemSize count: (size_t)count { @throw [OFNotImplementedException exceptionWithClass: self selector: _cmd]; } + (void*)resizeMemory: (void*)pointer toSize: (size_t)size { @throw [OFNotImplementedException exceptionWithClass: self selector: _cmd]; } + (void*)resizeMemory: (void*)pointer itemSize: (size_t)itemSize count: (size_t)count { @throw [OFNotImplementedException exceptionWithClass: self selector: _cmd]; } + (void)freeMemory: (void*)pointer { |
︙ | ︙ |
Modified src/OFProcess.m from [53a70ada66] to [6f88407ce3].
︙ | ︙ | |||
87 88 89 90 91 92 93 | switch ((pid = fork())) { case 0:; OFString **objects = [arguments objects]; size_t i, count = [arguments count]; char **argv; | | | | 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 | switch ((pid = fork())) { case 0:; OFString **objects = [arguments objects]; size_t i, count = [arguments count]; char **argv; argv = [self allocMemoryWithItemSize: sizeof(char*) count: count + 2]; argv[0] = (char*)[programName cStringWithEncoding: OF_STRING_ENCODING_NATIVE]; for (i = 0; i < count; i++) argv[i + 1] = (char*)[objects[i] cStringWithEncoding: |
︙ | ︙ |
Modified src/OFStream.m from [4d96b81ee9] to [a84cb06e69].
︙ | ︙ | |||
442 443 444 445 446 447 448 | - (OFDataArray*)readDataArrayWithItemSize: (size_t)itemSize andNItems: (size_t)nItems { OFDataArray *dataArray; char *tmp; dataArray = [OFDataArray dataArrayWithItemSize: itemSize]; | | | | 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 | - (OFDataArray*)readDataArrayWithItemSize: (size_t)itemSize andNItems: (size_t)nItems { OFDataArray *dataArray; char *tmp; dataArray = [OFDataArray dataArrayWithItemSize: itemSize]; tmp = [self allocMemoryWithItemSize: itemSize count: nItems]; @try { [self readExactlyNBytes: nItems * itemSize intoBuffer: tmp]; [dataArray addItemsFromCArray: tmp count: nItems]; |
︙ | ︙ | |||
939 940 941 942 943 944 945 | #ifdef OF_BIG_ENDIAN [self writeNBytes: size fromBuffer: buffer]; #else uint16_t *tmp; | | | | 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 | #ifdef OF_BIG_ENDIAN [self writeNBytes: size fromBuffer: buffer]; #else uint16_t *tmp; tmp = [self allocMemoryWithItemSize: sizeof(uint16_t) count: nInt16s]; @try { size_t i; for (i = 0; i < nInt16s; i++) tmp[i] = of_bswap16(buffer[i]); |
︙ | ︙ | |||
969 970 971 972 973 974 975 | #ifdef OF_BIG_ENDIAN [self writeNBytes: size fromBuffer: buffer]; #else uint32_t *tmp; | | | | 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 | #ifdef OF_BIG_ENDIAN [self writeNBytes: size fromBuffer: buffer]; #else uint32_t *tmp; tmp = [self allocMemoryWithItemSize: sizeof(uint32_t) count: nInt32s]; @try { size_t i; for (i = 0; i < nInt32s; i++) tmp[i] = of_bswap32(buffer[i]); |
︙ | ︙ | |||
999 1000 1001 1002 1003 1004 1005 | #ifdef OF_BIG_ENDIAN [self writeNBytes: size fromBuffer: buffer]; #else uint64_t *tmp; | | | | 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 | #ifdef OF_BIG_ENDIAN [self writeNBytes: size fromBuffer: buffer]; #else uint64_t *tmp; tmp = [self allocMemoryWithItemSize: sizeof(uint64_t) count: nInt64s]; @try { size_t i; for (i = 0; i < nInt64s; i++) tmp[i] = of_bswap64(buffer[i]); |
︙ | ︙ | |||
1029 1030 1031 1032 1033 1034 1035 | #ifdef OF_FLOAT_BIG_ENDIAN [self writeNBytes: size fromBuffer: buffer]; #else float *tmp; | | | | 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 | #ifdef OF_FLOAT_BIG_ENDIAN [self writeNBytes: size fromBuffer: buffer]; #else float *tmp; tmp = [self allocMemoryWithItemSize: sizeof(float) count: nFloats]; @try { size_t i; for (i = 0; i < nFloats; i++) tmp[i] = of_bswap_float(buffer[i]); |
︙ | ︙ | |||
1059 1060 1061 1062 1063 1064 1065 | #ifdef OF_FLOAT_BIG_ENDIAN [self writeNBytes: size fromBuffer: buffer]; #else double *tmp; | | | | 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 | #ifdef OF_FLOAT_BIG_ENDIAN [self writeNBytes: size fromBuffer: buffer]; #else double *tmp; tmp = [self allocMemoryWithItemSize: sizeof(double) count: nDoubles]; @try { size_t i; for (i = 0; i < nDoubles; i++) tmp[i] = of_bswap_double(buffer[i]); |
︙ | ︙ | |||
1129 1130 1131 1132 1133 1134 1135 | #ifndef OF_BIG_ENDIAN [self writeNBytes: size fromBuffer: buffer]; #else uint16_t *tmp; | | | | 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 | #ifndef OF_BIG_ENDIAN [self writeNBytes: size fromBuffer: buffer]; #else uint16_t *tmp; tmp = [self allocMemoryWithItemSize: sizeof(uint16_t) count: nInt16s]; @try { size_t i; for (i = 0; i < nInt16s; i++) tmp[i] = of_bswap16(buffer[i]); |
︙ | ︙ | |||
1159 1160 1161 1162 1163 1164 1165 | #ifndef OF_BIG_ENDIAN [self writeNBytes: size fromBuffer: buffer]; #else uint32_t *tmp; | | | | 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 | #ifndef OF_BIG_ENDIAN [self writeNBytes: size fromBuffer: buffer]; #else uint32_t *tmp; tmp = [self allocMemoryWithItemSize: sizeof(uint32_t) count: nInt32s]; @try { size_t i; for (i = 0; i < nInt32s; i++) tmp[i] = of_bswap32(buffer[i]); |
︙ | ︙ | |||
1189 1190 1191 1192 1193 1194 1195 | #ifndef OF_BIG_ENDIAN [self writeNBytes: size fromBuffer: buffer]; #else uint64_t *tmp; | | | | 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 | #ifndef OF_BIG_ENDIAN [self writeNBytes: size fromBuffer: buffer]; #else uint64_t *tmp; tmp = [self allocMemoryWithItemSize: sizeof(uint64_t) count: nInt64s]; @try { size_t i; for (i = 0; i < nInt64s; i++) tmp[i] = of_bswap64(buffer[i]); |
︙ | ︙ | |||
1219 1220 1221 1222 1223 1224 1225 | #ifndef OF_FLOAT_BIG_ENDIAN [self writeNBytes: size fromBuffer: buffer]; #else float *tmp; | | | | 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 | #ifndef OF_FLOAT_BIG_ENDIAN [self writeNBytes: size fromBuffer: buffer]; #else float *tmp; tmp = [self allocMemoryWithItemSize: sizeof(float) count: nFloats]; @try { size_t i; for (i = 0; i < nFloats; i++) tmp[i] = of_bswap_float(buffer[i]); |
︙ | ︙ | |||
1249 1250 1251 1252 1253 1254 1255 | #ifndef OF_FLOAT_BIG_ENDIAN [self writeNBytes: size fromBuffer: buffer]; #else double *tmp; | | | | 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 | #ifndef OF_FLOAT_BIG_ENDIAN [self writeNBytes: size fromBuffer: buffer]; #else double *tmp; tmp = [self allocMemoryWithItemSize: sizeof(double) count: nDoubles]; @try { size_t i; for (i = 0; i < nDoubles; i++) tmp[i] = of_bswap_double(buffer[i]); |
︙ | ︙ |
Modified src/OFStreamObserver.m from [9591f1939e] to [75b0a6497b].
︙ | ︙ | |||
135 136 137 138 139 140 141 | if (getsockname(cancelFD[0], (struct sockaddr*)&cancelAddr, &cancelAddrLen)) @throw [OFInitializationFailedException exceptionWithClass: isa]; #endif maxFD = cancelFD[0]; | | | | 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 | if (getsockname(cancelFD[0], (struct sockaddr*)&cancelAddr, &cancelAddrLen)) @throw [OFInitializationFailedException exceptionWithClass: isa]; #endif maxFD = cancelFD[0]; FDToStream = [self allocMemoryWithItemSize: sizeof(OFStream*) count: maxFD + 1]; FDToStream[cancelFD[0]] = nil; #ifdef OF_THREADS mutex = [[OFMutex alloc] init]; #endif } @catch (id e) { [self release]; |
︙ | ︙ | |||
308 309 310 311 312 313 314 | int fd = queueFDsCArray[i]; if ((action & QUEUE_ACTION) == QUEUE_ADD) { if (fd > maxFD) { maxFD = fd; FDToStream = [self resizeMemory: FDToStream | < | > | 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 | int fd = queueFDsCArray[i]; if ((action & QUEUE_ACTION) == QUEUE_ADD) { if (fd > maxFD) { maxFD = fd; FDToStream = [self resizeMemory: FDToStream itemSize: sizeof(OFStream*) count: maxFD + 1]; } FDToStream[fd] = stream; } if ((action & QUEUE_ACTION) == QUEUE_REMOVE) { /* FIXME: Maybe downsize? */ |
︙ | ︙ |
Modified src/OFString.m from [40151bee8f] to [788fd6f59d].
︙ | ︙ | |||
1519 1520 1521 1522 1523 1524 1525 | const of_unichar_t *prefixString; size_t prefixLength; int compare; if ((prefixLength = [prefix length]) > [self length]) return NO; | < | > | 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 | const of_unichar_t *prefixString; size_t prefixLength; int compare; if ((prefixLength = [prefix length]) > [self length]) return NO; tmp = [self allocMemoryWithItemSize: sizeof(of_unichar_t) count: prefixLength]; @try { OFAutoreleasePool *pool; [self getCharacters: tmp inRange: of_range(0, prefixLength)]; pool = [[OFAutoreleasePool alloc] init]; |
︙ | ︙ | |||
1553 1554 1555 1556 1557 1558 1559 | int compare; if ((suffixLength = [suffix length]) > [self length]) return NO; length = [self length]; | < | > | 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 | int compare; if ((suffixLength = [suffix length]) > [self length]) return NO; length = [self length]; tmp = [self allocMemoryWithItemSize: sizeof(of_unichar_t) count: suffixLength]; @try { OFAutoreleasePool *pool; [self getCharacters: tmp inRange: of_range(length - suffixLength, suffixLength)]; |
︙ | ︙ | |||
1955 1956 1957 1958 1959 1960 1961 | - (const of_unichar_t*)unicodeString { OFObject *object = [[[OFObject alloc] init] autorelease]; size_t length = [self length]; of_unichar_t *ret; | | | | | | 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 | - (const of_unichar_t*)unicodeString { OFObject *object = [[[OFObject alloc] init] autorelease]; size_t length = [self length]; of_unichar_t *ret; ret = [object allocMemoryWithItemSize: sizeof(of_unichar_t) count: length + 1]; [self getCharacters: ret inRange: of_range(0, length)]; ret[length] = 0; return ret; } - (const uint16_t*)UTF16String { OFObject *object = [[[OFObject alloc] init] autorelease]; OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; const of_unichar_t *unicodeString = [self unicodeString]; size_t length = [self length]; uint16_t *ret; size_t i, j; /* Allocate memory for the worst case */ ret = [object allocMemoryWithItemSize: sizeof(uint16_t) count: length * 2 + 1]; j = 0; for (i = 0; i < length; i++) { of_unichar_t c = unicodeString[i]; if (c > 0x10FFFF) |
︙ | ︙ | |||
1998 1999 2000 2001 2002 2003 2004 | ret[j++] = of_bswap16_if_le(c); } ret[j] = 0; @try { ret = [object resizeMemory: ret | < | > | 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 | ret[j++] = of_bswap16_if_le(c); } ret[j] = 0; @try { ret = [object resizeMemory: ret itemSize: sizeof(uint16_t) count: j + 1]; } @catch (OFOutOfMemoryException *e) { /* We don't care, as we only tried to make it smaller */ } [pool release]; return ret; |
︙ | ︙ |
Modified src/OFString_UTF8.m from [03beefc292] to [5faa6d539b].
︙ | ︙ | |||
1090 1091 1092 1093 1094 1095 1096 | - (const of_unichar_t*)unicodeString { OFObject *object = [[[OFObject alloc] init] autorelease]; of_unichar_t *ret; size_t i, j; | | | | 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 | - (const of_unichar_t*)unicodeString { OFObject *object = [[[OFObject alloc] init] autorelease]; of_unichar_t *ret; size_t i, j; ret = [object allocMemoryWithItemSize: sizeof(of_unichar_t) count: s->length + 1]; i = 0; j = 0; while (i < s->cStringLength) { of_unichar_t c; size_t cLen; |
︙ | ︙ |