| 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) { |
| 639 | struct u64_tape_t *data = &strs->data.u64_tape; |
| 640 | sz_assert_(data->offsets && "Expected offsets to be allocated"); |
| 641 | |
| 642 | sz_size_t string_data_size = (sz_size_t)data->offsets[data->count]; |
| 643 | sz_size_t offsets_size = (data->count + 1) * sizeof(sz_u64_t); |
| 644 | |
| 645 | // Allocate new string data with new allocator |
| 646 | sz_ptr_t new_string_data = |
| 647 | string_data_size ? (sz_ptr_t)allocator->allocate(string_data_size, allocator->handle) : (sz_ptr_t)NULL; |
| 648 | if (string_data_size && !new_string_data) return sz_false_k; |
| 649 | memcpy(new_string_data, data->data, string_data_size); |
| 650 | |
| 651 | // Allocate new offsets array |
| 652 | sz_u64_t *new_offsets = |
| 653 | offsets_size ? (sz_u64_t *)allocator->allocate(offsets_size, allocator->handle) : (sz_u64_t *)NULL; |
| 654 | if (offsets_size && !new_offsets) { |
| 655 | if (string_data_size) allocator->free(new_string_data, string_data_size, allocator->handle); |
| 656 | return sz_false_k; |
| 657 | } |
| 658 | memcpy(new_offsets, data->offsets, offsets_size); |
| 659 | |
| 660 | // Free old memory with old allocator (tapes always own their data) |
| 661 | old_allocator->free(data->data, string_data_size, old_allocator->handle); |
| 662 | old_allocator->free(data->offsets, offsets_size, old_allocator->handle); |
| 663 | |
| 664 | // Update pointers and allocator |
| 665 | data->data = new_string_data; |
| 666 | data->offsets = new_offsets; |
| 667 | data->allocator = *allocator; |
| 668 | return sz_true_k; |
| 669 | } |
| 670 | |
| 671 | static sz_bool_t sz_py_replace_u32_tape_view_allocator(Strs *strs, sz_memory_allocator_t *allocator) { |
| 672 | // Convert view to tape by copying the data |
no test coverage detected
searching dependent graphs…