From d526a2cf95d62bd1787833b411209565d4ed119e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hampus=20Fr=C3=B6jdholm?= Date: Mon, 20 May 2024 18:29:02 +0200 Subject: [PATCH] gpa: Add never_unmap and retain_metadata test --- lib/std/heap/general_purpose_allocator.zig | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/lib/std/heap/general_purpose_allocator.zig b/lib/std/heap/general_purpose_allocator.zig index add7aeb1b875..61e256d29097 100644 --- a/lib/std/heap/general_purpose_allocator.zig +++ b/lib/std/heap/general_purpose_allocator.zig @@ -1458,3 +1458,19 @@ test "bug 9995 fix, large allocs count requested size not backing size" { buf = try allocator.realloc(buf, 2); try std.testing.expect(gpa.total_requested_bytes == 2); } + +test "retain metadata and never unmap" { + var gpa = std.heap.GeneralPurposeAllocator(.{ + .safety = true, + .never_unmap = true, + .retain_metadata = true, + }){}; + defer std.debug.assert(gpa.deinit() == .ok); + const allocator = gpa.allocator(); + + const alloc = try allocator.alloc(u8, 8); + allocator.free(alloc); + + const alloc2 = try allocator.alloc(u8, 8); + allocator.free(alloc2); +}