Comment: | Avoid -[allocMemoryWithSize:] for temporary memory
-[allocMemoryWithSize:] has book keeping overhead that is unnecessary |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
0ddaac3f5b34a2349998883b02e61d8b |
User & Date: | js on 2020-11-05 00:24:29 |
Other Links: | manifest | tags |
2020-11-05
| ||
02:27 | Further reduce usage of -[allocMemoryWithSize:] check-in: da1fb6b21c user: js tags: trunk | |
00:24 | Avoid -[allocMemoryWithSize:] for temporary memory check-in: 0ddaac3f5b user: js tags: trunk | |
2020-11-04
| ||
23:18 | Remove of_free() check-in: 3d8286feee user: js tags: trunk | |
Modified src/OFArray.m from [3a99f337b3] to [e881543a8d].
︙ | ︙ | |||
377 378 379 380 381 382 383 | range.location + range.length < self.count) @throw [OFOutOfRangeException exception]; if (![self isKindOfClass: [OFMutableArray class]]) return [OFSubarray arrayWithArray: self range: range]; | < | < | | 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 | range.location + range.length < self.count) @throw [OFOutOfRangeException exception]; if (![self isKindOfClass: [OFMutableArray class]]) return [OFSubarray arrayWithArray: self range: range]; buffer = of_malloc(range.length, sizeof(*buffer)); @try { [self getObjects: buffer inRange: range]; ret = [OFArray arrayWithObjects: buffer count: range.length]; } @finally { free(buffer); } return ret; } - (OFString *)componentsJoinedByString: (OFString *)separator { |
︙ | ︙ | |||
854 855 856 857 858 859 860 | } #ifdef OF_HAVE_BLOCKS - (OFArray *)mappedArrayUsingBlock: (of_array_map_block_t)block { OFArray *ret; size_t count = self.count; | | < | | < | | 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 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 | } #ifdef OF_HAVE_BLOCKS - (OFArray *)mappedArrayUsingBlock: (of_array_map_block_t)block { OFArray *ret; size_t count = self.count; id *tmp = of_malloc(count, sizeof(id)); @try { [self enumerateObjectsUsingBlock: ^ (id object, size_t idx, bool *stop) { tmp[idx] = block(object, idx); }]; ret = [OFArray arrayWithObjects: tmp count: count]; } @finally { free(tmp); } return ret; } - (OFArray *)filteredArrayUsingBlock: (of_array_filter_block_t)block { OFArray *ret; size_t count = self.count; id *tmp = of_malloc(count, sizeof(id)); @try { __block size_t i = 0; [self enumerateObjectsUsingBlock: ^ (id object, size_t idx, bool *stop) { if (block(object, idx)) tmp[i++] = object; }]; ret = [OFArray arrayWithObjects: tmp count: i]; } @finally { free(tmp); } return ret; } - (id)foldUsingBlock: (of_array_fold_block_t)block { |
︙ | ︙ |
Modified src/OFData.m from [8ada741898] to [20a79e42c1].
︙ | ︙ | |||
193 194 195 196 197 198 199 | attributesOfItemAtPath: path].fileSize; # if ULLONG_MAX > SIZE_MAX if (size > SIZE_MAX) @throw [OFOutOfRangeException exception]; # endif | | | 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | attributesOfItemAtPath: path].fileSize; # if ULLONG_MAX > SIZE_MAX if (size > SIZE_MAX) @throw [OFOutOfRangeException exception]; # endif buffer = of_malloc((size_t)size, 1); file = [[OFFile alloc] initWithPath: path mode: @"r"]; @try { [file readIntoBuffer: buffer exactLength: (size_t)size]; } @finally { [file release]; |
︙ | ︙ |
Modified src/OFHTTPClient.m from [eedb53c084] to [72f7071464].
︙ | ︙ | |||
511 512 513 514 515 516 517 | } lineC = line.UTF8String; if ((tmp = strchr(lineC, ':')) == NULL) @throw [OFInvalidServerReplyException exception]; | | | 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 | } lineC = line.UTF8String; if ((tmp = strchr(lineC, ':')) == NULL) @throw [OFInvalidServerReplyException exception]; keyC = of_malloc(tmp - lineC + 1, 1); memcpy(keyC, lineC, tmp - lineC); keyC[tmp - lineC] = '\0'; normalizeKey(keyC); @try { key = [OFString stringWithUTF8StringNoCopy: keyC freeWhenDone: true]; |
︙ | ︙ |
Modified src/OFMapTableDictionary.m from [d2c4c5ea8c] to [afa073ac3b].
︙ | ︙ | |||
340 341 342 343 344 345 346 | - (OFArray *)allKeys { OFArray *ret; id *keys; size_t count; count = _mapTable.count; | | < | | < | | 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 | - (OFArray *)allKeys { OFArray *ret; id *keys; size_t count; count = _mapTable.count; keys = of_malloc(count, sizeof(*keys)); @try { void *pool = objc_autoreleasePoolPush(); OFMapTableEnumerator *enumerator; void **keyPtr; size_t i; i = 0; enumerator = [_mapTable keyEnumerator]; while ((keyPtr = [enumerator nextObject]) != NULL) { assert(i < count); keys[i++] = (id)*keyPtr; } objc_autoreleasePoolPop(pool); ret = [OFArray arrayWithObjects: keys count: count]; } @finally { free(keys); } return ret; } - (OFArray *)allObjects { OFArray *ret; id *objects; size_t count; count = _mapTable.count; objects = of_malloc(count, sizeof(*objects)); @try { void *pool = objc_autoreleasePoolPush(); OFMapTableEnumerator *enumerator; void **objectPtr; size_t i; i = 0; enumerator = [_mapTable objectEnumerator]; while ((objectPtr = [enumerator nextObject]) != NULL) { assert(i < count); objects[i++] = (id)*objectPtr; } objc_autoreleasePoolPop(pool); ret = [OFArray arrayWithObjects: objects count: count]; } @finally { free(objects); } return ret; } - (OFEnumerator *)keyEnumerator { |
︙ | ︙ |
Modified src/OFMutableAdjacentArray.m from [1999b771ee] to [73c0aec03a].
︙ | ︙ | |||
239 240 241 242 243 244 245 | size_t count = _array.count; id *copy; if (range.length > SIZE_MAX - range.location || range.location >= count || range.length > count - range.location) @throw [OFOutOfRangeException exception]; | < | | | 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 | size_t count = _array.count; id *copy; if (range.length > SIZE_MAX - range.location || range.location >= count || range.length > count - range.location) @throw [OFOutOfRangeException exception]; copy = of_malloc(range.length, sizeof(*copy)); memcpy(copy, objects + range.location, range.length * sizeof(id)); @try { [_array removeItemsInRange: range]; _mutations++; for (size_t i = 0; i < range.length; i++) [copy[i] release]; } @finally { free(copy); } } - (void)removeLastObject { #ifndef __clang_analyzer__ size_t count = _array.count; |
︙ | ︙ |
Modified src/OFMutableSet.m from [460faa4705] to [247e02065c].
︙ | ︙ | |||
168 169 170 171 172 173 174 | - (void)intersectSet: (OFSet *)set { void *pool = objc_autoreleasePoolPush(); size_t count = self.count; id *cArray; | < < | | | 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 | - (void)intersectSet: (OFSet *)set { void *pool = objc_autoreleasePoolPush(); size_t count = self.count; id *cArray; cArray = of_malloc(count, sizeof(id)); @try { size_t i; i = 0; for (id object in self) { assert(i < count); cArray[i++] = object; } for (i = 0; i < count; i++) if (![set containsObject: cArray[i]]) [self removeObject: cArray[i]]; } @finally { free(cArray); } objc_autoreleasePoolPop(pool); } - (void)unionSet: (OFSet *)set { |
︙ | ︙ |
Modified src/OFMutableUTF8String.m from [cb57991be9] to [77a77e4c53].
︙ | ︙ | |||
101 102 103 104 105 106 107 | _s->cString[i] = t; } return; } unicodeLen = self.length; | | < | 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 | _s->cString[i] = t; } return; } unicodeLen = self.length; unicodeString = of_malloc(unicodeLen, sizeof(of_unichar_t)); i = j = 0; newCStringLength = 0; while (i < _s->cStringLength) { const of_unichar_t *const *table; size_t tableSize; |
︙ | ︙ | |||
125 126 127 128 129 130 131 | tableSize = middleTableSize; } cLen = of_string_utf8_decode(_s->cString + i, _s->cStringLength - i, &c); if (cLen <= 0 || c > 0x10FFFF) { | | | 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 | tableSize = middleTableSize; } cLen = of_string_utf8_decode(_s->cString + i, _s->cStringLength - i, &c); if (cLen <= 0 || c > 0x10FFFF) { free(unicodeString); @throw [OFInvalidEncodingException exception]; } isStart = of_ascii_isspace(c); if (c >> 8 < tableSize) { of_unichar_t tc = table[c >> 8][c & 0xFF]; |
︙ | ︙ | |||
148 149 150 151 152 153 154 | else if (c < 0x800) newCStringLength += 2; else if (c < 0x10000) newCStringLength += 3; else if (c < 0x110000) newCStringLength += 4; else { | | | | | | 147 148 149 150 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 190 191 | else if (c < 0x800) newCStringLength += 2; else if (c < 0x10000) newCStringLength += 3; else if (c < 0x110000) newCStringLength += 4; else { free(unicodeString); @throw [OFInvalidEncodingException exception]; } i += cLen; } @try { newCString = [self allocMemoryWithSize: newCStringLength + 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); [self freeMemory: newCString]; @throw [OFInvalidEncodingException exception]; } j += d; } assert(j == newCStringLength); newCString[j] = 0; free(unicodeString); [self freeMemory: _s->cString]; _s->hashed = false; _s->cString = newCString; _s->cStringLength = newCStringLength; /* |
︙ | ︙ | |||
381 382 383 384 385 386 387 | } else _s->isUTF8 = true; } - (void)appendCharacters: (const of_unichar_t *)characters length: (size_t)length { | | < | 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 | } else _s->isUTF8 = true; } - (void)appendCharacters: (const of_unichar_t *)characters length: (size_t)length { char *tmp = of_malloc((length * 4) + 1, 1); @try { size_t j = 0; bool isUTF8 = false; for (size_t i = 0; i < length; i++) { size_t len = of_string_utf8_encode(characters[i], tmp + j); |
︙ | ︙ | |||
414 415 416 417 418 419 420 | _s->cStringLength += j; _s->length += length; if (isUTF8) _s->isUTF8 = true; } @finally { | | | 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 | _s->cStringLength += j; _s->length += length; if (isUTF8) _s->isUTF8 = true; } @finally { free(tmp); } } - (void)appendFormat: (OFConstantString *)format arguments: (va_list)arguments { char *UTF8String; |
︙ | ︙ |
Modified src/OFObject+KeyValueCoding.m from [b5a33b9502] to [060fc086b7].
︙ | ︙ | |||
46 47 48 49 50 51 52 | char *name; if ((keyLength = key.UTF8StringLength) < 1) { objc_autoreleasePoolPop(pool); return [self valueForUndefinedKey: key]; } | | | 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | char *name; if ((keyLength = key.UTF8StringLength) < 1) { objc_autoreleasePoolPop(pool); return [self valueForUndefinedKey: key]; } name = of_malloc(keyLength + 3, 1); @try { memcpy(name, "is", 2); memcpy(name + 2, key.UTF8String, keyLength); name[keyLength + 2] = '\0'; name[2] = of_ascii_toupper(name[2]); |
︙ | ︙ | |||
158 159 160 161 162 163 164 | if ((keyLength = key.UTF8StringLength) < 1) { objc_autoreleasePoolPop(pool); [self setValue: value forUndefinedKey: key]; return; } | | | 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 | if ((keyLength = key.UTF8StringLength) < 1) { objc_autoreleasePoolPop(pool); [self setValue: value forUndefinedKey: key]; return; } name = of_malloc(keyLength + 5, 1); @try { memcpy(name, "set", 3); memcpy(name + 3, key.UTF8String, keyLength); memcpy(name + keyLength + 3, ":", 2); name[3] = of_ascii_toupper(name[3]); |
︙ | ︙ |
Modified src/OFStream.m from [a4e5576272] to [631572b875].
︙ | ︙ | |||
653 654 655 656 657 658 659 | return ret; } - (OFData *)readDataUntilEndOfStream { OFMutableData *data = [OFMutableData data]; size_t pageSize = [OFSystemInfo pageSize]; | | | | | | | | | > > | 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 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 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 | return ret; } - (OFData *)readDataUntilEndOfStream { OFMutableData *data = [OFMutableData data]; size_t pageSize = [OFSystemInfo pageSize]; char *buffer = of_malloc(1, pageSize); @try { while (!self.atEndOfStream) { size_t length; length = [self readIntoBuffer: buffer length: pageSize]; [data addItems: buffer count: length]; } } @finally { free(buffer); } [data makeImmutable]; return data; } - (OFString *)readStringWithLength: (size_t)length { return [self readStringWithLength: length encoding: OF_STRING_ENCODING_UTF_8]; } - (OFString *)readStringWithLength: (size_t)length encoding: (of_string_encoding_t)encoding { OFString *ret; char *buffer = of_malloc(length + 1, 1); buffer[length] = 0; @try { [self readIntoBuffer: buffer exactLength: length]; ret = [OFString stringWithCString: buffer encoding: encoding]; } @finally { free(buffer); } return ret; } - (OFString *)tryReadLineWithEncoding: (of_string_encoding_t)encoding { size_t pageSize, bufferLength; char *buffer, *readBuffer; OFString *ret; /* Look if there's a line or \0 in our buffer */ if (!_waitingForDelimiter && _readBuffer != NULL) { for (size_t i = 0; i < _readBufferLength; i++) { if OF_UNLIKELY (_readBuffer[i] == '\n' || _readBuffer[i] == '\0') { size_t retLength = i; if (i > 0 && _readBuffer[i - 1] == '\r') retLength--; ret = [OFString stringWithCString: _readBuffer encoding: encoding length: retLength]; _readBuffer += i + 1; _readBufferLength -= i + 1; _waitingForDelimiter = false; return ret; } } } /* Read and see if we got a newline or \0 */ pageSize = [OFSystemInfo pageSize]; buffer = of_malloc(1, pageSize); @try { if ([self lowlevelIsAtEndOfStream]) { size_t retLength; if (_readBuffer == NULL) { _waitingForDelimiter = false; return nil; } retLength = _readBufferLength; |
︙ | ︙ | |||
763 764 765 766 767 768 769 | bufferLength = [self lowlevelReadIntoBuffer: buffer length: pageSize]; /* Look if there's a newline or \0 */ for (size_t i = 0; i < bufferLength; i++) { if OF_UNLIKELY (buffer[i] == '\n' || buffer[i] == '\0') { | | | < < < < | | | 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 | bufferLength = [self lowlevelReadIntoBuffer: buffer length: pageSize]; /* Look if there's a newline or \0 */ for (size_t i = 0; i < bufferLength; i++) { if OF_UNLIKELY (buffer[i] == '\n' || buffer[i] == '\0') { size_t retLength = _readBufferLength + i; char *retCString = of_malloc(retLength, 1); if (_readBuffer != NULL) memcpy(retCString, _readBuffer, _readBufferLength); memcpy(retCString + _readBufferLength, buffer, i); if (retLength > 0 && retCString[retLength - 1] == '\r') retLength--; @try { ret = [OFString stringWithCString: retCString encoding: encoding length: retLength]; } @catch (id e) { if (bufferLength > 0) { /* * Append data to _readBuffer * to prevent loss of data. */ readBuffer = [self |
︙ | ︙ | |||
812 813 814 815 816 817 818 | _readBufferMemory = readBuffer; _readBufferLength += bufferLength; } @throw e; } @finally { | | | 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 | _readBufferMemory = readBuffer; _readBufferLength += bufferLength; } @throw e; } @finally { free(retCString); } readBuffer = [self allocMemoryWithSize: bufferLength - i - 1]; if (readBuffer != NULL) memcpy(readBuffer, buffer + i + 1, bufferLength - i - 1); |
︙ | ︙ | |||
844 845 846 847 848 849 850 | buffer, bufferLength); [self freeMemory: _readBufferMemory]; _readBuffer = _readBufferMemory = readBuffer; _readBufferLength += bufferLength; } } @finally { | | | 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 | buffer, bufferLength); [self freeMemory: _readBufferMemory]; _readBuffer = _readBufferMemory = readBuffer; _readBufferLength += bufferLength; } } @finally { free(buffer); } _waitingForDelimiter = true; return nil; } - (OFString *)readLine |
︙ | ︙ | |||
936 937 938 939 940 941 942 | return [self tryReadLineWithEncoding: OF_STRING_ENCODING_UTF_8]; } - (OFString *)tryReadTillDelimiter: (OFString *)delimiter encoding: (of_string_encoding_t)encoding { const char *delimiterCString; | | | | 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 | return [self tryReadLineWithEncoding: OF_STRING_ENCODING_UTF_8]; } - (OFString *)tryReadTillDelimiter: (OFString *)delimiter encoding: (of_string_encoding_t)encoding { const char *delimiterCString; size_t j, delimiterLength, pageSize, bufferLength; char *buffer, *readBuffer; OFString *ret; delimiterCString = [delimiter cStringWithEncoding: encoding]; delimiterLength = [delimiter cStringLengthWithEncoding: encoding]; j = 0; if (delimiterLength == 0) |
︙ | ︙ | |||
973 974 975 976 977 978 979 | return ret; } } } /* Read and see if we got a delimiter or \0 */ pageSize = [OFSystemInfo pageSize]; | | | 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 | return ret; } } } /* Read and see if we got a delimiter or \0 */ pageSize = [OFSystemInfo pageSize]; buffer = of_malloc(1, pageSize); @try { if ([self lowlevelIsAtEndOfStream]) { if (_readBuffer == NULL) { _waitingForDelimiter = false; return nil; } |
︙ | ︙ | |||
1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 | /* Look if there's a delimiter or \0 */ for (size_t i = 0; i < bufferLength; i++) { if (buffer[i] != delimiterCString[j++]) j = 0; if (j == delimiterLength || buffer[i] == '\0') { if (buffer[i] == '\0') delimiterLength = 1; retLength = _readBufferLength + i + 1 - delimiterLength; | > > > | < < < < | | | 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 | /* Look if there's a delimiter or \0 */ for (size_t i = 0; i < bufferLength; i++) { if (buffer[i] != delimiterCString[j++]) j = 0; if (j == delimiterLength || buffer[i] == '\0') { size_t retLength; char *retCString; if (buffer[i] == '\0') delimiterLength = 1; retLength = _readBufferLength + i + 1 - delimiterLength; retCString = of_malloc(retLength, 1); if (_readBuffer != NULL && _readBufferLength <= retLength) memcpy(retCString, _readBuffer, _readBufferLength); else if (_readBuffer != NULL) memcpy(retCString, _readBuffer, retLength); if (i >= delimiterLength) memcpy(retCString + _readBufferLength, buffer, i + 1 - delimiterLength); @try { ret = [OFString stringWithCString: retCString encoding: encoding length: retLength]; } @catch (id e) { if (bufferLength > 0) { /* * Append data to _readBuffer * to prevent loss of data. */ readBuffer = [self |
︙ | ︙ | |||
1057 1058 1059 1060 1061 1062 1063 | _readBufferMemory = readBuffer; _readBufferLength += bufferLength; } @throw e; } @finally { | | | 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 | _readBufferMemory = readBuffer; _readBufferLength += bufferLength; } @throw e; } @finally { free(retCString); } readBuffer = [self allocMemoryWithSize: bufferLength - i - 1]; if (readBuffer != NULL) memcpy(readBuffer, buffer + i + 1, bufferLength - i - 1); |
︙ | ︙ | |||
1089 1090 1091 1092 1093 1094 1095 | buffer, bufferLength); [self freeMemory: _readBufferMemory]; _readBuffer = _readBufferMemory = readBuffer; _readBufferLength += bufferLength; } } @finally { | | | 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 | buffer, bufferLength); [self freeMemory: _readBufferMemory]; _readBuffer = _readBufferMemory = readBuffer; _readBufferLength += bufferLength; } } @finally { free(buffer); } _waitingForDelimiter = true; return nil; } |
︙ | ︙ | |||
1334 1335 1336 1337 1338 1339 1340 | size = count * sizeof(uint16_t); #ifdef OF_BIG_ENDIAN [self writeBuffer: buffer length: size]; #else | | < | | < | | < | | < | | < | | 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 | size = count * sizeof(uint16_t); #ifdef OF_BIG_ENDIAN [self writeBuffer: buffer length: size]; #else uint16_t *tmp = of_malloc(count, sizeof(uint16_t)); @try { for (size_t i = 0; i < count; i++) tmp[i] = OF_BSWAP16(buffer[i]); [self writeBuffer: tmp length: size]; } @finally { free(tmp); } #endif return size; } - (size_t)writeBigEndianInt32s: (const uint32_t *)buffer count: (size_t)count { size_t size; if OF_UNLIKELY (count > SIZE_MAX / sizeof(uint32_t)) @throw [OFOutOfRangeException exception]; size = count * sizeof(uint32_t); #ifdef OF_BIG_ENDIAN [self writeBuffer: buffer length: size]; #else uint32_t *tmp = of_malloc(count, sizeof(uint32_t)); @try { for (size_t i = 0; i < count; i++) tmp[i] = OF_BSWAP32(buffer[i]); [self writeBuffer: tmp length: size]; } @finally { free(tmp); } #endif return size; } - (size_t)writeBigEndianInt64s: (const uint64_t *)buffer count: (size_t)count { size_t size; if OF_UNLIKELY (count > SIZE_MAX / sizeof(uint64_t)) @throw [OFOutOfRangeException exception]; size = count * sizeof(uint64_t); #ifdef OF_BIG_ENDIAN [self writeBuffer: buffer length: size]; #else uint64_t *tmp = of_malloc(count, sizeof(uint64_t)); @try { for (size_t i = 0; i < count; i++) tmp[i] = OF_BSWAP64(buffer[i]); [self writeBuffer: tmp length: size]; } @finally { free(tmp); } #endif return size; } - (size_t)writeBigEndianFloats: (const float *)buffer count: (size_t)count { size_t size; if OF_UNLIKELY (count > SIZE_MAX / sizeof(float)) @throw [OFOutOfRangeException exception]; size = count * sizeof(float); #ifdef OF_FLOAT_BIG_ENDIAN [self writeBuffer: buffer length: size]; #else float *tmp = of_malloc(count, sizeof(float)); @try { for (size_t i = 0; i < count; i++) tmp[i] = OF_BSWAP_FLOAT(buffer[i]); [self writeBuffer: tmp length: size]; } @finally { free(tmp); } #endif return size; } - (size_t)writeBigEndianDoubles: (const double *)buffer count: (size_t)count { size_t size; if OF_UNLIKELY (count > SIZE_MAX / sizeof(double)) @throw [OFOutOfRangeException exception]; size = count * sizeof(double); #ifdef OF_FLOAT_BIG_ENDIAN [self writeBuffer: buffer length: size]; #else double *tmp = of_malloc(count, sizeof(double)); @try { for (size_t i = 0; i < count; i++) tmp[i] = OF_BSWAP_DOUBLE(buffer[i]); [self writeBuffer: tmp length: size]; } @finally { free(tmp); } #endif return size; } - (void)writeLittleEndianInt16: (uint16_t)int16 |
︙ | ︙ | |||
1529 1530 1531 1532 1533 1534 1535 | size = count * sizeof(uint16_t); #ifndef OF_BIG_ENDIAN [self writeBuffer: buffer length: size]; #else | | < | | < | | < | | < | | < | | 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 | size = count * sizeof(uint16_t); #ifndef OF_BIG_ENDIAN [self writeBuffer: buffer length: size]; #else uint16_t *tmp = of_malloc(count, sizeof(uint16_t)); @try { for (size_t i = 0; i < count; i++) tmp[i] = OF_BSWAP16(buffer[i]); [self writeBuffer: tmp length: size]; } @finally { free(tmp); } #endif return size; } - (size_t)writeLittleEndianInt32s: (const uint32_t *)buffer count: (size_t)count { size_t size; if OF_UNLIKELY (count > SIZE_MAX / sizeof(uint32_t)) @throw [OFOutOfRangeException exception]; size = count * sizeof(uint32_t); #ifndef OF_BIG_ENDIAN [self writeBuffer: buffer length: size]; #else uint32_t *tmp = of_malloc(count, sizeof(uint32_t)); @try { for (size_t i = 0; i < count; i++) tmp[i] = OF_BSWAP32(buffer[i]); [self writeBuffer: tmp length: size]; } @finally { free(tmp); } #endif return size; } - (size_t)writeLittleEndianInt64s: (const uint64_t *)buffer count: (size_t)count { size_t size; if OF_UNLIKELY (count > SIZE_MAX / sizeof(uint64_t)) @throw [OFOutOfRangeException exception]; size = count * sizeof(uint64_t); #ifndef OF_BIG_ENDIAN [self writeBuffer: buffer length: size]; #else uint64_t *tmp = of_malloc(count, sizeof(uint64_t)); @try { for (size_t i = 0; i < count; i++) tmp[i] = OF_BSWAP64(buffer[i]); [self writeBuffer: tmp length: size]; } @finally { free(tmp); } #endif return size; } - (size_t)writeLittleEndianFloats: (const float *)buffer count: (size_t)count { size_t size; if OF_UNLIKELY (count > SIZE_MAX / sizeof(float)) @throw [OFOutOfRangeException exception]; size = count * sizeof(float); #ifndef OF_FLOAT_BIG_ENDIAN [self writeBuffer: buffer length: size]; #else float *tmp = of_malloc(count, sizeof(float)); @try { for (size_t i = 0; i < count; i++) tmp[i] = OF_BSWAP_FLOAT(buffer[i]); [self writeBuffer: tmp length: size]; } @finally { free(tmp); } #endif return size; } - (size_t)writeLittleEndianDoubles: (const double *)buffer count: (size_t)count { size_t size; if OF_UNLIKELY (count > SIZE_MAX / sizeof(double)) @throw [OFOutOfRangeException exception]; size = count * sizeof(double); #ifndef OF_FLOAT_BIG_ENDIAN [self writeBuffer: buffer length: size]; #else double *tmp = of_malloc(count, sizeof(double)); @try { for (size_t i = 0; i < count; i++) tmp[i] = OF_BSWAP_DOUBLE(buffer[i]); [self writeBuffer: tmp length: size]; } @finally { free(tmp); } #endif return size; } - (size_t)writeData: (OFData *)data |
︙ | ︙ | |||
1727 1728 1729 1730 1731 1732 1733 | - (size_t)writeLine: (OFString *)string encoding: (of_string_encoding_t)encoding { size_t stringLength = [string cStringLengthWithEncoding: encoding]; char *buffer; | | | | 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 | - (size_t)writeLine: (OFString *)string encoding: (of_string_encoding_t)encoding { size_t stringLength = [string cStringLengthWithEncoding: encoding]; char *buffer; buffer = of_malloc(stringLength + 1, 1); @try { memcpy(buffer, [string cStringWithEncoding: encoding], stringLength); buffer[stringLength] = '\n'; [self writeBuffer: buffer length: stringLength + 1]; } @finally { free(buffer); } return stringLength + 1; } - (size_t)writeFormat: (OFConstantString *)format, ... { |
︙ | ︙ |
Modified src/OFString+JSONParsing.m from [6d4d4d10b0] to [c0346b7fe9].
︙ | ︙ | |||
144 145 146 147 148 149 150 | char *buffer; size_t i = 0; char delimiter = **pointer; if (++(*pointer) + 1 >= stop) return nil; | | | 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 | char *buffer; size_t i = 0; char delimiter = **pointer; if (++(*pointer) + 1 >= stop) return nil; buffer = of_malloc(stop - *pointer, 1); while (*pointer < stop) { /* Parse escape codes */ if (**pointer == '\\') { if (++(*pointer) >= stop) { free(buffer); return nil; |
︙ | ︙ | |||
290 291 292 293 294 295 296 | static inline OFString * parseIdentifier(const char **pointer, const char *stop) { char *buffer; size_t i = 0; | | | 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 | static inline OFString * parseIdentifier(const char **pointer, const char *stop) { char *buffer; size_t i = 0; buffer = of_malloc(stop - *pointer, 1); while (*pointer < stop) { if ((**pointer >= 'a' && **pointer <= 'z') || (**pointer >= 'A' && **pointer <= 'Z') || (**pointer >= '0' && **pointer <= '9') || **pointer == '_' || **pointer == '$' || (**pointer & 0x80)) { |
︙ | ︙ |
Modified src/OFString+URLEncoding.m from [7714669373] to [4c3b80addf].
︙ | ︙ | |||
85 86 87 88 89 90 91 | const char *string = self.UTF8String; size_t length = self.UTF8StringLength; char *retCString; char byte = 0; int state = 0; size_t i = 0; | | | 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 | const char *string = self.UTF8String; size_t length = self.UTF8StringLength; char *retCString; char byte = 0; int state = 0; size_t i = 0; retCString = of_malloc(length + 1, 1); while (length--) { char c = *string++; switch (state) { case 0: if (c == '%') |
︙ | ︙ |
Modified src/OFString+XMLEscaping.m from [bd600aa82b] to [e1df224af8].
︙ | ︙ | |||
38 39 40 41 42 43 44 | OFString *ret; string = self.UTF8String; length = self.UTF8StringLength; j = 0; retLength = length; | < < < < | | 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | OFString *ret; string = self.UTF8String; length = self.UTF8StringLength; j = 0; retLength = length; retCString = of_malloc(retLength, 1); for (size_t i = 0; i < length; i++) { switch (string[i]) { case '<': append = "<"; appendLen = 4; break; |
︙ | ︙ |
Modified src/OFString.m from [4df757c93c] to [8da779313c].
︙ | ︙ | |||
1025 1026 1027 1028 1029 1030 1031 | /* * We need one extra byte for the terminating zero if we want * to use -[initWithUTF8StringNoCopy:length:freeWhenDone:]. */ if (SIZE_MAX - (size_t)fileSize < 1) @throw [OFOutOfRangeException exception]; | | | 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 | /* * We need one extra byte for the terminating zero if we want * to use -[initWithUTF8StringNoCopy:length:freeWhenDone:]. */ if (SIZE_MAX - (size_t)fileSize < 1) @throw [OFOutOfRangeException exception]; tmp = of_malloc((size_t)fileSize + 1, 1); @try { file = [[OFFile alloc] initWithPath: path mode: @"r"]; [file readIntoBuffer: tmp exactLength: (size_t)fileSize]; } @catch (id e) { |
︙ | ︙ | |||
2164 2165 2166 2167 2168 2169 2170 | of_unichar_t *tmp; size_t prefixLength; bool hasPrefix; if ((prefixLength = prefix.length) > self.length) return false; | | < | | < | | 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 | of_unichar_t *tmp; size_t prefixLength; bool hasPrefix; if ((prefixLength = prefix.length) > self.length) return false; tmp = of_malloc(prefixLength, sizeof(of_unichar_t)); @try { void *pool = objc_autoreleasePoolPush(); [self getCharacters: tmp inRange: of_range(0, prefixLength)]; hasPrefix = (memcmp(tmp, prefix.characters, prefixLength * sizeof(of_unichar_t)) == 0); objc_autoreleasePoolPop(pool); } @finally { free(tmp); } return hasPrefix; } - (bool)hasSuffix: (OFString *)suffix { of_unichar_t *tmp; const of_unichar_t *suffixCharacters; size_t length, suffixLength; bool hasSuffix; if ((suffixLength = suffix.length) > self.length) return false; length = self.length; tmp = of_malloc(suffixLength, sizeof(of_unichar_t)); @try { void *pool = objc_autoreleasePoolPush(); [self getCharacters: tmp inRange: of_range(length - suffixLength, suffixLength)]; suffixCharacters = suffix.characters; hasSuffix = (memcmp(tmp, suffixCharacters, suffixLength * sizeof(of_unichar_t)) == 0); objc_autoreleasePoolPop(pool); } @finally { free(tmp); } return hasSuffix; } - (OFArray *)componentsSeparatedByString: (OFString *)delimiter { |
︙ | ︙ |
Modified src/OFWin32ConsoleStdIOStream.m from [959c780c29] to [7dd85d6178].
︙ | ︙ | |||
133 134 135 136 137 138 139 | char *buffer = buffer_; of_char16_t *UTF16; size_t j = 0; if (length > UINT32_MAX) @throw [OFOutOfRangeException exception]; | | < | 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 | char *buffer = buffer_; of_char16_t *UTF16; size_t j = 0; if (length > UINT32_MAX) @throw [OFOutOfRangeException exception]; UTF16 = of_malloc(length, sizeof(of_char16_t)); @try { DWORD UTF16Len; OFMutableData *rest = nil; size_t i = 0; if ([OFSystemInfo isWindowsNT]) { if (!ReadConsoleW(_handle, UTF16, (DWORD)length, |
︙ | ︙ | |||
256 257 258 259 260 261 262 | } } if (rest != nil) [self unreadFromBuffer: rest.items length: rest.count]; } @finally { | | | 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 | } } if (rest != nil) [self unreadFromBuffer: rest.items length: rest.count]; } @finally { free(UTF16); } objc_autoreleasePoolPop(pool); return j; } |
︙ | ︙ | |||
361 362 363 364 365 366 367 | bytesWritten: bytesWritten * 2 errNo: 0]; _incompleteUTF8SurrogateLen = 0; i += toCopy; } | | < | 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 | bytesWritten: bytesWritten * 2 errNo: 0]; _incompleteUTF8SurrogateLen = 0; i += toCopy; } tmp = of_malloc(length * 2, sizeof(of_char16_t)); @try { DWORD bytesWritten; while (i < length) { of_unichar_t c; ssize_t UTF8Len; |
︙ | ︙ | |||
441 442 443 444 445 446 447 | if (bytesWritten != j) @throw [OFWriteFailedException exceptionWithObject: self requestedLength: j * 2 bytesWritten: bytesWritten * 2 errNo: 0]; } @finally { | | | 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 | if (bytesWritten != j) @throw [OFWriteFailedException exceptionWithObject: self requestedLength: j * 2 bytesWritten: bytesWritten * 2 errNo: 0]; } @finally { free(tmp); } /* * We do not count in bytes when writing to the Win32 console. But * since any incomplete write is an exception here anyway, we can just * return length. */ |
︙ | ︙ |
Modified src/OFXMLComment.m from [cfed32bae5] to [2577a47d50].
︙ | ︙ | |||
112 113 114 115 116 117 118 | - (OFString *)XMLStringWithIndentation: (unsigned int)indentation level: (unsigned int)level { OFString *ret; if (indentation > 0 && level > 0) { | < | | | 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 | - (OFString *)XMLStringWithIndentation: (unsigned int)indentation level: (unsigned int)level { OFString *ret; if (indentation > 0 && level > 0) { char *whitespaces = of_malloc((level * indentation) + 1, 1); memset(whitespaces, ' ', level * indentation); whitespaces[level * indentation] = 0; @try { ret = [OFString stringWithFormat: @"%s<!--%@-->", whitespaces, _comment]; } @finally { free(whitespaces); } } else ret = [OFString stringWithFormat: @"<!--%@-->", _comment]; return ret; } |
︙ | ︙ |
Modified src/OFXMLElement.m from [804319c0a1] to [d12879cd95].
︙ | ︙ | |||
44 45 46 47 48 49 50 | /* References for static linking */ void _references_to_categories_of_OFXMLElement(void) { _OFXMLElement_Serialization_reference = 1; } | < < < | 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | /* References for static linking */ void _references_to_categories_of_OFXMLElement(void) { _OFXMLElement_Serialization_reference = 1; } @interface OFXMLElementElementBuilderDelegate: OFObject <OFXMLElementBuilderDelegate> { @public OFXMLElement *_element; } @end |
︙ | ︙ | |||
75 76 77 78 79 80 81 | } @end @implementation OFXMLElement @synthesize name = _name, namespace = _namespace; @synthesize defaultNamespace = _defaultNamespace; | < < < < < < < < | 72 73 74 75 76 77 78 79 80 81 82 83 84 85 | } @end @implementation OFXMLElement @synthesize name = _name, namespace = _namespace; @synthesize defaultNamespace = _defaultNamespace; + (instancetype)elementWithName: (OFString *)name { return [[[self alloc] initWithName: name] autorelease]; } + (instancetype)elementWithName: (OFString *)name stringValue: (OFString *)stringValue |
︙ | ︙ | |||
422 423 424 425 426 427 428 | [ret makeImmutable]; return ret; } - (OFString *)of_XMLStringWithParent: (OFXMLElement *)parent | | | | | | | | | > | | | | | | < < < < < < < | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | | | | | < | | 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 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 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 545 546 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 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 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 | [ret makeImmutable]; return ret; } - (OFString *)of_XMLStringWithParent: (OFXMLElement *)parent namespaces: (OFDictionary *)allNS indentation: (unsigned int)indentation level: (unsigned int)level OF_DIRECT { void *pool; char *cString; size_t length, i; OFString *prefix, *parentPrefix; OFString *ret; OFString *defaultNS; pool = objc_autoreleasePoolPush(); parentPrefix = [allNS objectForKey: (parent != nil && parent->_namespace != nil ? parent->_namespace : (OFString *)@"")]; /* Add the namespaces of the current element */ if (allNS != nil) { OFEnumerator *keyEnumerator = [_namespaces keyEnumerator]; OFEnumerator *objectEnumerator = [_namespaces objectEnumerator]; OFMutableDictionary *tmp; OFString *key, *object; tmp = [[allNS mutableCopy] autorelease]; while ((key = [keyEnumerator nextObject]) != nil && (object = [objectEnumerator nextObject]) != nil) [tmp setObject: object forKey: key]; allNS = tmp; } else allNS = _namespaces; prefix = [allNS objectForKey: (_namespace != nil ? _namespace : (OFString *)@"")]; if (parent != nil && parent->_namespace != nil && parentPrefix == nil) defaultNS = parent->_namespace; else if (parent != nil && parent->_defaultNamespace != nil) defaultNS = parent->_defaultNamespace; else defaultNS = _defaultNamespace; i = 0; length = _name.UTF8StringLength + 3 + (level * indentation); cString = of_malloc(length, 1); @try { memset(cString + i, ' ', level * indentation); i += level * indentation; /* Start of tag */ cString[i++] = '<'; if (prefix != nil && ![_namespace isEqual: defaultNS]) { length += prefix.UTF8StringLength + 1; cString = of_realloc(cString, length, 1); 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 && ((_namespace != nil && ![_namespace isEqual: defaultNS]) || (_namespace == nil && defaultNS != nil))) { length += _namespace.UTF8StringLength + 9; cString = of_realloc(cString, length, 1); memcpy(cString + i, " xmlns='", 8); i += 8; memcpy(cString + i, _namespace.UTF8String, _namespace.UTF8StringLength); i += _namespace.UTF8StringLength; cString[i++] = '\''; } /* Attributes */ for (OFXMLAttribute *attribute in _attributes) { void *pool2 = objc_autoreleasePoolPush(); const char *attributeNameCString = attribute->_name.UTF8String; size_t attributeNameLength = attribute->_name.UTF8StringLength; OFString *attributePrefix = nil; OFString *tmp = attribute.stringValue.stringByXMLEscaping; char delimiter = (attribute->_useDoubleQuotes ? '"' : '\''); if (attribute->_namespace != nil && (attributePrefix = [allNS objectForKey: attribute->_namespace]) == nil) @throw [OFUnboundNamespaceException exceptionWithNamespace: attribute.namespace element: self]; length += attributeNameLength + (attributePrefix != nil ? attributePrefix.UTF8StringLength + 1 : 0) + tmp.UTF8StringLength + 4; cString = of_realloc(cString, length, 1); cString[i++] = ' '; if (attributePrefix != nil) { memcpy(cString + i, attributePrefix.UTF8String, attributePrefix.UTF8StringLength); i += attributePrefix.UTF8StringLength; cString[i++] = ':'; } memcpy(cString + i, attributeNameCString, attributeNameLength); i += attributeNameLength; cString[i++] = '='; cString[i++] = delimiter; memcpy(cString + i, tmp.UTF8String, tmp.UTF8StringLength); i += tmp.UTF8StringLength; cString[i++] = delimiter; objc_autoreleasePoolPop(pool2); } /* Children */ if (_children != nil) { OFMutableData *tmp = [OFMutableData data]; bool indent; if (indentation > 0) { indent = true; for (OFXMLNode *child in _children) { if ([child isKindOfClass: [OFXMLCharacters class]] || [child isKindOfClass: [OFXMLCDATA class]]) { indent = false; break; } } } else indent = false; for (OFXMLNode *child in _children) { OFString *childString; unsigned int ind = (indent ? indentation : 0); if (ind) [tmp addItem: "\n"]; if ([child isKindOfClass: [OFXMLElement class]]) childString = [(OFXMLElement *)child of_XMLStringWithParent: self namespaces: allNS indentation: ind level: level + 1]; else childString = [child XMLStringWithIndentation: ind level: level + 1]; [tmp addItems: childString.UTF8String count: childString.UTF8StringLength]; } if (indent) [tmp addItem: "\n"]; length += tmp.count + _name.UTF8StringLength + 2 + (indent ? level * indentation : 0); cString = of_realloc(cString, length, 1); cString[i++] = '>'; memcpy(cString + i, tmp.items, tmp.count); i += tmp.count; if (indent) { memset(cString + i, ' ', level * indentation); i += level * indentation; } cString[i++] = '<'; cString[i++] = '/'; if (prefix != nil) { length += prefix.UTF8StringLength + 1; cString = of_realloc(cString, length, 1); memcpy(cString + i, prefix.UTF8String, prefix.UTF8StringLength); i += prefix.UTF8StringLength; cString[i++] = ':'; } memcpy(cString + i, _name.UTF8String, _name.UTF8StringLength); i += _name.UTF8StringLength; } else cString[i++] = '/'; cString[i++] = '>'; assert(i == length); objc_autoreleasePoolPop(pool); ret = [OFString stringWithUTF8String: cString length: length]; } @finally { free(cString); } return ret; } - (OFString *)XMLString { return [self of_XMLStringWithParent: nil |
︙ | ︙ |
Modified src/OFXMLParser.m from [ff15f62058] to [8b036ac867].
︙ | ︙ | |||
274 275 276 277 278 279 280 | [self parseBuffer: string.UTF8String length: string.UTF8StringLength]; } - (void)parseStream: (OFStream *)stream { size_t pageSize = [OFSystemInfo pageSize]; | | | | 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 | [self parseBuffer: string.UTF8String length: string.UTF8StringLength]; } - (void)parseStream: (OFStream *)stream { size_t pageSize = [OFSystemInfo pageSize]; char *buffer = of_malloc(1, pageSize); @try { while (!stream.atEndOfStream) { size_t length = [stream readIntoBuffer: buffer length: pageSize]; [self parseBuffer: buffer length: length]; } } @finally { free(buffer); } } #ifdef OF_HAVE_FILES - (void)parseFile: (OFString *)path { OFFile *file = [[OFFile alloc] initWithPath: path |
︙ | ︙ |
Modified src/OFXMLProcessingInstructions.m from [7c38ca2413] to [5705c589f5].
︙ | ︙ | |||
113 114 115 116 117 118 119 | - (OFString *)XMLStringWithIndentation: (unsigned int)indentation level: (unsigned int)level { OFString *ret; if (indentation > 0 && level > 0) { | < | | | 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 | - (OFString *)XMLStringWithIndentation: (unsigned int)indentation level: (unsigned int)level { OFString *ret; if (indentation > 0 && level > 0) { char *whitespaces = of_malloc((level * indentation) + 1, 1); memset(whitespaces, ' ', level * indentation); whitespaces[level * indentation] = 0; @try { ret = [OFString stringWithFormat: @"%s<?%@?>", whitespaces, _processingInstructions]; } @finally { free(whitespaces); } } else ret = [OFString stringWithFormat: @"<?%@?>", _processingInstructions]; return ret; } |
︙ | ︙ |
Modified src/platform/windows/OFProcess.m from [816ee6b0db] to [1de0e5d870].
︙ | ︙ | |||
191 192 193 194 195 196 197 | si.cb = sizeof(si); si.hStdInput = _writePipe[0]; si.hStdOutput = _readPipe[1]; si.hStdError = GetStdHandle(STD_ERROR_HANDLE); si.dwFlags |= STARTF_USESTDHANDLES; length = argumentsString.UTF16StringLength; | | < < | | 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 | si.cb = sizeof(si); si.hStdInput = _writePipe[0]; si.hStdOutput = _readPipe[1]; si.hStdError = GetStdHandle(STD_ERROR_HANDLE); si.dwFlags |= STARTF_USESTDHANDLES; length = argumentsString.UTF16StringLength; argumentsCopy = of_malloc(length + 1, sizeof(of_char16_t)); memcpy(argumentsCopy, argumentsString.UTF16String, (length + 1) * 2); @try { if (!CreateProcessW(program.UTF16String, argumentsCopy, NULL, NULL, TRUE, CREATE_UNICODE_ENVIRONMENT, [self of_wideEnvironmentForDictionary: environment], NULL, &si, &pi)) @throw [OFInitializationFailedException exceptionWithClass: self.class]; } @finally { free(argumentsCopy); } } else { of_string_encoding_t encoding = [OFLocale encoding]; STARTUPINFO si; memset(&si, 0, sizeof(si)); si.cb = sizeof(si); |
︙ | ︙ |