diff --git a/lib/std/Build.zig b/lib/std/Build.zig index bc9e1e98a0bc6fbb42a54847f7b4a0ab1558d9cb..8772361c71a7f2c6190ea1c5cd10effd236ccc03 100644 --- a/lib/std/Build.zig +++ b/lib/std/Build.zig @@ -122,22 +122,16 @@ pub const Graph = struct { return @enumFromInt(graph.generated_files.items.len - 1); } - pub fn dupeString(graph: *Graph, bytes: []const u8) [:0]const u8 { - // This code assumes the `Configuration.Wip` uses arena allocation such - // that references to string_bytes never die even when the ArrayList is - // reallocated. - const wc = &graph.wip_configuration; - const i = wc.addString(bytes) catch @panic("OOM"); - return wc.string_bytes.items[@intFromEnum(i)..][0..bytes.len :0]; + pub fn dupeString(graph: *Graph, bytes: []const u8) []const u8 { + return graph.arena.dupe(u8, bytes) catch @panic("OOM"); } - pub fn dupePath(graph: *Graph, bytes: []const u8) [:0]const u8 { - if (builtin.os.tag != .windows) return dupeString(graph, bytes); + pub fn dupePath(graph: *Graph, bytes: []const u8) []const u8 { const arena = graph.arena; + if (builtin.os.tag != .windows) return graph.arena.dupe(u8, bytes) catch @panic("OOM"); const the_copy = arena.dupe(u8, bytes) catch @panic("OOM"); - defer arena.free(the_copy); mem.replaceScalar(u8, the_copy, '/', '\\'); - return dupeString(graph, the_copy); + return the_copy; } pub fn dupeStrings(graph: *Graph, strings: []const []const u8) []const []const u8 { @@ -895,7 +889,7 @@ pub fn addConfigHeader( return config_header_step; } -pub fn dupe(b: *Build, bytes: []const u8) [:0]const u8 { +pub fn dupe(b: *Build, bytes: []const u8) []const u8 { return b.graph.dupeString(bytes); } @@ -905,7 +899,7 @@ pub fn dupeStrings(b: *Build, strings: []const []const u8) []const []const u8 { } /// Duplicates a path, canonicalizing path separators. -pub fn dupePath(b: *Build, bytes: []const u8) [:0]const u8 { +pub fn dupePath(b: *Build, bytes: []const u8) []const u8 { return b.graph.dupePath(bytes); } diff --git a/lib/std/Build/Step/Run.zig b/lib/std/Build/Step/Run.zig index f55074109c946da6f7cbae12417524ce040d9e25..bfb540a0eec2f32cceb9e44c47ac49801e3f81d3 100644 --- a/lib/std/Build/Step/Run.zig +++ b/lib/std/Build/Step/Run.zig @@ -139,7 +139,7 @@ pub const Arg = union(enum) { lazy_path: PrefixedLazyPath, decorated_directory: DecoratedLazyPath, file_content: PrefixedLazyPath, - bytes: [:0]const u8, + bytes: []const u8, output_file: *Output, output_directory: *Output, /// The arguments passed after "--" on the "zig build" CLI.