authorgravatar for justus@klausecker.deJustus Klausecker <justus@klausecker.de> 2026-03-06 13:05:06+01:00
committergravatar for justus@klausecker.deJustus Klausecker <justus@klausecker.de> 2026-03-06 13:08:37+01:00
log76498686639d01050eb917b016a61c58503510e5
tree7c84cde05a222ac8cd3e20700a0a11d02f70189e
parent2ba8c94df6b9e60d73c35bf3d1f80f143fc80cab

std.heap.ArenaAllocator/std.heap.FixedBufferAllocator: make shrinking always succeed

Shrinking allocations should always succeed with these allocators, even if the allocation in question is the most recent one and `resize` didn't manage to decrement the end index of its buffer successfully.

2 files changed, 4 insertions(+), 2 deletions(-)

lib/std/heap/ArenaAllocator.zig+2-1
...@@ -572,7 +572,8 @@ fn resize(ctx: *anyopaque, memory: []u8, alignment: Alignment, new_len: usize, r...@@ -572,7 +572,8 @@ fn resize(ctx: *anyopaque, memory: []u8, alignment: Alignment, new_len: usize, r
572 new_end_index,572 new_end_index,
573 .monotonic,573 .monotonic,
574 .monotonic,574 .monotonic,
575 );575 ) or
576 new_len <= memory.len; // Shrinking allocations should always succeed.
576}577}
577578
578fn remap(ctx: *anyopaque, memory: []u8, alignment: Alignment, new_len: usize, ret_addr: usize) ?[*]u8 {579fn remap(ctx: *anyopaque, memory: []u8, alignment: Alignment, new_len: usize, ret_addr: usize) ?[*]u8 {
lib/std/heap/FixedBufferAllocator.zig+2-1
...@@ -172,7 +172,8 @@ fn threadSafeResize(ctx: *anyopaque, memory: []u8, alignment: mem.Alignment, new...@@ -172,7 +172,8 @@ fn threadSafeResize(ctx: *anyopaque, memory: []u8, alignment: mem.Alignment, new
172 new_end_index,172 new_end_index,
173 .monotonic,173 .monotonic,
174 .monotonic,174 .monotonic,
175 );175 ) or
176 new_len <= memory.len; // Shrinking allocations should always succeed.
176}177}
177178
178fn threadSafeRemap(ctx: *anyopaque, memory: []u8, alignment: mem.Alignment, new_len: usize, ret_addr: usize) ?[*]u8 {179fn threadSafeRemap(ctx: *anyopaque, memory: []u8, alignment: mem.Alignment, new_len: usize, ret_addr: usize) ?[*]u8 {