authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-03-30 14:23:22-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-03-30 14:23:22-04:00
log9e7ae062492d4b41564832d37408336e36165e67
treeb6b898deb26a63f264ee43e00ecfe883a1e8db99
parentb980568c810fda4c014da42be8e5108b4cbadb7c
signaturelock-open Commit is signed but in an unrecognized format.

std lib API deprecations for the upcoming 0.6.0 release

See #3811

70 files changed, 597 insertions(+), 564 deletions(-)

doc/docgen.zig+44-25
......@@ -1048,7 +1048,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
10481048 allocator,
10491049 &[_][]const u8{ tmp_dir_name, name_plus_ext },
10501050 );
1051 try io.writeFile(tmp_source_file_name, trimmed_raw_source);
1051 try fs.cwd().writeFile(tmp_source_file_name, trimmed_raw_source);
10521052
10531053 switch (code.id) {
10541054 Code.Id.Exe => |expected_outcome| code_block: {
......@@ -1106,18 +1106,17 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
11061106 }
11071107 }
11081108 if (expected_outcome == .BuildFail) {
1109 const result = try ChildProcess.exec(
1110 allocator,
1111 build_args.toSliceConst(),
1112 null,
1113 &env_map,
1114 max_doc_file_size,
1115 );
1109 const result = try ChildProcess.exec(.{
1110 .allocator = allocator,
1111 .argv = build_args.span(),
1112 .env_map = &env_map,
1113 .max_output_bytes = max_doc_file_size,
1114 });
11161115 switch (result.term) {
11171116 .Exited => |exit_code| {
11181117 if (exit_code == 0) {
11191118 warn("{}\nThe following command incorrectly succeeded:\n", .{result.stderr});
1120 for (build_args.toSliceConst()) |arg|
1119 for (build_args.span()) |arg|
11211120 warn("{} ", .{arg})
11221121 else
11231122 warn("\n", .{});
......@@ -1126,7 +1125,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
11261125 },
11271126 else => {
11281127 warn("{}\nThe following command crashed:\n", .{result.stderr});
1129 for (build_args.toSliceConst()) |arg|
1128 for (build_args.span()) |arg|
11301129 warn("{} ", .{arg})
11311130 else
11321131 warn("\n", .{});
......@@ -1138,7 +1137,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
11381137 try out.print("\n{}</code></pre>\n", .{colored_stderr});
11391138 break :code_block;
11401139 }
1141 const exec_result = exec(allocator, &env_map, build_args.toSliceConst()) catch
1140 const exec_result = exec(allocator, &env_map, build_args.span()) catch
11421141 return parseError(tokenizer, code.source_token, "example failed to compile", .{});
11431142
11441143 if (code.target_str) |triple| {
......@@ -1167,7 +1166,12 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
11671166 var exited_with_signal = false;
11681167
11691168 const result = if (expected_outcome == ExpectedOutcome.Fail) blk: {
1170 const result = try ChildProcess.exec(allocator, run_args, null, &env_map, max_doc_file_size);
1169 const result = try ChildProcess.exec(.{
1170 .allocator = allocator,
1171 .argv = run_args,
1172 .env_map = &env_map,
1173 .max_output_bytes = max_doc_file_size,
1174 });
11711175 switch (result.term) {
11721176 .Exited => |exit_code| {
11731177 if (exit_code == 0) {
......@@ -1234,7 +1238,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
12341238 try test_args.appendSlice(&[_][]const u8{ "-target", triple });
12351239 try out.print(" -target {}", .{triple});
12361240 }
1237 const result = exec(allocator, &env_map, test_args.toSliceConst()) catch return parseError(tokenizer, code.source_token, "test failed", .{});
1241 const result = exec(allocator, &env_map, test_args.span()) catch return parseError(tokenizer, code.source_token, "test failed", .{});
12381242 const escaped_stderr = try escapeHtml(allocator, result.stderr);
12391243 const escaped_stdout = try escapeHtml(allocator, result.stdout);
12401244 try out.print("\n{}{}</code></pre>\n", .{ escaped_stderr, escaped_stdout });
......@@ -1268,12 +1272,17 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
12681272 try out.print(" --release-small", .{});
12691273 },
12701274 }
1271 const result = try ChildProcess.exec(allocator, test_args.toSliceConst(), null, &env_map, max_doc_file_size);
1275 const result = try ChildProcess.exec(.{
1276 .allocator = allocator,
1277 .argv = test_args.span(),
1278 .env_map = &env_map,
1279 .max_output_bytes = max_doc_file_size,
1280 });
12721281 switch (result.term) {
12731282 .Exited => |exit_code| {
12741283 if (exit_code == 0) {
12751284 warn("{}\nThe following command incorrectly succeeded:\n", .{result.stderr});
1276 for (test_args.toSliceConst()) |arg|
1285 for (test_args.span()) |arg|
12771286 warn("{} ", .{arg})
12781287 else
12791288 warn("\n", .{});
......@@ -1282,7 +1291,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
12821291 },
12831292 else => {
12841293 warn("{}\nThe following command crashed:\n", .{result.stderr});
1285 for (test_args.toSliceConst()) |arg|
1294 for (test_args.span()) |arg|
12861295 warn("{} ", .{arg})
12871296 else
12881297 warn("\n", .{});
......@@ -1326,12 +1335,17 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
13261335 },
13271336 }
13281337
1329 const result = try ChildProcess.exec(allocator, test_args.toSliceConst(), null, &env_map, max_doc_file_size);
1338 const result = try ChildProcess.exec(.{
1339 .allocator = allocator,
1340 .argv = test_args.span(),
1341 .env_map = &env_map,
1342 .max_output_bytes = max_doc_file_size,
1343 });
13301344 switch (result.term) {
13311345 .Exited => |exit_code| {
13321346 if (exit_code == 0) {
13331347 warn("{}\nThe following command incorrectly succeeded:\n", .{result.stderr});
1334 for (test_args.toSliceConst()) |arg|
1348 for (test_args.span()) |arg|
13351349 warn("{} ", .{arg})
13361350 else
13371351 warn("\n", .{});
......@@ -1340,7 +1354,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
13401354 },
13411355 else => {
13421356 warn("{}\nThe following command crashed:\n", .{result.stderr});
1343 for (test_args.toSliceConst()) |arg|
1357 for (test_args.span()) |arg|
13441358 warn("{} ", .{arg})
13451359 else
13461360 warn("\n", .{});
......@@ -1418,12 +1432,17 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
14181432 }
14191433
14201434 if (maybe_error_match) |error_match| {
1421 const result = try ChildProcess.exec(allocator, build_args.toSliceConst(), null, &env_map, max_doc_file_size);
1435 const result = try ChildProcess.exec(.{
1436 .allocator = allocator,
1437 .argv = build_args.span(),
1438 .env_map = &env_map,
1439 .max_output_bytes = max_doc_file_size,
1440 });
14221441 switch (result.term) {
14231442 .Exited => |exit_code| {
14241443 if (exit_code == 0) {
14251444 warn("{}\nThe following command incorrectly succeeded:\n", .{result.stderr});
1426 for (build_args.toSliceConst()) |arg|
1445 for (build_args.span()) |arg|
14271446 warn("{} ", .{arg})
14281447 else
14291448 warn("\n", .{});
......@@ -1432,7 +1451,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
14321451 },
14331452 else => {
14341453 warn("{}\nThe following command crashed:\n", .{result.stderr});
1435 for (build_args.toSliceConst()) |arg|
1454 for (build_args.span()) |arg|
14361455 warn("{} ", .{arg})
14371456 else
14381457 warn("\n", .{});
......@@ -1447,7 +1466,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
14471466 const colored_stderr = try termColor(allocator, escaped_stderr);
14481467 try out.print("\n{}", .{colored_stderr});
14491468 } else {
1450 _ = exec(allocator, &env_map, build_args.toSliceConst()) catch return parseError(tokenizer, code.source_token, "example failed to compile", .{});
1469 _ = exec(allocator, &env_map, build_args.span()) catch return parseError(tokenizer, code.source_token, "example failed to compile", .{});
14511470 }
14521471 if (!code.is_inline) {
14531472 try out.print("</code></pre>\n", .{});
......@@ -1484,7 +1503,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
14841503 try test_args.appendSlice(&[_][]const u8{ "-target", triple });
14851504 try out.print(" -target {}", .{triple});
14861505 }
1487 const result = exec(allocator, &env_map, test_args.toSliceConst()) catch return parseError(tokenizer, code.source_token, "test failed", .{});
1506 const result = exec(allocator, &env_map, test_args.span()) catch return parseError(tokenizer, code.source_token, "test failed", .{});
14881507 const escaped_stderr = try escapeHtml(allocator, result.stderr);
14891508 const escaped_stdout = try escapeHtml(allocator, result.stdout);
14901509 try out.print("\n{}{}</code></pre>\n", .{ escaped_stderr, escaped_stdout });
......@@ -1497,7 +1516,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
14971516}
14981517
14991518fn exec(allocator: *mem.Allocator, env_map: *std.BufMap, args: []const []const u8) !ChildProcess.ExecResult {
1500 const result = try ChildProcess.exec2(.{
1519 const result = try ChildProcess.exec(.{
15011520 .allocator = allocator,
15021521 .argv = args,
15031522 .env_map = env_map,
doc/langref.html.in+2-2
......@@ -4953,7 +4953,7 @@ const mem = std.mem;
49534953test "cast *[1][*]const u8 to [*]const ?[*]const u8" {
49544954 const window_name = [1][*]const u8{"window name"};
49554955 const x: [*]const ?[*]const u8 = &window_name;
4956 assert(mem.eql(u8, std.mem.toSliceConst(u8, @ptrCast([*:0]const u8, x[0].?)), "window name"));
4956 assert(mem.eql(u8, std.mem.spanZ(@ptrCast([*:0]const u8, x[0].?)), "window name"));
49574957}
49584958 {#code_end#}
49594959 {#header_close#}
......@@ -9310,7 +9310,7 @@ test "string literal to constant slice" {
93109310 </p>
93119311 <p>
93129312 Sometimes the lifetime of a pointer may be more complicated. For example, when using
9313 {#syntax#}std.ArrayList(T).toSlice(){#endsyntax#}, the returned slice has a lifetime that remains
9313 {#syntax#}std.ArrayList(T).span(){#endsyntax#}, the returned slice has a lifetime that remains
93149314 valid until the next time the list is resized, such as by appending new elements.
93159315 </p>
93169316 <p>
lib/std/atomic/queue.zig+1-1
......@@ -227,7 +227,7 @@ fn startPuts(ctx: *Context) u8 {
227227 var r = std.rand.DefaultPrng.init(0xdeadbeef);
228228 while (put_count != 0) : (put_count -= 1) {
229229 std.time.sleep(1); // let the os scheduler be our fuzz
230 const x = @bitCast(i32, r.random.scalar(u32));
230 const x = @bitCast(i32, r.random.int(u32));
231231 const node = ctx.allocator.create(Queue(i32).Node) catch unreachable;
232232 node.* = .{
233233 .prev = undefined,
lib/std/atomic/stack.zig+1-1
......@@ -150,7 +150,7 @@ fn startPuts(ctx: *Context) u8 {
150150 var r = std.rand.DefaultPrng.init(0xdeadbeef);
151151 while (put_count != 0) : (put_count -= 1) {
152152 std.time.sleep(1); // let the os scheduler be our fuzz
153 const x = @bitCast(i32, r.random.scalar(u32));
153 const x = @bitCast(i32, r.random.int(u32));
154154 const node = ctx.allocator.create(Stack(i32).Node) catch unreachable;
155155 node.* = Stack(i32).Node{
156156 .next = undefined,
lib/std/buffer.zig+13-20
......@@ -43,7 +43,7 @@ pub const Buffer = struct {
4343
4444 /// Must deinitialize with deinit.
4545 pub fn initFromBuffer(buffer: Buffer) !Buffer {
46 return Buffer.init(buffer.list.allocator, buffer.toSliceConst());
46 return Buffer.init(buffer.list.allocator, buffer.span());
4747 }
4848
4949 /// Buffer takes ownership of the passed in slice. The slice must have been
......@@ -81,15 +81,8 @@ pub const Buffer = struct {
8181 return self.list.span()[0..self.len() :0];
8282 }
8383
84 /// Deprecated: use `span`
85 pub fn toSlice(self: Buffer) [:0]u8 {
86 return self.span();
87 }
88
89 /// Deprecated: use `span`
90 pub fn toSliceConst(self: Buffer) [:0]const u8 {
91 return self.span();
92 }
84 pub const toSlice = @compileError("deprecated; use span()");
85 pub const toSliceConst = @compileError("deprecated; use span()");
9386
9487 pub fn shrink(self: *Buffer, new_len: usize) void {
9588 assert(new_len <= self.len());
......@@ -120,17 +113,17 @@ pub const Buffer = struct {
120113 pub fn append(self: *Buffer, m: []const u8) !void {
121114 const old_len = self.len();
122115 try self.resize(old_len + m.len);
123 mem.copy(u8, self.list.toSlice()[old_len..], m);
116 mem.copy(u8, self.list.span()[old_len..], m);
124117 }
125118
126119 pub fn appendByte(self: *Buffer, byte: u8) !void {
127120 const old_len = self.len();
128121 try self.resize(old_len + 1);
129 self.list.toSlice()[old_len] = byte;
122 self.list.span()[old_len] = byte;
130123 }
131124
132125 pub fn eql(self: Buffer, m: []const u8) bool {
133 return mem.eql(u8, self.toSliceConst(), m);
126 return mem.eql(u8, self.span(), m);
134127 }
135128
136129 pub fn startsWith(self: Buffer, m: []const u8) bool {
......@@ -147,7 +140,7 @@ pub const Buffer = struct {
147140
148141 pub fn replaceContents(self: *Buffer, m: []const u8) !void {
149142 try self.resize(m.len);
150 mem.copy(u8, self.list.toSlice(), m);
143 mem.copy(u8, self.list.span(), m);
151144 }
152145
153146 pub fn outStream(self: *Buffer) std.io.OutStream(*Buffer, error{OutOfMemory}, appendWrite) {
......@@ -171,17 +164,17 @@ test "simple Buffer" {
171164 try buf.append(" ");
172165 try buf.append("world");
173166 testing.expect(buf.eql("hello world"));
174 testing.expect(mem.eql(u8, mem.toSliceConst(u8, buf.toSliceConst().ptr), buf.toSliceConst()));
167 testing.expect(mem.eql(u8, mem.spanZ(buf.span().ptr), buf.span()));
175168
176169 var buf2 = try Buffer.initFromBuffer(buf);
177170 defer buf2.deinit();
178 testing.expect(buf.eql(buf2.toSliceConst()));
171 testing.expect(buf.eql(buf2.span()));
179172
180173 testing.expect(buf.startsWith("hell"));
181174 testing.expect(buf.endsWith("orld"));
182175
183176 try buf2.resize(4);
184 testing.expect(buf.startsWith(buf2.toSlice()));
177 testing.expect(buf.startsWith(buf2.span()));
185178}
186179
187180test "Buffer.initSize" {
......@@ -189,7 +182,7 @@ test "Buffer.initSize" {
189182 defer buf.deinit();
190183 testing.expect(buf.len() == 3);
191184 try buf.append("hello");
192 testing.expect(mem.eql(u8, buf.toSliceConst()[3..], "hello"));
185 testing.expect(mem.eql(u8, buf.span()[3..], "hello"));
193186}
194187
195188test "Buffer.initCapacity" {
......@@ -201,7 +194,7 @@ test "Buffer.initCapacity" {
201194 try buf.append("hello");
202195 testing.expect(buf.len() == 5);
203196 testing.expect(buf.capacity() == old_cap);
204 testing.expect(mem.eql(u8, buf.toSliceConst(), "hello"));
197 testing.expect(mem.eql(u8, buf.span(), "hello"));
205198}
206199
207200test "Buffer.print" {
......@@ -221,5 +214,5 @@ test "Buffer.outStream" {
221214 const y: i32 = 1234;
222215 try buf_stream.print("x: {}\ny: {}\n", .{ x, y });
223216
224 testing.expect(mem.eql(u8, buffer.toSlice(), "x: 42\ny: 1234\n"));
217 testing.expect(mem.eql(u8, buffer.span(), "x: 42\ny: 1234\n"));
225218}
lib/std/build.zig+20-23
......@@ -355,7 +355,7 @@ pub const Builder = struct {
355355 }
356356 }
357357
358 for (wanted_steps.toSliceConst()) |s| {
358 for (wanted_steps.span()) |s| {
359359 try self.makeOneStep(s);
360360 }
361361 }
......@@ -372,7 +372,7 @@ pub const Builder = struct {
372372 const uninstall_tls = @fieldParentPtr(TopLevelStep, "step", uninstall_step);
373373 const self = @fieldParentPtr(Builder, "uninstall_tls", uninstall_tls);
374374
375 for (self.installed_files.toSliceConst()) |installed_file| {
375 for (self.installed_files.span()) |installed_file| {
376376 const full_path = self.getInstallPath(installed_file.dir, installed_file.path);
377377 if (self.verbose) {
378378 warn("rm {}\n", .{full_path});
......@@ -390,7 +390,7 @@ pub const Builder = struct {
390390 }
391391 s.loop_flag = true;
392392
393 for (s.dependencies.toSlice()) |dep| {
393 for (s.dependencies.span()) |dep| {
394394 self.makeOneStep(dep) catch |err| {
395395 if (err == error.DependencyLoopDetected) {
396396 warn(" {}\n", .{s.name});
......@@ -405,7 +405,7 @@ pub const Builder = struct {
405405 }
406406
407407 fn getTopLevelStepByName(self: *Builder, name: []const u8) !*Step {
408 for (self.top_level_steps.toSliceConst()) |top_level_step| {
408 for (self.top_level_steps.span()) |top_level_step| {
409409 if (mem.eql(u8, top_level_step.step.name, name)) {
410410 return &top_level_step.step;
411411 }
......@@ -470,7 +470,7 @@ pub const Builder = struct {
470470 return null;
471471 },
472472 UserValue.Scalar => |s| return &[_][]const u8{s},
473 UserValue.List => |lst| return lst.toSliceConst(),
473 UserValue.List => |lst| return lst.span(),
474474 },
475475 }
476476 }
......@@ -866,7 +866,7 @@ pub const Builder = struct {
866866 pub fn findProgram(self: *Builder, names: []const []const u8, paths: []const []const u8) ![]const u8 {
867867 // TODO report error for ambiguous situations
868868 const exe_extension = @as(CrossTarget, .{}).exeFileExt();
869 for (self.search_prefixes.toSliceConst()) |search_prefix| {
869 for (self.search_prefixes.span()) |search_prefix| {
870870 for (names) |name| {
871871 if (fs.path.isAbsolute(name)) {
872872 return name;
......@@ -1010,7 +1010,7 @@ pub const Builder = struct {
10101010 .desc = tok_it.rest(),
10111011 });
10121012 }
1013 return list.toSliceConst();
1013 return list.span();
10141014 }
10151015
10161016 fn getPkgConfigList(self: *Builder) ![]const PkgConfigPkg {
......@@ -1395,7 +1395,7 @@ pub const LibExeObjStep = struct {
13951395 if (isLibCLibrary(name)) {
13961396 return self.is_linking_libc;
13971397 }
1398 for (self.link_objects.toSliceConst()) |link_object| {
1398 for (self.link_objects.span()) |link_object| {
13991399 switch (link_object) {
14001400 LinkObject.SystemLib => |n| if (mem.eql(u8, n, name)) return true,
14011401 else => continue,
......@@ -1599,10 +1599,7 @@ pub const LibExeObjStep = struct {
15991599 self.main_pkg_path = dir_path;
16001600 }
16011601
1602 /// Deprecated; just set the field directly.
1603 pub fn setDisableGenH(self: *LibExeObjStep, is_disabled: bool) void {
1604 self.emit_h = !is_disabled;
1605 }
1602 pub const setDisableGenH = @compileError("deprecated; set the emit_h field directly");
16061603
16071604 pub fn setLibCFile(self: *LibExeObjStep, libc_file: ?[]const u8) void {
16081605 self.libc_file = libc_file;
......@@ -1762,7 +1759,7 @@ pub const LibExeObjStep = struct {
17621759 self.include_dirs.append(IncludeDir{ .OtherStep = other }) catch unreachable;
17631760
17641761 // Inherit dependency on system libraries
1765 for (other.link_objects.toSliceConst()) |link_object| {
1762 for (other.link_objects.span()) |link_object| {
17661763 switch (link_object) {
17671764 .SystemLib => |name| self.linkSystemLibrary(name),
17681765 else => continue,
......@@ -1802,7 +1799,7 @@ pub const LibExeObjStep = struct {
18021799
18031800 if (self.root_src) |root_src| try zig_args.append(root_src.getPath(builder));
18041801
1805 for (self.link_objects.toSlice()) |link_object| {
1802 for (self.link_objects.span()) |link_object| {
18061803 switch (link_object) {
18071804 .StaticPath => |static_path| {
18081805 try zig_args.append("--object");
......@@ -1855,7 +1852,7 @@ pub const LibExeObjStep = struct {
18551852 builder.allocator,
18561853 &[_][]const u8{ builder.cache_root, builder.fmt("{}_build_options.zig", .{self.name}) },
18571854 );
1858 try std.io.writeFile(build_options_file, self.build_options_contents.toSliceConst());
1855 try fs.cwd().writeFile(build_options_file, self.build_options_contents.span());
18591856 try zig_args.append("--pkg-begin");
18601857 try zig_args.append("build_options");
18611858 try zig_args.append(builder.pathFromRoot(build_options_file));
......@@ -1978,7 +1975,7 @@ pub const LibExeObjStep = struct {
19781975 try mcpu_buffer.append(feature.name);
19791976 }
19801977 }
1981 try zig_args.append(mcpu_buffer.toSliceConst());
1978 try zig_args.append(mcpu_buffer.span());
19821979 }
19831980
19841981 if (self.target.dynamic_linker.get()) |dynamic_linker| {
......@@ -2040,7 +2037,7 @@ pub const LibExeObjStep = struct {
20402037 try zig_args.append("--test-cmd-bin");
20412038 },
20422039 }
2043 for (self.packages.toSliceConst()) |pkg| {
2040 for (self.packages.span()) |pkg| {
20442041 try zig_args.append("--pkg-begin");
20452042 try zig_args.append(pkg.name);
20462043 try zig_args.append(builder.pathFromRoot(pkg.path));
......@@ -2057,7 +2054,7 @@ pub const LibExeObjStep = struct {
20572054 try zig_args.append("--pkg-end");
20582055 }
20592056
2060 for (self.include_dirs.toSliceConst()) |include_dir| {
2057 for (self.include_dirs.span()) |include_dir| {
20612058 switch (include_dir) {
20622059 .RawPath => |include_path| {
20632060 try zig_args.append("-I");
......@@ -2075,18 +2072,18 @@ pub const LibExeObjStep = struct {
20752072 }
20762073 }
20772074
2078 for (self.lib_paths.toSliceConst()) |lib_path| {
2075 for (self.lib_paths.span()) |lib_path| {
20792076 try zig_args.append("-L");
20802077 try zig_args.append(lib_path);
20812078 }
20822079
2083 for (self.c_macros.toSliceConst()) |c_macro| {
2080 for (self.c_macros.span()) |c_macro| {
20842081 try zig_args.append("-D");
20852082 try zig_args.append(c_macro);
20862083 }
20872084
20882085 if (self.target.isDarwin()) {
2089 for (self.framework_dirs.toSliceConst()) |dir| {
2086 for (self.framework_dirs.span()) |dir| {
20902087 try zig_args.append("-F");
20912088 try zig_args.append(dir);
20922089 }
......@@ -2146,12 +2143,12 @@ pub const LibExeObjStep = struct {
21462143 }
21472144
21482145 if (self.kind == Kind.Test) {
2149 try builder.spawnChild(zig_args.toSliceConst());
2146 try builder.spawnChild(zig_args.span());
21502147 } else {
21512148 try zig_args.append("--cache");
21522149 try zig_args.append("on");
21532150
2154 const output_dir_nl = try builder.execFromStep(zig_args.toSliceConst(), &self.step);
2151 const output_dir_nl = try builder.execFromStep(zig_args.span(), &self.step);
21552152 const build_output_dir = mem.trimRight(u8, output_dir_nl, "\r\n");
21562153
21572154 if (self.output_dir) |output_dir| {
lib/std/build/emit_raw.zig+6-6
......@@ -72,7 +72,7 @@ const BinaryElfOutput = struct {
7272 newSegment.binaryOffset = 0;
7373 newSegment.firstSection = null;
7474
75 for (self.sections.toSlice()) |section| {
75 for (self.sections.span()) |section| {
7676 if (sectionWithinSegment(section, phdr)) {
7777 if (section.segment) |sectionSegment| {
7878 if (sectionSegment.elfOffset > newSegment.elfOffset) {
......@@ -92,7 +92,7 @@ const BinaryElfOutput = struct {
9292 }
9393 }
9494
95 sort.sort(*BinaryElfSegment, self.segments.toSlice(), segmentSortCompare);
95 sort.sort(*BinaryElfSegment, self.segments.span(), segmentSortCompare);
9696
9797 if (self.segments.len > 0) {
9898 const firstSegment = self.segments.at(0);
......@@ -105,19 +105,19 @@ const BinaryElfOutput = struct {
105105
106106 const basePhysicalAddress = firstSegment.physicalAddress;
107107
108 for (self.segments.toSlice()) |segment| {
108 for (self.segments.span()) |segment| {
109109 segment.binaryOffset = segment.physicalAddress - basePhysicalAddress;
110110 }
111111 }
112112 }
113113
114 for (self.sections.toSlice()) |section| {
114 for (self.sections.span()) |section| {
115115 if (section.segment) |segment| {
116116 section.binaryOffset = segment.binaryOffset + (section.elfOffset - segment.elfOffset);
117117 }
118118 }
119119
120 sort.sort(*BinaryElfSection, self.sections.toSlice(), sectionSortCompare);
120 sort.sort(*BinaryElfSection, self.sections.span(), sectionSortCompare);
121121
122122 return self;
123123 }
......@@ -165,7 +165,7 @@ fn emitRaw(allocator: *Allocator, elf_path: []const u8, raw_path: []const u8) !v
165165 var binary_elf_output = try BinaryElfOutput.parse(allocator, elf_file);
166166 defer binary_elf_output.deinit();
167167
168 for (binary_elf_output.sections.toSlice()) |section| {
168 for (binary_elf_output.sections.span()) |section| {
169169 try writeBinaryElfSection(elf_file, out_file, section);
170170 }
171171}
lib/std/build/run.zig+3-3
......@@ -139,7 +139,7 @@ pub const RunStep = struct {
139139 const cwd = if (self.cwd) |cwd| self.builder.pathFromRoot(cwd) else self.builder.build_root;
140140
141141 var argv_list = ArrayList([]const u8).init(self.builder.allocator);
142 for (self.argv.toSlice()) |arg| {
142 for (self.argv.span()) |arg| {
143143 switch (arg) {
144144 Arg.Bytes => |bytes| try argv_list.append(bytes),
145145 Arg.Artifact => |artifact| {
......@@ -153,7 +153,7 @@ pub const RunStep = struct {
153153 }
154154 }
155155
156 const argv = argv_list.toSliceConst();
156 const argv = argv_list.span();
157157
158158 const child = std.ChildProcess.init(argv, self.builder.allocator) catch unreachable;
159159 defer child.deinit();
......@@ -289,7 +289,7 @@ pub const RunStep = struct {
289289 }
290290
291291 fn addPathForDynLibs(self: *RunStep, artifact: *LibExeObjStep) void {
292 for (artifact.link_objects.toSliceConst()) |link_object| {
292 for (artifact.link_objects.span()) |link_object| {
293293 switch (link_object) {
294294 .OtherStep => |other| {
295295 if (other.target.isWindows() and other.isDynamicLibrary()) {
lib/std/build/translate_c.zig+1-1
......@@ -71,7 +71,7 @@ pub const TranslateCStep = struct {
7171
7272 try argv_list.append(self.source.getPath(self.builder));
7373
74 const output_path_nl = try self.builder.execFromStep(argv_list.toSliceConst(), &self.step);
74 const output_path_nl = try self.builder.execFromStep(argv_list.span(), &self.step);
7575 const output_path = mem.trimRight(u8, output_path_nl, "\r\n");
7676
7777 self.out_basename = fs.path.basename(output_path);
lib/std/build/write_file.zig+2-2
......@@ -59,7 +59,7 @@ pub const WriteFileStep = struct {
5959 // new random bytes when WriteFileStep implementation is modified
6060 // in a non-backwards-compatible way.
6161 hash.update("eagVR1dYXoE7ARDP");
62 for (self.files.toSliceConst()) |file| {
62 for (self.files.span()) |file| {
6363 hash.update(file.basename);
6464 hash.update(file.bytes);
6565 hash.update("|");
......@@ -80,7 +80,7 @@ pub const WriteFileStep = struct {
8080 };
8181 var dir = try fs.cwd().openDir(self.output_dir, .{});
8282 defer dir.close();
83 for (self.files.toSliceConst()) |file| {
83 for (self.files.span()) |file| {
8484 dir.writeFile(file.basename, file.bytes) catch |err| {
8585 warn("unable to write {} into {}: {}\n", .{
8686 file.basename,
lib/std/c.zig-1
......@@ -174,7 +174,6 @@ pub extern "c" fn realloc(?*c_void, usize) ?*c_void;
174174pub extern "c" fn free(*c_void) void;
175175pub extern "c" fn posix_memalign(memptr: **c_void, alignment: usize, size: usize) c_int;
176176
177// Deprecated
178177pub extern "c" fn futimes(fd: fd_t, times: *[2]timeval) c_int;
179178pub extern "c" fn utimes(path: [*:0]const u8, times: *[2]timeval) c_int;
180179
lib/std/child_process.zig+3-21
......@@ -175,29 +175,11 @@ pub const ChildProcess = struct {
175175 stderr: []u8,
176176 };
177177
178 /// Spawns a child process, waits for it, collecting stdout and stderr, and then returns.
179 /// If it succeeds, the caller owns result.stdout and result.stderr memory.
180 /// TODO deprecate in favor of exec2
181 pub fn exec(
182 allocator: *mem.Allocator,
183 argv: []const []const u8,
184 cwd: ?[]const u8,
185 env_map: ?*const BufMap,
186 max_output_bytes: usize,
187 ) !ExecResult {
188 return exec2(.{
189 .allocator = allocator,
190 .argv = argv,
191 .cwd = cwd,
192 .env_map = env_map,
193 .max_output_bytes = max_output_bytes,
194 });
195 }
178 pub const exec2 = @compileError("deprecated: exec2 is renamed to exec");
196179
197180 /// Spawns a child process, waits for it, collecting stdout and stderr, and then returns.
198181 /// If it succeeds, the caller owns result.stdout and result.stderr memory.
199 /// TODO rename to exec
200 pub fn exec2(args: struct {
182 pub fn exec(args: struct {
201183 allocator: *mem.Allocator,
202184 argv: []const []const u8,
203185 cwd: ?[]const u8 = null,
......@@ -370,7 +352,7 @@ pub const ChildProcess = struct {
370352
371353 const any_ignore = (self.stdin_behavior == StdIo.Ignore or self.stdout_behavior == StdIo.Ignore or self.stderr_behavior == StdIo.Ignore);
372354 const dev_null_fd = if (any_ignore)
373 os.openC("/dev/null", os.O_RDWR, 0) catch |err| switch (err) {
355 os.openZ("/dev/null", os.O_RDWR, 0) catch |err| switch (err) {
374356 error.PathAlreadyExists => unreachable,
375357 error.NoSpaceLeft => unreachable,
376358 error.FileTooBig => unreachable,
lib/std/coff.zig+2-2
......@@ -145,7 +145,7 @@ pub const Coff = struct {
145145 blk: while (i < debug_dir_entry_count) : (i += 1) {
146146 const debug_dir_entry = try in.readStruct(DebugDirectoryEntry);
147147 if (debug_dir_entry.type == IMAGE_DEBUG_TYPE_CODEVIEW) {
148 for (self.sections.toSlice()) |*section| {
148 for (self.sections.span()) |*section| {
149149 const section_start = section.header.virtual_address;
150150 const section_size = section.header.misc.virtual_size;
151151 const rva = debug_dir_entry.address_of_raw_data;
......@@ -211,7 +211,7 @@ pub const Coff = struct {
211211 }
212212
213213 pub fn getSection(self: *Coff, comptime name: []const u8) ?*Section {
214 for (self.sections.toSlice()) |*sec| {
214 for (self.sections.span()) |*sec| {
215215 if (mem.eql(u8, sec.header.name[0..name.len], name)) {
216216 return sec;
217217 }
lib/std/crypto/gimli.zig+2
......@@ -23,10 +23,12 @@ pub const State = struct {
2323
2424 const Self = @This();
2525
26 /// TODO follow the span() convention instead of having this and `toSliceConst`
2627 pub fn toSlice(self: *Self) []u8 {
2728 return mem.sliceAsBytes(self.data[0..]);
2829 }
2930
31 /// TODO follow the span() convention instead of having this and `toSlice`
3032 pub fn toSliceConst(self: *Self) []const u8 {
3133 return mem.sliceAsBytes(self.data[0..]);
3234 }
lib/std/debug.zig+6-9
......@@ -735,7 +735,7 @@ fn openCoffDebugInfo(allocator: *mem.Allocator, coff_file_path: [:0]const u16) !
735735 for (present) |_| {
736736 const name_offset = try pdb_stream.inStream().readIntLittle(u32);
737737 const name_index = try pdb_stream.inStream().readIntLittle(u32);
738 const name = mem.toSlice(u8, @ptrCast([*:0]u8, name_bytes.ptr + name_offset));
738 const name = mem.spanZ(@ptrCast([*:0]u8, name_bytes.ptr + name_offset));
739739 if (mem.eql(u8, name, "/names")) {
740740 break :str_tab_index name_index;
741741 }
......@@ -1131,7 +1131,7 @@ pub const DebugInfo = struct {
11311131 const obj_di = try self.allocator.create(ModuleDebugInfo);
11321132 errdefer self.allocator.destroy(obj_di);
11331133
1134 const macho_path = mem.toSliceConst(u8, std.c._dyld_get_image_name(i));
1134 const macho_path = mem.spanZ(std.c._dyld_get_image_name(i));
11351135 obj_di.* = openMachODebugInfo(self.allocator, macho_path) catch |err| switch (err) {
11361136 error.FileNotFound => return error.MissingDebugInfo,
11371137 else => return err,
......@@ -1254,10 +1254,7 @@ pub const DebugInfo = struct {
12541254 if (context.address >= seg_start and context.address < seg_end) {
12551255 // Android libc uses NULL instead of an empty string to mark the
12561256 // main program
1257 context.name = if (info.dlpi_name) |dlpi_name|
1258 mem.toSliceConst(u8, dlpi_name)
1259 else
1260 "";
1257 context.name = if (info.dlpi_name) |dlpi_name| mem.spanZ(dlpi_name) else "";
12611258 context.base_address = info.dlpi_addr;
12621259 // Stop the iteration
12631260 return error.Found;
......@@ -1426,7 +1423,7 @@ pub const ModuleDebugInfo = switch (builtin.os.tag) {
14261423 return SymbolInfo{};
14271424
14281425 assert(symbol.ofile.?.n_strx < self.strings.len);
1429 const o_file_path = mem.toSliceConst(u8, self.strings.ptr + symbol.ofile.?.n_strx);
1426 const o_file_path = mem.spanZ(self.strings.ptr + symbol.ofile.?.n_strx);
14301427
14311428 // Check if its debug infos are already in the cache
14321429 var o_file_di = self.ofiles.getValue(o_file_path) orelse
......@@ -1483,7 +1480,7 @@ pub const ModuleDebugInfo = switch (builtin.os.tag) {
14831480 const mod_index = for (self.sect_contribs) |sect_contrib| {
14841481 if (sect_contrib.Section > self.coff.sections.len) continue;
14851482 // Remember that SectionContribEntry.Section is 1-based.
1486 coff_section = &self.coff.sections.toSlice()[sect_contrib.Section - 1];
1483 coff_section = &self.coff.sections.span()[sect_contrib.Section - 1];
14871484
14881485 const vaddr_start = coff_section.header.virtual_address + sect_contrib.Offset;
14891486 const vaddr_end = vaddr_start + sect_contrib.Size;
......@@ -1510,7 +1507,7 @@ pub const ModuleDebugInfo = switch (builtin.os.tag) {
15101507 const vaddr_start = coff_section.header.virtual_address + proc_sym.CodeOffset;
15111508 const vaddr_end = vaddr_start + proc_sym.CodeSize;
15121509 if (relocated_address >= vaddr_start and relocated_address < vaddr_end) {
1513 break mem.toSliceConst(u8, @ptrCast([*:0]u8, proc_sym) + @sizeOf(pdb.ProcSym));
1510 break mem.spanZ(@ptrCast([*:0]u8, proc_sym) + @sizeOf(pdb.ProcSym));
15141511 }
15151512 },
15161513 else => {},
lib/std/dwarf.zig+7-7
......@@ -82,7 +82,7 @@ const Die = struct {
8282 };
8383
8484 fn getAttr(self: *const Die, id: u64) ?*const FormValue {
85 for (self.attrs.toSliceConst()) |*attr| {
85 for (self.attrs.span()) |*attr| {
8686 if (attr.id == id) return &attr.value;
8787 }
8888 return null;
......@@ -375,7 +375,7 @@ fn parseFormValue(allocator: *mem.Allocator, in_stream: var, form_id: u64, is_64
375375}
376376
377377fn getAbbrevTableEntry(abbrev_table: *const AbbrevTable, abbrev_code: u64) ?*const AbbrevTableEntry {
378 for (abbrev_table.toSliceConst()) |*table_entry| {
378 for (abbrev_table.span()) |*table_entry| {
379379 if (table_entry.abbrev_code == abbrev_code) return table_entry;
380380 }
381381 return null;
......@@ -399,7 +399,7 @@ pub const DwarfInfo = struct {
399399 }
400400
401401 fn getSymbolName(di: *DwarfInfo, address: u64) ?[]const u8 {
402 for (di.func_list.toSliceConst()) |*func| {
402 for (di.func_list.span()) |*func| {
403403 if (func.pc_range) |range| {
404404 if (address >= range.start and address < range.end) {
405405 return func.name;
......@@ -588,7 +588,7 @@ pub const DwarfInfo = struct {
588588 }
589589
590590 fn findCompileUnit(di: *DwarfInfo, target_address: u64) !*const CompileUnit {
591 for (di.compile_unit_list.toSlice()) |*compile_unit| {
591 for (di.compile_unit_list.span()) |*compile_unit| {
592592 if (compile_unit.pc_range) |range| {
593593 if (target_address >= range.start and target_address < range.end) return compile_unit;
594594 }
......@@ -636,7 +636,7 @@ pub const DwarfInfo = struct {
636636 /// Gets an already existing AbbrevTable given the abbrev_offset, or if not found,
637637 /// seeks in the stream and parses it.
638638 fn getAbbrevTable(di: *DwarfInfo, abbrev_offset: u64) !*const AbbrevTable {
639 for (di.abbrev_table_list.toSlice()) |*header| {
639 for (di.abbrev_table_list.span()) |*header| {
640640 if (header.offset == abbrev_offset) {
641641 return &header.table;
642642 }
......@@ -690,7 +690,7 @@ pub const DwarfInfo = struct {
690690 .attrs = ArrayList(Die.Attr).init(di.allocator()),
691691 };
692692 try result.attrs.resize(table_entry.attrs.len);
693 for (table_entry.attrs.toSliceConst()) |attr, i| {
693 for (table_entry.attrs.span()) |attr, i| {
694694 result.attrs.items[i] = Die.Attr{
695695 .id = attr.attr_id,
696696 .value = try parseFormValue(di.allocator(), in_stream, attr.form_id, is_64),
......@@ -757,7 +757,7 @@ pub const DwarfInfo = struct {
757757 }
758758
759759 var file_entries = ArrayList(FileEntry).init(di.allocator());
760 var prog = LineNumberProgram.init(default_is_stmt, include_directories.toSliceConst(), &file_entries, target_address);
760 var prog = LineNumberProgram.init(default_is_stmt, include_directories.span(), &file_entries, target_address);
761761
762762 while (true) {
763763 const file_name = try in.readUntilDelimiterAlloc(di.allocator(), 0, math.maxInt(usize));
lib/std/dynamic_library.zig+13-7
......@@ -254,9 +254,11 @@ pub const ElfDynLib = struct {
254254 };
255255 }
256256
257 pub const openC = @compileError("deprecated: renamed to openZ");
258
257259 /// Trusts the file. Malicious file will be able to execute arbitrary code.
258 pub fn openC(path_c: [*:0]const u8) !ElfDynLib {
259 return open(mem.toSlice(u8, path_c));
260 pub fn openZ(path_c: [*:0]const u8) !ElfDynLib {
261 return open(mem.spanZ(path_c));
260262 }
261263
262264 /// Trusts the file
......@@ -285,7 +287,7 @@ pub const ElfDynLib = struct {
285287 if (0 == (@as(u32, 1) << @intCast(u5, self.syms[i].st_info & 0xf) & OK_TYPES)) continue;
286288 if (0 == (@as(u32, 1) << @intCast(u5, self.syms[i].st_info >> 4) & OK_BINDS)) continue;
287289 if (0 == self.syms[i].st_shndx) continue;
288 if (!mem.eql(u8, name, mem.toSliceConst(u8, self.strings + self.syms[i].st_name))) continue;
290 if (!mem.eql(u8, name, mem.spanZ(self.strings + self.syms[i].st_name))) continue;
289291 if (maybe_versym) |versym| {
290292 if (!checkver(self.verdef.?, versym[i], vername, self.strings))
291293 continue;
......@@ -316,7 +318,7 @@ fn checkver(def_arg: *elf.Verdef, vsym_arg: i32, vername: []const u8, strings: [
316318 def = @intToPtr(*elf.Verdef, @ptrToInt(def) + def.vd_next);
317319 }
318320 const aux = @intToPtr(*elf.Verdaux, @ptrToInt(def) + def.vd_aux);
319 return mem.eql(u8, vername, mem.toSliceConst(u8, strings + aux.vda_name));
321 return mem.eql(u8, vername, mem.spanZ(strings + aux.vda_name));
320322}
321323
322324pub const WindowsDynLib = struct {
......@@ -329,7 +331,9 @@ pub const WindowsDynLib = struct {
329331 return openW(&path_w);
330332 }
331333
332 pub fn openC(path_c: [*:0]const u8) !WindowsDynLib {
334 pub const openC = @compileError("deprecated: renamed to openZ");
335
336 pub fn openZ(path_c: [*:0]const u8) !WindowsDynLib {
333337 const path_w = try windows.cStrToPrefixedFileW(path_c);
334338 return openW(&path_w);
335339 }
......@@ -362,10 +366,12 @@ pub const DlDynlib = struct {
362366
363367 pub fn open(path: []const u8) !DlDynlib {
364368 const path_c = try os.toPosixPath(path);
365 return openC(&path_c);
369 return openZ(&path_c);
366370 }
367371
368 pub fn openC(path_c: [*:0]const u8) !DlDynlib {
372 pub const openC = @compileError("deprecated: renamed to openZ");
373
374 pub fn openZ(path_c: [*:0]const u8) !DlDynlib {
369375 return DlDynlib{
370376 .handle = system.dlopen(path_c, system.RTLD_LAZY) orelse {
371377 return error.FileNotFound;
lib/std/event/loop.zig+2-2
......@@ -1096,10 +1096,10 @@ pub const Loop = struct {
10961096 msg.result = noasync os.preadv(msg.fd, msg.iov, msg.offset);
10971097 },
10981098 .open => |*msg| {
1099 msg.result = noasync os.openC(msg.path, msg.flags, msg.mode);
1099 msg.result = noasync os.openZ(msg.path, msg.flags, msg.mode);
11001100 },
11011101 .openat => |*msg| {
1102 msg.result = noasync os.openatC(msg.fd, msg.path, msg.flags, msg.mode);
1102 msg.result = noasync os.openatZ(msg.fd, msg.path, msg.flags, msg.mode);
11031103 },
11041104 .faccessat => |*msg| {
11051105 msg.result = noasync os.faccessatZ(msg.dirfd, msg.path, msg.mode, msg.flags);
lib/std/fs.zig+113-93
......@@ -11,13 +11,18 @@ const math = std.math;
1111pub const path = @import("fs/path.zig");
1212pub const File = @import("fs/file.zig").File;
1313
14// TODO audit these APIs with respect to Dir and absolute paths
15
1416pub const symLink = os.symlink;
15pub const symLinkC = os.symlinkC;
17pub const symLinkZ = os.symlinkZ;
18pub const symLinkC = @compileError("deprecated: renamed to symlinkZ");
1619pub const rename = os.rename;
17pub const renameC = os.renameC;
20pub const renameZ = os.renameZ;
21pub const renameC = @compileError("deprecated: renamed to renameZ");
1822pub const renameW = os.renameW;
1923pub const realpath = os.realpath;
20pub const realpathC = os.realpathC;
24pub const realpathZ = os.realpathZ;
25pub const realpathC = @compileError("deprecated: renamed to realpathZ");
2126pub const realpathW = os.realpathW;
2227
2328pub const getAppDataDir = @import("fs/get_app_data_dir.zig").getAppDataDir;
......@@ -120,7 +125,7 @@ pub const AtomicFile = struct {
120125 file: File,
121126 // TODO either replace this with rand_buf or use []u16 on Windows
122127 tmp_path_buf: [TMP_PATH_LEN:0]u8,
123 dest_path: []const u8,
128 dest_basename: []const u8,
124129 file_open: bool,
125130 file_exists: bool,
126131 close_dir_on_deinit: bool,
......@@ -131,17 +136,23 @@ pub const AtomicFile = struct {
131136 const RANDOM_BYTES = 12;
132137 const TMP_PATH_LEN = base64.Base64Encoder.calcSize(RANDOM_BYTES);
133138
134 /// TODO rename this. Callers should go through Dir API
135 pub fn init2(dest_path: []const u8, mode: File.Mode, dir: Dir, close_dir_on_deinit: bool) InitError!AtomicFile {
139 /// Note that the `Dir.atomicFile` API may be more handy than this lower-level function.
140 pub fn init(
141 dest_basename: []const u8,
142 mode: File.Mode,
143 dir: Dir,
144 close_dir_on_deinit: bool,
145 ) InitError!AtomicFile {
136146 var rand_buf: [RANDOM_BYTES]u8 = undefined;
137147 var tmp_path_buf: [TMP_PATH_LEN:0]u8 = undefined;
148 // TODO: should be able to use TMP_PATH_LEN here.
138149 tmp_path_buf[base64.Base64Encoder.calcSize(RANDOM_BYTES)] = 0;
139150
140151 while (true) {
141152 try crypto.randomBytes(rand_buf[0..]);
142153 base64_encoder.encode(&tmp_path_buf, &rand_buf);
143154
144 const file = dir.createFileC(
155 const file = dir.createFileZ(
145156 &tmp_path_buf,
146157 .{ .mode = mode, .exclusive = true },
147158 ) catch |err| switch (err) {
......@@ -152,7 +163,7 @@ pub const AtomicFile = struct {
152163 return AtomicFile{
153164 .file = file,
154165 .tmp_path_buf = tmp_path_buf,
155 .dest_path = dest_path,
166 .dest_basename = dest_basename,
156167 .file_open = true,
157168 .file_exists = true,
158169 .close_dir_on_deinit = close_dir_on_deinit,
......@@ -161,11 +172,6 @@ pub const AtomicFile = struct {
161172 }
162173 }
163174
164 /// Deprecated. Use `Dir.atomicFile`.
165 pub fn init(dest_path: []const u8, mode: File.Mode) InitError!AtomicFile {
166 return cwd().atomicFile(dest_path, .{ .mode = mode });
167 }
168
169175 /// always call deinit, even after successful finish()
170176 pub fn deinit(self: *AtomicFile) void {
171177 if (self.file_open) {
......@@ -173,7 +179,7 @@ pub const AtomicFile = struct {
173179 self.file_open = false;
174180 }
175181 if (self.file_exists) {
176 self.dir.deleteFileC(&self.tmp_path_buf) catch {};
182 self.dir.deleteFileZ(&self.tmp_path_buf) catch {};
177183 self.file_exists = false;
178184 }
179185 if (self.close_dir_on_deinit) {
......@@ -189,12 +195,12 @@ pub const AtomicFile = struct {
189195 self.file_open = false;
190196 }
191197 if (std.Target.current.os.tag == .windows) {
192 const dest_path_w = try os.windows.sliceToPrefixedFileW(self.dest_path);
198 const dest_path_w = try os.windows.sliceToPrefixedFileW(self.dest_basename);
193199 const tmp_path_w = try os.windows.cStrToPrefixedFileW(&self.tmp_path_buf);
194200 try os.renameatW(self.dir.fd, &tmp_path_w, self.dir.fd, &dest_path_w, os.windows.TRUE);
195201 self.file_exists = false;
196202 } else {
197 const dest_path_c = try os.toPosixPath(self.dest_path);
203 const dest_path_c = try os.toPosixPath(self.dest_basename);
198204 try os.renameatZ(self.dir.fd, &self.tmp_path_buf, self.dir.fd, &dest_path_c);
199205 self.file_exists = false;
200206 }
......@@ -213,7 +219,7 @@ pub fn makeDirAbsolute(absolute_path: []const u8) !void {
213219
214220/// Same as `makeDirAbsolute` except the parameter is a null-terminated UTF8-encoded string.
215221pub fn makeDirAbsoluteZ(absolute_path_z: [*:0]const u8) !void {
216 assert(path.isAbsoluteC(absolute_path_z));
222 assert(path.isAbsoluteZ(absolute_path_z));
217223 return os.mkdirZ(absolute_path_z, default_new_dir_mode);
218224}
219225
......@@ -224,18 +230,25 @@ pub fn makeDirAbsoluteW(absolute_path_w: [*:0]const u16) !void {
224230 os.windows.CloseHandle(handle);
225231}
226232
227/// Deprecated; use `Dir.deleteDir`.
228pub fn deleteDir(dir_path: []const u8) !void {
233pub const deleteDir = @compileError("deprecated; use dir.deleteDir or deleteDirAbsolute");
234pub const deleteDirC = @compileError("deprecated; use dir.deleteDirZ or deleteDirAbsoluteZ");
235pub const deleteDirW = @compileError("deprecated; use dir.deleteDirW or deleteDirAbsoluteW");
236
237/// Same as `Dir.deleteDir` except the path is absolute.
238pub fn deleteDirAbsolute(dir_path: []const u8) !void {
239 assert(path.isAbsolute(dir_path));
229240 return os.rmdir(dir_path);
230241}
231242
232/// Deprecated; use `Dir.deleteDirC`.
233pub fn deleteDirC(dir_path: [*:0]const u8) !void {
234 return os.rmdirC(dir_path);
243/// Same as `deleteDirAbsolute` except the path parameter is null-terminated.
244pub fn deleteDirAbsoluteZ(dir_path: [*:0]const u8) !void {
245 assert(path.isAbsoluteZ(dir_path));
246 return os.rmdirZ(dir_path);
235247}
236248
237/// Deprecated; use `Dir.deleteDirW`.
238pub fn deleteDirW(dir_path: [*:0]const u16) !void {
249/// Same as `deleteDirAbsolute` except the path parameter is WTF-16 and target OS is assumed Windows.
250pub fn deleteDirAbsoluteW(dir_path: [*:0]const u16) !void {
251 assert(path.isAbsoluteWindowsW(dir_path));
239252 return os.rmdirW(dir_path);
240253}
241254
......@@ -412,7 +425,7 @@ pub const Dir = struct {
412425 const next_index = self.index + linux_entry.reclen();
413426 self.index = next_index;
414427
415 const name = mem.toSlice(u8, @ptrCast([*:0]u8, &linux_entry.d_name));
428 const name = mem.spanZ(@ptrCast([*:0]u8, &linux_entry.d_name));
416429
417430 // skip . and .. entries
418431 if (mem.eql(u8, name, ".") or mem.eql(u8, name, "..")) {
......@@ -573,8 +586,7 @@ pub const Dir = struct {
573586 return self.openFileZ(&path_c, flags);
574587 }
575588
576 /// Deprecated; use `openFileZ`.
577 pub const openFileC = openFileZ;
589 pub const openFileC = @compileError("deprecated: renamed to openFileZ");
578590
579591 /// Same as `openFile` but the path parameter is null-terminated.
580592 pub fn openFileZ(self: Dir, sub_path: [*:0]const u8, flags: File.OpenFlags) File.OpenError!File {
......@@ -592,7 +604,7 @@ pub const Dir = struct {
592604 const fd = if (need_async_thread and !flags.always_blocking)
593605 try std.event.Loop.instance.?.openatZ(self.fd, sub_path, os_flags, 0)
594606 else
595 try os.openatC(self.fd, sub_path, os_flags, 0);
607 try os.openatZ(self.fd, sub_path, os_flags, 0);
596608 return File{
597609 .handle = fd,
598610 .io_mode = .blocking,
......@@ -625,11 +637,13 @@ pub const Dir = struct {
625637 return self.createFileW(&path_w, flags);
626638 }
627639 const path_c = try os.toPosixPath(sub_path);
628 return self.createFileC(&path_c, flags);
640 return self.createFileZ(&path_c, flags);
629641 }
630642
643 pub const createFileC = @compileError("deprecated: renamed to createFileZ");
644
631645 /// Same as `createFile` but the path parameter is null-terminated.
632 pub fn createFileC(self: Dir, sub_path_c: [*:0]const u8, flags: File.CreateFlags) File.OpenError!File {
646 pub fn createFileZ(self: Dir, sub_path_c: [*:0]const u8, flags: File.CreateFlags) File.OpenError!File {
633647 if (builtin.os.tag == .windows) {
634648 const path_w = try os.windows.cStrToPrefixedFileW(sub_path_c);
635649 return self.createFileW(&path_w, flags);
......@@ -642,7 +656,7 @@ pub const Dir = struct {
642656 const fd = if (need_async_thread)
643657 try std.event.Loop.instance.?.openatZ(self.fd, sub_path_c, os_flags, flags.mode)
644658 else
645 try os.openatC(self.fd, sub_path_c, os_flags, flags.mode);
659 try os.openatZ(self.fd, sub_path_c, os_flags, flags.mode);
646660 return File{ .handle = fd, .io_mode = .blocking };
647661 }
648662
......@@ -664,27 +678,16 @@ pub const Dir = struct {
664678 });
665679 }
666680
667 /// Deprecated; call `openFile` directly.
668 pub fn openRead(self: Dir, sub_path: []const u8) File.OpenError!File {
669 return self.openFile(sub_path, .{});
670 }
671
672 /// Deprecated; call `openFileZ` directly.
673 pub fn openReadC(self: Dir, sub_path: [*:0]const u8) File.OpenError!File {
674 return self.openFileZ(sub_path, .{});
675 }
676
677 /// Deprecated; call `openFileW` directly.
678 pub fn openReadW(self: Dir, sub_path: [*:0]const u16) File.OpenError!File {
679 return self.openFileW(sub_path, .{});
680 }
681 pub const openRead = @compileError("deprecated in favor of openFile");
682 pub const openReadC = @compileError("deprecated in favor of openFileZ");
683 pub const openReadW = @compileError("deprecated in favor of openFileW");
681684
682685 pub fn makeDir(self: Dir, sub_path: []const u8) !void {
683686 try os.mkdirat(self.fd, sub_path, default_new_dir_mode);
684687 }
685688
686689 pub fn makeDirZ(self: Dir, sub_path: [*:0]const u8) !void {
687 try os.mkdiratC(self.fd, sub_path, default_new_dir_mode);
690 try os.mkdiratZ(self.fd, sub_path, default_new_dir_mode);
688691 }
689692
690693 pub fn makeDirW(self: Dir, sub_path: [*:0]const u16) !void {
......@@ -758,20 +761,22 @@ pub const Dir = struct {
758761 return self.openDirW(&sub_path_w, args);
759762 } else {
760763 const sub_path_c = try os.toPosixPath(sub_path);
761 return self.openDirC(&sub_path_c, args);
764 return self.openDirZ(&sub_path_c, args);
762765 }
763766 }
764767
768 pub const openDirC = @compileError("deprecated: renamed to openDirZ");
769
765770 /// Same as `openDir` except the parameter is null-terminated.
766 pub fn openDirC(self: Dir, sub_path_c: [*:0]const u8, args: OpenDirOptions) OpenError!Dir {
771 pub fn openDirZ(self: Dir, sub_path_c: [*:0]const u8, args: OpenDirOptions) OpenError!Dir {
767772 if (builtin.os.tag == .windows) {
768773 const sub_path_w = try os.windows.cStrToPrefixedFileW(sub_path_c);
769774 return self.openDirW(&sub_path_w, args);
770775 } else if (!args.iterate) {
771776 const O_PATH = if (@hasDecl(os, "O_PATH")) os.O_PATH else 0;
772 return self.openDirFlagsC(sub_path_c, os.O_DIRECTORY | os.O_RDONLY | os.O_CLOEXEC | O_PATH);
777 return self.openDirFlagsZ(sub_path_c, os.O_DIRECTORY | os.O_RDONLY | os.O_CLOEXEC | O_PATH);
773778 } else {
774 return self.openDirFlagsC(sub_path_c, os.O_DIRECTORY | os.O_RDONLY | os.O_CLOEXEC);
779 return self.openDirFlagsZ(sub_path_c, os.O_DIRECTORY | os.O_RDONLY | os.O_CLOEXEC);
775780 }
776781 }
777782
......@@ -787,11 +792,11 @@ pub const Dir = struct {
787792 }
788793
789794 /// `flags` must contain `os.O_DIRECTORY`.
790 fn openDirFlagsC(self: Dir, sub_path_c: [*:0]const u8, flags: u32) OpenError!Dir {
795 fn openDirFlagsZ(self: Dir, sub_path_c: [*:0]const u8, flags: u32) OpenError!Dir {
791796 const result = if (need_async_thread)
792797 std.event.Loop.instance.?.openatZ(self.fd, sub_path_c, flags, 0)
793798 else
794 os.openatC(self.fd, sub_path_c, flags, 0);
799 os.openatZ(self.fd, sub_path_c, flags, 0);
795800 const fd = result catch |err| switch (err) {
796801 error.FileTooBig => unreachable, // can't happen for directories
797802 error.IsDir => unreachable, // we're providing O_DIRECTORY
......@@ -809,7 +814,7 @@ pub const Dir = struct {
809814 .fd = undefined,
810815 };
811816
812 const path_len_bytes = @intCast(u16, mem.toSliceConst(u16, sub_path_w).len * 2);
817 const path_len_bytes = @intCast(u16, mem.lenZ(sub_path_w) * 2);
813818 var nt_name = w.UNICODE_STRING{
814819 .Length = path_len_bytes,
815820 .MaximumLength = path_len_bytes,
......@@ -867,9 +872,11 @@ pub const Dir = struct {
867872 };
868873 }
869874
875 pub const deleteFileC = @compileError("deprecated: renamed to deleteFileZ");
876
870877 /// Same as `deleteFile` except the parameter is null-terminated.
871 pub fn deleteFileC(self: Dir, sub_path_c: [*:0]const u8) DeleteFileError!void {
872 os.unlinkatC(self.fd, sub_path_c, 0) catch |err| switch (err) {
878 pub fn deleteFileZ(self: Dir, sub_path_c: [*:0]const u8) DeleteFileError!void {
879 os.unlinkatZ(self.fd, sub_path_c, 0) catch |err| switch (err) {
873880 error.DirNotEmpty => unreachable, // not passing AT_REMOVEDIR
874881 else => |e| return e,
875882 };
......@@ -908,12 +915,12 @@ pub const Dir = struct {
908915 return self.deleteDirW(&sub_path_w);
909916 }
910917 const sub_path_c = try os.toPosixPath(sub_path);
911 return self.deleteDirC(&sub_path_c);
918 return self.deleteDirZ(&sub_path_c);
912919 }
913920
914921 /// Same as `deleteDir` except the parameter is null-terminated.
915 pub fn deleteDirC(self: Dir, sub_path_c: [*:0]const u8) DeleteDirError!void {
916 os.unlinkatC(self.fd, sub_path_c, os.AT_REMOVEDIR) catch |err| switch (err) {
922 pub fn deleteDirZ(self: Dir, sub_path_c: [*:0]const u8) DeleteDirError!void {
923 os.unlinkatZ(self.fd, sub_path_c, os.AT_REMOVEDIR) catch |err| switch (err) {
917924 error.IsDir => unreachable, // not possible since we pass AT_REMOVEDIR
918925 else => |e| return e,
919926 };
......@@ -933,12 +940,14 @@ pub const Dir = struct {
933940 /// Asserts that the path parameter has no null bytes.
934941 pub fn readLink(self: Dir, sub_path: []const u8, buffer: *[MAX_PATH_BYTES]u8) ![]u8 {
935942 const sub_path_c = try os.toPosixPath(sub_path);
936 return self.readLinkC(&sub_path_c, buffer);
943 return self.readLinkZ(&sub_path_c, buffer);
937944 }
938945
946 pub const readLinkC = @compileError("deprecated: renamed to readLinkZ");
947
939948 /// Same as `readLink`, except the `pathname` parameter is null-terminated.
940 pub fn readLinkC(self: Dir, sub_path_c: [*:0]const u8, buffer: *[MAX_PATH_BYTES]u8) ![]u8 {
941 return os.readlinkatC(self.fd, sub_path_c, buffer);
949 pub fn readLinkZ(self: Dir, sub_path_c: [*:0]const u8, buffer: *[MAX_PATH_BYTES]u8) ![]u8 {
950 return os.readlinkatZ(self.fd, sub_path_c, buffer);
942951 }
943952
944953 /// On success, caller owns returned buffer.
......@@ -956,7 +965,7 @@ pub const Dir = struct {
956965 max_bytes: usize,
957966 comptime A: u29,
958967 ) ![]align(A) u8 {
959 var file = try self.openRead(file_path);
968 var file = try self.openFile(file_path, .{});
960969 defer file.close();
961970
962971 const size = math.cast(usize, try file.getEndPos()) catch math.maxInt(usize);
......@@ -1280,9 +1289,9 @@ pub const Dir = struct {
12801289 pub fn atomicFile(self: Dir, dest_path: []const u8, options: AtomicFileOptions) !AtomicFile {
12811290 if (path.dirname(dest_path)) |dirname| {
12821291 const dir = try self.openDir(dirname, .{});
1283 return AtomicFile.init2(path.basename(dest_path), options.mode, dir, true);
1292 return AtomicFile.init(path.basename(dest_path), options.mode, dir, true);
12841293 } else {
1285 return AtomicFile.init2(dest_path, options.mode, self, false);
1294 return AtomicFile.init(dest_path, options.mode, self, false);
12861295 }
12871296 }
12881297};
......@@ -1309,9 +1318,11 @@ pub fn openFileAbsolute(absolute_path: []const u8, flags: File.OpenFlags) File.O
13091318 return cwd().openFile(absolute_path, flags);
13101319}
13111320
1321pub const openFileAbsoluteC = @compileError("deprecated: renamed to openFileAbsoluteZ");
1322
13121323/// Same as `openFileAbsolute` but the path parameter is null-terminated.
1313pub fn openFileAbsoluteC(absolute_path_c: [*:0]const u8, flags: File.OpenFlags) File.OpenError!File {
1314 assert(path.isAbsoluteC(absolute_path_c));
1324pub fn openFileAbsoluteZ(absolute_path_c: [*:0]const u8, flags: File.OpenFlags) File.OpenError!File {
1325 assert(path.isAbsoluteZ(absolute_path_c));
13151326 return cwd().openFileZ(absolute_path_c, flags);
13161327}
13171328
......@@ -1332,10 +1343,12 @@ pub fn createFileAbsolute(absolute_path: []const u8, flags: File.CreateFlags) Fi
13321343 return cwd().createFile(absolute_path, flags);
13331344}
13341345
1346pub const createFileAbsoluteC = @compileError("deprecated: renamed to createFileAbsoluteZ");
1347
13351348/// Same as `createFileAbsolute` but the path parameter is null-terminated.
1336pub fn createFileAbsoluteC(absolute_path_c: [*:0]const u8, flags: File.CreateFlags) File.OpenError!File {
1337 assert(path.isAbsoluteC(absolute_path_c));
1338 return cwd().createFileC(absolute_path_c, flags);
1349pub fn createFileAbsoluteZ(absolute_path_c: [*:0]const u8, flags: File.CreateFlags) File.OpenError!File {
1350 assert(path.isAbsoluteZ(absolute_path_c));
1351 return cwd().createFileZ(absolute_path_c, flags);
13391352}
13401353
13411354/// Same as `createFileAbsolute` but the path parameter is WTF-16 encoded.
......@@ -1353,10 +1366,12 @@ pub fn deleteFileAbsolute(absolute_path: []const u8) DeleteFileError!void {
13531366 return cwd().deleteFile(absolute_path);
13541367}
13551368
1369pub const deleteFileAbsoluteC = @compileError("deprecated: renamed to deleteFileAbsoluteZ");
1370
13561371/// Same as `deleteFileAbsolute` except the parameter is null-terminated.
1357pub fn deleteFileAbsoluteC(absolute_path_c: [*:0]const u8) DeleteFileError!void {
1358 assert(path.isAbsoluteC(absolute_path_c));
1359 return cwd().deleteFileC(absolute_path_c);
1372pub fn deleteFileAbsoluteZ(absolute_path_c: [*:0]const u8) DeleteFileError!void {
1373 assert(path.isAbsoluteZ(absolute_path_c));
1374 return cwd().deleteFileZ(absolute_path_c);
13601375}
13611376
13621377/// Same as `deleteFileAbsolute` except the parameter is WTF-16 encoded.
......@@ -1384,6 +1399,21 @@ pub fn deleteTreeAbsolute(absolute_path: []const u8) !void {
13841399 return dir.deleteTree(path.basename(absolute_path));
13851400}
13861401
1402/// Same as `Dir.readLink`, except it asserts the path is absolute.
1403pub fn readLinkAbsolute(pathname: []const u8, buffer: *[MAX_PATH_BYTES]u8) ![]u8 {
1404 assert(path.isAbsolute(pathname));
1405 return os.readlink(pathname, buffer);
1406}
1407
1408/// Same as `readLink`, except the path parameter is null-terminated.
1409pub fn readLinkAbsoluteZ(pathname_c: [*]const u8, buffer: *[MAX_PATH_BYTES]u8) ![]u8 {
1410 assert(path.isAbsoluteZ(pathname_c));
1411 return os.readlinkZ(pathname_c, buffer);
1412}
1413
1414pub const readLink = @compileError("deprecated; use Dir.readLink or readLinkAbsolute");
1415pub const readLinkC = @compileError("deprecated; use Dir.readLinkZ or readLinkAbsoluteZ");
1416
13871417pub const Walker = struct {
13881418 stack: std.ArrayList(StackItem),
13891419 name_buffer: std.Buffer,
......@@ -1411,7 +1441,7 @@ pub const Walker = struct {
14111441 while (true) {
14121442 if (self.stack.len == 0) return null;
14131443 // `top` becomes invalid after appending to `self.stack`.
1414 const top = &self.stack.toSlice()[self.stack.len - 1];
1444 const top = &self.stack.span()[self.stack.len - 1];
14151445 const dirname_len = top.dirname_len;
14161446 if (try top.dir_it.next()) |base| {
14171447 self.name_buffer.shrink(dirname_len);
......@@ -1432,8 +1462,8 @@ pub const Walker = struct {
14321462 }
14331463 return Entry{
14341464 .dir = top.dir_it.dir,
1435 .basename = self.name_buffer.toSliceConst()[dirname_len + 1 ..],
1436 .path = self.name_buffer.toSliceConst(),
1465 .basename = self.name_buffer.span()[dirname_len + 1 ..],
1466 .path = self.name_buffer.span(),
14371467 .kind = base.kind,
14381468 };
14391469 } else {
......@@ -1475,31 +1505,21 @@ pub fn walkPath(allocator: *Allocator, dir_path: []const u8) !Walker {
14751505 return walker;
14761506}
14771507
1478/// Deprecated; use `Dir.readLink`.
1479pub fn readLink(pathname: []const u8, buffer: *[MAX_PATH_BYTES]u8) ![]u8 {
1480 return os.readlink(pathname, buffer);
1481}
1482
1483/// Deprecated; use `Dir.readLinkC`.
1484pub fn readLinkC(pathname_c: [*]const u8, buffer: *[MAX_PATH_BYTES]u8) ![]u8 {
1485 return os.readlinkC(pathname_c, buffer);
1486}
1487
14881508pub const OpenSelfExeError = os.OpenError || os.windows.CreateFileError || SelfExePathError;
14891509
14901510pub fn openSelfExe() OpenSelfExeError!File {
14911511 if (builtin.os.tag == .linux) {
1492 return openFileAbsoluteC("/proc/self/exe", .{});
1512 return openFileAbsoluteZ("/proc/self/exe", .{});
14931513 }
14941514 if (builtin.os.tag == .windows) {
14951515 const wide_slice = selfExePathW();
14961516 const prefixed_path_w = try os.windows.wToPrefixedFileW(wide_slice);
1497 return cwd().openReadW(&prefixed_path_w);
1517 return cwd().openFileW(&prefixed_path_w, .{});
14981518 }
14991519 var buf: [MAX_PATH_BYTES]u8 = undefined;
15001520 const self_exe_path = try selfExePath(&buf);
15011521 buf[self_exe_path.len] = 0;
1502 return openFileAbsoluteC(self_exe_path[0..self_exe_path.len :0].ptr, .{});
1522 return openFileAbsoluteZ(self_exe_path[0..self_exe_path.len :0].ptr, .{});
15031523}
15041524
15051525test "openSelfExe" {
......@@ -1533,23 +1553,23 @@ pub fn selfExePath(out_buffer: *[MAX_PATH_BYTES]u8) SelfExePathError![]u8 {
15331553 var u32_len: u32 = out_buffer.len;
15341554 const rc = std.c._NSGetExecutablePath(out_buffer, &u32_len);
15351555 if (rc != 0) return error.NameTooLong;
1536 return mem.toSlice(u8, @ptrCast([*:0]u8, out_buffer));
1556 return mem.spanZ(@ptrCast([*:0]u8, out_buffer));
15371557 }
15381558 switch (builtin.os.tag) {
1539 .linux => return os.readlinkC("/proc/self/exe", out_buffer),
1559 .linux => return os.readlinkZ("/proc/self/exe", out_buffer),
15401560 .freebsd, .dragonfly => {
15411561 var mib = [4]c_int{ os.CTL_KERN, os.KERN_PROC, os.KERN_PROC_PATHNAME, -1 };
15421562 var out_len: usize = out_buffer.len;
15431563 try os.sysctl(&mib, out_buffer, &out_len, null, 0);
15441564 // TODO could this slice from 0 to out_len instead?
1545 return mem.toSlice(u8, @ptrCast([*:0]u8, out_buffer));
1565 return mem.spanZ(@ptrCast([*:0]u8, out_buffer));
15461566 },
15471567 .netbsd => {
15481568 var mib = [4]c_int{ os.CTL_KERN, os.KERN_PROC_ARGS, -1, os.KERN_PROC_PATHNAME };
15491569 var out_len: usize = out_buffer.len;
15501570 try os.sysctl(&mib, out_buffer, &out_len, null, 0);
15511571 // TODO could this slice from 0 to out_len instead?
1552 return mem.toSlice(u8, @ptrCast([*:0]u8, out_buffer));
1572 return mem.spanZ(@ptrCast([*:0]u8, out_buffer));
15531573 },
15541574 .windows => {
15551575 const utf16le_slice = selfExePathW();
......@@ -1564,7 +1584,7 @@ pub fn selfExePath(out_buffer: *[MAX_PATH_BYTES]u8) SelfExePathError![]u8 {
15641584/// The result is UTF16LE-encoded.
15651585pub fn selfExePathW() [:0]const u16 {
15661586 const image_path_name = &os.windows.peb().ProcessParameters.ImagePathName;
1567 return mem.toSliceConst(u16, @ptrCast([*:0]const u16, image_path_name.Buffer));
1587 return mem.spanZ(@ptrCast([*:0]const u16, image_path_name.Buffer));
15681588}
15691589
15701590/// `selfExeDirPath` except allocates the result on the heap.
lib/std/fs/file.zig+1-1
......@@ -89,7 +89,7 @@ pub const File = struct {
8989 if (self.isTty()) {
9090 if (self.handle == os.STDOUT_FILENO or self.handle == os.STDERR_FILENO) {
9191 // Use getenvC to workaround https://github.com/ziglang/zig/issues/3511
92 if (os.getenvC("TERM")) |term| {
92 if (os.getenvZ("TERM")) |term| {
9393 if (std.mem.eql(u8, term, "dumb"))
9494 return false;
9595 }
lib/std/fs/get_app_data_dir.zig+1-1
......@@ -24,7 +24,7 @@ pub fn getAppDataDir(allocator: *mem.Allocator, appname: []const u8) GetAppDataD
2424 )) {
2525 os.windows.S_OK => {
2626 defer os.windows.ole32.CoTaskMemFree(@ptrCast(*c_void, dir_path_ptr));
27 const global_dir = unicode.utf16leToUtf8Alloc(allocator, mem.toSliceConst(u16, dir_path_ptr)) catch |err| switch (err) {
27 const global_dir = unicode.utf16leToUtf8Alloc(allocator, mem.spanZ(dir_path_ptr)) catch |err| switch (err) {
2828 error.UnexpectedSecondSurrogateHalf => return error.AppDataDirUnavailable,
2929 error.ExpectedSecondSurrogateHalf => return error.AppDataDirUnavailable,
3030 error.DanglingSurrogateHalf => return error.AppDataDirUnavailable,
lib/std/fs/path.zig+14-8
......@@ -128,11 +128,13 @@ test "join" {
128128 testJoinPosix(&[_][]const u8{ "a/", "/c" }, "a/c");
129129}
130130
131pub fn isAbsoluteC(path_c: [*:0]const u8) bool {
131pub const isAbsoluteC = @compileError("deprecated: renamed to isAbsoluteZ");
132
133pub fn isAbsoluteZ(path_c: [*:0]const u8) bool {
132134 if (builtin.os.tag == .windows) {
133 return isAbsoluteWindowsC(path_c);
135 return isAbsoluteWindowsZ(path_c);
134136 } else {
135 return isAbsolutePosixC(path_c);
137 return isAbsolutePosixZ(path_c);
136138 }
137139}
138140
......@@ -172,19 +174,23 @@ pub fn isAbsoluteWindows(path: []const u8) bool {
172174}
173175
174176pub fn isAbsoluteWindowsW(path_w: [*:0]const u16) bool {
175 return isAbsoluteWindowsImpl(u16, mem.toSliceConst(u16, path_w));
177 return isAbsoluteWindowsImpl(u16, mem.spanZ(path_w));
176178}
177179
178pub fn isAbsoluteWindowsC(path_c: [*:0]const u8) bool {
179 return isAbsoluteWindowsImpl(u8, mem.toSliceConst(u8, path_c));
180pub const isAbsoluteWindowsC = @compileError("deprecated: renamed to isAbsoluteWindowsZ");
181
182pub fn isAbsoluteWindowsZ(path_c: [*:0]const u8) bool {
183 return isAbsoluteWindowsImpl(u8, mem.spanZ(path_c));
180184}
181185
182186pub fn isAbsolutePosix(path: []const u8) bool {
183187 return path.len > 0 and path[0] == sep_posix;
184188}
185189
186pub fn isAbsolutePosixC(path_c: [*:0]const u8) bool {
187 return isAbsolutePosix(mem.toSliceConst(u8, path_c));
190pub const isAbsolutePosixC = @compileError("deprecated: renamed to isAbsolutePosixZ");
191
192pub fn isAbsolutePosixZ(path_c: [*:0]const u8) bool {
193 return isAbsolutePosix(mem.spanZ(path_c));
188194}
189195
190196test "isAbsoluteWindows" {
lib/std/fs/watch.zig+1-1
......@@ -326,7 +326,7 @@ pub fn Watch(comptime V: type) type {
326326 var basename_with_null_consumed = false;
327327 defer if (!basename_with_null_consumed) self.allocator.free(basename_with_null);
328328
329 const wd = try os.inotify_add_watchC(
329 const wd = try os.inotify_add_watchZ(
330330 self.os_data.inotify_fd,
331331 dirname_with_null.ptr,
332332 os.linux.IN_CLOSE_WRITE | os.linux.IN_ONLYDIR | os.linux.IN_EXCL_UNLINK,
lib/std/heap.zig+1-2
......@@ -51,8 +51,7 @@ var wasm_page_allocator_state = Allocator{
5151 .shrinkFn = WasmPageAllocator.shrink,
5252};
5353
54/// Deprecated. Use `page_allocator`.
55pub const direct_allocator = page_allocator;
54pub const direct_allocator = @compileError("deprecated; use std.heap.page_allocator");
5655
5756const PageAllocator = struct {
5857 fn alloc(allocator: *Allocator, n: usize, alignment: u29) error{OutOfMemory}![]u8 {
lib/std/http/headers.zig+8-8
......@@ -129,7 +129,7 @@ pub const Headers = struct {
129129 self.index.deinit();
130130 }
131131 {
132 for (self.data.toSliceConst()) |entry| {
132 for (self.data.span()) |entry| {
133133 entry.deinit();
134134 }
135135 self.data.deinit();
......@@ -141,14 +141,14 @@ pub const Headers = struct {
141141 errdefer other.deinit();
142142 try other.data.ensureCapacity(self.data.len);
143143 try other.index.initCapacity(self.index.entries.len);
144 for (self.data.toSliceConst()) |entry| {
144 for (self.data.span()) |entry| {
145145 try other.append(entry.name, entry.value, entry.never_index);
146146 }
147147 return other;
148148 }
149149
150150 pub fn toSlice(self: Self) []const HeaderEntry {
151 return self.data.toSliceConst();
151 return self.data.span();
152152 }
153153
154154 pub fn append(self: *Self, name: []const u8, value: []const u8, never_index: ?bool) !void {
......@@ -279,7 +279,7 @@ pub const Headers = struct {
279279
280280 const buf = try allocator.alloc(HeaderEntry, dex.len);
281281 var n: usize = 0;
282 for (dex.toSliceConst()) |idx| {
282 for (dex.span()) |idx| {
283283 buf[n] = self.data.at(idx);
284284 n += 1;
285285 }
......@@ -302,7 +302,7 @@ pub const Headers = struct {
302302 // adapted from mem.join
303303 const total_len = blk: {
304304 var sum: usize = dex.len - 1; // space for separator(s)
305 for (dex.toSliceConst()) |idx|
305 for (dex.span()) |idx|
306306 sum += self.data.at(idx).value.len;
307307 break :blk sum;
308308 };
......@@ -334,7 +334,7 @@ pub const Headers = struct {
334334 }
335335 }
336336 { // fill up indexes again; we know capacity is fine from before
337 for (self.data.toSliceConst()) |entry, i| {
337 for (self.data.span()) |entry, i| {
338338 var dex = &self.index.get(entry.name).?.value;
339339 dex.appendAssumeCapacity(i);
340340 }
......@@ -495,8 +495,8 @@ test "Headers.getIndices" {
495495 try h.append("set-cookie", "y=2", null);
496496
497497 testing.expect(null == h.getIndices("not-present"));
498 testing.expectEqualSlices(usize, &[_]usize{0}, h.getIndices("foo").?.toSliceConst());
499 testing.expectEqualSlices(usize, &[_]usize{ 1, 2 }, h.getIndices("set-cookie").?.toSliceConst());
498 testing.expectEqualSlices(usize, &[_]usize{0}, h.getIndices("foo").?.span());
499 testing.expectEqualSlices(usize, &[_]usize{ 1, 2 }, h.getIndices("set-cookie").?.span());
500500}
501501
502502test "Headers.get" {
lib/std/io.zig+3-10
......@@ -128,16 +128,6 @@ pub const BufferedAtomicFile = @import("io/buffered_atomic_file.zig").BufferedAt
128128
129129pub const StreamSource = @import("io/stream_source.zig").StreamSource;
130130
131/// Deprecated; use `std.fs.Dir.writeFile`.
132pub fn writeFile(path: []const u8, data: []const u8) !void {
133 return fs.cwd().writeFile(path, data);
134}
135
136/// Deprecated; use `std.fs.Dir.readFileAlloc`.
137pub fn readFileAlloc(allocator: *mem.Allocator, path: []const u8) ![]u8 {
138 return fs.cwd().readFileAlloc(allocator, path, math.maxInt(usize));
139}
140
141131/// An OutStream that doesn't write to anything.
142132pub const null_out_stream = @as(NullOutStream, .{ .context = {} });
143133
......@@ -153,3 +143,6 @@ test "null_out_stream" {
153143test "" {
154144 _ = @import("io/test.zig");
155145}
146
147pub const writeFile = @compileError("deprecated: use std.fs.Dir.writeFile with math.maxInt(usize)");
148pub const readFileAlloc = @compileError("deprecated: use std.fs.Dir.readFileAlloc");
lib/std/io/buffered_atomic_file.zig+2-1
......@@ -15,6 +15,7 @@ pub const BufferedAtomicFile = struct {
1515
1616 /// TODO when https://github.com/ziglang/zig/issues/2761 is solved
1717 /// this API will not need an allocator
18 /// TODO integrate this with Dir API
1819 pub fn create(allocator: *mem.Allocator, dest_path: []const u8) !*BufferedAtomicFile {
1920 var self = try allocator.create(BufferedAtomicFile);
2021 self.* = BufferedAtomicFile{
......@@ -25,7 +26,7 @@ pub const BufferedAtomicFile = struct {
2526 };
2627 errdefer allocator.destroy(self);
2728
28 self.atomic_file = try fs.AtomicFile.init(dest_path, File.default_mode);
29 self.atomic_file = try fs.cwd().atomicFile(dest_path, .{});
2930 errdefer self.atomic_file.deinit();
3031
3132 self.file_stream = self.atomic_file.file.outStream();
lib/std/io/c_out_stream.zig+1-1
......@@ -36,7 +36,7 @@ test "" {
3636 const out_file = std.c.fopen(filename, "w") orelse return error.UnableToOpenTestFile;
3737 defer {
3838 _ = std.c.fclose(out_file);
39 fs.cwd().deleteFileC(filename) catch {};
39 fs.cwd().deleteFileZ(filename) catch {};
4040 }
4141
4242 const out_stream = &io.COutStream.init(out_file).stream;
lib/std/io/in_stream.zig+1-7
......@@ -48,13 +48,7 @@ pub fn InStream(
4848 if (amt_read < buf.len) return error.EndOfStream;
4949 }
5050
51 /// Deprecated: use `readAllArrayList`.
52 pub fn readAllBuffer(self: Self, buffer: *Buffer, max_size: usize) !void {
53 buffer.list.shrink(0);
54 try self.readAllArrayList(&buffer.list, max_size);
55 errdefer buffer.shrink(0);
56 try buffer.list.append(0);
57 }
51 pub const readAllBuffer = @compileError("deprecated; use readAllArrayList()");
5852
5953 /// Appends to the `std.ArrayList` contents by reading from the stream until end of stream is found.
6054 /// If the number of bytes appended would exceed `max_append_size`, `error.StreamTooLong` is returned
lib/std/json.zig+1-1
......@@ -1944,7 +1944,7 @@ pub const Parser = struct {
19441944 }
19451945
19461946 fn pushToParent(p: *Parser, value: *const Value) !void {
1947 switch (p.stack.toSlice()[p.stack.len - 1]) {
1947 switch (p.stack.span()[p.stack.len - 1]) {
19481948 // Object Parent -> [ ..., object, <key>, value ]
19491949 Value.String => |key| {
19501950 _ = p.stack.pop();
lib/std/json/write_stream.zig+1-1
......@@ -211,7 +211,7 @@ pub fn WriteStream(comptime OutStream: type, comptime max_depth: usize) type {
211211 .String => |inner| try self.emitString(inner),
212212 .Array => |inner| {
213213 try self.beginArray();
214 for (inner.toSliceConst()) |elem| {
214 for (inner.span()) |elem| {
215215 try self.arrayElem();
216216 try self.emitJson(elem);
217217 }
lib/std/mem.zig+2-9
......@@ -492,15 +492,8 @@ pub fn eql(comptime T: type, a: []const T, b: []const T) bool {
492492 return true;
493493}
494494
495/// Deprecated. Use `spanZ`.
496pub fn toSliceConst(comptime T: type, ptr: [*:0]const T) [:0]const T {
497 return ptr[0..lenZ(ptr) :0];
498}
499
500/// Deprecated. Use `spanZ`.
501pub fn toSlice(comptime T: type, ptr: [*:0]T) [:0]T {
502 return ptr[0..lenZ(ptr) :0];
503}
495pub const toSliceConst = @compileError("deprecated; use std.mem.spanZ");
496pub const toSlice = @compileError("deprecated; use std.mem.spanZ");
504497
505498/// Takes a pointer to an array, a sentinel-terminated pointer, or a slice, and
506499/// returns a slice. If there is a sentinel on the input type, there will be a
lib/std/net.zig+13-13
......@@ -490,7 +490,7 @@ pub fn getAddressList(allocator: *mem.Allocator, name: []const u8, port: u16) !*
490490
491491 if (info.canonname) |n| {
492492 if (result.canon_name == null) {
493 result.canon_name = try mem.dupe(arena, u8, mem.toSliceConst(u8, n));
493 result.canon_name = try mem.dupe(arena, u8, mem.spanZ(n));
494494 }
495495 }
496496 i += 1;
......@@ -514,7 +514,7 @@ pub fn getAddressList(allocator: *mem.Allocator, name: []const u8, port: u16) !*
514514 result.canon_name = canon.toOwnedSlice();
515515 }
516516
517 for (lookup_addrs.toSliceConst()) |lookup_addr, i| {
517 for (lookup_addrs.span()) |lookup_addr, i| {
518518 result.addrs[i] = lookup_addr.addr;
519519 assert(result.addrs[i].getPort() == port);
520520 }
......@@ -567,7 +567,7 @@ fn linuxLookupName(
567567 // No further processing is needed if there are fewer than 2
568568 // results or if there are only IPv4 results.
569569 if (addrs.len == 1 or family == os.AF_INET) return;
570 const all_ip4 = for (addrs.toSliceConst()) |addr| {
570 const all_ip4 = for (addrs.span()) |addr| {
571571 if (addr.addr.any.family != os.AF_INET) break false;
572572 } else true;
573573 if (all_ip4) return;
......@@ -579,7 +579,7 @@ fn linuxLookupName(
579579 // So far the label/precedence table cannot be customized.
580580 // This implementation is ported from musl libc.
581581 // A more idiomatic "ziggy" implementation would be welcome.
582 for (addrs.toSlice()) |*addr, i| {
582 for (addrs.span()) |*addr, i| {
583583 var key: i32 = 0;
584584 var sa6: os.sockaddr_in6 = undefined;
585585 @memset(@ptrCast([*]u8, &sa6), 0, @sizeOf(os.sockaddr_in6));
......@@ -644,7 +644,7 @@ fn linuxLookupName(
644644 key |= (MAXADDRS - @intCast(i32, i)) << DAS_ORDER_SHIFT;
645645 addr.sortkey = key;
646646 }
647 std.sort.sort(LookupAddr, addrs.toSlice(), addrCmpLessThan);
647 std.sort.sort(LookupAddr, addrs.span(), addrCmpLessThan);
648648}
649649
650650const Policy = struct {
......@@ -803,7 +803,7 @@ fn linuxLookupNameFromHosts(
803803 family: os.sa_family_t,
804804 port: u16,
805805) !void {
806 const file = fs.openFileAbsoluteC("/etc/hosts", .{}) catch |err| switch (err) {
806 const file = fs.openFileAbsoluteZ("/etc/hosts", .{}) catch |err| switch (err) {
807807 error.FileNotFound,
808808 error.NotDir,
809809 error.AccessDenied,
......@@ -887,7 +887,7 @@ fn linuxLookupNameFromDnsSearch(
887887 const search = if (rc.search.isNull() or dots >= rc.ndots or mem.endsWith(u8, name, "."))
888888 &[_]u8{}
889889 else
890 rc.search.toSliceConst();
890 rc.search.span();
891891
892892 var canon_name = name;
893893
......@@ -900,14 +900,14 @@ fn linuxLookupNameFromDnsSearch(
900900 // name is not a CNAME record) and serves as a buffer for passing
901901 // the full requested name to name_from_dns.
902902 try canon.resize(canon_name.len);
903 mem.copy(u8, canon.toSlice(), canon_name);
903 mem.copy(u8, canon.span(), canon_name);
904904 try canon.appendByte('.');
905905
906906 var tok_it = mem.tokenize(search, " \t");
907907 while (tok_it.next()) |tok| {
908908 canon.shrink(canon_name.len + 1);
909909 try canon.append(tok);
910 try linuxLookupNameFromDns(addrs, canon, canon.toSliceConst(), family, rc, port);
910 try linuxLookupNameFromDns(addrs, canon, canon.span(), family, rc, port);
911911 if (addrs.len != 0) return;
912912 }
913913
......@@ -1000,7 +1000,7 @@ fn getResolvConf(allocator: *mem.Allocator, rc: *ResolvConf) !void {
10001000 };
10011001 errdefer rc.deinit();
10021002
1003 const file = fs.openFileAbsoluteC("/etc/resolv.conf", .{}) catch |err| switch (err) {
1003 const file = fs.openFileAbsoluteZ("/etc/resolv.conf", .{}) catch |err| switch (err) {
10041004 error.FileNotFound,
10051005 error.NotDir,
10061006 error.AccessDenied,
......@@ -1079,9 +1079,9 @@ fn resMSendRc(
10791079 defer ns_list.deinit();
10801080
10811081 try ns_list.resize(rc.ns.len);
1082 const ns = ns_list.toSlice();
1082 const ns = ns_list.span();
10831083
1084 for (rc.ns.toSliceConst()) |iplit, i| {
1084 for (rc.ns.span()) |iplit, i| {
10851085 ns[i] = iplit.addr;
10861086 assert(ns[i].getPort() == 53);
10871087 if (iplit.addr.any.family != os.AF_INET) {
......@@ -1265,7 +1265,7 @@ fn dnsParseCallback(ctx: dpc_ctx, rr: u8, data: []const u8, packet: []const u8)
12651265 var tmp: [256]u8 = undefined;
12661266 // Returns len of compressed name. strlen to get canon name.
12671267 _ = try os.dn_expand(packet, data, &tmp);
1268 const canon_name = mem.toSliceConst(u8, @ptrCast([*:0]const u8, &tmp));
1268 const canon_name = mem.spanZ(@ptrCast([*:0]const u8, &tmp));
12691269 if (isValidHostName(canon_name)) {
12701270 try ctx.canon.replaceContents(canon_name);
12711271 }
lib/std/os.zig+85-55
......@@ -163,7 +163,7 @@ pub fn getrandom(buffer: []u8) GetRandomError!void {
163163}
164164
165165fn getRandomBytesDevURandom(buf: []u8) !void {
166 const fd = try openC("/dev/urandom", O_RDONLY | O_CLOEXEC, 0);
166 const fd = try openZ("/dev/urandom", O_RDONLY | O_CLOEXEC, 0);
167167 defer close(fd);
168168
169169 const st = try fstat(fd);
......@@ -853,13 +853,15 @@ pub const OpenError = error{
853853/// TODO support windows
854854pub fn open(file_path: []const u8, flags: u32, perm: usize) OpenError!fd_t {
855855 const file_path_c = try toPosixPath(file_path);
856 return openC(&file_path_c, flags, perm);
856 return openZ(&file_path_c, flags, perm);
857857}
858858
859pub const openC = @compileError("deprecated: renamed to openZ");
860
859861/// Open and possibly create a file. Keeps trying if it gets interrupted.
860862/// See also `open`.
861863/// TODO support windows
862pub fn openC(file_path: [*:0]const u8, flags: u32, perm: usize) OpenError!fd_t {
864pub fn openZ(file_path: [*:0]const u8, flags: u32, perm: usize) OpenError!fd_t {
863865 while (true) {
864866 const rc = system.open(file_path, flags, perm);
865867 switch (errno(rc)) {
......@@ -895,14 +897,16 @@ pub fn openC(file_path: [*:0]const u8, flags: u32, perm: usize) OpenError!fd_t {
895897/// TODO support windows
896898pub fn openat(dir_fd: fd_t, file_path: []const u8, flags: u32, mode: mode_t) OpenError!fd_t {
897899 const file_path_c = try toPosixPath(file_path);
898 return openatC(dir_fd, &file_path_c, flags, mode);
900 return openatZ(dir_fd, &file_path_c, flags, mode);
899901}
900902
903pub const openatC = @compileError("deprecated: renamed to openatZ");
904
901905/// Open and possibly create a file. Keeps trying if it gets interrupted.
902906/// `file_path` is relative to the open directory handle `dir_fd`.
903907/// See also `openat`.
904908/// TODO support windows
905pub fn openatC(dir_fd: fd_t, file_path: [*:0]const u8, flags: u32, mode: mode_t) OpenError!fd_t {
909pub fn openatZ(dir_fd: fd_t, file_path: [*:0]const u8, flags: u32, mode: mode_t) OpenError!fd_t {
906910 while (true) {
907911 const rc = system.openat(dir_fd, file_path, flags, mode);
908912 switch (errno(rc)) {
......@@ -959,8 +963,7 @@ pub const ExecveError = error{
959963 NameTooLong,
960964} || UnexpectedError;
961965
962/// Deprecated in favor of `execveZ`.
963pub const execveC = execveZ;
966pub const execveC = @compileError("deprecated: use execveZ");
964967
965968/// Like `execve` except the parameters are null-terminated,
966969/// matching the syscall API on all targets. This removes the need for an allocator.
......@@ -992,8 +995,7 @@ pub fn execveZ(
992995 }
993996}
994997
995/// Deprecated in favor of `execvpeZ`.
996pub const execvpeC = execvpeZ;
998pub const execvpeC = @compileError("deprecated in favor of execvpeZ");
997999
9981000pub const Arg0Expand = enum {
9991001 expand,
......@@ -1012,7 +1014,7 @@ pub fn execvpeZ_expandArg0(
10121014 },
10131015 envp: [*:null]const ?[*:0]const u8,
10141016) ExecveError {
1015 const file_slice = mem.toSliceConst(u8, file);
1017 const file_slice = mem.spanZ(file);
10161018 if (mem.indexOfScalar(u8, file_slice, '/') != null) return execveZ(file, child_argv, envp);
10171019
10181020 const PATH = getenvZ("PATH") orelse "/usr/local/bin:/bin/:/usr/bin";
......@@ -1076,7 +1078,7 @@ pub fn execvpe_expandArg0(
10761078 mem.set(?[*:0]u8, argv_buf, null);
10771079 defer {
10781080 for (argv_buf) |arg| {
1079 const arg_buf = if (arg) |ptr| mem.toSlice(u8, ptr) else break;
1081 const arg_buf = if (arg) |ptr| mem.spanZ(ptr) else break;
10801082 allocator.free(arg_buf);
10811083 }
10821084 allocator.free(argv_buf);
......@@ -1189,20 +1191,19 @@ pub fn getenv(key: []const u8) ?[]const u8 {
11891191 return null;
11901192}
11911193
1192/// Deprecated in favor of `getenvZ`.
1193pub const getenvC = getenvZ;
1194pub const getenvC = @compileError("Deprecated in favor of `getenvZ`");
11941195
11951196/// Get an environment variable with a null-terminated name.
11961197/// See also `getenv`.
11971198pub fn getenvZ(key: [*:0]const u8) ?[]const u8 {
11981199 if (builtin.link_libc) {
11991200 const value = system.getenv(key) orelse return null;
1200 return mem.toSliceConst(u8, value);
1201 return mem.spanZ(value);
12011202 }
12021203 if (builtin.os.tag == .windows) {
12031204 @compileError("std.os.getenvZ is unavailable for Windows because environment string is in WTF-16 format. See std.process.getEnvVarOwned for cross-platform API or std.os.getenvW for Windows-specific API.");
12041205 }
1205 return getenv(mem.toSliceConst(u8, key));
1206 return getenv(mem.spanZ(key));
12061207}
12071208
12081209/// Windows-only. Get an environment variable with a null-terminated, WTF-16 encoded name.
......@@ -1211,7 +1212,7 @@ pub fn getenvW(key: [*:0]const u16) ?[:0]const u16 {
12111212 if (builtin.os.tag != .windows) {
12121213 @compileError("std.os.getenvW is a Windows-only API");
12131214 }
1214 const key_slice = mem.toSliceConst(u16, key);
1215 const key_slice = mem.spanZ(key);
12151216 const ptr = windows.peb().ProcessParameters.Environment;
12161217 var i: usize = 0;
12171218 while (ptr[i] != 0) {
......@@ -1250,7 +1251,7 @@ pub fn getcwd(out_buffer: []u8) GetCwdError![]u8 {
12501251 break :blk errno(system.getcwd(out_buffer.ptr, out_buffer.len));
12511252 };
12521253 switch (err) {
1253 0 => return mem.toSlice(u8, @ptrCast([*:0]u8, out_buffer.ptr)),
1254 0 => return mem.spanZ(@ptrCast([*:0]u8, out_buffer.ptr)),
12541255 EFAULT => unreachable,
12551256 EINVAL => unreachable,
12561257 ENOENT => return error.CurrentWorkingDirectoryUnlinked,
......@@ -1288,13 +1289,15 @@ pub fn symlink(target_path: []const u8, sym_link_path: []const u8) SymLinkError!
12881289 } else {
12891290 const target_path_c = try toPosixPath(target_path);
12901291 const sym_link_path_c = try toPosixPath(sym_link_path);
1291 return symlinkC(&target_path_c, &sym_link_path_c);
1292 return symlinkZ(&target_path_c, &sym_link_path_c);
12921293 }
12931294}
12941295
1296pub const symlinkC = @compileError("deprecated: renamed to symlinkZ");
1297
12951298/// This is the same as `symlink` except the parameters are null-terminated pointers.
12961299/// See also `symlink`.
1297pub fn symlinkC(target_path: [*:0]const u8, sym_link_path: [*:0]const u8) SymLinkError!void {
1300pub fn symlinkZ(target_path: [*:0]const u8, sym_link_path: [*:0]const u8) SymLinkError!void {
12981301 if (builtin.os.tag == .windows) {
12991302 const target_path_w = try windows.cStrToPrefixedFileW(target_path);
13001303 const sym_link_path_w = try windows.cStrToPrefixedFileW(sym_link_path);
......@@ -1323,10 +1326,12 @@ pub fn symlinkC(target_path: [*:0]const u8, sym_link_path: [*:0]const u8) SymLin
13231326pub fn symlinkat(target_path: []const u8, newdirfd: fd_t, sym_link_path: []const u8) SymLinkError!void {
13241327 const target_path_c = try toPosixPath(target_path);
13251328 const sym_link_path_c = try toPosixPath(sym_link_path);
1326 return symlinkatC(target_path_c, newdirfd, sym_link_path_c);
1329 return symlinkatZ(target_path_c, newdirfd, sym_link_path_c);
13271330}
13281331
1329pub fn symlinkatC(target_path: [*:0]const u8, newdirfd: fd_t, sym_link_path: [*:0]const u8) SymLinkError!void {
1332pub const symlinkatC = @compileError("deprecated: renamed to symlinkatZ");
1333
1334pub fn symlinkatZ(target_path: [*:0]const u8, newdirfd: fd_t, sym_link_path: [*:0]const u8) SymLinkError!void {
13301335 switch (errno(system.symlinkat(target_path, newdirfd, sym_link_path))) {
13311336 0 => return,
13321337 EFAULT => unreachable,
......@@ -1375,12 +1380,14 @@ pub fn unlink(file_path: []const u8) UnlinkError!void {
13751380 return windows.DeleteFileW(&file_path_w);
13761381 } else {
13771382 const file_path_c = try toPosixPath(file_path);
1378 return unlinkC(&file_path_c);
1383 return unlinkZ(&file_path_c);
13791384 }
13801385}
13811386
1387pub const unlinkC = @compileError("deprecated: renamed to unlinkZ");
1388
13821389/// Same as `unlink` except the parameter is a null terminated UTF8-encoded string.
1383pub fn unlinkC(file_path: [*:0]const u8) UnlinkError!void {
1390pub fn unlinkZ(file_path: [*:0]const u8) UnlinkError!void {
13841391 if (builtin.os.tag == .windows) {
13851392 const file_path_w = try windows.cStrToPrefixedFileW(file_path);
13861393 return windows.DeleteFileW(&file_path_w);
......@@ -1417,11 +1424,13 @@ pub fn unlinkat(dirfd: fd_t, file_path: []const u8, flags: u32) UnlinkatError!vo
14171424 return unlinkatW(dirfd, &file_path_w, flags);
14181425 }
14191426 const file_path_c = try toPosixPath(file_path);
1420 return unlinkatC(dirfd, &file_path_c, flags);
1427 return unlinkatZ(dirfd, &file_path_c, flags);
14211428}
14221429
1430pub const unlinkatC = @compileError("deprecated: renamed to unlinkatZ");
1431
14231432/// Same as `unlinkat` but `file_path` is a null-terminated string.
1424pub fn unlinkatC(dirfd: fd_t, file_path_c: [*:0]const u8, flags: u32) UnlinkatError!void {
1433pub fn unlinkatZ(dirfd: fd_t, file_path_c: [*:0]const u8, flags: u32) UnlinkatError!void {
14251434 if (builtin.os.tag == .windows) {
14261435 const file_path_w = try windows.cStrToPrefixedFileW(file_path_c);
14271436 return unlinkatW(dirfd, &file_path_w, flags);
......@@ -1459,7 +1468,7 @@ pub fn unlinkatW(dirfd: fd_t, sub_path_w: [*:0]const u16, flags: u32) UnlinkatEr
14591468 else
14601469 @as(w.ULONG, w.FILE_DELETE_ON_CLOSE | w.FILE_NON_DIRECTORY_FILE);
14611470
1462 const path_len_bytes = @intCast(u16, mem.toSliceConst(u16, sub_path_w).len * 2);
1471 const path_len_bytes = @intCast(u16, mem.lenZ(sub_path_w) * 2);
14631472 var nt_name = w.UNICODE_STRING{
14641473 .Length = path_len_bytes,
14651474 .MaximumLength = path_len_bytes,
......@@ -1543,12 +1552,14 @@ pub fn rename(old_path: []const u8, new_path: []const u8) RenameError!void {
15431552 } else {
15441553 const old_path_c = try toPosixPath(old_path);
15451554 const new_path_c = try toPosixPath(new_path);
1546 return renameC(&old_path_c, &new_path_c);
1555 return renameZ(&old_path_c, &new_path_c);
15471556 }
15481557}
15491558
1559pub const renameC = @compileError("deprecated: renamed to renameZ");
1560
15501561/// Same as `rename` except the parameters are null-terminated byte arrays.
1551pub fn renameC(old_path: [*:0]const u8, new_path: [*:0]const u8) RenameError!void {
1562pub fn renameZ(old_path: [*:0]const u8, new_path: [*:0]const u8) RenameError!void {
15521563 if (builtin.os.tag == .windows) {
15531564 const old_path_w = try windows.cStrToPrefixedFileW(old_path);
15541565 const new_path_w = try windows.cStrToPrefixedFileW(new_path);
......@@ -1715,11 +1726,13 @@ pub fn mkdirat(dir_fd: fd_t, sub_dir_path: []const u8, mode: u32) MakeDirError!v
17151726 return mkdiratW(dir_fd, &sub_dir_path_w, mode);
17161727 } else {
17171728 const sub_dir_path_c = try toPosixPath(sub_dir_path);
1718 return mkdiratC(dir_fd, &sub_dir_path_c, mode);
1729 return mkdiratZ(dir_fd, &sub_dir_path_c, mode);
17191730 }
17201731}
17211732
1722pub fn mkdiratC(dir_fd: fd_t, sub_dir_path: [*:0]const u8, mode: u32) MakeDirError!void {
1733pub const mkdiratC = @compileError("deprecated: renamed to mkdiratZ");
1734
1735pub fn mkdiratZ(dir_fd: fd_t, sub_dir_path: [*:0]const u8, mode: u32) MakeDirError!void {
17231736 if (builtin.os.tag == .windows) {
17241737 const sub_dir_path_w = try windows.cStrToPrefixedFileW(sub_dir_path);
17251738 return mkdiratW(dir_fd, &sub_dir_path_w, mode);
......@@ -1810,12 +1823,14 @@ pub fn rmdir(dir_path: []const u8) DeleteDirError!void {
18101823 return windows.RemoveDirectoryW(&dir_path_w);
18111824 } else {
18121825 const dir_path_c = try toPosixPath(dir_path);
1813 return rmdirC(&dir_path_c);
1826 return rmdirZ(&dir_path_c);
18141827 }
18151828}
18161829
1830pub const rmdirC = @compileError("deprecated: renamed to rmdirZ");
1831
18171832/// Same as `rmdir` except the parameter is null-terminated.
1818pub fn rmdirC(dir_path: [*:0]const u8) DeleteDirError!void {
1833pub fn rmdirZ(dir_path: [*:0]const u8) DeleteDirError!void {
18191834 if (builtin.os.tag == .windows) {
18201835 const dir_path_w = try windows.cStrToPrefixedFileW(dir_path);
18211836 return windows.RemoveDirectoryW(&dir_path_w);
......@@ -1857,12 +1872,14 @@ pub fn chdir(dir_path: []const u8) ChangeCurDirError!void {
18571872 @compileError("TODO implement chdir for Windows");
18581873 } else {
18591874 const dir_path_c = try toPosixPath(dir_path);
1860 return chdirC(&dir_path_c);
1875 return chdirZ(&dir_path_c);
18611876 }
18621877}
18631878
1879pub const chdirC = @compileError("deprecated: renamed to chdirZ");
1880
18641881/// Same as `chdir` except the parameter is null-terminated.
1865pub fn chdirC(dir_path: [*:0]const u8) ChangeCurDirError!void {
1882pub fn chdirZ(dir_path: [*:0]const u8) ChangeCurDirError!void {
18661883 if (builtin.os.tag == .windows) {
18671884 const dir_path_w = try windows.cStrToPrefixedFileW(dir_path);
18681885 @compileError("TODO implement chdir for Windows");
......@@ -1919,12 +1936,14 @@ pub fn readlink(file_path: []const u8, out_buffer: []u8) ReadLinkError![]u8 {
19191936 @compileError("TODO implement readlink for Windows");
19201937 } else {
19211938 const file_path_c = try toPosixPath(file_path);
1922 return readlinkC(&file_path_c, out_buffer);
1939 return readlinkZ(&file_path_c, out_buffer);
19231940 }
19241941}
19251942
1943pub const readlinkC = @compileError("deprecated: renamed to readlinkZ");
1944
19261945/// Same as `readlink` except `file_path` is null-terminated.
1927pub fn readlinkC(file_path: [*:0]const u8, out_buffer: []u8) ReadLinkError![]u8 {
1946pub fn readlinkZ(file_path: [*:0]const u8, out_buffer: []u8) ReadLinkError![]u8 {
19281947 if (builtin.os.tag == .windows) {
19291948 const file_path_w = try windows.cStrToPrefixedFileW(file_path);
19301949 @compileError("TODO implement readlink for Windows");
......@@ -1945,7 +1964,9 @@ pub fn readlinkC(file_path: [*:0]const u8, out_buffer: []u8) ReadLinkError![]u8
19451964 }
19461965}
19471966
1948pub fn readlinkatC(dirfd: fd_t, file_path: [*:0]const u8, out_buffer: []u8) ReadLinkError![]u8 {
1967pub const readlinkatC = @compileError("deprecated: renamed to readlinkatZ");
1968
1969pub fn readlinkatZ(dirfd: fd_t, file_path: [*:0]const u8, out_buffer: []u8) ReadLinkError![]u8 {
19491970 if (builtin.os.tag == .windows) {
19501971 const file_path_w = try windows.cStrToPrefixedFileW(file_path);
19511972 @compileError("TODO implement readlink for Windows");
......@@ -2553,10 +2574,12 @@ const FStatAtError = FStatError || error{NameTooLong};
25532574
25542575pub fn fstatat(dirfd: fd_t, pathname: []const u8, flags: u32) FStatAtError![]Stat {
25552576 const pathname_c = try toPosixPath(pathname);
2556 return fstatatC(dirfd, &pathname_c, flags);
2577 return fstatatZ(dirfd, &pathname_c, flags);
25572578}
25582579
2559pub fn fstatatC(dirfd: fd_t, pathname: [*:0]const u8, flags: u32) FStatAtError!Stat {
2580pub const fstatatC = @compileError("deprecated: renamed to fstatatZ");
2581
2582pub fn fstatatZ(dirfd: fd_t, pathname: [*:0]const u8, flags: u32) FStatAtError!Stat {
25602583 var stat: Stat = undefined;
25612584 switch (errno(system.fstatat(dirfd, pathname, &stat, flags))) {
25622585 0 => return stat,
......@@ -2668,11 +2691,13 @@ pub const INotifyAddWatchError = error{
26682691/// add a watch to an initialized inotify instance
26692692pub fn inotify_add_watch(inotify_fd: i32, pathname: []const u8, mask: u32) INotifyAddWatchError!i32 {
26702693 const pathname_c = try toPosixPath(pathname);
2671 return inotify_add_watchC(inotify_fd, &pathname_c, mask);
2694 return inotify_add_watchZ(inotify_fd, &pathname_c, mask);
26722695}
26732696
2697pub const inotify_add_watchC = @compileError("deprecated: renamed to inotify_add_watchZ");
2698
26742699/// Same as `inotify_add_watch` except pathname is null-terminated.
2675pub fn inotify_add_watchC(inotify_fd: i32, pathname: [*:0]const u8, mask: u32) INotifyAddWatchError!i32 {
2700pub fn inotify_add_watchZ(inotify_fd: i32, pathname: [*:0]const u8, mask: u32) INotifyAddWatchError!i32 {
26762701 const rc = system.inotify_add_watch(inotify_fd, pathname, mask);
26772702 switch (errno(rc)) {
26782703 0 => return @intCast(i32, rc),
......@@ -2829,11 +2854,10 @@ pub fn access(path: []const u8, mode: u32) AccessError!void {
28292854 return;
28302855 }
28312856 const path_c = try toPosixPath(path);
2832 return accessC(&path_c, mode);
2857 return accessZ(&path_c, mode);
28332858}
28342859
2835/// Deprecated in favor of `accessZ`.
2836pub const accessC = accessZ;
2860pub const accessC = @compileError("Deprecated in favor of `accessZ`");
28372861
28382862/// Same as `access` except `path` is null-terminated.
28392863pub fn accessZ(path: [*:0]const u8, mode: u32) AccessError!void {
......@@ -2920,7 +2944,7 @@ pub fn faccessatW(dirfd: fd_t, sub_path_w: [*:0]const u16, mode: u32, flags: u32
29202944 return;
29212945 }
29222946
2923 const path_len_bytes = math.cast(u16, mem.toSliceConst(u16, sub_path_w).len * 2) catch |err| switch (err) {
2947 const path_len_bytes = math.cast(u16, mem.lenZ(sub_path_w) * 2) catch |err| switch (err) {
29242948 error.Overflow => return error.NameTooLong,
29252949 };
29262950 var nt_name = windows.UNICODE_STRING{
......@@ -3019,7 +3043,9 @@ pub fn sysctl(
30193043 }
30203044}
30213045
3022pub fn sysctlbynameC(
3046pub const sysctlbynameC = @compileError("deprecated: renamed to sysctlbynameZ");
3047
3048pub fn sysctlbynameZ(
30233049 name: [*:0]const u8,
30243050 oldp: ?*c_void,
30253051 oldlenp: ?*usize,
......@@ -3224,23 +3250,25 @@ pub fn realpath(pathname: []const u8, out_buffer: *[MAX_PATH_BYTES]u8) RealPathE
32243250 return realpathW(&pathname_w, out_buffer);
32253251 }
32263252 const pathname_c = try toPosixPath(pathname);
3227 return realpathC(&pathname_c, out_buffer);
3253 return realpathZ(&pathname_c, out_buffer);
32283254}
32293255
3256pub const realpathC = @compileError("deprecated: renamed realpathZ");
3257
32303258/// Same as `realpath` except `pathname` is null-terminated.
3231pub fn realpathC(pathname: [*:0]const u8, out_buffer: *[MAX_PATH_BYTES]u8) RealPathError![]u8 {
3259pub fn realpathZ(pathname: [*:0]const u8, out_buffer: *[MAX_PATH_BYTES]u8) RealPathError![]u8 {
32323260 if (builtin.os.tag == .windows) {
32333261 const pathname_w = try windows.cStrToPrefixedFileW(pathname);
32343262 return realpathW(&pathname_w, out_buffer);
32353263 }
32363264 if (builtin.os.tag == .linux and !builtin.link_libc) {
3237 const fd = try openC(pathname, linux.O_PATH | linux.O_NONBLOCK | linux.O_CLOEXEC, 0);
3265 const fd = try openZ(pathname, linux.O_PATH | linux.O_NONBLOCK | linux.O_CLOEXEC, 0);
32383266 defer close(fd);
32393267
32403268 var procfs_buf: ["/proc/self/fd/-2147483648".len:0]u8 = undefined;
32413269 const proc_path = std.fmt.bufPrint(procfs_buf[0..], "/proc/self/fd/{}\x00", .{fd}) catch unreachable;
32423270
3243 return readlinkC(@ptrCast([*:0]const u8, proc_path.ptr), out_buffer);
3271 return readlinkZ(@ptrCast([*:0]const u8, proc_path.ptr), out_buffer);
32443272 }
32453273 const result_path = std.c.realpath(pathname, out_buffer) orelse switch (std.c._errno().*) {
32463274 EINVAL => unreachable,
......@@ -3255,7 +3283,7 @@ pub fn realpathC(pathname: [*:0]const u8, out_buffer: *[MAX_PATH_BYTES]u8) RealP
32553283 EIO => return error.InputOutput,
32563284 else => |err| return unexpectedErrno(@intCast(usize, err)),
32573285 };
3258 return mem.toSlice(u8, result_path);
3286 return mem.spanZ(result_path);
32593287}
32603288
32613289/// Same as `realpath` except `pathname` is null-terminated and UTF16LE-encoded.
......@@ -3564,7 +3592,7 @@ pub const GetHostNameError = error{PermissionDenied} || UnexpectedError;
35643592pub fn gethostname(name_buffer: *[HOST_NAME_MAX]u8) GetHostNameError![]u8 {
35653593 if (builtin.link_libc) {
35663594 switch (errno(system.gethostname(name_buffer, name_buffer.len))) {
3567 0 => return mem.toSlice(u8, @ptrCast([*:0]u8, name_buffer)),
3595 0 => return mem.spanZ(@ptrCast([*:0]u8, name_buffer)),
35683596 EFAULT => unreachable,
35693597 ENAMETOOLONG => unreachable, // HOST_NAME_MAX prevents this
35703598 EPERM => return error.PermissionDenied,
......@@ -3573,7 +3601,7 @@ pub fn gethostname(name_buffer: *[HOST_NAME_MAX]u8) GetHostNameError![]u8 {
35733601 }
35743602 if (builtin.os.tag == .linux) {
35753603 const uts = uname();
3576 const hostname = mem.toSliceConst(u8, @ptrCast([*:0]const u8, &uts.nodename));
3604 const hostname = mem.spanZ(@ptrCast([*:0]const u8, &uts.nodename));
35773605 mem.copy(u8, name_buffer, hostname);
35783606 return name_buffer[0..hostname.len];
35793607 }
......@@ -4260,7 +4288,9 @@ pub const MemFdCreateError = error{
42604288 SystemOutdated,
42614289} || UnexpectedError;
42624290
4263pub fn memfd_createC(name: [*:0]const u8, flags: u32) MemFdCreateError!fd_t {
4291pub const memfd_createC = @compileError("deprecated: renamed to memfd_createZ");
4292
4293pub fn memfd_createZ(name: [*:0]const u8, flags: u32) MemFdCreateError!fd_t {
42644294 // memfd_create is available only in glibc versions starting with 2.27.
42654295 const use_c = std.c.versionCheck(.{ .major = 2, .minor = 27, .patch = 0 }).ok;
42664296 const sys = if (use_c) std.c else linux;
......@@ -4291,7 +4321,7 @@ fn toMemFdPath(name: []const u8) ![MFD_MAX_NAME_LEN:0]u8 {
42914321
42924322pub fn memfd_create(name: []const u8, flags: u32) !fd_t {
42934323 const name_t = try toMemFdPath(name);
4294 return memfd_createC(&name_t, flags);
4324 return memfd_createZ(&name_t, flags);
42954325}
42964326
42974327pub fn getrusage(who: i32) rusage {
lib/std/os/linux/vdso.zig+3-3
......@@ -22,7 +22,7 @@ pub fn lookup(vername: []const u8, name: []const u8) usize {
2222 }) {
2323 const this_ph = @intToPtr(*elf.Phdr, ph_addr);
2424 switch (this_ph.p_type) {
25 // On WSL1 as well as older kernels, the VDSO ELF image is pre-linked in the upper half
25 // On WSL1 as well as older kernels, the VDSO ELF image is pre-linked in the upper half
2626 // of the memory space (e.g. p_vaddr = 0xffffffffff700000 on WSL1).
2727 // Wrapping operations are used on this line as well as subsequent calculations relative to base
2828 // (lines 47, 78) to ensure no overflow check is tripped.
......@@ -70,7 +70,7 @@ pub fn lookup(vername: []const u8, name: []const u8) usize {
7070 if (0 == (@as(u32, 1) << @intCast(u5, syms[i].st_info >> 4) & OK_BINDS)) continue;
7171 if (0 == syms[i].st_shndx) continue;
7272 const sym_name = @ptrCast([*:0]const u8, strings + syms[i].st_name);
73 if (!mem.eql(u8, name, mem.toSliceConst(u8, sym_name))) continue;
73 if (!mem.eql(u8, name, mem.spanZ(sym_name))) continue;
7474 if (maybe_versym) |versym| {
7575 if (!checkver(maybe_verdef.?, versym[i], vername, strings))
7676 continue;
......@@ -93,5 +93,5 @@ fn checkver(def_arg: *elf.Verdef, vsym_arg: i32, vername: []const u8, strings: [
9393 }
9494 const aux = @intToPtr(*elf.Verdaux, @ptrToInt(def) + def.vd_aux);
9595 const vda_name = @ptrCast([*:0]const u8, strings + aux.vda_name);
96 return mem.eql(u8, vername, mem.toSliceConst(u8, vda_name));
96 return mem.eql(u8, vername, mem.spanZ(vda_name));
9797}
lib/std/os/test.zig+8-8
......@@ -18,8 +18,8 @@ const AtomicOrder = builtin.AtomicOrder;
1818
1919test "makePath, put some files in it, deleteTree" {
2020 try fs.cwd().makePath("os_test_tmp" ++ fs.path.sep_str ++ "b" ++ fs.path.sep_str ++ "c");
21 try io.writeFile("os_test_tmp" ++ fs.path.sep_str ++ "b" ++ fs.path.sep_str ++ "c" ++ fs.path.sep_str ++ "file.txt", "nonsense");
22 try io.writeFile("os_test_tmp" ++ fs.path.sep_str ++ "b" ++ fs.path.sep_str ++ "file2.txt", "blah");
21 try fs.cwd().writeFile("os_test_tmp" ++ fs.path.sep_str ++ "b" ++ fs.path.sep_str ++ "c" ++ fs.path.sep_str ++ "file.txt", "nonsense");
22 try fs.cwd().writeFile("os_test_tmp" ++ fs.path.sep_str ++ "b" ++ fs.path.sep_str ++ "file2.txt", "blah");
2323 try fs.cwd().deleteTree("os_test_tmp");
2424 if (fs.cwd().openDir("os_test_tmp", .{})) |dir| {
2525 @panic("expected error");
......@@ -36,8 +36,8 @@ test "access file" {
3636 expect(err == error.FileNotFound);
3737 }
3838
39 try io.writeFile("os_test_tmp" ++ fs.path.sep_str ++ "file.txt", "");
40 try os.access("os_test_tmp" ++ fs.path.sep_str ++ "file.txt", os.F_OK);
39 try fs.cwd().writeFile("os_test_tmp" ++ fs.path.sep_str ++ "file.txt", "");
40 try fs.cwd().access("os_test_tmp" ++ fs.path.sep_str ++ "file.txt", .{});
4141 try fs.cwd().deleteTree("os_test_tmp");
4242}
4343
......@@ -65,12 +65,12 @@ test "sendfile" {
6565 },
6666 };
6767
68 var src_file = try dir.createFileC("sendfile1.txt", .{ .read = true });
68 var src_file = try dir.createFileZ("sendfile1.txt", .{ .read = true });
6969 defer src_file.close();
7070
7171 try src_file.writevAll(&vecs);
7272
73 var dest_file = try dir.createFileC("sendfile2.txt", .{ .read = true });
73 var dest_file = try dir.createFileZ("sendfile2.txt", .{ .read = true });
7474 defer dest_file.close();
7575
7676 const header1 = "header1\n";
......@@ -192,12 +192,12 @@ test "AtomicFile" {
192192 \\ this is a test file
193193 ;
194194 {
195 var af = try fs.AtomicFile.init(test_out_file, File.default_mode);
195 var af = try fs.cwd().atomicFile(test_out_file, .{});
196196 defer af.deinit();
197197 try af.file.writeAll(test_content);
198198 try af.finish();
199199 }
200 const content = try io.readFileAlloc(testing.allocator, test_out_file);
200 const content = try fs.cwd().readFileAlloc(testing.allocator, test_out_file, 9999);
201201 defer testing.allocator.free(content);
202202 expect(mem.eql(u8, content, test_content));
203203
lib/std/os/windows.zig+3-3
......@@ -118,7 +118,7 @@ pub fn OpenFileW(
118118
119119 var result: HANDLE = undefined;
120120
121 const path_len_bytes = math.cast(u16, mem.toSliceConst(u16, sub_path_w).len * 2) catch |err| switch (err) {
121 const path_len_bytes = math.cast(u16, mem.lenZ(sub_path_w) * 2) catch |err| switch (err) {
122122 error.Overflow => return error.NameTooLong,
123123 };
124124 var nt_name = UNICODE_STRING{
......@@ -685,7 +685,7 @@ pub fn CreateDirectoryW(
685685 sub_path_w: [*:0]const u16,
686686 sa: ?*SECURITY_ATTRIBUTES,
687687) CreateDirectoryError!HANDLE {
688 const path_len_bytes = math.cast(u16, mem.toSliceConst(u16, sub_path_w).len * 2) catch |err| switch (err) {
688 const path_len_bytes = math.cast(u16, mem.lenZ(sub_path_w) * 2) catch |err| switch (err) {
689689 error.Overflow => return error.NameTooLong,
690690 };
691691 var nt_name = UNICODE_STRING{
......@@ -1214,7 +1214,7 @@ pub fn nanoSecondsToFileTime(ns: i64) FILETIME {
12141214}
12151215
12161216pub fn cStrToPrefixedFileW(s: [*:0]const u8) ![PATH_MAX_WIDE:0]u16 {
1217 return sliceToPrefixedFileW(mem.toSliceConst(u8, s));
1217 return sliceToPrefixedFileW(mem.spanZ(s));
12181218}
12191219
12201220pub fn sliceToPrefixedFileW(s: []const u8) ![PATH_MAX_WIDE:0]u16 {
lib/std/pdb.zig+1-1
......@@ -649,7 +649,7 @@ const MsfStream = struct {
649649 while (true) {
650650 const byte = try self.inStream().readByte();
651651 if (byte == 0) {
652 return list.toSlice();
652 return list.span();
653653 }
654654 try list.append(byte);
655655 }
lib/std/process.zig+7-7
......@@ -83,7 +83,7 @@ pub fn getEnvMap(allocator: *Allocator) !BufMap {
8383
8484 for (environ) |env| {
8585 if (env) |ptr| {
86 const pair = mem.toSlice(u8, ptr);
86 const pair = mem.spanZ(ptr);
8787 var parts = mem.separate(pair, "=");
8888 const key = parts.next().?;
8989 const value = parts.next().?;
......@@ -176,7 +176,7 @@ pub const ArgIteratorPosix = struct {
176176
177177 const s = os.argv[self.index];
178178 self.index += 1;
179 return mem.toSlice(u8, s);
179 return mem.spanZ(s);
180180 }
181181
182182 pub fn skip(self: *ArgIteratorPosix) bool {
......@@ -401,7 +401,7 @@ pub fn argsAlloc(allocator: *mem.Allocator) ![][]u8 {
401401
402402 var i: usize = 0;
403403 while (i < count) : (i += 1) {
404 result_slice[i] = mem.toSlice(u8, argv[i]);
404 result_slice[i] = mem.spanZ(argv[i]);
405405 }
406406
407407 return result_slice;
......@@ -422,8 +422,8 @@ pub fn argsAlloc(allocator: *mem.Allocator) ![][]u8 {
422422 try slice_list.append(arg.len);
423423 }
424424
425 const contents_slice = contents.toSliceConst();
426 const slice_sizes = slice_list.toSliceConst();
425 const contents_slice = contents.span();
426 const slice_sizes = slice_list.span();
427427 const slice_list_bytes = try math.mul(usize, @sizeOf([]u8), slice_sizes.len);
428428 const total_bytes = try math.add(usize, slice_list_bytes, contents_slice.len);
429429 const buf = try allocator.alignedAlloc(u8, @alignOf([]u8), total_bytes);
......@@ -636,7 +636,7 @@ pub fn getSelfExeSharedLibPaths(allocator: *Allocator) error{OutOfMemory}![][:0]
636636 fn callback(info: *os.dl_phdr_info, size: usize, list: *List) !void {
637637 const name = info.dlpi_name orelse return;
638638 if (name[0] == '/') {
639 const item = try mem.dupeZ(list.allocator, u8, mem.toSliceConst(u8, name));
639 const item = try mem.dupeZ(list.allocator, u8, mem.spanZ(name));
640640 errdefer list.allocator.free(item);
641641 try list.append(item);
642642 }
......@@ -657,7 +657,7 @@ pub fn getSelfExeSharedLibPaths(allocator: *Allocator) error{OutOfMemory}![][:0]
657657 var i: u32 = 0;
658658 while (i < img_count) : (i += 1) {
659659 const name = std.c._dyld_get_image_name(i);
660 const item = try mem.dupeZ(allocator, u8, mem.toSliceConst(u8, name));
660 const item = try mem.dupeZ(allocator, u8, mem.spanZ(name));
661661 errdefer allocator.free(item);
662662 try paths.append(item);
663663 }
lib/std/rand.zig+13-19
......@@ -59,7 +59,7 @@ pub const Random = struct {
5959 return @bitCast(T, unsigned_result);
6060 }
6161
62 /// Constant-time implementation off ::uintLessThan.
62 /// Constant-time implementation off `uintLessThan`.
6363 /// The results of this function may be biased.
6464 pub fn uintLessThanBiased(r: *Random, comptime T: type, less_than: T) T {
6565 comptime assert(T.is_signed == false);
......@@ -73,13 +73,13 @@ pub const Random = struct {
7373 }
7474
7575 /// Returns an evenly distributed random unsigned integer `0 <= i < less_than`.
76 /// This function assumes that the underlying ::fillFn produces evenly distributed values.
76 /// This function assumes that the underlying `fillFn` produces evenly distributed values.
7777 /// Within this assumption, the runtime of this function is exponentially distributed.
78 /// If ::fillFn were backed by a true random generator,
78 /// If `fillFn` were backed by a true random generator,
7979 /// the runtime of this function would technically be unbounded.
80 /// However, if ::fillFn is backed by any evenly distributed pseudo random number generator,
80 /// However, if `fillFn` is backed by any evenly distributed pseudo random number generator,
8181 /// this function is guaranteed to return.
82 /// If you need deterministic runtime bounds, use `::uintLessThanBiased`.
82 /// If you need deterministic runtime bounds, use `uintLessThanBiased`.
8383 pub fn uintLessThan(r: *Random, comptime T: type, less_than: T) T {
8484 comptime assert(T.is_signed == false);
8585 comptime assert(T.bit_count <= 64); // TODO: workaround: LLVM ERROR: Unsupported library call operation!
......@@ -116,7 +116,7 @@ pub const Random = struct {
116116 return @intCast(T, m >> Small.bit_count);
117117 }
118118
119 /// Constant-time implementation off ::uintAtMost.
119 /// Constant-time implementation off `uintAtMost`.
120120 /// The results of this function may be biased.
121121 pub fn uintAtMostBiased(r: *Random, comptime T: type, at_most: T) T {
122122 assert(T.is_signed == false);
......@@ -128,7 +128,7 @@ pub const Random = struct {
128128 }
129129
130130 /// Returns an evenly distributed random unsigned integer `0 <= i <= at_most`.
131 /// See ::uintLessThan, which this function uses in most cases,
131 /// See `uintLessThan`, which this function uses in most cases,
132132 /// for commentary on the runtime of this function.
133133 pub fn uintAtMost(r: *Random, comptime T: type, at_most: T) T {
134134 assert(T.is_signed == false);
......@@ -139,7 +139,7 @@ pub const Random = struct {
139139 return r.uintLessThan(T, at_most + 1);
140140 }
141141
142 /// Constant-time implementation off ::intRangeLessThan.
142 /// Constant-time implementation off `intRangeLessThan`.
143143 /// The results of this function may be biased.
144144 pub fn intRangeLessThanBiased(r: *Random, comptime T: type, at_least: T, less_than: T) T {
145145 assert(at_least < less_than);
......@@ -157,7 +157,7 @@ pub const Random = struct {
157157 }
158158
159159 /// Returns an evenly distributed random integer `at_least <= i < less_than`.
160 /// See ::uintLessThan, which this function uses in most cases,
160 /// See `uintLessThan`, which this function uses in most cases,
161161 /// for commentary on the runtime of this function.
162162 pub fn intRangeLessThan(r: *Random, comptime T: type, at_least: T, less_than: T) T {
163163 assert(at_least < less_than);
......@@ -174,7 +174,7 @@ pub const Random = struct {
174174 }
175175 }
176176
177 /// Constant-time implementation off ::intRangeAtMostBiased.
177 /// Constant-time implementation off `intRangeAtMostBiased`.
178178 /// The results of this function may be biased.
179179 pub fn intRangeAtMostBiased(r: *Random, comptime T: type, at_least: T, at_most: T) T {
180180 assert(at_least <= at_most);
......@@ -192,7 +192,7 @@ pub const Random = struct {
192192 }
193193
194194 /// Returns an evenly distributed random integer `at_least <= i <= at_most`.
195 /// See ::uintLessThan, which this function uses in most cases,
195 /// See `uintLessThan`, which this function uses in most cases,
196196 /// for commentary on the runtime of this function.
197197 pub fn intRangeAtMost(r: *Random, comptime T: type, at_least: T, at_most: T) T {
198198 assert(at_least <= at_most);
......@@ -209,15 +209,9 @@ pub const Random = struct {
209209 }
210210 }
211211
212 /// TODO: deprecated. use ::boolean or ::int instead.
213 pub fn scalar(r: *Random, comptime T: type) T {
214 return if (T == bool) r.boolean() else r.int(T);
215 }
212 pub const scalar = @compileError("deprecated; use boolean() or int() instead");
216213
217 /// TODO: deprecated. renamed to ::intRangeLessThan
218 pub fn range(r: *Random, comptime T: type, start: T, end: T) T {
219 return r.intRangeLessThan(T, start, end);
220 }
214 pub const range = @compileError("deprecated; use intRangeLessThan()");
221215
222216 /// Return a floating point value evenly distributed in the range [0, 1).
223217 pub fn float(r: *Random, comptime T: type) T {
lib/std/sort.zig+2-2
......@@ -1227,13 +1227,13 @@ test "sort fuzz testing" {
12271227var fixed_buffer_mem: [100 * 1024]u8 = undefined;
12281228
12291229fn fuzzTest(rng: *std.rand.Random) !void {
1230 const array_size = rng.range(usize, 0, 1000);
1230 const array_size = rng.intRangeLessThan(usize, 0, 1000);
12311231 var array = try testing.allocator.alloc(IdAndValue, array_size);
12321232 defer testing.allocator.free(array);
12331233 // populate with random data
12341234 for (array) |*item, index| {
12351235 item.id = index;
1236 item.value = rng.range(i32, 0, 100);
1236 item.value = rng.intRangeLessThan(i32, 0, 100);
12371237 }
12381238 sort(IdAndValue, array, cmpByValue);
12391239
lib/std/special/build_runner.zig+3-3
......@@ -116,7 +116,7 @@ pub fn main() !void {
116116 if (builder.validateUserInputDidItFail())
117117 return usageAndErr(builder, true, stderr_stream);
118118
119 builder.make(targets.toSliceConst()) catch |err| {
119 builder.make(targets.span()) catch |err| {
120120 switch (err) {
121121 error.InvalidStepName => {
122122 return usageAndErr(builder, true, stderr_stream);
......@@ -151,7 +151,7 @@ fn usage(builder: *Builder, already_ran_build: bool, out_stream: var) !void {
151151 , .{builder.zig_exe});
152152
153153 const allocator = builder.allocator;
154 for (builder.top_level_steps.toSliceConst()) |top_level_step| {
154 for (builder.top_level_steps.span()) |top_level_step| {
155155 const name = if (&top_level_step.step == builder.default_step)
156156 try fmt.allocPrint(allocator, "{} (default)", .{top_level_step.step.name})
157157 else
......@@ -174,7 +174,7 @@ fn usage(builder: *Builder, already_ran_build: bool, out_stream: var) !void {
174174 if (builder.available_options_list.len == 0) {
175175 try out_stream.print(" (none)\n", .{});
176176 } else {
177 for (builder.available_options_list.toSliceConst()) |option| {
177 for (builder.available_options_list.span()) |option| {
178178 const name = try fmt.allocPrint(allocator, " -D{}=[{}]", .{
179179 option.name,
180180 Builder.typeIdName(option.type_id),
lib/std/thread.zig+1-1
......@@ -464,7 +464,7 @@ pub const Thread = struct {
464464 var count: c_int = undefined;
465465 var count_len: usize = @sizeOf(c_int);
466466 const name = if (comptime std.Target.current.isDarwin()) "hw.logicalcpu" else "hw.ncpu";
467 os.sysctlbynameC(name, &count, &count_len, null, 0) catch |err| switch (err) {
467 os.sysctlbynameZ(name, &count, &count_len, null, 0) catch |err| switch (err) {
468468 error.NameTooLong, error.UnknownName => unreachable,
469469 else => |e| return e,
470470 };
lib/std/zig/render.zig+1-1
......@@ -1531,7 +1531,7 @@ fn renderExpression(
15311531 try renderToken(tree, stream, callconv_rparen, indent, start_col, Space.Space); // )
15321532 } else if (cc_rewrite_str) |str| {
15331533 try stream.writeAll("callconv(");
1534 try stream.writeAll(mem.toSliceConst(u8, str));
1534 try stream.writeAll(mem.spanZ(str));
15351535 try stream.writeAll(") ");
15361536 }
15371537
lib/std/zig/system.zig+8-8
......@@ -119,7 +119,7 @@ pub const NativePaths = struct {
119119 }
120120
121121 fn deinitArray(array: *ArrayList([:0]u8)) void {
122 for (array.toSlice()) |item| {
122 for (array.span()) |item| {
123123 array.allocator.free(item);
124124 }
125125 array.deinit();
......@@ -201,7 +201,7 @@ pub const NativeTargetInfo = struct {
201201 switch (Target.current.os.tag) {
202202 .linux => {
203203 const uts = std.os.uname();
204 const release = mem.toSliceConst(u8, &uts.release);
204 const release = mem.spanZ(&uts.release);
205205 // The release field may have several other fields after the
206206 // kernel version
207207 const kernel_version = if (mem.indexOfScalar(u8, release, '-')) |pos|
......@@ -265,7 +265,7 @@ pub const NativeTargetInfo = struct {
265265 // The osproductversion sysctl was introduced first with
266266 // High Sierra, thankfully that's also the baseline that Zig
267267 // supports
268 std.os.sysctlbynameC(
268 std.os.sysctlbynameZ(
269269 "kern.osproductversion",
270270 &product_version,
271271 &size,
......@@ -460,7 +460,7 @@ pub const NativeTargetInfo = struct {
460460 return result;
461461 }
462462
463 const env_file = std.fs.openFileAbsoluteC("/usr/bin/env", .{}) catch |err| switch (err) {
463 const env_file = std.fs.openFileAbsoluteZ("/usr/bin/env", .{}) catch |err| switch (err) {
464464 error.NoSpaceLeft => unreachable,
465465 error.NameTooLong => unreachable,
466466 error.PathAlreadyExists => unreachable,
......@@ -512,7 +512,7 @@ pub const NativeTargetInfo = struct {
512512
513513 fn glibcVerFromSO(so_path: [:0]const u8) !std.builtin.Version {
514514 var link_buf: [std.os.PATH_MAX]u8 = undefined;
515 const link_name = std.os.readlinkC(so_path.ptr, &link_buf) catch |err| switch (err) {
515 const link_name = std.os.readlinkZ(so_path.ptr, &link_buf) catch |err| switch (err) {
516516 error.AccessDenied => return error.GnuLibCVersionUnavailable,
517517 error.FileSystem => return error.FileSystem,
518518 error.SymLinkLoop => return error.SymLinkLoop,
......@@ -736,7 +736,7 @@ pub const NativeTargetInfo = struct {
736736 );
737737 const sh_name_off = elfInt(is_64, need_bswap, sh32.sh_name, sh64.sh_name);
738738 // TODO this pointer cast should not be necessary
739 const sh_name = mem.toSliceConst(u8, @ptrCast([*:0]u8, shstrtab[sh_name_off..].ptr));
739 const sh_name = mem.spanZ(@ptrCast([*:0]u8, shstrtab[sh_name_off..].ptr));
740740 if (mem.eql(u8, sh_name, ".dynstr")) {
741741 break :find_dyn_str .{
742742 .offset = elfInt(is_64, need_bswap, sh32.sh_offset, sh64.sh_offset),
......@@ -751,7 +751,7 @@ pub const NativeTargetInfo = struct {
751751 const strtab_read_len = try preadMin(file, &strtab_buf, ds.offset, shstrtab_len);
752752 const strtab = strtab_buf[0..strtab_read_len];
753753 // TODO this pointer cast should not be necessary
754 const rpath_list = mem.toSliceConst(u8, @ptrCast([*:0]u8, strtab[rpoff..].ptr));
754 const rpath_list = mem.spanZ(@ptrCast([*:0]u8, strtab[rpoff..].ptr));
755755 var it = mem.tokenize(rpath_list, ":");
756756 while (it.next()) |rpath| {
757757 var dir = fs.cwd().openDir(rpath, .{}) catch |err| switch (err) {
......@@ -776,7 +776,7 @@ pub const NativeTargetInfo = struct {
776776 defer dir.close();
777777
778778 var link_buf: [std.os.PATH_MAX]u8 = undefined;
779 const link_name = std.os.readlinkatC(
779 const link_name = std.os.readlinkatZ(
780780 dir.fd,
781781 glibc_so_basename,
782782 &link_buf,
src-self-hosted/codegen.zig+13-13
......@@ -25,10 +25,10 @@ pub async fn renderToLlvm(comp: *Compilation, fn_val: *Value.Fn, code: *ir.Code)
2525
2626 const context = llvm_handle.node.data;
2727
28 const module = llvm.ModuleCreateWithNameInContext(comp.name.toSliceConst(), context) orelse return error.OutOfMemory;
28 const module = llvm.ModuleCreateWithNameInContext(comp.name.span(), context) orelse return error.OutOfMemory;
2929 defer llvm.DisposeModule(module);
3030
31 llvm.SetTarget(module, comp.llvm_triple.toSliceConst());
31 llvm.SetTarget(module, comp.llvm_triple.span());
3232 llvm.SetDataLayout(module, comp.target_layout_str);
3333
3434 if (comp.target.getObjectFormat() == .coff) {
......@@ -54,15 +54,15 @@ pub async fn renderToLlvm(comp: *Compilation, fn_val: *Value.Fn, code: *ir.Code)
5454 const runtime_version = 0;
5555 const compile_unit_file = llvm.CreateFile(
5656 dibuilder,
57 comp.name.toSliceConst(),
58 comp.root_package.root_src_dir.toSliceConst(),
57 comp.name.span(),
58 comp.root_package.root_src_dir.span(),
5959 ) orelse return error.OutOfMemory;
6060 const is_optimized = comp.build_mode != .Debug;
6161 const compile_unit = llvm.CreateCompileUnit(
6262 dibuilder,
6363 DW.LANG_C99,
6464 compile_unit_file,
65 producer.toSliceConst(),
65 producer.span(),
6666 is_optimized,
6767 flags,
6868 runtime_version,
......@@ -109,14 +109,14 @@ pub async fn renderToLlvm(comp: *Compilation, fn_val: *Value.Fn, code: *ir.Code)
109109 if (llvm.TargetMachineEmitToFile(
110110 comp.target_machine,
111111 module,
112 output_path.toSliceConst(),
112 output_path.span(),
113113 llvm.EmitBinary,
114114 &err_msg,
115115 is_debug,
116116 is_small,
117117 )) {
118118 if (std.debug.runtime_safety) {
119 std.debug.panic("unable to write object file {}: {s}\n", .{ output_path.toSliceConst(), err_msg });
119 std.debug.panic("unable to write object file {}: {s}\n", .{ output_path.span(), err_msg });
120120 }
121121 return error.WritingObjectFileFailed;
122122 }
......@@ -127,7 +127,7 @@ pub async fn renderToLlvm(comp: *Compilation, fn_val: *Value.Fn, code: *ir.Code)
127127 llvm.DumpModule(ofile.module);
128128 }
129129 if (comp.verbose_link) {
130 std.debug.warn("created {}\n", .{output_path.toSliceConst()});
130 std.debug.warn("created {}\n", .{output_path.span()});
131131 }
132132}
133133
......@@ -150,7 +150,7 @@ pub fn renderToLlvmModule(ofile: *ObjectFile, fn_val: *Value.Fn, code: *ir.Code)
150150 const llvm_fn_type = try fn_val.base.typ.getLlvmType(ofile.arena, ofile.context);
151151 const llvm_fn = llvm.AddFunction(
152152 ofile.module,
153 fn_val.symbol_name.toSliceConst(),
153 fn_val.symbol_name.span(),
154154 llvm_fn_type,
155155 ) orelse return error.OutOfMemory;
156156
......@@ -211,7 +211,7 @@ pub fn renderToLlvmModule(ofile: *ObjectFile, fn_val: *Value.Fn, code: *ir.Code)
211211 const cur_ret_ptr = if (fn_type_normal.return_type.handleIsPtr()) llvm.GetParam(llvm_fn, 0) else null;
212212
213213 // build all basic blocks
214 for (code.basic_block_list.toSlice()) |bb| {
214 for (code.basic_block_list.span()) |bb| {
215215 bb.llvm_block = llvm.AppendBasicBlockInContext(
216216 ofile.context,
217217 llvm_fn,
......@@ -226,7 +226,7 @@ pub fn renderToLlvmModule(ofile: *ObjectFile, fn_val: *Value.Fn, code: *ir.Code)
226226 // TODO set up error return tracing
227227 // TODO allocate temporary stack values
228228
229 const var_list = fn_type.non_key.Normal.variable_list.toSliceConst();
229 const var_list = fn_type.non_key.Normal.variable_list.span();
230230 // create debug variable declarations for variables and allocate all local variables
231231 for (var_list) |var_scope, i| {
232232 const var_type = switch (var_scope.data) {
......@@ -306,9 +306,9 @@ pub fn renderToLlvmModule(ofile: *ObjectFile, fn_val: *Value.Fn, code: *ir.Code)
306306 //}
307307 }
308308
309 for (code.basic_block_list.toSlice()) |current_block| {
309 for (code.basic_block_list.span()) |current_block| {
310310 llvm.PositionBuilderAtEnd(ofile.builder, current_block.llvm_block);
311 for (current_block.instruction_list.toSlice()) |instruction| {
311 for (current_block.instruction_list.span()) |instruction| {
312312 if (instruction.ref_count == 0 and !instruction.hasSideEffects()) continue;
313313
314314 instruction.llvm_value = try instruction.render(ofile, fn_val);
src-self-hosted/compilation.zig+3-3
......@@ -465,7 +465,7 @@ pub const Compilation = struct {
465465
466466 comp.target_machine = llvm.CreateTargetMachine(
467467 comp.llvm_target,
468 comp.llvm_triple.toSliceConst(),
468 comp.llvm_triple.span(),
469469 target_specific_cpu_args orelse "",
470470 target_specific_cpu_features orelse "",
471471 opt_level,
......@@ -1106,7 +1106,7 @@ pub const Compilation = struct {
11061106 }
11071107 }
11081108
1109 for (self.link_libs_list.toSliceConst()) |existing_lib| {
1109 for (self.link_libs_list.span()) |existing_lib| {
11101110 if (mem.eql(u8, name, existing_lib.name)) {
11111111 return existing_lib;
11121112 }
......@@ -1371,7 +1371,7 @@ fn analyzeFnType(
13711371 var params = ArrayList(Type.Fn.Param).init(comp.gpa());
13721372 var params_consumed = false;
13731373 defer if (!params_consumed) {
1374 for (params.toSliceConst()) |param| {
1374 for (params.span()) |param| {
13751375 param.typ.base.deref(comp);
13761376 }
13771377 params.deinit();
src-self-hosted/dep_tokenizer.zig+19-19
......@@ -89,7 +89,7 @@ pub const Tokenizer = struct {
8989 },
9090 .target_colon => |*target| switch (char) {
9191 '\n', '\r' => {
92 const bytes = target.toSlice();
92 const bytes = target.span();
9393 if (bytes.len != 0) {
9494 self.state = State{ .lhs = {} };
9595 return Token{ .id = .target, .bytes = bytes };
......@@ -103,7 +103,7 @@ pub const Tokenizer = struct {
103103 break; // advance
104104 },
105105 else => {
106 const bytes = target.toSlice();
106 const bytes = target.span();
107107 if (bytes.len != 0) {
108108 self.state = State{ .rhs = {} };
109109 return Token{ .id = .target, .bytes = bytes };
......@@ -115,7 +115,7 @@ pub const Tokenizer = struct {
115115 },
116116 .target_colon_reverse_solidus => |*target| switch (char) {
117117 '\n', '\r' => {
118 const bytes = target.toSlice();
118 const bytes = target.span();
119119 if (bytes.len != 0) {
120120 self.state = State{ .lhs = {} };
121121 return Token{ .id = .target, .bytes = bytes };
......@@ -175,7 +175,7 @@ pub const Tokenizer = struct {
175175 },
176176 .prereq_quote => |*prereq| switch (char) {
177177 '"' => {
178 const bytes = prereq.toSlice();
178 const bytes = prereq.span();
179179 self.index += 1;
180180 self.state = State{ .rhs = {} };
181181 return Token{ .id = .prereq, .bytes = bytes };
......@@ -187,12 +187,12 @@ pub const Tokenizer = struct {
187187 },
188188 .prereq => |*prereq| switch (char) {
189189 '\t', ' ' => {
190 const bytes = prereq.toSlice();
190 const bytes = prereq.span();
191191 self.state = State{ .rhs = {} };
192192 return Token{ .id = .prereq, .bytes = bytes };
193193 },
194194 '\n', '\r' => {
195 const bytes = prereq.toSlice();
195 const bytes = prereq.span();
196196 self.state = State{ .lhs = {} };
197197 return Token{ .id = .prereq, .bytes = bytes };
198198 },
......@@ -207,7 +207,7 @@ pub const Tokenizer = struct {
207207 },
208208 .prereq_continuation => |*prereq| switch (char) {
209209 '\n' => {
210 const bytes = prereq.toSlice();
210 const bytes = prereq.span();
211211 self.index += 1;
212212 self.state = State{ .rhs = {} };
213213 return Token{ .id = .prereq, .bytes = bytes };
......@@ -225,7 +225,7 @@ pub const Tokenizer = struct {
225225 },
226226 .prereq_continuation_linefeed => |prereq| switch (char) {
227227 '\n' => {
228 const bytes = prereq.toSlice();
228 const bytes = prereq.span();
229229 self.index += 1;
230230 self.state = State{ .rhs = {} };
231231 return Token{ .id = .prereq, .bytes = bytes };
......@@ -249,7 +249,7 @@ pub const Tokenizer = struct {
249249 .rhs_continuation_linefeed,
250250 => {},
251251 .target => |target| {
252 return self.errorPosition(idx, target.toSlice(), "incomplete target", .{});
252 return self.errorPosition(idx, target.span(), "incomplete target", .{});
253253 },
254254 .target_reverse_solidus,
255255 .target_dollar_sign,
......@@ -258,7 +258,7 @@ pub const Tokenizer = struct {
258258 return self.errorIllegalChar(idx, self.bytes[idx], "incomplete escape", .{});
259259 },
260260 .target_colon => |target| {
261 const bytes = target.toSlice();
261 const bytes = target.span();
262262 if (bytes.len != 0) {
263263 self.index += 1;
264264 self.state = State{ .rhs = {} };
......@@ -268,7 +268,7 @@ pub const Tokenizer = struct {
268268 self.state = State{ .lhs = {} };
269269 },
270270 .target_colon_reverse_solidus => |target| {
271 const bytes = target.toSlice();
271 const bytes = target.span();
272272 if (bytes.len != 0) {
273273 self.index += 1;
274274 self.state = State{ .rhs = {} };
......@@ -278,20 +278,20 @@ pub const Tokenizer = struct {
278278 self.state = State{ .lhs = {} };
279279 },
280280 .prereq_quote => |prereq| {
281 return self.errorPosition(idx, prereq.toSlice(), "incomplete quoted prerequisite", .{});
281 return self.errorPosition(idx, prereq.span(), "incomplete quoted prerequisite", .{});
282282 },
283283 .prereq => |prereq| {
284 const bytes = prereq.toSlice();
284 const bytes = prereq.span();
285285 self.state = State{ .lhs = {} };
286286 return Token{ .id = .prereq, .bytes = bytes };
287287 },
288288 .prereq_continuation => |prereq| {
289 const bytes = prereq.toSlice();
289 const bytes = prereq.span();
290290 self.state = State{ .lhs = {} };
291291 return Token{ .id = .prereq, .bytes = bytes };
292292 },
293293 .prereq_continuation_linefeed => |prereq| {
294 const bytes = prereq.toSlice();
294 const bytes = prereq.span();
295295 self.state = State{ .lhs = {} };
296296 return Token{ .id = .prereq, .bytes = bytes };
297297 },
......@@ -300,7 +300,7 @@ pub const Tokenizer = struct {
300300 }
301301
302302 fn errorf(self: *Tokenizer, comptime fmt: []const u8, args: var) Error {
303 self.error_text = (try std.Buffer.allocPrint(&self.arena.allocator, fmt, args)).toSlice();
303 self.error_text = (try std.Buffer.allocPrint(&self.arena.allocator, fmt, args)).span();
304304 return Error.InvalidInput;
305305 }
306306
......@@ -312,7 +312,7 @@ pub const Tokenizer = struct {
312312 try printCharValues(&out, bytes);
313313 try buffer.append("'");
314314 try buffer.outStream().print(" at position {}", .{position - (bytes.len - 1)});
315 self.error_text = buffer.toSlice();
315 self.error_text = buffer.span();
316316 return Error.InvalidInput;
317317 }
318318
......@@ -322,7 +322,7 @@ pub const Tokenizer = struct {
322322 try printUnderstandableChar(&buffer, char);
323323 try buffer.outStream().print(" at position {}", .{position});
324324 if (fmt.len != 0) try buffer.outStream().print(": " ++ fmt, args);
325 self.error_text = buffer.toSlice();
325 self.error_text = buffer.span();
326326 return Error.InvalidInput;
327327 }
328328
......@@ -865,7 +865,7 @@ fn depTokenizer(input: []const u8, expect: []const u8) !void {
865865 try buffer.append("}");
866866 i += 1;
867867 }
868 const got: []const u8 = buffer.toSlice();
868 const got: []const u8 = buffer.span();
869869
870870 if (std.mem.eql(u8, expect, got)) {
871871 testing.expect(true);
src-self-hosted/ir.zig+4-4
......@@ -965,9 +965,9 @@ pub const Code = struct {
965965
966966 pub fn dump(self: *Code) void {
967967 var bb_i: usize = 0;
968 for (self.basic_block_list.toSliceConst()) |bb| {
968 for (self.basic_block_list.span()) |bb| {
969969 std.debug.warn("{s}_{}:\n", .{ bb.name_hint, bb.debug_id });
970 for (bb.instruction_list.toSliceConst()) |instr| {
970 for (bb.instruction_list.span()) |instr| {
971971 std.debug.warn(" ", .{});
972972 instr.dump();
973973 std.debug.warn("\n", .{});
......@@ -978,7 +978,7 @@ pub const Code = struct {
978978 /// returns a ref-incremented value, or adds a compile error
979979 pub fn getCompTimeResult(self: *Code, comp: *Compilation) !*Value {
980980 const bb = self.basic_block_list.at(0);
981 for (bb.instruction_list.toSliceConst()) |inst| {
981 for (bb.instruction_list.span()) |inst| {
982982 if (inst.cast(Inst.Return)) |ret_inst| {
983983 const ret_value = ret_inst.params.return_value;
984984 if (ret_value.isCompTime()) {
......@@ -2585,6 +2585,6 @@ pub fn analyze(comp: *Compilation, old_code: *Code, expected_type: ?*Type) !*Cod
25852585 return ira.irb.finish();
25862586 }
25872587
2588 ira.irb.code.return_type = try ira.resolvePeerTypes(expected_type, ira.src_implicit_return_type_list.toSliceConst());
2588 ira.irb.code.return_type = try ira.resolvePeerTypes(expected_type, ira.src_implicit_return_type_list.span());
25892589 return ira.irb.finish();
25902590}
src-self-hosted/libc_installation.zig+7-7
......@@ -54,7 +54,7 @@ pub const LibCInstallation = struct {
5454 }
5555 }
5656
57 const contents = try std.io.readFileAlloc(allocator, libc_file);
57 const contents = try std.fs.cwd().readFileAlloc(allocator, libc_file, std.math.maxInt(usize));
5858 defer allocator.free(contents);
5959
6060 var it = std.mem.tokenize(contents, "\n");
......@@ -229,7 +229,7 @@ pub const LibCInstallation = struct {
229229 "-xc",
230230 dev_null,
231231 };
232 const exec_res = std.ChildProcess.exec2(.{
232 const exec_res = std.ChildProcess.exec(.{
233233 .allocator = allocator,
234234 .argv = &argv,
235235 .max_output_bytes = 1024 * 1024,
......@@ -335,7 +335,7 @@ pub const LibCInstallation = struct {
335335 const stream = result_buf.outStream();
336336 try stream.print("{}\\Include\\{}\\ucrt", .{ search.path, search.version });
337337
338 var dir = fs.cwd().openDir(result_buf.toSliceConst(), .{}) catch |err| switch (err) {
338 var dir = fs.cwd().openDir(result_buf.span(), .{}) catch |err| switch (err) {
339339 error.FileNotFound,
340340 error.NotDir,
341341 error.NoDevice,
......@@ -382,7 +382,7 @@ pub const LibCInstallation = struct {
382382 const stream = result_buf.outStream();
383383 try stream.print("{}\\Lib\\{}\\ucrt\\{}", .{ search.path, search.version, arch_sub_dir });
384384
385 var dir = fs.cwd().openDir(result_buf.toSliceConst(), .{}) catch |err| switch (err) {
385 var dir = fs.cwd().openDir(result_buf.span(), .{}) catch |err| switch (err) {
386386 error.FileNotFound,
387387 error.NotDir,
388388 error.NoDevice,
......@@ -437,7 +437,7 @@ pub const LibCInstallation = struct {
437437 const stream = result_buf.outStream();
438438 try stream.print("{}\\Lib\\{}\\um\\{}", .{ search.path, search.version, arch_sub_dir });
439439
440 var dir = fs.cwd().openDir(result_buf.toSliceConst(), .{}) catch |err| switch (err) {
440 var dir = fs.cwd().openDir(result_buf.span(), .{}) catch |err| switch (err) {
441441 error.FileNotFound,
442442 error.NotDir,
443443 error.NoDevice,
......@@ -475,7 +475,7 @@ pub const LibCInstallation = struct {
475475
476476 try result_buf.append("\\include");
477477
478 var dir = fs.cwd().openDir(result_buf.toSliceConst(), .{}) catch |err| switch (err) {
478 var dir = fs.cwd().openDir(result_buf.span(), .{}) catch |err| switch (err) {
479479 error.FileNotFound,
480480 error.NotDir,
481481 error.NoDevice,
......@@ -522,7 +522,7 @@ fn ccPrintFileName(args: CCPrintFileNameOptions) ![:0]u8 {
522522 defer allocator.free(arg1);
523523 const argv = [_][]const u8{ cc_exe, arg1 };
524524
525 const exec_res = std.ChildProcess.exec2(.{
525 const exec_res = std.ChildProcess.exec(.{
526526 .allocator = allocator,
527527 .argv = &argv,
528528 .max_output_bytes = 1024 * 1024,
src-self-hosted/link.zig+9-9
......@@ -36,7 +36,7 @@ pub fn link(comp: *Compilation) !void {
3636 ctx.args = std.ArrayList([*:0]const u8).init(&ctx.arena.allocator);
3737 ctx.link_msg = std.Buffer.initNull(&ctx.arena.allocator);
3838
39 ctx.out_file_path = try std.Buffer.init(&ctx.arena.allocator, comp.name.toSliceConst());
39 ctx.out_file_path = try std.Buffer.init(&ctx.arena.allocator, comp.name.span());
4040 switch (comp.kind) {
4141 .Exe => {
4242 try ctx.out_file_path.append(comp.target.exeFileExt());
......@@ -70,7 +70,7 @@ pub fn link(comp: *Compilation) !void {
7070 try constructLinkerArgs(&ctx);
7171
7272 if (comp.verbose_link) {
73 for (ctx.args.toSliceConst()) |arg, i| {
73 for (ctx.args.span()) |arg, i| {
7474 const space = if (i == 0) "" else " ";
7575 std.debug.warn("{}{s}", .{ space, arg });
7676 }
......@@ -78,7 +78,7 @@ pub fn link(comp: *Compilation) !void {
7878 }
7979
8080 const extern_ofmt = toExternObjectFormatType(comp.target.getObjectFormat());
81 const args_slice = ctx.args.toSlice();
81 const args_slice = ctx.args.span();
8282
8383 {
8484 // LLD is not thread-safe, so we grab a global lock.
......@@ -91,7 +91,7 @@ pub fn link(comp: *Compilation) !void {
9191 // TODO capture these messages and pass them through the system, reporting them through the
9292 // event system instead of printing them directly here.
9393 // perhaps try to parse and understand them.
94 std.debug.warn("{}\n", .{ctx.link_msg.toSliceConst()});
94 std.debug.warn("{}\n", .{ctx.link_msg.span()});
9595 }
9696 return error.LinkFailed;
9797 }
......@@ -173,7 +173,7 @@ fn constructLinkerArgsElf(ctx: *Context) !void {
173173 //}
174174
175175 try ctx.args.append("-o");
176 try ctx.args.append(ctx.out_file_path.toSliceConst());
176 try ctx.args.append(ctx.out_file_path.span());
177177
178178 if (ctx.link_in_crt) {
179179 const crt1o = if (ctx.comp.is_static) "crt1.o" else "Scrt1.o";
......@@ -291,7 +291,7 @@ fn constructLinkerArgsCoff(ctx: *Context) !void {
291291
292292 const is_library = ctx.comp.kind == .Lib;
293293
294 const out_arg = try std.fmt.allocPrint(&ctx.arena.allocator, "-OUT:{}\x00", .{ctx.out_file_path.toSliceConst()});
294 const out_arg = try std.fmt.allocPrint(&ctx.arena.allocator, "-OUT:{}\x00", .{ctx.out_file_path.span()});
295295 try ctx.args.append(@ptrCast([*:0]const u8, out_arg.ptr));
296296
297297 if (ctx.comp.haveLibC()) {
......@@ -394,7 +394,7 @@ fn constructLinkerArgsMachO(ctx: *Context) !void {
394394 }
395395
396396 try ctx.args.append("-o");
397 try ctx.args.append(ctx.out_file_path.toSliceConst());
397 try ctx.args.append(ctx.out_file_path.span());
398398
399399 if (shared) {
400400 try ctx.args.append("-headerpad_max_install_names");
......@@ -432,7 +432,7 @@ fn constructLinkerArgsMachO(ctx: *Context) !void {
432432
433433 // TODO
434434 //if (ctx.comp.target == Target.Native) {
435 // for (ctx.comp.link_libs_list.toSliceConst()) |lib| {
435 // for (ctx.comp.link_libs_list.span()) |lib| {
436436 // if (mem.eql(u8, lib.name, "c")) {
437437 // // on Darwin, libSystem has libc in it, but also you have to use it
438438 // // to make syscalls because the syscall numbers are not documented
......@@ -482,7 +482,7 @@ fn addFnObjects(ctx: *Context) !void {
482482 ctx.comp.gpa().destroy(node);
483483 continue;
484484 };
485 try ctx.args.append(fn_val.containing_object.toSliceConst());
485 try ctx.args.append(fn_val.containing_object.span());
486486 it = node.next;
487487 }
488488}
src-self-hosted/main.zig+7-7
......@@ -421,7 +421,7 @@ fn buildOutputType(allocator: *Allocator, args: []const []const u8, out_type: Co
421421 process.exit(1);
422422 }
423423
424 try ZigCompiler.setLlvmArgv(allocator, mllvm_flags.toSliceConst());
424 try ZigCompiler.setLlvmArgv(allocator, mllvm_flags.span());
425425
426426 const zig_lib_dir = introspect.resolveZigLibDir(allocator) catch process.exit(1);
427427 defer allocator.free(zig_lib_dir);
......@@ -448,14 +448,14 @@ fn buildOutputType(allocator: *Allocator, args: []const []const u8, out_type: Co
448448 comp.override_libc = &override_libc;
449449 }
450450
451 for (system_libs.toSliceConst()) |lib| {
451 for (system_libs.span()) |lib| {
452452 _ = try comp.addLinkLib(lib, true);
453453 }
454454
455455 comp.version = version;
456456 comp.is_test = false;
457457 comp.linker_script = linker_script;
458 comp.clang_argv = clang_argv_buf.toSliceConst();
458 comp.clang_argv = clang_argv_buf.span();
459459 comp.strip = strip;
460460
461461 comp.verbose_tokenize = verbose_tokenize;
......@@ -488,8 +488,8 @@ fn buildOutputType(allocator: *Allocator, args: []const []const u8, out_type: Co
488488 comp.emit_asm = emit_asm;
489489 comp.emit_llvm_ir = emit_llvm_ir;
490490 comp.emit_h = emit_h;
491 comp.assembly_files = assembly_files.toSliceConst();
492 comp.link_objects = link_objects.toSliceConst();
491 comp.assembly_files = assembly_files.span();
492 comp.link_objects = link_objects.span();
493493
494494 comp.start();
495495 processBuildEvents(comp, color);
......@@ -683,7 +683,7 @@ fn cmdFmt(allocator: *Allocator, args: []const []const u8) !void {
683683 };
684684
685685 var group = event.Group(FmtError!void).init(allocator);
686 for (input_files.toSliceConst()) |file_path| {
686 for (input_files.span()) |file_path| {
687687 try group.call(fmtPath, .{ &fmt, file_path, check_flag });
688688 }
689689 try group.wait();
......@@ -898,7 +898,7 @@ const CliPkg = struct {
898898 }
899899
900900 pub fn deinit(self: *CliPkg) void {
901 for (self.children.toSliceConst()) |child| {
901 for (self.children.span()) |child| {
902902 child.deinit();
903903 }
904904 self.children.deinit();
src-self-hosted/stage2.zig+19-18
......@@ -185,14 +185,14 @@ fn fmtMain(argc: c_int, argv: [*]const [*:0]const u8) !void {
185185 const argc_usize = @intCast(usize, argc);
186186 var arg_i: usize = 0;
187187 while (arg_i < argc_usize) : (arg_i += 1) {
188 try args_list.append(mem.toSliceConst(u8, argv[arg_i]));
188 try args_list.append(mem.spanZ(argv[arg_i]));
189189 }
190190
191191 stdout = std.io.getStdOut().outStream();
192192 stderr_file = std.io.getStdErr();
193193 stderr = stderr_file.outStream();
194194
195 const args = args_list.toSliceConst()[2..];
195 const args = args_list.span()[2..];
196196
197197 var color: errmsg.Color = .Auto;
198198 var stdin_flag: bool = false;
......@@ -285,7 +285,7 @@ fn fmtMain(argc: c_int, argv: [*]const [*:0]const u8) !void {
285285 .allocator = allocator,
286286 };
287287
288 for (input_files.toSliceConst()) |file_path| {
288 for (input_files.span()) |file_path| {
289289 try fmtPath(&fmt, file_path, check_flag);
290290 }
291291 if (fmt.any_error) {
......@@ -318,7 +318,8 @@ fn fmtPath(fmt: *Fmt, file_path: []const u8, check_mode: bool) FmtError!void {
318318 if (fmt.seen.exists(file_path)) return;
319319 try fmt.seen.put(file_path);
320320
321 const source_code = io.readFileAlloc(fmt.allocator, file_path) catch |err| switch (err) {
321 const max = std.math.maxInt(usize);
322 const source_code = fs.cwd().readFileAlloc(fmt.allocator, file_path, max) catch |err| switch (err) {
322323 error.IsDir, error.AccessDenied => {
323324 // TODO make event based (and dir.next())
324325 var dir = try fs.cwd().openDir(file_path, .{ .iterate = true });
......@@ -450,7 +451,7 @@ export fn stage2_DepTokenizer_next(self: *stage2_DepTokenizer) stage2_DepNextRes
450451 const textz = std.Buffer.init(&self.handle.arena.allocator, self.handle.error_text) catch @panic("failed to create .d tokenizer error text");
451452 return stage2_DepNextResult{
452453 .type_id = .error_,
453 .textz = textz.toSlice().ptr,
454 .textz = textz.span().ptr,
454455 };
455456 };
456457 const token = otoken orelse {
......@@ -465,7 +466,7 @@ export fn stage2_DepTokenizer_next(self: *stage2_DepTokenizer) stage2_DepNextRes
465466 .target => .target,
466467 .prereq => .prereq,
467468 },
468 .textz = textz.toSlice().ptr,
469 .textz = textz.span().ptr,
469470 };
470471}
471472
......@@ -572,7 +573,7 @@ fn detectNativeCpuWithLLVM(
572573 var result = Target.Cpu.baseline(arch);
573574
574575 if (llvm_cpu_name_z) |cpu_name_z| {
575 const llvm_cpu_name = mem.toSliceConst(u8, cpu_name_z);
576 const llvm_cpu_name = mem.spanZ(cpu_name_z);
576577
577578 for (arch.allCpuModels()) |model| {
578579 const this_llvm_name = model.llvm_name orelse continue;
......@@ -593,7 +594,7 @@ fn detectNativeCpuWithLLVM(
593594 const all_features = arch.allFeaturesList();
594595
595596 if (llvm_cpu_features_opt) |llvm_cpu_features| {
596 var it = mem.tokenize(mem.toSliceConst(u8, llvm_cpu_features), ",");
597 var it = mem.tokenize(mem.spanZ(llvm_cpu_features), ",");
597598 while (it.next()) |decorated_llvm_feat| {
598599 var op: enum {
599600 add,
......@@ -688,9 +689,9 @@ fn stage2CrossTarget(
688689 mcpu_oz: ?[*:0]const u8,
689690 dynamic_linker_oz: ?[*:0]const u8,
690691) !CrossTarget {
691 const zig_triple = if (zig_triple_oz) |zig_triple_z| mem.toSliceConst(u8, zig_triple_z) else "native";
692 const mcpu = if (mcpu_oz) |mcpu_z| mem.toSliceConst(u8, mcpu_z) else null;
693 const dynamic_linker = if (dynamic_linker_oz) |dl_z| mem.toSliceConst(u8, dl_z) else null;
692 const zig_triple = if (zig_triple_oz) |zig_triple_z| mem.spanZ(zig_triple_z) else "native";
693 const mcpu = if (mcpu_oz) |mcpu_z| mem.spanZ(mcpu_z) else null;
694 const dynamic_linker = if (dynamic_linker_oz) |dl_z| mem.spanZ(dl_z) else null;
694695 var diags: CrossTarget.ParseOptions.Diagnostics = .{};
695696 const target: CrossTarget = CrossTarget.parse(.{
696697 .arch_os_abi = zig_triple,
......@@ -814,7 +815,7 @@ const Stage2LibCInstallation = extern struct {
814815export fn stage2_libc_parse(stage1_libc: *Stage2LibCInstallation, libc_file_z: [*:0]const u8) Error {
815816 stderr_file = std.io.getStdErr();
816817 stderr = stderr_file.outStream();
817 const libc_file = mem.toSliceConst(u8, libc_file_z);
818 const libc_file = mem.spanZ(libc_file_z);
818819 var libc = LibCInstallation.parse(std.heap.c_allocator, libc_file, stderr) catch |err| switch (err) {
819820 error.ParseError => return .SemanticAnalyzeFail,
820821 error.DiskQuota => return .DiskQuota,
......@@ -995,7 +996,7 @@ const Stage2Target = extern struct {
995996 \\
996997 );
997998
998 assert(mem.endsWith(u8, llvm_features_buffer.toSliceConst(), ","));
999 assert(mem.endsWith(u8, llvm_features_buffer.span(), ","));
9991000 llvm_features_buffer.shrink(llvm_features_buffer.len() - 1);
10001001
10011002 var os_builtin_str_buffer = try std.Buffer.allocPrint(allocator,
......@@ -1120,7 +1121,7 @@ const Stage2Target = extern struct {
11201121 try os_builtin_str_buffer.append("};\n");
11211122
11221123 try cache_hash.append(
1123 os_builtin_str_buffer.toSlice()[os_builtin_str_ver_start_index..os_builtin_str_buffer.len()],
1124 os_builtin_str_buffer.span()[os_builtin_str_ver_start_index..os_builtin_str_buffer.len()],
11241125 );
11251126
11261127 const glibc_or_darwin_version = blk: {
......@@ -1232,10 +1233,10 @@ fn stage2DetectNativePaths(stage1_paths: *Stage2NativePaths) !void {
12321233 var paths = try std.zig.system.NativePaths.detect(std.heap.c_allocator);
12331234 errdefer paths.deinit();
12341235
1235 try convertSlice(paths.include_dirs.toSlice(), &stage1_paths.include_dirs_ptr, &stage1_paths.include_dirs_len);
1236 try convertSlice(paths.lib_dirs.toSlice(), &stage1_paths.lib_dirs_ptr, &stage1_paths.lib_dirs_len);
1237 try convertSlice(paths.rpaths.toSlice(), &stage1_paths.rpaths_ptr, &stage1_paths.rpaths_len);
1238 try convertSlice(paths.warnings.toSlice(), &stage1_paths.warnings_ptr, &stage1_paths.warnings_len);
1236 try convertSlice(paths.include_dirs.span(), &stage1_paths.include_dirs_ptr, &stage1_paths.include_dirs_len);
1237 try convertSlice(paths.lib_dirs.span(), &stage1_paths.lib_dirs_ptr, &stage1_paths.lib_dirs_len);
1238 try convertSlice(paths.rpaths.span(), &stage1_paths.rpaths_ptr, &stage1_paths.rpaths_len);
1239 try convertSlice(paths.warnings.span(), &stage1_paths.warnings_ptr, &stage1_paths.warnings_len);
12391240}
12401241
12411242fn convertSlice(slice: [][:0]u8, ptr: *[*][*:0]u8, len: *usize) !void {
src-self-hosted/test.zig+7-5
......@@ -88,8 +88,7 @@ pub const TestContext = struct {
8888 try std.fs.cwd().makePath(dirname);
8989 }
9090
91 // TODO async I/O
92 try std.io.writeFile(file1_path, source);
91 try std.fs.cwd().writeFile(file1_path, source);
9392
9493 var comp = try Compilation.create(
9594 &self.zig_compiler,
......@@ -122,8 +121,7 @@ pub const TestContext = struct {
122121 try std.fs.cwd().makePath(dirname);
123122 }
124123
125 // TODO async I/O
126 try std.io.writeFile(file1_path, source);
124 try std.fs.cwd().writeFile(file1_path, source);
127125
128126 var comp = try Compilation.create(
129127 &self.zig_compiler,
......@@ -156,7 +154,11 @@ pub const TestContext = struct {
156154 .Ok => {
157155 const argv = [_][]const u8{exe_file};
158156 // TODO use event loop
159 const child = try std.ChildProcess.exec(allocator, argv, null, null, 1024 * 1024);
157 const child = try std.ChildProcess.exec(.{
158 .allocator = allocator,
159 .argv = argv,
160 .max_output_bytes = 1024 * 1024,
161 });
160162 switch (child.term) {
161163 .Exited => |code| {
162164 if (code != 0) {
src-self-hosted/translate_c.zig+2-2
......@@ -235,7 +235,7 @@ pub const Context = struct {
235235
236236 /// Convert a null-terminated C string to a slice allocated in the arena
237237 fn str(c: *Context, s: [*:0]const u8) ![]u8 {
238 return mem.dupe(c.a(), u8, mem.toSliceConst(u8, s));
238 return mem.dupe(c.a(), u8, mem.spanZ(s));
239239 }
240240
241241 /// Convert a clang source location to a file:line:column string
......@@ -5851,7 +5851,7 @@ fn parseCPrefixOpExpr(c: *Context, it: *CTokenList.Iterator, source: []const u8,
58515851
58525852fn tokenSlice(c: *Context, token: ast.TokenIndex) []u8 {
58535853 const tok = c.tree.tokens.at(token);
5854 const slice = c.source_buffer.toSlice()[tok.start..tok.end];
5854 const slice = c.source_buffer.span()[tok.start..tok.end];
58555855 return if (mem.startsWith(u8, slice, "@\""))
58565856 slice[2 .. slice.len - 1]
58575857 else
src-self-hosted/util.zig+2-2
......@@ -19,8 +19,8 @@ pub fn getDarwinArchString(self: Target) [:0]const u8 {
1919pub fn llvmTargetFromTriple(triple: std.Buffer) !*llvm.Target {
2020 var result: *llvm.Target = undefined;
2121 var err_msg: [*:0]u8 = undefined;
22 if (llvm.GetTargetFromTriple(triple.toSlice(), &result, &err_msg) != 0) {
23 std.debug.warn("triple: {s} error: {s}\n", .{ triple.toSlice(), err_msg });
22 if (llvm.GetTargetFromTriple(triple.span(), &result, &err_msg) != 0) {
23 std.debug.warn("triple: {s} error: {s}\n", .{ triple.span(), err_msg });
2424 return error.UnsupportedTarget;
2525 }
2626 return result;
src-self-hosted/value.zig+2-2
......@@ -156,7 +156,7 @@ pub const Value = struct {
156156 const llvm_fn_type = try self.base.typ.getLlvmType(ofile.arena, ofile.context);
157157 const llvm_fn = llvm.AddFunction(
158158 ofile.module,
159 self.symbol_name.toSliceConst(),
159 self.symbol_name.span(),
160160 llvm_fn_type,
161161 ) orelse return error.OutOfMemory;
162162
......@@ -241,7 +241,7 @@ pub const Value = struct {
241241 const llvm_fn_type = try self.base.typ.getLlvmType(ofile.arena, ofile.context);
242242 const llvm_fn = llvm.AddFunction(
243243 ofile.module,
244 self.symbol_name.toSliceConst(),
244 self.symbol_name.span(),
245245 llvm_fn_type,
246246 ) orelse return error.OutOfMemory;
247247
test/cli.zig+8-3
......@@ -59,7 +59,12 @@ fn printCmd(cwd: []const u8, argv: []const []const u8) void {
5959
6060fn exec(cwd: []const u8, argv: []const []const u8) !ChildProcess.ExecResult {
6161 const max_output_size = 100 * 1024;
62 const result = ChildProcess.exec(a, argv, cwd, null, max_output_size) catch |err| {
62 const result = ChildProcess.exec(.{
63 .allocator = a,
64 .argv = argv,
65 .cwd = cwd,
66 .max_output_bytes = max_output_size,
67 }) catch |err| {
6368 std.debug.warn("The following command failed:\n", .{});
6469 printCmd(cwd, argv);
6570 return err;
......@@ -101,7 +106,7 @@ fn testGodboltApi(zig_exe: []const u8, dir_path: []const u8) anyerror!void {
101106 const example_zig_path = try fs.path.join(a, &[_][]const u8{ dir_path, "example.zig" });
102107 const example_s_path = try fs.path.join(a, &[_][]const u8{ dir_path, "example.s" });
103108
104 try std.io.writeFile(example_zig_path,
109 try fs.cwd().writeFile(example_zig_path,
105110 \\// Type your code here, or load an example.
106111 \\export fn square(num: i32) i32 {
107112 \\ return num * num;
......@@ -124,7 +129,7 @@ fn testGodboltApi(zig_exe: []const u8, dir_path: []const u8) anyerror!void {
124129 };
125130 _ = try exec(dir_path, &args);
126131
127 const out_asm = try std.io.readFileAlloc(a, example_s_path);
132 const out_asm = try std.fs.cwd().readFileAlloc(a, example_s_path, std.math.maxInt(usize));
128133 testing.expect(std.mem.indexOf(u8, out_asm, "square:") != null);
129134 testing.expect(std.mem.indexOf(u8, out_asm, "mov\teax, edi") != null);
130135 testing.expect(std.mem.indexOf(u8, out_asm, "imul\teax, edi") != null);
test/src/compare_output.zig+4-4
......@@ -91,7 +91,7 @@ pub const CompareOutputContext = struct {
9191 const b = self.b;
9292
9393 const write_src = b.addWriteFiles();
94 for (case.sources.toSliceConst()) |src_file| {
94 for (case.sources.span()) |src_file| {
9595 write_src.add(src_file.filename, src_file.source);
9696 }
9797
......@@ -105,7 +105,7 @@ pub const CompareOutputContext = struct {
105105 }
106106
107107 const exe = b.addExecutable("test", null);
108 exe.addAssemblyFileFromWriteFileStep(write_src, case.sources.toSliceConst()[0].filename);
108 exe.addAssemblyFileFromWriteFileStep(write_src, case.sources.span()[0].filename);
109109
110110 const run = exe.run();
111111 run.addArgs(case.cli_args);
......@@ -125,7 +125,7 @@ pub const CompareOutputContext = struct {
125125 if (mem.indexOf(u8, annotated_case_name, filter) == null) continue;
126126 }
127127
128 const basename = case.sources.toSliceConst()[0].filename;
128 const basename = case.sources.span()[0].filename;
129129 const exe = b.addExecutableFromWriteFileStep("test", write_src, basename);
130130 exe.setBuildMode(mode);
131131 if (case.link_libc) {
......@@ -146,7 +146,7 @@ pub const CompareOutputContext = struct {
146146 if (mem.indexOf(u8, annotated_case_name, filter) == null) return;
147147 }
148148
149 const basename = case.sources.toSliceConst()[0].filename;
149 const basename = case.sources.span()[0].filename;
150150 const exe = b.addExecutableFromWriteFileStep("test", write_src, basename);
151151 if (case.link_libc) {
152152 exe.linkSystemLibrary("c");
test/src/run_translated_c.zig+2-2
......@@ -82,13 +82,13 @@ pub const RunTranslatedCContext = struct {
8282 }
8383
8484 const write_src = b.addWriteFiles();
85 for (case.sources.toSliceConst()) |src_file| {
85 for (case.sources.span()) |src_file| {
8686 write_src.add(src_file.filename, src_file.source);
8787 }
8888 const translate_c = b.addTranslateC(.{
8989 .write_file = .{
9090 .step = write_src,
91 .basename = case.sources.toSliceConst()[0].filename,
91 .basename = case.sources.span()[0].filename,
9292 },
9393 });
9494 translate_c.step.name = b.fmt("{} translate-c", .{annotated_case_name});
test/src/translate_c.zig+3-3
......@@ -105,20 +105,20 @@ pub const TranslateCContext = struct {
105105 }
106106
107107 const write_src = b.addWriteFiles();
108 for (case.sources.toSliceConst()) |src_file| {
108 for (case.sources.span()) |src_file| {
109109 write_src.add(src_file.filename, src_file.source);
110110 }
111111
112112 const translate_c = b.addTranslateC(.{
113113 .write_file = .{
114114 .step = write_src,
115 .basename = case.sources.toSliceConst()[0].filename,
115 .basename = case.sources.span()[0].filename,
116116 },
117117 });
118118 translate_c.step.name = annotated_case_name;
119119 translate_c.setTarget(case.target);
120120
121 const check_file = translate_c.addCheckFile(case.expected_lines.toSliceConst());
121 const check_file = translate_c.addCheckFile(case.expected_lines.span());
122122
123123 self.step.dependOn(&check_file.step);
124124 }
test/stage1/behavior/cast.zig+1-1
......@@ -329,7 +329,7 @@ fn testCastPtrOfArrayToSliceAndPtr() void {
329329test "cast *[1][*]const u8 to [*]const ?[*]const u8" {
330330 const window_name = [1][*]const u8{"window name"};
331331 const x: [*]const ?[*]const u8 = &window_name;
332 expect(mem.eql(u8, std.mem.toSliceConst(u8, @ptrCast([*:0]const u8, x[0].?)), "window name"));
332 expect(mem.eql(u8, std.mem.spanZ(@ptrCast([*:0]const u8, x[0].?)), "window name"));
333333}
334334
335335test "@intCast comptime_int" {
test/stage1/behavior/pointers.zig+1-1
......@@ -225,7 +225,7 @@ test "null terminated pointer" {
225225 var zero_ptr: [*:0]const u8 = @ptrCast([*:0]const u8, &array_with_zero);
226226 var no_zero_ptr: [*]const u8 = zero_ptr;
227227 var zero_ptr_again = @ptrCast([*:0]const u8, no_zero_ptr);
228 expect(std.mem.eql(u8, std.mem.toSliceConst(u8, zero_ptr_again), "hello"));
228 expect(std.mem.eql(u8, std.mem.spanZ(zero_ptr_again), "hello"));
229229 }
230230 };
231231 S.doTheTest();
test/standalone/brace_expansion/main.zig+10-10
......@@ -131,11 +131,11 @@ fn expandString(input: []const u8, output: *Buffer) !void {
131131 try expandNode(root, &result_list);
132132
133133 try output.resize(0);
134 for (result_list.toSliceConst()) |buf, i| {
134 for (result_list.span()) |buf, i| {
135135 if (i != 0) {
136136 try output.appendByte(' ');
137137 }
138 try output.append(buf.toSliceConst());
138 try output.append(buf.span());
139139 }
140140}
141141
......@@ -157,20 +157,20 @@ fn expandNode(node: Node, output: *ArrayList(Buffer)) ExpandNodeError!void {
157157 var child_list_b = ArrayList(Buffer).init(global_allocator);
158158 try expandNode(b_node, &child_list_b);
159159
160 for (child_list_a.toSliceConst()) |buf_a| {
161 for (child_list_b.toSliceConst()) |buf_b| {
160 for (child_list_a.span()) |buf_a| {
161 for (child_list_b.span()) |buf_b| {
162162 var combined_buf = try Buffer.initFromBuffer(buf_a);
163 try combined_buf.append(buf_b.toSliceConst());
163 try combined_buf.append(buf_b.span());
164164 try output.append(combined_buf);
165165 }
166166 }
167167 },
168168 Node.List => |list| {
169 for (list.toSliceConst()) |child_node| {
169 for (list.span()) |child_node| {
170170 var child_list = ArrayList(Buffer).init(global_allocator);
171171 try expandNode(child_node, &child_list);
172172
173 for (child_list.toSliceConst()) |buf| {
173 for (child_list.span()) |buf| {
174174 try output.append(buf);
175175 }
176176 }
......@@ -196,8 +196,8 @@ pub fn main() !void {
196196 var result_buf = try Buffer.initSize(global_allocator, 0);
197197 defer result_buf.deinit();
198198
199 try expandString(stdin_buf.toSlice(), &result_buf);
200 try stdout_file.write(result_buf.toSliceConst());
199 try expandString(stdin_buf.span(), &result_buf);
200 try stdout_file.write(result_buf.span());
201201}
202202
203203test "invalid inputs" {
......@@ -256,5 +256,5 @@ fn expectExpansion(test_input: []const u8, expected_result: []const u8) void {
256256
257257 expandString(test_input, &result) catch unreachable;
258258
259 testing.expectEqualSlices(u8, expected_result, result.toSlice());
259 testing.expectEqualSlices(u8, expected_result, result.span());
260260}
test/standalone/guess_number/main.zig+1-1
......@@ -17,7 +17,7 @@ pub fn main() !void {
1717 const seed = std.mem.readIntNative(u64, &seed_bytes);
1818 var prng = std.rand.DefaultPrng.init(seed);
1919
20 const answer = prng.random.range(u8, 0, 100) + 1;
20 const answer = prng.random.intRangeLessThan(u8, 0, 100) + 1;
2121
2222 while (true) {
2323 try stdout.print("\nGuess a number between 1 and 100: ", .{});
test/tests.zig+23-23
......@@ -583,7 +583,7 @@ pub const StackTracesContext = struct {
583583
584584 warn("Test {}/{} {}...", .{ self.test_index + 1, self.context.test_index, self.name });
585585
586 const child = std.ChildProcess.init(args.toSliceConst(), b.allocator) catch unreachable;
586 const child = std.ChildProcess.init(args.span(), b.allocator) catch unreachable;
587587 defer child.deinit();
588588
589589 child.stdin_behavior = .Ignore;
......@@ -592,7 +592,7 @@ pub const StackTracesContext = struct {
592592 child.env_map = b.env_map;
593593
594594 if (b.verbose) {
595 printInvocation(args.toSliceConst());
595 printInvocation(args.span());
596596 }
597597 child.spawn() catch |err| debug.panic("Unable to spawn {}: {}\n", .{ full_exe_path, @errorName(err) });
598598
......@@ -614,23 +614,23 @@ pub const StackTracesContext = struct {
614614 code,
615615 expect_code,
616616 });
617 printInvocation(args.toSliceConst());
617 printInvocation(args.span());
618618 return error.TestFailed;
619619 }
620620 },
621621 .Signal => |signum| {
622622 warn("Process {} terminated on signal {}\n", .{ full_exe_path, signum });
623 printInvocation(args.toSliceConst());
623 printInvocation(args.span());
624624 return error.TestFailed;
625625 },
626626 .Stopped => |signum| {
627627 warn("Process {} stopped on signal {}\n", .{ full_exe_path, signum });
628 printInvocation(args.toSliceConst());
628 printInvocation(args.span());
629629 return error.TestFailed;
630630 },
631631 .Unknown => |code| {
632632 warn("Process {} terminated unexpectedly with error code {}\n", .{ full_exe_path, code });
633 printInvocation(args.toSliceConst());
633 printInvocation(args.span());
634634 return error.TestFailed;
635635 },
636636 }
......@@ -785,7 +785,7 @@ pub const CompileErrorContext = struct {
785785 } else {
786786 try zig_args.append("build-obj");
787787 }
788 const root_src_basename = self.case.sources.toSliceConst()[0].filename;
788 const root_src_basename = self.case.sources.span()[0].filename;
789789 try zig_args.append(self.write_src.getOutputPath(root_src_basename));
790790
791791 zig_args.append("--name") catch unreachable;
......@@ -809,10 +809,10 @@ pub const CompileErrorContext = struct {
809809 warn("Test {}/{} {}...", .{ self.test_index + 1, self.context.test_index, self.name });
810810
811811 if (b.verbose) {
812 printInvocation(zig_args.toSliceConst());
812 printInvocation(zig_args.span());
813813 }
814814
815 const child = std.ChildProcess.init(zig_args.toSliceConst(), b.allocator) catch unreachable;
815 const child = std.ChildProcess.init(zig_args.span(), b.allocator) catch unreachable;
816816 defer child.deinit();
817817
818818 child.env_map = b.env_map;
......@@ -822,11 +822,11 @@ pub const CompileErrorContext = struct {
822822
823823 child.spawn() catch |err| debug.panic("Unable to spawn {}: {}\n", .{ zig_args.items[0], @errorName(err) });
824824
825 var stdout_buf = Buffer.initNull(b.allocator);
826 var stderr_buf = Buffer.initNull(b.allocator);
825 var stdout_buf = ArrayList(u8).init(b.allocator);
826 var stderr_buf = ArrayList(u8).init(b.allocator);
827827
828 child.stdout.?.inStream().readAllBuffer(&stdout_buf, max_stdout_size) catch unreachable;
829 child.stderr.?.inStream().readAllBuffer(&stderr_buf, max_stdout_size) catch unreachable;
828 child.stdout.?.inStream().readAllArrayList(&stdout_buf, max_stdout_size) catch unreachable;
829 child.stderr.?.inStream().readAllArrayList(&stderr_buf, max_stdout_size) catch unreachable;
830830
831831 const term = child.wait() catch |err| {
832832 debug.panic("Unable to spawn {}: {}\n", .{ zig_args.items[0], @errorName(err) });
......@@ -834,19 +834,19 @@ pub const CompileErrorContext = struct {
834834 switch (term) {
835835 .Exited => |code| {
836836 if (code == 0) {
837 printInvocation(zig_args.toSliceConst());
837 printInvocation(zig_args.span());
838838 return error.CompilationIncorrectlySucceeded;
839839 }
840840 },
841841 else => {
842842 warn("Process {} terminated unexpectedly\n", .{b.zig_exe});
843 printInvocation(zig_args.toSliceConst());
843 printInvocation(zig_args.span());
844844 return error.TestFailed;
845845 },
846846 }
847847
848 const stdout = stdout_buf.toSliceConst();
849 const stderr = stderr_buf.toSliceConst();
848 const stdout = stdout_buf.span();
849 const stderr = stderr_buf.span();
850850
851851 if (stdout.len != 0) {
852852 warn(
......@@ -875,12 +875,12 @@ pub const CompileErrorContext = struct {
875875
876876 if (!ok) {
877877 warn("\n======== Expected these compile errors: ========\n", .{});
878 for (self.case.expected_errors.toSliceConst()) |expected| {
878 for (self.case.expected_errors.span()) |expected| {
879879 warn("{}\n", .{expected});
880880 }
881881 }
882882 } else {
883 for (self.case.expected_errors.toSliceConst()) |expected| {
883 for (self.case.expected_errors.span()) |expected| {
884884 if (mem.indexOf(u8, stderr, expected) == null) {
885885 warn(
886886 \\
......@@ -980,7 +980,7 @@ pub const CompileErrorContext = struct {
980980 if (mem.indexOf(u8, annotated_case_name, filter) == null) return;
981981 }
982982 const write_src = b.addWriteFiles();
983 for (case.sources.toSliceConst()) |src_file| {
983 for (case.sources.span()) |src_file| {
984984 write_src.add(src_file.filename, src_file.source);
985985 }
986986
......@@ -1027,7 +1027,7 @@ pub const StandaloneContext = struct {
10271027 zig_args.append("--verbose") catch unreachable;
10281028 }
10291029
1030 const run_cmd = b.addSystemCommand(zig_args.toSliceConst());
1030 const run_cmd = b.addSystemCommand(zig_args.span());
10311031
10321032 const log_step = b.addLog("PASS {}\n", .{annotated_case_name});
10331033 log_step.step.dependOn(&run_cmd.step);
......@@ -1127,7 +1127,7 @@ pub const GenHContext = struct {
11271127 const full_h_path = self.obj.getOutputHPath();
11281128 const actual_h = try io.readFileAlloc(b.allocator, full_h_path);
11291129
1130 for (self.case.expected_lines.toSliceConst()) |expected_line| {
1130 for (self.case.expected_lines.span()) |expected_line| {
11311131 if (mem.indexOf(u8, actual_h, expected_line) == null) {
11321132 warn(
11331133 \\
......@@ -1188,7 +1188,7 @@ pub const GenHContext = struct {
11881188 }
11891189
11901190 const write_src = b.addWriteFiles();
1191 for (case.sources.toSliceConst()) |src_file| {
1191 for (case.sources.span()) |src_file| {
11921192 write_src.add(src_file.filename, src_file.source);
11931193 }
11941194
tools/merge_anal_dumps.zig+12-12
......@@ -183,13 +183,13 @@ const Dump = struct {
183183 try mergeSameStrings(&self.zig_version, zig_version);
184184 try mergeSameStrings(&self.root_name, root_name);
185185
186 for (params.get("builds").?.value.Array.toSliceConst()) |json_build| {
186 for (params.get("builds").?.value.Array.span()) |json_build| {
187187 const target = json_build.Object.get("target").?.value.String;
188188 try self.targets.append(target);
189189 }
190190
191191 // Merge files. If the string matches, it's the same file.
192 const other_files = root.Object.get("files").?.value.Array.toSliceConst();
192 const other_files = root.Object.get("files").?.value.Array.span();
193193 var other_file_to_mine = std.AutoHashMap(usize, usize).init(self.a());
194194 for (other_files) |other_file, i| {
195195 const gop = try self.file_map.getOrPut(other_file.String);
......@@ -201,7 +201,7 @@ const Dump = struct {
201201 }
202202
203203 // Merge AST nodes. If the file id, line, and column all match, it's the same AST node.
204 const other_ast_nodes = root.Object.get("astNodes").?.value.Array.toSliceConst();
204 const other_ast_nodes = root.Object.get("astNodes").?.value.Array.span();
205205 var other_ast_node_to_mine = std.AutoHashMap(usize, usize).init(self.a());
206206 for (other_ast_nodes) |other_ast_node_json, i| {
207207 const other_file_id = jsonObjInt(other_ast_node_json, "file");
......@@ -221,9 +221,9 @@ const Dump = struct {
221221 // convert fields lists
222222 for (other_ast_nodes) |other_ast_node_json, i| {
223223 const my_node_index = other_ast_node_to_mine.get(i).?.value;
224 const my_node = &self.node_list.toSlice()[my_node_index];
224 const my_node = &self.node_list.span()[my_node_index];
225225 if (other_ast_node_json.Object.get("fields")) |fields_json_kv| {
226 const other_fields = fields_json_kv.value.Array.toSliceConst();
226 const other_fields = fields_json_kv.value.Array.span();
227227 my_node.fields = try self.a().alloc(usize, other_fields.len);
228228 for (other_fields) |other_field_index, field_i| {
229229 const other_index = @intCast(usize, other_field_index.Integer);
......@@ -233,7 +233,7 @@ const Dump = struct {
233233 }
234234
235235 // Merge errors. If the AST Node matches, it's the same error value.
236 const other_errors = root.Object.get("errors").?.value.Array.toSliceConst();
236 const other_errors = root.Object.get("errors").?.value.Array.span();
237237 var other_error_to_mine = std.AutoHashMap(usize, usize).init(self.a());
238238 for (other_errors) |other_error_json, i| {
239239 const other_src_id = jsonObjInt(other_error_json, "src");
......@@ -253,7 +253,7 @@ const Dump = struct {
253253 // First we identify all the simple types and merge those.
254254 // Example: void, type, noreturn
255255 // We can also do integers and floats.
256 const other_types = root.Object.get("types").?.value.Array.toSliceConst();
256 const other_types = root.Object.get("types").?.value.Array.span();
257257 var other_types_to_mine = std.AutoHashMap(usize, usize).init(self.a());
258258 for (other_types) |other_type_json, i| {
259259 const type_kind = jsonObjInt(other_type_json, "kind");
......@@ -336,7 +336,7 @@ const Dump = struct {
336336
337337 try jw.objectField("builds");
338338 try jw.beginArray();
339 for (self.targets.toSliceConst()) |target| {
339 for (self.targets.span()) |target| {
340340 try jw.arrayElem();
341341 try jw.beginObject();
342342 try jw.objectField("target");
......@@ -349,7 +349,7 @@ const Dump = struct {
349349
350350 try jw.objectField("types");
351351 try jw.beginArray();
352 for (self.type_list.toSliceConst()) |t| {
352 for (self.type_list.span()) |t| {
353353 try jw.arrayElem();
354354 try jw.beginObject();
355355
......@@ -379,7 +379,7 @@ const Dump = struct {
379379
380380 try jw.objectField("errors");
381381 try jw.beginArray();
382 for (self.error_list.toSliceConst()) |zig_error| {
382 for (self.error_list.span()) |zig_error| {
383383 try jw.arrayElem();
384384 try jw.beginObject();
385385
......@@ -395,7 +395,7 @@ const Dump = struct {
395395
396396 try jw.objectField("astNodes");
397397 try jw.beginArray();
398 for (self.node_list.toSliceConst()) |node| {
398 for (self.node_list.span()) |node| {
399399 try jw.arrayElem();
400400 try jw.beginObject();
401401
......@@ -425,7 +425,7 @@ const Dump = struct {
425425
426426 try jw.objectField("files");
427427 try jw.beginArray();
428 for (self.file_list.toSliceConst()) |file| {
428 for (self.file_list.span()) |file| {
429429 try jw.arrayElem();
430430 try jw.emitString(file);
431431 }
tools/process_headers.zig+4-4
......@@ -324,7 +324,7 @@ pub fn main() !void {
324324 },
325325 .os = .linux,
326326 };
327 search: for (search_paths.toSliceConst()) |search_path| {
327 search: for (search_paths.span()) |search_path| {
328328 var sub_path: []const []const u8 = undefined;
329329 switch (vendor) {
330330 .musl => {
......@@ -414,13 +414,13 @@ pub fn main() !void {
414414 try contents_list.append(contents);
415415 }
416416 }
417 std.sort.sort(*Contents, contents_list.toSlice(), Contents.hitCountLessThan);
417 std.sort.sort(*Contents, contents_list.span(), Contents.hitCountLessThan);
418418 var best_contents = contents_list.popOrNull().?;
419419 if (best_contents.hit_count > 1) {
420420 // worth it to make it generic
421421 const full_path = try std.fs.path.join(allocator, &[_][]const u8{ out_dir, generic_name, path_kv.key });
422422 try std.fs.cwd().makePath(std.fs.path.dirname(full_path).?);
423 try std.io.writeFile(full_path, best_contents.bytes);
423 try std.fs.cwd().writeFile(full_path, best_contents.bytes);
424424 best_contents.is_generic = true;
425425 while (contents_list.popOrNull()) |contender| {
426426 if (contender.hit_count > 1) {
......@@ -447,7 +447,7 @@ pub fn main() !void {
447447 });
448448 const full_path = try std.fs.path.join(allocator, &[_][]const u8{ out_dir, out_subpath, path_kv.key });
449449 try std.fs.cwd().makePath(std.fs.path.dirname(full_path).?);
450 try std.io.writeFile(full_path, contents.bytes);
450 try std.fs.cwd().writeFile(full_path, contents.bytes);
451451 }
452452 }
453453}
tools/update_clang_options.zig+1-1
......@@ -239,7 +239,7 @@ pub fn main() anyerror!void {
239239 try std.fmt.allocPrint(allocator, "-I={}/clang/include/clang/Driver", .{llvm_src_root}),
240240 };
241241
242 const child_result = try std.ChildProcess.exec2(.{
242 const child_result = try std.ChildProcess.exec(.{
243243 .allocator = allocator,
244244 .argv = &child_args,
245245 .max_output_bytes = 100 * 1024 * 1024,
tools/update_glibc.zig+7-7
......@@ -223,15 +223,15 @@ pub fn main() !void {
223223 var list = std.ArrayList([]const u8).init(allocator);
224224 var it = global_fn_set.iterator();
225225 while (it.next()) |kv| try list.append(kv.key);
226 std.sort.sort([]const u8, list.toSlice(), strCmpLessThan);
227 break :blk list.toSliceConst();
226 std.sort.sort([]const u8, list.span(), strCmpLessThan);
227 break :blk list.span();
228228 };
229229 const global_ver_list = blk: {
230230 var list = std.ArrayList([]const u8).init(allocator);
231231 var it = global_ver_set.iterator();
232232 while (it.next()) |kv| try list.append(kv.key);
233 std.sort.sort([]const u8, list.toSlice(), versionLessThan);
234 break :blk list.toSliceConst();
233 std.sort.sort([]const u8, list.span(), versionLessThan);
234 break :blk list.span();
235235 };
236236 {
237237 const vers_txt_path = try fs.path.join(allocator, &[_][]const u8{ glibc_out_dir, "vers.txt" });
......@@ -264,13 +264,13 @@ pub fn main() !void {
264264 for (abi_lists) |*abi_list, abi_index| {
265265 const kv = target_functions.get(@ptrToInt(abi_list)).?;
266266 const fn_vers_list = &kv.value.fn_vers_list;
267 for (kv.value.list.toSliceConst()) |*ver_fn| {
267 for (kv.value.list.span()) |*ver_fn| {
268268 const gop = try fn_vers_list.getOrPut(ver_fn.name);
269269 if (!gop.found_existing) {
270270 gop.kv.value = std.ArrayList(usize).init(allocator);
271271 }
272272 const ver_index = global_ver_set.get(ver_fn.ver).?.value;
273 if (std.mem.indexOfScalar(usize, gop.kv.value.toSliceConst(), ver_index) == null) {
273 if (std.mem.indexOfScalar(usize, gop.kv.value.span(), ver_index) == null) {
274274 try gop.kv.value.append(ver_index);
275275 }
276276 }
......@@ -297,7 +297,7 @@ pub fn main() !void {
297297 try abilist_txt.writeByte('\n');
298298 continue;
299299 };
300 for (kv.value.toSliceConst()) |ver_index, it_i| {
300 for (kv.value.span()) |ver_index, it_i| {
301301 if (it_i != 0) try abilist_txt.writeByte(' ');
302302 try abilist_txt.print("{d}", .{ver_index});
303303 }