Comment: | OFObject: Remove -[allocMemoryWithSize:] |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
4fbdca698ce5a7e2d70a5e01330f6927 |
User & Date: | js on 2020-11-07 20:23:04 |
Other Links: | manifest | tags |
2020-11-12
| ||
00:32 | Fix weak references with the Apple runtime check-in: 4c16806252 user: js tags: trunk | |
2020-11-07
| ||
20:23 | OFObject: Remove -[allocMemoryWithSize:] check-in: 4fbdca698c user: js tags: trunk | |
10:38 | Make GCC happy again check-in: 7aa23887d0 user: js tags: trunk | |
Modified src/OFBlock.m from [a597363d01] to [d3c798f275].
︙ | ︙ | |||
435 436 437 438 439 440 441 | } - (instancetype)init { OF_INVALID_INIT_METHOD } | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | 435 436 437 438 439 440 441 442 443 444 445 446 447 448 | } - (instancetype)init { OF_INVALID_INIT_METHOD } - (instancetype)retain { if ([self isMemberOfClass: (Class)&_NSConcreteMallocBlock]) return Block_copy(self); return self; } |
︙ | ︙ |
Modified src/OFConstantString.m from [a6f51dcbb3] to [4db8f4cb59].
︙ | ︙ | |||
50 51 52 53 54 55 56 | @implementation OFConstantUTF8String + (instancetype)alloc { OF_UNRECOGNIZED_SELECTOR } | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | @implementation OFConstantUTF8String + (instancetype)alloc { OF_UNRECOGNIZED_SELECTOR } - (instancetype)retain { return self; } - (instancetype)autorelease { |
︙ | ︙ | |||
138 139 140 141 142 143 144 | { @synchronized (self) { struct of_string_utf8_ivars *ivars; if ([self isMemberOfClass: [OFConstantUTF8String class]]) return; | | < < < | < | | | | | | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | 109 110 111 112 113 114 115 116 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 | { @synchronized (self) { struct of_string_utf8_ivars *ivars; if ([self isMemberOfClass: [OFConstantUTF8String class]]) return; ivars = of_calloc(1, sizeof(*ivars)); ivars->cString = _cString; ivars->cStringLength = _cStringLength; switch (of_string_utf8_check(ivars->cString, ivars->cStringLength, &ivars->length)) { case 1: ivars->isUTF8 = true; break; case -1: free(ivars); @throw [OFInvalidEncodingException exception]; } _cString = (char *)ivars; object_setClass(self, [OFConstantUTF8String class]); } } + (instancetype)alloc { OF_UNRECOGNIZED_SELECTOR } - (instancetype)retain { return self; } |
︙ | ︙ |
Modified src/OFMutableUTF8String.m from [77a77e4c53] to [e2512a1c1d].
︙ | ︙ | |||
41 42 43 44 45 46 47 | if (self == [OFMutableUTF8String class]) [self inheritMethodsFromClass: [OFUTF8String class]]; } - (instancetype)initWithUTF8StringNoCopy: (char *)UTF8String freeWhenDone: (bool)freeWhenDone { | < | | | | < < | | | | | < | 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | if (self == [OFMutableUTF8String class]) [self inheritMethodsFromClass: [OFUTF8String class]]; } - (instancetype)initWithUTF8StringNoCopy: (char *)UTF8String freeWhenDone: (bool)freeWhenDone { self = [self initWithUTF8String: UTF8String]; if (freeWhenDone) free(UTF8String); return self; } - (instancetype)initWithUTF8StringNoCopy: (char *)UTF8String length: (size_t)UTF8StringLength freeWhenDone: (bool)freeWhenDone { self = [self initWithUTF8String: UTF8String length: UTF8StringLength]; if (freeWhenDone) free(UTF8String); return self; } - (void)of_convertWithWordStartTable: (const of_unichar_t *const[])startTable wordMiddleTable: (const of_unichar_t *const[])middleTable wordStartTableSize: (size_t)startTableSize |
︙ | ︙ | |||
155 156 157 158 159 160 161 | @throw [OFInvalidEncodingException exception]; } i += cLen; } @try { | | | | | 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 | @throw [OFInvalidEncodingException exception]; } i += cLen; } @try { newCString = of_malloc(newCStringLength + 1, 1); } @catch (id e) { free(unicodeString); @throw e; } j = 0; for (i = 0; i < unicodeLen; i++) { size_t d; if ((d = of_string_utf8_encode(unicodeString[i], newCString + j)) == 0) { free(unicodeString); free(newCString); @throw [OFInvalidEncodingException exception]; } j += d; } assert(j == newCStringLength); newCString[j] = 0; free(unicodeString); free(_s->cString); _s->hashed = false; _s->cString = newCString; _s->cStringLength = newCStringLength; /* * Even though cStringLength can change, length cannot, therefore no * need to change it. |
︙ | ︙ | |||
224 225 226 227 228 229 230 | @throw [OFInvalidEncodingException exception]; _s->hashed = false; if (lenNew == (size_t)lenOld) memcpy(_s->cString + idx, buffer, lenNew); else if (lenNew > (size_t)lenOld) { | < | | | 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 | @throw [OFInvalidEncodingException exception]; _s->hashed = false; if (lenNew == (size_t)lenOld) memcpy(_s->cString + idx, buffer, lenNew); else if (lenNew > (size_t)lenOld) { _s->cString = of_realloc(_s->cString, _s->cStringLength - lenOld + lenNew + 1, 1); memmove(_s->cString + idx + lenNew, _s->cString + idx + lenOld, _s->cStringLength - idx - lenOld); memcpy(_s->cString + idx, buffer, lenNew); _s->cStringLength -= lenOld; _s->cStringLength += lenNew; |
︙ | ︙ | |||
251 252 253 254 255 256 257 | _s->cStringLength += lenNew; _s->cString[_s->cStringLength] = '\0'; if (character >= 0x80) _s->isUTF8 = true; @try { | | < | | 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 | _s->cStringLength += lenNew; _s->cString[_s->cStringLength] = '\0'; if (character >= 0x80) _s->isUTF8 = true; @try { _s->cString = of_realloc(_s->cString, _s->cStringLength + 1, 1); } @catch (OFOutOfMemoryException *e) { /* We don't really care, as we only made it smaller */ } } } - (void)appendUTF8String: (const char *)UTF8String |
︙ | ︙ | |||
280 281 282 283 284 285 286 | _s->isUTF8 = true; break; case -1: @throw [OFInvalidEncodingException exception]; } _s->hashed = false; | < | | | 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 | _s->isUTF8 = true; break; case -1: @throw [OFInvalidEncodingException exception]; } _s->hashed = false; _s->cString = of_realloc(_s->cString, _s->cStringLength + UTF8StringLength + 1, 1); memcpy(_s->cString + _s->cStringLength, UTF8String, UTF8StringLength + 1); _s->cStringLength += UTF8StringLength; _s->length += length; } |
︙ | ︙ | |||
310 311 312 313 314 315 316 | _s->isUTF8 = true; break; case -1: @throw [OFInvalidEncodingException exception]; } _s->hashed = false; | < | | | 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 | _s->isUTF8 = true; break; case -1: @throw [OFInvalidEncodingException exception]; } _s->hashed = false; _s->cString = of_realloc(_s->cString, _s->cStringLength + UTF8StringLength + 1, 1); memcpy(_s->cString + _s->cStringLength, UTF8String, UTF8StringLength); _s->cStringLength += UTF8StringLength; _s->length += length; _s->cString[_s->cStringLength] = 0; } |
︙ | ︙ | |||
358 359 360 361 362 363 364 | if (string == nil) @throw [OFInvalidArgumentException exception]; UTF8StringLength = string.UTF8StringLength; _s->hashed = false; | < | | | 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 | if (string == nil) @throw [OFInvalidArgumentException exception]; UTF8StringLength = string.UTF8StringLength; _s->hashed = false; _s->cString = of_realloc(_s->cString, _s->cStringLength + UTF8StringLength + 1, 1); memcpy(_s->cString + _s->cStringLength, string.UTF8String, UTF8StringLength); _s->cStringLength += UTF8StringLength; _s->length += string.length; _s->cString[_s->cStringLength] = 0; |
︙ | ︙ | |||
402 403 404 405 406 407 408 | j += len; } tmp[j] = '\0'; _s->hashed = false; | | | | 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 | j += len; } tmp[j] = '\0'; _s->hashed = false; _s->cString = of_realloc(_s->cString, _s->cStringLength + j + 1, 1); memcpy(_s->cString + _s->cStringLength, tmp, j + 1); _s->cStringLength += j; _s->length += length; if (isUTF8) _s->isUTF8 = true; |
︙ | ︙ | |||
531 532 533 534 535 536 537 | if (_s->isUTF8) idx = of_string_utf8_get_position(_s->cString, idx, _s->cStringLength); newCStringLength = _s->cStringLength + string.UTF8StringLength; _s->hashed = false; | < | | 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 | if (_s->isUTF8) idx = of_string_utf8_get_position(_s->cString, idx, _s->cStringLength); newCStringLength = _s->cStringLength + string.UTF8StringLength; _s->hashed = false; _s->cString = of_realloc(_s->cString, newCStringLength + 1, 1); memmove(_s->cString + idx + string.UTF8StringLength, _s->cString + idx, _s->cStringLength - idx); memcpy(_s->cString + idx, string.UTF8String, string.UTF8StringLength); _s->cString[newCStringLength] = '\0'; |
︙ | ︙ | |||
574 575 576 577 578 579 580 | _s->cStringLength - end); _s->hashed = false; _s->length -= range.length; _s->cStringLength -= end - start; _s->cString[_s->cStringLength] = 0; @try { | < | | 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 | _s->cStringLength - end); _s->hashed = false; _s->length -= range.length; _s->cStringLength -= end - start; _s->cString[_s->cStringLength] = 0; @try { _s->cString = of_realloc(_s->cString, _s->cStringLength + 1, 1); } @catch (OFOutOfMemoryException *e) { /* We don't really care, as we only made it smaller */ } } - (void)replaceCharactersInRange: (of_range_t)range withString: (OFString *)replacement |
︙ | ︙ | |||
616 617 618 619 620 621 622 | * memmove() the rest of the string to the end. * * We must not resize the string if the new string is smaller, because * then we can't memmove() the rest of the string forward as the rest is * lost due to the resize! */ if (newCStringLength > _s->cStringLength) | < | < | | 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 | * memmove() the rest of the string to the end. * * We must not resize the string if the new string is smaller, because * then we can't memmove() the rest of the string forward as the rest is * lost due to the resize! */ if (newCStringLength > _s->cStringLength) _s->cString = of_realloc(_s->cString, newCStringLength + 1, 1); memmove(_s->cString + start + replacement.UTF8StringLength, _s->cString + end, _s->cStringLength - end); memcpy(_s->cString + start, replacement.UTF8String, replacement.UTF8StringLength); _s->cString[newCStringLength] = '\0'; /* * If the new string is smaller, we can safely resize it now as we're * done with memmove(). */ if (newCStringLength < _s->cStringLength) _s->cString = of_realloc(_s->cString, newCStringLength + 1, 1); _s->cStringLength = newCStringLength; _s->length = newLength; if ([replacement isKindOfClass: [OFUTF8String class]] || [replacement isKindOfClass: [OFMutableUTF8String class]]) { if (((OFMutableUTF8String *)replacement)->_s->isUTF8) |
︙ | ︙ | |||
684 685 686 687 688 689 690 | last = 0; for (size_t i = range.location; i <= range.length - searchLength; i++) { if (memcmp(_s->cString + i, searchString, searchLength) != 0) continue; @try { | < | < | > | < | | | | | 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 | last = 0; for (size_t i = range.location; i <= range.length - searchLength; i++) { if (memcmp(_s->cString + i, searchString, searchLength) != 0) continue; @try { newCString = of_realloc(newCString, newCStringLength + i - last + replacementLength + 1, 1); } @catch (id e) { free(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 = of_realloc(newCString, newCStringLength + _s->cStringLength - last + 1, 1); } @catch (id e) { free(newCString); @throw e; } memcpy(newCString + newCStringLength, _s->cString + last, _s->cStringLength - last); newCStringLength += _s->cStringLength - last; newCString[newCStringLength] = 0; free(_s->cString); _s->hashed = false; _s->cString = newCString; _s->cStringLength = newCStringLength; _s->length = newLength; if ([replacement isKindOfClass: [OFUTF8String class]] || [replacement isKindOfClass: [OFMutableUTF8String class]]) { |
︙ | ︙ | |||
747 748 749 750 751 752 753 | _s->cStringLength -= i; _s->length -= i; memmove(_s->cString, _s->cString + i, _s->cStringLength); _s->cString[_s->cStringLength] = '\0'; @try { | < | | 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 | _s->cStringLength -= i; _s->length -= i; memmove(_s->cString, _s->cString + i, _s->cStringLength); _s->cString[_s->cStringLength] = '\0'; @try { _s->cString = of_realloc(_s->cString, _s->cStringLength + 1, 1); } @catch (OFOutOfMemoryException *e) { /* We don't really care, as we only made it smaller */ } } - (void)deleteTrailingWhitespaces { |
︙ | ︙ | |||
774 775 776 777 778 779 780 | d++; } _s->cStringLength -= d; _s->length -= d; @try { | < | | 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 | d++; } _s->cStringLength -= d; _s->length -= d; @try { _s->cString = of_realloc(_s->cString, _s->cStringLength + 1, 1); } @catch (OFOutOfMemoryException *e) { /* We don't really care, as we only made it smaller */ } } - (void)deleteEnclosingWhitespaces { |
︙ | ︙ | |||
811 812 813 814 815 816 817 | _s->cStringLength -= i; _s->length -= i; memmove(_s->cString, _s->cString + i, _s->cStringLength); _s->cString[_s->cStringLength] = '\0'; @try { | < | | 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 | _s->cStringLength -= i; _s->length -= i; memmove(_s->cString, _s->cString + i, _s->cStringLength); _s->cString[_s->cStringLength] = '\0'; @try { _s->cString = of_realloc(_s->cString, _s->cStringLength + 1, 1); } @catch (OFOutOfMemoryException *e) { /* We don't really care, as we only made it smaller */ } } - (void)makeImmutable { object_setClass(self, [OFUTF8String class]); } @end |
Modified src/OFObject.h from [19b99027a7] to [3aacd2e524].
︙ | ︙ | |||
802 803 804 805 806 807 808 | * * @param selector The selector for which the method signature should be * returned * @return The method signature for the specified selector */ - (nullable OFMethodSignature *)methodSignatureForSelector: (SEL)selector; | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | 802 803 804 805 806 807 808 809 810 811 812 813 814 815 | * * @param selector The selector for which the method signature should be * returned * @return The method signature for the specified selector */ - (nullable OFMethodSignature *)methodSignatureForSelector: (SEL)selector; /** * @brief Deallocates the object. * * It is automatically called when the retain count reaches zero. * * This also frees all memory in its memory pool. */ |
︙ | ︙ |
Modified src/OFObject.m from [b6169ba098] to [e2e795413b].
︙ | ︙ | |||
82 83 84 85 86 87 88 | #endif struct pre_ivar { int retainCount; #if !defined(OF_HAVE_ATOMIC_OPS) && !defined(OF_AMIGAOS) of_spinlock_t retainCountSpinlock; #endif | < < < < < < < < < < | 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 | #endif struct pre_ivar { int retainCount; #if !defined(OF_HAVE_ATOMIC_OPS) && !defined(OF_AMIGAOS) of_spinlock_t retainCountSpinlock; #endif }; #define PRE_IVARS_ALIGN ((sizeof(struct pre_ivar) + \ (OF_BIGGEST_ALIGNMENT - 1)) & ~(OF_BIGGEST_ALIGNMENT - 1)) #define PRE_IVARS ((struct pre_ivar *)(void *)((char *)self - PRE_IVARS_ALIGN)) static struct { Class isa; } allocFailedException; uint32_t of_hash_seed; void * |
︙ | ︙ | |||
1098 1099 1100 1101 1102 1103 1104 | - (OFString *)description { /* Classes containing data should reimplement this! */ return [OFString stringWithFormat: @"<%@>", self.className]; } | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 | - (OFString *)description { /* Classes containing data should reimplement this! */ return [OFString stringWithFormat: @"<%@>", self.className]; } - (id)forwardingTargetForSelector: (SEL)selector { return nil; } - (void)doesNotRecognizeSelector: (SEL)selector { |
︙ | ︙ | |||
1327 1328 1329 1330 1331 1332 1333 | [self retain]; return true; } - (void)dealloc { | < < < < < < < < < < < < < < < < < | 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 | [self retain]; return true; } - (void)dealloc { objc_destructInstance(self); free((char *)self - PRE_IVARS_ALIGN); } /* Required to use properties with the Apple runtime */ - (id)copyWithZone: (void *)zone { if OF_UNLIKELY (zone != NULL) { |
︙ | ︙ | |||
1371 1372 1373 1374 1375 1376 1377 | abort(); } return [(id)self mutableCopy]; } /* | | | > < < < < < < < < < < < < < < < < < < < < < < < < < < < < | 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 | abort(); } return [(id)self mutableCopy]; } /* * The following are needed as the root class is the superclass of the root * class's metaclass and thus instance methods can be sent to class objects as * well. */ + (id)retain { return self; } + (id)autorelease |
︙ | ︙ |
Modified src/OFUTF8String.h from [e49ea36f6c] to [3093d4730f].
︙ | ︙ | |||
31 32 33 34 35 36 37 | struct of_string_utf8_ivars { char *cString; size_t cStringLength; bool isUTF8; size_t length; bool hashed; unsigned long hash; | | | 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | struct of_string_utf8_ivars { char *cString; size_t cStringLength; bool isUTF8; size_t length; bool hashed; unsigned long hash; bool freeWhenDone; } *restrict _s; struct of_string_utf8_ivars _storage; } @end #ifdef __cplusplus extern "C" { |
︙ | ︙ |
Modified src/OFUTF8String.m from [e04f7e1202] to [4cdd46e0d2].
︙ | ︙ | |||
24 25 26 27 28 29 30 31 32 33 34 35 36 37 | #ifdef OF_HAVE_SYS_TYPES_H # include <sys/types.h> #endif #import "OFUTF8String.h" #import "OFUTF8String+Private.h" #import "OFArray.h" #import "OFMutableUTF8String.h" #import "OFInitializationFailedException.h" #import "OFInvalidArgumentException.h" #import "OFInvalidEncodingException.h" #import "OFInvalidFormatException.h" #import "OFOutOfMemoryException.h" | > | 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | #ifdef OF_HAVE_SYS_TYPES_H # include <sys/types.h> #endif #import "OFUTF8String.h" #import "OFUTF8String+Private.h" #import "OFArray.h" #import "OFData.h" #import "OFMutableUTF8String.h" #import "OFInitializationFailedException.h" #import "OFInvalidArgumentException.h" #import "OFInvalidEncodingException.h" #import "OFInvalidFormatException.h" #import "OFOutOfMemoryException.h" |
︙ | ︙ | |||
176 177 178 179 180 181 182 | - (instancetype)init { self = [super init]; @try { _s = &_storage; | | | | 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 | - (instancetype)init { self = [super init]; @try { _s = &_storage; _s->cString = of_calloc(1, 1); _s->freeWhenDone = true; } @catch (id e) { [self release]; @throw e; } return self; } |
︙ | ︙ | |||
242 243 244 245 246 247 248 | memcmp(cString, "\xEF\xBB\xBF", 3) == 0) { cString += 3; cStringLength -= 3; } _s = &_storage; | | > | 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 | memcmp(cString, "\xEF\xBB\xBF", 3) == 0) { cString += 3; cStringLength -= 3; } _s = &_storage; _s->cString = of_malloc(cStringLength + 1, 1); _s->cStringLength = cStringLength; _s->freeWhenDone = true; if (encoding == OF_STRING_ENCODING_UTF_8 || encoding == OF_STRING_ENCODING_ASCII) { switch (of_string_utf8_check(cString, cStringLength, &_s->length)) { case 1: if (encoding == OF_STRING_ENCODING_ASCII) |
︙ | ︙ | |||
289 290 291 292 293 294 295 | (uint8_t)cString[i], buffer); if (bytes == 0) @throw [OFInvalidEncodingException exception]; _s->cStringLength += bytes - 1; | | < | | | | | | | 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 | (uint8_t)cString[i], buffer); if (bytes == 0) @throw [OFInvalidEncodingException exception]; _s->cStringLength += bytes - 1; _s->cString = of_realloc(_s->cString, _s->cStringLength + 1, 1); memcpy(_s->cString + j, buffer, bytes); j += bytes; } _s->cString[_s->cStringLength] = 0; return self; } switch (encoding) { #define CASE(encoding, var) \ case encoding: \ table = var; \ tableOffset = var##_offset; \ break; #ifdef HAVE_ISO_8859_2 CASE(OF_STRING_ENCODING_ISO_8859_2, of_iso_8859_2_table) #endif #ifdef HAVE_ISO_8859_3 CASE(OF_STRING_ENCODING_ISO_8859_3, of_iso_8859_3_table) #endif #ifdef HAVE_ISO_8859_15 |
︙ | ︙ | |||
370 371 372 373 374 375 376 | _s->isUTF8 = true; byteLength = of_string_utf8_encode(unichar, buffer); if (byteLength == 0) @throw [OFInvalidEncodingException exception]; _s->cStringLength += byteLength - 1; | | < | | 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 | _s->isUTF8 = true; byteLength = of_string_utf8_encode(unichar, buffer); if (byteLength == 0) @throw [OFInvalidEncodingException exception]; _s->cStringLength += byteLength - 1; _s->cString = of_realloc(_s->cString, _s->cStringLength + 1, 1); memcpy(_s->cString + j, buffer, byteLength); j += byteLength; } _s->cString[_s->cStringLength] = 0; } @catch (id e) { |
︙ | ︙ | |||
422 423 424 425 426 427 428 | break; case -1: @throw [OFInvalidEncodingException exception]; } _s->cString = (char *)UTF8String; _s->cStringLength = UTF8StringLength; | < < | | 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 | break; case -1: @throw [OFInvalidEncodingException exception]; } _s->cString = (char *)UTF8String; _s->cStringLength = UTF8StringLength; _s->freeWhenDone = freeWhenDone; } @catch (id e) { [self release]; @throw e; } return self; } |
︙ | ︙ | |||
450 451 452 453 454 455 456 | [string isKindOfClass: [OFMutableUTF8String class]]) _s->isUTF8 = ((OFUTF8String *)string)->_s->isUTF8; else _s->isUTF8 = true; _s->length = string.length; | | > | > | < | 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 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 | [string isKindOfClass: [OFMutableUTF8String class]]) _s->isUTF8 = ((OFUTF8String *)string)->_s->isUTF8; else _s->isUTF8 = true; _s->length = string.length; _s->cString = of_malloc(_s->cStringLength + 1, 1); memcpy(_s->cString, string.UTF8String, _s->cStringLength + 1); _s->freeWhenDone = true; } @catch (id e) { [self release]; @throw e; } return self; } - (instancetype)initWithCharacters: (const of_unichar_t *)characters length: (size_t)length { self = [super init]; @try { size_t j; _s = &_storage; _s->cString = of_malloc((length * 4) + 1, 1); _s->length = length; _s->freeWhenDone = true; j = 0; for (size_t i = 0; i < length; i++) { size_t len = of_string_utf8_encode(characters[i], _s->cString + j); if (len == 0) @throw [OFInvalidEncodingException exception]; if (len > 1) _s->isUTF8 = true; j += len; } _s->cString[j] = '\0'; _s->cStringLength = j; @try { _s->cString = of_realloc(_s->cString, j + 1, 1); } @catch (OFOutOfMemoryException *e) { /* We don't care, as we only tried to make it smaller */ } } @catch (id e) { [self release]; @throw e; } |
︙ | ︙ | |||
526 527 528 529 530 531 532 | string++; length--; } else if (byteOrder != OF_BYTE_ORDER_NATIVE) swap = true; _s = &_storage; | | > | 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 | string++; length--; } else if (byteOrder != OF_BYTE_ORDER_NATIVE) swap = true; _s = &_storage; _s->cString = of_malloc((length * 4) + 1, 1); _s->length = length; _s->freeWhenDone = true; j = 0; for (size_t i = 0; i < length; i++) { of_unichar_t character = (swap ? OF_BSWAP16(string[i]) : string[i]); size_t len; |
︙ | ︙ | |||
576 577 578 579 580 581 582 | j += len; } _s->cString[j] = '\0'; _s->cStringLength = j; @try { | | < | 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 | j += len; } _s->cString[j] = '\0'; _s->cStringLength = j; @try { _s->cString = of_realloc(_s->cString, j + 1, 1); } @catch (OFOutOfMemoryException *e) { /* We don't care, as we only tried to make it smaller */ } } @catch (id e) { [self release]; @throw e; } |
︙ | ︙ | |||
611 612 613 614 615 616 617 | characters++; length--; } else if (byteOrder != OF_BYTE_ORDER_NATIVE) swap = true; _s = &_storage; | | > | 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 | characters++; length--; } else if (byteOrder != OF_BYTE_ORDER_NATIVE) swap = true; _s = &_storage; _s->cString = of_malloc((length * 4) + 1, 1); _s->length = length; _s->freeWhenDone = true; j = 0; for (size_t i = 0; i < length; i++) { char buffer[4]; size_t len = of_string_utf8_encode( (swap ? OF_BSWAP32(characters[i]) : characters[i]), buffer); |
︙ | ︙ | |||
643 644 645 646 647 648 649 | } } _s->cString[j] = '\0'; _s->cStringLength = j; @try { | | < | 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 | } } _s->cString[j] = '\0'; _s->cStringLength = j; @try { _s->cString = of_realloc(_s->cString, j + 1, 1); } @catch (OFOutOfMemoryException *e) { /* We don't care, as we only tried to make it smaller */ } } @catch (id e) { [self release]; @throw e; } |
︙ | ︙ | |||
686 687 688 689 690 691 692 | case 1: _s->isUTF8 = true; break; case -1: @throw [OFInvalidEncodingException exception]; } | | < > | | | 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 | case 1: _s->isUTF8 = true; break; case -1: @throw [OFInvalidEncodingException exception]; } _s->cString = of_malloc(cStringLength + 1, 1); memcpy(_s->cString, tmp, cStringLength + 1); _s->freeWhenDone = true; } @finally { free(tmp); } } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { if (_s != NULL && _s->freeWhenDone) free(_s->cString); [super dealloc]; } - (size_t)getCString: (char *)cString maxLength: (size_t)maxLength encoding: (of_string_encoding_t)encoding |
︙ | ︙ | |||
1152 1153 1154 1155 1156 1157 1158 | objc_autoreleasePoolPop(pool); return array; } - (const of_unichar_t *)characters { | < | | < < < < < | > | > | | > > > < | | < < < < < | | > | > | | | | > > > | 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 | objc_autoreleasePoolPop(pool); return array; } - (const of_unichar_t *)characters { of_unichar_t *buffer = of_malloc(_s->length, sizeof(of_unichar_t)); size_t i = 0, j = 0; while (i < _s->cStringLength) { of_unichar_t c; ssize_t cLen; cLen = of_string_utf8_decode(_s->cString + i, _s->cStringLength - i, &c); if (cLen <= 0 || c > 0x10FFFF) { free(buffer); @throw [OFInvalidEncodingException exception]; } buffer[j++] = c; i += cLen; } return [[OFData dataWithItemsNoCopy: buffer count: _s->length itemSize: sizeof(of_unichar_t) freeWhenDone: true] items]; } - (const of_char32_t *)UTF32StringWithByteOrder: (of_byte_order_t)byteOrder { of_char32_t *buffer = of_malloc(_s->length + 1, sizeof(of_char32_t)); size_t i = 0, j = 0; while (i < _s->cStringLength) { of_char32_t c; ssize_t cLen; cLen = of_string_utf8_decode(_s->cString + i, _s->cStringLength - i, &c); if (cLen <= 0 || c > 0x10FFFF) { free(buffer); @throw [OFInvalidEncodingException exception]; } if (byteOrder != OF_BYTE_ORDER_NATIVE) buffer[j++] = OF_BSWAP32(c); else buffer[j++] = c; i += cLen; } buffer[j] = 0; return [[OFData dataWithItemsNoCopy: buffer count: _s->length + 1 itemSize: sizeof(of_char32_t) freeWhenDone: true] items]; } #ifdef OF_HAVE_BLOCKS - (void)enumerateLinesUsingBlock: (of_string_line_enumeration_block_t)block { void *pool; const char *cString = _s->cString; |
︙ | ︙ |
Modified src/exceptions/OFAllocFailedException.m from [54ff75e246] to [0eedb0ddc1].
︙ | ︙ | |||
32 33 34 35 36 37 38 | } - (instancetype)init { OF_INVALID_INIT_METHOD } | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | } - (instancetype)init { OF_INVALID_INIT_METHOD } - (instancetype)retain { return self; } - (instancetype)autorelease { |
︙ | ︙ |
Modified src/platform/posix/OFProcess.m from [a1d2451059] to [39ae31952e].
︙ | ︙ | |||
125 126 127 128 129 130 131 | environment: (OFDictionary *)environment { self = [super init]; @try { void *pool = objc_autoreleasePoolPush(); const char *path; | | < | | 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 | environment: (OFDictionary *)environment { self = [super init]; @try { void *pool = objc_autoreleasePoolPush(); const char *path; char **argv, **env = NULL; _pid = -1; _readPipe[0] = _writePipe[1] = -1; if (pipe(_readPipe) != 0 || pipe(_writePipe) != 0) @throw [OFInitializationFailedException exceptionWithClass: self.class]; path = [program cStringWithEncoding: [OFLocale encoding]]; [self of_getArgv: &argv forProgramName: programName andArguments: arguments]; @try { env = [self of_environmentForDictionary: environment]; #ifdef HAVE_POSIX_SPAWNP posix_spawn_file_actions_t actions; posix_spawnattr_t attr; if (posix_spawn_file_actions_init(&actions) != 0) @throw [OFInitializationFailedException exceptionWithClass: self.class]; |
︙ | ︙ | |||
202 203 204 205 206 207 208 209 210 | } if (_pid == -1) @throw [OFInitializationFailedException exceptionWithClass: self.class]; #endif } @finally { close(_readPipe[1]); close(_writePipe[0]); | > > > | > > > > | 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 | } if (_pid == -1) @throw [OFInitializationFailedException exceptionWithClass: self.class]; #endif } @finally { char **iter; close(_readPipe[1]); close(_writePipe[0]); free(argv); for (iter = env; *iter != NULL; iter++) free(*iter); free(env); } objc_autoreleasePoolPop(pool); } @catch (id e) { [self release]; @throw e; } |
︙ | ︙ | |||
232 233 234 235 236 237 238 | forProgramName: (OFString *)programName andArguments: (OFArray *)arguments { OFString *const *objects = arguments.objects; size_t i, count = arguments.count; of_string_encoding_t encoding; | | < < | | < > | | | | | | | | | > | | > | | | | | | > > > > | > > | 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 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 307 308 309 310 311 | forProgramName: (OFString *)programName andArguments: (OFArray *)arguments { OFString *const *objects = arguments.objects; size_t i, count = arguments.count; of_string_encoding_t encoding; *argv = of_malloc(count + 2, sizeof(char *)); encoding = [OFLocale encoding]; (*argv)[0] = (char *)[programName cStringWithEncoding: encoding]; for (i = 0; i < count; i++) (*argv)[i + 1] = (char *)[objects[i] cStringWithEncoding: encoding]; (*argv)[i + 1] = NULL; } - (char **)of_environmentForDictionary: (OFDictionary *)environment { char **envp; size_t count; of_string_encoding_t encoding; if (environment == nil) return NULL; encoding = [OFLocale encoding]; count = environment.count; envp = of_calloc(count + 1, sizeof(char *)); @try { OFEnumerator *keyEnumerator = [environment keyEnumerator]; OFEnumerator *objectEnumerator = [environment objectEnumerator]; for (size_t i = 0; i < count; i++) { OFString *key; OFString *object; size_t keyLen, objectLen; key = [keyEnumerator nextObject]; object = [objectEnumerator nextObject]; keyLen = [key cStringLengthWithEncoding: encoding]; objectLen = [object cStringLengthWithEncoding: encoding]; envp[i] = of_malloc(keyLen + objectLen + 2, 1); memcpy(envp[i], [key cStringWithEncoding: encoding], keyLen); envp[i][keyLen] = '='; memcpy(envp[i] + keyLen + 1, [object cStringWithEncoding: encoding], objectLen); envp[i][keyLen + objectLen + 1] = '\0'; } } @catch (id e) { for (size_t i = 0; i < count; i++) free(envp[i]); free(envp); @throw e; } return envp; } - (bool)lowlevelIsAtEndOfStream { if (_readPipe[0] == -1) |
︙ | ︙ |
Modified tests/OFDataTests.m from [a550decdef] to [b5f79a4b6c].
︙ | ︙ | |||
32 33 34 35 36 37 38 | OFData *immutable; void *raw[2]; of_range_t range; TEST(@"+[dataWithItemSize:]", (mutable = [OFMutableData dataWithItemSize: 4096])) | < | | | 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | OFData *immutable; void *raw[2]; of_range_t range; TEST(@"+[dataWithItemSize:]", (mutable = [OFMutableData dataWithItemSize: 4096])) raw[0] = of_malloc(1, 4096); raw[1] = of_malloc(1, 4096); memset(raw[0], 0xFF, 4096); memset(raw[1], 0x42, 4096); TEST(@"-[addItem:]", R([mutable addItem: raw[0]]) && R([mutable addItem: raw[1]])) TEST(@"-[itemAtIndex:]", |
︙ | ︙ | |||
203 204 205 206 207 208 209 210 211 212 213 | EXPECT_EXCEPTION(@"Detect out of range in -[addItems:count:]", OFOutOfRangeException, [mutable addItems: raw[0] count: SIZE_MAX]) EXPECT_EXCEPTION(@"Detect out of range in -[removeItemsInRange:]", OFOutOfRangeException, [mutable removeItemsInRange: of_range(mutable.count, 1)]) objc_autoreleasePoolPop(pool); } @end | > > > | 202 203 204 205 206 207 208 209 210 211 212 213 214 215 | EXPECT_EXCEPTION(@"Detect out of range in -[addItems:count:]", OFOutOfRangeException, [mutable addItems: raw[0] count: SIZE_MAX]) EXPECT_EXCEPTION(@"Detect out of range in -[removeItemsInRange:]", OFOutOfRangeException, [mutable removeItemsInRange: of_range(mutable.count, 1)]) free(raw[0]); free(raw[1]); objc_autoreleasePoolPop(pool); } @end |
Modified tests/OFObjectTests.m from [5ded62534c] to [7fc519cbf2].
︙ | ︙ | |||
83 84 85 86 87 88 89 | } @end @implementation TestsAppDelegate (OFObjectTests) - (void)objectTests { void *pool = objc_autoreleasePoolPush(); | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 | } @end @implementation TestsAppDelegate (OFObjectTests) - (void)objectTests { void *pool = objc_autoreleasePoolPush(); OFObject *o; MyObj *m; TEST(@"+[description]", [[OFObject description] isEqual: @"OFObject"] && [[MyObj description] isEqual: @"MyObj"]) o = [[[OFObject alloc] init] autorelease]; m = [[[MyObj alloc] init] autorelease]; |
︙ | ︙ |
Modified tests/OFStreamTests.m from [3c0c93a949] to [5c572f840c].
︙ | ︙ | |||
67 68 69 70 71 72 73 | { void *pool = objc_autoreleasePoolPush(); size_t pageSize = [OFSystemInfo pageSize]; StreamTester *t = [[[StreamTester alloc] init] autorelease]; OFString *str; char *cstr; | | > > | 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 | { void *pool = objc_autoreleasePoolPush(); size_t pageSize = [OFSystemInfo pageSize]; StreamTester *t = [[[StreamTester alloc] init] autorelease]; OFString *str; char *cstr; cstr = of_malloc(pageSize - 2, 1); memset(cstr, 'X', pageSize - 3); cstr[pageSize - 3] = '\0'; TEST(@"-[readLine]", [[t readLine] isEqual: @"foo"] && [(str = [t readLine]) length] == pageSize - 3 && !strcmp(str.UTF8String, cstr)) free(cstr); objc_autoreleasePoolPop(pool); } @end |