| ... | ... | @@ -109,11 +109,14 @@ pub fn tracyAllocator(allocator: std.mem.Allocator) TracyAllocator(null) { |
| 109 | 109 | |
| 110 | 110 | pub fn TracyAllocator(comptime name: ?[:0]const u8) type { |
| 111 | 111 | return struct { |
| 112 | | allocator: std.mem.Allocator, |
| 113 | 112 | parent_allocator: std.mem.Allocator, |
| 114 | 113 | |
| 115 | 114 | const Self = @This(); |
| 116 | 115 | |
| 116 | pub fn allocator(self: *Self) std.mem.Allocator { |
| 117 | return std.mem.Allocator.init(self, allocFn, resizeFn); |
| 118 | } |
| 119 | |
| 117 | 120 | pub fn init(allocator: std.mem.Allocator) Self { |
| 118 | 121 | return .{ |
| 119 | 122 | .parent_allocator = allocator, |
| ... | ... | @@ -124,8 +127,7 @@ pub fn TracyAllocator(comptime name: ?[:0]const u8) type { |
| 124 | 127 | }; |
| 125 | 128 | } |
| 126 | 129 | |
| 127 | | fn allocFn(allocator: std.mem.Allocator, len: usize, ptr_align: u29, len_align: u29, ret_addr: usize) std.mem.Allocator.Error![]u8 { |
| 128 | | const self = @fieldParentPtr(Self, "allocator", allocator); |
| 130 | fn allocFn(self: *Self, len: usize, ptr_align: u29, len_align: u29, ret_addr: usize) std.mem.Allocator.Error![]u8 { |
| 129 | 131 | const result = self.parent_allocator.allocFn(self.parent_allocator, len, ptr_align, len_align, ret_addr); |
| 130 | 132 | if (result) |data| { |
| 131 | 133 | if (data.len != 0) { |
| ... | ... | @@ -141,9 +143,7 @@ pub fn TracyAllocator(comptime name: ?[:0]const u8) type { |
| 141 | 143 | return result; |
| 142 | 144 | } |
| 143 | 145 | |
| 144 | | 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 { |
| 145 | | const self = @fieldParentPtr(Self, "allocator", allocator); |
| 146 | | |
| 146 | fn resizeFn(self: *Self, buf: []u8, buf_align: u29, new_len: usize, len_align: u29, ret_addr: usize) std.mem.Allocator.Error!usize { |
| 147 | 147 | if (self.parent_allocator.resizeFn(self.parent_allocator, buf, buf_align, new_len, len_align, ret_addr)) |resized_len| { |
| 148 | 148 | // this condition is to handle free being called on an empty slice that was never even allocated |
| 149 | 149 | // example case: `std.process.getSelfExeSharedLibPaths` can return `&[_][:0]u8{}` |