| 601 | } |
| 602 | |
| 603 | static sz_bool_t sz_py_replace_u32_tape_allocator(Strs *strs, sz_memory_allocator_t *old_allocator, |
| 604 | sz_memory_allocator_t *allocator) { |
| 605 | struct u32_tape_t *data = &strs->data.u32_tape; |
| 606 | sz_assert_(data->offsets && "Expected offsets to be allocated"); |
| 607 | |
| 608 | sz_size_t const string_data_size = (sz_size_t)data->offsets[data->count]; |
| 609 | sz_size_t const offsets_size = (data->count + 1) * sizeof(sz_u32_t); |
| 610 | |
| 611 | // Allocate new string data with new allocator |
| 612 | sz_ptr_t new_string_data = |
| 613 | string_data_size ? (sz_ptr_t)allocator->allocate(string_data_size, allocator->handle) : (sz_ptr_t)NULL; |
| 614 | if (string_data_size && !new_string_data) return sz_false_k; |
| 615 | memcpy(new_string_data, data->data, string_data_size); |
| 616 | |
| 617 | // Allocate new offsets array |
| 618 | sz_u32_t *new_offsets = |
| 619 | offsets_size ? (sz_u32_t *)allocator->allocate(offsets_size, allocator->handle) : (sz_u32_t *)NULL; |
| 620 | if (offsets_size && !new_offsets) { |
| 621 | if (string_data_size) allocator->free(new_string_data, string_data_size, allocator->handle); |
| 622 | return sz_false_k; |
| 623 | } |
| 624 | memcpy(new_offsets, data->offsets, offsets_size); |
| 625 | |
| 626 | // Free old memory with old allocator (tapes always own their data) |
| 627 | old_allocator->free(data->data, string_data_size, old_allocator->handle); |
| 628 | old_allocator->free(data->offsets, offsets_size, old_allocator->handle); |
| 629 | |
| 630 | // Update pointers and allocator |
| 631 | data->data = new_string_data; |
| 632 | data->offsets = new_offsets; |
| 633 | data->allocator = *allocator; |
| 634 | return sz_true_k; |
| 635 | } |
| 636 | |
| 637 | static sz_bool_t sz_py_replace_u64_tape_allocator(Strs *strs, sz_memory_allocator_t *old_allocator, |
| 638 | sz_memory_allocator_t *allocator) { |
no test coverage detected
searching dependent graphs…