| ... | @@ -120,20 +120,21 @@ pub fn TracyAllocator(comptime name: ?[:0]const u8) type { | ... | @@ -120,20 +120,21 @@ pub fn TracyAllocator(comptime name: ?[:0]const u8) type { |
| 120 | .vtable = &.{ | 120 | .vtable = &.{ |
| 121 | .alloc = allocFn, | 121 | .alloc = allocFn, |
| 122 | .resize = resizeFn, | 122 | .resize = resizeFn, |
| | 123 | .remap = remapFn, |
| 123 | .free = freeFn, | 124 | .free = freeFn, |
| 124 | }, | 125 | }, |
| 125 | }; | 126 | }; |
| 126 | } | 127 | } |
| 127 | | 128 | |
| 128 | fn allocFn(ptr: *anyopaque, len: usize, ptr_align: u8, ret_addr: usize) ?[*]u8 { | 129 | fn allocFn(ptr: *anyopaque, len: usize, alignment: std.mem.Alignment, ret_addr: usize) ?[*]u8 { |
| 129 | const self: *Self = @ptrCast(@alignCast(ptr)); | 130 | const self: *Self = @ptrCast(@alignCast(ptr)); |
| 130 | const result = self.parent_allocator.rawAlloc(len, ptr_align, ret_addr); | 131 | const result = self.parent_allocator.rawAlloc(len, alignment, ret_addr); |
| 131 | if (result) |data| { | 132 | if (result) |memory| { |
| 132 | if (len != 0) { | 133 | if (len != 0) { |
| 133 | if (name) |n| { | 134 | if (name) |n| { |
| 134 | allocNamed(data, len, n); | 135 | allocNamed(memory, len, n); |
| 135 | } else { | 136 | } else { |
| 136 | alloc(data, len); | 137 | alloc(memory, len); |
| 137 | } | 138 | } |
| 138 | } | 139 | } |
| 139 | } else { | 140 | } else { |
| ... | @@ -142,15 +143,15 @@ pub fn TracyAllocator(comptime name: ?[:0]const u8) type { | ... | @@ -142,15 +143,15 @@ pub fn TracyAllocator(comptime name: ?[:0]const u8) type { |
| 142 | return result; | 143 | return result; |
| 143 | } | 144 | } |
| 144 | | 145 | |
| 145 | fn resizeFn(ptr: *anyopaque, buf: []u8, buf_align: u8, new_len: usize, ret_addr: usize) bool { | 146 | fn resizeFn(ptr: *anyopaque, memory: []u8, alignment: std.mem.Alignment, new_len: usize, ret_addr: usize) bool { |
| 146 | const self: *Self = @ptrCast(@alignCast(ptr)); | 147 | const self: *Self = @ptrCast(@alignCast(ptr)); |
| 147 | if (self.parent_allocator.rawResize(buf, buf_align, new_len, ret_addr)) { | 148 | if (self.parent_allocator.rawResize(memory, alignment, new_len, ret_addr)) { |
| 148 | if (name) |n| { | 149 | if (name) |n| { |
| 149 | freeNamed(buf.ptr, n); | 150 | freeNamed(memory.ptr, n); |
| 150 | allocNamed(buf.ptr, new_len, n); | 151 | allocNamed(memory.ptr, new_len, n); |
| 151 | } else { | 152 | } else { |
| 152 | free(buf.ptr); | 153 | free(memory.ptr); |
| 153 | alloc(buf.ptr, new_len); | 154 | alloc(memory.ptr, new_len); |
| 154 | } | 155 | } |
| 155 | | 156 | |
| 156 | return true; | 157 | return true; |
| ... | @@ -161,16 +162,33 @@ pub fn TracyAllocator(comptime name: ?[:0]const u8) type { | ... | @@ -161,16 +162,33 @@ pub fn TracyAllocator(comptime name: ?[:0]const u8) type { |
| 161 | return false; | 162 | return false; |
| 162 | } | 163 | } |
| 163 | | 164 | |
| 164 | fn freeFn(ptr: *anyopaque, buf: []u8, buf_align: u8, ret_addr: usize) void { | 165 | fn remapFn(ptr: *anyopaque, memory: []u8, alignment: std.mem.Alignment, new_len: usize, ret_addr: usize) ?[*]u8 { |
| 165 | const self: *Self = @ptrCast(@alignCast(ptr)); | 166 | const self: *Self = @ptrCast(@alignCast(ptr)); |
| 166 | self.parent_allocator.rawFree(buf, buf_align, ret_addr); | 167 | if (self.parent_allocator.rawRemap(memory, alignment, new_len, ret_addr)) |new_memory| { |
| | 168 | if (name) |n| { |
| | 169 | freeNamed(memory.ptr, n); |
| | 170 | allocNamed(new_memory, new_len, n); |
| | 171 | } else { |
| | 172 | free(memory.ptr); |
| | 173 | alloc(new_memory, new_len); |
| | 174 | } |
| | 175 | return new_memory; |
| | 176 | } else { |
| | 177 | messageColor("reallocation failed", 0xFF0000); |
| | 178 | return null; |
| | 179 | } |
| | 180 | } |
| | 181 | |
| | 182 | fn freeFn(ptr: *anyopaque, memory: []u8, alignment: std.mem.Alignment, ret_addr: usize) void { |
| | 183 | const self: *Self = @ptrCast(@alignCast(ptr)); |
| | 184 | self.parent_allocator.rawFree(memory, alignment, ret_addr); |
| 167 | // this condition is to handle free being called on an empty slice that was never even allocated | 185 | // this condition is to handle free being called on an empty slice that was never even allocated |
| 168 | // example case: `std.process.getSelfExeSharedLibPaths` can return `&[_][:0]u8{}` | 186 | // example case: `std.process.getSelfExeSharedLibPaths` can return `&[_][:0]u8{}` |
| 169 | if (buf.len != 0) { | 187 | if (memory.len != 0) { |
| 170 | if (name) |n| { | 188 | if (name) |n| { |
| 171 | freeNamed(buf.ptr, n); | 189 | freeNamed(memory.ptr, n); |
| 172 | } else { | 190 | } else { |
| 173 | free(buf.ptr); | 191 | free(memory.ptr); |
| 174 | } | 192 | } |
| 175 | } | 193 | } |
| 176 | } | 194 | } |