| author | |
| committer | |
| log | 85de022c5671d777f62ddff254a814dab05242fc |
| tree | 037f58c4b07d18b80cf48cf74d0f0e8c8866f8f2 |
| parent | 1e0addcf73ee71d23a41b744995848bcca38e8d3 |
| signature |
148 files changed, 1092 insertions(+), 1095 deletions(-)
ci/srht/update-download-page.zig+1-1| ... | @@ -18,7 +18,7 @@ pub fn main() !void { | ... | @@ -18,7 +18,7 @@ pub fn main() !void { |
| 18 | } | 18 | } |
| 19 | 19 | ||
| 20 | fn render( | 20 | fn render( |
| 21 | allocator: *mem.Allocator, | 21 | allocator: mem.Allocator, |
| 22 | in_file: []const u8, | 22 | in_file: []const u8, |
| 23 | out_file: []const u8, | 23 | out_file: []const u8, |
| 24 | fmt: enum { | 24 | fmt: enum { |
doc/docgen.zig+10-10| ... | @@ -342,7 +342,7 @@ const Action = enum { | ... | @@ -342,7 +342,7 @@ const Action = enum { |
| 342 | Close, | 342 | Close, |
| 343 | }; | 343 | }; |
| 344 | 344 | ||
| 345 | fn genToc(allocator: *Allocator, tokenizer: *Tokenizer) !Toc { | 345 | fn genToc(allocator: Allocator, tokenizer: *Tokenizer) !Toc { |
| 346 | var urls = std.StringHashMap(Token).init(allocator); | 346 | var urls = std.StringHashMap(Token).init(allocator); |
| 347 | errdefer urls.deinit(); | 347 | errdefer urls.deinit(); |
| 348 | 348 | ||
| ... | @@ -708,7 +708,7 @@ fn genToc(allocator: *Allocator, tokenizer: *Tokenizer) !Toc { | ... | @@ -708,7 +708,7 @@ fn genToc(allocator: *Allocator, tokenizer: *Tokenizer) !Toc { |
| 708 | }; | 708 | }; |
| 709 | } | 709 | } |
| 710 | 710 | ||
| 711 | fn urlize(allocator: *Allocator, input: []const u8) ![]u8 { | 711 | fn urlize(allocator: Allocator, input: []const u8) ![]u8 { |
| 712 | var buf = std.ArrayList(u8).init(allocator); | 712 | var buf = std.ArrayList(u8).init(allocator); |
| 713 | defer buf.deinit(); | 713 | defer buf.deinit(); |
| 714 | 714 | ||
| ... | @@ -727,7 +727,7 @@ fn urlize(allocator: *Allocator, input: []const u8) ![]u8 { | ... | @@ -727,7 +727,7 @@ fn urlize(allocator: *Allocator, input: []const u8) ![]u8 { |
| 727 | return buf.toOwnedSlice(); | 727 | return buf.toOwnedSlice(); |
| 728 | } | 728 | } |
| 729 | 729 | ||
| 730 | fn escapeHtml(allocator: *Allocator, input: []const u8) ![]u8 { | 730 | fn escapeHtml(allocator: Allocator, input: []const u8) ![]u8 { |
| 731 | var buf = std.ArrayList(u8).init(allocator); | 731 | var buf = std.ArrayList(u8).init(allocator); |
| 732 | defer buf.deinit(); | 732 | defer buf.deinit(); |
| 733 | 733 | ||
| ... | @@ -773,7 +773,7 @@ test "term color" { | ... | @@ -773,7 +773,7 @@ test "term color" { |
| 773 | try testing.expectEqualSlices(u8, "A<span class=\"t32_1\">green</span>B", result); | 773 | try testing.expectEqualSlices(u8, "A<span class=\"t32_1\">green</span>B", result); |
| 774 | } | 774 | } |
| 775 | 775 | ||
| 776 | fn termColor(allocator: *Allocator, input: []const u8) ![]u8 { | 776 | fn termColor(allocator: Allocator, input: []const u8) ![]u8 { |
| 777 | var buf = std.ArrayList(u8).init(allocator); | 777 | var buf = std.ArrayList(u8).init(allocator); |
| 778 | defer buf.deinit(); | 778 | defer buf.deinit(); |
| 779 | 779 | ||
| ... | @@ -883,7 +883,7 @@ fn writeEscapedLines(out: anytype, text: []const u8) !void { | ... | @@ -883,7 +883,7 @@ fn writeEscapedLines(out: anytype, text: []const u8) !void { |
| 883 | } | 883 | } |
| 884 | 884 | ||
| 885 | fn tokenizeAndPrintRaw( | 885 | fn tokenizeAndPrintRaw( |
| 886 | allocator: *Allocator, | 886 | allocator: Allocator, |
| 887 | docgen_tokenizer: *Tokenizer, | 887 | docgen_tokenizer: *Tokenizer, |
| 888 | out: anytype, | 888 | out: anytype, |
| 889 | source_token: Token, | 889 | source_token: Token, |
| ... | @@ -1137,7 +1137,7 @@ fn tokenizeAndPrintRaw( | ... | @@ -1137,7 +1137,7 @@ fn tokenizeAndPrintRaw( |
| 1137 | } | 1137 | } |
| 1138 | 1138 | ||
| 1139 | fn tokenizeAndPrint( | 1139 | fn tokenizeAndPrint( |
| 1140 | allocator: *Allocator, | 1140 | allocator: Allocator, |
| 1141 | docgen_tokenizer: *Tokenizer, | 1141 | docgen_tokenizer: *Tokenizer, |
| 1142 | out: anytype, | 1142 | out: anytype, |
| 1143 | source_token: Token, | 1143 | source_token: Token, |
| ... | @@ -1146,7 +1146,7 @@ fn tokenizeAndPrint( | ... | @@ -1146,7 +1146,7 @@ fn tokenizeAndPrint( |
| 1146 | return tokenizeAndPrintRaw(allocator, docgen_tokenizer, out, source_token, raw_src); | 1146 | return tokenizeAndPrintRaw(allocator, docgen_tokenizer, out, source_token, raw_src); |
| 1147 | } | 1147 | } |
| 1148 | 1148 | ||
| 1149 | fn printSourceBlock(allocator: *Allocator, docgen_tokenizer: *Tokenizer, out: anytype, syntax_block: SyntaxBlock) !void { | 1149 | fn printSourceBlock(allocator: Allocator, docgen_tokenizer: *Tokenizer, out: anytype, syntax_block: SyntaxBlock) !void { |
| 1150 | const source_type = @tagName(syntax_block.source_type); | 1150 | const source_type = @tagName(syntax_block.source_type); |
| 1151 | 1151 | ||
| 1152 | try out.print("<figure><figcaption class=\"{s}-cap\"><cite class=\"file\">{s}</cite></figcaption><pre>", .{ source_type, syntax_block.name }); | 1152 | try out.print("<figure><figcaption class=\"{s}-cap\"><cite class=\"file\">{s}</cite></figcaption><pre>", .{ source_type, syntax_block.name }); |
| ... | @@ -1188,7 +1188,7 @@ fn printShell(out: anytype, shell_content: []const u8) !void { | ... | @@ -1188,7 +1188,7 @@ fn printShell(out: anytype, shell_content: []const u8) !void { |
| 1188 | } | 1188 | } |
| 1189 | 1189 | ||
| 1190 | fn genHtml( | 1190 | fn genHtml( |
| 1191 | allocator: *Allocator, | 1191 | allocator: Allocator, |
| 1192 | tokenizer: *Tokenizer, | 1192 | tokenizer: *Tokenizer, |
| 1193 | toc: *Toc, | 1193 | toc: *Toc, |
| 1194 | out: anytype, | 1194 | out: anytype, |
| ... | @@ -1687,7 +1687,7 @@ fn genHtml( | ... | @@ -1687,7 +1687,7 @@ fn genHtml( |
| 1687 | } | 1687 | } |
| 1688 | } | 1688 | } |
| 1689 | 1689 | ||
| 1690 | fn exec(allocator: *Allocator, env_map: *std.BufMap, args: []const []const u8) !ChildProcess.ExecResult { | 1690 | fn exec(allocator: Allocator, env_map: *std.BufMap, args: []const []const u8) !ChildProcess.ExecResult { |
| 1691 | const result = try ChildProcess.exec(.{ | 1691 | const result = try ChildProcess.exec(.{ |
| 1692 | .allocator = allocator, | 1692 | .allocator = allocator, |
| 1693 | .argv = args, | 1693 | .argv = args, |
| ... | @@ -1711,7 +1711,7 @@ fn exec(allocator: *Allocator, env_map: *std.BufMap, args: []const []const u8) ! | ... | @@ -1711,7 +1711,7 @@ fn exec(allocator: *Allocator, env_map: *std.BufMap, args: []const []const u8) ! |
| 1711 | return result; | 1711 | return result; |
| 1712 | } | 1712 | } |
| 1713 | 1713 | ||
| 1714 | fn getBuiltinCode(allocator: *Allocator, env_map: *std.BufMap, zig_exe: []const u8) ![]const u8 { | 1714 | fn getBuiltinCode(allocator: Allocator, env_map: *std.BufMap, zig_exe: []const u8) ![]const u8 { |
| 1715 | const result = try exec(allocator, env_map, &[_][]const u8{ zig_exe, "build-obj", "--show-builtin" }); | 1715 | const result = try exec(allocator, env_map, &[_][]const u8{ zig_exe, "build-obj", "--show-builtin" }); |
| 1716 | return result.stdout; | 1716 | return result.stdout; |
| 1717 | } | 1717 | } |
lib/std/Thread.zig+1-1| ... | @@ -460,7 +460,7 @@ const WindowsThreadImpl = struct { | ... | @@ -460,7 +460,7 @@ const WindowsThreadImpl = struct { |
| 460 | errdefer assert(windows.kernel32.HeapFree(heap_handle, 0, alloc_ptr) != 0); | 460 | errdefer assert(windows.kernel32.HeapFree(heap_handle, 0, alloc_ptr) != 0); |
| 461 | 461 | ||
| 462 | const instance_bytes = @ptrCast([*]u8, alloc_ptr)[0..alloc_bytes]; | 462 | const instance_bytes = @ptrCast([*]u8, alloc_ptr)[0..alloc_bytes]; |
| 463 | const instance = std.heap.FixedBufferAllocator.init(instance_bytes).allocator.create(Instance) catch unreachable; | 463 | const instance = std.heap.FixedBufferAllocator.init(instance_bytes).getAllocator().create(Instance) catch unreachable; |
| 464 | instance.* = .{ | 464 | instance.* = .{ |
| 465 | .fn_args = args, | 465 | .fn_args = args, |
| 466 | .thread = .{ | 466 | .thread = .{ |
lib/std/array_hash_map.zig+33-33| ... | @@ -79,7 +79,7 @@ pub fn ArrayHashMap( | ... | @@ -79,7 +79,7 @@ pub fn ArrayHashMap( |
| 79 | comptime std.hash_map.verifyContext(Context, K, K, u32); | 79 | comptime std.hash_map.verifyContext(Context, K, K, u32); |
| 80 | return struct { | 80 | return struct { |
| 81 | unmanaged: Unmanaged, | 81 | unmanaged: Unmanaged, |
| 82 | allocator: *Allocator, | 82 | allocator: Allocator, |
| 83 | ctx: Context, | 83 | ctx: Context, |
| 84 | 84 | ||
| 85 | /// The ArrayHashMapUnmanaged type using the same settings as this managed map. | 85 | /// The ArrayHashMapUnmanaged type using the same settings as this managed map. |
| ... | @@ -118,12 +118,12 @@ pub fn ArrayHashMap( | ... | @@ -118,12 +118,12 @@ pub fn ArrayHashMap( |
| 118 | const Self = @This(); | 118 | const Self = @This(); |
| 119 | 119 | ||
| 120 | /// Create an ArrayHashMap instance which will use a specified allocator. | 120 | /// Create an ArrayHashMap instance which will use a specified allocator. |
| 121 | pub fn init(allocator: *Allocator) Self { | 121 | pub fn init(allocator: Allocator) Self { |
| 122 | if (@sizeOf(Context) != 0) | 122 | if (@sizeOf(Context) != 0) |
| 123 | @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call initContext instead."); | 123 | @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call initContext instead."); |
| 124 | return initContext(allocator, undefined); | 124 | return initContext(allocator, undefined); |
| 125 | } | 125 | } |
| 126 | pub fn initContext(allocator: *Allocator, ctx: Context) Self { | 126 | pub fn initContext(allocator: Allocator, ctx: Context) Self { |
| 127 | return .{ | 127 | return .{ |
| 128 | .unmanaged = .{}, | 128 | .unmanaged = .{}, |
| 129 | .allocator = allocator, | 129 | .allocator = allocator, |
| ... | @@ -383,7 +383,7 @@ pub fn ArrayHashMap( | ... | @@ -383,7 +383,7 @@ pub fn ArrayHashMap( |
| 383 | /// Create a copy of the hash map which can be modified separately. | 383 | /// Create a copy of the hash map which can be modified separately. |
| 384 | /// The copy uses the same context as this instance, but the specified | 384 | /// The copy uses the same context as this instance, but the specified |
| 385 | /// allocator. | 385 | /// allocator. |
| 386 | pub fn cloneWithAllocator(self: Self, allocator: *Allocator) !Self { | 386 | pub fn cloneWithAllocator(self: Self, allocator: Allocator) !Self { |
| 387 | var other = try self.unmanaged.cloneContext(allocator, self.ctx); | 387 | var other = try self.unmanaged.cloneContext(allocator, self.ctx); |
| 388 | return other.promoteContext(allocator, self.ctx); | 388 | return other.promoteContext(allocator, self.ctx); |
| 389 | } | 389 | } |
| ... | @@ -396,7 +396,7 @@ pub fn ArrayHashMap( | ... | @@ -396,7 +396,7 @@ pub fn ArrayHashMap( |
| 396 | } | 396 | } |
| 397 | /// Create a copy of the hash map which can be modified separately. | 397 | /// Create a copy of the hash map which can be modified separately. |
| 398 | /// The copy uses the specified allocator and context. | 398 | /// The copy uses the specified allocator and context. |
| 399 | pub fn cloneWithAllocatorAndContext(self: Self, allocator: *Allocator, ctx: anytype) !ArrayHashMap(K, V, @TypeOf(ctx), store_hash) { | 399 | pub fn cloneWithAllocatorAndContext(self: Self, allocator: Allocator, ctx: anytype) !ArrayHashMap(K, V, @TypeOf(ctx), store_hash) { |
| 400 | var other = try self.unmanaged.cloneContext(allocator, ctx); | 400 | var other = try self.unmanaged.cloneContext(allocator, ctx); |
| 401 | return other.promoteContext(allocator, ctx); | 401 | return other.promoteContext(allocator, ctx); |
| 402 | } | 402 | } |
| ... | @@ -533,12 +533,12 @@ pub fn ArrayHashMapUnmanaged( | ... | @@ -533,12 +533,12 @@ pub fn ArrayHashMapUnmanaged( |
| 533 | 533 | ||
| 534 | /// Convert from an unmanaged map to a managed map. After calling this, | 534 | /// Convert from an unmanaged map to a managed map. After calling this, |
| 535 | /// the promoted map should no longer be used. | 535 | /// the promoted map should no longer be used. |
| 536 | pub fn promote(self: Self, allocator: *Allocator) Managed { | 536 | pub fn promote(self: Self, allocator: Allocator) Managed { |
| 537 | if (@sizeOf(Context) != 0) | 537 | if (@sizeOf(Context) != 0) |
| 538 | @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call promoteContext instead."); | 538 | @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call promoteContext instead."); |
| 539 | return self.promoteContext(allocator, undefined); | 539 | return self.promoteContext(allocator, undefined); |
| 540 | } | 540 | } |
| 541 | pub fn promoteContext(self: Self, allocator: *Allocator, ctx: Context) Managed { | 541 | pub fn promoteContext(self: Self, allocator: Allocator, ctx: Context) Managed { |
| 542 | return .{ | 542 | return .{ |
| 543 | .unmanaged = self, | 543 | .unmanaged = self, |
| 544 | .allocator = allocator, | 544 | .allocator = allocator, |
| ... | @@ -549,7 +549,7 @@ pub fn ArrayHashMapUnmanaged( | ... | @@ -549,7 +549,7 @@ pub fn ArrayHashMapUnmanaged( |
| 549 | /// Frees the backing allocation and leaves the map in an undefined state. | 549 | /// Frees the backing allocation and leaves the map in an undefined state. |
| 550 | /// Note that this does not free keys or values. You must take care of that | 550 | /// Note that this does not free keys or values. You must take care of that |
| 551 | /// before calling this function, if it is needed. | 551 | /// before calling this function, if it is needed. |
| 552 | pub fn deinit(self: *Self, allocator: *Allocator) void { | 552 | pub fn deinit(self: *Self, allocator: Allocator) void { |
| 553 | self.entries.deinit(allocator); | 553 | self.entries.deinit(allocator); |
| 554 | if (self.index_header) |header| { | 554 | if (self.index_header) |header| { |
| 555 | header.free(allocator); | 555 | header.free(allocator); |
| ... | @@ -570,7 +570,7 @@ pub fn ArrayHashMapUnmanaged( | ... | @@ -570,7 +570,7 @@ pub fn ArrayHashMapUnmanaged( |
| 570 | } | 570 | } |
| 571 | 571 | ||
| 572 | /// Clears the map and releases the backing allocation | 572 | /// Clears the map and releases the backing allocation |
| 573 | pub fn clearAndFree(self: *Self, allocator: *Allocator) void { | 573 | pub fn clearAndFree(self: *Self, allocator: Allocator) void { |
| 574 | self.entries.shrinkAndFree(allocator, 0); | 574 | self.entries.shrinkAndFree(allocator, 0); |
| 575 | if (self.index_header) |header| { | 575 | if (self.index_header) |header| { |
| 576 | header.free(allocator); | 576 | header.free(allocator); |
| ... | @@ -633,24 +633,24 @@ pub fn ArrayHashMapUnmanaged( | ... | @@ -633,24 +633,24 @@ pub fn ArrayHashMapUnmanaged( |
| 633 | /// Otherwise, puts a new item with undefined value, and | 633 | /// Otherwise, puts a new item with undefined value, and |
| 634 | /// the `Entry` pointer points to it. Caller should then initialize | 634 | /// the `Entry` pointer points to it. Caller should then initialize |
| 635 | /// the value (but not the key). | 635 | /// the value (but not the key). |
| 636 | pub fn getOrPut(self: *Self, allocator: *Allocator, key: K) !GetOrPutResult { | 636 | pub fn getOrPut(self: *Self, allocator: Allocator, key: K) !GetOrPutResult { |
| 637 | if (@sizeOf(Context) != 0) | 637 | if (@sizeOf(Context) != 0) |
| 638 | @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call getOrPutContext instead."); | 638 | @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call getOrPutContext instead."); |
| 639 | return self.getOrPutContext(allocator, key, undefined); | 639 | return self.getOrPutContext(allocator, key, undefined); |
| 640 | } | 640 | } |
| 641 | pub fn getOrPutContext(self: *Self, allocator: *Allocator, key: K, ctx: Context) !GetOrPutResult { | 641 | pub fn getOrPutContext(self: *Self, allocator: Allocator, key: K, ctx: Context) !GetOrPutResult { |
| 642 | const gop = try self.getOrPutContextAdapted(allocator, key, ctx, ctx); | 642 | const gop = try self.getOrPutContextAdapted(allocator, key, ctx, ctx); |
| 643 | if (!gop.found_existing) { | 643 | if (!gop.found_existing) { |
| 644 | gop.key_ptr.* = key; | 644 | gop.key_ptr.* = key; |
| 645 | } | 645 | } |
| 646 | return gop; | 646 | return gop; |
| 647 | } | 647 | } |
| 648 | pub fn getOrPutAdapted(self: *Self, allocator: *Allocator, key: anytype, key_ctx: anytype) !GetOrPutResult { | 648 | pub fn getOrPutAdapted(self: *Self, allocator: Allocator, key: anytype, key_ctx: anytype) !GetOrPutResult { |
| 649 | if (@sizeOf(Context) != 0) | 649 | if (@sizeOf(Context) != 0) |
| 650 | @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call getOrPutContextAdapted instead."); | 650 | @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call getOrPutContextAdapted instead."); |
| 651 | return self.getOrPutContextAdapted(allocator, key, key_ctx, undefined); | 651 | return self.getOrPutContextAdapted(allocator, key, key_ctx, undefined); |
| 652 | } | 652 | } |
| 653 | pub fn getOrPutContextAdapted(self: *Self, allocator: *Allocator, key: anytype, key_ctx: anytype, ctx: Context) !GetOrPutResult { | 653 | pub fn getOrPutContextAdapted(self: *Self, allocator: Allocator, key: anytype, key_ctx: anytype, ctx: Context) !GetOrPutResult { |
| 654 | self.ensureTotalCapacityContext(allocator, self.entries.len + 1, ctx) catch |err| { | 654 | self.ensureTotalCapacityContext(allocator, self.entries.len + 1, ctx) catch |err| { |
| 655 | // "If key exists this function cannot fail." | 655 | // "If key exists this function cannot fail." |
| 656 | const index = self.getIndexAdapted(key, key_ctx) orelse return err; | 656 | const index = self.getIndexAdapted(key, key_ctx) orelse return err; |
| ... | @@ -731,12 +731,12 @@ pub fn ArrayHashMapUnmanaged( | ... | @@ -731,12 +731,12 @@ pub fn ArrayHashMapUnmanaged( |
| 731 | } | 731 | } |
| 732 | } | 732 | } |
| 733 | 733 | ||
| 734 | pub fn getOrPutValue(self: *Self, allocator: *Allocator, key: K, value: V) !GetOrPutResult { | 734 | pub fn getOrPutValue(self: *Self, allocator: Allocator, key: K, value: V) !GetOrPutResult { |
| 735 | if (@sizeOf(Context) != 0) | 735 | if (@sizeOf(Context) != 0) |
| 736 | @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call getOrPutValueContext instead."); | 736 | @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call getOrPutValueContext instead."); |
| 737 | return self.getOrPutValueContext(allocator, key, value, undefined); | 737 | return self.getOrPutValueContext(allocator, key, value, undefined); |
| 738 | } | 738 | } |
| 739 | pub fn getOrPutValueContext(self: *Self, allocator: *Allocator, key: K, value: V, ctx: Context) !GetOrPutResult { | 739 | pub fn getOrPutValueContext(self: *Self, allocator: Allocator, key: K, value: V, ctx: Context) !GetOrPutResult { |
| 740 | const res = try self.getOrPutContextAdapted(allocator, key, ctx, ctx); | 740 | const res = try self.getOrPutContextAdapted(allocator, key, ctx, ctx); |
| 741 | if (!res.found_existing) { | 741 | if (!res.found_existing) { |
| 742 | res.key_ptr.* = key; | 742 | res.key_ptr.* = key; |
| ... | @@ -749,12 +749,12 @@ pub fn ArrayHashMapUnmanaged( | ... | @@ -749,12 +749,12 @@ pub fn ArrayHashMapUnmanaged( |
| 749 | 749 | ||
| 750 | /// Increases capacity, guaranteeing that insertions up until the | 750 | /// Increases capacity, guaranteeing that insertions up until the |
| 751 | /// `expected_count` will not cause an allocation, and therefore cannot fail. | 751 | /// `expected_count` will not cause an allocation, and therefore cannot fail. |
| 752 | pub fn ensureTotalCapacity(self: *Self, allocator: *Allocator, new_capacity: usize) !void { | 752 | pub fn ensureTotalCapacity(self: *Self, allocator: Allocator, new_capacity: usize) !void { |
| 753 | if (@sizeOf(ByIndexContext) != 0) | 753 | if (@sizeOf(ByIndexContext) != 0) |
| 754 | @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call ensureTotalCapacityContext instead."); | 754 | @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call ensureTotalCapacityContext instead."); |
| 755 | return self.ensureTotalCapacityContext(allocator, new_capacity, undefined); | 755 | return self.ensureTotalCapacityContext(allocator, new_capacity, undefined); |
| 756 | } | 756 | } |
| 757 | pub fn ensureTotalCapacityContext(self: *Self, allocator: *Allocator, new_capacity: usize, ctx: Context) !void { | 757 | pub fn ensureTotalCapacityContext(self: *Self, allocator: Allocator, new_capacity: usize, ctx: Context) !void { |
| 758 | if (new_capacity <= linear_scan_max) { | 758 | if (new_capacity <= linear_scan_max) { |
| 759 | try self.entries.ensureTotalCapacity(allocator, new_capacity); | 759 | try self.entries.ensureTotalCapacity(allocator, new_capacity); |
| 760 | return; | 760 | return; |
| ... | @@ -781,7 +781,7 @@ pub fn ArrayHashMapUnmanaged( | ... | @@ -781,7 +781,7 @@ pub fn ArrayHashMapUnmanaged( |
| 781 | /// therefore cannot fail. | 781 | /// therefore cannot fail. |
| 782 | pub fn ensureUnusedCapacity( | 782 | pub fn ensureUnusedCapacity( |
| 783 | self: *Self, | 783 | self: *Self, |
| 784 | allocator: *Allocator, | 784 | allocator: Allocator, |
| 785 | additional_capacity: usize, | 785 | additional_capacity: usize, |
| 786 | ) !void { | 786 | ) !void { |
| 787 | if (@sizeOf(ByIndexContext) != 0) | 787 | if (@sizeOf(ByIndexContext) != 0) |
| ... | @@ -790,7 +790,7 @@ pub fn ArrayHashMapUnmanaged( | ... | @@ -790,7 +790,7 @@ pub fn ArrayHashMapUnmanaged( |
| 790 | } | 790 | } |
| 791 | pub fn ensureUnusedCapacityContext( | 791 | pub fn ensureUnusedCapacityContext( |
| 792 | self: *Self, | 792 | self: *Self, |
| 793 | allocator: *Allocator, | 793 | allocator: Allocator, |
| 794 | additional_capacity: usize, | 794 | additional_capacity: usize, |
| 795 | ctx: Context, | 795 | ctx: Context, |
| 796 | ) !void { | 796 | ) !void { |
| ... | @@ -808,24 +808,24 @@ pub fn ArrayHashMapUnmanaged( | ... | @@ -808,24 +808,24 @@ pub fn ArrayHashMapUnmanaged( |
| 808 | 808 | ||
| 809 | /// Clobbers any existing data. To detect if a put would clobber | 809 | /// Clobbers any existing data. To detect if a put would clobber |
| 810 | /// existing data, see `getOrPut`. | 810 | /// existing data, see `getOrPut`. |
| 811 | pub fn put(self: *Self, allocator: *Allocator, key: K, value: V) !void { | 811 | pub fn put(self: *Self, allocator: Allocator, key: K, value: V) !void { |
| 812 | if (@sizeOf(Context) != 0) | 812 | if (@sizeOf(Context) != 0) |
| 813 | @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call putContext instead."); | 813 | @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call putContext instead."); |
| 814 | return self.putContext(allocator, key, value, undefined); | 814 | return self.putContext(allocator, key, value, undefined); |
| 815 | } | 815 | } |
| 816 | pub fn putContext(self: *Self, allocator: *Allocator, key: K, value: V, ctx: Context) !void { | 816 | pub fn putContext(self: *Self, allocator: Allocator, key: K, value: V, ctx: Context) !void { |
| 817 | const result = try self.getOrPutContext(allocator, key, ctx); | 817 | const result = try self.getOrPutContext(allocator, key, ctx); |
| 818 | result.value_ptr.* = value; | 818 | result.value_ptr.* = value; |
| 819 | } | 819 | } |
| 820 | 820 | ||
| 821 | /// Inserts a key-value pair into the hash map, asserting that no previous | 821 | /// Inserts a key-value pair into the hash map, asserting that no previous |
| 822 | /// entry with the same key is already present | 822 | /// entry with the same key is already present |
| 823 | pub fn putNoClobber(self: *Self, allocator: *Allocator, key: K, value: V) !void { | 823 | pub fn putNoClobber(self: *Self, allocator: Allocator, key: K, value: V) !void { |
| 824 | if (@sizeOf(Context) != 0) | 824 | if (@sizeOf(Context) != 0) |
| 825 | @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call putNoClobberContext instead."); | 825 | @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call putNoClobberContext instead."); |
| 826 | return self.putNoClobberContext(allocator, key, value, undefined); | 826 | return self.putNoClobberContext(allocator, key, value, undefined); |
| 827 | } | 827 | } |
| 828 | pub fn putNoClobberContext(self: *Self, allocator: *Allocator, key: K, value: V, ctx: Context) !void { | 828 | pub fn putNoClobberContext(self: *Self, allocator: Allocator, key: K, value: V, ctx: Context) !void { |
| 829 | const result = try self.getOrPutContext(allocator, key, ctx); | 829 | const result = try self.getOrPutContext(allocator, key, ctx); |
| 830 | assert(!result.found_existing); | 830 | assert(!result.found_existing); |
| 831 | result.value_ptr.* = value; | 831 | result.value_ptr.* = value; |
| ... | @@ -859,12 +859,12 @@ pub fn ArrayHashMapUnmanaged( | ... | @@ -859,12 +859,12 @@ pub fn ArrayHashMapUnmanaged( |
| 859 | } | 859 | } |
| 860 | 860 | ||
| 861 | /// Inserts a new `Entry` into the hash map, returning the previous one, if any. | 861 | /// Inserts a new `Entry` into the hash map, returning the previous one, if any. |
| 862 | pub fn fetchPut(self: *Self, allocator: *Allocator, key: K, value: V) !?KV { | 862 | pub fn fetchPut(self: *Self, allocator: Allocator, key: K, value: V) !?KV { |
| 863 | if (@sizeOf(Context) != 0) | 863 | if (@sizeOf(Context) != 0) |
| 864 | @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call fetchPutContext instead."); | 864 | @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call fetchPutContext instead."); |
| 865 | return self.fetchPutContext(allocator, key, value, undefined); | 865 | return self.fetchPutContext(allocator, key, value, undefined); |
| 866 | } | 866 | } |
| 867 | pub fn fetchPutContext(self: *Self, allocator: *Allocator, key: K, value: V, ctx: Context) !?KV { | 867 | pub fn fetchPutContext(self: *Self, allocator: Allocator, key: K, value: V, ctx: Context) !?KV { |
| 868 | const gop = try self.getOrPutContext(allocator, key, ctx); | 868 | const gop = try self.getOrPutContext(allocator, key, ctx); |
| 869 | var result: ?KV = null; | 869 | var result: ?KV = null; |
| 870 | if (gop.found_existing) { | 870 | if (gop.found_existing) { |
| ... | @@ -1132,12 +1132,12 @@ pub fn ArrayHashMapUnmanaged( | ... | @@ -1132,12 +1132,12 @@ pub fn ArrayHashMapUnmanaged( |
| 1132 | 1132 | ||
| 1133 | /// Create a copy of the hash map which can be modified separately. | 1133 | /// Create a copy of the hash map which can be modified separately. |
| 1134 | /// The copy uses the same context and allocator as this instance. | 1134 | /// The copy uses the same context and allocator as this instance. |
| 1135 | pub fn clone(self: Self, allocator: *Allocator) !Self { | 1135 | pub fn clone(self: Self, allocator: Allocator) !Self { |
| 1136 | if (@sizeOf(ByIndexContext) != 0) | 1136 | if (@sizeOf(ByIndexContext) != 0) |
| 1137 | @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call cloneContext instead."); | 1137 | @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call cloneContext instead."); |
| 1138 | return self.cloneContext(allocator, undefined); | 1138 | return self.cloneContext(allocator, undefined); |
| 1139 | } | 1139 | } |
| 1140 | pub fn cloneContext(self: Self, allocator: *Allocator, ctx: Context) !Self { | 1140 | pub fn cloneContext(self: Self, allocator: Allocator, ctx: Context) !Self { |
| 1141 | var other: Self = .{}; | 1141 | var other: Self = .{}; |
| 1142 | other.entries = try self.entries.clone(allocator); | 1142 | other.entries = try self.entries.clone(allocator); |
| 1143 | errdefer other.entries.deinit(allocator); | 1143 | errdefer other.entries.deinit(allocator); |
| ... | @@ -1152,12 +1152,12 @@ pub fn ArrayHashMapUnmanaged( | ... | @@ -1152,12 +1152,12 @@ pub fn ArrayHashMapUnmanaged( |
| 1152 | 1152 | ||
| 1153 | /// Rebuilds the key indexes. If the underlying entries has been modified directly, users | 1153 | /// Rebuilds the key indexes. If the underlying entries has been modified directly, users |
| 1154 | /// can call `reIndex` to update the indexes to account for these new entries. | 1154 | /// can call `reIndex` to update the indexes to account for these new entries. |
| 1155 | pub fn reIndex(self: *Self, allocator: *Allocator) !void { | 1155 | pub fn reIndex(self: *Self, allocator: Allocator) !void { |
| 1156 | if (@sizeOf(ByIndexContext) != 0) | 1156 | if (@sizeOf(ByIndexContext) != 0) |
| 1157 | @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call reIndexContext instead."); | 1157 | @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call reIndexContext instead."); |
| 1158 | return self.reIndexContext(allocator, undefined); | 1158 | return self.reIndexContext(allocator, undefined); |
| 1159 | } | 1159 | } |
| 1160 | pub fn reIndexContext(self: *Self, allocator: *Allocator, ctx: Context) !void { | 1160 | pub fn reIndexContext(self: *Self, allocator: Allocator, ctx: Context) !void { |
| 1161 | if (self.entries.capacity <= linear_scan_max) return; | 1161 | if (self.entries.capacity <= linear_scan_max) return; |
| 1162 | // We're going to rebuild the index header and replace the existing one (if any). The | 1162 | // We're going to rebuild the index header and replace the existing one (if any). The |
| 1163 | // indexes should sized such that they will be at most 60% full. | 1163 | // indexes should sized such that they will be at most 60% full. |
| ... | @@ -1189,12 +1189,12 @@ pub fn ArrayHashMapUnmanaged( | ... | @@ -1189,12 +1189,12 @@ pub fn ArrayHashMapUnmanaged( |
| 1189 | 1189 | ||
| 1190 | /// Shrinks the underlying `Entry` array to `new_len` elements and discards any associated | 1190 | /// Shrinks the underlying `Entry` array to `new_len` elements and discards any associated |
| 1191 | /// index entries. Reduces allocated capacity. | 1191 | /// index entries. Reduces allocated capacity. |
| 1192 | pub fn shrinkAndFree(self: *Self, allocator: *Allocator, new_len: usize) void { | 1192 | pub fn shrinkAndFree(self: *Self, allocator: Allocator, new_len: usize) void { |
| 1193 | if (@sizeOf(ByIndexContext) != 0) | 1193 | if (@sizeOf(ByIndexContext) != 0) |
| 1194 | @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call shrinkAndFreeContext instead."); | 1194 | @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call shrinkAndFreeContext instead."); |
| 1195 | return self.shrinkAndFreeContext(allocator, new_len, undefined); | 1195 | return self.shrinkAndFreeContext(allocator, new_len, undefined); |
| 1196 | } | 1196 | } |
| 1197 | pub fn shrinkAndFreeContext(self: *Self, allocator: *Allocator, new_len: usize, ctx: Context) void { | 1197 | pub fn shrinkAndFreeContext(self: *Self, allocator: Allocator, new_len: usize, ctx: Context) void { |
| 1198 | // Remove index entries from the new length onwards. | 1198 | // Remove index entries from the new length onwards. |
| 1199 | // Explicitly choose to ONLY remove index entries and not the underlying array list | 1199 | // Explicitly choose to ONLY remove index entries and not the underlying array list |
| 1200 | // entries as we're going to remove them in the subsequent shrink call. | 1200 | // entries as we're going to remove them in the subsequent shrink call. |
| ... | @@ -1844,7 +1844,7 @@ const IndexHeader = struct { | ... | @@ -1844,7 +1844,7 @@ const IndexHeader = struct { |
| 1844 | 1844 | ||
| 1845 | /// Allocates an index header, and fills the entryIndexes array with empty. | 1845 | /// Allocates an index header, and fills the entryIndexes array with empty. |
| 1846 | /// The distance array contents are undefined. | 1846 | /// The distance array contents are undefined. |
| 1847 | fn alloc(allocator: *Allocator, new_bit_index: u8) !*IndexHeader { | 1847 | fn alloc(allocator: Allocator, new_bit_index: u8) !*IndexHeader { |
| 1848 | const len = @as(usize, 1) << @intCast(math.Log2Int(usize), new_bit_index); | 1848 | const len = @as(usize, 1) << @intCast(math.Log2Int(usize), new_bit_index); |
| 1849 | const index_size = hash_map.capacityIndexSize(new_bit_index); | 1849 | const index_size = hash_map.capacityIndexSize(new_bit_index); |
| 1850 | const nbytes = @sizeOf(IndexHeader) + index_size * len; | 1850 | const nbytes = @sizeOf(IndexHeader) + index_size * len; |
| ... | @@ -1858,7 +1858,7 @@ const IndexHeader = struct { | ... | @@ -1858,7 +1858,7 @@ const IndexHeader = struct { |
| 1858 | } | 1858 | } |
| 1859 | 1859 | ||
| 1860 | /// Releases the memory for a header and its associated arrays. | 1860 | /// Releases the memory for a header and its associated arrays. |
| 1861 | fn free(header: *IndexHeader, allocator: *Allocator) void { | 1861 | fn free(header: *IndexHeader, allocator: Allocator) void { |
| 1862 | const index_size = hash_map.capacityIndexSize(header.bit_index); | 1862 | const index_size = hash_map.capacityIndexSize(header.bit_index); |
| 1863 | const ptr = @ptrCast([*]align(@alignOf(IndexHeader)) u8, header); | 1863 | const ptr = @ptrCast([*]align(@alignOf(IndexHeader)) u8, header); |
| 1864 | const slice = ptr[0 .. @sizeOf(IndexHeader) + header.length() * index_size]; | 1864 | const slice = ptr[0 .. @sizeOf(IndexHeader) + header.length() * index_size]; |
lib/std/array_list.zig+28-28| ... | @@ -42,12 +42,12 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type { | ... | @@ -42,12 +42,12 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type { |
| 42 | /// How many T values this list can hold without allocating | 42 | /// How many T values this list can hold without allocating |
| 43 | /// additional memory. | 43 | /// additional memory. |
| 44 | capacity: usize, | 44 | capacity: usize, |
| 45 | allocator: *Allocator, | 45 | allocator: Allocator, |
| 46 | 46 | ||
| 47 | pub const Slice = if (alignment) |a| ([]align(a) T) else []T; | 47 | pub const Slice = if (alignment) |a| ([]align(a) T) else []T; |
| 48 | 48 | ||
| 49 | /// Deinitialize with `deinit` or use `toOwnedSlice`. | 49 | /// Deinitialize with `deinit` or use `toOwnedSlice`. |
| 50 | pub fn init(allocator: *Allocator) Self { | 50 | pub fn init(allocator: Allocator) Self { |
| 51 | return Self{ | 51 | return Self{ |
| 52 | .items = &[_]T{}, | 52 | .items = &[_]T{}, |
| 53 | .capacity = 0, | 53 | .capacity = 0, |
| ... | @@ -58,7 +58,7 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type { | ... | @@ -58,7 +58,7 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type { |
| 58 | /// Initialize with capacity to hold at least `num` elements. | 58 | /// Initialize with capacity to hold at least `num` elements. |
| 59 | /// The resulting capacity is likely to be equal to `num`. | 59 | /// The resulting capacity is likely to be equal to `num`. |
| 60 | /// Deinitialize with `deinit` or use `toOwnedSlice`. | 60 | /// Deinitialize with `deinit` or use `toOwnedSlice`. |
| 61 | pub fn initCapacity(allocator: *Allocator, num: usize) !Self { | 61 | pub fn initCapacity(allocator: Allocator, num: usize) !Self { |
| 62 | var self = Self.init(allocator); | 62 | var self = Self.init(allocator); |
| 63 | try self.ensureTotalCapacityPrecise(num); | 63 | try self.ensureTotalCapacityPrecise(num); |
| 64 | return self; | 64 | return self; |
| ... | @@ -74,7 +74,7 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type { | ... | @@ -74,7 +74,7 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type { |
| 74 | /// ArrayList takes ownership of the passed in slice. The slice must have been | 74 | /// ArrayList takes ownership of the passed in slice. The slice must have been |
| 75 | /// allocated with `allocator`. | 75 | /// allocated with `allocator`. |
| 76 | /// Deinitialize with `deinit` or use `toOwnedSlice`. | 76 | /// Deinitialize with `deinit` or use `toOwnedSlice`. |
| 77 | pub fn fromOwnedSlice(allocator: *Allocator, slice: Slice) Self { | 77 | pub fn fromOwnedSlice(allocator: Allocator, slice: Slice) Self { |
| 78 | return Self{ | 78 | return Self{ |
| 79 | .items = slice, | 79 | .items = slice, |
| 80 | .capacity = slice.len, | 80 | .capacity = slice.len, |
| ... | @@ -457,33 +457,33 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ | ... | @@ -457,33 +457,33 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ |
| 457 | /// Initialize with capacity to hold at least num elements. | 457 | /// Initialize with capacity to hold at least num elements. |
| 458 | /// The resulting capacity is likely to be equal to `num`. | 458 | /// The resulting capacity is likely to be equal to `num`. |
| 459 | /// Deinitialize with `deinit` or use `toOwnedSlice`. | 459 | /// Deinitialize with `deinit` or use `toOwnedSlice`. |
| 460 | pub fn initCapacity(allocator: *Allocator, num: usize) !Self { | 460 | pub fn initCapacity(allocator: Allocator, num: usize) !Self { |
| 461 | var self = Self{}; | 461 | var self = Self{}; |
| 462 | try self.ensureTotalCapacityPrecise(allocator, num); | 462 | try self.ensureTotalCapacityPrecise(allocator, num); |
| 463 | return self; | 463 | return self; |
| 464 | } | 464 | } |
| 465 | 465 | ||
| 466 | /// Release all allocated memory. | 466 | /// Release all allocated memory. |
| 467 | pub fn deinit(self: *Self, allocator: *Allocator) void { | 467 | pub fn deinit(self: *Self, allocator: Allocator) void { |
| 468 | allocator.free(self.allocatedSlice()); | 468 | allocator.free(self.allocatedSlice()); |
| 469 | self.* = undefined; | 469 | self.* = undefined; |
| 470 | } | 470 | } |
| 471 | 471 | ||
| 472 | /// Convert this list into an analogous memory-managed one. | 472 | /// Convert this list into an analogous memory-managed one. |
| 473 | /// The returned list has ownership of the underlying memory. | 473 | /// The returned list has ownership of the underlying memory. |
| 474 | pub fn toManaged(self: *Self, allocator: *Allocator) ArrayListAligned(T, alignment) { | 474 | pub fn toManaged(self: *Self, allocator: Allocator) ArrayListAligned(T, alignment) { |
| 475 | return .{ .items = self.items, .capacity = self.capacity, .allocator = allocator }; | 475 | return .{ .items = self.items, .capacity = self.capacity, .allocator = allocator }; |
| 476 | } | 476 | } |
| 477 | 477 | ||
| 478 | /// The caller owns the returned memory. ArrayList becomes empty. | 478 | /// The caller owns the returned memory. ArrayList becomes empty. |
| 479 | pub fn toOwnedSlice(self: *Self, allocator: *Allocator) Slice { | 479 | pub fn toOwnedSlice(self: *Self, allocator: Allocator) Slice { |
| 480 | const result = allocator.shrink(self.allocatedSlice(), self.items.len); | 480 | const result = allocator.shrink(self.allocatedSlice(), self.items.len); |
| 481 | self.* = Self{}; | 481 | self.* = Self{}; |
| 482 | return result; | 482 | return result; |
| 483 | } | 483 | } |
| 484 | 484 | ||
| 485 | /// The caller owns the returned memory. ArrayList becomes empty. | 485 | /// The caller owns the returned memory. ArrayList becomes empty. |
| 486 | pub fn toOwnedSliceSentinel(self: *Self, allocator: *Allocator, comptime sentinel: T) ![:sentinel]T { | 486 | pub fn toOwnedSliceSentinel(self: *Self, allocator: Allocator, comptime sentinel: T) ![:sentinel]T { |
| 487 | try self.append(allocator, sentinel); | 487 | try self.append(allocator, sentinel); |
| 488 | const result = self.toOwnedSlice(allocator); | 488 | const result = self.toOwnedSlice(allocator); |
| 489 | return result[0 .. result.len - 1 :sentinel]; | 489 | return result[0 .. result.len - 1 :sentinel]; |
| ... | @@ -492,7 +492,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ | ... | @@ -492,7 +492,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ |
| 492 | /// Insert `item` at index `n`. Moves `list[n .. list.len]` | 492 | /// Insert `item` at index `n`. Moves `list[n .. list.len]` |
| 493 | /// to higher indices to make room. | 493 | /// to higher indices to make room. |
| 494 | /// This operation is O(N). | 494 | /// This operation is O(N). |
| 495 | pub fn insert(self: *Self, allocator: *Allocator, n: usize, item: T) !void { | 495 | pub fn insert(self: *Self, allocator: Allocator, n: usize, item: T) !void { |
| 496 | try self.ensureUnusedCapacity(allocator, 1); | 496 | try self.ensureUnusedCapacity(allocator, 1); |
| 497 | self.items.len += 1; | 497 | self.items.len += 1; |
| 498 | 498 | ||
| ... | @@ -503,7 +503,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ | ... | @@ -503,7 +503,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ |
| 503 | /// Insert slice `items` at index `i`. Moves `list[i .. list.len]` to | 503 | /// Insert slice `items` at index `i`. Moves `list[i .. list.len]` to |
| 504 | /// higher indicices make room. | 504 | /// higher indicices make room. |
| 505 | /// This operation is O(N). | 505 | /// This operation is O(N). |
| 506 | pub fn insertSlice(self: *Self, allocator: *Allocator, i: usize, items: []const T) !void { | 506 | pub fn insertSlice(self: *Self, allocator: Allocator, i: usize, items: []const T) !void { |
| 507 | try self.ensureUnusedCapacity(allocator, items.len); | 507 | try self.ensureUnusedCapacity(allocator, items.len); |
| 508 | self.items.len += items.len; | 508 | self.items.len += items.len; |
| 509 | 509 | ||
| ... | @@ -515,14 +515,14 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ | ... | @@ -515,14 +515,14 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ |
| 515 | /// Grows list if `len < new_items.len`. | 515 | /// Grows list if `len < new_items.len`. |
| 516 | /// Shrinks list if `len > new_items.len` | 516 | /// Shrinks list if `len > new_items.len` |
| 517 | /// Invalidates pointers if this ArrayList is resized. | 517 | /// Invalidates pointers if this ArrayList is resized. |
| 518 | pub fn replaceRange(self: *Self, allocator: *Allocator, start: usize, len: usize, new_items: []const T) !void { | 518 | pub fn replaceRange(self: *Self, allocator: Allocator, start: usize, len: usize, new_items: []const T) !void { |
| 519 | var managed = self.toManaged(allocator); | 519 | var managed = self.toManaged(allocator); |
| 520 | try managed.replaceRange(start, len, new_items); | 520 | try managed.replaceRange(start, len, new_items); |
| 521 | self.* = managed.moveToUnmanaged(); | 521 | self.* = managed.moveToUnmanaged(); |
| 522 | } | 522 | } |
| 523 | 523 | ||
| 524 | /// Extend the list by 1 element. Allocates more memory as necessary. | 524 | /// Extend the list by 1 element. Allocates more memory as necessary. |
| 525 | pub fn append(self: *Self, allocator: *Allocator, item: T) !void { | 525 | pub fn append(self: *Self, allocator: Allocator, item: T) !void { |
| 526 | const new_item_ptr = try self.addOne(allocator); | 526 | const new_item_ptr = try self.addOne(allocator); |
| 527 | new_item_ptr.* = item; | 527 | new_item_ptr.* = item; |
| 528 | } | 528 | } |
| ... | @@ -563,7 +563,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ | ... | @@ -563,7 +563,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ |
| 563 | 563 | ||
| 564 | /// Append the slice of items to the list. Allocates more | 564 | /// Append the slice of items to the list. Allocates more |
| 565 | /// memory as necessary. | 565 | /// memory as necessary. |
| 566 | pub fn appendSlice(self: *Self, allocator: *Allocator, items: []const T) !void { | 566 | pub fn appendSlice(self: *Self, allocator: Allocator, items: []const T) !void { |
| 567 | try self.ensureUnusedCapacity(allocator, items.len); | 567 | try self.ensureUnusedCapacity(allocator, items.len); |
| 568 | self.appendSliceAssumeCapacity(items); | 568 | self.appendSliceAssumeCapacity(items); |
| 569 | } | 569 | } |
| ... | @@ -580,7 +580,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ | ... | @@ -580,7 +580,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ |
| 580 | 580 | ||
| 581 | pub const WriterContext = struct { | 581 | pub const WriterContext = struct { |
| 582 | self: *Self, | 582 | self: *Self, |
| 583 | allocator: *Allocator, | 583 | allocator: Allocator, |
| 584 | }; | 584 | }; |
| 585 | 585 | ||
| 586 | pub const Writer = if (T != u8) | 586 | pub const Writer = if (T != u8) |
| ... | @@ -590,7 +590,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ | ... | @@ -590,7 +590,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ |
| 590 | std.io.Writer(WriterContext, error{OutOfMemory}, appendWrite); | 590 | std.io.Writer(WriterContext, error{OutOfMemory}, appendWrite); |
| 591 | 591 | ||
| 592 | /// Initializes a Writer which will append to the list. | 592 | /// Initializes a Writer which will append to the list. |
| 593 | pub fn writer(self: *Self, allocator: *Allocator) Writer { | 593 | pub fn writer(self: *Self, allocator: Allocator) Writer { |
| 594 | return .{ .context = .{ .self = self, .allocator = allocator } }; | 594 | return .{ .context = .{ .self = self, .allocator = allocator } }; |
| 595 | } | 595 | } |
| 596 | 596 | ||
| ... | @@ -603,7 +603,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ | ... | @@ -603,7 +603,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ |
| 603 | 603 | ||
| 604 | /// Append a value to the list `n` times. | 604 | /// Append a value to the list `n` times. |
| 605 | /// Allocates more memory as necessary. | 605 | /// Allocates more memory as necessary. |
| 606 | pub fn appendNTimes(self: *Self, allocator: *Allocator, value: T, n: usize) !void { | 606 | pub fn appendNTimes(self: *Self, allocator: Allocator, value: T, n: usize) !void { |
| 607 | const old_len = self.items.len; | 607 | const old_len = self.items.len; |
| 608 | try self.resize(allocator, self.items.len + n); | 608 | try self.resize(allocator, self.items.len + n); |
| 609 | mem.set(T, self.items[old_len..self.items.len], value); | 609 | mem.set(T, self.items[old_len..self.items.len], value); |
| ... | @@ -621,13 +621,13 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ | ... | @@ -621,13 +621,13 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ |
| 621 | 621 | ||
| 622 | /// Adjust the list's length to `new_len`. | 622 | /// Adjust the list's length to `new_len`. |
| 623 | /// Does not initialize added items, if any. | 623 | /// Does not initialize added items, if any. |
| 624 | pub fn resize(self: *Self, allocator: *Allocator, new_len: usize) !void { | 624 | pub fn resize(self: *Self, allocator: Allocator, new_len: usize) !void { |
| 625 | try self.ensureTotalCapacity(allocator, new_len); | 625 | try self.ensureTotalCapacity(allocator, new_len); |
| 626 | self.items.len = new_len; | 626 | self.items.len = new_len; |
| 627 | } | 627 | } |
| 628 | 628 | ||
| 629 | /// Reduce allocated capacity to `new_len`. | 629 | /// Reduce allocated capacity to `new_len`. |
| 630 | pub fn shrinkAndFree(self: *Self, allocator: *Allocator, new_len: usize) void { | 630 | pub fn shrinkAndFree(self: *Self, allocator: Allocator, new_len: usize) void { |
| 631 | assert(new_len <= self.items.len); | 631 | assert(new_len <= self.items.len); |
| 632 | 632 | ||
| 633 | self.items = allocator.realloc(self.allocatedSlice(), new_len) catch |e| switch (e) { | 633 | self.items = allocator.realloc(self.allocatedSlice(), new_len) catch |e| switch (e) { |
| ... | @@ -653,7 +653,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ | ... | @@ -653,7 +653,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ |
| 653 | } | 653 | } |
| 654 | 654 | ||
| 655 | /// Invalidates all element pointers. | 655 | /// Invalidates all element pointers. |
| 656 | pub fn clearAndFree(self: *Self, allocator: *Allocator) void { | 656 | pub fn clearAndFree(self: *Self, allocator: Allocator) void { |
| 657 | allocator.free(self.allocatedSlice()); | 657 | allocator.free(self.allocatedSlice()); |
| 658 | self.items.len = 0; | 658 | self.items.len = 0; |
| 659 | self.capacity = 0; | 659 | self.capacity = 0; |
| ... | @@ -663,7 +663,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ | ... | @@ -663,7 +663,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ |
| 663 | 663 | ||
| 664 | /// Modify the array so that it can hold at least `new_capacity` items. | 664 | /// Modify the array so that it can hold at least `new_capacity` items. |
| 665 | /// Invalidates pointers if additional memory is needed. | 665 | /// Invalidates pointers if additional memory is needed. |
| 666 | pub fn ensureTotalCapacity(self: *Self, allocator: *Allocator, new_capacity: usize) !void { | 666 | pub fn ensureTotalCapacity(self: *Self, allocator: Allocator, new_capacity: usize) !void { |
| 667 | var better_capacity = self.capacity; | 667 | var better_capacity = self.capacity; |
| 668 | if (better_capacity >= new_capacity) return; | 668 | if (better_capacity >= new_capacity) return; |
| 669 | 669 | ||
| ... | @@ -679,7 +679,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ | ... | @@ -679,7 +679,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ |
| 679 | /// Like `ensureTotalCapacity`, but the resulting capacity is much more likely | 679 | /// Like `ensureTotalCapacity`, but the resulting capacity is much more likely |
| 680 | /// (but not guaranteed) to be equal to `new_capacity`. | 680 | /// (but not guaranteed) to be equal to `new_capacity`. |
| 681 | /// Invalidates pointers if additional memory is needed. | 681 | /// Invalidates pointers if additional memory is needed. |
| 682 | pub fn ensureTotalCapacityPrecise(self: *Self, allocator: *Allocator, new_capacity: usize) !void { | 682 | pub fn ensureTotalCapacityPrecise(self: *Self, allocator: Allocator, new_capacity: usize) !void { |
| 683 | if (self.capacity >= new_capacity) return; | 683 | if (self.capacity >= new_capacity) return; |
| 684 | 684 | ||
| 685 | const new_memory = try allocator.reallocAtLeast(self.allocatedSlice(), new_capacity); | 685 | const new_memory = try allocator.reallocAtLeast(self.allocatedSlice(), new_capacity); |
| ... | @@ -691,7 +691,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ | ... | @@ -691,7 +691,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ |
| 691 | /// Invalidates pointers if additional memory is needed. | 691 | /// Invalidates pointers if additional memory is needed. |
| 692 | pub fn ensureUnusedCapacity( | 692 | pub fn ensureUnusedCapacity( |
| 693 | self: *Self, | 693 | self: *Self, |
| 694 | allocator: *Allocator, | 694 | allocator: Allocator, |
| 695 | additional_count: usize, | 695 | additional_count: usize, |
| 696 | ) !void { | 696 | ) !void { |
| 697 | return self.ensureTotalCapacity(allocator, self.items.len + additional_count); | 697 | return self.ensureTotalCapacity(allocator, self.items.len + additional_count); |
| ... | @@ -706,7 +706,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ | ... | @@ -706,7 +706,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ |
| 706 | 706 | ||
| 707 | /// Increase length by 1, returning pointer to the new item. | 707 | /// Increase length by 1, returning pointer to the new item. |
| 708 | /// The returned pointer becomes invalid when the list resized. | 708 | /// The returned pointer becomes invalid when the list resized. |
| 709 | pub fn addOne(self: *Self, allocator: *Allocator) !*T { | 709 | pub fn addOne(self: *Self, allocator: Allocator) !*T { |
| 710 | const newlen = self.items.len + 1; | 710 | const newlen = self.items.len + 1; |
| 711 | try self.ensureTotalCapacity(allocator, newlen); | 711 | try self.ensureTotalCapacity(allocator, newlen); |
| 712 | return self.addOneAssumeCapacity(); | 712 | return self.addOneAssumeCapacity(); |
| ... | @@ -726,7 +726,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ | ... | @@ -726,7 +726,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ |
| 726 | /// Resize the array, adding `n` new elements, which have `undefined` values. | 726 | /// Resize the array, adding `n` new elements, which have `undefined` values. |
| 727 | /// The return value is an array pointing to the newly allocated elements. | 727 | /// The return value is an array pointing to the newly allocated elements. |
| 728 | /// The returned pointer becomes invalid when the list is resized. | 728 | /// The returned pointer becomes invalid when the list is resized. |
| 729 | pub fn addManyAsArray(self: *Self, allocator: *Allocator, comptime n: usize) !*[n]T { | 729 | pub fn addManyAsArray(self: *Self, allocator: Allocator, comptime n: usize) !*[n]T { |
| 730 | const prev_len = self.items.len; | 730 | const prev_len = self.items.len; |
| 731 | try self.resize(allocator, self.items.len + n); | 731 | try self.resize(allocator, self.items.len + n); |
| 732 | return self.items[prev_len..][0..n]; | 732 | return self.items[prev_len..][0..n]; |
| ... | @@ -1119,7 +1119,7 @@ test "std.ArrayList/ArrayListUnmanaged.insertSlice" { | ... | @@ -1119,7 +1119,7 @@ test "std.ArrayList/ArrayListUnmanaged.insertSlice" { |
| 1119 | test "std.ArrayList/ArrayListUnmanaged.replaceRange" { | 1119 | test "std.ArrayList/ArrayListUnmanaged.replaceRange" { |
| 1120 | var arena = std.heap.ArenaAllocator.init(testing.allocator); | 1120 | var arena = std.heap.ArenaAllocator.init(testing.allocator); |
| 1121 | defer arena.deinit(); | 1121 | defer arena.deinit(); |
| 1122 | const a = &arena.allocator; | 1122 | const a = arena.getAllocator(); |
| 1123 | 1123 | ||
| 1124 | const init = [_]i32{ 1, 2, 3, 4, 5 }; | 1124 | const init = [_]i32{ 1, 2, 3, 4, 5 }; |
| 1125 | const new = [_]i32{ 0, 0, 0 }; | 1125 | const new = [_]i32{ 0, 0, 0 }; |
| ... | @@ -1263,7 +1263,7 @@ test "std.ArrayList/ArrayListUnmanaged.shrink still sets length on error.OutOfMe | ... | @@ -1263,7 +1263,7 @@ test "std.ArrayList/ArrayListUnmanaged.shrink still sets length on error.OutOfMe |
| 1263 | // use an arena allocator to make sure realloc returns error.OutOfMemory | 1263 | // use an arena allocator to make sure realloc returns error.OutOfMemory |
| 1264 | var arena = std.heap.ArenaAllocator.init(testing.allocator); | 1264 | var arena = std.heap.ArenaAllocator.init(testing.allocator); |
| 1265 | defer arena.deinit(); | 1265 | defer arena.deinit(); |
| 1266 | const a = &arena.allocator; | 1266 | const a = arena.getAllocator(); |
| 1267 | 1267 | ||
| 1268 | { | 1268 | { |
| 1269 | var list = ArrayList(i32).init(a); | 1269 | var list = ArrayList(i32).init(a); |
| ... | @@ -1361,7 +1361,7 @@ test "ArrayListAligned/ArrayListAlignedUnmanaged accepts unaligned slices" { | ... | @@ -1361,7 +1361,7 @@ test "ArrayListAligned/ArrayListAlignedUnmanaged accepts unaligned slices" { |
| 1361 | 1361 | ||
| 1362 | test "std.ArrayList(u0)" { | 1362 | test "std.ArrayList(u0)" { |
| 1363 | // An ArrayList on zero-sized types should not need to allocate | 1363 | // An ArrayList on zero-sized types should not need to allocate |
| 1364 | const a = &testing.FailingAllocator.init(testing.allocator, 0).allocator; | 1364 | const a = testing.FailingAllocator.init(testing.allocator, 0).getAllocator(); |
| 1365 | 1365 | ||
| 1366 | var list = ArrayList(u0).init(a); | 1366 | var list = ArrayList(u0).init(a); |
| 1367 | defer list.deinit(); | 1367 | defer list.deinit(); |
lib/std/ascii.zig+2-2| ... | @@ -301,7 +301,7 @@ test "lowerString" { | ... | @@ -301,7 +301,7 @@ test "lowerString" { |
| 301 | 301 | ||
| 302 | /// Allocates a lower case copy of `ascii_string`. | 302 | /// Allocates a lower case copy of `ascii_string`. |
| 303 | /// Caller owns returned string and must free with `allocator`. | 303 | /// Caller owns returned string and must free with `allocator`. |
| 304 | pub fn allocLowerString(allocator: *std.mem.Allocator, ascii_string: []const u8) ![]u8 { | 304 | pub fn allocLowerString(allocator: std.mem.Allocator, ascii_string: []const u8) ![]u8 { |
| 305 | const result = try allocator.alloc(u8, ascii_string.len); | 305 | const result = try allocator.alloc(u8, ascii_string.len); |
| 306 | return lowerString(result, ascii_string); | 306 | return lowerString(result, ascii_string); |
| 307 | } | 307 | } |
| ... | @@ -330,7 +330,7 @@ test "upperString" { | ... | @@ -330,7 +330,7 @@ test "upperString" { |
| 330 | 330 | ||
| 331 | /// Allocates an upper case copy of `ascii_string`. | 331 | /// Allocates an upper case copy of `ascii_string`. |
| 332 | /// Caller owns returned string and must free with `allocator`. | 332 | /// Caller owns returned string and must free with `allocator`. |
| 333 | pub fn allocUpperString(allocator: *std.mem.Allocator, ascii_string: []const u8) ![]u8 { | 333 | pub fn allocUpperString(allocator: std.mem.Allocator, ascii_string: []const u8) ![]u8 { |
| 334 | const result = try allocator.alloc(u8, ascii_string.len); | 334 | const result = try allocator.alloc(u8, ascii_string.len); |
| 335 | return upperString(result, ascii_string); | 335 | return upperString(result, ascii_string); |
| 336 | } | 336 | } |
lib/std/atomic/queue.zig+3-3| ... | @@ -156,7 +156,7 @@ pub fn Queue(comptime T: type) type { | ... | @@ -156,7 +156,7 @@ pub fn Queue(comptime T: type) type { |
| 156 | } | 156 | } |
| 157 | 157 | ||
| 158 | const Context = struct { | 158 | const Context = struct { |
| 159 | allocator: *std.mem.Allocator, | 159 | allocator: std.mem.Allocator, |
| 160 | queue: *Queue(i32), | 160 | queue: *Queue(i32), |
| 161 | put_sum: isize, | 161 | put_sum: isize, |
| 162 | get_sum: isize, | 162 | get_sum: isize, |
| ... | @@ -176,8 +176,8 @@ test "std.atomic.Queue" { | ... | @@ -176,8 +176,8 @@ test "std.atomic.Queue" { |
| 176 | var plenty_of_memory = try std.heap.page_allocator.alloc(u8, 300 * 1024); | 176 | var plenty_of_memory = try std.heap.page_allocator.alloc(u8, 300 * 1024); |
| 177 | defer std.heap.page_allocator.free(plenty_of_memory); | 177 | defer std.heap.page_allocator.free(plenty_of_memory); |
| 178 | 178 | ||
| 179 | var fixed_buffer_allocator = std.heap.ThreadSafeFixedBufferAllocator.init(plenty_of_memory); | 179 | var fixed_buffer_allocator = std.heap.FixedBufferAllocator.init(plenty_of_memory); |
| 180 | var a = &fixed_buffer_allocator.allocator; | 180 | var a = fixed_buffer_allocator.getThreadSafeAllocator(); |
| 181 | 181 | ||
| 182 | var queue = Queue(i32).init(); | 182 | var queue = Queue(i32).init(); |
| 183 | var context = Context{ | 183 | var context = Context{ |
lib/std/atomic/stack.zig+3-3| ... | @@ -69,7 +69,7 @@ pub fn Stack(comptime T: type) type { | ... | @@ -69,7 +69,7 @@ pub fn Stack(comptime T: type) type { |
| 69 | } | 69 | } |
| 70 | 70 | ||
| 71 | const Context = struct { | 71 | const Context = struct { |
| 72 | allocator: *std.mem.Allocator, | 72 | allocator: std.mem.Allocator, |
| 73 | stack: *Stack(i32), | 73 | stack: *Stack(i32), |
| 74 | put_sum: isize, | 74 | put_sum: isize, |
| 75 | get_sum: isize, | 75 | get_sum: isize, |
| ... | @@ -88,8 +88,8 @@ test "std.atomic.stack" { | ... | @@ -88,8 +88,8 @@ test "std.atomic.stack" { |
| 88 | var plenty_of_memory = try std.heap.page_allocator.alloc(u8, 300 * 1024); | 88 | var plenty_of_memory = try std.heap.page_allocator.alloc(u8, 300 * 1024); |
| 89 | defer std.heap.page_allocator.free(plenty_of_memory); | 89 | defer std.heap.page_allocator.free(plenty_of_memory); |
| 90 | 90 | ||
| 91 | var fixed_buffer_allocator = std.heap.ThreadSafeFixedBufferAllocator.init(plenty_of_memory); | 91 | var fixed_buffer_allocator = std.heap.FixedBufferAllocator.init(plenty_of_memory); |
| 92 | var a = &fixed_buffer_allocator.allocator; | 92 | var a = fixed_buffer_allocator.getThreadSafeAllocator(); |
| 93 | 93 | ||
| 94 | var stack = Stack(i32).init(); | 94 | var stack = Stack(i32).init(); |
| 95 | var context = Context{ | 95 | var context = Context{ |
lib/std/bit_set.zig+9-9| ... | @@ -476,7 +476,7 @@ pub const DynamicBitSetUnmanaged = struct { | ... | @@ -476,7 +476,7 @@ pub const DynamicBitSetUnmanaged = struct { |
| 476 | 476 | ||
| 477 | /// Creates a bit set with no elements present. | 477 | /// Creates a bit set with no elements present. |
| 478 | /// If bit_length is not zero, deinit must eventually be called. | 478 | /// If bit_length is not zero, deinit must eventually be called. |
| 479 | pub fn initEmpty(bit_length: usize, allocator: *Allocator) !Self { | 479 | pub fn initEmpty(bit_length: usize, allocator: Allocator) !Self { |
| 480 | var self = Self{}; | 480 | var self = Self{}; |
| 481 | try self.resize(bit_length, false, allocator); | 481 | try self.resize(bit_length, false, allocator); |
| 482 | return self; | 482 | return self; |
| ... | @@ -484,7 +484,7 @@ pub const DynamicBitSetUnmanaged = struct { | ... | @@ -484,7 +484,7 @@ pub const DynamicBitSetUnmanaged = struct { |
| 484 | 484 | ||
| 485 | /// Creates a bit set with all elements present. | 485 | /// Creates a bit set with all elements present. |
| 486 | /// If bit_length is not zero, deinit must eventually be called. | 486 | /// If bit_length is not zero, deinit must eventually be called. |
| 487 | pub fn initFull(bit_length: usize, allocator: *Allocator) !Self { | 487 | pub fn initFull(bit_length: usize, allocator: Allocator) !Self { |
| 488 | var self = Self{}; | 488 | var self = Self{}; |
| 489 | try self.resize(bit_length, true, allocator); | 489 | try self.resize(bit_length, true, allocator); |
| 490 | return self; | 490 | return self; |
| ... | @@ -493,7 +493,7 @@ pub const DynamicBitSetUnmanaged = struct { | ... | @@ -493,7 +493,7 @@ pub const DynamicBitSetUnmanaged = struct { |
| 493 | /// Resizes to a new bit_length. If the new length is larger | 493 | /// Resizes to a new bit_length. If the new length is larger |
| 494 | /// than the old length, fills any added bits with `fill`. | 494 | /// than the old length, fills any added bits with `fill`. |
| 495 | /// If new_len is not zero, deinit must eventually be called. | 495 | /// If new_len is not zero, deinit must eventually be called. |
| 496 | pub fn resize(self: *@This(), new_len: usize, fill: bool, allocator: *Allocator) !void { | 496 | pub fn resize(self: *@This(), new_len: usize, fill: bool, allocator: Allocator) !void { |
| 497 | const old_len = self.bit_length; | 497 | const old_len = self.bit_length; |
| 498 | 498 | ||
| 499 | const old_masks = numMasks(old_len); | 499 | const old_masks = numMasks(old_len); |
| ... | @@ -556,12 +556,12 @@ pub const DynamicBitSetUnmanaged = struct { | ... | @@ -556,12 +556,12 @@ pub const DynamicBitSetUnmanaged = struct { |
| 556 | /// deinitializes the array and releases its memory. | 556 | /// deinitializes the array and releases its memory. |
| 557 | /// The passed allocator must be the same one used for | 557 | /// The passed allocator must be the same one used for |
| 558 | /// init* or resize in the past. | 558 | /// init* or resize in the past. |
| 559 | pub fn deinit(self: *Self, allocator: *Allocator) void { | 559 | pub fn deinit(self: *Self, allocator: Allocator) void { |
| 560 | self.resize(0, false, allocator) catch unreachable; | 560 | self.resize(0, false, allocator) catch unreachable; |
| 561 | } | 561 | } |
| 562 | 562 | ||
| 563 | /// Creates a duplicate of this bit set, using the new allocator. | 563 | /// Creates a duplicate of this bit set, using the new allocator. |
| 564 | pub fn clone(self: *const Self, new_allocator: *Allocator) !Self { | 564 | pub fn clone(self: *const Self, new_allocator: Allocator) !Self { |
| 565 | const num_masks = numMasks(self.bit_length); | 565 | const num_masks = numMasks(self.bit_length); |
| 566 | var copy = Self{}; | 566 | var copy = Self{}; |
| 567 | try copy.resize(self.bit_length, false, new_allocator); | 567 | try copy.resize(self.bit_length, false, new_allocator); |
| ... | @@ -742,13 +742,13 @@ pub const DynamicBitSet = struct { | ... | @@ -742,13 +742,13 @@ pub const DynamicBitSet = struct { |
| 742 | pub const ShiftInt = std.math.Log2Int(MaskInt); | 742 | pub const ShiftInt = std.math.Log2Int(MaskInt); |
| 743 | 743 | ||
| 744 | /// The allocator used by this bit set | 744 | /// The allocator used by this bit set |
| 745 | allocator: *Allocator, | 745 | allocator: Allocator, |
| 746 | 746 | ||
| 747 | /// The number of valid items in this bit set | 747 | /// The number of valid items in this bit set |
| 748 | unmanaged: DynamicBitSetUnmanaged = .{}, | 748 | unmanaged: DynamicBitSetUnmanaged = .{}, |
| 749 | 749 | ||
| 750 | /// Creates a bit set with no elements present. | 750 | /// Creates a bit set with no elements present. |
| 751 | pub fn initEmpty(bit_length: usize, allocator: *Allocator) !Self { | 751 | pub fn initEmpty(bit_length: usize, allocator: Allocator) !Self { |
| 752 | return Self{ | 752 | return Self{ |
| 753 | .unmanaged = try DynamicBitSetUnmanaged.initEmpty(bit_length, allocator), | 753 | .unmanaged = try DynamicBitSetUnmanaged.initEmpty(bit_length, allocator), |
| 754 | .allocator = allocator, | 754 | .allocator = allocator, |
| ... | @@ -756,7 +756,7 @@ pub const DynamicBitSet = struct { | ... | @@ -756,7 +756,7 @@ pub const DynamicBitSet = struct { |
| 756 | } | 756 | } |
| 757 | 757 | ||
| 758 | /// Creates a bit set with all elements present. | 758 | /// Creates a bit set with all elements present. |
| 759 | pub fn initFull(bit_length: usize, allocator: *Allocator) !Self { | 759 | pub fn initFull(bit_length: usize, allocator: Allocator) !Self { |
| 760 | return Self{ | 760 | return Self{ |
| 761 | .unmanaged = try DynamicBitSetUnmanaged.initFull(bit_length, allocator), | 761 | .unmanaged = try DynamicBitSetUnmanaged.initFull(bit_length, allocator), |
| 762 | .allocator = allocator, | 762 | .allocator = allocator, |
| ... | @@ -777,7 +777,7 @@ pub const DynamicBitSet = struct { | ... | @@ -777,7 +777,7 @@ pub const DynamicBitSet = struct { |
| 777 | } | 777 | } |
| 778 | 778 | ||
| 779 | /// Creates a duplicate of this bit set, using the new allocator. | 779 | /// Creates a duplicate of this bit set, using the new allocator. |
| 780 | pub fn clone(self: *const Self, new_allocator: *Allocator) !Self { | 780 | pub fn clone(self: *const Self, new_allocator: Allocator) !Self { |
| 781 | return Self{ | 781 | return Self{ |
| 782 | .unmanaged = try self.unmanaged.clone(new_allocator), | 782 | .unmanaged = try self.unmanaged.clone(new_allocator), |
| 783 | .allocator = new_allocator, | 783 | .allocator = new_allocator, |
lib/std/buf_map.zig+1-1| ... | @@ -14,7 +14,7 @@ pub const BufMap = struct { | ... | @@ -14,7 +14,7 @@ pub const BufMap = struct { |
| 14 | /// Create a BufMap backed by a specific allocator. | 14 | /// Create a BufMap backed by a specific allocator. |
| 15 | /// That allocator will be used for both backing allocations | 15 | /// That allocator will be used for both backing allocations |
| 16 | /// and string deduplication. | 16 | /// and string deduplication. |
| 17 | pub fn init(allocator: *Allocator) BufMap { | 17 | pub fn init(allocator: Allocator) BufMap { |
| 18 | var self = BufMap{ .hash_map = BufMapHashMap.init(allocator) }; | 18 | var self = BufMap{ .hash_map = BufMapHashMap.init(allocator) }; |
| 19 | return self; | 19 | return self; |
| 20 | } | 20 | } |
lib/std/buf_set.zig+2-2| ... | @@ -16,7 +16,7 @@ pub const BufSet = struct { | ... | @@ -16,7 +16,7 @@ pub const BufSet = struct { |
| 16 | /// Create a BufSet using an allocator. The allocator will | 16 | /// Create a BufSet using an allocator. The allocator will |
| 17 | /// be used internally for both backing allocations and | 17 | /// be used internally for both backing allocations and |
| 18 | /// string duplication. | 18 | /// string duplication. |
| 19 | pub fn init(a: *Allocator) BufSet { | 19 | pub fn init(a: Allocator) BufSet { |
| 20 | var self = BufSet{ .hash_map = BufSetHashMap.init(a) }; | 20 | var self = BufSet{ .hash_map = BufSetHashMap.init(a) }; |
| 21 | return self; | 21 | return self; |
| 22 | } | 22 | } |
| ... | @@ -67,7 +67,7 @@ pub const BufSet = struct { | ... | @@ -67,7 +67,7 @@ pub const BufSet = struct { |
| 67 | } | 67 | } |
| 68 | 68 | ||
| 69 | /// Get the allocator used by this set | 69 | /// Get the allocator used by this set |
| 70 | pub fn allocator(self: *const BufSet) *Allocator { | 70 | pub fn allocator(self: *const BufSet) Allocator { |
| 71 | return self.hash_map.allocator; | 71 | return self.hash_map.allocator; |
| 72 | } | 72 | } |
| 73 | 73 |
lib/std/build.zig+9-9| ... | @@ -28,7 +28,7 @@ pub const OptionsStep = @import("build/OptionsStep.zig"); | ... | @@ -28,7 +28,7 @@ pub const OptionsStep = @import("build/OptionsStep.zig"); |
| 28 | pub const Builder = struct { | 28 | pub const Builder = struct { |
| 29 | install_tls: TopLevelStep, | 29 | install_tls: TopLevelStep, |
| 30 | uninstall_tls: TopLevelStep, | 30 | uninstall_tls: TopLevelStep, |
| 31 | allocator: *Allocator, | 31 | allocator: Allocator, |
| 32 | user_input_options: UserInputOptionsMap, | 32 | user_input_options: UserInputOptionsMap, |
| 33 | available_options_map: AvailableOptionsMap, | 33 | available_options_map: AvailableOptionsMap, |
| 34 | available_options_list: ArrayList(AvailableOption), | 34 | available_options_list: ArrayList(AvailableOption), |
| ... | @@ -134,7 +134,7 @@ pub const Builder = struct { | ... | @@ -134,7 +134,7 @@ pub const Builder = struct { |
| 134 | }; | 134 | }; |
| 135 | 135 | ||
| 136 | pub fn create( | 136 | pub fn create( |
| 137 | allocator: *Allocator, | 137 | allocator: Allocator, |
| 138 | zig_exe: []const u8, | 138 | zig_exe: []const u8, |
| 139 | build_root: []const u8, | 139 | build_root: []const u8, |
| 140 | cache_root: []const u8, | 140 | cache_root: []const u8, |
| ... | @@ -1285,7 +1285,7 @@ test "builder.findProgram compiles" { | ... | @@ -1285,7 +1285,7 @@ test "builder.findProgram compiles" { |
| 1285 | defer arena.deinit(); | 1285 | defer arena.deinit(); |
| 1286 | 1286 | ||
| 1287 | const builder = try Builder.create( | 1287 | const builder = try Builder.create( |
| 1288 | &arena.allocator, | 1288 | arena.getAllocator(), |
| 1289 | "zig", | 1289 | "zig", |
| 1290 | "zig-cache", | 1290 | "zig-cache", |
| 1291 | "zig-cache", | 1291 | "zig-cache", |
| ... | @@ -3077,7 +3077,7 @@ pub const Step = struct { | ... | @@ -3077,7 +3077,7 @@ pub const Step = struct { |
| 3077 | custom, | 3077 | custom, |
| 3078 | }; | 3078 | }; |
| 3079 | 3079 | ||
| 3080 | pub fn init(id: Id, name: []const u8, allocator: *Allocator, makeFn: fn (*Step) anyerror!void) Step { | 3080 | pub fn init(id: Id, name: []const u8, allocator: Allocator, makeFn: fn (*Step) anyerror!void) Step { |
| 3081 | return Step{ | 3081 | return Step{ |
| 3082 | .id = id, | 3082 | .id = id, |
| 3083 | .name = allocator.dupe(u8, name) catch unreachable, | 3083 | .name = allocator.dupe(u8, name) catch unreachable, |
| ... | @@ -3087,7 +3087,7 @@ pub const Step = struct { | ... | @@ -3087,7 +3087,7 @@ pub const Step = struct { |
| 3087 | .done_flag = false, | 3087 | .done_flag = false, |
| 3088 | }; | 3088 | }; |
| 3089 | } | 3089 | } |
| 3090 | pub fn initNoOp(id: Id, name: []const u8, allocator: *Allocator) Step { | 3090 | pub fn initNoOp(id: Id, name: []const u8, allocator: Allocator) Step { |
| 3091 | return init(id, name, allocator, makeNoOp); | 3091 | return init(id, name, allocator, makeNoOp); |
| 3092 | } | 3092 | } |
| 3093 | 3093 | ||
| ... | @@ -3114,7 +3114,7 @@ pub const Step = struct { | ... | @@ -3114,7 +3114,7 @@ pub const Step = struct { |
| 3114 | } | 3114 | } |
| 3115 | }; | 3115 | }; |
| 3116 | 3116 | ||
| 3117 | fn doAtomicSymLinks(allocator: *Allocator, output_path: []const u8, filename_major_only: []const u8, filename_name_only: []const u8) !void { | 3117 | fn doAtomicSymLinks(allocator: Allocator, output_path: []const u8, filename_major_only: []const u8, filename_name_only: []const u8) !void { |
| 3118 | const out_dir = fs.path.dirname(output_path) orelse "."; | 3118 | const out_dir = fs.path.dirname(output_path) orelse "."; |
| 3119 | const out_basename = fs.path.basename(output_path); | 3119 | const out_basename = fs.path.basename(output_path); |
| 3120 | // sym link for libfoo.so.1 to libfoo.so.1.2.3 | 3120 | // sym link for libfoo.so.1 to libfoo.so.1.2.3 |
| ... | @@ -3138,7 +3138,7 @@ fn doAtomicSymLinks(allocator: *Allocator, output_path: []const u8, filename_maj | ... | @@ -3138,7 +3138,7 @@ fn doAtomicSymLinks(allocator: *Allocator, output_path: []const u8, filename_maj |
| 3138 | } | 3138 | } |
| 3139 | 3139 | ||
| 3140 | /// Returned slice must be freed by the caller. | 3140 | /// Returned slice must be freed by the caller. |
| 3141 | fn findVcpkgRoot(allocator: *Allocator) !?[]const u8 { | 3141 | fn findVcpkgRoot(allocator: Allocator) !?[]const u8 { |
| 3142 | const appdata_path = try fs.getAppDataDir(allocator, "vcpkg"); | 3142 | const appdata_path = try fs.getAppDataDir(allocator, "vcpkg"); |
| 3143 | defer allocator.free(appdata_path); | 3143 | defer allocator.free(appdata_path); |
| 3144 | 3144 | ||
| ... | @@ -3207,7 +3207,7 @@ test "Builder.dupePkg()" { | ... | @@ -3207,7 +3207,7 @@ test "Builder.dupePkg()" { |
| 3207 | var arena = std.heap.ArenaAllocator.init(std.testing.allocator); | 3207 | var arena = std.heap.ArenaAllocator.init(std.testing.allocator); |
| 3208 | defer arena.deinit(); | 3208 | defer arena.deinit(); |
| 3209 | var builder = try Builder.create( | 3209 | var builder = try Builder.create( |
| 3210 | &arena.allocator, | 3210 | arena.getAllocator(), |
| 3211 | "test", | 3211 | "test", |
| 3212 | "test", | 3212 | "test", |
| 3213 | "test", | 3213 | "test", |
| ... | @@ -3252,7 +3252,7 @@ test "LibExeObjStep.addPackage" { | ... | @@ -3252,7 +3252,7 @@ test "LibExeObjStep.addPackage" { |
| 3252 | defer arena.deinit(); | 3252 | defer arena.deinit(); |
| 3253 | 3253 | ||
| 3254 | var builder = try Builder.create( | 3254 | var builder = try Builder.create( |
| 3255 | &arena.allocator, | 3255 | arena.getAllocator(), |
| 3256 | "test", | 3256 | "test", |
| 3257 | "test", | 3257 | "test", |
| 3258 | "test", | 3258 | "test", |
lib/std/build/InstallRawStep.zig+2-2| ... | @@ -40,7 +40,7 @@ const BinaryElfOutput = struct { | ... | @@ -40,7 +40,7 @@ const BinaryElfOutput = struct { |
| 40 | self.segments.deinit(); | 40 | self.segments.deinit(); |
| 41 | } | 41 | } |
| 42 | 42 | ||
| 43 | pub fn parse(allocator: *Allocator, elf_file: File) !Self { | 43 | pub fn parse(allocator: Allocator, elf_file: File) !Self { |
| 44 | var self: Self = .{ | 44 | var self: Self = .{ |
| 45 | .segments = ArrayList(*BinaryElfSegment).init(allocator), | 45 | .segments = ArrayList(*BinaryElfSegment).init(allocator), |
| 46 | .sections = ArrayList(*BinaryElfSection).init(allocator), | 46 | .sections = ArrayList(*BinaryElfSection).init(allocator), |
| ... | @@ -298,7 +298,7 @@ fn containsValidAddressRange(segments: []*BinaryElfSegment) bool { | ... | @@ -298,7 +298,7 @@ fn containsValidAddressRange(segments: []*BinaryElfSegment) bool { |
| 298 | return true; | 298 | return true; |
| 299 | } | 299 | } |
| 300 | 300 | ||
| 301 | fn emitRaw(allocator: *Allocator, elf_path: []const u8, raw_path: []const u8, format: RawFormat) !void { | 301 | fn emitRaw(allocator: Allocator, elf_path: []const u8, raw_path: []const u8, format: RawFormat) !void { |
| 302 | var elf_file = try fs.cwd().openFile(elf_path, .{}); | 302 | var elf_file = try fs.cwd().openFile(elf_path, .{}); |
| 303 | defer elf_file.close(); | 303 | defer elf_file.close(); |
| 304 | 304 |
lib/std/build/OptionsStep.zig+1-1| ... | @@ -274,7 +274,7 @@ test "OptionsStep" { | ... | @@ -274,7 +274,7 @@ test "OptionsStep" { |
| 274 | var arena = std.heap.ArenaAllocator.init(std.testing.allocator); | 274 | var arena = std.heap.ArenaAllocator.init(std.testing.allocator); |
| 275 | defer arena.deinit(); | 275 | defer arena.deinit(); |
| 276 | var builder = try Builder.create( | 276 | var builder = try Builder.create( |
| 277 | &arena.allocator, | 277 | arena.getAllocator(), |
| 278 | "test", | 278 | "test", |
| 279 | "test", | 279 | "test", |
| 280 | "test", | 280 | "test", |
lib/std/builtin.zig+1-1| ... | @@ -75,7 +75,7 @@ pub const StackTrace = struct { | ... | @@ -75,7 +75,7 @@ pub const StackTrace = struct { |
| 75 | }; | 75 | }; |
| 76 | const tty_config = std.debug.detectTTYConfig(); | 76 | const tty_config = std.debug.detectTTYConfig(); |
| 77 | try writer.writeAll("\n"); | 77 | try writer.writeAll("\n"); |
| 78 | std.debug.writeStackTrace(self, writer, &arena.allocator, debug_info, tty_config) catch |err| { | 78 | std.debug.writeStackTrace(self, writer, arena.getAllocator(), debug_info, tty_config) catch |err| { |
| 79 | try writer.print("Unable to print stack trace: {s}\n", .{@errorName(err)}); | 79 | try writer.print("Unable to print stack trace: {s}\n", .{@errorName(err)}); |
| 80 | }; | 80 | }; |
| 81 | try writer.writeAll("\n"); | 81 | try writer.writeAll("\n"); |
lib/std/child_process.zig+8-8| ... | @@ -23,7 +23,7 @@ pub const ChildProcess = struct { | ... | @@ -23,7 +23,7 @@ pub const ChildProcess = struct { |
| 23 | handle: if (builtin.os.tag == .windows) windows.HANDLE else void, | 23 | handle: if (builtin.os.tag == .windows) windows.HANDLE else void, |
| 24 | thread_handle: if (builtin.os.tag == .windows) windows.HANDLE else void, | 24 | thread_handle: if (builtin.os.tag == .windows) windows.HANDLE else void, |
| 25 | 25 | ||
| 26 | allocator: *mem.Allocator, | 26 | allocator: mem.Allocator, |
| 27 | 27 | ||
| 28 | stdin: ?File, | 28 | stdin: ?File, |
| 29 | stdout: ?File, | 29 | stdout: ?File, |
| ... | @@ -90,7 +90,7 @@ pub const ChildProcess = struct { | ... | @@ -90,7 +90,7 @@ pub const ChildProcess = struct { |
| 90 | 90 | ||
| 91 | /// First argument in argv is the executable. | 91 | /// First argument in argv is the executable. |
| 92 | /// On success must call deinit. | 92 | /// On success must call deinit. |
| 93 | pub fn init(argv: []const []const u8, allocator: *mem.Allocator) !*ChildProcess { | 93 | pub fn init(argv: []const []const u8, allocator: mem.Allocator) !*ChildProcess { |
| 94 | const child = try allocator.create(ChildProcess); | 94 | const child = try allocator.create(ChildProcess); |
| 95 | child.* = ChildProcess{ | 95 | child.* = ChildProcess{ |
| 96 | .allocator = allocator, | 96 | .allocator = allocator, |
| ... | @@ -329,7 +329,7 @@ pub const ChildProcess = struct { | ... | @@ -329,7 +329,7 @@ pub const ChildProcess = struct { |
| 329 | /// Spawns a child process, waits for it, collecting stdout and stderr, and then returns. | 329 | /// Spawns a child process, waits for it, collecting stdout and stderr, and then returns. |
| 330 | /// If it succeeds, the caller owns result.stdout and result.stderr memory. | 330 | /// If it succeeds, the caller owns result.stdout and result.stderr memory. |
| 331 | pub fn exec(args: struct { | 331 | pub fn exec(args: struct { |
| 332 | allocator: *mem.Allocator, | 332 | allocator: mem.Allocator, |
| 333 | argv: []const []const u8, | 333 | argv: []const []const u8, |
| 334 | cwd: ?[]const u8 = null, | 334 | cwd: ?[]const u8 = null, |
| 335 | cwd_dir: ?fs.Dir = null, | 335 | cwd_dir: ?fs.Dir = null, |
| ... | @@ -541,7 +541,7 @@ pub const ChildProcess = struct { | ... | @@ -541,7 +541,7 @@ pub const ChildProcess = struct { |
| 541 | 541 | ||
| 542 | var arena_allocator = std.heap.ArenaAllocator.init(self.allocator); | 542 | var arena_allocator = std.heap.ArenaAllocator.init(self.allocator); |
| 543 | defer arena_allocator.deinit(); | 543 | defer arena_allocator.deinit(); |
| 544 | const arena = &arena_allocator.allocator; | 544 | const arena = arena_allocator.getAllocator(); |
| 545 | 545 | ||
| 546 | // The POSIX standard does not allow malloc() between fork() and execve(), | 546 | // The POSIX standard does not allow malloc() between fork() and execve(), |
| 547 | // and `self.allocator` may be a libc allocator. | 547 | // and `self.allocator` may be a libc allocator. |
| ... | @@ -931,7 +931,7 @@ fn windowsCreateProcess(app_name: [*:0]u16, cmd_line: [*:0]u16, envp_ptr: ?[*]u1 | ... | @@ -931,7 +931,7 @@ fn windowsCreateProcess(app_name: [*:0]u16, cmd_line: [*:0]u16, envp_ptr: ?[*]u1 |
| 931 | } | 931 | } |
| 932 | 932 | ||
| 933 | /// Caller must dealloc. | 933 | /// Caller must dealloc. |
| 934 | fn windowsCreateCommandLine(allocator: *mem.Allocator, argv: []const []const u8) ![:0]u8 { | 934 | fn windowsCreateCommandLine(allocator: mem.Allocator, argv: []const []const u8) ![:0]u8 { |
| 935 | var buf = std.ArrayList(u8).init(allocator); | 935 | var buf = std.ArrayList(u8).init(allocator); |
| 936 | defer buf.deinit(); | 936 | defer buf.deinit(); |
| 937 | 937 | ||
| ... | @@ -1081,7 +1081,7 @@ fn readIntFd(fd: i32) !ErrInt { | ... | @@ -1081,7 +1081,7 @@ fn readIntFd(fd: i32) !ErrInt { |
| 1081 | } | 1081 | } |
| 1082 | 1082 | ||
| 1083 | /// Caller must free result. | 1083 | /// Caller must free result. |
| 1084 | pub fn createWindowsEnvBlock(allocator: *mem.Allocator, env_map: *const BufMap) ![]u16 { | 1084 | pub fn createWindowsEnvBlock(allocator: mem.Allocator, env_map: *const BufMap) ![]u16 { |
| 1085 | // count bytes needed | 1085 | // count bytes needed |
| 1086 | const max_chars_needed = x: { | 1086 | const max_chars_needed = x: { |
| 1087 | var max_chars_needed: usize = 4; // 4 for the final 4 null bytes | 1087 | var max_chars_needed: usize = 4; // 4 for the final 4 null bytes |
| ... | @@ -1117,7 +1117,7 @@ pub fn createWindowsEnvBlock(allocator: *mem.Allocator, env_map: *const BufMap) | ... | @@ -1117,7 +1117,7 @@ pub fn createWindowsEnvBlock(allocator: *mem.Allocator, env_map: *const BufMap) |
| 1117 | return allocator.shrink(result, i); | 1117 | return allocator.shrink(result, i); |
| 1118 | } | 1118 | } |
| 1119 | 1119 | ||
| 1120 | pub fn createNullDelimitedEnvMap(arena: *mem.Allocator, env_map: *const std.BufMap) ![:null]?[*:0]u8 { | 1120 | pub fn createNullDelimitedEnvMap(arena: mem.Allocator, env_map: *const std.BufMap) ![:null]?[*:0]u8 { |
| 1121 | const envp_count = env_map.count(); | 1121 | const envp_count = env_map.count(); |
| 1122 | const envp_buf = try arena.allocSentinel(?[*:0]u8, envp_count, null); | 1122 | const envp_buf = try arena.allocSentinel(?[*:0]u8, envp_count, null); |
| 1123 | { | 1123 | { |
| ... | @@ -1149,7 +1149,7 @@ test "createNullDelimitedEnvMap" { | ... | @@ -1149,7 +1149,7 @@ test "createNullDelimitedEnvMap" { |
| 1149 | 1149 | ||
| 1150 | var arena = std.heap.ArenaAllocator.init(allocator); | 1150 | var arena = std.heap.ArenaAllocator.init(allocator); |
| 1151 | defer arena.deinit(); | 1151 | defer arena.deinit(); |
| 1152 | const environ = try createNullDelimitedEnvMap(&arena.allocator, &envmap); | 1152 | const environ = try createNullDelimitedEnvMap(arena.getAllocator(), &envmap); |
| 1153 | 1153 | ||
| 1154 | try testing.expectEqual(@as(usize, 5), environ.len); | 1154 | try testing.expectEqual(@as(usize, 5), environ.len); |
| 1155 | 1155 |
lib/std/coff.zig+3-3| ... | @@ -98,7 +98,7 @@ pub const CoffError = error{ | ... | @@ -98,7 +98,7 @@ pub const CoffError = error{ |
| 98 | // Official documentation of the format: https://docs.microsoft.com/en-us/windows/win32/debug/pe-format | 98 | // Official documentation of the format: https://docs.microsoft.com/en-us/windows/win32/debug/pe-format |
| 99 | pub const Coff = struct { | 99 | pub const Coff = struct { |
| 100 | in_file: File, | 100 | in_file: File, |
| 101 | allocator: *mem.Allocator, | 101 | allocator: mem.Allocator, |
| 102 | 102 | ||
| 103 | coff_header: CoffHeader, | 103 | coff_header: CoffHeader, |
| 104 | pe_header: OptionalHeader, | 104 | pe_header: OptionalHeader, |
| ... | @@ -107,7 +107,7 @@ pub const Coff = struct { | ... | @@ -107,7 +107,7 @@ pub const Coff = struct { |
| 107 | guid: [16]u8, | 107 | guid: [16]u8, |
| 108 | age: u32, | 108 | age: u32, |
| 109 | 109 | ||
| 110 | pub fn init(allocator: *mem.Allocator, in_file: File) Coff { | 110 | pub fn init(allocator: mem.Allocator, in_file: File) Coff { |
| 111 | return Coff{ | 111 | return Coff{ |
| 112 | .in_file = in_file, | 112 | .in_file = in_file, |
| 113 | .allocator = allocator, | 113 | .allocator = allocator, |
| ... | @@ -324,7 +324,7 @@ pub const Coff = struct { | ... | @@ -324,7 +324,7 @@ pub const Coff = struct { |
| 324 | } | 324 | } |
| 325 | 325 | ||
| 326 | // Return an owned slice full of the section data | 326 | // Return an owned slice full of the section data |
| 327 | pub fn getSectionData(self: *Coff, comptime name: []const u8, allocator: *mem.Allocator) ![]u8 { | 327 | pub fn getSectionData(self: *Coff, comptime name: []const u8, allocator: mem.Allocator) ![]u8 { |
| 328 | const sec = for (self.sections.items) |*sec| { | 328 | const sec = for (self.sections.items) |*sec| { |
| 329 | if (mem.eql(u8, sec.header.name[0..name.len], name)) { | 329 | if (mem.eql(u8, sec.header.name[0..name.len], name)) { |
| 330 | break sec; | 330 | break sec; |
lib/std/compress/gzip.zig+3-3| ... | @@ -24,7 +24,7 @@ pub fn GzipStream(comptime ReaderType: type) type { | ... | @@ -24,7 +24,7 @@ pub fn GzipStream(comptime ReaderType: type) type { |
| 24 | error{ CorruptedData, WrongChecksum }; | 24 | error{ CorruptedData, WrongChecksum }; |
| 25 | pub const Reader = io.Reader(*Self, Error, read); | 25 | pub const Reader = io.Reader(*Self, Error, read); |
| 26 | 26 | ||
| 27 | allocator: *mem.Allocator, | 27 | allocator: mem.Allocator, |
| 28 | inflater: deflate.InflateStream(ReaderType), | 28 | inflater: deflate.InflateStream(ReaderType), |
| 29 | in_reader: ReaderType, | 29 | in_reader: ReaderType, |
| 30 | hasher: std.hash.Crc32, | 30 | hasher: std.hash.Crc32, |
| ... | @@ -37,7 +37,7 @@ pub fn GzipStream(comptime ReaderType: type) type { | ... | @@ -37,7 +37,7 @@ pub fn GzipStream(comptime ReaderType: type) type { |
| 37 | modification_time: u32, | 37 | modification_time: u32, |
| 38 | }, | 38 | }, |
| 39 | 39 | ||
| 40 | fn init(allocator: *mem.Allocator, source: ReaderType) !Self { | 40 | fn init(allocator: mem.Allocator, source: ReaderType) !Self { |
| 41 | // gzip header format is specified in RFC1952 | 41 | // gzip header format is specified in RFC1952 |
| 42 | const header = try source.readBytesNoEof(10); | 42 | const header = try source.readBytesNoEof(10); |
| 43 | 43 | ||
| ... | @@ -152,7 +152,7 @@ pub fn GzipStream(comptime ReaderType: type) type { | ... | @@ -152,7 +152,7 @@ pub fn GzipStream(comptime ReaderType: type) type { |
| 152 | }; | 152 | }; |
| 153 | } | 153 | } |
| 154 | 154 | ||
| 155 | pub fn gzipStream(allocator: *mem.Allocator, reader: anytype) !GzipStream(@TypeOf(reader)) { | 155 | pub fn gzipStream(allocator: mem.Allocator, reader: anytype) !GzipStream(@TypeOf(reader)) { |
| 156 | return GzipStream(@TypeOf(reader)).init(allocator, reader); | 156 | return GzipStream(@TypeOf(reader)).init(allocator, reader); |
| 157 | } | 157 | } |
| 158 | 158 |
lib/std/compress/zlib.zig+3-3| ... | @@ -17,13 +17,13 @@ pub fn ZlibStream(comptime ReaderType: type) type { | ... | @@ -17,13 +17,13 @@ pub fn ZlibStream(comptime ReaderType: type) type { |
| 17 | error{ WrongChecksum, Unsupported }; | 17 | error{ WrongChecksum, Unsupported }; |
| 18 | pub const Reader = io.Reader(*Self, Error, read); | 18 | pub const Reader = io.Reader(*Self, Error, read); |
| 19 | 19 | ||
| 20 | allocator: *mem.Allocator, | 20 | allocator: mem.Allocator, |
| 21 | inflater: deflate.InflateStream(ReaderType), | 21 | inflater: deflate.InflateStream(ReaderType), |
| 22 | in_reader: ReaderType, | 22 | in_reader: ReaderType, |
| 23 | hasher: std.hash.Adler32, | 23 | hasher: std.hash.Adler32, |
| 24 | window_slice: []u8, | 24 | window_slice: []u8, |
| 25 | 25 | ||
| 26 | fn init(allocator: *mem.Allocator, source: ReaderType) !Self { | 26 | fn init(allocator: mem.Allocator, source: ReaderType) !Self { |
| 27 | // Zlib header format is specified in RFC1950 | 27 | // Zlib header format is specified in RFC1950 |
| 28 | const header = try source.readBytesNoEof(2); | 28 | const header = try source.readBytesNoEof(2); |
| 29 | 29 | ||
| ... | @@ -88,7 +88,7 @@ pub fn ZlibStream(comptime ReaderType: type) type { | ... | @@ -88,7 +88,7 @@ pub fn ZlibStream(comptime ReaderType: type) type { |
| 88 | }; | 88 | }; |
| 89 | } | 89 | } |
| 90 | 90 | ||
| 91 | pub fn zlibStream(allocator: *mem.Allocator, reader: anytype) !ZlibStream(@TypeOf(reader)) { | 91 | pub fn zlibStream(allocator: mem.Allocator, reader: anytype) !ZlibStream(@TypeOf(reader)) { |
| 92 | return ZlibStream(@TypeOf(reader)).init(allocator, reader); | 92 | return ZlibStream(@TypeOf(reader)).init(allocator, reader); |
| 93 | } | 93 | } |
| 94 | 94 |
lib/std/crypto/argon2.zig+7-7| ... | @@ -201,7 +201,7 @@ fn initBlocks( | ... | @@ -201,7 +201,7 @@ fn initBlocks( |
| 201 | } | 201 | } |
| 202 | 202 | ||
| 203 | fn processBlocks( | 203 | fn processBlocks( |
| 204 | allocator: *mem.Allocator, | 204 | allocator: mem.Allocator, |
| 205 | blocks: *Blocks, | 205 | blocks: *Blocks, |
| 206 | time: u32, | 206 | time: u32, |
| 207 | memory: u32, | 207 | memory: u32, |
| ... | @@ -240,7 +240,7 @@ fn processBlocksSt( | ... | @@ -240,7 +240,7 @@ fn processBlocksSt( |
| 240 | } | 240 | } |
| 241 | 241 | ||
| 242 | fn processBlocksMt( | 242 | fn processBlocksMt( |
| 243 | allocator: *mem.Allocator, | 243 | allocator: mem.Allocator, |
| 244 | blocks: *Blocks, | 244 | blocks: *Blocks, |
| 245 | time: u32, | 245 | time: u32, |
| 246 | memory: u32, | 246 | memory: u32, |
| ... | @@ -480,7 +480,7 @@ fn indexAlpha( | ... | @@ -480,7 +480,7 @@ fn indexAlpha( |
| 480 | /// | 480 | /// |
| 481 | /// Salt has to be at least 8 bytes length. | 481 | /// Salt has to be at least 8 bytes length. |
| 482 | pub fn kdf( | 482 | pub fn kdf( |
| 483 | allocator: *mem.Allocator, | 483 | allocator: mem.Allocator, |
| 484 | derived_key: []u8, | 484 | derived_key: []u8, |
| 485 | password: []const u8, | 485 | password: []const u8, |
| 486 | salt: []const u8, | 486 | salt: []const u8, |
| ... | @@ -524,7 +524,7 @@ const PhcFormatHasher = struct { | ... | @@ -524,7 +524,7 @@ const PhcFormatHasher = struct { |
| 524 | }; | 524 | }; |
| 525 | 525 | ||
| 526 | pub fn create( | 526 | pub fn create( |
| 527 | allocator: *mem.Allocator, | 527 | allocator: mem.Allocator, |
| 528 | password: []const u8, | 528 | password: []const u8, |
| 529 | params: Params, | 529 | params: Params, |
| 530 | mode: Mode, | 530 | mode: Mode, |
| ... | @@ -550,7 +550,7 @@ const PhcFormatHasher = struct { | ... | @@ -550,7 +550,7 @@ const PhcFormatHasher = struct { |
| 550 | } | 550 | } |
| 551 | 551 | ||
| 552 | pub fn verify( | 552 | pub fn verify( |
| 553 | allocator: *mem.Allocator, | 553 | allocator: mem.Allocator, |
| 554 | str: []const u8, | 554 | str: []const u8, |
| 555 | password: []const u8, | 555 | password: []const u8, |
| 556 | ) HasherError!void { | 556 | ) HasherError!void { |
| ... | @@ -579,7 +579,7 @@ const PhcFormatHasher = struct { | ... | @@ -579,7 +579,7 @@ const PhcFormatHasher = struct { |
| 579 | /// | 579 | /// |
| 580 | /// Only phc encoding is supported. | 580 | /// Only phc encoding is supported. |
| 581 | pub const HashOptions = struct { | 581 | pub const HashOptions = struct { |
| 582 | allocator: ?*mem.Allocator, | 582 | allocator: ?mem.Allocator, |
| 583 | params: Params, | 583 | params: Params, |
| 584 | mode: Mode = .argon2id, | 584 | mode: Mode = .argon2id, |
| 585 | encoding: pwhash.Encoding = .phc, | 585 | encoding: pwhash.Encoding = .phc, |
| ... | @@ -609,7 +609,7 @@ pub fn strHash( | ... | @@ -609,7 +609,7 @@ pub fn strHash( |
| 609 | /// | 609 | /// |
| 610 | /// Allocator is required for argon2. | 610 | /// Allocator is required for argon2. |
| 611 | pub const VerifyOptions = struct { | 611 | pub const VerifyOptions = struct { |
| 612 | allocator: ?*mem.Allocator, | 612 | allocator: ?mem.Allocator, |
| 613 | }; | 613 | }; |
| 614 | 614 | ||
| 615 | /// Verify that a previously computed hash is valid for a given password. | 615 | /// Verify that a previously computed hash is valid for a given password. |
lib/std/crypto/bcrypt.zig+2-2| ... | @@ -368,7 +368,7 @@ const CryptFormatHasher = struct { | ... | @@ -368,7 +368,7 @@ const CryptFormatHasher = struct { |
| 368 | 368 | ||
| 369 | /// Options for hashing a password. | 369 | /// Options for hashing a password. |
| 370 | pub const HashOptions = struct { | 370 | pub const HashOptions = struct { |
| 371 | allocator: ?*mem.Allocator = null, | 371 | allocator: ?mem.Allocator = null, |
| 372 | params: Params, | 372 | params: Params, |
| 373 | encoding: pwhash.Encoding, | 373 | encoding: pwhash.Encoding, |
| 374 | }; | 374 | }; |
| ... | @@ -394,7 +394,7 @@ pub fn strHash( | ... | @@ -394,7 +394,7 @@ pub fn strHash( |
| 394 | 394 | ||
| 395 | /// Options for hash verification. | 395 | /// Options for hash verification. |
| 396 | pub const VerifyOptions = struct { | 396 | pub const VerifyOptions = struct { |
| 397 | allocator: ?*mem.Allocator = null, | 397 | allocator: ?mem.Allocator = null, |
| 398 | }; | 398 | }; |
| 399 | 399 | ||
| 400 | /// Verify that a previously computed hash is valid for a given password. | 400 | /// Verify that a previously computed hash is valid for a given password. |
lib/std/crypto/benchmark.zig+1-1| ... | @@ -363,7 +363,7 @@ pub fn main() !void { | ... | @@ -363,7 +363,7 @@ pub fn main() !void { |
| 363 | 363 | ||
| 364 | var buffer: [1024]u8 = undefined; | 364 | var buffer: [1024]u8 = undefined; |
| 365 | var fixed = std.heap.FixedBufferAllocator.init(buffer[0..]); | 365 | var fixed = std.heap.FixedBufferAllocator.init(buffer[0..]); |
| 366 | const args = try std.process.argsAlloc(&fixed.allocator); | 366 | const args = try std.process.argsAlloc(fixed.getAllocator()); |
| 367 | 367 | ||
| 368 | var filter: ?[]u8 = ""; | 368 | var filter: ?[]u8 = ""; |
| 369 | 369 |
lib/std/crypto/scrypt.zig+8-8| ... | @@ -161,7 +161,7 @@ pub const Params = struct { | ... | @@ -161,7 +161,7 @@ pub const Params = struct { |
| 161 | /// | 161 | /// |
| 162 | /// scrypt is defined in RFC 7914. | 162 | /// scrypt is defined in RFC 7914. |
| 163 | /// | 163 | /// |
| 164 | /// allocator: *mem.Allocator. | 164 | /// allocator: mem.Allocator. |
| 165 | /// | 165 | /// |
| 166 | /// derived_key: Slice of appropriate size for generated key. Generally 16 or 32 bytes in length. | 166 | /// derived_key: Slice of appropriate size for generated key. Generally 16 or 32 bytes in length. |
| 167 | /// May be uninitialized. All bytes will be overwritten. | 167 | /// May be uninitialized. All bytes will be overwritten. |
| ... | @@ -173,7 +173,7 @@ pub const Params = struct { | ... | @@ -173,7 +173,7 @@ pub const Params = struct { |
| 173 | /// | 173 | /// |
| 174 | /// params: Params. | 174 | /// params: Params. |
| 175 | pub fn kdf( | 175 | pub fn kdf( |
| 176 | allocator: *mem.Allocator, | 176 | allocator: mem.Allocator, |
| 177 | derived_key: []u8, | 177 | derived_key: []u8, |
| 178 | password: []const u8, | 178 | password: []const u8, |
| 179 | salt: []const u8, | 179 | salt: []const u8, |
| ... | @@ -406,7 +406,7 @@ const PhcFormatHasher = struct { | ... | @@ -406,7 +406,7 @@ const PhcFormatHasher = struct { |
| 406 | 406 | ||
| 407 | /// Return a non-deterministic hash of the password encoded as a PHC-format string | 407 | /// Return a non-deterministic hash of the password encoded as a PHC-format string |
| 408 | pub fn create( | 408 | pub fn create( |
| 409 | allocator: *mem.Allocator, | 409 | allocator: mem.Allocator, |
| 410 | password: []const u8, | 410 | password: []const u8, |
| 411 | params: Params, | 411 | params: Params, |
| 412 | buf: []u8, | 412 | buf: []u8, |
| ... | @@ -429,7 +429,7 @@ const PhcFormatHasher = struct { | ... | @@ -429,7 +429,7 @@ const PhcFormatHasher = struct { |
| 429 | 429 | ||
| 430 | /// Verify a password against a PHC-format encoded string | 430 | /// Verify a password against a PHC-format encoded string |
| 431 | pub fn verify( | 431 | pub fn verify( |
| 432 | allocator: *mem.Allocator, | 432 | allocator: mem.Allocator, |
| 433 | str: []const u8, | 433 | str: []const u8, |
| 434 | password: []const u8, | 434 | password: []const u8, |
| 435 | ) HasherError!void { | 435 | ) HasherError!void { |
| ... | @@ -455,7 +455,7 @@ const CryptFormatHasher = struct { | ... | @@ -455,7 +455,7 @@ const CryptFormatHasher = struct { |
| 455 | 455 | ||
| 456 | /// Return a non-deterministic hash of the password encoded into the modular crypt format | 456 | /// Return a non-deterministic hash of the password encoded into the modular crypt format |
| 457 | pub fn create( | 457 | pub fn create( |
| 458 | allocator: *mem.Allocator, | 458 | allocator: mem.Allocator, |
| 459 | password: []const u8, | 459 | password: []const u8, |
| 460 | params: Params, | 460 | params: Params, |
| 461 | buf: []u8, | 461 | buf: []u8, |
| ... | @@ -478,7 +478,7 @@ const CryptFormatHasher = struct { | ... | @@ -478,7 +478,7 @@ const CryptFormatHasher = struct { |
| 478 | 478 | ||
| 479 | /// Verify a password against a string in modular crypt format | 479 | /// Verify a password against a string in modular crypt format |
| 480 | pub fn verify( | 480 | pub fn verify( |
| 481 | allocator: *mem.Allocator, | 481 | allocator: mem.Allocator, |
| 482 | str: []const u8, | 482 | str: []const u8, |
| 483 | password: []const u8, | 483 | password: []const u8, |
| 484 | ) HasherError!void { | 484 | ) HasherError!void { |
| ... | @@ -497,7 +497,7 @@ const CryptFormatHasher = struct { | ... | @@ -497,7 +497,7 @@ const CryptFormatHasher = struct { |
| 497 | /// | 497 | /// |
| 498 | /// Allocator is required for scrypt. | 498 | /// Allocator is required for scrypt. |
| 499 | pub const HashOptions = struct { | 499 | pub const HashOptions = struct { |
| 500 | allocator: ?*mem.Allocator, | 500 | allocator: ?mem.Allocator, |
| 501 | params: Params, | 501 | params: Params, |
| 502 | encoding: pwhash.Encoding, | 502 | encoding: pwhash.Encoding, |
| 503 | }; | 503 | }; |
| ... | @@ -520,7 +520,7 @@ pub fn strHash( | ... | @@ -520,7 +520,7 @@ pub fn strHash( |
| 520 | /// | 520 | /// |
| 521 | /// Allocator is required for scrypt. | 521 | /// Allocator is required for scrypt. |
| 522 | pub const VerifyOptions = struct { | 522 | pub const VerifyOptions = struct { |
| 523 | allocator: ?*mem.Allocator, | 523 | allocator: ?mem.Allocator, |
| 524 | }; | 524 | }; |
| 525 | 525 | ||
| 526 | /// Verify that a previously computed hash is valid for a given password. | 526 | /// Verify that a previously computed hash is valid for a given password. |
lib/std/cstr.zig+3-3| ... | @@ -33,7 +33,7 @@ fn testCStrFnsImpl() !void { | ... | @@ -33,7 +33,7 @@ fn testCStrFnsImpl() !void { |
| 33 | 33 | ||
| 34 | /// Returns a mutable, null-terminated slice with the same length as `slice`. | 34 | /// Returns a mutable, null-terminated slice with the same length as `slice`. |
| 35 | /// Caller owns the returned memory. | 35 | /// Caller owns the returned memory. |
| 36 | pub fn addNullByte(allocator: *mem.Allocator, slice: []const u8) ![:0]u8 { | 36 | pub fn addNullByte(allocator: mem.Allocator, slice: []const u8) ![:0]u8 { |
| 37 | const result = try allocator.alloc(u8, slice.len + 1); | 37 | const result = try allocator.alloc(u8, slice.len + 1); |
| 38 | mem.copy(u8, result, slice); | 38 | mem.copy(u8, result, slice); |
| 39 | result[slice.len] = 0; | 39 | result[slice.len] = 0; |
| ... | @@ -48,13 +48,13 @@ test "addNullByte" { | ... | @@ -48,13 +48,13 @@ test "addNullByte" { |
| 48 | } | 48 | } |
| 49 | 49 | ||
| 50 | pub const NullTerminated2DArray = struct { | 50 | pub const NullTerminated2DArray = struct { |
| 51 | allocator: *mem.Allocator, | 51 | allocator: mem.Allocator, |
| 52 | byte_count: usize, | 52 | byte_count: usize, |
| 53 | ptr: ?[*:null]?[*:0]u8, | 53 | ptr: ?[*:null]?[*:0]u8, |
| 54 | 54 | ||
| 55 | /// Takes N lists of strings, concatenates the lists together, and adds a null terminator | 55 | /// Takes N lists of strings, concatenates the lists together, and adds a null terminator |
| 56 | /// Caller must deinit result | 56 | /// Caller must deinit result |
| 57 | pub fn fromSlices(allocator: *mem.Allocator, slices: []const []const []const u8) !NullTerminated2DArray { | 57 | pub fn fromSlices(allocator: mem.Allocator, slices: []const []const []const u8) !NullTerminated2DArray { |
| 58 | var new_len: usize = 1; // 1 for the list null | 58 | var new_len: usize = 1; // 1 for the list null |
| 59 | var byte_count: usize = 0; | 59 | var byte_count: usize = 0; |
| 60 | for (slices) |slice| { | 60 | for (slices) |slice| { |
lib/std/debug.zig+15-14| ... | @@ -29,7 +29,7 @@ pub const LineInfo = struct { | ... | @@ -29,7 +29,7 @@ pub const LineInfo = struct { |
| 29 | line: u64, | 29 | line: u64, |
| 30 | column: u64, | 30 | column: u64, |
| 31 | file_name: []const u8, | 31 | file_name: []const u8, |
| 32 | allocator: ?*mem.Allocator, | 32 | allocator: ?mem.Allocator, |
| 33 | 33 | ||
| 34 | pub fn deinit(self: LineInfo) void { | 34 | pub fn deinit(self: LineInfo) void { |
| 35 | const allocator = self.allocator orelse return; | 35 | const allocator = self.allocator orelse return; |
| ... | @@ -339,7 +339,7 @@ const RESET = "\x1b[0m"; | ... | @@ -339,7 +339,7 @@ const RESET = "\x1b[0m"; |
| 339 | pub fn writeStackTrace( | 339 | pub fn writeStackTrace( |
| 340 | stack_trace: std.builtin.StackTrace, | 340 | stack_trace: std.builtin.StackTrace, |
| 341 | out_stream: anytype, | 341 | out_stream: anytype, |
| 342 | allocator: *mem.Allocator, | 342 | allocator: mem.Allocator, |
| 343 | debug_info: *DebugInfo, | 343 | debug_info: *DebugInfo, |
| 344 | tty_config: TTY.Config, | 344 | tty_config: TTY.Config, |
| 345 | ) !void { | 345 | ) !void { |
| ... | @@ -662,7 +662,7 @@ pub const OpenSelfDebugInfoError = error{ | ... | @@ -662,7 +662,7 @@ pub const OpenSelfDebugInfoError = error{ |
| 662 | }; | 662 | }; |
| 663 | 663 | ||
| 664 | /// TODO resources https://github.com/ziglang/zig/issues/4353 | 664 | /// TODO resources https://github.com/ziglang/zig/issues/4353 |
| 665 | pub fn openSelfDebugInfo(allocator: *mem.Allocator) anyerror!DebugInfo { | 665 | pub fn openSelfDebugInfo(allocator: mem.Allocator) anyerror!DebugInfo { |
| 666 | nosuspend { | 666 | nosuspend { |
| 667 | if (builtin.strip_debug_info) | 667 | if (builtin.strip_debug_info) |
| 668 | return error.MissingDebugInfo; | 668 | return error.MissingDebugInfo; |
| ... | @@ -688,7 +688,7 @@ pub fn openSelfDebugInfo(allocator: *mem.Allocator) anyerror!DebugInfo { | ... | @@ -688,7 +688,7 @@ pub fn openSelfDebugInfo(allocator: *mem.Allocator) anyerror!DebugInfo { |
| 688 | /// it themselves, even on error. | 688 | /// it themselves, even on error. |
| 689 | /// TODO resources https://github.com/ziglang/zig/issues/4353 | 689 | /// TODO resources https://github.com/ziglang/zig/issues/4353 |
| 690 | /// TODO it's weird to take ownership even on error, rework this code. | 690 | /// TODO it's weird to take ownership even on error, rework this code. |
| 691 | fn readCoffDebugInfo(allocator: *mem.Allocator, coff_file: File) !ModuleDebugInfo { | 691 | fn readCoffDebugInfo(allocator: mem.Allocator, coff_file: File) !ModuleDebugInfo { |
| 692 | nosuspend { | 692 | nosuspend { |
| 693 | errdefer coff_file.close(); | 693 | errdefer coff_file.close(); |
| 694 | 694 | ||
| ... | @@ -755,7 +755,7 @@ fn chopSlice(ptr: []const u8, offset: u64, size: u64) ![]const u8 { | ... | @@ -755,7 +755,7 @@ fn chopSlice(ptr: []const u8, offset: u64, size: u64) ![]const u8 { |
| 755 | /// it themselves, even on error. | 755 | /// it themselves, even on error. |
| 756 | /// TODO resources https://github.com/ziglang/zig/issues/4353 | 756 | /// TODO resources https://github.com/ziglang/zig/issues/4353 |
| 757 | /// TODO it's weird to take ownership even on error, rework this code. | 757 | /// TODO it's weird to take ownership even on error, rework this code. |
| 758 | pub fn readElfDebugInfo(allocator: *mem.Allocator, elf_file: File) !ModuleDebugInfo { | 758 | pub fn readElfDebugInfo(allocator: mem.Allocator, elf_file: File) !ModuleDebugInfo { |
| 759 | nosuspend { | 759 | nosuspend { |
| 760 | const mapped_mem = try mapWholeFile(elf_file); | 760 | const mapped_mem = try mapWholeFile(elf_file); |
| 761 | const hdr = @ptrCast(*const elf.Ehdr, &mapped_mem[0]); | 761 | const hdr = @ptrCast(*const elf.Ehdr, &mapped_mem[0]); |
| ... | @@ -827,7 +827,7 @@ pub fn readElfDebugInfo(allocator: *mem.Allocator, elf_file: File) !ModuleDebugI | ... | @@ -827,7 +827,7 @@ pub fn readElfDebugInfo(allocator: *mem.Allocator, elf_file: File) !ModuleDebugI |
| 827 | /// This takes ownership of macho_file: users of this function should not close | 827 | /// This takes ownership of macho_file: users of this function should not close |
| 828 | /// it themselves, even on error. | 828 | /// it themselves, even on error. |
| 829 | /// TODO it's weird to take ownership even on error, rework this code. | 829 | /// TODO it's weird to take ownership even on error, rework this code. |
| 830 | fn readMachODebugInfo(allocator: *mem.Allocator, macho_file: File) !ModuleDebugInfo { | 830 | fn readMachODebugInfo(allocator: mem.Allocator, macho_file: File) !ModuleDebugInfo { |
| 831 | const mapped_mem = try mapWholeFile(macho_file); | 831 | const mapped_mem = try mapWholeFile(macho_file); |
| 832 | 832 | ||
| 833 | const hdr = @ptrCast( | 833 | const hdr = @ptrCast( |
| ... | @@ -1025,10 +1025,10 @@ fn mapWholeFile(file: File) ![]align(mem.page_size) const u8 { | ... | @@ -1025,10 +1025,10 @@ fn mapWholeFile(file: File) ![]align(mem.page_size) const u8 { |
| 1025 | } | 1025 | } |
| 1026 | 1026 | ||
| 1027 | pub const DebugInfo = struct { | 1027 | pub const DebugInfo = struct { |
| 1028 | allocator: *mem.Allocator, | 1028 | allocator: mem.Allocator, |
| 1029 | address_map: std.AutoHashMap(usize, *ModuleDebugInfo), | 1029 | address_map: std.AutoHashMap(usize, *ModuleDebugInfo), |
| 1030 | 1030 | ||
| 1031 | pub fn init(allocator: *mem.Allocator) DebugInfo { | 1031 | pub fn init(allocator: mem.Allocator) DebugInfo { |
| 1032 | return DebugInfo{ | 1032 | return DebugInfo{ |
| 1033 | .allocator = allocator, | 1033 | .allocator = allocator, |
| 1034 | .address_map = std.AutoHashMap(usize, *ModuleDebugInfo).init(allocator), | 1034 | .address_map = std.AutoHashMap(usize, *ModuleDebugInfo).init(allocator), |
| ... | @@ -1278,7 +1278,7 @@ pub const ModuleDebugInfo = switch (native_os) { | ... | @@ -1278,7 +1278,7 @@ pub const ModuleDebugInfo = switch (native_os) { |
| 1278 | addr_table: std.StringHashMap(u64), | 1278 | addr_table: std.StringHashMap(u64), |
| 1279 | }; | 1279 | }; |
| 1280 | 1280 | ||
| 1281 | pub fn allocator(self: @This()) *mem.Allocator { | 1281 | pub fn allocator(self: @This()) mem.Allocator { |
| 1282 | return self.ofiles.allocator; | 1282 | return self.ofiles.allocator; |
| 1283 | } | 1283 | } |
| 1284 | 1284 | ||
| ... | @@ -1470,7 +1470,7 @@ pub const ModuleDebugInfo = switch (native_os) { | ... | @@ -1470,7 +1470,7 @@ pub const ModuleDebugInfo = switch (native_os) { |
| 1470 | debug_data: PdbOrDwarf, | 1470 | debug_data: PdbOrDwarf, |
| 1471 | coff: *coff.Coff, | 1471 | coff: *coff.Coff, |
| 1472 | 1472 | ||
| 1473 | pub fn allocator(self: @This()) *mem.Allocator { | 1473 | pub fn allocator(self: @This()) mem.Allocator { |
| 1474 | return self.coff.allocator; | 1474 | return self.coff.allocator; |
| 1475 | } | 1475 | } |
| 1476 | 1476 | ||
| ... | @@ -1560,14 +1560,15 @@ fn getSymbolFromDwarf(address: u64, di: *DW.DwarfInfo) !SymbolInfo { | ... | @@ -1560,14 +1560,15 @@ fn getSymbolFromDwarf(address: u64, di: *DW.DwarfInfo) !SymbolInfo { |
| 1560 | } | 1560 | } |
| 1561 | 1561 | ||
| 1562 | /// TODO multithreaded awareness | 1562 | /// TODO multithreaded awareness |
| 1563 | var debug_info_allocator: ?*mem.Allocator = null; | 1563 | var debug_info_allocator: ?mem.Allocator = null; |
| 1564 | var debug_info_arena_allocator: std.heap.ArenaAllocator = undefined; | 1564 | var debug_info_arena_allocator: std.heap.ArenaAllocator = undefined; |
| 1565 | fn getDebugInfoAllocator() *mem.Allocator { | 1565 | fn getDebugInfoAllocator() mem.Allocator { |
| 1566 | if (debug_info_allocator) |a| return a; | 1566 | if (debug_info_allocator) |a| return a; |
| 1567 | 1567 | ||
| 1568 | debug_info_arena_allocator = std.heap.ArenaAllocator.init(std.heap.page_allocator); | 1568 | debug_info_arena_allocator = std.heap.ArenaAllocator.init(std.heap.page_allocator); |
| 1569 | debug_info_allocator = &debug_info_arena_allocator.allocator; | 1569 | const allocator = debug_info_arena_allocator.getAllocator(); |
| 1570 | return &debug_info_arena_allocator.allocator; | 1570 | debug_info_allocator = allocator; |
| 1571 | return allocator; | ||
| 1571 | } | 1572 | } |
| 1572 | 1573 | ||
| 1573 | /// Whether or not the current target can print useful debug information when a segfault occurs. | 1574 | /// Whether or not the current target can print useful debug information when a segfault occurs. |
lib/std/dwarf.zig+8-8| ... | @@ -466,7 +466,7 @@ fn readUnitLength(in_stream: anytype, endian: std.builtin.Endian, is_64: *bool) | ... | @@ -466,7 +466,7 @@ fn readUnitLength(in_stream: anytype, endian: std.builtin.Endian, is_64: *bool) |
| 466 | } | 466 | } |
| 467 | 467 | ||
| 468 | // TODO the nosuspends here are workarounds | 468 | // TODO the nosuspends here are workarounds |
| 469 | fn readAllocBytes(allocator: *mem.Allocator, in_stream: anytype, size: usize) ![]u8 { | 469 | fn readAllocBytes(allocator: mem.Allocator, in_stream: anytype, size: usize) ![]u8 { |
| 470 | const buf = try allocator.alloc(u8, size); | 470 | const buf = try allocator.alloc(u8, size); |
| 471 | errdefer allocator.free(buf); | 471 | errdefer allocator.free(buf); |
| 472 | if ((try nosuspend in_stream.read(buf)) < size) return error.EndOfFile; | 472 | if ((try nosuspend in_stream.read(buf)) < size) return error.EndOfFile; |
| ... | @@ -481,18 +481,18 @@ fn readAddress(in_stream: anytype, endian: std.builtin.Endian, is_64: bool) !u64 | ... | @@ -481,18 +481,18 @@ fn readAddress(in_stream: anytype, endian: std.builtin.Endian, is_64: bool) !u64 |
| 481 | @as(u64, try in_stream.readInt(u32, endian)); | 481 | @as(u64, try in_stream.readInt(u32, endian)); |
| 482 | } | 482 | } |
| 483 | 483 | ||
| 484 | fn parseFormValueBlockLen(allocator: *mem.Allocator, in_stream: anytype, size: usize) !FormValue { | 484 | fn parseFormValueBlockLen(allocator: mem.Allocator, in_stream: anytype, size: usize) !FormValue { |
| 485 | const buf = try readAllocBytes(allocator, in_stream, size); | 485 | const buf = try readAllocBytes(allocator, in_stream, size); |
| 486 | return FormValue{ .Block = buf }; | 486 | return FormValue{ .Block = buf }; |
| 487 | } | 487 | } |
| 488 | 488 | ||
| 489 | // TODO the nosuspends here are workarounds | 489 | // TODO the nosuspends here are workarounds |
| 490 | fn parseFormValueBlock(allocator: *mem.Allocator, in_stream: anytype, endian: std.builtin.Endian, size: usize) !FormValue { | 490 | fn parseFormValueBlock(allocator: mem.Allocator, in_stream: anytype, endian: std.builtin.Endian, size: usize) !FormValue { |
| 491 | const block_len = try nosuspend in_stream.readVarInt(usize, endian, size); | 491 | const block_len = try nosuspend in_stream.readVarInt(usize, endian, size); |
| 492 | return parseFormValueBlockLen(allocator, in_stream, block_len); | 492 | return parseFormValueBlockLen(allocator, in_stream, block_len); |
| 493 | } | 493 | } |
| 494 | 494 | ||
| 495 | fn parseFormValueConstant(allocator: *mem.Allocator, in_stream: anytype, signed: bool, endian: std.builtin.Endian, comptime size: i32) !FormValue { | 495 | fn parseFormValueConstant(allocator: mem.Allocator, in_stream: anytype, signed: bool, endian: std.builtin.Endian, comptime size: i32) !FormValue { |
| 496 | _ = allocator; | 496 | _ = allocator; |
| 497 | // TODO: Please forgive me, I've worked around zig not properly spilling some intermediate values here. | 497 | // TODO: Please forgive me, I've worked around zig not properly spilling some intermediate values here. |
| 498 | // `nosuspend` should be removed from all the function calls once it is fixed. | 498 | // `nosuspend` should be removed from all the function calls once it is fixed. |
| ... | @@ -520,7 +520,7 @@ fn parseFormValueConstant(allocator: *mem.Allocator, in_stream: anytype, signed: | ... | @@ -520,7 +520,7 @@ fn parseFormValueConstant(allocator: *mem.Allocator, in_stream: anytype, signed: |
| 520 | } | 520 | } |
| 521 | 521 | ||
| 522 | // TODO the nosuspends here are workarounds | 522 | // TODO the nosuspends here are workarounds |
| 523 | fn parseFormValueRef(allocator: *mem.Allocator, in_stream: anytype, endian: std.builtin.Endian, size: i32) !FormValue { | 523 | fn parseFormValueRef(allocator: mem.Allocator, in_stream: anytype, endian: std.builtin.Endian, size: i32) !FormValue { |
| 524 | _ = allocator; | 524 | _ = allocator; |
| 525 | return FormValue{ | 525 | return FormValue{ |
| 526 | .Ref = switch (size) { | 526 | .Ref = switch (size) { |
| ... | @@ -535,7 +535,7 @@ fn parseFormValueRef(allocator: *mem.Allocator, in_stream: anytype, endian: std. | ... | @@ -535,7 +535,7 @@ fn parseFormValueRef(allocator: *mem.Allocator, in_stream: anytype, endian: std. |
| 535 | } | 535 | } |
| 536 | 536 | ||
| 537 | // TODO the nosuspends here are workarounds | 537 | // TODO the nosuspends here are workarounds |
| 538 | fn parseFormValue(allocator: *mem.Allocator, in_stream: anytype, form_id: u64, endian: std.builtin.Endian, is_64: bool) anyerror!FormValue { | 538 | fn parseFormValue(allocator: mem.Allocator, in_stream: anytype, form_id: u64, endian: std.builtin.Endian, is_64: bool) anyerror!FormValue { |
| 539 | return switch (form_id) { | 539 | return switch (form_id) { |
| 540 | FORM.addr => FormValue{ .Address = try readAddress(in_stream, endian, @sizeOf(usize) == 8) }, | 540 | FORM.addr => FormValue{ .Address = try readAddress(in_stream, endian, @sizeOf(usize) == 8) }, |
| 541 | FORM.block1 => parseFormValueBlock(allocator, in_stream, endian, 1), | 541 | FORM.block1 => parseFormValueBlock(allocator, in_stream, endian, 1), |
| ... | @@ -604,7 +604,7 @@ pub const DwarfInfo = struct { | ... | @@ -604,7 +604,7 @@ pub const DwarfInfo = struct { |
| 604 | compile_unit_list: ArrayList(CompileUnit) = undefined, | 604 | compile_unit_list: ArrayList(CompileUnit) = undefined, |
| 605 | func_list: ArrayList(Func) = undefined, | 605 | func_list: ArrayList(Func) = undefined, |
| 606 | 606 | ||
| 607 | pub fn allocator(self: DwarfInfo) *mem.Allocator { | 607 | pub fn allocator(self: DwarfInfo) mem.Allocator { |
| 608 | return self.abbrev_table_list.allocator; | 608 | return self.abbrev_table_list.allocator; |
| 609 | } | 609 | } |
| 610 | 610 | ||
| ... | @@ -1092,7 +1092,7 @@ pub const DwarfInfo = struct { | ... | @@ -1092,7 +1092,7 @@ pub const DwarfInfo = struct { |
| 1092 | /// the DwarfInfo fields before calling. These fields can be left undefined: | 1092 | /// the DwarfInfo fields before calling. These fields can be left undefined: |
| 1093 | /// * abbrev_table_list | 1093 | /// * abbrev_table_list |
| 1094 | /// * compile_unit_list | 1094 | /// * compile_unit_list |
| 1095 | pub fn openDwarfDebugInfo(di: *DwarfInfo, allocator: *mem.Allocator) !void { | 1095 | pub fn openDwarfDebugInfo(di: *DwarfInfo, allocator: mem.Allocator) !void { |
| 1096 | di.abbrev_table_list = ArrayList(AbbrevTableHeader).init(allocator); | 1096 | di.abbrev_table_list = ArrayList(AbbrevTableHeader).init(allocator); |
| 1097 | di.compile_unit_list = ArrayList(CompileUnit).init(allocator); | 1097 | di.compile_unit_list = ArrayList(CompileUnit).init(allocator); |
| 1098 | di.func_list = ArrayList(Func).init(allocator); | 1098 | di.func_list = ArrayList(Func).init(allocator); |
lib/std/event/group.zig+3-3| ... | @@ -15,7 +15,7 @@ pub fn Group(comptime ReturnType: type) type { | ... | @@ -15,7 +15,7 @@ pub fn Group(comptime ReturnType: type) type { |
| 15 | frame_stack: Stack, | 15 | frame_stack: Stack, |
| 16 | alloc_stack: AllocStack, | 16 | alloc_stack: AllocStack, |
| 17 | lock: Lock, | 17 | lock: Lock, |
| 18 | allocator: *Allocator, | 18 | allocator: Allocator, |
| 19 | 19 | ||
| 20 | const Self = @This(); | 20 | const Self = @This(); |
| 21 | 21 | ||
| ... | @@ -31,7 +31,7 @@ pub fn Group(comptime ReturnType: type) type { | ... | @@ -31,7 +31,7 @@ pub fn Group(comptime ReturnType: type) type { |
| 31 | handle: anyframe->ReturnType, | 31 | handle: anyframe->ReturnType, |
| 32 | }; | 32 | }; |
| 33 | 33 | ||
| 34 | pub fn init(allocator: *Allocator) Self { | 34 | pub fn init(allocator: Allocator) Self { |
| 35 | return Self{ | 35 | return Self{ |
| 36 | .frame_stack = Stack.init(), | 36 | .frame_stack = Stack.init(), |
| 37 | .alloc_stack = AllocStack.init(), | 37 | .alloc_stack = AllocStack.init(), |
| ... | @@ -127,7 +127,7 @@ test "std.event.Group" { | ... | @@ -127,7 +127,7 @@ test "std.event.Group" { |
| 127 | 127 | ||
| 128 | _ = async testGroup(std.heap.page_allocator); | 128 | _ = async testGroup(std.heap.page_allocator); |
| 129 | } | 129 | } |
| 130 | fn testGroup(allocator: *Allocator) callconv(.Async) void { | 130 | fn testGroup(allocator: Allocator) callconv(.Async) void { |
| 131 | var count: usize = 0; | 131 | var count: usize = 0; |
| 132 | var group = Group(void).init(allocator); | 132 | var group = Group(void).init(allocator); |
| 133 | var sleep_a_little_frame = async sleepALittle(&count); | 133 | var sleep_a_little_frame = async sleepALittle(&count); |
lib/std/event/loop.zig+2-2| ... | @@ -727,7 +727,7 @@ pub const Loop = struct { | ... | @@ -727,7 +727,7 @@ pub const Loop = struct { |
| 727 | /// with `allocator` and freed when the function returns. | 727 | /// with `allocator` and freed when the function returns. |
| 728 | /// `func` must return void and it can be an async function. | 728 | /// `func` must return void and it can be an async function. |
| 729 | /// Yields to the event loop, running the function on the next tick. | 729 | /// Yields to the event loop, running the function on the next tick. |
| 730 | pub fn runDetached(self: *Loop, alloc: *mem.Allocator, comptime func: anytype, args: anytype) error{OutOfMemory}!void { | 730 | pub fn runDetached(self: *Loop, alloc: mem.Allocator, comptime func: anytype, args: anytype) error{OutOfMemory}!void { |
| 731 | if (!std.io.is_async) @compileError("Can't use runDetached in non-async mode!"); | 731 | if (!std.io.is_async) @compileError("Can't use runDetached in non-async mode!"); |
| 732 | if (@TypeOf(@call(.{}, func, args)) != void) { | 732 | if (@TypeOf(@call(.{}, func, args)) != void) { |
| 733 | @compileError("`func` must not have a return value"); | 733 | @compileError("`func` must not have a return value"); |
| ... | @@ -735,7 +735,7 @@ pub const Loop = struct { | ... | @@ -735,7 +735,7 @@ pub const Loop = struct { |
| 735 | 735 | ||
| 736 | const Wrapper = struct { | 736 | const Wrapper = struct { |
| 737 | const Args = @TypeOf(args); | 737 | const Args = @TypeOf(args); |
| 738 | fn run(func_args: Args, loop: *Loop, allocator: *mem.Allocator) void { | 738 | fn run(func_args: Args, loop: *Loop, allocator: mem.Allocator) void { |
| 739 | loop.beginOneEvent(); | 739 | loop.beginOneEvent(); |
| 740 | loop.yield(); | 740 | loop.yield(); |
| 741 | @call(.{}, func, func_args); // compile error when called with non-void ret type | 741 | @call(.{}, func, func_args); // compile error when called with non-void ret type |
lib/std/event/rwlock.zig+1-1| ... | @@ -226,7 +226,7 @@ test "std.event.RwLock" { | ... | @@ -226,7 +226,7 @@ test "std.event.RwLock" { |
| 226 | const expected_result = [1]i32{shared_it_count * @intCast(i32, shared_test_data.len)} ** shared_test_data.len; | 226 | const expected_result = [1]i32{shared_it_count * @intCast(i32, shared_test_data.len)} ** shared_test_data.len; |
| 227 | try testing.expectEqualSlices(i32, expected_result, shared_test_data); | 227 | try testing.expectEqualSlices(i32, expected_result, shared_test_data); |
| 228 | } | 228 | } |
| 229 | fn testLock(allocator: *Allocator, lock: *RwLock) callconv(.Async) void { | 229 | fn testLock(allocator: Allocator, lock: *RwLock) callconv(.Async) void { |
| 230 | var read_nodes: [100]Loop.NextTickNode = undefined; | 230 | var read_nodes: [100]Loop.NextTickNode = undefined; |
| 231 | for (read_nodes) |*read_node| { | 231 | for (read_nodes) |*read_node| { |
| 232 | const frame = allocator.create(@Frame(readRunner)) catch @panic("memory"); | 232 | const frame = allocator.create(@Frame(readRunner)) catch @panic("memory"); |
lib/std/fifo.zig+2-2| ... | @@ -33,7 +33,7 @@ pub fn LinearFifo( | ... | @@ -33,7 +33,7 @@ pub fn LinearFifo( |
| 33 | }; | 33 | }; |
| 34 | 34 | ||
| 35 | return struct { | 35 | return struct { |
| 36 | allocator: if (buffer_type == .Dynamic) *Allocator else void, | 36 | allocator: if (buffer_type == .Dynamic) Allocator else void, |
| 37 | buf: if (buffer_type == .Static) [buffer_type.Static]T else []T, | 37 | buf: if (buffer_type == .Static) [buffer_type.Static]T else []T, |
| 38 | head: usize, | 38 | head: usize, |
| 39 | count: usize, | 39 | count: usize, |
| ... | @@ -69,7 +69,7 @@ pub fn LinearFifo( | ... | @@ -69,7 +69,7 @@ pub fn LinearFifo( |
| 69 | } | 69 | } |
| 70 | }, | 70 | }, |
| 71 | .Dynamic => struct { | 71 | .Dynamic => struct { |
| 72 | pub fn init(allocator: *Allocator) Self { | 72 | pub fn init(allocator: Allocator) Self { |
| 73 | return .{ | 73 | return .{ |
| 74 | .allocator = allocator, | 74 | .allocator = allocator, |
| 75 | .buf = &[_]T{}, | 75 | .buf = &[_]T{}, |
lib/std/fmt.zig+2-2| ... | @@ -1803,7 +1803,7 @@ pub fn count(comptime fmt: []const u8, args: anytype) u64 { | ... | @@ -1803,7 +1803,7 @@ pub fn count(comptime fmt: []const u8, args: anytype) u64 { |
| 1803 | 1803 | ||
| 1804 | pub const AllocPrintError = error{OutOfMemory}; | 1804 | pub const AllocPrintError = error{OutOfMemory}; |
| 1805 | 1805 | ||
| 1806 | pub fn allocPrint(allocator: *mem.Allocator, comptime fmt: []const u8, args: anytype) AllocPrintError![]u8 { | 1806 | pub fn allocPrint(allocator: mem.Allocator, comptime fmt: []const u8, args: anytype) AllocPrintError![]u8 { |
| 1807 | const size = math.cast(usize, count(fmt, args)) catch |err| switch (err) { | 1807 | const size = math.cast(usize, count(fmt, args)) catch |err| switch (err) { |
| 1808 | // Output too long. Can't possibly allocate enough memory to display it. | 1808 | // Output too long. Can't possibly allocate enough memory to display it. |
| 1809 | error.Overflow => return error.OutOfMemory, | 1809 | error.Overflow => return error.OutOfMemory, |
| ... | @@ -1816,7 +1816,7 @@ pub fn allocPrint(allocator: *mem.Allocator, comptime fmt: []const u8, args: any | ... | @@ -1816,7 +1816,7 @@ pub fn allocPrint(allocator: *mem.Allocator, comptime fmt: []const u8, args: any |
| 1816 | 1816 | ||
| 1817 | pub const allocPrint0 = @compileError("deprecated; use allocPrintZ"); | 1817 | pub const allocPrint0 = @compileError("deprecated; use allocPrintZ"); |
| 1818 | 1818 | ||
| 1819 | pub fn allocPrintZ(allocator: *mem.Allocator, comptime fmt: []const u8, args: anytype) AllocPrintError![:0]u8 { | 1819 | pub fn allocPrintZ(allocator: mem.Allocator, comptime fmt: []const u8, args: anytype) AllocPrintError![:0]u8 { |
| 1820 | const result = try allocPrint(allocator, fmt ++ "\x00", args); | 1820 | const result = try allocPrint(allocator, fmt ++ "\x00", args); |
| 1821 | return result[0 .. result.len - 1 :0]; | 1821 | return result[0 .. result.len - 1 :0]; |
| 1822 | } | 1822 | } |
lib/std/fs.zig+8-8| ... | @@ -64,7 +64,7 @@ pub const need_async_thread = std.io.is_async and switch (builtin.os.tag) { | ... | @@ -64,7 +64,7 @@ pub const need_async_thread = std.io.is_async and switch (builtin.os.tag) { |
| 64 | }; | 64 | }; |
| 65 | 65 | ||
| 66 | /// TODO remove the allocator requirement from this API | 66 | /// TODO remove the allocator requirement from this API |
| 67 | pub fn atomicSymLink(allocator: *Allocator, existing_path: []const u8, new_path: []const u8) !void { | 67 | pub fn atomicSymLink(allocator: Allocator, existing_path: []const u8, new_path: []const u8) !void { |
| 68 | if (cwd().symLink(existing_path, new_path, .{})) { | 68 | if (cwd().symLink(existing_path, new_path, .{})) { |
| 69 | return; | 69 | return; |
| 70 | } else |err| switch (err) { | 70 | } else |err| switch (err) { |
| ... | @@ -875,7 +875,7 @@ pub const Dir = struct { | ... | @@ -875,7 +875,7 @@ pub const Dir = struct { |
| 875 | /// Must call `Walker.deinit` when done. | 875 | /// Must call `Walker.deinit` when done. |
| 876 | /// The order of returned file system entries is undefined. | 876 | /// The order of returned file system entries is undefined. |
| 877 | /// `self` will not be closed after walking it. | 877 | /// `self` will not be closed after walking it. |
| 878 | pub fn walk(self: Dir, allocator: *Allocator) !Walker { | 878 | pub fn walk(self: Dir, allocator: Allocator) !Walker { |
| 879 | var name_buffer = std.ArrayList(u8).init(allocator); | 879 | var name_buffer = std.ArrayList(u8).init(allocator); |
| 880 | errdefer name_buffer.deinit(); | 880 | errdefer name_buffer.deinit(); |
| 881 | 881 | ||
| ... | @@ -1393,7 +1393,7 @@ pub const Dir = struct { | ... | @@ -1393,7 +1393,7 @@ pub const Dir = struct { |
| 1393 | 1393 | ||
| 1394 | /// Same as `Dir.realpath` except caller must free the returned memory. | 1394 | /// Same as `Dir.realpath` except caller must free the returned memory. |
| 1395 | /// See also `Dir.realpath`. | 1395 | /// See also `Dir.realpath`. |
| 1396 | pub fn realpathAlloc(self: Dir, allocator: *Allocator, pathname: []const u8) ![]u8 { | 1396 | pub fn realpathAlloc(self: Dir, allocator: Allocator, pathname: []const u8) ![]u8 { |
| 1397 | // Use of MAX_PATH_BYTES here is valid as the realpath function does not | 1397 | // Use of MAX_PATH_BYTES here is valid as the realpath function does not |
| 1398 | // have a variant that takes an arbitrary-size buffer. | 1398 | // have a variant that takes an arbitrary-size buffer. |
| 1399 | // TODO(#4812): Consider reimplementing realpath or using the POSIX.1-2008 | 1399 | // TODO(#4812): Consider reimplementing realpath or using the POSIX.1-2008 |
| ... | @@ -1804,7 +1804,7 @@ pub const Dir = struct { | ... | @@ -1804,7 +1804,7 @@ pub const Dir = struct { |
| 1804 | 1804 | ||
| 1805 | /// On success, caller owns returned buffer. | 1805 | /// On success, caller owns returned buffer. |
| 1806 | /// If the file is larger than `max_bytes`, returns `error.FileTooBig`. | 1806 | /// If the file is larger than `max_bytes`, returns `error.FileTooBig`. |
| 1807 | pub fn readFileAlloc(self: Dir, allocator: *mem.Allocator, file_path: []const u8, max_bytes: usize) ![]u8 { | 1807 | pub fn readFileAlloc(self: Dir, allocator: mem.Allocator, file_path: []const u8, max_bytes: usize) ![]u8 { |
| 1808 | return self.readFileAllocOptions(allocator, file_path, max_bytes, null, @alignOf(u8), null); | 1808 | return self.readFileAllocOptions(allocator, file_path, max_bytes, null, @alignOf(u8), null); |
| 1809 | } | 1809 | } |
| 1810 | 1810 | ||
| ... | @@ -1815,7 +1815,7 @@ pub const Dir = struct { | ... | @@ -1815,7 +1815,7 @@ pub const Dir = struct { |
| 1815 | /// Allows specifying alignment and a sentinel value. | 1815 | /// Allows specifying alignment and a sentinel value. |
| 1816 | pub fn readFileAllocOptions( | 1816 | pub fn readFileAllocOptions( |
| 1817 | self: Dir, | 1817 | self: Dir, |
| 1818 | allocator: *mem.Allocator, | 1818 | allocator: mem.Allocator, |
| 1819 | file_path: []const u8, | 1819 | file_path: []const u8, |
| 1820 | max_bytes: usize, | 1820 | max_bytes: usize, |
| 1821 | size_hint: ?usize, | 1821 | size_hint: ?usize, |
| ... | @@ -2464,7 +2464,7 @@ pub const SelfExePathError = os.ReadLinkError || os.SysCtlError || os.RealPathEr | ... | @@ -2464,7 +2464,7 @@ pub const SelfExePathError = os.ReadLinkError || os.SysCtlError || os.RealPathEr |
| 2464 | 2464 | ||
| 2465 | /// `selfExePath` except allocates the result on the heap. | 2465 | /// `selfExePath` except allocates the result on the heap. |
| 2466 | /// Caller owns returned memory. | 2466 | /// Caller owns returned memory. |
| 2467 | pub fn selfExePathAlloc(allocator: *Allocator) ![]u8 { | 2467 | pub fn selfExePathAlloc(allocator: Allocator) ![]u8 { |
| 2468 | // Use of MAX_PATH_BYTES here is justified as, at least on one tested Linux | 2468 | // Use of MAX_PATH_BYTES here is justified as, at least on one tested Linux |
| 2469 | // system, readlink will completely fail to return a result larger than | 2469 | // system, readlink will completely fail to return a result larger than |
| 2470 | // PATH_MAX even if given a sufficiently large buffer. This makes it | 2470 | // PATH_MAX even if given a sufficiently large buffer. This makes it |
| ... | @@ -2573,7 +2573,7 @@ pub fn selfExePathW() [:0]const u16 { | ... | @@ -2573,7 +2573,7 @@ pub fn selfExePathW() [:0]const u16 { |
| 2573 | 2573 | ||
| 2574 | /// `selfExeDirPath` except allocates the result on the heap. | 2574 | /// `selfExeDirPath` except allocates the result on the heap. |
| 2575 | /// Caller owns returned memory. | 2575 | /// Caller owns returned memory. |
| 2576 | pub fn selfExeDirPathAlloc(allocator: *Allocator) ![]u8 { | 2576 | pub fn selfExeDirPathAlloc(allocator: Allocator) ![]u8 { |
| 2577 | // Use of MAX_PATH_BYTES here is justified as, at least on one tested Linux | 2577 | // Use of MAX_PATH_BYTES here is justified as, at least on one tested Linux |
| 2578 | // system, readlink will completely fail to return a result larger than | 2578 | // system, readlink will completely fail to return a result larger than |
| 2579 | // PATH_MAX even if given a sufficiently large buffer. This makes it | 2579 | // PATH_MAX even if given a sufficiently large buffer. This makes it |
| ... | @@ -2596,7 +2596,7 @@ pub fn selfExeDirPath(out_buffer: []u8) SelfExePathError![]const u8 { | ... | @@ -2596,7 +2596,7 @@ pub fn selfExeDirPath(out_buffer: []u8) SelfExePathError![]const u8 { |
| 2596 | 2596 | ||
| 2597 | /// `realpath`, except caller must free the returned memory. | 2597 | /// `realpath`, except caller must free the returned memory. |
| 2598 | /// See also `Dir.realpath`. | 2598 | /// See also `Dir.realpath`. |
| 2599 | pub fn realpathAlloc(allocator: *Allocator, pathname: []const u8) ![]u8 { | 2599 | pub fn realpathAlloc(allocator: Allocator, pathname: []const u8) ![]u8 { |
| 2600 | // Use of MAX_PATH_BYTES here is valid as the realpath function does not | 2600 | // Use of MAX_PATH_BYTES here is valid as the realpath function does not |
| 2601 | // have a variant that takes an arbitrary-size buffer. | 2601 | // have a variant that takes an arbitrary-size buffer. |
| 2602 | // TODO(#4812): Consider reimplementing realpath or using the POSIX.1-2008 | 2602 | // TODO(#4812): Consider reimplementing realpath or using the POSIX.1-2008 |
lib/std/fs/file.zig+2-2| ... | @@ -420,7 +420,7 @@ pub const File = struct { | ... | @@ -420,7 +420,7 @@ pub const File = struct { |
| 420 | /// Reads all the bytes from the current position to the end of the file. | 420 | /// Reads all the bytes from the current position to the end of the file. |
| 421 | /// On success, caller owns returned buffer. | 421 | /// On success, caller owns returned buffer. |
| 422 | /// If the file is larger than `max_bytes`, returns `error.FileTooBig`. | 422 | /// If the file is larger than `max_bytes`, returns `error.FileTooBig`. |
| 423 | pub fn readToEndAlloc(self: File, allocator: *mem.Allocator, max_bytes: usize) ![]u8 { | 423 | pub fn readToEndAlloc(self: File, allocator: mem.Allocator, max_bytes: usize) ![]u8 { |
| 424 | return self.readToEndAllocOptions(allocator, max_bytes, null, @alignOf(u8), null); | 424 | return self.readToEndAllocOptions(allocator, max_bytes, null, @alignOf(u8), null); |
| 425 | } | 425 | } |
| 426 | 426 | ||
| ... | @@ -432,7 +432,7 @@ pub const File = struct { | ... | @@ -432,7 +432,7 @@ pub const File = struct { |
| 432 | /// Allows specifying alignment and a sentinel value. | 432 | /// Allows specifying alignment and a sentinel value. |
| 433 | pub fn readToEndAllocOptions( | 433 | pub fn readToEndAllocOptions( |
| 434 | self: File, | 434 | self: File, |
| 435 | allocator: *mem.Allocator, | 435 | allocator: mem.Allocator, |
| 436 | max_bytes: usize, | 436 | max_bytes: usize, |
| 437 | size_hint: ?usize, | 437 | size_hint: ?usize, |
| 438 | comptime alignment: u29, | 438 | comptime alignment: u29, |
lib/std/fs/get_app_data_dir.zig+1-1| ... | @@ -12,7 +12,7 @@ pub const GetAppDataDirError = error{ | ... | @@ -12,7 +12,7 @@ pub const GetAppDataDirError = error{ |
| 12 | 12 | ||
| 13 | /// Caller owns returned memory. | 13 | /// Caller owns returned memory. |
| 14 | /// TODO determine if we can remove the allocator requirement | 14 | /// TODO determine if we can remove the allocator requirement |
| 15 | pub fn getAppDataDir(allocator: *mem.Allocator, appname: []const u8) GetAppDataDirError![]u8 { | 15 | pub fn getAppDataDir(allocator: mem.Allocator, appname: []const u8) GetAppDataDirError![]u8 { |
| 16 | switch (builtin.os.tag) { | 16 | switch (builtin.os.tag) { |
| 17 | .windows => { | 17 | .windows => { |
| 18 | var dir_path_ptr: [*:0]u16 = undefined; | 18 | var dir_path_ptr: [*:0]u16 = undefined; |
lib/std/fs/path.zig+9-9| ... | @@ -35,7 +35,7 @@ pub fn isSep(byte: u8) bool { | ... | @@ -35,7 +35,7 @@ pub fn isSep(byte: u8) bool { |
| 35 | 35 | ||
| 36 | /// This is different from mem.join in that the separator will not be repeated if | 36 | /// This is different from mem.join in that the separator will not be repeated if |
| 37 | /// it is found at the end or beginning of a pair of consecutive paths. | 37 | /// it is found at the end or beginning of a pair of consecutive paths. |
| 38 | fn joinSepMaybeZ(allocator: *Allocator, separator: u8, sepPredicate: fn (u8) bool, paths: []const []const u8, zero: bool) ![]u8 { | 38 | fn joinSepMaybeZ(allocator: Allocator, separator: u8, sepPredicate: fn (u8) bool, paths: []const []const u8, zero: bool) ![]u8 { |
| 39 | if (paths.len == 0) return if (zero) try allocator.dupe(u8, &[1]u8{0}) else &[0]u8{}; | 39 | if (paths.len == 0) return if (zero) try allocator.dupe(u8, &[1]u8{0}) else &[0]u8{}; |
| 40 | 40 | ||
| 41 | // Find first non-empty path index. | 41 | // Find first non-empty path index. |
| ... | @@ -99,13 +99,13 @@ fn joinSepMaybeZ(allocator: *Allocator, separator: u8, sepPredicate: fn (u8) boo | ... | @@ -99,13 +99,13 @@ fn joinSepMaybeZ(allocator: *Allocator, separator: u8, sepPredicate: fn (u8) boo |
| 99 | 99 | ||
| 100 | /// Naively combines a series of paths with the native path seperator. | 100 | /// Naively combines a series of paths with the native path seperator. |
| 101 | /// Allocates memory for the result, which must be freed by the caller. | 101 | /// Allocates memory for the result, which must be freed by the caller. |
| 102 | pub fn join(allocator: *Allocator, paths: []const []const u8) ![]u8 { | 102 | pub fn join(allocator: Allocator, paths: []const []const u8) ![]u8 { |
| 103 | return joinSepMaybeZ(allocator, sep, isSep, paths, false); | 103 | return joinSepMaybeZ(allocator, sep, isSep, paths, false); |
| 104 | } | 104 | } |
| 105 | 105 | ||
| 106 | /// Naively combines a series of paths with the native path seperator and null terminator. | 106 | /// Naively combines a series of paths with the native path seperator and null terminator. |
| 107 | /// Allocates memory for the result, which must be freed by the caller. | 107 | /// Allocates memory for the result, which must be freed by the caller. |
| 108 | pub fn joinZ(allocator: *Allocator, paths: []const []const u8) ![:0]u8 { | 108 | pub fn joinZ(allocator: Allocator, paths: []const []const u8) ![:0]u8 { |
| 109 | const out = try joinSepMaybeZ(allocator, sep, isSep, paths, true); | 109 | const out = try joinSepMaybeZ(allocator, sep, isSep, paths, true); |
| 110 | return out[0 .. out.len - 1 :0]; | 110 | return out[0 .. out.len - 1 :0]; |
| 111 | } | 111 | } |
| ... | @@ -445,7 +445,7 @@ fn asciiEqlIgnoreCase(s1: []const u8, s2: []const u8) bool { | ... | @@ -445,7 +445,7 @@ fn asciiEqlIgnoreCase(s1: []const u8, s2: []const u8) bool { |
| 445 | } | 445 | } |
| 446 | 446 | ||
| 447 | /// On Windows, this calls `resolveWindows` and on POSIX it calls `resolvePosix`. | 447 | /// On Windows, this calls `resolveWindows` and on POSIX it calls `resolvePosix`. |
| 448 | pub fn resolve(allocator: *Allocator, paths: []const []const u8) ![]u8 { | 448 | pub fn resolve(allocator: Allocator, paths: []const []const u8) ![]u8 { |
| 449 | if (native_os == .windows) { | 449 | if (native_os == .windows) { |
| 450 | return resolveWindows(allocator, paths); | 450 | return resolveWindows(allocator, paths); |
| 451 | } else { | 451 | } else { |
| ... | @@ -461,7 +461,7 @@ pub fn resolve(allocator: *Allocator, paths: []const []const u8) ![]u8 { | ... | @@ -461,7 +461,7 @@ pub fn resolve(allocator: *Allocator, paths: []const []const u8) ![]u8 { |
| 461 | /// Path separators are canonicalized to '\\' and drives are canonicalized to capital letters. | 461 | /// Path separators are canonicalized to '\\' and drives are canonicalized to capital letters. |
| 462 | /// Note: all usage of this function should be audited due to the existence of symlinks. | 462 | /// Note: all usage of this function should be audited due to the existence of symlinks. |
| 463 | /// Without performing actual syscalls, resolving `..` could be incorrect. | 463 | /// Without performing actual syscalls, resolving `..` could be incorrect. |
| 464 | pub fn resolveWindows(allocator: *Allocator, paths: []const []const u8) ![]u8 { | 464 | pub fn resolveWindows(allocator: Allocator, paths: []const []const u8) ![]u8 { |
| 465 | if (paths.len == 0) { | 465 | if (paths.len == 0) { |
| 466 | assert(native_os == .windows); // resolveWindows called on non windows can't use getCwd | 466 | assert(native_os == .windows); // resolveWindows called on non windows can't use getCwd |
| 467 | return process.getCwdAlloc(allocator); | 467 | return process.getCwdAlloc(allocator); |
| ... | @@ -647,7 +647,7 @@ pub fn resolveWindows(allocator: *Allocator, paths: []const []const u8) ![]u8 { | ... | @@ -647,7 +647,7 @@ pub fn resolveWindows(allocator: *Allocator, paths: []const []const u8) ![]u8 { |
| 647 | /// If all paths are relative it uses the current working directory as a starting point. | 647 | /// If all paths are relative it uses the current working directory as a starting point. |
| 648 | /// Note: all usage of this function should be audited due to the existence of symlinks. | 648 | /// Note: all usage of this function should be audited due to the existence of symlinks. |
| 649 | /// Without performing actual syscalls, resolving `..` could be incorrect. | 649 | /// Without performing actual syscalls, resolving `..` could be incorrect. |
| 650 | pub fn resolvePosix(allocator: *Allocator, paths: []const []const u8) ![]u8 { | 650 | pub fn resolvePosix(allocator: Allocator, paths: []const []const u8) ![]u8 { |
| 651 | if (paths.len == 0) { | 651 | if (paths.len == 0) { |
| 652 | assert(native_os != .windows); // resolvePosix called on windows can't use getCwd | 652 | assert(native_os != .windows); // resolvePosix called on windows can't use getCwd |
| 653 | return process.getCwdAlloc(allocator); | 653 | return process.getCwdAlloc(allocator); |
| ... | @@ -1058,7 +1058,7 @@ fn testBasenameWindows(input: []const u8, expected_output: []const u8) !void { | ... | @@ -1058,7 +1058,7 @@ fn testBasenameWindows(input: []const u8, expected_output: []const u8) !void { |
| 1058 | /// resolve to the same path (after calling `resolve` on each), a zero-length | 1058 | /// resolve to the same path (after calling `resolve` on each), a zero-length |
| 1059 | /// string is returned. | 1059 | /// string is returned. |
| 1060 | /// On Windows this canonicalizes the drive to a capital letter and paths to `\\`. | 1060 | /// On Windows this canonicalizes the drive to a capital letter and paths to `\\`. |
| 1061 | pub fn relative(allocator: *Allocator, from: []const u8, to: []const u8) ![]u8 { | 1061 | pub fn relative(allocator: Allocator, from: []const u8, to: []const u8) ![]u8 { |
| 1062 | if (native_os == .windows) { | 1062 | if (native_os == .windows) { |
| 1063 | return relativeWindows(allocator, from, to); | 1063 | return relativeWindows(allocator, from, to); |
| 1064 | } else { | 1064 | } else { |
| ... | @@ -1066,7 +1066,7 @@ pub fn relative(allocator: *Allocator, from: []const u8, to: []const u8) ![]u8 { | ... | @@ -1066,7 +1066,7 @@ pub fn relative(allocator: *Allocator, from: []const u8, to: []const u8) ![]u8 { |
| 1066 | } | 1066 | } |
| 1067 | } | 1067 | } |
| 1068 | 1068 | ||
| 1069 | pub fn relativeWindows(allocator: *Allocator, from: []const u8, to: []const u8) ![]u8 { | 1069 | pub fn relativeWindows(allocator: Allocator, from: []const u8, to: []const u8) ![]u8 { |
| 1070 | const resolved_from = try resolveWindows(allocator, &[_][]const u8{from}); | 1070 | const resolved_from = try resolveWindows(allocator, &[_][]const u8{from}); |
| 1071 | defer allocator.free(resolved_from); | 1071 | defer allocator.free(resolved_from); |
| 1072 | 1072 | ||
| ... | @@ -1139,7 +1139,7 @@ pub fn relativeWindows(allocator: *Allocator, from: []const u8, to: []const u8) | ... | @@ -1139,7 +1139,7 @@ pub fn relativeWindows(allocator: *Allocator, from: []const u8, to: []const u8) |
| 1139 | return [_]u8{}; | 1139 | return [_]u8{}; |
| 1140 | } | 1140 | } |
| 1141 | 1141 | ||
| 1142 | pub fn relativePosix(allocator: *Allocator, from: []const u8, to: []const u8) ![]u8 { | 1142 | pub fn relativePosix(allocator: Allocator, from: []const u8, to: []const u8) ![]u8 { |
| 1143 | const resolved_from = try resolvePosix(allocator, &[_][]const u8{from}); | 1143 | const resolved_from = try resolvePosix(allocator, &[_][]const u8{from}); |
| 1144 | defer allocator.free(resolved_from); | 1144 | defer allocator.free(resolved_from); |
| 1145 | 1145 |
lib/std/fs/test.zig+28-22| ... | @@ -52,9 +52,11 @@ test "accessAbsolute" { | ... | @@ -52,9 +52,11 @@ test "accessAbsolute" { |
| 52 | 52 | ||
| 53 | var arena = ArenaAllocator.init(testing.allocator); | 53 | var arena = ArenaAllocator.init(testing.allocator); |
| 54 | defer arena.deinit(); | 54 | defer arena.deinit(); |
| 55 | const allocator = arena.getAllocator(); | ||
| 56 | |||
| 55 | const base_path = blk: { | 57 | const base_path = blk: { |
| 56 | const relative_path = try fs.path.join(&arena.allocator, &[_][]const u8{ "zig-cache", "tmp", tmp.sub_path[0..] }); | 58 | const relative_path = try fs.path.join(allocator, &[_][]const u8{ "zig-cache", "tmp", tmp.sub_path[0..] }); |
| 57 | break :blk try fs.realpathAlloc(&arena.allocator, relative_path); | 59 | break :blk try fs.realpathAlloc(allocator, relative_path); |
| 58 | }; | 60 | }; |
| 59 | 61 | ||
| 60 | try fs.accessAbsolute(base_path, .{}); | 62 | try fs.accessAbsolute(base_path, .{}); |
| ... | @@ -69,9 +71,11 @@ test "openDirAbsolute" { | ... | @@ -69,9 +71,11 @@ test "openDirAbsolute" { |
| 69 | try tmp.dir.makeDir("subdir"); | 71 | try tmp.dir.makeDir("subdir"); |
| 70 | var arena = ArenaAllocator.init(testing.allocator); | 72 | var arena = ArenaAllocator.init(testing.allocator); |
| 71 | defer arena.deinit(); | 73 | defer arena.deinit(); |
| 74 | const allocator = arena.getAllocator(); | ||
| 75 | |||
| 72 | const base_path = blk: { | 76 | const base_path = blk: { |
| 73 | const relative_path = try fs.path.join(&arena.allocator, &[_][]const u8{ "zig-cache", "tmp", tmp.sub_path[0..], "subdir" }); | 77 | const relative_path = try fs.path.join(allocator, &[_][]const u8{ "zig-cache", "tmp", tmp.sub_path[0..], "subdir" }); |
| 74 | break :blk try fs.realpathAlloc(&arena.allocator, relative_path); | 78 | break :blk try fs.realpathAlloc(allocator, relative_path); |
| 75 | }; | 79 | }; |
| 76 | 80 | ||
| 77 | { | 81 | { |
| ... | @@ -80,8 +84,8 @@ test "openDirAbsolute" { | ... | @@ -80,8 +84,8 @@ test "openDirAbsolute" { |
| 80 | } | 84 | } |
| 81 | 85 | ||
| 82 | for ([_][]const u8{ ".", ".." }) |sub_path| { | 86 | for ([_][]const u8{ ".", ".." }) |sub_path| { |
| 83 | const dir_path = try fs.path.join(&arena.allocator, &[_][]const u8{ base_path, sub_path }); | 87 | const dir_path = try fs.path.join(allocator, &[_][]const u8{ base_path, sub_path }); |
| 84 | defer arena.allocator.free(dir_path); | 88 | defer allocator.free(dir_path); |
| 85 | var dir = try fs.openDirAbsolute(dir_path, .{}); | 89 | var dir = try fs.openDirAbsolute(dir_path, .{}); |
| 86 | defer dir.close(); | 90 | defer dir.close(); |
| 87 | } | 91 | } |
| ... | @@ -107,12 +111,12 @@ test "readLinkAbsolute" { | ... | @@ -107,12 +111,12 @@ test "readLinkAbsolute" { |
| 107 | // Get base abs path | 111 | // Get base abs path |
| 108 | var arena = ArenaAllocator.init(testing.allocator); | 112 | var arena = ArenaAllocator.init(testing.allocator); |
| 109 | defer arena.deinit(); | 113 | defer arena.deinit(); |
| 114 | const allocator = arena.getAllocator(); | ||
| 110 | 115 | ||
| 111 | const base_path = blk: { | 116 | const base_path = blk: { |
| 112 | const relative_path = try fs.path.join(&arena.allocator, &[_][]const u8{ "zig-cache", "tmp", tmp.sub_path[0..] }); | 117 | const relative_path = try fs.path.join(allocator, &[_][]const u8{ "zig-cache", "tmp", tmp.sub_path[0..] }); |
| 113 | break :blk try fs.realpathAlloc(&arena.allocator, relative_path); | 118 | break :blk try fs.realpathAlloc(allocator, relative_path); |
| 114 | }; | 119 | }; |
| 115 | const allocator = &arena.allocator; | ||
| 116 | 120 | ||
| 117 | { | 121 | { |
| 118 | const target_path = try fs.path.join(allocator, &[_][]const u8{ base_path, "file.txt" }); | 122 | const target_path = try fs.path.join(allocator, &[_][]const u8{ base_path, "file.txt" }); |
| ... | @@ -158,15 +162,16 @@ test "Dir.Iterator" { | ... | @@ -158,15 +162,16 @@ test "Dir.Iterator" { |
| 158 | 162 | ||
| 159 | var arena = ArenaAllocator.init(testing.allocator); | 163 | var arena = ArenaAllocator.init(testing.allocator); |
| 160 | defer arena.deinit(); | 164 | defer arena.deinit(); |
| 165 | const allocator = arena.getAllocator(); | ||
| 161 | 166 | ||
| 162 | var entries = std.ArrayList(Dir.Entry).init(&arena.allocator); | 167 | var entries = std.ArrayList(Dir.Entry).init(allocator); |
| 163 | 168 | ||
| 164 | // Create iterator. | 169 | // Create iterator. |
| 165 | var iter = tmp_dir.dir.iterate(); | 170 | var iter = tmp_dir.dir.iterate(); |
| 166 | while (try iter.next()) |entry| { | 171 | while (try iter.next()) |entry| { |
| 167 | // We cannot just store `entry` as on Windows, we're re-using the name buffer | 172 | // We cannot just store `entry` as on Windows, we're re-using the name buffer |
| 168 | // which means we'll actually share the `name` pointer between entries! | 173 | // which means we'll actually share the `name` pointer between entries! |
| 169 | const name = try arena.allocator.dupe(u8, entry.name); | 174 | const name = try allocator.dupe(u8, entry.name); |
| 170 | try entries.append(Dir.Entry{ .name = name, .kind = entry.kind }); | 175 | try entries.append(Dir.Entry{ .name = name, .kind = entry.kind }); |
| 171 | } | 176 | } |
| 172 | 177 | ||
| ... | @@ -202,25 +207,26 @@ test "Dir.realpath smoke test" { | ... | @@ -202,25 +207,26 @@ test "Dir.realpath smoke test" { |
| 202 | 207 | ||
| 203 | var arena = ArenaAllocator.init(testing.allocator); | 208 | var arena = ArenaAllocator.init(testing.allocator); |
| 204 | defer arena.deinit(); | 209 | defer arena.deinit(); |
| 210 | const allocator = arena.getAllocator(); | ||
| 205 | 211 | ||
| 206 | const base_path = blk: { | 212 | const base_path = blk: { |
| 207 | const relative_path = try fs.path.join(&arena.allocator, &[_][]const u8{ "zig-cache", "tmp", tmp_dir.sub_path[0..] }); | 213 | const relative_path = try fs.path.join(allocator, &[_][]const u8{ "zig-cache", "tmp", tmp_dir.sub_path[0..] }); |
| 208 | break :blk try fs.realpathAlloc(&arena.allocator, relative_path); | 214 | break :blk try fs.realpathAlloc(allocator, relative_path); |
| 209 | }; | 215 | }; |
| 210 | 216 | ||
| 211 | // First, test non-alloc version | 217 | // First, test non-alloc version |
| 212 | { | 218 | { |
| 213 | var buf1: [fs.MAX_PATH_BYTES]u8 = undefined; | 219 | var buf1: [fs.MAX_PATH_BYTES]u8 = undefined; |
| 214 | const file_path = try tmp_dir.dir.realpath("test_file", buf1[0..]); | 220 | const file_path = try tmp_dir.dir.realpath("test_file", buf1[0..]); |
| 215 | const expected_path = try fs.path.join(&arena.allocator, &[_][]const u8{ base_path, "test_file" }); | 221 | const expected_path = try fs.path.join(allocator, &[_][]const u8{ base_path, "test_file" }); |
| 216 | 222 | ||
| 217 | try testing.expect(mem.eql(u8, file_path, expected_path)); | 223 | try testing.expect(mem.eql(u8, file_path, expected_path)); |
| 218 | } | 224 | } |
| 219 | 225 | ||
| 220 | // Next, test alloc version | 226 | // Next, test alloc version |
| 221 | { | 227 | { |
| 222 | const file_path = try tmp_dir.dir.realpathAlloc(&arena.allocator, "test_file"); | 228 | const file_path = try tmp_dir.dir.realpathAlloc(allocator, "test_file"); |
| 223 | const expected_path = try fs.path.join(&arena.allocator, &[_][]const u8{ base_path, "test_file" }); | 229 | const expected_path = try fs.path.join(allocator, &[_][]const u8{ base_path, "test_file" }); |
| 224 | 230 | ||
| 225 | try testing.expect(mem.eql(u8, file_path, expected_path)); | 231 | try testing.expect(mem.eql(u8, file_path, expected_path)); |
| 226 | } | 232 | } |
| ... | @@ -476,11 +482,11 @@ test "renameAbsolute" { | ... | @@ -476,11 +482,11 @@ test "renameAbsolute" { |
| 476 | // Get base abs path | 482 | // Get base abs path |
| 477 | var arena = ArenaAllocator.init(testing.allocator); | 483 | var arena = ArenaAllocator.init(testing.allocator); |
| 478 | defer arena.deinit(); | 484 | defer arena.deinit(); |
| 479 | const allocator = &arena.allocator; | 485 | const allocator = arena.getAllocator(); |
| 480 | 486 | ||
| 481 | const base_path = blk: { | 487 | const base_path = blk: { |
| 482 | const relative_path = try fs.path.join(&arena.allocator, &[_][]const u8{ "zig-cache", "tmp", tmp_dir.sub_path[0..] }); | 488 | const relative_path = try fs.path.join(allocator, &[_][]const u8{ "zig-cache", "tmp", tmp_dir.sub_path[0..] }); |
| 483 | break :blk try fs.realpathAlloc(&arena.allocator, relative_path); | 489 | break :blk try fs.realpathAlloc(allocator, relative_path); |
| 484 | }; | 490 | }; |
| 485 | 491 | ||
| 486 | try testing.expectError(error.FileNotFound, fs.renameAbsolute( | 492 | try testing.expectError(error.FileNotFound, fs.renameAbsolute( |
| ... | @@ -987,11 +993,11 @@ test ". and .. in absolute functions" { | ... | @@ -987,11 +993,11 @@ test ". and .. in absolute functions" { |
| 987 | 993 | ||
| 988 | var arena = ArenaAllocator.init(testing.allocator); | 994 | var arena = ArenaAllocator.init(testing.allocator); |
| 989 | defer arena.deinit(); | 995 | defer arena.deinit(); |
| 990 | const allocator = &arena.allocator; | 996 | const allocator = arena.getAllocator(); |
| 991 | 997 | ||
| 992 | const base_path = blk: { | 998 | const base_path = blk: { |
| 993 | const relative_path = try fs.path.join(&arena.allocator, &[_][]const u8{ "zig-cache", "tmp", tmp.sub_path[0..] }); | 999 | const relative_path = try fs.path.join(allocator, &[_][]const u8{ "zig-cache", "tmp", tmp.sub_path[0..] }); |
| 994 | break :blk try fs.realpathAlloc(&arena.allocator, relative_path); | 1000 | break :blk try fs.realpathAlloc(allocator, relative_path); |
| 995 | }; | 1001 | }; |
| 996 | 1002 | ||
| 997 | const subdir_path = try fs.path.join(allocator, &[_][]const u8{ base_path, "./subdir" }); | 1003 | const subdir_path = try fs.path.join(allocator, &[_][]const u8{ base_path, "./subdir" }); |
lib/std/fs/wasi.zig+1-1| ... | @@ -80,7 +80,7 @@ pub const PreopenList = struct { | ... | @@ -80,7 +80,7 @@ pub const PreopenList = struct { |
| 80 | pub const Error = error{ OutOfMemory, Overflow } || os.UnexpectedError; | 80 | pub const Error = error{ OutOfMemory, Overflow } || os.UnexpectedError; |
| 81 | 81 | ||
| 82 | /// Deinitialize with `deinit`. | 82 | /// Deinitialize with `deinit`. |
| 83 | pub fn init(allocator: *Allocator) Self { | 83 | pub fn init(allocator: Allocator) Self { |
| 84 | return Self{ .buffer = InnerList.init(allocator) }; | 84 | return Self{ .buffer = InnerList.init(allocator) }; |
| 85 | } | 85 | } |
| 86 | 86 |
lib/std/fs/watch.zig+3-3| ... | @@ -30,7 +30,7 @@ pub fn Watch(comptime V: type) type { | ... | @@ -30,7 +30,7 @@ pub fn Watch(comptime V: type) type { |
| 30 | return struct { | 30 | return struct { |
| 31 | channel: event.Channel(Event.Error!Event), | 31 | channel: event.Channel(Event.Error!Event), |
| 32 | os_data: OsData, | 32 | os_data: OsData, |
| 33 | allocator: *Allocator, | 33 | allocator: Allocator, |
| 34 | 34 | ||
| 35 | const OsData = switch (builtin.os.tag) { | 35 | const OsData = switch (builtin.os.tag) { |
| 36 | // TODO https://github.com/ziglang/zig/issues/3778 | 36 | // TODO https://github.com/ziglang/zig/issues/3778 |
| ... | @@ -96,7 +96,7 @@ pub fn Watch(comptime V: type) type { | ... | @@ -96,7 +96,7 @@ pub fn Watch(comptime V: type) type { |
| 96 | pub const Error = WatchEventError; | 96 | pub const Error = WatchEventError; |
| 97 | }; | 97 | }; |
| 98 | 98 | ||
| 99 | pub fn init(allocator: *Allocator, event_buf_count: usize) !*Self { | 99 | pub fn init(allocator: Allocator, event_buf_count: usize) !*Self { |
| 100 | const self = try allocator.create(Self); | 100 | const self = try allocator.create(Self); |
| 101 | errdefer allocator.destroy(self); | 101 | errdefer allocator.destroy(self); |
| 102 | 102 | ||
| ... | @@ -648,7 +648,7 @@ test "write a file, watch it, write it again, delete it" { | ... | @@ -648,7 +648,7 @@ test "write a file, watch it, write it again, delete it" { |
| 648 | return testWriteWatchWriteDelete(std.testing.allocator); | 648 | return testWriteWatchWriteDelete(std.testing.allocator); |
| 649 | } | 649 | } |
| 650 | 650 | ||
| 651 | fn testWriteWatchWriteDelete(allocator: *Allocator) !void { | 651 | fn testWriteWatchWriteDelete(allocator: Allocator) !void { |
| 652 | const file_path = try std.fs.path.join(allocator, &[_][]const u8{ test_tmp_dir, "file.txt" }); | 652 | const file_path = try std.fs.path.join(allocator, &[_][]const u8{ test_tmp_dir, "file.txt" }); |
| 653 | defer allocator.free(file_path); | 653 | defer allocator.free(file_path); |
| 654 | 654 |
lib/std/hash/auto_hash.zig+1-1| ... | @@ -309,7 +309,7 @@ test "hash struct deep" { | ... | @@ -309,7 +309,7 @@ test "hash struct deep" { |
| 309 | 309 | ||
| 310 | const Self = @This(); | 310 | const Self = @This(); |
| 311 | 311 | ||
| 312 | pub fn init(allocator: *mem.Allocator, a_: u32, b_: u16, c_: bool) !Self { | 312 | pub fn init(allocator: mem.Allocator, a_: u32, b_: u16, c_: bool) !Self { |
| 313 | const ptr = try allocator.create(bool); | 313 | const ptr = try allocator.create(bool); |
| 314 | ptr.* = c_; | 314 | ptr.* = c_; |
| 315 | return Self{ .a = a_, .b = b_, .c = ptr }; | 315 | return Self{ .a = a_, .b = b_, .c = ptr }; |
lib/std/hash/benchmark.zig+1-1| ... | @@ -165,7 +165,7 @@ pub fn main() !void { | ... | @@ -165,7 +165,7 @@ pub fn main() !void { |
| 165 | 165 | ||
| 166 | var buffer: [1024]u8 = undefined; | 166 | var buffer: [1024]u8 = undefined; |
| 167 | var fixed = std.heap.FixedBufferAllocator.init(buffer[0..]); | 167 | var fixed = std.heap.FixedBufferAllocator.init(buffer[0..]); |
| 168 | const args = try std.process.argsAlloc(&fixed.allocator); | 168 | const args = try std.process.argsAlloc(fixed.getAllocator()); |
| 169 | 169 | ||
| 170 | var filter: ?[]u8 = ""; | 170 | var filter: ?[]u8 = ""; |
| 171 | var count: usize = mode(128 * MiB); | 171 | var count: usize = mode(128 * MiB); |
lib/std/hash_map.zig+31-31| ... | @@ -363,7 +363,7 @@ pub fn HashMap( | ... | @@ -363,7 +363,7 @@ pub fn HashMap( |
| 363 | comptime verifyContext(Context, K, K, u64); | 363 | comptime verifyContext(Context, K, K, u64); |
| 364 | return struct { | 364 | return struct { |
| 365 | unmanaged: Unmanaged, | 365 | unmanaged: Unmanaged, |
| 366 | allocator: *Allocator, | 366 | allocator: Allocator, |
| 367 | ctx: Context, | 367 | ctx: Context, |
| 368 | 368 | ||
| 369 | /// The type of the unmanaged hash map underlying this wrapper | 369 | /// The type of the unmanaged hash map underlying this wrapper |
| ... | @@ -390,7 +390,7 @@ pub fn HashMap( | ... | @@ -390,7 +390,7 @@ pub fn HashMap( |
| 390 | /// Create a managed hash map with an empty context. | 390 | /// Create a managed hash map with an empty context. |
| 391 | /// If the context is not zero-sized, you must use | 391 | /// If the context is not zero-sized, you must use |
| 392 | /// initContext(allocator, ctx) instead. | 392 | /// initContext(allocator, ctx) instead. |
| 393 | pub fn init(allocator: *Allocator) Self { | 393 | pub fn init(allocator: Allocator) Self { |
| 394 | if (@sizeOf(Context) != 0) { | 394 | if (@sizeOf(Context) != 0) { |
| 395 | @compileError("Context must be specified! Call initContext(allocator, ctx) instead."); | 395 | @compileError("Context must be specified! Call initContext(allocator, ctx) instead."); |
| 396 | } | 396 | } |
| ... | @@ -402,7 +402,7 @@ pub fn HashMap( | ... | @@ -402,7 +402,7 @@ pub fn HashMap( |
| 402 | } | 402 | } |
| 403 | 403 | ||
| 404 | /// Create a managed hash map with a context | 404 | /// Create a managed hash map with a context |
| 405 | pub fn initContext(allocator: *Allocator, ctx: Context) Self { | 405 | pub fn initContext(allocator: Allocator, ctx: Context) Self { |
| 406 | return .{ | 406 | return .{ |
| 407 | .unmanaged = .{}, | 407 | .unmanaged = .{}, |
| 408 | .allocator = allocator, | 408 | .allocator = allocator, |
| ... | @@ -636,7 +636,7 @@ pub fn HashMap( | ... | @@ -636,7 +636,7 @@ pub fn HashMap( |
| 636 | } | 636 | } |
| 637 | 637 | ||
| 638 | /// Creates a copy of this map, using a specified allocator | 638 | /// Creates a copy of this map, using a specified allocator |
| 639 | pub fn cloneWithAllocator(self: Self, new_allocator: *Allocator) !Self { | 639 | pub fn cloneWithAllocator(self: Self, new_allocator: Allocator) !Self { |
| 640 | var other = try self.unmanaged.cloneContext(new_allocator, self.ctx); | 640 | var other = try self.unmanaged.cloneContext(new_allocator, self.ctx); |
| 641 | return other.promoteContext(new_allocator, self.ctx); | 641 | return other.promoteContext(new_allocator, self.ctx); |
| 642 | } | 642 | } |
| ... | @@ -650,7 +650,7 @@ pub fn HashMap( | ... | @@ -650,7 +650,7 @@ pub fn HashMap( |
| 650 | /// Creates a copy of this map, using a specified allocator and context. | 650 | /// Creates a copy of this map, using a specified allocator and context. |
| 651 | pub fn cloneWithAllocatorAndContext( | 651 | pub fn cloneWithAllocatorAndContext( |
| 652 | self: Self, | 652 | self: Self, |
| 653 | new_allocator: *Allocator, | 653 | new_allocator: Allocator, |
| 654 | new_ctx: anytype, | 654 | new_ctx: anytype, |
| 655 | ) !HashMap(K, V, @TypeOf(new_ctx), max_load_percentage) { | 655 | ) !HashMap(K, V, @TypeOf(new_ctx), max_load_percentage) { |
| 656 | var other = try self.unmanaged.cloneContext(new_allocator, new_ctx); | 656 | var other = try self.unmanaged.cloneContext(new_allocator, new_ctx); |
| ... | @@ -841,13 +841,13 @@ pub fn HashMapUnmanaged( | ... | @@ -841,13 +841,13 @@ pub fn HashMapUnmanaged( |
| 841 | 841 | ||
| 842 | pub const Managed = HashMap(K, V, Context, max_load_percentage); | 842 | pub const Managed = HashMap(K, V, Context, max_load_percentage); |
| 843 | 843 | ||
| 844 | pub fn promote(self: Self, allocator: *Allocator) Managed { | 844 | pub fn promote(self: Self, allocator: Allocator) Managed { |
| 845 | if (@sizeOf(Context) != 0) | 845 | if (@sizeOf(Context) != 0) |
| 846 | @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call promoteContext instead."); | 846 | @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call promoteContext instead."); |
| 847 | return promoteContext(self, allocator, undefined); | 847 | return promoteContext(self, allocator, undefined); |
| 848 | } | 848 | } |
| 849 | 849 | ||
| 850 | pub fn promoteContext(self: Self, allocator: *Allocator, ctx: Context) Managed { | 850 | pub fn promoteContext(self: Self, allocator: Allocator, ctx: Context) Managed { |
| 851 | return .{ | 851 | return .{ |
| 852 | .unmanaged = self, | 852 | .unmanaged = self, |
| 853 | .allocator = allocator, | 853 | .allocator = allocator, |
| ... | @@ -859,7 +859,7 @@ pub fn HashMapUnmanaged( | ... | @@ -859,7 +859,7 @@ pub fn HashMapUnmanaged( |
| 859 | return size * 100 < max_load_percentage * cap; | 859 | return size * 100 < max_load_percentage * cap; |
| 860 | } | 860 | } |
| 861 | 861 | ||
| 862 | pub fn deinit(self: *Self, allocator: *Allocator) void { | 862 | pub fn deinit(self: *Self, allocator: Allocator) void { |
| 863 | self.deallocate(allocator); | 863 | self.deallocate(allocator); |
| 864 | self.* = undefined; | 864 | self.* = undefined; |
| 865 | } | 865 | } |
| ... | @@ -872,20 +872,20 @@ pub fn HashMapUnmanaged( | ... | @@ -872,20 +872,20 @@ pub fn HashMapUnmanaged( |
| 872 | 872 | ||
| 873 | pub const ensureCapacity = @compileError("deprecated; call `ensureUnusedCapacity` or `ensureTotalCapacity`"); | 873 | pub const ensureCapacity = @compileError("deprecated; call `ensureUnusedCapacity` or `ensureTotalCapacity`"); |
| 874 | 874 | ||
| 875 | pub fn ensureTotalCapacity(self: *Self, allocator: *Allocator, new_size: Size) !void { | 875 | pub fn ensureTotalCapacity(self: *Self, allocator: Allocator, new_size: Size) !void { |
| 876 | if (@sizeOf(Context) != 0) | 876 | if (@sizeOf(Context) != 0) |
| 877 | @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call ensureTotalCapacityContext instead."); | 877 | @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call ensureTotalCapacityContext instead."); |
| 878 | return ensureTotalCapacityContext(self, allocator, new_size, undefined); | 878 | return ensureTotalCapacityContext(self, allocator, new_size, undefined); |
| 879 | } | 879 | } |
| 880 | pub fn ensureTotalCapacityContext(self: *Self, allocator: *Allocator, new_size: Size, ctx: Context) !void { | 880 | pub fn ensureTotalCapacityContext(self: *Self, allocator: Allocator, new_size: Size, ctx: Context) !void { |
| 881 | if (new_size > self.size) | 881 | if (new_size > self.size) |
| 882 | try self.growIfNeeded(allocator, new_size - self.size, ctx); | 882 | try self.growIfNeeded(allocator, new_size - self.size, ctx); |
| 883 | } | 883 | } |
| 884 | 884 | ||
| 885 | pub fn ensureUnusedCapacity(self: *Self, allocator: *Allocator, additional_size: Size) !void { | 885 | pub fn ensureUnusedCapacity(self: *Self, allocator: Allocator, additional_size: Size) !void { |
| 886 | return ensureUnusedCapacityContext(self, allocator, additional_size, undefined); | 886 | return ensureUnusedCapacityContext(self, allocator, additional_size, undefined); |
| 887 | } | 887 | } |
| 888 | pub fn ensureUnusedCapacityContext(self: *Self, allocator: *Allocator, additional_size: Size, ctx: Context) !void { | 888 | pub fn ensureUnusedCapacityContext(self: *Self, allocator: Allocator, additional_size: Size, ctx: Context) !void { |
| 889 | return ensureTotalCapacityContext(self, allocator, self.count() + additional_size, ctx); | 889 | return ensureTotalCapacityContext(self, allocator, self.count() + additional_size, ctx); |
| 890 | } | 890 | } |
| 891 | 891 | ||
| ... | @@ -897,7 +897,7 @@ pub fn HashMapUnmanaged( | ... | @@ -897,7 +897,7 @@ pub fn HashMapUnmanaged( |
| 897 | } | 897 | } |
| 898 | } | 898 | } |
| 899 | 899 | ||
| 900 | pub fn clearAndFree(self: *Self, allocator: *Allocator) void { | 900 | pub fn clearAndFree(self: *Self, allocator: Allocator) void { |
| 901 | self.deallocate(allocator); | 901 | self.deallocate(allocator); |
| 902 | self.size = 0; | 902 | self.size = 0; |
| 903 | self.available = 0; | 903 | self.available = 0; |
| ... | @@ -962,12 +962,12 @@ pub fn HashMapUnmanaged( | ... | @@ -962,12 +962,12 @@ pub fn HashMapUnmanaged( |
| 962 | } | 962 | } |
| 963 | 963 | ||
| 964 | /// Insert an entry in the map. Assumes it is not already present. | 964 | /// Insert an entry in the map. Assumes it is not already present. |
| 965 | pub fn putNoClobber(self: *Self, allocator: *Allocator, key: K, value: V) !void { | 965 | pub fn putNoClobber(self: *Self, allocator: Allocator, key: K, value: V) !void { |
| 966 | if (@sizeOf(Context) != 0) | 966 | if (@sizeOf(Context) != 0) |
| 967 | @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call putNoClobberContext instead."); | 967 | @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call putNoClobberContext instead."); |
| 968 | return self.putNoClobberContext(allocator, key, value, undefined); | 968 | return self.putNoClobberContext(allocator, key, value, undefined); |
| 969 | } | 969 | } |
| 970 | pub fn putNoClobberContext(self: *Self, allocator: *Allocator, key: K, value: V, ctx: Context) !void { | 970 | pub fn putNoClobberContext(self: *Self, allocator: Allocator, key: K, value: V, ctx: Context) !void { |
| 971 | assert(!self.containsContext(key, ctx)); | 971 | assert(!self.containsContext(key, ctx)); |
| 972 | try self.growIfNeeded(allocator, 1, ctx); | 972 | try self.growIfNeeded(allocator, 1, ctx); |
| 973 | 973 | ||
| ... | @@ -1021,12 +1021,12 @@ pub fn HashMapUnmanaged( | ... | @@ -1021,12 +1021,12 @@ pub fn HashMapUnmanaged( |
| 1021 | } | 1021 | } |
| 1022 | 1022 | ||
| 1023 | /// Inserts a new `Entry` into the hash map, returning the previous one, if any. | 1023 | /// Inserts a new `Entry` into the hash map, returning the previous one, if any. |
| 1024 | pub fn fetchPut(self: *Self, allocator: *Allocator, key: K, value: V) !?KV { | 1024 | pub fn fetchPut(self: *Self, allocator: Allocator, key: K, value: V) !?KV { |
| 1025 | if (@sizeOf(Context) != 0) | 1025 | if (@sizeOf(Context) != 0) |
| 1026 | @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call fetchPutContext instead."); | 1026 | @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call fetchPutContext instead."); |
| 1027 | return self.fetchPutContext(allocator, key, value, undefined); | 1027 | return self.fetchPutContext(allocator, key, value, undefined); |
| 1028 | } | 1028 | } |
| 1029 | pub fn fetchPutContext(self: *Self, allocator: *Allocator, key: K, value: V, ctx: Context) !?KV { | 1029 | pub fn fetchPutContext(self: *Self, allocator: Allocator, key: K, value: V, ctx: Context) !?KV { |
| 1030 | const gop = try self.getOrPutContext(allocator, key, ctx); | 1030 | const gop = try self.getOrPutContext(allocator, key, ctx); |
| 1031 | var result: ?KV = null; | 1031 | var result: ?KV = null; |
| 1032 | if (gop.found_existing) { | 1032 | if (gop.found_existing) { |
| ... | @@ -1157,12 +1157,12 @@ pub fn HashMapUnmanaged( | ... | @@ -1157,12 +1157,12 @@ pub fn HashMapUnmanaged( |
| 1157 | } | 1157 | } |
| 1158 | 1158 | ||
| 1159 | /// Insert an entry if the associated key is not already present, otherwise update preexisting value. | 1159 | /// Insert an entry if the associated key is not already present, otherwise update preexisting value. |
| 1160 | pub fn put(self: *Self, allocator: *Allocator, key: K, value: V) !void { | 1160 | pub fn put(self: *Self, allocator: Allocator, key: K, value: V) !void { |
| 1161 | if (@sizeOf(Context) != 0) | 1161 | if (@sizeOf(Context) != 0) |
| 1162 | @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call putContext instead."); | 1162 | @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call putContext instead."); |
| 1163 | return self.putContext(allocator, key, value, undefined); | 1163 | return self.putContext(allocator, key, value, undefined); |
| 1164 | } | 1164 | } |
| 1165 | pub fn putContext(self: *Self, allocator: *Allocator, key: K, value: V, ctx: Context) !void { | 1165 | pub fn putContext(self: *Self, allocator: Allocator, key: K, value: V, ctx: Context) !void { |
| 1166 | const result = try self.getOrPutContext(allocator, key, ctx); | 1166 | const result = try self.getOrPutContext(allocator, key, ctx); |
| 1167 | result.value_ptr.* = value; | 1167 | result.value_ptr.* = value; |
| 1168 | } | 1168 | } |
| ... | @@ -1231,24 +1231,24 @@ pub fn HashMapUnmanaged( | ... | @@ -1231,24 +1231,24 @@ pub fn HashMapUnmanaged( |
| 1231 | return null; | 1231 | return null; |
| 1232 | } | 1232 | } |
| 1233 | 1233 | ||
| 1234 | pub fn getOrPut(self: *Self, allocator: *Allocator, key: K) !GetOrPutResult { | 1234 | pub fn getOrPut(self: *Self, allocator: Allocator, key: K) !GetOrPutResult { |
| 1235 | if (@sizeOf(Context) != 0) | 1235 | if (@sizeOf(Context) != 0) |
| 1236 | @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call getOrPutContext instead."); | 1236 | @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call getOrPutContext instead."); |
| 1237 | return self.getOrPutContext(allocator, key, undefined); | 1237 | return self.getOrPutContext(allocator, key, undefined); |
| 1238 | } | 1238 | } |
| 1239 | pub fn getOrPutContext(self: *Self, allocator: *Allocator, key: K, ctx: Context) !GetOrPutResult { | 1239 | pub fn getOrPutContext(self: *Self, allocator: Allocator, key: K, ctx: Context) !GetOrPutResult { |
| 1240 | const gop = try self.getOrPutContextAdapted(allocator, key, ctx, ctx); | 1240 | const gop = try self.getOrPutContextAdapted(allocator, key, ctx, ctx); |
| 1241 | if (!gop.found_existing) { | 1241 | if (!gop.found_existing) { |
| 1242 | gop.key_ptr.* = key; | 1242 | gop.key_ptr.* = key; |
| 1243 | } | 1243 | } |
| 1244 | return gop; | 1244 | return gop; |
| 1245 | } | 1245 | } |
| 1246 | pub fn getOrPutAdapted(self: *Self, allocator: *Allocator, key: anytype, key_ctx: anytype) !GetOrPutResult { | 1246 | pub fn getOrPutAdapted(self: *Self, allocator: Allocator, key: anytype, key_ctx: anytype) !GetOrPutResult { |
| 1247 | if (@sizeOf(Context) != 0) | 1247 | if (@sizeOf(Context) != 0) |
| 1248 | @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call getOrPutContextAdapted instead."); | 1248 | @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call getOrPutContextAdapted instead."); |
| 1249 | return self.getOrPutContextAdapted(allocator, key, key_ctx, undefined); | 1249 | return self.getOrPutContextAdapted(allocator, key, key_ctx, undefined); |
| 1250 | } | 1250 | } |
| 1251 | pub fn getOrPutContextAdapted(self: *Self, allocator: *Allocator, key: anytype, key_ctx: anytype, ctx: Context) !GetOrPutResult { | 1251 | pub fn getOrPutContextAdapted(self: *Self, allocator: Allocator, key: anytype, key_ctx: anytype, ctx: Context) !GetOrPutResult { |
| 1252 | self.growIfNeeded(allocator, 1, ctx) catch |err| { | 1252 | self.growIfNeeded(allocator, 1, ctx) catch |err| { |
| 1253 | // If allocation fails, try to do the lookup anyway. | 1253 | // If allocation fails, try to do the lookup anyway. |
| 1254 | // If we find an existing item, we can return it. | 1254 | // If we find an existing item, we can return it. |
| ... | @@ -1341,12 +1341,12 @@ pub fn HashMapUnmanaged( | ... | @@ -1341,12 +1341,12 @@ pub fn HashMapUnmanaged( |
| 1341 | }; | 1341 | }; |
| 1342 | } | 1342 | } |
| 1343 | 1343 | ||
| 1344 | pub fn getOrPutValue(self: *Self, allocator: *Allocator, key: K, value: V) !Entry { | 1344 | pub fn getOrPutValue(self: *Self, allocator: Allocator, key: K, value: V) !Entry { |
| 1345 | if (@sizeOf(Context) != 0) | 1345 | if (@sizeOf(Context) != 0) |
| 1346 | @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call getOrPutValueContext instead."); | 1346 | @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call getOrPutValueContext instead."); |
| 1347 | return self.getOrPutValueContext(allocator, key, value, undefined); | 1347 | return self.getOrPutValueContext(allocator, key, value, undefined); |
| 1348 | } | 1348 | } |
| 1349 | pub fn getOrPutValueContext(self: *Self, allocator: *Allocator, key: K, value: V, ctx: Context) !Entry { | 1349 | pub fn getOrPutValueContext(self: *Self, allocator: Allocator, key: K, value: V, ctx: Context) !Entry { |
| 1350 | const res = try self.getOrPutAdapted(allocator, key, ctx); | 1350 | const res = try self.getOrPutAdapted(allocator, key, ctx); |
| 1351 | if (!res.found_existing) { | 1351 | if (!res.found_existing) { |
| 1352 | res.key_ptr.* = key; | 1352 | res.key_ptr.* = key; |
| ... | @@ -1403,18 +1403,18 @@ pub fn HashMapUnmanaged( | ... | @@ -1403,18 +1403,18 @@ pub fn HashMapUnmanaged( |
| 1403 | return @truncate(Size, max_load - self.available); | 1403 | return @truncate(Size, max_load - self.available); |
| 1404 | } | 1404 | } |
| 1405 | 1405 | ||
| 1406 | fn growIfNeeded(self: *Self, allocator: *Allocator, new_count: Size, ctx: Context) !void { | 1406 | fn growIfNeeded(self: *Self, allocator: Allocator, new_count: Size, ctx: Context) !void { |
| 1407 | if (new_count > self.available) { | 1407 | if (new_count > self.available) { |
| 1408 | try self.grow(allocator, capacityForSize(self.load() + new_count), ctx); | 1408 | try self.grow(allocator, capacityForSize(self.load() + new_count), ctx); |
| 1409 | } | 1409 | } |
| 1410 | } | 1410 | } |
| 1411 | 1411 | ||
| 1412 | pub fn clone(self: Self, allocator: *Allocator) !Self { | 1412 | pub fn clone(self: Self, allocator: Allocator) !Self { |
| 1413 | if (@sizeOf(Context) != 0) | 1413 | if (@sizeOf(Context) != 0) |
| 1414 | @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call cloneContext instead."); | 1414 | @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call cloneContext instead."); |
| 1415 | return self.cloneContext(allocator, @as(Context, undefined)); | 1415 | return self.cloneContext(allocator, @as(Context, undefined)); |
| 1416 | } | 1416 | } |
| 1417 | pub fn cloneContext(self: Self, allocator: *Allocator, new_ctx: anytype) !HashMapUnmanaged(K, V, @TypeOf(new_ctx), max_load_percentage) { | 1417 | pub fn cloneContext(self: Self, allocator: Allocator, new_ctx: anytype) !HashMapUnmanaged(K, V, @TypeOf(new_ctx), max_load_percentage) { |
| 1418 | var other = HashMapUnmanaged(K, V, @TypeOf(new_ctx), max_load_percentage){}; | 1418 | var other = HashMapUnmanaged(K, V, @TypeOf(new_ctx), max_load_percentage){}; |
| 1419 | if (self.size == 0) | 1419 | if (self.size == 0) |
| 1420 | return other; | 1420 | return other; |
| ... | @@ -1439,7 +1439,7 @@ pub fn HashMapUnmanaged( | ... | @@ -1439,7 +1439,7 @@ pub fn HashMapUnmanaged( |
| 1439 | return other; | 1439 | return other; |
| 1440 | } | 1440 | } |
| 1441 | 1441 | ||
| 1442 | fn grow(self: *Self, allocator: *Allocator, new_capacity: Size, ctx: Context) !void { | 1442 | fn grow(self: *Self, allocator: Allocator, new_capacity: Size, ctx: Context) !void { |
| 1443 | @setCold(true); | 1443 | @setCold(true); |
| 1444 | const new_cap = std.math.max(new_capacity, minimal_capacity); | 1444 | const new_cap = std.math.max(new_capacity, minimal_capacity); |
| 1445 | assert(new_cap > self.capacity()); | 1445 | assert(new_cap > self.capacity()); |
| ... | @@ -1470,7 +1470,7 @@ pub fn HashMapUnmanaged( | ... | @@ -1470,7 +1470,7 @@ pub fn HashMapUnmanaged( |
| 1470 | std.mem.swap(Self, self, &map); | 1470 | std.mem.swap(Self, self, &map); |
| 1471 | } | 1471 | } |
| 1472 | 1472 | ||
| 1473 | fn allocate(self: *Self, allocator: *Allocator, new_capacity: Size) !void { | 1473 | fn allocate(self: *Self, allocator: Allocator, new_capacity: Size) !void { |
| 1474 | const header_align = @alignOf(Header); | 1474 | const header_align = @alignOf(Header); |
| 1475 | const key_align = if (@sizeOf(K) == 0) 1 else @alignOf(K); | 1475 | const key_align = if (@sizeOf(K) == 0) 1 else @alignOf(K); |
| 1476 | const val_align = if (@sizeOf(V) == 0) 1 else @alignOf(V); | 1476 | const val_align = if (@sizeOf(V) == 0) 1 else @alignOf(V); |
| ... | @@ -1503,7 +1503,7 @@ pub fn HashMapUnmanaged( | ... | @@ -1503,7 +1503,7 @@ pub fn HashMapUnmanaged( |
| 1503 | self.metadata = @intToPtr([*]Metadata, metadata); | 1503 | self.metadata = @intToPtr([*]Metadata, metadata); |
| 1504 | } | 1504 | } |
| 1505 | 1505 | ||
| 1506 | fn deallocate(self: *Self, allocator: *Allocator) void { | 1506 | fn deallocate(self: *Self, allocator: Allocator) void { |
| 1507 | if (self.metadata == null) return; | 1507 | if (self.metadata == null) return; |
| 1508 | 1508 | ||
| 1509 | const header_align = @alignOf(Header); | 1509 | const header_align = @alignOf(Header); |
lib/std/heap.zig+114-148| ... | @@ -97,13 +97,12 @@ const CAllocator = struct { | ... | @@ -97,13 +97,12 @@ const CAllocator = struct { |
| 97 | } | 97 | } |
| 98 | 98 | ||
| 99 | fn alloc( | 99 | fn alloc( |
| 100 | allocator: *Allocator, | 100 | _: *u1, |
| 101 | len: usize, | 101 | len: usize, |
| 102 | alignment: u29, | 102 | alignment: u29, |
| 103 | len_align: u29, | 103 | len_align: u29, |
| 104 | return_address: usize, | 104 | return_address: usize, |
| 105 | ) error{OutOfMemory}![]u8 { | 105 | ) error{OutOfMemory}![]u8 { |
| 106 | _ = allocator; | ||
| 107 | _ = return_address; | 106 | _ = return_address; |
| 108 | assert(len > 0); | 107 | assert(len > 0); |
| 109 | assert(std.math.isPowerOfTwo(alignment)); | 108 | assert(std.math.isPowerOfTwo(alignment)); |
| ... | @@ -124,14 +123,13 @@ const CAllocator = struct { | ... | @@ -124,14 +123,13 @@ const CAllocator = struct { |
| 124 | } | 123 | } |
| 125 | 124 | ||
| 126 | fn resize( | 125 | fn resize( |
| 127 | allocator: *Allocator, | 126 | _: *u1, |
| 128 | buf: []u8, | 127 | buf: []u8, |
| 129 | buf_align: u29, | 128 | buf_align: u29, |
| 130 | new_len: usize, | 129 | new_len: usize, |
| 131 | len_align: u29, | 130 | len_align: u29, |
| 132 | return_address: usize, | 131 | return_address: usize, |
| 133 | ) Allocator.Error!usize { | 132 | ) Allocator.Error!usize { |
| 134 | _ = allocator; | ||
| 135 | _ = buf_align; | 133 | _ = buf_align; |
| 136 | _ = return_address; | 134 | _ = return_address; |
| 137 | if (new_len == 0) { | 135 | if (new_len == 0) { |
| ... | @@ -154,10 +152,11 @@ const CAllocator = struct { | ... | @@ -154,10 +152,11 @@ const CAllocator = struct { |
| 154 | /// Supports the full Allocator interface, including alignment, and exploiting | 152 | /// Supports the full Allocator interface, including alignment, and exploiting |
| 155 | /// `malloc_usable_size` if available. For an allocator that directly calls | 153 | /// `malloc_usable_size` if available. For an allocator that directly calls |
| 156 | /// `malloc`/`free`, see `raw_c_allocator`. | 154 | /// `malloc`/`free`, see `raw_c_allocator`. |
| 157 | pub const c_allocator = &c_allocator_state; | 155 | pub const c_allocator = blk: { |
| 158 | var c_allocator_state = Allocator{ | 156 | // TODO: This is an ugly hack, it could be improved once https://github.com/ziglang/zig/issues/6706 is implemented |
| 159 | .allocFn = CAllocator.alloc, | 157 | // allowing the use of `*void` but it would still be ugly |
| 160 | .resizeFn = CAllocator.resize, | 158 | var tmp: u1 = 0; |
| 159 | break :blk Allocator.init(&tmp, CAllocator.alloc, CAllocator.resize); | ||
| 161 | }; | 160 | }; |
| 162 | 161 | ||
| 163 | /// Asserts allocations are within `@alignOf(std.c.max_align_t)` and directly calls | 162 | /// Asserts allocations are within `@alignOf(std.c.max_align_t)` and directly calls |
| ... | @@ -165,20 +164,20 @@ var c_allocator_state = Allocator{ | ... | @@ -165,20 +164,20 @@ var c_allocator_state = Allocator{ |
| 165 | /// This allocator is safe to use as the backing allocator with | 164 | /// This allocator is safe to use as the backing allocator with |
| 166 | /// `ArenaAllocator` for example and is more optimal in such a case | 165 | /// `ArenaAllocator` for example and is more optimal in such a case |
| 167 | /// than `c_allocator`. | 166 | /// than `c_allocator`. |
| 168 | pub const raw_c_allocator = &raw_c_allocator_state; | 167 | pub const raw_c_allocator = blk: { |
| 169 | var raw_c_allocator_state = Allocator{ | 168 | // TODO: This is an ugly hack, it could be improved once https://github.com/ziglang/zig/issues/6706 is implemented |
| 170 | .allocFn = rawCAlloc, | 169 | // allowing the use of `*void` but it would still be ugly |
| 171 | .resizeFn = rawCResize, | 170 | var tmp: u1 = 0; |
| 171 | break :blk Allocator.init(&tmp, rawCAlloc, rawCResize); | ||
| 172 | }; | 172 | }; |
| 173 | 173 | ||
| 174 | fn rawCAlloc( | 174 | fn rawCAlloc( |
| 175 | self: *Allocator, | 175 | _: *u1, |
| 176 | len: usize, | 176 | len: usize, |
| 177 | ptr_align: u29, | 177 | ptr_align: u29, |
| 178 | len_align: u29, | 178 | len_align: u29, |
| 179 | ret_addr: usize, | 179 | ret_addr: usize, |
| 180 | ) Allocator.Error![]u8 { | 180 | ) Allocator.Error![]u8 { |
| 181 | _ = self; | ||
| 182 | _ = len_align; | 181 | _ = len_align; |
| 183 | _ = ret_addr; | 182 | _ = ret_addr; |
| 184 | assert(ptr_align <= @alignOf(std.c.max_align_t)); | 183 | assert(ptr_align <= @alignOf(std.c.max_align_t)); |
| ... | @@ -187,14 +186,13 @@ fn rawCAlloc( | ... | @@ -187,14 +186,13 @@ fn rawCAlloc( |
| 187 | } | 186 | } |
| 188 | 187 | ||
| 189 | fn rawCResize( | 188 | fn rawCResize( |
| 190 | self: *Allocator, | 189 | _: *u1, |
| 191 | buf: []u8, | 190 | buf: []u8, |
| 192 | old_align: u29, | 191 | old_align: u29, |
| 193 | new_len: usize, | 192 | new_len: usize, |
| 194 | len_align: u29, | 193 | len_align: u29, |
| 195 | ret_addr: usize, | 194 | ret_addr: usize, |
| 196 | ) Allocator.Error!usize { | 195 | ) Allocator.Error!usize { |
| 197 | _ = self; | ||
| 198 | _ = old_align; | 196 | _ = old_align; |
| 199 | _ = ret_addr; | 197 | _ = ret_addr; |
| 200 | if (new_len == 0) { | 198 | if (new_len == 0) { |
| ... | @@ -210,19 +208,18 @@ fn rawCResize( | ... | @@ -210,19 +208,18 @@ fn rawCResize( |
| 210 | /// This allocator makes a syscall directly for every allocation and free. | 208 | /// This allocator makes a syscall directly for every allocation and free. |
| 211 | /// Thread-safe and lock-free. | 209 | /// Thread-safe and lock-free. |
| 212 | pub const page_allocator = if (builtin.target.isWasm()) | 210 | pub const page_allocator = if (builtin.target.isWasm()) |
| 213 | &wasm_page_allocator_state | 211 | blk: { |
| 214 | else if (builtin.target.os.tag == .freestanding) | 212 | // TODO: This is an ugly hack, it could be improved once https://github.com/ziglang/zig/issues/6706 is implemented |
| 213 | // allowing the use of `*void` but it would still be ugly | ||
| 214 | var tmp: u1 = 0; | ||
| 215 | break :blk Allocator.init(&tmp, WasmPageAllocator.alloc, WasmPageAllocator.resize); | ||
| 216 | } else if (builtin.target.os.tag == .freestanding) | ||
| 215 | root.os.heap.page_allocator | 217 | root.os.heap.page_allocator |
| 216 | else | 218 | else blk: { |
| 217 | &page_allocator_state; | 219 | // TODO: This is an ugly hack, it could be improved once https://github.com/ziglang/zig/issues/6706 is implemented |
| 218 | 220 | // allowing the use of `*void` but it would still be ugly | |
| 219 | var page_allocator_state = Allocator{ | 221 | var tmp: u1 = 0; |
| 220 | .allocFn = PageAllocator.alloc, | 222 | break :blk Allocator.init(&tmp, PageAllocator.alloc, PageAllocator.resize); |
| 221 | .resizeFn = PageAllocator.resize, | ||
| 222 | }; | ||
| 223 | var wasm_page_allocator_state = Allocator{ | ||
| 224 | .allocFn = WasmPageAllocator.alloc, | ||
| 225 | .resizeFn = WasmPageAllocator.resize, | ||
| 226 | }; | 223 | }; |
| 227 | 224 | ||
| 228 | /// Verifies that the adjusted length will still map to the full length | 225 | /// Verifies that the adjusted length will still map to the full length |
| ... | @@ -236,8 +233,7 @@ pub fn alignPageAllocLen(full_len: usize, len: usize, len_align: u29) usize { | ... | @@ -236,8 +233,7 @@ pub fn alignPageAllocLen(full_len: usize, len: usize, len_align: u29) usize { |
| 236 | pub var next_mmap_addr_hint: ?[*]align(mem.page_size) u8 = null; | 233 | pub var next_mmap_addr_hint: ?[*]align(mem.page_size) u8 = null; |
| 237 | 234 | ||
| 238 | const PageAllocator = struct { | 235 | const PageAllocator = struct { |
| 239 | fn alloc(allocator: *Allocator, n: usize, alignment: u29, len_align: u29, ra: usize) error{OutOfMemory}![]u8 { | 236 | fn alloc(_: *u1, n: usize, alignment: u29, len_align: u29, ra: usize) error{OutOfMemory}![]u8 { |
| 240 | _ = allocator; | ||
| 241 | _ = ra; | 237 | _ = ra; |
| 242 | assert(n > 0); | 238 | assert(n > 0); |
| 243 | const aligned_len = mem.alignForward(n, mem.page_size); | 239 | const aligned_len = mem.alignForward(n, mem.page_size); |
| ... | @@ -335,14 +331,13 @@ const PageAllocator = struct { | ... | @@ -335,14 +331,13 @@ const PageAllocator = struct { |
| 335 | } | 331 | } |
| 336 | 332 | ||
| 337 | fn resize( | 333 | fn resize( |
| 338 | allocator: *Allocator, | 334 | _: *u1, |
| 339 | buf_unaligned: []u8, | 335 | buf_unaligned: []u8, |
| 340 | buf_align: u29, | 336 | buf_align: u29, |
| 341 | new_size: usize, | 337 | new_size: usize, |
| 342 | len_align: u29, | 338 | len_align: u29, |
| 343 | return_address: usize, | 339 | return_address: usize, |
| 344 | ) Allocator.Error!usize { | 340 | ) Allocator.Error!usize { |
| 345 | _ = allocator; | ||
| 346 | _ = buf_align; | 341 | _ = buf_align; |
| 347 | _ = return_address; | 342 | _ = return_address; |
| 348 | const new_size_aligned = mem.alignForward(new_size, mem.page_size); | 343 | const new_size_aligned = mem.alignForward(new_size, mem.page_size); |
| ... | @@ -492,8 +487,7 @@ const WasmPageAllocator = struct { | ... | @@ -492,8 +487,7 @@ const WasmPageAllocator = struct { |
| 492 | return mem.alignForward(memsize, mem.page_size) / mem.page_size; | 487 | return mem.alignForward(memsize, mem.page_size) / mem.page_size; |
| 493 | } | 488 | } |
| 494 | 489 | ||
| 495 | fn alloc(allocator: *Allocator, len: usize, alignment: u29, len_align: u29, ra: usize) error{OutOfMemory}![]u8 { | 490 | fn alloc(_: *u1, len: usize, alignment: u29, len_align: u29, ra: usize) error{OutOfMemory}![]u8 { |
| 496 | _ = allocator; | ||
| 497 | _ = ra; | 491 | _ = ra; |
| 498 | const page_count = nPages(len); | 492 | const page_count = nPages(len); |
| 499 | const page_idx = try allocPages(page_count, alignment); | 493 | const page_idx = try allocPages(page_count, alignment); |
| ... | @@ -548,14 +542,13 @@ const WasmPageAllocator = struct { | ... | @@ -548,14 +542,13 @@ const WasmPageAllocator = struct { |
| 548 | } | 542 | } |
| 549 | 543 | ||
| 550 | fn resize( | 544 | fn resize( |
| 551 | allocator: *Allocator, | 545 | _: *u1, |
| 552 | buf: []u8, | 546 | buf: []u8, |
| 553 | buf_align: u29, | 547 | buf_align: u29, |
| 554 | new_len: usize, | 548 | new_len: usize, |
| 555 | len_align: u29, | 549 | len_align: u29, |
| 556 | return_address: usize, | 550 | return_address: usize, |
| 557 | ) error{OutOfMemory}!usize { | 551 | ) error{OutOfMemory}!usize { |
| 558 | _ = allocator; | ||
| 559 | _ = buf_align; | 552 | _ = buf_align; |
| 560 | _ = return_address; | 553 | _ = return_address; |
| 561 | const aligned_len = mem.alignForward(buf.len, mem.page_size); | 554 | const aligned_len = mem.alignForward(buf.len, mem.page_size); |
| ... | @@ -572,21 +565,20 @@ const WasmPageAllocator = struct { | ... | @@ -572,21 +565,20 @@ const WasmPageAllocator = struct { |
| 572 | 565 | ||
| 573 | pub const HeapAllocator = switch (builtin.os.tag) { | 566 | pub const HeapAllocator = switch (builtin.os.tag) { |
| 574 | .windows => struct { | 567 | .windows => struct { |
| 575 | allocator: Allocator, | ||
| 576 | heap_handle: ?HeapHandle, | 568 | heap_handle: ?HeapHandle, |
| 577 | 569 | ||
| 578 | const HeapHandle = os.windows.HANDLE; | 570 | const HeapHandle = os.windows.HANDLE; |
| 579 | 571 | ||
| 580 | pub fn init() HeapAllocator { | 572 | pub fn init() HeapAllocator { |
| 581 | return HeapAllocator{ | 573 | return HeapAllocator{ |
| 582 | .allocator = Allocator{ | ||
| 583 | .allocFn = alloc, | ||
| 584 | .resizeFn = resize, | ||
| 585 | }, | ||
| 586 | .heap_handle = null, | 574 | .heap_handle = null, |
| 587 | }; | 575 | }; |
| 588 | } | 576 | } |
| 589 | 577 | ||
| 578 | pub fn getAllocator(self: *HeapAllocator) Allocator { | ||
| 579 | return Allocator.init(self, alloc, resize); | ||
| 580 | } | ||
| 581 | |||
| 590 | pub fn deinit(self: *HeapAllocator) void { | 582 | pub fn deinit(self: *HeapAllocator) void { |
| 591 | if (self.heap_handle) |heap_handle| { | 583 | if (self.heap_handle) |heap_handle| { |
| 592 | os.windows.HeapDestroy(heap_handle); | 584 | os.windows.HeapDestroy(heap_handle); |
| ... | @@ -598,14 +590,13 @@ pub const HeapAllocator = switch (builtin.os.tag) { | ... | @@ -598,14 +590,13 @@ pub const HeapAllocator = switch (builtin.os.tag) { |
| 598 | } | 590 | } |
| 599 | 591 | ||
| 600 | fn alloc( | 592 | fn alloc( |
| 601 | allocator: *Allocator, | 593 | self: *HeapAllocator, |
| 602 | n: usize, | 594 | n: usize, |
| 603 | ptr_align: u29, | 595 | ptr_align: u29, |
| 604 | len_align: u29, | 596 | len_align: u29, |
| 605 | return_address: usize, | 597 | return_address: usize, |
| 606 | ) error{OutOfMemory}![]u8 { | 598 | ) error{OutOfMemory}![]u8 { |
| 607 | _ = return_address; | 599 | _ = return_address; |
| 608 | const self = @fieldParentPtr(HeapAllocator, "allocator", allocator); | ||
| 609 | 600 | ||
| 610 | const amt = n + ptr_align - 1 + @sizeOf(usize); | 601 | const amt = n + ptr_align - 1 + @sizeOf(usize); |
| 611 | const optional_heap_handle = @atomicLoad(?HeapHandle, &self.heap_handle, .SeqCst); | 602 | const optional_heap_handle = @atomicLoad(?HeapHandle, &self.heap_handle, .SeqCst); |
| ... | @@ -632,7 +623,7 @@ pub const HeapAllocator = switch (builtin.os.tag) { | ... | @@ -632,7 +623,7 @@ pub const HeapAllocator = switch (builtin.os.tag) { |
| 632 | } | 623 | } |
| 633 | 624 | ||
| 634 | fn resize( | 625 | fn resize( |
| 635 | allocator: *Allocator, | 626 | self: *HeapAllocator, |
| 636 | buf: []u8, | 627 | buf: []u8, |
| 637 | buf_align: u29, | 628 | buf_align: u29, |
| 638 | new_size: usize, | 629 | new_size: usize, |
| ... | @@ -641,7 +632,6 @@ pub const HeapAllocator = switch (builtin.os.tag) { | ... | @@ -641,7 +632,6 @@ pub const HeapAllocator = switch (builtin.os.tag) { |
| 641 | ) error{OutOfMemory}!usize { | 632 | ) error{OutOfMemory}!usize { |
| 642 | _ = buf_align; | 633 | _ = buf_align; |
| 643 | _ = return_address; | 634 | _ = return_address; |
| 644 | const self = @fieldParentPtr(HeapAllocator, "allocator", allocator); | ||
| 645 | if (new_size == 0) { | 635 | if (new_size == 0) { |
| 646 | os.windows.HeapFree(self.heap_handle.?, 0, @intToPtr(*c_void, getRecordPtr(buf).*)); | 636 | os.windows.HeapFree(self.heap_handle.?, 0, @intToPtr(*c_void, getRecordPtr(buf).*)); |
| 647 | return 0; | 637 | return 0; |
| ... | @@ -682,21 +672,27 @@ fn sliceContainsSlice(container: []u8, slice: []u8) bool { | ... | @@ -682,21 +672,27 @@ fn sliceContainsSlice(container: []u8, slice: []u8) bool { |
| 682 | } | 672 | } |
| 683 | 673 | ||
| 684 | pub const FixedBufferAllocator = struct { | 674 | pub const FixedBufferAllocator = struct { |
| 685 | allocator: Allocator, | ||
| 686 | end_index: usize, | 675 | end_index: usize, |
| 687 | buffer: []u8, | 676 | buffer: []u8, |
| 688 | 677 | ||
| 689 | pub fn init(buffer: []u8) FixedBufferAllocator { | 678 | pub fn init(buffer: []u8) FixedBufferAllocator { |
| 690 | return FixedBufferAllocator{ | 679 | return FixedBufferAllocator{ |
| 691 | .allocator = Allocator{ | ||
| 692 | .allocFn = alloc, | ||
| 693 | .resizeFn = resize, | ||
| 694 | }, | ||
| 695 | .buffer = buffer, | 680 | .buffer = buffer, |
| 696 | .end_index = 0, | 681 | .end_index = 0, |
| 697 | }; | 682 | }; |
| 698 | } | 683 | } |
| 699 | 684 | ||
| 685 | /// *WARNING* using this at the same time as the interface returned by `getThreadSafeAllocator` is not thread safe | ||
| 686 | pub fn getAllocator(self: *FixedBufferAllocator) Allocator { | ||
| 687 | return Allocator.init(self, alloc, resize); | ||
| 688 | } | ||
| 689 | |||
| 690 | /// Provides a lock free thread safe `Allocator` interface to the underlying `FixedBufferAllocator` | ||
| 691 | /// *WARNING* using this at the same time as the interface returned by `getAllocator` is not thread safe | ||
| 692 | pub fn getThreadSafeAllocator(self: *FixedBufferAllocator) Allocator { | ||
| 693 | return Allocator.init(self, threadSafeAlloc, Allocator.NoResize(FixedBufferAllocator).noResize); | ||
| 694 | } | ||
| 695 | |||
| 700 | pub fn ownsPtr(self: *FixedBufferAllocator, ptr: [*]u8) bool { | 696 | pub fn ownsPtr(self: *FixedBufferAllocator, ptr: [*]u8) bool { |
| 701 | return sliceContainsPtr(self.buffer, ptr); | 697 | return sliceContainsPtr(self.buffer, ptr); |
| 702 | } | 698 | } |
| ... | @@ -712,10 +708,9 @@ pub const FixedBufferAllocator = struct { | ... | @@ -712,10 +708,9 @@ pub const FixedBufferAllocator = struct { |
| 712 | return buf.ptr + buf.len == self.buffer.ptr + self.end_index; | 708 | return buf.ptr + buf.len == self.buffer.ptr + self.end_index; |
| 713 | } | 709 | } |
| 714 | 710 | ||
| 715 | fn alloc(allocator: *Allocator, n: usize, ptr_align: u29, len_align: u29, ra: usize) ![]u8 { | 711 | fn alloc(self: *FixedBufferAllocator, n: usize, ptr_align: u29, len_align: u29, ra: usize) ![]u8 { |
| 716 | _ = len_align; | 712 | _ = len_align; |
| 717 | _ = ra; | 713 | _ = ra; |
| 718 | const self = @fieldParentPtr(FixedBufferAllocator, "allocator", allocator); | ||
| 719 | const adjust_off = mem.alignPointerOffset(self.buffer.ptr + self.end_index, ptr_align) orelse | 714 | const adjust_off = mem.alignPointerOffset(self.buffer.ptr + self.end_index, ptr_align) orelse |
| 720 | return error.OutOfMemory; | 715 | return error.OutOfMemory; |
| 721 | const adjusted_index = self.end_index + adjust_off; | 716 | const adjusted_index = self.end_index + adjust_off; |
| ... | @@ -730,7 +725,7 @@ pub const FixedBufferAllocator = struct { | ... | @@ -730,7 +725,7 @@ pub const FixedBufferAllocator = struct { |
| 730 | } | 725 | } |
| 731 | 726 | ||
| 732 | fn resize( | 727 | fn resize( |
| 733 | allocator: *Allocator, | 728 | self: *FixedBufferAllocator, |
| 734 | buf: []u8, | 729 | buf: []u8, |
| 735 | buf_align: u29, | 730 | buf_align: u29, |
| 736 | new_size: usize, | 731 | new_size: usize, |
| ... | @@ -739,7 +734,6 @@ pub const FixedBufferAllocator = struct { | ... | @@ -739,7 +734,6 @@ pub const FixedBufferAllocator = struct { |
| 739 | ) Allocator.Error!usize { | 734 | ) Allocator.Error!usize { |
| 740 | _ = buf_align; | 735 | _ = buf_align; |
| 741 | _ = return_address; | 736 | _ = return_address; |
| 742 | const self = @fieldParentPtr(FixedBufferAllocator, "allocator", allocator); | ||
| 743 | assert(self.ownsSlice(buf)); // sanity check | 737 | assert(self.ownsSlice(buf)); // sanity check |
| 744 | 738 | ||
| 745 | if (!self.isLastAllocation(buf)) { | 739 | if (!self.isLastAllocation(buf)) { |
| ... | @@ -762,65 +756,34 @@ pub const FixedBufferAllocator = struct { | ... | @@ -762,65 +756,34 @@ pub const FixedBufferAllocator = struct { |
| 762 | return new_size; | 756 | return new_size; |
| 763 | } | 757 | } |
| 764 | 758 | ||
| 759 | fn threadSafeAlloc(self: *FixedBufferAllocator, n: usize, ptr_align: u29, len_align: u29, ra: usize) ![]u8 { | ||
| 760 | _ = len_align; | ||
| 761 | _ = ra; | ||
| 762 | var end_index = @atomicLoad(usize, &self.end_index, .SeqCst); | ||
| 763 | while (true) { | ||
| 764 | const adjust_off = mem.alignPointerOffset(self.buffer.ptr + end_index, ptr_align) orelse | ||
| 765 | return error.OutOfMemory; | ||
| 766 | const adjusted_index = end_index + adjust_off; | ||
| 767 | const new_end_index = adjusted_index + n; | ||
| 768 | if (new_end_index > self.buffer.len) { | ||
| 769 | return error.OutOfMemory; | ||
| 770 | } | ||
| 771 | end_index = @cmpxchgWeak(usize, &self.end_index, end_index, new_end_index, .SeqCst, .SeqCst) orelse return self.buffer[adjusted_index..new_end_index]; | ||
| 772 | } | ||
| 773 | } | ||
| 774 | |||
| 765 | pub fn reset(self: *FixedBufferAllocator) void { | 775 | pub fn reset(self: *FixedBufferAllocator) void { |
| 766 | self.end_index = 0; | 776 | self.end_index = 0; |
| 767 | } | 777 | } |
| 768 | }; | 778 | }; |
| 769 | 779 | ||
| 770 | pub const ThreadSafeFixedBufferAllocator = blk: { | 780 | pub const ThreadSafeFixedBufferAllocator = @compileError("ThreadSafeFixedBufferAllocator has been replaced with `getThreadSafeAllocator` on FixedBufferAllocator"); |
| 771 | if (builtin.single_threaded) { | ||
| 772 | break :blk FixedBufferAllocator; | ||
| 773 | } else { | ||
| 774 | // lock free | ||
| 775 | break :blk struct { | ||
| 776 | allocator: Allocator, | ||
| 777 | end_index: usize, | ||
| 778 | buffer: []u8, | ||
| 779 | |||
| 780 | pub fn init(buffer: []u8) ThreadSafeFixedBufferAllocator { | ||
| 781 | return ThreadSafeFixedBufferAllocator{ | ||
| 782 | .allocator = Allocator{ | ||
| 783 | .allocFn = alloc, | ||
| 784 | .resizeFn = Allocator.noResize, | ||
| 785 | }, | ||
| 786 | .buffer = buffer, | ||
| 787 | .end_index = 0, | ||
| 788 | }; | ||
| 789 | } | ||
| 790 | |||
| 791 | fn alloc(allocator: *Allocator, n: usize, ptr_align: u29, len_align: u29, ra: usize) ![]u8 { | ||
| 792 | _ = len_align; | ||
| 793 | _ = ra; | ||
| 794 | const self = @fieldParentPtr(ThreadSafeFixedBufferAllocator, "allocator", allocator); | ||
| 795 | var end_index = @atomicLoad(usize, &self.end_index, .SeqCst); | ||
| 796 | while (true) { | ||
| 797 | const adjust_off = mem.alignPointerOffset(self.buffer.ptr + end_index, ptr_align) orelse | ||
| 798 | return error.OutOfMemory; | ||
| 799 | const adjusted_index = end_index + adjust_off; | ||
| 800 | const new_end_index = adjusted_index + n; | ||
| 801 | if (new_end_index > self.buffer.len) { | ||
| 802 | return error.OutOfMemory; | ||
| 803 | } | ||
| 804 | end_index = @cmpxchgWeak(usize, &self.end_index, end_index, new_end_index, .SeqCst, .SeqCst) orelse return self.buffer[adjusted_index..new_end_index]; | ||
| 805 | } | ||
| 806 | } | ||
| 807 | 781 | ||
| 808 | pub fn reset(self: *ThreadSafeFixedBufferAllocator) void { | 782 | pub fn stackFallback(comptime size: usize, fallback_allocator: Allocator) StackFallbackAllocator(size) { |
| 809 | self.end_index = 0; | ||
| 810 | } | ||
| 811 | }; | ||
| 812 | } | ||
| 813 | }; | ||
| 814 | |||
| 815 | pub fn stackFallback(comptime size: usize, fallback_allocator: *Allocator) StackFallbackAllocator(size) { | ||
| 816 | return StackFallbackAllocator(size){ | 783 | return StackFallbackAllocator(size){ |
| 817 | .buffer = undefined, | 784 | .buffer = undefined, |
| 818 | .fallback_allocator = fallback_allocator, | 785 | .fallback_allocator = fallback_allocator, |
| 819 | .fixed_buffer_allocator = undefined, | 786 | .fixed_buffer_allocator = undefined, |
| 820 | .allocator = Allocator{ | ||
| 821 | .allocFn = StackFallbackAllocator(size).alloc, | ||
| 822 | .resizeFn = StackFallbackAllocator(size).resize, | ||
| 823 | }, | ||
| 824 | }; | 787 | }; |
| 825 | } | 788 | } |
| 826 | 789 | ||
| ... | @@ -829,40 +792,38 @@ pub fn StackFallbackAllocator(comptime size: usize) type { | ... | @@ -829,40 +792,38 @@ pub fn StackFallbackAllocator(comptime size: usize) type { |
| 829 | const Self = @This(); | 792 | const Self = @This(); |
| 830 | 793 | ||
| 831 | buffer: [size]u8, | 794 | buffer: [size]u8, |
| 832 | allocator: Allocator, | 795 | fallback_allocator: Allocator, |
| 833 | fallback_allocator: *Allocator, | ||
| 834 | fixed_buffer_allocator: FixedBufferAllocator, | 796 | fixed_buffer_allocator: FixedBufferAllocator, |
| 835 | 797 | ||
| 836 | pub fn get(self: *Self) *Allocator { | 798 | /// WARNING: This functions both fetches a `std.mem.Allocator` interface to this allocator *and* resets the internal buffer allocator |
| 799 | pub fn get(self: *Self) Allocator { | ||
| 837 | self.fixed_buffer_allocator = FixedBufferAllocator.init(self.buffer[0..]); | 800 | self.fixed_buffer_allocator = FixedBufferAllocator.init(self.buffer[0..]); |
| 838 | return &self.allocator; | 801 | return Allocator.init(self, alloc, resize); |
| 839 | } | 802 | } |
| 840 | 803 | ||
| 841 | fn alloc( | 804 | fn alloc( |
| 842 | allocator: *Allocator, | 805 | self: *Self, |
| 843 | len: usize, | 806 | len: usize, |
| 844 | ptr_align: u29, | 807 | ptr_align: u29, |
| 845 | len_align: u29, | 808 | len_align: u29, |
| 846 | return_address: usize, | 809 | return_address: usize, |
| 847 | ) error{OutOfMemory}![]u8 { | 810 | ) error{OutOfMemory}![]u8 { |
| 848 | const self = @fieldParentPtr(Self, "allocator", allocator); | 811 | return FixedBufferAllocator.alloc(&self.fixed_buffer_allocator, len, ptr_align, len_align, return_address) catch |
| 849 | return FixedBufferAllocator.alloc(&self.fixed_buffer_allocator.allocator, len, ptr_align, len_align, return_address) catch | 812 | return self.fallback_allocator.allocFn(self.fallback_allocator.ptr, len, ptr_align, len_align, return_address); |
| 850 | return self.fallback_allocator.allocFn(self.fallback_allocator, len, ptr_align, len_align, return_address); | ||
| 851 | } | 813 | } |
| 852 | 814 | ||
| 853 | fn resize( | 815 | fn resize( |
| 854 | allocator: *Allocator, | 816 | self: *Self, |
| 855 | buf: []u8, | 817 | buf: []u8, |
| 856 | buf_align: u29, | 818 | buf_align: u29, |
| 857 | new_len: usize, | 819 | new_len: usize, |
| 858 | len_align: u29, | 820 | len_align: u29, |
| 859 | return_address: usize, | 821 | return_address: usize, |
| 860 | ) error{OutOfMemory}!usize { | 822 | ) error{OutOfMemory}!usize { |
| 861 | const self = @fieldParentPtr(Self, "allocator", allocator); | ||
| 862 | if (self.fixed_buffer_allocator.ownsPtr(buf.ptr)) { | 823 | if (self.fixed_buffer_allocator.ownsPtr(buf.ptr)) { |
| 863 | return FixedBufferAllocator.resize(&self.fixed_buffer_allocator.allocator, buf, buf_align, new_len, len_align, return_address); | 824 | return FixedBufferAllocator.resize(&self.fixed_buffer_allocator, buf, buf_align, new_len, len_align, return_address); |
| 864 | } else { | 825 | } else { |
| 865 | return self.fallback_allocator.resizeFn(self.fallback_allocator, buf, buf_align, new_len, len_align, return_address); | 826 | return self.fallback_allocator.resizeFn(self.fallback_allocator.ptr, buf, buf_align, new_len, len_align, return_address); |
| 866 | } | 827 | } |
| 867 | } | 828 | } |
| 868 | }; | 829 | }; |
| ... | @@ -950,8 +911,8 @@ test "HeapAllocator" { | ... | @@ -950,8 +911,8 @@ test "HeapAllocator" { |
| 950 | if (builtin.os.tag == .windows) { | 911 | if (builtin.os.tag == .windows) { |
| 951 | var heap_allocator = HeapAllocator.init(); | 912 | var heap_allocator = HeapAllocator.init(); |
| 952 | defer heap_allocator.deinit(); | 913 | defer heap_allocator.deinit(); |
| 914 | const allocator = heap_allocator.getAllocator(); | ||
| 953 | 915 | ||
| 954 | const allocator = &heap_allocator.allocator; | ||
| 955 | try testAllocator(allocator); | 916 | try testAllocator(allocator); |
| 956 | try testAllocatorAligned(allocator); | 917 | try testAllocatorAligned(allocator); |
| 957 | try testAllocatorLargeAlignment(allocator); | 918 | try testAllocatorLargeAlignment(allocator); |
| ... | @@ -962,36 +923,39 @@ test "HeapAllocator" { | ... | @@ -962,36 +923,39 @@ test "HeapAllocator" { |
| 962 | test "ArenaAllocator" { | 923 | test "ArenaAllocator" { |
| 963 | var arena_allocator = ArenaAllocator.init(page_allocator); | 924 | var arena_allocator = ArenaAllocator.init(page_allocator); |
| 964 | defer arena_allocator.deinit(); | 925 | defer arena_allocator.deinit(); |
| 926 | const allocator = arena_allocator.getAllocator(); | ||
| 965 | 927 | ||
| 966 | try testAllocator(&arena_allocator.allocator); | 928 | try testAllocator(allocator); |
| 967 | try testAllocatorAligned(&arena_allocator.allocator); | 929 | try testAllocatorAligned(allocator); |
| 968 | try testAllocatorLargeAlignment(&arena_allocator.allocator); | 930 | try testAllocatorLargeAlignment(allocator); |
| 969 | try testAllocatorAlignedShrink(&arena_allocator.allocator); | 931 | try testAllocatorAlignedShrink(allocator); |
| 970 | } | 932 | } |
| 971 | 933 | ||
| 972 | var test_fixed_buffer_allocator_memory: [800000 * @sizeOf(u64)]u8 = undefined; | 934 | var test_fixed_buffer_allocator_memory: [800000 * @sizeOf(u64)]u8 = undefined; |
| 973 | test "FixedBufferAllocator" { | 935 | test "FixedBufferAllocator" { |
| 974 | var fixed_buffer_allocator = mem.validationWrap(FixedBufferAllocator.init(test_fixed_buffer_allocator_memory[0..])); | 936 | var fixed_buffer_allocator = mem.validationWrap(FixedBufferAllocator.init(test_fixed_buffer_allocator_memory[0..])); |
| 937 | const allocator = fixed_buffer_allocator.getAllocator(); | ||
| 975 | 938 | ||
| 976 | try testAllocator(&fixed_buffer_allocator.allocator); | 939 | try testAllocator(allocator); |
| 977 | try testAllocatorAligned(&fixed_buffer_allocator.allocator); | 940 | try testAllocatorAligned(allocator); |
| 978 | try testAllocatorLargeAlignment(&fixed_buffer_allocator.allocator); | 941 | try testAllocatorLargeAlignment(allocator); |
| 979 | try testAllocatorAlignedShrink(&fixed_buffer_allocator.allocator); | 942 | try testAllocatorAlignedShrink(allocator); |
| 980 | } | 943 | } |
| 981 | 944 | ||
| 982 | test "FixedBufferAllocator.reset" { | 945 | test "FixedBufferAllocator.reset" { |
| 983 | var buf: [8]u8 align(@alignOf(u64)) = undefined; | 946 | var buf: [8]u8 align(@alignOf(u64)) = undefined; |
| 984 | var fba = FixedBufferAllocator.init(buf[0..]); | 947 | var fba = FixedBufferAllocator.init(buf[0..]); |
| 948 | const allocator = fba.getAllocator(); | ||
| 985 | 949 | ||
| 986 | const X = 0xeeeeeeeeeeeeeeee; | 950 | const X = 0xeeeeeeeeeeeeeeee; |
| 987 | const Y = 0xffffffffffffffff; | 951 | const Y = 0xffffffffffffffff; |
| 988 | 952 | ||
| 989 | var x = try fba.allocator.create(u64); | 953 | var x = try allocator.create(u64); |
| 990 | x.* = X; | 954 | x.* = X; |
| 991 | try testing.expectError(error.OutOfMemory, fba.allocator.create(u64)); | 955 | try testing.expectError(error.OutOfMemory, allocator.create(u64)); |
| 992 | 956 | ||
| 993 | fba.reset(); | 957 | fba.reset(); |
| 994 | var y = try fba.allocator.create(u64); | 958 | var y = try allocator.create(u64); |
| 995 | y.* = Y; | 959 | y.* = Y; |
| 996 | 960 | ||
| 997 | // we expect Y to have overwritten X. | 961 | // we expect Y to have overwritten X. |
| ... | @@ -1014,23 +978,25 @@ test "FixedBufferAllocator Reuse memory on realloc" { | ... | @@ -1014,23 +978,25 @@ test "FixedBufferAllocator Reuse memory on realloc" { |
| 1014 | // check if we re-use the memory | 978 | // check if we re-use the memory |
| 1015 | { | 979 | { |
| 1016 | var fixed_buffer_allocator = FixedBufferAllocator.init(small_fixed_buffer[0..]); | 980 | var fixed_buffer_allocator = FixedBufferAllocator.init(small_fixed_buffer[0..]); |
| 981 | const allocator = fixed_buffer_allocator.getAllocator(); | ||
| 1017 | 982 | ||
| 1018 | var slice0 = try fixed_buffer_allocator.allocator.alloc(u8, 5); | 983 | var slice0 = try allocator.alloc(u8, 5); |
| 1019 | try testing.expect(slice0.len == 5); | 984 | try testing.expect(slice0.len == 5); |
| 1020 | var slice1 = try fixed_buffer_allocator.allocator.realloc(slice0, 10); | 985 | var slice1 = try allocator.realloc(slice0, 10); |
| 1021 | try testing.expect(slice1.ptr == slice0.ptr); | 986 | try testing.expect(slice1.ptr == slice0.ptr); |
| 1022 | try testing.expect(slice1.len == 10); | 987 | try testing.expect(slice1.len == 10); |
| 1023 | try testing.expectError(error.OutOfMemory, fixed_buffer_allocator.allocator.realloc(slice1, 11)); | 988 | try testing.expectError(error.OutOfMemory, allocator.realloc(slice1, 11)); |
| 1024 | } | 989 | } |
| 1025 | // check that we don't re-use the memory if it's not the most recent block | 990 | // check that we don't re-use the memory if it's not the most recent block |
| 1026 | { | 991 | { |
| 1027 | var fixed_buffer_allocator = FixedBufferAllocator.init(small_fixed_buffer[0..]); | 992 | var fixed_buffer_allocator = FixedBufferAllocator.init(small_fixed_buffer[0..]); |
| 993 | const allocator = fixed_buffer_allocator.getAllocator(); | ||
| 1028 | 994 | ||
| 1029 | var slice0 = try fixed_buffer_allocator.allocator.alloc(u8, 2); | 995 | var slice0 = try allocator.alloc(u8, 2); |
| 1030 | slice0[0] = 1; | 996 | slice0[0] = 1; |
| 1031 | slice0[1] = 2; | 997 | slice0[1] = 2; |
| 1032 | var slice1 = try fixed_buffer_allocator.allocator.alloc(u8, 2); | 998 | var slice1 = try allocator.alloc(u8, 2); |
| 1033 | var slice2 = try fixed_buffer_allocator.allocator.realloc(slice0, 4); | 999 | var slice2 = try allocator.realloc(slice0, 4); |
| 1034 | try testing.expect(slice0.ptr != slice2.ptr); | 1000 | try testing.expect(slice0.ptr != slice2.ptr); |
| 1035 | try testing.expect(slice1.ptr != slice2.ptr); | 1001 | try testing.expect(slice1.ptr != slice2.ptr); |
| 1036 | try testing.expect(slice2[0] == 1); | 1002 | try testing.expect(slice2[0] == 1); |
| ... | @@ -1038,19 +1004,19 @@ test "FixedBufferAllocator Reuse memory on realloc" { | ... | @@ -1038,19 +1004,19 @@ test "FixedBufferAllocator Reuse memory on realloc" { |
| 1038 | } | 1004 | } |
| 1039 | } | 1005 | } |
| 1040 | 1006 | ||
| 1041 | test "ThreadSafeFixedBufferAllocator" { | 1007 | test "Thread safe FixedBufferAllocator" { |
| 1042 | var fixed_buffer_allocator = ThreadSafeFixedBufferAllocator.init(test_fixed_buffer_allocator_memory[0..]); | 1008 | var fixed_buffer_allocator = FixedBufferAllocator.init(test_fixed_buffer_allocator_memory[0..]); |
| 1043 | 1009 | ||
| 1044 | try testAllocator(&fixed_buffer_allocator.allocator); | 1010 | try testAllocator(fixed_buffer_allocator.getThreadSafeAllocator()); |
| 1045 | try testAllocatorAligned(&fixed_buffer_allocator.allocator); | 1011 | try testAllocatorAligned(fixed_buffer_allocator.getThreadSafeAllocator()); |
| 1046 | try testAllocatorLargeAlignment(&fixed_buffer_allocator.allocator); | 1012 | try testAllocatorLargeAlignment(fixed_buffer_allocator.getThreadSafeAllocator()); |
| 1047 | try testAllocatorAlignedShrink(&fixed_buffer_allocator.allocator); | 1013 | try testAllocatorAlignedShrink(fixed_buffer_allocator.getThreadSafeAllocator()); |
| 1048 | } | 1014 | } |
| 1049 | 1015 | ||
| 1050 | /// This one should not try alignments that exceed what C malloc can handle. | 1016 | /// This one should not try alignments that exceed what C malloc can handle. |
| 1051 | pub fn testAllocator(base_allocator: *mem.Allocator) !void { | 1017 | pub fn testAllocator(base_allocator: mem.Allocator) !void { |
| 1052 | var validationAllocator = mem.validationWrap(base_allocator); | 1018 | var validationAllocator = mem.validationWrap(base_allocator); |
| 1053 | const allocator = &validationAllocator.allocator; | 1019 | const allocator = validationAllocator.getAllocator(); |
| 1054 | 1020 | ||
| 1055 | var slice = try allocator.alloc(*i32, 100); | 1021 | var slice = try allocator.alloc(*i32, 100); |
| 1056 | try testing.expect(slice.len == 100); | 1022 | try testing.expect(slice.len == 100); |
| ... | @@ -1094,9 +1060,9 @@ pub fn testAllocator(base_allocator: *mem.Allocator) !void { | ... | @@ -1094,9 +1060,9 @@ pub fn testAllocator(base_allocator: *mem.Allocator) !void { |
| 1094 | allocator.free(oversize); | 1060 | allocator.free(oversize); |
| 1095 | } | 1061 | } |
| 1096 | 1062 | ||
| 1097 | pub fn testAllocatorAligned(base_allocator: *mem.Allocator) !void { | 1063 | pub fn testAllocatorAligned(base_allocator: mem.Allocator) !void { |
| 1098 | var validationAllocator = mem.validationWrap(base_allocator); | 1064 | var validationAllocator = mem.validationWrap(base_allocator); |
| 1099 | const allocator = &validationAllocator.allocator; | 1065 | const allocator = validationAllocator.getAllocator(); |
| 1100 | 1066 | ||
| 1101 | // Test a few alignment values, smaller and bigger than the type's one | 1067 | // Test a few alignment values, smaller and bigger than the type's one |
| 1102 | inline for ([_]u29{ 1, 2, 4, 8, 16, 32, 64 }) |alignment| { | 1068 | inline for ([_]u29{ 1, 2, 4, 8, 16, 32, 64 }) |alignment| { |
| ... | @@ -1124,9 +1090,9 @@ pub fn testAllocatorAligned(base_allocator: *mem.Allocator) !void { | ... | @@ -1124,9 +1090,9 @@ pub fn testAllocatorAligned(base_allocator: *mem.Allocator) !void { |
| 1124 | } | 1090 | } |
| 1125 | } | 1091 | } |
| 1126 | 1092 | ||
| 1127 | pub fn testAllocatorLargeAlignment(base_allocator: *mem.Allocator) !void { | 1093 | pub fn testAllocatorLargeAlignment(base_allocator: mem.Allocator) !void { |
| 1128 | var validationAllocator = mem.validationWrap(base_allocator); | 1094 | var validationAllocator = mem.validationWrap(base_allocator); |
| 1129 | const allocator = &validationAllocator.allocator; | 1095 | const allocator = validationAllocator.getAllocator(); |
| 1130 | 1096 | ||
| 1131 | //Maybe a platform's page_size is actually the same as or | 1097 | //Maybe a platform's page_size is actually the same as or |
| 1132 | // very near usize? | 1098 | // very near usize? |
| ... | @@ -1156,12 +1122,12 @@ pub fn testAllocatorLargeAlignment(base_allocator: *mem.Allocator) !void { | ... | @@ -1156,12 +1122,12 @@ pub fn testAllocatorLargeAlignment(base_allocator: *mem.Allocator) !void { |
| 1156 | allocator.free(slice); | 1122 | allocator.free(slice); |
| 1157 | } | 1123 | } |
| 1158 | 1124 | ||
| 1159 | pub fn testAllocatorAlignedShrink(base_allocator: *mem.Allocator) !void { | 1125 | pub fn testAllocatorAlignedShrink(base_allocator: mem.Allocator) !void { |
| 1160 | var validationAllocator = mem.validationWrap(base_allocator); | 1126 | var validationAllocator = mem.validationWrap(base_allocator); |
| 1161 | const allocator = &validationAllocator.allocator; | 1127 | const allocator = validationAllocator.getAllocator(); |
| 1162 | 1128 | ||
| 1163 | var debug_buffer: [1000]u8 = undefined; | 1129 | var debug_buffer: [1000]u8 = undefined; |
| 1164 | const debug_allocator = &FixedBufferAllocator.init(&debug_buffer).allocator; | 1130 | const debug_allocator = FixedBufferAllocator.init(&debug_buffer).getAllocator(); |
| 1165 | 1131 | ||
| 1166 | const alloc_size = mem.page_size * 2 + 50; | 1132 | const alloc_size = mem.page_size * 2 + 50; |
| 1167 | var slice = try allocator.alignedAlloc(u8, 16, alloc_size); | 1133 | var slice = try allocator.alignedAlloc(u8, 16, alloc_size); |
lib/std/heap/arena_allocator.zig+10-14| ... | @@ -6,9 +6,7 @@ const Allocator = std.mem.Allocator; | ... | @@ -6,9 +6,7 @@ const Allocator = std.mem.Allocator; |
| 6 | /// This allocator takes an existing allocator, wraps it, and provides an interface | 6 | /// This allocator takes an existing allocator, wraps it, and provides an interface |
| 7 | /// where you can allocate without freeing, and then free it all together. | 7 | /// where you can allocate without freeing, and then free it all together. |
| 8 | pub const ArenaAllocator = struct { | 8 | pub const ArenaAllocator = struct { |
| 9 | allocator: Allocator, | 9 | child_allocator: Allocator, |
| 10 | |||
| 11 | child_allocator: *Allocator, | ||
| 12 | state: State, | 10 | state: State, |
| 13 | 11 | ||
| 14 | /// Inner state of ArenaAllocator. Can be stored rather than the entire ArenaAllocator | 12 | /// Inner state of ArenaAllocator. Can be stored rather than the entire ArenaAllocator |
| ... | @@ -17,21 +15,21 @@ pub const ArenaAllocator = struct { | ... | @@ -17,21 +15,21 @@ pub const ArenaAllocator = struct { |
| 17 | buffer_list: std.SinglyLinkedList([]u8) = @as(std.SinglyLinkedList([]u8), .{}), | 15 | buffer_list: std.SinglyLinkedList([]u8) = @as(std.SinglyLinkedList([]u8), .{}), |
| 18 | end_index: usize = 0, | 16 | end_index: usize = 0, |
| 19 | 17 | ||
| 20 | pub fn promote(self: State, child_allocator: *Allocator) ArenaAllocator { | 18 | pub fn promote(self: State, child_allocator: Allocator) ArenaAllocator { |
| 21 | return .{ | 19 | return .{ |
| 22 | .allocator = Allocator{ | ||
| 23 | .allocFn = alloc, | ||
| 24 | .resizeFn = resize, | ||
| 25 | }, | ||
| 26 | .child_allocator = child_allocator, | 20 | .child_allocator = child_allocator, |
| 27 | .state = self, | 21 | .state = self, |
| 28 | }; | 22 | }; |
| 29 | } | 23 | } |
| 30 | }; | 24 | }; |
| 31 | 25 | ||
| 26 | pub fn getAllocator(self: *ArenaAllocator) Allocator { | ||
| 27 | return Allocator.init(self, alloc, resize); | ||
| 28 | } | ||
| 29 | |||
| 32 | const BufNode = std.SinglyLinkedList([]u8).Node; | 30 | const BufNode = std.SinglyLinkedList([]u8).Node; |
| 33 | 31 | ||
| 34 | pub fn init(child_allocator: *Allocator) ArenaAllocator { | 32 | pub fn init(child_allocator: Allocator) ArenaAllocator { |
| 35 | return (State{}).promote(child_allocator); | 33 | return (State{}).promote(child_allocator); |
| 36 | } | 34 | } |
| 37 | 35 | ||
| ... | @@ -49,7 +47,7 @@ pub const ArenaAllocator = struct { | ... | @@ -49,7 +47,7 @@ pub const ArenaAllocator = struct { |
| 49 | const actual_min_size = minimum_size + (@sizeOf(BufNode) + 16); | 47 | const actual_min_size = minimum_size + (@sizeOf(BufNode) + 16); |
| 50 | const big_enough_len = prev_len + actual_min_size; | 48 | const big_enough_len = prev_len + actual_min_size; |
| 51 | const len = big_enough_len + big_enough_len / 2; | 49 | const len = big_enough_len + big_enough_len / 2; |
| 52 | const buf = try self.child_allocator.allocFn(self.child_allocator, len, @alignOf(BufNode), 1, @returnAddress()); | 50 | const buf = try self.child_allocator.allocFn(self.child_allocator.ptr, len, @alignOf(BufNode), 1, @returnAddress()); |
| 53 | const buf_node = @ptrCast(*BufNode, @alignCast(@alignOf(BufNode), buf.ptr)); | 51 | const buf_node = @ptrCast(*BufNode, @alignCast(@alignOf(BufNode), buf.ptr)); |
| 54 | buf_node.* = BufNode{ | 52 | buf_node.* = BufNode{ |
| 55 | .data = buf, | 53 | .data = buf, |
| ... | @@ -60,10 +58,9 @@ pub const ArenaAllocator = struct { | ... | @@ -60,10 +58,9 @@ pub const ArenaAllocator = struct { |
| 60 | return buf_node; | 58 | return buf_node; |
| 61 | } | 59 | } |
| 62 | 60 | ||
| 63 | fn alloc(allocator: *Allocator, n: usize, ptr_align: u29, len_align: u29, ra: usize) ![]u8 { | 61 | fn alloc(self: *ArenaAllocator, n: usize, ptr_align: u29, len_align: u29, ra: usize) ![]u8 { |
| 64 | _ = len_align; | 62 | _ = len_align; |
| 65 | _ = ra; | 63 | _ = ra; |
| 66 | const self = @fieldParentPtr(ArenaAllocator, "allocator", allocator); | ||
| 67 | 64 | ||
| 68 | var cur_node = if (self.state.buffer_list.first) |first_node| first_node else try self.createNode(0, n + ptr_align); | 65 | var cur_node = if (self.state.buffer_list.first) |first_node| first_node else try self.createNode(0, n + ptr_align); |
| 69 | while (true) { | 66 | while (true) { |
| ... | @@ -91,11 +88,10 @@ pub const ArenaAllocator = struct { | ... | @@ -91,11 +88,10 @@ pub const ArenaAllocator = struct { |
| 91 | } | 88 | } |
| 92 | } | 89 | } |
| 93 | 90 | ||
| 94 | fn resize(allocator: *Allocator, buf: []u8, buf_align: u29, new_len: usize, len_align: u29, ret_addr: usize) Allocator.Error!usize { | 91 | fn resize(self: *ArenaAllocator, buf: []u8, buf_align: u29, new_len: usize, len_align: u29, ret_addr: usize) Allocator.Error!usize { |
| 95 | _ = buf_align; | 92 | _ = buf_align; |
| 96 | _ = len_align; | 93 | _ = len_align; |
| 97 | _ = ret_addr; | 94 | _ = ret_addr; |
| 98 | const self = @fieldParentPtr(ArenaAllocator, "allocator", allocator); | ||
| 99 | 95 | ||
| 100 | const cur_node = self.state.buffer_list.first orelse return error.OutOfMemory; | 96 | const cur_node = self.state.buffer_list.first orelse return error.OutOfMemory; |
| 101 | const cur_buf = cur_node.data[@sizeOf(BufNode)..]; | 97 | const cur_buf = cur_node.data[@sizeOf(BufNode)..]; |
lib/std/heap/general_purpose_allocator.zig+31-35| ... | @@ -172,11 +172,7 @@ pub const Config = struct { | ... | @@ -172,11 +172,7 @@ pub const Config = struct { |
| 172 | 172 | ||
| 173 | pub fn GeneralPurposeAllocator(comptime config: Config) type { | 173 | pub fn GeneralPurposeAllocator(comptime config: Config) type { |
| 174 | return struct { | 174 | return struct { |
| 175 | allocator: Allocator = Allocator{ | 175 | backing_allocator: Allocator = std.heap.page_allocator, |
| 176 | .allocFn = alloc, | ||
| 177 | .resizeFn = resize, | ||
| 178 | }, | ||
| 179 | backing_allocator: *Allocator = std.heap.page_allocator, | ||
| 180 | buckets: [small_bucket_count]?*BucketHeader = [1]?*BucketHeader{null} ** small_bucket_count, | 176 | buckets: [small_bucket_count]?*BucketHeader = [1]?*BucketHeader{null} ** small_bucket_count, |
| 181 | large_allocations: LargeAllocTable = .{}, | 177 | large_allocations: LargeAllocTable = .{}, |
| 182 | empty_buckets: if (config.retain_metadata) ?*BucketHeader else void = | 178 | empty_buckets: if (config.retain_metadata) ?*BucketHeader else void = |
| ... | @@ -284,6 +280,10 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type { | ... | @@ -284,6 +280,10 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type { |
| 284 | } | 280 | } |
| 285 | }; | 281 | }; |
| 286 | 282 | ||
| 283 | pub fn getAllocator(self: *Self) Allocator { | ||
| 284 | return Allocator.init(self, alloc, resize); | ||
| 285 | } | ||
| 286 | |||
| 287 | fn bucketStackTrace( | 287 | fn bucketStackTrace( |
| 288 | bucket: *BucketHeader, | 288 | bucket: *BucketHeader, |
| 289 | size_class: usize, | 289 | size_class: usize, |
| ... | @@ -388,7 +388,7 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type { | ... | @@ -388,7 +388,7 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type { |
| 388 | var it = self.large_allocations.iterator(); | 388 | var it = self.large_allocations.iterator(); |
| 389 | while (it.next()) |large| { | 389 | while (it.next()) |large| { |
| 390 | if (large.value_ptr.freed) { | 390 | if (large.value_ptr.freed) { |
| 391 | _ = self.backing_allocator.resizeFn(self.backing_allocator, large.value_ptr.bytes, large.value_ptr.ptr_align, 0, 0, @returnAddress()) catch unreachable; | 391 | _ = self.backing_allocator.resizeFn(self.backing_allocator.ptr, large.value_ptr.bytes, large.value_ptr.ptr_align, 0, 0, @returnAddress()) catch unreachable; |
| 392 | } | 392 | } |
| 393 | } | 393 | } |
| 394 | } | 394 | } |
| ... | @@ -571,7 +571,7 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type { | ... | @@ -571,7 +571,7 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type { |
| 571 | const result_len = if (config.never_unmap and new_size == 0) | 571 | const result_len = if (config.never_unmap and new_size == 0) |
| 572 | 0 | 572 | 0 |
| 573 | else | 573 | else |
| 574 | try self.backing_allocator.resizeFn(self.backing_allocator, old_mem, old_align, new_size, len_align, ret_addr); | 574 | try self.backing_allocator.resizeFn(self.backing_allocator.ptr, old_mem, old_align, new_size, len_align, ret_addr); |
| 575 | 575 | ||
| 576 | if (config.enable_memory_limit) { | 576 | if (config.enable_memory_limit) { |
| 577 | entry.value_ptr.requested_size = new_size; | 577 | entry.value_ptr.requested_size = new_size; |
| ... | @@ -606,15 +606,13 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type { | ... | @@ -606,15 +606,13 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type { |
| 606 | } | 606 | } |
| 607 | 607 | ||
| 608 | fn resize( | 608 | fn resize( |
| 609 | allocator: *Allocator, | 609 | self: *Self, |
| 610 | old_mem: []u8, | 610 | old_mem: []u8, |
| 611 | old_align: u29, | 611 | old_align: u29, |
| 612 | new_size: usize, | 612 | new_size: usize, |
| 613 | len_align: u29, | 613 | len_align: u29, |
| 614 | ret_addr: usize, | 614 | ret_addr: usize, |
| 615 | ) Error!usize { | 615 | ) Error!usize { |
| 616 | const self = @fieldParentPtr(Self, "allocator", allocator); | ||
| 617 | |||
| 618 | self.mutex.lock(); | 616 | self.mutex.lock(); |
| 619 | defer self.mutex.unlock(); | 617 | defer self.mutex.unlock(); |
| 620 | 618 | ||
| ... | @@ -755,9 +753,7 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type { | ... | @@ -755,9 +753,7 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type { |
| 755 | return true; | 753 | return true; |
| 756 | } | 754 | } |
| 757 | 755 | ||
| 758 | fn alloc(allocator: *Allocator, len: usize, ptr_align: u29, len_align: u29, ret_addr: usize) Error![]u8 { | 756 | fn alloc(self: Allocator, len: usize, ptr_align: u29, len_align: u29, ret_addr: usize) Error![]u8 { |
| 759 | const self = @fieldParentPtr(Self, "allocator", allocator); | ||
| 760 | |||
| 761 | self.mutex.lock(); | 757 | self.mutex.lock(); |
| 762 | defer self.mutex.unlock(); | 758 | defer self.mutex.unlock(); |
| 763 | 759 | ||
| ... | @@ -768,7 +764,7 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type { | ... | @@ -768,7 +764,7 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type { |
| 768 | const new_aligned_size = math.max(len, ptr_align); | 764 | const new_aligned_size = math.max(len, ptr_align); |
| 769 | if (new_aligned_size > largest_bucket_object_size) { | 765 | if (new_aligned_size > largest_bucket_object_size) { |
| 770 | try self.large_allocations.ensureUnusedCapacity(self.backing_allocator, 1); | 766 | try self.large_allocations.ensureUnusedCapacity(self.backing_allocator, 1); |
| 771 | const slice = try self.backing_allocator.allocFn(self.backing_allocator, len, ptr_align, len_align, ret_addr); | 767 | const slice = try self.backing_allocator.allocFn(self.backing_allocator.ptr, len, ptr_align, len_align, ret_addr); |
| 772 | 768 | ||
| 773 | const gop = self.large_allocations.getOrPutAssumeCapacity(@ptrToInt(slice.ptr)); | 769 | const gop = self.large_allocations.getOrPutAssumeCapacity(@ptrToInt(slice.ptr)); |
| 774 | if (config.retain_metadata and !config.never_unmap) { | 770 | if (config.retain_metadata and !config.never_unmap) { |
| ... | @@ -834,7 +830,7 @@ const test_config = Config{}; | ... | @@ -834,7 +830,7 @@ const test_config = Config{}; |
| 834 | test "small allocations - free in same order" { | 830 | test "small allocations - free in same order" { |
| 835 | var gpa = GeneralPurposeAllocator(test_config){}; | 831 | var gpa = GeneralPurposeAllocator(test_config){}; |
| 836 | defer std.testing.expect(!gpa.deinit()) catch @panic("leak"); | 832 | defer std.testing.expect(!gpa.deinit()) catch @panic("leak"); |
| 837 | const allocator = &gpa.allocator; | 833 | const allocator = gpa.getAllocator(); |
| 838 | 834 | ||
| 839 | var list = std.ArrayList(*u64).init(std.testing.allocator); | 835 | var list = std.ArrayList(*u64).init(std.testing.allocator); |
| 840 | defer list.deinit(); | 836 | defer list.deinit(); |
| ... | @@ -853,7 +849,7 @@ test "small allocations - free in same order" { | ... | @@ -853,7 +849,7 @@ test "small allocations - free in same order" { |
| 853 | test "small allocations - free in reverse order" { | 849 | test "small allocations - free in reverse order" { |
| 854 | var gpa = GeneralPurposeAllocator(test_config){}; | 850 | var gpa = GeneralPurposeAllocator(test_config){}; |
| 855 | defer std.testing.expect(!gpa.deinit()) catch @panic("leak"); | 851 | defer std.testing.expect(!gpa.deinit()) catch @panic("leak"); |
| 856 | const allocator = &gpa.allocator; | 852 | const allocator = gpa.getAllocator(); |
| 857 | 853 | ||
| 858 | var list = std.ArrayList(*u64).init(std.testing.allocator); | 854 | var list = std.ArrayList(*u64).init(std.testing.allocator); |
| 859 | defer list.deinit(); | 855 | defer list.deinit(); |
| ... | @@ -872,7 +868,7 @@ test "small allocations - free in reverse order" { | ... | @@ -872,7 +868,7 @@ test "small allocations - free in reverse order" { |
| 872 | test "large allocations" { | 868 | test "large allocations" { |
| 873 | var gpa = GeneralPurposeAllocator(test_config){}; | 869 | var gpa = GeneralPurposeAllocator(test_config){}; |
| 874 | defer std.testing.expect(!gpa.deinit()) catch @panic("leak"); | 870 | defer std.testing.expect(!gpa.deinit()) catch @panic("leak"); |
| 875 | const allocator = &gpa.allocator; | 871 | const allocator = gpa.getAllocator(); |
| 876 | 872 | ||
| 877 | const ptr1 = try allocator.alloc(u64, 42768); | 873 | const ptr1 = try allocator.alloc(u64, 42768); |
| 878 | const ptr2 = try allocator.alloc(u64, 52768); | 874 | const ptr2 = try allocator.alloc(u64, 52768); |
| ... | @@ -885,7 +881,7 @@ test "large allocations" { | ... | @@ -885,7 +881,7 @@ test "large allocations" { |
| 885 | test "realloc" { | 881 | test "realloc" { |
| 886 | var gpa = GeneralPurposeAllocator(test_config){}; | 882 | var gpa = GeneralPurposeAllocator(test_config){}; |
| 887 | defer std.testing.expect(!gpa.deinit()) catch @panic("leak"); | 883 | defer std.testing.expect(!gpa.deinit()) catch @panic("leak"); |
| 888 | const allocator = &gpa.allocator; | 884 | const allocator = gpa.getAllocator(); |
| 889 | 885 | ||
| 890 | var slice = try allocator.alignedAlloc(u8, @alignOf(u32), 1); | 886 | var slice = try allocator.alignedAlloc(u8, @alignOf(u32), 1); |
| 891 | defer allocator.free(slice); | 887 | defer allocator.free(slice); |
| ... | @@ -907,7 +903,7 @@ test "realloc" { | ... | @@ -907,7 +903,7 @@ test "realloc" { |
| 907 | test "shrink" { | 903 | test "shrink" { |
| 908 | var gpa = GeneralPurposeAllocator(test_config){}; | 904 | var gpa = GeneralPurposeAllocator(test_config){}; |
| 909 | defer std.testing.expect(!gpa.deinit()) catch @panic("leak"); | 905 | defer std.testing.expect(!gpa.deinit()) catch @panic("leak"); |
| 910 | const allocator = &gpa.allocator; | 906 | const allocator = gpa.getAllocator(); |
| 911 | 907 | ||
| 912 | var slice = try allocator.alloc(u8, 20); | 908 | var slice = try allocator.alloc(u8, 20); |
| 913 | defer allocator.free(slice); | 909 | defer allocator.free(slice); |
| ... | @@ -930,7 +926,7 @@ test "shrink" { | ... | @@ -930,7 +926,7 @@ test "shrink" { |
| 930 | test "large object - grow" { | 926 | test "large object - grow" { |
| 931 | var gpa = GeneralPurposeAllocator(test_config){}; | 927 | var gpa = GeneralPurposeAllocator(test_config){}; |
| 932 | defer std.testing.expect(!gpa.deinit()) catch @panic("leak"); | 928 | defer std.testing.expect(!gpa.deinit()) catch @panic("leak"); |
| 933 | const allocator = &gpa.allocator; | 929 | const allocator = gpa.getAllocator(); |
| 934 | 930 | ||
| 935 | var slice1 = try allocator.alloc(u8, page_size * 2 - 20); | 931 | var slice1 = try allocator.alloc(u8, page_size * 2 - 20); |
| 936 | defer allocator.free(slice1); | 932 | defer allocator.free(slice1); |
| ... | @@ -948,7 +944,7 @@ test "large object - grow" { | ... | @@ -948,7 +944,7 @@ test "large object - grow" { |
| 948 | test "realloc small object to large object" { | 944 | test "realloc small object to large object" { |
| 949 | var gpa = GeneralPurposeAllocator(test_config){}; | 945 | var gpa = GeneralPurposeAllocator(test_config){}; |
| 950 | defer std.testing.expect(!gpa.deinit()) catch @panic("leak"); | 946 | defer std.testing.expect(!gpa.deinit()) catch @panic("leak"); |
| 951 | const allocator = &gpa.allocator; | 947 | const allocator = gpa.getAllocator(); |
| 952 | 948 | ||
| 953 | var slice = try allocator.alloc(u8, 70); | 949 | var slice = try allocator.alloc(u8, 70); |
| 954 | defer allocator.free(slice); | 950 | defer allocator.free(slice); |
| ... | @@ -965,7 +961,7 @@ test "realloc small object to large object" { | ... | @@ -965,7 +961,7 @@ test "realloc small object to large object" { |
| 965 | test "shrink large object to large object" { | 961 | test "shrink large object to large object" { |
| 966 | var gpa = GeneralPurposeAllocator(test_config){}; | 962 | var gpa = GeneralPurposeAllocator(test_config){}; |
| 967 | defer std.testing.expect(!gpa.deinit()) catch @panic("leak"); | 963 | defer std.testing.expect(!gpa.deinit()) catch @panic("leak"); |
| 968 | const allocator = &gpa.allocator; | 964 | const allocator = gpa.getAllocator(); |
| 969 | 965 | ||
| 970 | var slice = try allocator.alloc(u8, page_size * 2 + 50); | 966 | var slice = try allocator.alloc(u8, page_size * 2 + 50); |
| 971 | defer allocator.free(slice); | 967 | defer allocator.free(slice); |
| ... | @@ -988,10 +984,10 @@ test "shrink large object to large object" { | ... | @@ -988,10 +984,10 @@ test "shrink large object to large object" { |
| 988 | test "shrink large object to large object with larger alignment" { | 984 | test "shrink large object to large object with larger alignment" { |
| 989 | var gpa = GeneralPurposeAllocator(test_config){}; | 985 | var gpa = GeneralPurposeAllocator(test_config){}; |
| 990 | defer std.testing.expect(!gpa.deinit()) catch @panic("leak"); | 986 | defer std.testing.expect(!gpa.deinit()) catch @panic("leak"); |
| 991 | const allocator = &gpa.allocator; | 987 | const allocator = gpa.getAllocator(); |
| 992 | 988 | ||
| 993 | var debug_buffer: [1000]u8 = undefined; | 989 | var debug_buffer: [1000]u8 = undefined; |
| 994 | const debug_allocator = &std.heap.FixedBufferAllocator.init(&debug_buffer).allocator; | 990 | const debug_allocator = std.heap.FixedBufferAllocator.init(&debug_buffer).getAllocator(); |
| 995 | 991 | ||
| 996 | const alloc_size = page_size * 2 + 50; | 992 | const alloc_size = page_size * 2 + 50; |
| 997 | var slice = try allocator.alignedAlloc(u8, 16, alloc_size); | 993 | var slice = try allocator.alignedAlloc(u8, 16, alloc_size); |
| ... | @@ -1023,7 +1019,7 @@ test "shrink large object to large object with larger alignment" { | ... | @@ -1023,7 +1019,7 @@ test "shrink large object to large object with larger alignment" { |
| 1023 | test "realloc large object to small object" { | 1019 | test "realloc large object to small object" { |
| 1024 | var gpa = GeneralPurposeAllocator(test_config){}; | 1020 | var gpa = GeneralPurposeAllocator(test_config){}; |
| 1025 | defer std.testing.expect(!gpa.deinit()) catch @panic("leak"); | 1021 | defer std.testing.expect(!gpa.deinit()) catch @panic("leak"); |
| 1026 | const allocator = &gpa.allocator; | 1022 | const allocator = gpa.getAllocator(); |
| 1027 | 1023 | ||
| 1028 | var slice = try allocator.alloc(u8, page_size * 2 + 50); | 1024 | var slice = try allocator.alloc(u8, page_size * 2 + 50); |
| 1029 | defer allocator.free(slice); | 1025 | defer allocator.free(slice); |
| ... | @@ -1041,7 +1037,7 @@ test "overrideable mutexes" { | ... | @@ -1041,7 +1037,7 @@ test "overrideable mutexes" { |
| 1041 | .mutex = std.Thread.Mutex{}, | 1037 | .mutex = std.Thread.Mutex{}, |
| 1042 | }; | 1038 | }; |
| 1043 | defer std.testing.expect(!gpa.deinit()) catch @panic("leak"); | 1039 | defer std.testing.expect(!gpa.deinit()) catch @panic("leak"); |
| 1044 | const allocator = &gpa.allocator; | 1040 | const allocator = gpa.getAllocator(); |
| 1045 | 1041 | ||
| 1046 | const ptr = try allocator.create(i32); | 1042 | const ptr = try allocator.create(i32); |
| 1047 | defer allocator.destroy(ptr); | 1043 | defer allocator.destroy(ptr); |
| ... | @@ -1050,7 +1046,7 @@ test "overrideable mutexes" { | ... | @@ -1050,7 +1046,7 @@ test "overrideable mutexes" { |
| 1050 | test "non-page-allocator backing allocator" { | 1046 | test "non-page-allocator backing allocator" { |
| 1051 | var gpa = GeneralPurposeAllocator(.{}){ .backing_allocator = std.testing.allocator }; | 1047 | var gpa = GeneralPurposeAllocator(.{}){ .backing_allocator = std.testing.allocator }; |
| 1052 | defer std.testing.expect(!gpa.deinit()) catch @panic("leak"); | 1048 | defer std.testing.expect(!gpa.deinit()) catch @panic("leak"); |
| 1053 | const allocator = &gpa.allocator; | 1049 | const allocator = gpa.getAllocator(); |
| 1054 | 1050 | ||
| 1055 | const ptr = try allocator.create(i32); | 1051 | const ptr = try allocator.create(i32); |
| 1056 | defer allocator.destroy(ptr); | 1052 | defer allocator.destroy(ptr); |
| ... | @@ -1059,10 +1055,10 @@ test "non-page-allocator backing allocator" { | ... | @@ -1059,10 +1055,10 @@ test "non-page-allocator backing allocator" { |
| 1059 | test "realloc large object to larger alignment" { | 1055 | test "realloc large object to larger alignment" { |
| 1060 | var gpa = GeneralPurposeAllocator(test_config){}; | 1056 | var gpa = GeneralPurposeAllocator(test_config){}; |
| 1061 | defer std.testing.expect(!gpa.deinit()) catch @panic("leak"); | 1057 | defer std.testing.expect(!gpa.deinit()) catch @panic("leak"); |
| 1062 | const allocator = &gpa.allocator; | 1058 | const allocator = gpa.getAllocator(); |
| 1063 | 1059 | ||
| 1064 | var debug_buffer: [1000]u8 = undefined; | 1060 | var debug_buffer: [1000]u8 = undefined; |
| 1065 | const debug_allocator = &std.heap.FixedBufferAllocator.init(&debug_buffer).allocator; | 1061 | const debug_allocator = std.heap.FixedBufferAllocator.init(&debug_buffer).getAllocator(); |
| 1066 | 1062 | ||
| 1067 | var slice = try allocator.alignedAlloc(u8, 16, page_size * 2 + 50); | 1063 | var slice = try allocator.alignedAlloc(u8, 16, page_size * 2 + 50); |
| 1068 | defer allocator.free(slice); | 1064 | defer allocator.free(slice); |
| ... | @@ -1098,9 +1094,9 @@ test "realloc large object to larger alignment" { | ... | @@ -1098,9 +1094,9 @@ test "realloc large object to larger alignment" { |
| 1098 | 1094 | ||
| 1099 | test "large object shrinks to small but allocation fails during shrink" { | 1095 | test "large object shrinks to small but allocation fails during shrink" { |
| 1100 | var failing_allocator = std.testing.FailingAllocator.init(std.heap.page_allocator, 3); | 1096 | var failing_allocator = std.testing.FailingAllocator.init(std.heap.page_allocator, 3); |
| 1101 | var gpa = GeneralPurposeAllocator(.{}){ .backing_allocator = &failing_allocator.allocator }; | 1097 | var gpa = GeneralPurposeAllocator(.{}){ .backing_allocator = failing_allocator.getAllocator() }; |
| 1102 | defer std.testing.expect(!gpa.deinit()) catch @panic("leak"); | 1098 | defer std.testing.expect(!gpa.deinit()) catch @panic("leak"); |
| 1103 | const allocator = &gpa.allocator; | 1099 | const allocator = gpa.getAllocator(); |
| 1104 | 1100 | ||
| 1105 | var slice = try allocator.alloc(u8, page_size * 2 + 50); | 1101 | var slice = try allocator.alloc(u8, page_size * 2 + 50); |
| 1106 | defer allocator.free(slice); | 1102 | defer allocator.free(slice); |
| ... | @@ -1117,7 +1113,7 @@ test "large object shrinks to small but allocation fails during shrink" { | ... | @@ -1117,7 +1113,7 @@ test "large object shrinks to small but allocation fails during shrink" { |
| 1117 | test "objects of size 1024 and 2048" { | 1113 | test "objects of size 1024 and 2048" { |
| 1118 | var gpa = GeneralPurposeAllocator(test_config){}; | 1114 | var gpa = GeneralPurposeAllocator(test_config){}; |
| 1119 | defer std.testing.expect(!gpa.deinit()) catch @panic("leak"); | 1115 | defer std.testing.expect(!gpa.deinit()) catch @panic("leak"); |
| 1120 | const allocator = &gpa.allocator; | 1116 | const allocator = gpa.getAllocator(); |
| 1121 | 1117 | ||
| 1122 | const slice = try allocator.alloc(u8, 1025); | 1118 | const slice = try allocator.alloc(u8, 1025); |
| 1123 | const slice2 = try allocator.alloc(u8, 3000); | 1119 | const slice2 = try allocator.alloc(u8, 3000); |
| ... | @@ -1129,7 +1125,7 @@ test "objects of size 1024 and 2048" { | ... | @@ -1129,7 +1125,7 @@ test "objects of size 1024 and 2048" { |
| 1129 | test "setting a memory cap" { | 1125 | test "setting a memory cap" { |
| 1130 | var gpa = GeneralPurposeAllocator(.{ .enable_memory_limit = true }){}; | 1126 | var gpa = GeneralPurposeAllocator(.{ .enable_memory_limit = true }){}; |
| 1131 | defer std.testing.expect(!gpa.deinit()) catch @panic("leak"); | 1127 | defer std.testing.expect(!gpa.deinit()) catch @panic("leak"); |
| 1132 | const allocator = &gpa.allocator; | 1128 | const allocator = gpa.getAllocator(); |
| 1133 | 1129 | ||
| 1134 | gpa.setRequestedMemoryLimit(1010); | 1130 | gpa.setRequestedMemoryLimit(1010); |
| 1135 | 1131 | ||
| ... | @@ -1158,9 +1154,9 @@ test "double frees" { | ... | @@ -1158,9 +1154,9 @@ test "double frees" { |
| 1158 | defer std.testing.expect(!backing_gpa.deinit()) catch @panic("leak"); | 1154 | defer std.testing.expect(!backing_gpa.deinit()) catch @panic("leak"); |
| 1159 | 1155 | ||
| 1160 | const GPA = GeneralPurposeAllocator(.{ .safety = true, .never_unmap = true, .retain_metadata = true }); | 1156 | const GPA = GeneralPurposeAllocator(.{ .safety = true, .never_unmap = true, .retain_metadata = true }); |
| 1161 | var gpa = GPA{ .backing_allocator = &backing_gpa.allocator }; | 1157 | var gpa = GPA{ .backing_allocator = backing_gpa.getAllocator() }; |
| 1162 | defer std.testing.expect(!gpa.deinit()) catch @panic("leak"); | 1158 | defer std.testing.expect(!gpa.deinit()) catch @panic("leak"); |
| 1163 | const allocator = &gpa.allocator; | 1159 | const allocator = gpa.getAllocator(); |
| 1164 | 1160 | ||
| 1165 | // detect a small allocation double free, even though bucket is emptied | 1161 | // detect a small allocation double free, even though bucket is emptied |
| 1166 | const index: usize = 6; | 1162 | const index: usize = 6; |
lib/std/heap/log_to_writer_allocator.zig+12-15| ... | @@ -5,33 +5,31 @@ const Allocator = std.mem.Allocator; | ... | @@ -5,33 +5,31 @@ const Allocator = std.mem.Allocator; |
| 5 | /// on every call to the allocator. Writer errors are ignored. | 5 | /// on every call to the allocator. Writer errors are ignored. |
| 6 | pub fn LogToWriterAllocator(comptime Writer: type) type { | 6 | pub fn LogToWriterAllocator(comptime Writer: type) type { |
| 7 | return struct { | 7 | return struct { |
| 8 | allocator: Allocator, | 8 | parent_allocator: Allocator, |
| 9 | parent_allocator: *Allocator, | ||
| 10 | writer: Writer, | 9 | writer: Writer, |
| 11 | 10 | ||
| 12 | const Self = @This(); | 11 | const Self = @This(); |
| 13 | 12 | ||
| 14 | pub fn init(parent_allocator: *Allocator, writer: Writer) Self { | 13 | pub fn init(parent_allocator: Allocator, writer: Writer) Self { |
| 15 | return Self{ | 14 | return Self{ |
| 16 | .allocator = Allocator{ | ||
| 17 | .allocFn = alloc, | ||
| 18 | .resizeFn = resize, | ||
| 19 | }, | ||
| 20 | .parent_allocator = parent_allocator, | 15 | .parent_allocator = parent_allocator, |
| 21 | .writer = writer, | 16 | .writer = writer, |
| 22 | }; | 17 | }; |
| 23 | } | 18 | } |
| 24 | 19 | ||
| 20 | pub fn getAllocator(self: *Self) Allocator { | ||
| 21 | return Allocator.init(self, alloc, resize); | ||
| 22 | } | ||
| 23 | |||
| 25 | fn alloc( | 24 | fn alloc( |
| 26 | allocator: *Allocator, | 25 | self: *Self, |
| 27 | len: usize, | 26 | len: usize, |
| 28 | ptr_align: u29, | 27 | ptr_align: u29, |
| 29 | len_align: u29, | 28 | len_align: u29, |
| 30 | ra: usize, | 29 | ra: usize, |
| 31 | ) error{OutOfMemory}![]u8 { | 30 | ) error{OutOfMemory}![]u8 { |
| 32 | const self = @fieldParentPtr(Self, "allocator", allocator); | ||
| 33 | self.writer.print("alloc : {}", .{len}) catch {}; | 31 | self.writer.print("alloc : {}", .{len}) catch {}; |
| 34 | const result = self.parent_allocator.allocFn(self.parent_allocator, len, ptr_align, len_align, ra); | 32 | const result = self.parent_allocator.allocFn(self.parent_allocator.ptr, len, ptr_align, len_align, ra); |
| 35 | if (result) |_| { | 33 | if (result) |_| { |
| 36 | self.writer.print(" success!\n", .{}) catch {}; | 34 | self.writer.print(" success!\n", .{}) catch {}; |
| 37 | } else |_| { | 35 | } else |_| { |
| ... | @@ -41,14 +39,13 @@ pub fn LogToWriterAllocator(comptime Writer: type) type { | ... | @@ -41,14 +39,13 @@ pub fn LogToWriterAllocator(comptime Writer: type) type { |
| 41 | } | 39 | } |
| 42 | 40 | ||
| 43 | fn resize( | 41 | fn resize( |
| 44 | allocator: *Allocator, | 42 | self: *Self, |
| 45 | buf: []u8, | 43 | buf: []u8, |
| 46 | buf_align: u29, | 44 | buf_align: u29, |
| 47 | new_len: usize, | 45 | new_len: usize, |
| 48 | len_align: u29, | 46 | len_align: u29, |
| 49 | ra: usize, | 47 | ra: usize, |
| 50 | ) error{OutOfMemory}!usize { | 48 | ) error{OutOfMemory}!usize { |
| 51 | const self = @fieldParentPtr(Self, "allocator", allocator); | ||
| 52 | if (new_len == 0) { | 49 | if (new_len == 0) { |
| 53 | self.writer.print("free : {}\n", .{buf.len}) catch {}; | 50 | self.writer.print("free : {}\n", .{buf.len}) catch {}; |
| 54 | } else if (new_len <= buf.len) { | 51 | } else if (new_len <= buf.len) { |
| ... | @@ -56,7 +53,7 @@ pub fn LogToWriterAllocator(comptime Writer: type) type { | ... | @@ -56,7 +53,7 @@ pub fn LogToWriterAllocator(comptime Writer: type) type { |
| 56 | } else { | 53 | } else { |
| 57 | self.writer.print("expand: {} to {}", .{ buf.len, new_len }) catch {}; | 54 | self.writer.print("expand: {} to {}", .{ buf.len, new_len }) catch {}; |
| 58 | } | 55 | } |
| 59 | if (self.parent_allocator.resizeFn(self.parent_allocator, buf, buf_align, new_len, len_align, ra)) |resized_len| { | 56 | if (self.parent_allocator.resizeFn(self.parent_allocator.ptr, buf, buf_align, new_len, len_align, ra)) |resized_len| { |
| 60 | if (new_len > buf.len) { | 57 | if (new_len > buf.len) { |
| 61 | self.writer.print(" success!\n", .{}) catch {}; | 58 | self.writer.print(" success!\n", .{}) catch {}; |
| 62 | } | 59 | } |
| ... | @@ -73,7 +70,7 @@ pub fn LogToWriterAllocator(comptime Writer: type) type { | ... | @@ -73,7 +70,7 @@ pub fn LogToWriterAllocator(comptime Writer: type) type { |
| 73 | /// This allocator is used in front of another allocator and logs to the provided writer | 70 | /// This allocator is used in front of another allocator and logs to the provided writer |
| 74 | /// on every call to the allocator. Writer errors are ignored. | 71 | /// on every call to the allocator. Writer errors are ignored. |
| 75 | pub fn logToWriterAllocator( | 72 | pub fn logToWriterAllocator( |
| 76 | parent_allocator: *Allocator, | 73 | parent_allocator: Allocator, |
| 77 | writer: anytype, | 74 | writer: anytype, |
| 78 | ) LogToWriterAllocator(@TypeOf(writer)) { | 75 | ) LogToWriterAllocator(@TypeOf(writer)) { |
| 79 | return LogToWriterAllocator(@TypeOf(writer)).init(parent_allocator, writer); | 76 | return LogToWriterAllocator(@TypeOf(writer)).init(parent_allocator, writer); |
| ... | @@ -85,7 +82,7 @@ test "LogToWriterAllocator" { | ... | @@ -85,7 +82,7 @@ test "LogToWriterAllocator" { |
| 85 | 82 | ||
| 86 | var allocator_buf: [10]u8 = undefined; | 83 | var allocator_buf: [10]u8 = undefined; |
| 87 | var fixedBufferAllocator = std.mem.validationWrap(std.heap.FixedBufferAllocator.init(&allocator_buf)); | 84 | var fixedBufferAllocator = std.mem.validationWrap(std.heap.FixedBufferAllocator.init(&allocator_buf)); |
| 88 | const allocator = &logToWriterAllocator(&fixedBufferAllocator.allocator, fbs.writer()).allocator; | 85 | const allocator = logToWriterAllocator(fixedBufferAllocator.getAllocator(), fbs.writer()).getAllocator(); |
| 89 | 86 | ||
| 90 | var a = try allocator.alloc(u8, 10); | 87 | var a = try allocator.alloc(u8, 10); |
| 91 | a = allocator.shrink(a, 5); | 88 | a = allocator.shrink(a, 5); |
lib/std/heap/logging_allocator.zig+9-13| ... | @@ -22,21 +22,20 @@ pub fn ScopedLoggingAllocator( | ... | @@ -22,21 +22,20 @@ pub fn ScopedLoggingAllocator( |
| 22 | const log = std.log.scoped(scope); | 22 | const log = std.log.scoped(scope); |
| 23 | 23 | ||
| 24 | return struct { | 24 | return struct { |
| 25 | allocator: Allocator, | 25 | parent_allocator: Allocator, |
| 26 | parent_allocator: *Allocator, | ||
| 27 | 26 | ||
| 28 | const Self = @This(); | 27 | const Self = @This(); |
| 29 | 28 | ||
| 30 | pub fn init(parent_allocator: *Allocator) Self { | 29 | pub fn init(parent_allocator: Allocator) Self { |
| 31 | return .{ | 30 | return .{ |
| 32 | .allocator = Allocator{ | ||
| 33 | .allocFn = alloc, | ||
| 34 | .resizeFn = resize, | ||
| 35 | }, | ||
| 36 | .parent_allocator = parent_allocator, | 31 | .parent_allocator = parent_allocator, |
| 37 | }; | 32 | }; |
| 38 | } | 33 | } |
| 39 | 34 | ||
| 35 | pub fn getAllocator(self: *Self) Allocator { | ||
| 36 | return Allocator.init(self, alloc, resize); | ||
| 37 | } | ||
| 38 | |||
| 40 | // This function is required as the `std.log.log` function is not public | 39 | // This function is required as the `std.log.log` function is not public |
| 41 | inline fn logHelper(comptime log_level: std.log.Level, comptime format: []const u8, args: anytype) void { | 40 | inline fn logHelper(comptime log_level: std.log.Level, comptime format: []const u8, args: anytype) void { |
| 42 | switch (log_level) { | 41 | switch (log_level) { |
| ... | @@ -48,13 +47,12 @@ pub fn ScopedLoggingAllocator( | ... | @@ -48,13 +47,12 @@ pub fn ScopedLoggingAllocator( |
| 48 | } | 47 | } |
| 49 | 48 | ||
| 50 | fn alloc( | 49 | fn alloc( |
| 51 | allocator: *Allocator, | 50 | self: *Self, |
| 52 | len: usize, | 51 | len: usize, |
| 53 | ptr_align: u29, | 52 | ptr_align: u29, |
| 54 | len_align: u29, | 53 | len_align: u29, |
| 55 | ra: usize, | 54 | ra: usize, |
| 56 | ) error{OutOfMemory}![]u8 { | 55 | ) error{OutOfMemory}![]u8 { |
| 57 | const self = @fieldParentPtr(Self, "allocator", allocator); | ||
| 58 | const result = self.parent_allocator.allocFn(self.parent_allocator, len, ptr_align, len_align, ra); | 56 | const result = self.parent_allocator.allocFn(self.parent_allocator, len, ptr_align, len_align, ra); |
| 59 | if (result) |_| { | 57 | if (result) |_| { |
| 60 | logHelper( | 58 | logHelper( |
| ... | @@ -73,15 +71,13 @@ pub fn ScopedLoggingAllocator( | ... | @@ -73,15 +71,13 @@ pub fn ScopedLoggingAllocator( |
| 73 | } | 71 | } |
| 74 | 72 | ||
| 75 | fn resize( | 73 | fn resize( |
| 76 | allocator: *Allocator, | 74 | self: *Self, |
| 77 | buf: []u8, | 75 | buf: []u8, |
| 78 | buf_align: u29, | 76 | buf_align: u29, |
| 79 | new_len: usize, | 77 | new_len: usize, |
| 80 | len_align: u29, | 78 | len_align: u29, |
| 81 | ra: usize, | 79 | ra: usize, |
| 82 | ) error{OutOfMemory}!usize { | 80 | ) error{OutOfMemory}!usize { |
| 83 | const self = @fieldParentPtr(Self, "allocator", allocator); | ||
| 84 | |||
| 85 | if (self.parent_allocator.resizeFn(self.parent_allocator, buf, buf_align, new_len, len_align, ra)) |resized_len| { | 81 | if (self.parent_allocator.resizeFn(self.parent_allocator, buf, buf_align, new_len, len_align, ra)) |resized_len| { |
| 86 | if (new_len == 0) { | 82 | if (new_len == 0) { |
| 87 | logHelper(success_log_level, "free - success - len: {}", .{buf.len}); | 83 | logHelper(success_log_level, "free - success - len: {}", .{buf.len}); |
| ... | @@ -116,6 +112,6 @@ pub fn ScopedLoggingAllocator( | ... | @@ -116,6 +112,6 @@ pub fn ScopedLoggingAllocator( |
| 116 | /// This allocator is used in front of another allocator and logs to `std.log` | 112 | /// This allocator is used in front of another allocator and logs to `std.log` |
| 117 | /// on every call to the allocator. | 113 | /// on every call to the allocator. |
| 118 | /// For logging to a `std.io.Writer` see `std.heap.LogToWriterAllocator` | 114 | /// For logging to a `std.io.Writer` see `std.heap.LogToWriterAllocator` |
| 119 | pub fn loggingAllocator(parent_allocator: *Allocator) LoggingAllocator(.debug, .err) { | 115 | pub fn loggingAllocator(parent_allocator: Allocator) LoggingAllocator(.debug, .err) { |
| 120 | return LoggingAllocator(.debug, .err).init(parent_allocator); | 116 | return LoggingAllocator(.debug, .err).init(parent_allocator); |
| 121 | } | 117 | } |
lib/std/io/buffered_atomic_file.zig+2-2| ... | @@ -7,7 +7,7 @@ pub const BufferedAtomicFile = struct { | ... | @@ -7,7 +7,7 @@ pub const BufferedAtomicFile = struct { |
| 7 | atomic_file: fs.AtomicFile, | 7 | atomic_file: fs.AtomicFile, |
| 8 | file_writer: File.Writer, | 8 | file_writer: File.Writer, |
| 9 | buffered_writer: BufferedWriter, | 9 | buffered_writer: BufferedWriter, |
| 10 | allocator: *mem.Allocator, | 10 | allocator: mem.Allocator, |
| 11 | 11 | ||
| 12 | pub const buffer_size = 4096; | 12 | pub const buffer_size = 4096; |
| 13 | pub const BufferedWriter = std.io.BufferedWriter(buffer_size, File.Writer); | 13 | pub const BufferedWriter = std.io.BufferedWriter(buffer_size, File.Writer); |
| ... | @@ -16,7 +16,7 @@ pub const BufferedAtomicFile = struct { | ... | @@ -16,7 +16,7 @@ pub const BufferedAtomicFile = struct { |
| 16 | /// TODO when https://github.com/ziglang/zig/issues/2761 is solved | 16 | /// TODO when https://github.com/ziglang/zig/issues/2761 is solved |
| 17 | /// this API will not need an allocator | 17 | /// this API will not need an allocator |
| 18 | pub fn create( | 18 | pub fn create( |
| 19 | allocator: *mem.Allocator, | 19 | allocator: mem.Allocator, |
| 20 | dir: fs.Dir, | 20 | dir: fs.Dir, |
| 21 | dest_path: []const u8, | 21 | dest_path: []const u8, |
| 22 | atomic_file_options: fs.Dir.AtomicFileOptions, | 22 | atomic_file_options: fs.Dir.AtomicFileOptions, |
lib/std/io/peek_stream.zig+1-1| ... | @@ -38,7 +38,7 @@ pub fn PeekStream( | ... | @@ -38,7 +38,7 @@ pub fn PeekStream( |
| 38 | } | 38 | } |
| 39 | }, | 39 | }, |
| 40 | .Dynamic => struct { | 40 | .Dynamic => struct { |
| 41 | pub fn init(base: ReaderType, allocator: *mem.Allocator) Self { | 41 | pub fn init(base: ReaderType, allocator: mem.Allocator) Self { |
| 42 | return .{ | 42 | return .{ |
| 43 | .unbuffered_reader = base, | 43 | .unbuffered_reader = base, |
| 44 | .fifo = FifoType.init(allocator), | 44 | .fifo = FifoType.init(allocator), |
lib/std/io/reader.zig+3-3| ... | @@ -88,7 +88,7 @@ pub fn Reader( | ... | @@ -88,7 +88,7 @@ pub fn Reader( |
| 88 | /// memory would be greater than `max_size`, returns `error.StreamTooLong`. | 88 | /// memory would be greater than `max_size`, returns `error.StreamTooLong`. |
| 89 | /// Caller owns returned memory. | 89 | /// Caller owns returned memory. |
| 90 | /// If this function returns an error, the contents from the stream read so far are lost. | 90 | /// If this function returns an error, the contents from the stream read so far are lost. |
| 91 | pub fn readAllAlloc(self: Self, allocator: *mem.Allocator, max_size: usize) ![]u8 { | 91 | pub fn readAllAlloc(self: Self, allocator: mem.Allocator, max_size: usize) ![]u8 { |
| 92 | var array_list = std.ArrayList(u8).init(allocator); | 92 | var array_list = std.ArrayList(u8).init(allocator); |
| 93 | defer array_list.deinit(); | 93 | defer array_list.deinit(); |
| 94 | try self.readAllArrayList(&array_list, max_size); | 94 | try self.readAllArrayList(&array_list, max_size); |
| ... | @@ -127,7 +127,7 @@ pub fn Reader( | ... | @@ -127,7 +127,7 @@ pub fn Reader( |
| 127 | /// If this function returns an error, the contents from the stream read so far are lost. | 127 | /// If this function returns an error, the contents from the stream read so far are lost. |
| 128 | pub fn readUntilDelimiterAlloc( | 128 | pub fn readUntilDelimiterAlloc( |
| 129 | self: Self, | 129 | self: Self, |
| 130 | allocator: *mem.Allocator, | 130 | allocator: mem.Allocator, |
| 131 | delimiter: u8, | 131 | delimiter: u8, |
| 132 | max_size: usize, | 132 | max_size: usize, |
| 133 | ) ![]u8 { | 133 | ) ![]u8 { |
| ... | @@ -163,7 +163,7 @@ pub fn Reader( | ... | @@ -163,7 +163,7 @@ pub fn Reader( |
| 163 | /// If this function returns an error, the contents from the stream read so far are lost. | 163 | /// If this function returns an error, the contents from the stream read so far are lost. |
| 164 | pub fn readUntilDelimiterOrEofAlloc( | 164 | pub fn readUntilDelimiterOrEofAlloc( |
| 165 | self: Self, | 165 | self: Self, |
| 166 | allocator: *mem.Allocator, | 166 | allocator: mem.Allocator, |
| 167 | delimiter: u8, | 167 | delimiter: u8, |
| 168 | max_size: usize, | 168 | max_size: usize, |
| 169 | ) !?[]u8 { | 169 | ) !?[]u8 { |
lib/std/json.zig+16-14| ... | @@ -1476,7 +1476,7 @@ fn parsedEqual(a: anytype, b: @TypeOf(a)) bool { | ... | @@ -1476,7 +1476,7 @@ fn parsedEqual(a: anytype, b: @TypeOf(a)) bool { |
| 1476 | } | 1476 | } |
| 1477 | 1477 | ||
| 1478 | pub const ParseOptions = struct { | 1478 | pub const ParseOptions = struct { |
| 1479 | allocator: ?*Allocator = null, | 1479 | allocator: ?Allocator = null, |
| 1480 | 1480 | ||
| 1481 | /// Behaviour when a duplicate field is encountered. | 1481 | /// Behaviour when a duplicate field is encountered. |
| 1482 | duplicate_field_behavior: enum { | 1482 | duplicate_field_behavior: enum { |
| ... | @@ -2033,7 +2033,7 @@ test "parse into tagged union" { | ... | @@ -2033,7 +2033,7 @@ test "parse into tagged union" { |
| 2033 | 2033 | ||
| 2034 | { // failing allocations should be bubbled up instantly without trying next member | 2034 | { // failing allocations should be bubbled up instantly without trying next member |
| 2035 | var fail_alloc = testing.FailingAllocator.init(testing.allocator, 0); | 2035 | var fail_alloc = testing.FailingAllocator.init(testing.allocator, 0); |
| 2036 | const options = ParseOptions{ .allocator = &fail_alloc.allocator }; | 2036 | const options = ParseOptions{ .allocator = fail_alloc.getAllocator() }; |
| 2037 | const T = union(enum) { | 2037 | const T = union(enum) { |
| 2038 | // both fields here match the input | 2038 | // both fields here match the input |
| 2039 | string: []const u8, | 2039 | string: []const u8, |
| ... | @@ -2081,7 +2081,7 @@ test "parse union bubbles up AllocatorRequired" { | ... | @@ -2081,7 +2081,7 @@ test "parse union bubbles up AllocatorRequired" { |
| 2081 | 2081 | ||
| 2082 | test "parseFree descends into tagged union" { | 2082 | test "parseFree descends into tagged union" { |
| 2083 | var fail_alloc = testing.FailingAllocator.init(testing.allocator, 1); | 2083 | var fail_alloc = testing.FailingAllocator.init(testing.allocator, 1); |
| 2084 | const options = ParseOptions{ .allocator = &fail_alloc.allocator }; | 2084 | const options = ParseOptions{ .allocator = fail_alloc.getAllocator() }; |
| 2085 | const T = union(enum) { | 2085 | const T = union(enum) { |
| 2086 | int: i32, | 2086 | int: i32, |
| 2087 | float: f64, | 2087 | float: f64, |
| ... | @@ -2328,7 +2328,7 @@ test "parse into double recursive union definition" { | ... | @@ -2328,7 +2328,7 @@ test "parse into double recursive union definition" { |
| 2328 | 2328 | ||
| 2329 | /// A non-stream JSON parser which constructs a tree of Value's. | 2329 | /// A non-stream JSON parser which constructs a tree of Value's. |
| 2330 | pub const Parser = struct { | 2330 | pub const Parser = struct { |
| 2331 | allocator: *Allocator, | 2331 | allocator: Allocator, |
| 2332 | state: State, | 2332 | state: State, |
| 2333 | copy_strings: bool, | 2333 | copy_strings: bool, |
| 2334 | // Stores parent nodes and un-combined Values. | 2334 | // Stores parent nodes and un-combined Values. |
| ... | @@ -2341,7 +2341,7 @@ pub const Parser = struct { | ... | @@ -2341,7 +2341,7 @@ pub const Parser = struct { |
| 2341 | Simple, | 2341 | Simple, |
| 2342 | }; | 2342 | }; |
| 2343 | 2343 | ||
| 2344 | pub fn init(allocator: *Allocator, copy_strings: bool) Parser { | 2344 | pub fn init(allocator: Allocator, copy_strings: bool) Parser { |
| 2345 | return Parser{ | 2345 | return Parser{ |
| 2346 | .allocator = allocator, | 2346 | .allocator = allocator, |
| 2347 | .state = .Simple, | 2347 | .state = .Simple, |
| ... | @@ -2364,9 +2364,10 @@ pub const Parser = struct { | ... | @@ -2364,9 +2364,10 @@ pub const Parser = struct { |
| 2364 | 2364 | ||
| 2365 | var arena = ArenaAllocator.init(p.allocator); | 2365 | var arena = ArenaAllocator.init(p.allocator); |
| 2366 | errdefer arena.deinit(); | 2366 | errdefer arena.deinit(); |
| 2367 | const allocator = arena.getAllocator(); | ||
| 2367 | 2368 | ||
| 2368 | while (try s.next()) |token| { | 2369 | while (try s.next()) |token| { |
| 2369 | try p.transition(&arena.allocator, input, s.i - 1, token); | 2370 | try p.transition(allocator, input, s.i - 1, token); |
| 2370 | } | 2371 | } |
| 2371 | 2372 | ||
| 2372 | debug.assert(p.stack.items.len == 1); | 2373 | debug.assert(p.stack.items.len == 1); |
| ... | @@ -2379,7 +2380,7 @@ pub const Parser = struct { | ... | @@ -2379,7 +2380,7 @@ pub const Parser = struct { |
| 2379 | 2380 | ||
| 2380 | // Even though p.allocator exists, we take an explicit allocator so that allocation state | 2381 | // Even though p.allocator exists, we take an explicit allocator so that allocation state |
| 2381 | // can be cleaned up on error correctly during a `parse` on call. | 2382 | // can be cleaned up on error correctly during a `parse` on call. |
| 2382 | fn transition(p: *Parser, allocator: *Allocator, input: []const u8, i: usize, token: Token) !void { | 2383 | fn transition(p: *Parser, allocator: Allocator, input: []const u8, i: usize, token: Token) !void { |
| 2383 | switch (p.state) { | 2384 | switch (p.state) { |
| 2384 | .ObjectKey => switch (token) { | 2385 | .ObjectKey => switch (token) { |
| 2385 | .ObjectEnd => { | 2386 | .ObjectEnd => { |
| ... | @@ -2536,7 +2537,7 @@ pub const Parser = struct { | ... | @@ -2536,7 +2537,7 @@ pub const Parser = struct { |
| 2536 | } | 2537 | } |
| 2537 | } | 2538 | } |
| 2538 | 2539 | ||
| 2539 | fn parseString(p: *Parser, allocator: *Allocator, s: std.meta.TagPayload(Token, Token.String), input: []const u8, i: usize) !Value { | 2540 | fn parseString(p: *Parser, allocator: Allocator, s: std.meta.TagPayload(Token, Token.String), input: []const u8, i: usize) !Value { |
| 2540 | const slice = s.slice(input, i); | 2541 | const slice = s.slice(input, i); |
| 2541 | switch (s.escapes) { | 2542 | switch (s.escapes) { |
| 2542 | .None => return Value{ .String = if (p.copy_strings) try allocator.dupe(u8, slice) else slice }, | 2543 | .None => return Value{ .String = if (p.copy_strings) try allocator.dupe(u8, slice) else slice }, |
| ... | @@ -2737,7 +2738,7 @@ test "write json then parse it" { | ... | @@ -2737,7 +2738,7 @@ test "write json then parse it" { |
| 2737 | try testing.expect(mem.eql(u8, tree.root.Object.get("str").?.String, "hello")); | 2738 | try testing.expect(mem.eql(u8, tree.root.Object.get("str").?.String, "hello")); |
| 2738 | } | 2739 | } |
| 2739 | 2740 | ||
| 2740 | fn testParse(arena_allocator: *std.mem.Allocator, json_str: []const u8) !Value { | 2741 | fn testParse(arena_allocator: std.mem.Allocator, json_str: []const u8) !Value { |
| 2741 | var p = Parser.init(arena_allocator, false); | 2742 | var p = Parser.init(arena_allocator, false); |
| 2742 | return (try p.parse(json_str)).root; | 2743 | return (try p.parse(json_str)).root; |
| 2743 | } | 2744 | } |
| ... | @@ -2745,13 +2746,13 @@ fn testParse(arena_allocator: *std.mem.Allocator, json_str: []const u8) !Value { | ... | @@ -2745,13 +2746,13 @@ fn testParse(arena_allocator: *std.mem.Allocator, json_str: []const u8) !Value { |
| 2745 | test "parsing empty string gives appropriate error" { | 2746 | test "parsing empty string gives appropriate error" { |
| 2746 | var arena_allocator = std.heap.ArenaAllocator.init(std.testing.allocator); | 2747 | var arena_allocator = std.heap.ArenaAllocator.init(std.testing.allocator); |
| 2747 | defer arena_allocator.deinit(); | 2748 | defer arena_allocator.deinit(); |
| 2748 | try testing.expectError(error.UnexpectedEndOfJson, testParse(&arena_allocator.allocator, "")); | 2749 | try testing.expectError(error.UnexpectedEndOfJson, testParse(arena_allocator.getAllocator(), "")); |
| 2749 | } | 2750 | } |
| 2750 | 2751 | ||
| 2751 | test "integer after float has proper type" { | 2752 | test "integer after float has proper type" { |
| 2752 | var arena_allocator = std.heap.ArenaAllocator.init(std.testing.allocator); | 2753 | var arena_allocator = std.heap.ArenaAllocator.init(std.testing.allocator); |
| 2753 | defer arena_allocator.deinit(); | 2754 | defer arena_allocator.deinit(); |
| 2754 | const json = try testParse(&arena_allocator.allocator, | 2755 | const json = try testParse(arena_allocator.getAllocator(), |
| 2755 | \\{ | 2756 | \\{ |
| 2756 | \\ "float": 3.14, | 2757 | \\ "float": 3.14, |
| 2757 | \\ "ints": [1, 2, 3] | 2758 | \\ "ints": [1, 2, 3] |
| ... | @@ -2786,7 +2787,7 @@ test "escaped characters" { | ... | @@ -2786,7 +2787,7 @@ test "escaped characters" { |
| 2786 | \\} | 2787 | \\} |
| 2787 | ; | 2788 | ; |
| 2788 | 2789 | ||
| 2789 | const obj = (try testParse(&arena_allocator.allocator, input)).Object; | 2790 | const obj = (try testParse(arena_allocator.getAllocator(), input)).Object; |
| 2790 | 2791 | ||
| 2791 | try testing.expectEqualSlices(u8, obj.get("backslash").?.String, "\\"); | 2792 | try testing.expectEqualSlices(u8, obj.get("backslash").?.String, "\\"); |
| 2792 | try testing.expectEqualSlices(u8, obj.get("forwardslash").?.String, "/"); | 2793 | try testing.expectEqualSlices(u8, obj.get("forwardslash").?.String, "/"); |
| ... | @@ -2812,11 +2813,12 @@ test "string copy option" { | ... | @@ -2812,11 +2813,12 @@ test "string copy option" { |
| 2812 | 2813 | ||
| 2813 | var arena_allocator = std.heap.ArenaAllocator.init(std.testing.allocator); | 2814 | var arena_allocator = std.heap.ArenaAllocator.init(std.testing.allocator); |
| 2814 | defer arena_allocator.deinit(); | 2815 | defer arena_allocator.deinit(); |
| 2816 | const allocator = arena_allocator.getAllocator(); | ||
| 2815 | 2817 | ||
| 2816 | const tree_nocopy = try Parser.init(&arena_allocator.allocator, false).parse(input); | 2818 | const tree_nocopy = try Parser.init(allocator, false).parse(input); |
| 2817 | const obj_nocopy = tree_nocopy.root.Object; | 2819 | const obj_nocopy = tree_nocopy.root.Object; |
| 2818 | 2820 | ||
| 2819 | const tree_copy = try Parser.init(&arena_allocator.allocator, true).parse(input); | 2821 | const tree_copy = try Parser.init(allocator, true).parse(input); |
| 2820 | const obj_copy = tree_copy.root.Object; | 2822 | const obj_copy = tree_copy.root.Object; |
| 2821 | 2823 | ||
| 2822 | for ([_][]const u8{ "noescape", "simple", "unicode", "surrogatepair" }) |field_name| { | 2824 | for ([_][]const u8{ "noescape", "simple", "unicode", "surrogatepair" }) |field_name| { |
lib/std/json/write_stream.zig+2-2| ... | @@ -243,7 +243,7 @@ test "json write stream" { | ... | @@ -243,7 +243,7 @@ test "json write stream" { |
| 243 | try w.beginObject(); | 243 | try w.beginObject(); |
| 244 | 244 | ||
| 245 | try w.objectField("object"); | 245 | try w.objectField("object"); |
| 246 | try w.emitJson(try getJsonObject(&arena_allocator.allocator)); | 246 | try w.emitJson(try getJsonObject(arena_allocator.getAllocator())); |
| 247 | 247 | ||
| 248 | try w.objectField("string"); | 248 | try w.objectField("string"); |
| 249 | try w.emitString("This is a string"); | 249 | try w.emitString("This is a string"); |
| ... | @@ -286,7 +286,7 @@ test "json write stream" { | ... | @@ -286,7 +286,7 @@ test "json write stream" { |
| 286 | try std.testing.expect(std.mem.eql(u8, expected, result)); | 286 | try std.testing.expect(std.mem.eql(u8, expected, result)); |
| 287 | } | 287 | } |
| 288 | 288 | ||
| 289 | fn getJsonObject(allocator: *std.mem.Allocator) !std.json.Value { | 289 | fn getJsonObject(allocator: std.mem.Allocator) !std.json.Value { |
| 290 | var value = std.json.Value{ .Object = std.json.ObjectMap.init(allocator) }; | 290 | var value = std.json.Value{ .Object = std.json.ObjectMap.init(allocator) }; |
| 291 | try value.Object.put("one", std.json.Value{ .Integer = @intCast(i64, 1) }); | 291 | try value.Object.put("one", std.json.Value{ .Integer = @intCast(i64, 1) }); |
| 292 | try value.Object.put("two", std.json.Value{ .Float = 2.0 }); | 292 | try value.Object.put("two", std.json.Value{ .Float = 2.0 }); |
lib/std/math/big/int.zig+17-17| ... | @@ -142,7 +142,7 @@ pub const Mutable = struct { | ... | @@ -142,7 +142,7 @@ pub const Mutable = struct { |
| 142 | 142 | ||
| 143 | /// Asserts that the allocator owns the limbs memory. If this is not the case, | 143 | /// Asserts that the allocator owns the limbs memory. If this is not the case, |
| 144 | /// use `toConst().toManaged()`. | 144 | /// use `toConst().toManaged()`. |
| 145 | pub fn toManaged(self: Mutable, allocator: *Allocator) Managed { | 145 | pub fn toManaged(self: Mutable, allocator: Allocator) Managed { |
| 146 | return .{ | 146 | return .{ |
| 147 | .allocator = allocator, | 147 | .allocator = allocator, |
| 148 | .limbs = self.limbs, | 148 | .limbs = self.limbs, |
| ... | @@ -283,7 +283,7 @@ pub const Mutable = struct { | ... | @@ -283,7 +283,7 @@ pub const Mutable = struct { |
| 283 | base: u8, | 283 | base: u8, |
| 284 | value: []const u8, | 284 | value: []const u8, |
| 285 | limbs_buffer: []Limb, | 285 | limbs_buffer: []Limb, |
| 286 | allocator: ?*Allocator, | 286 | allocator: ?Allocator, |
| 287 | ) error{InvalidCharacter}!void { | 287 | ) error{InvalidCharacter}!void { |
| 288 | assert(base >= 2 and base <= 16); | 288 | assert(base >= 2 and base <= 16); |
| 289 | 289 | ||
| ... | @@ -608,7 +608,7 @@ pub const Mutable = struct { | ... | @@ -608,7 +608,7 @@ pub const Mutable = struct { |
| 608 | /// rma is given by `a.limbs.len + b.limbs.len`. | 608 | /// rma is given by `a.limbs.len + b.limbs.len`. |
| 609 | /// | 609 | /// |
| 610 | /// `limbs_buffer` is used for temporary storage. The amount required is given by `calcMulLimbsBufferLen`. | 610 | /// `limbs_buffer` is used for temporary storage. The amount required is given by `calcMulLimbsBufferLen`. |
| 611 | pub fn mul(rma: *Mutable, a: Const, b: Const, limbs_buffer: []Limb, allocator: ?*Allocator) void { | 611 | pub fn mul(rma: *Mutable, a: Const, b: Const, limbs_buffer: []Limb, allocator: ?Allocator) void { |
| 612 | var buf_index: usize = 0; | 612 | var buf_index: usize = 0; |
| 613 | 613 | ||
| 614 | const a_copy = if (rma.limbs.ptr == a.limbs.ptr) blk: { | 614 | const a_copy = if (rma.limbs.ptr == a.limbs.ptr) blk: { |
| ... | @@ -638,7 +638,7 @@ pub const Mutable = struct { | ... | @@ -638,7 +638,7 @@ pub const Mutable = struct { |
| 638 | /// | 638 | /// |
| 639 | /// If `allocator` is provided, it will be used for temporary storage to improve | 639 | /// If `allocator` is provided, it will be used for temporary storage to improve |
| 640 | /// multiplication performance. `error.OutOfMemory` is handled with a fallback algorithm. | 640 | /// multiplication performance. `error.OutOfMemory` is handled with a fallback algorithm. |
| 641 | pub fn mulNoAlias(rma: *Mutable, a: Const, b: Const, allocator: ?*Allocator) void { | 641 | pub fn mulNoAlias(rma: *Mutable, a: Const, b: Const, allocator: ?Allocator) void { |
| 642 | assert(rma.limbs.ptr != a.limbs.ptr); // illegal aliasing | 642 | assert(rma.limbs.ptr != a.limbs.ptr); // illegal aliasing |
| 643 | assert(rma.limbs.ptr != b.limbs.ptr); // illegal aliasing | 643 | assert(rma.limbs.ptr != b.limbs.ptr); // illegal aliasing |
| 644 | 644 | ||
| ... | @@ -674,7 +674,7 @@ pub const Mutable = struct { | ... | @@ -674,7 +674,7 @@ pub const Mutable = struct { |
| 674 | signedness: Signedness, | 674 | signedness: Signedness, |
| 675 | bit_count: usize, | 675 | bit_count: usize, |
| 676 | limbs_buffer: []Limb, | 676 | limbs_buffer: []Limb, |
| 677 | allocator: ?*Allocator, | 677 | allocator: ?Allocator, |
| 678 | ) void { | 678 | ) void { |
| 679 | var buf_index: usize = 0; | 679 | var buf_index: usize = 0; |
| 680 | const req_limbs = calcTwosCompLimbCount(bit_count); | 680 | const req_limbs = calcTwosCompLimbCount(bit_count); |
| ... | @@ -714,7 +714,7 @@ pub const Mutable = struct { | ... | @@ -714,7 +714,7 @@ pub const Mutable = struct { |
| 714 | b: Const, | 714 | b: Const, |
| 715 | signedness: Signedness, | 715 | signedness: Signedness, |
| 716 | bit_count: usize, | 716 | bit_count: usize, |
| 717 | allocator: ?*Allocator, | 717 | allocator: ?Allocator, |
| 718 | ) void { | 718 | ) void { |
| 719 | assert(rma.limbs.ptr != a.limbs.ptr); // illegal aliasing | 719 | assert(rma.limbs.ptr != a.limbs.ptr); // illegal aliasing |
| 720 | assert(rma.limbs.ptr != b.limbs.ptr); // illegal aliasing | 720 | assert(rma.limbs.ptr != b.limbs.ptr); // illegal aliasing |
| ... | @@ -763,7 +763,7 @@ pub const Mutable = struct { | ... | @@ -763,7 +763,7 @@ pub const Mutable = struct { |
| 763 | /// | 763 | /// |
| 764 | /// If `allocator` is provided, it will be used for temporary storage to improve | 764 | /// If `allocator` is provided, it will be used for temporary storage to improve |
| 765 | /// multiplication performance. `error.OutOfMemory` is handled with a fallback algorithm. | 765 | /// multiplication performance. `error.OutOfMemory` is handled with a fallback algorithm. |
| 766 | pub fn sqrNoAlias(rma: *Mutable, a: Const, opt_allocator: ?*Allocator) void { | 766 | pub fn sqrNoAlias(rma: *Mutable, a: Const, opt_allocator: ?Allocator) void { |
| 767 | _ = opt_allocator; | 767 | _ = opt_allocator; |
| 768 | assert(rma.limbs.ptr != a.limbs.ptr); // illegal aliasing | 768 | assert(rma.limbs.ptr != a.limbs.ptr); // illegal aliasing |
| 769 | 769 | ||
| ... | @@ -1660,7 +1660,7 @@ pub const Const = struct { | ... | @@ -1660,7 +1660,7 @@ pub const Const = struct { |
| 1660 | positive: bool, | 1660 | positive: bool, |
| 1661 | 1661 | ||
| 1662 | /// The result is an independent resource which is managed by the caller. | 1662 | /// The result is an independent resource which is managed by the caller. |
| 1663 | pub fn toManaged(self: Const, allocator: *Allocator) Allocator.Error!Managed { | 1663 | pub fn toManaged(self: Const, allocator: Allocator) Allocator.Error!Managed { |
| 1664 | const limbs = try allocator.alloc(Limb, math.max(Managed.default_capacity, self.limbs.len)); | 1664 | const limbs = try allocator.alloc(Limb, math.max(Managed.default_capacity, self.limbs.len)); |
| 1665 | mem.copy(Limb, limbs, self.limbs); | 1665 | mem.copy(Limb, limbs, self.limbs); |
| 1666 | return Managed{ | 1666 | return Managed{ |
| ... | @@ -1873,7 +1873,7 @@ pub const Const = struct { | ... | @@ -1873,7 +1873,7 @@ pub const Const = struct { |
| 1873 | /// Caller owns returned memory. | 1873 | /// Caller owns returned memory. |
| 1874 | /// Asserts that `base` is in the range [2, 16]. | 1874 | /// Asserts that `base` is in the range [2, 16]. |
| 1875 | /// See also `toString`, a lower level function than this. | 1875 | /// See also `toString`, a lower level function than this. |
| 1876 | pub fn toStringAlloc(self: Const, allocator: *Allocator, base: u8, case: std.fmt.Case) Allocator.Error![]u8 { | 1876 | pub fn toStringAlloc(self: Const, allocator: Allocator, base: u8, case: std.fmt.Case) Allocator.Error![]u8 { |
| 1877 | assert(base >= 2); | 1877 | assert(base >= 2); |
| 1878 | assert(base <= 16); | 1878 | assert(base <= 16); |
| 1879 | 1879 | ||
| ... | @@ -2092,7 +2092,7 @@ pub const Managed = struct { | ... | @@ -2092,7 +2092,7 @@ pub const Managed = struct { |
| 2092 | pub const default_capacity = 4; | 2092 | pub const default_capacity = 4; |
| 2093 | 2093 | ||
| 2094 | /// Allocator used by the Managed when requesting memory. | 2094 | /// Allocator used by the Managed when requesting memory. |
| 2095 | allocator: *Allocator, | 2095 | allocator: Allocator, |
| 2096 | 2096 | ||
| 2097 | /// Raw digits. These are: | 2097 | /// Raw digits. These are: |
| 2098 | /// | 2098 | /// |
| ... | @@ -2109,7 +2109,7 @@ pub const Managed = struct { | ... | @@ -2109,7 +2109,7 @@ pub const Managed = struct { |
| 2109 | 2109 | ||
| 2110 | /// Creates a new `Managed`. `default_capacity` limbs will be allocated immediately. | 2110 | /// Creates a new `Managed`. `default_capacity` limbs will be allocated immediately. |
| 2111 | /// The integer value after initializing is `0`. | 2111 | /// The integer value after initializing is `0`. |
| 2112 | pub fn init(allocator: *Allocator) !Managed { | 2112 | pub fn init(allocator: Allocator) !Managed { |
| 2113 | return initCapacity(allocator, default_capacity); | 2113 | return initCapacity(allocator, default_capacity); |
| 2114 | } | 2114 | } |
| 2115 | 2115 | ||
| ... | @@ -2131,7 +2131,7 @@ pub const Managed = struct { | ... | @@ -2131,7 +2131,7 @@ pub const Managed = struct { |
| 2131 | /// Creates a new `Managed` with value `value`. | 2131 | /// Creates a new `Managed` with value `value`. |
| 2132 | /// | 2132 | /// |
| 2133 | /// This is identical to an `init`, followed by a `set`. | 2133 | /// This is identical to an `init`, followed by a `set`. |
| 2134 | pub fn initSet(allocator: *Allocator, value: anytype) !Managed { | 2134 | pub fn initSet(allocator: Allocator, value: anytype) !Managed { |
| 2135 | var s = try Managed.init(allocator); | 2135 | var s = try Managed.init(allocator); |
| 2136 | try s.set(value); | 2136 | try s.set(value); |
| 2137 | return s; | 2137 | return s; |
| ... | @@ -2140,7 +2140,7 @@ pub const Managed = struct { | ... | @@ -2140,7 +2140,7 @@ pub const Managed = struct { |
| 2140 | /// Creates a new Managed with a specific capacity. If capacity < default_capacity then the | 2140 | /// Creates a new Managed with a specific capacity. If capacity < default_capacity then the |
| 2141 | /// default capacity will be used instead. | 2141 | /// default capacity will be used instead. |
| 2142 | /// The integer value after initializing is `0`. | 2142 | /// The integer value after initializing is `0`. |
| 2143 | pub fn initCapacity(allocator: *Allocator, capacity: usize) !Managed { | 2143 | pub fn initCapacity(allocator: Allocator, capacity: usize) !Managed { |
| 2144 | return Managed{ | 2144 | return Managed{ |
| 2145 | .allocator = allocator, | 2145 | .allocator = allocator, |
| 2146 | .metadata = 1, | 2146 | .metadata = 1, |
| ... | @@ -2206,7 +2206,7 @@ pub const Managed = struct { | ... | @@ -2206,7 +2206,7 @@ pub const Managed = struct { |
| 2206 | return other.cloneWithDifferentAllocator(other.allocator); | 2206 | return other.cloneWithDifferentAllocator(other.allocator); |
| 2207 | } | 2207 | } |
| 2208 | 2208 | ||
| 2209 | pub fn cloneWithDifferentAllocator(other: Managed, allocator: *Allocator) !Managed { | 2209 | pub fn cloneWithDifferentAllocator(other: Managed, allocator: Allocator) !Managed { |
| 2210 | return Managed{ | 2210 | return Managed{ |
| 2211 | .allocator = allocator, | 2211 | .allocator = allocator, |
| 2212 | .metadata = other.metadata, | 2212 | .metadata = other.metadata, |
| ... | @@ -2347,7 +2347,7 @@ pub const Managed = struct { | ... | @@ -2347,7 +2347,7 @@ pub const Managed = struct { |
| 2347 | 2347 | ||
| 2348 | /// Converts self to a string in the requested base. Memory is allocated from the provided | 2348 | /// Converts self to a string in the requested base. Memory is allocated from the provided |
| 2349 | /// allocator and not the one present in self. | 2349 | /// allocator and not the one present in self. |
| 2350 | pub fn toString(self: Managed, allocator: *Allocator, base: u8, case: std.fmt.Case) ![]u8 { | 2350 | pub fn toString(self: Managed, allocator: Allocator, base: u8, case: std.fmt.Case) ![]u8 { |
| 2351 | _ = allocator; | 2351 | _ = allocator; |
| 2352 | if (base < 2 or base > 16) return error.InvalidBase; | 2352 | if (base < 2 or base > 16) return error.InvalidBase; |
| 2353 | return self.toConst().toStringAlloc(self.allocator, base, case); | 2353 | return self.toConst().toStringAlloc(self.allocator, base, case); |
| ... | @@ -2784,7 +2784,7 @@ const AccOp = enum { | ... | @@ -2784,7 +2784,7 @@ const AccOp = enum { |
| 2784 | /// r MUST NOT alias any of a or b. | 2784 | /// r MUST NOT alias any of a or b. |
| 2785 | /// | 2785 | /// |
| 2786 | /// The result is computed modulo `r.len`. When `r.len >= a.len + b.len`, no overflow occurs. | 2786 | /// The result is computed modulo `r.len`. When `r.len >= a.len + b.len`, no overflow occurs. |
| 2787 | fn llmulacc(comptime op: AccOp, opt_allocator: ?*Allocator, r: []Limb, a: []const Limb, b: []const Limb) void { | 2787 | fn llmulacc(comptime op: AccOp, opt_allocator: ?Allocator, r: []Limb, a: []const Limb, b: []const Limb) void { |
| 2788 | @setRuntimeSafety(debug_safety); | 2788 | @setRuntimeSafety(debug_safety); |
| 2789 | assert(r.len >= a.len); | 2789 | assert(r.len >= a.len); |
| 2790 | assert(r.len >= b.len); | 2790 | assert(r.len >= b.len); |
| ... | @@ -2819,7 +2819,7 @@ fn llmulacc(comptime op: AccOp, opt_allocator: ?*Allocator, r: []Limb, a: []cons | ... | @@ -2819,7 +2819,7 @@ fn llmulacc(comptime op: AccOp, opt_allocator: ?*Allocator, r: []Limb, a: []cons |
| 2819 | /// The result is computed modulo `r.len`. When `r.len >= a.len + b.len`, no overflow occurs. | 2819 | /// The result is computed modulo `r.len`. When `r.len >= a.len + b.len`, no overflow occurs. |
| 2820 | fn llmulaccKaratsuba( | 2820 | fn llmulaccKaratsuba( |
| 2821 | comptime op: AccOp, | 2821 | comptime op: AccOp, |
| 2822 | allocator: *Allocator, | 2822 | allocator: Allocator, |
| 2823 | r: []Limb, | 2823 | r: []Limb, |
| 2824 | a: []const Limb, | 2824 | a: []const Limb, |
| 2825 | b: []const Limb, | 2825 | b: []const Limb, |
lib/std/math/big/rational.zig+1-1| ... | @@ -29,7 +29,7 @@ pub const Rational = struct { | ... | @@ -29,7 +29,7 @@ pub const Rational = struct { |
| 29 | 29 | ||
| 30 | /// Create a new Rational. A small amount of memory will be allocated on initialization. | 30 | /// Create a new Rational. A small amount of memory will be allocated on initialization. |
| 31 | /// This will be 2 * Int.default_capacity. | 31 | /// This will be 2 * Int.default_capacity. |
| 32 | pub fn init(a: *Allocator) !Rational { | 32 | pub fn init(a: Allocator) !Rational { |
| 33 | return Rational{ | 33 | return Rational{ |
| 34 | .p = try Int.init(a), | 34 | .p = try Int.init(a), |
| 35 | .q = try Int.initSet(a, 1), | 35 | .q = try Int.initSet(a, 1), |
lib/std/mem.zig+29-26| ... | @@ -37,24 +37,26 @@ pub const Allocator = @import("mem/Allocator.zig"); | ... | @@ -37,24 +37,26 @@ pub const Allocator = @import("mem/Allocator.zig"); |
| 37 | pub fn ValidationAllocator(comptime T: type) type { | 37 | pub fn ValidationAllocator(comptime T: type) type { |
| 38 | return struct { | 38 | return struct { |
| 39 | const Self = @This(); | 39 | const Self = @This(); |
| 40 | allocator: Allocator, | 40 | |
| 41 | underlying_allocator: T, | 41 | underlying_allocator: T, |
| 42 | |||
| 42 | pub fn init(allocator: T) @This() { | 43 | pub fn init(allocator: T) @This() { |
| 43 | return .{ | 44 | return .{ |
| 44 | .allocator = .{ | ||
| 45 | .allocFn = alloc, | ||
| 46 | .resizeFn = resize, | ||
| 47 | }, | ||
| 48 | .underlying_allocator = allocator, | 45 | .underlying_allocator = allocator, |
| 49 | }; | 46 | }; |
| 50 | } | 47 | } |
| 51 | fn getUnderlyingAllocatorPtr(self: *@This()) *Allocator { | 48 | |
| 52 | if (T == *Allocator) return self.underlying_allocator; | 49 | pub fn getAllocator(self: *Self) Allocator { |
| 53 | if (*T == *Allocator) return &self.underlying_allocator; | 50 | return Allocator.init(self, alloc, resize); |
| 54 | return &self.underlying_allocator.allocator; | ||
| 55 | } | 51 | } |
| 52 | |||
| 53 | fn getUnderlyingAllocatorPtr(self: *Self) Allocator { | ||
| 54 | if (T == Allocator) return self.underlying_allocator; | ||
| 55 | return self.underlying_allocator.getAllocator(); | ||
| 56 | } | ||
| 57 | |||
| 56 | pub fn alloc( | 58 | pub fn alloc( |
| 57 | allocator: *Allocator, | 59 | self: *Self, |
| 58 | n: usize, | 60 | n: usize, |
| 59 | ptr_align: u29, | 61 | ptr_align: u29, |
| 60 | len_align: u29, | 62 | len_align: u29, |
| ... | @@ -67,9 +69,8 @@ pub fn ValidationAllocator(comptime T: type) type { | ... | @@ -67,9 +69,8 @@ pub fn ValidationAllocator(comptime T: type) type { |
| 67 | assert(n >= len_align); | 69 | assert(n >= len_align); |
| 68 | } | 70 | } |
| 69 | 71 | ||
| 70 | const self = @fieldParentPtr(@This(), "allocator", allocator); | ||
| 71 | const underlying = self.getUnderlyingAllocatorPtr(); | 72 | const underlying = self.getUnderlyingAllocatorPtr(); |
| 72 | const result = try underlying.allocFn(underlying, n, ptr_align, len_align, ret_addr); | 73 | const result = try underlying.allocFn(underlying.ptr, n, ptr_align, len_align, ret_addr); |
| 73 | assert(mem.isAligned(@ptrToInt(result.ptr), ptr_align)); | 74 | assert(mem.isAligned(@ptrToInt(result.ptr), ptr_align)); |
| 74 | if (len_align == 0) { | 75 | if (len_align == 0) { |
| 75 | assert(result.len == n); | 76 | assert(result.len == n); |
| ... | @@ -79,8 +80,9 @@ pub fn ValidationAllocator(comptime T: type) type { | ... | @@ -79,8 +80,9 @@ pub fn ValidationAllocator(comptime T: type) type { |
| 79 | } | 80 | } |
| 80 | return result; | 81 | return result; |
| 81 | } | 82 | } |
| 83 | |||
| 82 | pub fn resize( | 84 | pub fn resize( |
| 83 | allocator: *Allocator, | 85 | self: *Self, |
| 84 | buf: []u8, | 86 | buf: []u8, |
| 85 | buf_align: u29, | 87 | buf_align: u29, |
| 86 | new_len: usize, | 88 | new_len: usize, |
| ... | @@ -92,9 +94,8 @@ pub fn ValidationAllocator(comptime T: type) type { | ... | @@ -92,9 +94,8 @@ pub fn ValidationAllocator(comptime T: type) type { |
| 92 | assert(mem.isAlignedAnyAlign(new_len, len_align)); | 94 | assert(mem.isAlignedAnyAlign(new_len, len_align)); |
| 93 | assert(new_len >= len_align); | 95 | assert(new_len >= len_align); |
| 94 | } | 96 | } |
| 95 | const self = @fieldParentPtr(@This(), "allocator", allocator); | ||
| 96 | const underlying = self.getUnderlyingAllocatorPtr(); | 97 | const underlying = self.getUnderlyingAllocatorPtr(); |
| 97 | const result = try underlying.resizeFn(underlying, buf, buf_align, new_len, len_align, ret_addr); | 98 | const result = try underlying.resizeFn(underlying.ptr, buf, buf_align, new_len, len_align, ret_addr); |
| 98 | if (len_align == 0) { | 99 | if (len_align == 0) { |
| 99 | assert(result == new_len); | 100 | assert(result == new_len); |
| 100 | } else { | 101 | } else { |
| ... | @@ -103,7 +104,7 @@ pub fn ValidationAllocator(comptime T: type) type { | ... | @@ -103,7 +104,7 @@ pub fn ValidationAllocator(comptime T: type) type { |
| 103 | } | 104 | } |
| 104 | return result; | 105 | return result; |
| 105 | } | 106 | } |
| 106 | pub usingnamespace if (T == *Allocator or !@hasDecl(T, "reset")) struct {} else struct { | 107 | pub usingnamespace if (T == Allocator or !@hasDecl(T, "reset")) struct {} else struct { |
| 107 | pub fn reset(self: *Self) void { | 108 | pub fn reset(self: *Self) void { |
| 108 | self.underlying_allocator.reset(); | 109 | self.underlying_allocator.reset(); |
| 109 | } | 110 | } |
| ... | @@ -130,12 +131,14 @@ pub fn alignAllocLen(full_len: usize, alloc_len: usize, len_align: u29) usize { | ... | @@ -130,12 +131,14 @@ pub fn alignAllocLen(full_len: usize, alloc_len: usize, len_align: u29) usize { |
| 130 | return adjusted; | 131 | return adjusted; |
| 131 | } | 132 | } |
| 132 | 133 | ||
| 133 | var failAllocator = Allocator{ | 134 | const failAllocator = blk: { |
| 134 | .allocFn = failAllocatorAlloc, | 135 | // TODO: This is an ugly hack, it could be improved once https://github.com/ziglang/zig/issues/6706 is implemented |
| 135 | .resizeFn = Allocator.noResize, | 136 | // allowing the use of `*void` but it would still be ugly |
| 137 | var tmp: u1 = 0; | ||
| 138 | break :blk Allocator.init(&tmp, failAllocatorAlloc, Allocator.NoResize(u1).noResize); | ||
| 136 | }; | 139 | }; |
| 137 | fn failAllocatorAlloc(self: *Allocator, n: usize, alignment: u29, len_align: u29, ra: usize) Allocator.Error![]u8 { | 140 | |
| 138 | _ = self; | 141 | fn failAllocatorAlloc(_: *u1, n: usize, alignment: u29, len_align: u29, ra: usize) Allocator.Error![]u8 { |
| 139 | _ = n; | 142 | _ = n; |
| 140 | _ = alignment; | 143 | _ = alignment; |
| 141 | _ = len_align; | 144 | _ = len_align; |
| ... | @@ -1786,18 +1789,18 @@ pub fn SplitIterator(comptime T: type) type { | ... | @@ -1786,18 +1789,18 @@ pub fn SplitIterator(comptime T: type) type { |
| 1786 | 1789 | ||
| 1787 | /// Naively combines a series of slices with a separator. | 1790 | /// Naively combines a series of slices with a separator. |
| 1788 | /// Allocates memory for the result, which must be freed by the caller. | 1791 | /// Allocates memory for the result, which must be freed by the caller. |
| 1789 | pub fn join(allocator: *Allocator, separator: []const u8, slices: []const []const u8) ![]u8 { | 1792 | pub fn join(allocator: Allocator, separator: []const u8, slices: []const []const u8) ![]u8 { |
| 1790 | return joinMaybeZ(allocator, separator, slices, false); | 1793 | return joinMaybeZ(allocator, separator, slices, false); |
| 1791 | } | 1794 | } |
| 1792 | 1795 | ||
| 1793 | /// Naively combines a series of slices with a separator and null terminator. | 1796 | /// Naively combines a series of slices with a separator and null terminator. |
| 1794 | /// Allocates memory for the result, which must be freed by the caller. | 1797 | /// Allocates memory for the result, which must be freed by the caller. |
| 1795 | pub fn joinZ(allocator: *Allocator, separator: []const u8, slices: []const []const u8) ![:0]u8 { | 1798 | pub fn joinZ(allocator: Allocator, separator: []const u8, slices: []const []const u8) ![:0]u8 { |
| 1796 | const out = try joinMaybeZ(allocator, separator, slices, true); | 1799 | const out = try joinMaybeZ(allocator, separator, slices, true); |
| 1797 | return out[0 .. out.len - 1 :0]; | 1800 | return out[0 .. out.len - 1 :0]; |
| 1798 | } | 1801 | } |
| 1799 | 1802 | ||
| 1800 | fn joinMaybeZ(allocator: *Allocator, separator: []const u8, slices: []const []const u8, zero: bool) ![]u8 { | 1803 | fn joinMaybeZ(allocator: Allocator, separator: []const u8, slices: []const []const u8, zero: bool) ![]u8 { |
| 1801 | if (slices.len == 0) return if (zero) try allocator.dupe(u8, &[1]u8{0}) else &[0]u8{}; | 1804 | if (slices.len == 0) return if (zero) try allocator.dupe(u8, &[1]u8{0}) else &[0]u8{}; |
| 1802 | 1805 | ||
| 1803 | const total_len = blk: { | 1806 | const total_len = blk: { |
| ... | @@ -1876,7 +1879,7 @@ test "mem.joinZ" { | ... | @@ -1876,7 +1879,7 @@ test "mem.joinZ" { |
| 1876 | } | 1879 | } |
| 1877 | 1880 | ||
| 1878 | /// Copies each T from slices into a new slice that exactly holds all the elements. | 1881 | /// Copies each T from slices into a new slice that exactly holds all the elements. |
| 1879 | pub fn concat(allocator: *Allocator, comptime T: type, slices: []const []const T) ![]T { | 1882 | pub fn concat(allocator: Allocator, comptime T: type, slices: []const []const T) ![]T { |
| 1880 | if (slices.len == 0) return &[0]T{}; | 1883 | if (slices.len == 0) return &[0]T{}; |
| 1881 | 1884 | ||
| 1882 | const total_len = blk: { | 1885 | const total_len = blk: { |
| ... | @@ -2318,7 +2321,7 @@ test "replacementSize" { | ... | @@ -2318,7 +2321,7 @@ test "replacementSize" { |
| 2318 | } | 2321 | } |
| 2319 | 2322 | ||
| 2320 | /// Perform a replacement on an allocated buffer of pre-determined size. Caller must free returned memory. | 2323 | /// Perform a replacement on an allocated buffer of pre-determined size. Caller must free returned memory. |
| 2321 | pub fn replaceOwned(comptime T: type, allocator: *Allocator, input: []const T, needle: []const T, replacement: []const T) Allocator.Error![]T { | 2324 | pub fn replaceOwned(comptime T: type, allocator: Allocator, input: []const T, needle: []const T, replacement: []const T) Allocator.Error![]T { |
| 2322 | var output = try allocator.alloc(T, replacementSize(T, input, needle, replacement)); | 2325 | var output = try allocator.alloc(T, replacementSize(T, input, needle, replacement)); |
| 2323 | _ = replace(T, input, needle, replacement, output); | 2326 | _ = replace(T, input, needle, replacement, output); |
| 2324 | return output; | 2327 | return output; |
lib/std/mem/Allocator.zig+83-48| ... | @@ -8,6 +8,9 @@ const Allocator = @This(); | ... | @@ -8,6 +8,9 @@ const Allocator = @This(); |
| 8 | 8 | ||
| 9 | pub const Error = error{OutOfMemory}; | 9 | pub const Error = error{OutOfMemory}; |
| 10 | 10 | ||
| 11 | // The type erased pointer to the allocator implementation | ||
| 12 | ptr: *c_void, | ||
| 13 | |||
| 11 | /// Attempt to allocate at least `len` bytes aligned to `ptr_align`. | 14 | /// Attempt to allocate at least `len` bytes aligned to `ptr_align`. |
| 12 | /// | 15 | /// |
| 13 | /// If `len_align` is `0`, then the length returned MUST be exactly `len` bytes, | 16 | /// If `len_align` is `0`, then the length returned MUST be exactly `len` bytes, |
| ... | @@ -17,7 +20,7 @@ pub const Error = error{OutOfMemory}; | ... | @@ -17,7 +20,7 @@ pub const Error = error{OutOfMemory}; |
| 17 | /// | 20 | /// |
| 18 | /// `ret_addr` is optionally provided as the first return address of the allocation call stack. | 21 | /// `ret_addr` is optionally provided as the first return address of the allocation call stack. |
| 19 | /// If the value is `0` it means no return address has been provided. | 22 | /// If the value is `0` it means no return address has been provided. |
| 20 | allocFn: fn (self: *Allocator, len: usize, ptr_align: u29, len_align: u29, ret_addr: usize) Error![]u8, | 23 | allocFn: fn (ptr: *c_void, len: usize, ptr_align: u29, len_align: u29, ret_addr: usize) Error![]u8, |
| 21 | 24 | ||
| 22 | /// Attempt to expand or shrink memory in place. `buf.len` must equal the most recent | 25 | /// Attempt to expand or shrink memory in place. `buf.len` must equal the most recent |
| 23 | /// length returned by `allocFn` or `resizeFn`. `buf_align` must equal the same value | 26 | /// length returned by `allocFn` or `resizeFn`. `buf_align` must equal the same value |
| ... | @@ -39,24 +42,56 @@ allocFn: fn (self: *Allocator, len: usize, ptr_align: u29, len_align: u29, ret_a | ... | @@ -39,24 +42,56 @@ allocFn: fn (self: *Allocator, len: usize, ptr_align: u29, len_align: u29, ret_a |
| 39 | /// | 42 | /// |
| 40 | /// `ret_addr` is optionally provided as the first return address of the allocation call stack. | 43 | /// `ret_addr` is optionally provided as the first return address of the allocation call stack. |
| 41 | /// If the value is `0` it means no return address has been provided. | 44 | /// If the value is `0` it means no return address has been provided. |
| 42 | resizeFn: fn (self: *Allocator, buf: []u8, buf_align: u29, new_len: usize, len_align: u29, ret_addr: usize) Error!usize, | 45 | resizeFn: fn (ptr: *c_void, buf: []u8, buf_align: u29, new_len: usize, len_align: u29, ret_addr: usize) Error!usize, |
| 46 | |||
| 47 | pub fn init( | ||
| 48 | pointer: anytype, | ||
| 49 | comptime allocFn: fn (ptr: @TypeOf(pointer), len: usize, ptr_align: u29, len_align: u29, ret_addr: usize) Error![]u8, | ||
| 50 | comptime resizeFn: fn (ptr: @TypeOf(pointer), buf: []u8, buf_align: u29, new_len: usize, len_align: u29, ret_addr: usize) Error!usize, | ||
| 51 | ) Allocator { | ||
| 52 | const Ptr = @TypeOf(pointer); | ||
| 53 | assert(@typeInfo(Ptr) == .Pointer); // Must be a pointer | ||
| 54 | assert(@typeInfo(Ptr).Pointer.size == .One); // Must be a single-item pointer | ||
| 55 | const gen = struct { | ||
| 56 | fn alloc(ptr: *c_void, len: usize, ptr_align: u29, len_align: u29, ret_addr: usize) Error![]u8 { | ||
| 57 | const alignment = @typeInfo(Ptr).Pointer.alignment; | ||
| 58 | const self = @ptrCast(Ptr, @alignCast(alignment, ptr)); | ||
| 59 | return allocFn(self, len, ptr_align, len_align, ret_addr); | ||
| 60 | } | ||
| 61 | fn resize(ptr: *c_void, buf: []u8, buf_align: u29, new_len: usize, len_align: u29, ret_addr: usize) Error!usize { | ||
| 62 | const alignment = @typeInfo(Ptr).Pointer.alignment; | ||
| 63 | const self = @ptrCast(Ptr, @alignCast(alignment, ptr)); | ||
| 64 | return resizeFn(self, buf, buf_align, new_len, len_align, ret_addr); | ||
| 65 | } | ||
| 66 | }; | ||
| 43 | 67 | ||
| 44 | /// Set to resizeFn if in-place resize is not supported. | 68 | return .{ |
| 45 | pub fn noResize( | 69 | .ptr = pointer, |
| 46 | self: *Allocator, | 70 | .allocFn = gen.alloc, |
| 47 | buf: []u8, | 71 | .resizeFn = gen.resize, |
| 48 | buf_align: u29, | 72 | }; |
| 49 | new_len: usize, | 73 | } |
| 50 | len_align: u29, | 74 | |
| 51 | ret_addr: usize, | 75 | /// Set resizeFn to `NoResize(AllocatorType).noResize` if in-place resize is not supported. |
| 52 | ) Error!usize { | 76 | pub fn NoResize(comptime AllocatorType: type) type { |
| 53 | _ = self; | 77 | return struct { |
| 54 | _ = buf_align; | 78 | pub fn noResize( |
| 55 | _ = len_align; | 79 | self: *AllocatorType, |
| 56 | _ = ret_addr; | 80 | buf: []u8, |
| 57 | if (new_len > buf.len) | 81 | buf_align: u29, |
| 58 | return error.OutOfMemory; | 82 | new_len: usize, |
| 59 | return new_len; | 83 | len_align: u29, |
| 84 | ret_addr: usize, | ||
| 85 | ) Error!usize { | ||
| 86 | _ = self; | ||
| 87 | _ = buf_align; | ||
| 88 | _ = len_align; | ||
| 89 | _ = ret_addr; | ||
| 90 | if (new_len > buf.len) | ||
| 91 | return error.OutOfMemory; | ||
| 92 | return new_len; | ||
| 93 | } | ||
| 94 | }; | ||
| 60 | } | 95 | } |
| 61 | 96 | ||
| 62 | /// Realloc is used to modify the size or alignment of an existing allocation, | 97 | /// Realloc is used to modify the size or alignment of an existing allocation, |
| ... | @@ -80,8 +115,8 @@ pub fn noResize( | ... | @@ -80,8 +115,8 @@ pub fn noResize( |
| 80 | /// as `old_mem` was when `reallocFn` is called. The bytes of | 115 | /// as `old_mem` was when `reallocFn` is called. The bytes of |
| 81 | /// `return_value[old_mem.len..]` have undefined values. | 116 | /// `return_value[old_mem.len..]` have undefined values. |
| 82 | /// The returned slice must have its pointer aligned at least to `new_alignment` bytes. | 117 | /// The returned slice must have its pointer aligned at least to `new_alignment` bytes. |
| 83 | pub fn reallocBytes( | 118 | fn reallocBytes( |
| 84 | self: *Allocator, | 119 | self: Allocator, |
| 85 | /// Guaranteed to be the same as what was returned from most recent call to | 120 | /// Guaranteed to be the same as what was returned from most recent call to |
| 86 | /// `allocFn` or `resizeFn`. | 121 | /// `allocFn` or `resizeFn`. |
| 87 | /// If `old_mem.len == 0` then this is a new allocation and `new_byte_count` | 122 | /// If `old_mem.len == 0` then this is a new allocation and `new_byte_count` |
| ... | @@ -106,7 +141,7 @@ pub fn reallocBytes( | ... | @@ -106,7 +141,7 @@ pub fn reallocBytes( |
| 106 | return_address: usize, | 141 | return_address: usize, |
| 107 | ) Error![]u8 { | 142 | ) Error![]u8 { |
| 108 | if (old_mem.len == 0) { | 143 | if (old_mem.len == 0) { |
| 109 | const new_mem = try self.allocFn(self, new_byte_count, new_alignment, len_align, return_address); | 144 | const new_mem = try self.allocFn(self.ptr, new_byte_count, new_alignment, len_align, return_address); |
| 110 | // TODO: https://github.com/ziglang/zig/issues/4298 | 145 | // TODO: https://github.com/ziglang/zig/issues/4298 |
| 111 | @memset(new_mem.ptr, undefined, new_byte_count); | 146 | @memset(new_mem.ptr, undefined, new_byte_count); |
| 112 | return new_mem; | 147 | return new_mem; |
| ... | @@ -117,7 +152,7 @@ pub fn reallocBytes( | ... | @@ -117,7 +152,7 @@ pub fn reallocBytes( |
| 117 | const shrunk_len = self.shrinkBytes(old_mem, old_alignment, new_byte_count, len_align, return_address); | 152 | const shrunk_len = self.shrinkBytes(old_mem, old_alignment, new_byte_count, len_align, return_address); |
| 118 | return old_mem.ptr[0..shrunk_len]; | 153 | return old_mem.ptr[0..shrunk_len]; |
| 119 | } | 154 | } |
| 120 | if (self.resizeFn(self, old_mem, old_alignment, new_byte_count, len_align, return_address)) |resized_len| { | 155 | if (self.resizeFn(self.ptr, old_mem, old_alignment, new_byte_count, len_align, return_address)) |resized_len| { |
| 121 | assert(resized_len >= new_byte_count); | 156 | assert(resized_len >= new_byte_count); |
| 122 | // TODO: https://github.com/ziglang/zig/issues/4298 | 157 | // TODO: https://github.com/ziglang/zig/issues/4298 |
| 123 | @memset(old_mem.ptr + new_byte_count, undefined, resized_len - new_byte_count); | 158 | @memset(old_mem.ptr + new_byte_count, undefined, resized_len - new_byte_count); |
| ... | @@ -133,7 +168,7 @@ pub fn reallocBytes( | ... | @@ -133,7 +168,7 @@ pub fn reallocBytes( |
| 133 | /// Move the given memory to a new location in the given allocator to accomodate a new | 168 | /// Move the given memory to a new location in the given allocator to accomodate a new |
| 134 | /// size and alignment. | 169 | /// size and alignment. |
| 135 | fn moveBytes( | 170 | fn moveBytes( |
| 136 | self: *Allocator, | 171 | self: Allocator, |
| 137 | old_mem: []u8, | 172 | old_mem: []u8, |
| 138 | old_align: u29, | 173 | old_align: u29, |
| 139 | new_len: usize, | 174 | new_len: usize, |
| ... | @@ -143,7 +178,7 @@ fn moveBytes( | ... | @@ -143,7 +178,7 @@ fn moveBytes( |
| 143 | ) Error![]u8 { | 178 | ) Error![]u8 { |
| 144 | assert(old_mem.len > 0); | 179 | assert(old_mem.len > 0); |
| 145 | assert(new_len > 0); | 180 | assert(new_len > 0); |
| 146 | const new_mem = try self.allocFn(self, new_len, new_alignment, len_align, return_address); | 181 | const new_mem = try self.allocFn(self.ptr, new_len, new_alignment, len_align, return_address); |
| 147 | @memcpy(new_mem.ptr, old_mem.ptr, math.min(new_len, old_mem.len)); | 182 | @memcpy(new_mem.ptr, old_mem.ptr, math.min(new_len, old_mem.len)); |
| 148 | // TODO https://github.com/ziglang/zig/issues/4298 | 183 | // TODO https://github.com/ziglang/zig/issues/4298 |
| 149 | @memset(old_mem.ptr, undefined, old_mem.len); | 184 | @memset(old_mem.ptr, undefined, old_mem.len); |
| ... | @@ -153,7 +188,7 @@ fn moveBytes( | ... | @@ -153,7 +188,7 @@ fn moveBytes( |
| 153 | 188 | ||
| 154 | /// Returns a pointer to undefined memory. | 189 | /// Returns a pointer to undefined memory. |
| 155 | /// Call `destroy` with the result to free the memory. | 190 | /// Call `destroy` with the result to free the memory. |
| 156 | pub fn create(self: *Allocator, comptime T: type) Error!*T { | 191 | pub fn create(self: Allocator, comptime T: type) Error!*T { |
| 157 | if (@sizeOf(T) == 0) return @as(*T, undefined); | 192 | if (@sizeOf(T) == 0) return @as(*T, undefined); |
| 158 | const slice = try self.allocAdvancedWithRetAddr(T, null, 1, .exact, @returnAddress()); | 193 | const slice = try self.allocAdvancedWithRetAddr(T, null, 1, .exact, @returnAddress()); |
| 159 | return &slice[0]; | 194 | return &slice[0]; |
| ... | @@ -161,7 +196,7 @@ pub fn create(self: *Allocator, comptime T: type) Error!*T { | ... | @@ -161,7 +196,7 @@ pub fn create(self: *Allocator, comptime T: type) Error!*T { |
| 161 | 196 | ||
| 162 | /// `ptr` should be the return value of `create`, or otherwise | 197 | /// `ptr` should be the return value of `create`, or otherwise |
| 163 | /// have the same address and alignment property. | 198 | /// have the same address and alignment property. |
| 164 | pub fn destroy(self: *Allocator, ptr: anytype) void { | 199 | pub fn destroy(self: Allocator, ptr: anytype) void { |
| 165 | const info = @typeInfo(@TypeOf(ptr)).Pointer; | 200 | const info = @typeInfo(@TypeOf(ptr)).Pointer; |
| 166 | const T = info.child; | 201 | const T = info.child; |
| 167 | if (@sizeOf(T) == 0) return; | 202 | if (@sizeOf(T) == 0) return; |
| ... | @@ -177,12 +212,12 @@ pub fn destroy(self: *Allocator, ptr: anytype) void { | ... | @@ -177,12 +212,12 @@ pub fn destroy(self: *Allocator, ptr: anytype) void { |
| 177 | /// call `free` when done. | 212 | /// call `free` when done. |
| 178 | /// | 213 | /// |
| 179 | /// For allocating a single item, see `create`. | 214 | /// For allocating a single item, see `create`. |
| 180 | pub fn alloc(self: *Allocator, comptime T: type, n: usize) Error![]T { | 215 | pub fn alloc(self: Allocator, comptime T: type, n: usize) Error![]T { |
| 181 | return self.allocAdvancedWithRetAddr(T, null, n, .exact, @returnAddress()); | 216 | return self.allocAdvancedWithRetAddr(T, null, n, .exact, @returnAddress()); |
| 182 | } | 217 | } |
| 183 | 218 | ||
| 184 | pub fn allocWithOptions( | 219 | pub fn allocWithOptions( |
| 185 | self: *Allocator, | 220 | self: Allocator, |
| 186 | comptime Elem: type, | 221 | comptime Elem: type, |
| 187 | n: usize, | 222 | n: usize, |
| 188 | /// null means naturally aligned | 223 | /// null means naturally aligned |
| ... | @@ -193,7 +228,7 @@ pub fn allocWithOptions( | ... | @@ -193,7 +228,7 @@ pub fn allocWithOptions( |
| 193 | } | 228 | } |
| 194 | 229 | ||
| 195 | pub fn allocWithOptionsRetAddr( | 230 | pub fn allocWithOptionsRetAddr( |
| 196 | self: *Allocator, | 231 | self: Allocator, |
| 197 | comptime Elem: type, | 232 | comptime Elem: type, |
| 198 | n: usize, | 233 | n: usize, |
| 199 | /// null means naturally aligned | 234 | /// null means naturally aligned |
| ... | @@ -227,7 +262,7 @@ fn AllocWithOptionsPayload(comptime Elem: type, comptime alignment: ?u29, compti | ... | @@ -227,7 +262,7 @@ fn AllocWithOptionsPayload(comptime Elem: type, comptime alignment: ?u29, compti |
| 227 | /// | 262 | /// |
| 228 | /// For allocating a single item, see `create`. | 263 | /// For allocating a single item, see `create`. |
| 229 | pub fn allocSentinel( | 264 | pub fn allocSentinel( |
| 230 | self: *Allocator, | 265 | self: Allocator, |
| 231 | comptime Elem: type, | 266 | comptime Elem: type, |
| 232 | n: usize, | 267 | n: usize, |
| 233 | comptime sentinel: Elem, | 268 | comptime sentinel: Elem, |
| ... | @@ -236,7 +271,7 @@ pub fn allocSentinel( | ... | @@ -236,7 +271,7 @@ pub fn allocSentinel( |
| 236 | } | 271 | } |
| 237 | 272 | ||
| 238 | pub fn alignedAlloc( | 273 | pub fn alignedAlloc( |
| 239 | self: *Allocator, | 274 | self: Allocator, |
| 240 | comptime T: type, | 275 | comptime T: type, |
| 241 | /// null means naturally aligned | 276 | /// null means naturally aligned |
| 242 | comptime alignment: ?u29, | 277 | comptime alignment: ?u29, |
| ... | @@ -246,7 +281,7 @@ pub fn alignedAlloc( | ... | @@ -246,7 +281,7 @@ pub fn alignedAlloc( |
| 246 | } | 281 | } |
| 247 | 282 | ||
| 248 | pub fn allocAdvanced( | 283 | pub fn allocAdvanced( |
| 249 | self: *Allocator, | 284 | self: Allocator, |
| 250 | comptime T: type, | 285 | comptime T: type, |
| 251 | /// null means naturally aligned | 286 | /// null means naturally aligned |
| 252 | comptime alignment: ?u29, | 287 | comptime alignment: ?u29, |
| ... | @@ -259,7 +294,7 @@ pub fn allocAdvanced( | ... | @@ -259,7 +294,7 @@ pub fn allocAdvanced( |
| 259 | pub const Exact = enum { exact, at_least }; | 294 | pub const Exact = enum { exact, at_least }; |
| 260 | 295 | ||
| 261 | pub fn allocAdvancedWithRetAddr( | 296 | pub fn allocAdvancedWithRetAddr( |
| 262 | self: *Allocator, | 297 | self: Allocator, |
| 263 | comptime T: type, | 298 | comptime T: type, |
| 264 | /// null means naturally aligned | 299 | /// null means naturally aligned |
| 265 | comptime alignment: ?u29, | 300 | comptime alignment: ?u29, |
| ... | @@ -285,7 +320,7 @@ pub fn allocAdvancedWithRetAddr( | ... | @@ -285,7 +320,7 @@ pub fn allocAdvancedWithRetAddr( |
| 285 | .exact => 0, | 320 | .exact => 0, |
| 286 | .at_least => size_of_T, | 321 | .at_least => size_of_T, |
| 287 | }; | 322 | }; |
| 288 | const byte_slice = try self.allocFn(self, byte_count, a, len_align, return_address); | 323 | const byte_slice = try self.allocFn(self.ptr, byte_count, a, len_align, return_address); |
| 289 | switch (exact) { | 324 | switch (exact) { |
| 290 | .exact => assert(byte_slice.len == byte_count), | 325 | .exact => assert(byte_slice.len == byte_count), |
| 291 | .at_least => assert(byte_slice.len >= byte_count), | 326 | .at_least => assert(byte_slice.len >= byte_count), |
| ... | @@ -301,7 +336,7 @@ pub fn allocAdvancedWithRetAddr( | ... | @@ -301,7 +336,7 @@ pub fn allocAdvancedWithRetAddr( |
| 301 | } | 336 | } |
| 302 | 337 | ||
| 303 | /// Increases or decreases the size of an allocation. It is guaranteed to not move the pointer. | 338 | /// Increases or decreases the size of an allocation. It is guaranteed to not move the pointer. |
| 304 | pub fn resize(self: *Allocator, old_mem: anytype, new_n: usize) Error!@TypeOf(old_mem) { | 339 | pub fn resize(self: Allocator, old_mem: anytype, new_n: usize) Error!@TypeOf(old_mem) { |
| 305 | const Slice = @typeInfo(@TypeOf(old_mem)).Pointer; | 340 | const Slice = @typeInfo(@TypeOf(old_mem)).Pointer; |
| 306 | const T = Slice.child; | 341 | const T = Slice.child; |
| 307 | if (new_n == 0) { | 342 | if (new_n == 0) { |
| ... | @@ -310,7 +345,7 @@ pub fn resize(self: *Allocator, old_mem: anytype, new_n: usize) Error!@TypeOf(ol | ... | @@ -310,7 +345,7 @@ pub fn resize(self: *Allocator, old_mem: anytype, new_n: usize) Error!@TypeOf(ol |
| 310 | } | 345 | } |
| 311 | const old_byte_slice = mem.sliceAsBytes(old_mem); | 346 | const old_byte_slice = mem.sliceAsBytes(old_mem); |
| 312 | const new_byte_count = math.mul(usize, @sizeOf(T), new_n) catch return Error.OutOfMemory; | 347 | const new_byte_count = math.mul(usize, @sizeOf(T), new_n) catch return Error.OutOfMemory; |
| 313 | const rc = try self.resizeFn(self, old_byte_slice, Slice.alignment, new_byte_count, 0, @returnAddress()); | 348 | const rc = try self.resizeFn(self.ptr, old_byte_slice, Slice.alignment, new_byte_count, 0, @returnAddress()); |
| 314 | assert(rc == new_byte_count); | 349 | assert(rc == new_byte_count); |
| 315 | const new_byte_slice = old_byte_slice.ptr[0..new_byte_count]; | 350 | const new_byte_slice = old_byte_slice.ptr[0..new_byte_count]; |
| 316 | return mem.bytesAsSlice(T, new_byte_slice); | 351 | return mem.bytesAsSlice(T, new_byte_slice); |
| ... | @@ -326,7 +361,7 @@ pub fn resize(self: *Allocator, old_mem: anytype, new_n: usize) Error!@TypeOf(ol | ... | @@ -326,7 +361,7 @@ pub fn resize(self: *Allocator, old_mem: anytype, new_n: usize) Error!@TypeOf(ol |
| 326 | /// in `std.ArrayList.shrink`. | 361 | /// in `std.ArrayList.shrink`. |
| 327 | /// If you need guaranteed success, call `shrink`. | 362 | /// If you need guaranteed success, call `shrink`. |
| 328 | /// If `new_n` is 0, this is the same as `free` and it always succeeds. | 363 | /// If `new_n` is 0, this is the same as `free` and it always succeeds. |
| 329 | pub fn realloc(self: *Allocator, old_mem: anytype, new_n: usize) t: { | 364 | pub fn realloc(self: Allocator, old_mem: anytype, new_n: usize) t: { |
| 330 | const Slice = @typeInfo(@TypeOf(old_mem)).Pointer; | 365 | const Slice = @typeInfo(@TypeOf(old_mem)).Pointer; |
| 331 | break :t Error![]align(Slice.alignment) Slice.child; | 366 | break :t Error![]align(Slice.alignment) Slice.child; |
| 332 | } { | 367 | } { |
| ... | @@ -334,7 +369,7 @@ pub fn realloc(self: *Allocator, old_mem: anytype, new_n: usize) t: { | ... | @@ -334,7 +369,7 @@ pub fn realloc(self: *Allocator, old_mem: anytype, new_n: usize) t: { |
| 334 | return self.reallocAdvancedWithRetAddr(old_mem, old_alignment, new_n, .exact, @returnAddress()); | 369 | return self.reallocAdvancedWithRetAddr(old_mem, old_alignment, new_n, .exact, @returnAddress()); |
| 335 | } | 370 | } |
| 336 | 371 | ||
| 337 | pub fn reallocAtLeast(self: *Allocator, old_mem: anytype, new_n: usize) t: { | 372 | pub fn reallocAtLeast(self: Allocator, old_mem: anytype, new_n: usize) t: { |
| 338 | const Slice = @typeInfo(@TypeOf(old_mem)).Pointer; | 373 | const Slice = @typeInfo(@TypeOf(old_mem)).Pointer; |
| 339 | break :t Error![]align(Slice.alignment) Slice.child; | 374 | break :t Error![]align(Slice.alignment) Slice.child; |
| 340 | } { | 375 | } { |
| ... | @@ -346,7 +381,7 @@ pub fn reallocAtLeast(self: *Allocator, old_mem: anytype, new_n: usize) t: { | ... | @@ -346,7 +381,7 @@ pub fn reallocAtLeast(self: *Allocator, old_mem: anytype, new_n: usize) t: { |
| 346 | /// a new alignment, which can be larger, smaller, or the same as the old | 381 | /// a new alignment, which can be larger, smaller, or the same as the old |
| 347 | /// allocation. | 382 | /// allocation. |
| 348 | pub fn reallocAdvanced( | 383 | pub fn reallocAdvanced( |
| 349 | self: *Allocator, | 384 | self: Allocator, |
| 350 | old_mem: anytype, | 385 | old_mem: anytype, |
| 351 | comptime new_alignment: u29, | 386 | comptime new_alignment: u29, |
| 352 | new_n: usize, | 387 | new_n: usize, |
| ... | @@ -356,7 +391,7 @@ pub fn reallocAdvanced( | ... | @@ -356,7 +391,7 @@ pub fn reallocAdvanced( |
| 356 | } | 391 | } |
| 357 | 392 | ||
| 358 | pub fn reallocAdvancedWithRetAddr( | 393 | pub fn reallocAdvancedWithRetAddr( |
| 359 | self: *Allocator, | 394 | self: Allocator, |
| 360 | old_mem: anytype, | 395 | old_mem: anytype, |
| 361 | comptime new_alignment: u29, | 396 | comptime new_alignment: u29, |
| 362 | new_n: usize, | 397 | new_n: usize, |
| ... | @@ -389,7 +424,7 @@ pub fn reallocAdvancedWithRetAddr( | ... | @@ -389,7 +424,7 @@ pub fn reallocAdvancedWithRetAddr( |
| 389 | /// Shrink always succeeds, and `new_n` must be <= `old_mem.len`. | 424 | /// Shrink always succeeds, and `new_n` must be <= `old_mem.len`. |
| 390 | /// Returned slice has same alignment as old_mem. | 425 | /// Returned slice has same alignment as old_mem. |
| 391 | /// Shrinking to 0 is the same as calling `free`. | 426 | /// Shrinking to 0 is the same as calling `free`. |
| 392 | pub fn shrink(self: *Allocator, old_mem: anytype, new_n: usize) t: { | 427 | pub fn shrink(self: Allocator, old_mem: anytype, new_n: usize) t: { |
| 393 | const Slice = @typeInfo(@TypeOf(old_mem)).Pointer; | 428 | const Slice = @typeInfo(@TypeOf(old_mem)).Pointer; |
| 394 | break :t []align(Slice.alignment) Slice.child; | 429 | break :t []align(Slice.alignment) Slice.child; |
| 395 | } { | 430 | } { |
| ... | @@ -401,7 +436,7 @@ pub fn shrink(self: *Allocator, old_mem: anytype, new_n: usize) t: { | ... | @@ -401,7 +436,7 @@ pub fn shrink(self: *Allocator, old_mem: anytype, new_n: usize) t: { |
| 401 | /// a new alignment, which must be smaller or the same as the old | 436 | /// a new alignment, which must be smaller or the same as the old |
| 402 | /// allocation. | 437 | /// allocation. |
| 403 | pub fn alignedShrink( | 438 | pub fn alignedShrink( |
| 404 | self: *Allocator, | 439 | self: Allocator, |
| 405 | old_mem: anytype, | 440 | old_mem: anytype, |
| 406 | comptime new_alignment: u29, | 441 | comptime new_alignment: u29, |
| 407 | new_n: usize, | 442 | new_n: usize, |
| ... | @@ -413,7 +448,7 @@ pub fn alignedShrink( | ... | @@ -413,7 +448,7 @@ pub fn alignedShrink( |
| 413 | /// the return address of the first stack frame, which may be relevant for | 448 | /// the return address of the first stack frame, which may be relevant for |
| 414 | /// allocators which collect stack traces. | 449 | /// allocators which collect stack traces. |
| 415 | pub fn alignedShrinkWithRetAddr( | 450 | pub fn alignedShrinkWithRetAddr( |
| 416 | self: *Allocator, | 451 | self: Allocator, |
| 417 | old_mem: anytype, | 452 | old_mem: anytype, |
| 418 | comptime new_alignment: u29, | 453 | comptime new_alignment: u29, |
| 419 | new_n: usize, | 454 | new_n: usize, |
| ... | @@ -440,7 +475,7 @@ pub fn alignedShrinkWithRetAddr( | ... | @@ -440,7 +475,7 @@ pub fn alignedShrinkWithRetAddr( |
| 440 | 475 | ||
| 441 | /// Free an array allocated with `alloc`. To free a single item, | 476 | /// Free an array allocated with `alloc`. To free a single item, |
| 442 | /// see `destroy`. | 477 | /// see `destroy`. |
| 443 | pub fn free(self: *Allocator, memory: anytype) void { | 478 | pub fn free(self: Allocator, memory: anytype) void { |
| 444 | const Slice = @typeInfo(@TypeOf(memory)).Pointer; | 479 | const Slice = @typeInfo(@TypeOf(memory)).Pointer; |
| 445 | const bytes = mem.sliceAsBytes(memory); | 480 | const bytes = mem.sliceAsBytes(memory); |
| 446 | const bytes_len = bytes.len + if (Slice.sentinel != null) @sizeOf(Slice.child) else 0; | 481 | const bytes_len = bytes.len + if (Slice.sentinel != null) @sizeOf(Slice.child) else 0; |
| ... | @@ -452,14 +487,14 @@ pub fn free(self: *Allocator, memory: anytype) void { | ... | @@ -452,14 +487,14 @@ pub fn free(self: *Allocator, memory: anytype) void { |
| 452 | } | 487 | } |
| 453 | 488 | ||
| 454 | /// Copies `m` to newly allocated memory. Caller owns the memory. | 489 | /// Copies `m` to newly allocated memory. Caller owns the memory. |
| 455 | pub fn dupe(allocator: *Allocator, comptime T: type, m: []const T) ![]T { | 490 | pub fn dupe(allocator: Allocator, comptime T: type, m: []const T) ![]T { |
| 456 | const new_buf = try allocator.alloc(T, m.len); | 491 | const new_buf = try allocator.alloc(T, m.len); |
| 457 | mem.copy(T, new_buf, m); | 492 | mem.copy(T, new_buf, m); |
| 458 | return new_buf; | 493 | return new_buf; |
| 459 | } | 494 | } |
| 460 | 495 | ||
| 461 | /// Copies `m` to newly allocated memory, with a null-terminated element. Caller owns the memory. | 496 | /// Copies `m` to newly allocated memory, with a null-terminated element. Caller owns the memory. |
| 462 | pub fn dupeZ(allocator: *Allocator, comptime T: type, m: []const T) ![:0]T { | 497 | pub fn dupeZ(allocator: Allocator, comptime T: type, m: []const T) ![:0]T { |
| 463 | const new_buf = try allocator.alloc(T, m.len + 1); | 498 | const new_buf = try allocator.alloc(T, m.len + 1); |
| 464 | mem.copy(T, new_buf, m); | 499 | mem.copy(T, new_buf, m); |
| 465 | new_buf[m.len] = 0; | 500 | new_buf[m.len] = 0; |
| ... | @@ -471,7 +506,7 @@ pub fn dupeZ(allocator: *Allocator, comptime T: type, m: []const T) ![:0]T { | ... | @@ -471,7 +506,7 @@ pub fn dupeZ(allocator: *Allocator, comptime T: type, m: []const T) ![:0]T { |
| 471 | /// This function allows a runtime `buf_align` value. Callers should generally prefer | 506 | /// This function allows a runtime `buf_align` value. Callers should generally prefer |
| 472 | /// to call `shrink` directly. | 507 | /// to call `shrink` directly. |
| 473 | pub fn shrinkBytes( | 508 | pub fn shrinkBytes( |
| 474 | self: *Allocator, | 509 | self: Allocator, |
| 475 | buf: []u8, | 510 | buf: []u8, |
| 476 | buf_align: u29, | 511 | buf_align: u29, |
| 477 | new_len: usize, | 512 | new_len: usize, |
| ... | @@ -479,5 +514,5 @@ pub fn shrinkBytes( | ... | @@ -479,5 +514,5 @@ pub fn shrinkBytes( |
| 479 | return_address: usize, | 514 | return_address: usize, |
| 480 | ) usize { | 515 | ) usize { |
| 481 | assert(new_len <= buf.len); | 516 | assert(new_len <= buf.len); |
| 482 | return self.resizeFn(self, buf, buf_align, new_len, len_align, return_address) catch unreachable; | 517 | return self.resizeFn(self.ptr, buf, buf_align, new_len, len_align, return_address) catch unreachable; |
| 483 | } | 518 | } |
lib/std/multi_array_list.zig+10-10| ... | @@ -59,7 +59,7 @@ pub fn MultiArrayList(comptime S: type) type { | ... | @@ -59,7 +59,7 @@ pub fn MultiArrayList(comptime S: type) type { |
| 59 | }; | 59 | }; |
| 60 | } | 60 | } |
| 61 | 61 | ||
| 62 | pub fn deinit(self: *Slice, gpa: *Allocator) void { | 62 | pub fn deinit(self: *Slice, gpa: Allocator) void { |
| 63 | var other = self.toMultiArrayList(); | 63 | var other = self.toMultiArrayList(); |
| 64 | other.deinit(gpa); | 64 | other.deinit(gpa); |
| 65 | self.* = undefined; | 65 | self.* = undefined; |
| ... | @@ -106,7 +106,7 @@ pub fn MultiArrayList(comptime S: type) type { | ... | @@ -106,7 +106,7 @@ pub fn MultiArrayList(comptime S: type) type { |
| 106 | }; | 106 | }; |
| 107 | 107 | ||
| 108 | /// Release all allocated memory. | 108 | /// Release all allocated memory. |
| 109 | pub fn deinit(self: *Self, gpa: *Allocator) void { | 109 | pub fn deinit(self: *Self, gpa: Allocator) void { |
| 110 | gpa.free(self.allocatedBytes()); | 110 | gpa.free(self.allocatedBytes()); |
| 111 | self.* = undefined; | 111 | self.* = undefined; |
| 112 | } | 112 | } |
| ... | @@ -161,7 +161,7 @@ pub fn MultiArrayList(comptime S: type) type { | ... | @@ -161,7 +161,7 @@ pub fn MultiArrayList(comptime S: type) type { |
| 161 | } | 161 | } |
| 162 | 162 | ||
| 163 | /// Extend the list by 1 element. Allocates more memory as necessary. | 163 | /// Extend the list by 1 element. Allocates more memory as necessary. |
| 164 | pub fn append(self: *Self, gpa: *Allocator, elem: S) !void { | 164 | pub fn append(self: *Self, gpa: Allocator, elem: S) !void { |
| 165 | try self.ensureUnusedCapacity(gpa, 1); | 165 | try self.ensureUnusedCapacity(gpa, 1); |
| 166 | self.appendAssumeCapacity(elem); | 166 | self.appendAssumeCapacity(elem); |
| 167 | } | 167 | } |
| ... | @@ -188,7 +188,7 @@ pub fn MultiArrayList(comptime S: type) type { | ... | @@ -188,7 +188,7 @@ pub fn MultiArrayList(comptime S: type) type { |
| 188 | /// after and including the specified index back by one and | 188 | /// after and including the specified index back by one and |
| 189 | /// sets the given index to the specified element. May reallocate | 189 | /// sets the given index to the specified element. May reallocate |
| 190 | /// and invalidate iterators. | 190 | /// and invalidate iterators. |
| 191 | pub fn insert(self: *Self, gpa: *Allocator, index: usize, elem: S) void { | 191 | pub fn insert(self: *Self, gpa: Allocator, index: usize, elem: S) void { |
| 192 | try self.ensureUnusedCapacity(gpa, 1); | 192 | try self.ensureUnusedCapacity(gpa, 1); |
| 193 | self.insertAssumeCapacity(index, elem); | 193 | self.insertAssumeCapacity(index, elem); |
| 194 | } | 194 | } |
| ... | @@ -242,7 +242,7 @@ pub fn MultiArrayList(comptime S: type) type { | ... | @@ -242,7 +242,7 @@ pub fn MultiArrayList(comptime S: type) type { |
| 242 | 242 | ||
| 243 | /// Adjust the list's length to `new_len`. | 243 | /// Adjust the list's length to `new_len`. |
| 244 | /// Does not initialize added items, if any. | 244 | /// Does not initialize added items, if any. |
| 245 | pub fn resize(self: *Self, gpa: *Allocator, new_len: usize) !void { | 245 | pub fn resize(self: *Self, gpa: Allocator, new_len: usize) !void { |
| 246 | try self.ensureTotalCapacity(gpa, new_len); | 246 | try self.ensureTotalCapacity(gpa, new_len); |
| 247 | self.len = new_len; | 247 | self.len = new_len; |
| 248 | } | 248 | } |
| ... | @@ -250,7 +250,7 @@ pub fn MultiArrayList(comptime S: type) type { | ... | @@ -250,7 +250,7 @@ pub fn MultiArrayList(comptime S: type) type { |
| 250 | /// Attempt to reduce allocated capacity to `new_len`. | 250 | /// Attempt to reduce allocated capacity to `new_len`. |
| 251 | /// If `new_len` is greater than zero, this may fail to reduce the capacity, | 251 | /// If `new_len` is greater than zero, this may fail to reduce the capacity, |
| 252 | /// but the data remains intact and the length is updated to new_len. | 252 | /// but the data remains intact and the length is updated to new_len. |
| 253 | pub fn shrinkAndFree(self: *Self, gpa: *Allocator, new_len: usize) void { | 253 | pub fn shrinkAndFree(self: *Self, gpa: Allocator, new_len: usize) void { |
| 254 | if (new_len == 0) { | 254 | if (new_len == 0) { |
| 255 | gpa.free(self.allocatedBytes()); | 255 | gpa.free(self.allocatedBytes()); |
| 256 | self.* = .{}; | 256 | self.* = .{}; |
| ... | @@ -314,7 +314,7 @@ pub fn MultiArrayList(comptime S: type) type { | ... | @@ -314,7 +314,7 @@ pub fn MultiArrayList(comptime S: type) type { |
| 314 | /// Modify the array so that it can hold at least `new_capacity` items. | 314 | /// Modify the array so that it can hold at least `new_capacity` items. |
| 315 | /// Implements super-linear growth to achieve amortized O(1) append operations. | 315 | /// Implements super-linear growth to achieve amortized O(1) append operations. |
| 316 | /// Invalidates pointers if additional memory is needed. | 316 | /// Invalidates pointers if additional memory is needed. |
| 317 | pub fn ensureTotalCapacity(self: *Self, gpa: *Allocator, new_capacity: usize) !void { | 317 | pub fn ensureTotalCapacity(self: *Self, gpa: Allocator, new_capacity: usize) !void { |
| 318 | var better_capacity = self.capacity; | 318 | var better_capacity = self.capacity; |
| 319 | if (better_capacity >= new_capacity) return; | 319 | if (better_capacity >= new_capacity) return; |
| 320 | 320 | ||
| ... | @@ -328,14 +328,14 @@ pub fn MultiArrayList(comptime S: type) type { | ... | @@ -328,14 +328,14 @@ pub fn MultiArrayList(comptime S: type) type { |
| 328 | 328 | ||
| 329 | /// Modify the array so that it can hold at least `additional_count` **more** items. | 329 | /// Modify the array so that it can hold at least `additional_count` **more** items. |
| 330 | /// Invalidates pointers if additional memory is needed. | 330 | /// Invalidates pointers if additional memory is needed. |
| 331 | pub fn ensureUnusedCapacity(self: *Self, gpa: *Allocator, additional_count: usize) !void { | 331 | pub fn ensureUnusedCapacity(self: *Self, gpa: Allocator, additional_count: usize) !void { |
| 332 | return self.ensureTotalCapacity(gpa, self.len + additional_count); | 332 | return self.ensureTotalCapacity(gpa, self.len + additional_count); |
| 333 | } | 333 | } |
| 334 | 334 | ||
| 335 | /// Modify the array so that it can hold exactly `new_capacity` items. | 335 | /// Modify the array so that it can hold exactly `new_capacity` items. |
| 336 | /// Invalidates pointers if additional memory is needed. | 336 | /// Invalidates pointers if additional memory is needed. |
| 337 | /// `new_capacity` must be greater or equal to `len`. | 337 | /// `new_capacity` must be greater or equal to `len`. |
| 338 | pub fn setCapacity(self: *Self, gpa: *Allocator, new_capacity: usize) !void { | 338 | pub fn setCapacity(self: *Self, gpa: Allocator, new_capacity: usize) !void { |
| 339 | assert(new_capacity >= self.len); | 339 | assert(new_capacity >= self.len); |
| 340 | const new_bytes = try gpa.allocAdvanced( | 340 | const new_bytes = try gpa.allocAdvanced( |
| 341 | u8, | 341 | u8, |
| ... | @@ -372,7 +372,7 @@ pub fn MultiArrayList(comptime S: type) type { | ... | @@ -372,7 +372,7 @@ pub fn MultiArrayList(comptime S: type) type { |
| 372 | 372 | ||
| 373 | /// Create a copy of this list with a new backing store, | 373 | /// Create a copy of this list with a new backing store, |
| 374 | /// using the specified allocator. | 374 | /// using the specified allocator. |
| 375 | pub fn clone(self: Self, gpa: *Allocator) !Self { | 375 | pub fn clone(self: Self, gpa: Allocator) !Self { |
| 376 | var result = Self{}; | 376 | var result = Self{}; |
| 377 | errdefer result.deinit(gpa); | 377 | errdefer result.deinit(gpa); |
| 378 | try result.ensureTotalCapacity(gpa, self.len); | 378 | try result.ensureTotalCapacity(gpa, self.len); |
lib/std/net.zig+5-5| ... | @@ -664,7 +664,7 @@ pub const AddressList = struct { | ... | @@ -664,7 +664,7 @@ pub const AddressList = struct { |
| 664 | }; | 664 | }; |
| 665 | 665 | ||
| 666 | /// All memory allocated with `allocator` will be freed before this function returns. | 666 | /// All memory allocated with `allocator` will be freed before this function returns. |
| 667 | pub fn tcpConnectToHost(allocator: *mem.Allocator, name: []const u8, port: u16) !Stream { | 667 | pub fn tcpConnectToHost(allocator: mem.Allocator, name: []const u8, port: u16) !Stream { |
| 668 | const list = try getAddressList(allocator, name, port); | 668 | const list = try getAddressList(allocator, name, port); |
| 669 | defer list.deinit(); | 669 | defer list.deinit(); |
| 670 | 670 | ||
| ... | @@ -699,12 +699,12 @@ pub fn tcpConnectToAddress(address: Address) !Stream { | ... | @@ -699,12 +699,12 @@ pub fn tcpConnectToAddress(address: Address) !Stream { |
| 699 | } | 699 | } |
| 700 | 700 | ||
| 701 | /// Call `AddressList.deinit` on the result. | 701 | /// Call `AddressList.deinit` on the result. |
| 702 | pub fn getAddressList(allocator: *mem.Allocator, name: []const u8, port: u16) !*AddressList { | 702 | pub fn getAddressList(allocator: mem.Allocator, name: []const u8, port: u16) !*AddressList { |
| 703 | const result = blk: { | 703 | const result = blk: { |
| 704 | var arena = std.heap.ArenaAllocator.init(allocator); | 704 | var arena = std.heap.ArenaAllocator.init(allocator); |
| 705 | errdefer arena.deinit(); | 705 | errdefer arena.deinit(); |
| 706 | 706 | ||
| 707 | const result = try arena.allocator.create(AddressList); | 707 | const result = try arena.getAllocator().create(AddressList); |
| 708 | result.* = AddressList{ | 708 | result.* = AddressList{ |
| 709 | .arena = arena, | 709 | .arena = arena, |
| 710 | .addrs = undefined, | 710 | .addrs = undefined, |
| ... | @@ -712,7 +712,7 @@ pub fn getAddressList(allocator: *mem.Allocator, name: []const u8, port: u16) !* | ... | @@ -712,7 +712,7 @@ pub fn getAddressList(allocator: *mem.Allocator, name: []const u8, port: u16) !* |
| 712 | }; | 712 | }; |
| 713 | break :blk result; | 713 | break :blk result; |
| 714 | }; | 714 | }; |
| 715 | const arena = &result.arena.allocator; | 715 | const arena = result.arena.getAllocator(); |
| 716 | errdefer result.arena.deinit(); | 716 | errdefer result.arena.deinit(); |
| 717 | 717 | ||
| 718 | if (builtin.target.os.tag == .windows or builtin.link_libc) { | 718 | if (builtin.target.os.tag == .windows or builtin.link_libc) { |
| ... | @@ -1303,7 +1303,7 @@ const ResolvConf = struct { | ... | @@ -1303,7 +1303,7 @@ const ResolvConf = struct { |
| 1303 | 1303 | ||
| 1304 | /// Ignores lines longer than 512 bytes. | 1304 | /// Ignores lines longer than 512 bytes. |
| 1305 | /// TODO: https://github.com/ziglang/zig/issues/2765 and https://github.com/ziglang/zig/issues/2761 | 1305 | /// TODO: https://github.com/ziglang/zig/issues/2765 and https://github.com/ziglang/zig/issues/2761 |
| 1306 | fn getResolvConf(allocator: *mem.Allocator, rc: *ResolvConf) !void { | 1306 | fn getResolvConf(allocator: mem.Allocator, rc: *ResolvConf) !void { |
| 1307 | rc.* = ResolvConf{ | 1307 | rc.* = ResolvConf{ |
| 1308 | .ns = std.ArrayList(LookupAddr).init(allocator), | 1308 | .ns = std.ArrayList(LookupAddr).init(allocator), |
| 1309 | .search = std.ArrayList(u8).init(allocator), | 1309 | .search = std.ArrayList(u8).init(allocator), |
lib/std/net/test.zig+1-1| ... | @@ -230,7 +230,7 @@ test "listen on ipv4 try connect on ipv6 then ipv4" { | ... | @@ -230,7 +230,7 @@ test "listen on ipv4 try connect on ipv6 then ipv4" { |
| 230 | try await client_frame; | 230 | try await client_frame; |
| 231 | } | 231 | } |
| 232 | 232 | ||
| 233 | fn testClientToHost(allocator: *mem.Allocator, name: []const u8, port: u16) anyerror!void { | 233 | fn testClientToHost(allocator: mem.Allocator, name: []const u8, port: u16) anyerror!void { |
| 234 | if (builtin.os.tag == .wasi) return error.SkipZigTest; | 234 | if (builtin.os.tag == .wasi) return error.SkipZigTest; |
| 235 | 235 | ||
| 236 | const connection = try net.tcpConnectToHost(allocator, name, port); | 236 | const connection = try net.tcpConnectToHost(allocator, name, port); |
lib/std/os/test.zig+10-9| ... | @@ -58,10 +58,11 @@ test "open smoke test" { | ... | @@ -58,10 +58,11 @@ test "open smoke test" { |
| 58 | // Get base abs path | 58 | // Get base abs path |
| 59 | var arena = ArenaAllocator.init(testing.allocator); | 59 | var arena = ArenaAllocator.init(testing.allocator); |
| 60 | defer arena.deinit(); | 60 | defer arena.deinit(); |
| 61 | const allocator = arena.getAllocator(); | ||
| 61 | 62 | ||
| 62 | const base_path = blk: { | 63 | const base_path = blk: { |
| 63 | const relative_path = try fs.path.join(&arena.allocator, &[_][]const u8{ "zig-cache", "tmp", tmp.sub_path[0..] }); | 64 | const relative_path = try fs.path.join(allocator, &[_][]const u8{ "zig-cache", "tmp", tmp.sub_path[0..] }); |
| 64 | break :blk try fs.realpathAlloc(&arena.allocator, relative_path); | 65 | break :blk try fs.realpathAlloc(allocator, relative_path); |
| 65 | }; | 66 | }; |
| 66 | 67 | ||
| 67 | var file_path: []u8 = undefined; | 68 | var file_path: []u8 = undefined; |
| ... | @@ -69,34 +70,34 @@ test "open smoke test" { | ... | @@ -69,34 +70,34 @@ test "open smoke test" { |
| 69 | const mode: os.mode_t = if (native_os == .windows) 0 else 0o666; | 70 | const mode: os.mode_t = if (native_os == .windows) 0 else 0o666; |
| 70 | 71 | ||
| 71 | // Create some file using `open`. | 72 | // Create some file using `open`. |
| 72 | file_path = try fs.path.join(&arena.allocator, &[_][]const u8{ base_path, "some_file" }); | 73 | file_path = try fs.path.join(allocator, &[_][]const u8{ base_path, "some_file" }); |
| 73 | fd = try os.open(file_path, os.O.RDWR | os.O.CREAT | os.O.EXCL, mode); | 74 | fd = try os.open(file_path, os.O.RDWR | os.O.CREAT | os.O.EXCL, mode); |
| 74 | os.close(fd); | 75 | os.close(fd); |
| 75 | 76 | ||
| 76 | // Try this again with the same flags. This op should fail with error.PathAlreadyExists. | 77 | // Try this again with the same flags. This op should fail with error.PathAlreadyExists. |
| 77 | file_path = try fs.path.join(&arena.allocator, &[_][]const u8{ base_path, "some_file" }); | 78 | file_path = try fs.path.join(allocator, &[_][]const u8{ base_path, "some_file" }); |
| 78 | try expectError(error.PathAlreadyExists, os.open(file_path, os.O.RDWR | os.O.CREAT | os.O.EXCL, mode)); | 79 | try expectError(error.PathAlreadyExists, os.open(file_path, os.O.RDWR | os.O.CREAT | os.O.EXCL, mode)); |
| 79 | 80 | ||
| 80 | // Try opening without `O.EXCL` flag. | 81 | // Try opening without `O.EXCL` flag. |
| 81 | file_path = try fs.path.join(&arena.allocator, &[_][]const u8{ base_path, "some_file" }); | 82 | file_path = try fs.path.join(allocator, &[_][]const u8{ base_path, "some_file" }); |
| 82 | fd = try os.open(file_path, os.O.RDWR | os.O.CREAT, mode); | 83 | fd = try os.open(file_path, os.O.RDWR | os.O.CREAT, mode); |
| 83 | os.close(fd); | 84 | os.close(fd); |
| 84 | 85 | ||
| 85 | // Try opening as a directory which should fail. | 86 | // Try opening as a directory which should fail. |
| 86 | file_path = try fs.path.join(&arena.allocator, &[_][]const u8{ base_path, "some_file" }); | 87 | file_path = try fs.path.join(allocator, &[_][]const u8{ base_path, "some_file" }); |
| 87 | try expectError(error.NotDir, os.open(file_path, os.O.RDWR | os.O.DIRECTORY, mode)); | 88 | try expectError(error.NotDir, os.open(file_path, os.O.RDWR | os.O.DIRECTORY, mode)); |
| 88 | 89 | ||
| 89 | // Create some directory | 90 | // Create some directory |
| 90 | file_path = try fs.path.join(&arena.allocator, &[_][]const u8{ base_path, "some_dir" }); | 91 | file_path = try fs.path.join(allocator, &[_][]const u8{ base_path, "some_dir" }); |
| 91 | try os.mkdir(file_path, mode); | 92 | try os.mkdir(file_path, mode); |
| 92 | 93 | ||
| 93 | // Open dir using `open` | 94 | // Open dir using `open` |
| 94 | file_path = try fs.path.join(&arena.allocator, &[_][]const u8{ base_path, "some_dir" }); | 95 | file_path = try fs.path.join(allocator, &[_][]const u8{ base_path, "some_dir" }); |
| 95 | fd = try os.open(file_path, os.O.RDONLY | os.O.DIRECTORY, mode); | 96 | fd = try os.open(file_path, os.O.RDONLY | os.O.DIRECTORY, mode); |
| 96 | os.close(fd); | 97 | os.close(fd); |
| 97 | 98 | ||
| 98 | // Try opening as file which should fail. | 99 | // Try opening as file which should fail. |
| 99 | file_path = try fs.path.join(&arena.allocator, &[_][]const u8{ base_path, "some_dir" }); | 100 | file_path = try fs.path.join(allocator, &[_][]const u8{ base_path, "some_dir" }); |
| 100 | try expectError(error.IsDir, os.open(file_path, os.O.RDWR, mode)); | 101 | try expectError(error.IsDir, os.open(file_path, os.O.RDWR, mode)); |
| 101 | } | 102 | } |
| 102 | 103 |
lib/std/pdb.zig+4-4| ... | @@ -460,7 +460,7 @@ pub const PDBStringTableHeader = packed struct { | ... | @@ -460,7 +460,7 @@ pub const PDBStringTableHeader = packed struct { |
| 460 | ByteSize: u32, | 460 | ByteSize: u32, |
| 461 | }; | 461 | }; |
| 462 | 462 | ||
| 463 | fn readSparseBitVector(stream: anytype, allocator: *mem.Allocator) ![]u32 { | 463 | fn readSparseBitVector(stream: anytype, allocator: mem.Allocator) ![]u32 { |
| 464 | const num_words = try stream.readIntLittle(u32); | 464 | const num_words = try stream.readIntLittle(u32); |
| 465 | var list = ArrayList(u32).init(allocator); | 465 | var list = ArrayList(u32).init(allocator); |
| 466 | errdefer list.deinit(); | 466 | errdefer list.deinit(); |
| ... | @@ -481,7 +481,7 @@ fn readSparseBitVector(stream: anytype, allocator: *mem.Allocator) ![]u32 { | ... | @@ -481,7 +481,7 @@ fn readSparseBitVector(stream: anytype, allocator: *mem.Allocator) ![]u32 { |
| 481 | pub const Pdb = struct { | 481 | pub const Pdb = struct { |
| 482 | in_file: File, | 482 | in_file: File, |
| 483 | msf: Msf, | 483 | msf: Msf, |
| 484 | allocator: *mem.Allocator, | 484 | allocator: mem.Allocator, |
| 485 | string_table: ?*MsfStream, | 485 | string_table: ?*MsfStream, |
| 486 | dbi: ?*MsfStream, | 486 | dbi: ?*MsfStream, |
| 487 | modules: []Module, | 487 | modules: []Module, |
| ... | @@ -500,7 +500,7 @@ pub const Pdb = struct { | ... | @@ -500,7 +500,7 @@ pub const Pdb = struct { |
| 500 | checksum_offset: ?usize, | 500 | checksum_offset: ?usize, |
| 501 | }; | 501 | }; |
| 502 | 502 | ||
| 503 | pub fn init(allocator: *mem.Allocator, path: []const u8) !Pdb { | 503 | pub fn init(allocator: mem.Allocator, path: []const u8) !Pdb { |
| 504 | const file = try fs.cwd().openFile(path, .{ .intended_io_mode = .blocking }); | 504 | const file = try fs.cwd().openFile(path, .{ .intended_io_mode = .blocking }); |
| 505 | errdefer file.close(); | 505 | errdefer file.close(); |
| 506 | 506 | ||
| ... | @@ -858,7 +858,7 @@ const Msf = struct { | ... | @@ -858,7 +858,7 @@ const Msf = struct { |
| 858 | directory: MsfStream, | 858 | directory: MsfStream, |
| 859 | streams: []MsfStream, | 859 | streams: []MsfStream, |
| 860 | 860 | ||
| 861 | fn init(allocator: *mem.Allocator, file: File) !Msf { | 861 | fn init(allocator: mem.Allocator, file: File) !Msf { |
| 862 | const in = file.reader(); | 862 | const in = file.reader(); |
| 863 | 863 | ||
| 864 | const superblock = try in.readStruct(SuperBlock); | 864 | const superblock = try in.readStruct(SuperBlock); |
lib/std/priority_dequeue.zig+4-4| ... | @@ -21,10 +21,10 @@ pub fn PriorityDequeue(comptime T: type, comptime compareFn: fn (T, T) Order) ty | ... | @@ -21,10 +21,10 @@ pub fn PriorityDequeue(comptime T: type, comptime compareFn: fn (T, T) Order) ty |
| 21 | 21 | ||
| 22 | items: []T, | 22 | items: []T, |
| 23 | len: usize, | 23 | len: usize, |
| 24 | allocator: *Allocator, | 24 | allocator: Allocator, |
| 25 | 25 | ||
| 26 | /// Initialize and return a new priority dequeue. | 26 | /// Initialize and return a new priority dequeue. |
| 27 | pub fn init(allocator: *Allocator) Self { | 27 | pub fn init(allocator: Allocator) Self { |
| 28 | return Self{ | 28 | return Self{ |
| 29 | .items = &[_]T{}, | 29 | .items = &[_]T{}, |
| 30 | .len = 0, | 30 | .len = 0, |
| ... | @@ -336,7 +336,7 @@ pub fn PriorityDequeue(comptime T: type, comptime compareFn: fn (T, T) Order) ty | ... | @@ -336,7 +336,7 @@ pub fn PriorityDequeue(comptime T: type, comptime compareFn: fn (T, T) Order) ty |
| 336 | /// Dequeue takes ownership of the passed in slice. The slice must have been | 336 | /// Dequeue takes ownership of the passed in slice. The slice must have been |
| 337 | /// allocated with `allocator`. | 337 | /// allocated with `allocator`. |
| 338 | /// De-initialize with `deinit`. | 338 | /// De-initialize with `deinit`. |
| 339 | pub fn fromOwnedSlice(allocator: *Allocator, items: []T) Self { | 339 | pub fn fromOwnedSlice(allocator: Allocator, items: []T) Self { |
| 340 | var queue = Self{ | 340 | var queue = Self{ |
| 341 | .items = items, | 341 | .items = items, |
| 342 | .len = items.len, | 342 | .len = items.len, |
| ... | @@ -945,7 +945,7 @@ fn fuzzTestMinMax(rng: std.rand.Random, queue_size: usize) !void { | ... | @@ -945,7 +945,7 @@ fn fuzzTestMinMax(rng: std.rand.Random, queue_size: usize) !void { |
| 945 | } | 945 | } |
| 946 | } | 946 | } |
| 947 | 947 | ||
| 948 | fn generateRandomSlice(allocator: *std.mem.Allocator, rng: std.rand.Random, size: usize) ![]u32 { | 948 | fn generateRandomSlice(allocator: std.mem.Allocator, rng: std.rand.Random, size: usize) ![]u32 { |
| 949 | var array = std.ArrayList(u32).init(allocator); | 949 | var array = std.ArrayList(u32).init(allocator); |
| 950 | try array.ensureTotalCapacity(size); | 950 | try array.ensureTotalCapacity(size); |
| 951 | 951 |
lib/std/priority_queue.zig+3-3| ... | @@ -20,10 +20,10 @@ pub fn PriorityQueue(comptime T: type, comptime compareFn: fn (a: T, b: T) Order | ... | @@ -20,10 +20,10 @@ pub fn PriorityQueue(comptime T: type, comptime compareFn: fn (a: T, b: T) Order |
| 20 | 20 | ||
| 21 | items: []T, | 21 | items: []T, |
| 22 | len: usize, | 22 | len: usize, |
| 23 | allocator: *Allocator, | 23 | allocator: Allocator, |
| 24 | 24 | ||
| 25 | /// Initialize and return a priority queue. | 25 | /// Initialize and return a priority queue. |
| 26 | pub fn init(allocator: *Allocator) Self { | 26 | pub fn init(allocator: Allocator) Self { |
| 27 | return Self{ | 27 | return Self{ |
| 28 | .items = &[_]T{}, | 28 | .items = &[_]T{}, |
| 29 | .len = 0, | 29 | .len = 0, |
| ... | @@ -153,7 +153,7 @@ pub fn PriorityQueue(comptime T: type, comptime compareFn: fn (a: T, b: T) Order | ... | @@ -153,7 +153,7 @@ pub fn PriorityQueue(comptime T: type, comptime compareFn: fn (a: T, b: T) Order |
| 153 | /// PriorityQueue takes ownership of the passed in slice. The slice must have been | 153 | /// PriorityQueue takes ownership of the passed in slice. The slice must have been |
| 154 | /// allocated with `allocator`. | 154 | /// allocated with `allocator`. |
| 155 | /// Deinitialize with `deinit`. | 155 | /// Deinitialize with `deinit`. |
| 156 | pub fn fromOwnedSlice(allocator: *Allocator, items: []T) Self { | 156 | pub fn fromOwnedSlice(allocator: Allocator, items: []T) Self { |
| 157 | var queue = Self{ | 157 | var queue = Self{ |
| 158 | .items = items, | 158 | .items = items, |
| 159 | .len = items.len, | 159 | .len = items.len, |
lib/std/process.zig+20-20| ... | @@ -21,7 +21,7 @@ pub fn getCwd(out_buffer: []u8) ![]u8 { | ... | @@ -21,7 +21,7 @@ pub fn getCwd(out_buffer: []u8) ![]u8 { |
| 21 | } | 21 | } |
| 22 | 22 | ||
| 23 | /// Caller must free the returned memory. | 23 | /// Caller must free the returned memory. |
| 24 | pub fn getCwdAlloc(allocator: *Allocator) ![]u8 { | 24 | pub fn getCwdAlloc(allocator: Allocator) ![]u8 { |
| 25 | // The use of MAX_PATH_BYTES here is just a heuristic: most paths will fit | 25 | // The use of MAX_PATH_BYTES here is just a heuristic: most paths will fit |
| 26 | // in stack_buf, avoiding an extra allocation in the common case. | 26 | // in stack_buf, avoiding an extra allocation in the common case. |
| 27 | var stack_buf: [fs.MAX_PATH_BYTES]u8 = undefined; | 27 | var stack_buf: [fs.MAX_PATH_BYTES]u8 = undefined; |
| ... | @@ -54,7 +54,7 @@ test "getCwdAlloc" { | ... | @@ -54,7 +54,7 @@ test "getCwdAlloc" { |
| 54 | } | 54 | } |
| 55 | 55 | ||
| 56 | /// Caller owns resulting `BufMap`. | 56 | /// Caller owns resulting `BufMap`. |
| 57 | pub fn getEnvMap(allocator: *Allocator) !BufMap { | 57 | pub fn getEnvMap(allocator: Allocator) !BufMap { |
| 58 | var result = BufMap.init(allocator); | 58 | var result = BufMap.init(allocator); |
| 59 | errdefer result.deinit(); | 59 | errdefer result.deinit(); |
| 60 | 60 | ||
| ... | @@ -154,7 +154,7 @@ pub const GetEnvVarOwnedError = error{ | ... | @@ -154,7 +154,7 @@ pub const GetEnvVarOwnedError = error{ |
| 154 | }; | 154 | }; |
| 155 | 155 | ||
| 156 | /// Caller must free returned memory. | 156 | /// Caller must free returned memory. |
| 157 | pub fn getEnvVarOwned(allocator: *mem.Allocator, key: []const u8) GetEnvVarOwnedError![]u8 { | 157 | pub fn getEnvVarOwned(allocator: mem.Allocator, key: []const u8) GetEnvVarOwnedError![]u8 { |
| 158 | if (builtin.os.tag == .windows) { | 158 | if (builtin.os.tag == .windows) { |
| 159 | const result_w = blk: { | 159 | const result_w = blk: { |
| 160 | const key_w = try std.unicode.utf8ToUtf16LeWithNull(allocator, key); | 160 | const key_w = try std.unicode.utf8ToUtf16LeWithNull(allocator, key); |
| ... | @@ -183,10 +183,10 @@ pub fn hasEnvVarConstant(comptime key: []const u8) bool { | ... | @@ -183,10 +183,10 @@ pub fn hasEnvVarConstant(comptime key: []const u8) bool { |
| 183 | } | 183 | } |
| 184 | } | 184 | } |
| 185 | 185 | ||
| 186 | pub fn hasEnvVar(allocator: *Allocator, key: []const u8) error{OutOfMemory}!bool { | 186 | pub fn hasEnvVar(allocator: Allocator, key: []const u8) error{OutOfMemory}!bool { |
| 187 | if (builtin.os.tag == .windows) { | 187 | if (builtin.os.tag == .windows) { |
| 188 | var stack_alloc = std.heap.stackFallback(256 * @sizeOf(u16), allocator); | 188 | var stack_alloc = std.heap.stackFallback(256 * @sizeOf(u16), allocator); |
| 189 | const key_w = try std.unicode.utf8ToUtf16LeWithNull(&stack_alloc.allocator, key); | 189 | const key_w = try std.unicode.utf8ToUtf16LeWithNull(stack_alloc.get(), key); |
| 190 | defer stack_alloc.allocator.free(key_w); | 190 | defer stack_alloc.allocator.free(key_w); |
| 191 | return std.os.getenvW(key_w) != null; | 191 | return std.os.getenvW(key_w) != null; |
| 192 | } else { | 192 | } else { |
| ... | @@ -227,7 +227,7 @@ pub const ArgIteratorPosix = struct { | ... | @@ -227,7 +227,7 @@ pub const ArgIteratorPosix = struct { |
| 227 | }; | 227 | }; |
| 228 | 228 | ||
| 229 | pub const ArgIteratorWasi = struct { | 229 | pub const ArgIteratorWasi = struct { |
| 230 | allocator: *mem.Allocator, | 230 | allocator: mem.Allocator, |
| 231 | index: usize, | 231 | index: usize, |
| 232 | args: [][:0]u8, | 232 | args: [][:0]u8, |
| 233 | 233 | ||
| ... | @@ -235,7 +235,7 @@ pub const ArgIteratorWasi = struct { | ... | @@ -235,7 +235,7 @@ pub const ArgIteratorWasi = struct { |
| 235 | 235 | ||
| 236 | /// You must call deinit to free the internal buffer of the | 236 | /// You must call deinit to free the internal buffer of the |
| 237 | /// iterator after you are done. | 237 | /// iterator after you are done. |
| 238 | pub fn init(allocator: *mem.Allocator) InitError!ArgIteratorWasi { | 238 | pub fn init(allocator: mem.Allocator) InitError!ArgIteratorWasi { |
| 239 | const fetched_args = try ArgIteratorWasi.internalInit(allocator); | 239 | const fetched_args = try ArgIteratorWasi.internalInit(allocator); |
| 240 | return ArgIteratorWasi{ | 240 | return ArgIteratorWasi{ |
| 241 | .allocator = allocator, | 241 | .allocator = allocator, |
| ... | @@ -244,7 +244,7 @@ pub const ArgIteratorWasi = struct { | ... | @@ -244,7 +244,7 @@ pub const ArgIteratorWasi = struct { |
| 244 | }; | 244 | }; |
| 245 | } | 245 | } |
| 246 | 246 | ||
| 247 | fn internalInit(allocator: *mem.Allocator) InitError![][:0]u8 { | 247 | fn internalInit(allocator: mem.Allocator) InitError![][:0]u8 { |
| 248 | const w = os.wasi; | 248 | const w = os.wasi; |
| 249 | var count: usize = undefined; | 249 | var count: usize = undefined; |
| 250 | var buf_size: usize = undefined; | 250 | var buf_size: usize = undefined; |
| ... | @@ -325,7 +325,7 @@ pub const ArgIteratorWindows = struct { | ... | @@ -325,7 +325,7 @@ pub const ArgIteratorWindows = struct { |
| 325 | } | 325 | } |
| 326 | 326 | ||
| 327 | /// You must free the returned memory when done. | 327 | /// You must free the returned memory when done. |
| 328 | pub fn next(self: *ArgIteratorWindows, allocator: *Allocator) ?(NextError![:0]u8) { | 328 | pub fn next(self: *ArgIteratorWindows, allocator: Allocator) ?(NextError![:0]u8) { |
| 329 | // march forward over whitespace | 329 | // march forward over whitespace |
| 330 | while (true) : (self.index += 1) { | 330 | while (true) : (self.index += 1) { |
| 331 | const character = self.getPointAtIndex(); | 331 | const character = self.getPointAtIndex(); |
| ... | @@ -379,7 +379,7 @@ pub const ArgIteratorWindows = struct { | ... | @@ -379,7 +379,7 @@ pub const ArgIteratorWindows = struct { |
| 379 | } | 379 | } |
| 380 | } | 380 | } |
| 381 | 381 | ||
| 382 | fn internalNext(self: *ArgIteratorWindows, allocator: *Allocator) NextError![:0]u8 { | 382 | fn internalNext(self: *ArgIteratorWindows, allocator: Allocator) NextError![:0]u8 { |
| 383 | var buf = std.ArrayList(u16).init(allocator); | 383 | var buf = std.ArrayList(u16).init(allocator); |
| 384 | defer buf.deinit(); | 384 | defer buf.deinit(); |
| 385 | 385 | ||
| ... | @@ -423,7 +423,7 @@ pub const ArgIteratorWindows = struct { | ... | @@ -423,7 +423,7 @@ pub const ArgIteratorWindows = struct { |
| 423 | } | 423 | } |
| 424 | } | 424 | } |
| 425 | 425 | ||
| 426 | fn convertFromWindowsCmdLineToUTF8(allocator: *Allocator, buf: []u16) NextError![:0]u8 { | 426 | fn convertFromWindowsCmdLineToUTF8(allocator: Allocator, buf: []u16) NextError![:0]u8 { |
| 427 | return std.unicode.utf16leToUtf8AllocZ(allocator, buf) catch |err| switch (err) { | 427 | return std.unicode.utf16leToUtf8AllocZ(allocator, buf) catch |err| switch (err) { |
| 428 | error.ExpectedSecondSurrogateHalf, | 428 | error.ExpectedSecondSurrogateHalf, |
| 429 | error.DanglingSurrogateHalf, | 429 | error.DanglingSurrogateHalf, |
| ... | @@ -463,7 +463,7 @@ pub const ArgIterator = struct { | ... | @@ -463,7 +463,7 @@ pub const ArgIterator = struct { |
| 463 | pub const InitError = ArgIteratorWasi.InitError; | 463 | pub const InitError = ArgIteratorWasi.InitError; |
| 464 | 464 | ||
| 465 | /// You must deinitialize iterator's internal buffers by calling `deinit` when done. | 465 | /// You must deinitialize iterator's internal buffers by calling `deinit` when done. |
| 466 | pub fn initWithAllocator(allocator: *mem.Allocator) InitError!ArgIterator { | 466 | pub fn initWithAllocator(allocator: mem.Allocator) InitError!ArgIterator { |
| 467 | if (builtin.os.tag == .wasi and !builtin.link_libc) { | 467 | if (builtin.os.tag == .wasi and !builtin.link_libc) { |
| 468 | return ArgIterator{ .inner = try InnerType.init(allocator) }; | 468 | return ArgIterator{ .inner = try InnerType.init(allocator) }; |
| 469 | } | 469 | } |
| ... | @@ -474,7 +474,7 @@ pub const ArgIterator = struct { | ... | @@ -474,7 +474,7 @@ pub const ArgIterator = struct { |
| 474 | pub const NextError = ArgIteratorWindows.NextError; | 474 | pub const NextError = ArgIteratorWindows.NextError; |
| 475 | 475 | ||
| 476 | /// You must free the returned memory when done. | 476 | /// You must free the returned memory when done. |
| 477 | pub fn next(self: *ArgIterator, allocator: *Allocator) ?(NextError![:0]u8) { | 477 | pub fn next(self: *ArgIterator, allocator: Allocator) ?(NextError![:0]u8) { |
| 478 | if (builtin.os.tag == .windows) { | 478 | if (builtin.os.tag == .windows) { |
| 479 | return self.inner.next(allocator); | 479 | return self.inner.next(allocator); |
| 480 | } else { | 480 | } else { |
| ... | @@ -513,7 +513,7 @@ pub fn args() ArgIterator { | ... | @@ -513,7 +513,7 @@ pub fn args() ArgIterator { |
| 513 | } | 513 | } |
| 514 | 514 | ||
| 515 | /// You must deinitialize iterator's internal buffers by calling `deinit` when done. | 515 | /// You must deinitialize iterator's internal buffers by calling `deinit` when done. |
| 516 | pub fn argsWithAllocator(allocator: *mem.Allocator) ArgIterator.InitError!ArgIterator { | 516 | pub fn argsWithAllocator(allocator: mem.Allocator) ArgIterator.InitError!ArgIterator { |
| 517 | return ArgIterator.initWithAllocator(allocator); | 517 | return ArgIterator.initWithAllocator(allocator); |
| 518 | } | 518 | } |
| 519 | 519 | ||
| ... | @@ -539,7 +539,7 @@ test "args iterator" { | ... | @@ -539,7 +539,7 @@ test "args iterator" { |
| 539 | } | 539 | } |
| 540 | 540 | ||
| 541 | /// Caller must call argsFree on result. | 541 | /// Caller must call argsFree on result. |
| 542 | pub fn argsAlloc(allocator: *mem.Allocator) ![][:0]u8 { | 542 | pub fn argsAlloc(allocator: mem.Allocator) ![][:0]u8 { |
| 543 | // TODO refactor to only make 1 allocation. | 543 | // TODO refactor to only make 1 allocation. |
| 544 | var it = if (builtin.os.tag == .wasi) try argsWithAllocator(allocator) else args(); | 544 | var it = if (builtin.os.tag == .wasi) try argsWithAllocator(allocator) else args(); |
| 545 | defer it.deinit(); | 545 | defer it.deinit(); |
| ... | @@ -579,7 +579,7 @@ pub fn argsAlloc(allocator: *mem.Allocator) ![][:0]u8 { | ... | @@ -579,7 +579,7 @@ pub fn argsAlloc(allocator: *mem.Allocator) ![][:0]u8 { |
| 579 | return result_slice_list; | 579 | return result_slice_list; |
| 580 | } | 580 | } |
| 581 | 581 | ||
| 582 | pub fn argsFree(allocator: *mem.Allocator, args_alloc: []const [:0]u8) void { | 582 | pub fn argsFree(allocator: mem.Allocator, args_alloc: []const [:0]u8) void { |
| 583 | var total_bytes: usize = 0; | 583 | var total_bytes: usize = 0; |
| 584 | for (args_alloc) |arg| { | 584 | for (args_alloc) |arg| { |
| 585 | total_bytes += @sizeOf([]u8) + arg.len + 1; | 585 | total_bytes += @sizeOf([]u8) + arg.len + 1; |
| ... | @@ -741,7 +741,7 @@ pub fn getBaseAddress() usize { | ... | @@ -741,7 +741,7 @@ pub fn getBaseAddress() usize { |
| 741 | /// requirement from `std.zig.system.NativeTargetInfo.detect`. Most likely this will require | 741 | /// requirement from `std.zig.system.NativeTargetInfo.detect`. Most likely this will require |
| 742 | /// introducing a new, lower-level function which takes a callback function, and then this | 742 | /// introducing a new, lower-level function which takes a callback function, and then this |
| 743 | /// function which takes an allocator can exist on top of it. | 743 | /// function which takes an allocator can exist on top of it. |
| 744 | pub fn getSelfExeSharedLibPaths(allocator: *Allocator) error{OutOfMemory}![][:0]u8 { | 744 | pub fn getSelfExeSharedLibPaths(allocator: Allocator) error{OutOfMemory}![][:0]u8 { |
| 745 | switch (builtin.link_mode) { | 745 | switch (builtin.link_mode) { |
| 746 | .Static => return &[_][:0]u8{}, | 746 | .Static => return &[_][:0]u8{}, |
| 747 | .Dynamic => {}, | 747 | .Dynamic => {}, |
| ... | @@ -833,7 +833,7 @@ pub const ExecvError = std.os.ExecveError || error{OutOfMemory}; | ... | @@ -833,7 +833,7 @@ pub const ExecvError = std.os.ExecveError || error{OutOfMemory}; |
| 833 | /// This function also uses the PATH environment variable to get the full path to the executable. | 833 | /// This function also uses the PATH environment variable to get the full path to the executable. |
| 834 | /// Due to the heap-allocation, it is illegal to call this function in a fork() child. | 834 | /// Due to the heap-allocation, it is illegal to call this function in a fork() child. |
| 835 | /// For that use case, use the `std.os` functions directly. | 835 | /// For that use case, use the `std.os` functions directly. |
| 836 | pub fn execv(allocator: *mem.Allocator, argv: []const []const u8) ExecvError { | 836 | pub fn execv(allocator: mem.Allocator, argv: []const []const u8) ExecvError { |
| 837 | return execve(allocator, argv, null); | 837 | return execve(allocator, argv, null); |
| 838 | } | 838 | } |
| 839 | 839 | ||
| ... | @@ -846,7 +846,7 @@ pub fn execv(allocator: *mem.Allocator, argv: []const []const u8) ExecvError { | ... | @@ -846,7 +846,7 @@ pub fn execv(allocator: *mem.Allocator, argv: []const []const u8) ExecvError { |
| 846 | /// Due to the heap-allocation, it is illegal to call this function in a fork() child. | 846 | /// Due to the heap-allocation, it is illegal to call this function in a fork() child. |
| 847 | /// For that use case, use the `std.os` functions directly. | 847 | /// For that use case, use the `std.os` functions directly. |
| 848 | pub fn execve( | 848 | pub fn execve( |
| 849 | allocator: *mem.Allocator, | 849 | allocator: mem.Allocator, |
| 850 | argv: []const []const u8, | 850 | argv: []const []const u8, |
| 851 | env_map: ?*const std.BufMap, | 851 | env_map: ?*const std.BufMap, |
| 852 | ) ExecvError { | 852 | ) ExecvError { |
| ... | @@ -854,7 +854,7 @@ pub fn execve( | ... | @@ -854,7 +854,7 @@ pub fn execve( |
| 854 | 854 | ||
| 855 | var arena_allocator = std.heap.ArenaAllocator.init(allocator); | 855 | var arena_allocator = std.heap.ArenaAllocator.init(allocator); |
| 856 | defer arena_allocator.deinit(); | 856 | defer arena_allocator.deinit(); |
| 857 | const arena = &arena_allocator.allocator; | 857 | const arena = arena_allocator.getAllocator(); |
| 858 | 858 | ||
| 859 | const argv_buf = try arena.allocSentinel(?[*:0]u8, argv.len, null); | 859 | const argv_buf = try arena.allocSentinel(?[*:0]u8, argv.len, null); |
| 860 | for (argv) |arg, i| argv_buf[i] = (try arena.dupeZ(u8, arg)).ptr; | 860 | for (argv) |arg, i| argv_buf[i] = (try arena.dupeZ(u8, arg)).ptr; |
lib/std/special/build_runner.zig+1-1| ... | @@ -16,7 +16,7 @@ pub fn main() !void { | ... | @@ -16,7 +16,7 @@ pub fn main() !void { |
| 16 | var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator); | 16 | var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator); |
| 17 | defer arena.deinit(); | 17 | defer arena.deinit(); |
| 18 | 18 | ||
| 19 | const allocator = &arena.allocator; | 19 | const allocator = arena.getAllocator(); |
| 20 | var args = try process.argsAlloc(allocator); | 20 | var args = try process.argsAlloc(allocator); |
| 21 | defer process.argsFree(allocator, args); | 21 | defer process.argsFree(allocator, args); |
| 22 | 22 |
lib/std/special/test_runner.zig+1-1| ... | @@ -10,7 +10,7 @@ var args_buffer: [std.fs.MAX_PATH_BYTES + std.mem.page_size]u8 = undefined; | ... | @@ -10,7 +10,7 @@ var args_buffer: [std.fs.MAX_PATH_BYTES + std.mem.page_size]u8 = undefined; |
| 10 | var args_allocator = std.heap.FixedBufferAllocator.init(&args_buffer); | 10 | var args_allocator = std.heap.FixedBufferAllocator.init(&args_buffer); |
| 11 | 11 | ||
| 12 | fn processArgs() void { | 12 | fn processArgs() void { |
| 13 | const args = std.process.argsAlloc(&args_allocator.allocator) catch { | 13 | const args = std.process.argsAlloc(args_allocator.getAllocator()) catch { |
| 14 | @panic("Too many bytes passed over the CLI to the test runner"); | 14 | @panic("Too many bytes passed over the CLI to the test runner"); |
| 15 | }; | 15 | }; |
| 16 | if (args.len != 2) { | 16 | if (args.len != 2) { |
lib/std/target.zig+3-3| ... | @@ -1323,15 +1323,15 @@ pub const Target = struct { | ... | @@ -1323,15 +1323,15 @@ pub const Target = struct { |
| 1323 | 1323 | ||
| 1324 | pub const stack_align = 16; | 1324 | pub const stack_align = 16; |
| 1325 | 1325 | ||
| 1326 | pub fn zigTriple(self: Target, allocator: *mem.Allocator) ![]u8 { | 1326 | pub fn zigTriple(self: Target, allocator: mem.Allocator) ![]u8 { |
| 1327 | return std.zig.CrossTarget.fromTarget(self).zigTriple(allocator); | 1327 | return std.zig.CrossTarget.fromTarget(self).zigTriple(allocator); |
| 1328 | } | 1328 | } |
| 1329 | 1329 | ||
| 1330 | pub fn linuxTripleSimple(allocator: *mem.Allocator, cpu_arch: Cpu.Arch, os_tag: Os.Tag, abi: Abi) ![]u8 { | 1330 | pub fn linuxTripleSimple(allocator: mem.Allocator, cpu_arch: Cpu.Arch, os_tag: Os.Tag, abi: Abi) ![]u8 { |
| 1331 | return std.fmt.allocPrint(allocator, "{s}-{s}-{s}", .{ @tagName(cpu_arch), @tagName(os_tag), @tagName(abi) }); | 1331 | return std.fmt.allocPrint(allocator, "{s}-{s}-{s}", .{ @tagName(cpu_arch), @tagName(os_tag), @tagName(abi) }); |
| 1332 | } | 1332 | } |
| 1333 | 1333 | ||
| 1334 | pub fn linuxTriple(self: Target, allocator: *mem.Allocator) ![]u8 { | 1334 | pub fn linuxTriple(self: Target, allocator: mem.Allocator) ![]u8 { |
| 1335 | return linuxTripleSimple(allocator, self.cpu.arch, self.os.tag, self.abi); | 1335 | return linuxTripleSimple(allocator, self.cpu.arch, self.os.tag, self.abi); |
| 1336 | } | 1336 | } |
| 1337 | 1337 |
lib/std/testing.zig+3-3| ... | @@ -7,11 +7,11 @@ const print = std.debug.print; | ... | @@ -7,11 +7,11 @@ const print = std.debug.print; |
| 7 | pub const FailingAllocator = @import("testing/failing_allocator.zig").FailingAllocator; | 7 | pub const FailingAllocator = @import("testing/failing_allocator.zig").FailingAllocator; |
| 8 | 8 | ||
| 9 | /// This should only be used in temporary test programs. | 9 | /// This should only be used in temporary test programs. |
| 10 | pub const allocator = &allocator_instance.allocator; | 10 | pub const allocator = allocator_instance.getAllocator(); |
| 11 | pub var allocator_instance = std.heap.GeneralPurposeAllocator(.{}){}; | 11 | pub var allocator_instance = std.heap.GeneralPurposeAllocator(.{}){}; |
| 12 | 12 | ||
| 13 | pub const failing_allocator = &failing_allocator_instance.allocator; | 13 | pub const failing_allocator = failing_allocator_instance.getAllocator(); |
| 14 | pub var failing_allocator_instance = FailingAllocator.init(&base_allocator_instance.allocator, 0); | 14 | pub var failing_allocator_instance = FailingAllocator.init(base_allocator_instance.getAllocator(), 0); |
| 15 | 15 | ||
| 16 | pub var base_allocator_instance = std.heap.FixedBufferAllocator.init(""); | 16 | pub var base_allocator_instance = std.heap.FixedBufferAllocator.init(""); |
| 17 | 17 |
lib/std/testing/failing_allocator.zig+10-13| ... | @@ -12,10 +12,9 @@ const mem = std.mem; | ... | @@ -12,10 +12,9 @@ const mem = std.mem; |
| 12 | /// Then use `failing_allocator` anywhere you would have used a | 12 | /// Then use `failing_allocator` anywhere you would have used a |
| 13 | /// different allocator. | 13 | /// different allocator. |
| 14 | pub const FailingAllocator = struct { | 14 | pub const FailingAllocator = struct { |
| 15 | allocator: mem.Allocator, | ||
| 16 | index: usize, | 15 | index: usize, |
| 17 | fail_index: usize, | 16 | fail_index: usize, |
| 18 | internal_allocator: *mem.Allocator, | 17 | internal_allocator: mem.Allocator, |
| 19 | allocated_bytes: usize, | 18 | allocated_bytes: usize, |
| 20 | freed_bytes: usize, | 19 | freed_bytes: usize, |
| 21 | allocations: usize, | 20 | allocations: usize, |
| ... | @@ -29,7 +28,7 @@ pub const FailingAllocator = struct { | ... | @@ -29,7 +28,7 @@ pub const FailingAllocator = struct { |
| 29 | /// var a = try failing_alloc.create(i32); | 28 | /// var a = try failing_alloc.create(i32); |
| 30 | /// var b = try failing_alloc.create(i32); | 29 | /// var b = try failing_alloc.create(i32); |
| 31 | /// testing.expectError(error.OutOfMemory, failing_alloc.create(i32)); | 30 | /// testing.expectError(error.OutOfMemory, failing_alloc.create(i32)); |
| 32 | pub fn init(allocator: *mem.Allocator, fail_index: usize) FailingAllocator { | 31 | pub fn init(allocator: mem.Allocator, fail_index: usize) FailingAllocator { |
| 33 | return FailingAllocator{ | 32 | return FailingAllocator{ |
| 34 | .internal_allocator = allocator, | 33 | .internal_allocator = allocator, |
| 35 | .fail_index = fail_index, | 34 | .fail_index = fail_index, |
| ... | @@ -38,25 +37,24 @@ pub const FailingAllocator = struct { | ... | @@ -38,25 +37,24 @@ pub const FailingAllocator = struct { |
| 38 | .freed_bytes = 0, | 37 | .freed_bytes = 0, |
| 39 | .allocations = 0, | 38 | .allocations = 0, |
| 40 | .deallocations = 0, | 39 | .deallocations = 0, |
| 41 | .allocator = mem.Allocator{ | ||
| 42 | .allocFn = alloc, | ||
| 43 | .resizeFn = resize, | ||
| 44 | }, | ||
| 45 | }; | 40 | }; |
| 46 | } | 41 | } |
| 47 | 42 | ||
| 43 | pub fn getAllocator(self: *FailingAllocator) mem.Allocator { | ||
| 44 | return mem.Allocator.init(self, alloc, resize); | ||
| 45 | } | ||
| 46 | |||
| 48 | fn alloc( | 47 | fn alloc( |
| 49 | allocator: *std.mem.Allocator, | 48 | self: *FailingAllocator, |
| 50 | len: usize, | 49 | len: usize, |
| 51 | ptr_align: u29, | 50 | ptr_align: u29, |
| 52 | len_align: u29, | 51 | len_align: u29, |
| 53 | return_address: usize, | 52 | return_address: usize, |
| 54 | ) error{OutOfMemory}![]u8 { | 53 | ) error{OutOfMemory}![]u8 { |
| 55 | const self = @fieldParentPtr(FailingAllocator, "allocator", allocator); | ||
| 56 | if (self.index == self.fail_index) { | 54 | if (self.index == self.fail_index) { |
| 57 | return error.OutOfMemory; | 55 | return error.OutOfMemory; |
| 58 | } | 56 | } |
| 59 | const result = try self.internal_allocator.allocFn(self.internal_allocator, len, ptr_align, len_align, return_address); | 57 | const result = try self.internal_allocator.allocFn(self.internal_allocator.ptr, len, ptr_align, len_align, return_address); |
| 60 | self.allocated_bytes += result.len; | 58 | self.allocated_bytes += result.len; |
| 61 | self.allocations += 1; | 59 | self.allocations += 1; |
| 62 | self.index += 1; | 60 | self.index += 1; |
| ... | @@ -64,15 +62,14 @@ pub const FailingAllocator = struct { | ... | @@ -64,15 +62,14 @@ pub const FailingAllocator = struct { |
| 64 | } | 62 | } |
| 65 | 63 | ||
| 66 | fn resize( | 64 | fn resize( |
| 67 | allocator: *std.mem.Allocator, | 65 | self: *FailingAllocator, |
| 68 | old_mem: []u8, | 66 | old_mem: []u8, |
| 69 | old_align: u29, | 67 | old_align: u29, |
| 70 | new_len: usize, | 68 | new_len: usize, |
| 71 | len_align: u29, | 69 | len_align: u29, |
| 72 | ra: usize, | 70 | ra: usize, |
| 73 | ) error{OutOfMemory}!usize { | 71 | ) error{OutOfMemory}!usize { |
| 74 | const self = @fieldParentPtr(FailingAllocator, "allocator", allocator); | 72 | const r = self.internal_allocator.resizeFn(self.internal_allocator.ptr, old_mem, old_align, new_len, len_align, ra) catch |e| { |
| 75 | const r = self.internal_allocator.resizeFn(self.internal_allocator, old_mem, old_align, new_len, len_align, ra) catch |e| { | ||
| 76 | std.debug.assert(new_len > old_mem.len); | 73 | std.debug.assert(new_len > old_mem.len); |
| 77 | return e; | 74 | return e; |
| 78 | }; | 75 | }; |
lib/std/unicode.zig+3-3| ... | @@ -550,7 +550,7 @@ fn testDecode(bytes: []const u8) !u21 { | ... | @@ -550,7 +550,7 @@ fn testDecode(bytes: []const u8) !u21 { |
| 550 | } | 550 | } |
| 551 | 551 | ||
| 552 | /// Caller must free returned memory. | 552 | /// Caller must free returned memory. |
| 553 | pub fn utf16leToUtf8Alloc(allocator: *mem.Allocator, utf16le: []const u16) ![]u8 { | 553 | pub fn utf16leToUtf8Alloc(allocator: mem.Allocator, utf16le: []const u16) ![]u8 { |
| 554 | // optimistically guess that it will all be ascii. | 554 | // optimistically guess that it will all be ascii. |
| 555 | var result = try std.ArrayList(u8).initCapacity(allocator, utf16le.len); | 555 | var result = try std.ArrayList(u8).initCapacity(allocator, utf16le.len); |
| 556 | errdefer result.deinit(); | 556 | errdefer result.deinit(); |
| ... | @@ -567,7 +567,7 @@ pub fn utf16leToUtf8Alloc(allocator: *mem.Allocator, utf16le: []const u16) ![]u8 | ... | @@ -567,7 +567,7 @@ pub fn utf16leToUtf8Alloc(allocator: *mem.Allocator, utf16le: []const u16) ![]u8 |
| 567 | } | 567 | } |
| 568 | 568 | ||
| 569 | /// Caller must free returned memory. | 569 | /// Caller must free returned memory. |
| 570 | pub fn utf16leToUtf8AllocZ(allocator: *mem.Allocator, utf16le: []const u16) ![:0]u8 { | 570 | pub fn utf16leToUtf8AllocZ(allocator: mem.Allocator, utf16le: []const u16) ![:0]u8 { |
| 571 | // optimistically guess that it will all be ascii. | 571 | // optimistically guess that it will all be ascii. |
| 572 | var result = try std.ArrayList(u8).initCapacity(allocator, utf16le.len); | 572 | var result = try std.ArrayList(u8).initCapacity(allocator, utf16le.len); |
| 573 | errdefer result.deinit(); | 573 | errdefer result.deinit(); |
| ... | @@ -661,7 +661,7 @@ test "utf16leToUtf8" { | ... | @@ -661,7 +661,7 @@ test "utf16leToUtf8" { |
| 661 | } | 661 | } |
| 662 | } | 662 | } |
| 663 | 663 | ||
| 664 | pub fn utf8ToUtf16LeWithNull(allocator: *mem.Allocator, utf8: []const u8) ![:0]u16 { | 664 | pub fn utf8ToUtf16LeWithNull(allocator: mem.Allocator, utf8: []const u8) ![:0]u16 { |
| 665 | // optimistically guess that it will not require surrogate pairs | 665 | // optimistically guess that it will not require surrogate pairs |
| 666 | var result = try std.ArrayList(u16).initCapacity(allocator, utf8.len + 1); | 666 | var result = try std.ArrayList(u16).initCapacity(allocator, utf8.len + 1); |
| 667 | errdefer result.deinit(); | 667 | errdefer result.deinit(); |
lib/std/wasm.zig+1-1| ... | @@ -361,7 +361,7 @@ pub const Type = struct { | ... | @@ -361,7 +361,7 @@ pub const Type = struct { |
| 361 | std.mem.eql(Valtype, self.returns, other.returns); | 361 | std.mem.eql(Valtype, self.returns, other.returns); |
| 362 | } | 362 | } |
| 363 | 363 | ||
| 364 | pub fn deinit(self: *Type, gpa: *std.mem.Allocator) void { | 364 | pub fn deinit(self: *Type, gpa: std.mem.Allocator) void { |
| 365 | gpa.free(self.params); | 365 | gpa.free(self.params); |
| 366 | gpa.free(self.returns); | 366 | gpa.free(self.returns); |
| 367 | self.* = undefined; | 367 | self.* = undefined; |
lib/std/zig.zig+1-1| ... | @@ -100,7 +100,7 @@ pub const BinNameOptions = struct { | ... | @@ -100,7 +100,7 @@ pub const BinNameOptions = struct { |
| 100 | }; | 100 | }; |
| 101 | 101 | ||
| 102 | /// Returns the standard file system basename of a binary generated by the Zig compiler. | 102 | /// Returns the standard file system basename of a binary generated by the Zig compiler. |
| 103 | pub fn binNameAlloc(allocator: *std.mem.Allocator, options: BinNameOptions) error{OutOfMemory}![]u8 { | 103 | pub fn binNameAlloc(allocator: std.mem.Allocator, options: BinNameOptions) error{OutOfMemory}![]u8 { |
| 104 | const root_name = options.root_name; | 104 | const root_name = options.root_name; |
| 105 | const target = options.target; | 105 | const target = options.target; |
| 106 | const ofmt = options.object_format orelse target.getObjectFormat(); | 106 | const ofmt = options.object_format orelse target.getObjectFormat(); |
lib/std/zig/Ast.zig+2-2| ... | @@ -34,7 +34,7 @@ pub const Location = struct { | ... | @@ -34,7 +34,7 @@ pub const Location = struct { |
| 34 | line_end: usize, | 34 | line_end: usize, |
| 35 | }; | 35 | }; |
| 36 | 36 | ||
| 37 | pub fn deinit(tree: *Tree, gpa: *mem.Allocator) void { | 37 | pub fn deinit(tree: *Tree, gpa: mem.Allocator) void { |
| 38 | tree.tokens.deinit(gpa); | 38 | tree.tokens.deinit(gpa); |
| 39 | tree.nodes.deinit(gpa); | 39 | tree.nodes.deinit(gpa); |
| 40 | gpa.free(tree.extra_data); | 40 | gpa.free(tree.extra_data); |
| ... | @@ -52,7 +52,7 @@ pub const RenderError = error{ | ... | @@ -52,7 +52,7 @@ pub const RenderError = error{ |
| 52 | /// for allocating extra stack memory if needed, because this function utilizes recursion. | 52 | /// for allocating extra stack memory if needed, because this function utilizes recursion. |
| 53 | /// Note: that's not actually true yet, see https://github.com/ziglang/zig/issues/1006. | 53 | /// Note: that's not actually true yet, see https://github.com/ziglang/zig/issues/1006. |
| 54 | /// Caller owns the returned slice of bytes, allocated with `gpa`. | 54 | /// Caller owns the returned slice of bytes, allocated with `gpa`. |
| 55 | pub fn render(tree: Tree, gpa: *mem.Allocator) RenderError![]u8 { | 55 | pub fn render(tree: Tree, gpa: mem.Allocator) RenderError![]u8 { |
| 56 | var buffer = std.ArrayList(u8).init(gpa); | 56 | var buffer = std.ArrayList(u8).init(gpa); |
| 57 | defer buffer.deinit(); | 57 | defer buffer.deinit(); |
| 58 | 58 |
lib/std/zig/CrossTarget.zig+4-4| ... | @@ -520,7 +520,7 @@ pub fn isNative(self: CrossTarget) bool { | ... | @@ -520,7 +520,7 @@ pub fn isNative(self: CrossTarget) bool { |
| 520 | return self.isNativeCpu() and self.isNativeOs() and self.isNativeAbi(); | 520 | return self.isNativeCpu() and self.isNativeOs() and self.isNativeAbi(); |
| 521 | } | 521 | } |
| 522 | 522 | ||
| 523 | pub fn zigTriple(self: CrossTarget, allocator: *mem.Allocator) error{OutOfMemory}![]u8 { | 523 | pub fn zigTriple(self: CrossTarget, allocator: mem.Allocator) error{OutOfMemory}![]u8 { |
| 524 | if (self.isNative()) { | 524 | if (self.isNative()) { |
| 525 | return allocator.dupe(u8, "native"); | 525 | return allocator.dupe(u8, "native"); |
| 526 | } | 526 | } |
| ... | @@ -559,13 +559,13 @@ pub fn zigTriple(self: CrossTarget, allocator: *mem.Allocator) error{OutOfMemory | ... | @@ -559,13 +559,13 @@ pub fn zigTriple(self: CrossTarget, allocator: *mem.Allocator) error{OutOfMemory |
| 559 | return result.toOwnedSlice(); | 559 | return result.toOwnedSlice(); |
| 560 | } | 560 | } |
| 561 | 561 | ||
| 562 | pub fn allocDescription(self: CrossTarget, allocator: *mem.Allocator) ![]u8 { | 562 | pub fn allocDescription(self: CrossTarget, allocator: mem.Allocator) ![]u8 { |
| 563 | // TODO is there anything else worthy of the description that is not | 563 | // TODO is there anything else worthy of the description that is not |
| 564 | // already captured in the triple? | 564 | // already captured in the triple? |
| 565 | return self.zigTriple(allocator); | 565 | return self.zigTriple(allocator); |
| 566 | } | 566 | } |
| 567 | 567 | ||
| 568 | pub fn linuxTriple(self: CrossTarget, allocator: *mem.Allocator) ![]u8 { | 568 | pub fn linuxTriple(self: CrossTarget, allocator: mem.Allocator) ![]u8 { |
| 569 | return Target.linuxTripleSimple(allocator, self.getCpuArch(), self.getOsTag(), self.getAbi()); | 569 | return Target.linuxTripleSimple(allocator, self.getCpuArch(), self.getOsTag(), self.getAbi()); |
| 570 | } | 570 | } |
| 571 | 571 | ||
| ... | @@ -576,7 +576,7 @@ pub fn wantSharedLibSymLinks(self: CrossTarget) bool { | ... | @@ -576,7 +576,7 @@ pub fn wantSharedLibSymLinks(self: CrossTarget) bool { |
| 576 | pub const VcpkgLinkage = std.builtin.LinkMode; | 576 | pub const VcpkgLinkage = std.builtin.LinkMode; |
| 577 | 577 | ||
| 578 | /// Returned slice must be freed by the caller. | 578 | /// Returned slice must be freed by the caller. |
| 579 | pub fn vcpkgTriplet(self: CrossTarget, allocator: *mem.Allocator, linkage: VcpkgLinkage) ![]u8 { | 579 | pub fn vcpkgTriplet(self: CrossTarget, allocator: mem.Allocator, linkage: VcpkgLinkage) ![]u8 { |
| 580 | const arch = switch (self.getCpuArch()) { | 580 | const arch = switch (self.getCpuArch()) { |
| 581 | .i386 => "x86", | 581 | .i386 => "x86", |
| 582 | .x86_64 => "x64", | 582 | .x86_64 => "x64", |
lib/std/zig/parse.zig+2-2| ... | @@ -11,7 +11,7 @@ pub const Error = error{ParseError} || Allocator.Error; | ... | @@ -11,7 +11,7 @@ pub const Error = error{ParseError} || Allocator.Error; |
| 11 | 11 | ||
| 12 | /// Result should be freed with tree.deinit() when there are | 12 | /// Result should be freed with tree.deinit() when there are |
| 13 | /// no more references to any of the tokens or nodes. | 13 | /// no more references to any of the tokens or nodes. |
| 14 | pub fn parse(gpa: *Allocator, source: [:0]const u8) Allocator.Error!Ast { | 14 | pub fn parse(gpa: Allocator, source: [:0]const u8) Allocator.Error!Ast { |
| 15 | var tokens = Ast.TokenList{}; | 15 | var tokens = Ast.TokenList{}; |
| 16 | defer tokens.deinit(gpa); | 16 | defer tokens.deinit(gpa); |
| 17 | 17 | ||
| ... | @@ -81,7 +81,7 @@ const null_node: Node.Index = 0; | ... | @@ -81,7 +81,7 @@ const null_node: Node.Index = 0; |
| 81 | 81 | ||
| 82 | /// Represents in-progress parsing, will be converted to an Ast after completion. | 82 | /// Represents in-progress parsing, will be converted to an Ast after completion. |
| 83 | const Parser = struct { | 83 | const Parser = struct { |
| 84 | gpa: *Allocator, | 84 | gpa: Allocator, |
| 85 | source: []const u8, | 85 | source: []const u8, |
| 86 | token_tags: []const Token.Tag, | 86 | token_tags: []const Token.Tag, |
| 87 | token_starts: []const Ast.ByteOffset, | 87 | token_starts: []const Ast.ByteOffset, |
lib/std/zig/parser_test.zig+9-8| ... | @@ -1220,7 +1220,7 @@ test "zig fmt: doc comments on param decl" { | ... | @@ -1220,7 +1220,7 @@ test "zig fmt: doc comments on param decl" { |
| 1220 | try testCanonical( | 1220 | try testCanonical( |
| 1221 | \\pub const Allocator = struct { | 1221 | \\pub const Allocator = struct { |
| 1222 | \\ shrinkFn: fn ( | 1222 | \\ shrinkFn: fn ( |
| 1223 | \\ self: *Allocator, | 1223 | \\ self: Allocator, |
| 1224 | \\ /// Guaranteed to be the same as what was returned from most recent call to | 1224 | \\ /// Guaranteed to be the same as what was returned from most recent call to |
| 1225 | \\ /// `allocFn`, `reallocFn`, or `shrinkFn`. | 1225 | \\ /// `allocFn`, `reallocFn`, or `shrinkFn`. |
| 1226 | \\ old_mem: []u8, | 1226 | \\ old_mem: []u8, |
| ... | @@ -4250,7 +4250,7 @@ test "zig fmt: Only indent multiline string literals in function calls" { | ... | @@ -4250,7 +4250,7 @@ test "zig fmt: Only indent multiline string literals in function calls" { |
| 4250 | 4250 | ||
| 4251 | test "zig fmt: Don't add extra newline after if" { | 4251 | test "zig fmt: Don't add extra newline after if" { |
| 4252 | try testCanonical( | 4252 | try testCanonical( |
| 4253 | \\pub fn atomicSymLink(allocator: *Allocator, existing_path: []const u8, new_path: []const u8) !void { | 4253 | \\pub fn atomicSymLink(allocator: Allocator, existing_path: []const u8, new_path: []const u8) !void { |
| 4254 | \\ if (cwd().symLink(existing_path, new_path, .{})) { | 4254 | \\ if (cwd().symLink(existing_path, new_path, .{})) { |
| 4255 | \\ return; | 4255 | \\ return; |
| 4256 | \\ } | 4256 | \\ } |
| ... | @@ -5319,7 +5319,7 @@ const maxInt = std.math.maxInt; | ... | @@ -5319,7 +5319,7 @@ const maxInt = std.math.maxInt; |
| 5319 | 5319 | ||
| 5320 | var fixed_buffer_mem: [100 * 1024]u8 = undefined; | 5320 | var fixed_buffer_mem: [100 * 1024]u8 = undefined; |
| 5321 | 5321 | ||
| 5322 | fn testParse(source: [:0]const u8, allocator: *mem.Allocator, anything_changed: *bool) ![]u8 { | 5322 | fn testParse(source: [:0]const u8, allocator: mem.Allocator, anything_changed: *bool) ![]u8 { |
| 5323 | const stderr = io.getStdErr().writer(); | 5323 | const stderr = io.getStdErr().writer(); |
| 5324 | 5324 | ||
| 5325 | var tree = try std.zig.parse(allocator, source); | 5325 | var tree = try std.zig.parse(allocator, source); |
| ... | @@ -5351,9 +5351,10 @@ fn testTransform(source: [:0]const u8, expected_source: []const u8) !void { | ... | @@ -5351,9 +5351,10 @@ fn testTransform(source: [:0]const u8, expected_source: []const u8) !void { |
| 5351 | const needed_alloc_count = x: { | 5351 | const needed_alloc_count = x: { |
| 5352 | // Try it once with unlimited memory, make sure it works | 5352 | // Try it once with unlimited memory, make sure it works |
| 5353 | var fixed_allocator = std.heap.FixedBufferAllocator.init(fixed_buffer_mem[0..]); | 5353 | var fixed_allocator = std.heap.FixedBufferAllocator.init(fixed_buffer_mem[0..]); |
| 5354 | var failing_allocator = std.testing.FailingAllocator.init(&fixed_allocator.allocator, maxInt(usize)); | 5354 | var failing_allocator = std.testing.FailingAllocator.init(fixed_allocator.getAllocator(), maxInt(usize)); |
| 5355 | const allocator = failing_allocator.getAllocator(); | ||
| 5355 | var anything_changed: bool = undefined; | 5356 | var anything_changed: bool = undefined; |
| 5356 | const result_source = try testParse(source, &failing_allocator.allocator, &anything_changed); | 5357 | const result_source = try testParse(source, allocator, &anything_changed); |
| 5357 | try std.testing.expectEqualStrings(expected_source, result_source); | 5358 | try std.testing.expectEqualStrings(expected_source, result_source); |
| 5358 | const changes_expected = source.ptr != expected_source.ptr; | 5359 | const changes_expected = source.ptr != expected_source.ptr; |
| 5359 | if (anything_changed != changes_expected) { | 5360 | if (anything_changed != changes_expected) { |
| ... | @@ -5361,16 +5362,16 @@ fn testTransform(source: [:0]const u8, expected_source: []const u8) !void { | ... | @@ -5361,16 +5362,16 @@ fn testTransform(source: [:0]const u8, expected_source: []const u8) !void { |
| 5361 | return error.TestFailed; | 5362 | return error.TestFailed; |
| 5362 | } | 5363 | } |
| 5363 | try std.testing.expect(anything_changed == changes_expected); | 5364 | try std.testing.expect(anything_changed == changes_expected); |
| 5364 | failing_allocator.allocator.free(result_source); | 5365 | allocator.free(result_source); |
| 5365 | break :x failing_allocator.index; | 5366 | break :x failing_allocator.index; |
| 5366 | }; | 5367 | }; |
| 5367 | 5368 | ||
| 5368 | var fail_index: usize = 0; | 5369 | var fail_index: usize = 0; |
| 5369 | while (fail_index < needed_alloc_count) : (fail_index += 1) { | 5370 | while (fail_index < needed_alloc_count) : (fail_index += 1) { |
| 5370 | var fixed_allocator = std.heap.FixedBufferAllocator.init(fixed_buffer_mem[0..]); | 5371 | var fixed_allocator = std.heap.FixedBufferAllocator.init(fixed_buffer_mem[0..]); |
| 5371 | var failing_allocator = std.testing.FailingAllocator.init(&fixed_allocator.allocator, fail_index); | 5372 | var failing_allocator = std.testing.FailingAllocator.init(fixed_allocator.getAllocator(), fail_index); |
| 5372 | var anything_changed: bool = undefined; | 5373 | var anything_changed: bool = undefined; |
| 5373 | if (testParse(source, &failing_allocator.allocator, &anything_changed)) |_| { | 5374 | if (testParse(source, failing_allocator.getAllocator(), &anything_changed)) |_| { |
| 5374 | return error.NondeterministicMemoryUsage; | 5375 | return error.NondeterministicMemoryUsage; |
| 5375 | } else |err| switch (err) { | 5376 | } else |err| switch (err) { |
| 5376 | error.OutOfMemory => { | 5377 | error.OutOfMemory => { |
lib/std/zig/perf_test.zig+1-1| ... | @@ -33,7 +33,7 @@ pub fn main() !void { | ... | @@ -33,7 +33,7 @@ pub fn main() !void { |
| 33 | 33 | ||
| 34 | fn testOnce() usize { | 34 | fn testOnce() usize { |
| 35 | var fixed_buf_alloc = std.heap.FixedBufferAllocator.init(fixed_buffer_mem[0..]); | 35 | var fixed_buf_alloc = std.heap.FixedBufferAllocator.init(fixed_buffer_mem[0..]); |
| 36 | var allocator = &fixed_buf_alloc.allocator; | 36 | var allocator = fixed_buf_alloc.getAllocator(); |
| 37 | _ = std.zig.parse(allocator, source) catch @panic("parse failure"); | 37 | _ = std.zig.parse(allocator, source) catch @panic("parse failure"); |
| 38 | return fixed_buf_alloc.end_index; | 38 | return fixed_buf_alloc.end_index; |
| 39 | } | 39 | } |
lib/std/zig/render.zig+24-24| ... | @@ -37,7 +37,7 @@ pub fn renderTree(buffer: *std.ArrayList(u8), tree: Ast) Error!void { | ... | @@ -37,7 +37,7 @@ pub fn renderTree(buffer: *std.ArrayList(u8), tree: Ast) Error!void { |
| 37 | } | 37 | } |
| 38 | 38 | ||
| 39 | /// Render all members in the given slice, keeping empty lines where appropriate | 39 | /// Render all members in the given slice, keeping empty lines where appropriate |
| 40 | fn renderMembers(gpa: *Allocator, ais: *Ais, tree: Ast, members: []const Ast.Node.Index) Error!void { | 40 | fn renderMembers(gpa: Allocator, ais: *Ais, tree: Ast, members: []const Ast.Node.Index) Error!void { |
| 41 | if (members.len == 0) return; | 41 | if (members.len == 0) return; |
| 42 | try renderMember(gpa, ais, tree, members[0], .newline); | 42 | try renderMember(gpa, ais, tree, members[0], .newline); |
| 43 | for (members[1..]) |member| { | 43 | for (members[1..]) |member| { |
| ... | @@ -46,7 +46,7 @@ fn renderMembers(gpa: *Allocator, ais: *Ais, tree: Ast, members: []const Ast.Nod | ... | @@ -46,7 +46,7 @@ fn renderMembers(gpa: *Allocator, ais: *Ais, tree: Ast, members: []const Ast.Nod |
| 46 | } | 46 | } |
| 47 | } | 47 | } |
| 48 | 48 | ||
| 49 | fn renderMember(gpa: *Allocator, ais: *Ais, tree: Ast, decl: Ast.Node.Index, space: Space) Error!void { | 49 | fn renderMember(gpa: Allocator, ais: *Ais, tree: Ast, decl: Ast.Node.Index, space: Space) Error!void { |
| 50 | const token_tags = tree.tokens.items(.tag); | 50 | const token_tags = tree.tokens.items(.tag); |
| 51 | const main_tokens = tree.nodes.items(.main_token); | 51 | const main_tokens = tree.nodes.items(.main_token); |
| 52 | const datas = tree.nodes.items(.data); | 52 | const datas = tree.nodes.items(.data); |
| ... | @@ -168,7 +168,7 @@ fn renderMember(gpa: *Allocator, ais: *Ais, tree: Ast, decl: Ast.Node.Index, spa | ... | @@ -168,7 +168,7 @@ fn renderMember(gpa: *Allocator, ais: *Ais, tree: Ast, decl: Ast.Node.Index, spa |
| 168 | } | 168 | } |
| 169 | 169 | ||
| 170 | /// Render all expressions in the slice, keeping empty lines where appropriate | 170 | /// Render all expressions in the slice, keeping empty lines where appropriate |
| 171 | fn renderExpressions(gpa: *Allocator, ais: *Ais, tree: Ast, expressions: []const Ast.Node.Index, space: Space) Error!void { | 171 | fn renderExpressions(gpa: Allocator, ais: *Ais, tree: Ast, expressions: []const Ast.Node.Index, space: Space) Error!void { |
| 172 | if (expressions.len == 0) return; | 172 | if (expressions.len == 0) return; |
| 173 | try renderExpression(gpa, ais, tree, expressions[0], space); | 173 | try renderExpression(gpa, ais, tree, expressions[0], space); |
| 174 | for (expressions[1..]) |expression| { | 174 | for (expressions[1..]) |expression| { |
| ... | @@ -177,7 +177,7 @@ fn renderExpressions(gpa: *Allocator, ais: *Ais, tree: Ast, expressions: []const | ... | @@ -177,7 +177,7 @@ fn renderExpressions(gpa: *Allocator, ais: *Ais, tree: Ast, expressions: []const |
| 177 | } | 177 | } |
| 178 | } | 178 | } |
| 179 | 179 | ||
| 180 | fn renderExpression(gpa: *Allocator, ais: *Ais, tree: Ast, node: Ast.Node.Index, space: Space) Error!void { | 180 | fn renderExpression(gpa: Allocator, ais: *Ais, tree: Ast, node: Ast.Node.Index, space: Space) Error!void { |
| 181 | const token_tags = tree.tokens.items(.tag); | 181 | const token_tags = tree.tokens.items(.tag); |
| 182 | const main_tokens = tree.nodes.items(.main_token); | 182 | const main_tokens = tree.nodes.items(.main_token); |
| 183 | const node_tags = tree.nodes.items(.tag); | 183 | const node_tags = tree.nodes.items(.tag); |
| ... | @@ -710,7 +710,7 @@ fn renderExpression(gpa: *Allocator, ais: *Ais, tree: Ast, node: Ast.Node.Index, | ... | @@ -710,7 +710,7 @@ fn renderExpression(gpa: *Allocator, ais: *Ais, tree: Ast, node: Ast.Node.Index, |
| 710 | } | 710 | } |
| 711 | 711 | ||
| 712 | fn renderArrayType( | 712 | fn renderArrayType( |
| 713 | gpa: *Allocator, | 713 | gpa: Allocator, |
| 714 | ais: *Ais, | 714 | ais: *Ais, |
| 715 | tree: Ast, | 715 | tree: Ast, |
| 716 | array_type: Ast.full.ArrayType, | 716 | array_type: Ast.full.ArrayType, |
| ... | @@ -732,7 +732,7 @@ fn renderArrayType( | ... | @@ -732,7 +732,7 @@ fn renderArrayType( |
| 732 | } | 732 | } |
| 733 | 733 | ||
| 734 | fn renderPtrType( | 734 | fn renderPtrType( |
| 735 | gpa: *Allocator, | 735 | gpa: Allocator, |
| 736 | ais: *Ais, | 736 | ais: *Ais, |
| 737 | tree: Ast, | 737 | tree: Ast, |
| 738 | ptr_type: Ast.full.PtrType, | 738 | ptr_type: Ast.full.PtrType, |
| ... | @@ -825,7 +825,7 @@ fn renderPtrType( | ... | @@ -825,7 +825,7 @@ fn renderPtrType( |
| 825 | } | 825 | } |
| 826 | 826 | ||
| 827 | fn renderSlice( | 827 | fn renderSlice( |
| 828 | gpa: *Allocator, | 828 | gpa: Allocator, |
| 829 | ais: *Ais, | 829 | ais: *Ais, |
| 830 | tree: Ast, | 830 | tree: Ast, |
| 831 | slice_node: Ast.Node.Index, | 831 | slice_node: Ast.Node.Index, |
| ... | @@ -861,7 +861,7 @@ fn renderSlice( | ... | @@ -861,7 +861,7 @@ fn renderSlice( |
| 861 | } | 861 | } |
| 862 | 862 | ||
| 863 | fn renderAsmOutput( | 863 | fn renderAsmOutput( |
| 864 | gpa: *Allocator, | 864 | gpa: Allocator, |
| 865 | ais: *Ais, | 865 | ais: *Ais, |
| 866 | tree: Ast, | 866 | tree: Ast, |
| 867 | asm_output: Ast.Node.Index, | 867 | asm_output: Ast.Node.Index, |
| ... | @@ -891,7 +891,7 @@ fn renderAsmOutput( | ... | @@ -891,7 +891,7 @@ fn renderAsmOutput( |
| 891 | } | 891 | } |
| 892 | 892 | ||
| 893 | fn renderAsmInput( | 893 | fn renderAsmInput( |
| 894 | gpa: *Allocator, | 894 | gpa: Allocator, |
| 895 | ais: *Ais, | 895 | ais: *Ais, |
| 896 | tree: Ast, | 896 | tree: Ast, |
| 897 | asm_input: Ast.Node.Index, | 897 | asm_input: Ast.Node.Index, |
| ... | @@ -912,7 +912,7 @@ fn renderAsmInput( | ... | @@ -912,7 +912,7 @@ fn renderAsmInput( |
| 912 | return renderToken(ais, tree, datas[asm_input].rhs, space); // rparen | 912 | return renderToken(ais, tree, datas[asm_input].rhs, space); // rparen |
| 913 | } | 913 | } |
| 914 | 914 | ||
| 915 | fn renderVarDecl(gpa: *Allocator, ais: *Ais, tree: Ast, var_decl: Ast.full.VarDecl) Error!void { | 915 | fn renderVarDecl(gpa: Allocator, ais: *Ais, tree: Ast, var_decl: Ast.full.VarDecl) Error!void { |
| 916 | if (var_decl.visib_token) |visib_token| { | 916 | if (var_decl.visib_token) |visib_token| { |
| 917 | try renderToken(ais, tree, visib_token, Space.space); // pub | 917 | try renderToken(ais, tree, visib_token, Space.space); // pub |
| 918 | } | 918 | } |
| ... | @@ -1019,7 +1019,7 @@ fn renderVarDecl(gpa: *Allocator, ais: *Ais, tree: Ast, var_decl: Ast.full.VarDe | ... | @@ -1019,7 +1019,7 @@ fn renderVarDecl(gpa: *Allocator, ais: *Ais, tree: Ast, var_decl: Ast.full.VarDe |
| 1019 | return renderToken(ais, tree, var_decl.ast.mut_token + 2, .newline); // ; | 1019 | return renderToken(ais, tree, var_decl.ast.mut_token + 2, .newline); // ; |
| 1020 | } | 1020 | } |
| 1021 | 1021 | ||
| 1022 | fn renderIf(gpa: *Allocator, ais: *Ais, tree: Ast, if_node: Ast.full.If, space: Space) Error!void { | 1022 | fn renderIf(gpa: Allocator, ais: *Ais, tree: Ast, if_node: Ast.full.If, space: Space) Error!void { |
| 1023 | return renderWhile(gpa, ais, tree, .{ | 1023 | return renderWhile(gpa, ais, tree, .{ |
| 1024 | .ast = .{ | 1024 | .ast = .{ |
| 1025 | .while_token = if_node.ast.if_token, | 1025 | .while_token = if_node.ast.if_token, |
| ... | @@ -1038,7 +1038,7 @@ fn renderIf(gpa: *Allocator, ais: *Ais, tree: Ast, if_node: Ast.full.If, space: | ... | @@ -1038,7 +1038,7 @@ fn renderIf(gpa: *Allocator, ais: *Ais, tree: Ast, if_node: Ast.full.If, space: |
| 1038 | 1038 | ||
| 1039 | /// Note that this function is additionally used to render if and for expressions, with | 1039 | /// Note that this function is additionally used to render if and for expressions, with |
| 1040 | /// respective values set to null. | 1040 | /// respective values set to null. |
| 1041 | fn renderWhile(gpa: *Allocator, ais: *Ais, tree: Ast, while_node: Ast.full.While, space: Space) Error!void { | 1041 | fn renderWhile(gpa: Allocator, ais: *Ais, tree: Ast, while_node: Ast.full.While, space: Space) Error!void { |
| 1042 | const node_tags = tree.nodes.items(.tag); | 1042 | const node_tags = tree.nodes.items(.tag); |
| 1043 | const token_tags = tree.tokens.items(.tag); | 1043 | const token_tags = tree.tokens.items(.tag); |
| 1044 | 1044 | ||
| ... | @@ -1141,7 +1141,7 @@ fn renderWhile(gpa: *Allocator, ais: *Ais, tree: Ast, while_node: Ast.full.While | ... | @@ -1141,7 +1141,7 @@ fn renderWhile(gpa: *Allocator, ais: *Ais, tree: Ast, while_node: Ast.full.While |
| 1141 | } | 1141 | } |
| 1142 | 1142 | ||
| 1143 | fn renderContainerField( | 1143 | fn renderContainerField( |
| 1144 | gpa: *Allocator, | 1144 | gpa: Allocator, |
| 1145 | ais: *Ais, | 1145 | ais: *Ais, |
| 1146 | tree: Ast, | 1146 | tree: Ast, |
| 1147 | field: Ast.full.ContainerField, | 1147 | field: Ast.full.ContainerField, |
| ... | @@ -1215,7 +1215,7 @@ fn renderContainerField( | ... | @@ -1215,7 +1215,7 @@ fn renderContainerField( |
| 1215 | } | 1215 | } |
| 1216 | 1216 | ||
| 1217 | fn renderBuiltinCall( | 1217 | fn renderBuiltinCall( |
| 1218 | gpa: *Allocator, | 1218 | gpa: Allocator, |
| 1219 | ais: *Ais, | 1219 | ais: *Ais, |
| 1220 | tree: Ast, | 1220 | tree: Ast, |
| 1221 | builtin_token: Ast.TokenIndex, | 1221 | builtin_token: Ast.TokenIndex, |
| ... | @@ -1272,7 +1272,7 @@ fn renderBuiltinCall( | ... | @@ -1272,7 +1272,7 @@ fn renderBuiltinCall( |
| 1272 | } | 1272 | } |
| 1273 | } | 1273 | } |
| 1274 | 1274 | ||
| 1275 | fn renderFnProto(gpa: *Allocator, ais: *Ais, tree: Ast, fn_proto: Ast.full.FnProto, space: Space) Error!void { | 1275 | fn renderFnProto(gpa: Allocator, ais: *Ais, tree: Ast, fn_proto: Ast.full.FnProto, space: Space) Error!void { |
| 1276 | const token_tags = tree.tokens.items(.tag); | 1276 | const token_tags = tree.tokens.items(.tag); |
| 1277 | const token_starts = tree.tokens.items(.start); | 1277 | const token_starts = tree.tokens.items(.start); |
| 1278 | 1278 | ||
| ... | @@ -1488,7 +1488,7 @@ fn renderFnProto(gpa: *Allocator, ais: *Ais, tree: Ast, fn_proto: Ast.full.FnPro | ... | @@ -1488,7 +1488,7 @@ fn renderFnProto(gpa: *Allocator, ais: *Ais, tree: Ast, fn_proto: Ast.full.FnPro |
| 1488 | } | 1488 | } |
| 1489 | 1489 | ||
| 1490 | fn renderSwitchCase( | 1490 | fn renderSwitchCase( |
| 1491 | gpa: *Allocator, | 1491 | gpa: Allocator, |
| 1492 | ais: *Ais, | 1492 | ais: *Ais, |
| 1493 | tree: Ast, | 1493 | tree: Ast, |
| 1494 | switch_case: Ast.full.SwitchCase, | 1494 | switch_case: Ast.full.SwitchCase, |
| ... | @@ -1541,7 +1541,7 @@ fn renderSwitchCase( | ... | @@ -1541,7 +1541,7 @@ fn renderSwitchCase( |
| 1541 | } | 1541 | } |
| 1542 | 1542 | ||
| 1543 | fn renderBlock( | 1543 | fn renderBlock( |
| 1544 | gpa: *Allocator, | 1544 | gpa: Allocator, |
| 1545 | ais: *Ais, | 1545 | ais: *Ais, |
| 1546 | tree: Ast, | 1546 | tree: Ast, |
| 1547 | block_node: Ast.Node.Index, | 1547 | block_node: Ast.Node.Index, |
| ... | @@ -1581,7 +1581,7 @@ fn renderBlock( | ... | @@ -1581,7 +1581,7 @@ fn renderBlock( |
| 1581 | } | 1581 | } |
| 1582 | 1582 | ||
| 1583 | fn renderStructInit( | 1583 | fn renderStructInit( |
| 1584 | gpa: *Allocator, | 1584 | gpa: Allocator, |
| 1585 | ais: *Ais, | 1585 | ais: *Ais, |
| 1586 | tree: Ast, | 1586 | tree: Ast, |
| 1587 | struct_node: Ast.Node.Index, | 1587 | struct_node: Ast.Node.Index, |
| ... | @@ -1640,7 +1640,7 @@ fn renderStructInit( | ... | @@ -1640,7 +1640,7 @@ fn renderStructInit( |
| 1640 | } | 1640 | } |
| 1641 | 1641 | ||
| 1642 | fn renderArrayInit( | 1642 | fn renderArrayInit( |
| 1643 | gpa: *Allocator, | 1643 | gpa: Allocator, |
| 1644 | ais: *Ais, | 1644 | ais: *Ais, |
| 1645 | tree: Ast, | 1645 | tree: Ast, |
| 1646 | array_init: Ast.full.ArrayInit, | 1646 | array_init: Ast.full.ArrayInit, |
| ... | @@ -1859,7 +1859,7 @@ fn renderArrayInit( | ... | @@ -1859,7 +1859,7 @@ fn renderArrayInit( |
| 1859 | } | 1859 | } |
| 1860 | 1860 | ||
| 1861 | fn renderContainerDecl( | 1861 | fn renderContainerDecl( |
| 1862 | gpa: *Allocator, | 1862 | gpa: Allocator, |
| 1863 | ais: *Ais, | 1863 | ais: *Ais, |
| 1864 | tree: Ast, | 1864 | tree: Ast, |
| 1865 | container_decl_node: Ast.Node.Index, | 1865 | container_decl_node: Ast.Node.Index, |
| ... | @@ -1956,7 +1956,7 @@ fn renderContainerDecl( | ... | @@ -1956,7 +1956,7 @@ fn renderContainerDecl( |
| 1956 | } | 1956 | } |
| 1957 | 1957 | ||
| 1958 | fn renderAsm( | 1958 | fn renderAsm( |
| 1959 | gpa: *Allocator, | 1959 | gpa: Allocator, |
| 1960 | ais: *Ais, | 1960 | ais: *Ais, |
| 1961 | tree: Ast, | 1961 | tree: Ast, |
| 1962 | asm_node: Ast.full.Asm, | 1962 | asm_node: Ast.full.Asm, |
| ... | @@ -2105,7 +2105,7 @@ fn renderAsm( | ... | @@ -2105,7 +2105,7 @@ fn renderAsm( |
| 2105 | } | 2105 | } |
| 2106 | 2106 | ||
| 2107 | fn renderCall( | 2107 | fn renderCall( |
| 2108 | gpa: *Allocator, | 2108 | gpa: Allocator, |
| 2109 | ais: *Ais, | 2109 | ais: *Ais, |
| 2110 | tree: Ast, | 2110 | tree: Ast, |
| 2111 | call: Ast.full.Call, | 2111 | call: Ast.full.Call, |
| ... | @@ -2180,7 +2180,7 @@ fn renderCall( | ... | @@ -2180,7 +2180,7 @@ fn renderCall( |
| 2180 | 2180 | ||
| 2181 | /// Renders the given expression indented, popping the indent before rendering | 2181 | /// Renders the given expression indented, popping the indent before rendering |
| 2182 | /// any following line comments | 2182 | /// any following line comments |
| 2183 | fn renderExpressionIndented(gpa: *Allocator, ais: *Ais, tree: Ast, node: Ast.Node.Index, space: Space) Error!void { | 2183 | fn renderExpressionIndented(gpa: Allocator, ais: *Ais, tree: Ast, node: Ast.Node.Index, space: Space) Error!void { |
| 2184 | const token_starts = tree.tokens.items(.start); | 2184 | const token_starts = tree.tokens.items(.start); |
| 2185 | const token_tags = tree.tokens.items(.tag); | 2185 | const token_tags = tree.tokens.items(.tag); |
| 2186 | 2186 | ||
| ... | @@ -2238,7 +2238,7 @@ fn renderExpressionIndented(gpa: *Allocator, ais: *Ais, tree: Ast, node: Ast.Nod | ... | @@ -2238,7 +2238,7 @@ fn renderExpressionIndented(gpa: *Allocator, ais: *Ais, tree: Ast, node: Ast.Nod |
| 2238 | 2238 | ||
| 2239 | /// Render an expression, and the comma that follows it, if it is present in the source. | 2239 | /// Render an expression, and the comma that follows it, if it is present in the source. |
| 2240 | /// If a comma is present, and `space` is `Space.comma`, render only a single comma. | 2240 | /// If a comma is present, and `space` is `Space.comma`, render only a single comma. |
| 2241 | fn renderExpressionComma(gpa: *Allocator, ais: *Ais, tree: Ast, node: Ast.Node.Index, space: Space) Error!void { | 2241 | fn renderExpressionComma(gpa: Allocator, ais: *Ais, tree: Ast, node: Ast.Node.Index, space: Space) Error!void { |
| 2242 | const token_tags = tree.tokens.items(.tag); | 2242 | const token_tags = tree.tokens.items(.tag); |
| 2243 | const maybe_comma = tree.lastToken(node) + 1; | 2243 | const maybe_comma = tree.lastToken(node) + 1; |
| 2244 | if (token_tags[maybe_comma] == .comma and space != .comma) { | 2244 | if (token_tags[maybe_comma] == .comma and space != .comma) { |
lib/std/zig/string_literal.zig+2-2| ... | @@ -131,7 +131,7 @@ pub fn parseAppend(buf: *std.ArrayList(u8), bytes: []const u8) error{OutOfMemory | ... | @@ -131,7 +131,7 @@ pub fn parseAppend(buf: *std.ArrayList(u8), bytes: []const u8) error{OutOfMemory |
| 131 | 131 | ||
| 132 | /// Higher level API. Does not return extra info about parse errors. | 132 | /// Higher level API. Does not return extra info about parse errors. |
| 133 | /// Caller owns returned memory. | 133 | /// Caller owns returned memory. |
| 134 | pub fn parseAlloc(allocator: *std.mem.Allocator, bytes: []const u8) ParseError![]u8 { | 134 | pub fn parseAlloc(allocator: std.mem.Allocator, bytes: []const u8) ParseError![]u8 { |
| 135 | var buf = std.ArrayList(u8).init(allocator); | 135 | var buf = std.ArrayList(u8).init(allocator); |
| 136 | defer buf.deinit(); | 136 | defer buf.deinit(); |
| 137 | 137 | ||
| ... | @@ -147,7 +147,7 @@ test "parse" { | ... | @@ -147,7 +147,7 @@ test "parse" { |
| 147 | 147 | ||
| 148 | var fixed_buf_mem: [32]u8 = undefined; | 148 | var fixed_buf_mem: [32]u8 = undefined; |
| 149 | var fixed_buf_alloc = std.heap.FixedBufferAllocator.init(fixed_buf_mem[0..]); | 149 | var fixed_buf_alloc = std.heap.FixedBufferAllocator.init(fixed_buf_mem[0..]); |
| 150 | var alloc = &fixed_buf_alloc.allocator; | 150 | var alloc = fixed_buf_alloc.getAllocator(); |
| 151 | 151 | ||
| 152 | try expect(eql(u8, "foo", try parseAlloc(alloc, "\"foo\""))); | 152 | try expect(eql(u8, "foo", try parseAlloc(alloc, "\"foo\""))); |
| 153 | try expect(eql(u8, "foo", try parseAlloc(alloc, "\"f\x6f\x6f\""))); | 153 | try expect(eql(u8, "foo", try parseAlloc(alloc, "\"f\x6f\x6f\""))); |
lib/std/zig/system.zig+3-3| ... | @@ -21,7 +21,7 @@ pub const NativePaths = struct { | ... | @@ -21,7 +21,7 @@ pub const NativePaths = struct { |
| 21 | rpaths: ArrayList([:0]u8), | 21 | rpaths: ArrayList([:0]u8), |
| 22 | warnings: ArrayList([:0]u8), | 22 | warnings: ArrayList([:0]u8), |
| 23 | 23 | ||
| 24 | pub fn detect(allocator: *Allocator, native_info: NativeTargetInfo) !NativePaths { | 24 | pub fn detect(allocator: Allocator, native_info: NativeTargetInfo) !NativePaths { |
| 25 | const native_target = native_info.target; | 25 | const native_target = native_info.target; |
| 26 | 26 | ||
| 27 | var self: NativePaths = .{ | 27 | var self: NativePaths = .{ |
| ... | @@ -237,7 +237,7 @@ pub const NativeTargetInfo = struct { | ... | @@ -237,7 +237,7 @@ pub const NativeTargetInfo = struct { |
| 237 | /// Any resources this function allocates are released before returning, and so there is no | 237 | /// Any resources this function allocates are released before returning, and so there is no |
| 238 | /// deinitialization method. | 238 | /// deinitialization method. |
| 239 | /// TODO Remove the Allocator requirement from this function. | 239 | /// TODO Remove the Allocator requirement from this function. |
| 240 | pub fn detect(allocator: *Allocator, cross_target: CrossTarget) DetectError!NativeTargetInfo { | 240 | pub fn detect(allocator: Allocator, cross_target: CrossTarget) DetectError!NativeTargetInfo { |
| 241 | var os = cross_target.getOsTag().defaultVersionRange(cross_target.getCpuArch()); | 241 | var os = cross_target.getOsTag().defaultVersionRange(cross_target.getCpuArch()); |
| 242 | if (cross_target.os_tag == null) { | 242 | if (cross_target.os_tag == null) { |
| 243 | switch (builtin.target.os.tag) { | 243 | switch (builtin.target.os.tag) { |
| ... | @@ -441,7 +441,7 @@ pub const NativeTargetInfo = struct { | ... | @@ -441,7 +441,7 @@ pub const NativeTargetInfo = struct { |
| 441 | /// we fall back to the defaults. | 441 | /// we fall back to the defaults. |
| 442 | /// TODO Remove the Allocator requirement from this function. | 442 | /// TODO Remove the Allocator requirement from this function. |
| 443 | fn detectAbiAndDynamicLinker( | 443 | fn detectAbiAndDynamicLinker( |
| 444 | allocator: *Allocator, | 444 | allocator: Allocator, |
| 445 | cpu: Target.Cpu, | 445 | cpu: Target.Cpu, |
| 446 | os: Target.Os, | 446 | os: Target.Os, |
| 447 | cross_target: CrossTarget, | 447 | cross_target: CrossTarget, |
lib/std/zig/system/darwin.zig+3-3| ... | @@ -11,7 +11,7 @@ pub const macos = @import("darwin/macos.zig"); | ... | @@ -11,7 +11,7 @@ pub const macos = @import("darwin/macos.zig"); |
| 11 | /// Therefore, we resort to the same tool used by Homebrew, namely, invoking `xcode-select --print-path` | 11 | /// Therefore, we resort to the same tool used by Homebrew, namely, invoking `xcode-select --print-path` |
| 12 | /// and checking if the status is nonzero or the returned string in nonempty. | 12 | /// and checking if the status is nonzero or the returned string in nonempty. |
| 13 | /// https://github.com/Homebrew/brew/blob/e119bdc571dcb000305411bc1e26678b132afb98/Library/Homebrew/brew.sh#L630 | 13 | /// https://github.com/Homebrew/brew/blob/e119bdc571dcb000305411bc1e26678b132afb98/Library/Homebrew/brew.sh#L630 |
| 14 | pub fn isDarwinSDKInstalled(allocator: *Allocator) bool { | 14 | pub fn isDarwinSDKInstalled(allocator: Allocator) bool { |
| 15 | const argv = &[_][]const u8{ "/usr/bin/xcode-select", "--print-path" }; | 15 | const argv = &[_][]const u8{ "/usr/bin/xcode-select", "--print-path" }; |
| 16 | const result = std.ChildProcess.exec(.{ .allocator = allocator, .argv = argv }) catch return false; | 16 | const result = std.ChildProcess.exec(.{ .allocator = allocator, .argv = argv }) catch return false; |
| 17 | defer { | 17 | defer { |
| ... | @@ -29,7 +29,7 @@ pub fn isDarwinSDKInstalled(allocator: *Allocator) bool { | ... | @@ -29,7 +29,7 @@ pub fn isDarwinSDKInstalled(allocator: *Allocator) bool { |
| 29 | /// Calls `xcrun --sdk <target_sdk> --show-sdk-path` which fetches the path to the SDK sysroot (if any). | 29 | /// Calls `xcrun --sdk <target_sdk> --show-sdk-path` which fetches the path to the SDK sysroot (if any). |
| 30 | /// Subsequently calls `xcrun --sdk <target_sdk> --show-sdk-version` which fetches version of the SDK. | 30 | /// Subsequently calls `xcrun --sdk <target_sdk> --show-sdk-version` which fetches version of the SDK. |
| 31 | /// The caller needs to deinit the resulting struct. | 31 | /// The caller needs to deinit the resulting struct. |
| 32 | pub fn getDarwinSDK(allocator: *Allocator, target: Target) ?DarwinSDK { | 32 | pub fn getDarwinSDK(allocator: Allocator, target: Target) ?DarwinSDK { |
| 33 | const is_simulator_abi = target.abi == .simulator; | 33 | const is_simulator_abi = target.abi == .simulator; |
| 34 | const sdk = switch (target.os.tag) { | 34 | const sdk = switch (target.os.tag) { |
| 35 | .macos => "macosx", | 35 | .macos => "macosx", |
| ... | @@ -82,7 +82,7 @@ pub const DarwinSDK = struct { | ... | @@ -82,7 +82,7 @@ pub const DarwinSDK = struct { |
| 82 | path: []const u8, | 82 | path: []const u8, |
| 83 | version: Version, | 83 | version: Version, |
| 84 | 84 | ||
| 85 | pub fn deinit(self: DarwinSDK, allocator: *Allocator) void { | 85 | pub fn deinit(self: DarwinSDK, allocator: Allocator) void { |
| 86 | allocator.free(self.path); | 86 | allocator.free(self.path); |
| 87 | } | 87 | } |
| 88 | }; | 88 | }; |
src/Air.zig+1-1| ... | @@ -841,7 +841,7 @@ pub fn extraData(air: Air, comptime T: type, index: usize) struct { data: T, end | ... | @@ -841,7 +841,7 @@ pub fn extraData(air: Air, comptime T: type, index: usize) struct { data: T, end |
| 841 | }; | 841 | }; |
| 842 | } | 842 | } |
| 843 | 843 | ||
| 844 | pub fn deinit(air: *Air, gpa: *std.mem.Allocator) void { | 844 | pub fn deinit(air: *Air, gpa: std.mem.Allocator) void { |
| 845 | air.instructions.deinit(gpa); | 845 | air.instructions.deinit(gpa); |
| 846 | gpa.free(air.extra); | 846 | gpa.free(air.extra); |
| 847 | gpa.free(air.values); | 847 | gpa.free(air.values); |
src/AstGen.zig+9-9| ... | @@ -16,7 +16,7 @@ const indexToRef = Zir.indexToRef; | ... | @@ -16,7 +16,7 @@ const indexToRef = Zir.indexToRef; |
| 16 | const trace = @import("tracy.zig").trace; | 16 | const trace = @import("tracy.zig").trace; |
| 17 | const BuiltinFn = @import("BuiltinFn.zig"); | 17 | const BuiltinFn = @import("BuiltinFn.zig"); |
| 18 | 18 | ||
| 19 | gpa: *Allocator, | 19 | gpa: Allocator, |
| 20 | tree: *const Ast, | 20 | tree: *const Ast, |
| 21 | instructions: std.MultiArrayList(Zir.Inst) = .{}, | 21 | instructions: std.MultiArrayList(Zir.Inst) = .{}, |
| 22 | extra: ArrayListUnmanaged(u32) = .{}, | 22 | extra: ArrayListUnmanaged(u32) = .{}, |
| ... | @@ -33,7 +33,7 @@ source_line: u32 = 0, | ... | @@ -33,7 +33,7 @@ source_line: u32 = 0, |
| 33 | source_column: u32 = 0, | 33 | source_column: u32 = 0, |
| 34 | /// Used for temporary allocations; freed after AstGen is complete. | 34 | /// Used for temporary allocations; freed after AstGen is complete. |
| 35 | /// The resulting ZIR code has no references to anything in this arena. | 35 | /// The resulting ZIR code has no references to anything in this arena. |
| 36 | arena: *Allocator, | 36 | arena: Allocator, |
| 37 | string_table: std.HashMapUnmanaged(u32, void, StringIndexContext, std.hash_map.default_max_load_percentage) = .{}, | 37 | string_table: std.HashMapUnmanaged(u32, void, StringIndexContext, std.hash_map.default_max_load_percentage) = .{}, |
| 38 | compile_errors: ArrayListUnmanaged(Zir.Inst.CompileErrors.Item) = .{}, | 38 | compile_errors: ArrayListUnmanaged(Zir.Inst.CompileErrors.Item) = .{}, |
| 39 | /// The topmost block of the current function. | 39 | /// The topmost block of the current function. |
| ... | @@ -92,7 +92,7 @@ fn appendRefsAssumeCapacity(astgen: *AstGen, refs: []const Zir.Inst.Ref) void { | ... | @@ -92,7 +92,7 @@ fn appendRefsAssumeCapacity(astgen: *AstGen, refs: []const Zir.Inst.Ref) void { |
| 92 | astgen.extra.appendSliceAssumeCapacity(coerced); | 92 | astgen.extra.appendSliceAssumeCapacity(coerced); |
| 93 | } | 93 | } |
| 94 | 94 | ||
| 95 | pub fn generate(gpa: *Allocator, tree: Ast) Allocator.Error!Zir { | 95 | pub fn generate(gpa: Allocator, tree: Ast) Allocator.Error!Zir { |
| 96 | var arena = std.heap.ArenaAllocator.init(gpa); | 96 | var arena = std.heap.ArenaAllocator.init(gpa); |
| 97 | defer arena.deinit(); | 97 | defer arena.deinit(); |
| 98 | 98 | ||
| ... | @@ -196,7 +196,7 @@ pub fn generate(gpa: *Allocator, tree: Ast) Allocator.Error!Zir { | ... | @@ -196,7 +196,7 @@ pub fn generate(gpa: *Allocator, tree: Ast) Allocator.Error!Zir { |
| 196 | }; | 196 | }; |
| 197 | } | 197 | } |
| 198 | 198 | ||
| 199 | pub fn deinit(astgen: *AstGen, gpa: *Allocator) void { | 199 | pub fn deinit(astgen: *AstGen, gpa: Allocator) void { |
| 200 | astgen.instructions.deinit(gpa); | 200 | astgen.instructions.deinit(gpa); |
| 201 | astgen.extra.deinit(gpa); | 201 | astgen.extra.deinit(gpa); |
| 202 | astgen.string_table.deinit(gpa); | 202 | astgen.string_table.deinit(gpa); |
| ... | @@ -2460,7 +2460,7 @@ fn makeDeferScope( | ... | @@ -2460,7 +2460,7 @@ fn makeDeferScope( |
| 2460 | astgen: *AstGen, | 2460 | astgen: *AstGen, |
| 2461 | scope: *Scope, | 2461 | scope: *Scope, |
| 2462 | node: Ast.Node.Index, | 2462 | node: Ast.Node.Index, |
| 2463 | block_arena: *Allocator, | 2463 | block_arena: Allocator, |
| 2464 | scope_tag: Scope.Tag, | 2464 | scope_tag: Scope.Tag, |
| 2465 | ) InnerError!*Scope { | 2465 | ) InnerError!*Scope { |
| 2466 | const tree = astgen.tree; | 2466 | const tree = astgen.tree; |
| ... | @@ -2486,7 +2486,7 @@ fn varDecl( | ... | @@ -2486,7 +2486,7 @@ fn varDecl( |
| 2486 | gz: *GenZir, | 2486 | gz: *GenZir, |
| 2487 | scope: *Scope, | 2487 | scope: *Scope, |
| 2488 | node: Ast.Node.Index, | 2488 | node: Ast.Node.Index, |
| 2489 | block_arena: *Allocator, | 2489 | block_arena: Allocator, |
| 2490 | var_decl: Ast.full.VarDecl, | 2490 | var_decl: Ast.full.VarDecl, |
| 2491 | ) InnerError!*Scope { | 2491 | ) InnerError!*Scope { |
| 2492 | try emitDbgNode(gz, node); | 2492 | try emitDbgNode(gz, node); |
| ... | @@ -3030,7 +3030,7 @@ const WipMembers = struct { | ... | @@ -3030,7 +3030,7 @@ const WipMembers = struct { |
| 3030 | /// (4 for src_hash + line + name + value + align + link_section + address_space) | 3030 | /// (4 for src_hash + line + name + value + align + link_section + address_space) |
| 3031 | const max_decl_size = 10; | 3031 | const max_decl_size = 10; |
| 3032 | 3032 | ||
| 3033 | pub fn init(gpa: *Allocator, payload: *ArrayListUnmanaged(u32), decl_count: u32, field_count: u32, comptime bits_per_field: u32, comptime max_field_size: u32) Allocator.Error!Self { | 3033 | pub fn init(gpa: Allocator, payload: *ArrayListUnmanaged(u32), decl_count: u32, field_count: u32, comptime bits_per_field: u32, comptime max_field_size: u32) Allocator.Error!Self { |
| 3034 | const payload_top = @intCast(u32, payload.items.len); | 3034 | const payload_top = @intCast(u32, payload.items.len); |
| 3035 | const decls_start = payload_top + (decl_count + decls_per_u32 - 1) / decls_per_u32; | 3035 | const decls_start = payload_top + (decl_count + decls_per_u32 - 1) / decls_per_u32; |
| 3036 | const field_bits_start = decls_start + decl_count * max_decl_size; | 3036 | const field_bits_start = decls_start + decl_count * max_decl_size; |
| ... | @@ -6178,7 +6178,7 @@ fn tunnelThroughClosure( | ... | @@ -6178,7 +6178,7 @@ fn tunnelThroughClosure( |
| 6178 | ns: ?*Scope.Namespace, | 6178 | ns: ?*Scope.Namespace, |
| 6179 | value: Zir.Inst.Ref, | 6179 | value: Zir.Inst.Ref, |
| 6180 | token: Ast.TokenIndex, | 6180 | token: Ast.TokenIndex, |
| 6181 | gpa: *Allocator, | 6181 | gpa: Allocator, |
| 6182 | ) !Zir.Inst.Ref { | 6182 | ) !Zir.Inst.Ref { |
| 6183 | // For trivial values, we don't need a tunnel. | 6183 | // For trivial values, we don't need a tunnel. |
| 6184 | // Just return the ref. | 6184 | // Just return the ref. |
| ... | @@ -8806,7 +8806,7 @@ const Scope = struct { | ... | @@ -8806,7 +8806,7 @@ const Scope = struct { |
| 8806 | /// ref of the capture for decls in this namespace | 8806 | /// ref of the capture for decls in this namespace |
| 8807 | captures: std.AutoArrayHashMapUnmanaged(Zir.Inst.Index, Zir.Inst.Index) = .{}, | 8807 | captures: std.AutoArrayHashMapUnmanaged(Zir.Inst.Index, Zir.Inst.Index) = .{}, |
| 8808 | 8808 | ||
| 8809 | pub fn deinit(self: *Namespace, gpa: *Allocator) void { | 8809 | pub fn deinit(self: *Namespace, gpa: Allocator) void { |
| 8810 | self.decls.deinit(gpa); | 8810 | self.decls.deinit(gpa); |
| 8811 | self.captures.deinit(gpa); | 8811 | self.captures.deinit(gpa); |
| 8812 | self.* = undefined; | 8812 | self.* = undefined; |
src/Cache.zig+2-2| ... | @@ -1,4 +1,4 @@ | ... | @@ -1,4 +1,4 @@ |
| 1 | gpa: *Allocator, | 1 | gpa: Allocator, |
| 2 | manifest_dir: fs.Dir, | 2 | manifest_dir: fs.Dir, |
| 3 | hash: HashHelper = .{}, | 3 | hash: HashHelper = .{}, |
| 4 | 4 | ||
| ... | @@ -48,7 +48,7 @@ pub const File = struct { | ... | @@ -48,7 +48,7 @@ pub const File = struct { |
| 48 | bin_digest: BinDigest, | 48 | bin_digest: BinDigest, |
| 49 | contents: ?[]const u8, | 49 | contents: ?[]const u8, |
| 50 | 50 | ||
| 51 | pub fn deinit(self: *File, allocator: *Allocator) void { | 51 | pub fn deinit(self: *File, allocator: Allocator) void { |
| 52 | if (self.path) |owned_slice| { | 52 | if (self.path) |owned_slice| { |
| 53 | allocator.free(owned_slice); | 53 | allocator.free(owned_slice); |
| 54 | self.path = null; | 54 | self.path = null; |
src/Compilation.zig+22-22| ... | @@ -36,7 +36,7 @@ const libtsan = @import("libtsan.zig"); | ... | @@ -36,7 +36,7 @@ const libtsan = @import("libtsan.zig"); |
| 36 | const Zir = @import("Zir.zig"); | 36 | const Zir = @import("Zir.zig"); |
| 37 | 37 | ||
| 38 | /// General-purpose allocator. Used for both temporary and long-term storage. | 38 | /// General-purpose allocator. Used for both temporary and long-term storage. |
| 39 | gpa: *Allocator, | 39 | gpa: Allocator, |
| 40 | /// Arena-allocated memory used during initialization. Should be untouched until deinit. | 40 | /// Arena-allocated memory used during initialization. Should be untouched until deinit. |
| 41 | arena_state: std.heap.ArenaAllocator.State, | 41 | arena_state: std.heap.ArenaAllocator.State, |
| 42 | bin_file: *link.File, | 42 | bin_file: *link.File, |
| ... | @@ -164,7 +164,7 @@ pub const CRTFile = struct { | ... | @@ -164,7 +164,7 @@ pub const CRTFile = struct { |
| 164 | lock: Cache.Lock, | 164 | lock: Cache.Lock, |
| 165 | full_object_path: []const u8, | 165 | full_object_path: []const u8, |
| 166 | 166 | ||
| 167 | fn deinit(self: *CRTFile, gpa: *Allocator) void { | 167 | fn deinit(self: *CRTFile, gpa: Allocator) void { |
| 168 | self.lock.release(); | 168 | self.lock.release(); |
| 169 | gpa.free(self.full_object_path); | 169 | gpa.free(self.full_object_path); |
| 170 | self.* = undefined; | 170 | self.* = undefined; |
| ... | @@ -253,14 +253,14 @@ pub const CObject = struct { | ... | @@ -253,14 +253,14 @@ pub const CObject = struct { |
| 253 | line: u32, | 253 | line: u32, |
| 254 | column: u32, | 254 | column: u32, |
| 255 | 255 | ||
| 256 | pub fn destroy(em: *ErrorMsg, gpa: *Allocator) void { | 256 | pub fn destroy(em: *ErrorMsg, gpa: Allocator) void { |
| 257 | gpa.free(em.msg); | 257 | gpa.free(em.msg); |
| 258 | gpa.destroy(em); | 258 | gpa.destroy(em); |
| 259 | } | 259 | } |
| 260 | }; | 260 | }; |
| 261 | 261 | ||
| 262 | /// Returns if there was failure. | 262 | /// Returns if there was failure. |
| 263 | pub fn clearStatus(self: *CObject, gpa: *Allocator) bool { | 263 | pub fn clearStatus(self: *CObject, gpa: Allocator) bool { |
| 264 | switch (self.status) { | 264 | switch (self.status) { |
| 265 | .new => return false, | 265 | .new => return false, |
| 266 | .failure, .failure_retryable => { | 266 | .failure, .failure_retryable => { |
| ... | @@ -276,7 +276,7 @@ pub const CObject = struct { | ... | @@ -276,7 +276,7 @@ pub const CObject = struct { |
| 276 | } | 276 | } |
| 277 | } | 277 | } |
| 278 | 278 | ||
| 279 | pub fn destroy(self: *CObject, gpa: *Allocator) void { | 279 | pub fn destroy(self: *CObject, gpa: Allocator) void { |
| 280 | _ = self.clearStatus(gpa); | 280 | _ = self.clearStatus(gpa); |
| 281 | gpa.destroy(self); | 281 | gpa.destroy(self); |
| 282 | } | 282 | } |
| ... | @@ -305,7 +305,7 @@ pub const MiscError = struct { | ... | @@ -305,7 +305,7 @@ pub const MiscError = struct { |
| 305 | msg: []u8, | 305 | msg: []u8, |
| 306 | children: ?AllErrors = null, | 306 | children: ?AllErrors = null, |
| 307 | 307 | ||
| 308 | pub fn deinit(misc_err: *MiscError, gpa: *Allocator) void { | 308 | pub fn deinit(misc_err: *MiscError, gpa: Allocator) void { |
| 309 | gpa.free(misc_err.msg); | 309 | gpa.free(misc_err.msg); |
| 310 | if (misc_err.children) |*children| { | 310 | if (misc_err.children) |*children| { |
| 311 | children.deinit(gpa); | 311 | children.deinit(gpa); |
| ... | @@ -402,7 +402,7 @@ pub const AllErrors = struct { | ... | @@ -402,7 +402,7 @@ pub const AllErrors = struct { |
| 402 | } | 402 | } |
| 403 | }; | 403 | }; |
| 404 | 404 | ||
| 405 | pub fn deinit(self: *AllErrors, gpa: *Allocator) void { | 405 | pub fn deinit(self: *AllErrors, gpa: Allocator) void { |
| 406 | self.arena.promote(gpa).deinit(); | 406 | self.arena.promote(gpa).deinit(); |
| 407 | } | 407 | } |
| 408 | 408 | ||
| ... | @@ -456,7 +456,7 @@ pub const AllErrors = struct { | ... | @@ -456,7 +456,7 @@ pub const AllErrors = struct { |
| 456 | } | 456 | } |
| 457 | 457 | ||
| 458 | pub fn addZir( | 458 | pub fn addZir( |
| 459 | arena: *Allocator, | 459 | arena: Allocator, |
| 460 | errors: *std.ArrayList(Message), | 460 | errors: *std.ArrayList(Message), |
| 461 | file: *Module.File, | 461 | file: *Module.File, |
| 462 | ) !void { | 462 | ) !void { |
| ... | @@ -559,7 +559,7 @@ pub const AllErrors = struct { | ... | @@ -559,7 +559,7 @@ pub const AllErrors = struct { |
| 559 | } | 559 | } |
| 560 | } | 560 | } |
| 561 | 561 | ||
| 562 | fn dupeList(list: []const Message, arena: *Allocator) Allocator.Error![]Message { | 562 | fn dupeList(list: []const Message, arena: Allocator) Allocator.Error![]Message { |
| 563 | const duped_list = try arena.alloc(Message, list.len); | 563 | const duped_list = try arena.alloc(Message, list.len); |
| 564 | for (list) |item, i| { | 564 | for (list) |item, i| { |
| 565 | duped_list[i] = switch (item) { | 565 | duped_list[i] = switch (item) { |
| ... | @@ -589,7 +589,7 @@ pub const Directory = struct { | ... | @@ -589,7 +589,7 @@ pub const Directory = struct { |
| 589 | path: ?[]const u8, | 589 | path: ?[]const u8, |
| 590 | handle: std.fs.Dir, | 590 | handle: std.fs.Dir, |
| 591 | 591 | ||
| 592 | pub fn join(self: Directory, allocator: *Allocator, paths: []const []const u8) ![]u8 { | 592 | pub fn join(self: Directory, allocator: Allocator, paths: []const []const u8) ![]u8 { |
| 593 | if (self.path) |p| { | 593 | if (self.path) |p| { |
| 594 | // TODO clean way to do this with only 1 allocation | 594 | // TODO clean way to do this with only 1 allocation |
| 595 | const part2 = try std.fs.path.join(allocator, paths); | 595 | const part2 = try std.fs.path.join(allocator, paths); |
| ... | @@ -600,7 +600,7 @@ pub const Directory = struct { | ... | @@ -600,7 +600,7 @@ pub const Directory = struct { |
| 600 | } | 600 | } |
| 601 | } | 601 | } |
| 602 | 602 | ||
| 603 | pub fn joinZ(self: Directory, allocator: *Allocator, paths: []const []const u8) ![:0]u8 { | 603 | pub fn joinZ(self: Directory, allocator: Allocator, paths: []const []const u8) ![:0]u8 { |
| 604 | if (self.path) |p| { | 604 | if (self.path) |p| { |
| 605 | // TODO clean way to do this with only 1 allocation | 605 | // TODO clean way to do this with only 1 allocation |
| 606 | const part2 = try std.fs.path.join(allocator, paths); | 606 | const part2 = try std.fs.path.join(allocator, paths); |
| ... | @@ -829,7 +829,7 @@ fn addPackageTableToCacheHash( | ... | @@ -829,7 +829,7 @@ fn addPackageTableToCacheHash( |
| 829 | } | 829 | } |
| 830 | } | 830 | } |
| 831 | 831 | ||
| 832 | pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation { | 832 | pub fn create(gpa: Allocator, options: InitOptions) !*Compilation { |
| 833 | const is_dyn_lib = switch (options.output_mode) { | 833 | const is_dyn_lib = switch (options.output_mode) { |
| 834 | .Obj, .Exe => false, | 834 | .Obj, .Exe => false, |
| 835 | .Lib => (options.link_mode orelse .Static) == .Dynamic, | 835 | .Lib => (options.link_mode orelse .Static) == .Dynamic, |
| ... | @@ -3263,7 +3263,7 @@ fn updateCObject(comp: *Compilation, c_object: *CObject, c_obj_prog_node: *std.P | ... | @@ -3263,7 +3263,7 @@ fn updateCObject(comp: *Compilation, c_object: *CObject, c_obj_prog_node: *std.P |
| 3263 | }; | 3263 | }; |
| 3264 | } | 3264 | } |
| 3265 | 3265 | ||
| 3266 | pub fn tmpFilePath(comp: *Compilation, arena: *Allocator, suffix: []const u8) error{OutOfMemory}![]const u8 { | 3266 | pub fn tmpFilePath(comp: *Compilation, arena: Allocator, suffix: []const u8) error{OutOfMemory}![]const u8 { |
| 3267 | const s = std.fs.path.sep_str; | 3267 | const s = std.fs.path.sep_str; |
| 3268 | const rand_int = std.crypto.random.int(u64); | 3268 | const rand_int = std.crypto.random.int(u64); |
| 3269 | if (comp.local_cache_directory.path) |p| { | 3269 | if (comp.local_cache_directory.path) |p| { |
| ... | @@ -3275,7 +3275,7 @@ pub fn tmpFilePath(comp: *Compilation, arena: *Allocator, suffix: []const u8) er | ... | @@ -3275,7 +3275,7 @@ pub fn tmpFilePath(comp: *Compilation, arena: *Allocator, suffix: []const u8) er |
| 3275 | 3275 | ||
| 3276 | pub fn addTranslateCCArgs( | 3276 | pub fn addTranslateCCArgs( |
| 3277 | comp: *Compilation, | 3277 | comp: *Compilation, |
| 3278 | arena: *Allocator, | 3278 | arena: Allocator, |
| 3279 | argv: *std.ArrayList([]const u8), | 3279 | argv: *std.ArrayList([]const u8), |
| 3280 | ext: FileExt, | 3280 | ext: FileExt, |
| 3281 | out_dep_path: ?[]const u8, | 3281 | out_dep_path: ?[]const u8, |
| ... | @@ -3289,7 +3289,7 @@ pub fn addTranslateCCArgs( | ... | @@ -3289,7 +3289,7 @@ pub fn addTranslateCCArgs( |
| 3289 | /// Add common C compiler args between translate-c and C object compilation. | 3289 | /// Add common C compiler args between translate-c and C object compilation. |
| 3290 | pub fn addCCArgs( | 3290 | pub fn addCCArgs( |
| 3291 | comp: *const Compilation, | 3291 | comp: *const Compilation, |
| 3292 | arena: *Allocator, | 3292 | arena: Allocator, |
| 3293 | argv: *std.ArrayList([]const u8), | 3293 | argv: *std.ArrayList([]const u8), |
| 3294 | ext: FileExt, | 3294 | ext: FileExt, |
| 3295 | out_dep_path: ?[]const u8, | 3295 | out_dep_path: ?[]const u8, |
| ... | @@ -3776,7 +3776,7 @@ const LibCDirs = struct { | ... | @@ -3776,7 +3776,7 @@ const LibCDirs = struct { |
| 3776 | libc_installation: ?*const LibCInstallation, | 3776 | libc_installation: ?*const LibCInstallation, |
| 3777 | }; | 3777 | }; |
| 3778 | 3778 | ||
| 3779 | fn getZigShippedLibCIncludeDirsDarwin(arena: *Allocator, zig_lib_dir: []const u8, target: Target) !LibCDirs { | 3779 | fn getZigShippedLibCIncludeDirsDarwin(arena: Allocator, zig_lib_dir: []const u8, target: Target) !LibCDirs { |
| 3780 | const arch_name = @tagName(target.cpu.arch); | 3780 | const arch_name = @tagName(target.cpu.arch); |
| 3781 | const os_name = try std.fmt.allocPrint(arena, "{s}.{d}", .{ | 3781 | const os_name = try std.fmt.allocPrint(arena, "{s}.{d}", .{ |
| 3782 | @tagName(target.os.tag), | 3782 | @tagName(target.os.tag), |
| ... | @@ -3808,7 +3808,7 @@ fn getZigShippedLibCIncludeDirsDarwin(arena: *Allocator, zig_lib_dir: []const u8 | ... | @@ -3808,7 +3808,7 @@ fn getZigShippedLibCIncludeDirsDarwin(arena: *Allocator, zig_lib_dir: []const u8 |
| 3808 | } | 3808 | } |
| 3809 | 3809 | ||
| 3810 | fn detectLibCIncludeDirs( | 3810 | fn detectLibCIncludeDirs( |
| 3811 | arena: *Allocator, | 3811 | arena: Allocator, |
| 3812 | zig_lib_dir: []const u8, | 3812 | zig_lib_dir: []const u8, |
| 3813 | target: Target, | 3813 | target: Target, |
| 3814 | is_native_abi: bool, | 3814 | is_native_abi: bool, |
| ... | @@ -3933,7 +3933,7 @@ fn detectLibCIncludeDirs( | ... | @@ -3933,7 +3933,7 @@ fn detectLibCIncludeDirs( |
| 3933 | }; | 3933 | }; |
| 3934 | } | 3934 | } |
| 3935 | 3935 | ||
| 3936 | fn detectLibCFromLibCInstallation(arena: *Allocator, target: Target, lci: *const LibCInstallation) !LibCDirs { | 3936 | fn detectLibCFromLibCInstallation(arena: Allocator, target: Target, lci: *const LibCInstallation) !LibCDirs { |
| 3937 | var list = try std.ArrayList([]const u8).initCapacity(arena, 4); | 3937 | var list = try std.ArrayList([]const u8).initCapacity(arena, 4); |
| 3938 | 3938 | ||
| 3939 | list.appendAssumeCapacity(lci.include_dir.?); | 3939 | list.appendAssumeCapacity(lci.include_dir.?); |
| ... | @@ -3965,7 +3965,7 @@ fn detectLibCFromLibCInstallation(arena: *Allocator, target: Target, lci: *const | ... | @@ -3965,7 +3965,7 @@ fn detectLibCFromLibCInstallation(arena: *Allocator, target: Target, lci: *const |
| 3965 | }; | 3965 | }; |
| 3966 | } | 3966 | } |
| 3967 | 3967 | ||
| 3968 | pub fn get_libc_crt_file(comp: *Compilation, arena: *Allocator, basename: []const u8) ![]const u8 { | 3968 | pub fn get_libc_crt_file(comp: *Compilation, arena: Allocator, basename: []const u8) ![]const u8 { |
| 3969 | if (comp.wantBuildGLibCFromSource() or | 3969 | if (comp.wantBuildGLibCFromSource() or |
| 3970 | comp.wantBuildMuslFromSource() or | 3970 | comp.wantBuildMuslFromSource() or |
| 3971 | comp.wantBuildMinGWFromSource() or | 3971 | comp.wantBuildMinGWFromSource() or |
| ... | @@ -4066,7 +4066,7 @@ pub fn dump_argv(argv: []const []const u8) void { | ... | @@ -4066,7 +4066,7 @@ pub fn dump_argv(argv: []const []const u8) void { |
| 4066 | std.debug.print("{s}\n", .{argv[argv.len - 1]}); | 4066 | std.debug.print("{s}\n", .{argv[argv.len - 1]}); |
| 4067 | } | 4067 | } |
| 4068 | 4068 | ||
| 4069 | pub fn generateBuiltinZigSource(comp: *Compilation, allocator: *Allocator) Allocator.Error![]u8 { | 4069 | pub fn generateBuiltinZigSource(comp: *Compilation, allocator: Allocator) Allocator.Error![]u8 { |
| 4070 | const t = trace(@src()); | 4070 | const t = trace(@src()); |
| 4071 | defer t.end(); | 4071 | defer t.end(); |
| 4072 | 4072 | ||
| ... | @@ -4717,14 +4717,14 @@ fn updateStage1Module(comp: *Compilation, main_progress_node: *std.Progress.Node | ... | @@ -4717,14 +4717,14 @@ fn updateStage1Module(comp: *Compilation, main_progress_node: *std.Progress.Node |
| 4717 | comp.stage1_lock = man.toOwnedLock(); | 4717 | comp.stage1_lock = man.toOwnedLock(); |
| 4718 | } | 4718 | } |
| 4719 | 4719 | ||
| 4720 | fn stage1LocPath(arena: *Allocator, opt_loc: ?EmitLoc, cache_directory: Directory) ![]const u8 { | 4720 | fn stage1LocPath(arena: Allocator, opt_loc: ?EmitLoc, cache_directory: Directory) ![]const u8 { |
| 4721 | const loc = opt_loc orelse return ""; | 4721 | const loc = opt_loc orelse return ""; |
| 4722 | const directory = loc.directory orelse cache_directory; | 4722 | const directory = loc.directory orelse cache_directory; |
| 4723 | return directory.join(arena, &[_][]const u8{loc.basename}); | 4723 | return directory.join(arena, &[_][]const u8{loc.basename}); |
| 4724 | } | 4724 | } |
| 4725 | 4725 | ||
| 4726 | fn createStage1Pkg( | 4726 | fn createStage1Pkg( |
| 4727 | arena: *Allocator, | 4727 | arena: Allocator, |
| 4728 | name: []const u8, | 4728 | name: []const u8, |
| 4729 | pkg: *Package, | 4729 | pkg: *Package, |
| 4730 | parent_pkg: ?*stage1.Pkg, | 4730 | parent_pkg: ?*stage1.Pkg, |
src/Liveness.zig+3-3| ... | @@ -51,7 +51,7 @@ pub const SwitchBr = struct { | ... | @@ -51,7 +51,7 @@ pub const SwitchBr = struct { |
| 51 | else_death_count: u32, | 51 | else_death_count: u32, |
| 52 | }; | 52 | }; |
| 53 | 53 | ||
| 54 | pub fn analyze(gpa: *Allocator, air: Air, zir: Zir) Allocator.Error!Liveness { | 54 | pub fn analyze(gpa: Allocator, air: Air, zir: Zir) Allocator.Error!Liveness { |
| 55 | const tracy = trace(@src()); | 55 | const tracy = trace(@src()); |
| 56 | defer tracy.end(); | 56 | defer tracy.end(); |
| 57 | 57 | ||
| ... | @@ -136,7 +136,7 @@ pub fn getCondBr(l: Liveness, inst: Air.Inst.Index) CondBrSlices { | ... | @@ -136,7 +136,7 @@ pub fn getCondBr(l: Liveness, inst: Air.Inst.Index) CondBrSlices { |
| 136 | }; | 136 | }; |
| 137 | } | 137 | } |
| 138 | 138 | ||
| 139 | pub fn deinit(l: *Liveness, gpa: *Allocator) void { | 139 | pub fn deinit(l: *Liveness, gpa: Allocator) void { |
| 140 | gpa.free(l.tomb_bits); | 140 | gpa.free(l.tomb_bits); |
| 141 | gpa.free(l.extra); | 141 | gpa.free(l.extra); |
| 142 | l.special.deinit(gpa); | 142 | l.special.deinit(gpa); |
| ... | @@ -150,7 +150,7 @@ pub const OperandInt = std.math.Log2Int(Bpi); | ... | @@ -150,7 +150,7 @@ pub const OperandInt = std.math.Log2Int(Bpi); |
| 150 | 150 | ||
| 151 | /// In-progress data; on successful analysis converted into `Liveness`. | 151 | /// In-progress data; on successful analysis converted into `Liveness`. |
| 152 | const Analysis = struct { | 152 | const Analysis = struct { |
| 153 | gpa: *Allocator, | 153 | gpa: Allocator, |
| 154 | air: Air, | 154 | air: Air, |
| 155 | table: std.AutoHashMapUnmanaged(Air.Inst.Index, void), | 155 | table: std.AutoHashMapUnmanaged(Air.Inst.Index, void), |
| 156 | tomb_bits: []usize, | 156 | tomb_bits: []usize, |
src/Module.zig+33-33| ... | @@ -30,7 +30,7 @@ const target_util = @import("target.zig"); | ... | @@ -30,7 +30,7 @@ const target_util = @import("target.zig"); |
| 30 | const build_options = @import("build_options"); | 30 | const build_options = @import("build_options"); |
| 31 | 31 | ||
| 32 | /// General-purpose allocator. Used for both temporary and long-term storage. | 32 | /// General-purpose allocator. Used for both temporary and long-term storage. |
| 33 | gpa: *Allocator, | 33 | gpa: Allocator, |
| 34 | comp: *Compilation, | 34 | comp: *Compilation, |
| 35 | 35 | ||
| 36 | /// Where our incremental compilation metadata serialization will go. | 36 | /// Where our incremental compilation metadata serialization will go. |
| ... | @@ -299,10 +299,10 @@ pub const CaptureScope = struct { | ... | @@ -299,10 +299,10 @@ pub const CaptureScope = struct { |
| 299 | pub const WipCaptureScope = struct { | 299 | pub const WipCaptureScope = struct { |
| 300 | scope: *CaptureScope, | 300 | scope: *CaptureScope, |
| 301 | finalized: bool, | 301 | finalized: bool, |
| 302 | gpa: *Allocator, | 302 | gpa: Allocator, |
| 303 | perm_arena: *Allocator, | 303 | perm_arena: Allocator, |
| 304 | 304 | ||
| 305 | pub fn init(gpa: *Allocator, perm_arena: *Allocator, parent: ?*CaptureScope) !@This() { | 305 | pub fn init(gpa: Allocator, perm_arena: Allocator, parent: ?*CaptureScope) !@This() { |
| 306 | const scope = try perm_arena.create(CaptureScope); | 306 | const scope = try perm_arena.create(CaptureScope); |
| 307 | scope.* = .{ .parent = parent }; | 307 | scope.* = .{ .parent = parent }; |
| 308 | return @This(){ | 308 | return @This(){ |
| ... | @@ -469,7 +469,7 @@ pub const Decl = struct { | ... | @@ -469,7 +469,7 @@ pub const Decl = struct { |
| 469 | 469 | ||
| 470 | pub const DepsTable = std.AutoArrayHashMapUnmanaged(*Decl, void); | 470 | pub const DepsTable = std.AutoArrayHashMapUnmanaged(*Decl, void); |
| 471 | 471 | ||
| 472 | pub fn clearName(decl: *Decl, gpa: *Allocator) void { | 472 | pub fn clearName(decl: *Decl, gpa: Allocator) void { |
| 473 | gpa.free(mem.sliceTo(decl.name, 0)); | 473 | gpa.free(mem.sliceTo(decl.name, 0)); |
| 474 | decl.name = undefined; | 474 | decl.name = undefined; |
| 475 | } | 475 | } |
| ... | @@ -499,7 +499,7 @@ pub const Decl = struct { | ... | @@ -499,7 +499,7 @@ pub const Decl = struct { |
| 499 | } | 499 | } |
| 500 | } | 500 | } |
| 501 | 501 | ||
| 502 | pub fn clearValues(decl: *Decl, gpa: *Allocator) void { | 502 | pub fn clearValues(decl: *Decl, gpa: Allocator) void { |
| 503 | if (decl.getFunction()) |func| { | 503 | if (decl.getFunction()) |func| { |
| 504 | func.deinit(gpa); | 504 | func.deinit(gpa); |
| 505 | gpa.destroy(func); | 505 | gpa.destroy(func); |
| ... | @@ -636,7 +636,7 @@ pub const Decl = struct { | ... | @@ -636,7 +636,7 @@ pub const Decl = struct { |
| 636 | return decl.src_namespace.renderFullyQualifiedDebugName(unqualified_name, writer); | 636 | return decl.src_namespace.renderFullyQualifiedDebugName(unqualified_name, writer); |
| 637 | } | 637 | } |
| 638 | 638 | ||
| 639 | pub fn getFullyQualifiedName(decl: Decl, gpa: *Allocator) ![:0]u8 { | 639 | pub fn getFullyQualifiedName(decl: Decl, gpa: Allocator) ![:0]u8 { |
| 640 | var buffer = std.ArrayList(u8).init(gpa); | 640 | var buffer = std.ArrayList(u8).init(gpa); |
| 641 | defer buffer.deinit(); | 641 | defer buffer.deinit(); |
| 642 | try decl.renderFullyQualifiedName(buffer.writer()); | 642 | try decl.renderFullyQualifiedName(buffer.writer()); |
| ... | @@ -855,7 +855,7 @@ pub const Struct = struct { | ... | @@ -855,7 +855,7 @@ pub const Struct = struct { |
| 855 | is_comptime: bool, | 855 | is_comptime: bool, |
| 856 | }; | 856 | }; |
| 857 | 857 | ||
| 858 | pub fn getFullyQualifiedName(s: *Struct, gpa: *Allocator) ![:0]u8 { | 858 | pub fn getFullyQualifiedName(s: *Struct, gpa: Allocator) ![:0]u8 { |
| 859 | return s.owner_decl.getFullyQualifiedName(gpa); | 859 | return s.owner_decl.getFullyQualifiedName(gpa); |
| 860 | } | 860 | } |
| 861 | 861 | ||
| ... | @@ -999,7 +999,7 @@ pub const Union = struct { | ... | @@ -999,7 +999,7 @@ pub const Union = struct { |
| 999 | 999 | ||
| 1000 | pub const Fields = std.StringArrayHashMapUnmanaged(Field); | 1000 | pub const Fields = std.StringArrayHashMapUnmanaged(Field); |
| 1001 | 1001 | ||
| 1002 | pub fn getFullyQualifiedName(s: *Union, gpa: *Allocator) ![:0]u8 { | 1002 | pub fn getFullyQualifiedName(s: *Union, gpa: Allocator) ![:0]u8 { |
| 1003 | return s.owner_decl.getFullyQualifiedName(gpa); | 1003 | return s.owner_decl.getFullyQualifiedName(gpa); |
| 1004 | } | 1004 | } |
| 1005 | 1005 | ||
| ... | @@ -1178,7 +1178,7 @@ pub const Opaque = struct { | ... | @@ -1178,7 +1178,7 @@ pub const Opaque = struct { |
| 1178 | }; | 1178 | }; |
| 1179 | } | 1179 | } |
| 1180 | 1180 | ||
| 1181 | pub fn getFullyQualifiedName(s: *Opaque, gpa: *Allocator) ![:0]u8 { | 1181 | pub fn getFullyQualifiedName(s: *Opaque, gpa: Allocator) ![:0]u8 { |
| 1182 | return s.owner_decl.getFullyQualifiedName(gpa); | 1182 | return s.owner_decl.getFullyQualifiedName(gpa); |
| 1183 | } | 1183 | } |
| 1184 | }; | 1184 | }; |
| ... | @@ -1225,7 +1225,7 @@ pub const Fn = struct { | ... | @@ -1225,7 +1225,7 @@ pub const Fn = struct { |
| 1225 | success, | 1225 | success, |
| 1226 | }; | 1226 | }; |
| 1227 | 1227 | ||
| 1228 | pub fn deinit(func: *Fn, gpa: *Allocator) void { | 1228 | pub fn deinit(func: *Fn, gpa: Allocator) void { |
| 1229 | if (func.getInferredErrorSet()) |map| { | 1229 | if (func.getInferredErrorSet()) |map| { |
| 1230 | map.deinit(gpa); | 1230 | map.deinit(gpa); |
| 1231 | } | 1231 | } |
| ... | @@ -1422,27 +1422,27 @@ pub const File = struct { | ... | @@ -1422,27 +1422,27 @@ pub const File = struct { |
| 1422 | /// successful, this field is unloaded. | 1422 | /// successful, this field is unloaded. |
| 1423 | prev_zir: ?*Zir = null, | 1423 | prev_zir: ?*Zir = null, |
| 1424 | 1424 | ||
| 1425 | pub fn unload(file: *File, gpa: *Allocator) void { | 1425 | pub fn unload(file: *File, gpa: Allocator) void { |
| 1426 | file.unloadTree(gpa); | 1426 | file.unloadTree(gpa); |
| 1427 | file.unloadSource(gpa); | 1427 | file.unloadSource(gpa); |
| 1428 | file.unloadZir(gpa); | 1428 | file.unloadZir(gpa); |
| 1429 | } | 1429 | } |
| 1430 | 1430 | ||
| 1431 | pub fn unloadTree(file: *File, gpa: *Allocator) void { | 1431 | pub fn unloadTree(file: *File, gpa: Allocator) void { |
| 1432 | if (file.tree_loaded) { | 1432 | if (file.tree_loaded) { |
| 1433 | file.tree_loaded = false; | 1433 | file.tree_loaded = false; |
| 1434 | file.tree.deinit(gpa); | 1434 | file.tree.deinit(gpa); |
| 1435 | } | 1435 | } |
| 1436 | } | 1436 | } |
| 1437 | 1437 | ||
| 1438 | pub fn unloadSource(file: *File, gpa: *Allocator) void { | 1438 | pub fn unloadSource(file: *File, gpa: Allocator) void { |
| 1439 | if (file.source_loaded) { | 1439 | if (file.source_loaded) { |
| 1440 | file.source_loaded = false; | 1440 | file.source_loaded = false; |
| 1441 | gpa.free(file.source); | 1441 | gpa.free(file.source); |
| 1442 | } | 1442 | } |
| 1443 | } | 1443 | } |
| 1444 | 1444 | ||
| 1445 | pub fn unloadZir(file: *File, gpa: *Allocator) void { | 1445 | pub fn unloadZir(file: *File, gpa: Allocator) void { |
| 1446 | if (file.zir_loaded) { | 1446 | if (file.zir_loaded) { |
| 1447 | file.zir_loaded = false; | 1447 | file.zir_loaded = false; |
| 1448 | file.zir.deinit(gpa); | 1448 | file.zir.deinit(gpa); |
| ... | @@ -1466,7 +1466,7 @@ pub const File = struct { | ... | @@ -1466,7 +1466,7 @@ pub const File = struct { |
| 1466 | file.* = undefined; | 1466 | file.* = undefined; |
| 1467 | } | 1467 | } |
| 1468 | 1468 | ||
| 1469 | pub fn getSource(file: *File, gpa: *Allocator) ![:0]const u8 { | 1469 | pub fn getSource(file: *File, gpa: Allocator) ![:0]const u8 { |
| 1470 | if (file.source_loaded) return file.source; | 1470 | if (file.source_loaded) return file.source; |
| 1471 | 1471 | ||
| 1472 | const root_dir_path = file.pkg.root_src_directory.path orelse "."; | 1472 | const root_dir_path = file.pkg.root_src_directory.path orelse "."; |
| ... | @@ -1499,7 +1499,7 @@ pub const File = struct { | ... | @@ -1499,7 +1499,7 @@ pub const File = struct { |
| 1499 | return source; | 1499 | return source; |
| 1500 | } | 1500 | } |
| 1501 | 1501 | ||
| 1502 | pub fn getTree(file: *File, gpa: *Allocator) !*const Ast { | 1502 | pub fn getTree(file: *File, gpa: Allocator) !*const Ast { |
| 1503 | if (file.tree_loaded) return &file.tree; | 1503 | if (file.tree_loaded) return &file.tree; |
| 1504 | 1504 | ||
| 1505 | const source = try file.getSource(gpa); | 1505 | const source = try file.getSource(gpa); |
| ... | @@ -1531,7 +1531,7 @@ pub const File = struct { | ... | @@ -1531,7 +1531,7 @@ pub const File = struct { |
| 1531 | }; | 1531 | }; |
| 1532 | } | 1532 | } |
| 1533 | 1533 | ||
| 1534 | pub fn fullyQualifiedNameZ(file: File, gpa: *Allocator) ![:0]u8 { | 1534 | pub fn fullyQualifiedNameZ(file: File, gpa: Allocator) ![:0]u8 { |
| 1535 | var buf = std.ArrayList(u8).init(gpa); | 1535 | var buf = std.ArrayList(u8).init(gpa); |
| 1536 | defer buf.deinit(); | 1536 | defer buf.deinit(); |
| 1537 | try file.renderFullyQualifiedName(buf.writer()); | 1537 | try file.renderFullyQualifiedName(buf.writer()); |
| ... | @@ -1539,7 +1539,7 @@ pub const File = struct { | ... | @@ -1539,7 +1539,7 @@ pub const File = struct { |
| 1539 | } | 1539 | } |
| 1540 | 1540 | ||
| 1541 | /// Returns the full path to this file relative to its package. | 1541 | /// Returns the full path to this file relative to its package. |
| 1542 | pub fn fullPath(file: File, ally: *Allocator) ![]u8 { | 1542 | pub fn fullPath(file: File, ally: Allocator) ![]u8 { |
| 1543 | return file.pkg.root_src_directory.join(ally, &[_][]const u8{file.sub_file_path}); | 1543 | return file.pkg.root_src_directory.join(ally, &[_][]const u8{file.sub_file_path}); |
| 1544 | } | 1544 | } |
| 1545 | 1545 | ||
| ... | @@ -1594,7 +1594,7 @@ pub const ErrorMsg = struct { | ... | @@ -1594,7 +1594,7 @@ pub const ErrorMsg = struct { |
| 1594 | notes: []ErrorMsg = &.{}, | 1594 | notes: []ErrorMsg = &.{}, |
| 1595 | 1595 | ||
| 1596 | pub fn create( | 1596 | pub fn create( |
| 1597 | gpa: *Allocator, | 1597 | gpa: Allocator, |
| 1598 | src_loc: SrcLoc, | 1598 | src_loc: SrcLoc, |
| 1599 | comptime format: []const u8, | 1599 | comptime format: []const u8, |
| 1600 | args: anytype, | 1600 | args: anytype, |
| ... | @@ -1607,13 +1607,13 @@ pub const ErrorMsg = struct { | ... | @@ -1607,13 +1607,13 @@ pub const ErrorMsg = struct { |
| 1607 | 1607 | ||
| 1608 | /// Assumes the ErrorMsg struct and msg were both allocated with `gpa`, | 1608 | /// Assumes the ErrorMsg struct and msg were both allocated with `gpa`, |
| 1609 | /// as well as all notes. | 1609 | /// as well as all notes. |
| 1610 | pub fn destroy(err_msg: *ErrorMsg, gpa: *Allocator) void { | 1610 | pub fn destroy(err_msg: *ErrorMsg, gpa: Allocator) void { |
| 1611 | err_msg.deinit(gpa); | 1611 | err_msg.deinit(gpa); |
| 1612 | gpa.destroy(err_msg); | 1612 | gpa.destroy(err_msg); |
| 1613 | } | 1613 | } |
| 1614 | 1614 | ||
| 1615 | pub fn init( | 1615 | pub fn init( |
| 1616 | gpa: *Allocator, | 1616 | gpa: Allocator, |
| 1617 | src_loc: SrcLoc, | 1617 | src_loc: SrcLoc, |
| 1618 | comptime format: []const u8, | 1618 | comptime format: []const u8, |
| 1619 | args: anytype, | 1619 | args: anytype, |
| ... | @@ -1624,7 +1624,7 @@ pub const ErrorMsg = struct { | ... | @@ -1624,7 +1624,7 @@ pub const ErrorMsg = struct { |
| 1624 | }; | 1624 | }; |
| 1625 | } | 1625 | } |
| 1626 | 1626 | ||
| 1627 | pub fn deinit(err_msg: *ErrorMsg, gpa: *Allocator) void { | 1627 | pub fn deinit(err_msg: *ErrorMsg, gpa: Allocator) void { |
| 1628 | for (err_msg.notes) |*note| { | 1628 | for (err_msg.notes) |*note| { |
| 1629 | note.deinit(gpa); | 1629 | note.deinit(gpa); |
| 1630 | } | 1630 | } |
| ... | @@ -1651,7 +1651,7 @@ pub const SrcLoc = struct { | ... | @@ -1651,7 +1651,7 @@ pub const SrcLoc = struct { |
| 1651 | return @bitCast(Ast.Node.Index, offset + @bitCast(i32, src_loc.parent_decl_node)); | 1651 | return @bitCast(Ast.Node.Index, offset + @bitCast(i32, src_loc.parent_decl_node)); |
| 1652 | } | 1652 | } |
| 1653 | 1653 | ||
| 1654 | pub fn byteOffset(src_loc: SrcLoc, gpa: *Allocator) !u32 { | 1654 | pub fn byteOffset(src_loc: SrcLoc, gpa: Allocator) !u32 { |
| 1655 | switch (src_loc.lazy) { | 1655 | switch (src_loc.lazy) { |
| 1656 | .unneeded => unreachable, | 1656 | .unneeded => unreachable, |
| 1657 | .entire_file => return 0, | 1657 | .entire_file => return 0, |
| ... | @@ -2066,7 +2066,7 @@ pub const SrcLoc = struct { | ... | @@ -2066,7 +2066,7 @@ pub const SrcLoc = struct { |
| 2066 | 2066 | ||
| 2067 | pub fn byteOffsetBuiltinCallArg( | 2067 | pub fn byteOffsetBuiltinCallArg( |
| 2068 | src_loc: SrcLoc, | 2068 | src_loc: SrcLoc, |
| 2069 | gpa: *Allocator, | 2069 | gpa: Allocator, |
| 2070 | node_off: i32, | 2070 | node_off: i32, |
| 2071 | arg_index: u32, | 2071 | arg_index: u32, |
| 2072 | ) !u32 { | 2072 | ) !u32 { |
| ... | @@ -2464,7 +2464,7 @@ pub fn deinit(mod: *Module) void { | ... | @@ -2464,7 +2464,7 @@ pub fn deinit(mod: *Module) void { |
| 2464 | } | 2464 | } |
| 2465 | } | 2465 | } |
| 2466 | 2466 | ||
| 2467 | fn freeExportList(gpa: *Allocator, export_list: []*Export) void { | 2467 | fn freeExportList(gpa: Allocator, export_list: []*Export) void { |
| 2468 | for (export_list) |exp| { | 2468 | for (export_list) |exp| { |
| 2469 | gpa.free(exp.options.name); | 2469 | gpa.free(exp.options.name); |
| 2470 | if (exp.options.section) |s| gpa.free(s); | 2470 | if (exp.options.section) |s| gpa.free(s); |
| ... | @@ -2871,7 +2871,7 @@ pub fn astGenFile(mod: *Module, file: *File) !void { | ... | @@ -2871,7 +2871,7 @@ pub fn astGenFile(mod: *Module, file: *File) !void { |
| 2871 | /// * Decl.zir_index | 2871 | /// * Decl.zir_index |
| 2872 | /// * Fn.zir_body_inst | 2872 | /// * Fn.zir_body_inst |
| 2873 | /// * Decl.zir_decl_index | 2873 | /// * Decl.zir_decl_index |
| 2874 | fn updateZirRefs(gpa: *Allocator, file: *File, old_zir: Zir) !void { | 2874 | fn updateZirRefs(gpa: Allocator, file: *File, old_zir: Zir) !void { |
| 2875 | const new_zir = file.zir; | 2875 | const new_zir = file.zir; |
| 2876 | 2876 | ||
| 2877 | // Maps from old ZIR to new ZIR, struct_decl, enum_decl, etc. Any instruction which | 2877 | // Maps from old ZIR to new ZIR, struct_decl, enum_decl, etc. Any instruction which |
| ... | @@ -2965,7 +2965,7 @@ fn updateZirRefs(gpa: *Allocator, file: *File, old_zir: Zir) !void { | ... | @@ -2965,7 +2965,7 @@ fn updateZirRefs(gpa: *Allocator, file: *File, old_zir: Zir) !void { |
| 2965 | } | 2965 | } |
| 2966 | 2966 | ||
| 2967 | pub fn mapOldZirToNew( | 2967 | pub fn mapOldZirToNew( |
| 2968 | gpa: *Allocator, | 2968 | gpa: Allocator, |
| 2969 | old_zir: Zir, | 2969 | old_zir: Zir, |
| 2970 | new_zir: Zir, | 2970 | new_zir: Zir, |
| 2971 | inst_map: *std.AutoHashMapUnmanaged(Zir.Inst.Index, Zir.Inst.Index), | 2971 | inst_map: *std.AutoHashMapUnmanaged(Zir.Inst.Index, Zir.Inst.Index), |
| ... | @@ -4119,7 +4119,7 @@ fn deleteDeclExports(mod: *Module, decl: *Decl) void { | ... | @@ -4119,7 +4119,7 @@ fn deleteDeclExports(mod: *Module, decl: *Decl) void { |
| 4119 | mod.gpa.free(kv.value); | 4119 | mod.gpa.free(kv.value); |
| 4120 | } | 4120 | } |
| 4121 | 4121 | ||
| 4122 | pub fn analyzeFnBody(mod: *Module, decl: *Decl, func: *Fn, arena: *Allocator) SemaError!Air { | 4122 | pub fn analyzeFnBody(mod: *Module, decl: *Decl, func: *Fn, arena: Allocator) SemaError!Air { |
| 4123 | const tracy = trace(@src()); | 4123 | const tracy = trace(@src()); |
| 4124 | defer tracy.end(); | 4124 | defer tracy.end(); |
| 4125 | 4125 | ||
| ... | @@ -4427,7 +4427,7 @@ pub fn getNextAnonNameIndex(mod: *Module) usize { | ... | @@ -4427,7 +4427,7 @@ pub fn getNextAnonNameIndex(mod: *Module) usize { |
| 4427 | return @atomicRmw(usize, &mod.next_anon_name_index, .Add, 1, .Monotonic); | 4427 | return @atomicRmw(usize, &mod.next_anon_name_index, .Add, 1, .Monotonic); |
| 4428 | } | 4428 | } |
| 4429 | 4429 | ||
| 4430 | pub fn makeIntType(arena: *Allocator, signedness: std.builtin.Signedness, bits: u16) !Type { | 4430 | pub fn makeIntType(arena: Allocator, signedness: std.builtin.Signedness, bits: u16) !Type { |
| 4431 | const int_payload = try arena.create(Type.Payload.Bits); | 4431 | const int_payload = try arena.create(Type.Payload.Bits); |
| 4432 | int_payload.* = .{ | 4432 | int_payload.* = .{ |
| 4433 | .base = .{ | 4433 | .base = .{ |
| ... | @@ -4459,7 +4459,7 @@ pub fn errNoteNonLazy( | ... | @@ -4459,7 +4459,7 @@ pub fn errNoteNonLazy( |
| 4459 | } | 4459 | } |
| 4460 | 4460 | ||
| 4461 | pub fn errorUnionType( | 4461 | pub fn errorUnionType( |
| 4462 | arena: *Allocator, | 4462 | arena: Allocator, |
| 4463 | error_set: Type, | 4463 | error_set: Type, |
| 4464 | payload: Type, | 4464 | payload: Type, |
| 4465 | ) Allocator.Error!Type { | 4465 | ) Allocator.Error!Type { |
| ... | @@ -4511,7 +4511,7 @@ pub const SwitchProngSrc = union(enum) { | ... | @@ -4511,7 +4511,7 @@ pub const SwitchProngSrc = union(enum) { |
| 4511 | /// the LazySrcLoc in order to emit a compile error. | 4511 | /// the LazySrcLoc in order to emit a compile error. |
| 4512 | pub fn resolve( | 4512 | pub fn resolve( |
| 4513 | prong_src: SwitchProngSrc, | 4513 | prong_src: SwitchProngSrc, |
| 4514 | gpa: *Allocator, | 4514 | gpa: Allocator, |
| 4515 | decl: *Decl, | 4515 | decl: *Decl, |
| 4516 | switch_node_offset: i32, | 4516 | switch_node_offset: i32, |
| 4517 | range_expand: RangeExpand, | 4517 | range_expand: RangeExpand, |
| ... | @@ -4605,7 +4605,7 @@ pub const PeerTypeCandidateSrc = union(enum) { | ... | @@ -4605,7 +4605,7 @@ pub const PeerTypeCandidateSrc = union(enum) { |
| 4605 | 4605 | ||
| 4606 | pub fn resolve( | 4606 | pub fn resolve( |
| 4607 | self: PeerTypeCandidateSrc, | 4607 | self: PeerTypeCandidateSrc, |
| 4608 | gpa: *Allocator, | 4608 | gpa: Allocator, |
| 4609 | decl: *Decl, | 4609 | decl: *Decl, |
| 4610 | candidate_i: usize, | 4610 | candidate_i: usize, |
| 4611 | ) ?LazySrcLoc { | 4611 | ) ?LazySrcLoc { |
src/Package.zig+6-6| ... | @@ -21,7 +21,7 @@ root_src_directory_owned: bool = false, | ... | @@ -21,7 +21,7 @@ root_src_directory_owned: bool = false, |
| 21 | 21 | ||
| 22 | /// Allocate a Package. No references to the slices passed are kept. | 22 | /// Allocate a Package. No references to the slices passed are kept. |
| 23 | pub fn create( | 23 | pub fn create( |
| 24 | gpa: *Allocator, | 24 | gpa: Allocator, |
| 25 | /// Null indicates the current working directory | 25 | /// Null indicates the current working directory |
| 26 | root_src_dir_path: ?[]const u8, | 26 | root_src_dir_path: ?[]const u8, |
| 27 | /// Relative to root_src_dir_path | 27 | /// Relative to root_src_dir_path |
| ... | @@ -49,7 +49,7 @@ pub fn create( | ... | @@ -49,7 +49,7 @@ pub fn create( |
| 49 | } | 49 | } |
| 50 | 50 | ||
| 51 | pub fn createWithDir( | 51 | pub fn createWithDir( |
| 52 | gpa: *Allocator, | 52 | gpa: Allocator, |
| 53 | directory: Compilation.Directory, | 53 | directory: Compilation.Directory, |
| 54 | /// Relative to `directory`. If null, means `directory` is the root src dir | 54 | /// Relative to `directory`. If null, means `directory` is the root src dir |
| 55 | /// and is owned externally. | 55 | /// and is owned externally. |
| ... | @@ -87,7 +87,7 @@ pub fn createWithDir( | ... | @@ -87,7 +87,7 @@ pub fn createWithDir( |
| 87 | 87 | ||
| 88 | /// Free all memory associated with this package. It does not destroy any packages | 88 | /// Free all memory associated with this package. It does not destroy any packages |
| 89 | /// inside its table; the caller is responsible for calling destroy() on them. | 89 | /// inside its table; the caller is responsible for calling destroy() on them. |
| 90 | pub fn destroy(pkg: *Package, gpa: *Allocator) void { | 90 | pub fn destroy(pkg: *Package, gpa: Allocator) void { |
| 91 | gpa.free(pkg.root_src_path); | 91 | gpa.free(pkg.root_src_path); |
| 92 | 92 | ||
| 93 | if (pkg.root_src_directory_owned) { | 93 | if (pkg.root_src_directory_owned) { |
| ... | @@ -104,7 +104,7 @@ pub fn destroy(pkg: *Package, gpa: *Allocator) void { | ... | @@ -104,7 +104,7 @@ pub fn destroy(pkg: *Package, gpa: *Allocator) void { |
| 104 | } | 104 | } |
| 105 | 105 | ||
| 106 | /// Only frees memory associated with the table. | 106 | /// Only frees memory associated with the table. |
| 107 | pub fn deinitTable(pkg: *Package, gpa: *Allocator) void { | 107 | pub fn deinitTable(pkg: *Package, gpa: Allocator) void { |
| 108 | var it = pkg.table.keyIterator(); | 108 | var it = pkg.table.keyIterator(); |
| 109 | while (it.next()) |key| { | 109 | while (it.next()) |key| { |
| 110 | gpa.free(key.*); | 110 | gpa.free(key.*); |
| ... | @@ -113,13 +113,13 @@ pub fn deinitTable(pkg: *Package, gpa: *Allocator) void { | ... | @@ -113,13 +113,13 @@ pub fn deinitTable(pkg: *Package, gpa: *Allocator) void { |
| 113 | pkg.table.deinit(gpa); | 113 | pkg.table.deinit(gpa); |
| 114 | } | 114 | } |
| 115 | 115 | ||
| 116 | pub fn add(pkg: *Package, gpa: *Allocator, name: []const u8, package: *Package) !void { | 116 | pub fn add(pkg: *Package, gpa: Allocator, name: []const u8, package: *Package) !void { |
| 117 | try pkg.table.ensureUnusedCapacity(gpa, 1); | 117 | try pkg.table.ensureUnusedCapacity(gpa, 1); |
| 118 | const name_dupe = try gpa.dupe(u8, name); | 118 | const name_dupe = try gpa.dupe(u8, name); |
| 119 | pkg.table.putAssumeCapacityNoClobber(name_dupe, package); | 119 | pkg.table.putAssumeCapacityNoClobber(name_dupe, package); |
| 120 | } | 120 | } |
| 121 | 121 | ||
| 122 | pub fn addAndAdopt(parent: *Package, gpa: *Allocator, name: []const u8, child: *Package) !void { | 122 | pub fn addAndAdopt(parent: *Package, gpa: Allocator, name: []const u8, child: *Package) !void { |
| 123 | assert(child.parent == null); // make up your mind, who is the parent?? | 123 | assert(child.parent == null); // make up your mind, who is the parent?? |
| 124 | child.parent = parent; | 124 | child.parent = parent; |
| 125 | return parent.add(gpa, name, child); | 125 | return parent.add(gpa, name, child); |
src/RangeSet.zig+1-1| ... | @@ -13,7 +13,7 @@ pub const Range = struct { | ... | @@ -13,7 +13,7 @@ pub const Range = struct { |
| 13 | src: SwitchProngSrc, | 13 | src: SwitchProngSrc, |
| 14 | }; | 14 | }; |
| 15 | 15 | ||
| 16 | pub fn init(allocator: *std.mem.Allocator) RangeSet { | 16 | pub fn init(allocator: std.mem.Allocator) RangeSet { |
| 17 | return .{ | 17 | return .{ |
| 18 | .ranges = std.ArrayList(Range).init(allocator), | 18 | .ranges = std.ArrayList(Range).init(allocator), |
| 19 | }; | 19 | }; |
src/Sema.zig+5-5| ... | @@ -7,13 +7,13 @@ | ... | @@ -7,13 +7,13 @@ |
| 7 | 7 | ||
| 8 | mod: *Module, | 8 | mod: *Module, |
| 9 | /// Alias to `mod.gpa`. | 9 | /// Alias to `mod.gpa`. |
| 10 | gpa: *Allocator, | 10 | gpa: Allocator, |
| 11 | /// Points to the temporary arena allocator of the Sema. | 11 | /// Points to the temporary arena allocator of the Sema. |
| 12 | /// This arena will be cleared when the sema is destroyed. | 12 | /// This arena will be cleared when the sema is destroyed. |
| 13 | arena: *Allocator, | 13 | arena: Allocator, |
| 14 | /// Points to the arena allocator for the owner_decl. | 14 | /// Points to the arena allocator for the owner_decl. |
| 15 | /// This arena will persist until the decl is invalidated. | 15 | /// This arena will persist until the decl is invalidated. |
| 16 | perm_arena: *Allocator, | 16 | perm_arena: Allocator, |
| 17 | code: Zir, | 17 | code: Zir, |
| 18 | air_instructions: std.MultiArrayList(Air.Inst) = .{}, | 18 | air_instructions: std.MultiArrayList(Air.Inst) = .{}, |
| 19 | air_extra: std.ArrayListUnmanaged(u32) = .{}, | 19 | air_extra: std.ArrayListUnmanaged(u32) = .{}, |
| ... | @@ -417,7 +417,7 @@ pub const Block = struct { | ... | @@ -417,7 +417,7 @@ pub const Block = struct { |
| 417 | new_decl_arena: std.heap.ArenaAllocator, | 417 | new_decl_arena: std.heap.ArenaAllocator, |
| 418 | finished: bool, | 418 | finished: bool, |
| 419 | 419 | ||
| 420 | pub fn arena(wad: *WipAnonDecl) *Allocator { | 420 | pub fn arena(wad: *WipAnonDecl) Allocator { |
| 421 | return &wad.new_decl_arena.allocator; | 421 | return &wad.new_decl_arena.allocator; |
| 422 | } | 422 | } |
| 423 | 423 | ||
| ... | @@ -12793,7 +12793,7 @@ const ComptimePtrMutationKit = struct { | ... | @@ -12793,7 +12793,7 @@ const ComptimePtrMutationKit = struct { |
| 12793 | ty: Type, | 12793 | ty: Type, |
| 12794 | decl_arena: std.heap.ArenaAllocator = undefined, | 12794 | decl_arena: std.heap.ArenaAllocator = undefined, |
| 12795 | 12795 | ||
| 12796 | fn beginArena(self: *ComptimePtrMutationKit, gpa: *Allocator) *Allocator { | 12796 | fn beginArena(self: *ComptimePtrMutationKit, gpa: Allocator) Allocator { |
| 12797 | self.decl_arena = self.decl_ref_mut.decl.value_arena.?.promote(gpa); | 12797 | self.decl_arena = self.decl_ref_mut.decl.value_arena.?.promote(gpa); |
| 12798 | return &self.decl_arena.allocator; | 12798 | return &self.decl_arena.allocator; |
| 12799 | } | 12799 | } |
src/ThreadPool.zig+2-2| ... | @@ -9,7 +9,7 @@ const ThreadPool = @This(); | ... | @@ -9,7 +9,7 @@ const ThreadPool = @This(); |
| 9 | 9 | ||
| 10 | mutex: std.Thread.Mutex = .{}, | 10 | mutex: std.Thread.Mutex = .{}, |
| 11 | is_running: bool = true, | 11 | is_running: bool = true, |
| 12 | allocator: *std.mem.Allocator, | 12 | allocator: std.mem.Allocator, |
| 13 | workers: []Worker, | 13 | workers: []Worker, |
| 14 | run_queue: RunQueue = .{}, | 14 | run_queue: RunQueue = .{}, |
| 15 | idle_queue: IdleQueue = .{}, | 15 | idle_queue: IdleQueue = .{}, |
| ... | @@ -55,7 +55,7 @@ const Worker = struct { | ... | @@ -55,7 +55,7 @@ const Worker = struct { |
| 55 | } | 55 | } |
| 56 | }; | 56 | }; |
| 57 | 57 | ||
| 58 | pub fn init(self: *ThreadPool, allocator: *std.mem.Allocator) !void { | 58 | pub fn init(self: *ThreadPool, allocator: std.mem.Allocator) !void { |
| 59 | self.* = .{ | 59 | self.* = .{ |
| 60 | .allocator = allocator, | 60 | .allocator = allocator, |
| 61 | .workers = &[_]Worker{}, | 61 | .workers = &[_]Worker{}, |
src/TypedValue.zig+2-2| ... | @@ -16,14 +16,14 @@ pub const Managed = struct { | ... | @@ -16,14 +16,14 @@ pub const Managed = struct { |
| 16 | /// If this is `null` then there is no memory management needed. | 16 | /// If this is `null` then there is no memory management needed. |
| 17 | arena: ?*std.heap.ArenaAllocator.State = null, | 17 | arena: ?*std.heap.ArenaAllocator.State = null, |
| 18 | 18 | ||
| 19 | pub fn deinit(self: *Managed, allocator: *Allocator) void { | 19 | pub fn deinit(self: *Managed, allocator: Allocator) void { |
| 20 | if (self.arena) |a| a.promote(allocator).deinit(); | 20 | if (self.arena) |a| a.promote(allocator).deinit(); |
| 21 | self.* = undefined; | 21 | self.* = undefined; |
| 22 | } | 22 | } |
| 23 | }; | 23 | }; |
| 24 | 24 | ||
| 25 | /// Assumes arena allocation. Does a recursive copy. | 25 | /// Assumes arena allocation. Does a recursive copy. |
| 26 | pub fn copy(self: TypedValue, arena: *Allocator) error{OutOfMemory}!TypedValue { | 26 | pub fn copy(self: TypedValue, arena: Allocator) error{OutOfMemory}!TypedValue { |
| 27 | return TypedValue{ | 27 | return TypedValue{ |
| 28 | .ty = try self.ty.copy(arena), | 28 | .ty = try self.ty.copy(arena), |
| 29 | .val = try self.val.copy(arena), | 29 | .val = try self.val.copy(arena), |
src/Zir.zig+1-1| ... | @@ -101,7 +101,7 @@ pub fn hasCompileErrors(code: Zir) bool { | ... | @@ -101,7 +101,7 @@ pub fn hasCompileErrors(code: Zir) bool { |
| 101 | return code.extra[@enumToInt(ExtraIndex.compile_errors)] != 0; | 101 | return code.extra[@enumToInt(ExtraIndex.compile_errors)] != 0; |
| 102 | } | 102 | } |
| 103 | 103 | ||
| 104 | pub fn deinit(code: *Zir, gpa: *Allocator) void { | 104 | pub fn deinit(code: *Zir, gpa: Allocator) void { |
| 105 | code.instructions.deinit(gpa); | 105 | code.instructions.deinit(gpa); |
| 106 | gpa.free(code.string_bytes); | 106 | gpa.free(code.string_bytes); |
| 107 | gpa.free(code.extra); | 107 | gpa.free(code.extra); |
src/arch/aarch64/CodeGen.zig+2-2| ... | @@ -33,7 +33,7 @@ const InnerError = error{ | ... | @@ -33,7 +33,7 @@ const InnerError = error{ |
| 33 | CodegenFail, | 33 | CodegenFail, |
| 34 | }; | 34 | }; |
| 35 | 35 | ||
| 36 | gpa: *Allocator, | 36 | gpa: Allocator, |
| 37 | air: Air, | 37 | air: Air, |
| 38 | liveness: Liveness, | 38 | liveness: Liveness, |
| 39 | bin_file: *link.File, | 39 | bin_file: *link.File, |
| ... | @@ -164,7 +164,7 @@ const MCValue = union(enum) { | ... | @@ -164,7 +164,7 @@ const MCValue = union(enum) { |
| 164 | const Branch = struct { | 164 | const Branch = struct { |
| 165 | inst_table: std.AutoArrayHashMapUnmanaged(Air.Inst.Index, MCValue) = .{}, | 165 | inst_table: std.AutoArrayHashMapUnmanaged(Air.Inst.Index, MCValue) = .{}, |
| 166 | 166 | ||
| 167 | fn deinit(self: *Branch, gpa: *Allocator) void { | 167 | fn deinit(self: *Branch, gpa: Allocator) void { |
| 168 | self.inst_table.deinit(gpa); | 168 | self.inst_table.deinit(gpa); |
| 169 | self.* = undefined; | 169 | self.* = undefined; |
| 170 | } | 170 | } |
src/arch/aarch64/Mir.zig+1-1| ... | @@ -229,7 +229,7 @@ pub const Inst = struct { | ... | @@ -229,7 +229,7 @@ pub const Inst = struct { |
| 229 | // } | 229 | // } |
| 230 | }; | 230 | }; |
| 231 | 231 | ||
| 232 | pub fn deinit(mir: *Mir, gpa: *std.mem.Allocator) void { | 232 | pub fn deinit(mir: *Mir, gpa: std.mem.Allocator) void { |
| 233 | mir.instructions.deinit(gpa); | 233 | mir.instructions.deinit(gpa); |
| 234 | gpa.free(mir.extra); | 234 | gpa.free(mir.extra); |
| 235 | mir.* = undefined; | 235 | mir.* = undefined; |
src/arch/arm/CodeGen.zig+2-2| ... | @@ -33,7 +33,7 @@ const InnerError = error{ | ... | @@ -33,7 +33,7 @@ const InnerError = error{ |
| 33 | CodegenFail, | 33 | CodegenFail, |
| 34 | }; | 34 | }; |
| 35 | 35 | ||
| 36 | gpa: *Allocator, | 36 | gpa: Allocator, |
| 37 | air: Air, | 37 | air: Air, |
| 38 | liveness: Liveness, | 38 | liveness: Liveness, |
| 39 | bin_file: *link.File, | 39 | bin_file: *link.File, |
| ... | @@ -164,7 +164,7 @@ const MCValue = union(enum) { | ... | @@ -164,7 +164,7 @@ const MCValue = union(enum) { |
| 164 | const Branch = struct { | 164 | const Branch = struct { |
| 165 | inst_table: std.AutoArrayHashMapUnmanaged(Air.Inst.Index, MCValue) = .{}, | 165 | inst_table: std.AutoArrayHashMapUnmanaged(Air.Inst.Index, MCValue) = .{}, |
| 166 | 166 | ||
| 167 | fn deinit(self: *Branch, gpa: *Allocator) void { | 167 | fn deinit(self: *Branch, gpa: Allocator) void { |
| 168 | self.inst_table.deinit(gpa); | 168 | self.inst_table.deinit(gpa); |
| 169 | self.* = undefined; | 169 | self.* = undefined; |
| 170 | } | 170 | } |
src/arch/arm/Mir.zig+1-1| ... | @@ -193,7 +193,7 @@ pub const Inst = struct { | ... | @@ -193,7 +193,7 @@ pub const Inst = struct { |
| 193 | // } | 193 | // } |
| 194 | }; | 194 | }; |
| 195 | 195 | ||
| 196 | pub fn deinit(mir: *Mir, gpa: *std.mem.Allocator) void { | 196 | pub fn deinit(mir: *Mir, gpa: std.mem.Allocator) void { |
| 197 | mir.instructions.deinit(gpa); | 197 | mir.instructions.deinit(gpa); |
| 198 | gpa.free(mir.extra); | 198 | gpa.free(mir.extra); |
| 199 | mir.* = undefined; | 199 | mir.* = undefined; |
src/arch/riscv64/CodeGen.zig+2-2| ... | @@ -33,7 +33,7 @@ const InnerError = error{ | ... | @@ -33,7 +33,7 @@ const InnerError = error{ |
| 33 | CodegenFail, | 33 | CodegenFail, |
| 34 | }; | 34 | }; |
| 35 | 35 | ||
| 36 | gpa: *Allocator, | 36 | gpa: Allocator, |
| 37 | air: Air, | 37 | air: Air, |
| 38 | liveness: Liveness, | 38 | liveness: Liveness, |
| 39 | bin_file: *link.File, | 39 | bin_file: *link.File, |
| ... | @@ -158,7 +158,7 @@ const MCValue = union(enum) { | ... | @@ -158,7 +158,7 @@ const MCValue = union(enum) { |
| 158 | const Branch = struct { | 158 | const Branch = struct { |
| 159 | inst_table: std.AutoArrayHashMapUnmanaged(Air.Inst.Index, MCValue) = .{}, | 159 | inst_table: std.AutoArrayHashMapUnmanaged(Air.Inst.Index, MCValue) = .{}, |
| 160 | 160 | ||
| 161 | fn deinit(self: *Branch, gpa: *Allocator) void { | 161 | fn deinit(self: *Branch, gpa: Allocator) void { |
| 162 | self.inst_table.deinit(gpa); | 162 | self.inst_table.deinit(gpa); |
| 163 | self.* = undefined; | 163 | self.* = undefined; |
| 164 | } | 164 | } |
src/arch/riscv64/Mir.zig+1-1| ... | @@ -101,7 +101,7 @@ pub const Inst = struct { | ... | @@ -101,7 +101,7 @@ pub const Inst = struct { |
| 101 | // } | 101 | // } |
| 102 | }; | 102 | }; |
| 103 | 103 | ||
| 104 | pub fn deinit(mir: *Mir, gpa: *std.mem.Allocator) void { | 104 | pub fn deinit(mir: *Mir, gpa: std.mem.Allocator) void { |
| 105 | mir.instructions.deinit(gpa); | 105 | mir.instructions.deinit(gpa); |
| 106 | gpa.free(mir.extra); | 106 | gpa.free(mir.extra); |
| 107 | mir.* = undefined; | 107 | mir.* = undefined; |
src/arch/wasm/CodeGen.zig+2-2| ... | @@ -508,7 +508,7 @@ const Self = @This(); | ... | @@ -508,7 +508,7 @@ const Self = @This(); |
| 508 | decl: *Decl, | 508 | decl: *Decl, |
| 509 | air: Air, | 509 | air: Air, |
| 510 | liveness: Liveness, | 510 | liveness: Liveness, |
| 511 | gpa: *mem.Allocator, | 511 | gpa: mem.Allocator, |
| 512 | /// Table to save `WValue`'s generated by an `Air.Inst` | 512 | /// Table to save `WValue`'s generated by an `Air.Inst` |
| 513 | values: ValueTable, | 513 | values: ValueTable, |
| 514 | /// Mapping from Air.Inst.Index to block ids | 514 | /// Mapping from Air.Inst.Index to block ids |
| ... | @@ -983,7 +983,7 @@ const CallWValues = struct { | ... | @@ -983,7 +983,7 @@ const CallWValues = struct { |
| 983 | args: []WValue, | 983 | args: []WValue, |
| 984 | return_value: WValue, | 984 | return_value: WValue, |
| 985 | 985 | ||
| 986 | fn deinit(self: *CallWValues, gpa: *Allocator) void { | 986 | fn deinit(self: *CallWValues, gpa: Allocator) void { |
| 987 | gpa.free(self.args); | 987 | gpa.free(self.args); |
| 988 | self.* = undefined; | 988 | self.* = undefined; |
| 989 | } | 989 | } |
src/arch/wasm/Mir.zig+1-1| ... | @@ -411,7 +411,7 @@ pub const Inst = struct { | ... | @@ -411,7 +411,7 @@ pub const Inst = struct { |
| 411 | }; | 411 | }; |
| 412 | }; | 412 | }; |
| 413 | 413 | ||
| 414 | pub fn deinit(self: *Mir, gpa: *std.mem.Allocator) void { | 414 | pub fn deinit(self: *Mir, gpa: std.mem.Allocator) void { |
| 415 | self.instructions.deinit(gpa); | 415 | self.instructions.deinit(gpa); |
| 416 | gpa.free(self.extra); | 416 | gpa.free(self.extra); |
| 417 | self.* = undefined; | 417 | self.* = undefined; |
src/arch/x86_64/CodeGen.zig+2-2| ... | @@ -33,7 +33,7 @@ const InnerError = error{ | ... | @@ -33,7 +33,7 @@ const InnerError = error{ |
| 33 | CodegenFail, | 33 | CodegenFail, |
| 34 | }; | 34 | }; |
| 35 | 35 | ||
| 36 | gpa: *Allocator, | 36 | gpa: Allocator, |
| 37 | air: Air, | 37 | air: Air, |
| 38 | liveness: Liveness, | 38 | liveness: Liveness, |
| 39 | bin_file: *link.File, | 39 | bin_file: *link.File, |
| ... | @@ -174,7 +174,7 @@ pub const MCValue = union(enum) { | ... | @@ -174,7 +174,7 @@ pub const MCValue = union(enum) { |
| 174 | const Branch = struct { | 174 | const Branch = struct { |
| 175 | inst_table: std.AutoArrayHashMapUnmanaged(Air.Inst.Index, MCValue) = .{}, | 175 | inst_table: std.AutoArrayHashMapUnmanaged(Air.Inst.Index, MCValue) = .{}, |
| 176 | 176 | ||
| 177 | fn deinit(self: *Branch, gpa: *Allocator) void { | 177 | fn deinit(self: *Branch, gpa: Allocator) void { |
| 178 | self.inst_table.deinit(gpa); | 178 | self.inst_table.deinit(gpa); |
| 179 | self.* = undefined; | 179 | self.* = undefined; |
| 180 | } | 180 | } |
src/arch/x86_64/Mir.zig+1-1| ... | @@ -347,7 +347,7 @@ pub const ArgDbgInfo = struct { | ... | @@ -347,7 +347,7 @@ pub const ArgDbgInfo = struct { |
| 347 | arg_index: u32, | 347 | arg_index: u32, |
| 348 | }; | 348 | }; |
| 349 | 349 | ||
| 350 | pub fn deinit(mir: *Mir, gpa: *std.mem.Allocator) void { | 350 | pub fn deinit(mir: *Mir, gpa: std.mem.Allocator) void { |
| 351 | mir.instructions.deinit(gpa); | 351 | mir.instructions.deinit(gpa); |
| 352 | gpa.free(mir.extra); | 352 | gpa.free(mir.extra); |
| 353 | mir.* = undefined; | 353 | mir.* = undefined; |
src/codegen/c.zig+2-2| ... | @@ -163,14 +163,14 @@ pub const Object = struct { | ... | @@ -163,14 +163,14 @@ pub const Object = struct { |
| 163 | 163 | ||
| 164 | /// This data is available both when outputting .c code and when outputting an .h file. | 164 | /// This data is available both when outputting .c code and when outputting an .h file. |
| 165 | pub const DeclGen = struct { | 165 | pub const DeclGen = struct { |
| 166 | gpa: *std.mem.Allocator, | 166 | gpa: std.mem.Allocator, |
| 167 | module: *Module, | 167 | module: *Module, |
| 168 | decl: *Decl, | 168 | decl: *Decl, |
| 169 | fwd_decl: std.ArrayList(u8), | 169 | fwd_decl: std.ArrayList(u8), |
| 170 | error_msg: ?*Module.ErrorMsg, | 170 | error_msg: ?*Module.ErrorMsg, |
| 171 | /// The key of this map is Type which has references to typedefs_arena. | 171 | /// The key of this map is Type which has references to typedefs_arena. |
| 172 | typedefs: TypedefMap, | 172 | typedefs: TypedefMap, |
| 173 | typedefs_arena: *std.mem.Allocator, | 173 | typedefs_arena: std.mem.Allocator, |
| 174 | 174 | ||
| 175 | fn fail(dg: *DeclGen, comptime format: []const u8, args: anytype) error{ AnalysisFail, OutOfMemory } { | 175 | fn fail(dg: *DeclGen, comptime format: []const u8, args: anytype) error{ AnalysisFail, OutOfMemory } { |
| 176 | @setCold(true); | 176 | @setCold(true); |
src/codegen/llvm.zig+8-8| ... | @@ -23,7 +23,7 @@ const LazySrcLoc = Module.LazySrcLoc; | ... | @@ -23,7 +23,7 @@ const LazySrcLoc = Module.LazySrcLoc; |
| 23 | 23 | ||
| 24 | const Error = error{ OutOfMemory, CodegenFail }; | 24 | const Error = error{ OutOfMemory, CodegenFail }; |
| 25 | 25 | ||
| 26 | pub fn targetTriple(allocator: *Allocator, target: std.Target) ![:0]u8 { | 26 | pub fn targetTriple(allocator: Allocator, target: std.Target) ![:0]u8 { |
| 27 | const llvm_arch = switch (target.cpu.arch) { | 27 | const llvm_arch = switch (target.cpu.arch) { |
| 28 | .arm => "arm", | 28 | .arm => "arm", |
| 29 | .armeb => "armeb", | 29 | .armeb => "armeb", |
| ... | @@ -190,14 +190,14 @@ pub const Object = struct { | ... | @@ -190,14 +190,14 @@ pub const Object = struct { |
| 190 | std.hash_map.default_max_load_percentage, | 190 | std.hash_map.default_max_load_percentage, |
| 191 | ); | 191 | ); |
| 192 | 192 | ||
| 193 | pub fn create(gpa: *Allocator, sub_path: []const u8, options: link.Options) !*Object { | 193 | pub fn create(gpa: Allocator, sub_path: []const u8, options: link.Options) !*Object { |
| 194 | const obj = try gpa.create(Object); | 194 | const obj = try gpa.create(Object); |
| 195 | errdefer gpa.destroy(obj); | 195 | errdefer gpa.destroy(obj); |
| 196 | obj.* = try Object.init(gpa, sub_path, options); | 196 | obj.* = try Object.init(gpa, sub_path, options); |
| 197 | return obj; | 197 | return obj; |
| 198 | } | 198 | } |
| 199 | 199 | ||
| 200 | pub fn init(gpa: *Allocator, sub_path: []const u8, options: link.Options) !Object { | 200 | pub fn init(gpa: Allocator, sub_path: []const u8, options: link.Options) !Object { |
| 201 | const context = llvm.Context.create(); | 201 | const context = llvm.Context.create(); |
| 202 | errdefer context.dispose(); | 202 | errdefer context.dispose(); |
| 203 | 203 | ||
| ... | @@ -287,7 +287,7 @@ pub const Object = struct { | ... | @@ -287,7 +287,7 @@ pub const Object = struct { |
| 287 | }; | 287 | }; |
| 288 | } | 288 | } |
| 289 | 289 | ||
| 290 | pub fn deinit(self: *Object, gpa: *Allocator) void { | 290 | pub fn deinit(self: *Object, gpa: Allocator) void { |
| 291 | self.target_machine.dispose(); | 291 | self.target_machine.dispose(); |
| 292 | self.llvm_module.dispose(); | 292 | self.llvm_module.dispose(); |
| 293 | self.context.dispose(); | 293 | self.context.dispose(); |
| ... | @@ -297,13 +297,13 @@ pub const Object = struct { | ... | @@ -297,13 +297,13 @@ pub const Object = struct { |
| 297 | self.* = undefined; | 297 | self.* = undefined; |
| 298 | } | 298 | } |
| 299 | 299 | ||
| 300 | pub fn destroy(self: *Object, gpa: *Allocator) void { | 300 | pub fn destroy(self: *Object, gpa: Allocator) void { |
| 301 | self.deinit(gpa); | 301 | self.deinit(gpa); |
| 302 | gpa.destroy(self); | 302 | gpa.destroy(self); |
| 303 | } | 303 | } |
| 304 | 304 | ||
| 305 | fn locPath( | 305 | fn locPath( |
| 306 | arena: *Allocator, | 306 | arena: Allocator, |
| 307 | opt_loc: ?Compilation.EmitLoc, | 307 | opt_loc: ?Compilation.EmitLoc, |
| 308 | cache_directory: Compilation.Directory, | 308 | cache_directory: Compilation.Directory, |
| 309 | ) !?[*:0]u8 { | 309 | ) !?[*:0]u8 { |
| ... | @@ -554,7 +554,7 @@ pub const DeclGen = struct { | ... | @@ -554,7 +554,7 @@ pub const DeclGen = struct { |
| 554 | object: *Object, | 554 | object: *Object, |
| 555 | module: *Module, | 555 | module: *Module, |
| 556 | decl: *Module.Decl, | 556 | decl: *Module.Decl, |
| 557 | gpa: *Allocator, | 557 | gpa: Allocator, |
| 558 | err_msg: ?*Module.ErrorMsg, | 558 | err_msg: ?*Module.ErrorMsg, |
| 559 | 559 | ||
| 560 | fn todo(self: *DeclGen, comptime format: []const u8, args: anytype) Error { | 560 | fn todo(self: *DeclGen, comptime format: []const u8, args: anytype) Error { |
| ... | @@ -1621,7 +1621,7 @@ pub const DeclGen = struct { | ... | @@ -1621,7 +1621,7 @@ pub const DeclGen = struct { |
| 1621 | }; | 1621 | }; |
| 1622 | 1622 | ||
| 1623 | pub const FuncGen = struct { | 1623 | pub const FuncGen = struct { |
| 1624 | gpa: *Allocator, | 1624 | gpa: Allocator, |
| 1625 | dg: *DeclGen, | 1625 | dg: *DeclGen, |
| 1626 | air: Air, | 1626 | air: Air, |
| 1627 | liveness: Liveness, | 1627 | liveness: Liveness, |
src/codegen/spirv.zig+2-2| ... | @@ -70,7 +70,7 @@ pub fn writeInstructionWithString(code: *std.ArrayList(Word), opcode: Opcode, ar | ... | @@ -70,7 +70,7 @@ pub fn writeInstructionWithString(code: *std.ArrayList(Word), opcode: Opcode, ar |
| 70 | /// of data which needs to be persistent over different calls to Decl code generation. | 70 | /// of data which needs to be persistent over different calls to Decl code generation. |
| 71 | pub const SPIRVModule = struct { | 71 | pub const SPIRVModule = struct { |
| 72 | /// A general-purpose allocator which may be used to allocate temporary resources required for compilation. | 72 | /// A general-purpose allocator which may be used to allocate temporary resources required for compilation. |
| 73 | gpa: *Allocator, | 73 | gpa: Allocator, |
| 74 | 74 | ||
| 75 | /// The parent module. | 75 | /// The parent module. |
| 76 | module: *Module, | 76 | module: *Module, |
| ... | @@ -103,7 +103,7 @@ pub const SPIRVModule = struct { | ... | @@ -103,7 +103,7 @@ pub const SPIRVModule = struct { |
| 103 | /// just the ones for OpLine. Note that OpLine needs the result of OpString, and not that of OpSource. | 103 | /// just the ones for OpLine. Note that OpLine needs the result of OpString, and not that of OpSource. |
| 104 | file_names: std.StringHashMap(ResultId), | 104 | file_names: std.StringHashMap(ResultId), |
| 105 | 105 | ||
| 106 | pub fn init(gpa: *Allocator, module: *Module) SPIRVModule { | 106 | pub fn init(gpa: Allocator, module: *Module) SPIRVModule { |
| 107 | return .{ | 107 | return .{ |
| 108 | .gpa = gpa, | 108 | .gpa = gpa, |
| 109 | .module = module, | 109 | .module = module, |
src/glibc.zig+9-9| ... | @@ -34,7 +34,7 @@ pub const ABI = struct { | ... | @@ -34,7 +34,7 @@ pub const ABI = struct { |
| 34 | version_table: std.AutoHashMapUnmanaged(target_util.ArchOsAbi, [*]VerList), | 34 | version_table: std.AutoHashMapUnmanaged(target_util.ArchOsAbi, [*]VerList), |
| 35 | arena_state: std.heap.ArenaAllocator.State, | 35 | arena_state: std.heap.ArenaAllocator.State, |
| 36 | 36 | ||
| 37 | pub fn destroy(abi: *ABI, gpa: *Allocator) void { | 37 | pub fn destroy(abi: *ABI, gpa: Allocator) void { |
| 38 | abi.version_table.deinit(gpa); | 38 | abi.version_table.deinit(gpa); |
| 39 | abi.arena_state.promote(gpa).deinit(); // Frees the ABI memory too. | 39 | abi.arena_state.promote(gpa).deinit(); // Frees the ABI memory too. |
| 40 | } | 40 | } |
| ... | @@ -59,7 +59,7 @@ pub const LoadMetaDataError = error{ | ... | @@ -59,7 +59,7 @@ pub const LoadMetaDataError = error{ |
| 59 | 59 | ||
| 60 | /// This function will emit a log error when there is a problem with the zig installation and then return | 60 | /// This function will emit a log error when there is a problem with the zig installation and then return |
| 61 | /// `error.ZigInstallationCorrupt`. | 61 | /// `error.ZigInstallationCorrupt`. |
| 62 | pub fn loadMetaData(gpa: *Allocator, zig_lib_dir: std.fs.Dir) LoadMetaDataError!*ABI { | 62 | pub fn loadMetaData(gpa: Allocator, zig_lib_dir: std.fs.Dir) LoadMetaDataError!*ABI { |
| 63 | const tracy = trace(@src()); | 63 | const tracy = trace(@src()); |
| 64 | defer tracy.end(); | 64 | defer tracy.end(); |
| 65 | 65 | ||
| ... | @@ -433,7 +433,7 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile) !void { | ... | @@ -433,7 +433,7 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile) !void { |
| 433 | } | 433 | } |
| 434 | } | 434 | } |
| 435 | 435 | ||
| 436 | fn start_asm_path(comp: *Compilation, arena: *Allocator, basename: []const u8) ![]const u8 { | 436 | fn start_asm_path(comp: *Compilation, arena: Allocator, basename: []const u8) ![]const u8 { |
| 437 | const arch = comp.getTarget().cpu.arch; | 437 | const arch = comp.getTarget().cpu.arch; |
| 438 | const is_ppc = arch == .powerpc or arch == .powerpc64 or arch == .powerpc64le; | 438 | const is_ppc = arch == .powerpc or arch == .powerpc64 or arch == .powerpc64le; |
| 439 | const is_aarch64 = arch == .aarch64 or arch == .aarch64_be; | 439 | const is_aarch64 = arch == .aarch64 or arch == .aarch64_be; |
| ... | @@ -493,7 +493,7 @@ fn start_asm_path(comp: *Compilation, arena: *Allocator, basename: []const u8) ! | ... | @@ -493,7 +493,7 @@ fn start_asm_path(comp: *Compilation, arena: *Allocator, basename: []const u8) ! |
| 493 | return result.items; | 493 | return result.items; |
| 494 | } | 494 | } |
| 495 | 495 | ||
| 496 | fn add_include_dirs(comp: *Compilation, arena: *Allocator, args: *std.ArrayList([]const u8)) error{OutOfMemory}!void { | 496 | fn add_include_dirs(comp: *Compilation, arena: Allocator, args: *std.ArrayList([]const u8)) error{OutOfMemory}!void { |
| 497 | const target = comp.getTarget(); | 497 | const target = comp.getTarget(); |
| 498 | const arch = target.cpu.arch; | 498 | const arch = target.cpu.arch; |
| 499 | const opt_nptl: ?[]const u8 = if (target.os.tag == .linux) "nptl" else "htl"; | 499 | const opt_nptl: ?[]const u8 = if (target.os.tag == .linux) "nptl" else "htl"; |
| ... | @@ -566,7 +566,7 @@ fn add_include_dirs(comp: *Compilation, arena: *Allocator, args: *std.ArrayList( | ... | @@ -566,7 +566,7 @@ fn add_include_dirs(comp: *Compilation, arena: *Allocator, args: *std.ArrayList( |
| 566 | } | 566 | } |
| 567 | 567 | ||
| 568 | fn add_include_dirs_arch( | 568 | fn add_include_dirs_arch( |
| 569 | arena: *Allocator, | 569 | arena: Allocator, |
| 570 | args: *std.ArrayList([]const u8), | 570 | args: *std.ArrayList([]const u8), |
| 571 | arch: std.Target.Cpu.Arch, | 571 | arch: std.Target.Cpu.Arch, |
| 572 | opt_nptl: ?[]const u8, | 572 | opt_nptl: ?[]const u8, |
| ... | @@ -677,14 +677,14 @@ fn add_include_dirs_arch( | ... | @@ -677,14 +677,14 @@ fn add_include_dirs_arch( |
| 677 | } | 677 | } |
| 678 | } | 678 | } |
| 679 | 679 | ||
| 680 | fn path_from_lib(comp: *Compilation, arena: *Allocator, sub_path: []const u8) ![]const u8 { | 680 | fn path_from_lib(comp: *Compilation, arena: Allocator, sub_path: []const u8) ![]const u8 { |
| 681 | return path.join(arena, &[_][]const u8{ comp.zig_lib_directory.path.?, sub_path }); | 681 | return path.join(arena, &[_][]const u8{ comp.zig_lib_directory.path.?, sub_path }); |
| 682 | } | 682 | } |
| 683 | 683 | ||
| 684 | const lib_libc = "libc" ++ path.sep_str; | 684 | const lib_libc = "libc" ++ path.sep_str; |
| 685 | const lib_libc_glibc = lib_libc ++ "glibc" ++ path.sep_str; | 685 | const lib_libc_glibc = lib_libc ++ "glibc" ++ path.sep_str; |
| 686 | 686 | ||
| 687 | fn lib_path(comp: *Compilation, arena: *Allocator, sub_path: []const u8) ![]const u8 { | 687 | fn lib_path(comp: *Compilation, arena: Allocator, sub_path: []const u8) ![]const u8 { |
| 688 | return path.join(arena, &[_][]const u8{ comp.zig_lib_directory.path.?, sub_path }); | 688 | return path.join(arena, &[_][]const u8{ comp.zig_lib_directory.path.?, sub_path }); |
| 689 | } | 689 | } |
| 690 | 690 | ||
| ... | @@ -692,7 +692,7 @@ pub const BuiltSharedObjects = struct { | ... | @@ -692,7 +692,7 @@ pub const BuiltSharedObjects = struct { |
| 692 | lock: Cache.Lock, | 692 | lock: Cache.Lock, |
| 693 | dir_path: []u8, | 693 | dir_path: []u8, |
| 694 | 694 | ||
| 695 | pub fn deinit(self: *BuiltSharedObjects, gpa: *Allocator) void { | 695 | pub fn deinit(self: *BuiltSharedObjects, gpa: Allocator) void { |
| 696 | self.lock.release(); | 696 | self.lock.release(); |
| 697 | gpa.free(self.dir_path); | 697 | gpa.free(self.dir_path); |
| 698 | self.* = undefined; | 698 | self.* = undefined; |
| ... | @@ -915,7 +915,7 @@ pub fn buildSharedObjects(comp: *Compilation) !void { | ... | @@ -915,7 +915,7 @@ pub fn buildSharedObjects(comp: *Compilation) !void { |
| 915 | 915 | ||
| 916 | fn buildSharedLib( | 916 | fn buildSharedLib( |
| 917 | comp: *Compilation, | 917 | comp: *Compilation, |
| 918 | arena: *Allocator, | 918 | arena: Allocator, |
| 919 | zig_cache_directory: Compilation.Directory, | 919 | zig_cache_directory: Compilation.Directory, |
| 920 | bin_directory: Compilation.Directory, | 920 | bin_directory: Compilation.Directory, |
| 921 | asm_file_basename: []const u8, | 921 | asm_file_basename: []const u8, |
src/introspect.zig+3-3| ... | @@ -33,7 +33,7 @@ fn testZigInstallPrefix(base_dir: fs.Dir) ?Compilation.Directory { | ... | @@ -33,7 +33,7 @@ fn testZigInstallPrefix(base_dir: fs.Dir) ?Compilation.Directory { |
| 33 | } | 33 | } |
| 34 | 34 | ||
| 35 | /// Both the directory handle and the path are newly allocated resources which the caller now owns. | 35 | /// Both the directory handle and the path are newly allocated resources which the caller now owns. |
| 36 | pub fn findZigLibDir(gpa: *mem.Allocator) !Compilation.Directory { | 36 | pub fn findZigLibDir(gpa: mem.Allocator) !Compilation.Directory { |
| 37 | const self_exe_path = try fs.selfExePathAlloc(gpa); | 37 | const self_exe_path = try fs.selfExePathAlloc(gpa); |
| 38 | defer gpa.free(self_exe_path); | 38 | defer gpa.free(self_exe_path); |
| 39 | 39 | ||
| ... | @@ -42,7 +42,7 @@ pub fn findZigLibDir(gpa: *mem.Allocator) !Compilation.Directory { | ... | @@ -42,7 +42,7 @@ pub fn findZigLibDir(gpa: *mem.Allocator) !Compilation.Directory { |
| 42 | 42 | ||
| 43 | /// Both the directory handle and the path are newly allocated resources which the caller now owns. | 43 | /// Both the directory handle and the path are newly allocated resources which the caller now owns. |
| 44 | pub fn findZigLibDirFromSelfExe( | 44 | pub fn findZigLibDirFromSelfExe( |
| 45 | allocator: *mem.Allocator, | 45 | allocator: mem.Allocator, |
| 46 | self_exe_path: []const u8, | 46 | self_exe_path: []const u8, |
| 47 | ) error{ OutOfMemory, FileNotFound }!Compilation.Directory { | 47 | ) error{ OutOfMemory, FileNotFound }!Compilation.Directory { |
| 48 | const cwd = fs.cwd(); | 48 | const cwd = fs.cwd(); |
| ... | @@ -61,7 +61,7 @@ pub fn findZigLibDirFromSelfExe( | ... | @@ -61,7 +61,7 @@ pub fn findZigLibDirFromSelfExe( |
| 61 | } | 61 | } |
| 62 | 62 | ||
| 63 | /// Caller owns returned memory. | 63 | /// Caller owns returned memory. |
| 64 | pub fn resolveGlobalCacheDir(allocator: *mem.Allocator) ![]u8 { | 64 | pub fn resolveGlobalCacheDir(allocator: mem.Allocator) ![]u8 { |
| 65 | if (std.process.getEnvVarOwned(allocator, "ZIG_GLOBAL_CACHE_DIR")) |value| { | 65 | if (std.process.getEnvVarOwned(allocator, "ZIG_GLOBAL_CACHE_DIR")) |value| { |
| 66 | if (value.len > 0) { | 66 | if (value.len > 0) { |
| 67 | return value; | 67 | return value; |
src/libc_installation.zig+4-4| ... | @@ -39,7 +39,7 @@ pub const LibCInstallation = struct { | ... | @@ -39,7 +39,7 @@ pub const LibCInstallation = struct { |
| 39 | }; | 39 | }; |
| 40 | 40 | ||
| 41 | pub fn parse( | 41 | pub fn parse( |
| 42 | allocator: *Allocator, | 42 | allocator: Allocator, |
| 43 | libc_file: []const u8, | 43 | libc_file: []const u8, |
| 44 | target: std.zig.CrossTarget, | 44 | target: std.zig.CrossTarget, |
| 45 | ) !LibCInstallation { | 45 | ) !LibCInstallation { |
| ... | @@ -175,7 +175,7 @@ pub const LibCInstallation = struct { | ... | @@ -175,7 +175,7 @@ pub const LibCInstallation = struct { |
| 175 | } | 175 | } |
| 176 | 176 | ||
| 177 | pub const FindNativeOptions = struct { | 177 | pub const FindNativeOptions = struct { |
| 178 | allocator: *Allocator, | 178 | allocator: Allocator, |
| 179 | 179 | ||
| 180 | /// If enabled, will print human-friendly errors to stderr. | 180 | /// If enabled, will print human-friendly errors to stderr. |
| 181 | verbose: bool = false, | 181 | verbose: bool = false, |
| ... | @@ -234,7 +234,7 @@ pub const LibCInstallation = struct { | ... | @@ -234,7 +234,7 @@ pub const LibCInstallation = struct { |
| 234 | } | 234 | } |
| 235 | 235 | ||
| 236 | /// Must be the same allocator passed to `parse` or `findNative`. | 236 | /// Must be the same allocator passed to `parse` or `findNative`. |
| 237 | pub fn deinit(self: *LibCInstallation, allocator: *Allocator) void { | 237 | pub fn deinit(self: *LibCInstallation, allocator: Allocator) void { |
| 238 | const fields = std.meta.fields(LibCInstallation); | 238 | const fields = std.meta.fields(LibCInstallation); |
| 239 | inline for (fields) |field| { | 239 | inline for (fields) |field| { |
| 240 | if (@field(self, field.name)) |payload| { | 240 | if (@field(self, field.name)) |payload| { |
| ... | @@ -562,7 +562,7 @@ pub const LibCInstallation = struct { | ... | @@ -562,7 +562,7 @@ pub const LibCInstallation = struct { |
| 562 | }; | 562 | }; |
| 563 | 563 | ||
| 564 | pub const CCPrintFileNameOptions = struct { | 564 | pub const CCPrintFileNameOptions = struct { |
| 565 | allocator: *Allocator, | 565 | allocator: Allocator, |
| 566 | search_basename: []const u8, | 566 | search_basename: []const u8, |
| 567 | want_dirname: enum { full_path, only_dir }, | 567 | want_dirname: enum { full_path, only_dir }, |
| 568 | verbose: bool = false, | 568 | verbose: bool = false, |
src/link.zig+2-2| ... | @@ -165,7 +165,7 @@ pub const File = struct { | ... | @@ -165,7 +165,7 @@ pub const File = struct { |
| 165 | tag: Tag, | 165 | tag: Tag, |
| 166 | options: Options, | 166 | options: Options, |
| 167 | file: ?fs.File, | 167 | file: ?fs.File, |
| 168 | allocator: *Allocator, | 168 | allocator: Allocator, |
| 169 | /// When linking with LLD, this linker code will output an object file only at | 169 | /// When linking with LLD, this linker code will output an object file only at |
| 170 | /// this location, and then this path can be placed on the LLD linker line. | 170 | /// this location, and then this path can be placed on the LLD linker line. |
| 171 | intermediary_basename: ?[]const u8 = null, | 171 | intermediary_basename: ?[]const u8 = null, |
| ... | @@ -221,7 +221,7 @@ pub const File = struct { | ... | @@ -221,7 +221,7 @@ pub const File = struct { |
| 221 | /// incremental linking fails, falls back to truncating the file and | 221 | /// incremental linking fails, falls back to truncating the file and |
| 222 | /// rewriting it. A malicious file is detected as incremental link failure | 222 | /// rewriting it. A malicious file is detected as incremental link failure |
| 223 | /// and does not cause Illegal Behavior. This operation is not atomic. | 223 | /// and does not cause Illegal Behavior. This operation is not atomic. |
| 224 | pub fn openPath(allocator: *Allocator, options: Options) !*File { | 224 | pub fn openPath(allocator: Allocator, options: Options) !*File { |
| 225 | if (options.object_format == .macho) { | 225 | if (options.object_format == .macho) { |
| 226 | return &(try MachO.openPath(allocator, options)).base; | 226 | return &(try MachO.openPath(allocator, options)).base; |
| 227 | } | 227 | } |
src/link/C.zig+3-3| ... | @@ -36,7 +36,7 @@ const DeclBlock = struct { | ... | @@ -36,7 +36,7 @@ const DeclBlock = struct { |
| 36 | /// Any arena memory the Type points to lives in the `arena` field of `C`. | 36 | /// Any arena memory the Type points to lives in the `arena` field of `C`. |
| 37 | typedefs: codegen.TypedefMap.Unmanaged = .{}, | 37 | typedefs: codegen.TypedefMap.Unmanaged = .{}, |
| 38 | 38 | ||
| 39 | fn deinit(db: *DeclBlock, gpa: *Allocator) void { | 39 | fn deinit(db: *DeclBlock, gpa: Allocator) void { |
| 40 | db.code.deinit(gpa); | 40 | db.code.deinit(gpa); |
| 41 | db.fwd_decl.deinit(gpa); | 41 | db.fwd_decl.deinit(gpa); |
| 42 | for (db.typedefs.values()) |typedef| { | 42 | for (db.typedefs.values()) |typedef| { |
| ... | @@ -47,7 +47,7 @@ const DeclBlock = struct { | ... | @@ -47,7 +47,7 @@ const DeclBlock = struct { |
| 47 | } | 47 | } |
| 48 | }; | 48 | }; |
| 49 | 49 | ||
| 50 | pub fn openPath(gpa: *Allocator, sub_path: []const u8, options: link.Options) !*C { | 50 | pub fn openPath(gpa: Allocator, sub_path: []const u8, options: link.Options) !*C { |
| 51 | assert(options.object_format == .c); | 51 | assert(options.object_format == .c); |
| 52 | 52 | ||
| 53 | if (options.use_llvm) return error.LLVMHasNoCBackend; | 53 | if (options.use_llvm) return error.LLVMHasNoCBackend; |
| ... | @@ -336,7 +336,7 @@ const Flush = struct { | ... | @@ -336,7 +336,7 @@ const Flush = struct { |
| 336 | std.hash_map.default_max_load_percentage, | 336 | std.hash_map.default_max_load_percentage, |
| 337 | ); | 337 | ); |
| 338 | 338 | ||
| 339 | fn deinit(f: *Flush, gpa: *Allocator) void { | 339 | fn deinit(f: *Flush, gpa: Allocator) void { |
| 340 | f.all_buffers.deinit(gpa); | 340 | f.all_buffers.deinit(gpa); |
| 341 | f.err_typedef_buf.deinit(gpa); | 341 | f.err_typedef_buf.deinit(gpa); |
| 342 | f.typedefs.deinit(gpa); | 342 | f.typedefs.deinit(gpa); |
src/link/Coff.zig+3-3| ... | @@ -125,7 +125,7 @@ pub const TextBlock = struct { | ... | @@ -125,7 +125,7 @@ pub const TextBlock = struct { |
| 125 | 125 | ||
| 126 | pub const SrcFn = void; | 126 | pub const SrcFn = void; |
| 127 | 127 | ||
| 128 | pub fn openPath(allocator: *Allocator, sub_path: []const u8, options: link.Options) !*Coff { | 128 | pub fn openPath(allocator: Allocator, sub_path: []const u8, options: link.Options) !*Coff { |
| 129 | assert(options.object_format == .coff); | 129 | assert(options.object_format == .coff); |
| 130 | 130 | ||
| 131 | if (build_options.have_llvm and options.use_llvm) { | 131 | if (build_options.have_llvm and options.use_llvm) { |
| ... | @@ -396,7 +396,7 @@ pub fn openPath(allocator: *Allocator, sub_path: []const u8, options: link.Optio | ... | @@ -396,7 +396,7 @@ pub fn openPath(allocator: *Allocator, sub_path: []const u8, options: link.Optio |
| 396 | return self; | 396 | return self; |
| 397 | } | 397 | } |
| 398 | 398 | ||
| 399 | pub fn createEmpty(gpa: *Allocator, options: link.Options) !*Coff { | 399 | pub fn createEmpty(gpa: Allocator, options: link.Options) !*Coff { |
| 400 | const ptr_width: PtrWidth = switch (options.target.cpu.arch.ptrBitWidth()) { | 400 | const ptr_width: PtrWidth = switch (options.target.cpu.arch.ptrBitWidth()) { |
| 401 | 0...32 => .p32, | 401 | 0...32 => .p32, |
| 402 | 33...64 => .p64, | 402 | 33...64 => .p64, |
| ... | @@ -1394,7 +1394,7 @@ fn linkWithLLD(self: *Coff, comp: *Compilation) !void { | ... | @@ -1394,7 +1394,7 @@ fn linkWithLLD(self: *Coff, comp: *Compilation) !void { |
| 1394 | } | 1394 | } |
| 1395 | } | 1395 | } |
| 1396 | 1396 | ||
| 1397 | fn findLib(self: *Coff, arena: *Allocator, name: []const u8) !?[]const u8 { | 1397 | fn findLib(self: *Coff, arena: Allocator, name: []const u8) !?[]const u8 { |
| 1398 | for (self.base.options.lib_dirs) |lib_dir| { | 1398 | for (self.base.options.lib_dirs) |lib_dir| { |
| 1399 | const full_path = try fs.path.join(arena, &.{ lib_dir, name }); | 1399 | const full_path = try fs.path.join(arena, &.{ lib_dir, name }); |
| 1400 | fs.cwd().access(full_path, .{}) catch |err| switch (err) { | 1400 | fs.cwd().access(full_path, .{}) catch |err| switch (err) { |
src/link/Elf.zig+4-4| ... | @@ -228,7 +228,7 @@ pub const SrcFn = struct { | ... | @@ -228,7 +228,7 @@ pub const SrcFn = struct { |
| 228 | }; | 228 | }; |
| 229 | }; | 229 | }; |
| 230 | 230 | ||
| 231 | pub fn openPath(allocator: *Allocator, sub_path: []const u8, options: link.Options) !*Elf { | 231 | pub fn openPath(allocator: Allocator, sub_path: []const u8, options: link.Options) !*Elf { |
| 232 | assert(options.object_format == .elf); | 232 | assert(options.object_format == .elf); |
| 233 | 233 | ||
| 234 | if (build_options.have_llvm and options.use_llvm) { | 234 | if (build_options.have_llvm and options.use_llvm) { |
| ... | @@ -281,7 +281,7 @@ pub fn openPath(allocator: *Allocator, sub_path: []const u8, options: link.Optio | ... | @@ -281,7 +281,7 @@ pub fn openPath(allocator: *Allocator, sub_path: []const u8, options: link.Optio |
| 281 | return self; | 281 | return self; |
| 282 | } | 282 | } |
| 283 | 283 | ||
| 284 | pub fn createEmpty(gpa: *Allocator, options: link.Options) !*Elf { | 284 | pub fn createEmpty(gpa: Allocator, options: link.Options) !*Elf { |
| 285 | const ptr_width: PtrWidth = switch (options.target.cpu.arch.ptrBitWidth()) { | 285 | const ptr_width: PtrWidth = switch (options.target.cpu.arch.ptrBitWidth()) { |
| 286 | 0...32 => .p32, | 286 | 0...32 => .p32, |
| 287 | 33...64 => .p64, | 287 | 33...64 => .p64, |
| ... | @@ -2205,7 +2205,7 @@ pub fn freeDecl(self: *Elf, decl: *Module.Decl) void { | ... | @@ -2205,7 +2205,7 @@ pub fn freeDecl(self: *Elf, decl: *Module.Decl) void { |
| 2205 | } | 2205 | } |
| 2206 | } | 2206 | } |
| 2207 | 2207 | ||
| 2208 | fn deinitRelocs(gpa: *Allocator, table: *File.DbgInfoTypeRelocsTable) void { | 2208 | fn deinitRelocs(gpa: Allocator, table: *File.DbgInfoTypeRelocsTable) void { |
| 2209 | var it = table.valueIterator(); | 2209 | var it = table.valueIterator(); |
| 2210 | while (it.next()) |value| { | 2210 | while (it.next()) |value| { |
| 2211 | value.relocs.deinit(gpa); | 2211 | value.relocs.deinit(gpa); |
| ... | @@ -3360,7 +3360,7 @@ const CsuObjects = struct { | ... | @@ -3360,7 +3360,7 @@ const CsuObjects = struct { |
| 3360 | crtend: ?[]const u8 = null, | 3360 | crtend: ?[]const u8 = null, |
| 3361 | crtn: ?[]const u8 = null, | 3361 | crtn: ?[]const u8 = null, |
| 3362 | 3362 | ||
| 3363 | fn init(arena: *mem.Allocator, link_options: link.Options, comp: *const Compilation) !CsuObjects { | 3363 | fn init(arena: mem.Allocator, link_options: link.Options, comp: *const Compilation) !CsuObjects { |
| 3364 | // crt objects are only required for libc. | 3364 | // crt objects are only required for libc. |
| 3365 | if (!link_options.link_libc) return CsuObjects{}; | 3365 | if (!link_options.link_libc) return CsuObjects{}; |
| 3366 | 3366 |
src/link/MachO.zig+5-5| ... | @@ -280,7 +280,7 @@ pub const SrcFn = struct { | ... | @@ -280,7 +280,7 @@ pub const SrcFn = struct { |
| 280 | }; | 280 | }; |
| 281 | }; | 281 | }; |
| 282 | 282 | ||
| 283 | pub fn openPath(allocator: *Allocator, options: link.Options) !*MachO { | 283 | pub fn openPath(allocator: Allocator, options: link.Options) !*MachO { |
| 284 | assert(options.object_format == .macho); | 284 | assert(options.object_format == .macho); |
| 285 | 285 | ||
| 286 | const use_stage1 = build_options.is_stage1 and options.use_stage1; | 286 | const use_stage1 = build_options.is_stage1 and options.use_stage1; |
| ... | @@ -366,7 +366,7 @@ pub fn openPath(allocator: *Allocator, options: link.Options) !*MachO { | ... | @@ -366,7 +366,7 @@ pub fn openPath(allocator: *Allocator, options: link.Options) !*MachO { |
| 366 | return self; | 366 | return self; |
| 367 | } | 367 | } |
| 368 | 368 | ||
| 369 | pub fn createEmpty(gpa: *Allocator, options: link.Options) !*MachO { | 369 | pub fn createEmpty(gpa: Allocator, options: link.Options) !*MachO { |
| 370 | const self = try gpa.create(MachO); | 370 | const self = try gpa.create(MachO); |
| 371 | const cpu_arch = options.target.cpu.arch; | 371 | const cpu_arch = options.target.cpu.arch; |
| 372 | const os_tag = options.target.os.tag; | 372 | const os_tag = options.target.os.tag; |
| ... | @@ -1032,7 +1032,7 @@ pub fn flushObject(self: *MachO, comp: *Compilation) !void { | ... | @@ -1032,7 +1032,7 @@ pub fn flushObject(self: *MachO, comp: *Compilation) !void { |
| 1032 | } | 1032 | } |
| 1033 | 1033 | ||
| 1034 | fn resolveSearchDir( | 1034 | fn resolveSearchDir( |
| 1035 | arena: *Allocator, | 1035 | arena: Allocator, |
| 1036 | dir: []const u8, | 1036 | dir: []const u8, |
| 1037 | syslibroot: ?[]const u8, | 1037 | syslibroot: ?[]const u8, |
| 1038 | ) !?[]const u8 { | 1038 | ) !?[]const u8 { |
| ... | @@ -1074,7 +1074,7 @@ fn resolveSearchDir( | ... | @@ -1074,7 +1074,7 @@ fn resolveSearchDir( |
| 1074 | } | 1074 | } |
| 1075 | 1075 | ||
| 1076 | fn resolveLib( | 1076 | fn resolveLib( |
| 1077 | arena: *Allocator, | 1077 | arena: Allocator, |
| 1078 | search_dirs: []const []const u8, | 1078 | search_dirs: []const []const u8, |
| 1079 | name: []const u8, | 1079 | name: []const u8, |
| 1080 | ext: []const u8, | 1080 | ext: []const u8, |
| ... | @@ -1098,7 +1098,7 @@ fn resolveLib( | ... | @@ -1098,7 +1098,7 @@ fn resolveLib( |
| 1098 | } | 1098 | } |
| 1099 | 1099 | ||
| 1100 | fn resolveFramework( | 1100 | fn resolveFramework( |
| 1101 | arena: *Allocator, | 1101 | arena: Allocator, |
| 1102 | search_dirs: []const []const u8, | 1102 | search_dirs: []const []const u8, |
| 1103 | name: []const u8, | 1103 | name: []const u8, |
| 1104 | ext: []const u8, | 1104 | ext: []const u8, |
src/link/MachO/Archive.zig+5-5| ... | @@ -92,7 +92,7 @@ const ar_hdr = extern struct { | ... | @@ -92,7 +92,7 @@ const ar_hdr = extern struct { |
| 92 | } | 92 | } |
| 93 | }; | 93 | }; |
| 94 | 94 | ||
| 95 | pub fn deinit(self: *Archive, allocator: *Allocator) void { | 95 | pub fn deinit(self: *Archive, allocator: Allocator) void { |
| 96 | for (self.toc.keys()) |*key| { | 96 | for (self.toc.keys()) |*key| { |
| 97 | allocator.free(key.*); | 97 | allocator.free(key.*); |
| 98 | } | 98 | } |
| ... | @@ -103,7 +103,7 @@ pub fn deinit(self: *Archive, allocator: *Allocator) void { | ... | @@ -103,7 +103,7 @@ pub fn deinit(self: *Archive, allocator: *Allocator) void { |
| 103 | allocator.free(self.name); | 103 | allocator.free(self.name); |
| 104 | } | 104 | } |
| 105 | 105 | ||
| 106 | pub fn parse(self: *Archive, allocator: *Allocator, target: std.Target) !void { | 106 | pub fn parse(self: *Archive, allocator: Allocator, target: std.Target) !void { |
| 107 | const reader = self.file.reader(); | 107 | const reader = self.file.reader(); |
| 108 | self.library_offset = try fat.getLibraryOffset(reader, target); | 108 | self.library_offset = try fat.getLibraryOffset(reader, target); |
| 109 | try self.file.seekTo(self.library_offset); | 109 | try self.file.seekTo(self.library_offset); |
| ... | @@ -128,7 +128,7 @@ pub fn parse(self: *Archive, allocator: *Allocator, target: std.Target) !void { | ... | @@ -128,7 +128,7 @@ pub fn parse(self: *Archive, allocator: *Allocator, target: std.Target) !void { |
| 128 | try reader.context.seekTo(0); | 128 | try reader.context.seekTo(0); |
| 129 | } | 129 | } |
| 130 | 130 | ||
| 131 | fn parseName(allocator: *Allocator, header: ar_hdr, reader: anytype) ![]u8 { | 131 | fn parseName(allocator: Allocator, header: ar_hdr, reader: anytype) ![]u8 { |
| 132 | const name_or_length = try header.nameOrLength(); | 132 | const name_or_length = try header.nameOrLength(); |
| 133 | var name: []u8 = undefined; | 133 | var name: []u8 = undefined; |
| 134 | switch (name_or_length) { | 134 | switch (name_or_length) { |
| ... | @@ -146,7 +146,7 @@ fn parseName(allocator: *Allocator, header: ar_hdr, reader: anytype) ![]u8 { | ... | @@ -146,7 +146,7 @@ fn parseName(allocator: *Allocator, header: ar_hdr, reader: anytype) ![]u8 { |
| 146 | return name; | 146 | return name; |
| 147 | } | 147 | } |
| 148 | 148 | ||
| 149 | fn parseTableOfContents(self: *Archive, allocator: *Allocator, reader: anytype) !void { | 149 | fn parseTableOfContents(self: *Archive, allocator: Allocator, reader: anytype) !void { |
| 150 | const symtab_size = try reader.readIntLittle(u32); | 150 | const symtab_size = try reader.readIntLittle(u32); |
| 151 | var symtab = try allocator.alloc(u8, symtab_size); | 151 | var symtab = try allocator.alloc(u8, symtab_size); |
| 152 | defer allocator.free(symtab); | 152 | defer allocator.free(symtab); |
| ... | @@ -188,7 +188,7 @@ fn parseTableOfContents(self: *Archive, allocator: *Allocator, reader: anytype) | ... | @@ -188,7 +188,7 @@ fn parseTableOfContents(self: *Archive, allocator: *Allocator, reader: anytype) |
| 188 | } | 188 | } |
| 189 | } | 189 | } |
| 190 | 190 | ||
| 191 | pub fn parseObject(self: Archive, allocator: *Allocator, target: std.Target, offset: u32) !Object { | 191 | pub fn parseObject(self: Archive, allocator: Allocator, target: std.Target, offset: u32) !Object { |
| 192 | const reader = self.file.reader(); | 192 | const reader = self.file.reader(); |
| 193 | try reader.context.seekTo(offset + self.library_offset); | 193 | try reader.context.seekTo(offset + self.library_offset); |
| 194 | 194 |
src/link/MachO/Atom.zig+2-2| ... | @@ -195,7 +195,7 @@ pub const empty = Atom{ | ... | @@ -195,7 +195,7 @@ pub const empty = Atom{ |
| 195 | .dbg_info_len = undefined, | 195 | .dbg_info_len = undefined, |
| 196 | }; | 196 | }; |
| 197 | 197 | ||
| 198 | pub fn deinit(self: *Atom, allocator: *Allocator) void { | 198 | pub fn deinit(self: *Atom, allocator: Allocator) void { |
| 199 | self.dices.deinit(allocator); | 199 | self.dices.deinit(allocator); |
| 200 | self.lazy_bindings.deinit(allocator); | 200 | self.lazy_bindings.deinit(allocator); |
| 201 | self.bindings.deinit(allocator); | 201 | self.bindings.deinit(allocator); |
| ... | @@ -246,7 +246,7 @@ pub fn freeListEligible(self: Atom, macho_file: MachO) bool { | ... | @@ -246,7 +246,7 @@ pub fn freeListEligible(self: Atom, macho_file: MachO) bool { |
| 246 | 246 | ||
| 247 | const RelocContext = struct { | 247 | const RelocContext = struct { |
| 248 | base_addr: u64 = 0, | 248 | base_addr: u64 = 0, |
| 249 | allocator: *Allocator, | 249 | allocator: Allocator, |
| 250 | object: *Object, | 250 | object: *Object, |
| 251 | macho_file: *MachO, | 251 | macho_file: *MachO, |
| 252 | }; | 252 | }; |
src/link/MachO/CodeSignature.zig+2-2| ... | @@ -58,7 +58,7 @@ cdir: ?CodeDirectory = null, | ... | @@ -58,7 +58,7 @@ cdir: ?CodeDirectory = null, |
| 58 | 58 | ||
| 59 | pub fn calcAdhocSignature( | 59 | pub fn calcAdhocSignature( |
| 60 | self: *CodeSignature, | 60 | self: *CodeSignature, |
| 61 | allocator: *Allocator, | 61 | allocator: Allocator, |
| 62 | file: fs.File, | 62 | file: fs.File, |
| 63 | id: []const u8, | 63 | id: []const u8, |
| 64 | text_segment: macho.segment_command_64, | 64 | text_segment: macho.segment_command_64, |
| ... | @@ -145,7 +145,7 @@ pub fn write(self: CodeSignature, writer: anytype) !void { | ... | @@ -145,7 +145,7 @@ pub fn write(self: CodeSignature, writer: anytype) !void { |
| 145 | try self.cdir.?.write(writer); | 145 | try self.cdir.?.write(writer); |
| 146 | } | 146 | } |
| 147 | 147 | ||
| 148 | pub fn deinit(self: *CodeSignature, allocator: *Allocator) void { | 148 | pub fn deinit(self: *CodeSignature, allocator: Allocator) void { |
| 149 | if (self.cdir) |*cdir| { | 149 | if (self.cdir) |*cdir| { |
| 150 | cdir.data.deinit(allocator); | 150 | cdir.data.deinit(allocator); |
| 151 | } | 151 | } |
src/link/MachO/DebugSymbols.zig+9-9| ... | @@ -104,7 +104,7 @@ const min_nop_size = 2; | ... | @@ -104,7 +104,7 @@ const min_nop_size = 2; |
| 104 | 104 | ||
| 105 | /// You must call this function *after* `MachO.populateMissingMetadata()` | 105 | /// You must call this function *after* `MachO.populateMissingMetadata()` |
| 106 | /// has been called to get a viable debug symbols output. | 106 | /// has been called to get a viable debug symbols output. |
| 107 | pub fn populateMissingMetadata(self: *DebugSymbols, allocator: *Allocator) !void { | 107 | pub fn populateMissingMetadata(self: *DebugSymbols, allocator: Allocator) !void { |
| 108 | if (self.uuid_cmd_index == null) { | 108 | if (self.uuid_cmd_index == null) { |
| 109 | const base_cmd = self.base.load_commands.items[self.base.uuid_cmd_index.?]; | 109 | const base_cmd = self.base.load_commands.items[self.base.uuid_cmd_index.?]; |
| 110 | self.uuid_cmd_index = @intCast(u16, self.load_commands.items.len); | 110 | self.uuid_cmd_index = @intCast(u16, self.load_commands.items.len); |
| ... | @@ -268,7 +268,7 @@ fn allocateSection(self: *DebugSymbols, sectname: []const u8, size: u64, alignme | ... | @@ -268,7 +268,7 @@ fn allocateSection(self: *DebugSymbols, sectname: []const u8, size: u64, alignme |
| 268 | return index; | 268 | return index; |
| 269 | } | 269 | } |
| 270 | 270 | ||
| 271 | pub fn flushModule(self: *DebugSymbols, allocator: *Allocator, options: link.Options) !void { | 271 | pub fn flushModule(self: *DebugSymbols, allocator: Allocator, options: link.Options) !void { |
| 272 | // TODO This linker code currently assumes there is only 1 compilation unit and it corresponds to the | 272 | // TODO This linker code currently assumes there is only 1 compilation unit and it corresponds to the |
| 273 | // Zig source code. | 273 | // Zig source code. |
| 274 | const module = options.module orelse return error.LinkingWithoutZigSourceUnimplemented; | 274 | const module = options.module orelse return error.LinkingWithoutZigSourceUnimplemented; |
| ... | @@ -577,7 +577,7 @@ pub fn flushModule(self: *DebugSymbols, allocator: *Allocator, options: link.Opt | ... | @@ -577,7 +577,7 @@ pub fn flushModule(self: *DebugSymbols, allocator: *Allocator, options: link.Opt |
| 577 | assert(!self.debug_string_table_dirty); | 577 | assert(!self.debug_string_table_dirty); |
| 578 | } | 578 | } |
| 579 | 579 | ||
| 580 | pub fn deinit(self: *DebugSymbols, allocator: *Allocator) void { | 580 | pub fn deinit(self: *DebugSymbols, allocator: Allocator) void { |
| 581 | self.dbg_info_decl_free_list.deinit(allocator); | 581 | self.dbg_info_decl_free_list.deinit(allocator); |
| 582 | self.dbg_line_fn_free_list.deinit(allocator); | 582 | self.dbg_line_fn_free_list.deinit(allocator); |
| 583 | self.debug_string_table.deinit(allocator); | 583 | self.debug_string_table.deinit(allocator); |
| ... | @@ -588,7 +588,7 @@ pub fn deinit(self: *DebugSymbols, allocator: *Allocator) void { | ... | @@ -588,7 +588,7 @@ pub fn deinit(self: *DebugSymbols, allocator: *Allocator) void { |
| 588 | self.file.close(); | 588 | self.file.close(); |
| 589 | } | 589 | } |
| 590 | 590 | ||
| 591 | fn copySegmentCommand(self: *DebugSymbols, allocator: *Allocator, base_cmd: SegmentCommand) !SegmentCommand { | 591 | fn copySegmentCommand(self: *DebugSymbols, allocator: Allocator, base_cmd: SegmentCommand) !SegmentCommand { |
| 592 | var cmd = SegmentCommand{ | 592 | var cmd = SegmentCommand{ |
| 593 | .inner = .{ | 593 | .inner = .{ |
| 594 | .segname = undefined, | 594 | .segname = undefined, |
| ... | @@ -648,7 +648,7 @@ fn updateDwarfSegment(self: *DebugSymbols) void { | ... | @@ -648,7 +648,7 @@ fn updateDwarfSegment(self: *DebugSymbols) void { |
| 648 | } | 648 | } |
| 649 | 649 | ||
| 650 | /// Writes all load commands and section headers. | 650 | /// Writes all load commands and section headers. |
| 651 | fn writeLoadCommands(self: *DebugSymbols, allocator: *Allocator) !void { | 651 | fn writeLoadCommands(self: *DebugSymbols, allocator: Allocator) !void { |
| 652 | if (!self.load_commands_dirty) return; | 652 | if (!self.load_commands_dirty) return; |
| 653 | 653 | ||
| 654 | var sizeofcmds: u32 = 0; | 654 | var sizeofcmds: u32 = 0; |
| ... | @@ -834,7 +834,7 @@ pub const DeclDebugBuffers = struct { | ... | @@ -834,7 +834,7 @@ pub const DeclDebugBuffers = struct { |
| 834 | /// Caller owns the returned memory. | 834 | /// Caller owns the returned memory. |
| 835 | pub fn initDeclDebugBuffers( | 835 | pub fn initDeclDebugBuffers( |
| 836 | self: *DebugSymbols, | 836 | self: *DebugSymbols, |
| 837 | allocator: *Allocator, | 837 | allocator: Allocator, |
| 838 | module: *Module, | 838 | module: *Module, |
| 839 | decl: *Module.Decl, | 839 | decl: *Module.Decl, |
| 840 | ) !DeclDebugBuffers { | 840 | ) !DeclDebugBuffers { |
| ... | @@ -930,7 +930,7 @@ pub fn initDeclDebugBuffers( | ... | @@ -930,7 +930,7 @@ pub fn initDeclDebugBuffers( |
| 930 | 930 | ||
| 931 | pub fn commitDeclDebugInfo( | 931 | pub fn commitDeclDebugInfo( |
| 932 | self: *DebugSymbols, | 932 | self: *DebugSymbols, |
| 933 | allocator: *Allocator, | 933 | allocator: Allocator, |
| 934 | module: *Module, | 934 | module: *Module, |
| 935 | decl: *Module.Decl, | 935 | decl: *Module.Decl, |
| 936 | debug_buffers: *DeclDebugBuffers, | 936 | debug_buffers: *DeclDebugBuffers, |
| ... | @@ -1141,7 +1141,7 @@ fn addDbgInfoType( | ... | @@ -1141,7 +1141,7 @@ fn addDbgInfoType( |
| 1141 | 1141 | ||
| 1142 | fn updateDeclDebugInfoAllocation( | 1142 | fn updateDeclDebugInfoAllocation( |
| 1143 | self: *DebugSymbols, | 1143 | self: *DebugSymbols, |
| 1144 | allocator: *Allocator, | 1144 | allocator: Allocator, |
| 1145 | text_block: *TextBlock, | 1145 | text_block: *TextBlock, |
| 1146 | len: u32, | 1146 | len: u32, |
| 1147 | ) !void { | 1147 | ) !void { |
| ... | @@ -1256,7 +1256,7 @@ fn getDebugLineProgramEnd(self: DebugSymbols) u32 { | ... | @@ -1256,7 +1256,7 @@ fn getDebugLineProgramEnd(self: DebugSymbols) u32 { |
| 1256 | } | 1256 | } |
| 1257 | 1257 | ||
| 1258 | /// TODO Improve this to use a table. | 1258 | /// TODO Improve this to use a table. |
| 1259 | fn makeDebugString(self: *DebugSymbols, allocator: *Allocator, bytes: []const u8) !u32 { | 1259 | fn makeDebugString(self: *DebugSymbols, allocator: Allocator, bytes: []const u8) !u32 { |
| 1260 | try self.debug_string_table.ensureUnusedCapacity(allocator, bytes.len + 1); | 1260 | try self.debug_string_table.ensureUnusedCapacity(allocator, bytes.len + 1); |
| 1261 | const result = self.debug_string_table.items.len; | 1261 | const result = self.debug_string_table.items.len; |
| 1262 | self.debug_string_table.appendSliceAssumeCapacity(bytes); | 1262 | self.debug_string_table.appendSliceAssumeCapacity(bytes); |
src/link/MachO/Dylib.zig+16-16| ... | @@ -44,7 +44,7 @@ pub const Id = struct { | ... | @@ -44,7 +44,7 @@ pub const Id = struct { |
| 44 | current_version: u32, | 44 | current_version: u32, |
| 45 | compatibility_version: u32, | 45 | compatibility_version: u32, |
| 46 | 46 | ||
| 47 | pub fn default(allocator: *Allocator, name: []const u8) !Id { | 47 | pub fn default(allocator: Allocator, name: []const u8) !Id { |
| 48 | return Id{ | 48 | return Id{ |
| 49 | .name = try allocator.dupe(u8, name), | 49 | .name = try allocator.dupe(u8, name), |
| 50 | .timestamp = 2, | 50 | .timestamp = 2, |
| ... | @@ -53,7 +53,7 @@ pub const Id = struct { | ... | @@ -53,7 +53,7 @@ pub const Id = struct { |
| 53 | }; | 53 | }; |
| 54 | } | 54 | } |
| 55 | 55 | ||
| 56 | pub fn fromLoadCommand(allocator: *Allocator, lc: commands.GenericCommandWithData(macho.dylib_command)) !Id { | 56 | pub fn fromLoadCommand(allocator: Allocator, lc: commands.GenericCommandWithData(macho.dylib_command)) !Id { |
| 57 | const dylib = lc.inner.dylib; | 57 | const dylib = lc.inner.dylib; |
| 58 | const dylib_name = @ptrCast([*:0]const u8, lc.data[dylib.name - @sizeOf(macho.dylib_command) ..]); | 58 | const dylib_name = @ptrCast([*:0]const u8, lc.data[dylib.name - @sizeOf(macho.dylib_command) ..]); |
| 59 | const name = try allocator.dupe(u8, mem.sliceTo(dylib_name, 0)); | 59 | const name = try allocator.dupe(u8, mem.sliceTo(dylib_name, 0)); |
| ... | @@ -66,7 +66,7 @@ pub const Id = struct { | ... | @@ -66,7 +66,7 @@ pub const Id = struct { |
| 66 | }; | 66 | }; |
| 67 | } | 67 | } |
| 68 | 68 | ||
| 69 | pub fn deinit(id: *Id, allocator: *Allocator) void { | 69 | pub fn deinit(id: *Id, allocator: Allocator) void { |
| 70 | allocator.free(id.name); | 70 | allocator.free(id.name); |
| 71 | } | 71 | } |
| 72 | 72 | ||
| ... | @@ -125,7 +125,7 @@ pub const Id = struct { | ... | @@ -125,7 +125,7 @@ pub const Id = struct { |
| 125 | } | 125 | } |
| 126 | }; | 126 | }; |
| 127 | 127 | ||
| 128 | pub fn deinit(self: *Dylib, allocator: *Allocator) void { | 128 | pub fn deinit(self: *Dylib, allocator: Allocator) void { |
| 129 | for (self.load_commands.items) |*lc| { | 129 | for (self.load_commands.items) |*lc| { |
| 130 | lc.deinit(allocator); | 130 | lc.deinit(allocator); |
| 131 | } | 131 | } |
| ... | @@ -143,7 +143,7 @@ pub fn deinit(self: *Dylib, allocator: *Allocator) void { | ... | @@ -143,7 +143,7 @@ pub fn deinit(self: *Dylib, allocator: *Allocator) void { |
| 143 | } | 143 | } |
| 144 | } | 144 | } |
| 145 | 145 | ||
| 146 | pub fn parse(self: *Dylib, allocator: *Allocator, target: std.Target, dependent_libs: anytype) !void { | 146 | pub fn parse(self: *Dylib, allocator: Allocator, target: std.Target, dependent_libs: anytype) !void { |
| 147 | log.debug("parsing shared library '{s}'", .{self.name}); | 147 | log.debug("parsing shared library '{s}'", .{self.name}); |
| 148 | 148 | ||
| 149 | self.library_offset = try fat.getLibraryOffset(self.file.reader(), target); | 149 | self.library_offset = try fat.getLibraryOffset(self.file.reader(), target); |
| ... | @@ -170,7 +170,7 @@ pub fn parse(self: *Dylib, allocator: *Allocator, target: std.Target, dependent_ | ... | @@ -170,7 +170,7 @@ pub fn parse(self: *Dylib, allocator: *Allocator, target: std.Target, dependent_ |
| 170 | try self.parseSymbols(allocator); | 170 | try self.parseSymbols(allocator); |
| 171 | } | 171 | } |
| 172 | 172 | ||
| 173 | fn readLoadCommands(self: *Dylib, allocator: *Allocator, reader: anytype, dependent_libs: anytype) !void { | 173 | fn readLoadCommands(self: *Dylib, allocator: Allocator, reader: anytype, dependent_libs: anytype) !void { |
| 174 | const should_lookup_reexports = self.header.?.flags & macho.MH_NO_REEXPORTED_DYLIBS == 0; | 174 | const should_lookup_reexports = self.header.?.flags & macho.MH_NO_REEXPORTED_DYLIBS == 0; |
| 175 | 175 | ||
| 176 | try self.load_commands.ensureUnusedCapacity(allocator, self.header.?.ncmds); | 176 | try self.load_commands.ensureUnusedCapacity(allocator, self.header.?.ncmds); |
| ... | @@ -203,7 +203,7 @@ fn readLoadCommands(self: *Dylib, allocator: *Allocator, reader: anytype, depend | ... | @@ -203,7 +203,7 @@ fn readLoadCommands(self: *Dylib, allocator: *Allocator, reader: anytype, depend |
| 203 | } | 203 | } |
| 204 | } | 204 | } |
| 205 | 205 | ||
| 206 | fn parseId(self: *Dylib, allocator: *Allocator) !void { | 206 | fn parseId(self: *Dylib, allocator: Allocator) !void { |
| 207 | const index = self.id_cmd_index orelse { | 207 | const index = self.id_cmd_index orelse { |
| 208 | log.debug("no LC_ID_DYLIB load command found; using hard-coded defaults...", .{}); | 208 | log.debug("no LC_ID_DYLIB load command found; using hard-coded defaults...", .{}); |
| 209 | self.id = try Id.default(allocator, self.name); | 209 | self.id = try Id.default(allocator, self.name); |
| ... | @@ -212,7 +212,7 @@ fn parseId(self: *Dylib, allocator: *Allocator) !void { | ... | @@ -212,7 +212,7 @@ fn parseId(self: *Dylib, allocator: *Allocator) !void { |
| 212 | self.id = try Id.fromLoadCommand(allocator, self.load_commands.items[index].Dylib); | 212 | self.id = try Id.fromLoadCommand(allocator, self.load_commands.items[index].Dylib); |
| 213 | } | 213 | } |
| 214 | 214 | ||
| 215 | fn parseSymbols(self: *Dylib, allocator: *Allocator) !void { | 215 | fn parseSymbols(self: *Dylib, allocator: Allocator) !void { |
| 216 | const index = self.symtab_cmd_index orelse return; | 216 | const index = self.symtab_cmd_index orelse return; |
| 217 | const symtab_cmd = self.load_commands.items[index].Symtab; | 217 | const symtab_cmd = self.load_commands.items[index].Symtab; |
| 218 | 218 | ||
| ... | @@ -236,7 +236,7 @@ fn parseSymbols(self: *Dylib, allocator: *Allocator) !void { | ... | @@ -236,7 +236,7 @@ fn parseSymbols(self: *Dylib, allocator: *Allocator) !void { |
| 236 | } | 236 | } |
| 237 | } | 237 | } |
| 238 | 238 | ||
| 239 | fn addObjCClassSymbol(self: *Dylib, allocator: *Allocator, sym_name: []const u8) !void { | 239 | fn addObjCClassSymbol(self: *Dylib, allocator: Allocator, sym_name: []const u8) !void { |
| 240 | const expanded = &[_][]const u8{ | 240 | const expanded = &[_][]const u8{ |
| 241 | try std.fmt.allocPrint(allocator, "_OBJC_CLASS_$_{s}", .{sym_name}), | 241 | try std.fmt.allocPrint(allocator, "_OBJC_CLASS_$_{s}", .{sym_name}), |
| 242 | try std.fmt.allocPrint(allocator, "_OBJC_METACLASS_$_{s}", .{sym_name}), | 242 | try std.fmt.allocPrint(allocator, "_OBJC_METACLASS_$_{s}", .{sym_name}), |
| ... | @@ -248,29 +248,29 @@ fn addObjCClassSymbol(self: *Dylib, allocator: *Allocator, sym_name: []const u8) | ... | @@ -248,29 +248,29 @@ fn addObjCClassSymbol(self: *Dylib, allocator: *Allocator, sym_name: []const u8) |
| 248 | } | 248 | } |
| 249 | } | 249 | } |
| 250 | 250 | ||
| 251 | fn addObjCIVarSymbol(self: *Dylib, allocator: *Allocator, sym_name: []const u8) !void { | 251 | fn addObjCIVarSymbol(self: *Dylib, allocator: Allocator, sym_name: []const u8) !void { |
| 252 | const expanded = try std.fmt.allocPrint(allocator, "_OBJC_IVAR_$_{s}", .{sym_name}); | 252 | const expanded = try std.fmt.allocPrint(allocator, "_OBJC_IVAR_$_{s}", .{sym_name}); |
| 253 | if (self.symbols.contains(expanded)) return; | 253 | if (self.symbols.contains(expanded)) return; |
| 254 | try self.symbols.putNoClobber(allocator, expanded, .{}); | 254 | try self.symbols.putNoClobber(allocator, expanded, .{}); |
| 255 | } | 255 | } |
| 256 | 256 | ||
| 257 | fn addObjCEhTypeSymbol(self: *Dylib, allocator: *Allocator, sym_name: []const u8) !void { | 257 | fn addObjCEhTypeSymbol(self: *Dylib, allocator: Allocator, sym_name: []const u8) !void { |
| 258 | const expanded = try std.fmt.allocPrint(allocator, "_OBJC_EHTYPE_$_{s}", .{sym_name}); | 258 | const expanded = try std.fmt.allocPrint(allocator, "_OBJC_EHTYPE_$_{s}", .{sym_name}); |
| 259 | if (self.symbols.contains(expanded)) return; | 259 | if (self.symbols.contains(expanded)) return; |
| 260 | try self.symbols.putNoClobber(allocator, expanded, .{}); | 260 | try self.symbols.putNoClobber(allocator, expanded, .{}); |
| 261 | } | 261 | } |
| 262 | 262 | ||
| 263 | fn addSymbol(self: *Dylib, allocator: *Allocator, sym_name: []const u8) !void { | 263 | fn addSymbol(self: *Dylib, allocator: Allocator, sym_name: []const u8) !void { |
| 264 | if (self.symbols.contains(sym_name)) return; | 264 | if (self.symbols.contains(sym_name)) return; |
| 265 | try self.symbols.putNoClobber(allocator, try allocator.dupe(u8, sym_name), {}); | 265 | try self.symbols.putNoClobber(allocator, try allocator.dupe(u8, sym_name), {}); |
| 266 | } | 266 | } |
| 267 | 267 | ||
| 268 | const TargetMatcher = struct { | 268 | const TargetMatcher = struct { |
| 269 | allocator: *Allocator, | 269 | allocator: Allocator, |
| 270 | target: std.Target, | 270 | target: std.Target, |
| 271 | target_strings: std.ArrayListUnmanaged([]const u8) = .{}, | 271 | target_strings: std.ArrayListUnmanaged([]const u8) = .{}, |
| 272 | 272 | ||
| 273 | fn init(allocator: *Allocator, target: std.Target) !TargetMatcher { | 273 | fn init(allocator: Allocator, target: std.Target) !TargetMatcher { |
| 274 | var self = TargetMatcher{ | 274 | var self = TargetMatcher{ |
| 275 | .allocator = allocator, | 275 | .allocator = allocator, |
| 276 | .target = target, | 276 | .target = target, |
| ... | @@ -297,7 +297,7 @@ const TargetMatcher = struct { | ... | @@ -297,7 +297,7 @@ const TargetMatcher = struct { |
| 297 | self.target_strings.deinit(self.allocator); | 297 | self.target_strings.deinit(self.allocator); |
| 298 | } | 298 | } |
| 299 | 299 | ||
| 300 | fn targetToAppleString(allocator: *Allocator, target: std.Target) ![]const u8 { | 300 | fn targetToAppleString(allocator: Allocator, target: std.Target) ![]const u8 { |
| 301 | const arch = switch (target.cpu.arch) { | 301 | const arch = switch (target.cpu.arch) { |
| 302 | .aarch64 => "arm64", | 302 | .aarch64 => "arm64", |
| 303 | .x86_64 => "x86_64", | 303 | .x86_64 => "x86_64", |
| ... | @@ -336,7 +336,7 @@ const TargetMatcher = struct { | ... | @@ -336,7 +336,7 @@ const TargetMatcher = struct { |
| 336 | 336 | ||
| 337 | pub fn parseFromStub( | 337 | pub fn parseFromStub( |
| 338 | self: *Dylib, | 338 | self: *Dylib, |
| 339 | allocator: *Allocator, | 339 | allocator: Allocator, |
| 340 | target: std.Target, | 340 | target: std.Target, |
| 341 | lib_stub: LibStub, | 341 | lib_stub: LibStub, |
| 342 | dependent_libs: anytype, | 342 | dependent_libs: anytype, |
src/link/MachO/Object.zig+11-11| ... | @@ -74,7 +74,7 @@ const DebugInfo = struct { | ... | @@ -74,7 +74,7 @@ const DebugInfo = struct { |
| 74 | debug_line: []u8, | 74 | debug_line: []u8, |
| 75 | debug_ranges: []u8, | 75 | debug_ranges: []u8, |
| 76 | 76 | ||
| 77 | pub fn parseFromObject(allocator: *Allocator, object: *const Object) !?DebugInfo { | 77 | pub fn parseFromObject(allocator: Allocator, object: *const Object) !?DebugInfo { |
| 78 | var debug_info = blk: { | 78 | var debug_info = blk: { |
| 79 | const index = object.dwarf_debug_info_index orelse return null; | 79 | const index = object.dwarf_debug_info_index orelse return null; |
| 80 | break :blk try object.readSection(allocator, index); | 80 | break :blk try object.readSection(allocator, index); |
| ... | @@ -118,7 +118,7 @@ const DebugInfo = struct { | ... | @@ -118,7 +118,7 @@ const DebugInfo = struct { |
| 118 | }; | 118 | }; |
| 119 | } | 119 | } |
| 120 | 120 | ||
| 121 | pub fn deinit(self: *DebugInfo, allocator: *Allocator) void { | 121 | pub fn deinit(self: *DebugInfo, allocator: Allocator) void { |
| 122 | allocator.free(self.debug_info); | 122 | allocator.free(self.debug_info); |
| 123 | allocator.free(self.debug_abbrev); | 123 | allocator.free(self.debug_abbrev); |
| 124 | allocator.free(self.debug_str); | 124 | allocator.free(self.debug_str); |
| ... | @@ -130,7 +130,7 @@ const DebugInfo = struct { | ... | @@ -130,7 +130,7 @@ const DebugInfo = struct { |
| 130 | } | 130 | } |
| 131 | }; | 131 | }; |
| 132 | 132 | ||
| 133 | pub fn deinit(self: *Object, allocator: *Allocator) void { | 133 | pub fn deinit(self: *Object, allocator: Allocator) void { |
| 134 | for (self.load_commands.items) |*lc| { | 134 | for (self.load_commands.items) |*lc| { |
| 135 | lc.deinit(allocator); | 135 | lc.deinit(allocator); |
| 136 | } | 136 | } |
| ... | @@ -160,7 +160,7 @@ pub fn deinit(self: *Object, allocator: *Allocator) void { | ... | @@ -160,7 +160,7 @@ pub fn deinit(self: *Object, allocator: *Allocator) void { |
| 160 | } | 160 | } |
| 161 | } | 161 | } |
| 162 | 162 | ||
| 163 | pub fn free(self: *Object, allocator: *Allocator, macho_file: *MachO) void { | 163 | pub fn free(self: *Object, allocator: Allocator, macho_file: *MachO) void { |
| 164 | log.debug("freeObject {*}", .{self}); | 164 | log.debug("freeObject {*}", .{self}); |
| 165 | 165 | ||
| 166 | var it = self.end_atoms.iterator(); | 166 | var it = self.end_atoms.iterator(); |
| ... | @@ -227,7 +227,7 @@ fn freeAtoms(self: *Object, macho_file: *MachO) void { | ... | @@ -227,7 +227,7 @@ fn freeAtoms(self: *Object, macho_file: *MachO) void { |
| 227 | } | 227 | } |
| 228 | } | 228 | } |
| 229 | 229 | ||
| 230 | pub fn parse(self: *Object, allocator: *Allocator, target: std.Target) !void { | 230 | pub fn parse(self: *Object, allocator: Allocator, target: std.Target) !void { |
| 231 | const reader = self.file.reader(); | 231 | const reader = self.file.reader(); |
| 232 | if (self.file_offset) |offset| { | 232 | if (self.file_offset) |offset| { |
| 233 | try reader.context.seekTo(offset); | 233 | try reader.context.seekTo(offset); |
| ... | @@ -263,7 +263,7 @@ pub fn parse(self: *Object, allocator: *Allocator, target: std.Target) !void { | ... | @@ -263,7 +263,7 @@ pub fn parse(self: *Object, allocator: *Allocator, target: std.Target) !void { |
| 263 | try self.parseDebugInfo(allocator); | 263 | try self.parseDebugInfo(allocator); |
| 264 | } | 264 | } |
| 265 | 265 | ||
| 266 | pub fn readLoadCommands(self: *Object, allocator: *Allocator, reader: anytype) !void { | 266 | pub fn readLoadCommands(self: *Object, allocator: Allocator, reader: anytype) !void { |
| 267 | const header = self.header orelse unreachable; // Unreachable here signifies a fatal unexplored condition. | 267 | const header = self.header orelse unreachable; // Unreachable here signifies a fatal unexplored condition. |
| 268 | const offset = self.file_offset orelse 0; | 268 | const offset = self.file_offset orelse 0; |
| 269 | 269 | ||
| ... | @@ -381,7 +381,7 @@ fn filterDice(dices: []macho.data_in_code_entry, start_addr: u64, end_addr: u64) | ... | @@ -381,7 +381,7 @@ fn filterDice(dices: []macho.data_in_code_entry, start_addr: u64, end_addr: u64) |
| 381 | return dices[start..end]; | 381 | return dices[start..end]; |
| 382 | } | 382 | } |
| 383 | 383 | ||
| 384 | pub fn parseIntoAtoms(self: *Object, allocator: *Allocator, macho_file: *MachO) !void { | 384 | pub fn parseIntoAtoms(self: *Object, allocator: Allocator, macho_file: *MachO) !void { |
| 385 | const tracy = trace(@src()); | 385 | const tracy = trace(@src()); |
| 386 | defer tracy.end(); | 386 | defer tracy.end(); |
| 387 | 387 | ||
| ... | @@ -555,7 +555,7 @@ pub fn parseIntoAtoms(self: *Object, allocator: *Allocator, macho_file: *MachO) | ... | @@ -555,7 +555,7 @@ pub fn parseIntoAtoms(self: *Object, allocator: *Allocator, macho_file: *MachO) |
| 555 | } | 555 | } |
| 556 | } | 556 | } |
| 557 | 557 | ||
| 558 | fn parseSymtab(self: *Object, allocator: *Allocator) !void { | 558 | fn parseSymtab(self: *Object, allocator: Allocator) !void { |
| 559 | const index = self.symtab_cmd_index orelse return; | 559 | const index = self.symtab_cmd_index orelse return; |
| 560 | const symtab_cmd = self.load_commands.items[index].Symtab; | 560 | const symtab_cmd = self.load_commands.items[index].Symtab; |
| 561 | 561 | ||
| ... | @@ -571,7 +571,7 @@ fn parseSymtab(self: *Object, allocator: *Allocator) !void { | ... | @@ -571,7 +571,7 @@ fn parseSymtab(self: *Object, allocator: *Allocator) !void { |
| 571 | try self.strtab.appendSlice(allocator, strtab); | 571 | try self.strtab.appendSlice(allocator, strtab); |
| 572 | } | 572 | } |
| 573 | 573 | ||
| 574 | pub fn parseDebugInfo(self: *Object, allocator: *Allocator) !void { | 574 | pub fn parseDebugInfo(self: *Object, allocator: Allocator) !void { |
| 575 | log.debug("parsing debug info in '{s}'", .{self.name}); | 575 | log.debug("parsing debug info in '{s}'", .{self.name}); |
| 576 | 576 | ||
| 577 | var debug_info = blk: { | 577 | var debug_info = blk: { |
| ... | @@ -603,7 +603,7 @@ pub fn parseDebugInfo(self: *Object, allocator: *Allocator) !void { | ... | @@ -603,7 +603,7 @@ pub fn parseDebugInfo(self: *Object, allocator: *Allocator) !void { |
| 603 | } | 603 | } |
| 604 | } | 604 | } |
| 605 | 605 | ||
| 606 | pub fn parseDataInCode(self: *Object, allocator: *Allocator) !void { | 606 | pub fn parseDataInCode(self: *Object, allocator: Allocator) !void { |
| 607 | const index = self.data_in_code_cmd_index orelse return; | 607 | const index = self.data_in_code_cmd_index orelse return; |
| 608 | const data_in_code = self.load_commands.items[index].LinkeditData; | 608 | const data_in_code = self.load_commands.items[index].LinkeditData; |
| 609 | 609 | ||
| ... | @@ -623,7 +623,7 @@ pub fn parseDataInCode(self: *Object, allocator: *Allocator) !void { | ... | @@ -623,7 +623,7 @@ pub fn parseDataInCode(self: *Object, allocator: *Allocator) !void { |
| 623 | } | 623 | } |
| 624 | } | 624 | } |
| 625 | 625 | ||
| 626 | fn readSection(self: Object, allocator: *Allocator, index: u16) ![]u8 { | 626 | fn readSection(self: Object, allocator: Allocator, index: u16) ![]u8 { |
| 627 | const seg = self.load_commands.items[self.segment_cmd_index.?].Segment; | 627 | const seg = self.load_commands.items[self.segment_cmd_index.?].Segment; |
| 628 | const sect = seg.sections.items[index]; | 628 | const sect = seg.sections.items[index]; |
| 629 | var buffer = try allocator.alloc(u8, @intCast(usize, sect.size)); | 629 | var buffer = try allocator.alloc(u8, @intCast(usize, sect.size)); |
src/link/MachO/Trie.zig+9-9| ... | @@ -65,7 +65,7 @@ pub const Node = struct { | ... | @@ -65,7 +65,7 @@ pub const Node = struct { |
| 65 | to: *Node, | 65 | to: *Node, |
| 66 | label: []u8, | 66 | label: []u8, |
| 67 | 67 | ||
| 68 | fn deinit(self: *Edge, allocator: *Allocator) void { | 68 | fn deinit(self: *Edge, allocator: Allocator) void { |
| 69 | self.to.deinit(allocator); | 69 | self.to.deinit(allocator); |
| 70 | allocator.destroy(self.to); | 70 | allocator.destroy(self.to); |
| 71 | allocator.free(self.label); | 71 | allocator.free(self.label); |
| ... | @@ -75,7 +75,7 @@ pub const Node = struct { | ... | @@ -75,7 +75,7 @@ pub const Node = struct { |
| 75 | } | 75 | } |
| 76 | }; | 76 | }; |
| 77 | 77 | ||
| 78 | fn deinit(self: *Node, allocator: *Allocator) void { | 78 | fn deinit(self: *Node, allocator: Allocator) void { |
| 79 | for (self.edges.items) |*edge| { | 79 | for (self.edges.items) |*edge| { |
| 80 | edge.deinit(allocator); | 80 | edge.deinit(allocator); |
| 81 | } | 81 | } |
| ... | @@ -83,7 +83,7 @@ pub const Node = struct { | ... | @@ -83,7 +83,7 @@ pub const Node = struct { |
| 83 | } | 83 | } |
| 84 | 84 | ||
| 85 | /// Inserts a new node starting from `self`. | 85 | /// Inserts a new node starting from `self`. |
| 86 | fn put(self: *Node, allocator: *Allocator, label: []const u8) !*Node { | 86 | fn put(self: *Node, allocator: Allocator, label: []const u8) !*Node { |
| 87 | // Check for match with edges from this node. | 87 | // Check for match with edges from this node. |
| 88 | for (self.edges.items) |*edge| { | 88 | for (self.edges.items) |*edge| { |
| 89 | const match = mem.indexOfDiff(u8, edge.label, label) orelse return edge.to; | 89 | const match = mem.indexOfDiff(u8, edge.label, label) orelse return edge.to; |
| ... | @@ -126,7 +126,7 @@ pub const Node = struct { | ... | @@ -126,7 +126,7 @@ pub const Node = struct { |
| 126 | } | 126 | } |
| 127 | 127 | ||
| 128 | /// Recursively parses the node from the input byte stream. | 128 | /// Recursively parses the node from the input byte stream. |
| 129 | fn read(self: *Node, allocator: *Allocator, reader: anytype) Trie.ReadError!usize { | 129 | fn read(self: *Node, allocator: Allocator, reader: anytype) Trie.ReadError!usize { |
| 130 | self.node_dirty = true; | 130 | self.node_dirty = true; |
| 131 | const trie_offset = try reader.context.getPos(); | 131 | const trie_offset = try reader.context.getPos(); |
| 132 | self.trie_offset = trie_offset; | 132 | self.trie_offset = trie_offset; |
| ... | @@ -308,7 +308,7 @@ pub const ExportSymbol = struct { | ... | @@ -308,7 +308,7 @@ pub const ExportSymbol = struct { |
| 308 | /// Insert a symbol into the trie, updating the prefixes in the process. | 308 | /// Insert a symbol into the trie, updating the prefixes in the process. |
| 309 | /// This operation may change the layout of the trie by splicing edges in | 309 | /// This operation may change the layout of the trie by splicing edges in |
| 310 | /// certain circumstances. | 310 | /// certain circumstances. |
| 311 | pub fn put(self: *Trie, allocator: *Allocator, symbol: ExportSymbol) !void { | 311 | pub fn put(self: *Trie, allocator: Allocator, symbol: ExportSymbol) !void { |
| 312 | try self.createRoot(allocator); | 312 | try self.createRoot(allocator); |
| 313 | const node = try self.root.?.put(allocator, symbol.name); | 313 | const node = try self.root.?.put(allocator, symbol.name); |
| 314 | node.terminal_info = .{ | 314 | node.terminal_info = .{ |
| ... | @@ -322,7 +322,7 @@ pub fn put(self: *Trie, allocator: *Allocator, symbol: ExportSymbol) !void { | ... | @@ -322,7 +322,7 @@ pub fn put(self: *Trie, allocator: *Allocator, symbol: ExportSymbol) !void { |
| 322 | /// This step performs multiple passes through the trie ensuring | 322 | /// This step performs multiple passes through the trie ensuring |
| 323 | /// there are no gaps after every `Node` is ULEB128 encoded. | 323 | /// there are no gaps after every `Node` is ULEB128 encoded. |
| 324 | /// Call this method before trying to `write` the trie to a byte stream. | 324 | /// Call this method before trying to `write` the trie to a byte stream. |
| 325 | pub fn finalize(self: *Trie, allocator: *Allocator) !void { | 325 | pub fn finalize(self: *Trie, allocator: Allocator) !void { |
| 326 | if (!self.trie_dirty) return; | 326 | if (!self.trie_dirty) return; |
| 327 | 327 | ||
| 328 | self.ordered_nodes.shrinkRetainingCapacity(0); | 328 | self.ordered_nodes.shrinkRetainingCapacity(0); |
| ... | @@ -361,7 +361,7 @@ const ReadError = error{ | ... | @@ -361,7 +361,7 @@ const ReadError = error{ |
| 361 | }; | 361 | }; |
| 362 | 362 | ||
| 363 | /// Parse the trie from a byte stream. | 363 | /// Parse the trie from a byte stream. |
| 364 | pub fn read(self: *Trie, allocator: *Allocator, reader: anytype) ReadError!usize { | 364 | pub fn read(self: *Trie, allocator: Allocator, reader: anytype) ReadError!usize { |
| 365 | try self.createRoot(allocator); | 365 | try self.createRoot(allocator); |
| 366 | return self.root.?.read(allocator, reader); | 366 | return self.root.?.read(allocator, reader); |
| 367 | } | 367 | } |
| ... | @@ -377,7 +377,7 @@ pub fn write(self: Trie, writer: anytype) !u64 { | ... | @@ -377,7 +377,7 @@ pub fn write(self: Trie, writer: anytype) !u64 { |
| 377 | return counting_writer.bytes_written; | 377 | return counting_writer.bytes_written; |
| 378 | } | 378 | } |
| 379 | 379 | ||
| 380 | pub fn deinit(self: *Trie, allocator: *Allocator) void { | 380 | pub fn deinit(self: *Trie, allocator: Allocator) void { |
| 381 | if (self.root) |root| { | 381 | if (self.root) |root| { |
| 382 | root.deinit(allocator); | 382 | root.deinit(allocator); |
| 383 | allocator.destroy(root); | 383 | allocator.destroy(root); |
| ... | @@ -385,7 +385,7 @@ pub fn deinit(self: *Trie, allocator: *Allocator) void { | ... | @@ -385,7 +385,7 @@ pub fn deinit(self: *Trie, allocator: *Allocator) void { |
| 385 | self.ordered_nodes.deinit(allocator); | 385 | self.ordered_nodes.deinit(allocator); |
| 386 | } | 386 | } |
| 387 | 387 | ||
| 388 | fn createRoot(self: *Trie, allocator: *Allocator) !void { | 388 | fn createRoot(self: *Trie, allocator: Allocator) !void { |
| 389 | if (self.root == null) { | 389 | if (self.root == null) { |
| 390 | const root = try allocator.create(Node); | 390 | const root = try allocator.create(Node); |
| 391 | root.* = .{ .base = self }; | 391 | root.* = .{ .base = self }; |
src/link/MachO/commands.zig+8-8| ... | @@ -50,7 +50,7 @@ pub const LoadCommand = union(enum) { | ... | @@ -50,7 +50,7 @@ pub const LoadCommand = union(enum) { |
| 50 | Rpath: GenericCommandWithData(macho.rpath_command), | 50 | Rpath: GenericCommandWithData(macho.rpath_command), |
| 51 | Unknown: GenericCommandWithData(macho.load_command), | 51 | Unknown: GenericCommandWithData(macho.load_command), |
| 52 | 52 | ||
| 53 | pub fn read(allocator: *Allocator, reader: anytype) !LoadCommand { | 53 | pub fn read(allocator: Allocator, reader: anytype) !LoadCommand { |
| 54 | const header = try reader.readStruct(macho.load_command); | 54 | const header = try reader.readStruct(macho.load_command); |
| 55 | var buffer = try allocator.alloc(u8, header.cmdsize); | 55 | var buffer = try allocator.alloc(u8, header.cmdsize); |
| 56 | defer allocator.free(buffer); | 56 | defer allocator.free(buffer); |
| ... | @@ -177,7 +177,7 @@ pub const LoadCommand = union(enum) { | ... | @@ -177,7 +177,7 @@ pub const LoadCommand = union(enum) { |
| 177 | }; | 177 | }; |
| 178 | } | 178 | } |
| 179 | 179 | ||
| 180 | pub fn deinit(self: *LoadCommand, allocator: *Allocator) void { | 180 | pub fn deinit(self: *LoadCommand, allocator: Allocator) void { |
| 181 | return switch (self.*) { | 181 | return switch (self.*) { |
| 182 | .Segment => |*x| x.deinit(allocator), | 182 | .Segment => |*x| x.deinit(allocator), |
| 183 | .Dylinker => |*x| x.deinit(allocator), | 183 | .Dylinker => |*x| x.deinit(allocator), |
| ... | @@ -218,7 +218,7 @@ pub const SegmentCommand = struct { | ... | @@ -218,7 +218,7 @@ pub const SegmentCommand = struct { |
| 218 | inner: macho.segment_command_64, | 218 | inner: macho.segment_command_64, |
| 219 | sections: std.ArrayListUnmanaged(macho.section_64) = .{}, | 219 | sections: std.ArrayListUnmanaged(macho.section_64) = .{}, |
| 220 | 220 | ||
| 221 | pub fn read(alloc: *Allocator, reader: anytype) !SegmentCommand { | 221 | pub fn read(alloc: Allocator, reader: anytype) !SegmentCommand { |
| 222 | const inner = try reader.readStruct(macho.segment_command_64); | 222 | const inner = try reader.readStruct(macho.segment_command_64); |
| 223 | var segment = SegmentCommand{ | 223 | var segment = SegmentCommand{ |
| 224 | .inner = inner, | 224 | .inner = inner, |
| ... | @@ -241,7 +241,7 @@ pub const SegmentCommand = struct { | ... | @@ -241,7 +241,7 @@ pub const SegmentCommand = struct { |
| 241 | } | 241 | } |
| 242 | } | 242 | } |
| 243 | 243 | ||
| 244 | pub fn deinit(self: *SegmentCommand, alloc: *Allocator) void { | 244 | pub fn deinit(self: *SegmentCommand, alloc: Allocator) void { |
| 245 | self.sections.deinit(alloc); | 245 | self.sections.deinit(alloc); |
| 246 | } | 246 | } |
| 247 | 247 | ||
| ... | @@ -299,7 +299,7 @@ pub fn GenericCommandWithData(comptime Cmd: type) type { | ... | @@ -299,7 +299,7 @@ pub fn GenericCommandWithData(comptime Cmd: type) type { |
| 299 | 299 | ||
| 300 | const Self = @This(); | 300 | const Self = @This(); |
| 301 | 301 | ||
| 302 | pub fn read(allocator: *Allocator, reader: anytype) !Self { | 302 | pub fn read(allocator: Allocator, reader: anytype) !Self { |
| 303 | const inner = try reader.readStruct(Cmd); | 303 | const inner = try reader.readStruct(Cmd); |
| 304 | var data = try allocator.alloc(u8, inner.cmdsize - @sizeOf(Cmd)); | 304 | var data = try allocator.alloc(u8, inner.cmdsize - @sizeOf(Cmd)); |
| 305 | errdefer allocator.free(data); | 305 | errdefer allocator.free(data); |
| ... | @@ -315,7 +315,7 @@ pub fn GenericCommandWithData(comptime Cmd: type) type { | ... | @@ -315,7 +315,7 @@ pub fn GenericCommandWithData(comptime Cmd: type) type { |
| 315 | try writer.writeAll(self.data); | 315 | try writer.writeAll(self.data); |
| 316 | } | 316 | } |
| 317 | 317 | ||
| 318 | pub fn deinit(self: *Self, allocator: *Allocator) void { | 318 | pub fn deinit(self: *Self, allocator: Allocator) void { |
| 319 | allocator.free(self.data); | 319 | allocator.free(self.data); |
| 320 | } | 320 | } |
| 321 | 321 | ||
| ... | @@ -327,7 +327,7 @@ pub fn GenericCommandWithData(comptime Cmd: type) type { | ... | @@ -327,7 +327,7 @@ pub fn GenericCommandWithData(comptime Cmd: type) type { |
| 327 | } | 327 | } |
| 328 | 328 | ||
| 329 | pub fn createLoadDylibCommand( | 329 | pub fn createLoadDylibCommand( |
| 330 | allocator: *Allocator, | 330 | allocator: Allocator, |
| 331 | name: []const u8, | 331 | name: []const u8, |
| 332 | timestamp: u32, | 332 | timestamp: u32, |
| 333 | current_version: u32, | 333 | current_version: u32, |
| ... | @@ -395,7 +395,7 @@ pub fn sectionIsDontDeadStripIfReferencesLive(sect: macho.section_64) bool { | ... | @@ -395,7 +395,7 @@ pub fn sectionIsDontDeadStripIfReferencesLive(sect: macho.section_64) bool { |
| 395 | return sectionAttrs(sect) & macho.S_ATTR_LIVE_SUPPORT != 0; | 395 | return sectionAttrs(sect) & macho.S_ATTR_LIVE_SUPPORT != 0; |
| 396 | } | 396 | } |
| 397 | 397 | ||
| 398 | fn testRead(allocator: *Allocator, buffer: []const u8, expected: anytype) !void { | 398 | fn testRead(allocator: Allocator, buffer: []const u8, expected: anytype) !void { |
| 399 | var stream = io.fixedBufferStream(buffer); | 399 | var stream = io.fixedBufferStream(buffer); |
| 400 | var given = try LoadCommand.read(allocator, stream.reader()); | 400 | var given = try LoadCommand.read(allocator, stream.reader()); |
| 401 | defer given.deinit(allocator); | 401 | defer given.deinit(allocator); |
src/link/Plan9.zig+2-2| ... | @@ -132,7 +132,7 @@ pub fn defaultBaseAddrs(arch: std.Target.Cpu.Arch) Bases { | ... | @@ -132,7 +132,7 @@ pub fn defaultBaseAddrs(arch: std.Target.Cpu.Arch) Bases { |
| 132 | 132 | ||
| 133 | pub const PtrWidth = enum { p32, p64 }; | 133 | pub const PtrWidth = enum { p32, p64 }; |
| 134 | 134 | ||
| 135 | pub fn createEmpty(gpa: *Allocator, options: link.Options) !*Plan9 { | 135 | pub fn createEmpty(gpa: Allocator, options: link.Options) !*Plan9 { |
| 136 | if (options.use_llvm) | 136 | if (options.use_llvm) |
| 137 | return error.LLVMBackendDoesNotSupportPlan9; | 137 | return error.LLVMBackendDoesNotSupportPlan9; |
| 138 | const sixtyfour_bit: bool = switch (options.target.cpu.arch.ptrBitWidth()) { | 138 | const sixtyfour_bit: bool = switch (options.target.cpu.arch.ptrBitWidth()) { |
| ... | @@ -621,7 +621,7 @@ pub fn deinit(self: *Plan9) void { | ... | @@ -621,7 +621,7 @@ pub fn deinit(self: *Plan9) void { |
| 621 | 621 | ||
| 622 | pub const Export = ?usize; | 622 | pub const Export = ?usize; |
| 623 | pub const base_tag = .plan9; | 623 | pub const base_tag = .plan9; |
| 624 | pub fn openPath(allocator: *Allocator, sub_path: []const u8, options: link.Options) !*Plan9 { | 624 | pub fn openPath(allocator: Allocator, sub_path: []const u8, options: link.Options) !*Plan9 { |
| 625 | if (options.use_llvm) | 625 | if (options.use_llvm) |
| 626 | return error.LLVMBackendDoesNotSupportPlan9; | 626 | return error.LLVMBackendDoesNotSupportPlan9; |
| 627 | assert(options.object_format == .plan9); | 627 | assert(options.object_format == .plan9); |
src/link/SpirV.zig+2-2| ... | @@ -58,7 +58,7 @@ const DeclGenContext = struct { | ... | @@ -58,7 +58,7 @@ const DeclGenContext = struct { |
| 58 | liveness: Liveness, | 58 | liveness: Liveness, |
| 59 | }; | 59 | }; |
| 60 | 60 | ||
| 61 | pub fn createEmpty(gpa: *Allocator, options: link.Options) !*SpirV { | 61 | pub fn createEmpty(gpa: Allocator, options: link.Options) !*SpirV { |
| 62 | const spirv = try gpa.create(SpirV); | 62 | const spirv = try gpa.create(SpirV); |
| 63 | spirv.* = .{ | 63 | spirv.* = .{ |
| 64 | .base = .{ | 64 | .base = .{ |
| ... | @@ -87,7 +87,7 @@ pub fn createEmpty(gpa: *Allocator, options: link.Options) !*SpirV { | ... | @@ -87,7 +87,7 @@ pub fn createEmpty(gpa: *Allocator, options: link.Options) !*SpirV { |
| 87 | return spirv; | 87 | return spirv; |
| 88 | } | 88 | } |
| 89 | 89 | ||
| 90 | pub fn openPath(allocator: *Allocator, sub_path: []const u8, options: link.Options) !*SpirV { | 90 | pub fn openPath(allocator: Allocator, sub_path: []const u8, options: link.Options) !*SpirV { |
| 91 | assert(options.object_format == .spirv); | 91 | assert(options.object_format == .spirv); |
| 92 | 92 | ||
| 93 | if (options.use_llvm) return error.LLVM_BackendIsTODO_ForSpirV; // TODO: LLVM Doesn't support SpirV at all. | 93 | if (options.use_llvm) return error.LLVM_BackendIsTODO_ForSpirV; // TODO: LLVM Doesn't support SpirV at all. |
src/link/Wasm.zig+2-2| ... | @@ -97,7 +97,7 @@ pub const FnData = struct { | ... | @@ -97,7 +97,7 @@ pub const FnData = struct { |
| 97 | }; | 97 | }; |
| 98 | }; | 98 | }; |
| 99 | 99 | ||
| 100 | pub fn openPath(allocator: *Allocator, sub_path: []const u8, options: link.Options) !*Wasm { | 100 | pub fn openPath(allocator: Allocator, sub_path: []const u8, options: link.Options) !*Wasm { |
| 101 | assert(options.object_format == .wasm); | 101 | assert(options.object_format == .wasm); |
| 102 | 102 | ||
| 103 | if (build_options.have_llvm and options.use_llvm) { | 103 | if (build_options.have_llvm and options.use_llvm) { |
| ... | @@ -138,7 +138,7 @@ pub fn openPath(allocator: *Allocator, sub_path: []const u8, options: link.Optio | ... | @@ -138,7 +138,7 @@ pub fn openPath(allocator: *Allocator, sub_path: []const u8, options: link.Optio |
| 138 | return wasm_bin; | 138 | return wasm_bin; |
| 139 | } | 139 | } |
| 140 | 140 | ||
| 141 | pub fn createEmpty(gpa: *Allocator, options: link.Options) !*Wasm { | 141 | pub fn createEmpty(gpa: Allocator, options: link.Options) !*Wasm { |
| 142 | const wasm_bin = try gpa.create(Wasm); | 142 | const wasm_bin = try gpa.create(Wasm); |
| 143 | wasm_bin.* = .{ | 143 | wasm_bin.* = .{ |
| 144 | .base = .{ | 144 | .base = .{ |
src/link/Wasm/Atom.zig+1-1| ... | @@ -42,7 +42,7 @@ pub const empty: Atom = .{ | ... | @@ -42,7 +42,7 @@ pub const empty: Atom = .{ |
| 42 | }; | 42 | }; |
| 43 | 43 | ||
| 44 | /// Frees all resources owned by this `Atom`. | 44 | /// Frees all resources owned by this `Atom`. |
| 45 | pub fn deinit(self: *Atom, gpa: *Allocator) void { | 45 | pub fn deinit(self: *Atom, gpa: Allocator) void { |
| 46 | self.relocs.deinit(gpa); | 46 | self.relocs.deinit(gpa); |
| 47 | self.code.deinit(gpa); | 47 | self.code.deinit(gpa); |
| 48 | } | 48 | } |
src/link/tapi.zig+1-1| ... | @@ -106,7 +106,7 @@ pub const LibStub = struct { | ... | @@ -106,7 +106,7 @@ pub const LibStub = struct { |
| 106 | /// Typed contents of the tbd file. | 106 | /// Typed contents of the tbd file. |
| 107 | inner: []Tbd, | 107 | inner: []Tbd, |
| 108 | 108 | ||
| 109 | pub fn loadFromFile(allocator: *Allocator, file: fs.File) !LibStub { | 109 | pub fn loadFromFile(allocator: Allocator, file: fs.File) !LibStub { |
| 110 | const source = try file.readToEndAlloc(allocator, std.math.maxInt(u32)); | 110 | const source = try file.readToEndAlloc(allocator, std.math.maxInt(u32)); |
| 111 | defer allocator.free(source); | 111 | defer allocator.free(source); |
| 112 | 112 |
src/link/tapi/parse.zig+7-7| ... | @@ -37,7 +37,7 @@ pub const Node = struct { | ... | @@ -37,7 +37,7 @@ pub const Node = struct { |
| 37 | return @fieldParentPtr(T, "base", self); | 37 | return @fieldParentPtr(T, "base", self); |
| 38 | } | 38 | } |
| 39 | 39 | ||
| 40 | pub fn deinit(self: *Node, allocator: *Allocator) void { | 40 | pub fn deinit(self: *Node, allocator: Allocator) void { |
| 41 | switch (self.tag) { | 41 | switch (self.tag) { |
| 42 | .doc => @fieldParentPtr(Node.Doc, "base", self).deinit(allocator), | 42 | .doc => @fieldParentPtr(Node.Doc, "base", self).deinit(allocator), |
| 43 | .map => @fieldParentPtr(Node.Map, "base", self).deinit(allocator), | 43 | .map => @fieldParentPtr(Node.Map, "base", self).deinit(allocator), |
| ... | @@ -69,7 +69,7 @@ pub const Node = struct { | ... | @@ -69,7 +69,7 @@ pub const Node = struct { |
| 69 | 69 | ||
| 70 | pub const base_tag: Node.Tag = .doc; | 70 | pub const base_tag: Node.Tag = .doc; |
| 71 | 71 | ||
| 72 | pub fn deinit(self: *Doc, allocator: *Allocator) void { | 72 | pub fn deinit(self: *Doc, allocator: Allocator) void { |
| 73 | if (self.value) |node| { | 73 | if (self.value) |node| { |
| 74 | node.deinit(allocator); | 74 | node.deinit(allocator); |
| 75 | allocator.destroy(node); | 75 | allocator.destroy(node); |
| ... | @@ -113,7 +113,7 @@ pub const Node = struct { | ... | @@ -113,7 +113,7 @@ pub const Node = struct { |
| 113 | value: *Node, | 113 | value: *Node, |
| 114 | }; | 114 | }; |
| 115 | 115 | ||
| 116 | pub fn deinit(self: *Map, allocator: *Allocator) void { | 116 | pub fn deinit(self: *Map, allocator: Allocator) void { |
| 117 | for (self.values.items) |entry| { | 117 | for (self.values.items) |entry| { |
| 118 | entry.value.deinit(allocator); | 118 | entry.value.deinit(allocator); |
| 119 | allocator.destroy(entry.value); | 119 | allocator.destroy(entry.value); |
| ... | @@ -149,7 +149,7 @@ pub const Node = struct { | ... | @@ -149,7 +149,7 @@ pub const Node = struct { |
| 149 | 149 | ||
| 150 | pub const base_tag: Node.Tag = .list; | 150 | pub const base_tag: Node.Tag = .list; |
| 151 | 151 | ||
| 152 | pub fn deinit(self: *List, allocator: *Allocator) void { | 152 | pub fn deinit(self: *List, allocator: Allocator) void { |
| 153 | for (self.values.items) |node| { | 153 | for (self.values.items) |node| { |
| 154 | node.deinit(allocator); | 154 | node.deinit(allocator); |
| 155 | allocator.destroy(node); | 155 | allocator.destroy(node); |
| ... | @@ -198,12 +198,12 @@ pub const Node = struct { | ... | @@ -198,12 +198,12 @@ pub const Node = struct { |
| 198 | }; | 198 | }; |
| 199 | 199 | ||
| 200 | pub const Tree = struct { | 200 | pub const Tree = struct { |
| 201 | allocator: *Allocator, | 201 | allocator: Allocator, |
| 202 | source: []const u8, | 202 | source: []const u8, |
| 203 | tokens: []Token, | 203 | tokens: []Token, |
| 204 | docs: std.ArrayListUnmanaged(*Node) = .{}, | 204 | docs: std.ArrayListUnmanaged(*Node) = .{}, |
| 205 | 205 | ||
| 206 | pub fn init(allocator: *Allocator) Tree { | 206 | pub fn init(allocator: Allocator) Tree { |
| 207 | return .{ | 207 | return .{ |
| 208 | .allocator = allocator, | 208 | .allocator = allocator, |
| 209 | .source = undefined, | 209 | .source = undefined, |
| ... | @@ -266,7 +266,7 @@ pub const Tree = struct { | ... | @@ -266,7 +266,7 @@ pub const Tree = struct { |
| 266 | }; | 266 | }; |
| 267 | 267 | ||
| 268 | const Parser = struct { | 268 | const Parser = struct { |
| 269 | allocator: *Allocator, | 269 | allocator: Allocator, |
| 270 | tree: *Tree, | 270 | tree: *Tree, |
| 271 | token_it: *TokenIterator, | 271 | token_it: *TokenIterator, |
| 272 | scopes: std.ArrayListUnmanaged(Scope) = .{}, | 272 | scopes: std.ArrayListUnmanaged(Scope) = .{}, |
src/link/tapi/yaml.zig+2-2| ... | @@ -149,7 +149,7 @@ pub const Value = union(ValueType) { | ... | @@ -149,7 +149,7 @@ pub const Value = union(ValueType) { |
| 149 | }; | 149 | }; |
| 150 | } | 150 | } |
| 151 | 151 | ||
| 152 | fn fromNode(arena: *Allocator, tree: *const Tree, node: *const Node, type_hint: ?ValueType) YamlError!Value { | 152 | fn fromNode(arena: Allocator, tree: *const Tree, node: *const Node, type_hint: ?ValueType) YamlError!Value { |
| 153 | if (node.cast(Node.Doc)) |doc| { | 153 | if (node.cast(Node.Doc)) |doc| { |
| 154 | const inner = doc.value orelse { | 154 | const inner = doc.value orelse { |
| 155 | // empty doc | 155 | // empty doc |
| ... | @@ -246,7 +246,7 @@ pub const Yaml = struct { | ... | @@ -246,7 +246,7 @@ pub const Yaml = struct { |
| 246 | } | 246 | } |
| 247 | } | 247 | } |
| 248 | 248 | ||
| 249 | pub fn load(allocator: *Allocator, source: []const u8) !Yaml { | 249 | pub fn load(allocator: Allocator, source: []const u8) !Yaml { |
| 250 | var arena = ArenaAllocator.init(allocator); | 250 | var arena = ArenaAllocator.init(allocator); |
| 251 | 251 | ||
| 252 | var tree = Tree.init(&arena.allocator); | 252 | var tree = Tree.init(&arena.allocator); |
src/main.zig+31-31| ... | @@ -165,7 +165,7 @@ pub fn main() anyerror!void { | ... | @@ -165,7 +165,7 @@ pub fn main() anyerror!void { |
| 165 | return mainArgs(gpa, arena, args); | 165 | return mainArgs(gpa, arena, args); |
| 166 | } | 166 | } |
| 167 | 167 | ||
| 168 | pub fn mainArgs(gpa: *Allocator, arena: *Allocator, args: []const []const u8) !void { | 168 | pub fn mainArgs(gpa: Allocator, arena: Allocator, args: []const []const u8) !void { |
| 169 | if (args.len <= 1) { | 169 | if (args.len <= 1) { |
| 170 | std.log.info("{s}", .{usage}); | 170 | std.log.info("{s}", .{usage}); |
| 171 | fatal("expected command argument", .{}); | 171 | fatal("expected command argument", .{}); |
| ... | @@ -535,7 +535,7 @@ const Emit = union(enum) { | ... | @@ -535,7 +535,7 @@ const Emit = union(enum) { |
| 535 | } | 535 | } |
| 536 | }; | 536 | }; |
| 537 | 537 | ||
| 538 | fn optionalStringEnvVar(arena: *Allocator, name: []const u8) !?[]const u8 { | 538 | fn optionalStringEnvVar(arena: Allocator, name: []const u8) !?[]const u8 { |
| 539 | if (std.process.getEnvVarOwned(arena, name)) |value| { | 539 | if (std.process.getEnvVarOwned(arena, name)) |value| { |
| 540 | return value; | 540 | return value; |
| 541 | } else |err| switch (err) { | 541 | } else |err| switch (err) { |
| ... | @@ -554,8 +554,8 @@ const ArgMode = union(enum) { | ... | @@ -554,8 +554,8 @@ const ArgMode = union(enum) { |
| 554 | }; | 554 | }; |
| 555 | 555 | ||
| 556 | fn buildOutputType( | 556 | fn buildOutputType( |
| 557 | gpa: *Allocator, | 557 | gpa: Allocator, |
| 558 | arena: *Allocator, | 558 | arena: Allocator, |
| 559 | all_args: []const []const u8, | 559 | all_args: []const []const u8, |
| 560 | arg_mode: ArgMode, | 560 | arg_mode: ArgMode, |
| 561 | ) !void { | 561 | ) !void { |
| ... | @@ -2645,7 +2645,7 @@ fn buildOutputType( | ... | @@ -2645,7 +2645,7 @@ fn buildOutputType( |
| 2645 | } | 2645 | } |
| 2646 | 2646 | ||
| 2647 | fn parseCrossTargetOrReportFatalError( | 2647 | fn parseCrossTargetOrReportFatalError( |
| 2648 | allocator: *Allocator, | 2648 | allocator: Allocator, |
| 2649 | opts: std.zig.CrossTarget.ParseOptions, | 2649 | opts: std.zig.CrossTarget.ParseOptions, |
| 2650 | ) !std.zig.CrossTarget { | 2650 | ) !std.zig.CrossTarget { |
| 2651 | var opts_with_diags = opts; | 2651 | var opts_with_diags = opts; |
| ... | @@ -2686,8 +2686,8 @@ fn parseCrossTargetOrReportFatalError( | ... | @@ -2686,8 +2686,8 @@ fn parseCrossTargetOrReportFatalError( |
| 2686 | 2686 | ||
| 2687 | fn runOrTest( | 2687 | fn runOrTest( |
| 2688 | comp: *Compilation, | 2688 | comp: *Compilation, |
| 2689 | gpa: *Allocator, | 2689 | gpa: Allocator, |
| 2690 | arena: *Allocator, | 2690 | arena: Allocator, |
| 2691 | emit_bin_loc: ?Compilation.EmitLoc, | 2691 | emit_bin_loc: ?Compilation.EmitLoc, |
| 2692 | test_exec_args: []const ?[]const u8, | 2692 | test_exec_args: []const ?[]const u8, |
| 2693 | self_exe_path: []const u8, | 2693 | self_exe_path: []const u8, |
| ... | @@ -2818,7 +2818,7 @@ const AfterUpdateHook = union(enum) { | ... | @@ -2818,7 +2818,7 @@ const AfterUpdateHook = union(enum) { |
| 2818 | update: []const u8, | 2818 | update: []const u8, |
| 2819 | }; | 2819 | }; |
| 2820 | 2820 | ||
| 2821 | fn updateModule(gpa: *Allocator, comp: *Compilation, hook: AfterUpdateHook) !void { | 2821 | fn updateModule(gpa: Allocator, comp: *Compilation, hook: AfterUpdateHook) !void { |
| 2822 | try comp.update(); | 2822 | try comp.update(); |
| 2823 | 2823 | ||
| 2824 | var errors = try comp.getAllErrorsAlloc(); | 2824 | var errors = try comp.getAllErrorsAlloc(); |
| ... | @@ -2872,7 +2872,7 @@ fn updateModule(gpa: *Allocator, comp: *Compilation, hook: AfterUpdateHook) !voi | ... | @@ -2872,7 +2872,7 @@ fn updateModule(gpa: *Allocator, comp: *Compilation, hook: AfterUpdateHook) !voi |
| 2872 | } | 2872 | } |
| 2873 | } | 2873 | } |
| 2874 | 2874 | ||
| 2875 | fn freePkgTree(gpa: *Allocator, pkg: *Package, free_parent: bool) void { | 2875 | fn freePkgTree(gpa: Allocator, pkg: *Package, free_parent: bool) void { |
| 2876 | { | 2876 | { |
| 2877 | var it = pkg.table.valueIterator(); | 2877 | var it = pkg.table.valueIterator(); |
| 2878 | while (it.next()) |value| { | 2878 | while (it.next()) |value| { |
| ... | @@ -2884,7 +2884,7 @@ fn freePkgTree(gpa: *Allocator, pkg: *Package, free_parent: bool) void { | ... | @@ -2884,7 +2884,7 @@ fn freePkgTree(gpa: *Allocator, pkg: *Package, free_parent: bool) void { |
| 2884 | } | 2884 | } |
| 2885 | } | 2885 | } |
| 2886 | 2886 | ||
| 2887 | fn cmdTranslateC(comp: *Compilation, arena: *Allocator, enable_cache: bool) !void { | 2887 | fn cmdTranslateC(comp: *Compilation, arena: Allocator, enable_cache: bool) !void { |
| 2888 | if (!build_options.have_llvm) | 2888 | if (!build_options.have_llvm) |
| 2889 | fatal("cannot translate-c: compiler built without LLVM extensions", .{}); | 2889 | fatal("cannot translate-c: compiler built without LLVM extensions", .{}); |
| 2890 | 2890 | ||
| ... | @@ -3031,7 +3031,7 @@ pub const usage_libc = | ... | @@ -3031,7 +3031,7 @@ pub const usage_libc = |
| 3031 | \\ | 3031 | \\ |
| 3032 | ; | 3032 | ; |
| 3033 | 3033 | ||
| 3034 | pub fn cmdLibC(gpa: *Allocator, args: []const []const u8) !void { | 3034 | pub fn cmdLibC(gpa: Allocator, args: []const []const u8) !void { |
| 3035 | var input_file: ?[]const u8 = null; | 3035 | var input_file: ?[]const u8 = null; |
| 3036 | var target_arch_os_abi: []const u8 = "native"; | 3036 | var target_arch_os_abi: []const u8 = "native"; |
| 3037 | { | 3037 | { |
| ... | @@ -3100,8 +3100,8 @@ pub const usage_init = | ... | @@ -3100,8 +3100,8 @@ pub const usage_init = |
| 3100 | ; | 3100 | ; |
| 3101 | 3101 | ||
| 3102 | pub fn cmdInit( | 3102 | pub fn cmdInit( |
| 3103 | gpa: *Allocator, | 3103 | gpa: Allocator, |
| 3104 | arena: *Allocator, | 3104 | arena: Allocator, |
| 3105 | args: []const []const u8, | 3105 | args: []const []const u8, |
| 3106 | output_mode: std.builtin.OutputMode, | 3106 | output_mode: std.builtin.OutputMode, |
| 3107 | ) !void { | 3107 | ) !void { |
| ... | @@ -3196,7 +3196,7 @@ pub const usage_build = | ... | @@ -3196,7 +3196,7 @@ pub const usage_build = |
| 3196 | \\ | 3196 | \\ |
| 3197 | ; | 3197 | ; |
| 3198 | 3198 | ||
| 3199 | pub fn cmdBuild(gpa: *Allocator, arena: *Allocator, args: []const []const u8) !void { | 3199 | pub fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !void { |
| 3200 | var prominent_compile_errors: bool = false; | 3200 | var prominent_compile_errors: bool = false; |
| 3201 | 3201 | ||
| 3202 | // We want to release all the locks before executing the child process, so we make a nice | 3202 | // We want to release all the locks before executing the child process, so we make a nice |
| ... | @@ -3436,7 +3436,7 @@ pub fn cmdBuild(gpa: *Allocator, arena: *Allocator, args: []const []const u8) !v | ... | @@ -3436,7 +3436,7 @@ pub fn cmdBuild(gpa: *Allocator, arena: *Allocator, args: []const []const u8) !v |
| 3436 | } | 3436 | } |
| 3437 | } | 3437 | } |
| 3438 | 3438 | ||
| 3439 | fn argvCmd(allocator: *Allocator, argv: []const []const u8) ![]u8 { | 3439 | fn argvCmd(allocator: Allocator, argv: []const []const u8) ![]u8 { |
| 3440 | var cmd = std.ArrayList(u8).init(allocator); | 3440 | var cmd = std.ArrayList(u8).init(allocator); |
| 3441 | defer cmd.deinit(); | 3441 | defer cmd.deinit(); |
| 3442 | for (argv[0 .. argv.len - 1]) |arg| { | 3442 | for (argv[0 .. argv.len - 1]) |arg| { |
| ... | @@ -3448,7 +3448,7 @@ fn argvCmd(allocator: *Allocator, argv: []const []const u8) ![]u8 { | ... | @@ -3448,7 +3448,7 @@ fn argvCmd(allocator: *Allocator, argv: []const []const u8) ![]u8 { |
| 3448 | } | 3448 | } |
| 3449 | 3449 | ||
| 3450 | fn readSourceFileToEndAlloc( | 3450 | fn readSourceFileToEndAlloc( |
| 3451 | allocator: *mem.Allocator, | 3451 | allocator: mem.Allocator, |
| 3452 | input: *const fs.File, | 3452 | input: *const fs.File, |
| 3453 | size_hint: ?usize, | 3453 | size_hint: ?usize, |
| 3454 | ) ![:0]u8 { | 3454 | ) ![:0]u8 { |
| ... | @@ -3518,14 +3518,14 @@ const Fmt = struct { | ... | @@ -3518,14 +3518,14 @@ const Fmt = struct { |
| 3518 | any_error: bool, | 3518 | any_error: bool, |
| 3519 | check_ast: bool, | 3519 | check_ast: bool, |
| 3520 | color: Color, | 3520 | color: Color, |
| 3521 | gpa: *Allocator, | 3521 | gpa: Allocator, |
| 3522 | arena: *Allocator, | 3522 | arena: Allocator, |
| 3523 | out_buffer: std.ArrayList(u8), | 3523 | out_buffer: std.ArrayList(u8), |
| 3524 | 3524 | ||
| 3525 | const SeenMap = std.AutoHashMap(fs.File.INode, void); | 3525 | const SeenMap = std.AutoHashMap(fs.File.INode, void); |
| 3526 | }; | 3526 | }; |
| 3527 | 3527 | ||
| 3528 | pub fn cmdFmt(gpa: *Allocator, arena: *Allocator, args: []const []const u8) !void { | 3528 | pub fn cmdFmt(gpa: Allocator, arena: Allocator, args: []const []const u8) !void { |
| 3529 | var color: Color = .auto; | 3529 | var color: Color = .auto; |
| 3530 | var stdin_flag: bool = false; | 3530 | var stdin_flag: bool = false; |
| 3531 | var check_flag: bool = false; | 3531 | var check_flag: bool = false; |
| ... | @@ -3855,8 +3855,8 @@ fn fmtPathFile( | ... | @@ -3855,8 +3855,8 @@ fn fmtPathFile( |
| 3855 | } | 3855 | } |
| 3856 | 3856 | ||
| 3857 | fn printErrMsgToStdErr( | 3857 | fn printErrMsgToStdErr( |
| 3858 | gpa: *mem.Allocator, | 3858 | gpa: mem.Allocator, |
| 3859 | arena: *mem.Allocator, | 3859 | arena: mem.Allocator, |
| 3860 | parse_error: Ast.Error, | 3860 | parse_error: Ast.Error, |
| 3861 | tree: Ast, | 3861 | tree: Ast, |
| 3862 | path: []const u8, | 3862 | path: []const u8, |
| ... | @@ -3938,7 +3938,7 @@ extern "c" fn ZigClang_main(argc: c_int, argv: [*:null]?[*:0]u8) c_int; | ... | @@ -3938,7 +3938,7 @@ extern "c" fn ZigClang_main(argc: c_int, argv: [*:null]?[*:0]u8) c_int; |
| 3938 | extern "c" fn ZigLlvmAr_main(argc: c_int, argv: [*:null]?[*:0]u8) c_int; | 3938 | extern "c" fn ZigLlvmAr_main(argc: c_int, argv: [*:null]?[*:0]u8) c_int; |
| 3939 | 3939 | ||
| 3940 | /// TODO https://github.com/ziglang/zig/issues/3257 | 3940 | /// TODO https://github.com/ziglang/zig/issues/3257 |
| 3941 | fn punt_to_clang(arena: *Allocator, args: []const []const u8) error{OutOfMemory} { | 3941 | fn punt_to_clang(arena: Allocator, args: []const []const u8) error{OutOfMemory} { |
| 3942 | if (!build_options.have_llvm) | 3942 | if (!build_options.have_llvm) |
| 3943 | fatal("`zig cc` and `zig c++` unavailable: compiler built without LLVM extensions", .{}); | 3943 | fatal("`zig cc` and `zig c++` unavailable: compiler built without LLVM extensions", .{}); |
| 3944 | // Convert the args to the format Clang expects. | 3944 | // Convert the args to the format Clang expects. |
| ... | @@ -3952,7 +3952,7 @@ fn punt_to_clang(arena: *Allocator, args: []const []const u8) error{OutOfMemory} | ... | @@ -3952,7 +3952,7 @@ fn punt_to_clang(arena: *Allocator, args: []const []const u8) error{OutOfMemory} |
| 3952 | } | 3952 | } |
| 3953 | 3953 | ||
| 3954 | /// TODO https://github.com/ziglang/zig/issues/3257 | 3954 | /// TODO https://github.com/ziglang/zig/issues/3257 |
| 3955 | fn punt_to_llvm_ar(arena: *Allocator, args: []const []const u8) error{OutOfMemory} { | 3955 | fn punt_to_llvm_ar(arena: Allocator, args: []const []const u8) error{OutOfMemory} { |
| 3956 | if (!build_options.have_llvm) | 3956 | if (!build_options.have_llvm) |
| 3957 | fatal("`zig ar`, `zig dlltool`, `zig ranlib', and `zig lib` unavailable: compiler built without LLVM extensions", .{}); | 3957 | fatal("`zig ar`, `zig dlltool`, `zig ranlib', and `zig lib` unavailable: compiler built without LLVM extensions", .{}); |
| 3958 | 3958 | ||
| ... | @@ -3973,7 +3973,7 @@ fn punt_to_llvm_ar(arena: *Allocator, args: []const []const u8) error{OutOfMemor | ... | @@ -3973,7 +3973,7 @@ fn punt_to_llvm_ar(arena: *Allocator, args: []const []const u8) error{OutOfMemor |
| 3973 | /// * `lld-link` - COFF | 3973 | /// * `lld-link` - COFF |
| 3974 | /// * `wasm-ld` - WebAssembly | 3974 | /// * `wasm-ld` - WebAssembly |
| 3975 | /// TODO https://github.com/ziglang/zig/issues/3257 | 3975 | /// TODO https://github.com/ziglang/zig/issues/3257 |
| 3976 | pub fn punt_to_lld(arena: *Allocator, args: []const []const u8) error{OutOfMemory} { | 3976 | pub fn punt_to_lld(arena: Allocator, args: []const []const u8) error{OutOfMemory} { |
| 3977 | if (!build_options.have_llvm) | 3977 | if (!build_options.have_llvm) |
| 3978 | fatal("`zig {s}` unavailable: compiler built without LLVM extensions", .{args[0]}); | 3978 | fatal("`zig {s}` unavailable: compiler built without LLVM extensions", .{args[0]}); |
| 3979 | // Convert the args to the format LLD expects. | 3979 | // Convert the args to the format LLD expects. |
| ... | @@ -4009,7 +4009,7 @@ pub const ClangArgIterator = struct { | ... | @@ -4009,7 +4009,7 @@ pub const ClangArgIterator = struct { |
| 4009 | argv: []const []const u8, | 4009 | argv: []const []const u8, |
| 4010 | next_index: usize, | 4010 | next_index: usize, |
| 4011 | root_args: ?*Args, | 4011 | root_args: ?*Args, |
| 4012 | allocator: *Allocator, | 4012 | allocator: Allocator, |
| 4013 | 4013 | ||
| 4014 | pub const ZigEquivalent = enum { | 4014 | pub const ZigEquivalent = enum { |
| 4015 | target, | 4015 | target, |
| ... | @@ -4069,7 +4069,7 @@ pub const ClangArgIterator = struct { | ... | @@ -4069,7 +4069,7 @@ pub const ClangArgIterator = struct { |
| 4069 | argv: []const []const u8, | 4069 | argv: []const []const u8, |
| 4070 | }; | 4070 | }; |
| 4071 | 4071 | ||
| 4072 | fn init(allocator: *Allocator, argv: []const []const u8) ClangArgIterator { | 4072 | fn init(allocator: Allocator, argv: []const []const u8) ClangArgIterator { |
| 4073 | return .{ | 4073 | return .{ |
| 4074 | .next_index = 2, // `zig cc foo` this points to `foo` | 4074 | .next_index = 2, // `zig cc foo` this points to `foo` |
| 4075 | .has_next = argv.len > 2, | 4075 | .has_next = argv.len > 2, |
| ... | @@ -4308,7 +4308,7 @@ test "fds" { | ... | @@ -4308,7 +4308,7 @@ test "fds" { |
| 4308 | gimmeMoreOfThoseSweetSweetFileDescriptors(); | 4308 | gimmeMoreOfThoseSweetSweetFileDescriptors(); |
| 4309 | } | 4309 | } |
| 4310 | 4310 | ||
| 4311 | fn detectNativeTargetInfo(gpa: *Allocator, cross_target: std.zig.CrossTarget) !std.zig.system.NativeTargetInfo { | 4311 | fn detectNativeTargetInfo(gpa: Allocator, cross_target: std.zig.CrossTarget) !std.zig.system.NativeTargetInfo { |
| 4312 | return std.zig.system.NativeTargetInfo.detect(gpa, cross_target); | 4312 | return std.zig.system.NativeTargetInfo.detect(gpa, cross_target); |
| 4313 | } | 4313 | } |
| 4314 | 4314 | ||
| ... | @@ -4343,8 +4343,8 @@ const usage_ast_check = | ... | @@ -4343,8 +4343,8 @@ const usage_ast_check = |
| 4343 | ; | 4343 | ; |
| 4344 | 4344 | ||
| 4345 | pub fn cmdAstCheck( | 4345 | pub fn cmdAstCheck( |
| 4346 | gpa: *Allocator, | 4346 | gpa: Allocator, |
| 4347 | arena: *Allocator, | 4347 | arena: Allocator, |
| 4348 | args: []const []const u8, | 4348 | args: []const []const u8, |
| 4349 | ) !void { | 4349 | ) !void { |
| 4350 | const Module = @import("Module.zig"); | 4350 | const Module = @import("Module.zig"); |
| ... | @@ -4513,8 +4513,8 @@ pub fn cmdAstCheck( | ... | @@ -4513,8 +4513,8 @@ pub fn cmdAstCheck( |
| 4513 | 4513 | ||
| 4514 | /// This is only enabled for debug builds. | 4514 | /// This is only enabled for debug builds. |
| 4515 | pub fn cmdChangelist( | 4515 | pub fn cmdChangelist( |
| 4516 | gpa: *Allocator, | 4516 | gpa: Allocator, |
| 4517 | arena: *Allocator, | 4517 | arena: Allocator, |
| 4518 | args: []const []const u8, | 4518 | args: []const []const u8, |
| 4519 | ) !void { | 4519 | ) !void { |
| 4520 | const Module = @import("Module.zig"); | 4520 | const Module = @import("Module.zig"); |
src/mingw.zig+2-2| ... | @@ -252,7 +252,7 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile) !void { | ... | @@ -252,7 +252,7 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile) !void { |
| 252 | 252 | ||
| 253 | fn add_cc_args( | 253 | fn add_cc_args( |
| 254 | comp: *Compilation, | 254 | comp: *Compilation, |
| 255 | arena: *Allocator, | 255 | arena: Allocator, |
| 256 | args: *std.ArrayList([]const u8), | 256 | args: *std.ArrayList([]const u8), |
| 257 | ) error{OutOfMemory}!void { | 257 | ) error{OutOfMemory}!void { |
| 258 | try args.appendSlice(&[_][]const u8{ | 258 | try args.appendSlice(&[_][]const u8{ |
| ... | @@ -428,7 +428,7 @@ pub fn buildImportLib(comp: *Compilation, lib_name: []const u8) !void { | ... | @@ -428,7 +428,7 @@ pub fn buildImportLib(comp: *Compilation, lib_name: []const u8) !void { |
| 428 | } | 428 | } |
| 429 | 429 | ||
| 430 | /// This function body is verbose but all it does is test 3 different paths and see if a .def file exists. | 430 | /// This function body is verbose but all it does is test 3 different paths and see if a .def file exists. |
| 431 | fn findDef(comp: *Compilation, allocator: *Allocator, lib_name: []const u8) ![]u8 { | 431 | fn findDef(comp: *Compilation, allocator: Allocator, lib_name: []const u8) ![]u8 { |
| 432 | const target = comp.getTarget(); | 432 | const target = comp.getTarget(); |
| 433 | 433 | ||
| 434 | const lib_path = switch (target.cpu.arch) { | 434 | const lib_path = switch (target.cpu.arch) { |
src/musl.zig+3-3| ... | @@ -310,7 +310,7 @@ const Ext = enum { | ... | @@ -310,7 +310,7 @@ const Ext = enum { |
| 310 | o3, | 310 | o3, |
| 311 | }; | 311 | }; |
| 312 | 312 | ||
| 313 | fn addSrcFile(arena: *Allocator, source_table: *std.StringArrayHashMap(Ext), file_path: []const u8) !void { | 313 | fn addSrcFile(arena: Allocator, source_table: *std.StringArrayHashMap(Ext), file_path: []const u8) !void { |
| 314 | const ext: Ext = ext: { | 314 | const ext: Ext = ext: { |
| 315 | if (mem.endsWith(u8, file_path, ".c")) { | 315 | if (mem.endsWith(u8, file_path, ".c")) { |
| 316 | if (mem.startsWith(u8, file_path, "musl/src/malloc/") or | 316 | if (mem.startsWith(u8, file_path, "musl/src/malloc/") or |
| ... | @@ -344,7 +344,7 @@ fn addSrcFile(arena: *Allocator, source_table: *std.StringArrayHashMap(Ext), fil | ... | @@ -344,7 +344,7 @@ fn addSrcFile(arena: *Allocator, source_table: *std.StringArrayHashMap(Ext), fil |
| 344 | 344 | ||
| 345 | fn addCcArgs( | 345 | fn addCcArgs( |
| 346 | comp: *Compilation, | 346 | comp: *Compilation, |
| 347 | arena: *Allocator, | 347 | arena: Allocator, |
| 348 | args: *std.ArrayList([]const u8), | 348 | args: *std.ArrayList([]const u8), |
| 349 | want_O3: bool, | 349 | want_O3: bool, |
| 350 | ) error{OutOfMemory}!void { | 350 | ) error{OutOfMemory}!void { |
| ... | @@ -394,7 +394,7 @@ fn addCcArgs( | ... | @@ -394,7 +394,7 @@ fn addCcArgs( |
| 394 | }); | 394 | }); |
| 395 | } | 395 | } |
| 396 | 396 | ||
| 397 | fn start_asm_path(comp: *Compilation, arena: *Allocator, basename: []const u8) ![]const u8 { | 397 | fn start_asm_path(comp: *Compilation, arena: Allocator, basename: []const u8) ![]const u8 { |
| 398 | const target = comp.getTarget(); | 398 | const target = comp.getTarget(); |
| 399 | return comp.zig_lib_directory.join(arena, &[_][]const u8{ | 399 | return comp.zig_lib_directory.join(arena, &[_][]const u8{ |
| 400 | "libc", "musl", "crt", archName(target.cpu.arch), basename, | 400 | "libc", "musl", "crt", archName(target.cpu.arch), basename, |
src/print_air.zig+3-3| ... | @@ -8,7 +8,7 @@ const Zir = @import("Zir.zig"); | ... | @@ -8,7 +8,7 @@ const Zir = @import("Zir.zig"); |
| 8 | const Air = @import("Air.zig"); | 8 | const Air = @import("Air.zig"); |
| 9 | const Liveness = @import("Liveness.zig"); | 9 | const Liveness = @import("Liveness.zig"); |
| 10 | 10 | ||
| 11 | pub fn dump(gpa: *Allocator, air: Air, zir: Zir, liveness: Liveness) void { | 11 | pub fn dump(gpa: Allocator, air: Air, zir: Zir, liveness: Liveness) void { |
| 12 | const instruction_bytes = air.instructions.len * | 12 | const instruction_bytes = air.instructions.len * |
| 13 | // Here we don't use @sizeOf(Air.Inst.Data) because it would include | 13 | // Here we don't use @sizeOf(Air.Inst.Data) because it would include |
| 14 | // the debug safety tag but we want to measure release size. | 14 | // the debug safety tag but we want to measure release size. |
| ... | @@ -60,8 +60,8 @@ pub fn dump(gpa: *Allocator, air: Air, zir: Zir, liveness: Liveness) void { | ... | @@ -60,8 +60,8 @@ pub fn dump(gpa: *Allocator, air: Air, zir: Zir, liveness: Liveness) void { |
| 60 | } | 60 | } |
| 61 | 61 | ||
| 62 | const Writer = struct { | 62 | const Writer = struct { |
| 63 | gpa: *Allocator, | 63 | gpa: Allocator, |
| 64 | arena: *Allocator, | 64 | arena: Allocator, |
| 65 | air: Air, | 65 | air: Air, |
| 66 | zir: Zir, | 66 | zir: Zir, |
| 67 | liveness: Liveness, | 67 | liveness: Liveness, |
src/print_env.zig+1-1| ... | @@ -4,7 +4,7 @@ const introspect = @import("introspect.zig"); | ... | @@ -4,7 +4,7 @@ const introspect = @import("introspect.zig"); |
| 4 | const Allocator = std.mem.Allocator; | 4 | const Allocator = std.mem.Allocator; |
| 5 | const fatal = @import("main.zig").fatal; | 5 | const fatal = @import("main.zig").fatal; |
| 6 | 6 | ||
| 7 | pub fn cmdEnv(gpa: *Allocator, args: []const []const u8, stdout: std.fs.File.Writer) !void { | 7 | pub fn cmdEnv(gpa: Allocator, args: []const []const u8, stdout: std.fs.File.Writer) !void { |
| 8 | _ = args; | 8 | _ = args; |
| 9 | const self_exe_path = try std.fs.selfExePathAlloc(gpa); | 9 | const self_exe_path = try std.fs.selfExePathAlloc(gpa); |
| 10 | defer gpa.free(self_exe_path); | 10 | defer gpa.free(self_exe_path); |
src/print_targets.zig+1-1| ... | @@ -11,7 +11,7 @@ const introspect = @import("introspect.zig"); | ... | @@ -11,7 +11,7 @@ const introspect = @import("introspect.zig"); |
| 11 | const fatal = @import("main.zig").fatal; | 11 | const fatal = @import("main.zig").fatal; |
| 12 | 12 | ||
| 13 | pub fn cmdTargets( | 13 | pub fn cmdTargets( |
| 14 | allocator: *Allocator, | 14 | allocator: Allocator, |
| 15 | args: []const []const u8, | 15 | args: []const []const u8, |
| 16 | /// Output stream | 16 | /// Output stream |
| 17 | stdout: anytype, | 17 | stdout: anytype, |
src/print_zir.zig+5-5| ... | @@ -10,7 +10,7 @@ const LazySrcLoc = Module.LazySrcLoc; | ... | @@ -10,7 +10,7 @@ const LazySrcLoc = Module.LazySrcLoc; |
| 10 | 10 | ||
| 11 | /// Write human-readable, debug formatted ZIR code to a file. | 11 | /// Write human-readable, debug formatted ZIR code to a file. |
| 12 | pub fn renderAsTextToFile( | 12 | pub fn renderAsTextToFile( |
| 13 | gpa: *Allocator, | 13 | gpa: Allocator, |
| 14 | scope_file: *Module.File, | 14 | scope_file: *Module.File, |
| 15 | fs_file: std.fs.File, | 15 | fs_file: std.fs.File, |
| 16 | ) !void { | 16 | ) !void { |
| ... | @@ -61,7 +61,7 @@ pub fn renderAsTextToFile( | ... | @@ -61,7 +61,7 @@ pub fn renderAsTextToFile( |
| 61 | } | 61 | } |
| 62 | 62 | ||
| 63 | pub fn renderInstructionContext( | 63 | pub fn renderInstructionContext( |
| 64 | gpa: *Allocator, | 64 | gpa: Allocator, |
| 65 | block: []const Zir.Inst.Index, | 65 | block: []const Zir.Inst.Index, |
| 66 | block_index: usize, | 66 | block_index: usize, |
| 67 | scope_file: *Module.File, | 67 | scope_file: *Module.File, |
| ... | @@ -94,7 +94,7 @@ pub fn renderInstructionContext( | ... | @@ -94,7 +94,7 @@ pub fn renderInstructionContext( |
| 94 | } | 94 | } |
| 95 | 95 | ||
| 96 | pub fn renderSingleInstruction( | 96 | pub fn renderSingleInstruction( |
| 97 | gpa: *Allocator, | 97 | gpa: Allocator, |
| 98 | inst: Zir.Inst.Index, | 98 | inst: Zir.Inst.Index, |
| 99 | scope_file: *Module.File, | 99 | scope_file: *Module.File, |
| 100 | parent_decl_node: Ast.Node.Index, | 100 | parent_decl_node: Ast.Node.Index, |
| ... | @@ -120,8 +120,8 @@ pub fn renderSingleInstruction( | ... | @@ -120,8 +120,8 @@ pub fn renderSingleInstruction( |
| 120 | } | 120 | } |
| 121 | 121 | ||
| 122 | const Writer = struct { | 122 | const Writer = struct { |
| 123 | gpa: *Allocator, | 123 | gpa: Allocator, |
| 124 | arena: *Allocator, | 124 | arena: Allocator, |
| 125 | file: *Module.File, | 125 | file: *Module.File, |
| 126 | code: Zir, | 126 | code: Zir, |
| 127 | indent: u32, | 127 | indent: u32, |
src/register_manager.zig+1-1| ... | @@ -254,7 +254,7 @@ const MockRegister2 = enum(u2) { | ... | @@ -254,7 +254,7 @@ const MockRegister2 = enum(u2) { |
| 254 | 254 | ||
| 255 | fn MockFunction(comptime Register: type) type { | 255 | fn MockFunction(comptime Register: type) type { |
| 256 | return struct { | 256 | return struct { |
| 257 | allocator: *Allocator, | 257 | allocator: Allocator, |
| 258 | register_manager: RegisterManager(Self, Register, &Register.callee_preserved_regs) = .{}, | 258 | register_manager: RegisterManager(Self, Register, &Register.callee_preserved_regs) = .{}, |
| 259 | spilled: std.ArrayListUnmanaged(Register) = .{}, | 259 | spilled: std.ArrayListUnmanaged(Register) = .{}, |
| 260 | 260 |
src/test.zig+1-1| ... | @@ -680,7 +680,7 @@ pub const TestContext = struct { | ... | @@ -680,7 +680,7 @@ pub const TestContext = struct { |
| 680 | } | 680 | } |
| 681 | 681 | ||
| 682 | fn runOneCase( | 682 | fn runOneCase( |
| 683 | allocator: *Allocator, | 683 | allocator: Allocator, |
| 684 | root_node: *std.Progress.Node, | 684 | root_node: *std.Progress.Node, |
| 685 | case: Case, | 685 | case: Case, |
| 686 | zig_lib_directory: Compilation.Directory, | 686 | zig_lib_directory: Compilation.Directory, |
src/tracy.zig+5-5| ... | @@ -103,18 +103,18 @@ pub inline fn traceNamed(comptime src: std.builtin.SourceLocation, comptime name | ... | @@ -103,18 +103,18 @@ pub inline fn traceNamed(comptime src: std.builtin.SourceLocation, comptime name |
| 103 | } | 103 | } |
| 104 | } | 104 | } |
| 105 | 105 | ||
| 106 | pub fn tracyAllocator(allocator: *std.mem.Allocator) TracyAllocator(null) { | 106 | pub fn tracyAllocator(allocator: std.mem.Allocator) TracyAllocator(null) { |
| 107 | return TracyAllocator(null).init(allocator); | 107 | return TracyAllocator(null).init(allocator); |
| 108 | } | 108 | } |
| 109 | 109 | ||
| 110 | pub fn TracyAllocator(comptime name: ?[:0]const u8) type { | 110 | pub fn TracyAllocator(comptime name: ?[:0]const u8) type { |
| 111 | return struct { | 111 | return struct { |
| 112 | allocator: std.mem.Allocator, | 112 | allocator: std.mem.Allocator, |
| 113 | parent_allocator: *std.mem.Allocator, | 113 | parent_allocator: std.mem.Allocator, |
| 114 | 114 | ||
| 115 | const Self = @This(); | 115 | const Self = @This(); |
| 116 | 116 | ||
| 117 | pub fn init(allocator: *std.mem.Allocator) Self { | 117 | pub fn init(allocator: std.mem.Allocator) Self { |
| 118 | return .{ | 118 | return .{ |
| 119 | .parent_allocator = allocator, | 119 | .parent_allocator = allocator, |
| 120 | .allocator = .{ | 120 | .allocator = .{ |
| ... | @@ -124,7 +124,7 @@ pub fn TracyAllocator(comptime name: ?[:0]const u8) type { | ... | @@ -124,7 +124,7 @@ pub fn TracyAllocator(comptime name: ?[:0]const u8) type { |
| 124 | }; | 124 | }; |
| 125 | } | 125 | } |
| 126 | 126 | ||
| 127 | fn allocFn(allocator: *std.mem.Allocator, len: usize, ptr_align: u29, len_align: u29, ret_addr: usize) std.mem.Allocator.Error![]u8 { | 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); | 128 | const self = @fieldParentPtr(Self, "allocator", allocator); |
| 129 | const result = self.parent_allocator.allocFn(self.parent_allocator, len, ptr_align, len_align, ret_addr); | 129 | const result = self.parent_allocator.allocFn(self.parent_allocator, len, ptr_align, len_align, ret_addr); |
| 130 | if (result) |data| { | 130 | if (result) |data| { |
| ... | @@ -141,7 +141,7 @@ pub fn TracyAllocator(comptime name: ?[:0]const u8) type { | ... | @@ -141,7 +141,7 @@ pub fn TracyAllocator(comptime name: ?[:0]const u8) type { |
| 141 | return result; | 141 | return result; |
| 142 | } | 142 | } |
| 143 | 143 | ||
| 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 { | 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); | 145 | const self = @fieldParentPtr(Self, "allocator", allocator); |
| 146 | 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| { |
src/translate_c.zig+12-12| ... | @@ -305,8 +305,8 @@ const Scope = struct { | ... | @@ -305,8 +305,8 @@ const Scope = struct { |
| 305 | }; | 305 | }; |
| 306 | 306 | ||
| 307 | pub const Context = struct { | 307 | pub const Context = struct { |
| 308 | gpa: *mem.Allocator, | 308 | gpa: mem.Allocator, |
| 309 | arena: *mem.Allocator, | 309 | arena: mem.Allocator, |
| 310 | source_manager: *clang.SourceManager, | 310 | source_manager: *clang.SourceManager, |
| 311 | decl_table: std.AutoArrayHashMapUnmanaged(usize, []const u8) = .{}, | 311 | decl_table: std.AutoArrayHashMapUnmanaged(usize, []const u8) = .{}, |
| 312 | alias_list: AliasList, | 312 | alias_list: AliasList, |
| ... | @@ -351,7 +351,7 @@ pub const Context = struct { | ... | @@ -351,7 +351,7 @@ pub const Context = struct { |
| 351 | }; | 351 | }; |
| 352 | 352 | ||
| 353 | pub fn translate( | 353 | pub fn translate( |
| 354 | gpa: *mem.Allocator, | 354 | gpa: mem.Allocator, |
| 355 | args_begin: [*]?[*]const u8, | 355 | args_begin: [*]?[*]const u8, |
| 356 | args_end: [*]?[*]const u8, | 356 | args_end: [*]?[*]const u8, |
| 357 | errors: *[]ClangErrMsg, | 357 | errors: *[]ClangErrMsg, |
| ... | @@ -1448,7 +1448,7 @@ fn makeShuffleMask(c: *Context, scope: *Scope, expr: *const clang.ShuffleVectorE | ... | @@ -1448,7 +1448,7 @@ fn makeShuffleMask(c: *Context, scope: *Scope, expr: *const clang.ShuffleVectorE |
| 1448 | } | 1448 | } |
| 1449 | 1449 | ||
| 1450 | /// @typeInfo(@TypeOf(vec_node)).Vector.<field> | 1450 | /// @typeInfo(@TypeOf(vec_node)).Vector.<field> |
| 1451 | fn vectorTypeInfo(arena: *mem.Allocator, vec_node: Node, field: []const u8) TransError!Node { | 1451 | fn vectorTypeInfo(arena: mem.Allocator, vec_node: Node, field: []const u8) TransError!Node { |
| 1452 | const typeof_call = try Tag.typeof.create(arena, vec_node); | 1452 | const typeof_call = try Tag.typeof.create(arena, vec_node); |
| 1453 | const typeinfo_call = try Tag.typeinfo.create(arena, typeof_call); | 1453 | const typeinfo_call = try Tag.typeinfo.create(arena, typeof_call); |
| 1454 | const vector_type_info = try Tag.field_access.create(arena, .{ .lhs = typeinfo_call, .field_name = "Vector" }); | 1454 | const vector_type_info = try Tag.field_access.create(arena, .{ .lhs = typeinfo_call, .field_name = "Vector" }); |
| ... | @@ -1536,7 +1536,7 @@ fn transOffsetOfExpr( | ... | @@ -1536,7 +1536,7 @@ fn transOffsetOfExpr( |
| 1536 | /// will become very large positive numbers but that is ok since we only use this in | 1536 | /// will become very large positive numbers but that is ok since we only use this in |
| 1537 | /// pointer arithmetic expressions, where wraparound will ensure we get the correct value. | 1537 | /// pointer arithmetic expressions, where wraparound will ensure we get the correct value. |
| 1538 | /// node -> @bitCast(usize, @intCast(isize, node)) | 1538 | /// node -> @bitCast(usize, @intCast(isize, node)) |
| 1539 | fn usizeCastForWrappingPtrArithmetic(gpa: *mem.Allocator, node: Node) TransError!Node { | 1539 | fn usizeCastForWrappingPtrArithmetic(gpa: mem.Allocator, node: Node) TransError!Node { |
| 1540 | const intcast_node = try Tag.int_cast.create(gpa, .{ | 1540 | const intcast_node = try Tag.int_cast.create(gpa, .{ |
| 1541 | .lhs = try Tag.type.create(gpa, "isize"), | 1541 | .lhs = try Tag.type.create(gpa, "isize"), |
| 1542 | .rhs = node, | 1542 | .rhs = node, |
| ... | @@ -5072,7 +5072,7 @@ const PatternList = struct { | ... | @@ -5072,7 +5072,7 @@ const PatternList = struct { |
| 5072 | }; | 5072 | }; |
| 5073 | 5073 | ||
| 5074 | /// Assumes that `ms` represents a tokenized function-like macro. | 5074 | /// Assumes that `ms` represents a tokenized function-like macro. |
| 5075 | fn buildArgsHash(allocator: *mem.Allocator, ms: MacroSlicer, hash: *ArgsPositionMap) MacroProcessingError!void { | 5075 | fn buildArgsHash(allocator: mem.Allocator, ms: MacroSlicer, hash: *ArgsPositionMap) MacroProcessingError!void { |
| 5076 | assert(ms.tokens.len > 2); | 5076 | assert(ms.tokens.len > 2); |
| 5077 | assert(ms.tokens[0].id == .Identifier); | 5077 | assert(ms.tokens[0].id == .Identifier); |
| 5078 | assert(ms.tokens[1].id == .LParen); | 5078 | assert(ms.tokens[1].id == .LParen); |
| ... | @@ -5098,7 +5098,7 @@ const PatternList = struct { | ... | @@ -5098,7 +5098,7 @@ const PatternList = struct { |
| 5098 | impl: []const u8, | 5098 | impl: []const u8, |
| 5099 | args_hash: ArgsPositionMap, | 5099 | args_hash: ArgsPositionMap, |
| 5100 | 5100 | ||
| 5101 | fn init(self: *Pattern, allocator: *mem.Allocator, template: [2][]const u8) Error!void { | 5101 | fn init(self: *Pattern, allocator: mem.Allocator, template: [2][]const u8) Error!void { |
| 5102 | const source = template[0]; | 5102 | const source = template[0]; |
| 5103 | const impl = template[1]; | 5103 | const impl = template[1]; |
| 5104 | 5104 | ||
| ... | @@ -5120,7 +5120,7 @@ const PatternList = struct { | ... | @@ -5120,7 +5120,7 @@ const PatternList = struct { |
| 5120 | }; | 5120 | }; |
| 5121 | } | 5121 | } |
| 5122 | 5122 | ||
| 5123 | fn deinit(self: *Pattern, allocator: *mem.Allocator) void { | 5123 | fn deinit(self: *Pattern, allocator: mem.Allocator) void { |
| 5124 | self.args_hash.deinit(allocator); | 5124 | self.args_hash.deinit(allocator); |
| 5125 | allocator.free(self.tokens); | 5125 | allocator.free(self.tokens); |
| 5126 | } | 5126 | } |
| ... | @@ -5171,7 +5171,7 @@ const PatternList = struct { | ... | @@ -5171,7 +5171,7 @@ const PatternList = struct { |
| 5171 | } | 5171 | } |
| 5172 | }; | 5172 | }; |
| 5173 | 5173 | ||
| 5174 | fn init(allocator: *mem.Allocator) Error!PatternList { | 5174 | fn init(allocator: mem.Allocator) Error!PatternList { |
| 5175 | const patterns = try allocator.alloc(Pattern, templates.len); | 5175 | const patterns = try allocator.alloc(Pattern, templates.len); |
| 5176 | for (templates) |template, i| { | 5176 | for (templates) |template, i| { |
| 5177 | try patterns[i].init(allocator, template); | 5177 | try patterns[i].init(allocator, template); |
| ... | @@ -5179,12 +5179,12 @@ const PatternList = struct { | ... | @@ -5179,12 +5179,12 @@ const PatternList = struct { |
| 5179 | return PatternList{ .patterns = patterns }; | 5179 | return PatternList{ .patterns = patterns }; |
| 5180 | } | 5180 | } |
| 5181 | 5181 | ||
| 5182 | fn deinit(self: *PatternList, allocator: *mem.Allocator) void { | 5182 | fn deinit(self: *PatternList, allocator: mem.Allocator) void { |
| 5183 | for (self.patterns) |*pattern| pattern.deinit(allocator); | 5183 | for (self.patterns) |*pattern| pattern.deinit(allocator); |
| 5184 | allocator.free(self.patterns); | 5184 | allocator.free(self.patterns); |
| 5185 | } | 5185 | } |
| 5186 | 5186 | ||
| 5187 | fn match(self: PatternList, allocator: *mem.Allocator, ms: MacroSlicer) Error!?Pattern { | 5187 | fn match(self: PatternList, allocator: mem.Allocator, ms: MacroSlicer) Error!?Pattern { |
| 5188 | var args_hash: ArgsPositionMap = .{}; | 5188 | var args_hash: ArgsPositionMap = .{}; |
| 5189 | defer args_hash.deinit(allocator); | 5189 | defer args_hash.deinit(allocator); |
| 5190 | 5190 | ||
| ... | @@ -5211,7 +5211,7 @@ const MacroSlicer = struct { | ... | @@ -5211,7 +5211,7 @@ const MacroSlicer = struct { |
| 5211 | test "Macro matching" { | 5211 | test "Macro matching" { |
| 5212 | const helper = struct { | 5212 | const helper = struct { |
| 5213 | const MacroFunctions = @import("std").zig.c_translation.Macros; | 5213 | const MacroFunctions = @import("std").zig.c_translation.Macros; |
| 5214 | fn checkMacro(allocator: *mem.Allocator, pattern_list: PatternList, source: []const u8, comptime expected_match: ?[]const u8) !void { | 5214 | fn checkMacro(allocator: mem.Allocator, pattern_list: PatternList, source: []const u8, comptime expected_match: ?[]const u8) !void { |
| 5215 | var tok_list = std.ArrayList(CToken).init(allocator); | 5215 | var tok_list = std.ArrayList(CToken).init(allocator); |
| 5216 | defer tok_list.deinit(); | 5216 | defer tok_list.deinit(); |
| 5217 | try tokenizeMacro(source, &tok_list); | 5217 | try tokenizeMacro(source, &tok_list); |
src/translate_c/ast.zig+3-3| ... | @@ -378,7 +378,7 @@ pub const Node = extern union { | ... | @@ -378,7 +378,7 @@ pub const Node = extern union { |
| 378 | return .{ .tag_if_small_enough = @enumToInt(t) }; | 378 | return .{ .tag_if_small_enough = @enumToInt(t) }; |
| 379 | } | 379 | } |
| 380 | 380 | ||
| 381 | pub fn create(comptime t: Tag, ally: *Allocator, data: Data(t)) error{OutOfMemory}!Node { | 381 | pub fn create(comptime t: Tag, ally: Allocator, data: Data(t)) error{OutOfMemory}!Node { |
| 382 | const ptr = try ally.create(t.Type()); | 382 | const ptr = try ally.create(t.Type()); |
| 383 | ptr.* = .{ | 383 | ptr.* = .{ |
| 384 | .base = .{ .tag = t }, | 384 | .base = .{ .tag = t }, |
| ... | @@ -717,7 +717,7 @@ pub const Payload = struct { | ... | @@ -717,7 +717,7 @@ pub const Payload = struct { |
| 717 | 717 | ||
| 718 | /// Converts the nodes into a Zig Ast. | 718 | /// Converts the nodes into a Zig Ast. |
| 719 | /// Caller must free the source slice. | 719 | /// Caller must free the source slice. |
| 720 | pub fn render(gpa: *Allocator, nodes: []const Node) !std.zig.Ast { | 720 | pub fn render(gpa: Allocator, nodes: []const Node) !std.zig.Ast { |
| 721 | var ctx = Context{ | 721 | var ctx = Context{ |
| 722 | .gpa = gpa, | 722 | .gpa = gpa, |
| 723 | .buf = std.ArrayList(u8).init(gpa), | 723 | .buf = std.ArrayList(u8).init(gpa), |
| ... | @@ -783,7 +783,7 @@ const TokenIndex = std.zig.Ast.TokenIndex; | ... | @@ -783,7 +783,7 @@ const TokenIndex = std.zig.Ast.TokenIndex; |
| 783 | const TokenTag = std.zig.Token.Tag; | 783 | const TokenTag = std.zig.Token.Tag; |
| 784 | 784 | ||
| 785 | const Context = struct { | 785 | const Context = struct { |
| 786 | gpa: *Allocator, | 786 | gpa: Allocator, |
| 787 | buf: std.ArrayList(u8) = .{}, | 787 | buf: std.ArrayList(u8) = .{}, |
| 788 | nodes: std.zig.Ast.NodeList = .{}, | 788 | nodes: std.zig.Ast.NodeList = .{}, |
| 789 | extra_data: std.ArrayListUnmanaged(std.zig.Ast.Node.Index) = .{}, | 789 | extra_data: std.ArrayListUnmanaged(std.zig.Ast.Node.Index) = .{}, |
src/type.zig+15-15| ... | @@ -728,7 +728,7 @@ pub const Type = extern union { | ... | @@ -728,7 +728,7 @@ pub const Type = extern union { |
| 728 | } | 728 | } |
| 729 | }; | 729 | }; |
| 730 | 730 | ||
| 731 | pub fn copy(self: Type, allocator: *Allocator) error{OutOfMemory}!Type { | 731 | pub fn copy(self: Type, allocator: Allocator) error{OutOfMemory}!Type { |
| 732 | if (@enumToInt(self.tag_if_small_enough) < Tag.no_payload_count) { | 732 | if (@enumToInt(self.tag_if_small_enough) < Tag.no_payload_count) { |
| 733 | return Type{ .tag_if_small_enough = self.tag_if_small_enough }; | 733 | return Type{ .tag_if_small_enough = self.tag_if_small_enough }; |
| 734 | } else switch (self.ptr_otherwise.tag) { | 734 | } else switch (self.ptr_otherwise.tag) { |
| ... | @@ -905,7 +905,7 @@ pub const Type = extern union { | ... | @@ -905,7 +905,7 @@ pub const Type = extern union { |
| 905 | } | 905 | } |
| 906 | } | 906 | } |
| 907 | 907 | ||
| 908 | fn copyPayloadShallow(self: Type, allocator: *Allocator, comptime T: type) error{OutOfMemory}!Type { | 908 | fn copyPayloadShallow(self: Type, allocator: Allocator, comptime T: type) error{OutOfMemory}!Type { |
| 909 | const payload = self.cast(T).?; | 909 | const payload = self.cast(T).?; |
| 910 | const new_payload = try allocator.create(T); | 910 | const new_payload = try allocator.create(T); |
| 911 | new_payload.* = payload.*; | 911 | new_payload.* = payload.*; |
| ... | @@ -1198,7 +1198,7 @@ pub const Type = extern union { | ... | @@ -1198,7 +1198,7 @@ pub const Type = extern union { |
| 1198 | } | 1198 | } |
| 1199 | 1199 | ||
| 1200 | /// Returns a name suitable for `@typeName`. | 1200 | /// Returns a name suitable for `@typeName`. |
| 1201 | pub fn nameAlloc(ty: Type, arena: *Allocator) Allocator.Error![:0]const u8 { | 1201 | pub fn nameAlloc(ty: Type, arena: Allocator) Allocator.Error![:0]const u8 { |
| 1202 | const t = ty.tag(); | 1202 | const t = ty.tag(); |
| 1203 | switch (t) { | 1203 | switch (t) { |
| 1204 | .inferred_alloc_const => unreachable, | 1204 | .inferred_alloc_const => unreachable, |
| ... | @@ -1421,7 +1421,7 @@ pub const Type = extern union { | ... | @@ -1421,7 +1421,7 @@ pub const Type = extern union { |
| 1421 | }; | 1421 | }; |
| 1422 | } | 1422 | } |
| 1423 | 1423 | ||
| 1424 | pub fn toValue(self: Type, allocator: *Allocator) Allocator.Error!Value { | 1424 | pub fn toValue(self: Type, allocator: Allocator) Allocator.Error!Value { |
| 1425 | switch (self.tag()) { | 1425 | switch (self.tag()) { |
| 1426 | .u1 => return Value.initTag(.u1_type), | 1426 | .u1 => return Value.initTag(.u1_type), |
| 1427 | .u8 => return Value.initTag(.u8_type), | 1427 | .u8 => return Value.initTag(.u8_type), |
| ... | @@ -2676,7 +2676,7 @@ pub const Type = extern union { | ... | @@ -2676,7 +2676,7 @@ pub const Type = extern union { |
| 2676 | /// For [*]T, returns *T | 2676 | /// For [*]T, returns *T |
| 2677 | /// For []T, returns *T | 2677 | /// For []T, returns *T |
| 2678 | /// Handles const-ness and address spaces in particular. | 2678 | /// Handles const-ness and address spaces in particular. |
| 2679 | pub fn elemPtrType(ptr_ty: Type, arena: *Allocator) !Type { | 2679 | pub fn elemPtrType(ptr_ty: Type, arena: Allocator) !Type { |
| 2680 | return try Type.ptr(arena, .{ | 2680 | return try Type.ptr(arena, .{ |
| 2681 | .pointee_type = ptr_ty.elemType2(), | 2681 | .pointee_type = ptr_ty.elemType2(), |
| 2682 | .mutable = ptr_ty.ptrIsMutable(), | 2682 | .mutable = ptr_ty.ptrIsMutable(), |
| ... | @@ -2731,7 +2731,7 @@ pub const Type = extern union { | ... | @@ -2731,7 +2731,7 @@ pub const Type = extern union { |
| 2731 | 2731 | ||
| 2732 | /// Asserts that the type is an optional. | 2732 | /// Asserts that the type is an optional. |
| 2733 | /// Same as `optionalChild` but allocates the buffer if needed. | 2733 | /// Same as `optionalChild` but allocates the buffer if needed. |
| 2734 | pub fn optionalChildAlloc(ty: Type, allocator: *Allocator) !Type { | 2734 | pub fn optionalChildAlloc(ty: Type, allocator: Allocator) !Type { |
| 2735 | switch (ty.tag()) { | 2735 | switch (ty.tag()) { |
| 2736 | .optional => return ty.castTag(.optional).?.data, | 2736 | .optional => return ty.castTag(.optional).?.data, |
| 2737 | .optional_single_mut_pointer => { | 2737 | .optional_single_mut_pointer => { |
| ... | @@ -3379,7 +3379,7 @@ pub const Type = extern union { | ... | @@ -3379,7 +3379,7 @@ pub const Type = extern union { |
| 3379 | } | 3379 | } |
| 3380 | 3380 | ||
| 3381 | /// Asserts that self.zigTypeTag() == .Int. | 3381 | /// Asserts that self.zigTypeTag() == .Int. |
| 3382 | pub fn minInt(self: Type, arena: *Allocator, target: Target) !Value { | 3382 | pub fn minInt(self: Type, arena: Allocator, target: Target) !Value { |
| 3383 | assert(self.zigTypeTag() == .Int); | 3383 | assert(self.zigTypeTag() == .Int); |
| 3384 | const info = self.intInfo(target); | 3384 | const info = self.intInfo(target); |
| 3385 | 3385 | ||
| ... | @@ -3404,7 +3404,7 @@ pub const Type = extern union { | ... | @@ -3404,7 +3404,7 @@ pub const Type = extern union { |
| 3404 | } | 3404 | } |
| 3405 | 3405 | ||
| 3406 | /// Asserts that self.zigTypeTag() == .Int. | 3406 | /// Asserts that self.zigTypeTag() == .Int. |
| 3407 | pub fn maxInt(self: Type, arena: *Allocator, target: Target) !Value { | 3407 | pub fn maxInt(self: Type, arena: Allocator, target: Target) !Value { |
| 3408 | assert(self.zigTypeTag() == .Int); | 3408 | assert(self.zigTypeTag() == .Int); |
| 3409 | const info = self.intInfo(target); | 3409 | const info = self.intInfo(target); |
| 3410 | 3410 | ||
| ... | @@ -4008,7 +4008,7 @@ pub const Type = extern union { | ... | @@ -4008,7 +4008,7 @@ pub const Type = extern union { |
| 4008 | return .{ .tag_if_small_enough = t }; | 4008 | return .{ .tag_if_small_enough = t }; |
| 4009 | } | 4009 | } |
| 4010 | 4010 | ||
| 4011 | pub fn create(comptime t: Tag, ally: *Allocator, data: Data(t)) error{OutOfMemory}!file_struct.Type { | 4011 | pub fn create(comptime t: Tag, ally: Allocator, data: Data(t)) error{OutOfMemory}!file_struct.Type { |
| 4012 | const p = try ally.create(t.Type()); | 4012 | const p = try ally.create(t.Type()); |
| 4013 | p.* = .{ | 4013 | p.* = .{ |
| 4014 | .base = .{ .tag = t }, | 4014 | .base = .{ .tag = t }, |
| ... | @@ -4104,7 +4104,7 @@ pub const Type = extern union { | ... | @@ -4104,7 +4104,7 @@ pub const Type = extern union { |
| 4104 | functions: std.AutoHashMapUnmanaged(*Module.Fn, void), | 4104 | functions: std.AutoHashMapUnmanaged(*Module.Fn, void), |
| 4105 | is_anyerror: bool, | 4105 | is_anyerror: bool, |
| 4106 | 4106 | ||
| 4107 | pub fn addErrorSet(self: *Data, gpa: *Allocator, err_set_ty: Type) !void { | 4107 | pub fn addErrorSet(self: *Data, gpa: Allocator, err_set_ty: Type) !void { |
| 4108 | switch (err_set_ty.tag()) { | 4108 | switch (err_set_ty.tag()) { |
| 4109 | .error_set => { | 4109 | .error_set => { |
| 4110 | const names = err_set_ty.castTag(.error_set).?.data.names(); | 4110 | const names = err_set_ty.castTag(.error_set).?.data.names(); |
| ... | @@ -4225,7 +4225,7 @@ pub const Type = extern union { | ... | @@ -4225,7 +4225,7 @@ pub const Type = extern union { |
| 4225 | pub const @"type" = initTag(.type); | 4225 | pub const @"type" = initTag(.type); |
| 4226 | pub const @"anyerror" = initTag(.anyerror); | 4226 | pub const @"anyerror" = initTag(.anyerror); |
| 4227 | 4227 | ||
| 4228 | pub fn ptr(arena: *Allocator, d: Payload.Pointer.Data) !Type { | 4228 | pub fn ptr(arena: Allocator, d: Payload.Pointer.Data) !Type { |
| 4229 | assert(d.host_size == 0 or d.bit_offset < d.host_size * 8); | 4229 | assert(d.host_size == 0 or d.bit_offset < d.host_size * 8); |
| 4230 | 4230 | ||
| 4231 | if (d.sentinel != null or d.@"align" != 0 or d.@"addrspace" != .generic or | 4231 | if (d.sentinel != null or d.@"align" != 0 or d.@"addrspace" != .generic or |
| ... | @@ -4260,7 +4260,7 @@ pub const Type = extern union { | ... | @@ -4260,7 +4260,7 @@ pub const Type = extern union { |
| 4260 | } | 4260 | } |
| 4261 | 4261 | ||
| 4262 | pub fn array( | 4262 | pub fn array( |
| 4263 | arena: *Allocator, | 4263 | arena: Allocator, |
| 4264 | len: u64, | 4264 | len: u64, |
| 4265 | sent: ?Value, | 4265 | sent: ?Value, |
| 4266 | elem_type: Type, | 4266 | elem_type: Type, |
| ... | @@ -4289,14 +4289,14 @@ pub const Type = extern union { | ... | @@ -4289,14 +4289,14 @@ pub const Type = extern union { |
| 4289 | }); | 4289 | }); |
| 4290 | } | 4290 | } |
| 4291 | 4291 | ||
| 4292 | pub fn vector(arena: *Allocator, len: u64, elem_type: Type) Allocator.Error!Type { | 4292 | pub fn vector(arena: Allocator, len: u64, elem_type: Type) Allocator.Error!Type { |
| 4293 | return Tag.vector.create(arena, .{ | 4293 | return Tag.vector.create(arena, .{ |
| 4294 | .len = len, | 4294 | .len = len, |
| 4295 | .elem_type = elem_type, | 4295 | .elem_type = elem_type, |
| 4296 | }); | 4296 | }); |
| 4297 | } | 4297 | } |
| 4298 | 4298 | ||
| 4299 | pub fn optional(arena: *Allocator, child_type: Type) Allocator.Error!Type { | 4299 | pub fn optional(arena: Allocator, child_type: Type) Allocator.Error!Type { |
| 4300 | switch (child_type.tag()) { | 4300 | switch (child_type.tag()) { |
| 4301 | .single_const_pointer => return Type.Tag.optional_single_const_pointer.create( | 4301 | .single_const_pointer => return Type.Tag.optional_single_const_pointer.create( |
| 4302 | arena, | 4302 | arena, |
| ... | @@ -4317,7 +4317,7 @@ pub const Type = extern union { | ... | @@ -4317,7 +4317,7 @@ pub const Type = extern union { |
| 4317 | return @intCast(u16, base + @boolToInt(upper < max)); | 4317 | return @intCast(u16, base + @boolToInt(upper < max)); |
| 4318 | } | 4318 | } |
| 4319 | 4319 | ||
| 4320 | pub fn smallestUnsignedInt(arena: *Allocator, max: u64) !Type { | 4320 | pub fn smallestUnsignedInt(arena: Allocator, max: u64) !Type { |
| 4321 | const bits = smallestUnsignedBits(max); | 4321 | const bits = smallestUnsignedBits(max); |
| 4322 | return switch (bits) { | 4322 | return switch (bits) { |
| 4323 | 1 => initTag(.u1), | 4323 | 1 => initTag(.u1), |
src/value.zig+46-46| ... | @@ -297,7 +297,7 @@ pub const Value = extern union { | ... | @@ -297,7 +297,7 @@ pub const Value = extern union { |
| 297 | }; | 297 | }; |
| 298 | } | 298 | } |
| 299 | 299 | ||
| 300 | pub fn create(comptime t: Tag, ally: *Allocator, data: Data(t)) error{OutOfMemory}!Value { | 300 | pub fn create(comptime t: Tag, ally: Allocator, data: Data(t)) error{OutOfMemory}!Value { |
| 301 | const ptr = try ally.create(t.Type()); | 301 | const ptr = try ally.create(t.Type()); |
| 302 | ptr.* = .{ | 302 | ptr.* = .{ |
| 303 | .base = .{ .tag = t }, | 303 | .base = .{ .tag = t }, |
| ... | @@ -363,7 +363,7 @@ pub const Value = extern union { | ... | @@ -363,7 +363,7 @@ pub const Value = extern union { |
| 363 | 363 | ||
| 364 | /// It's intentional that this function is not passed a corresponding Type, so that | 364 | /// It's intentional that this function is not passed a corresponding Type, so that |
| 365 | /// a Value can be copied from a Sema to a Decl prior to resolving struct/union field types. | 365 | /// a Value can be copied from a Sema to a Decl prior to resolving struct/union field types. |
| 366 | pub fn copy(self: Value, arena: *Allocator) error{OutOfMemory}!Value { | 366 | pub fn copy(self: Value, arena: Allocator) error{OutOfMemory}!Value { |
| 367 | if (@enumToInt(self.tag_if_small_enough) < Tag.no_payload_count) { | 367 | if (@enumToInt(self.tag_if_small_enough) < Tag.no_payload_count) { |
| 368 | return Value{ .tag_if_small_enough = self.tag_if_small_enough }; | 368 | return Value{ .tag_if_small_enough = self.tag_if_small_enough }; |
| 369 | } else switch (self.ptr_otherwise.tag) { | 369 | } else switch (self.ptr_otherwise.tag) { |
| ... | @@ -578,7 +578,7 @@ pub const Value = extern union { | ... | @@ -578,7 +578,7 @@ pub const Value = extern union { |
| 578 | } | 578 | } |
| 579 | } | 579 | } |
| 580 | 580 | ||
| 581 | fn copyPayloadShallow(self: Value, arena: *Allocator, comptime T: type) error{OutOfMemory}!Value { | 581 | fn copyPayloadShallow(self: Value, arena: Allocator, comptime T: type) error{OutOfMemory}!Value { |
| 582 | const payload = self.cast(T).?; | 582 | const payload = self.cast(T).?; |
| 583 | const new_payload = try arena.create(T); | 583 | const new_payload = try arena.create(T); |
| 584 | new_payload.* = payload.*; | 584 | new_payload.* = payload.*; |
| ... | @@ -747,7 +747,7 @@ pub const Value = extern union { | ... | @@ -747,7 +747,7 @@ pub const Value = extern union { |
| 747 | 747 | ||
| 748 | /// Asserts that the value is representable as an array of bytes. | 748 | /// Asserts that the value is representable as an array of bytes. |
| 749 | /// Copies the value into a freshly allocated slice of memory, which is owned by the caller. | 749 | /// Copies the value into a freshly allocated slice of memory, which is owned by the caller. |
| 750 | pub fn toAllocatedBytes(val: Value, ty: Type, allocator: *Allocator) ![]u8 { | 750 | pub fn toAllocatedBytes(val: Value, ty: Type, allocator: Allocator) ![]u8 { |
| 751 | switch (val.tag()) { | 751 | switch (val.tag()) { |
| 752 | .bytes => { | 752 | .bytes => { |
| 753 | const bytes = val.castTag(.bytes).?.data; | 753 | const bytes = val.castTag(.bytes).?.data; |
| ... | @@ -1035,7 +1035,7 @@ pub const Value = extern union { | ... | @@ -1035,7 +1035,7 @@ pub const Value = extern union { |
| 1035 | } | 1035 | } |
| 1036 | } | 1036 | } |
| 1037 | 1037 | ||
| 1038 | pub fn readFromMemory(ty: Type, target: Target, buffer: []const u8, arena: *Allocator) !Value { | 1038 | pub fn readFromMemory(ty: Type, target: Target, buffer: []const u8, arena: Allocator) !Value { |
| 1039 | switch (ty.zigTypeTag()) { | 1039 | switch (ty.zigTypeTag()) { |
| 1040 | .Int => { | 1040 | .Int => { |
| 1041 | const int_info = ty.intInfo(target); | 1041 | const int_info = ty.intInfo(target); |
| ... | @@ -1185,7 +1185,7 @@ pub const Value = extern union { | ... | @@ -1185,7 +1185,7 @@ pub const Value = extern union { |
| 1185 | } | 1185 | } |
| 1186 | } | 1186 | } |
| 1187 | 1187 | ||
| 1188 | pub fn popCount(val: Value, ty: Type, target: Target, arena: *Allocator) !Value { | 1188 | pub fn popCount(val: Value, ty: Type, target: Target, arena: Allocator) !Value { |
| 1189 | assert(!val.isUndef()); | 1189 | assert(!val.isUndef()); |
| 1190 | 1190 | ||
| 1191 | const info = ty.intInfo(target); | 1191 | const info = ty.intInfo(target); |
| ... | @@ -1273,7 +1273,7 @@ pub const Value = extern union { | ... | @@ -1273,7 +1273,7 @@ pub const Value = extern union { |
| 1273 | 1273 | ||
| 1274 | /// Converts an integer or a float to a float. May result in a loss of information. | 1274 | /// Converts an integer or a float to a float. May result in a loss of information. |
| 1275 | /// Caller can find out by equality checking the result against the operand. | 1275 | /// Caller can find out by equality checking the result against the operand. |
| 1276 | pub fn floatCast(self: Value, arena: *Allocator, dest_ty: Type) !Value { | 1276 | pub fn floatCast(self: Value, arena: Allocator, dest_ty: Type) !Value { |
| 1277 | switch (dest_ty.tag()) { | 1277 | switch (dest_ty.tag()) { |
| 1278 | .f16 => return Value.Tag.float_16.create(arena, self.toFloat(f16)), | 1278 | .f16 => return Value.Tag.float_16.create(arena, self.toFloat(f16)), |
| 1279 | .f32 => return Value.Tag.float_32.create(arena, self.toFloat(f32)), | 1279 | .f32 => return Value.Tag.float_32.create(arena, self.toFloat(f32)), |
| ... | @@ -1678,7 +1678,7 @@ pub const Value = extern union { | ... | @@ -1678,7 +1678,7 @@ pub const Value = extern union { |
| 1678 | 1678 | ||
| 1679 | /// Asserts the value is a single-item pointer to an array, or an array, | 1679 | /// Asserts the value is a single-item pointer to an array, or an array, |
| 1680 | /// or an unknown-length pointer, and returns the element value at the index. | 1680 | /// or an unknown-length pointer, and returns the element value at the index. |
| 1681 | pub fn elemValue(val: Value, arena: *Allocator, index: usize) !Value { | 1681 | pub fn elemValue(val: Value, arena: Allocator, index: usize) !Value { |
| 1682 | return elemValueAdvanced(val, index, arena, undefined); | 1682 | return elemValueAdvanced(val, index, arena, undefined); |
| 1683 | } | 1683 | } |
| 1684 | 1684 | ||
| ... | @@ -1691,7 +1691,7 @@ pub const Value = extern union { | ... | @@ -1691,7 +1691,7 @@ pub const Value = extern union { |
| 1691 | pub fn elemValueAdvanced( | 1691 | pub fn elemValueAdvanced( |
| 1692 | val: Value, | 1692 | val: Value, |
| 1693 | index: usize, | 1693 | index: usize, |
| 1694 | arena: ?*Allocator, | 1694 | arena: ?Allocator, |
| 1695 | buffer: *ElemValueBuffer, | 1695 | buffer: *ElemValueBuffer, |
| 1696 | ) error{OutOfMemory}!Value { | 1696 | ) error{OutOfMemory}!Value { |
| 1697 | switch (val.tag()) { | 1697 | switch (val.tag()) { |
| ... | @@ -1732,7 +1732,7 @@ pub const Value = extern union { | ... | @@ -1732,7 +1732,7 @@ pub const Value = extern union { |
| 1732 | } | 1732 | } |
| 1733 | } | 1733 | } |
| 1734 | 1734 | ||
| 1735 | pub fn fieldValue(val: Value, allocator: *Allocator, index: usize) error{OutOfMemory}!Value { | 1735 | pub fn fieldValue(val: Value, allocator: Allocator, index: usize) error{OutOfMemory}!Value { |
| 1736 | _ = allocator; | 1736 | _ = allocator; |
| 1737 | switch (val.tag()) { | 1737 | switch (val.tag()) { |
| 1738 | .@"struct" => { | 1738 | .@"struct" => { |
| ... | @@ -1760,7 +1760,7 @@ pub const Value = extern union { | ... | @@ -1760,7 +1760,7 @@ pub const Value = extern union { |
| 1760 | } | 1760 | } |
| 1761 | 1761 | ||
| 1762 | /// Returns a pointer to the element value at the index. | 1762 | /// Returns a pointer to the element value at the index. |
| 1763 | pub fn elemPtr(self: Value, allocator: *Allocator, index: usize) !Value { | 1763 | pub fn elemPtr(self: Value, allocator: Allocator, index: usize) !Value { |
| 1764 | switch (self.tag()) { | 1764 | switch (self.tag()) { |
| 1765 | .elem_ptr => { | 1765 | .elem_ptr => { |
| 1766 | const elem_ptr = self.castTag(.elem_ptr).?.data; | 1766 | const elem_ptr = self.castTag(.elem_ptr).?.data; |
| ... | @@ -1874,7 +1874,7 @@ pub const Value = extern union { | ... | @@ -1874,7 +1874,7 @@ pub const Value = extern union { |
| 1874 | }; | 1874 | }; |
| 1875 | } | 1875 | } |
| 1876 | 1876 | ||
| 1877 | pub fn intToFloat(val: Value, arena: *Allocator, dest_ty: Type, target: Target) !Value { | 1877 | pub fn intToFloat(val: Value, arena: Allocator, dest_ty: Type, target: Target) !Value { |
| 1878 | switch (val.tag()) { | 1878 | switch (val.tag()) { |
| 1879 | .undef, .zero, .one => return val, | 1879 | .undef, .zero, .one => return val, |
| 1880 | .the_only_possible_value => return Value.initTag(.zero), // for i0, u0 | 1880 | .the_only_possible_value => return Value.initTag(.zero), // for i0, u0 |
| ... | @@ -1898,7 +1898,7 @@ pub const Value = extern union { | ... | @@ -1898,7 +1898,7 @@ pub const Value = extern union { |
| 1898 | } | 1898 | } |
| 1899 | } | 1899 | } |
| 1900 | 1900 | ||
| 1901 | fn intToFloatInner(x: anytype, arena: *Allocator, dest_ty: Type, target: Target) !Value { | 1901 | fn intToFloatInner(x: anytype, arena: Allocator, dest_ty: Type, target: Target) !Value { |
| 1902 | switch (dest_ty.floatBits(target)) { | 1902 | switch (dest_ty.floatBits(target)) { |
| 1903 | 16 => return Value.Tag.float_16.create(arena, @intToFloat(f16, x)), | 1903 | 16 => return Value.Tag.float_16.create(arena, @intToFloat(f16, x)), |
| 1904 | 32 => return Value.Tag.float_32.create(arena, @intToFloat(f32, x)), | 1904 | 32 => return Value.Tag.float_32.create(arena, @intToFloat(f32, x)), |
| ... | @@ -1908,7 +1908,7 @@ pub const Value = extern union { | ... | @@ -1908,7 +1908,7 @@ pub const Value = extern union { |
| 1908 | } | 1908 | } |
| 1909 | } | 1909 | } |
| 1910 | 1910 | ||
| 1911 | fn floatToValue(float: f128, arena: *Allocator, dest_ty: Type, target: Target) !Value { | 1911 | fn floatToValue(float: f128, arena: Allocator, dest_ty: Type, target: Target) !Value { |
| 1912 | switch (dest_ty.floatBits(target)) { | 1912 | switch (dest_ty.floatBits(target)) { |
| 1913 | 16 => return Value.Tag.float_16.create(arena, @floatCast(f16, float)), | 1913 | 16 => return Value.Tag.float_16.create(arena, @floatCast(f16, float)), |
| 1914 | 32 => return Value.Tag.float_32.create(arena, @floatCast(f32, float)), | 1914 | 32 => return Value.Tag.float_32.create(arena, @floatCast(f32, float)), |
| ... | @@ -1918,7 +1918,7 @@ pub const Value = extern union { | ... | @@ -1918,7 +1918,7 @@ pub const Value = extern union { |
| 1918 | } | 1918 | } |
| 1919 | } | 1919 | } |
| 1920 | 1920 | ||
| 1921 | pub fn floatToInt(val: Value, arena: *Allocator, dest_ty: Type, target: Target) error{ FloatCannotFit, OutOfMemory }!Value { | 1921 | pub fn floatToInt(val: Value, arena: Allocator, dest_ty: Type, target: Target) error{ FloatCannotFit, OutOfMemory }!Value { |
| 1922 | const Limb = std.math.big.Limb; | 1922 | const Limb = std.math.big.Limb; |
| 1923 | 1923 | ||
| 1924 | var value = val.toFloat(f64); // TODO: f128 ? | 1924 | var value = val.toFloat(f64); // TODO: f128 ? |
| ... | @@ -1969,7 +1969,7 @@ pub const Value = extern union { | ... | @@ -1969,7 +1969,7 @@ pub const Value = extern union { |
| 1969 | lhs: Value, | 1969 | lhs: Value, |
| 1970 | rhs: Value, | 1970 | rhs: Value, |
| 1971 | ty: Type, | 1971 | ty: Type, |
| 1972 | arena: *Allocator, | 1972 | arena: Allocator, |
| 1973 | target: Target, | 1973 | target: Target, |
| 1974 | ) !Value { | 1974 | ) !Value { |
| 1975 | if (lhs.isUndef() or rhs.isUndef()) return Value.initTag(.undef); | 1975 | if (lhs.isUndef() or rhs.isUndef()) return Value.initTag(.undef); |
| ... | @@ -1993,7 +1993,7 @@ pub const Value = extern union { | ... | @@ -1993,7 +1993,7 @@ pub const Value = extern union { |
| 1993 | return fromBigInt(arena, result_bigint.toConst()); | 1993 | return fromBigInt(arena, result_bigint.toConst()); |
| 1994 | } | 1994 | } |
| 1995 | 1995 | ||
| 1996 | fn fromBigInt(arena: *Allocator, big_int: BigIntConst) !Value { | 1996 | fn fromBigInt(arena: Allocator, big_int: BigIntConst) !Value { |
| 1997 | if (big_int.positive) { | 1997 | if (big_int.positive) { |
| 1998 | if (big_int.to(u64)) |x| { | 1998 | if (big_int.to(u64)) |x| { |
| 1999 | return Value.Tag.int_u64.create(arena, x); | 1999 | return Value.Tag.int_u64.create(arena, x); |
| ... | @@ -2014,7 +2014,7 @@ pub const Value = extern union { | ... | @@ -2014,7 +2014,7 @@ pub const Value = extern union { |
| 2014 | lhs: Value, | 2014 | lhs: Value, |
| 2015 | rhs: Value, | 2015 | rhs: Value, |
| 2016 | ty: Type, | 2016 | ty: Type, |
| 2017 | arena: *Allocator, | 2017 | arena: Allocator, |
| 2018 | target: Target, | 2018 | target: Target, |
| 2019 | ) !Value { | 2019 | ) !Value { |
| 2020 | assert(!lhs.isUndef()); | 2020 | assert(!lhs.isUndef()); |
| ... | @@ -2040,7 +2040,7 @@ pub const Value = extern union { | ... | @@ -2040,7 +2040,7 @@ pub const Value = extern union { |
| 2040 | lhs: Value, | 2040 | lhs: Value, |
| 2041 | rhs: Value, | 2041 | rhs: Value, |
| 2042 | ty: Type, | 2042 | ty: Type, |
| 2043 | arena: *Allocator, | 2043 | arena: Allocator, |
| 2044 | target: Target, | 2044 | target: Target, |
| 2045 | ) !Value { | 2045 | ) !Value { |
| 2046 | if (lhs.isUndef() or rhs.isUndef()) return Value.initTag(.undef); | 2046 | if (lhs.isUndef() or rhs.isUndef()) return Value.initTag(.undef); |
| ... | @@ -2069,7 +2069,7 @@ pub const Value = extern union { | ... | @@ -2069,7 +2069,7 @@ pub const Value = extern union { |
| 2069 | lhs: Value, | 2069 | lhs: Value, |
| 2070 | rhs: Value, | 2070 | rhs: Value, |
| 2071 | ty: Type, | 2071 | ty: Type, |
| 2072 | arena: *Allocator, | 2072 | arena: Allocator, |
| 2073 | target: Target, | 2073 | target: Target, |
| 2074 | ) !Value { | 2074 | ) !Value { |
| 2075 | assert(!lhs.isUndef()); | 2075 | assert(!lhs.isUndef()); |
| ... | @@ -2095,7 +2095,7 @@ pub const Value = extern union { | ... | @@ -2095,7 +2095,7 @@ pub const Value = extern union { |
| 2095 | lhs: Value, | 2095 | lhs: Value, |
| 2096 | rhs: Value, | 2096 | rhs: Value, |
| 2097 | ty: Type, | 2097 | ty: Type, |
| 2098 | arena: *Allocator, | 2098 | arena: Allocator, |
| 2099 | target: Target, | 2099 | target: Target, |
| 2100 | ) !Value { | 2100 | ) !Value { |
| 2101 | if (lhs.isUndef() or rhs.isUndef()) return Value.initTag(.undef); | 2101 | if (lhs.isUndef() or rhs.isUndef()) return Value.initTag(.undef); |
| ... | @@ -2129,7 +2129,7 @@ pub const Value = extern union { | ... | @@ -2129,7 +2129,7 @@ pub const Value = extern union { |
| 2129 | lhs: Value, | 2129 | lhs: Value, |
| 2130 | rhs: Value, | 2130 | rhs: Value, |
| 2131 | ty: Type, | 2131 | ty: Type, |
| 2132 | arena: *Allocator, | 2132 | arena: Allocator, |
| 2133 | target: Target, | 2133 | target: Target, |
| 2134 | ) !Value { | 2134 | ) !Value { |
| 2135 | assert(!lhs.isUndef()); | 2135 | assert(!lhs.isUndef()); |
| ... | @@ -2185,7 +2185,7 @@ pub const Value = extern union { | ... | @@ -2185,7 +2185,7 @@ pub const Value = extern union { |
| 2185 | } | 2185 | } |
| 2186 | 2186 | ||
| 2187 | /// operands must be integers; handles undefined. | 2187 | /// operands must be integers; handles undefined. |
| 2188 | pub fn bitwiseNot(val: Value, ty: Type, arena: *Allocator, target: Target) !Value { | 2188 | pub fn bitwiseNot(val: Value, ty: Type, arena: Allocator, target: Target) !Value { |
| 2189 | if (val.isUndef()) return Value.initTag(.undef); | 2189 | if (val.isUndef()) return Value.initTag(.undef); |
| 2190 | 2190 | ||
| 2191 | const info = ty.intInfo(target); | 2191 | const info = ty.intInfo(target); |
| ... | @@ -2205,7 +2205,7 @@ pub const Value = extern union { | ... | @@ -2205,7 +2205,7 @@ pub const Value = extern union { |
| 2205 | } | 2205 | } |
| 2206 | 2206 | ||
| 2207 | /// operands must be integers; handles undefined. | 2207 | /// operands must be integers; handles undefined. |
| 2208 | pub fn bitwiseAnd(lhs: Value, rhs: Value, arena: *Allocator) !Value { | 2208 | pub fn bitwiseAnd(lhs: Value, rhs: Value, arena: Allocator) !Value { |
| 2209 | if (lhs.isUndef() or rhs.isUndef()) return Value.initTag(.undef); | 2209 | if (lhs.isUndef() or rhs.isUndef()) return Value.initTag(.undef); |
| 2210 | 2210 | ||
| 2211 | // TODO is this a performance issue? maybe we should try the operation without | 2211 | // TODO is this a performance issue? maybe we should try the operation without |
| ... | @@ -2225,7 +2225,7 @@ pub const Value = extern union { | ... | @@ -2225,7 +2225,7 @@ pub const Value = extern union { |
| 2225 | } | 2225 | } |
| 2226 | 2226 | ||
| 2227 | /// operands must be integers; handles undefined. | 2227 | /// operands must be integers; handles undefined. |
| 2228 | pub fn bitwiseNand(lhs: Value, rhs: Value, ty: Type, arena: *Allocator, target: Target) !Value { | 2228 | pub fn bitwiseNand(lhs: Value, rhs: Value, ty: Type, arena: Allocator, target: Target) !Value { |
| 2229 | if (lhs.isUndef() or rhs.isUndef()) return Value.initTag(.undef); | 2229 | if (lhs.isUndef() or rhs.isUndef()) return Value.initTag(.undef); |
| 2230 | 2230 | ||
| 2231 | const anded = try bitwiseAnd(lhs, rhs, arena); | 2231 | const anded = try bitwiseAnd(lhs, rhs, arena); |
| ... | @@ -2239,7 +2239,7 @@ pub const Value = extern union { | ... | @@ -2239,7 +2239,7 @@ pub const Value = extern union { |
| 2239 | } | 2239 | } |
| 2240 | 2240 | ||
| 2241 | /// operands must be integers; handles undefined. | 2241 | /// operands must be integers; handles undefined. |
| 2242 | pub fn bitwiseOr(lhs: Value, rhs: Value, arena: *Allocator) !Value { | 2242 | pub fn bitwiseOr(lhs: Value, rhs: Value, arena: Allocator) !Value { |
| 2243 | if (lhs.isUndef() or rhs.isUndef()) return Value.initTag(.undef); | 2243 | if (lhs.isUndef() or rhs.isUndef()) return Value.initTag(.undef); |
| 2244 | 2244 | ||
| 2245 | // TODO is this a performance issue? maybe we should try the operation without | 2245 | // TODO is this a performance issue? maybe we should try the operation without |
| ... | @@ -2258,7 +2258,7 @@ pub const Value = extern union { | ... | @@ -2258,7 +2258,7 @@ pub const Value = extern union { |
| 2258 | } | 2258 | } |
| 2259 | 2259 | ||
| 2260 | /// operands must be integers; handles undefined. | 2260 | /// operands must be integers; handles undefined. |
| 2261 | pub fn bitwiseXor(lhs: Value, rhs: Value, arena: *Allocator) !Value { | 2261 | pub fn bitwiseXor(lhs: Value, rhs: Value, arena: Allocator) !Value { |
| 2262 | if (lhs.isUndef() or rhs.isUndef()) return Value.initTag(.undef); | 2262 | if (lhs.isUndef() or rhs.isUndef()) return Value.initTag(.undef); |
| 2263 | 2263 | ||
| 2264 | // TODO is this a performance issue? maybe we should try the operation without | 2264 | // TODO is this a performance issue? maybe we should try the operation without |
| ... | @@ -2277,7 +2277,7 @@ pub const Value = extern union { | ... | @@ -2277,7 +2277,7 @@ pub const Value = extern union { |
| 2277 | return fromBigInt(arena, result_bigint.toConst()); | 2277 | return fromBigInt(arena, result_bigint.toConst()); |
| 2278 | } | 2278 | } |
| 2279 | 2279 | ||
| 2280 | pub fn intAdd(lhs: Value, rhs: Value, allocator: *Allocator) !Value { | 2280 | pub fn intAdd(lhs: Value, rhs: Value, allocator: Allocator) !Value { |
| 2281 | // TODO is this a performance issue? maybe we should try the operation without | 2281 | // TODO is this a performance issue? maybe we should try the operation without |
| 2282 | // resorting to BigInt first. | 2282 | // resorting to BigInt first. |
| 2283 | var lhs_space: Value.BigIntSpace = undefined; | 2283 | var lhs_space: Value.BigIntSpace = undefined; |
| ... | @@ -2293,7 +2293,7 @@ pub const Value = extern union { | ... | @@ -2293,7 +2293,7 @@ pub const Value = extern union { |
| 2293 | return fromBigInt(allocator, result_bigint.toConst()); | 2293 | return fromBigInt(allocator, result_bigint.toConst()); |
| 2294 | } | 2294 | } |
| 2295 | 2295 | ||
| 2296 | pub fn intSub(lhs: Value, rhs: Value, allocator: *Allocator) !Value { | 2296 | pub fn intSub(lhs: Value, rhs: Value, allocator: Allocator) !Value { |
| 2297 | // TODO is this a performance issue? maybe we should try the operation without | 2297 | // TODO is this a performance issue? maybe we should try the operation without |
| 2298 | // resorting to BigInt first. | 2298 | // resorting to BigInt first. |
| 2299 | var lhs_space: Value.BigIntSpace = undefined; | 2299 | var lhs_space: Value.BigIntSpace = undefined; |
| ... | @@ -2309,7 +2309,7 @@ pub const Value = extern union { | ... | @@ -2309,7 +2309,7 @@ pub const Value = extern union { |
| 2309 | return fromBigInt(allocator, result_bigint.toConst()); | 2309 | return fromBigInt(allocator, result_bigint.toConst()); |
| 2310 | } | 2310 | } |
| 2311 | 2311 | ||
| 2312 | pub fn intDiv(lhs: Value, rhs: Value, allocator: *Allocator) !Value { | 2312 | pub fn intDiv(lhs: Value, rhs: Value, allocator: Allocator) !Value { |
| 2313 | // TODO is this a performance issue? maybe we should try the operation without | 2313 | // TODO is this a performance issue? maybe we should try the operation without |
| 2314 | // resorting to BigInt first. | 2314 | // resorting to BigInt first. |
| 2315 | var lhs_space: Value.BigIntSpace = undefined; | 2315 | var lhs_space: Value.BigIntSpace = undefined; |
| ... | @@ -2334,7 +2334,7 @@ pub const Value = extern union { | ... | @@ -2334,7 +2334,7 @@ pub const Value = extern union { |
| 2334 | return fromBigInt(allocator, result_q.toConst()); | 2334 | return fromBigInt(allocator, result_q.toConst()); |
| 2335 | } | 2335 | } |
| 2336 | 2336 | ||
| 2337 | pub fn intDivFloor(lhs: Value, rhs: Value, allocator: *Allocator) !Value { | 2337 | pub fn intDivFloor(lhs: Value, rhs: Value, allocator: Allocator) !Value { |
| 2338 | // TODO is this a performance issue? maybe we should try the operation without | 2338 | // TODO is this a performance issue? maybe we should try the operation without |
| 2339 | // resorting to BigInt first. | 2339 | // resorting to BigInt first. |
| 2340 | var lhs_space: Value.BigIntSpace = undefined; | 2340 | var lhs_space: Value.BigIntSpace = undefined; |
| ... | @@ -2359,7 +2359,7 @@ pub const Value = extern union { | ... | @@ -2359,7 +2359,7 @@ pub const Value = extern union { |
| 2359 | return fromBigInt(allocator, result_q.toConst()); | 2359 | return fromBigInt(allocator, result_q.toConst()); |
| 2360 | } | 2360 | } |
| 2361 | 2361 | ||
| 2362 | pub fn intRem(lhs: Value, rhs: Value, allocator: *Allocator) !Value { | 2362 | pub fn intRem(lhs: Value, rhs: Value, allocator: Allocator) !Value { |
| 2363 | // TODO is this a performance issue? maybe we should try the operation without | 2363 | // TODO is this a performance issue? maybe we should try the operation without |
| 2364 | // resorting to BigInt first. | 2364 | // resorting to BigInt first. |
| 2365 | var lhs_space: Value.BigIntSpace = undefined; | 2365 | var lhs_space: Value.BigIntSpace = undefined; |
| ... | @@ -2386,7 +2386,7 @@ pub const Value = extern union { | ... | @@ -2386,7 +2386,7 @@ pub const Value = extern union { |
| 2386 | return fromBigInt(allocator, result_r.toConst()); | 2386 | return fromBigInt(allocator, result_r.toConst()); |
| 2387 | } | 2387 | } |
| 2388 | 2388 | ||
| 2389 | pub fn intMod(lhs: Value, rhs: Value, allocator: *Allocator) !Value { | 2389 | pub fn intMod(lhs: Value, rhs: Value, allocator: Allocator) !Value { |
| 2390 | // TODO is this a performance issue? maybe we should try the operation without | 2390 | // TODO is this a performance issue? maybe we should try the operation without |
| 2391 | // resorting to BigInt first. | 2391 | // resorting to BigInt first. |
| 2392 | var lhs_space: Value.BigIntSpace = undefined; | 2392 | var lhs_space: Value.BigIntSpace = undefined; |
| ... | @@ -2422,21 +2422,21 @@ pub const Value = extern union { | ... | @@ -2422,21 +2422,21 @@ pub const Value = extern union { |
| 2422 | }; | 2422 | }; |
| 2423 | } | 2423 | } |
| 2424 | 2424 | ||
| 2425 | pub fn floatRem(lhs: Value, rhs: Value, allocator: *Allocator) !Value { | 2425 | pub fn floatRem(lhs: Value, rhs: Value, allocator: Allocator) !Value { |
| 2426 | _ = lhs; | 2426 | _ = lhs; |
| 2427 | _ = rhs; | 2427 | _ = rhs; |
| 2428 | _ = allocator; | 2428 | _ = allocator; |
| 2429 | @panic("TODO implement Value.floatRem"); | 2429 | @panic("TODO implement Value.floatRem"); |
| 2430 | } | 2430 | } |
| 2431 | 2431 | ||
| 2432 | pub fn floatMod(lhs: Value, rhs: Value, allocator: *Allocator) !Value { | 2432 | pub fn floatMod(lhs: Value, rhs: Value, allocator: Allocator) !Value { |
| 2433 | _ = lhs; | 2433 | _ = lhs; |
| 2434 | _ = rhs; | 2434 | _ = rhs; |
| 2435 | _ = allocator; | 2435 | _ = allocator; |
| 2436 | @panic("TODO implement Value.floatMod"); | 2436 | @panic("TODO implement Value.floatMod"); |
| 2437 | } | 2437 | } |
| 2438 | 2438 | ||
| 2439 | pub fn intMul(lhs: Value, rhs: Value, allocator: *Allocator) !Value { | 2439 | pub fn intMul(lhs: Value, rhs: Value, allocator: Allocator) !Value { |
| 2440 | // TODO is this a performance issue? maybe we should try the operation without | 2440 | // TODO is this a performance issue? maybe we should try the operation without |
| 2441 | // resorting to BigInt first. | 2441 | // resorting to BigInt first. |
| 2442 | var lhs_space: Value.BigIntSpace = undefined; | 2442 | var lhs_space: Value.BigIntSpace = undefined; |
| ... | @@ -2457,7 +2457,7 @@ pub const Value = extern union { | ... | @@ -2457,7 +2457,7 @@ pub const Value = extern union { |
| 2457 | return fromBigInt(allocator, result_bigint.toConst()); | 2457 | return fromBigInt(allocator, result_bigint.toConst()); |
| 2458 | } | 2458 | } |
| 2459 | 2459 | ||
| 2460 | pub fn intTrunc(val: Value, allocator: *Allocator, signedness: std.builtin.Signedness, bits: u16) !Value { | 2460 | pub fn intTrunc(val: Value, allocator: Allocator, signedness: std.builtin.Signedness, bits: u16) !Value { |
| 2461 | var val_space: Value.BigIntSpace = undefined; | 2461 | var val_space: Value.BigIntSpace = undefined; |
| 2462 | const val_bigint = val.toBigInt(&val_space); | 2462 | const val_bigint = val.toBigInt(&val_space); |
| 2463 | 2463 | ||
| ... | @@ -2471,7 +2471,7 @@ pub const Value = extern union { | ... | @@ -2471,7 +2471,7 @@ pub const Value = extern union { |
| 2471 | return fromBigInt(allocator, result_bigint.toConst()); | 2471 | return fromBigInt(allocator, result_bigint.toConst()); |
| 2472 | } | 2472 | } |
| 2473 | 2473 | ||
| 2474 | pub fn shl(lhs: Value, rhs: Value, allocator: *Allocator) !Value { | 2474 | pub fn shl(lhs: Value, rhs: Value, allocator: Allocator) !Value { |
| 2475 | // TODO is this a performance issue? maybe we should try the operation without | 2475 | // TODO is this a performance issue? maybe we should try the operation without |
| 2476 | // resorting to BigInt first. | 2476 | // resorting to BigInt first. |
| 2477 | var lhs_space: Value.BigIntSpace = undefined; | 2477 | var lhs_space: Value.BigIntSpace = undefined; |
| ... | @@ -2494,7 +2494,7 @@ pub const Value = extern union { | ... | @@ -2494,7 +2494,7 @@ pub const Value = extern union { |
| 2494 | lhs: Value, | 2494 | lhs: Value, |
| 2495 | rhs: Value, | 2495 | rhs: Value, |
| 2496 | ty: Type, | 2496 | ty: Type, |
| 2497 | arena: *Allocator, | 2497 | arena: Allocator, |
| 2498 | target: Target, | 2498 | target: Target, |
| 2499 | ) !Value { | 2499 | ) !Value { |
| 2500 | // TODO is this a performance issue? maybe we should try the operation without | 2500 | // TODO is this a performance issue? maybe we should try the operation without |
| ... | @@ -2517,7 +2517,7 @@ pub const Value = extern union { | ... | @@ -2517,7 +2517,7 @@ pub const Value = extern union { |
| 2517 | return fromBigInt(arena, result_bigint.toConst()); | 2517 | return fromBigInt(arena, result_bigint.toConst()); |
| 2518 | } | 2518 | } |
| 2519 | 2519 | ||
| 2520 | pub fn shr(lhs: Value, rhs: Value, allocator: *Allocator) !Value { | 2520 | pub fn shr(lhs: Value, rhs: Value, allocator: Allocator) !Value { |
| 2521 | // TODO is this a performance issue? maybe we should try the operation without | 2521 | // TODO is this a performance issue? maybe we should try the operation without |
| 2522 | // resorting to BigInt first. | 2522 | // resorting to BigInt first. |
| 2523 | var lhs_space: Value.BigIntSpace = undefined; | 2523 | var lhs_space: Value.BigIntSpace = undefined; |
| ... | @@ -2540,7 +2540,7 @@ pub const Value = extern union { | ... | @@ -2540,7 +2540,7 @@ pub const Value = extern union { |
| 2540 | lhs: Value, | 2540 | lhs: Value, |
| 2541 | rhs: Value, | 2541 | rhs: Value, |
| 2542 | float_type: Type, | 2542 | float_type: Type, |
| 2543 | arena: *Allocator, | 2543 | arena: Allocator, |
| 2544 | ) !Value { | 2544 | ) !Value { |
| 2545 | switch (float_type.tag()) { | 2545 | switch (float_type.tag()) { |
| 2546 | .f16 => { | 2546 | .f16 => { |
| ... | @@ -2571,7 +2571,7 @@ pub const Value = extern union { | ... | @@ -2571,7 +2571,7 @@ pub const Value = extern union { |
| 2571 | lhs: Value, | 2571 | lhs: Value, |
| 2572 | rhs: Value, | 2572 | rhs: Value, |
| 2573 | float_type: Type, | 2573 | float_type: Type, |
| 2574 | arena: *Allocator, | 2574 | arena: Allocator, |
| 2575 | ) !Value { | 2575 | ) !Value { |
| 2576 | switch (float_type.tag()) { | 2576 | switch (float_type.tag()) { |
| 2577 | .f16 => { | 2577 | .f16 => { |
| ... | @@ -2602,7 +2602,7 @@ pub const Value = extern union { | ... | @@ -2602,7 +2602,7 @@ pub const Value = extern union { |
| 2602 | lhs: Value, | 2602 | lhs: Value, |
| 2603 | rhs: Value, | 2603 | rhs: Value, |
| 2604 | float_type: Type, | 2604 | float_type: Type, |
| 2605 | arena: *Allocator, | 2605 | arena: Allocator, |
| 2606 | ) !Value { | 2606 | ) !Value { |
| 2607 | switch (float_type.tag()) { | 2607 | switch (float_type.tag()) { |
| 2608 | .f16 => { | 2608 | .f16 => { |
| ... | @@ -2633,7 +2633,7 @@ pub const Value = extern union { | ... | @@ -2633,7 +2633,7 @@ pub const Value = extern union { |
| 2633 | lhs: Value, | 2633 | lhs: Value, |
| 2634 | rhs: Value, | 2634 | rhs: Value, |
| 2635 | float_type: Type, | 2635 | float_type: Type, |
| 2636 | arena: *Allocator, | 2636 | arena: Allocator, |
| 2637 | ) !Value { | 2637 | ) !Value { |
| 2638 | switch (float_type.tag()) { | 2638 | switch (float_type.tag()) { |
| 2639 | .f16 => { | 2639 | .f16 => { |
| ... | @@ -2664,7 +2664,7 @@ pub const Value = extern union { | ... | @@ -2664,7 +2664,7 @@ pub const Value = extern union { |
| 2664 | lhs: Value, | 2664 | lhs: Value, |
| 2665 | rhs: Value, | 2665 | rhs: Value, |
| 2666 | float_type: Type, | 2666 | float_type: Type, |
| 2667 | arena: *Allocator, | 2667 | arena: Allocator, |
| 2668 | ) !Value { | 2668 | ) !Value { |
| 2669 | switch (float_type.tag()) { | 2669 | switch (float_type.tag()) { |
| 2670 | .f16 => { | 2670 | .f16 => { |
| ... | @@ -2695,7 +2695,7 @@ pub const Value = extern union { | ... | @@ -2695,7 +2695,7 @@ pub const Value = extern union { |
| 2695 | lhs: Value, | 2695 | lhs: Value, |
| 2696 | rhs: Value, | 2696 | rhs: Value, |
| 2697 | float_type: Type, | 2697 | float_type: Type, |
| 2698 | arena: *Allocator, | 2698 | arena: Allocator, |
| 2699 | ) !Value { | 2699 | ) !Value { |
| 2700 | switch (float_type.tag()) { | 2700 | switch (float_type.tag()) { |
| 2701 | .f16 => { | 2701 | .f16 => { |
src/wasi_libc.zig+4-4| ... | @@ -243,7 +243,7 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile) !void { | ... | @@ -243,7 +243,7 @@ pub fn buildCRTFile(comp: *Compilation, crt_file: CRTFile) !void { |
| 243 | } | 243 | } |
| 244 | } | 244 | } |
| 245 | 245 | ||
| 246 | fn sanitize(arena: *Allocator, file_path: []const u8) ![]const u8 { | 246 | fn sanitize(arena: Allocator, file_path: []const u8) ![]const u8 { |
| 247 | // TODO do this at comptime on the comptime data rather than at runtime | 247 | // TODO do this at comptime on the comptime data rather than at runtime |
| 248 | // probably best to wait until self-hosted is done and our comptime execution | 248 | // probably best to wait until self-hosted is done and our comptime execution |
| 249 | // is faster and uses less memory. | 249 | // is faster and uses less memory. |
| ... | @@ -261,7 +261,7 @@ fn sanitize(arena: *Allocator, file_path: []const u8) ![]const u8 { | ... | @@ -261,7 +261,7 @@ fn sanitize(arena: *Allocator, file_path: []const u8) ![]const u8 { |
| 261 | 261 | ||
| 262 | fn addCCArgs( | 262 | fn addCCArgs( |
| 263 | comp: *Compilation, | 263 | comp: *Compilation, |
| 264 | arena: *Allocator, | 264 | arena: Allocator, |
| 265 | args: *std.ArrayList([]const u8), | 265 | args: *std.ArrayList([]const u8), |
| 266 | want_O3: bool, | 266 | want_O3: bool, |
| 267 | ) error{OutOfMemory}!void { | 267 | ) error{OutOfMemory}!void { |
| ... | @@ -292,7 +292,7 @@ fn addCCArgs( | ... | @@ -292,7 +292,7 @@ fn addCCArgs( |
| 292 | 292 | ||
| 293 | fn addLibcBottomHalfIncludes( | 293 | fn addLibcBottomHalfIncludes( |
| 294 | comp: *Compilation, | 294 | comp: *Compilation, |
| 295 | arena: *Allocator, | 295 | arena: Allocator, |
| 296 | args: *std.ArrayList([]const u8), | 296 | args: *std.ArrayList([]const u8), |
| 297 | ) error{OutOfMemory}!void { | 297 | ) error{OutOfMemory}!void { |
| 298 | try args.appendSlice(&[_][]const u8{ | 298 | try args.appendSlice(&[_][]const u8{ |
| ... | @@ -328,7 +328,7 @@ fn addLibcBottomHalfIncludes( | ... | @@ -328,7 +328,7 @@ fn addLibcBottomHalfIncludes( |
| 328 | 328 | ||
| 329 | fn addLibcTopHalfIncludes( | 329 | fn addLibcTopHalfIncludes( |
| 330 | comp: *Compilation, | 330 | comp: *Compilation, |
| 331 | arena: *Allocator, | 331 | arena: Allocator, |
| 332 | args: *std.ArrayList([]const u8), | 332 | args: *std.ArrayList([]const u8), |
| 333 | ) error{OutOfMemory}!void { | 333 | ) error{OutOfMemory}!void { |
| 334 | try args.appendSlice(&[_][]const u8{ | 334 | try args.appendSlice(&[_][]const u8{ |
test/behavior/async_fn.zig+3-3| ... | @@ -713,7 +713,7 @@ fn testAsyncAwaitTypicalUsage( | ... | @@ -713,7 +713,7 @@ fn testAsyncAwaitTypicalUsage( |
| 713 | } | 713 | } |
| 714 | 714 | ||
| 715 | var global_download_frame: anyframe = undefined; | 715 | var global_download_frame: anyframe = undefined; |
| 716 | fn fetchUrl(allocator: *std.mem.Allocator, url: []const u8) anyerror![]u8 { | 716 | fn fetchUrl(allocator: std.mem.Allocator, url: []const u8) anyerror![]u8 { |
| 717 | _ = url; | 717 | _ = url; |
| 718 | const result = try allocator.dupe(u8, "expected download text"); | 718 | const result = try allocator.dupe(u8, "expected download text"); |
| 719 | errdefer allocator.free(result); | 719 | errdefer allocator.free(result); |
| ... | @@ -727,7 +727,7 @@ fn testAsyncAwaitTypicalUsage( | ... | @@ -727,7 +727,7 @@ fn testAsyncAwaitTypicalUsage( |
| 727 | } | 727 | } |
| 728 | 728 | ||
| 729 | var global_file_frame: anyframe = undefined; | 729 | var global_file_frame: anyframe = undefined; |
| 730 | fn readFile(allocator: *std.mem.Allocator, filename: []const u8) anyerror![]u8 { | 730 | fn readFile(allocator: std.mem.Allocator, filename: []const u8) anyerror![]u8 { |
| 731 | _ = filename; | 731 | _ = filename; |
| 732 | const result = try allocator.dupe(u8, "expected file text"); | 732 | const result = try allocator.dupe(u8, "expected file text"); |
| 733 | errdefer allocator.free(result); | 733 | errdefer allocator.free(result); |
| ... | @@ -912,7 +912,7 @@ test "recursive async function" { | ... | @@ -912,7 +912,7 @@ test "recursive async function" { |
| 912 | 912 | ||
| 913 | fn recursiveAsyncFunctionTest(comptime suspending_implementation: bool) type { | 913 | fn recursiveAsyncFunctionTest(comptime suspending_implementation: bool) type { |
| 914 | return struct { | 914 | return struct { |
| 915 | fn fib(allocator: *std.mem.Allocator, x: u32) error{OutOfMemory}!u32 { | 915 | fn fib(allocator: std.mem.Allocator, x: u32) error{OutOfMemory}!u32 { |
| 916 | if (x <= 1) return x; | 916 | if (x <= 1) return x; |
| 917 | 917 | ||
| 918 | if (suspending_implementation) { | 918 | if (suspending_implementation) { |
test/cli.zig+1-1| ... | @@ -5,7 +5,7 @@ const process = std.process; | ... | @@ -5,7 +5,7 @@ const process = std.process; |
| 5 | const fs = std.fs; | 5 | const fs = std.fs; |
| 6 | const ChildProcess = std.ChildProcess; | 6 | const ChildProcess = std.ChildProcess; |
| 7 | 7 | ||
| 8 | var a: *std.mem.Allocator = undefined; | 8 | var a: std.mem.Allocator = undefined; |
| 9 | 9 | ||
| 10 | pub fn main() !void { | 10 | pub fn main() !void { |
| 11 | var arena = std.heap.ArenaAllocator.init(std.testing.allocator); | 11 | var arena = std.heap.ArenaAllocator.init(std.testing.allocator); |
tools/merge_anal_dumps.zig+2-2| ... | @@ -160,7 +160,7 @@ const Dump = struct { | ... | @@ -160,7 +160,7 @@ const Dump = struct { |
| 160 | const ErrorMap = std.HashMap(Error, usize, Error.hash, Error.eql, 80); | 160 | const ErrorMap = std.HashMap(Error, usize, Error.hash, Error.eql, 80); |
| 161 | const TypeMap = std.HashMap(Type, usize, Type.hash, Type.eql, 80); | 161 | const TypeMap = std.HashMap(Type, usize, Type.hash, Type.eql, 80); |
| 162 | 162 | ||
| 163 | fn init(allocator: *mem.Allocator) Dump { | 163 | fn init(allocator: mem.Allocator) Dump { |
| 164 | return Dump{ | 164 | return Dump{ |
| 165 | .targets = std.ArrayList([]const u8).init(allocator), | 165 | .targets = std.ArrayList([]const u8).init(allocator), |
| 166 | .file_list = std.ArrayList([]const u8).init(allocator), | 166 | .file_list = std.ArrayList([]const u8).init(allocator), |
| ... | @@ -434,7 +434,7 @@ const Dump = struct { | ... | @@ -434,7 +434,7 @@ const Dump = struct { |
| 434 | try jw.endObject(); | 434 | try jw.endObject(); |
| 435 | } | 435 | } |
| 436 | 436 | ||
| 437 | fn a(self: Dump) *mem.Allocator { | 437 | fn a(self: Dump) mem.Allocator { |
| 438 | return self.targets.allocator; | 438 | return self.targets.allocator; |
| 439 | } | 439 | } |
| 440 | 440 |
tools/update_cpu_features.zig+3-3| ... | @@ -1244,7 +1244,7 @@ fn asciiLessThan(context: void, a: []const u8, b: []const u8) bool { | ... | @@ -1244,7 +1244,7 @@ fn asciiLessThan(context: void, a: []const u8, b: []const u8) bool { |
| 1244 | return std.ascii.lessThanIgnoreCase(a, b); | 1244 | return std.ascii.lessThanIgnoreCase(a, b); |
| 1245 | } | 1245 | } |
| 1246 | 1246 | ||
| 1247 | fn llvmNameToZigName(arena: *mem.Allocator, llvm_name: []const u8) ![]const u8 { | 1247 | fn llvmNameToZigName(arena: mem.Allocator, llvm_name: []const u8) ![]const u8 { |
| 1248 | const duped = try arena.dupe(u8, llvm_name); | 1248 | const duped = try arena.dupe(u8, llvm_name); |
| 1249 | for (duped) |*byte| switch (byte.*) { | 1249 | for (duped) |*byte| switch (byte.*) { |
| 1250 | '-', '.' => byte.* = '_', | 1250 | '-', '.' => byte.* = '_', |
| ... | @@ -1254,7 +1254,7 @@ fn llvmNameToZigName(arena: *mem.Allocator, llvm_name: []const u8) ![]const u8 { | ... | @@ -1254,7 +1254,7 @@ fn llvmNameToZigName(arena: *mem.Allocator, llvm_name: []const u8) ![]const u8 { |
| 1254 | } | 1254 | } |
| 1255 | 1255 | ||
| 1256 | fn llvmNameToZigNameOmit( | 1256 | fn llvmNameToZigNameOmit( |
| 1257 | arena: *mem.Allocator, | 1257 | arena: mem.Allocator, |
| 1258 | llvm_target: LlvmTarget, | 1258 | llvm_target: LlvmTarget, |
| 1259 | llvm_name: []const u8, | 1259 | llvm_name: []const u8, |
| 1260 | ) !?[]const u8 { | 1260 | ) !?[]const u8 { |
| ... | @@ -1279,7 +1279,7 @@ fn hasSuperclass(obj: *json.ObjectMap, class_name: []const u8) bool { | ... | @@ -1279,7 +1279,7 @@ fn hasSuperclass(obj: *json.ObjectMap, class_name: []const u8) bool { |
| 1279 | } | 1279 | } |
| 1280 | 1280 | ||
| 1281 | fn pruneFeatures( | 1281 | fn pruneFeatures( |
| 1282 | arena: *mem.Allocator, | 1282 | arena: mem.Allocator, |
| 1283 | features_table: std.StringHashMap(Feature), | 1283 | features_table: std.StringHashMap(Feature), |
| 1284 | deps_set: *std.StringHashMap(void), | 1284 | deps_set: *std.StringHashMap(void), |
| 1285 | ) !void { | 1285 | ) !void { |
tools/update_spirv_features.zig+2-2| ... | @@ -216,7 +216,7 @@ pub fn main() !void { | ... | @@ -216,7 +216,7 @@ pub fn main() !void { |
| 216 | /// The *.grammar.json in SPIRV-Headers should have most of these as well, but with this we're sure to get only the actually | 216 | /// The *.grammar.json in SPIRV-Headers should have most of these as well, but with this we're sure to get only the actually |
| 217 | /// registered ones. | 217 | /// registered ones. |
| 218 | /// TODO: Unfortunately, neither repository contains a machine-readable list of extension dependencies. | 218 | /// TODO: Unfortunately, neither repository contains a machine-readable list of extension dependencies. |
| 219 | fn gather_extensions(allocator: *Allocator, spirv_registry_root: []const u8) ![]const []const u8 { | 219 | fn gather_extensions(allocator: Allocator, spirv_registry_root: []const u8) ![]const []const u8 { |
| 220 | const extensions_path = try fs.path.join(allocator, &.{ spirv_registry_root, "extensions" }); | 220 | const extensions_path = try fs.path.join(allocator, &.{ spirv_registry_root, "extensions" }); |
| 221 | var extensions_dir = try fs.cwd().openDir(extensions_path, .{ .iterate = true }); | 221 | var extensions_dir = try fs.cwd().openDir(extensions_path, .{ .iterate = true }); |
| 222 | defer extensions_dir.close(); | 222 | defer extensions_dir.close(); |
| ... | @@ -286,7 +286,7 @@ fn insertVersion(versions: *std.ArrayList(Version), version: ?[]const u8) !void | ... | @@ -286,7 +286,7 @@ fn insertVersion(versions: *std.ArrayList(Version), version: ?[]const u8) !void |
| 286 | try versions.append(ver); | 286 | try versions.append(ver); |
| 287 | } | 287 | } |
| 288 | 288 | ||
| 289 | fn gatherVersions(allocator: *Allocator, registry: g.CoreRegistry) ![]const Version { | 289 | fn gatherVersions(allocator: Allocator, registry: g.CoreRegistry) ![]const Version { |
| 290 | // Expected number of versions is small | 290 | // Expected number of versions is small |
| 291 | var versions = std.ArrayList(Version).init(allocator); | 291 | var versions = std.ArrayList(Version).init(allocator); |
| 292 | 292 |