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" {...@@ -1192,7 +1192,7 @@ test "bug 9995 fix, large allocs count requested size not backing size" {
1192 // with AtLeast, buffer likely to be larger than requested, especially when shrinking1192 // with AtLeast, buffer likely to be larger than requested, especially when shrinking
1193 var gpa = GeneralPurposeAllocator(.{ .enable_memory_limit = true }){};1193 var gpa = GeneralPurposeAllocator(.{ .enable_memory_limit = true }){};
1194 const allocator = gpa.allocator();1194 const allocator = gpa.allocator();
1195 1195
1196 var buf = try allocator.allocAdvanced(u8, 1, page_size + 1, .at_least);1196 var buf = try allocator.allocAdvanced(u8, 1, page_size + 1, .at_least);
1197 try std.testing.expect(gpa.total_requested_bytes == page_size + 1);1197 try std.testing.expect(gpa.total_requested_bytes == page_size + 1);
1198 buf = try allocator.reallocAtLeast(buf, 1);1198 buf = try allocator.reallocAtLeast(buf, 1);
src/tracy.zig+6-6
...@@ -109,11 +109,14 @@ pub fn tracyAllocator(allocator: std.mem.Allocator) TracyAllocator(null) {...@@ -109,11 +109,14 @@ pub fn tracyAllocator(allocator: std.mem.Allocator) TracyAllocator(null) {
109109
110pub fn TracyAllocator(comptime name: ?[:0]const u8) type {110pub fn TracyAllocator(comptime name: ?[:0]const u8) type {
111 return struct {111 return struct {
112 allocator: std.mem.Allocator,
113 parent_allocator: std.mem.Allocator,112 parent_allocator: std.mem.Allocator,
114113
115 const Self = @This();114 const Self = @This();
116115
116 pub fn allocator(self: *Self) std.mem.Allocator {
117 return std.mem.Allocator.init(self, allocFn, resizeFn);
118 }
119
117 pub fn init(allocator: std.mem.Allocator) Self {120 pub fn init(allocator: std.mem.Allocator) Self {
118 return .{121 return .{
119 .parent_allocator = allocator,122 .parent_allocator = allocator,
...@@ -124,8 +127,7 @@ pub fn TracyAllocator(comptime name: ?[:0]const u8) type {...@@ -124,8 +127,7 @@ pub fn TracyAllocator(comptime name: ?[:0]const u8) type {
124 };127 };
125 }128 }
126129
127 fn allocFn(allocator: std.mem.Allocator, len: usize, ptr_align: u29, len_align: u29, ret_addr: usize) std.mem.Allocator.Error![]u8 {130 fn allocFn(self: *Self, len: usize, ptr_align: u29, len_align: u29, ret_addr: usize) std.mem.Allocator.Error![]u8 {
128 const self = @fieldParentPtr(Self, "allocator", allocator);
129 const result = self.parent_allocator.allocFn(self.parent_allocator, len, ptr_align, len_align, ret_addr);131 const result = self.parent_allocator.allocFn(self.parent_allocator, len, ptr_align, len_align, ret_addr);
130 if (result) |data| {132 if (result) |data| {
131 if (data.len != 0) {133 if (data.len != 0) {
...@@ -141,9 +143,7 @@ pub fn TracyAllocator(comptime name: ?[:0]const u8) type {...@@ -141,9 +143,7 @@ pub fn TracyAllocator(comptime name: ?[:0]const u8) type {
141 return result;143 return result;
142 }144 }
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 {146 fn resizeFn(self: *Self, 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
147 if (self.parent_allocator.resizeFn(self.parent_allocator, buf, buf_align, new_len, len_align, ret_addr)) |resized_len| {147 if (self.parent_allocator.resizeFn(self.parent_allocator, buf, buf_align, new_len, len_align, ret_addr)) |resized_len| {
148 // this condition is to handle free being called on an empty slice that was never even allocated148 // this condition is to handle free being called on an empty slice that was never even allocated
149 // example case: `std.process.getSelfExeSharedLibPaths` can return `&[_][:0]u8{}`149 // example case: `std.process.getSelfExeSharedLibPaths` can return `&[_][:0]u8{}`