authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-02-05 16:39:14-08:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-02-06 14:23:23-08:00
logf82ec3f02af68ca25870f8ae3861a416225af554
treeb6242f1437470a2a263f1ed2311283c15ce74fb9
parent8282565ce524c14e62e8c30e1feb8afc5c2ab961

std.testing.allocator: different canary + enable resize traces

Accept a slight performance degradation when unit testing for better debuggability when a leak or double-free is detected.

1 files changed, 5 insertions(+), 0 deletions(-)

lib/std/testing.zig+5
...@@ -18,6 +18,11 @@ var base_allocator_instance = std.heap.FixedBufferAllocator.init("");...@@ -18,6 +18,11 @@ var base_allocator_instance = std.heap.FixedBufferAllocator.init("");
18pub const allocator = allocator_instance.allocator();18pub const allocator = allocator_instance.allocator();
19pub var allocator_instance: std.heap.GeneralPurposeAllocator(.{19pub var allocator_instance: std.heap.GeneralPurposeAllocator(.{
20 .stack_trace_frames = 10,20 .stack_trace_frames = 10,
21 .resize_stack_traces = true,
22 // A unique value so that when a default-constructed
23 // GeneralPurposeAllocator is incorrectly passed to testing allocator, or
24 // vice versa, panic occurs.
25 .canary = @truncate(0x2731e675c3a701ba),
21}) = b: {26}) = b: {
22 if (!builtin.is_test) @compileError("testing allocator used when not testing");27 if (!builtin.is_test) @compileError("testing allocator used when not testing");
23 break :b .init;28 break :b .init;