From 4f6eda6c294818b7ca68a6797e208cdaeaefa8fa Mon Sep 17 00:00:00 2001 From: Simon Galli Date: Tue, 25 Mar 2025 13:06:37 +0100 Subject: [PATCH] Upgrade allocator wrapper for zig 0.14.0 --- src/ztracy.zig | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/src/ztracy.zig b/src/ztracy.zig index 63b2081..aa83f66 100644 --- a/src/ztracy.zig +++ b/src/ztracy.zig @@ -568,6 +568,7 @@ const tracy_full = struct { .vtable = &.{ .alloc = alloc, .resize = resize, + .remap = remap, .free = free, }, }; @@ -576,11 +577,11 @@ const tracy_full = struct { fn alloc( ctx: *anyopaque, len: usize, - log2_ptr_align: u8, + alignment: std.mem.Alignment, ra: usize, ) ?[*]u8 { const self: *TracyAllocator = @ptrCast(@alignCast(ctx)); - const result = self.child_allocator.rawAlloc(len, log2_ptr_align, ra); + const result = self.child_allocator.rawAlloc(len, alignment, ra); if (result) |addr| { Alloc(addr, len); } else { @@ -594,12 +595,12 @@ const tracy_full = struct { fn resize( ctx: *anyopaque, buf: []u8, - log2_ptr_align: u8, + alignment: std.mem.Alignment, new_len: usize, ra: usize, ) bool { const self: *TracyAllocator = @ptrCast(@alignCast(ctx)); - const result = self.child_allocator.rawResize(buf, log2_ptr_align, new_len, ra); + const result = self.child_allocator.rawResize(buf, alignment, new_len, ra); if (result) { Free(buf.ptr); Alloc(buf.ptr, new_len); @@ -611,14 +612,34 @@ const tracy_full = struct { return result; } + fn remap( + ctx: *anyopaque, + buf: []u8, + alignment: std.mem.Alignment, + new_len: usize, + ra: usize, + ) ?[*]u8 { + const self: *TracyAllocator = @ptrCast(@alignCast(ctx)); + const result = self.child_allocator.rawRemap(buf, alignment, new_len, ra); + if (result) |data| { + Free(buf.ptr); + Alloc(data, new_len); + } else { + var buffer: [128]u8 = undefined; + const msg = std.fmt.bufPrint(&buffer, "remap failed requesting {d} -> {d}", .{ buf.len, new_len }) catch return result; + Message(msg); + } + return result; + } + fn free( ctx: *anyopaque, buf: []u8, - log2_ptr_align: u8, + alignment: std.mem.Alignment, ra: usize, ) void { const self: *TracyAllocator = @ptrCast(@alignCast(ctx)); - self.child_allocator.rawFree(buf, log2_ptr_align, ra); + self.child_allocator.rawFree(buf, alignment, ra); Free(buf.ptr); } };