| author | |
| committer | |
| log | 9e7ae062492d4b41564832d37408336e36165e67 |
| tree | b6b898deb26a63f264ee43e00ecfe883a1e8db99 |
| parent | b980568c810fda4c014da42be8e5108b4cbadb7c |
| signature |
See #381170 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 |
| 1048 | 1048 | allocator, |
| 1049 | 1049 | &[_][]const u8{ tmp_dir_name, name_plus_ext }, |
| 1050 | 1050 | ); |
| 1051 | try io.writeFile(tmp_source_file_name, trimmed_raw_source); | |
| 1051 | try fs.cwd().writeFile(tmp_source_file_name, trimmed_raw_source); | |
| 1052 | 1052 | |
| 1053 | 1053 | switch (code.id) { |
| 1054 | 1054 | Code.Id.Exe => |expected_outcome| code_block: { |
| ... | ... | @@ -1106,18 +1106,17 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var |
| 1106 | 1106 | } |
| 1107 | 1107 | } |
| 1108 | 1108 | 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 | }); | |
| 1116 | 1115 | switch (result.term) { |
| 1117 | 1116 | .Exited => |exit_code| { |
| 1118 | 1117 | if (exit_code == 0) { |
| 1119 | 1118 | warn("{}\nThe following command incorrectly succeeded:\n", .{result.stderr}); |
| 1120 | for (build_args.toSliceConst()) |arg| | |
| 1119 | for (build_args.span()) |arg| | |
| 1121 | 1120 | warn("{} ", .{arg}) |
| 1122 | 1121 | else |
| 1123 | 1122 | warn("\n", .{}); |
| ... | ... | @@ -1126,7 +1125,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var |
| 1126 | 1125 | }, |
| 1127 | 1126 | else => { |
| 1128 | 1127 | warn("{}\nThe following command crashed:\n", .{result.stderr}); |
| 1129 | for (build_args.toSliceConst()) |arg| | |
| 1128 | for (build_args.span()) |arg| | |
| 1130 | 1129 | warn("{} ", .{arg}) |
| 1131 | 1130 | else |
| 1132 | 1131 | warn("\n", .{}); |
| ... | ... | @@ -1138,7 +1137,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var |
| 1138 | 1137 | try out.print("\n{}</code></pre>\n", .{colored_stderr}); |
| 1139 | 1138 | break :code_block; |
| 1140 | 1139 | } |
| 1141 | const exec_result = exec(allocator, &env_map, build_args.toSliceConst()) catch | |
| 1140 | const exec_result = exec(allocator, &env_map, build_args.span()) catch | |
| 1142 | 1141 | return parseError(tokenizer, code.source_token, "example failed to compile", .{}); |
| 1143 | 1142 | |
| 1144 | 1143 | if (code.target_str) |triple| { |
| ... | ... | @@ -1167,7 +1166,12 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var |
| 1167 | 1166 | var exited_with_signal = false; |
| 1168 | 1167 | |
| 1169 | 1168 | 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 | }); | |
| 1171 | 1175 | switch (result.term) { |
| 1172 | 1176 | .Exited => |exit_code| { |
| 1173 | 1177 | if (exit_code == 0) { |
| ... | ... | @@ -1234,7 +1238,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var |
| 1234 | 1238 | try test_args.appendSlice(&[_][]const u8{ "-target", triple }); |
| 1235 | 1239 | try out.print(" -target {}", .{triple}); |
| 1236 | 1240 | } |
| 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", .{}); | |
| 1238 | 1242 | const escaped_stderr = try escapeHtml(allocator, result.stderr); |
| 1239 | 1243 | const escaped_stdout = try escapeHtml(allocator, result.stdout); |
| 1240 | 1244 | 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 |
| 1268 | 1272 | try out.print(" --release-small", .{}); |
| 1269 | 1273 | }, |
| 1270 | 1274 | } |
| 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 | }); | |
| 1272 | 1281 | switch (result.term) { |
| 1273 | 1282 | .Exited => |exit_code| { |
| 1274 | 1283 | if (exit_code == 0) { |
| 1275 | 1284 | warn("{}\nThe following command incorrectly succeeded:\n", .{result.stderr}); |
| 1276 | for (test_args.toSliceConst()) |arg| | |
| 1285 | for (test_args.span()) |arg| | |
| 1277 | 1286 | warn("{} ", .{arg}) |
| 1278 | 1287 | else |
| 1279 | 1288 | warn("\n", .{}); |
| ... | ... | @@ -1282,7 +1291,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var |
| 1282 | 1291 | }, |
| 1283 | 1292 | else => { |
| 1284 | 1293 | warn("{}\nThe following command crashed:\n", .{result.stderr}); |
| 1285 | for (test_args.toSliceConst()) |arg| | |
| 1294 | for (test_args.span()) |arg| | |
| 1286 | 1295 | warn("{} ", .{arg}) |
| 1287 | 1296 | else |
| 1288 | 1297 | warn("\n", .{}); |
| ... | ... | @@ -1326,12 +1335,17 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var |
| 1326 | 1335 | }, |
| 1327 | 1336 | } |
| 1328 | 1337 | |
| 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 | }); | |
| 1330 | 1344 | switch (result.term) { |
| 1331 | 1345 | .Exited => |exit_code| { |
| 1332 | 1346 | if (exit_code == 0) { |
| 1333 | 1347 | warn("{}\nThe following command incorrectly succeeded:\n", .{result.stderr}); |
| 1334 | for (test_args.toSliceConst()) |arg| | |
| 1348 | for (test_args.span()) |arg| | |
| 1335 | 1349 | warn("{} ", .{arg}) |
| 1336 | 1350 | else |
| 1337 | 1351 | warn("\n", .{}); |
| ... | ... | @@ -1340,7 +1354,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var |
| 1340 | 1354 | }, |
| 1341 | 1355 | else => { |
| 1342 | 1356 | warn("{}\nThe following command crashed:\n", .{result.stderr}); |
| 1343 | for (test_args.toSliceConst()) |arg| | |
| 1357 | for (test_args.span()) |arg| | |
| 1344 | 1358 | warn("{} ", .{arg}) |
| 1345 | 1359 | else |
| 1346 | 1360 | warn("\n", .{}); |
| ... | ... | @@ -1418,12 +1432,17 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var |
| 1418 | 1432 | } |
| 1419 | 1433 | |
| 1420 | 1434 | 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 | }); | |
| 1422 | 1441 | switch (result.term) { |
| 1423 | 1442 | .Exited => |exit_code| { |
| 1424 | 1443 | if (exit_code == 0) { |
| 1425 | 1444 | warn("{}\nThe following command incorrectly succeeded:\n", .{result.stderr}); |
| 1426 | for (build_args.toSliceConst()) |arg| | |
| 1445 | for (build_args.span()) |arg| | |
| 1427 | 1446 | warn("{} ", .{arg}) |
| 1428 | 1447 | else |
| 1429 | 1448 | warn("\n", .{}); |
| ... | ... | @@ -1432,7 +1451,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var |
| 1432 | 1451 | }, |
| 1433 | 1452 | else => { |
| 1434 | 1453 | warn("{}\nThe following command crashed:\n", .{result.stderr}); |
| 1435 | for (build_args.toSliceConst()) |arg| | |
| 1454 | for (build_args.span()) |arg| | |
| 1436 | 1455 | warn("{} ", .{arg}) |
| 1437 | 1456 | else |
| 1438 | 1457 | warn("\n", .{}); |
| ... | ... | @@ -1447,7 +1466,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var |
| 1447 | 1466 | const colored_stderr = try termColor(allocator, escaped_stderr); |
| 1448 | 1467 | try out.print("\n{}", .{colored_stderr}); |
| 1449 | 1468 | } 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", .{}); | |
| 1451 | 1470 | } |
| 1452 | 1471 | if (!code.is_inline) { |
| 1453 | 1472 | try out.print("</code></pre>\n", .{}); |
| ... | ... | @@ -1484,7 +1503,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var |
| 1484 | 1503 | try test_args.appendSlice(&[_][]const u8{ "-target", triple }); |
| 1485 | 1504 | try out.print(" -target {}", .{triple}); |
| 1486 | 1505 | } |
| 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", .{}); | |
| 1488 | 1507 | const escaped_stderr = try escapeHtml(allocator, result.stderr); |
| 1489 | 1508 | const escaped_stdout = try escapeHtml(allocator, result.stdout); |
| 1490 | 1509 | 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 |
| 1497 | 1516 | } |
| 1498 | 1517 | |
| 1499 | 1518 | fn 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(.{ | |
| 1501 | 1520 | .allocator = allocator, |
| 1502 | 1521 | .argv = args, |
| 1503 | 1522 | .env_map = env_map, |
doc/langref.html.in+2-2| ... | ... | @@ -4953,7 +4953,7 @@ const mem = std.mem; |
| 4953 | 4953 | test "cast *[1][*]const u8 to [*]const ?[*]const u8" { |
| 4954 | 4954 | const window_name = [1][*]const u8{"window name"}; |
| 4955 | 4955 | 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")); | |
| 4957 | 4957 | } |
| 4958 | 4958 | {#code_end#} |
| 4959 | 4959 | {#header_close#} |
| ... | ... | @@ -9310,7 +9310,7 @@ test "string literal to constant slice" { |
| 9310 | 9310 | </p> |
| 9311 | 9311 | <p> |
| 9312 | 9312 | 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 | |
| 9314 | 9314 | valid until the next time the list is resized, such as by appending new elements. |
| 9315 | 9315 | </p> |
| 9316 | 9316 | <p> |
lib/std/atomic/queue.zig+1-1| ... | ... | @@ -227,7 +227,7 @@ fn startPuts(ctx: *Context) u8 { |
| 227 | 227 | var r = std.rand.DefaultPrng.init(0xdeadbeef); |
| 228 | 228 | while (put_count != 0) : (put_count -= 1) { |
| 229 | 229 | 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)); | |
| 231 | 231 | const node = ctx.allocator.create(Queue(i32).Node) catch unreachable; |
| 232 | 232 | node.* = .{ |
| 233 | 233 | .prev = undefined, |
lib/std/atomic/stack.zig+1-1| ... | ... | @@ -150,7 +150,7 @@ fn startPuts(ctx: *Context) u8 { |
| 150 | 150 | var r = std.rand.DefaultPrng.init(0xdeadbeef); |
| 151 | 151 | while (put_count != 0) : (put_count -= 1) { |
| 152 | 152 | 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)); | |
| 154 | 154 | const node = ctx.allocator.create(Stack(i32).Node) catch unreachable; |
| 155 | 155 | node.* = Stack(i32).Node{ |
| 156 | 156 | .next = undefined, |
lib/std/buffer.zig+13-20| ... | ... | @@ -43,7 +43,7 @@ pub const Buffer = struct { |
| 43 | 43 | |
| 44 | 44 | /// Must deinitialize with deinit. |
| 45 | 45 | pub fn initFromBuffer(buffer: Buffer) !Buffer { |
| 46 | return Buffer.init(buffer.list.allocator, buffer.toSliceConst()); | |
| 46 | return Buffer.init(buffer.list.allocator, buffer.span()); | |
| 47 | 47 | } |
| 48 | 48 | |
| 49 | 49 | /// Buffer takes ownership of the passed in slice. The slice must have been |
| ... | ... | @@ -81,15 +81,8 @@ pub const Buffer = struct { |
| 81 | 81 | return self.list.span()[0..self.len() :0]; |
| 82 | 82 | } |
| 83 | 83 | |
| 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()"); | |
| 93 | 86 | |
| 94 | 87 | pub fn shrink(self: *Buffer, new_len: usize) void { |
| 95 | 88 | assert(new_len <= self.len()); |
| ... | ... | @@ -120,17 +113,17 @@ pub const Buffer = struct { |
| 120 | 113 | pub fn append(self: *Buffer, m: []const u8) !void { |
| 121 | 114 | const old_len = self.len(); |
| 122 | 115 | 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); | |
| 124 | 117 | } |
| 125 | 118 | |
| 126 | 119 | pub fn appendByte(self: *Buffer, byte: u8) !void { |
| 127 | 120 | const old_len = self.len(); |
| 128 | 121 | try self.resize(old_len + 1); |
| 129 | self.list.toSlice()[old_len] = byte; | |
| 122 | self.list.span()[old_len] = byte; | |
| 130 | 123 | } |
| 131 | 124 | |
| 132 | 125 | 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); | |
| 134 | 127 | } |
| 135 | 128 | |
| 136 | 129 | pub fn startsWith(self: Buffer, m: []const u8) bool { |
| ... | ... | @@ -147,7 +140,7 @@ pub const Buffer = struct { |
| 147 | 140 | |
| 148 | 141 | pub fn replaceContents(self: *Buffer, m: []const u8) !void { |
| 149 | 142 | try self.resize(m.len); |
| 150 | mem.copy(u8, self.list.toSlice(), m); | |
| 143 | mem.copy(u8, self.list.span(), m); | |
| 151 | 144 | } |
| 152 | 145 | |
| 153 | 146 | pub fn outStream(self: *Buffer) std.io.OutStream(*Buffer, error{OutOfMemory}, appendWrite) { |
| ... | ... | @@ -171,17 +164,17 @@ test "simple Buffer" { |
| 171 | 164 | try buf.append(" "); |
| 172 | 165 | try buf.append("world"); |
| 173 | 166 | 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())); | |
| 175 | 168 | |
| 176 | 169 | var buf2 = try Buffer.initFromBuffer(buf); |
| 177 | 170 | defer buf2.deinit(); |
| 178 | testing.expect(buf.eql(buf2.toSliceConst())); | |
| 171 | testing.expect(buf.eql(buf2.span())); | |
| 179 | 172 | |
| 180 | 173 | testing.expect(buf.startsWith("hell")); |
| 181 | 174 | testing.expect(buf.endsWith("orld")); |
| 182 | 175 | |
| 183 | 176 | try buf2.resize(4); |
| 184 | testing.expect(buf.startsWith(buf2.toSlice())); | |
| 177 | testing.expect(buf.startsWith(buf2.span())); | |
| 185 | 178 | } |
| 186 | 179 | |
| 187 | 180 | test "Buffer.initSize" { |
| ... | ... | @@ -189,7 +182,7 @@ test "Buffer.initSize" { |
| 189 | 182 | defer buf.deinit(); |
| 190 | 183 | testing.expect(buf.len() == 3); |
| 191 | 184 | try buf.append("hello"); |
| 192 | testing.expect(mem.eql(u8, buf.toSliceConst()[3..], "hello")); | |
| 185 | testing.expect(mem.eql(u8, buf.span()[3..], "hello")); | |
| 193 | 186 | } |
| 194 | 187 | |
| 195 | 188 | test "Buffer.initCapacity" { |
| ... | ... | @@ -201,7 +194,7 @@ test "Buffer.initCapacity" { |
| 201 | 194 | try buf.append("hello"); |
| 202 | 195 | testing.expect(buf.len() == 5); |
| 203 | 196 | testing.expect(buf.capacity() == old_cap); |
| 204 | testing.expect(mem.eql(u8, buf.toSliceConst(), "hello")); | |
| 197 | testing.expect(mem.eql(u8, buf.span(), "hello")); | |
| 205 | 198 | } |
| 206 | 199 | |
| 207 | 200 | test "Buffer.print" { |
| ... | ... | @@ -221,5 +214,5 @@ test "Buffer.outStream" { |
| 221 | 214 | const y: i32 = 1234; |
| 222 | 215 | try buf_stream.print("x: {}\ny: {}\n", .{ x, y }); |
| 223 | 216 | |
| 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")); | |
| 225 | 218 | } |
lib/std/build.zig+20-23| ... | ... | @@ -355,7 +355,7 @@ pub const Builder = struct { |
| 355 | 355 | } |
| 356 | 356 | } |
| 357 | 357 | |
| 358 | for (wanted_steps.toSliceConst()) |s| { | |
| 358 | for (wanted_steps.span()) |s| { | |
| 359 | 359 | try self.makeOneStep(s); |
| 360 | 360 | } |
| 361 | 361 | } |
| ... | ... | @@ -372,7 +372,7 @@ pub const Builder = struct { |
| 372 | 372 | const uninstall_tls = @fieldParentPtr(TopLevelStep, "step", uninstall_step); |
| 373 | 373 | const self = @fieldParentPtr(Builder, "uninstall_tls", uninstall_tls); |
| 374 | 374 | |
| 375 | for (self.installed_files.toSliceConst()) |installed_file| { | |
| 375 | for (self.installed_files.span()) |installed_file| { | |
| 376 | 376 | const full_path = self.getInstallPath(installed_file.dir, installed_file.path); |
| 377 | 377 | if (self.verbose) { |
| 378 | 378 | warn("rm {}\n", .{full_path}); |
| ... | ... | @@ -390,7 +390,7 @@ pub const Builder = struct { |
| 390 | 390 | } |
| 391 | 391 | s.loop_flag = true; |
| 392 | 392 | |
| 393 | for (s.dependencies.toSlice()) |dep| { | |
| 393 | for (s.dependencies.span()) |dep| { | |
| 394 | 394 | self.makeOneStep(dep) catch |err| { |
| 395 | 395 | if (err == error.DependencyLoopDetected) { |
| 396 | 396 | warn(" {}\n", .{s.name}); |
| ... | ... | @@ -405,7 +405,7 @@ pub const Builder = struct { |
| 405 | 405 | } |
| 406 | 406 | |
| 407 | 407 | 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| { | |
| 409 | 409 | if (mem.eql(u8, top_level_step.step.name, name)) { |
| 410 | 410 | return &top_level_step.step; |
| 411 | 411 | } |
| ... | ... | @@ -470,7 +470,7 @@ pub const Builder = struct { |
| 470 | 470 | return null; |
| 471 | 471 | }, |
| 472 | 472 | UserValue.Scalar => |s| return &[_][]const u8{s}, |
| 473 | UserValue.List => |lst| return lst.toSliceConst(), | |
| 473 | UserValue.List => |lst| return lst.span(), | |
| 474 | 474 | }, |
| 475 | 475 | } |
| 476 | 476 | } |
| ... | ... | @@ -866,7 +866,7 @@ pub const Builder = struct { |
| 866 | 866 | pub fn findProgram(self: *Builder, names: []const []const u8, paths: []const []const u8) ![]const u8 { |
| 867 | 867 | // TODO report error for ambiguous situations |
| 868 | 868 | const exe_extension = @as(CrossTarget, .{}).exeFileExt(); |
| 869 | for (self.search_prefixes.toSliceConst()) |search_prefix| { | |
| 869 | for (self.search_prefixes.span()) |search_prefix| { | |
| 870 | 870 | for (names) |name| { |
| 871 | 871 | if (fs.path.isAbsolute(name)) { |
| 872 | 872 | return name; |
| ... | ... | @@ -1010,7 +1010,7 @@ pub const Builder = struct { |
| 1010 | 1010 | .desc = tok_it.rest(), |
| 1011 | 1011 | }); |
| 1012 | 1012 | } |
| 1013 | return list.toSliceConst(); | |
| 1013 | return list.span(); | |
| 1014 | 1014 | } |
| 1015 | 1015 | |
| 1016 | 1016 | fn getPkgConfigList(self: *Builder) ![]const PkgConfigPkg { |
| ... | ... | @@ -1395,7 +1395,7 @@ pub const LibExeObjStep = struct { |
| 1395 | 1395 | if (isLibCLibrary(name)) { |
| 1396 | 1396 | return self.is_linking_libc; |
| 1397 | 1397 | } |
| 1398 | for (self.link_objects.toSliceConst()) |link_object| { | |
| 1398 | for (self.link_objects.span()) |link_object| { | |
| 1399 | 1399 | switch (link_object) { |
| 1400 | 1400 | LinkObject.SystemLib => |n| if (mem.eql(u8, n, name)) return true, |
| 1401 | 1401 | else => continue, |
| ... | ... | @@ -1599,10 +1599,7 @@ pub const LibExeObjStep = struct { |
| 1599 | 1599 | self.main_pkg_path = dir_path; |
| 1600 | 1600 | } |
| 1601 | 1601 | |
| 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"); | |
| 1606 | 1603 | |
| 1607 | 1604 | pub fn setLibCFile(self: *LibExeObjStep, libc_file: ?[]const u8) void { |
| 1608 | 1605 | self.libc_file = libc_file; |
| ... | ... | @@ -1762,7 +1759,7 @@ pub const LibExeObjStep = struct { |
| 1762 | 1759 | self.include_dirs.append(IncludeDir{ .OtherStep = other }) catch unreachable; |
| 1763 | 1760 | |
| 1764 | 1761 | // Inherit dependency on system libraries |
| 1765 | for (other.link_objects.toSliceConst()) |link_object| { | |
| 1762 | for (other.link_objects.span()) |link_object| { | |
| 1766 | 1763 | switch (link_object) { |
| 1767 | 1764 | .SystemLib => |name| self.linkSystemLibrary(name), |
| 1768 | 1765 | else => continue, |
| ... | ... | @@ -1802,7 +1799,7 @@ pub const LibExeObjStep = struct { |
| 1802 | 1799 | |
| 1803 | 1800 | if (self.root_src) |root_src| try zig_args.append(root_src.getPath(builder)); |
| 1804 | 1801 | |
| 1805 | for (self.link_objects.toSlice()) |link_object| { | |
| 1802 | for (self.link_objects.span()) |link_object| { | |
| 1806 | 1803 | switch (link_object) { |
| 1807 | 1804 | .StaticPath => |static_path| { |
| 1808 | 1805 | try zig_args.append("--object"); |
| ... | ... | @@ -1855,7 +1852,7 @@ pub const LibExeObjStep = struct { |
| 1855 | 1852 | builder.allocator, |
| 1856 | 1853 | &[_][]const u8{ builder.cache_root, builder.fmt("{}_build_options.zig", .{self.name}) }, |
| 1857 | 1854 | ); |
| 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()); | |
| 1859 | 1856 | try zig_args.append("--pkg-begin"); |
| 1860 | 1857 | try zig_args.append("build_options"); |
| 1861 | 1858 | try zig_args.append(builder.pathFromRoot(build_options_file)); |
| ... | ... | @@ -1978,7 +1975,7 @@ pub const LibExeObjStep = struct { |
| 1978 | 1975 | try mcpu_buffer.append(feature.name); |
| 1979 | 1976 | } |
| 1980 | 1977 | } |
| 1981 | try zig_args.append(mcpu_buffer.toSliceConst()); | |
| 1978 | try zig_args.append(mcpu_buffer.span()); | |
| 1982 | 1979 | } |
| 1983 | 1980 | |
| 1984 | 1981 | if (self.target.dynamic_linker.get()) |dynamic_linker| { |
| ... | ... | @@ -2040,7 +2037,7 @@ pub const LibExeObjStep = struct { |
| 2040 | 2037 | try zig_args.append("--test-cmd-bin"); |
| 2041 | 2038 | }, |
| 2042 | 2039 | } |
| 2043 | for (self.packages.toSliceConst()) |pkg| { | |
| 2040 | for (self.packages.span()) |pkg| { | |
| 2044 | 2041 | try zig_args.append("--pkg-begin"); |
| 2045 | 2042 | try zig_args.append(pkg.name); |
| 2046 | 2043 | try zig_args.append(builder.pathFromRoot(pkg.path)); |
| ... | ... | @@ -2057,7 +2054,7 @@ pub const LibExeObjStep = struct { |
| 2057 | 2054 | try zig_args.append("--pkg-end"); |
| 2058 | 2055 | } |
| 2059 | 2056 | |
| 2060 | for (self.include_dirs.toSliceConst()) |include_dir| { | |
| 2057 | for (self.include_dirs.span()) |include_dir| { | |
| 2061 | 2058 | switch (include_dir) { |
| 2062 | 2059 | .RawPath => |include_path| { |
| 2063 | 2060 | try zig_args.append("-I"); |
| ... | ... | @@ -2075,18 +2072,18 @@ pub const LibExeObjStep = struct { |
| 2075 | 2072 | } |
| 2076 | 2073 | } |
| 2077 | 2074 | |
| 2078 | for (self.lib_paths.toSliceConst()) |lib_path| { | |
| 2075 | for (self.lib_paths.span()) |lib_path| { | |
| 2079 | 2076 | try zig_args.append("-L"); |
| 2080 | 2077 | try zig_args.append(lib_path); |
| 2081 | 2078 | } |
| 2082 | 2079 | |
| 2083 | for (self.c_macros.toSliceConst()) |c_macro| { | |
| 2080 | for (self.c_macros.span()) |c_macro| { | |
| 2084 | 2081 | try zig_args.append("-D"); |
| 2085 | 2082 | try zig_args.append(c_macro); |
| 2086 | 2083 | } |
| 2087 | 2084 | |
| 2088 | 2085 | if (self.target.isDarwin()) { |
| 2089 | for (self.framework_dirs.toSliceConst()) |dir| { | |
| 2086 | for (self.framework_dirs.span()) |dir| { | |
| 2090 | 2087 | try zig_args.append("-F"); |
| 2091 | 2088 | try zig_args.append(dir); |
| 2092 | 2089 | } |
| ... | ... | @@ -2146,12 +2143,12 @@ pub const LibExeObjStep = struct { |
| 2146 | 2143 | } |
| 2147 | 2144 | |
| 2148 | 2145 | if (self.kind == Kind.Test) { |
| 2149 | try builder.spawnChild(zig_args.toSliceConst()); | |
| 2146 | try builder.spawnChild(zig_args.span()); | |
| 2150 | 2147 | } else { |
| 2151 | 2148 | try zig_args.append("--cache"); |
| 2152 | 2149 | try zig_args.append("on"); |
| 2153 | 2150 | |
| 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); | |
| 2155 | 2152 | const build_output_dir = mem.trimRight(u8, output_dir_nl, "\r\n"); |
| 2156 | 2153 | |
| 2157 | 2154 | if (self.output_dir) |output_dir| { |
lib/std/build/emit_raw.zig+6-6| ... | ... | @@ -72,7 +72,7 @@ const BinaryElfOutput = struct { |
| 72 | 72 | newSegment.binaryOffset = 0; |
| 73 | 73 | newSegment.firstSection = null; |
| 74 | 74 | |
| 75 | for (self.sections.toSlice()) |section| { | |
| 75 | for (self.sections.span()) |section| { | |
| 76 | 76 | if (sectionWithinSegment(section, phdr)) { |
| 77 | 77 | if (section.segment) |sectionSegment| { |
| 78 | 78 | if (sectionSegment.elfOffset > newSegment.elfOffset) { |
| ... | ... | @@ -92,7 +92,7 @@ const BinaryElfOutput = struct { |
| 92 | 92 | } |
| 93 | 93 | } |
| 94 | 94 | |
| 95 | sort.sort(*BinaryElfSegment, self.segments.toSlice(), segmentSortCompare); | |
| 95 | sort.sort(*BinaryElfSegment, self.segments.span(), segmentSortCompare); | |
| 96 | 96 | |
| 97 | 97 | if (self.segments.len > 0) { |
| 98 | 98 | const firstSegment = self.segments.at(0); |
| ... | ... | @@ -105,19 +105,19 @@ const BinaryElfOutput = struct { |
| 105 | 105 | |
| 106 | 106 | const basePhysicalAddress = firstSegment.physicalAddress; |
| 107 | 107 | |
| 108 | for (self.segments.toSlice()) |segment| { | |
| 108 | for (self.segments.span()) |segment| { | |
| 109 | 109 | segment.binaryOffset = segment.physicalAddress - basePhysicalAddress; |
| 110 | 110 | } |
| 111 | 111 | } |
| 112 | 112 | } |
| 113 | 113 | |
| 114 | for (self.sections.toSlice()) |section| { | |
| 114 | for (self.sections.span()) |section| { | |
| 115 | 115 | if (section.segment) |segment| { |
| 116 | 116 | section.binaryOffset = segment.binaryOffset + (section.elfOffset - segment.elfOffset); |
| 117 | 117 | } |
| 118 | 118 | } |
| 119 | 119 | |
| 120 | sort.sort(*BinaryElfSection, self.sections.toSlice(), sectionSortCompare); | |
| 120 | sort.sort(*BinaryElfSection, self.sections.span(), sectionSortCompare); | |
| 121 | 121 | |
| 122 | 122 | return self; |
| 123 | 123 | } |
| ... | ... | @@ -165,7 +165,7 @@ fn emitRaw(allocator: *Allocator, elf_path: []const u8, raw_path: []const u8) !v |
| 165 | 165 | var binary_elf_output = try BinaryElfOutput.parse(allocator, elf_file); |
| 166 | 166 | defer binary_elf_output.deinit(); |
| 167 | 167 | |
| 168 | for (binary_elf_output.sections.toSlice()) |section| { | |
| 168 | for (binary_elf_output.sections.span()) |section| { | |
| 169 | 169 | try writeBinaryElfSection(elf_file, out_file, section); |
| 170 | 170 | } |
| 171 | 171 | } |
lib/std/build/run.zig+3-3| ... | ... | @@ -139,7 +139,7 @@ pub const RunStep = struct { |
| 139 | 139 | const cwd = if (self.cwd) |cwd| self.builder.pathFromRoot(cwd) else self.builder.build_root; |
| 140 | 140 | |
| 141 | 141 | var argv_list = ArrayList([]const u8).init(self.builder.allocator); |
| 142 | for (self.argv.toSlice()) |arg| { | |
| 142 | for (self.argv.span()) |arg| { | |
| 143 | 143 | switch (arg) { |
| 144 | 144 | Arg.Bytes => |bytes| try argv_list.append(bytes), |
| 145 | 145 | Arg.Artifact => |artifact| { |
| ... | ... | @@ -153,7 +153,7 @@ pub const RunStep = struct { |
| 153 | 153 | } |
| 154 | 154 | } |
| 155 | 155 | |
| 156 | const argv = argv_list.toSliceConst(); | |
| 156 | const argv = argv_list.span(); | |
| 157 | 157 | |
| 158 | 158 | const child = std.ChildProcess.init(argv, self.builder.allocator) catch unreachable; |
| 159 | 159 | defer child.deinit(); |
| ... | ... | @@ -289,7 +289,7 @@ pub const RunStep = struct { |
| 289 | 289 | } |
| 290 | 290 | |
| 291 | 291 | fn addPathForDynLibs(self: *RunStep, artifact: *LibExeObjStep) void { |
| 292 | for (artifact.link_objects.toSliceConst()) |link_object| { | |
| 292 | for (artifact.link_objects.span()) |link_object| { | |
| 293 | 293 | switch (link_object) { |
| 294 | 294 | .OtherStep => |other| { |
| 295 | 295 | if (other.target.isWindows() and other.isDynamicLibrary()) { |
lib/std/build/translate_c.zig+1-1| ... | ... | @@ -71,7 +71,7 @@ pub const TranslateCStep = struct { |
| 71 | 71 | |
| 72 | 72 | try argv_list.append(self.source.getPath(self.builder)); |
| 73 | 73 | |
| 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); | |
| 75 | 75 | const output_path = mem.trimRight(u8, output_path_nl, "\r\n"); |
| 76 | 76 | |
| 77 | 77 | self.out_basename = fs.path.basename(output_path); |
lib/std/build/write_file.zig+2-2| ... | ... | @@ -59,7 +59,7 @@ pub const WriteFileStep = struct { |
| 59 | 59 | // new random bytes when WriteFileStep implementation is modified |
| 60 | 60 | // in a non-backwards-compatible way. |
| 61 | 61 | hash.update("eagVR1dYXoE7ARDP"); |
| 62 | for (self.files.toSliceConst()) |file| { | |
| 62 | for (self.files.span()) |file| { | |
| 63 | 63 | hash.update(file.basename); |
| 64 | 64 | hash.update(file.bytes); |
| 65 | 65 | hash.update("|"); |
| ... | ... | @@ -80,7 +80,7 @@ pub const WriteFileStep = struct { |
| 80 | 80 | }; |
| 81 | 81 | var dir = try fs.cwd().openDir(self.output_dir, .{}); |
| 82 | 82 | defer dir.close(); |
| 83 | for (self.files.toSliceConst()) |file| { | |
| 83 | for (self.files.span()) |file| { | |
| 84 | 84 | dir.writeFile(file.basename, file.bytes) catch |err| { |
| 85 | 85 | warn("unable to write {} into {}: {}\n", .{ |
| 86 | 86 | file.basename, |
lib/std/c.zig-1| ... | ... | @@ -174,7 +174,6 @@ pub extern "c" fn realloc(?*c_void, usize) ?*c_void; |
| 174 | 174 | pub extern "c" fn free(*c_void) void; |
| 175 | 175 | pub extern "c" fn posix_memalign(memptr: **c_void, alignment: usize, size: usize) c_int; |
| 176 | 176 | |
| 177 | // Deprecated | |
| 178 | 177 | pub extern "c" fn futimes(fd: fd_t, times: *[2]timeval) c_int; |
| 179 | 178 | pub extern "c" fn utimes(path: [*:0]const u8, times: *[2]timeval) c_int; |
| 180 | 179 |
lib/std/child_process.zig+3-21| ... | ... | @@ -175,29 +175,11 @@ pub const ChildProcess = struct { |
| 175 | 175 | stderr: []u8, |
| 176 | 176 | }; |
| 177 | 177 | |
| 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"); | |
| 196 | 179 | |
| 197 | 180 | /// Spawns a child process, waits for it, collecting stdout and stderr, and then returns. |
| 198 | 181 | /// 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 { | |
| 201 | 183 | allocator: *mem.Allocator, |
| 202 | 184 | argv: []const []const u8, |
| 203 | 185 | cwd: ?[]const u8 = null, |
| ... | ... | @@ -370,7 +352,7 @@ pub const ChildProcess = struct { |
| 370 | 352 | |
| 371 | 353 | const any_ignore = (self.stdin_behavior == StdIo.Ignore or self.stdout_behavior == StdIo.Ignore or self.stderr_behavior == StdIo.Ignore); |
| 372 | 354 | 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) { | |
| 374 | 356 | error.PathAlreadyExists => unreachable, |
| 375 | 357 | error.NoSpaceLeft => unreachable, |
| 376 | 358 | error.FileTooBig => unreachable, |
lib/std/coff.zig+2-2| ... | ... | @@ -145,7 +145,7 @@ pub const Coff = struct { |
| 145 | 145 | blk: while (i < debug_dir_entry_count) : (i += 1) { |
| 146 | 146 | const debug_dir_entry = try in.readStruct(DebugDirectoryEntry); |
| 147 | 147 | if (debug_dir_entry.type == IMAGE_DEBUG_TYPE_CODEVIEW) { |
| 148 | for (self.sections.toSlice()) |*section| { | |
| 148 | for (self.sections.span()) |*section| { | |
| 149 | 149 | const section_start = section.header.virtual_address; |
| 150 | 150 | const section_size = section.header.misc.virtual_size; |
| 151 | 151 | const rva = debug_dir_entry.address_of_raw_data; |
| ... | ... | @@ -211,7 +211,7 @@ pub const Coff = struct { |
| 211 | 211 | } |
| 212 | 212 | |
| 213 | 213 | pub fn getSection(self: *Coff, comptime name: []const u8) ?*Section { |
| 214 | for (self.sections.toSlice()) |*sec| { | |
| 214 | for (self.sections.span()) |*sec| { | |
| 215 | 215 | if (mem.eql(u8, sec.header.name[0..name.len], name)) { |
| 216 | 216 | return sec; |
| 217 | 217 | } |
lib/std/crypto/gimli.zig+2| ... | ... | @@ -23,10 +23,12 @@ pub const State = struct { |
| 23 | 23 | |
| 24 | 24 | const Self = @This(); |
| 25 | 25 | |
| 26 | /// TODO follow the span() convention instead of having this and `toSliceConst` | |
| 26 | 27 | pub fn toSlice(self: *Self) []u8 { |
| 27 | 28 | return mem.sliceAsBytes(self.data[0..]); |
| 28 | 29 | } |
| 29 | 30 | |
| 31 | /// TODO follow the span() convention instead of having this and `toSlice` | |
| 30 | 32 | pub fn toSliceConst(self: *Self) []const u8 { |
| 31 | 33 | return mem.sliceAsBytes(self.data[0..]); |
| 32 | 34 | } |
lib/std/debug.zig+6-9| ... | ... | @@ -735,7 +735,7 @@ fn openCoffDebugInfo(allocator: *mem.Allocator, coff_file_path: [:0]const u16) ! |
| 735 | 735 | for (present) |_| { |
| 736 | 736 | const name_offset = try pdb_stream.inStream().readIntLittle(u32); |
| 737 | 737 | 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)); | |
| 739 | 739 | if (mem.eql(u8, name, "/names")) { |
| 740 | 740 | break :str_tab_index name_index; |
| 741 | 741 | } |
| ... | ... | @@ -1131,7 +1131,7 @@ pub const DebugInfo = struct { |
| 1131 | 1131 | const obj_di = try self.allocator.create(ModuleDebugInfo); |
| 1132 | 1132 | errdefer self.allocator.destroy(obj_di); |
| 1133 | 1133 | |
| 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)); | |
| 1135 | 1135 | obj_di.* = openMachODebugInfo(self.allocator, macho_path) catch |err| switch (err) { |
| 1136 | 1136 | error.FileNotFound => return error.MissingDebugInfo, |
| 1137 | 1137 | else => return err, |
| ... | ... | @@ -1254,10 +1254,7 @@ pub const DebugInfo = struct { |
| 1254 | 1254 | if (context.address >= seg_start and context.address < seg_end) { |
| 1255 | 1255 | // Android libc uses NULL instead of an empty string to mark the |
| 1256 | 1256 | // 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 ""; | |
| 1261 | 1258 | context.base_address = info.dlpi_addr; |
| 1262 | 1259 | // Stop the iteration |
| 1263 | 1260 | return error.Found; |
| ... | ... | @@ -1426,7 +1423,7 @@ pub const ModuleDebugInfo = switch (builtin.os.tag) { |
| 1426 | 1423 | return SymbolInfo{}; |
| 1427 | 1424 | |
| 1428 | 1425 | 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); | |
| 1430 | 1427 | |
| 1431 | 1428 | // Check if its debug infos are already in the cache |
| 1432 | 1429 | var o_file_di = self.ofiles.getValue(o_file_path) orelse |
| ... | ... | @@ -1483,7 +1480,7 @@ pub const ModuleDebugInfo = switch (builtin.os.tag) { |
| 1483 | 1480 | const mod_index = for (self.sect_contribs) |sect_contrib| { |
| 1484 | 1481 | if (sect_contrib.Section > self.coff.sections.len) continue; |
| 1485 | 1482 | // 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]; | |
| 1487 | 1484 | |
| 1488 | 1485 | const vaddr_start = coff_section.header.virtual_address + sect_contrib.Offset; |
| 1489 | 1486 | const vaddr_end = vaddr_start + sect_contrib.Size; |
| ... | ... | @@ -1510,7 +1507,7 @@ pub const ModuleDebugInfo = switch (builtin.os.tag) { |
| 1510 | 1507 | const vaddr_start = coff_section.header.virtual_address + proc_sym.CodeOffset; |
| 1511 | 1508 | const vaddr_end = vaddr_start + proc_sym.CodeSize; |
| 1512 | 1509 | 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)); | |
| 1514 | 1511 | } |
| 1515 | 1512 | }, |
| 1516 | 1513 | else => {}, |
lib/std/dwarf.zig+7-7| ... | ... | @@ -82,7 +82,7 @@ const Die = struct { |
| 82 | 82 | }; |
| 83 | 83 | |
| 84 | 84 | fn getAttr(self: *const Die, id: u64) ?*const FormValue { |
| 85 | for (self.attrs.toSliceConst()) |*attr| { | |
| 85 | for (self.attrs.span()) |*attr| { | |
| 86 | 86 | if (attr.id == id) return &attr.value; |
| 87 | 87 | } |
| 88 | 88 | return null; |
| ... | ... | @@ -375,7 +375,7 @@ fn parseFormValue(allocator: *mem.Allocator, in_stream: var, form_id: u64, is_64 |
| 375 | 375 | } |
| 376 | 376 | |
| 377 | 377 | fn getAbbrevTableEntry(abbrev_table: *const AbbrevTable, abbrev_code: u64) ?*const AbbrevTableEntry { |
| 378 | for (abbrev_table.toSliceConst()) |*table_entry| { | |
| 378 | for (abbrev_table.span()) |*table_entry| { | |
| 379 | 379 | if (table_entry.abbrev_code == abbrev_code) return table_entry; |
| 380 | 380 | } |
| 381 | 381 | return null; |
| ... | ... | @@ -399,7 +399,7 @@ pub const DwarfInfo = struct { |
| 399 | 399 | } |
| 400 | 400 | |
| 401 | 401 | fn getSymbolName(di: *DwarfInfo, address: u64) ?[]const u8 { |
| 402 | for (di.func_list.toSliceConst()) |*func| { | |
| 402 | for (di.func_list.span()) |*func| { | |
| 403 | 403 | if (func.pc_range) |range| { |
| 404 | 404 | if (address >= range.start and address < range.end) { |
| 405 | 405 | return func.name; |
| ... | ... | @@ -588,7 +588,7 @@ pub const DwarfInfo = struct { |
| 588 | 588 | } |
| 589 | 589 | |
| 590 | 590 | 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| { | |
| 592 | 592 | if (compile_unit.pc_range) |range| { |
| 593 | 593 | if (target_address >= range.start and target_address < range.end) return compile_unit; |
| 594 | 594 | } |
| ... | ... | @@ -636,7 +636,7 @@ pub const DwarfInfo = struct { |
| 636 | 636 | /// Gets an already existing AbbrevTable given the abbrev_offset, or if not found, |
| 637 | 637 | /// seeks in the stream and parses it. |
| 638 | 638 | 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| { | |
| 640 | 640 | if (header.offset == abbrev_offset) { |
| 641 | 641 | return &header.table; |
| 642 | 642 | } |
| ... | ... | @@ -690,7 +690,7 @@ pub const DwarfInfo = struct { |
| 690 | 690 | .attrs = ArrayList(Die.Attr).init(di.allocator()), |
| 691 | 691 | }; |
| 692 | 692 | try result.attrs.resize(table_entry.attrs.len); |
| 693 | for (table_entry.attrs.toSliceConst()) |attr, i| { | |
| 693 | for (table_entry.attrs.span()) |attr, i| { | |
| 694 | 694 | result.attrs.items[i] = Die.Attr{ |
| 695 | 695 | .id = attr.attr_id, |
| 696 | 696 | .value = try parseFormValue(di.allocator(), in_stream, attr.form_id, is_64), |
| ... | ... | @@ -757,7 +757,7 @@ pub const DwarfInfo = struct { |
| 757 | 757 | } |
| 758 | 758 | |
| 759 | 759 | 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); | |
| 761 | 761 | |
| 762 | 762 | while (true) { |
| 763 | 763 | 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 { |
| 254 | 254 | }; |
| 255 | 255 | } |
| 256 | 256 | |
| 257 | pub const openC = @compileError("deprecated: renamed to openZ"); | |
| 258 | ||
| 257 | 259 | /// 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)); | |
| 260 | 262 | } |
| 261 | 263 | |
| 262 | 264 | /// Trusts the file |
| ... | ... | @@ -285,7 +287,7 @@ pub const ElfDynLib = struct { |
| 285 | 287 | if (0 == (@as(u32, 1) << @intCast(u5, self.syms[i].st_info & 0xf) & OK_TYPES)) continue; |
| 286 | 288 | if (0 == (@as(u32, 1) << @intCast(u5, self.syms[i].st_info >> 4) & OK_BINDS)) continue; |
| 287 | 289 | 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; | |
| 289 | 291 | if (maybe_versym) |versym| { |
| 290 | 292 | if (!checkver(self.verdef.?, versym[i], vername, self.strings)) |
| 291 | 293 | continue; |
| ... | ... | @@ -316,7 +318,7 @@ fn checkver(def_arg: *elf.Verdef, vsym_arg: i32, vername: []const u8, strings: [ |
| 316 | 318 | def = @intToPtr(*elf.Verdef, @ptrToInt(def) + def.vd_next); |
| 317 | 319 | } |
| 318 | 320 | 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)); | |
| 320 | 322 | } |
| 321 | 323 | |
| 322 | 324 | pub const WindowsDynLib = struct { |
| ... | ... | @@ -329,7 +331,9 @@ pub const WindowsDynLib = struct { |
| 329 | 331 | return openW(&path_w); |
| 330 | 332 | } |
| 331 | 333 | |
| 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 { | |
| 333 | 337 | const path_w = try windows.cStrToPrefixedFileW(path_c); |
| 334 | 338 | return openW(&path_w); |
| 335 | 339 | } |
| ... | ... | @@ -362,10 +366,12 @@ pub const DlDynlib = struct { |
| 362 | 366 | |
| 363 | 367 | pub fn open(path: []const u8) !DlDynlib { |
| 364 | 368 | const path_c = try os.toPosixPath(path); |
| 365 | return openC(&path_c); | |
| 369 | return openZ(&path_c); | |
| 366 | 370 | } |
| 367 | 371 | |
| 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 { | |
| 369 | 375 | return DlDynlib{ |
| 370 | 376 | .handle = system.dlopen(path_c, system.RTLD_LAZY) orelse { |
| 371 | 377 | return error.FileNotFound; |
lib/std/event/loop.zig+2-2| ... | ... | @@ -1096,10 +1096,10 @@ pub const Loop = struct { |
| 1096 | 1096 | msg.result = noasync os.preadv(msg.fd, msg.iov, msg.offset); |
| 1097 | 1097 | }, |
| 1098 | 1098 | .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); | |
| 1100 | 1100 | }, |
| 1101 | 1101 | .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); | |
| 1103 | 1103 | }, |
| 1104 | 1104 | .faccessat => |*msg| { |
| 1105 | 1105 | 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; |
| 11 | 11 | pub const path = @import("fs/path.zig"); |
| 12 | 12 | pub const File = @import("fs/file.zig").File; |
| 13 | 13 | |
| 14 | // TODO audit these APIs with respect to Dir and absolute paths | |
| 15 | ||
| 14 | 16 | pub const symLink = os.symlink; |
| 15 | pub const symLinkC = os.symlinkC; | |
| 17 | pub const symLinkZ = os.symlinkZ; | |
| 18 | pub const symLinkC = @compileError("deprecated: renamed to symlinkZ"); | |
| 16 | 19 | pub const rename = os.rename; |
| 17 | pub const renameC = os.renameC; | |
| 20 | pub const renameZ = os.renameZ; | |
| 21 | pub const renameC = @compileError("deprecated: renamed to renameZ"); | |
| 18 | 22 | pub const renameW = os.renameW; |
| 19 | 23 | pub const realpath = os.realpath; |
| 20 | pub const realpathC = os.realpathC; | |
| 24 | pub const realpathZ = os.realpathZ; | |
| 25 | pub const realpathC = @compileError("deprecated: renamed to realpathZ"); | |
| 21 | 26 | pub const realpathW = os.realpathW; |
| 22 | 27 | |
| 23 | 28 | pub const getAppDataDir = @import("fs/get_app_data_dir.zig").getAppDataDir; |
| ... | ... | @@ -120,7 +125,7 @@ pub const AtomicFile = struct { |
| 120 | 125 | file: File, |
| 121 | 126 | // TODO either replace this with rand_buf or use []u16 on Windows |
| 122 | 127 | tmp_path_buf: [TMP_PATH_LEN:0]u8, |
| 123 | dest_path: []const u8, | |
| 128 | dest_basename: []const u8, | |
| 124 | 129 | file_open: bool, |
| 125 | 130 | file_exists: bool, |
| 126 | 131 | close_dir_on_deinit: bool, |
| ... | ... | @@ -131,17 +136,23 @@ pub const AtomicFile = struct { |
| 131 | 136 | const RANDOM_BYTES = 12; |
| 132 | 137 | const TMP_PATH_LEN = base64.Base64Encoder.calcSize(RANDOM_BYTES); |
| 133 | 138 | |
| 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 { | |
| 136 | 146 | var rand_buf: [RANDOM_BYTES]u8 = undefined; |
| 137 | 147 | var tmp_path_buf: [TMP_PATH_LEN:0]u8 = undefined; |
| 148 | // TODO: should be able to use TMP_PATH_LEN here. | |
| 138 | 149 | tmp_path_buf[base64.Base64Encoder.calcSize(RANDOM_BYTES)] = 0; |
| 139 | 150 | |
| 140 | 151 | while (true) { |
| 141 | 152 | try crypto.randomBytes(rand_buf[0..]); |
| 142 | 153 | base64_encoder.encode(&tmp_path_buf, &rand_buf); |
| 143 | 154 | |
| 144 | const file = dir.createFileC( | |
| 155 | const file = dir.createFileZ( | |
| 145 | 156 | &tmp_path_buf, |
| 146 | 157 | .{ .mode = mode, .exclusive = true }, |
| 147 | 158 | ) catch |err| switch (err) { |
| ... | ... | @@ -152,7 +163,7 @@ pub const AtomicFile = struct { |
| 152 | 163 | return AtomicFile{ |
| 153 | 164 | .file = file, |
| 154 | 165 | .tmp_path_buf = tmp_path_buf, |
| 155 | .dest_path = dest_path, | |
| 166 | .dest_basename = dest_basename, | |
| 156 | 167 | .file_open = true, |
| 157 | 168 | .file_exists = true, |
| 158 | 169 | .close_dir_on_deinit = close_dir_on_deinit, |
| ... | ... | @@ -161,11 +172,6 @@ pub const AtomicFile = struct { |
| 161 | 172 | } |
| 162 | 173 | } |
| 163 | 174 | |
| 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 | ||
| 169 | 175 | /// always call deinit, even after successful finish() |
| 170 | 176 | pub fn deinit(self: *AtomicFile) void { |
| 171 | 177 | if (self.file_open) { |
| ... | ... | @@ -173,7 +179,7 @@ pub const AtomicFile = struct { |
| 173 | 179 | self.file_open = false; |
| 174 | 180 | } |
| 175 | 181 | if (self.file_exists) { |
| 176 | self.dir.deleteFileC(&self.tmp_path_buf) catch {}; | |
| 182 | self.dir.deleteFileZ(&self.tmp_path_buf) catch {}; | |
| 177 | 183 | self.file_exists = false; |
| 178 | 184 | } |
| 179 | 185 | if (self.close_dir_on_deinit) { |
| ... | ... | @@ -189,12 +195,12 @@ pub const AtomicFile = struct { |
| 189 | 195 | self.file_open = false; |
| 190 | 196 | } |
| 191 | 197 | 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); | |
| 193 | 199 | const tmp_path_w = try os.windows.cStrToPrefixedFileW(&self.tmp_path_buf); |
| 194 | 200 | try os.renameatW(self.dir.fd, &tmp_path_w, self.dir.fd, &dest_path_w, os.windows.TRUE); |
| 195 | 201 | self.file_exists = false; |
| 196 | 202 | } else { |
| 197 | const dest_path_c = try os.toPosixPath(self.dest_path); | |
| 203 | const dest_path_c = try os.toPosixPath(self.dest_basename); | |
| 198 | 204 | try os.renameatZ(self.dir.fd, &self.tmp_path_buf, self.dir.fd, &dest_path_c); |
| 199 | 205 | self.file_exists = false; |
| 200 | 206 | } |
| ... | ... | @@ -213,7 +219,7 @@ pub fn makeDirAbsolute(absolute_path: []const u8) !void { |
| 213 | 219 | |
| 214 | 220 | /// Same as `makeDirAbsolute` except the parameter is a null-terminated UTF8-encoded string. |
| 215 | 221 | pub fn makeDirAbsoluteZ(absolute_path_z: [*:0]const u8) !void { |
| 216 | assert(path.isAbsoluteC(absolute_path_z)); | |
| 222 | assert(path.isAbsoluteZ(absolute_path_z)); | |
| 217 | 223 | return os.mkdirZ(absolute_path_z, default_new_dir_mode); |
| 218 | 224 | } |
| 219 | 225 | |
| ... | ... | @@ -224,18 +230,25 @@ pub fn makeDirAbsoluteW(absolute_path_w: [*:0]const u16) !void { |
| 224 | 230 | os.windows.CloseHandle(handle); |
| 225 | 231 | } |
| 226 | 232 | |
| 227 | /// Deprecated; use `Dir.deleteDir`. | |
| 228 | pub fn deleteDir(dir_path: []const u8) !void { | |
| 233 | pub const deleteDir = @compileError("deprecated; use dir.deleteDir or deleteDirAbsolute"); | |
| 234 | pub const deleteDirC = @compileError("deprecated; use dir.deleteDirZ or deleteDirAbsoluteZ"); | |
| 235 | pub const deleteDirW = @compileError("deprecated; use dir.deleteDirW or deleteDirAbsoluteW"); | |
| 236 | ||
| 237 | /// Same as `Dir.deleteDir` except the path is absolute. | |
| 238 | pub fn deleteDirAbsolute(dir_path: []const u8) !void { | |
| 239 | assert(path.isAbsolute(dir_path)); | |
| 229 | 240 | return os.rmdir(dir_path); |
| 230 | 241 | } |
| 231 | 242 | |
| 232 | /// Deprecated; use `Dir.deleteDirC`. | |
| 233 | pub 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. | |
| 244 | pub fn deleteDirAbsoluteZ(dir_path: [*:0]const u8) !void { | |
| 245 | assert(path.isAbsoluteZ(dir_path)); | |
| 246 | return os.rmdirZ(dir_path); | |
| 235 | 247 | } |
| 236 | 248 | |
| 237 | /// Deprecated; use `Dir.deleteDirW`. | |
| 238 | pub 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. | |
| 250 | pub fn deleteDirAbsoluteW(dir_path: [*:0]const u16) !void { | |
| 251 | assert(path.isAbsoluteWindowsW(dir_path)); | |
| 239 | 252 | return os.rmdirW(dir_path); |
| 240 | 253 | } |
| 241 | 254 | |
| ... | ... | @@ -412,7 +425,7 @@ pub const Dir = struct { |
| 412 | 425 | const next_index = self.index + linux_entry.reclen(); |
| 413 | 426 | self.index = next_index; |
| 414 | 427 | |
| 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)); | |
| 416 | 429 | |
| 417 | 430 | // skip . and .. entries |
| 418 | 431 | if (mem.eql(u8, name, ".") or mem.eql(u8, name, "..")) { |
| ... | ... | @@ -573,8 +586,7 @@ pub const Dir = struct { |
| 573 | 586 | return self.openFileZ(&path_c, flags); |
| 574 | 587 | } |
| 575 | 588 | |
| 576 | /// Deprecated; use `openFileZ`. | |
| 577 | pub const openFileC = openFileZ; | |
| 589 | pub const openFileC = @compileError("deprecated: renamed to openFileZ"); | |
| 578 | 590 | |
| 579 | 591 | /// Same as `openFile` but the path parameter is null-terminated. |
| 580 | 592 | pub fn openFileZ(self: Dir, sub_path: [*:0]const u8, flags: File.OpenFlags) File.OpenError!File { |
| ... | ... | @@ -592,7 +604,7 @@ pub const Dir = struct { |
| 592 | 604 | const fd = if (need_async_thread and !flags.always_blocking) |
| 593 | 605 | try std.event.Loop.instance.?.openatZ(self.fd, sub_path, os_flags, 0) |
| 594 | 606 | else |
| 595 | try os.openatC(self.fd, sub_path, os_flags, 0); | |
| 607 | try os.openatZ(self.fd, sub_path, os_flags, 0); | |
| 596 | 608 | return File{ |
| 597 | 609 | .handle = fd, |
| 598 | 610 | .io_mode = .blocking, |
| ... | ... | @@ -625,11 +637,13 @@ pub const Dir = struct { |
| 625 | 637 | return self.createFileW(&path_w, flags); |
| 626 | 638 | } |
| 627 | 639 | const path_c = try os.toPosixPath(sub_path); |
| 628 | return self.createFileC(&path_c, flags); | |
| 640 | return self.createFileZ(&path_c, flags); | |
| 629 | 641 | } |
| 630 | 642 | |
| 643 | pub const createFileC = @compileError("deprecated: renamed to createFileZ"); | |
| 644 | ||
| 631 | 645 | /// 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 { | |
| 633 | 647 | if (builtin.os.tag == .windows) { |
| 634 | 648 | const path_w = try os.windows.cStrToPrefixedFileW(sub_path_c); |
| 635 | 649 | return self.createFileW(&path_w, flags); |
| ... | ... | @@ -642,7 +656,7 @@ pub const Dir = struct { |
| 642 | 656 | const fd = if (need_async_thread) |
| 643 | 657 | try std.event.Loop.instance.?.openatZ(self.fd, sub_path_c, os_flags, flags.mode) |
| 644 | 658 | 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); | |
| 646 | 660 | return File{ .handle = fd, .io_mode = .blocking }; |
| 647 | 661 | } |
| 648 | 662 | |
| ... | ... | @@ -664,27 +678,16 @@ pub const Dir = struct { |
| 664 | 678 | }); |
| 665 | 679 | } |
| 666 | 680 | |
| 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"); | |
| 681 | 684 | |
| 682 | 685 | pub fn makeDir(self: Dir, sub_path: []const u8) !void { |
| 683 | 686 | try os.mkdirat(self.fd, sub_path, default_new_dir_mode); |
| 684 | 687 | } |
| 685 | 688 | |
| 686 | 689 | 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); | |
| 688 | 691 | } |
| 689 | 692 | |
| 690 | 693 | pub fn makeDirW(self: Dir, sub_path: [*:0]const u16) !void { |
| ... | ... | @@ -758,20 +761,22 @@ pub const Dir = struct { |
| 758 | 761 | return self.openDirW(&sub_path_w, args); |
| 759 | 762 | } else { |
| 760 | 763 | 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); | |
| 762 | 765 | } |
| 763 | 766 | } |
| 764 | 767 | |
| 768 | pub const openDirC = @compileError("deprecated: renamed to openDirZ"); | |
| 769 | ||
| 765 | 770 | /// 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 { | |
| 767 | 772 | if (builtin.os.tag == .windows) { |
| 768 | 773 | const sub_path_w = try os.windows.cStrToPrefixedFileW(sub_path_c); |
| 769 | 774 | return self.openDirW(&sub_path_w, args); |
| 770 | 775 | } else if (!args.iterate) { |
| 771 | 776 | 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); | |
| 773 | 778 | } 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); | |
| 775 | 780 | } |
| 776 | 781 | } |
| 777 | 782 | |
| ... | ... | @@ -787,11 +792,11 @@ pub const Dir = struct { |
| 787 | 792 | } |
| 788 | 793 | |
| 789 | 794 | /// `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 { | |
| 791 | 796 | const result = if (need_async_thread) |
| 792 | 797 | std.event.Loop.instance.?.openatZ(self.fd, sub_path_c, flags, 0) |
| 793 | 798 | else |
| 794 | os.openatC(self.fd, sub_path_c, flags, 0); | |
| 799 | os.openatZ(self.fd, sub_path_c, flags, 0); | |
| 795 | 800 | const fd = result catch |err| switch (err) { |
| 796 | 801 | error.FileTooBig => unreachable, // can't happen for directories |
| 797 | 802 | error.IsDir => unreachable, // we're providing O_DIRECTORY |
| ... | ... | @@ -809,7 +814,7 @@ pub const Dir = struct { |
| 809 | 814 | .fd = undefined, |
| 810 | 815 | }; |
| 811 | 816 | |
| 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); | |
| 813 | 818 | var nt_name = w.UNICODE_STRING{ |
| 814 | 819 | .Length = path_len_bytes, |
| 815 | 820 | .MaximumLength = path_len_bytes, |
| ... | ... | @@ -867,9 +872,11 @@ pub const Dir = struct { |
| 867 | 872 | }; |
| 868 | 873 | } |
| 869 | 874 | |
| 875 | pub const deleteFileC = @compileError("deprecated: renamed to deleteFileZ"); | |
| 876 | ||
| 870 | 877 | /// 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) { | |
| 873 | 880 | error.DirNotEmpty => unreachable, // not passing AT_REMOVEDIR |
| 874 | 881 | else => |e| return e, |
| 875 | 882 | }; |
| ... | ... | @@ -908,12 +915,12 @@ pub const Dir = struct { |
| 908 | 915 | return self.deleteDirW(&sub_path_w); |
| 909 | 916 | } |
| 910 | 917 | const sub_path_c = try os.toPosixPath(sub_path); |
| 911 | return self.deleteDirC(&sub_path_c); | |
| 918 | return self.deleteDirZ(&sub_path_c); | |
| 912 | 919 | } |
| 913 | 920 | |
| 914 | 921 | /// 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) { | |
| 917 | 924 | error.IsDir => unreachable, // not possible since we pass AT_REMOVEDIR |
| 918 | 925 | else => |e| return e, |
| 919 | 926 | }; |
| ... | ... | @@ -933,12 +940,14 @@ pub const Dir = struct { |
| 933 | 940 | /// Asserts that the path parameter has no null bytes. |
| 934 | 941 | pub fn readLink(self: Dir, sub_path: []const u8, buffer: *[MAX_PATH_BYTES]u8) ![]u8 { |
| 935 | 942 | 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); | |
| 937 | 944 | } |
| 938 | 945 | |
| 946 | pub const readLinkC = @compileError("deprecated: renamed to readLinkZ"); | |
| 947 | ||
| 939 | 948 | /// 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); | |
| 942 | 951 | } |
| 943 | 952 | |
| 944 | 953 | /// On success, caller owns returned buffer. |
| ... | ... | @@ -956,7 +965,7 @@ pub const Dir = struct { |
| 956 | 965 | max_bytes: usize, |
| 957 | 966 | comptime A: u29, |
| 958 | 967 | ) ![]align(A) u8 { |
| 959 | var file = try self.openRead(file_path); | |
| 968 | var file = try self.openFile(file_path, .{}); | |
| 960 | 969 | defer file.close(); |
| 961 | 970 | |
| 962 | 971 | const size = math.cast(usize, try file.getEndPos()) catch math.maxInt(usize); |
| ... | ... | @@ -1280,9 +1289,9 @@ pub const Dir = struct { |
| 1280 | 1289 | pub fn atomicFile(self: Dir, dest_path: []const u8, options: AtomicFileOptions) !AtomicFile { |
| 1281 | 1290 | if (path.dirname(dest_path)) |dirname| { |
| 1282 | 1291 | 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); | |
| 1284 | 1293 | } else { |
| 1285 | return AtomicFile.init2(dest_path, options.mode, self, false); | |
| 1294 | return AtomicFile.init(dest_path, options.mode, self, false); | |
| 1286 | 1295 | } |
| 1287 | 1296 | } |
| 1288 | 1297 | }; |
| ... | ... | @@ -1309,9 +1318,11 @@ pub fn openFileAbsolute(absolute_path: []const u8, flags: File.OpenFlags) File.O |
| 1309 | 1318 | return cwd().openFile(absolute_path, flags); |
| 1310 | 1319 | } |
| 1311 | 1320 | |
| 1321 | pub const openFileAbsoluteC = @compileError("deprecated: renamed to openFileAbsoluteZ"); | |
| 1322 | ||
| 1312 | 1323 | /// Same as `openFileAbsolute` but the path parameter is null-terminated. |
| 1313 | pub fn openFileAbsoluteC(absolute_path_c: [*:0]const u8, flags: File.OpenFlags) File.OpenError!File { | |
| 1314 | assert(path.isAbsoluteC(absolute_path_c)); | |
| 1324 | pub fn openFileAbsoluteZ(absolute_path_c: [*:0]const u8, flags: File.OpenFlags) File.OpenError!File { | |
| 1325 | assert(path.isAbsoluteZ(absolute_path_c)); | |
| 1315 | 1326 | return cwd().openFileZ(absolute_path_c, flags); |
| 1316 | 1327 | } |
| 1317 | 1328 | |
| ... | ... | @@ -1332,10 +1343,12 @@ pub fn createFileAbsolute(absolute_path: []const u8, flags: File.CreateFlags) Fi |
| 1332 | 1343 | return cwd().createFile(absolute_path, flags); |
| 1333 | 1344 | } |
| 1334 | 1345 | |
| 1346 | pub const createFileAbsoluteC = @compileError("deprecated: renamed to createFileAbsoluteZ"); | |
| 1347 | ||
| 1335 | 1348 | /// Same as `createFileAbsolute` but the path parameter is null-terminated. |
| 1336 | pub 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); | |
| 1349 | pub 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); | |
| 1339 | 1352 | } |
| 1340 | 1353 | |
| 1341 | 1354 | /// Same as `createFileAbsolute` but the path parameter is WTF-16 encoded. |
| ... | ... | @@ -1353,10 +1366,12 @@ pub fn deleteFileAbsolute(absolute_path: []const u8) DeleteFileError!void { |
| 1353 | 1366 | return cwd().deleteFile(absolute_path); |
| 1354 | 1367 | } |
| 1355 | 1368 | |
| 1369 | pub const deleteFileAbsoluteC = @compileError("deprecated: renamed to deleteFileAbsoluteZ"); | |
| 1370 | ||
| 1356 | 1371 | /// Same as `deleteFileAbsolute` except the parameter is null-terminated. |
| 1357 | pub fn deleteFileAbsoluteC(absolute_path_c: [*:0]const u8) DeleteFileError!void { | |
| 1358 | assert(path.isAbsoluteC(absolute_path_c)); | |
| 1359 | return cwd().deleteFileC(absolute_path_c); | |
| 1372 | pub fn deleteFileAbsoluteZ(absolute_path_c: [*:0]const u8) DeleteFileError!void { | |
| 1373 | assert(path.isAbsoluteZ(absolute_path_c)); | |
| 1374 | return cwd().deleteFileZ(absolute_path_c); | |
| 1360 | 1375 | } |
| 1361 | 1376 | |
| 1362 | 1377 | /// Same as `deleteFileAbsolute` except the parameter is WTF-16 encoded. |
| ... | ... | @@ -1384,6 +1399,21 @@ pub fn deleteTreeAbsolute(absolute_path: []const u8) !void { |
| 1384 | 1399 | return dir.deleteTree(path.basename(absolute_path)); |
| 1385 | 1400 | } |
| 1386 | 1401 | |
| 1402 | /// Same as `Dir.readLink`, except it asserts the path is absolute. | |
| 1403 | pub 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. | |
| 1409 | pub 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 | ||
| 1414 | pub const readLink = @compileError("deprecated; use Dir.readLink or readLinkAbsolute"); | |
| 1415 | pub const readLinkC = @compileError("deprecated; use Dir.readLinkZ or readLinkAbsoluteZ"); | |
| 1416 | ||
| 1387 | 1417 | pub const Walker = struct { |
| 1388 | 1418 | stack: std.ArrayList(StackItem), |
| 1389 | 1419 | name_buffer: std.Buffer, |
| ... | ... | @@ -1411,7 +1441,7 @@ pub const Walker = struct { |
| 1411 | 1441 | while (true) { |
| 1412 | 1442 | if (self.stack.len == 0) return null; |
| 1413 | 1443 | // `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]; | |
| 1415 | 1445 | const dirname_len = top.dirname_len; |
| 1416 | 1446 | if (try top.dir_it.next()) |base| { |
| 1417 | 1447 | self.name_buffer.shrink(dirname_len); |
| ... | ... | @@ -1432,8 +1462,8 @@ pub const Walker = struct { |
| 1432 | 1462 | } |
| 1433 | 1463 | return Entry{ |
| 1434 | 1464 | .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(), | |
| 1437 | 1467 | .kind = base.kind, |
| 1438 | 1468 | }; |
| 1439 | 1469 | } else { |
| ... | ... | @@ -1475,31 +1505,21 @@ pub fn walkPath(allocator: *Allocator, dir_path: []const u8) !Walker { |
| 1475 | 1505 | return walker; |
| 1476 | 1506 | } |
| 1477 | 1507 | |
| 1478 | /// Deprecated; use `Dir.readLink`. | |
| 1479 | pub fn readLink(pathname: []const u8, buffer: *[MAX_PATH_BYTES]u8) ![]u8 { | |
| 1480 | return os.readlink(pathname, buffer); | |
| 1481 | } | |
| 1482 | ||
| 1483 | /// Deprecated; use `Dir.readLinkC`. | |
| 1484 | pub fn readLinkC(pathname_c: [*]const u8, buffer: *[MAX_PATH_BYTES]u8) ![]u8 { | |
| 1485 | return os.readlinkC(pathname_c, buffer); | |
| 1486 | } | |
| 1487 | ||
| 1488 | 1508 | pub const OpenSelfExeError = os.OpenError || os.windows.CreateFileError || SelfExePathError; |
| 1489 | 1509 | |
| 1490 | 1510 | pub fn openSelfExe() OpenSelfExeError!File { |
| 1491 | 1511 | if (builtin.os.tag == .linux) { |
| 1492 | return openFileAbsoluteC("/proc/self/exe", .{}); | |
| 1512 | return openFileAbsoluteZ("/proc/self/exe", .{}); | |
| 1493 | 1513 | } |
| 1494 | 1514 | if (builtin.os.tag == .windows) { |
| 1495 | 1515 | const wide_slice = selfExePathW(); |
| 1496 | 1516 | const prefixed_path_w = try os.windows.wToPrefixedFileW(wide_slice); |
| 1497 | return cwd().openReadW(&prefixed_path_w); | |
| 1517 | return cwd().openFileW(&prefixed_path_w, .{}); | |
| 1498 | 1518 | } |
| 1499 | 1519 | var buf: [MAX_PATH_BYTES]u8 = undefined; |
| 1500 | 1520 | const self_exe_path = try selfExePath(&buf); |
| 1501 | 1521 | 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, .{}); | |
| 1503 | 1523 | } |
| 1504 | 1524 | |
| 1505 | 1525 | test "openSelfExe" { |
| ... | ... | @@ -1533,23 +1553,23 @@ pub fn selfExePath(out_buffer: *[MAX_PATH_BYTES]u8) SelfExePathError![]u8 { |
| 1533 | 1553 | var u32_len: u32 = out_buffer.len; |
| 1534 | 1554 | const rc = std.c._NSGetExecutablePath(out_buffer, &u32_len); |
| 1535 | 1555 | 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)); | |
| 1537 | 1557 | } |
| 1538 | 1558 | switch (builtin.os.tag) { |
| 1539 | .linux => return os.readlinkC("/proc/self/exe", out_buffer), | |
| 1559 | .linux => return os.readlinkZ("/proc/self/exe", out_buffer), | |
| 1540 | 1560 | .freebsd, .dragonfly => { |
| 1541 | 1561 | var mib = [4]c_int{ os.CTL_KERN, os.KERN_PROC, os.KERN_PROC_PATHNAME, -1 }; |
| 1542 | 1562 | var out_len: usize = out_buffer.len; |
| 1543 | 1563 | try os.sysctl(&mib, out_buffer, &out_len, null, 0); |
| 1544 | 1564 | // 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)); | |
| 1546 | 1566 | }, |
| 1547 | 1567 | .netbsd => { |
| 1548 | 1568 | var mib = [4]c_int{ os.CTL_KERN, os.KERN_PROC_ARGS, -1, os.KERN_PROC_PATHNAME }; |
| 1549 | 1569 | var out_len: usize = out_buffer.len; |
| 1550 | 1570 | try os.sysctl(&mib, out_buffer, &out_len, null, 0); |
| 1551 | 1571 | // 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)); | |
| 1553 | 1573 | }, |
| 1554 | 1574 | .windows => { |
| 1555 | 1575 | const utf16le_slice = selfExePathW(); |
| ... | ... | @@ -1564,7 +1584,7 @@ pub fn selfExePath(out_buffer: *[MAX_PATH_BYTES]u8) SelfExePathError![]u8 { |
| 1564 | 1584 | /// The result is UTF16LE-encoded. |
| 1565 | 1585 | pub fn selfExePathW() [:0]const u16 { |
| 1566 | 1586 | 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)); | |
| 1568 | 1588 | } |
| 1569 | 1589 | |
| 1570 | 1590 | /// `selfExeDirPath` except allocates the result on the heap. |
lib/std/fs/file.zig+1-1| ... | ... | @@ -89,7 +89,7 @@ pub const File = struct { |
| 89 | 89 | if (self.isTty()) { |
| 90 | 90 | if (self.handle == os.STDOUT_FILENO or self.handle == os.STDERR_FILENO) { |
| 91 | 91 | // Use getenvC to workaround https://github.com/ziglang/zig/issues/3511 |
| 92 | if (os.getenvC("TERM")) |term| { | |
| 92 | if (os.getenvZ("TERM")) |term| { | |
| 93 | 93 | if (std.mem.eql(u8, term, "dumb")) |
| 94 | 94 | return false; |
| 95 | 95 | } |
lib/std/fs/get_app_data_dir.zig+1-1| ... | ... | @@ -24,7 +24,7 @@ pub fn getAppDataDir(allocator: *mem.Allocator, appname: []const u8) GetAppDataD |
| 24 | 24 | )) { |
| 25 | 25 | os.windows.S_OK => { |
| 26 | 26 | 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) { | |
| 28 | 28 | error.UnexpectedSecondSurrogateHalf => return error.AppDataDirUnavailable, |
| 29 | 29 | error.ExpectedSecondSurrogateHalf => return error.AppDataDirUnavailable, |
| 30 | 30 | error.DanglingSurrogateHalf => return error.AppDataDirUnavailable, |
lib/std/fs/path.zig+14-8| ... | ... | @@ -128,11 +128,13 @@ test "join" { |
| 128 | 128 | testJoinPosix(&[_][]const u8{ "a/", "/c" }, "a/c"); |
| 129 | 129 | } |
| 130 | 130 | |
| 131 | pub fn isAbsoluteC(path_c: [*:0]const u8) bool { | |
| 131 | pub const isAbsoluteC = @compileError("deprecated: renamed to isAbsoluteZ"); | |
| 132 | ||
| 133 | pub fn isAbsoluteZ(path_c: [*:0]const u8) bool { | |
| 132 | 134 | if (builtin.os.tag == .windows) { |
| 133 | return isAbsoluteWindowsC(path_c); | |
| 135 | return isAbsoluteWindowsZ(path_c); | |
| 134 | 136 | } else { |
| 135 | return isAbsolutePosixC(path_c); | |
| 137 | return isAbsolutePosixZ(path_c); | |
| 136 | 138 | } |
| 137 | 139 | } |
| 138 | 140 | |
| ... | ... | @@ -172,19 +174,23 @@ pub fn isAbsoluteWindows(path: []const u8) bool { |
| 172 | 174 | } |
| 173 | 175 | |
| 174 | 176 | pub 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)); | |
| 176 | 178 | } |
| 177 | 179 | |
| 178 | pub fn isAbsoluteWindowsC(path_c: [*:0]const u8) bool { | |
| 179 | return isAbsoluteWindowsImpl(u8, mem.toSliceConst(u8, path_c)); | |
| 180 | pub const isAbsoluteWindowsC = @compileError("deprecated: renamed to isAbsoluteWindowsZ"); | |
| 181 | ||
| 182 | pub fn isAbsoluteWindowsZ(path_c: [*:0]const u8) bool { | |
| 183 | return isAbsoluteWindowsImpl(u8, mem.spanZ(path_c)); | |
| 180 | 184 | } |
| 181 | 185 | |
| 182 | 186 | pub fn isAbsolutePosix(path: []const u8) bool { |
| 183 | 187 | return path.len > 0 and path[0] == sep_posix; |
| 184 | 188 | } |
| 185 | 189 | |
| 186 | pub fn isAbsolutePosixC(path_c: [*:0]const u8) bool { | |
| 187 | return isAbsolutePosix(mem.toSliceConst(u8, path_c)); | |
| 190 | pub const isAbsolutePosixC = @compileError("deprecated: renamed to isAbsolutePosixZ"); | |
| 191 | ||
| 192 | pub fn isAbsolutePosixZ(path_c: [*:0]const u8) bool { | |
| 193 | return isAbsolutePosix(mem.spanZ(path_c)); | |
| 188 | 194 | } |
| 189 | 195 | |
| 190 | 196 | test "isAbsoluteWindows" { |
lib/std/fs/watch.zig+1-1| ... | ... | @@ -326,7 +326,7 @@ pub fn Watch(comptime V: type) type { |
| 326 | 326 | var basename_with_null_consumed = false; |
| 327 | 327 | defer if (!basename_with_null_consumed) self.allocator.free(basename_with_null); |
| 328 | 328 | |
| 329 | const wd = try os.inotify_add_watchC( | |
| 329 | const wd = try os.inotify_add_watchZ( | |
| 330 | 330 | self.os_data.inotify_fd, |
| 331 | 331 | dirname_with_null.ptr, |
| 332 | 332 | 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{ |
| 51 | 51 | .shrinkFn = WasmPageAllocator.shrink, |
| 52 | 52 | }; |
| 53 | 53 | |
| 54 | /// Deprecated. Use `page_allocator`. | |
| 55 | pub const direct_allocator = page_allocator; | |
| 54 | pub const direct_allocator = @compileError("deprecated; use std.heap.page_allocator"); | |
| 56 | 55 | |
| 57 | 56 | const PageAllocator = struct { |
| 58 | 57 | 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 { |
| 129 | 129 | self.index.deinit(); |
| 130 | 130 | } |
| 131 | 131 | { |
| 132 | for (self.data.toSliceConst()) |entry| { | |
| 132 | for (self.data.span()) |entry| { | |
| 133 | 133 | entry.deinit(); |
| 134 | 134 | } |
| 135 | 135 | self.data.deinit(); |
| ... | ... | @@ -141,14 +141,14 @@ pub const Headers = struct { |
| 141 | 141 | errdefer other.deinit(); |
| 142 | 142 | try other.data.ensureCapacity(self.data.len); |
| 143 | 143 | try other.index.initCapacity(self.index.entries.len); |
| 144 | for (self.data.toSliceConst()) |entry| { | |
| 144 | for (self.data.span()) |entry| { | |
| 145 | 145 | try other.append(entry.name, entry.value, entry.never_index); |
| 146 | 146 | } |
| 147 | 147 | return other; |
| 148 | 148 | } |
| 149 | 149 | |
| 150 | 150 | pub fn toSlice(self: Self) []const HeaderEntry { |
| 151 | return self.data.toSliceConst(); | |
| 151 | return self.data.span(); | |
| 152 | 152 | } |
| 153 | 153 | |
| 154 | 154 | pub fn append(self: *Self, name: []const u8, value: []const u8, never_index: ?bool) !void { |
| ... | ... | @@ -279,7 +279,7 @@ pub const Headers = struct { |
| 279 | 279 | |
| 280 | 280 | const buf = try allocator.alloc(HeaderEntry, dex.len); |
| 281 | 281 | var n: usize = 0; |
| 282 | for (dex.toSliceConst()) |idx| { | |
| 282 | for (dex.span()) |idx| { | |
| 283 | 283 | buf[n] = self.data.at(idx); |
| 284 | 284 | n += 1; |
| 285 | 285 | } |
| ... | ... | @@ -302,7 +302,7 @@ pub const Headers = struct { |
| 302 | 302 | // adapted from mem.join |
| 303 | 303 | const total_len = blk: { |
| 304 | 304 | var sum: usize = dex.len - 1; // space for separator(s) |
| 305 | for (dex.toSliceConst()) |idx| | |
| 305 | for (dex.span()) |idx| | |
| 306 | 306 | sum += self.data.at(idx).value.len; |
| 307 | 307 | break :blk sum; |
| 308 | 308 | }; |
| ... | ... | @@ -334,7 +334,7 @@ pub const Headers = struct { |
| 334 | 334 | } |
| 335 | 335 | } |
| 336 | 336 | { // 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| { | |
| 338 | 338 | var dex = &self.index.get(entry.name).?.value; |
| 339 | 339 | dex.appendAssumeCapacity(i); |
| 340 | 340 | } |
| ... | ... | @@ -495,8 +495,8 @@ test "Headers.getIndices" { |
| 495 | 495 | try h.append("set-cookie", "y=2", null); |
| 496 | 496 | |
| 497 | 497 | 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()); | |
| 500 | 500 | } |
| 501 | 501 | |
| 502 | 502 | test "Headers.get" { |
lib/std/io.zig+3-10| ... | ... | @@ -128,16 +128,6 @@ pub const BufferedAtomicFile = @import("io/buffered_atomic_file.zig").BufferedAt |
| 128 | 128 | |
| 129 | 129 | pub const StreamSource = @import("io/stream_source.zig").StreamSource; |
| 130 | 130 | |
| 131 | /// Deprecated; use `std.fs.Dir.writeFile`. | |
| 132 | pub 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`. | |
| 137 | pub fn readFileAlloc(allocator: *mem.Allocator, path: []const u8) ![]u8 { | |
| 138 | return fs.cwd().readFileAlloc(allocator, path, math.maxInt(usize)); | |
| 139 | } | |
| 140 | ||
| 141 | 131 | /// An OutStream that doesn't write to anything. |
| 142 | 132 | pub const null_out_stream = @as(NullOutStream, .{ .context = {} }); |
| 143 | 133 | |
| ... | ... | @@ -153,3 +143,6 @@ test "null_out_stream" { |
| 153 | 143 | test "" { |
| 154 | 144 | _ = @import("io/test.zig"); |
| 155 | 145 | } |
| 146 | ||
| 147 | pub const writeFile = @compileError("deprecated: use std.fs.Dir.writeFile with math.maxInt(usize)"); | |
| 148 | pub 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 { |
| 15 | 15 | |
| 16 | 16 | /// TODO when https://github.com/ziglang/zig/issues/2761 is solved |
| 17 | 17 | /// this API will not need an allocator |
| 18 | /// TODO integrate this with Dir API | |
| 18 | 19 | pub fn create(allocator: *mem.Allocator, dest_path: []const u8) !*BufferedAtomicFile { |
| 19 | 20 | var self = try allocator.create(BufferedAtomicFile); |
| 20 | 21 | self.* = BufferedAtomicFile{ |
| ... | ... | @@ -25,7 +26,7 @@ pub const BufferedAtomicFile = struct { |
| 25 | 26 | }; |
| 26 | 27 | errdefer allocator.destroy(self); |
| 27 | 28 | |
| 28 | self.atomic_file = try fs.AtomicFile.init(dest_path, File.default_mode); | |
| 29 | self.atomic_file = try fs.cwd().atomicFile(dest_path, .{}); | |
| 29 | 30 | errdefer self.atomic_file.deinit(); |
| 30 | 31 | |
| 31 | 32 | self.file_stream = self.atomic_file.file.outStream(); |
lib/std/io/c_out_stream.zig+1-1| ... | ... | @@ -36,7 +36,7 @@ test "" { |
| 36 | 36 | const out_file = std.c.fopen(filename, "w") orelse return error.UnableToOpenTestFile; |
| 37 | 37 | defer { |
| 38 | 38 | _ = std.c.fclose(out_file); |
| 39 | fs.cwd().deleteFileC(filename) catch {}; | |
| 39 | fs.cwd().deleteFileZ(filename) catch {}; | |
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 42 | const out_stream = &io.COutStream.init(out_file).stream; |
lib/std/io/in_stream.zig+1-7| ... | ... | @@ -48,13 +48,7 @@ pub fn InStream( |
| 48 | 48 | if (amt_read < buf.len) return error.EndOfStream; |
| 49 | 49 | } |
| 50 | 50 | |
| 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()"); | |
| 58 | 52 | |
| 59 | 53 | /// Appends to the `std.ArrayList` contents by reading from the stream until end of stream is found. |
| 60 | 54 | /// 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 { |
| 1944 | 1944 | } |
| 1945 | 1945 | |
| 1946 | 1946 | 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]) { | |
| 1948 | 1948 | // Object Parent -> [ ..., object, <key>, value ] |
| 1949 | 1949 | Value.String => |key| { |
| 1950 | 1950 | _ = 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 { |
| 211 | 211 | .String => |inner| try self.emitString(inner), |
| 212 | 212 | .Array => |inner| { |
| 213 | 213 | try self.beginArray(); |
| 214 | for (inner.toSliceConst()) |elem| { | |
| 214 | for (inner.span()) |elem| { | |
| 215 | 215 | try self.arrayElem(); |
| 216 | 216 | try self.emitJson(elem); |
| 217 | 217 | } |
lib/std/mem.zig+2-9| ... | ... | @@ -492,15 +492,8 @@ pub fn eql(comptime T: type, a: []const T, b: []const T) bool { |
| 492 | 492 | return true; |
| 493 | 493 | } |
| 494 | 494 | |
| 495 | /// Deprecated. Use `spanZ`. | |
| 496 | pub 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`. | |
| 501 | pub fn toSlice(comptime T: type, ptr: [*:0]T) [:0]T { | |
| 502 | return ptr[0..lenZ(ptr) :0]; | |
| 503 | } | |
| 495 | pub const toSliceConst = @compileError("deprecated; use std.mem.spanZ"); | |
| 496 | pub const toSlice = @compileError("deprecated; use std.mem.spanZ"); | |
| 504 | 497 | |
| 505 | 498 | /// Takes a pointer to an array, a sentinel-terminated pointer, or a slice, and |
| 506 | 499 | /// 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) !* |
| 490 | 490 | |
| 491 | 491 | if (info.canonname) |n| { |
| 492 | 492 | 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)); | |
| 494 | 494 | } |
| 495 | 495 | } |
| 496 | 496 | i += 1; |
| ... | ... | @@ -514,7 +514,7 @@ pub fn getAddressList(allocator: *mem.Allocator, name: []const u8, port: u16) !* |
| 514 | 514 | result.canon_name = canon.toOwnedSlice(); |
| 515 | 515 | } |
| 516 | 516 | |
| 517 | for (lookup_addrs.toSliceConst()) |lookup_addr, i| { | |
| 517 | for (lookup_addrs.span()) |lookup_addr, i| { | |
| 518 | 518 | result.addrs[i] = lookup_addr.addr; |
| 519 | 519 | assert(result.addrs[i].getPort() == port); |
| 520 | 520 | } |
| ... | ... | @@ -567,7 +567,7 @@ fn linuxLookupName( |
| 567 | 567 | // No further processing is needed if there are fewer than 2 |
| 568 | 568 | // results or if there are only IPv4 results. |
| 569 | 569 | 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| { | |
| 571 | 571 | if (addr.addr.any.family != os.AF_INET) break false; |
| 572 | 572 | } else true; |
| 573 | 573 | if (all_ip4) return; |
| ... | ... | @@ -579,7 +579,7 @@ fn linuxLookupName( |
| 579 | 579 | // So far the label/precedence table cannot be customized. |
| 580 | 580 | // This implementation is ported from musl libc. |
| 581 | 581 | // A more idiomatic "ziggy" implementation would be welcome. |
| 582 | for (addrs.toSlice()) |*addr, i| { | |
| 582 | for (addrs.span()) |*addr, i| { | |
| 583 | 583 | var key: i32 = 0; |
| 584 | 584 | var sa6: os.sockaddr_in6 = undefined; |
| 585 | 585 | @memset(@ptrCast([*]u8, &sa6), 0, @sizeOf(os.sockaddr_in6)); |
| ... | ... | @@ -644,7 +644,7 @@ fn linuxLookupName( |
| 644 | 644 | key |= (MAXADDRS - @intCast(i32, i)) << DAS_ORDER_SHIFT; |
| 645 | 645 | addr.sortkey = key; |
| 646 | 646 | } |
| 647 | std.sort.sort(LookupAddr, addrs.toSlice(), addrCmpLessThan); | |
| 647 | std.sort.sort(LookupAddr, addrs.span(), addrCmpLessThan); | |
| 648 | 648 | } |
| 649 | 649 | |
| 650 | 650 | const Policy = struct { |
| ... | ... | @@ -803,7 +803,7 @@ fn linuxLookupNameFromHosts( |
| 803 | 803 | family: os.sa_family_t, |
| 804 | 804 | port: u16, |
| 805 | 805 | ) !void { |
| 806 | const file = fs.openFileAbsoluteC("/etc/hosts", .{}) catch |err| switch (err) { | |
| 806 | const file = fs.openFileAbsoluteZ("/etc/hosts", .{}) catch |err| switch (err) { | |
| 807 | 807 | error.FileNotFound, |
| 808 | 808 | error.NotDir, |
| 809 | 809 | error.AccessDenied, |
| ... | ... | @@ -887,7 +887,7 @@ fn linuxLookupNameFromDnsSearch( |
| 887 | 887 | const search = if (rc.search.isNull() or dots >= rc.ndots or mem.endsWith(u8, name, ".")) |
| 888 | 888 | &[_]u8{} |
| 889 | 889 | else |
| 890 | rc.search.toSliceConst(); | |
| 890 | rc.search.span(); | |
| 891 | 891 | |
| 892 | 892 | var canon_name = name; |
| 893 | 893 | |
| ... | ... | @@ -900,14 +900,14 @@ fn linuxLookupNameFromDnsSearch( |
| 900 | 900 | // name is not a CNAME record) and serves as a buffer for passing |
| 901 | 901 | // the full requested name to name_from_dns. |
| 902 | 902 | try canon.resize(canon_name.len); |
| 903 | mem.copy(u8, canon.toSlice(), canon_name); | |
| 903 | mem.copy(u8, canon.span(), canon_name); | |
| 904 | 904 | try canon.appendByte('.'); |
| 905 | 905 | |
| 906 | 906 | var tok_it = mem.tokenize(search, " \t"); |
| 907 | 907 | while (tok_it.next()) |tok| { |
| 908 | 908 | canon.shrink(canon_name.len + 1); |
| 909 | 909 | try canon.append(tok); |
| 910 | try linuxLookupNameFromDns(addrs, canon, canon.toSliceConst(), family, rc, port); | |
| 910 | try linuxLookupNameFromDns(addrs, canon, canon.span(), family, rc, port); | |
| 911 | 911 | if (addrs.len != 0) return; |
| 912 | 912 | } |
| 913 | 913 | |
| ... | ... | @@ -1000,7 +1000,7 @@ fn getResolvConf(allocator: *mem.Allocator, rc: *ResolvConf) !void { |
| 1000 | 1000 | }; |
| 1001 | 1001 | errdefer rc.deinit(); |
| 1002 | 1002 | |
| 1003 | const file = fs.openFileAbsoluteC("/etc/resolv.conf", .{}) catch |err| switch (err) { | |
| 1003 | const file = fs.openFileAbsoluteZ("/etc/resolv.conf", .{}) catch |err| switch (err) { | |
| 1004 | 1004 | error.FileNotFound, |
| 1005 | 1005 | error.NotDir, |
| 1006 | 1006 | error.AccessDenied, |
| ... | ... | @@ -1079,9 +1079,9 @@ fn resMSendRc( |
| 1079 | 1079 | defer ns_list.deinit(); |
| 1080 | 1080 | |
| 1081 | 1081 | try ns_list.resize(rc.ns.len); |
| 1082 | const ns = ns_list.toSlice(); | |
| 1082 | const ns = ns_list.span(); | |
| 1083 | 1083 | |
| 1084 | for (rc.ns.toSliceConst()) |iplit, i| { | |
| 1084 | for (rc.ns.span()) |iplit, i| { | |
| 1085 | 1085 | ns[i] = iplit.addr; |
| 1086 | 1086 | assert(ns[i].getPort() == 53); |
| 1087 | 1087 | 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) |
| 1265 | 1265 | var tmp: [256]u8 = undefined; |
| 1266 | 1266 | // Returns len of compressed name. strlen to get canon name. |
| 1267 | 1267 | _ = 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)); | |
| 1269 | 1269 | if (isValidHostName(canon_name)) { |
| 1270 | 1270 | try ctx.canon.replaceContents(canon_name); |
| 1271 | 1271 | } |
lib/std/os.zig+85-55| ... | ... | @@ -163,7 +163,7 @@ pub fn getrandom(buffer: []u8) GetRandomError!void { |
| 163 | 163 | } |
| 164 | 164 | |
| 165 | 165 | fn 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); | |
| 167 | 167 | defer close(fd); |
| 168 | 168 | |
| 169 | 169 | const st = try fstat(fd); |
| ... | ... | @@ -853,13 +853,15 @@ pub const OpenError = error{ |
| 853 | 853 | /// TODO support windows |
| 854 | 854 | pub fn open(file_path: []const u8, flags: u32, perm: usize) OpenError!fd_t { |
| 855 | 855 | const file_path_c = try toPosixPath(file_path); |
| 856 | return openC(&file_path_c, flags, perm); | |
| 856 | return openZ(&file_path_c, flags, perm); | |
| 857 | 857 | } |
| 858 | 858 | |
| 859 | pub const openC = @compileError("deprecated: renamed to openZ"); | |
| 860 | ||
| 859 | 861 | /// Open and possibly create a file. Keeps trying if it gets interrupted. |
| 860 | 862 | /// See also `open`. |
| 861 | 863 | /// TODO support windows |
| 862 | pub fn openC(file_path: [*:0]const u8, flags: u32, perm: usize) OpenError!fd_t { | |
| 864 | pub fn openZ(file_path: [*:0]const u8, flags: u32, perm: usize) OpenError!fd_t { | |
| 863 | 865 | while (true) { |
| 864 | 866 | const rc = system.open(file_path, flags, perm); |
| 865 | 867 | switch (errno(rc)) { |
| ... | ... | @@ -895,14 +897,16 @@ pub fn openC(file_path: [*:0]const u8, flags: u32, perm: usize) OpenError!fd_t { |
| 895 | 897 | /// TODO support windows |
| 896 | 898 | pub fn openat(dir_fd: fd_t, file_path: []const u8, flags: u32, mode: mode_t) OpenError!fd_t { |
| 897 | 899 | 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); | |
| 899 | 901 | } |
| 900 | 902 | |
| 903 | pub const openatC = @compileError("deprecated: renamed to openatZ"); | |
| 904 | ||
| 901 | 905 | /// Open and possibly create a file. Keeps trying if it gets interrupted. |
| 902 | 906 | /// `file_path` is relative to the open directory handle `dir_fd`. |
| 903 | 907 | /// See also `openat`. |
| 904 | 908 | /// TODO support windows |
| 905 | pub fn openatC(dir_fd: fd_t, file_path: [*:0]const u8, flags: u32, mode: mode_t) OpenError!fd_t { | |
| 909 | pub fn openatZ(dir_fd: fd_t, file_path: [*:0]const u8, flags: u32, mode: mode_t) OpenError!fd_t { | |
| 906 | 910 | while (true) { |
| 907 | 911 | const rc = system.openat(dir_fd, file_path, flags, mode); |
| 908 | 912 | switch (errno(rc)) { |
| ... | ... | @@ -959,8 +963,7 @@ pub const ExecveError = error{ |
| 959 | 963 | NameTooLong, |
| 960 | 964 | } || UnexpectedError; |
| 961 | 965 | |
| 962 | /// Deprecated in favor of `execveZ`. | |
| 963 | pub const execveC = execveZ; | |
| 966 | pub const execveC = @compileError("deprecated: use execveZ"); | |
| 964 | 967 | |
| 965 | 968 | /// Like `execve` except the parameters are null-terminated, |
| 966 | 969 | /// matching the syscall API on all targets. This removes the need for an allocator. |
| ... | ... | @@ -992,8 +995,7 @@ pub fn execveZ( |
| 992 | 995 | } |
| 993 | 996 | } |
| 994 | 997 | |
| 995 | /// Deprecated in favor of `execvpeZ`. | |
| 996 | pub const execvpeC = execvpeZ; | |
| 998 | pub const execvpeC = @compileError("deprecated in favor of execvpeZ"); | |
| 997 | 999 | |
| 998 | 1000 | pub const Arg0Expand = enum { |
| 999 | 1001 | expand, |
| ... | ... | @@ -1012,7 +1014,7 @@ pub fn execvpeZ_expandArg0( |
| 1012 | 1014 | }, |
| 1013 | 1015 | envp: [*:null]const ?[*:0]const u8, |
| 1014 | 1016 | ) ExecveError { |
| 1015 | const file_slice = mem.toSliceConst(u8, file); | |
| 1017 | const file_slice = mem.spanZ(file); | |
| 1016 | 1018 | if (mem.indexOfScalar(u8, file_slice, '/') != null) return execveZ(file, child_argv, envp); |
| 1017 | 1019 | |
| 1018 | 1020 | const PATH = getenvZ("PATH") orelse "/usr/local/bin:/bin/:/usr/bin"; |
| ... | ... | @@ -1076,7 +1078,7 @@ pub fn execvpe_expandArg0( |
| 1076 | 1078 | mem.set(?[*:0]u8, argv_buf, null); |
| 1077 | 1079 | defer { |
| 1078 | 1080 | 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; | |
| 1080 | 1082 | allocator.free(arg_buf); |
| 1081 | 1083 | } |
| 1082 | 1084 | allocator.free(argv_buf); |
| ... | ... | @@ -1189,20 +1191,19 @@ pub fn getenv(key: []const u8) ?[]const u8 { |
| 1189 | 1191 | return null; |
| 1190 | 1192 | } |
| 1191 | 1193 | |
| 1192 | /// Deprecated in favor of `getenvZ`. | |
| 1193 | pub const getenvC = getenvZ; | |
| 1194 | pub const getenvC = @compileError("Deprecated in favor of `getenvZ`"); | |
| 1194 | 1195 | |
| 1195 | 1196 | /// Get an environment variable with a null-terminated name. |
| 1196 | 1197 | /// See also `getenv`. |
| 1197 | 1198 | pub fn getenvZ(key: [*:0]const u8) ?[]const u8 { |
| 1198 | 1199 | if (builtin.link_libc) { |
| 1199 | 1200 | const value = system.getenv(key) orelse return null; |
| 1200 | return mem.toSliceConst(u8, value); | |
| 1201 | return mem.spanZ(value); | |
| 1201 | 1202 | } |
| 1202 | 1203 | if (builtin.os.tag == .windows) { |
| 1203 | 1204 | @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."); |
| 1204 | 1205 | } |
| 1205 | return getenv(mem.toSliceConst(u8, key)); | |
| 1206 | return getenv(mem.spanZ(key)); | |
| 1206 | 1207 | } |
| 1207 | 1208 | |
| 1208 | 1209 | /// 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 { |
| 1211 | 1212 | if (builtin.os.tag != .windows) { |
| 1212 | 1213 | @compileError("std.os.getenvW is a Windows-only API"); |
| 1213 | 1214 | } |
| 1214 | const key_slice = mem.toSliceConst(u16, key); | |
| 1215 | const key_slice = mem.spanZ(key); | |
| 1215 | 1216 | const ptr = windows.peb().ProcessParameters.Environment; |
| 1216 | 1217 | var i: usize = 0; |
| 1217 | 1218 | while (ptr[i] != 0) { |
| ... | ... | @@ -1250,7 +1251,7 @@ pub fn getcwd(out_buffer: []u8) GetCwdError![]u8 { |
| 1250 | 1251 | break :blk errno(system.getcwd(out_buffer.ptr, out_buffer.len)); |
| 1251 | 1252 | }; |
| 1252 | 1253 | 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)), | |
| 1254 | 1255 | EFAULT => unreachable, |
| 1255 | 1256 | EINVAL => unreachable, |
| 1256 | 1257 | ENOENT => return error.CurrentWorkingDirectoryUnlinked, |
| ... | ... | @@ -1288,13 +1289,15 @@ pub fn symlink(target_path: []const u8, sym_link_path: []const u8) SymLinkError! |
| 1288 | 1289 | } else { |
| 1289 | 1290 | const target_path_c = try toPosixPath(target_path); |
| 1290 | 1291 | 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); | |
| 1292 | 1293 | } |
| 1293 | 1294 | } |
| 1294 | 1295 | |
| 1296 | pub const symlinkC = @compileError("deprecated: renamed to symlinkZ"); | |
| 1297 | ||
| 1295 | 1298 | /// This is the same as `symlink` except the parameters are null-terminated pointers. |
| 1296 | 1299 | /// See also `symlink`. |
| 1297 | pub fn symlinkC(target_path: [*:0]const u8, sym_link_path: [*:0]const u8) SymLinkError!void { | |
| 1300 | pub fn symlinkZ(target_path: [*:0]const u8, sym_link_path: [*:0]const u8) SymLinkError!void { | |
| 1298 | 1301 | if (builtin.os.tag == .windows) { |
| 1299 | 1302 | const target_path_w = try windows.cStrToPrefixedFileW(target_path); |
| 1300 | 1303 | 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 |
| 1323 | 1326 | pub fn symlinkat(target_path: []const u8, newdirfd: fd_t, sym_link_path: []const u8) SymLinkError!void { |
| 1324 | 1327 | const target_path_c = try toPosixPath(target_path); |
| 1325 | 1328 | 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); | |
| 1327 | 1330 | } |
| 1328 | 1331 | |
| 1329 | pub fn symlinkatC(target_path: [*:0]const u8, newdirfd: fd_t, sym_link_path: [*:0]const u8) SymLinkError!void { | |
| 1332 | pub const symlinkatC = @compileError("deprecated: renamed to symlinkatZ"); | |
| 1333 | ||
| 1334 | pub fn symlinkatZ(target_path: [*:0]const u8, newdirfd: fd_t, sym_link_path: [*:0]const u8) SymLinkError!void { | |
| 1330 | 1335 | switch (errno(system.symlinkat(target_path, newdirfd, sym_link_path))) { |
| 1331 | 1336 | 0 => return, |
| 1332 | 1337 | EFAULT => unreachable, |
| ... | ... | @@ -1375,12 +1380,14 @@ pub fn unlink(file_path: []const u8) UnlinkError!void { |
| 1375 | 1380 | return windows.DeleteFileW(&file_path_w); |
| 1376 | 1381 | } else { |
| 1377 | 1382 | const file_path_c = try toPosixPath(file_path); |
| 1378 | return unlinkC(&file_path_c); | |
| 1383 | return unlinkZ(&file_path_c); | |
| 1379 | 1384 | } |
| 1380 | 1385 | } |
| 1381 | 1386 | |
| 1387 | pub const unlinkC = @compileError("deprecated: renamed to unlinkZ"); | |
| 1388 | ||
| 1382 | 1389 | /// Same as `unlink` except the parameter is a null terminated UTF8-encoded string. |
| 1383 | pub fn unlinkC(file_path: [*:0]const u8) UnlinkError!void { | |
| 1390 | pub fn unlinkZ(file_path: [*:0]const u8) UnlinkError!void { | |
| 1384 | 1391 | if (builtin.os.tag == .windows) { |
| 1385 | 1392 | const file_path_w = try windows.cStrToPrefixedFileW(file_path); |
| 1386 | 1393 | return windows.DeleteFileW(&file_path_w); |
| ... | ... | @@ -1417,11 +1424,13 @@ pub fn unlinkat(dirfd: fd_t, file_path: []const u8, flags: u32) UnlinkatError!vo |
| 1417 | 1424 | return unlinkatW(dirfd, &file_path_w, flags); |
| 1418 | 1425 | } |
| 1419 | 1426 | const file_path_c = try toPosixPath(file_path); |
| 1420 | return unlinkatC(dirfd, &file_path_c, flags); | |
| 1427 | return unlinkatZ(dirfd, &file_path_c, flags); | |
| 1421 | 1428 | } |
| 1422 | 1429 | |
| 1430 | pub const unlinkatC = @compileError("deprecated: renamed to unlinkatZ"); | |
| 1431 | ||
| 1423 | 1432 | /// Same as `unlinkat` but `file_path` is a null-terminated string. |
| 1424 | pub fn unlinkatC(dirfd: fd_t, file_path_c: [*:0]const u8, flags: u32) UnlinkatError!void { | |
| 1433 | pub fn unlinkatZ(dirfd: fd_t, file_path_c: [*:0]const u8, flags: u32) UnlinkatError!void { | |
| 1425 | 1434 | if (builtin.os.tag == .windows) { |
| 1426 | 1435 | const file_path_w = try windows.cStrToPrefixedFileW(file_path_c); |
| 1427 | 1436 | 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 |
| 1459 | 1468 | else |
| 1460 | 1469 | @as(w.ULONG, w.FILE_DELETE_ON_CLOSE | w.FILE_NON_DIRECTORY_FILE); |
| 1461 | 1470 | |
| 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); | |
| 1463 | 1472 | var nt_name = w.UNICODE_STRING{ |
| 1464 | 1473 | .Length = path_len_bytes, |
| 1465 | 1474 | .MaximumLength = path_len_bytes, |
| ... | ... | @@ -1543,12 +1552,14 @@ pub fn rename(old_path: []const u8, new_path: []const u8) RenameError!void { |
| 1543 | 1552 | } else { |
| 1544 | 1553 | const old_path_c = try toPosixPath(old_path); |
| 1545 | 1554 | 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); | |
| 1547 | 1556 | } |
| 1548 | 1557 | } |
| 1549 | 1558 | |
| 1559 | pub const renameC = @compileError("deprecated: renamed to renameZ"); | |
| 1560 | ||
| 1550 | 1561 | /// Same as `rename` except the parameters are null-terminated byte arrays. |
| 1551 | pub fn renameC(old_path: [*:0]const u8, new_path: [*:0]const u8) RenameError!void { | |
| 1562 | pub fn renameZ(old_path: [*:0]const u8, new_path: [*:0]const u8) RenameError!void { | |
| 1552 | 1563 | if (builtin.os.tag == .windows) { |
| 1553 | 1564 | const old_path_w = try windows.cStrToPrefixedFileW(old_path); |
| 1554 | 1565 | 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 |
| 1715 | 1726 | return mkdiratW(dir_fd, &sub_dir_path_w, mode); |
| 1716 | 1727 | } else { |
| 1717 | 1728 | 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); | |
| 1719 | 1730 | } |
| 1720 | 1731 | } |
| 1721 | 1732 | |
| 1722 | pub fn mkdiratC(dir_fd: fd_t, sub_dir_path: [*:0]const u8, mode: u32) MakeDirError!void { | |
| 1733 | pub const mkdiratC = @compileError("deprecated: renamed to mkdiratZ"); | |
| 1734 | ||
| 1735 | pub fn mkdiratZ(dir_fd: fd_t, sub_dir_path: [*:0]const u8, mode: u32) MakeDirError!void { | |
| 1723 | 1736 | if (builtin.os.tag == .windows) { |
| 1724 | 1737 | const sub_dir_path_w = try windows.cStrToPrefixedFileW(sub_dir_path); |
| 1725 | 1738 | return mkdiratW(dir_fd, &sub_dir_path_w, mode); |
| ... | ... | @@ -1810,12 +1823,14 @@ pub fn rmdir(dir_path: []const u8) DeleteDirError!void { |
| 1810 | 1823 | return windows.RemoveDirectoryW(&dir_path_w); |
| 1811 | 1824 | } else { |
| 1812 | 1825 | const dir_path_c = try toPosixPath(dir_path); |
| 1813 | return rmdirC(&dir_path_c); | |
| 1826 | return rmdirZ(&dir_path_c); | |
| 1814 | 1827 | } |
| 1815 | 1828 | } |
| 1816 | 1829 | |
| 1830 | pub const rmdirC = @compileError("deprecated: renamed to rmdirZ"); | |
| 1831 | ||
| 1817 | 1832 | /// Same as `rmdir` except the parameter is null-terminated. |
| 1818 | pub fn rmdirC(dir_path: [*:0]const u8) DeleteDirError!void { | |
| 1833 | pub fn rmdirZ(dir_path: [*:0]const u8) DeleteDirError!void { | |
| 1819 | 1834 | if (builtin.os.tag == .windows) { |
| 1820 | 1835 | const dir_path_w = try windows.cStrToPrefixedFileW(dir_path); |
| 1821 | 1836 | return windows.RemoveDirectoryW(&dir_path_w); |
| ... | ... | @@ -1857,12 +1872,14 @@ pub fn chdir(dir_path: []const u8) ChangeCurDirError!void { |
| 1857 | 1872 | @compileError("TODO implement chdir for Windows"); |
| 1858 | 1873 | } else { |
| 1859 | 1874 | const dir_path_c = try toPosixPath(dir_path); |
| 1860 | return chdirC(&dir_path_c); | |
| 1875 | return chdirZ(&dir_path_c); | |
| 1861 | 1876 | } |
| 1862 | 1877 | } |
| 1863 | 1878 | |
| 1879 | pub const chdirC = @compileError("deprecated: renamed to chdirZ"); | |
| 1880 | ||
| 1864 | 1881 | /// Same as `chdir` except the parameter is null-terminated. |
| 1865 | pub fn chdirC(dir_path: [*:0]const u8) ChangeCurDirError!void { | |
| 1882 | pub fn chdirZ(dir_path: [*:0]const u8) ChangeCurDirError!void { | |
| 1866 | 1883 | if (builtin.os.tag == .windows) { |
| 1867 | 1884 | const dir_path_w = try windows.cStrToPrefixedFileW(dir_path); |
| 1868 | 1885 | @compileError("TODO implement chdir for Windows"); |
| ... | ... | @@ -1919,12 +1936,14 @@ pub fn readlink(file_path: []const u8, out_buffer: []u8) ReadLinkError![]u8 { |
| 1919 | 1936 | @compileError("TODO implement readlink for Windows"); |
| 1920 | 1937 | } else { |
| 1921 | 1938 | const file_path_c = try toPosixPath(file_path); |
| 1922 | return readlinkC(&file_path_c, out_buffer); | |
| 1939 | return readlinkZ(&file_path_c, out_buffer); | |
| 1923 | 1940 | } |
| 1924 | 1941 | } |
| 1925 | 1942 | |
| 1943 | pub const readlinkC = @compileError("deprecated: renamed to readlinkZ"); | |
| 1944 | ||
| 1926 | 1945 | /// Same as `readlink` except `file_path` is null-terminated. |
| 1927 | pub fn readlinkC(file_path: [*:0]const u8, out_buffer: []u8) ReadLinkError![]u8 { | |
| 1946 | pub fn readlinkZ(file_path: [*:0]const u8, out_buffer: []u8) ReadLinkError![]u8 { | |
| 1928 | 1947 | if (builtin.os.tag == .windows) { |
| 1929 | 1948 | const file_path_w = try windows.cStrToPrefixedFileW(file_path); |
| 1930 | 1949 | @compileError("TODO implement readlink for Windows"); |
| ... | ... | @@ -1945,7 +1964,9 @@ pub fn readlinkC(file_path: [*:0]const u8, out_buffer: []u8) ReadLinkError![]u8 |
| 1945 | 1964 | } |
| 1946 | 1965 | } |
| 1947 | 1966 | |
| 1948 | pub fn readlinkatC(dirfd: fd_t, file_path: [*:0]const u8, out_buffer: []u8) ReadLinkError![]u8 { | |
| 1967 | pub const readlinkatC = @compileError("deprecated: renamed to readlinkatZ"); | |
| 1968 | ||
| 1969 | pub fn readlinkatZ(dirfd: fd_t, file_path: [*:0]const u8, out_buffer: []u8) ReadLinkError![]u8 { | |
| 1949 | 1970 | if (builtin.os.tag == .windows) { |
| 1950 | 1971 | const file_path_w = try windows.cStrToPrefixedFileW(file_path); |
| 1951 | 1972 | @compileError("TODO implement readlink for Windows"); |
| ... | ... | @@ -2553,10 +2574,12 @@ const FStatAtError = FStatError || error{NameTooLong}; |
| 2553 | 2574 | |
| 2554 | 2575 | pub fn fstatat(dirfd: fd_t, pathname: []const u8, flags: u32) FStatAtError![]Stat { |
| 2555 | 2576 | const pathname_c = try toPosixPath(pathname); |
| 2556 | return fstatatC(dirfd, &pathname_c, flags); | |
| 2577 | return fstatatZ(dirfd, &pathname_c, flags); | |
| 2557 | 2578 | } |
| 2558 | 2579 | |
| 2559 | pub fn fstatatC(dirfd: fd_t, pathname: [*:0]const u8, flags: u32) FStatAtError!Stat { | |
| 2580 | pub const fstatatC = @compileError("deprecated: renamed to fstatatZ"); | |
| 2581 | ||
| 2582 | pub fn fstatatZ(dirfd: fd_t, pathname: [*:0]const u8, flags: u32) FStatAtError!Stat { | |
| 2560 | 2583 | var stat: Stat = undefined; |
| 2561 | 2584 | switch (errno(system.fstatat(dirfd, pathname, &stat, flags))) { |
| 2562 | 2585 | 0 => return stat, |
| ... | ... | @@ -2668,11 +2691,13 @@ pub const INotifyAddWatchError = error{ |
| 2668 | 2691 | /// add a watch to an initialized inotify instance |
| 2669 | 2692 | pub fn inotify_add_watch(inotify_fd: i32, pathname: []const u8, mask: u32) INotifyAddWatchError!i32 { |
| 2670 | 2693 | 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); | |
| 2672 | 2695 | } |
| 2673 | 2696 | |
| 2697 | pub const inotify_add_watchC = @compileError("deprecated: renamed to inotify_add_watchZ"); | |
| 2698 | ||
| 2674 | 2699 | /// Same as `inotify_add_watch` except pathname is null-terminated. |
| 2675 | pub fn inotify_add_watchC(inotify_fd: i32, pathname: [*:0]const u8, mask: u32) INotifyAddWatchError!i32 { | |
| 2700 | pub fn inotify_add_watchZ(inotify_fd: i32, pathname: [*:0]const u8, mask: u32) INotifyAddWatchError!i32 { | |
| 2676 | 2701 | const rc = system.inotify_add_watch(inotify_fd, pathname, mask); |
| 2677 | 2702 | switch (errno(rc)) { |
| 2678 | 2703 | 0 => return @intCast(i32, rc), |
| ... | ... | @@ -2829,11 +2854,10 @@ pub fn access(path: []const u8, mode: u32) AccessError!void { |
| 2829 | 2854 | return; |
| 2830 | 2855 | } |
| 2831 | 2856 | const path_c = try toPosixPath(path); |
| 2832 | return accessC(&path_c, mode); | |
| 2857 | return accessZ(&path_c, mode); | |
| 2833 | 2858 | } |
| 2834 | 2859 | |
| 2835 | /// Deprecated in favor of `accessZ`. | |
| 2836 | pub const accessC = accessZ; | |
| 2860 | pub const accessC = @compileError("Deprecated in favor of `accessZ`"); | |
| 2837 | 2861 | |
| 2838 | 2862 | /// Same as `access` except `path` is null-terminated. |
| 2839 | 2863 | pub 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 |
| 2920 | 2944 | return; |
| 2921 | 2945 | } |
| 2922 | 2946 | |
| 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) { | |
| 2924 | 2948 | error.Overflow => return error.NameTooLong, |
| 2925 | 2949 | }; |
| 2926 | 2950 | var nt_name = windows.UNICODE_STRING{ |
| ... | ... | @@ -3019,7 +3043,9 @@ pub fn sysctl( |
| 3019 | 3043 | } |
| 3020 | 3044 | } |
| 3021 | 3045 | |
| 3022 | pub fn sysctlbynameC( | |
| 3046 | pub const sysctlbynameC = @compileError("deprecated: renamed to sysctlbynameZ"); | |
| 3047 | ||
| 3048 | pub fn sysctlbynameZ( | |
| 3023 | 3049 | name: [*:0]const u8, |
| 3024 | 3050 | oldp: ?*c_void, |
| 3025 | 3051 | oldlenp: ?*usize, |
| ... | ... | @@ -3224,23 +3250,25 @@ pub fn realpath(pathname: []const u8, out_buffer: *[MAX_PATH_BYTES]u8) RealPathE |
| 3224 | 3250 | return realpathW(&pathname_w, out_buffer); |
| 3225 | 3251 | } |
| 3226 | 3252 | const pathname_c = try toPosixPath(pathname); |
| 3227 | return realpathC(&pathname_c, out_buffer); | |
| 3253 | return realpathZ(&pathname_c, out_buffer); | |
| 3228 | 3254 | } |
| 3229 | 3255 | |
| 3256 | pub const realpathC = @compileError("deprecated: renamed realpathZ"); | |
| 3257 | ||
| 3230 | 3258 | /// Same as `realpath` except `pathname` is null-terminated. |
| 3231 | pub fn realpathC(pathname: [*:0]const u8, out_buffer: *[MAX_PATH_BYTES]u8) RealPathError![]u8 { | |
| 3259 | pub fn realpathZ(pathname: [*:0]const u8, out_buffer: *[MAX_PATH_BYTES]u8) RealPathError![]u8 { | |
| 3232 | 3260 | if (builtin.os.tag == .windows) { |
| 3233 | 3261 | const pathname_w = try windows.cStrToPrefixedFileW(pathname); |
| 3234 | 3262 | return realpathW(&pathname_w, out_buffer); |
| 3235 | 3263 | } |
| 3236 | 3264 | 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); | |
| 3238 | 3266 | defer close(fd); |
| 3239 | 3267 | |
| 3240 | 3268 | var procfs_buf: ["/proc/self/fd/-2147483648".len:0]u8 = undefined; |
| 3241 | 3269 | const proc_path = std.fmt.bufPrint(procfs_buf[0..], "/proc/self/fd/{}\x00", .{fd}) catch unreachable; |
| 3242 | 3270 | |
| 3243 | return readlinkC(@ptrCast([*:0]const u8, proc_path.ptr), out_buffer); | |
| 3271 | return readlinkZ(@ptrCast([*:0]const u8, proc_path.ptr), out_buffer); | |
| 3244 | 3272 | } |
| 3245 | 3273 | const result_path = std.c.realpath(pathname, out_buffer) orelse switch (std.c._errno().*) { |
| 3246 | 3274 | EINVAL => unreachable, |
| ... | ... | @@ -3255,7 +3283,7 @@ pub fn realpathC(pathname: [*:0]const u8, out_buffer: *[MAX_PATH_BYTES]u8) RealP |
| 3255 | 3283 | EIO => return error.InputOutput, |
| 3256 | 3284 | else => |err| return unexpectedErrno(@intCast(usize, err)), |
| 3257 | 3285 | }; |
| 3258 | return mem.toSlice(u8, result_path); | |
| 3286 | return mem.spanZ(result_path); | |
| 3259 | 3287 | } |
| 3260 | 3288 | |
| 3261 | 3289 | /// Same as `realpath` except `pathname` is null-terminated and UTF16LE-encoded. |
| ... | ... | @@ -3564,7 +3592,7 @@ pub const GetHostNameError = error{PermissionDenied} || UnexpectedError; |
| 3564 | 3592 | pub fn gethostname(name_buffer: *[HOST_NAME_MAX]u8) GetHostNameError![]u8 { |
| 3565 | 3593 | if (builtin.link_libc) { |
| 3566 | 3594 | 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)), | |
| 3568 | 3596 | EFAULT => unreachable, |
| 3569 | 3597 | ENAMETOOLONG => unreachable, // HOST_NAME_MAX prevents this |
| 3570 | 3598 | EPERM => return error.PermissionDenied, |
| ... | ... | @@ -3573,7 +3601,7 @@ pub fn gethostname(name_buffer: *[HOST_NAME_MAX]u8) GetHostNameError![]u8 { |
| 3573 | 3601 | } |
| 3574 | 3602 | if (builtin.os.tag == .linux) { |
| 3575 | 3603 | 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)); | |
| 3577 | 3605 | mem.copy(u8, name_buffer, hostname); |
| 3578 | 3606 | return name_buffer[0..hostname.len]; |
| 3579 | 3607 | } |
| ... | ... | @@ -4260,7 +4288,9 @@ pub const MemFdCreateError = error{ |
| 4260 | 4288 | SystemOutdated, |
| 4261 | 4289 | } || UnexpectedError; |
| 4262 | 4290 | |
| 4263 | pub fn memfd_createC(name: [*:0]const u8, flags: u32) MemFdCreateError!fd_t { | |
| 4291 | pub const memfd_createC = @compileError("deprecated: renamed to memfd_createZ"); | |
| 4292 | ||
| 4293 | pub fn memfd_createZ(name: [*:0]const u8, flags: u32) MemFdCreateError!fd_t { | |
| 4264 | 4294 | // memfd_create is available only in glibc versions starting with 2.27. |
| 4265 | 4295 | const use_c = std.c.versionCheck(.{ .major = 2, .minor = 27, .patch = 0 }).ok; |
| 4266 | 4296 | const sys = if (use_c) std.c else linux; |
| ... | ... | @@ -4291,7 +4321,7 @@ fn toMemFdPath(name: []const u8) ![MFD_MAX_NAME_LEN:0]u8 { |
| 4291 | 4321 | |
| 4292 | 4322 | pub fn memfd_create(name: []const u8, flags: u32) !fd_t { |
| 4293 | 4323 | const name_t = try toMemFdPath(name); |
| 4294 | return memfd_createC(&name_t, flags); | |
| 4324 | return memfd_createZ(&name_t, flags); | |
| 4295 | 4325 | } |
| 4296 | 4326 | |
| 4297 | 4327 | pub 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 { |
| 22 | 22 | }) { |
| 23 | 23 | const this_ph = @intToPtr(*elf.Phdr, ph_addr); |
| 24 | 24 | 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 | |
| 26 | 26 | // of the memory space (e.g. p_vaddr = 0xffffffffff700000 on WSL1). |
| 27 | 27 | // Wrapping operations are used on this line as well as subsequent calculations relative to base |
| 28 | 28 | // (lines 47, 78) to ensure no overflow check is tripped. |
| ... | ... | @@ -70,7 +70,7 @@ pub fn lookup(vername: []const u8, name: []const u8) usize { |
| 70 | 70 | if (0 == (@as(u32, 1) << @intCast(u5, syms[i].st_info >> 4) & OK_BINDS)) continue; |
| 71 | 71 | if (0 == syms[i].st_shndx) continue; |
| 72 | 72 | 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; | |
| 74 | 74 | if (maybe_versym) |versym| { |
| 75 | 75 | if (!checkver(maybe_verdef.?, versym[i], vername, strings)) |
| 76 | 76 | continue; |
| ... | ... | @@ -93,5 +93,5 @@ fn checkver(def_arg: *elf.Verdef, vsym_arg: i32, vername: []const u8, strings: [ |
| 93 | 93 | } |
| 94 | 94 | const aux = @intToPtr(*elf.Verdaux, @ptrToInt(def) + def.vd_aux); |
| 95 | 95 | 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)); | |
| 97 | 97 | } |
lib/std/os/test.zig+8-8| ... | ... | @@ -18,8 +18,8 @@ const AtomicOrder = builtin.AtomicOrder; |
| 18 | 18 | |
| 19 | 19 | test "makePath, put some files in it, deleteTree" { |
| 20 | 20 | 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"); | |
| 23 | 23 | try fs.cwd().deleteTree("os_test_tmp"); |
| 24 | 24 | if (fs.cwd().openDir("os_test_tmp", .{})) |dir| { |
| 25 | 25 | @panic("expected error"); |
| ... | ... | @@ -36,8 +36,8 @@ test "access file" { |
| 36 | 36 | expect(err == error.FileNotFound); |
| 37 | 37 | } |
| 38 | 38 | |
| 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", .{}); | |
| 41 | 41 | try fs.cwd().deleteTree("os_test_tmp"); |
| 42 | 42 | } |
| 43 | 43 | |
| ... | ... | @@ -65,12 +65,12 @@ test "sendfile" { |
| 65 | 65 | }, |
| 66 | 66 | }; |
| 67 | 67 | |
| 68 | var src_file = try dir.createFileC("sendfile1.txt", .{ .read = true }); | |
| 68 | var src_file = try dir.createFileZ("sendfile1.txt", .{ .read = true }); | |
| 69 | 69 | defer src_file.close(); |
| 70 | 70 | |
| 71 | 71 | try src_file.writevAll(&vecs); |
| 72 | 72 | |
| 73 | var dest_file = try dir.createFileC("sendfile2.txt", .{ .read = true }); | |
| 73 | var dest_file = try dir.createFileZ("sendfile2.txt", .{ .read = true }); | |
| 74 | 74 | defer dest_file.close(); |
| 75 | 75 | |
| 76 | 76 | const header1 = "header1\n"; |
| ... | ... | @@ -192,12 +192,12 @@ test "AtomicFile" { |
| 192 | 192 | \\ this is a test file |
| 193 | 193 | ; |
| 194 | 194 | { |
| 195 | var af = try fs.AtomicFile.init(test_out_file, File.default_mode); | |
| 195 | var af = try fs.cwd().atomicFile(test_out_file, .{}); | |
| 196 | 196 | defer af.deinit(); |
| 197 | 197 | try af.file.writeAll(test_content); |
| 198 | 198 | try af.finish(); |
| 199 | 199 | } |
| 200 | const content = try io.readFileAlloc(testing.allocator, test_out_file); | |
| 200 | const content = try fs.cwd().readFileAlloc(testing.allocator, test_out_file, 9999); | |
| 201 | 201 | defer testing.allocator.free(content); |
| 202 | 202 | expect(mem.eql(u8, content, test_content)); |
| 203 | 203 |
lib/std/os/windows.zig+3-3| ... | ... | @@ -118,7 +118,7 @@ pub fn OpenFileW( |
| 118 | 118 | |
| 119 | 119 | var result: HANDLE = undefined; |
| 120 | 120 | |
| 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) { | |
| 122 | 122 | error.Overflow => return error.NameTooLong, |
| 123 | 123 | }; |
| 124 | 124 | var nt_name = UNICODE_STRING{ |
| ... | ... | @@ -685,7 +685,7 @@ pub fn CreateDirectoryW( |
| 685 | 685 | sub_path_w: [*:0]const u16, |
| 686 | 686 | sa: ?*SECURITY_ATTRIBUTES, |
| 687 | 687 | ) 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) { | |
| 689 | 689 | error.Overflow => return error.NameTooLong, |
| 690 | 690 | }; |
| 691 | 691 | var nt_name = UNICODE_STRING{ |
| ... | ... | @@ -1214,7 +1214,7 @@ pub fn nanoSecondsToFileTime(ns: i64) FILETIME { |
| 1214 | 1214 | } |
| 1215 | 1215 | |
| 1216 | 1216 | pub fn cStrToPrefixedFileW(s: [*:0]const u8) ![PATH_MAX_WIDE:0]u16 { |
| 1217 | return sliceToPrefixedFileW(mem.toSliceConst(u8, s)); | |
| 1217 | return sliceToPrefixedFileW(mem.spanZ(s)); | |
| 1218 | 1218 | } |
| 1219 | 1219 | |
| 1220 | 1220 | pub fn sliceToPrefixedFileW(s: []const u8) ![PATH_MAX_WIDE:0]u16 { |
lib/std/pdb.zig+1-1| ... | ... | @@ -649,7 +649,7 @@ const MsfStream = struct { |
| 649 | 649 | while (true) { |
| 650 | 650 | const byte = try self.inStream().readByte(); |
| 651 | 651 | if (byte == 0) { |
| 652 | return list.toSlice(); | |
| 652 | return list.span(); | |
| 653 | 653 | } |
| 654 | 654 | try list.append(byte); |
| 655 | 655 | } |
lib/std/process.zig+7-7| ... | ... | @@ -83,7 +83,7 @@ pub fn getEnvMap(allocator: *Allocator) !BufMap { |
| 83 | 83 | |
| 84 | 84 | for (environ) |env| { |
| 85 | 85 | if (env) |ptr| { |
| 86 | const pair = mem.toSlice(u8, ptr); | |
| 86 | const pair = mem.spanZ(ptr); | |
| 87 | 87 | var parts = mem.separate(pair, "="); |
| 88 | 88 | const key = parts.next().?; |
| 89 | 89 | const value = parts.next().?; |
| ... | ... | @@ -176,7 +176,7 @@ pub const ArgIteratorPosix = struct { |
| 176 | 176 | |
| 177 | 177 | const s = os.argv[self.index]; |
| 178 | 178 | self.index += 1; |
| 179 | return mem.toSlice(u8, s); | |
| 179 | return mem.spanZ(s); | |
| 180 | 180 | } |
| 181 | 181 | |
| 182 | 182 | pub fn skip(self: *ArgIteratorPosix) bool { |
| ... | ... | @@ -401,7 +401,7 @@ pub fn argsAlloc(allocator: *mem.Allocator) ![][]u8 { |
| 401 | 401 | |
| 402 | 402 | var i: usize = 0; |
| 403 | 403 | while (i < count) : (i += 1) { |
| 404 | result_slice[i] = mem.toSlice(u8, argv[i]); | |
| 404 | result_slice[i] = mem.spanZ(argv[i]); | |
| 405 | 405 | } |
| 406 | 406 | |
| 407 | 407 | return result_slice; |
| ... | ... | @@ -422,8 +422,8 @@ pub fn argsAlloc(allocator: *mem.Allocator) ![][]u8 { |
| 422 | 422 | try slice_list.append(arg.len); |
| 423 | 423 | } |
| 424 | 424 | |
| 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(); | |
| 427 | 427 | const slice_list_bytes = try math.mul(usize, @sizeOf([]u8), slice_sizes.len); |
| 428 | 428 | const total_bytes = try math.add(usize, slice_list_bytes, contents_slice.len); |
| 429 | 429 | const buf = try allocator.alignedAlloc(u8, @alignOf([]u8), total_bytes); |
| ... | ... | @@ -636,7 +636,7 @@ pub fn getSelfExeSharedLibPaths(allocator: *Allocator) error{OutOfMemory}![][:0] |
| 636 | 636 | fn callback(info: *os.dl_phdr_info, size: usize, list: *List) !void { |
| 637 | 637 | const name = info.dlpi_name orelse return; |
| 638 | 638 | 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)); | |
| 640 | 640 | errdefer list.allocator.free(item); |
| 641 | 641 | try list.append(item); |
| 642 | 642 | } |
| ... | ... | @@ -657,7 +657,7 @@ pub fn getSelfExeSharedLibPaths(allocator: *Allocator) error{OutOfMemory}![][:0] |
| 657 | 657 | var i: u32 = 0; |
| 658 | 658 | while (i < img_count) : (i += 1) { |
| 659 | 659 | 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)); | |
| 661 | 661 | errdefer allocator.free(item); |
| 662 | 662 | try paths.append(item); |
| 663 | 663 | } |
lib/std/rand.zig+13-19| ... | ... | @@ -59,7 +59,7 @@ pub const Random = struct { |
| 59 | 59 | return @bitCast(T, unsigned_result); |
| 60 | 60 | } |
| 61 | 61 | |
| 62 | /// Constant-time implementation off ::uintLessThan. | |
| 62 | /// Constant-time implementation off `uintLessThan`. | |
| 63 | 63 | /// The results of this function may be biased. |
| 64 | 64 | pub fn uintLessThanBiased(r: *Random, comptime T: type, less_than: T) T { |
| 65 | 65 | comptime assert(T.is_signed == false); |
| ... | ... | @@ -73,13 +73,13 @@ pub const Random = struct { |
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | /// 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. | |
| 77 | 77 | /// 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, | |
| 79 | 79 | /// 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, | |
| 81 | 81 | /// this function is guaranteed to return. |
| 82 | /// If you need deterministic runtime bounds, use `::uintLessThanBiased`. | |
| 82 | /// If you need deterministic runtime bounds, use `uintLessThanBiased`. | |
| 83 | 83 | pub fn uintLessThan(r: *Random, comptime T: type, less_than: T) T { |
| 84 | 84 | comptime assert(T.is_signed == false); |
| 85 | 85 | comptime assert(T.bit_count <= 64); // TODO: workaround: LLVM ERROR: Unsupported library call operation! |
| ... | ... | @@ -116,7 +116,7 @@ pub const Random = struct { |
| 116 | 116 | return @intCast(T, m >> Small.bit_count); |
| 117 | 117 | } |
| 118 | 118 | |
| 119 | /// Constant-time implementation off ::uintAtMost. | |
| 119 | /// Constant-time implementation off `uintAtMost`. | |
| 120 | 120 | /// The results of this function may be biased. |
| 121 | 121 | pub fn uintAtMostBiased(r: *Random, comptime T: type, at_most: T) T { |
| 122 | 122 | assert(T.is_signed == false); |
| ... | ... | @@ -128,7 +128,7 @@ pub const Random = struct { |
| 128 | 128 | } |
| 129 | 129 | |
| 130 | 130 | /// 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, | |
| 132 | 132 | /// for commentary on the runtime of this function. |
| 133 | 133 | pub fn uintAtMost(r: *Random, comptime T: type, at_most: T) T { |
| 134 | 134 | assert(T.is_signed == false); |
| ... | ... | @@ -139,7 +139,7 @@ pub const Random = struct { |
| 139 | 139 | return r.uintLessThan(T, at_most + 1); |
| 140 | 140 | } |
| 141 | 141 | |
| 142 | /// Constant-time implementation off ::intRangeLessThan. | |
| 142 | /// Constant-time implementation off `intRangeLessThan`. | |
| 143 | 143 | /// The results of this function may be biased. |
| 144 | 144 | pub fn intRangeLessThanBiased(r: *Random, comptime T: type, at_least: T, less_than: T) T { |
| 145 | 145 | assert(at_least < less_than); |
| ... | ... | @@ -157,7 +157,7 @@ pub const Random = struct { |
| 157 | 157 | } |
| 158 | 158 | |
| 159 | 159 | /// 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, | |
| 161 | 161 | /// for commentary on the runtime of this function. |
| 162 | 162 | pub fn intRangeLessThan(r: *Random, comptime T: type, at_least: T, less_than: T) T { |
| 163 | 163 | assert(at_least < less_than); |
| ... | ... | @@ -174,7 +174,7 @@ pub const Random = struct { |
| 174 | 174 | } |
| 175 | 175 | } |
| 176 | 176 | |
| 177 | /// Constant-time implementation off ::intRangeAtMostBiased. | |
| 177 | /// Constant-time implementation off `intRangeAtMostBiased`. | |
| 178 | 178 | /// The results of this function may be biased. |
| 179 | 179 | pub fn intRangeAtMostBiased(r: *Random, comptime T: type, at_least: T, at_most: T) T { |
| 180 | 180 | assert(at_least <= at_most); |
| ... | ... | @@ -192,7 +192,7 @@ pub const Random = struct { |
| 192 | 192 | } |
| 193 | 193 | |
| 194 | 194 | /// 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, | |
| 196 | 196 | /// for commentary on the runtime of this function. |
| 197 | 197 | pub fn intRangeAtMost(r: *Random, comptime T: type, at_least: T, at_most: T) T { |
| 198 | 198 | assert(at_least <= at_most); |
| ... | ... | @@ -209,15 +209,9 @@ pub const Random = struct { |
| 209 | 209 | } |
| 210 | 210 | } |
| 211 | 211 | |
| 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"); | |
| 216 | 213 | |
| 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()"); | |
| 221 | 215 | |
| 222 | 216 | /// Return a floating point value evenly distributed in the range [0, 1). |
| 223 | 217 | pub fn float(r: *Random, comptime T: type) T { |
lib/std/sort.zig+2-2| ... | ... | @@ -1227,13 +1227,13 @@ test "sort fuzz testing" { |
| 1227 | 1227 | var fixed_buffer_mem: [100 * 1024]u8 = undefined; |
| 1228 | 1228 | |
| 1229 | 1229 | fn fuzzTest(rng: *std.rand.Random) !void { |
| 1230 | const array_size = rng.range(usize, 0, 1000); | |
| 1230 | const array_size = rng.intRangeLessThan(usize, 0, 1000); | |
| 1231 | 1231 | var array = try testing.allocator.alloc(IdAndValue, array_size); |
| 1232 | 1232 | defer testing.allocator.free(array); |
| 1233 | 1233 | // populate with random data |
| 1234 | 1234 | for (array) |*item, index| { |
| 1235 | 1235 | item.id = index; |
| 1236 | item.value = rng.range(i32, 0, 100); | |
| 1236 | item.value = rng.intRangeLessThan(i32, 0, 100); | |
| 1237 | 1237 | } |
| 1238 | 1238 | sort(IdAndValue, array, cmpByValue); |
| 1239 | 1239 |
lib/std/special/build_runner.zig+3-3| ... | ... | @@ -116,7 +116,7 @@ pub fn main() !void { |
| 116 | 116 | if (builder.validateUserInputDidItFail()) |
| 117 | 117 | return usageAndErr(builder, true, stderr_stream); |
| 118 | 118 | |
| 119 | builder.make(targets.toSliceConst()) catch |err| { | |
| 119 | builder.make(targets.span()) catch |err| { | |
| 120 | 120 | switch (err) { |
| 121 | 121 | error.InvalidStepName => { |
| 122 | 122 | return usageAndErr(builder, true, stderr_stream); |
| ... | ... | @@ -151,7 +151,7 @@ fn usage(builder: *Builder, already_ran_build: bool, out_stream: var) !void { |
| 151 | 151 | , .{builder.zig_exe}); |
| 152 | 152 | |
| 153 | 153 | const allocator = builder.allocator; |
| 154 | for (builder.top_level_steps.toSliceConst()) |top_level_step| { | |
| 154 | for (builder.top_level_steps.span()) |top_level_step| { | |
| 155 | 155 | const name = if (&top_level_step.step == builder.default_step) |
| 156 | 156 | try fmt.allocPrint(allocator, "{} (default)", .{top_level_step.step.name}) |
| 157 | 157 | else |
| ... | ... | @@ -174,7 +174,7 @@ fn usage(builder: *Builder, already_ran_build: bool, out_stream: var) !void { |
| 174 | 174 | if (builder.available_options_list.len == 0) { |
| 175 | 175 | try out_stream.print(" (none)\n", .{}); |
| 176 | 176 | } else { |
| 177 | for (builder.available_options_list.toSliceConst()) |option| { | |
| 177 | for (builder.available_options_list.span()) |option| { | |
| 178 | 178 | const name = try fmt.allocPrint(allocator, " -D{}=[{}]", .{ |
| 179 | 179 | option.name, |
| 180 | 180 | Builder.typeIdName(option.type_id), |
lib/std/thread.zig+1-1| ... | ... | @@ -464,7 +464,7 @@ pub const Thread = struct { |
| 464 | 464 | var count: c_int = undefined; |
| 465 | 465 | var count_len: usize = @sizeOf(c_int); |
| 466 | 466 | 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) { | |
| 468 | 468 | error.NameTooLong, error.UnknownName => unreachable, |
| 469 | 469 | else => |e| return e, |
| 470 | 470 | }; |
lib/std/zig/render.zig+1-1| ... | ... | @@ -1531,7 +1531,7 @@ fn renderExpression( |
| 1531 | 1531 | try renderToken(tree, stream, callconv_rparen, indent, start_col, Space.Space); // ) |
| 1532 | 1532 | } else if (cc_rewrite_str) |str| { |
| 1533 | 1533 | try stream.writeAll("callconv("); |
| 1534 | try stream.writeAll(mem.toSliceConst(u8, str)); | |
| 1534 | try stream.writeAll(mem.spanZ(str)); | |
| 1535 | 1535 | try stream.writeAll(") "); |
| 1536 | 1536 | } |
| 1537 | 1537 |
lib/std/zig/system.zig+8-8| ... | ... | @@ -119,7 +119,7 @@ pub const NativePaths = struct { |
| 119 | 119 | } |
| 120 | 120 | |
| 121 | 121 | fn deinitArray(array: *ArrayList([:0]u8)) void { |
| 122 | for (array.toSlice()) |item| { | |
| 122 | for (array.span()) |item| { | |
| 123 | 123 | array.allocator.free(item); |
| 124 | 124 | } |
| 125 | 125 | array.deinit(); |
| ... | ... | @@ -201,7 +201,7 @@ pub const NativeTargetInfo = struct { |
| 201 | 201 | switch (Target.current.os.tag) { |
| 202 | 202 | .linux => { |
| 203 | 203 | const uts = std.os.uname(); |
| 204 | const release = mem.toSliceConst(u8, &uts.release); | |
| 204 | const release = mem.spanZ(&uts.release); | |
| 205 | 205 | // The release field may have several other fields after the |
| 206 | 206 | // kernel version |
| 207 | 207 | const kernel_version = if (mem.indexOfScalar(u8, release, '-')) |pos| |
| ... | ... | @@ -265,7 +265,7 @@ pub const NativeTargetInfo = struct { |
| 265 | 265 | // The osproductversion sysctl was introduced first with |
| 266 | 266 | // High Sierra, thankfully that's also the baseline that Zig |
| 267 | 267 | // supports |
| 268 | std.os.sysctlbynameC( | |
| 268 | std.os.sysctlbynameZ( | |
| 269 | 269 | "kern.osproductversion", |
| 270 | 270 | &product_version, |
| 271 | 271 | &size, |
| ... | ... | @@ -460,7 +460,7 @@ pub const NativeTargetInfo = struct { |
| 460 | 460 | return result; |
| 461 | 461 | } |
| 462 | 462 | |
| 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) { | |
| 464 | 464 | error.NoSpaceLeft => unreachable, |
| 465 | 465 | error.NameTooLong => unreachable, |
| 466 | 466 | error.PathAlreadyExists => unreachable, |
| ... | ... | @@ -512,7 +512,7 @@ pub const NativeTargetInfo = struct { |
| 512 | 512 | |
| 513 | 513 | fn glibcVerFromSO(so_path: [:0]const u8) !std.builtin.Version { |
| 514 | 514 | 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) { | |
| 516 | 516 | error.AccessDenied => return error.GnuLibCVersionUnavailable, |
| 517 | 517 | error.FileSystem => return error.FileSystem, |
| 518 | 518 | error.SymLinkLoop => return error.SymLinkLoop, |
| ... | ... | @@ -736,7 +736,7 @@ pub const NativeTargetInfo = struct { |
| 736 | 736 | ); |
| 737 | 737 | const sh_name_off = elfInt(is_64, need_bswap, sh32.sh_name, sh64.sh_name); |
| 738 | 738 | // 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)); | |
| 740 | 740 | if (mem.eql(u8, sh_name, ".dynstr")) { |
| 741 | 741 | break :find_dyn_str .{ |
| 742 | 742 | .offset = elfInt(is_64, need_bswap, sh32.sh_offset, sh64.sh_offset), |
| ... | ... | @@ -751,7 +751,7 @@ pub const NativeTargetInfo = struct { |
| 751 | 751 | const strtab_read_len = try preadMin(file, &strtab_buf, ds.offset, shstrtab_len); |
| 752 | 752 | const strtab = strtab_buf[0..strtab_read_len]; |
| 753 | 753 | // 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)); | |
| 755 | 755 | var it = mem.tokenize(rpath_list, ":"); |
| 756 | 756 | while (it.next()) |rpath| { |
| 757 | 757 | var dir = fs.cwd().openDir(rpath, .{}) catch |err| switch (err) { |
| ... | ... | @@ -776,7 +776,7 @@ pub const NativeTargetInfo = struct { |
| 776 | 776 | defer dir.close(); |
| 777 | 777 | |
| 778 | 778 | var link_buf: [std.os.PATH_MAX]u8 = undefined; |
| 779 | const link_name = std.os.readlinkatC( | |
| 779 | const link_name = std.os.readlinkatZ( | |
| 780 | 780 | dir.fd, |
| 781 | 781 | glibc_so_basename, |
| 782 | 782 | &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) |
| 25 | 25 | |
| 26 | 26 | const context = llvm_handle.node.data; |
| 27 | 27 | |
| 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; | |
| 29 | 29 | defer llvm.DisposeModule(module); |
| 30 | 30 | |
| 31 | llvm.SetTarget(module, comp.llvm_triple.toSliceConst()); | |
| 31 | llvm.SetTarget(module, comp.llvm_triple.span()); | |
| 32 | 32 | llvm.SetDataLayout(module, comp.target_layout_str); |
| 33 | 33 | |
| 34 | 34 | if (comp.target.getObjectFormat() == .coff) { |
| ... | ... | @@ -54,15 +54,15 @@ pub async fn renderToLlvm(comp: *Compilation, fn_val: *Value.Fn, code: *ir.Code) |
| 54 | 54 | const runtime_version = 0; |
| 55 | 55 | const compile_unit_file = llvm.CreateFile( |
| 56 | 56 | 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(), | |
| 59 | 59 | ) orelse return error.OutOfMemory; |
| 60 | 60 | const is_optimized = comp.build_mode != .Debug; |
| 61 | 61 | const compile_unit = llvm.CreateCompileUnit( |
| 62 | 62 | dibuilder, |
| 63 | 63 | DW.LANG_C99, |
| 64 | 64 | compile_unit_file, |
| 65 | producer.toSliceConst(), | |
| 65 | producer.span(), | |
| 66 | 66 | is_optimized, |
| 67 | 67 | flags, |
| 68 | 68 | runtime_version, |
| ... | ... | @@ -109,14 +109,14 @@ pub async fn renderToLlvm(comp: *Compilation, fn_val: *Value.Fn, code: *ir.Code) |
| 109 | 109 | if (llvm.TargetMachineEmitToFile( |
| 110 | 110 | comp.target_machine, |
| 111 | 111 | module, |
| 112 | output_path.toSliceConst(), | |
| 112 | output_path.span(), | |
| 113 | 113 | llvm.EmitBinary, |
| 114 | 114 | &err_msg, |
| 115 | 115 | is_debug, |
| 116 | 116 | is_small, |
| 117 | 117 | )) { |
| 118 | 118 | 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 }); | |
| 120 | 120 | } |
| 121 | 121 | return error.WritingObjectFileFailed; |
| 122 | 122 | } |
| ... | ... | @@ -127,7 +127,7 @@ pub async fn renderToLlvm(comp: *Compilation, fn_val: *Value.Fn, code: *ir.Code) |
| 127 | 127 | llvm.DumpModule(ofile.module); |
| 128 | 128 | } |
| 129 | 129 | if (comp.verbose_link) { |
| 130 | std.debug.warn("created {}\n", .{output_path.toSliceConst()}); | |
| 130 | std.debug.warn("created {}\n", .{output_path.span()}); | |
| 131 | 131 | } |
| 132 | 132 | } |
| 133 | 133 | |
| ... | ... | @@ -150,7 +150,7 @@ pub fn renderToLlvmModule(ofile: *ObjectFile, fn_val: *Value.Fn, code: *ir.Code) |
| 150 | 150 | const llvm_fn_type = try fn_val.base.typ.getLlvmType(ofile.arena, ofile.context); |
| 151 | 151 | const llvm_fn = llvm.AddFunction( |
| 152 | 152 | ofile.module, |
| 153 | fn_val.symbol_name.toSliceConst(), | |
| 153 | fn_val.symbol_name.span(), | |
| 154 | 154 | llvm_fn_type, |
| 155 | 155 | ) orelse return error.OutOfMemory; |
| 156 | 156 | |
| ... | ... | @@ -211,7 +211,7 @@ pub fn renderToLlvmModule(ofile: *ObjectFile, fn_val: *Value.Fn, code: *ir.Code) |
| 211 | 211 | const cur_ret_ptr = if (fn_type_normal.return_type.handleIsPtr()) llvm.GetParam(llvm_fn, 0) else null; |
| 212 | 212 | |
| 213 | 213 | // build all basic blocks |
| 214 | for (code.basic_block_list.toSlice()) |bb| { | |
| 214 | for (code.basic_block_list.span()) |bb| { | |
| 215 | 215 | bb.llvm_block = llvm.AppendBasicBlockInContext( |
| 216 | 216 | ofile.context, |
| 217 | 217 | llvm_fn, |
| ... | ... | @@ -226,7 +226,7 @@ pub fn renderToLlvmModule(ofile: *ObjectFile, fn_val: *Value.Fn, code: *ir.Code) |
| 226 | 226 | // TODO set up error return tracing |
| 227 | 227 | // TODO allocate temporary stack values |
| 228 | 228 | |
| 229 | const var_list = fn_type.non_key.Normal.variable_list.toSliceConst(); | |
| 229 | const var_list = fn_type.non_key.Normal.variable_list.span(); | |
| 230 | 230 | // create debug variable declarations for variables and allocate all local variables |
| 231 | 231 | for (var_list) |var_scope, i| { |
| 232 | 232 | const var_type = switch (var_scope.data) { |
| ... | ... | @@ -306,9 +306,9 @@ pub fn renderToLlvmModule(ofile: *ObjectFile, fn_val: *Value.Fn, code: *ir.Code) |
| 306 | 306 | //} |
| 307 | 307 | } |
| 308 | 308 | |
| 309 | for (code.basic_block_list.toSlice()) |current_block| { | |
| 309 | for (code.basic_block_list.span()) |current_block| { | |
| 310 | 310 | llvm.PositionBuilderAtEnd(ofile.builder, current_block.llvm_block); |
| 311 | for (current_block.instruction_list.toSlice()) |instruction| { | |
| 311 | for (current_block.instruction_list.span()) |instruction| { | |
| 312 | 312 | if (instruction.ref_count == 0 and !instruction.hasSideEffects()) continue; |
| 313 | 313 | |
| 314 | 314 | instruction.llvm_value = try instruction.render(ofile, fn_val); |
src-self-hosted/compilation.zig+3-3| ... | ... | @@ -465,7 +465,7 @@ pub const Compilation = struct { |
| 465 | 465 | |
| 466 | 466 | comp.target_machine = llvm.CreateTargetMachine( |
| 467 | 467 | comp.llvm_target, |
| 468 | comp.llvm_triple.toSliceConst(), | |
| 468 | comp.llvm_triple.span(), | |
| 469 | 469 | target_specific_cpu_args orelse "", |
| 470 | 470 | target_specific_cpu_features orelse "", |
| 471 | 471 | opt_level, |
| ... | ... | @@ -1106,7 +1106,7 @@ pub const Compilation = struct { |
| 1106 | 1106 | } |
| 1107 | 1107 | } |
| 1108 | 1108 | |
| 1109 | for (self.link_libs_list.toSliceConst()) |existing_lib| { | |
| 1109 | for (self.link_libs_list.span()) |existing_lib| { | |
| 1110 | 1110 | if (mem.eql(u8, name, existing_lib.name)) { |
| 1111 | 1111 | return existing_lib; |
| 1112 | 1112 | } |
| ... | ... | @@ -1371,7 +1371,7 @@ fn analyzeFnType( |
| 1371 | 1371 | var params = ArrayList(Type.Fn.Param).init(comp.gpa()); |
| 1372 | 1372 | var params_consumed = false; |
| 1373 | 1373 | defer if (!params_consumed) { |
| 1374 | for (params.toSliceConst()) |param| { | |
| 1374 | for (params.span()) |param| { | |
| 1375 | 1375 | param.typ.base.deref(comp); |
| 1376 | 1376 | } |
| 1377 | 1377 | params.deinit(); |
src-self-hosted/dep_tokenizer.zig+19-19| ... | ... | @@ -89,7 +89,7 @@ pub const Tokenizer = struct { |
| 89 | 89 | }, |
| 90 | 90 | .target_colon => |*target| switch (char) { |
| 91 | 91 | '\n', '\r' => { |
| 92 | const bytes = target.toSlice(); | |
| 92 | const bytes = target.span(); | |
| 93 | 93 | if (bytes.len != 0) { |
| 94 | 94 | self.state = State{ .lhs = {} }; |
| 95 | 95 | return Token{ .id = .target, .bytes = bytes }; |
| ... | ... | @@ -103,7 +103,7 @@ pub const Tokenizer = struct { |
| 103 | 103 | break; // advance |
| 104 | 104 | }, |
| 105 | 105 | else => { |
| 106 | const bytes = target.toSlice(); | |
| 106 | const bytes = target.span(); | |
| 107 | 107 | if (bytes.len != 0) { |
| 108 | 108 | self.state = State{ .rhs = {} }; |
| 109 | 109 | return Token{ .id = .target, .bytes = bytes }; |
| ... | ... | @@ -115,7 +115,7 @@ pub const Tokenizer = struct { |
| 115 | 115 | }, |
| 116 | 116 | .target_colon_reverse_solidus => |*target| switch (char) { |
| 117 | 117 | '\n', '\r' => { |
| 118 | const bytes = target.toSlice(); | |
| 118 | const bytes = target.span(); | |
| 119 | 119 | if (bytes.len != 0) { |
| 120 | 120 | self.state = State{ .lhs = {} }; |
| 121 | 121 | return Token{ .id = .target, .bytes = bytes }; |
| ... | ... | @@ -175,7 +175,7 @@ pub const Tokenizer = struct { |
| 175 | 175 | }, |
| 176 | 176 | .prereq_quote => |*prereq| switch (char) { |
| 177 | 177 | '"' => { |
| 178 | const bytes = prereq.toSlice(); | |
| 178 | const bytes = prereq.span(); | |
| 179 | 179 | self.index += 1; |
| 180 | 180 | self.state = State{ .rhs = {} }; |
| 181 | 181 | return Token{ .id = .prereq, .bytes = bytes }; |
| ... | ... | @@ -187,12 +187,12 @@ pub const Tokenizer = struct { |
| 187 | 187 | }, |
| 188 | 188 | .prereq => |*prereq| switch (char) { |
| 189 | 189 | '\t', ' ' => { |
| 190 | const bytes = prereq.toSlice(); | |
| 190 | const bytes = prereq.span(); | |
| 191 | 191 | self.state = State{ .rhs = {} }; |
| 192 | 192 | return Token{ .id = .prereq, .bytes = bytes }; |
| 193 | 193 | }, |
| 194 | 194 | '\n', '\r' => { |
| 195 | const bytes = prereq.toSlice(); | |
| 195 | const bytes = prereq.span(); | |
| 196 | 196 | self.state = State{ .lhs = {} }; |
| 197 | 197 | return Token{ .id = .prereq, .bytes = bytes }; |
| 198 | 198 | }, |
| ... | ... | @@ -207,7 +207,7 @@ pub const Tokenizer = struct { |
| 207 | 207 | }, |
| 208 | 208 | .prereq_continuation => |*prereq| switch (char) { |
| 209 | 209 | '\n' => { |
| 210 | const bytes = prereq.toSlice(); | |
| 210 | const bytes = prereq.span(); | |
| 211 | 211 | self.index += 1; |
| 212 | 212 | self.state = State{ .rhs = {} }; |
| 213 | 213 | return Token{ .id = .prereq, .bytes = bytes }; |
| ... | ... | @@ -225,7 +225,7 @@ pub const Tokenizer = struct { |
| 225 | 225 | }, |
| 226 | 226 | .prereq_continuation_linefeed => |prereq| switch (char) { |
| 227 | 227 | '\n' => { |
| 228 | const bytes = prereq.toSlice(); | |
| 228 | const bytes = prereq.span(); | |
| 229 | 229 | self.index += 1; |
| 230 | 230 | self.state = State{ .rhs = {} }; |
| 231 | 231 | return Token{ .id = .prereq, .bytes = bytes }; |
| ... | ... | @@ -249,7 +249,7 @@ pub const Tokenizer = struct { |
| 249 | 249 | .rhs_continuation_linefeed, |
| 250 | 250 | => {}, |
| 251 | 251 | .target => |target| { |
| 252 | return self.errorPosition(idx, target.toSlice(), "incomplete target", .{}); | |
| 252 | return self.errorPosition(idx, target.span(), "incomplete target", .{}); | |
| 253 | 253 | }, |
| 254 | 254 | .target_reverse_solidus, |
| 255 | 255 | .target_dollar_sign, |
| ... | ... | @@ -258,7 +258,7 @@ pub const Tokenizer = struct { |
| 258 | 258 | return self.errorIllegalChar(idx, self.bytes[idx], "incomplete escape", .{}); |
| 259 | 259 | }, |
| 260 | 260 | .target_colon => |target| { |
| 261 | const bytes = target.toSlice(); | |
| 261 | const bytes = target.span(); | |
| 262 | 262 | if (bytes.len != 0) { |
| 263 | 263 | self.index += 1; |
| 264 | 264 | self.state = State{ .rhs = {} }; |
| ... | ... | @@ -268,7 +268,7 @@ pub const Tokenizer = struct { |
| 268 | 268 | self.state = State{ .lhs = {} }; |
| 269 | 269 | }, |
| 270 | 270 | .target_colon_reverse_solidus => |target| { |
| 271 | const bytes = target.toSlice(); | |
| 271 | const bytes = target.span(); | |
| 272 | 272 | if (bytes.len != 0) { |
| 273 | 273 | self.index += 1; |
| 274 | 274 | self.state = State{ .rhs = {} }; |
| ... | ... | @@ -278,20 +278,20 @@ pub const Tokenizer = struct { |
| 278 | 278 | self.state = State{ .lhs = {} }; |
| 279 | 279 | }, |
| 280 | 280 | .prereq_quote => |prereq| { |
| 281 | return self.errorPosition(idx, prereq.toSlice(), "incomplete quoted prerequisite", .{}); | |
| 281 | return self.errorPosition(idx, prereq.span(), "incomplete quoted prerequisite", .{}); | |
| 282 | 282 | }, |
| 283 | 283 | .prereq => |prereq| { |
| 284 | const bytes = prereq.toSlice(); | |
| 284 | const bytes = prereq.span(); | |
| 285 | 285 | self.state = State{ .lhs = {} }; |
| 286 | 286 | return Token{ .id = .prereq, .bytes = bytes }; |
| 287 | 287 | }, |
| 288 | 288 | .prereq_continuation => |prereq| { |
| 289 | const bytes = prereq.toSlice(); | |
| 289 | const bytes = prereq.span(); | |
| 290 | 290 | self.state = State{ .lhs = {} }; |
| 291 | 291 | return Token{ .id = .prereq, .bytes = bytes }; |
| 292 | 292 | }, |
| 293 | 293 | .prereq_continuation_linefeed => |prereq| { |
| 294 | const bytes = prereq.toSlice(); | |
| 294 | const bytes = prereq.span(); | |
| 295 | 295 | self.state = State{ .lhs = {} }; |
| 296 | 296 | return Token{ .id = .prereq, .bytes = bytes }; |
| 297 | 297 | }, |
| ... | ... | @@ -300,7 +300,7 @@ pub const Tokenizer = struct { |
| 300 | 300 | } |
| 301 | 301 | |
| 302 | 302 | 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(); | |
| 304 | 304 | return Error.InvalidInput; |
| 305 | 305 | } |
| 306 | 306 | |
| ... | ... | @@ -312,7 +312,7 @@ pub const Tokenizer = struct { |
| 312 | 312 | try printCharValues(&out, bytes); |
| 313 | 313 | try buffer.append("'"); |
| 314 | 314 | try buffer.outStream().print(" at position {}", .{position - (bytes.len - 1)}); |
| 315 | self.error_text = buffer.toSlice(); | |
| 315 | self.error_text = buffer.span(); | |
| 316 | 316 | return Error.InvalidInput; |
| 317 | 317 | } |
| 318 | 318 | |
| ... | ... | @@ -322,7 +322,7 @@ pub const Tokenizer = struct { |
| 322 | 322 | try printUnderstandableChar(&buffer, char); |
| 323 | 323 | try buffer.outStream().print(" at position {}", .{position}); |
| 324 | 324 | if (fmt.len != 0) try buffer.outStream().print(": " ++ fmt, args); |
| 325 | self.error_text = buffer.toSlice(); | |
| 325 | self.error_text = buffer.span(); | |
| 326 | 326 | return Error.InvalidInput; |
| 327 | 327 | } |
| 328 | 328 | |
| ... | ... | @@ -865,7 +865,7 @@ fn depTokenizer(input: []const u8, expect: []const u8) !void { |
| 865 | 865 | try buffer.append("}"); |
| 866 | 866 | i += 1; |
| 867 | 867 | } |
| 868 | const got: []const u8 = buffer.toSlice(); | |
| 868 | const got: []const u8 = buffer.span(); | |
| 869 | 869 | |
| 870 | 870 | if (std.mem.eql(u8, expect, got)) { |
| 871 | 871 | testing.expect(true); |
src-self-hosted/ir.zig+4-4| ... | ... | @@ -965,9 +965,9 @@ pub const Code = struct { |
| 965 | 965 | |
| 966 | 966 | pub fn dump(self: *Code) void { |
| 967 | 967 | var bb_i: usize = 0; |
| 968 | for (self.basic_block_list.toSliceConst()) |bb| { | |
| 968 | for (self.basic_block_list.span()) |bb| { | |
| 969 | 969 | 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| { | |
| 971 | 971 | std.debug.warn(" ", .{}); |
| 972 | 972 | instr.dump(); |
| 973 | 973 | std.debug.warn("\n", .{}); |
| ... | ... | @@ -978,7 +978,7 @@ pub const Code = struct { |
| 978 | 978 | /// returns a ref-incremented value, or adds a compile error |
| 979 | 979 | pub fn getCompTimeResult(self: *Code, comp: *Compilation) !*Value { |
| 980 | 980 | const bb = self.basic_block_list.at(0); |
| 981 | for (bb.instruction_list.toSliceConst()) |inst| { | |
| 981 | for (bb.instruction_list.span()) |inst| { | |
| 982 | 982 | if (inst.cast(Inst.Return)) |ret_inst| { |
| 983 | 983 | const ret_value = ret_inst.params.return_value; |
| 984 | 984 | if (ret_value.isCompTime()) { |
| ... | ... | @@ -2585,6 +2585,6 @@ pub fn analyze(comp: *Compilation, old_code: *Code, expected_type: ?*Type) !*Cod |
| 2585 | 2585 | return ira.irb.finish(); |
| 2586 | 2586 | } |
| 2587 | 2587 | |
| 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()); | |
| 2589 | 2589 | return ira.irb.finish(); |
| 2590 | 2590 | } |
src-self-hosted/libc_installation.zig+7-7| ... | ... | @@ -54,7 +54,7 @@ pub const LibCInstallation = struct { |
| 54 | 54 | } |
| 55 | 55 | } |
| 56 | 56 | |
| 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)); | |
| 58 | 58 | defer allocator.free(contents); |
| 59 | 59 | |
| 60 | 60 | var it = std.mem.tokenize(contents, "\n"); |
| ... | ... | @@ -229,7 +229,7 @@ pub const LibCInstallation = struct { |
| 229 | 229 | "-xc", |
| 230 | 230 | dev_null, |
| 231 | 231 | }; |
| 232 | const exec_res = std.ChildProcess.exec2(.{ | |
| 232 | const exec_res = std.ChildProcess.exec(.{ | |
| 233 | 233 | .allocator = allocator, |
| 234 | 234 | .argv = &argv, |
| 235 | 235 | .max_output_bytes = 1024 * 1024, |
| ... | ... | @@ -335,7 +335,7 @@ pub const LibCInstallation = struct { |
| 335 | 335 | const stream = result_buf.outStream(); |
| 336 | 336 | try stream.print("{}\\Include\\{}\\ucrt", .{ search.path, search.version }); |
| 337 | 337 | |
| 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) { | |
| 339 | 339 | error.FileNotFound, |
| 340 | 340 | error.NotDir, |
| 341 | 341 | error.NoDevice, |
| ... | ... | @@ -382,7 +382,7 @@ pub const LibCInstallation = struct { |
| 382 | 382 | const stream = result_buf.outStream(); |
| 383 | 383 | try stream.print("{}\\Lib\\{}\\ucrt\\{}", .{ search.path, search.version, arch_sub_dir }); |
| 384 | 384 | |
| 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) { | |
| 386 | 386 | error.FileNotFound, |
| 387 | 387 | error.NotDir, |
| 388 | 388 | error.NoDevice, |
| ... | ... | @@ -437,7 +437,7 @@ pub const LibCInstallation = struct { |
| 437 | 437 | const stream = result_buf.outStream(); |
| 438 | 438 | try stream.print("{}\\Lib\\{}\\um\\{}", .{ search.path, search.version, arch_sub_dir }); |
| 439 | 439 | |
| 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) { | |
| 441 | 441 | error.FileNotFound, |
| 442 | 442 | error.NotDir, |
| 443 | 443 | error.NoDevice, |
| ... | ... | @@ -475,7 +475,7 @@ pub const LibCInstallation = struct { |
| 475 | 475 | |
| 476 | 476 | try result_buf.append("\\include"); |
| 477 | 477 | |
| 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) { | |
| 479 | 479 | error.FileNotFound, |
| 480 | 480 | error.NotDir, |
| 481 | 481 | error.NoDevice, |
| ... | ... | @@ -522,7 +522,7 @@ fn ccPrintFileName(args: CCPrintFileNameOptions) ![:0]u8 { |
| 522 | 522 | defer allocator.free(arg1); |
| 523 | 523 | const argv = [_][]const u8{ cc_exe, arg1 }; |
| 524 | 524 | |
| 525 | const exec_res = std.ChildProcess.exec2(.{ | |
| 525 | const exec_res = std.ChildProcess.exec(.{ | |
| 526 | 526 | .allocator = allocator, |
| 527 | 527 | .argv = &argv, |
| 528 | 528 | .max_output_bytes = 1024 * 1024, |
src-self-hosted/link.zig+9-9| ... | ... | @@ -36,7 +36,7 @@ pub fn link(comp: *Compilation) !void { |
| 36 | 36 | ctx.args = std.ArrayList([*:0]const u8).init(&ctx.arena.allocator); |
| 37 | 37 | ctx.link_msg = std.Buffer.initNull(&ctx.arena.allocator); |
| 38 | 38 | |
| 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()); | |
| 40 | 40 | switch (comp.kind) { |
| 41 | 41 | .Exe => { |
| 42 | 42 | try ctx.out_file_path.append(comp.target.exeFileExt()); |
| ... | ... | @@ -70,7 +70,7 @@ pub fn link(comp: *Compilation) !void { |
| 70 | 70 | try constructLinkerArgs(&ctx); |
| 71 | 71 | |
| 72 | 72 | if (comp.verbose_link) { |
| 73 | for (ctx.args.toSliceConst()) |arg, i| { | |
| 73 | for (ctx.args.span()) |arg, i| { | |
| 74 | 74 | const space = if (i == 0) "" else " "; |
| 75 | 75 | std.debug.warn("{}{s}", .{ space, arg }); |
| 76 | 76 | } |
| ... | ... | @@ -78,7 +78,7 @@ pub fn link(comp: *Compilation) !void { |
| 78 | 78 | } |
| 79 | 79 | |
| 80 | 80 | const extern_ofmt = toExternObjectFormatType(comp.target.getObjectFormat()); |
| 81 | const args_slice = ctx.args.toSlice(); | |
| 81 | const args_slice = ctx.args.span(); | |
| 82 | 82 | |
| 83 | 83 | { |
| 84 | 84 | // LLD is not thread-safe, so we grab a global lock. |
| ... | ... | @@ -91,7 +91,7 @@ pub fn link(comp: *Compilation) !void { |
| 91 | 91 | // TODO capture these messages and pass them through the system, reporting them through the |
| 92 | 92 | // event system instead of printing them directly here. |
| 93 | 93 | // 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()}); | |
| 95 | 95 | } |
| 96 | 96 | return error.LinkFailed; |
| 97 | 97 | } |
| ... | ... | @@ -173,7 +173,7 @@ fn constructLinkerArgsElf(ctx: *Context) !void { |
| 173 | 173 | //} |
| 174 | 174 | |
| 175 | 175 | 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()); | |
| 177 | 177 | |
| 178 | 178 | if (ctx.link_in_crt) { |
| 179 | 179 | const crt1o = if (ctx.comp.is_static) "crt1.o" else "Scrt1.o"; |
| ... | ... | @@ -291,7 +291,7 @@ fn constructLinkerArgsCoff(ctx: *Context) !void { |
| 291 | 291 | |
| 292 | 292 | const is_library = ctx.comp.kind == .Lib; |
| 293 | 293 | |
| 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()}); | |
| 295 | 295 | try ctx.args.append(@ptrCast([*:0]const u8, out_arg.ptr)); |
| 296 | 296 | |
| 297 | 297 | if (ctx.comp.haveLibC()) { |
| ... | ... | @@ -394,7 +394,7 @@ fn constructLinkerArgsMachO(ctx: *Context) !void { |
| 394 | 394 | } |
| 395 | 395 | |
| 396 | 396 | 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()); | |
| 398 | 398 | |
| 399 | 399 | if (shared) { |
| 400 | 400 | try ctx.args.append("-headerpad_max_install_names"); |
| ... | ... | @@ -432,7 +432,7 @@ fn constructLinkerArgsMachO(ctx: *Context) !void { |
| 432 | 432 | |
| 433 | 433 | // TODO |
| 434 | 434 | //if (ctx.comp.target == Target.Native) { |
| 435 | // for (ctx.comp.link_libs_list.toSliceConst()) |lib| { | |
| 435 | // for (ctx.comp.link_libs_list.span()) |lib| { | |
| 436 | 436 | // if (mem.eql(u8, lib.name, "c")) { |
| 437 | 437 | // // on Darwin, libSystem has libc in it, but also you have to use it |
| 438 | 438 | // // to make syscalls because the syscall numbers are not documented |
| ... | ... | @@ -482,7 +482,7 @@ fn addFnObjects(ctx: *Context) !void { |
| 482 | 482 | ctx.comp.gpa().destroy(node); |
| 483 | 483 | continue; |
| 484 | 484 | }; |
| 485 | try ctx.args.append(fn_val.containing_object.toSliceConst()); | |
| 485 | try ctx.args.append(fn_val.containing_object.span()); | |
| 486 | 486 | it = node.next; |
| 487 | 487 | } |
| 488 | 488 | } |
src-self-hosted/main.zig+7-7| ... | ... | @@ -421,7 +421,7 @@ fn buildOutputType(allocator: *Allocator, args: []const []const u8, out_type: Co |
| 421 | 421 | process.exit(1); |
| 422 | 422 | } |
| 423 | 423 | |
| 424 | try ZigCompiler.setLlvmArgv(allocator, mllvm_flags.toSliceConst()); | |
| 424 | try ZigCompiler.setLlvmArgv(allocator, mllvm_flags.span()); | |
| 425 | 425 | |
| 426 | 426 | const zig_lib_dir = introspect.resolveZigLibDir(allocator) catch process.exit(1); |
| 427 | 427 | defer allocator.free(zig_lib_dir); |
| ... | ... | @@ -448,14 +448,14 @@ fn buildOutputType(allocator: *Allocator, args: []const []const u8, out_type: Co |
| 448 | 448 | comp.override_libc = &override_libc; |
| 449 | 449 | } |
| 450 | 450 | |
| 451 | for (system_libs.toSliceConst()) |lib| { | |
| 451 | for (system_libs.span()) |lib| { | |
| 452 | 452 | _ = try comp.addLinkLib(lib, true); |
| 453 | 453 | } |
| 454 | 454 | |
| 455 | 455 | comp.version = version; |
| 456 | 456 | comp.is_test = false; |
| 457 | 457 | comp.linker_script = linker_script; |
| 458 | comp.clang_argv = clang_argv_buf.toSliceConst(); | |
| 458 | comp.clang_argv = clang_argv_buf.span(); | |
| 459 | 459 | comp.strip = strip; |
| 460 | 460 | |
| 461 | 461 | comp.verbose_tokenize = verbose_tokenize; |
| ... | ... | @@ -488,8 +488,8 @@ fn buildOutputType(allocator: *Allocator, args: []const []const u8, out_type: Co |
| 488 | 488 | comp.emit_asm = emit_asm; |
| 489 | 489 | comp.emit_llvm_ir = emit_llvm_ir; |
| 490 | 490 | 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(); | |
| 493 | 493 | |
| 494 | 494 | comp.start(); |
| 495 | 495 | processBuildEvents(comp, color); |
| ... | ... | @@ -683,7 +683,7 @@ fn cmdFmt(allocator: *Allocator, args: []const []const u8) !void { |
| 683 | 683 | }; |
| 684 | 684 | |
| 685 | 685 | var group = event.Group(FmtError!void).init(allocator); |
| 686 | for (input_files.toSliceConst()) |file_path| { | |
| 686 | for (input_files.span()) |file_path| { | |
| 687 | 687 | try group.call(fmtPath, .{ &fmt, file_path, check_flag }); |
| 688 | 688 | } |
| 689 | 689 | try group.wait(); |
| ... | ... | @@ -898,7 +898,7 @@ const CliPkg = struct { |
| 898 | 898 | } |
| 899 | 899 | |
| 900 | 900 | pub fn deinit(self: *CliPkg) void { |
| 901 | for (self.children.toSliceConst()) |child| { | |
| 901 | for (self.children.span()) |child| { | |
| 902 | 902 | child.deinit(); |
| 903 | 903 | } |
| 904 | 904 | 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 { |
| 185 | 185 | const argc_usize = @intCast(usize, argc); |
| 186 | 186 | var arg_i: usize = 0; |
| 187 | 187 | 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])); | |
| 189 | 189 | } |
| 190 | 190 | |
| 191 | 191 | stdout = std.io.getStdOut().outStream(); |
| 192 | 192 | stderr_file = std.io.getStdErr(); |
| 193 | 193 | stderr = stderr_file.outStream(); |
| 194 | 194 | |
| 195 | const args = args_list.toSliceConst()[2..]; | |
| 195 | const args = args_list.span()[2..]; | |
| 196 | 196 | |
| 197 | 197 | var color: errmsg.Color = .Auto; |
| 198 | 198 | var stdin_flag: bool = false; |
| ... | ... | @@ -285,7 +285,7 @@ fn fmtMain(argc: c_int, argv: [*]const [*:0]const u8) !void { |
| 285 | 285 | .allocator = allocator, |
| 286 | 286 | }; |
| 287 | 287 | |
| 288 | for (input_files.toSliceConst()) |file_path| { | |
| 288 | for (input_files.span()) |file_path| { | |
| 289 | 289 | try fmtPath(&fmt, file_path, check_flag); |
| 290 | 290 | } |
| 291 | 291 | if (fmt.any_error) { |
| ... | ... | @@ -318,7 +318,8 @@ fn fmtPath(fmt: *Fmt, file_path: []const u8, check_mode: bool) FmtError!void { |
| 318 | 318 | if (fmt.seen.exists(file_path)) return; |
| 319 | 319 | try fmt.seen.put(file_path); |
| 320 | 320 | |
| 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) { | |
| 322 | 323 | error.IsDir, error.AccessDenied => { |
| 323 | 324 | // TODO make event based (and dir.next()) |
| 324 | 325 | var dir = try fs.cwd().openDir(file_path, .{ .iterate = true }); |
| ... | ... | @@ -450,7 +451,7 @@ export fn stage2_DepTokenizer_next(self: *stage2_DepTokenizer) stage2_DepNextRes |
| 450 | 451 | const textz = std.Buffer.init(&self.handle.arena.allocator, self.handle.error_text) catch @panic("failed to create .d tokenizer error text"); |
| 451 | 452 | return stage2_DepNextResult{ |
| 452 | 453 | .type_id = .error_, |
| 453 | .textz = textz.toSlice().ptr, | |
| 454 | .textz = textz.span().ptr, | |
| 454 | 455 | }; |
| 455 | 456 | }; |
| 456 | 457 | const token = otoken orelse { |
| ... | ... | @@ -465,7 +466,7 @@ export fn stage2_DepTokenizer_next(self: *stage2_DepTokenizer) stage2_DepNextRes |
| 465 | 466 | .target => .target, |
| 466 | 467 | .prereq => .prereq, |
| 467 | 468 | }, |
| 468 | .textz = textz.toSlice().ptr, | |
| 469 | .textz = textz.span().ptr, | |
| 469 | 470 | }; |
| 470 | 471 | } |
| 471 | 472 | |
| ... | ... | @@ -572,7 +573,7 @@ fn detectNativeCpuWithLLVM( |
| 572 | 573 | var result = Target.Cpu.baseline(arch); |
| 573 | 574 | |
| 574 | 575 | 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); | |
| 576 | 577 | |
| 577 | 578 | for (arch.allCpuModels()) |model| { |
| 578 | 579 | const this_llvm_name = model.llvm_name orelse continue; |
| ... | ... | @@ -593,7 +594,7 @@ fn detectNativeCpuWithLLVM( |
| 593 | 594 | const all_features = arch.allFeaturesList(); |
| 594 | 595 | |
| 595 | 596 | 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), ","); | |
| 597 | 598 | while (it.next()) |decorated_llvm_feat| { |
| 598 | 599 | var op: enum { |
| 599 | 600 | add, |
| ... | ... | @@ -688,9 +689,9 @@ fn stage2CrossTarget( |
| 688 | 689 | mcpu_oz: ?[*:0]const u8, |
| 689 | 690 | dynamic_linker_oz: ?[*:0]const u8, |
| 690 | 691 | ) !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; | |
| 694 | 695 | var diags: CrossTarget.ParseOptions.Diagnostics = .{}; |
| 695 | 696 | const target: CrossTarget = CrossTarget.parse(.{ |
| 696 | 697 | .arch_os_abi = zig_triple, |
| ... | ... | @@ -814,7 +815,7 @@ const Stage2LibCInstallation = extern struct { |
| 814 | 815 | export fn stage2_libc_parse(stage1_libc: *Stage2LibCInstallation, libc_file_z: [*:0]const u8) Error { |
| 815 | 816 | stderr_file = std.io.getStdErr(); |
| 816 | 817 | stderr = stderr_file.outStream(); |
| 817 | const libc_file = mem.toSliceConst(u8, libc_file_z); | |
| 818 | const libc_file = mem.spanZ(libc_file_z); | |
| 818 | 819 | var libc = LibCInstallation.parse(std.heap.c_allocator, libc_file, stderr) catch |err| switch (err) { |
| 819 | 820 | error.ParseError => return .SemanticAnalyzeFail, |
| 820 | 821 | error.DiskQuota => return .DiskQuota, |
| ... | ... | @@ -995,7 +996,7 @@ const Stage2Target = extern struct { |
| 995 | 996 | \\ |
| 996 | 997 | ); |
| 997 | 998 | |
| 998 | assert(mem.endsWith(u8, llvm_features_buffer.toSliceConst(), ",")); | |
| 999 | assert(mem.endsWith(u8, llvm_features_buffer.span(), ",")); | |
| 999 | 1000 | llvm_features_buffer.shrink(llvm_features_buffer.len() - 1); |
| 1000 | 1001 | |
| 1001 | 1002 | var os_builtin_str_buffer = try std.Buffer.allocPrint(allocator, |
| ... | ... | @@ -1120,7 +1121,7 @@ const Stage2Target = extern struct { |
| 1120 | 1121 | try os_builtin_str_buffer.append("};\n"); |
| 1121 | 1122 | |
| 1122 | 1123 | 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()], | |
| 1124 | 1125 | ); |
| 1125 | 1126 | |
| 1126 | 1127 | const glibc_or_darwin_version = blk: { |
| ... | ... | @@ -1232,10 +1233,10 @@ fn stage2DetectNativePaths(stage1_paths: *Stage2NativePaths) !void { |
| 1232 | 1233 | var paths = try std.zig.system.NativePaths.detect(std.heap.c_allocator); |
| 1233 | 1234 | errdefer paths.deinit(); |
| 1234 | 1235 | |
| 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); | |
| 1239 | 1240 | } |
| 1240 | 1241 | |
| 1241 | 1242 | fn 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 { |
| 88 | 88 | try std.fs.cwd().makePath(dirname); |
| 89 | 89 | } |
| 90 | 90 | |
| 91 | // TODO async I/O | |
| 92 | try std.io.writeFile(file1_path, source); | |
| 91 | try std.fs.cwd().writeFile(file1_path, source); | |
| 93 | 92 | |
| 94 | 93 | var comp = try Compilation.create( |
| 95 | 94 | &self.zig_compiler, |
| ... | ... | @@ -122,8 +121,7 @@ pub const TestContext = struct { |
| 122 | 121 | try std.fs.cwd().makePath(dirname); |
| 123 | 122 | } |
| 124 | 123 | |
| 125 | // TODO async I/O | |
| 126 | try std.io.writeFile(file1_path, source); | |
| 124 | try std.fs.cwd().writeFile(file1_path, source); | |
| 127 | 125 | |
| 128 | 126 | var comp = try Compilation.create( |
| 129 | 127 | &self.zig_compiler, |
| ... | ... | @@ -156,7 +154,11 @@ pub const TestContext = struct { |
| 156 | 154 | .Ok => { |
| 157 | 155 | const argv = [_][]const u8{exe_file}; |
| 158 | 156 | // 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 | }); | |
| 160 | 162 | switch (child.term) { |
| 161 | 163 | .Exited => |code| { |
| 162 | 164 | if (code != 0) { |
src-self-hosted/translate_c.zig+2-2| ... | ... | @@ -235,7 +235,7 @@ pub const Context = struct { |
| 235 | 235 | |
| 236 | 236 | /// Convert a null-terminated C string to a slice allocated in the arena |
| 237 | 237 | 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)); | |
| 239 | 239 | } |
| 240 | 240 | |
| 241 | 241 | /// 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, |
| 5851 | 5851 | |
| 5852 | 5852 | fn tokenSlice(c: *Context, token: ast.TokenIndex) []u8 { |
| 5853 | 5853 | 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]; | |
| 5855 | 5855 | return if (mem.startsWith(u8, slice, "@\"")) |
| 5856 | 5856 | slice[2 .. slice.len - 1] |
| 5857 | 5857 | else |
src-self-hosted/util.zig+2-2| ... | ... | @@ -19,8 +19,8 @@ pub fn getDarwinArchString(self: Target) [:0]const u8 { |
| 19 | 19 | pub fn llvmTargetFromTriple(triple: std.Buffer) !*llvm.Target { |
| 20 | 20 | var result: *llvm.Target = undefined; |
| 21 | 21 | 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 }); | |
| 24 | 24 | return error.UnsupportedTarget; |
| 25 | 25 | } |
| 26 | 26 | return result; |
src-self-hosted/value.zig+2-2| ... | ... | @@ -156,7 +156,7 @@ pub const Value = struct { |
| 156 | 156 | const llvm_fn_type = try self.base.typ.getLlvmType(ofile.arena, ofile.context); |
| 157 | 157 | const llvm_fn = llvm.AddFunction( |
| 158 | 158 | ofile.module, |
| 159 | self.symbol_name.toSliceConst(), | |
| 159 | self.symbol_name.span(), | |
| 160 | 160 | llvm_fn_type, |
| 161 | 161 | ) orelse return error.OutOfMemory; |
| 162 | 162 | |
| ... | ... | @@ -241,7 +241,7 @@ pub const Value = struct { |
| 241 | 241 | const llvm_fn_type = try self.base.typ.getLlvmType(ofile.arena, ofile.context); |
| 242 | 242 | const llvm_fn = llvm.AddFunction( |
| 243 | 243 | ofile.module, |
| 244 | self.symbol_name.toSliceConst(), | |
| 244 | self.symbol_name.span(), | |
| 245 | 245 | llvm_fn_type, |
| 246 | 246 | ) orelse return error.OutOfMemory; |
| 247 | 247 |
test/cli.zig+8-3| ... | ... | @@ -59,7 +59,12 @@ fn printCmd(cwd: []const u8, argv: []const []const u8) void { |
| 59 | 59 | |
| 60 | 60 | fn exec(cwd: []const u8, argv: []const []const u8) !ChildProcess.ExecResult { |
| 61 | 61 | 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| { | |
| 63 | 68 | std.debug.warn("The following command failed:\n", .{}); |
| 64 | 69 | printCmd(cwd, argv); |
| 65 | 70 | return err; |
| ... | ... | @@ -101,7 +106,7 @@ fn testGodboltApi(zig_exe: []const u8, dir_path: []const u8) anyerror!void { |
| 101 | 106 | const example_zig_path = try fs.path.join(a, &[_][]const u8{ dir_path, "example.zig" }); |
| 102 | 107 | const example_s_path = try fs.path.join(a, &[_][]const u8{ dir_path, "example.s" }); |
| 103 | 108 | |
| 104 | try std.io.writeFile(example_zig_path, | |
| 109 | try fs.cwd().writeFile(example_zig_path, | |
| 105 | 110 | \\// Type your code here, or load an example. |
| 106 | 111 | \\export fn square(num: i32) i32 { |
| 107 | 112 | \\ return num * num; |
| ... | ... | @@ -124,7 +129,7 @@ fn testGodboltApi(zig_exe: []const u8, dir_path: []const u8) anyerror!void { |
| 124 | 129 | }; |
| 125 | 130 | _ = try exec(dir_path, &args); |
| 126 | 131 | |
| 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)); | |
| 128 | 133 | testing.expect(std.mem.indexOf(u8, out_asm, "square:") != null); |
| 129 | 134 | testing.expect(std.mem.indexOf(u8, out_asm, "mov\teax, edi") != null); |
| 130 | 135 | 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 { |
| 91 | 91 | const b = self.b; |
| 92 | 92 | |
| 93 | 93 | const write_src = b.addWriteFiles(); |
| 94 | for (case.sources.toSliceConst()) |src_file| { | |
| 94 | for (case.sources.span()) |src_file| { | |
| 95 | 95 | write_src.add(src_file.filename, src_file.source); |
| 96 | 96 | } |
| 97 | 97 | |
| ... | ... | @@ -105,7 +105,7 @@ pub const CompareOutputContext = struct { |
| 105 | 105 | } |
| 106 | 106 | |
| 107 | 107 | 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); | |
| 109 | 109 | |
| 110 | 110 | const run = exe.run(); |
| 111 | 111 | run.addArgs(case.cli_args); |
| ... | ... | @@ -125,7 +125,7 @@ pub const CompareOutputContext = struct { |
| 125 | 125 | if (mem.indexOf(u8, annotated_case_name, filter) == null) continue; |
| 126 | 126 | } |
| 127 | 127 | |
| 128 | const basename = case.sources.toSliceConst()[0].filename; | |
| 128 | const basename = case.sources.span()[0].filename; | |
| 129 | 129 | const exe = b.addExecutableFromWriteFileStep("test", write_src, basename); |
| 130 | 130 | exe.setBuildMode(mode); |
| 131 | 131 | if (case.link_libc) { |
| ... | ... | @@ -146,7 +146,7 @@ pub const CompareOutputContext = struct { |
| 146 | 146 | if (mem.indexOf(u8, annotated_case_name, filter) == null) return; |
| 147 | 147 | } |
| 148 | 148 | |
| 149 | const basename = case.sources.toSliceConst()[0].filename; | |
| 149 | const basename = case.sources.span()[0].filename; | |
| 150 | 150 | const exe = b.addExecutableFromWriteFileStep("test", write_src, basename); |
| 151 | 151 | if (case.link_libc) { |
| 152 | 152 | exe.linkSystemLibrary("c"); |
test/src/run_translated_c.zig+2-2| ... | ... | @@ -82,13 +82,13 @@ pub const RunTranslatedCContext = struct { |
| 82 | 82 | } |
| 83 | 83 | |
| 84 | 84 | const write_src = b.addWriteFiles(); |
| 85 | for (case.sources.toSliceConst()) |src_file| { | |
| 85 | for (case.sources.span()) |src_file| { | |
| 86 | 86 | write_src.add(src_file.filename, src_file.source); |
| 87 | 87 | } |
| 88 | 88 | const translate_c = b.addTranslateC(.{ |
| 89 | 89 | .write_file = .{ |
| 90 | 90 | .step = write_src, |
| 91 | .basename = case.sources.toSliceConst()[0].filename, | |
| 91 | .basename = case.sources.span()[0].filename, | |
| 92 | 92 | }, |
| 93 | 93 | }); |
| 94 | 94 | 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 { |
| 105 | 105 | } |
| 106 | 106 | |
| 107 | 107 | const write_src = b.addWriteFiles(); |
| 108 | for (case.sources.toSliceConst()) |src_file| { | |
| 108 | for (case.sources.span()) |src_file| { | |
| 109 | 109 | write_src.add(src_file.filename, src_file.source); |
| 110 | 110 | } |
| 111 | 111 | |
| 112 | 112 | const translate_c = b.addTranslateC(.{ |
| 113 | 113 | .write_file = .{ |
| 114 | 114 | .step = write_src, |
| 115 | .basename = case.sources.toSliceConst()[0].filename, | |
| 115 | .basename = case.sources.span()[0].filename, | |
| 116 | 116 | }, |
| 117 | 117 | }); |
| 118 | 118 | translate_c.step.name = annotated_case_name; |
| 119 | 119 | translate_c.setTarget(case.target); |
| 120 | 120 | |
| 121 | const check_file = translate_c.addCheckFile(case.expected_lines.toSliceConst()); | |
| 121 | const check_file = translate_c.addCheckFile(case.expected_lines.span()); | |
| 122 | 122 | |
| 123 | 123 | self.step.dependOn(&check_file.step); |
| 124 | 124 | } |
test/stage1/behavior/cast.zig+1-1| ... | ... | @@ -329,7 +329,7 @@ fn testCastPtrOfArrayToSliceAndPtr() void { |
| 329 | 329 | test "cast *[1][*]const u8 to [*]const ?[*]const u8" { |
| 330 | 330 | const window_name = [1][*]const u8{"window name"}; |
| 331 | 331 | 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")); | |
| 333 | 333 | } |
| 334 | 334 | |
| 335 | 335 | test "@intCast comptime_int" { |
test/stage1/behavior/pointers.zig+1-1| ... | ... | @@ -225,7 +225,7 @@ test "null terminated pointer" { |
| 225 | 225 | var zero_ptr: [*:0]const u8 = @ptrCast([*:0]const u8, &array_with_zero); |
| 226 | 226 | var no_zero_ptr: [*]const u8 = zero_ptr; |
| 227 | 227 | 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")); | |
| 229 | 229 | } |
| 230 | 230 | }; |
| 231 | 231 | S.doTheTest(); |
test/standalone/brace_expansion/main.zig+10-10| ... | ... | @@ -131,11 +131,11 @@ fn expandString(input: []const u8, output: *Buffer) !void { |
| 131 | 131 | try expandNode(root, &result_list); |
| 132 | 132 | |
| 133 | 133 | try output.resize(0); |
| 134 | for (result_list.toSliceConst()) |buf, i| { | |
| 134 | for (result_list.span()) |buf, i| { | |
| 135 | 135 | if (i != 0) { |
| 136 | 136 | try output.appendByte(' '); |
| 137 | 137 | } |
| 138 | try output.append(buf.toSliceConst()); | |
| 138 | try output.append(buf.span()); | |
| 139 | 139 | } |
| 140 | 140 | } |
| 141 | 141 | |
| ... | ... | @@ -157,20 +157,20 @@ fn expandNode(node: Node, output: *ArrayList(Buffer)) ExpandNodeError!void { |
| 157 | 157 | var child_list_b = ArrayList(Buffer).init(global_allocator); |
| 158 | 158 | try expandNode(b_node, &child_list_b); |
| 159 | 159 | |
| 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| { | |
| 162 | 162 | var combined_buf = try Buffer.initFromBuffer(buf_a); |
| 163 | try combined_buf.append(buf_b.toSliceConst()); | |
| 163 | try combined_buf.append(buf_b.span()); | |
| 164 | 164 | try output.append(combined_buf); |
| 165 | 165 | } |
| 166 | 166 | } |
| 167 | 167 | }, |
| 168 | 168 | Node.List => |list| { |
| 169 | for (list.toSliceConst()) |child_node| { | |
| 169 | for (list.span()) |child_node| { | |
| 170 | 170 | var child_list = ArrayList(Buffer).init(global_allocator); |
| 171 | 171 | try expandNode(child_node, &child_list); |
| 172 | 172 | |
| 173 | for (child_list.toSliceConst()) |buf| { | |
| 173 | for (child_list.span()) |buf| { | |
| 174 | 174 | try output.append(buf); |
| 175 | 175 | } |
| 176 | 176 | } |
| ... | ... | @@ -196,8 +196,8 @@ pub fn main() !void { |
| 196 | 196 | var result_buf = try Buffer.initSize(global_allocator, 0); |
| 197 | 197 | defer result_buf.deinit(); |
| 198 | 198 | |
| 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()); | |
| 201 | 201 | } |
| 202 | 202 | |
| 203 | 203 | test "invalid inputs" { |
| ... | ... | @@ -256,5 +256,5 @@ fn expectExpansion(test_input: []const u8, expected_result: []const u8) void { |
| 256 | 256 | |
| 257 | 257 | expandString(test_input, &result) catch unreachable; |
| 258 | 258 | |
| 259 | testing.expectEqualSlices(u8, expected_result, result.toSlice()); | |
| 259 | testing.expectEqualSlices(u8, expected_result, result.span()); | |
| 260 | 260 | } |
test/standalone/guess_number/main.zig+1-1| ... | ... | @@ -17,7 +17,7 @@ pub fn main() !void { |
| 17 | 17 | const seed = std.mem.readIntNative(u64, &seed_bytes); |
| 18 | 18 | var prng = std.rand.DefaultPrng.init(seed); |
| 19 | 19 | |
| 20 | const answer = prng.random.range(u8, 0, 100) + 1; | |
| 20 | const answer = prng.random.intRangeLessThan(u8, 0, 100) + 1; | |
| 21 | 21 | |
| 22 | 22 | while (true) { |
| 23 | 23 | try stdout.print("\nGuess a number between 1 and 100: ", .{}); |
test/tests.zig+23-23| ... | ... | @@ -583,7 +583,7 @@ pub const StackTracesContext = struct { |
| 583 | 583 | |
| 584 | 584 | warn("Test {}/{} {}...", .{ self.test_index + 1, self.context.test_index, self.name }); |
| 585 | 585 | |
| 586 | const child = std.ChildProcess.init(args.toSliceConst(), b.allocator) catch unreachable; | |
| 586 | const child = std.ChildProcess.init(args.span(), b.allocator) catch unreachable; | |
| 587 | 587 | defer child.deinit(); |
| 588 | 588 | |
| 589 | 589 | child.stdin_behavior = .Ignore; |
| ... | ... | @@ -592,7 +592,7 @@ pub const StackTracesContext = struct { |
| 592 | 592 | child.env_map = b.env_map; |
| 593 | 593 | |
| 594 | 594 | if (b.verbose) { |
| 595 | printInvocation(args.toSliceConst()); | |
| 595 | printInvocation(args.span()); | |
| 596 | 596 | } |
| 597 | 597 | child.spawn() catch |err| debug.panic("Unable to spawn {}: {}\n", .{ full_exe_path, @errorName(err) }); |
| 598 | 598 | |
| ... | ... | @@ -614,23 +614,23 @@ pub const StackTracesContext = struct { |
| 614 | 614 | code, |
| 615 | 615 | expect_code, |
| 616 | 616 | }); |
| 617 | printInvocation(args.toSliceConst()); | |
| 617 | printInvocation(args.span()); | |
| 618 | 618 | return error.TestFailed; |
| 619 | 619 | } |
| 620 | 620 | }, |
| 621 | 621 | .Signal => |signum| { |
| 622 | 622 | warn("Process {} terminated on signal {}\n", .{ full_exe_path, signum }); |
| 623 | printInvocation(args.toSliceConst()); | |
| 623 | printInvocation(args.span()); | |
| 624 | 624 | return error.TestFailed; |
| 625 | 625 | }, |
| 626 | 626 | .Stopped => |signum| { |
| 627 | 627 | warn("Process {} stopped on signal {}\n", .{ full_exe_path, signum }); |
| 628 | printInvocation(args.toSliceConst()); | |
| 628 | printInvocation(args.span()); | |
| 629 | 629 | return error.TestFailed; |
| 630 | 630 | }, |
| 631 | 631 | .Unknown => |code| { |
| 632 | 632 | warn("Process {} terminated unexpectedly with error code {}\n", .{ full_exe_path, code }); |
| 633 | printInvocation(args.toSliceConst()); | |
| 633 | printInvocation(args.span()); | |
| 634 | 634 | return error.TestFailed; |
| 635 | 635 | }, |
| 636 | 636 | } |
| ... | ... | @@ -785,7 +785,7 @@ pub const CompileErrorContext = struct { |
| 785 | 785 | } else { |
| 786 | 786 | try zig_args.append("build-obj"); |
| 787 | 787 | } |
| 788 | const root_src_basename = self.case.sources.toSliceConst()[0].filename; | |
| 788 | const root_src_basename = self.case.sources.span()[0].filename; | |
| 789 | 789 | try zig_args.append(self.write_src.getOutputPath(root_src_basename)); |
| 790 | 790 | |
| 791 | 791 | zig_args.append("--name") catch unreachable; |
| ... | ... | @@ -809,10 +809,10 @@ pub const CompileErrorContext = struct { |
| 809 | 809 | warn("Test {}/{} {}...", .{ self.test_index + 1, self.context.test_index, self.name }); |
| 810 | 810 | |
| 811 | 811 | if (b.verbose) { |
| 812 | printInvocation(zig_args.toSliceConst()); | |
| 812 | printInvocation(zig_args.span()); | |
| 813 | 813 | } |
| 814 | 814 | |
| 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; | |
| 816 | 816 | defer child.deinit(); |
| 817 | 817 | |
| 818 | 818 | child.env_map = b.env_map; |
| ... | ... | @@ -822,11 +822,11 @@ pub const CompileErrorContext = struct { |
| 822 | 822 | |
| 823 | 823 | child.spawn() catch |err| debug.panic("Unable to spawn {}: {}\n", .{ zig_args.items[0], @errorName(err) }); |
| 824 | 824 | |
| 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); | |
| 827 | 827 | |
| 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; | |
| 830 | 830 | |
| 831 | 831 | const term = child.wait() catch |err| { |
| 832 | 832 | debug.panic("Unable to spawn {}: {}\n", .{ zig_args.items[0], @errorName(err) }); |
| ... | ... | @@ -834,19 +834,19 @@ pub const CompileErrorContext = struct { |
| 834 | 834 | switch (term) { |
| 835 | 835 | .Exited => |code| { |
| 836 | 836 | if (code == 0) { |
| 837 | printInvocation(zig_args.toSliceConst()); | |
| 837 | printInvocation(zig_args.span()); | |
| 838 | 838 | return error.CompilationIncorrectlySucceeded; |
| 839 | 839 | } |
| 840 | 840 | }, |
| 841 | 841 | else => { |
| 842 | 842 | warn("Process {} terminated unexpectedly\n", .{b.zig_exe}); |
| 843 | printInvocation(zig_args.toSliceConst()); | |
| 843 | printInvocation(zig_args.span()); | |
| 844 | 844 | return error.TestFailed; |
| 845 | 845 | }, |
| 846 | 846 | } |
| 847 | 847 | |
| 848 | const stdout = stdout_buf.toSliceConst(); | |
| 849 | const stderr = stderr_buf.toSliceConst(); | |
| 848 | const stdout = stdout_buf.span(); | |
| 849 | const stderr = stderr_buf.span(); | |
| 850 | 850 | |
| 851 | 851 | if (stdout.len != 0) { |
| 852 | 852 | warn( |
| ... | ... | @@ -875,12 +875,12 @@ pub const CompileErrorContext = struct { |
| 875 | 875 | |
| 876 | 876 | if (!ok) { |
| 877 | 877 | warn("\n======== Expected these compile errors: ========\n", .{}); |
| 878 | for (self.case.expected_errors.toSliceConst()) |expected| { | |
| 878 | for (self.case.expected_errors.span()) |expected| { | |
| 879 | 879 | warn("{}\n", .{expected}); |
| 880 | 880 | } |
| 881 | 881 | } |
| 882 | 882 | } else { |
| 883 | for (self.case.expected_errors.toSliceConst()) |expected| { | |
| 883 | for (self.case.expected_errors.span()) |expected| { | |
| 884 | 884 | if (mem.indexOf(u8, stderr, expected) == null) { |
| 885 | 885 | warn( |
| 886 | 886 | \\ |
| ... | ... | @@ -980,7 +980,7 @@ pub const CompileErrorContext = struct { |
| 980 | 980 | if (mem.indexOf(u8, annotated_case_name, filter) == null) return; |
| 981 | 981 | } |
| 982 | 982 | const write_src = b.addWriteFiles(); |
| 983 | for (case.sources.toSliceConst()) |src_file| { | |
| 983 | for (case.sources.span()) |src_file| { | |
| 984 | 984 | write_src.add(src_file.filename, src_file.source); |
| 985 | 985 | } |
| 986 | 986 | |
| ... | ... | @@ -1027,7 +1027,7 @@ pub const StandaloneContext = struct { |
| 1027 | 1027 | zig_args.append("--verbose") catch unreachable; |
| 1028 | 1028 | } |
| 1029 | 1029 | |
| 1030 | const run_cmd = b.addSystemCommand(zig_args.toSliceConst()); | |
| 1030 | const run_cmd = b.addSystemCommand(zig_args.span()); | |
| 1031 | 1031 | |
| 1032 | 1032 | const log_step = b.addLog("PASS {}\n", .{annotated_case_name}); |
| 1033 | 1033 | log_step.step.dependOn(&run_cmd.step); |
| ... | ... | @@ -1127,7 +1127,7 @@ pub const GenHContext = struct { |
| 1127 | 1127 | const full_h_path = self.obj.getOutputHPath(); |
| 1128 | 1128 | const actual_h = try io.readFileAlloc(b.allocator, full_h_path); |
| 1129 | 1129 | |
| 1130 | for (self.case.expected_lines.toSliceConst()) |expected_line| { | |
| 1130 | for (self.case.expected_lines.span()) |expected_line| { | |
| 1131 | 1131 | if (mem.indexOf(u8, actual_h, expected_line) == null) { |
| 1132 | 1132 | warn( |
| 1133 | 1133 | \\ |
| ... | ... | @@ -1188,7 +1188,7 @@ pub const GenHContext = struct { |
| 1188 | 1188 | } |
| 1189 | 1189 | |
| 1190 | 1190 | const write_src = b.addWriteFiles(); |
| 1191 | for (case.sources.toSliceConst()) |src_file| { | |
| 1191 | for (case.sources.span()) |src_file| { | |
| 1192 | 1192 | write_src.add(src_file.filename, src_file.source); |
| 1193 | 1193 | } |
| 1194 | 1194 |
tools/merge_anal_dumps.zig+12-12| ... | ... | @@ -183,13 +183,13 @@ const Dump = struct { |
| 183 | 183 | try mergeSameStrings(&self.zig_version, zig_version); |
| 184 | 184 | try mergeSameStrings(&self.root_name, root_name); |
| 185 | 185 | |
| 186 | for (params.get("builds").?.value.Array.toSliceConst()) |json_build| { | |
| 186 | for (params.get("builds").?.value.Array.span()) |json_build| { | |
| 187 | 187 | const target = json_build.Object.get("target").?.value.String; |
| 188 | 188 | try self.targets.append(target); |
| 189 | 189 | } |
| 190 | 190 | |
| 191 | 191 | // 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(); | |
| 193 | 193 | var other_file_to_mine = std.AutoHashMap(usize, usize).init(self.a()); |
| 194 | 194 | for (other_files) |other_file, i| { |
| 195 | 195 | const gop = try self.file_map.getOrPut(other_file.String); |
| ... | ... | @@ -201,7 +201,7 @@ const Dump = struct { |
| 201 | 201 | } |
| 202 | 202 | |
| 203 | 203 | // 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(); | |
| 205 | 205 | var other_ast_node_to_mine = std.AutoHashMap(usize, usize).init(self.a()); |
| 206 | 206 | for (other_ast_nodes) |other_ast_node_json, i| { |
| 207 | 207 | const other_file_id = jsonObjInt(other_ast_node_json, "file"); |
| ... | ... | @@ -221,9 +221,9 @@ const Dump = struct { |
| 221 | 221 | // convert fields lists |
| 222 | 222 | for (other_ast_nodes) |other_ast_node_json, i| { |
| 223 | 223 | 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]; | |
| 225 | 225 | 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(); | |
| 227 | 227 | my_node.fields = try self.a().alloc(usize, other_fields.len); |
| 228 | 228 | for (other_fields) |other_field_index, field_i| { |
| 229 | 229 | const other_index = @intCast(usize, other_field_index.Integer); |
| ... | ... | @@ -233,7 +233,7 @@ const Dump = struct { |
| 233 | 233 | } |
| 234 | 234 | |
| 235 | 235 | // 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(); | |
| 237 | 237 | var other_error_to_mine = std.AutoHashMap(usize, usize).init(self.a()); |
| 238 | 238 | for (other_errors) |other_error_json, i| { |
| 239 | 239 | const other_src_id = jsonObjInt(other_error_json, "src"); |
| ... | ... | @@ -253,7 +253,7 @@ const Dump = struct { |
| 253 | 253 | // First we identify all the simple types and merge those. |
| 254 | 254 | // Example: void, type, noreturn |
| 255 | 255 | // 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(); | |
| 257 | 257 | var other_types_to_mine = std.AutoHashMap(usize, usize).init(self.a()); |
| 258 | 258 | for (other_types) |other_type_json, i| { |
| 259 | 259 | const type_kind = jsonObjInt(other_type_json, "kind"); |
| ... | ... | @@ -336,7 +336,7 @@ const Dump = struct { |
| 336 | 336 | |
| 337 | 337 | try jw.objectField("builds"); |
| 338 | 338 | try jw.beginArray(); |
| 339 | for (self.targets.toSliceConst()) |target| { | |
| 339 | for (self.targets.span()) |target| { | |
| 340 | 340 | try jw.arrayElem(); |
| 341 | 341 | try jw.beginObject(); |
| 342 | 342 | try jw.objectField("target"); |
| ... | ... | @@ -349,7 +349,7 @@ const Dump = struct { |
| 349 | 349 | |
| 350 | 350 | try jw.objectField("types"); |
| 351 | 351 | try jw.beginArray(); |
| 352 | for (self.type_list.toSliceConst()) |t| { | |
| 352 | for (self.type_list.span()) |t| { | |
| 353 | 353 | try jw.arrayElem(); |
| 354 | 354 | try jw.beginObject(); |
| 355 | 355 | |
| ... | ... | @@ -379,7 +379,7 @@ const Dump = struct { |
| 379 | 379 | |
| 380 | 380 | try jw.objectField("errors"); |
| 381 | 381 | try jw.beginArray(); |
| 382 | for (self.error_list.toSliceConst()) |zig_error| { | |
| 382 | for (self.error_list.span()) |zig_error| { | |
| 383 | 383 | try jw.arrayElem(); |
| 384 | 384 | try jw.beginObject(); |
| 385 | 385 | |
| ... | ... | @@ -395,7 +395,7 @@ const Dump = struct { |
| 395 | 395 | |
| 396 | 396 | try jw.objectField("astNodes"); |
| 397 | 397 | try jw.beginArray(); |
| 398 | for (self.node_list.toSliceConst()) |node| { | |
| 398 | for (self.node_list.span()) |node| { | |
| 399 | 399 | try jw.arrayElem(); |
| 400 | 400 | try jw.beginObject(); |
| 401 | 401 | |
| ... | ... | @@ -425,7 +425,7 @@ const Dump = struct { |
| 425 | 425 | |
| 426 | 426 | try jw.objectField("files"); |
| 427 | 427 | try jw.beginArray(); |
| 428 | for (self.file_list.toSliceConst()) |file| { | |
| 428 | for (self.file_list.span()) |file| { | |
| 429 | 429 | try jw.arrayElem(); |
| 430 | 430 | try jw.emitString(file); |
| 431 | 431 | } |
tools/process_headers.zig+4-4| ... | ... | @@ -324,7 +324,7 @@ pub fn main() !void { |
| 324 | 324 | }, |
| 325 | 325 | .os = .linux, |
| 326 | 326 | }; |
| 327 | search: for (search_paths.toSliceConst()) |search_path| { | |
| 327 | search: for (search_paths.span()) |search_path| { | |
| 328 | 328 | var sub_path: []const []const u8 = undefined; |
| 329 | 329 | switch (vendor) { |
| 330 | 330 | .musl => { |
| ... | ... | @@ -414,13 +414,13 @@ pub fn main() !void { |
| 414 | 414 | try contents_list.append(contents); |
| 415 | 415 | } |
| 416 | 416 | } |
| 417 | std.sort.sort(*Contents, contents_list.toSlice(), Contents.hitCountLessThan); | |
| 417 | std.sort.sort(*Contents, contents_list.span(), Contents.hitCountLessThan); | |
| 418 | 418 | var best_contents = contents_list.popOrNull().?; |
| 419 | 419 | if (best_contents.hit_count > 1) { |
| 420 | 420 | // worth it to make it generic |
| 421 | 421 | const full_path = try std.fs.path.join(allocator, &[_][]const u8{ out_dir, generic_name, path_kv.key }); |
| 422 | 422 | 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); | |
| 424 | 424 | best_contents.is_generic = true; |
| 425 | 425 | while (contents_list.popOrNull()) |contender| { |
| 426 | 426 | if (contender.hit_count > 1) { |
| ... | ... | @@ -447,7 +447,7 @@ pub fn main() !void { |
| 447 | 447 | }); |
| 448 | 448 | const full_path = try std.fs.path.join(allocator, &[_][]const u8{ out_dir, out_subpath, path_kv.key }); |
| 449 | 449 | 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); | |
| 451 | 451 | } |
| 452 | 452 | } |
| 453 | 453 | } |
tools/update_clang_options.zig+1-1| ... | ... | @@ -239,7 +239,7 @@ pub fn main() anyerror!void { |
| 239 | 239 | try std.fmt.allocPrint(allocator, "-I={}/clang/include/clang/Driver", .{llvm_src_root}), |
| 240 | 240 | }; |
| 241 | 241 | |
| 242 | const child_result = try std.ChildProcess.exec2(.{ | |
| 242 | const child_result = try std.ChildProcess.exec(.{ | |
| 243 | 243 | .allocator = allocator, |
| 244 | 244 | .argv = &child_args, |
| 245 | 245 | .max_output_bytes = 100 * 1024 * 1024, |
tools/update_glibc.zig+7-7| ... | ... | @@ -223,15 +223,15 @@ pub fn main() !void { |
| 223 | 223 | var list = std.ArrayList([]const u8).init(allocator); |
| 224 | 224 | var it = global_fn_set.iterator(); |
| 225 | 225 | 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(); | |
| 228 | 228 | }; |
| 229 | 229 | const global_ver_list = blk: { |
| 230 | 230 | var list = std.ArrayList([]const u8).init(allocator); |
| 231 | 231 | var it = global_ver_set.iterator(); |
| 232 | 232 | 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(); | |
| 235 | 235 | }; |
| 236 | 236 | { |
| 237 | 237 | const vers_txt_path = try fs.path.join(allocator, &[_][]const u8{ glibc_out_dir, "vers.txt" }); |
| ... | ... | @@ -264,13 +264,13 @@ pub fn main() !void { |
| 264 | 264 | for (abi_lists) |*abi_list, abi_index| { |
| 265 | 265 | const kv = target_functions.get(@ptrToInt(abi_list)).?; |
| 266 | 266 | 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| { | |
| 268 | 268 | const gop = try fn_vers_list.getOrPut(ver_fn.name); |
| 269 | 269 | if (!gop.found_existing) { |
| 270 | 270 | gop.kv.value = std.ArrayList(usize).init(allocator); |
| 271 | 271 | } |
| 272 | 272 | 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) { | |
| 274 | 274 | try gop.kv.value.append(ver_index); |
| 275 | 275 | } |
| 276 | 276 | } |
| ... | ... | @@ -297,7 +297,7 @@ pub fn main() !void { |
| 297 | 297 | try abilist_txt.writeByte('\n'); |
| 298 | 298 | continue; |
| 299 | 299 | }; |
| 300 | for (kv.value.toSliceConst()) |ver_index, it_i| { | |
| 300 | for (kv.value.span()) |ver_index, it_i| { | |
| 301 | 301 | if (it_i != 0) try abilist_txt.writeByte(' '); |
| 302 | 302 | try abilist_txt.print("{d}", .{ver_index}); |
| 303 | 303 | } |