diff options
| author | Lee Cannon <leecannon@leecannon.xyz> | 2021-11-03 12:49:31 +0000 |
|---|---|---|
| committer | Lee Cannon <leecannon@leecannon.xyz> | 2021-11-30 23:32:48 +0000 |
| commit | 23866b1f81010277b204d6f3f5db23d020a76400 (patch) | |
| tree | eee92d2b958fdc32c59bf6f2fd5129008c07a2f1 /src | |
| parent | 02e5e0ba1fec38a3f8ed20e24219966f944a4ec2 (diff) | |
| download | zig-23866b1f81010277b204d6f3f5db23d020a76400.tar.gz zig-23866b1f81010277b204d6f3f5db23d020a76400.zip | |
allocgate: update code to use new interface
Diffstat (limited to 'src')
| -rw-r--r-- | src/tracy.zig | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/src/tracy.zig b/src/tracy.zig index 8abd78110f..83e31e5764 100644 --- a/src/tracy.zig +++ b/src/tracy.zig @@ -109,11 +109,14 @@ pub fn tracyAllocator(allocator: std.mem.Allocator) TracyAllocator(null) { pub fn TracyAllocator(comptime name: ?[:0]const u8) type { return struct { - allocator: std.mem.Allocator, parent_allocator: std.mem.Allocator, const Self = @This(); + pub fn allocator(self: *Self) std.mem.Allocator { + return std.mem.Allocator.init(self, allocFn, resizeFn); + } + pub fn init(allocator: std.mem.Allocator) Self { return .{ .parent_allocator = allocator, @@ -124,8 +127,7 @@ pub fn TracyAllocator(comptime name: ?[:0]const u8) type { }; } - fn allocFn(allocator: std.mem.Allocator, len: usize, ptr_align: u29, len_align: u29, ret_addr: usize) std.mem.Allocator.Error![]u8 { - const self = @fieldParentPtr(Self, "allocator", allocator); + fn allocFn(self: *Self, len: usize, ptr_align: u29, len_align: u29, ret_addr: usize) std.mem.Allocator.Error![]u8 { const result = self.parent_allocator.allocFn(self.parent_allocator, len, ptr_align, len_align, ret_addr); if (result) |data| { if (data.len != 0) { @@ -141,9 +143,7 @@ pub fn TracyAllocator(comptime name: ?[:0]const u8) type { return result; } - fn resizeFn(allocator: std.mem.Allocator, buf: []u8, buf_align: u29, new_len: usize, len_align: u29, ret_addr: usize) std.mem.Allocator.Error!usize { - const self = @fieldParentPtr(Self, "allocator", allocator); - + fn resizeFn(self: *Self, buf: []u8, buf_align: u29, new_len: usize, len_align: u29, ret_addr: usize) std.mem.Allocator.Error!usize { if (self.parent_allocator.resizeFn(self.parent_allocator, buf, buf_align, new_len, len_align, ret_addr)) |resized_len| { // this condition is to handle free being called on an empty slice that was never even allocated // example case: `std.process.getSelfExeSharedLibPaths` can return `&[_][:0]u8{}` |
