From d8fa8b5455058d235793a8b9ecdf252fb8dd8782 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Tue, 29 Sep 2020 12:06:35 -0700 Subject: [PATCH] use Allocator.allocSentinel now that the stage1 bug is fixed Thanks @LemonBoy! --- BRANCH_TODO | 3 --- lib/std/mem/Allocator.zig | 2 -- src/link/Coff.zig | 4 +--- src/link/Elf.zig | 5 +---- src/link/MachO.zig | 5 +---- src/link/Wasm.zig | 5 +---- 6 files changed, 4 insertions(+), 20 deletions(-) delete mode 100644 BRANCH_TODO diff --git a/BRANCH_TODO b/BRANCH_TODO deleted file mode 100644 index c6b3c8d8b..000000000 --- a/BRANCH_TODO +++ /dev/null @@ -1,3 +0,0 @@ - * wasi behavior tests failing - * go ahead and use allocSentinel now that the stage1 bug is fixed - * audit the base cache hash diff --git a/lib/std/mem/Allocator.zig b/lib/std/mem/Allocator.zig index 326a73b91..4511acb27 100644 --- a/lib/std/mem/Allocator.zig +++ b/lib/std/mem/Allocator.zig @@ -231,8 +231,6 @@ fn AllocWithOptionsPayload(comptime Elem: type, comptime alignment: ?u29, compti /// call `free` when done. /// /// For allocating a single item, see `create`. -/// -/// Deprecated; use `allocWithOptions`. pub fn allocSentinel( self: *Allocator, comptime Elem: type, diff --git a/src/link/Coff.zig b/src/link/Coff.zig index 0356a327b..424ece511 100644 --- a/src/link/Coff.zig +++ b/src/link/Coff.zig @@ -1118,9 +1118,7 @@ fn linkWithLLD(self: *Coff, comp: *Compilation) !void { Compilation.dump_argv(argv.items); } - const new_argv_with_sentinel = try arena.alloc(?[*:0]const u8, argv.items.len + 1); - new_argv_with_sentinel[argv.items.len] = null; - const new_argv = new_argv_with_sentinel[0..argv.items.len :null]; + const new_argv = try arena.allocSentinel(?[*:0]const u8, argv.items.len, null); for (argv.items) |arg, i| { new_argv[i] = try arena.dupeZ(u8, arg); } diff --git a/src/link/Elf.zig b/src/link/Elf.zig index dc664b14b..38b9b1acc 100644 --- a/src/link/Elf.zig +++ b/src/link/Elf.zig @@ -1589,10 +1589,7 @@ fn linkWithLLD(self: *Elf, comp: *Compilation) !void { } // Oh, snapplesauce! We need null terminated argv. - // TODO allocSentinel crashed stage1 so this is working around it. - const new_argv_with_sentinel = try arena.alloc(?[*:0]const u8, argv.items.len + 1); - new_argv_with_sentinel[argv.items.len] = null; - const new_argv = new_argv_with_sentinel[0..argv.items.len: null]; + const new_argv = try arena.allocSentinel(?[*:0]const u8, argv.items.len, null); for (argv.items) |arg, i| { new_argv[i] = try arena.dupeZ(u8, arg); } diff --git a/src/link/MachO.zig b/src/link/MachO.zig index 146f2616c..2570a92da 100644 --- a/src/link/MachO.zig +++ b/src/link/MachO.zig @@ -567,10 +567,7 @@ fn linkWithLLD(self: *MachO, comp: *Compilation) !void { Compilation.dump_argv(argv.items); } - // TODO allocSentinel crashed stage1 so this is working around it. - const new_argv_with_sentinel = try arena.alloc(?[*:0]const u8, argv.items.len + 1); - new_argv_with_sentinel[argv.items.len] = null; - const new_argv = new_argv_with_sentinel[0..argv.items.len :null]; + const new_argv = try arena.allocSentinel(?[*:0]const u8, argv.items.len, null); for (argv.items) |arg, i| { new_argv[i] = try arena.dupeZ(u8, arg); } diff --git a/src/link/Wasm.zig b/src/link/Wasm.zig index 509544c94..3f879a3b3 100644 --- a/src/link/Wasm.zig +++ b/src/link/Wasm.zig @@ -385,10 +385,7 @@ fn linkWithLLD(self: *Wasm, comp: *Compilation) !void { Compilation.dump_argv(argv.items); } - // TODO allocSentinel crashed stage1 so this is working around it. - const new_argv_with_sentinel = try arena.alloc(?[*:0]const u8, argv.items.len + 1); - new_argv_with_sentinel[argv.items.len] = null; - const new_argv = new_argv_with_sentinel[0..argv.items.len :null]; + const new_argv = try arena.allocSentinel(?[*:0]const u8, argv.items.len, null); for (argv.items) |arg, i| { new_argv[i] = try arena.dupeZ(u8, arg); }