Comment: | More API improvements. |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
11d3d69a2258d53f34bbd4bfe632ee9e |
User & Date: | js on 2012-06-10 13:28:05 |
Other Links: | manifest | tags |
2012-06-10
| ||
16:03 | Add a few array methods. check-in: 95e8e1e486 user: js tags: trunk | |
13:28 | More API improvements. check-in: 11d3d69a22 user: js tags: trunk | |
2012-06-07
| ||
12:03 | Rework OFStream API. check-in: 0d4059306a user: js tags: trunk | |
Modified src/OFArray.m from [5ae87127d9] to [b302a054ee].
︙ | ︙ | |||
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 allocMemoryWithSize: 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 allocMemoryWithSize: 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 allocMemoryWithSize: 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 allocMemoryWithSize: 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 [bc3a0d2a2f] to [42c4c969f4].
︙ | ︙ | |||
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 | #endif } if (previousPool != nil) previousPool->nextPool = self; size = GROW_SIZE; objects = [self allocMemoryWithSize: 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 size: sizeof(id) count: size + GROW_SIZE]; size += GROW_SIZE; } objects[count] = object; count++; } |
︙ | ︙ |
Modified src/OFBlock.m from [5825d5d284] to [76c357f460].
︙ | ︙ | |||
400 401 402 403 404 405 406 | - (void*)allocMemoryWithSize: (size_t)size { @throw [OFNotImplementedException exceptionWithClass: isa selector: _cmd]; } | | | | | | | 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 | - (void*)allocMemoryWithSize: (size_t)size { @throw [OFNotImplementedException exceptionWithClass: isa selector: _cmd]; } - (void*)allocMemoryWithSize: (size_t)size count: (size_t)count { @throw [OFNotImplementedException exceptionWithClass: isa selector: _cmd]; } - (void*)resizeMemory: (void*)ptr size: (size_t)size { @throw [OFNotImplementedException exceptionWithClass: isa selector: _cmd]; } - (void*)resizeMemory: (void*)ptr size: (size_t)size count: (size_t)count { @throw [OFNotImplementedException exceptionWithClass: isa selector: _cmd]; } - (void)freeMemory: (void*)ptr { |
︙ | ︙ |
Modified src/OFConstantString.m from [e6c815e41d] to [63e98f3fd3].
︙ | ︙ | |||
58 59 60 61 62 63 64 | - (void*)allocMemoryWithSize: (size_t)size { @throw [OFNotImplementedException exceptionWithClass: isa selector: _cmd]; } | | | | | 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 | - (void*)allocMemoryWithSize: (size_t)size { @throw [OFNotImplementedException exceptionWithClass: isa selector: _cmd]; } - (void*)allocMemoryWithSize: (size_t)itemSize count: (size_t)count { @throw [OFNotImplementedException exceptionWithClass: isa selector: _cmd]; } - (void*)resizeMemory: (void*)ptr size: (size_t)size { @throw [OFNotImplementedException exceptionWithClass: isa selector: _cmd]; } - (void*)resizeMemory: (void*)ptr toNItems: (size_t)nitems |
︙ | ︙ | |||
178 179 180 181 182 183 184 | - (void*)allocMemoryWithSize: (size_t)size { @throw [OFNotImplementedException exceptionWithClass: isa selector: _cmd]; } | | | | | | | 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 | - (void*)allocMemoryWithSize: (size_t)size { @throw [OFNotImplementedException exceptionWithClass: isa selector: _cmd]; } - (void*)allocMemoryWithSize: (size_t)size count: (size_t)count { @throw [OFNotImplementedException exceptionWithClass: isa selector: _cmd]; } - (void*)resizeMemory: (void*)ptr size: (size_t)size { @throw [OFNotImplementedException exceptionWithClass: isa selector: _cmd]; } - (void*)resizeMemory: (void*)ptr size: (size_t)size count: (size_t)count { @throw [OFNotImplementedException exceptionWithClass: isa selector: _cmd]; } - (void)freeMemory: (void*)ptr { |
︙ | ︙ |
Modified src/OFDataArray.m from [a3be020022] to [a3f3ece2b2].
︙ | ︙ | |||
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 | - (void)addItem: (const void*)item { if (SIZE_MAX - count < 1) @throw [OFOutOfRangeException exceptionWithClass: isa]; data = [self resizeMemory: data size: itemSize count: count + 1]; memcpy(data + count * itemSize, item, itemSize); count++; } |
︙ | ︙ | |||
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 | - (void)addItemsFromCArray: (const void*)cArray count: (size_t)nItems { if (nItems > SIZE_MAX - count) @throw [OFOutOfRangeException exceptionWithClass: isa]; data = [self resizeMemory: data size: 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 size: 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 | 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 size: 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 size: itemSize count: count]; } @catch (OFOutOfMemoryException *e) { /* We don't care, as we only made it smaller */ } } - (void)removeAllItems |
︙ | ︙ | |||
476 477 478 479 480 481 482 | @throw [OFOutOfRangeException exceptionWithClass: isa]; lastPageByte = of_pagesize - 1; newSize = ((count + 1) * itemSize + lastPageByte) & ~lastPageByte; if (size != newSize) data = [self resizeMemory: data | | | | 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 | @throw [OFOutOfRangeException exceptionWithClass: isa]; lastPageByte = of_pagesize - 1; newSize = ((count + 1) * itemSize + lastPageByte) & ~lastPageByte; if (size != newSize) data = [self resizeMemory: data size: newSize]; memcpy(data + count * itemSize, item, itemSize); count++; size = newSize; } - (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]; lastPageByte = of_pagesize - 1; newSize = ((count + nItems) * itemSize + lastPageByte) & ~lastPageByte; if (size != newSize) data = [self resizeMemory: data size: newSize]; memcpy(data + count * itemSize, cArray, nItems * itemSize); count += nItems; size = newSize; } |
︙ | ︙ | |||
520 521 522 523 524 525 526 | @throw [OFOutOfRangeException exceptionWithClass: isa]; lastPageByte = of_pagesize - 1; newSize = ((count + nItems) * itemSize + lastPageByte) & ~lastPageByte; if (size != newSize) data = [self resizeMemory: data | | | 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 | @throw [OFOutOfRangeException exceptionWithClass: isa]; lastPageByte = of_pagesize - 1; newSize = ((count + nItems) * itemSize + lastPageByte) & ~lastPageByte; if (size != newSize) data = [self resizeMemory: data size: newSize]; memmove(data + (index + nItems) * itemSize, data + index * itemSize, (count - index) * itemSize); memcpy(data + index * itemSize, cArray, nItems * itemSize); count += nItems; size = newSize; |
︙ | ︙ | |||
547 548 549 550 551 552 553 | count -= range.length; lastPageByte = of_pagesize - 1; newSize = (count * itemSize + lastPageByte) & ~lastPageByte; if (size != newSize) data = [self resizeMemory: data | | | | 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 | count -= range.length; lastPageByte = of_pagesize - 1; newSize = (count * itemSize + lastPageByte) & ~lastPageByte; if (size != newSize) data = [self resizeMemory: data size: newSize]; size = newSize; } - (void)removeLastItem { size_t newSize, lastPageByte; if (count < 1) @throw [OFOutOfRangeException exceptionWithClass: isa]; count--; lastPageByte = of_pagesize - 1; newSize = (count * itemSize + lastPageByte) & ~lastPageByte; if (size != newSize) { @try { data = [self resizeMemory: data size: newSize]; } @catch (OFOutOfMemoryException *e) { /* We don't care, as we only made it smaller */ } size = newSize; } } |
︙ | ︙ |
Modified src/OFDictionary.m from [170550a25e] to [d6efe13c19].
︙ | ︙ | |||
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 allocMemoryWithSize: 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 allocMemoryWithSize: 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 [c77b46c66d] to [81e5d7fd45].
︙ | ︙ | |||
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 allocMemoryWithSize: 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 allocMemoryWithSize: 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 allocMemoryWithSize: 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 allocMemoryWithSize: 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 allocMemoryWithSize: 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 allocMemoryWithSize: 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 allocMemoryWithSize: 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 [489af893ca] to [fb3dbd6aee].
︙ | ︙ | |||
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 allocMemoryWithSize: 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 [959d2e2496] to [aeb921a44b].
︙ | ︙ | |||
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 allocMemoryWithSize: 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 [f111a1faac] to [ae4b0f4644].
︙ | ︙ | |||
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 allocMemoryWithSize: 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 [3f21e1777e] to [ccd236b694].
︙ | ︙ | |||
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 allocMemoryWithSize: 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); |
︙ | ︙ | |||
174 175 176 177 178 179 180 | if (length == oldLength) { memcpy(s->cString + index, buffer, length); return; } if (length > oldLength) { s->cString = [self resizeMemory: s->cString | | | | 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 | if (length == oldLength) { memcpy(s->cString + index, buffer, length); return; } if (length > oldLength) { s->cString = [self resizeMemory: s->cString size: s->cStringLength - oldLength + length + 1]; memmove(s->cString + index + length, s->cString + index + oldLength, s->cStringLength - index - oldLength); memcpy(s->cString + index, buffer, length); s->cStringLength -= oldLength; |
︙ | ︙ | |||
204 205 206 207 208 209 210 | s->cStringLength -= oldLength; s->cStringLength += length; s->cString[s->cStringLength] = '\0'; @try { s->cString = [self resizeMemory: s->cString | | | 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 | s->cStringLength -= oldLength; s->cStringLength += length; s->cString[s->cStringLength] = '\0'; @try { s->cString = [self resizeMemory: s->cString size: s->cStringLength + 1]; } @catch (OFOutOfMemoryException *e) { /* We don't really care, as we only made it smaller */ } return; } |
︙ | ︙ | |||
235 236 237 238 239 240 241 | break; case -1: @throw [OFInvalidEncodingException exceptionWithClass: isa]; } s->hashed = NO; s->cString = [self resizeMemory: s->cString | | | 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 | break; case -1: @throw [OFInvalidEncodingException exceptionWithClass: isa]; } s->hashed = NO; s->cString = [self resizeMemory: s->cString size: s->cStringLength + UTF8StringLength + 1]; memcpy(s->cString + s->cStringLength, UTF8String, UTF8StringLength + 1); s->cStringLength += UTF8StringLength; s->length += length; } |
︙ | ︙ | |||
263 264 265 266 267 268 269 | break; case -1: @throw [OFInvalidEncodingException exceptionWithClass: isa]; } s->hashed = NO; s->cString = [self resizeMemory: s->cString | | | 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 | break; case -1: @throw [OFInvalidEncodingException exceptionWithClass: isa]; } s->hashed = NO; s->cString = [self resizeMemory: s->cString size: s->cStringLength + UTF8StringLength + 1]; memcpy(s->cString + s->cStringLength, UTF8String, UTF8StringLength); s->cStringLength += UTF8StringLength; s->length += length; s->cString[s->cStringLength] = 0; |
︙ | ︙ | |||
310 311 312 313 314 315 316 | @throw [OFInvalidArgumentException exceptionWithClass: isa selector: _cmd]; UTF8StringLength = [string UTF8StringLength]; s->hashed = NO; s->cString = [self resizeMemory: s->cString | | | 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 | @throw [OFInvalidArgumentException exceptionWithClass: isa selector: _cmd]; UTF8StringLength = [string UTF8StringLength]; s->hashed = NO; s->cString = [self resizeMemory: s->cString size: s->cStringLength + UTF8StringLength + 1]; memcpy(s->cString + s->cStringLength, [string UTF8String], UTF8StringLength); s->cStringLength += UTF8StringLength; s->length += [string length]; |
︙ | ︙ | |||
449 450 451 452 453 454 455 | if (s->UTF8) index = of_string_index_to_position(s->cString, index, s->cStringLength); newCStringLength = s->cStringLength + [string UTF8StringLength]; s->hashed = NO; s->cString = [self resizeMemory: s->cString | | | 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 | if (s->UTF8) index = of_string_index_to_position(s->cString, index, s->cStringLength); newCStringLength = s->cStringLength + [string UTF8StringLength]; s->hashed = NO; s->cString = [self resizeMemory: s->cString size: newCStringLength + 1]; memmove(s->cString + index + [string UTF8StringLength], s->cString + index, s->cStringLength - index); memcpy(s->cString + index, [string UTF8String], [string UTF8StringLength]); s->cString[newCStringLength] = '\0'; |
︙ | ︙ | |||
492 493 494 495 496 497 498 | memmove(s->cString + start, s->cString + end, s->cStringLength - end); s->cStringLength -= end - start; s->cString[s->cStringLength] = 0; @try { s->cString = [self resizeMemory: s->cString | | | 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 | memmove(s->cString + start, s->cString + end, s->cStringLength - end); s->cStringLength -= end - start; s->cString[s->cStringLength] = 0; @try { s->cString = [self resizeMemory: s->cString size: s->cStringLength + 1]; } @catch (OFOutOfMemoryException *e) { /* We don't really care, as we only made it smaller */ } } - (void)replaceCharactersInRange: (of_range_t)range withString: (OFString*)replacement |
︙ | ︙ | |||
521 522 523 524 525 526 527 | s->cStringLength); } newCStringLength = s->cStringLength - (end - start) + [replacement UTF8StringLength]; s->hashed = NO; s->cString = [self resizeMemory: s->cString | | | 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 | s->cStringLength); } newCStringLength = s->cStringLength - (end - start) + [replacement UTF8StringLength]; s->hashed = NO; s->cString = [self resizeMemory: s->cString size: newCStringLength + 1]; memmove(s->cString + start + [replacement UTF8StringLength], s->cString + end, s->cStringLength - end); memcpy(s->cString + start, [replacement UTF8String], [replacement UTF8StringLength]); s->cString[newCStringLength] = '\0'; |
︙ | ︙ | |||
568 569 570 571 572 573 574 | for (i = range.start, last = 0; i <= range.length - searchLength; i++) { if (memcmp(s->cString + i, searchString, searchLength)) continue; @try { newCString = [self resizeMemory: newCString | | | < | | | 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 | for (i = range.start, last = 0; i <= range.length - searchLength; i++) { if (memcmp(s->cString + i, searchString, searchLength)) continue; @try { newCString = [self resizeMemory: newCString size: newCStringLength + i - last + replacementLength + 1]; } @catch (id e) { [self freeMemory: newCString]; @throw e; } memcpy(newCString + newCStringLength, s->cString + last, i - last); memcpy(newCString + newCStringLength + i - last, replacementString, replacementLength); newCStringLength += i - last + replacementLength; newLength = newLength - [string length] + [replacement length]; i += searchLength - 1; last = i + 1; } @try { newCString = [self resizeMemory: newCString size: newCStringLength + s->cStringLength - last + 1]; } @catch (id e) { [self freeMemory: newCString]; @throw e; } memcpy(newCString + newCStringLength, s->cString + last, s->cStringLength - last); newCStringLength += s->cStringLength - last; |
︙ | ︙ | |||
626 627 628 629 630 631 632 | s->length -= i; memmove(s->cString, s->cString + i, s->cStringLength); s->cString[s->cStringLength] = '\0'; @try { s->cString = [self resizeMemory: s->cString | | | 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 | s->length -= i; memmove(s->cString, s->cString + i, s->cStringLength); s->cString[s->cStringLength] = '\0'; @try { s->cString = [self resizeMemory: s->cString size: s->cStringLength + 1]; } @catch (OFOutOfMemoryException *e) { /* We don't really care, as we only made it smaller */ } } - (void)deleteTrailingWhitespaces { |
︙ | ︙ | |||
654 655 656 657 658 659 660 | } s->cStringLength -= d; s->length -= d; @try { s->cString = [self resizeMemory: s->cString | | | 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 | } s->cStringLength -= d; s->length -= d; @try { s->cString = [self resizeMemory: s->cString size: s->cStringLength + 1]; } @catch (OFOutOfMemoryException *e) { /* We don't really care, as we only made it smaller */ } } - (void)deleteEnclosingWhitespaces { |
︙ | ︙ | |||
694 695 696 697 698 699 700 | s->length -= i; memmove(s->cString, s->cString + i, s->cStringLength); s->cString[s->cStringLength] = '\0'; @try { s->cString = [self resizeMemory: s->cString | | | 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 | s->length -= i; memmove(s->cString, s->cString + i, s->cStringLength); s->cString[s->cStringLength] = '\0'; @try { s->cString = [self resizeMemory: s->cString size: s->cStringLength + 1]; } @catch (OFOutOfMemoryException *e) { /* We don't really care, as we only made it smaller */ } } - (void)makeImmutable { isa = [OFString_UTF8 class]; } @end |
Modified src/OFObject.h from [08ae6bde87] to [84660ce002].
︙ | ︙ | |||
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 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 | /** * \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 size The size of each item to allocate * \param count The number of items to allocate * \return A pointer to the allocated memory */ - (void*)allocMemoryWithSize: (size_t)size 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. * * \param pointer A pointer to the already allocated memory * \param size The new size for the memory chunk * \return A pointer to the resized memory chunk */ - (void*)resizeMemory: (void*)pointer size: (size_t)size; /** * \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 size 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 size: (size_t)size count: (size_t)count; /** * \brief Frees allocated memory and removes it from the object's memory pool. * * Does nothing if the pointer is NULL. * |
︙ | ︙ |
Modified src/OFObject.m from [51c24d6468] to [7124c4f433].
︙ | ︙ | |||
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 823 824 825 826 | PRE_IVAR->lastMem->next = preMem; PRE_IVAR->lastMem = preMem; return (char*)pointer + PRE_MEM_ALIGN; } - (void*)allocMemoryWithSize: (size_t)size count: (size_t)count { if (size == 0 || count == 0) return NULL; if (count > SIZE_MAX / size) @throw [OFOutOfRangeException exceptionWithClass: isa]; return [self allocMemoryWithSize: size * count]; } - (void*)resizeMemory: (void*)pointer size: (size_t)size { void *new; struct pre_mem *preMem; if (pointer == NULL) return [self allocMemoryWithSize: size]; |
︙ | ︙ | |||
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 size: (size_t)size count: (size_t)count { if (pointer == NULL) return [self allocMemoryWithSize: size count: count]; if (size == 0 || count == 0) { [self freeMemory: pointer]; return NULL; } if (count > SIZE_MAX / size) @throw [OFOutOfRangeException exceptionWithClass: isa]; return [self resizeMemory: pointer size: size * 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 | */ + (void*)allocMemoryWithSize: (size_t)size { @throw [OFNotImplementedException exceptionWithClass: self selector: _cmd]; } + (void*)allocMemoryWithSize: (size_t)size count: (size_t)count { @throw [OFNotImplementedException exceptionWithClass: self selector: _cmd]; } + (void*)resizeMemory: (void*)pointer size: (size_t)size { @throw [OFNotImplementedException exceptionWithClass: self selector: _cmd]; } + (void*)resizeMemory: (void*)pointer size: (size_t)size count: (size_t)count { @throw [OFNotImplementedException exceptionWithClass: self selector: _cmd]; } + (void)freeMemory: (void*)pointer |
︙ | ︙ |
Modified src/OFProcess.m from [fb8b1060e5] to [8d0f0fd4b4].
︙ | ︙ | |||
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 allocMemoryWithSize: 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 [335de526be] to [6e083ee3de].
︙ | ︙ | |||
442 443 444 445 446 447 448 | - (OFDataArray*)readDataArrayWithItemSize: (size_t)itemSize count: (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 count: (size_t)nItems { OFDataArray *dataArray; char *tmp; dataArray = [OFDataArray dataArrayWithItemSize: itemSize]; tmp = [self allocMemoryWithSize: itemSize count: nItems]; @try { [self readIntoBuffer: tmp exactLength: nItems * itemSize]; [dataArray addItemsFromCArray: tmp count: nItems]; |
︙ | ︙ | |||
605 606 607 608 609 610 611 | } @catch (id e) { /* * Append data to cache to prevent loss * of data due to wrong encoding. */ cache = [self resizeMemory: cache | | | 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 | } @catch (id e) { /* * Append data to cache to prevent loss * of data due to wrong encoding. */ cache = [self resizeMemory: cache size: cacheLength + bufferLength]; if (cache != NULL) memcpy(cache + cacheLength, buffer, bufferLength); cacheLength += bufferLength; |
︙ | ︙ | |||
636 637 638 639 640 641 642 | waitingForDelimiter = NO; return ret; } } /* There was no newline or \0 */ cache = [self resizeMemory: cache | | | | 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 | waitingForDelimiter = NO; return ret; } } /* There was no newline or \0 */ cache = [self resizeMemory: cache size: cacheLength + bufferLength]; /* * It's possible that cacheLen + len is 0 and thus cache was * set to NULL by resizeMemory:size:. */ if (cache != NULL) memcpy(cache + cacheLength, buffer, bufferLength); cacheLength += bufferLength; } @finally { [self freeMemory: buffer]; |
︙ | ︙ | |||
799 800 801 802 803 804 805 | waitingForDelimiter = NO; return ret; } } /* Neither the delimiter nor \0 was found */ cache = [self resizeMemory: cache | | | | 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 | waitingForDelimiter = NO; return ret; } } /* Neither the delimiter nor \0 was found */ cache = [self resizeMemory: cache size: cacheLength + bufferLength]; /* * It's possible that cacheLen + len is 0 and thus cache was * set to NULL by resizeMemory:size:. */ if (cache != NULL) memcpy(cache + cacheLength, buffer, bufferLength); cacheLength += bufferLength; } @finally { |
︙ | ︙ | |||
876 877 878 879 880 881 882 | length: (size_t)length { if (!writeBufferEnabled) [self _writeBuffer: buffer length: length]; else { writeBuffer = [self resizeMemory: writeBuffer | | | 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 | length: (size_t)length { if (!writeBufferEnabled) [self _writeBuffer: buffer length: length]; else { writeBuffer = [self resizeMemory: writeBuffer size: writeBufferLength + length]; memcpy(writeBuffer + writeBufferLength, buffer, length); writeBufferLength += length; } } - (void)writeInt8: (uint8_t)int8 { |
︙ | ︙ | |||
939 940 941 942 943 944 945 | #ifdef OF_BIG_ENDIAN [self writeBuffer: buffer length: size]; #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 writeBuffer: buffer length: size]; #else uint16_t *tmp; tmp = [self allocMemoryWithSize: 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 writeBuffer: buffer length: size]; #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 writeBuffer: buffer length: size]; #else uint32_t *tmp; tmp = [self allocMemoryWithSize: 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 writeBuffer: buffer length: size]; #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 writeBuffer: buffer length: size]; #else uint64_t *tmp; tmp = [self allocMemoryWithSize: 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 writeBuffer: buffer length: size]; #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 writeBuffer: buffer length: size]; #else float *tmp; tmp = [self allocMemoryWithSize: 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 writeBuffer: buffer length: size]; #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 writeBuffer: buffer length: size]; #else double *tmp; tmp = [self allocMemoryWithSize: 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 writeBuffer: buffer length: size]; #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 writeBuffer: buffer length: size]; #else uint16_t *tmp; tmp = [self allocMemoryWithSize: 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 writeBuffer: buffer length: size]; #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 writeBuffer: buffer length: size]; #else uint32_t *tmp; tmp = [self allocMemoryWithSize: 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 writeBuffer: buffer length: size]; #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 writeBuffer: buffer length: size]; #else uint64_t *tmp; tmp = [self allocMemoryWithSize: 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 writeBuffer: buffer length: size]; #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 writeBuffer: buffer length: size]; #else float *tmp; tmp = [self allocMemoryWithSize: 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 writeBuffer: buffer length: size]; #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 writeBuffer: buffer length: size]; #else double *tmp; tmp = [self allocMemoryWithSize: 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 [75b0a6497b] to [aaaee883eb].
︙ | ︙ | |||
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 allocMemoryWithSize: 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 | int fd = queueFDsCArray[i]; if ((action & QUEUE_ACTION) == QUEUE_ADD) { if (fd > maxFD) { maxFD = fd; FDToStream = [self resizeMemory: FDToStream size: sizeof(OFStream*) count: maxFD + 1]; } FDToStream[fd] = stream; } if ((action & QUEUE_ACTION) == QUEUE_REMOVE) { |
︙ | ︙ |
Modified src/OFString.m from [3028812e1c] to [a987125a46].
︙ | ︙ | |||
995 996 997 998 999 1000 1001 | } } UTF8String[j] = '\0'; @try { UTF8String = [object resizeMemory: UTF8String | | | 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 | } } UTF8String[j] = '\0'; @try { UTF8String = [object resizeMemory: UTF8String size: UTF8StringLength + 1]; } @catch (OFOutOfMemoryException *e) { /* We don't care, as we only tried to make it smaller */ } return UTF8String; } |
︙ | ︙ | |||
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 allocMemoryWithSize: 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 allocMemoryWithSize: 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 allocMemoryWithSize: 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 allocMemoryWithSize: 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 | ret[j++] = of_bswap16_if_le(c); } ret[j] = 0; @try { ret = [object resizeMemory: ret size: sizeof(uint16_t) count: j + 1]; } @catch (OFOutOfMemoryException *e) { /* We don't care, as we only tried to make it smaller */ } [pool release]; |
︙ | ︙ |
Modified src/OFString_UTF8.m from [5faa6d539b] to [65dd22d751].
︙ | ︙ | |||
177 178 179 180 181 182 183 | if (bytes == 0) @throw [OFInvalidEncodingException exceptionWithClass: isa]; s->cStringLength += bytes - 1; s->cString = [self resizeMemory: s->cString | | | 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | if (bytes == 0) @throw [OFInvalidEncodingException exceptionWithClass: isa]; s->cStringLength += bytes - 1; s->cString = [self resizeMemory: s->cString size: s->cStringLength + 1]; memcpy(s->cString + j, buffer, bytes); j += bytes; } s->cString[s->cStringLength] = 0; |
︙ | ︙ | |||
226 227 228 229 230 231 232 | if (characterBytes == 0) @throw [OFInvalidEncodingException exceptionWithClass: isa]; s->cStringLength += characterBytes - 1; s->cString = [self resizeMemory: s->cString | | | 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 | if (characterBytes == 0) @throw [OFInvalidEncodingException exceptionWithClass: isa]; s->cStringLength += characterBytes - 1; s->cString = [self resizeMemory: s->cString size: s->cStringLength + 1]; memcpy(s->cString + j, buffer, characterBytes); j += characterBytes; } s->cString[s->cStringLength] = 0; } @catch (id e) { |
︙ | ︙ | |||
338 339 340 341 342 343 344 | } } s->cString[j] = '\0'; @try { s->cString = [self resizeMemory: s->cString | | | 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 | } } s->cString[j] = '\0'; @try { s->cString = [self resizeMemory: s->cString size: s->cStringLength + 1]; } @catch (OFOutOfMemoryException *e) { /* We don't care, as we only tried to make it smaller */ } } @catch (id e) { [self release]; @throw e; } |
︙ | ︙ | |||
446 447 448 449 450 451 452 | } } s->cString[j] = '\0'; @try { s->cString = [self resizeMemory: s->cString | | | 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 | } } s->cString[j] = '\0'; @try { s->cString = [self resizeMemory: s->cString size: s->cStringLength + 1]; } @catch (OFOutOfMemoryException *e) { /* We don't care, as we only tried to make it smaller */ } } @catch (id e) { [self release]; @throw e; } |
︙ | ︙ | |||
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 allocMemoryWithSize: sizeof(of_unichar_t) count: s->length + 1]; i = 0; j = 0; while (i < s->cStringLength) { of_unichar_t c; size_t cLen; |
︙ | ︙ |
Modified src/OFXMLElement.m from [23e15b2038] to [dff10de86f].
︙ | ︙ | |||
511 512 513 514 515 516 517 | /* Start of tag */ cString[i++] = '<'; if (prefix != nil && ![ns isEqual: defaultNS]) { length += [prefix UTF8StringLength] + 1; @try { cString = [self resizeMemory: cString | | | | 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 | /* Start of tag */ cString[i++] = '<'; if (prefix != nil && ![ns isEqual: defaultNS]) { length += [prefix UTF8StringLength] + 1; @try { cString = [self resizeMemory: cString size: length]; } @catch (id e) { [self freeMemory: cString]; @throw e; } memcpy(cString + i, [prefix UTF8String], [prefix UTF8StringLength]); i += [prefix UTF8StringLength]; cString[i++] = ':'; } memcpy(cString + i, [name UTF8String], [name UTF8StringLength]); i += [name UTF8StringLength]; /* xmlns if necessary */ if (prefix == nil && ((ns != nil && ![ns isEqual: defaultNS]) || (ns == nil && defaultNS != nil))) { length += [ns UTF8StringLength] + 9; @try { cString = [self resizeMemory: cString size: length]; } @catch (id e) { [self freeMemory: cString]; @throw e; } memcpy(cString + i, " xmlns='", 8); i += 8; |
︙ | ︙ | |||
571 572 573 574 575 576 577 | length += [attributeName UTF8StringLength] + (attributePrefix != nil ? [attributePrefix UTF8StringLength] + 1 : 0) + [tmp UTF8StringLength] + 4; @try { cString = [self resizeMemory: cString | | | 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 | length += [attributeName UTF8StringLength] + (attributePrefix != nil ? [attributePrefix UTF8StringLength] + 1 : 0) + [tmp UTF8StringLength] + 4; @try { cString = [self resizeMemory: cString size: length]; } @catch (id e) { [self freeMemory: cString]; @throw e; } cString[i++] = ' '; if (attributePrefix != nil) { |
︙ | ︙ | |||
647 648 649 650 651 652 653 | if (indent) [tmp addItem: "\n"]; length += [tmp count] + [name UTF8StringLength] + 2 + (indent ? level * indentation : 0); @try { cString = [self resizeMemory: cString | | | 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 | if (indent) [tmp addItem: "\n"]; length += [tmp count] + [name UTF8StringLength] + 2 + (indent ? level * indentation : 0); @try { cString = [self resizeMemory: cString size: length]; } @catch (id e) { [self freeMemory: cString]; @throw e; } cString[i++] = '>'; |
︙ | ︙ | |||
669 670 671 672 673 674 675 | cString[i++] = '<'; cString[i++] = '/'; if (prefix != nil) { length += [prefix UTF8StringLength] + 1; @try { cString = [self resizeMemory: cString | | | 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 | cString[i++] = '<'; cString[i++] = '/'; if (prefix != nil) { length += [prefix UTF8StringLength] + 1; @try { cString = [self resizeMemory: cString size: length]; } @catch (id e) { [self freeMemory: cString]; @throw e; } memcpy(cString + i, [prefix UTF8String], [prefix UTF8StringLength]); |
︙ | ︙ |
Modified tests/OFObjectTests.m from [4509cfc31c] to [dd072d17db].
︙ | ︙ | |||
62 63 64 65 66 67 68 | OFOutOfMemoryException, [obj allocMemoryWithSize: SIZE_MAX - 128]) EXPECT_EXCEPTION(@"Detect out of memory on resize", OFOutOfMemoryException, { p = [obj allocMemoryWithSize: 1]; [obj resizeMemory: p | | | | | 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 | OFOutOfMemoryException, [obj allocMemoryWithSize: SIZE_MAX - 128]) EXPECT_EXCEPTION(@"Detect out of memory on resize", OFOutOfMemoryException, { p = [obj allocMemoryWithSize: 1]; [obj resizeMemory: p size: SIZE_MAX - 128]; }) [obj freeMemory: p]; TEST(@"Allocate when trying to resize NULL", (p = [obj resizeMemory: NULL size: 1024]) != NULL) [obj freeMemory: p]; EXPECT_EXCEPTION(@"Detect resizing of memory not allocated by object", OFMemoryNotPartOfObjectException, [obj resizeMemory: tmp size: 2048]) [self freeMemory: tmp]; TEST(@"+[description]", [[OFObject description] isEqual: @"OFObject"] && [[MyObj description] isEqual: @"MyObj"]) o = [[[OFObject alloc] init] autorelease]; |
︙ | ︙ |