Differences From Artifact [7044157852]:
- File
src/OFString.m
— part of check-in
[0f260e0fd5]
at
2020-11-06 02:37:02
on branch trunk
— OFString: Make freeWhenDone behave like in OFData
In particular, this means that if initialization fails, the buffer is
NOT free'd. While freeing it on error in convenient when not handling
the error, it makes handling the error and retrying impossible (e.g.
retrying with a different encoding). (user: js, size: 65913) [annotate] [blame] [check-ins using]
To Artifact [3f36b9543e]:
- File src/OFString.m — part of check-in [7aa23887d0] at 2020-11-07 10:38:49 on branch trunk — Make GCC happy again (user: js, size: 65932) [annotate] [blame] [check-ins using] [more...]
︙ | ︙ | |||
1429 1430 1431 1432 1433 1434 1435 | break; default: @throw [OFInvalidEncodingException exception]; } @try { | | | | | 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 | break; default: @throw [OFInvalidEncodingException exception]; } @try { return [[OFData dataWithItemsNoCopy: cString count: cStringLength + 1 freeWhenDone: true] items]; } @catch (id e) { free(cString); @throw e; } } - (const char *)cStringWithEncoding: (of_string_encoding_t)encoding |
︙ | ︙ | |||
2504 2505 2506 2507 2508 2509 2510 | of_unichar_t *buffer; buffer = of_malloc(length, sizeof(of_unichar_t)); @try { [self getCharacters: buffer inRange: of_range(0, length)]; | | | | | | 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 | of_unichar_t *buffer; buffer = of_malloc(length, sizeof(of_unichar_t)); @try { [self getCharacters: buffer inRange: of_range(0, length)]; return [[OFData dataWithItemsNoCopy: buffer count: length itemSize: sizeof(of_unichar_t) freeWhenDone: true] items]; } @catch (id e) { free(buffer); @throw e; } } - (const of_char16_t *)UTF16String |
︙ | ︙ | |||
2567 2568 2569 2570 2571 2572 2573 | } @catch (OFOutOfMemoryException *e) { /* We don't care, as we only tried to make it smaller */ } objc_autoreleasePoolPop(pool); @try { | | | | | | 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 | } @catch (OFOutOfMemoryException *e) { /* We don't care, as we only tried to make it smaller */ } objc_autoreleasePoolPop(pool); @try { return [[OFData dataWithItemsNoCopy: buffer count: j + 1 itemSize: sizeof(of_char16_t) freeWhenDone: true] items]; } @catch (id e) { free(buffer); @throw e; } } - (size_t)UTF16StringLength |
︙ | ︙ | |||
2611 2612 2613 2614 2615 2616 2617 | inRange: of_range(0, length)]; buffer[length] = 0; if (byteOrder != OF_BYTE_ORDER_NATIVE) for (size_t i = 0; i < length; i++) buffer[i] = OF_BSWAP32(buffer[i]); | | | | | | 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 | inRange: of_range(0, length)]; buffer[length] = 0; if (byteOrder != OF_BYTE_ORDER_NATIVE) for (size_t i = 0; i < length; i++) buffer[i] = OF_BSWAP32(buffer[i]); return [[OFData dataWithItemsNoCopy: buffer count: length + 1 itemSize: sizeof(of_char32_t) freeWhenDone: true] items]; } @catch (id e) { free(buffer); @throw e; } } - (OFData *)dataWithEncoding: (of_string_encoding_t)encoding |
︙ | ︙ |