diff options
| author | Lee Cannon <leecannon@leecannon.xyz> | 2021-11-07 01:40:06 +0000 |
|---|---|---|
| committer | Lee Cannon <leecannon@leecannon.xyz> | 2021-11-30 23:45:01 +0000 |
| commit | 066eaa5e9cbfde172449f6d95bb884c7d86ac10c (patch) | |
| tree | 7829767fd8b421f6a1c58798692f45ebec43746d /src | |
| parent | f68cda738ad0d3e9bc0f328befad301d9e23756e (diff) | |
| download | zig-066eaa5e9cbfde172449f6d95bb884c7d86ac10c.tar.gz zig-066eaa5e9cbfde172449f6d95bb884c7d86ac10c.zip | |
allocgate: change resize to return optional instead of error
Diffstat (limited to 'src')
| -rw-r--r-- | src/link/MachO.zig | 2 | ||||
| -rw-r--r-- | src/link/tapi.zig | 2 | ||||
| -rw-r--r-- | src/main.zig | 2 | ||||
| -rw-r--r-- | src/tracy.zig | 25 |
4 files changed, 13 insertions, 18 deletions
diff --git a/src/link/MachO.zig b/src/link/MachO.zig index db2b8ffc42..fc592ab5e8 100644 --- a/src/link/MachO.zig +++ b/src/link/MachO.zig @@ -1288,7 +1288,7 @@ fn parseDependentLibs(self: *MachO, syslibroot: ?[]const u8, dependent_libs: any // TODO this should not be performed if the user specifies `-flat_namespace` flag. // See ld64 manpages. var arena_alloc = std.heap.ArenaAllocator.init(self.base.allocator); - const arena = &arena_alloc.allocator; + const arena = arena_alloc.allocator(); defer arena_alloc.deinit(); while (dependent_libs.readItem()) |*id| { diff --git a/src/link/tapi.zig b/src/link/tapi.zig index 7a55a5104d..e31ca92ed9 100644 --- a/src/link/tapi.zig +++ b/src/link/tapi.zig @@ -138,7 +138,7 @@ pub const LibStub = struct { err: { log.debug("trying to parse as []TbdV3", .{}); const inner = lib_stub.yaml.parse([]TbdV3) catch break :err; - var out = try lib_stub.yaml.arena.allocator.alloc(Tbd, inner.len); + var out = try lib_stub.yaml.arena.allocator().alloc(Tbd, inner.len); for (inner) |doc, i| { out[i] = .{ .v3 = doc }; } diff --git a/src/main.zig b/src/main.zig index 981a76a364..ad86858240 100644 --- a/src/main.zig +++ b/src/main.zig @@ -159,7 +159,7 @@ pub fn main() anyerror!void { if (tracy.enable_allocation) { var gpa_tracy = tracy.tracyAllocator(gpa); - return mainArgs(&gpa_tracy.allocator, arena, args); + return mainArgs(gpa_tracy.allocator(), arena, args); } return mainArgs(gpa, arena, args); diff --git a/src/tracy.zig b/src/tracy.zig index 064374030f..9a5bcc749b 100644 --- a/src/tracy.zig +++ b/src/tracy.zig @@ -113,20 +113,16 @@ pub fn TracyAllocator(comptime name: ?[:0]const u8) type { 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 { + pub fn init(parent_allocator: std.mem.Allocator) Self { return .{ - .parent_allocator = allocator, - .allocator = .{ - .allocFn = allocFn, - .resizeFn = resizeFn, - }, + .parent_allocator = parent_allocator, }; } + pub fn allocator(self: *Self) std.mem.Allocator { + return std.mem.Allocator.init(self, allocFn, resizeFn, freeFn); + } + 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| { @@ -162,12 +158,11 @@ pub fn TracyAllocator(comptime name: ?[:0]const u8) type { } return resized_len; - } else |err| { - // this is not really an error condition, during normal operation the compiler hits this case thousands of times - // due to this emitting messages for it is both slow and causes clutter - // messageColor("allocation resize failed", 0xFF0000); - return err; } + + // during normal operation the compiler hits this case thousands of times due to this + // emitting messages for it is both slow and causes clutter + return null; } fn freeFn(self: *Self, buf: []u8, buf_align: u29, ret_addr: usize) void { |
