| ... | @@ -555,7 +555,7 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type { | ... | @@ -555,7 +555,7 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type { |
| 555 | | 555 | |
| 556 | // Do memory limit accounting with requested sizes rather than what backing_allocator returns | 556 | // Do memory limit accounting with requested sizes rather than what backing_allocator returns |
| 557 | // because if we want to return error.OutOfMemory, we have to leave allocation untouched, and | 557 | // because if we want to return error.OutOfMemory, we have to leave allocation untouched, and |
| 558 | // that is impossible to guarantee after calling backing_allocator.resizeFn. | 558 | // that is impossible to guarantee after calling backing_allocator.vtable.resize. |
| 559 | const prev_req_bytes = self.total_requested_bytes; | 559 | const prev_req_bytes = self.total_requested_bytes; |
| 560 | if (config.enable_memory_limit) { | 560 | if (config.enable_memory_limit) { |
| 561 | const new_req_bytes = prev_req_bytes + new_size - entry.value_ptr.requested_size; | 561 | const new_req_bytes = prev_req_bytes + new_size - entry.value_ptr.requested_size; |
| ... | @@ -571,7 +571,7 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type { | ... | @@ -571,7 +571,7 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type { |
| 571 | const result_len = if (config.never_unmap and new_size == 0) | 571 | const result_len = if (config.never_unmap and new_size == 0) |
| 572 | 0 | 572 | 0 |
| 573 | else | 573 | else |
| 574 | try self.backing_allocator.resizeFn(self.backing_allocator.ptr, old_mem, old_align, new_size, len_align, ret_addr); | 574 | try self.backing_allocator.vtable.resize(self.backing_allocator.ptr, old_mem, old_align, new_size, len_align, ret_addr); |
| 575 | | 575 | |
| 576 | if (config.enable_memory_limit) { | 576 | if (config.enable_memory_limit) { |
| 577 | entry.value_ptr.requested_size = new_size; | 577 | entry.value_ptr.requested_size = new_size; |
| ... | @@ -764,7 +764,7 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type { | ... | @@ -764,7 +764,7 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type { |
| 764 | const new_aligned_size = math.max(len, ptr_align); | 764 | const new_aligned_size = math.max(len, ptr_align); |
| 765 | if (new_aligned_size > largest_bucket_object_size) { | 765 | if (new_aligned_size > largest_bucket_object_size) { |
| 766 | try self.large_allocations.ensureUnusedCapacity(self.backing_allocator, 1); | 766 | try self.large_allocations.ensureUnusedCapacity(self.backing_allocator, 1); |
| 767 | const slice = try self.backing_allocator.allocFn(self.backing_allocator.ptr, len, ptr_align, len_align, ret_addr); | 767 | const slice = try self.backing_allocator.vtable.alloc(self.backing_allocator.ptr, len, ptr_align, len_align, ret_addr); |
| 768 | | 768 | |
| 769 | const gop = self.large_allocations.getOrPutAssumeCapacity(@ptrToInt(slice.ptr)); | 769 | const gop = self.large_allocations.getOrPutAssumeCapacity(@ptrToInt(slice.ptr)); |
| 770 | if (config.retain_metadata and !config.never_unmap) { | 770 | if (config.retain_metadata and !config.never_unmap) { |
| ... | @@ -1191,10 +1191,12 @@ test "double frees" { | ... | @@ -1191,10 +1191,12 @@ test "double frees" { |
| 1191 | test "bug 9995 fix, large allocs count requested size not backing size" { | 1191 | test "bug 9995 fix, large allocs count requested size not backing size" { |
| 1192 | // with AtLeast, buffer likely to be larger than requested, especially when shrinking | 1192 | // with AtLeast, buffer likely to be larger than requested, especially when shrinking |
| 1193 | var gpa = GeneralPurposeAllocator(.{ .enable_memory_limit = true }){}; | 1193 | var gpa = GeneralPurposeAllocator(.{ .enable_memory_limit = true }){}; |
| 1194 | var buf = try gpa.allocator.allocAdvanced(u8, 1, page_size + 1, .at_least); | 1194 | const allocator = gpa.allocator(); |
| | 1195 | |
| | 1196 | var buf = try allocator.allocAdvanced(u8, 1, page_size + 1, .at_least); |
| 1195 | try std.testing.expect(gpa.total_requested_bytes == page_size + 1); | 1197 | try std.testing.expect(gpa.total_requested_bytes == page_size + 1); |
| 1196 | buf = try gpa.allocator.reallocAtLeast(buf, 1); | 1198 | buf = try allocator.reallocAtLeast(buf, 1); |
| 1197 | try std.testing.expect(gpa.total_requested_bytes == 1); | 1199 | try std.testing.expect(gpa.total_requested_bytes == 1); |
| 1198 | buf = try gpa.allocator.reallocAtLeast(buf, 2); | 1200 | buf = try allocator.reallocAtLeast(buf, 2); |
| 1199 | try std.testing.expect(gpa.total_requested_bytes == 2); | 1201 | try std.testing.expect(gpa.total_requested_bytes == 2); |
| 1200 | } | 1202 | } |