authorgravatar for leecannon@leecannon.xyzLee Cannon <leecannon@leecannon.xyz> 2021-11-03 12:49:31+00:00
committergravatar for leecannon@leecannon.xyzLee Cannon <leecannon@leecannon.xyz> 2021-11-30 23:32:48+00:00
log23866b1f81010277b204d6f3f5db23d020a76400
treeeee92d2b958fdc32c59bf6f2fd5129008c07a2f1
parent02e5e0ba1fec38a3f8ed20e24219966f944a4ec2
signaturelock-open Commit is signed but in an unrecognized format.

allocgate: update code to use new interface


2 files changed, 7 insertions(+), 7 deletions(-)

lib/std/heap/general_purpose_allocator.zig+1-1
......@@ -1192,7 +1192,7 @@ test "bug 9995 fix, large allocs count requested size not backing size" {
11921192 // with AtLeast, buffer likely to be larger than requested, especially when shrinking
11931193 var gpa = GeneralPurposeAllocator(.{ .enable_memory_limit = true }){};
11941194 const allocator = gpa.allocator();
1195
1195
11961196 var buf = try allocator.allocAdvanced(u8, 1, page_size + 1, .at_least);
11971197 try std.testing.expect(gpa.total_requested_bytes == page_size + 1);
11981198 buf = try allocator.reallocAtLeast(buf, 1);
src/tracy.zig+6-6
......@@ -109,11 +109,14 @@ pub fn tracyAllocator(allocator: std.mem.Allocator) TracyAllocator(null) {
109109
110110pub fn TracyAllocator(comptime name: ?[:0]const u8) type {
111111 return struct {
112 allocator: std.mem.Allocator,
113112 parent_allocator: std.mem.Allocator,
114113
115114 const Self = @This();
116115
116 pub fn allocator(self: *Self) std.mem.Allocator {
117 return std.mem.Allocator.init(self, allocFn, resizeFn);
118 }
119
117120 pub fn init(allocator: std.mem.Allocator) Self {
118121 return .{
119122 .parent_allocator = allocator,
......@@ -124,8 +127,7 @@ pub fn TracyAllocator(comptime name: ?[:0]const u8) type {
124127 };
125128 }
126129
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 {
129131 const result = self.parent_allocator.allocFn(self.parent_allocator, len, ptr_align, len_align, ret_addr);
130132 if (result) |data| {
131133 if (data.len != 0) {
......@@ -141,9 +143,7 @@ pub fn TracyAllocator(comptime name: ?[:0]const u8) type {
141143 return result;
142144 }
143145
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 {
147147 if (self.parent_allocator.resizeFn(self.parent_allocator, buf, buf_align, new_len, len_align, ret_addr)) |resized_len| {
148148 // this condition is to handle free being called on an empty slice that was never even allocated
149149 // example case: `std.process.getSelfExeSharedLibPaths` can return `&[_][:0]u8{}`