diff options
author | 2022-02-16 00:36:16 -0800 | |
---|---|---|
committer | 2022-02-16 00:36:16 -0800 | |
commit | 9f2f33e4e6ae2cf8abe9c1de825e2ab7aa31a190 (patch) | |
tree | cb0792cd5f71237bbc3054da38d4958e394fd390 | |
parent | acb743923201f436cef725694116a1cb5ec37f5f (diff) | |
download | bun-9f2f33e4e6ae2cf8abe9c1de825e2ab7aa31a190.tar.gz bun-9f2f33e4e6ae2cf8abe9c1de825e2ab7aa31a190.tar.zst bun-9f2f33e4e6ae2cf8abe9c1de825e2ab7aa31a190.zip |
Update mimalloc_arena.zig
-rw-r--r-- | src/mimalloc_arena.zig | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/src/mimalloc_arena.zig b/src/mimalloc_arena.zig index e2df152fb..e2f7aac60 100644 --- a/src/mimalloc_arena.zig +++ b/src/mimalloc_arena.zig @@ -3,7 +3,7 @@ const builtin = @import("std").builtin; const std = @import("std"); const mimalloc = @import("./allocators/mimalloc.zig"); - +const Environment = @import("./env.zig"); const Allocator = mem.Allocator; const assert = std.debug.assert; @@ -74,7 +74,16 @@ pub const Arena = struct { if (len_align == 0) { return ptr[0..len]; } - return ptr[0..mem.alignBackwardAnyAlign(mimalloc.mi_usable_size(ptr), len_align)]; + + // std.mem.Allocator asserts this, we do it here so we can see the metadata + if (comptime Environment.allow_assert) { + const size = mem.alignBackwardAnyAlign(mimalloc.mi_usable_size(ptr), len_align); + + assert(size >= len); + return ptr[0..size]; + } else { + return ptr[0..mem.alignBackwardAnyAlign(mimalloc.mi_usable_size(ptr), len_align)]; + } } fn resize( |