Commit d8fa8b5455

Andrew Kelley <andrew@ziglang.org>
2020-09-29 21:06:35
use Allocator.allocSentinel now that the stage1 bug is fixed
Thanks @LemonBoy!
1 parent 3efdd7b
Changed files (6)
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,
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);
     }
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);
     }
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);
     }
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);
     }
BRANCH_TODO
@@ -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