authorgravatar for leroycepearson@geemili.xyzLeRoyce Pearson <leroycepearson@geemili.xyz> 2020-04-02 21:46:48-06:00
committergravatar for leroycepearson@geemili.xyzLeRoyce Pearson <leroycepearson@geemili.xyz> 2020-04-02 21:46:48-06:00
log35c462caf0c0763c14d0f1303197c86a63c51f03
tree46591490be3dcf41f664c411385b62de9b1326d2
parent457f557c37947af6ce90a82a70e08e59526af0dc
parente7f555ca550cc73288adbdf4ec8d0e4abbc7a987

Merge branch 'master' into feature-file-locks


151 files changed, 5715 insertions(+), 4377 deletions(-)

CMakeLists.txt+13-4
......@@ -224,7 +224,7 @@ set(EMBEDDED_SOFTFLOAT_SOURCES
224224add_library(embedded_softfloat STATIC ${EMBEDDED_SOFTFLOAT_SOURCES})
225225if(MSVC)
226226 set_target_properties(embedded_softfloat PROPERTIES
227 COMPILE_FLAGS "-std=c99 /w"
227 COMPILE_FLAGS "/w /O2"
228228 )
229229else()
230230 set_target_properties(embedded_softfloat PROPERTIES
......@@ -315,12 +315,17 @@ include_directories(
315315)
316316
317317# These have to go before the -Wno- flags
318set(EXE_CFLAGS "-std=c++14")
318if(MSVC)
319 set(EXE_CFLAGS "/std:c++14")
320else(MSVC)
321 set(EXE_CFLAGS "-std=c++14")
322endif(MSVC)
323
319324if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
320325 if(MSVC)
321326 set(EXE_CFLAGS "${EXE_CFLAGS} /w")
322327 else()
323 set(EXE_CFLAGS "${EXE_CFLAGS} -Werror -Wall")
328 set(EXE_CFLAGS "${EXE_CFLAGS} -Werror -Wall -Werror=implicit-fallthrough")
324329 endif()
325330endif()
326331
......@@ -333,7 +338,11 @@ else()
333338 endif()
334339endif()
335340
336set(OPTIMIZED_C_FLAGS "-std=c99 -O3")
341if(MSVC)
342 set(OPTIMIZED_C_FLAGS "/O2")
343else(MSVC)
344 set(OPTIMIZED_C_FLAGS "-std=c99 -O3")
345endif(MSVC)
337346
338347set(EXE_LDFLAGS " ")
339348if(MSVC)
README.md+2-2
......@@ -54,8 +54,8 @@ make install
5454##### MacOS
5555
5656```
57brew install cmake llvm@10
58brew outdated llvm@10 || brew upgrade llvm@10
57brew install cmake llvm
58brew outdated llvm || brew upgrade llvm
5959mkdir build
6060cd build
6161cmake .. -DCMAKE_PREFIX_PATH=$(brew --prefix llvm)
ci/azure/linux_script+5-1
......@@ -12,7 +12,11 @@ sudo apt-get update -q
1212
1313sudo apt-get remove -y llvm-*
1414sudo rm -rf /usr/local/*
15sudo apt-get install -y libxml2-dev libclang-10-dev llvm-10 llvm-10-dev liblld-10-dev cmake s3cmd gcc-7 g++-7 qemu
15sudo apt-get install -y libxml2-dev libclang-10-dev llvm-10 llvm-10-dev liblld-10-dev cmake s3cmd gcc-7 g++-7
16
17wget https://ziglang.org/deps/qemu-5.0.0-rc1-x86_64-alpinelinux.tar.xz
18tar xf qemu-5.0.0-rc1-x86_64-alpinelinux.tar.xz
19PATH=$PWD/qemu-5.0.0-rc1/bin:$PATH
1620
1721# Make the `zig version` number consistent.
1822# This will affect the cmake command below.
ci/srht/update_download_page+1
......@@ -71,6 +71,7 @@ export X86_64_FREEBSD_SHASUM="$(echo "$X86_64_FREEBSD_JSON" | jq .shasum -r)"
7171git clone https://github.com/ziglang/www.ziglang.org --depth 1
7272cd www.ziglang.org
7373export MASTER_DATE="$(date +%Y-%m-%d)"
74export MASTER_VERSION="$VERSION"
7475"../$ZIG" run update-download-page.zig
7576
7677$S3CMD put -P --no-mime-magic --add-header="cache-control: public, max-age=31536000, immutable" "../$SRC_TARBALL" s3://ziglang.org/builds/
cmake/Findlld.cmake+1
......@@ -24,6 +24,7 @@ else()
2424 string(TOUPPER ${_libname_} _prettylibname_)
2525 find_library(LLD_${_prettylibname_}_LIB NAMES ${_libname_}
2626 PATHS
27 ${LLD_LIBDIRS}
2728 /usr/lib/llvm-10/lib
2829 /usr/local/llvm100/lib
2930 /mingw64/lib
doc/docgen.zig+48-29
......@@ -321,7 +321,7 @@ fn genToc(allocator: *mem.Allocator, tokenizer: *Tokenizer) !Toc {
321321 var last_action = Action.Open;
322322 var last_columns: ?u8 = null;
323323
324 var toc_buf = try std.Buffer.initSize(allocator, 0);
324 var toc_buf = std.ArrayList(u8).init(allocator);
325325 defer toc_buf.deinit();
326326
327327 var toc = toc_buf.outStream();
......@@ -607,7 +607,7 @@ fn genToc(allocator: *mem.Allocator, tokenizer: *Tokenizer) !Toc {
607607}
608608
609609fn urlize(allocator: *mem.Allocator, input: []const u8) ![]u8 {
610 var buf = try std.Buffer.initSize(allocator, 0);
610 var buf = std.ArrayList(u8).init(allocator);
611611 defer buf.deinit();
612612
613613 const out = buf.outStream();
......@@ -626,7 +626,7 @@ fn urlize(allocator: *mem.Allocator, input: []const u8) ![]u8 {
626626}
627627
628628fn escapeHtml(allocator: *mem.Allocator, input: []const u8) ![]u8 {
629 var buf = try std.Buffer.initSize(allocator, 0);
629 var buf = std.ArrayList(u8).init(allocator);
630630 defer buf.deinit();
631631
632632 const out = buf.outStream();
......@@ -672,7 +672,7 @@ test "term color" {
672672}
673673
674674fn termColor(allocator: *mem.Allocator, input: []const u8) ![]u8 {
675 var buf = try std.Buffer.initSize(allocator, 0);
675 var buf = std.ArrayList(u8).init(allocator);
676676 defer buf.deinit();
677677
678678 var out = buf.outStream();
......@@ -1048,7 +1048,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
10481048 allocator,
10491049 &[_][]const u8{ tmp_dir_name, name_plus_ext },
10501050 );
1051 try io.writeFile(tmp_source_file_name, trimmed_raw_source);
1051 try fs.cwd().writeFile(tmp_source_file_name, trimmed_raw_source);
10521052
10531053 switch (code.id) {
10541054 Code.Id.Exe => |expected_outcome| code_block: {
......@@ -1106,18 +1106,17 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
11061106 }
11071107 }
11081108 if (expected_outcome == .BuildFail) {
1109 const result = try ChildProcess.exec(
1110 allocator,
1111 build_args.toSliceConst(),
1112 null,
1113 &env_map,
1114 max_doc_file_size,
1115 );
1109 const result = try ChildProcess.exec(.{
1110 .allocator = allocator,
1111 .argv = build_args.span(),
1112 .env_map = &env_map,
1113 .max_output_bytes = max_doc_file_size,
1114 });
11161115 switch (result.term) {
11171116 .Exited => |exit_code| {
11181117 if (exit_code == 0) {
11191118 warn("{}\nThe following command incorrectly succeeded:\n", .{result.stderr});
1120 for (build_args.toSliceConst()) |arg|
1119 for (build_args.span()) |arg|
11211120 warn("{} ", .{arg})
11221121 else
11231122 warn("\n", .{});
......@@ -1126,7 +1125,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
11261125 },
11271126 else => {
11281127 warn("{}\nThe following command crashed:\n", .{result.stderr});
1129 for (build_args.toSliceConst()) |arg|
1128 for (build_args.span()) |arg|
11301129 warn("{} ", .{arg})
11311130 else
11321131 warn("\n", .{});
......@@ -1138,7 +1137,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
11381137 try out.print("\n{}</code></pre>\n", .{colored_stderr});
11391138 break :code_block;
11401139 }
1141 const exec_result = exec(allocator, &env_map, build_args.toSliceConst()) catch
1140 const exec_result = exec(allocator, &env_map, build_args.span()) catch
11421141 return parseError(tokenizer, code.source_token, "example failed to compile", .{});
11431142
11441143 if (code.target_str) |triple| {
......@@ -1167,7 +1166,12 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
11671166 var exited_with_signal = false;
11681167
11691168 const result = if (expected_outcome == ExpectedOutcome.Fail) blk: {
1170 const result = try ChildProcess.exec(allocator, run_args, null, &env_map, max_doc_file_size);
1169 const result = try ChildProcess.exec(.{
1170 .allocator = allocator,
1171 .argv = run_args,
1172 .env_map = &env_map,
1173 .max_output_bytes = max_doc_file_size,
1174 });
11711175 switch (result.term) {
11721176 .Exited => |exit_code| {
11731177 if (exit_code == 0) {
......@@ -1234,7 +1238,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
12341238 try test_args.appendSlice(&[_][]const u8{ "-target", triple });
12351239 try out.print(" -target {}", .{triple});
12361240 }
1237 const result = exec(allocator, &env_map, test_args.toSliceConst()) catch return parseError(tokenizer, code.source_token, "test failed", .{});
1241 const result = exec(allocator, &env_map, test_args.span()) catch return parseError(tokenizer, code.source_token, "test failed", .{});
12381242 const escaped_stderr = try escapeHtml(allocator, result.stderr);
12391243 const escaped_stdout = try escapeHtml(allocator, result.stdout);
12401244 try out.print("\n{}{}</code></pre>\n", .{ escaped_stderr, escaped_stdout });
......@@ -1268,12 +1272,17 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
12681272 try out.print(" --release-small", .{});
12691273 },
12701274 }
1271 const result = try ChildProcess.exec(allocator, test_args.toSliceConst(), null, &env_map, max_doc_file_size);
1275 const result = try ChildProcess.exec(.{
1276 .allocator = allocator,
1277 .argv = test_args.span(),
1278 .env_map = &env_map,
1279 .max_output_bytes = max_doc_file_size,
1280 });
12721281 switch (result.term) {
12731282 .Exited => |exit_code| {
12741283 if (exit_code == 0) {
12751284 warn("{}\nThe following command incorrectly succeeded:\n", .{result.stderr});
1276 for (test_args.toSliceConst()) |arg|
1285 for (test_args.span()) |arg|
12771286 warn("{} ", .{arg})
12781287 else
12791288 warn("\n", .{});
......@@ -1282,7 +1291,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
12821291 },
12831292 else => {
12841293 warn("{}\nThe following command crashed:\n", .{result.stderr});
1285 for (test_args.toSliceConst()) |arg|
1294 for (test_args.span()) |arg|
12861295 warn("{} ", .{arg})
12871296 else
12881297 warn("\n", .{});
......@@ -1326,12 +1335,17 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
13261335 },
13271336 }
13281337
1329 const result = try ChildProcess.exec(allocator, test_args.toSliceConst(), null, &env_map, max_doc_file_size);
1338 const result = try ChildProcess.exec(.{
1339 .allocator = allocator,
1340 .argv = test_args.span(),
1341 .env_map = &env_map,
1342 .max_output_bytes = max_doc_file_size,
1343 });
13301344 switch (result.term) {
13311345 .Exited => |exit_code| {
13321346 if (exit_code == 0) {
13331347 warn("{}\nThe following command incorrectly succeeded:\n", .{result.stderr});
1334 for (test_args.toSliceConst()) |arg|
1348 for (test_args.span()) |arg|
13351349 warn("{} ", .{arg})
13361350 else
13371351 warn("\n", .{});
......@@ -1340,7 +1354,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
13401354 },
13411355 else => {
13421356 warn("{}\nThe following command crashed:\n", .{result.stderr});
1343 for (test_args.toSliceConst()) |arg|
1357 for (test_args.span()) |arg|
13441358 warn("{} ", .{arg})
13451359 else
13461360 warn("\n", .{});
......@@ -1418,12 +1432,17 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
14181432 }
14191433
14201434 if (maybe_error_match) |error_match| {
1421 const result = try ChildProcess.exec(allocator, build_args.toSliceConst(), null, &env_map, max_doc_file_size);
1435 const result = try ChildProcess.exec(.{
1436 .allocator = allocator,
1437 .argv = build_args.span(),
1438 .env_map = &env_map,
1439 .max_output_bytes = max_doc_file_size,
1440 });
14221441 switch (result.term) {
14231442 .Exited => |exit_code| {
14241443 if (exit_code == 0) {
14251444 warn("{}\nThe following command incorrectly succeeded:\n", .{result.stderr});
1426 for (build_args.toSliceConst()) |arg|
1445 for (build_args.span()) |arg|
14271446 warn("{} ", .{arg})
14281447 else
14291448 warn("\n", .{});
......@@ -1432,7 +1451,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
14321451 },
14331452 else => {
14341453 warn("{}\nThe following command crashed:\n", .{result.stderr});
1435 for (build_args.toSliceConst()) |arg|
1454 for (build_args.span()) |arg|
14361455 warn("{} ", .{arg})
14371456 else
14381457 warn("\n", .{});
......@@ -1447,7 +1466,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
14471466 const colored_stderr = try termColor(allocator, escaped_stderr);
14481467 try out.print("\n{}", .{colored_stderr});
14491468 } else {
1450 _ = exec(allocator, &env_map, build_args.toSliceConst()) catch return parseError(tokenizer, code.source_token, "example failed to compile", .{});
1469 _ = exec(allocator, &env_map, build_args.span()) catch return parseError(tokenizer, code.source_token, "example failed to compile", .{});
14511470 }
14521471 if (!code.is_inline) {
14531472 try out.print("</code></pre>\n", .{});
......@@ -1484,7 +1503,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
14841503 try test_args.appendSlice(&[_][]const u8{ "-target", triple });
14851504 try out.print(" -target {}", .{triple});
14861505 }
1487 const result = exec(allocator, &env_map, test_args.toSliceConst()) catch return parseError(tokenizer, code.source_token, "test failed", .{});
1506 const result = exec(allocator, &env_map, test_args.span()) catch return parseError(tokenizer, code.source_token, "test failed", .{});
14881507 const escaped_stderr = try escapeHtml(allocator, result.stderr);
14891508 const escaped_stdout = try escapeHtml(allocator, result.stdout);
14901509 try out.print("\n{}{}</code></pre>\n", .{ escaped_stderr, escaped_stdout });
......@@ -1497,7 +1516,7 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
14971516}
14981517
14991518fn exec(allocator: *mem.Allocator, env_map: *std.BufMap, args: []const []const u8) !ChildProcess.ExecResult {
1500 const result = try ChildProcess.exec2(.{
1519 const result = try ChildProcess.exec(.{
15011520 .allocator = allocator,
15021521 .argv = args,
15031522 .env_map = env_map,
doc/langref.html.in+2-2
......@@ -4953,7 +4953,7 @@ const mem = std.mem;
49534953test "cast *[1][*]const u8 to [*]const ?[*]const u8" {
49544954 const window_name = [1][*]const u8{"window name"};
49554955 const x: [*]const ?[*]const u8 = &window_name;
4956 assert(mem.eql(u8, std.mem.toSliceConst(u8, @ptrCast([*:0]const u8, x[0].?)), "window name"));
4956 assert(mem.eql(u8, std.mem.spanZ(@ptrCast([*:0]const u8, x[0].?)), "window name"));
49574957}
49584958 {#code_end#}
49594959 {#header_close#}
......@@ -9310,7 +9310,7 @@ test "string literal to constant slice" {
93109310 </p>
93119311 <p>
93129312 Sometimes the lifetime of a pointer may be more complicated. For example, when using
9313 {#syntax#}std.ArrayList(T).toSlice(){#endsyntax#}, the returned slice has a lifetime that remains
9313 {#syntax#}std.ArrayList(T).span(){#endsyntax#}, the returned slice has a lifetime that remains
93149314 valid until the next time the list is resized, such as by appending new elements.
93159315 </p>
93169316 <p>
lib/std/array_list.zig+29-4
......@@ -189,16 +189,30 @@ pub fn AlignedArrayList(comptime T: type, comptime alignment: ?u29) type {
189189 self.len += items.len;
190190 }
191191
192 /// Append a value to the list `n` times. Allocates more memory
193 /// as necessary.
192 /// Same as `append` except it returns the number of bytes written, which is always the same
193 /// as `m.len`. The purpose of this function existing is to match `std.io.OutStream` API.
194 /// This function may be called only when `T` is `u8`.
195 fn appendWrite(self: *Self, m: []const u8) !usize {
196 try self.appendSlice(m);
197 return m.len;
198 }
199
200 /// Initializes an OutStream which will append to the list.
201 /// This function may be called only when `T` is `u8`.
202 pub fn outStream(self: *Self) std.io.OutStream(*Self, error{OutOfMemory}, appendWrite) {
203 return .{ .context = self };
204 }
205
206 /// Append a value to the list `n` times.
207 /// Allocates more memory as necessary.
194208 pub fn appendNTimes(self: *Self, value: T, n: usize) !void {
195209 const old_len = self.len;
196210 try self.resize(self.len + n);
197211 mem.set(T, self.items[old_len..self.len], value);
198212 }
199213
200 /// Adjust the list's length to `new_len`. Doesn't initialize
201 /// added items if any.
214 /// Adjust the list's length to `new_len`.
215 /// Does not initialize added items if any.
202216 pub fn resize(self: *Self, new_len: usize) !void {
203217 try self.ensureCapacity(new_len);
204218 self.len = new_len;
......@@ -479,3 +493,14 @@ test "std.ArrayList: ArrayList(T) of struct T" {
479493 try root.sub_items.append(Item{ .integer = 42, .sub_items = ArrayList(Item).init(testing.allocator) });
480494 testing.expect(root.sub_items.items[0].integer == 42);
481495}
496
497test "std.ArrayList(u8) implements outStream" {
498 var buffer = ArrayList(u8).init(std.testing.allocator);
499 defer buffer.deinit();
500
501 const x: i32 = 42;
502 const y: i32 = 1234;
503 try buffer.outStream().print("x: {}\ny: {}\n", .{ x, y });
504
505 testing.expectEqualSlices(u8, "x: 42\ny: 1234\n", buffer.span());
506}
lib/std/array_list_sentineled.zig created+224
......@@ -0,0 +1,224 @@
1const std = @import("std.zig");
2const debug = std.debug;
3const mem = std.mem;
4const Allocator = mem.Allocator;
5const assert = debug.assert;
6const testing = std.testing;
7const ArrayList = std.ArrayList;
8
9/// A contiguous, growable list of items in memory, with a sentinel after them.
10/// The sentinel is maintained when appending, resizing, etc.
11/// If you do not need a sentinel, consider using `ArrayList` instead.
12pub fn ArrayListSentineled(comptime T: type, comptime sentinel: T) type {
13 return struct {
14 list: ArrayList(T),
15
16 const Self = @This();
17
18 /// Must deinitialize with deinit.
19 pub fn init(allocator: *Allocator, m: []const T) !Self {
20 var self = try initSize(allocator, m.len);
21 mem.copy(T, self.list.items, m);
22 return self;
23 }
24
25 /// Initialize memory to size bytes of undefined values.
26 /// Must deinitialize with deinit.
27 pub fn initSize(allocator: *Allocator, size: usize) !Self {
28 var self = initNull(allocator);
29 try self.resize(size);
30 return self;
31 }
32
33 /// Initialize with capacity to hold at least num bytes.
34 /// Must deinitialize with deinit.
35 pub fn initCapacity(allocator: *Allocator, num: usize) !Self {
36 var self = Self{ .list = try ArrayList(T).initCapacity(allocator, num + 1) };
37 self.list.appendAssumeCapacity(sentinel);
38 return self;
39 }
40
41 /// Must deinitialize with deinit.
42 /// None of the other operations are valid until you do one of these:
43 /// * `replaceContents`
44 /// * `resize`
45 pub fn initNull(allocator: *Allocator) Self {
46 return Self{ .list = ArrayList(T).init(allocator) };
47 }
48
49 /// Must deinitialize with deinit.
50 pub fn initFromBuffer(buffer: Self) !Self {
51 return Self.init(buffer.list.allocator, buffer.span());
52 }
53
54 /// Takes ownership of the passed in slice. The slice must have been
55 /// allocated with `allocator`.
56 /// Must deinitialize with deinit.
57 pub fn fromOwnedSlice(allocator: *Allocator, slice: []T) !Self {
58 var self = Self{ .list = ArrayList(T).fromOwnedSlice(allocator, slice) };
59 try self.list.append(sentinel);
60 return self;
61 }
62
63 /// The caller owns the returned memory. The list becomes null and is safe to `deinit`.
64 pub fn toOwnedSlice(self: *Self) [:sentinel]T {
65 const allocator = self.list.allocator;
66 const result = self.list.toOwnedSlice();
67 self.* = initNull(allocator);
68 return result[0 .. result.len - 1 :sentinel];
69 }
70
71 /// Only works when `T` is `u8`.
72 pub fn allocPrint(allocator: *Allocator, comptime format: []const u8, args: var) !Self {
73 const size = std.math.cast(usize, std.fmt.count(format, args)) catch |err| switch (err) {
74 error.Overflow => return error.OutOfMemory,
75 };
76 var self = try Self.initSize(allocator, size);
77 assert((std.fmt.bufPrint(self.list.items, format, args) catch unreachable).len == size);
78 return self;
79 }
80
81 pub fn deinit(self: *Self) void {
82 self.list.deinit();
83 }
84
85 pub fn span(self: var) @TypeOf(self.list.items[0 .. self.list.len - 1 :sentinel]) {
86 return self.list.span()[0..self.len() :sentinel];
87 }
88
89 pub fn shrink(self: *Self, new_len: usize) void {
90 assert(new_len <= self.len());
91 self.list.shrink(new_len + 1);
92 self.list.items[self.len()] = sentinel;
93 }
94
95 pub fn resize(self: *Self, new_len: usize) !void {
96 try self.list.resize(new_len + 1);
97 self.list.items[self.len()] = sentinel;
98 }
99
100 pub fn isNull(self: Self) bool {
101 return self.list.len == 0;
102 }
103
104 pub fn len(self: Self) usize {
105 return self.list.len - 1;
106 }
107
108 pub fn capacity(self: Self) usize {
109 return if (self.list.items.len > 0)
110 self.list.items.len - 1
111 else
112 0;
113 }
114
115 pub fn appendSlice(self: *Self, m: []const T) !void {
116 const old_len = self.len();
117 try self.resize(old_len + m.len);
118 mem.copy(T, self.list.span()[old_len..], m);
119 }
120
121 pub fn append(self: *Self, byte: T) !void {
122 const old_len = self.len();
123 try self.resize(old_len + 1);
124 self.list.span()[old_len] = byte;
125 }
126
127 pub fn eql(self: Self, m: []const T) bool {
128 return mem.eql(T, self.span(), m);
129 }
130
131 pub fn startsWith(self: Self, m: []const T) bool {
132 if (self.len() < m.len) return false;
133 return mem.eql(T, self.list.items[0..m.len], m);
134 }
135
136 pub fn endsWith(self: Self, m: []const T) bool {
137 const l = self.len();
138 if (l < m.len) return false;
139 const start = l - m.len;
140 return mem.eql(T, self.list.items[start..l], m);
141 }
142
143 pub fn replaceContents(self: *Self, m: []const T) !void {
144 try self.resize(m.len);
145 mem.copy(T, self.list.span(), m);
146 }
147
148 /// Initializes an OutStream which will append to the list.
149 /// This function may be called only when `T` is `u8`.
150 pub fn outStream(self: *Self) std.io.OutStream(*Self, error{OutOfMemory}, appendWrite) {
151 return .{ .context = self };
152 }
153
154 /// Same as `append` except it returns the number of bytes written, which is always the same
155 /// as `m.len`. The purpose of this function existing is to match `std.io.OutStream` API.
156 /// This function may be called only when `T` is `u8`.
157 pub fn appendWrite(self: *Self, m: []const u8) !usize {
158 try self.appendSlice(m);
159 return m.len;
160 }
161 };
162}
163
164test "simple" {
165 var buf = try ArrayListSentineled(u8, 0).init(testing.allocator, "");
166 defer buf.deinit();
167
168 testing.expect(buf.len() == 0);
169 try buf.appendSlice("hello");
170 try buf.appendSlice(" ");
171 try buf.appendSlice("world");
172 testing.expect(buf.eql("hello world"));
173 testing.expect(mem.eql(u8, mem.spanZ(buf.span().ptr), buf.span()));
174
175 var buf2 = try ArrayListSentineled(u8, 0).initFromBuffer(buf);
176 defer buf2.deinit();
177 testing.expect(buf.eql(buf2.span()));
178
179 testing.expect(buf.startsWith("hell"));
180 testing.expect(buf.endsWith("orld"));
181
182 try buf2.resize(4);
183 testing.expect(buf.startsWith(buf2.span()));
184}
185
186test "initSize" {
187 var buf = try ArrayListSentineled(u8, 0).initSize(testing.allocator, 3);
188 defer buf.deinit();
189 testing.expect(buf.len() == 3);
190 try buf.appendSlice("hello");
191 testing.expect(mem.eql(u8, buf.span()[3..], "hello"));
192}
193
194test "initCapacity" {
195 var buf = try ArrayListSentineled(u8, 0).initCapacity(testing.allocator, 10);
196 defer buf.deinit();
197 testing.expect(buf.len() == 0);
198 testing.expect(buf.capacity() >= 10);
199 const old_cap = buf.capacity();
200 try buf.appendSlice("hello");
201 testing.expect(buf.len() == 5);
202 testing.expect(buf.capacity() == old_cap);
203 testing.expect(mem.eql(u8, buf.span(), "hello"));
204}
205
206test "print" {
207 var buf = try ArrayListSentineled(u8, 0).init(testing.allocator, "");
208 defer buf.deinit();
209
210 try buf.outStream().print("Hello {} the {}", .{ 2, "world" });
211 testing.expect(buf.eql("Hello 2 the world"));
212}
213
214test "outStream" {
215 var buffer = try ArrayListSentineled(u8, 0).initSize(testing.allocator, 0);
216 defer buffer.deinit();
217 const buf_stream = buffer.outStream();
218
219 const x: i32 = 42;
220 const y: i32 = 1234;
221 try buf_stream.print("x: {}\ny: {}\n", .{ x, y });
222
223 testing.expect(mem.eql(u8, buffer.span(), "x: 42\ny: 1234\n"));
224}
lib/std/atomic/queue.zig+1-1
......@@ -227,7 +227,7 @@ fn startPuts(ctx: *Context) u8 {
227227 var r = std.rand.DefaultPrng.init(0xdeadbeef);
228228 while (put_count != 0) : (put_count -= 1) {
229229 std.time.sleep(1); // let the os scheduler be our fuzz
230 const x = @bitCast(i32, r.random.scalar(u32));
230 const x = @bitCast(i32, r.random.int(u32));
231231 const node = ctx.allocator.create(Queue(i32).Node) catch unreachable;
232232 node.* = .{
233233 .prev = undefined,
lib/std/atomic/stack.zig+1-1
......@@ -150,7 +150,7 @@ fn startPuts(ctx: *Context) u8 {
150150 var r = std.rand.DefaultPrng.init(0xdeadbeef);
151151 while (put_count != 0) : (put_count -= 1) {
152152 std.time.sleep(1); // let the os scheduler be our fuzz
153 const x = @bitCast(i32, r.random.scalar(u32));
153 const x = @bitCast(i32, r.random.int(u32));
154154 const node = ctx.allocator.create(Stack(i32).Node) catch unreachable;
155155 node.* = Stack(i32).Node{
156156 .next = undefined,
lib/std/buffer.zig deleted-225
......@@ -1,225 +0,0 @@
1const std = @import("std.zig");
2const debug = std.debug;
3const mem = std.mem;
4const Allocator = mem.Allocator;
5const assert = debug.assert;
6const testing = std.testing;
7const ArrayList = std.ArrayList;
8
9/// A buffer that allocates memory and maintains a null byte at the end.
10pub const Buffer = struct {
11 list: ArrayList(u8),
12
13 /// Must deinitialize with deinit.
14 pub fn init(allocator: *Allocator, m: []const u8) !Buffer {
15 var self = try initSize(allocator, m.len);
16 mem.copy(u8, self.list.items, m);
17 return self;
18 }
19
20 /// Initialize memory to size bytes of undefined values.
21 /// Must deinitialize with deinit.
22 pub fn initSize(allocator: *Allocator, size: usize) !Buffer {
23 var self = initNull(allocator);
24 try self.resize(size);
25 return self;
26 }
27
28 /// Initialize with capacity to hold at least num bytes.
29 /// Must deinitialize with deinit.
30 pub fn initCapacity(allocator: *Allocator, num: usize) !Buffer {
31 var self = Buffer{ .list = try ArrayList(u8).initCapacity(allocator, num + 1) };
32 self.list.appendAssumeCapacity(0);
33 return self;
34 }
35
36 /// Must deinitialize with deinit.
37 /// None of the other operations are valid until you do one of these:
38 /// * ::replaceContents
39 /// * ::resize
40 pub fn initNull(allocator: *Allocator) Buffer {
41 return Buffer{ .list = ArrayList(u8).init(allocator) };
42 }
43
44 /// Must deinitialize with deinit.
45 pub fn initFromBuffer(buffer: Buffer) !Buffer {
46 return Buffer.init(buffer.list.allocator, buffer.toSliceConst());
47 }
48
49 /// Buffer takes ownership of the passed in slice. The slice must have been
50 /// allocated with `allocator`.
51 /// Must deinitialize with deinit.
52 pub fn fromOwnedSlice(allocator: *Allocator, slice: []u8) !Buffer {
53 var self = Buffer{ .list = ArrayList(u8).fromOwnedSlice(allocator, slice) };
54 try self.list.append(0);
55 return self;
56 }
57
58 /// The caller owns the returned memory. The Buffer becomes null and
59 /// is safe to `deinit`.
60 pub fn toOwnedSlice(self: *Buffer) [:0]u8 {
61 const allocator = self.list.allocator;
62 const result = self.list.toOwnedSlice();
63 self.* = initNull(allocator);
64 return result[0 .. result.len - 1 :0];
65 }
66
67 pub fn allocPrint(allocator: *Allocator, comptime format: []const u8, args: var) !Buffer {
68 const size = std.math.cast(usize, std.fmt.count(format, args)) catch |err| switch (err) {
69 error.Overflow => return error.OutOfMemory,
70 };
71 var self = try Buffer.initSize(allocator, size);
72 assert((std.fmt.bufPrint(self.list.items, format, args) catch unreachable).len == size);
73 return self;
74 }
75
76 pub fn deinit(self: *Buffer) void {
77 self.list.deinit();
78 }
79
80 pub fn span(self: var) @TypeOf(self.list.items[0 .. self.list.len - 1 :0]) {
81 return self.list.span()[0..self.len() :0];
82 }
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 }
93
94 pub fn shrink(self: *Buffer, new_len: usize) void {
95 assert(new_len <= self.len());
96 self.list.shrink(new_len + 1);
97 self.list.items[self.len()] = 0;
98 }
99
100 pub fn resize(self: *Buffer, new_len: usize) !void {
101 try self.list.resize(new_len + 1);
102 self.list.items[self.len()] = 0;
103 }
104
105 pub fn isNull(self: Buffer) bool {
106 return self.list.len == 0;
107 }
108
109 pub fn len(self: Buffer) usize {
110 return self.list.len - 1;
111 }
112
113 pub fn capacity(self: Buffer) usize {
114 return if (self.list.items.len > 0)
115 self.list.items.len - 1
116 else
117 0;
118 }
119
120 pub fn append(self: *Buffer, m: []const u8) !void {
121 const old_len = self.len();
122 try self.resize(old_len + m.len);
123 mem.copy(u8, self.list.toSlice()[old_len..], m);
124 }
125
126 pub fn appendByte(self: *Buffer, byte: u8) !void {
127 const old_len = self.len();
128 try self.resize(old_len + 1);
129 self.list.toSlice()[old_len] = byte;
130 }
131
132 pub fn eql(self: Buffer, m: []const u8) bool {
133 return mem.eql(u8, self.toSliceConst(), m);
134 }
135
136 pub fn startsWith(self: Buffer, m: []const u8) bool {
137 if (self.len() < m.len) return false;
138 return mem.eql(u8, self.list.items[0..m.len], m);
139 }
140
141 pub fn endsWith(self: Buffer, m: []const u8) bool {
142 const l = self.len();
143 if (l < m.len) return false;
144 const start = l - m.len;
145 return mem.eql(u8, self.list.items[start..l], m);
146 }
147
148 pub fn replaceContents(self: *Buffer, m: []const u8) !void {
149 try self.resize(m.len);
150 mem.copy(u8, self.list.toSlice(), m);
151 }
152
153 pub fn outStream(self: *Buffer) std.io.OutStream(*Buffer, error{OutOfMemory}, appendWrite) {
154 return .{ .context = self };
155 }
156
157 /// Same as `append` except it returns the number of bytes written, which is always the same
158 /// as `m.len`. The purpose of this function existing is to match `std.io.OutStream` API.
159 pub fn appendWrite(self: *Buffer, m: []const u8) !usize {
160 try self.append(m);
161 return m.len;
162 }
163};
164
165test "simple Buffer" {
166 var buf = try Buffer.init(testing.allocator, "");
167 defer buf.deinit();
168
169 testing.expect(buf.len() == 0);
170 try buf.append("hello");
171 try buf.append(" ");
172 try buf.append("world");
173 testing.expect(buf.eql("hello world"));
174 testing.expect(mem.eql(u8, mem.toSliceConst(u8, buf.toSliceConst().ptr), buf.toSliceConst()));
175
176 var buf2 = try Buffer.initFromBuffer(buf);
177 defer buf2.deinit();
178 testing.expect(buf.eql(buf2.toSliceConst()));
179
180 testing.expect(buf.startsWith("hell"));
181 testing.expect(buf.endsWith("orld"));
182
183 try buf2.resize(4);
184 testing.expect(buf.startsWith(buf2.toSlice()));
185}
186
187test "Buffer.initSize" {
188 var buf = try Buffer.initSize(testing.allocator, 3);
189 defer buf.deinit();
190 testing.expect(buf.len() == 3);
191 try buf.append("hello");
192 testing.expect(mem.eql(u8, buf.toSliceConst()[3..], "hello"));
193}
194
195test "Buffer.initCapacity" {
196 var buf = try Buffer.initCapacity(testing.allocator, 10);
197 defer buf.deinit();
198 testing.expect(buf.len() == 0);
199 testing.expect(buf.capacity() >= 10);
200 const old_cap = buf.capacity();
201 try buf.append("hello");
202 testing.expect(buf.len() == 5);
203 testing.expect(buf.capacity() == old_cap);
204 testing.expect(mem.eql(u8, buf.toSliceConst(), "hello"));
205}
206
207test "Buffer.print" {
208 var buf = try Buffer.init(testing.allocator, "");
209 defer buf.deinit();
210
211 try buf.outStream().print("Hello {} the {}", .{ 2, "world" });
212 testing.expect(buf.eql("Hello 2 the world"));
213}
214
215test "Buffer.outStream" {
216 var buffer = try Buffer.initSize(testing.allocator, 0);
217 defer buffer.deinit();
218 const buf_stream = buffer.outStream();
219
220 const x: i32 = 42;
221 const y: i32 = 1234;
222 try buf_stream.print("x: {}\ny: {}\n", .{ x, y });
223
224 testing.expect(mem.eql(u8, buffer.toSlice(), "x: 42\ny: 1234\n"));
225}
lib/std/build.zig+29-32
......@@ -355,7 +355,7 @@ pub const Builder = struct {
355355 }
356356 }
357357
358 for (wanted_steps.toSliceConst()) |s| {
358 for (wanted_steps.span()) |s| {
359359 try self.makeOneStep(s);
360360 }
361361 }
......@@ -372,7 +372,7 @@ pub const Builder = struct {
372372 const uninstall_tls = @fieldParentPtr(TopLevelStep, "step", uninstall_step);
373373 const self = @fieldParentPtr(Builder, "uninstall_tls", uninstall_tls);
374374
375 for (self.installed_files.toSliceConst()) |installed_file| {
375 for (self.installed_files.span()) |installed_file| {
376376 const full_path = self.getInstallPath(installed_file.dir, installed_file.path);
377377 if (self.verbose) {
378378 warn("rm {}\n", .{full_path});
......@@ -390,7 +390,7 @@ pub const Builder = struct {
390390 }
391391 s.loop_flag = true;
392392
393 for (s.dependencies.toSlice()) |dep| {
393 for (s.dependencies.span()) |dep| {
394394 self.makeOneStep(dep) catch |err| {
395395 if (err == error.DependencyLoopDetected) {
396396 warn(" {}\n", .{s.name});
......@@ -405,7 +405,7 @@ pub const Builder = struct {
405405 }
406406
407407 fn getTopLevelStepByName(self: *Builder, name: []const u8) !*Step {
408 for (self.top_level_steps.toSliceConst()) |top_level_step| {
408 for (self.top_level_steps.span()) |top_level_step| {
409409 if (mem.eql(u8, top_level_step.step.name, name)) {
410410 return &top_level_step.step;
411411 }
......@@ -470,7 +470,7 @@ pub const Builder = struct {
470470 return null;
471471 },
472472 UserValue.Scalar => |s| return &[_][]const u8{s},
473 UserValue.List => |lst| return lst.toSliceConst(),
473 UserValue.List => |lst| return lst.span(),
474474 },
475475 }
476476 }
......@@ -866,7 +866,7 @@ pub const Builder = struct {
866866 pub fn findProgram(self: *Builder, names: []const []const u8, paths: []const []const u8) ![]const u8 {
867867 // TODO report error for ambiguous situations
868868 const exe_extension = @as(CrossTarget, .{}).exeFileExt();
869 for (self.search_prefixes.toSliceConst()) |search_prefix| {
869 for (self.search_prefixes.span()) |search_prefix| {
870870 for (names) |name| {
871871 if (fs.path.isAbsolute(name)) {
872872 return name;
......@@ -1010,7 +1010,7 @@ pub const Builder = struct {
10101010 .desc = tok_it.rest(),
10111011 });
10121012 }
1013 return list.toSliceConst();
1013 return list.span();
10141014 }
10151015
10161016 fn getPkgConfigList(self: *Builder) ![]const PkgConfigPkg {
......@@ -1139,7 +1139,7 @@ pub const LibExeObjStep = struct {
11391139 out_lib_filename: []const u8,
11401140 out_pdb_filename: []const u8,
11411141 packages: ArrayList(Pkg),
1142 build_options_contents: std.Buffer,
1142 build_options_contents: std.ArrayList(u8),
11431143 system_linker_hack: bool = false,
11441144
11451145 object_src: []const u8,
......@@ -1274,7 +1274,7 @@ pub const LibExeObjStep = struct {
12741274 .lib_paths = ArrayList([]const u8).init(builder.allocator),
12751275 .framework_dirs = ArrayList([]const u8).init(builder.allocator),
12761276 .object_src = undefined,
1277 .build_options_contents = std.Buffer.initSize(builder.allocator, 0) catch unreachable,
1277 .build_options_contents = std.ArrayList(u8).init(builder.allocator),
12781278 .c_std = Builder.CStd.C99,
12791279 .override_lib_dir = null,
12801280 .main_pkg_path = null,
......@@ -1395,7 +1395,7 @@ pub const LibExeObjStep = struct {
13951395 if (isLibCLibrary(name)) {
13961396 return self.is_linking_libc;
13971397 }
1398 for (self.link_objects.toSliceConst()) |link_object| {
1398 for (self.link_objects.span()) |link_object| {
13991399 switch (link_object) {
14001400 LinkObject.SystemLib => |n| if (mem.eql(u8, n, name)) return true,
14011401 else => continue,
......@@ -1599,10 +1599,7 @@ pub const LibExeObjStep = struct {
15991599 self.main_pkg_path = dir_path;
16001600 }
16011601
1602 /// Deprecated; just set the field directly.
1603 pub fn setDisableGenH(self: *LibExeObjStep, is_disabled: bool) void {
1604 self.emit_h = !is_disabled;
1605 }
1602 pub const setDisableGenH = @compileError("deprecated; set the emit_h field directly");
16061603
16071604 pub fn setLibCFile(self: *LibExeObjStep, libc_file: ?[]const u8) void {
16081605 self.libc_file = libc_file;
......@@ -1762,7 +1759,7 @@ pub const LibExeObjStep = struct {
17621759 self.include_dirs.append(IncludeDir{ .OtherStep = other }) catch unreachable;
17631760
17641761 // Inherit dependency on system libraries
1765 for (other.link_objects.toSliceConst()) |link_object| {
1762 for (other.link_objects.span()) |link_object| {
17661763 switch (link_object) {
17671764 .SystemLib => |name| self.linkSystemLibrary(name),
17681765 else => continue,
......@@ -1802,7 +1799,7 @@ pub const LibExeObjStep = struct {
18021799
18031800 if (self.root_src) |root_src| try zig_args.append(root_src.getPath(builder));
18041801
1805 for (self.link_objects.toSlice()) |link_object| {
1802 for (self.link_objects.span()) |link_object| {
18061803 switch (link_object) {
18071804 .StaticPath => |static_path| {
18081805 try zig_args.append("--object");
......@@ -1850,12 +1847,12 @@ pub const LibExeObjStep = struct {
18501847 }
18511848 }
18521849
1853 if (self.build_options_contents.len() > 0) {
1850 if (self.build_options_contents.len > 0) {
18541851 const build_options_file = try fs.path.join(
18551852 builder.allocator,
18561853 &[_][]const u8{ builder.cache_root, builder.fmt("{}_build_options.zig", .{self.name}) },
18571854 );
1858 try std.io.writeFile(build_options_file, self.build_options_contents.toSliceConst());
1855 try fs.cwd().writeFile(build_options_file, self.build_options_contents.span());
18591856 try zig_args.append("--pkg-begin");
18601857 try zig_args.append("build_options");
18611858 try zig_args.append(builder.pathFromRoot(build_options_file));
......@@ -1963,22 +1960,22 @@ pub const LibExeObjStep = struct {
19631960 try zig_args.append(cross.cpu.model.name);
19641961 }
19651962 } else {
1966 var mcpu_buffer = try std.Buffer.init(builder.allocator, "-mcpu=");
1967 try mcpu_buffer.append(cross.cpu.model.name);
1963 var mcpu_buffer = std.ArrayList(u8).init(builder.allocator);
1964
1965 try mcpu_buffer.outStream().print("-mcpu={}", .{cross.cpu.model.name});
19681966
19691967 for (all_features) |feature, i_usize| {
19701968 const i = @intCast(std.Target.Cpu.Feature.Set.Index, i_usize);
19711969 const in_cpu_set = populated_cpu_features.isEnabled(i);
19721970 const in_actual_set = cross.cpu.features.isEnabled(i);
19731971 if (in_cpu_set and !in_actual_set) {
1974 try mcpu_buffer.appendByte('-');
1975 try mcpu_buffer.append(feature.name);
1972 try mcpu_buffer.outStream().print("-{}", .{feature.name});
19761973 } else if (!in_cpu_set and in_actual_set) {
1977 try mcpu_buffer.appendByte('+');
1978 try mcpu_buffer.append(feature.name);
1974 try mcpu_buffer.outStream().print("+{}", .{feature.name});
19791975 }
19801976 }
1981 try zig_args.append(mcpu_buffer.toSliceConst());
1977
1978 try zig_args.append(mcpu_buffer.toOwnedSlice());
19821979 }
19831980
19841981 if (self.target.dynamic_linker.get()) |dynamic_linker| {
......@@ -2040,7 +2037,7 @@ pub const LibExeObjStep = struct {
20402037 try zig_args.append("--test-cmd-bin");
20412038 },
20422039 }
2043 for (self.packages.toSliceConst()) |pkg| {
2040 for (self.packages.span()) |pkg| {
20442041 try zig_args.append("--pkg-begin");
20452042 try zig_args.append(pkg.name);
20462043 try zig_args.append(builder.pathFromRoot(pkg.path));
......@@ -2057,7 +2054,7 @@ pub const LibExeObjStep = struct {
20572054 try zig_args.append("--pkg-end");
20582055 }
20592056
2060 for (self.include_dirs.toSliceConst()) |include_dir| {
2057 for (self.include_dirs.span()) |include_dir| {
20612058 switch (include_dir) {
20622059 .RawPath => |include_path| {
20632060 try zig_args.append("-I");
......@@ -2075,18 +2072,18 @@ pub const LibExeObjStep = struct {
20752072 }
20762073 }
20772074
2078 for (self.lib_paths.toSliceConst()) |lib_path| {
2075 for (self.lib_paths.span()) |lib_path| {
20792076 try zig_args.append("-L");
20802077 try zig_args.append(lib_path);
20812078 }
20822079
2083 for (self.c_macros.toSliceConst()) |c_macro| {
2080 for (self.c_macros.span()) |c_macro| {
20842081 try zig_args.append("-D");
20852082 try zig_args.append(c_macro);
20862083 }
20872084
20882085 if (self.target.isDarwin()) {
2089 for (self.framework_dirs.toSliceConst()) |dir| {
2086 for (self.framework_dirs.span()) |dir| {
20902087 try zig_args.append("-F");
20912088 try zig_args.append(dir);
20922089 }
......@@ -2146,12 +2143,12 @@ pub const LibExeObjStep = struct {
21462143 }
21472144
21482145 if (self.kind == Kind.Test) {
2149 try builder.spawnChild(zig_args.toSliceConst());
2146 try builder.spawnChild(zig_args.span());
21502147 } else {
21512148 try zig_args.append("--cache");
21522149 try zig_args.append("on");
21532150
2154 const output_dir_nl = try builder.execFromStep(zig_args.toSliceConst(), &self.step);
2151 const output_dir_nl = try builder.execFromStep(zig_args.span(), &self.step);
21552152 const build_output_dir = mem.trimRight(u8, output_dir_nl, "\r\n");
21562153
21572154 if (self.output_dir) |output_dir| {
lib/std/build/emit_raw.zig+6-6
......@@ -72,7 +72,7 @@ const BinaryElfOutput = struct {
7272 newSegment.binaryOffset = 0;
7373 newSegment.firstSection = null;
7474
75 for (self.sections.toSlice()) |section| {
75 for (self.sections.span()) |section| {
7676 if (sectionWithinSegment(section, phdr)) {
7777 if (section.segment) |sectionSegment| {
7878 if (sectionSegment.elfOffset > newSegment.elfOffset) {
......@@ -92,7 +92,7 @@ const BinaryElfOutput = struct {
9292 }
9393 }
9494
95 sort.sort(*BinaryElfSegment, self.segments.toSlice(), segmentSortCompare);
95 sort.sort(*BinaryElfSegment, self.segments.span(), segmentSortCompare);
9696
9797 if (self.segments.len > 0) {
9898 const firstSegment = self.segments.at(0);
......@@ -105,19 +105,19 @@ const BinaryElfOutput = struct {
105105
106106 const basePhysicalAddress = firstSegment.physicalAddress;
107107
108 for (self.segments.toSlice()) |segment| {
108 for (self.segments.span()) |segment| {
109109 segment.binaryOffset = segment.physicalAddress - basePhysicalAddress;
110110 }
111111 }
112112 }
113113
114 for (self.sections.toSlice()) |section| {
114 for (self.sections.span()) |section| {
115115 if (section.segment) |segment| {
116116 section.binaryOffset = segment.binaryOffset + (section.elfOffset - segment.elfOffset);
117117 }
118118 }
119119
120 sort.sort(*BinaryElfSection, self.sections.toSlice(), sectionSortCompare);
120 sort.sort(*BinaryElfSection, self.sections.span(), sectionSortCompare);
121121
122122 return self;
123123 }
......@@ -165,7 +165,7 @@ fn emitRaw(allocator: *Allocator, elf_path: []const u8, raw_path: []const u8) !v
165165 var binary_elf_output = try BinaryElfOutput.parse(allocator, elf_file);
166166 defer binary_elf_output.deinit();
167167
168 for (binary_elf_output.sections.toSlice()) |section| {
168 for (binary_elf_output.sections.span()) |section| {
169169 try writeBinaryElfSection(elf_file, out_file, section);
170170 }
171171}
lib/std/build/run.zig+3-3
......@@ -139,7 +139,7 @@ pub const RunStep = struct {
139139 const cwd = if (self.cwd) |cwd| self.builder.pathFromRoot(cwd) else self.builder.build_root;
140140
141141 var argv_list = ArrayList([]const u8).init(self.builder.allocator);
142 for (self.argv.toSlice()) |arg| {
142 for (self.argv.span()) |arg| {
143143 switch (arg) {
144144 Arg.Bytes => |bytes| try argv_list.append(bytes),
145145 Arg.Artifact => |artifact| {
......@@ -153,7 +153,7 @@ pub const RunStep = struct {
153153 }
154154 }
155155
156 const argv = argv_list.toSliceConst();
156 const argv = argv_list.span();
157157
158158 const child = std.ChildProcess.init(argv, self.builder.allocator) catch unreachable;
159159 defer child.deinit();
......@@ -289,7 +289,7 @@ pub const RunStep = struct {
289289 }
290290
291291 fn addPathForDynLibs(self: *RunStep, artifact: *LibExeObjStep) void {
292 for (artifact.link_objects.toSliceConst()) |link_object| {
292 for (artifact.link_objects.span()) |link_object| {
293293 switch (link_object) {
294294 .OtherStep => |other| {
295295 if (other.target.isWindows() and other.isDynamicLibrary()) {
lib/std/build/translate_c.zig+1-1
......@@ -71,7 +71,7 @@ pub const TranslateCStep = struct {
7171
7272 try argv_list.append(self.source.getPath(self.builder));
7373
74 const output_path_nl = try self.builder.execFromStep(argv_list.toSliceConst(), &self.step);
74 const output_path_nl = try self.builder.execFromStep(argv_list.span(), &self.step);
7575 const output_path = mem.trimRight(u8, output_path_nl, "\r\n");
7676
7777 self.out_basename = fs.path.basename(output_path);
lib/std/build/write_file.zig+2-2
......@@ -59,7 +59,7 @@ pub const WriteFileStep = struct {
5959 // new random bytes when WriteFileStep implementation is modified
6060 // in a non-backwards-compatible way.
6161 hash.update("eagVR1dYXoE7ARDP");
62 for (self.files.toSliceConst()) |file| {
62 for (self.files.span()) |file| {
6363 hash.update(file.basename);
6464 hash.update(file.bytes);
6565 hash.update("|");
......@@ -80,7 +80,7 @@ pub const WriteFileStep = struct {
8080 };
8181 var dir = try fs.cwd().openDir(self.output_dir, .{});
8282 defer dir.close();
83 for (self.files.toSliceConst()) |file| {
83 for (self.files.span()) |file| {
8484 dir.writeFile(file.basename, file.bytes) catch |err| {
8585 warn("unable to write {} into {}: {}\n", .{
8686 file.basename,
lib/std/c.zig+45-13
......@@ -73,7 +73,6 @@ pub extern "c" fn abort() noreturn;
7373pub extern "c" fn exit(code: c_int) noreturn;
7474pub extern "c" fn isatty(fd: fd_t) c_int;
7575pub extern "c" fn close(fd: fd_t) c_int;
76pub extern "c" fn fstat(fd: fd_t, buf: *Stat) c_int;
7776pub extern "c" fn fstatat(dirfd: fd_t, path: [*:0]const u8, stat_buf: *Stat, flags: u32) c_int;
7877pub extern "c" fn lseek(fd: fd_t, offset: off_t, whence: c_int) off_t;
7978pub extern "c" fn open(path: [*:0]const u8, oflag: c_uint, ...) c_int;
......@@ -86,7 +85,6 @@ pub extern "c" fn pread(fd: fd_t, buf: [*]u8, nbyte: usize, offset: u64) isize;
8685pub extern "c" fn preadv(fd: c_int, iov: [*]const iovec, iovcnt: c_uint, offset: u64) isize;
8786pub extern "c" fn writev(fd: c_int, iov: [*]const iovec_const, iovcnt: c_uint) isize;
8887pub extern "c" fn pwritev(fd: c_int, iov: [*]const iovec_const, iovcnt: c_uint, offset: u64) isize;
89pub extern "c" fn stat(noalias path: [*:0]const u8, noalias buf: *Stat) c_int;
9088pub extern "c" fn write(fd: fd_t, buf: [*]const u8, nbyte: usize) isize;
9189pub extern "c" fn pwrite(fd: fd_t, buf: [*]const u8, nbyte: usize, offset: u64) isize;
9290pub extern "c" fn mmap(addr: ?*align(page_size) c_void, len: usize, prot: c_uint, flags: c_uint, fd: fd_t, offset: u64) *c_void;
......@@ -114,15 +112,10 @@ pub extern "c" fn dup2(old_fd: fd_t, new_fd: fd_t) c_int;
114112pub extern "c" fn readlink(noalias path: [*:0]const u8, noalias buf: [*]u8, bufsize: usize) isize;
115113pub extern "c" fn readlinkat(dirfd: fd_t, noalias path: [*:0]const u8, noalias buf: [*]u8, bufsize: usize) isize;
116114pub extern "c" fn realpath(noalias file_name: [*:0]const u8, noalias resolved_name: [*]u8) ?[*:0]u8;
117pub extern "c" fn sigprocmask(how: c_int, noalias set: ?*const sigset_t, noalias oset: ?*sigset_t) c_int;
118pub extern "c" fn gettimeofday(noalias tv: ?*timeval, noalias tz: ?*timezone) c_int;
119pub extern "c" fn sigaction(sig: c_int, noalias act: *const Sigaction, noalias oact: ?*Sigaction) c_int;
120pub extern "c" fn nanosleep(rqtp: *const timespec, rmtp: ?*timespec) c_int;
121115pub extern "c" fn setreuid(ruid: c_uint, euid: c_uint) c_int;
122116pub extern "c" fn setregid(rgid: c_uint, egid: c_uint) c_int;
123117pub extern "c" fn rmdir(path: [*:0]const u8) c_int;
124118pub extern "c" fn getenv(name: [*:0]const u8) ?[*:0]u8;
125pub extern "c" fn getrusage(who: c_int, usage: *rusage) c_int;
126119pub extern "c" fn sysctl(name: [*]const c_int, namelen: c_uint, oldp: ?*c_void, oldlenp: ?*usize, newp: ?*c_void, newlen: usize) c_int;
127120pub extern "c" fn sysctlbyname(name: [*:0]const u8, oldp: ?*c_void, oldlenp: ?*usize, newp: ?*c_void, newlen: usize) c_int;
128121pub extern "c" fn sysctlnametomib(name: [*:0]const u8, mibp: ?*c_int, sizep: ?*usize) c_int;
......@@ -133,7 +126,6 @@ pub extern "c" fn uname(buf: *utsname) c_int;
133126
134127pub extern "c" fn gethostname(name: [*]u8, len: usize) c_int;
135128pub extern "c" fn bind(socket: fd_t, address: ?*const sockaddr, address_len: socklen_t) c_int;
136pub extern "c" fn socket(domain: c_uint, sock_type: c_uint, protocol: c_uint) c_int;
137129pub extern "c" fn socketpair(domain: c_uint, sock_type: c_uint, protocol: c_uint, sv: *[2]fd_t) c_int;
138130pub extern "c" fn listen(sockfd: fd_t, backlog: c_uint) c_int;
139131pub extern "c" fn getsockname(sockfd: fd_t, noalias addr: *sockaddr, noalias addrlen: *socklen_t) c_int;
......@@ -161,12 +153,55 @@ pub extern fn recvfrom(
161153 noalias addrlen: ?*socklen_t,
162154) isize;
163155
156pub usingnamespace switch (builtin.os.tag) {
157 .netbsd => struct {
158 pub const clock_getres = __clock_getres50;
159 pub const clock_gettime = __clock_gettime50;
160 pub const fstat = __fstat50;
161 pub const getdents = __getdents30;
162 pub const getrusage = __getrusage50;
163 pub const gettimeofday = __gettimeofday50;
164 pub const nanosleep = __nanosleep50;
165 pub const sched_yield = __libc_thr_yield;
166 pub const sigaction = __sigaction14;
167 pub const sigaltstack = __sigaltstack14;
168 pub const sigprocmask = __sigprocmask14;
169 pub const stat = __stat50;
170 },
171 .macosx, .ios, .watchos, .tvos => struct {
172 // XXX: close -> close$NOCANCEL
173 // XXX: getdirentries -> _getdirentries64
174 pub extern "c" fn clock_getres(clk_id: c_int, tp: *timespec) c_int;
175 pub extern "c" fn clock_gettime(clk_id: c_int, tp: *timespec) c_int;
176 pub const fstat = @"fstat$INODE64";
177 pub extern "c" fn getrusage(who: c_int, usage: *rusage) c_int;
178 pub extern "c" fn gettimeofday(noalias tv: ?*timeval, noalias tz: ?*timezone) c_int;
179 pub extern "c" fn nanosleep(rqtp: *const timespec, rmtp: ?*timespec) c_int;
180 pub extern "c" fn sched_yield() c_int;
181 pub extern "c" fn sigaction(sig: c_int, noalias act: *const Sigaction, noalias oact: ?*Sigaction) c_int;
182 pub extern "c" fn sigprocmask(how: c_int, noalias set: ?*const sigset_t, noalias oset: ?*sigset_t) c_int;
183 pub extern "c" fn socket(domain: c_uint, sock_type: c_uint, protocol: c_uint) c_int;
184 pub extern "c" fn stat(noalias path: [*:0]const u8, noalias buf: *Stat) c_int;
185 },
186 else => struct {
187 pub extern "c" fn clock_getres(clk_id: c_int, tp: *timespec) c_int;
188 pub extern "c" fn clock_gettime(clk_id: c_int, tp: *timespec) c_int;
189 pub extern "c" fn fstat(fd: fd_t, buf: *Stat) c_int;
190 pub extern "c" fn getrusage(who: c_int, usage: *rusage) c_int;
191 pub extern "c" fn gettimeofday(noalias tv: ?*timeval, noalias tz: ?*timezone) c_int;
192 pub extern "c" fn nanosleep(rqtp: *const timespec, rmtp: ?*timespec) c_int;
193 pub extern "c" fn sched_yield() c_int;
194 pub extern "c" fn sigaction(sig: c_int, noalias act: *const Sigaction, noalias oact: ?*Sigaction) c_int;
195 pub extern "c" fn sigprocmask(how: c_int, noalias set: ?*const sigset_t, noalias oset: ?*sigset_t) c_int;
196 pub extern "c" fn socket(domain: c_uint, sock_type: c_uint, protocol: c_uint) c_int;
197 pub extern "c" fn stat(noalias path: [*:0]const u8, noalias buf: *Stat) c_int;
198 },
199};
200
164201pub extern "c" fn kill(pid: pid_t, sig: c_int) c_int;
165202pub extern "c" fn getdirentries(fd: fd_t, buf_ptr: [*]u8, nbytes: usize, basep: *i64) isize;
166203pub extern "c" fn setgid(ruid: c_uint, euid: c_uint) c_int;
167204pub extern "c" fn setuid(uid: c_uint) c_int;
168pub extern "c" fn clock_gettime(clk_id: c_int, tp: *timespec) c_int;
169pub extern "c" fn clock_getres(clk_id: c_int, tp: *timespec) c_int;
170205
171206pub extern "c" fn aligned_alloc(alignment: usize, size: usize) ?*c_void;
172207pub extern "c" fn malloc(usize) ?*c_void;
......@@ -174,7 +209,6 @@ pub extern "c" fn realloc(?*c_void, usize) ?*c_void;
174209pub extern "c" fn free(*c_void) void;
175210pub extern "c" fn posix_memalign(memptr: **c_void, alignment: usize, size: usize) c_int;
176211
177// Deprecated
178212pub extern "c" fn futimes(fd: fd_t, times: *[2]timeval) c_int;
179213pub extern "c" fn utimes(path: [*:0]const u8, times: *[2]timeval) c_int;
180214
......@@ -230,8 +264,6 @@ pub extern "c" fn dn_expand(
230264 length: c_int,
231265) c_int;
232266
233pub extern "c" fn sched_yield() c_int;
234
235267pub const PTHREAD_MUTEX_INITIALIZER = pthread_mutex_t{};
236268pub extern "c" fn pthread_mutex_lock(mutex: *pthread_mutex_t) c_int;
237269pub extern "c" fn pthread_mutex_unlock(mutex: *pthread_mutex_t) c_int;
lib/std/c/netbsd.zig+33-11
......@@ -10,36 +10,58 @@ pub const dl_iterate_phdr_callback = extern fn (info: *dl_phdr_info, size: usize
1010pub extern "c" fn dl_iterate_phdr(callback: dl_iterate_phdr_callback, data: ?*c_void) c_int;
1111
1212pub extern "c" fn __fstat50(fd: fd_t, buf: *Stat) c_int;
13pub extern "c" fn __stat50(path: [*:0]const u8, buf: *Stat) c_int;
1314pub extern "c" fn __clock_gettime50(clk_id: c_int, tp: *timespec) c_int;
1415pub extern "c" fn __clock_getres50(clk_id: c_int, tp: *timespec) c_int;
1516pub extern "c" fn __getdents30(fd: c_int, buf_ptr: [*]u8, nbytes: usize) c_int;
1617pub extern "c" fn __sigaltstack14(ss: ?*stack_t, old_ss: ?*stack_t) c_int;
18pub extern "c" fn __nanosleep50(rqtp: *const timespec, rmtp: ?*timespec) c_int;
19pub extern "c" fn __sigaction14(sig: c_int, noalias act: *const Sigaction, noalias oact: ?*Sigaction) c_int;
20pub extern "c" fn __sigprocmask14(how: c_int, noalias set: ?*const sigset_t, noalias oset: ?*sigset_t) c_int;
21pub extern "c" fn __socket30(domain: c_uint, sock_type: c_uint, protocol: c_uint) c_int;
22pub extern "c" fn __gettimeofday50(noalias tv: ?*timeval, noalias tz: ?*timezone) c_int;
23pub extern "c" fn __getrusage50(who: c_int, usage: *rusage) c_int;
24// libc aliases this as sched_yield
25pub extern "c" fn __libc_thr_yield() c_int;
1726
1827pub const pthread_mutex_t = extern struct {
19 ptm_magic: c_uint = 0x33330003,
20 ptm_errorcheck: padded_spin_t = 0,
21 ptm_unused: padded_spin_t = 0,
28 ptm_magic: u32 = 0x33330003,
29 ptm_errorcheck: padded_pthread_spin_t = 0,
30 ptm_ceiling: padded_pthread_spin_t = 0,
2231 ptm_owner: usize = 0,
2332 ptm_waiters: ?*u8 = null,
24 ptm_recursed: c_uint = 0,
33 ptm_recursed: u32 = 0,
2534 ptm_spare2: ?*c_void = null,
2635};
36
2737pub const pthread_cond_t = extern struct {
28 ptc_magic: c_uint = 0x55550005,
38 ptc_magic: u32 = 0x55550005,
2939 ptc_lock: pthread_spin_t = 0,
3040 ptc_waiters_first: ?*u8 = null,
3141 ptc_waiters_last: ?*u8 = null,
3242 ptc_mutex: ?*pthread_mutex_t = null,
3343 ptc_private: ?*c_void = null,
3444};
35const pthread_spin_t = if (builtin.arch == .arm or .arch == .powerpc) c_int else u8;
36const padded_spin_t = switch (builtin.arch) {
37 .sparc, .sparcel, .sparcv9, .i386, .x86_64, .le64 => u32,
38 else => spin_t,
45
46const pthread_spin_t = switch (builtin.arch) {
47 .aarch64, .aarch64_be, .aarch64_32 => u8,
48 .mips, .mipsel, .mips64, .mips64el => u32,
49 .powerpc, .powerpc64, .powerpc64le => i32,
50 .i386, .x86_64 => u8,
51 .arm, .armeb, .thumb, .thumbeb => i32,
52 .sparc, .sparcel, .sparcv9 => u8,
53 .riscv32, .riscv64 => u32,
54 else => @compileError("undefined pthread_spin_t for this arch"),
55};
56
57const padded_pthread_spin_t = switch (builtin.arch) {
58 .i386, .x86_64 => u32,
59 .sparc, .sparcel, .sparcv9 => u32,
60 else => pthread_spin_t,
3961};
4062
4163pub const pthread_attr_t = extern struct {
4264 pta_magic: u32,
43 pta_flags: c_int,
44 pta_private: *c_void,
65 pta_flags: i32,
66 pta_private: ?*c_void,
4567};
lib/std/child_process.zig+13-33
......@@ -10,7 +10,7 @@ const windows = os.windows;
1010const mem = std.mem;
1111const debug = std.debug;
1212const BufMap = std.BufMap;
13const Buffer = std.Buffer;
13const ArrayListSentineled = std.ArrayListSentineled;
1414const builtin = @import("builtin");
1515const Os = builtin.Os;
1616const TailQueue = std.TailQueue;
......@@ -175,29 +175,11 @@ pub const ChildProcess = struct {
175175 stderr: []u8,
176176 };
177177
178 /// Spawns a child process, waits for it, collecting stdout and stderr, and then returns.
179 /// If it succeeds, the caller owns result.stdout and result.stderr memory.
180 /// TODO deprecate in favor of exec2
181 pub fn exec(
182 allocator: *mem.Allocator,
183 argv: []const []const u8,
184 cwd: ?[]const u8,
185 env_map: ?*const BufMap,
186 max_output_bytes: usize,
187 ) !ExecResult {
188 return exec2(.{
189 .allocator = allocator,
190 .argv = argv,
191 .cwd = cwd,
192 .env_map = env_map,
193 .max_output_bytes = max_output_bytes,
194 });
195 }
178 pub const exec2 = @compileError("deprecated: exec2 is renamed to exec");
196179
197180 /// Spawns a child process, waits for it, collecting stdout and stderr, and then returns.
198181 /// If it succeeds, the caller owns result.stdout and result.stderr memory.
199 /// TODO rename to exec
200 pub fn exec2(args: struct {
182 pub fn exec(args: struct {
201183 allocator: *mem.Allocator,
202184 argv: []const []const u8,
203185 cwd: ?[]const u8 = null,
......@@ -370,7 +352,7 @@ pub const ChildProcess = struct {
370352
371353 const any_ignore = (self.stdin_behavior == StdIo.Ignore or self.stdout_behavior == StdIo.Ignore or self.stderr_behavior == StdIo.Ignore);
372354 const dev_null_fd = if (any_ignore)
373 os.openC("/dev/null", os.O_RDWR, 0) catch |err| switch (err) {
355 os.openZ("/dev/null", os.O_RDWR, 0) catch |err| switch (err) {
374356 error.PathAlreadyExists => unreachable,
375357 error.NoSpaceLeft => unreachable,
376358 error.FileTooBig => unreachable,
......@@ -775,38 +757,36 @@ fn windowsCreateProcess(app_name: [*:0]u16, cmd_line: [*:0]u16, envp_ptr: ?[*]u1
775757}
776758
777759/// Caller must dealloc.
778/// Guarantees a null byte at result[result.len].
779fn windowsCreateCommandLine(allocator: *mem.Allocator, argv: []const []const u8) ![]u8 {
780 var buf = try Buffer.initSize(allocator, 0);
760fn windowsCreateCommandLine(allocator: *mem.Allocator, argv: []const []const u8) ![:0]u8 {
761 var buf = try ArrayListSentineled(u8, 0).initSize(allocator, 0);
781762 defer buf.deinit();
782
783 var buf_stream = buf.outStream();
763 const buf_stream = buf.outStream();
784764
785765 for (argv) |arg, arg_i| {
786 if (arg_i != 0) try buf.appendByte(' ');
766 if (arg_i != 0) try buf_stream.writeByte(' ');
787767 if (mem.indexOfAny(u8, arg, " \t\n\"") == null) {
788 try buf.append(arg);
768 try buf_stream.writeAll(arg);
789769 continue;
790770 }
791 try buf.appendByte('"');
771 try buf_stream.writeByte('"');
792772 var backslash_count: usize = 0;
793773 for (arg) |byte| {
794774 switch (byte) {
795775 '\\' => backslash_count += 1,
796776 '"' => {
797777 try buf_stream.writeByteNTimes('\\', backslash_count * 2 + 1);
798 try buf.appendByte('"');
778 try buf_stream.writeByte('"');
799779 backslash_count = 0;
800780 },
801781 else => {
802782 try buf_stream.writeByteNTimes('\\', backslash_count);
803 try buf.appendByte(byte);
783 try buf_stream.writeByte(byte);
804784 backslash_count = 0;
805785 },
806786 }
807787 }
808788 try buf_stream.writeByteNTimes('\\', backslash_count * 2);
809 try buf.appendByte('"');
789 try buf_stream.writeByte('"');
810790 }
811791
812792 return buf.toOwnedSlice();
lib/std/coff.zig+2-2
......@@ -145,7 +145,7 @@ pub const Coff = struct {
145145 blk: while (i < debug_dir_entry_count) : (i += 1) {
146146 const debug_dir_entry = try in.readStruct(DebugDirectoryEntry);
147147 if (debug_dir_entry.type == IMAGE_DEBUG_TYPE_CODEVIEW) {
148 for (self.sections.toSlice()) |*section| {
148 for (self.sections.span()) |*section| {
149149 const section_start = section.header.virtual_address;
150150 const section_size = section.header.misc.virtual_size;
151151 const rva = debug_dir_entry.address_of_raw_data;
......@@ -211,7 +211,7 @@ pub const Coff = struct {
211211 }
212212
213213 pub fn getSection(self: *Coff, comptime name: []const u8) ?*Section {
214 for (self.sections.toSlice()) |*sec| {
214 for (self.sections.span()) |*sec| {
215215 if (mem.eql(u8, sec.header.name[0..name.len], name)) {
216216 return sec;
217217 }
lib/std/crypto/gimli.zig+2
......@@ -23,10 +23,12 @@ pub const State = struct {
2323
2424 const Self = @This();
2525
26 /// TODO follow the span() convention instead of having this and `toSliceConst`
2627 pub fn toSlice(self: *Self) []u8 {
2728 return mem.sliceAsBytes(self.data[0..]);
2829 }
2930
31 /// TODO follow the span() convention instead of having this and `toSlice`
3032 pub fn toSliceConst(self: *Self) []const u8 {
3133 return mem.sliceAsBytes(self.data[0..]);
3234 }
lib/std/debug.zig+17-12
......@@ -735,7 +735,7 @@ fn openCoffDebugInfo(allocator: *mem.Allocator, coff_file_path: [:0]const u16) !
735735 for (present) |_| {
736736 const name_offset = try pdb_stream.inStream().readIntLittle(u32);
737737 const name_index = try pdb_stream.inStream().readIntLittle(u32);
738 const name = mem.toSlice(u8, @ptrCast([*:0]u8, name_bytes.ptr + name_offset));
738 const name = mem.spanZ(@ptrCast([*:0]u8, name_bytes.ptr + name_offset));
739739 if (mem.eql(u8, name, "/names")) {
740740 break :str_tab_index name_index;
741741 }
......@@ -1131,7 +1131,7 @@ pub const DebugInfo = struct {
11311131 const obj_di = try self.allocator.create(ModuleDebugInfo);
11321132 errdefer self.allocator.destroy(obj_di);
11331133
1134 const macho_path = mem.toSliceConst(u8, std.c._dyld_get_image_name(i));
1134 const macho_path = mem.spanZ(std.c._dyld_get_image_name(i));
11351135 obj_di.* = openMachODebugInfo(self.allocator, macho_path) catch |err| switch (err) {
11361136 error.FileNotFound => return error.MissingDebugInfo,
11371137 else => return err,
......@@ -1254,10 +1254,7 @@ pub const DebugInfo = struct {
12541254 if (context.address >= seg_start and context.address < seg_end) {
12551255 // Android libc uses NULL instead of an empty string to mark the
12561256 // main program
1257 context.name = if (info.dlpi_name) |dlpi_name|
1258 mem.toSliceConst(u8, dlpi_name)
1259 else
1260 "";
1257 context.name = mem.spanZ(info.dlpi_name) orelse "";
12611258 context.base_address = info.dlpi_addr;
12621259 // Stop the iteration
12631260 return error.Found;
......@@ -1426,7 +1423,7 @@ pub const ModuleDebugInfo = switch (builtin.os.tag) {
14261423 return SymbolInfo{};
14271424
14281425 assert(symbol.ofile.?.n_strx < self.strings.len);
1429 const o_file_path = mem.toSliceConst(u8, self.strings.ptr + symbol.ofile.?.n_strx);
1426 const o_file_path = mem.spanZ(self.strings.ptr + symbol.ofile.?.n_strx);
14301427
14311428 // Check if its debug infos are already in the cache
14321429 var o_file_di = self.ofiles.getValue(o_file_path) orelse
......@@ -1483,7 +1480,7 @@ pub const ModuleDebugInfo = switch (builtin.os.tag) {
14831480 const mod_index = for (self.sect_contribs) |sect_contrib| {
14841481 if (sect_contrib.Section > self.coff.sections.len) continue;
14851482 // Remember that SectionContribEntry.Section is 1-based.
1486 coff_section = &self.coff.sections.toSlice()[sect_contrib.Section - 1];
1483 coff_section = &self.coff.sections.span()[sect_contrib.Section - 1];
14871484
14881485 const vaddr_start = coff_section.header.virtual_address + sect_contrib.Offset;
14891486 const vaddr_end = vaddr_start + sect_contrib.Size;
......@@ -1510,7 +1507,7 @@ pub const ModuleDebugInfo = switch (builtin.os.tag) {
15101507 const vaddr_start = coff_section.header.virtual_address + proc_sym.CodeOffset;
15111508 const vaddr_end = vaddr_start + proc_sym.CodeSize;
15121509 if (relocated_address >= vaddr_start and relocated_address < vaddr_end) {
1513 break mem.toSliceConst(u8, @ptrCast([*:0]u8, proc_sym) + @sizeOf(pdb.ProcSym));
1510 break mem.spanZ(@ptrCast([*:0]u8, proc_sym) + @sizeOf(pdb.ProcSym));
15141511 }
15151512 },
15161513 else => {},
......@@ -1669,7 +1666,11 @@ fn getDebugInfoAllocator() *mem.Allocator {
16691666}
16701667
16711668/// Whether or not the current target can print useful debug information when a segfault occurs.
1672pub const have_segfault_handling_support = builtin.os.tag == .linux or builtin.os.tag == .windows;
1669pub const have_segfault_handling_support = switch (builtin.os.tag) {
1670 .linux, .netbsd => true,
1671 .windows => true,
1672 else => false,
1673};
16731674pub const enable_segfault_handler: bool = if (@hasDecl(root, "enable_segfault_handler"))
16741675 root.enable_segfault_handler
16751676else
......@@ -1721,13 +1722,17 @@ fn resetSegfaultHandler() void {
17211722 os.sigaction(os.SIGBUS, &act, null);
17221723}
17231724
1724fn handleSegfaultLinux(sig: i32, info: *const os.siginfo_t, ctx_ptr: *const c_void) callconv(.C) noreturn {
1725fn handleSegfaultLinux(sig: i32, info: *const os.siginfo_t, ctx_ptr: ?*const c_void) callconv(.C) noreturn {
17251726 // Reset to the default handler so that if a segfault happens in this handler it will crash
17261727 // the process. Also when this handler returns, the original instruction will be repeated
17271728 // and the resulting segfault will crash the process rather than continually dump stack traces.
17281729 resetSegfaultHandler();
17291730
1730 const addr = @ptrToInt(info.fields.sigfault.addr);
1731 const addr = switch (builtin.os.tag) {
1732 .linux => @ptrToInt(info.fields.sigfault.addr),
1733 .netbsd => @ptrToInt(info.info.reason.fault.addr),
1734 else => unreachable,
1735 };
17311736 switch (sig) {
17321737 os.SIGSEGV => std.debug.warn("Segmentation fault at address 0x{x}\n", .{addr}),
17331738 os.SIGILL => std.debug.warn("Illegal instruction at address 0x{x}\n", .{addr}),
lib/std/dwarf.zig+7-7
......@@ -82,7 +82,7 @@ const Die = struct {
8282 };
8383
8484 fn getAttr(self: *const Die, id: u64) ?*const FormValue {
85 for (self.attrs.toSliceConst()) |*attr| {
85 for (self.attrs.span()) |*attr| {
8686 if (attr.id == id) return &attr.value;
8787 }
8888 return null;
......@@ -375,7 +375,7 @@ fn parseFormValue(allocator: *mem.Allocator, in_stream: var, form_id: u64, is_64
375375}
376376
377377fn getAbbrevTableEntry(abbrev_table: *const AbbrevTable, abbrev_code: u64) ?*const AbbrevTableEntry {
378 for (abbrev_table.toSliceConst()) |*table_entry| {
378 for (abbrev_table.span()) |*table_entry| {
379379 if (table_entry.abbrev_code == abbrev_code) return table_entry;
380380 }
381381 return null;
......@@ -399,7 +399,7 @@ pub const DwarfInfo = struct {
399399 }
400400
401401 fn getSymbolName(di: *DwarfInfo, address: u64) ?[]const u8 {
402 for (di.func_list.toSliceConst()) |*func| {
402 for (di.func_list.span()) |*func| {
403403 if (func.pc_range) |range| {
404404 if (address >= range.start and address < range.end) {
405405 return func.name;
......@@ -588,7 +588,7 @@ pub const DwarfInfo = struct {
588588 }
589589
590590 fn findCompileUnit(di: *DwarfInfo, target_address: u64) !*const CompileUnit {
591 for (di.compile_unit_list.toSlice()) |*compile_unit| {
591 for (di.compile_unit_list.span()) |*compile_unit| {
592592 if (compile_unit.pc_range) |range| {
593593 if (target_address >= range.start and target_address < range.end) return compile_unit;
594594 }
......@@ -636,7 +636,7 @@ pub const DwarfInfo = struct {
636636 /// Gets an already existing AbbrevTable given the abbrev_offset, or if not found,
637637 /// seeks in the stream and parses it.
638638 fn getAbbrevTable(di: *DwarfInfo, abbrev_offset: u64) !*const AbbrevTable {
639 for (di.abbrev_table_list.toSlice()) |*header| {
639 for (di.abbrev_table_list.span()) |*header| {
640640 if (header.offset == abbrev_offset) {
641641 return &header.table;
642642 }
......@@ -690,7 +690,7 @@ pub const DwarfInfo = struct {
690690 .attrs = ArrayList(Die.Attr).init(di.allocator()),
691691 };
692692 try result.attrs.resize(table_entry.attrs.len);
693 for (table_entry.attrs.toSliceConst()) |attr, i| {
693 for (table_entry.attrs.span()) |attr, i| {
694694 result.attrs.items[i] = Die.Attr{
695695 .id = attr.attr_id,
696696 .value = try parseFormValue(di.allocator(), in_stream, attr.form_id, is_64),
......@@ -757,7 +757,7 @@ pub const DwarfInfo = struct {
757757 }
758758
759759 var file_entries = ArrayList(FileEntry).init(di.allocator());
760 var prog = LineNumberProgram.init(default_is_stmt, include_directories.toSliceConst(), &file_entries, target_address);
760 var prog = LineNumberProgram.init(default_is_stmt, include_directories.span(), &file_entries, target_address);
761761
762762 while (true) {
763763 const file_name = try in.readUntilDelimiterAlloc(di.allocator(), 0, math.maxInt(usize));
lib/std/dynamic_library.zig+13-7
......@@ -254,9 +254,11 @@ pub const ElfDynLib = struct {
254254 };
255255 }
256256
257 pub const openC = @compileError("deprecated: renamed to openZ");
258
257259 /// Trusts the file. Malicious file will be able to execute arbitrary code.
258 pub fn openC(path_c: [*:0]const u8) !ElfDynLib {
259 return open(mem.toSlice(u8, path_c));
260 pub fn openZ(path_c: [*:0]const u8) !ElfDynLib {
261 return open(mem.spanZ(path_c));
260262 }
261263
262264 /// Trusts the file
......@@ -285,7 +287,7 @@ pub const ElfDynLib = struct {
285287 if (0 == (@as(u32, 1) << @intCast(u5, self.syms[i].st_info & 0xf) & OK_TYPES)) continue;
286288 if (0 == (@as(u32, 1) << @intCast(u5, self.syms[i].st_info >> 4) & OK_BINDS)) continue;
287289 if (0 == self.syms[i].st_shndx) continue;
288 if (!mem.eql(u8, name, mem.toSliceConst(u8, self.strings + self.syms[i].st_name))) continue;
290 if (!mem.eql(u8, name, mem.spanZ(self.strings + self.syms[i].st_name))) continue;
289291 if (maybe_versym) |versym| {
290292 if (!checkver(self.verdef.?, versym[i], vername, self.strings))
291293 continue;
......@@ -316,7 +318,7 @@ fn checkver(def_arg: *elf.Verdef, vsym_arg: i32, vername: []const u8, strings: [
316318 def = @intToPtr(*elf.Verdef, @ptrToInt(def) + def.vd_next);
317319 }
318320 const aux = @intToPtr(*elf.Verdaux, @ptrToInt(def) + def.vd_aux);
319 return mem.eql(u8, vername, mem.toSliceConst(u8, strings + aux.vda_name));
321 return mem.eql(u8, vername, mem.spanZ(strings + aux.vda_name));
320322}
321323
322324pub const WindowsDynLib = struct {
......@@ -329,7 +331,9 @@ pub const WindowsDynLib = struct {
329331 return openW(&path_w);
330332 }
331333
332 pub fn openC(path_c: [*:0]const u8) !WindowsDynLib {
334 pub const openC = @compileError("deprecated: renamed to openZ");
335
336 pub fn openZ(path_c: [*:0]const u8) !WindowsDynLib {
333337 const path_w = try windows.cStrToPrefixedFileW(path_c);
334338 return openW(&path_w);
335339 }
......@@ -362,10 +366,12 @@ pub const DlDynlib = struct {
362366
363367 pub fn open(path: []const u8) !DlDynlib {
364368 const path_c = try os.toPosixPath(path);
365 return openC(&path_c);
369 return openZ(&path_c);
366370 }
367371
368 pub fn openC(path_c: [*:0]const u8) !DlDynlib {
372 pub const openC = @compileError("deprecated: renamed to openZ");
373
374 pub fn openZ(path_c: [*:0]const u8) !DlDynlib {
369375 return DlDynlib{
370376 .handle = system.dlopen(path_c, system.RTLD_LAZY) orelse {
371377 return error.FileNotFound;
lib/std/event/loop.zig+2-2
......@@ -1096,10 +1096,10 @@ pub const Loop = struct {
10961096 msg.result = noasync os.preadv(msg.fd, msg.iov, msg.offset);
10971097 },
10981098 .open => |*msg| {
1099 msg.result = noasync os.openC(msg.path, msg.flags, msg.mode);
1099 msg.result = noasync os.openZ(msg.path, msg.flags, msg.mode);
11001100 },
11011101 .openat => |*msg| {
1102 msg.result = noasync os.openatC(msg.fd, msg.path, msg.flags, msg.mode);
1102 msg.result = noasync os.openatZ(msg.fd, msg.path, msg.flags, msg.mode);
11031103 },
11041104 .faccessat => |*msg| {
11051105 msg.result = noasync os.faccessatZ(msg.dirfd, msg.path, msg.mode, msg.flags);
lib/std/fifo.zig+50-25
......@@ -160,7 +160,7 @@ pub fn LinearFifo(
160160 return self.readableSliceMut(offset);
161161 }
162162
163 /// Discard first `count` bytes of readable data
163 /// Discard first `count` items in the fifo
164164 pub fn discard(self: *Self, count: usize) void {
165165 assert(count <= self.count);
166166 { // set old range to undefined. Note: may be wrapped around
......@@ -199,7 +199,7 @@ pub fn LinearFifo(
199199 return c;
200200 }
201201
202 /// Read data from the fifo into `dst`, returns number of bytes copied.
202 /// Read data from the fifo into `dst`, returns number of items copied.
203203 pub fn read(self: *Self, dst: []T) usize {
204204 var dst_left = dst;
205205
......@@ -215,7 +215,17 @@ pub fn LinearFifo(
215215 return dst.len - dst_left.len;
216216 }
217217
218 /// Returns number of bytes available in fifo
218 /// Same as `read` except it returns an error union
219 /// The purpose of this function existing is to match `std.io.InStream` API.
220 fn readFn(self: *Self, dest: []u8) error{}!usize {
221 return self.read(dest);
222 }
223
224 pub fn inStream(self: *Self) std.io.InStream(*Self, error{}, readFn) {
225 return .{ .context = self };
226 }
227
228 /// Returns number of items available in fifo
219229 pub fn writableLength(self: Self) usize {
220230 return self.buf.len - self.count;
221231 }
......@@ -233,9 +243,9 @@ pub fn LinearFifo(
233243 }
234244 }
235245
236 /// Returns a writable buffer of at least `size` bytes, allocating memory as needed.
246 /// Returns a writable buffer of at least `size` items, allocating memory as needed.
237247 /// Use `fifo.update` once you've written data to it.
238 pub fn writeableWithSize(self: *Self, size: usize) ![]T {
248 pub fn writableWithSize(self: *Self, size: usize) ![]T {
239249 try self.ensureUnusedCapacity(size);
240250
241251 // try to avoid realigning buffer
......@@ -247,7 +257,7 @@ pub fn LinearFifo(
247257 return slice;
248258 }
249259
250 /// Update the tail location of the buffer (usually follows use of writable/writeableWithSize)
260 /// Update the tail location of the buffer (usually follows use of writable/writableWithSize)
251261 pub fn update(self: *Self, count: usize) void {
252262 assert(self.count + count <= self.buf.len);
253263 self.count += count;
......@@ -279,7 +289,7 @@ pub fn LinearFifo(
279289 } else {
280290 tail %= self.buf.len;
281291 }
282 self.buf[tail] = byte;
292 self.buf[tail] = item;
283293 self.update(1);
284294 }
285295
......@@ -291,24 +301,16 @@ pub fn LinearFifo(
291301 return self.writeAssumeCapacity(src);
292302 }
293303
294 pub usingnamespace if (T == u8)
295 struct {
296 const OutStream = std.io.OutStream(*Self, Error, appendWrite);
297 const Error = error{OutOfMemory};
298
299 /// Same as `write` except it returns the number of bytes written, which is always the same
300 /// as `bytes.len`. The purpose of this function existing is to match `std.io.OutStream` API.
301 pub fn appendWrite(fifo: *Self, bytes: []const u8) Error!usize {
302 try fifo.write(bytes);
303 return bytes.len;
304 }
304 /// Same as `write` except it returns the number of bytes written, which is always the same
305 /// as `bytes.len`. The purpose of this function existing is to match `std.io.OutStream` API.
306 fn appendWrite(self: *Self, bytes: []const u8) error{OutOfMemory}!usize {
307 try self.write(bytes);
308 return bytes.len;
309 }
305310
306 pub fn outStream(self: *Self) OutStream {
307 return .{ .context = self };
308 }
309 }
310 else
311 struct {};
311 pub fn outStream(self: *Self) std.io.OutStream(*Self, error{OutOfMemory}, appendWrite) {
312 return .{ .context = self };
313 }
312314
313315 /// Make `count` items available before the current read location
314316 fn rewind(self: *Self, count: usize) void {
......@@ -395,7 +397,7 @@ test "LinearFifo(u8, .Dynamic)" {
395397 }
396398
397399 {
398 const buf = try fifo.writeableWithSize(12);
400 const buf = try fifo.writableWithSize(12);
399401 testing.expectEqual(@as(usize, 12), buf.len);
400402 var i: u8 = 0;
401403 while (i < 10) : (i += 1) {
......@@ -422,6 +424,15 @@ test "LinearFifo(u8, .Dynamic)" {
422424 testing.expectEqualSlices(u8, "Hello, World!", result[0..fifo.read(&result)]);
423425 testing.expectEqual(@as(usize, 0), fifo.readableLength());
424426 }
427
428 {
429 try fifo.outStream().writeAll("This is a test");
430 var result: [30]u8 = undefined;
431 testing.expectEqualSlices(u8, "This", (try fifo.inStream().readUntilDelimiterOrEof(&result, ' ')).?);
432 testing.expectEqualSlices(u8, "is", (try fifo.inStream().readUntilDelimiterOrEof(&result, ' ')).?);
433 testing.expectEqualSlices(u8, "a", (try fifo.inStream().readUntilDelimiterOrEof(&result, ' ')).?);
434 testing.expectEqualSlices(u8, "test", (try fifo.inStream().readUntilDelimiterOrEof(&result, ' ')).?);
435 }
425436}
426437
427438test "LinearFifo" {
......@@ -445,6 +456,20 @@ test "LinearFifo" {
445456 testing.expectEqual(@as(T, 1), try fifo.readItem());
446457 testing.expectEqual(@as(T, 0), try fifo.readItem());
447458 testing.expectEqual(@as(T, 1), try fifo.readItem());
459 testing.expectEqual(@as(usize, 0), fifo.readableLength());
460 }
461
462 {
463 try fifo.writeItem(1);
464 try fifo.writeItem(1);
465 try fifo.writeItem(1);
466 testing.expectEqual(@as(usize, 3), fifo.readableLength());
467 }
468
469 {
470 var readBuf: [3]T = undefined;
471 const n = fifo.read(&readBuf);
472 testing.expectEqual(@as(usize, 3), n); // NOTE: It should be the number of items.
448473 }
449474 }
450475 }
lib/std/fmt/parse_float.zig+51-71
......@@ -30,6 +30,7 @@
3030// - Does not handle denormals
3131
3232const std = @import("../std.zig");
33const ascii = std.ascii;
3334
3435const max_digits = 25;
3536
......@@ -190,14 +191,6 @@ const ParseResult = enum {
190191 MinusInf,
191192};
192193
193inline fn isDigit(c: u8) bool {
194 return c >= '0' and c <= '9';
195}
196
197inline fn isSpace(c: u8) bool {
198 return (c >= 0x09 and c <= 0x13) or c == 0x20;
199}
200
201194fn parseRepr(s: []const u8, n: *FloatRepr) !ParseResult {
202195 var digit_index: usize = 0;
203196 var negative = false;
......@@ -207,52 +200,49 @@ fn parseRepr(s: []const u8, n: *FloatRepr) !ParseResult {
207200 var state = State.MaybeSign;
208201
209202 var i: usize = 0;
210 loop: while (i < s.len) {
203 while (i < s.len) {
211204 const c = s[i];
212205
213206 switch (state) {
214 State.MaybeSign => {
215 state = State.LeadingMantissaZeros;
207 .MaybeSign => {
208 state = .LeadingMantissaZeros;
216209
217210 if (c == '+') {
218211 i += 1;
219212 } else if (c == '-') {
220213 n.negative = true;
221214 i += 1;
222 } else if (isDigit(c) or c == '.') {
215 } else if (ascii.isDigit(c) or c == '.') {
223216 // continue
224217 } else {
225218 return error.InvalidCharacter;
226219 }
227220 },
228
229 State.LeadingMantissaZeros => {
221 .LeadingMantissaZeros => {
230222 if (c == '0') {
231223 i += 1;
232224 } else if (c == '.') {
233225 i += 1;
234 state = State.LeadingFractionalZeros;
226 state = .LeadingFractionalZeros;
235227 } else {
236 state = State.MantissaIntegral;
228 state = .MantissaIntegral;
237229 }
238230 },
239
240 State.LeadingFractionalZeros => {
231 .LeadingFractionalZeros => {
241232 if (c == '0') {
242233 i += 1;
243234 if (n.exponent > std.math.minInt(i32)) {
244235 n.exponent -= 1;
245236 }
246237 } else {
247 state = State.MantissaFractional;
238 state = .MantissaFractional;
248239 }
249240 },
250
251 State.MantissaIntegral => {
252 if (isDigit(c)) {
241 .MantissaIntegral => {
242 if (ascii.isDigit(c)) {
253243 if (digit_index < max_digits) {
254244 n.mantissa *%= 10;
255 n.mantissa += s[i] - '0';
245 n.mantissa += c - '0';
256246 digit_index += 1;
257247 } else if (n.exponent < std.math.maxInt(i32)) {
258248 n.exponent += 1;
......@@ -261,14 +251,13 @@ fn parseRepr(s: []const u8, n: *FloatRepr) !ParseResult {
261251 i += 1;
262252 } else if (c == '.') {
263253 i += 1;
264 state = State.MantissaFractional;
254 state = .MantissaFractional;
265255 } else {
266 state = State.MantissaFractional;
256 state = .MantissaFractional;
267257 }
268258 },
269
270 State.MantissaFractional => {
271 if (isDigit(c)) {
259 .MantissaFractional => {
260 if (ascii.isDigit(c)) {
272261 if (digit_index < max_digits) {
273262 n.mantissa *%= 10;
274263 n.mantissa += c - '0';
......@@ -279,13 +268,12 @@ fn parseRepr(s: []const u8, n: *FloatRepr) !ParseResult {
279268 i += 1;
280269 } else if (c == 'e' or c == 'E') {
281270 i += 1;
282 state = State.ExponentSign;
271 state = .ExponentSign;
283272 } else {
284 state = State.ExponentSign;
273 state = .ExponentSign;
285274 }
286275 },
287
288 State.ExponentSign => {
276 .ExponentSign => {
289277 if (c == '+') {
290278 i += 1;
291279 } else if (c == '-') {
......@@ -293,20 +281,18 @@ fn parseRepr(s: []const u8, n: *FloatRepr) !ParseResult {
293281 i += 1;
294282 }
295283
296 state = State.LeadingExponentZeros;
284 state = .LeadingExponentZeros;
297285 },
298
299 State.LeadingExponentZeros => {
286 .LeadingExponentZeros => {
300287 if (c == '0') {
301288 i += 1;
302289 } else {
303 state = State.Exponent;
290 state = .Exponent;
304291 }
305292 },
306
307 State.Exponent => {
308 if (isDigit(c)) {
309 if (exponent < std.math.maxInt(i32)) {
293 .Exponent => {
294 if (ascii.isDigit(c)) {
295 if (exponent < std.math.maxInt(i32) / 10) {
310296 exponent *= 10;
311297 exponent += @intCast(i32, c - '0');
312298 }
......@@ -323,29 +309,21 @@ fn parseRepr(s: []const u8, n: *FloatRepr) !ParseResult {
323309 n.exponent += exponent;
324310
325311 if (n.mantissa == 0) {
326 return if (n.negative) ParseResult.MinusZero else ParseResult.PlusZero;
312 return if (n.negative) .MinusZero else .PlusZero;
327313 } else if (n.exponent > 309) {
328 return if (n.negative) ParseResult.MinusInf else ParseResult.PlusInf;
314 return if (n.negative) .MinusInf else .PlusInf;
329315 } else if (n.exponent < -328) {
330 return if (n.negative) ParseResult.MinusZero else ParseResult.PlusZero;
316 return if (n.negative) .MinusZero else .PlusZero;
331317 }
332318
333 return ParseResult.Ok;
334}
335
336inline fn isLower(c: u8) bool {
337 return c -% 'a' < 26;
338}
339
340inline fn toUpper(c: u8) u8 {
341 return if (isLower(c)) (c & 0x5f) else c;
319 return .Ok;
342320}
343321
344322fn caseInEql(a: []const u8, b: []const u8) bool {
345323 if (a.len != b.len) return false;
346324
347325 for (a) |_, i| {
348 if (toUpper(a[i]) != toUpper(b[i])) {
326 if (ascii.toUpper(a[i]) != ascii.toUpper(b[i])) {
349327 return false;
350328 }
351329 }
......@@ -373,11 +351,11 @@ pub fn parseFloat(comptime T: type, s: []const u8) !T {
373351 };
374352
375353 return switch (try parseRepr(s, &r)) {
376 ParseResult.Ok => convertRepr(T, r),
377 ParseResult.PlusZero => 0.0,
378 ParseResult.MinusZero => -@as(T, 0.0),
379 ParseResult.PlusInf => std.math.inf(T),
380 ParseResult.MinusInf => -std.math.inf(T),
354 .Ok => convertRepr(T, r),
355 .PlusZero => 0.0,
356 .MinusZero => -@as(T, 0.0),
357 .PlusInf => std.math.inf(T),
358 .MinusInf => -std.math.inf(T),
381359 };
382360}
383361
......@@ -396,26 +374,28 @@ test "fmt.parseFloat" {
396374 testing.expectError(error.InvalidCharacter, parseFloat(T, "1abc"));
397375
398376 expectEqual(try parseFloat(T, "0"), 0.0);
399 expectEqual((try parseFloat(T, "0")), 0.0);
400 expectEqual((try parseFloat(T, "+0")), 0.0);
401 expectEqual((try parseFloat(T, "-0")), 0.0);
377 expectEqual(try parseFloat(T, "0"), 0.0);
378 expectEqual(try parseFloat(T, "+0"), 0.0);
379 expectEqual(try parseFloat(T, "-0"), 0.0);
402380
403 expectEqual((try parseFloat(T, "0e0")), 0);
404 expectEqual((try parseFloat(T, "2e3")), 2000.0);
405 expectEqual((try parseFloat(T, "1e0")), 1.0);
406 expectEqual((try parseFloat(T, "-2e3")), -2000.0);
407 expectEqual((try parseFloat(T, "-1e0")), -1.0);
408 expectEqual((try parseFloat(T, "1.234e3")), 1234);
381 expectEqual(try parseFloat(T, "0e0"), 0);
382 expectEqual(try parseFloat(T, "2e3"), 2000.0);
383 expectEqual(try parseFloat(T, "1e0"), 1.0);
384 expectEqual(try parseFloat(T, "-2e3"), -2000.0);
385 expectEqual(try parseFloat(T, "-1e0"), -1.0);
386 expectEqual(try parseFloat(T, "1.234e3"), 1234);
409387
410388 expect(approxEq(T, try parseFloat(T, "3.141"), 3.141, epsilon));
411389 expect(approxEq(T, try parseFloat(T, "-3.141"), -3.141, epsilon));
412390
413 expectEqual((try parseFloat(T, "1e-700")), 0);
414 expectEqual((try parseFloat(T, "1e+700")), std.math.inf(T));
391 expectEqual(try parseFloat(T, "1e-700"), 0);
392 expectEqual(try parseFloat(T, "1e+700"), std.math.inf(T));
415393
416394 expectEqual(@bitCast(Z, try parseFloat(T, "nAn")), @bitCast(Z, std.math.nan(T)));
417 expectEqual((try parseFloat(T, "inF")), std.math.inf(T));
418 expectEqual((try parseFloat(T, "-INF")), -std.math.inf(T));
395 expectEqual(try parseFloat(T, "inF"), std.math.inf(T));
396 expectEqual(try parseFloat(T, "-INF"), -std.math.inf(T));
397
398 expectEqual(try parseFloat(T, "0.4e0066999999999999999999999999999999999999999999999999999"), std.math.inf(T));
419399
420400 if (T != f16) {
421401 expect(approxEq(T, try parseFloat(T, "1e-2"), 0.01, epsilon));
lib/std/fs.zig+121-98
......@@ -11,13 +11,18 @@ const math = std.math;
1111pub const path = @import("fs/path.zig");
1212pub const File = @import("fs/file.zig").File;
1313
14// TODO audit these APIs with respect to Dir and absolute paths
15
1416pub const symLink = os.symlink;
15pub const symLinkC = os.symlinkC;
17pub const symLinkZ = os.symlinkZ;
18pub const symLinkC = @compileError("deprecated: renamed to symlinkZ");
1619pub const rename = os.rename;
17pub const renameC = os.renameC;
20pub const renameZ = os.renameZ;
21pub const renameC = @compileError("deprecated: renamed to renameZ");
1822pub const renameW = os.renameW;
1923pub const realpath = os.realpath;
20pub const realpathC = os.realpathC;
24pub const realpathZ = os.realpathZ;
25pub const realpathC = @compileError("deprecated: renamed to realpathZ");
2126pub const realpathW = os.realpathW;
2227
2328pub const getAppDataDir = @import("fs/get_app_data_dir.zig").getAppDataDir;
......@@ -120,7 +125,7 @@ pub const AtomicFile = struct {
120125 file: File,
121126 // TODO either replace this with rand_buf or use []u16 on Windows
122127 tmp_path_buf: [TMP_PATH_LEN:0]u8,
123 dest_path: []const u8,
128 dest_basename: []const u8,
124129 file_open: bool,
125130 file_exists: bool,
126131 close_dir_on_deinit: bool,
......@@ -131,17 +136,23 @@ pub const AtomicFile = struct {
131136 const RANDOM_BYTES = 12;
132137 const TMP_PATH_LEN = base64.Base64Encoder.calcSize(RANDOM_BYTES);
133138
134 /// TODO rename this. Callers should go through Dir API
135 pub fn init2(dest_path: []const u8, mode: File.Mode, dir: Dir, close_dir_on_deinit: bool) InitError!AtomicFile {
139 /// Note that the `Dir.atomicFile` API may be more handy than this lower-level function.
140 pub fn init(
141 dest_basename: []const u8,
142 mode: File.Mode,
143 dir: Dir,
144 close_dir_on_deinit: bool,
145 ) InitError!AtomicFile {
136146 var rand_buf: [RANDOM_BYTES]u8 = undefined;
137147 var tmp_path_buf: [TMP_PATH_LEN:0]u8 = undefined;
148 // TODO: should be able to use TMP_PATH_LEN here.
138149 tmp_path_buf[base64.Base64Encoder.calcSize(RANDOM_BYTES)] = 0;
139150
140151 while (true) {
141152 try crypto.randomBytes(rand_buf[0..]);
142153 base64_encoder.encode(&tmp_path_buf, &rand_buf);
143154
144 const file = dir.createFileC(
155 const file = dir.createFileZ(
145156 &tmp_path_buf,
146157 .{ .mode = mode, .exclusive = true },
147158 ) catch |err| switch (err) {
......@@ -152,7 +163,7 @@ pub const AtomicFile = struct {
152163 return AtomicFile{
153164 .file = file,
154165 .tmp_path_buf = tmp_path_buf,
155 .dest_path = dest_path,
166 .dest_basename = dest_basename,
156167 .file_open = true,
157168 .file_exists = true,
158169 .close_dir_on_deinit = close_dir_on_deinit,
......@@ -161,11 +172,6 @@ pub const AtomicFile = struct {
161172 }
162173 }
163174
164 /// Deprecated. Use `Dir.atomicFile`.
165 pub fn init(dest_path: []const u8, mode: File.Mode) InitError!AtomicFile {
166 return cwd().atomicFile(dest_path, .{ .mode = mode });
167 }
168
169175 /// always call deinit, even after successful finish()
170176 pub fn deinit(self: *AtomicFile) void {
171177 if (self.file_open) {
......@@ -173,7 +179,7 @@ pub const AtomicFile = struct {
173179 self.file_open = false;
174180 }
175181 if (self.file_exists) {
176 self.dir.deleteFileC(&self.tmp_path_buf) catch {};
182 self.dir.deleteFileZ(&self.tmp_path_buf) catch {};
177183 self.file_exists = false;
178184 }
179185 if (self.close_dir_on_deinit) {
......@@ -189,12 +195,12 @@ pub const AtomicFile = struct {
189195 self.file_open = false;
190196 }
191197 if (std.Target.current.os.tag == .windows) {
192 const dest_path_w = try os.windows.sliceToPrefixedFileW(self.dest_path);
198 const dest_path_w = try os.windows.sliceToPrefixedFileW(self.dest_basename);
193199 const tmp_path_w = try os.windows.cStrToPrefixedFileW(&self.tmp_path_buf);
194200 try os.renameatW(self.dir.fd, &tmp_path_w, self.dir.fd, &dest_path_w, os.windows.TRUE);
195201 self.file_exists = false;
196202 } else {
197 const dest_path_c = try os.toPosixPath(self.dest_path);
203 const dest_path_c = try os.toPosixPath(self.dest_basename);
198204 try os.renameatZ(self.dir.fd, &self.tmp_path_buf, self.dir.fd, &dest_path_c);
199205 self.file_exists = false;
200206 }
......@@ -213,7 +219,7 @@ pub fn makeDirAbsolute(absolute_path: []const u8) !void {
213219
214220/// Same as `makeDirAbsolute` except the parameter is a null-terminated UTF8-encoded string.
215221pub fn makeDirAbsoluteZ(absolute_path_z: [*:0]const u8) !void {
216 assert(path.isAbsoluteC(absolute_path_z));
222 assert(path.isAbsoluteZ(absolute_path_z));
217223 return os.mkdirZ(absolute_path_z, default_new_dir_mode);
218224}
219225
......@@ -224,18 +230,25 @@ pub fn makeDirAbsoluteW(absolute_path_w: [*:0]const u16) !void {
224230 os.windows.CloseHandle(handle);
225231}
226232
227/// Deprecated; use `Dir.deleteDir`.
228pub fn deleteDir(dir_path: []const u8) !void {
233pub const deleteDir = @compileError("deprecated; use dir.deleteDir or deleteDirAbsolute");
234pub const deleteDirC = @compileError("deprecated; use dir.deleteDirZ or deleteDirAbsoluteZ");
235pub const deleteDirW = @compileError("deprecated; use dir.deleteDirW or deleteDirAbsoluteW");
236
237/// Same as `Dir.deleteDir` except the path is absolute.
238pub fn deleteDirAbsolute(dir_path: []const u8) !void {
239 assert(path.isAbsolute(dir_path));
229240 return os.rmdir(dir_path);
230241}
231242
232/// Deprecated; use `Dir.deleteDirC`.
233pub fn deleteDirC(dir_path: [*:0]const u8) !void {
234 return os.rmdirC(dir_path);
243/// Same as `deleteDirAbsolute` except the path parameter is null-terminated.
244pub fn deleteDirAbsoluteZ(dir_path: [*:0]const u8) !void {
245 assert(path.isAbsoluteZ(dir_path));
246 return os.rmdirZ(dir_path);
235247}
236248
237/// Deprecated; use `Dir.deleteDirW`.
238pub fn deleteDirW(dir_path: [*:0]const u16) !void {
249/// Same as `deleteDirAbsolute` except the path parameter is WTF-16 and target OS is assumed Windows.
250pub fn deleteDirAbsoluteW(dir_path: [*:0]const u16) !void {
251 assert(path.isAbsoluteWindowsW(dir_path));
239252 return os.rmdirW(dir_path);
240253}
241254
......@@ -412,7 +425,7 @@ pub const Dir = struct {
412425 const next_index = self.index + linux_entry.reclen();
413426 self.index = next_index;
414427
415 const name = mem.toSlice(u8, @ptrCast([*:0]u8, &linux_entry.d_name));
428 const name = mem.spanZ(@ptrCast([*:0]u8, &linux_entry.d_name));
416429
417430 // skip . and .. entries
418431 if (mem.eql(u8, name, ".") or mem.eql(u8, name, "..")) {
......@@ -573,8 +586,7 @@ pub const Dir = struct {
573586 return self.openFileZ(&path_c, flags);
574587 }
575588
576 /// Deprecated; use `openFileZ`.
577 pub const openFileC = openFileZ;
589 pub const openFileC = @compileError("deprecated: renamed to openFileZ");
578590
579591 /// Same as `openFile` but the path parameter is null-terminated.
580592 pub fn openFileZ(self: Dir, sub_path: [*:0]const u8, flags: File.OpenFlags) File.OpenError!File {
......@@ -603,7 +615,7 @@ pub const Dir = struct {
603615 const fd = if (need_async_thread and !flags.always_blocking)
604616 try std.event.Loop.instance.?.openatZ(self.fd, sub_path, os_flags, 0)
605617 else
606 try os.openatC(self.fd, sub_path, os_flags, 0);
618 try os.openatZ(self.fd, sub_path, os_flags, 0);
607619
608620 // use fcntl file locking if no lock flag was given
609621 if (flags.lock and lock_flag == 0) {
......@@ -652,11 +664,13 @@ pub const Dir = struct {
652664 return self.createFileW(&path_w, flags);
653665 }
654666 const path_c = try os.toPosixPath(sub_path);
655 return self.createFileC(&path_c, flags);
667 return self.createFileZ(&path_c, flags);
656668 }
657669
670 pub const createFileC = @compileError("deprecated: renamed to createFileZ");
671
658672 /// Same as `createFile` but the path parameter is null-terminated.
659 pub fn createFileC(self: Dir, sub_path_c: [*:0]const u8, flags: File.CreateFlags) File.OpenError!File {
673 pub fn createFileZ(self: Dir, sub_path_c: [*:0]const u8, flags: File.CreateFlags) File.OpenError!File {
660674 if (builtin.os.tag == .windows) {
661675 const path_w = try os.windows.cStrToPrefixedFileW(sub_path_c);
662676 return self.createFileW(&path_w, flags);
......@@ -676,7 +690,7 @@ pub const Dir = struct {
676690 const fd = if (need_async_thread)
677691 try std.event.Loop.instance.?.openatZ(self.fd, sub_path_c, os_flags, flags.mode)
678692 else
679 try os.openatC(self.fd, sub_path_c, os_flags, flags.mode);
693 try os.openatZ(self.fd, sub_path_c, os_flags, flags.mode);
680694
681695 if (flags.lock and lock_flag == 0) {
682696 // TODO: integrate async I/O
......@@ -713,27 +727,16 @@ pub const Dir = struct {
713727 });
714728 }
715729
716 /// Deprecated; call `openFile` directly.
717 pub fn openRead(self: Dir, sub_path: []const u8) File.OpenError!File {
718 return self.openFile(sub_path, .{});
719 }
720
721 /// Deprecated; call `openFileZ` directly.
722 pub fn openReadC(self: Dir, sub_path: [*:0]const u8) File.OpenError!File {
723 return self.openFileZ(sub_path, .{});
724 }
725
726 /// Deprecated; call `openFileW` directly.
727 pub fn openReadW(self: Dir, sub_path: [*:0]const u16) File.OpenError!File {
728 return self.openFileW(sub_path, .{});
729 }
730 pub const openRead = @compileError("deprecated in favor of openFile");
731 pub const openReadC = @compileError("deprecated in favor of openFileZ");
732 pub const openReadW = @compileError("deprecated in favor of openFileW");
730733
731734 pub fn makeDir(self: Dir, sub_path: []const u8) !void {
732735 try os.mkdirat(self.fd, sub_path, default_new_dir_mode);
733736 }
734737
735738 pub fn makeDirZ(self: Dir, sub_path: [*:0]const u8) !void {
736 try os.mkdiratC(self.fd, sub_path, default_new_dir_mode);
739 try os.mkdiratZ(self.fd, sub_path, default_new_dir_mode);
737740 }
738741
739742 pub fn makeDirW(self: Dir, sub_path: [*:0]const u16) !void {
......@@ -807,20 +810,22 @@ pub const Dir = struct {
807810 return self.openDirW(&sub_path_w, args);
808811 } else {
809812 const sub_path_c = try os.toPosixPath(sub_path);
810 return self.openDirC(&sub_path_c, args);
813 return self.openDirZ(&sub_path_c, args);
811814 }
812815 }
813816
817 pub const openDirC = @compileError("deprecated: renamed to openDirZ");
818
814819 /// Same as `openDir` except the parameter is null-terminated.
815 pub fn openDirC(self: Dir, sub_path_c: [*:0]const u8, args: OpenDirOptions) OpenError!Dir {
820 pub fn openDirZ(self: Dir, sub_path_c: [*:0]const u8, args: OpenDirOptions) OpenError!Dir {
816821 if (builtin.os.tag == .windows) {
817822 const sub_path_w = try os.windows.cStrToPrefixedFileW(sub_path_c);
818823 return self.openDirW(&sub_path_w, args);
819824 } else if (!args.iterate) {
820825 const O_PATH = if (@hasDecl(os, "O_PATH")) os.O_PATH else 0;
821 return self.openDirFlagsC(sub_path_c, os.O_DIRECTORY | os.O_RDONLY | os.O_CLOEXEC | O_PATH);
826 return self.openDirFlagsZ(sub_path_c, os.O_DIRECTORY | os.O_RDONLY | os.O_CLOEXEC | O_PATH);
822827 } else {
823 return self.openDirFlagsC(sub_path_c, os.O_DIRECTORY | os.O_RDONLY | os.O_CLOEXEC);
828 return self.openDirFlagsZ(sub_path_c, os.O_DIRECTORY | os.O_RDONLY | os.O_CLOEXEC);
824829 }
825830 }
826831
......@@ -836,11 +841,11 @@ pub const Dir = struct {
836841 }
837842
838843 /// `flags` must contain `os.O_DIRECTORY`.
839 fn openDirFlagsC(self: Dir, sub_path_c: [*:0]const u8, flags: u32) OpenError!Dir {
844 fn openDirFlagsZ(self: Dir, sub_path_c: [*:0]const u8, flags: u32) OpenError!Dir {
840845 const result = if (need_async_thread)
841846 std.event.Loop.instance.?.openatZ(self.fd, sub_path_c, flags, 0)
842847 else
843 os.openatC(self.fd, sub_path_c, flags, 0);
848 os.openatZ(self.fd, sub_path_c, flags, 0);
844849 const fd = result catch |err| switch (err) {
845850 error.FileTooBig => unreachable, // can't happen for directories
846851 error.IsDir => unreachable, // we're providing O_DIRECTORY
......@@ -858,7 +863,7 @@ pub const Dir = struct {
858863 .fd = undefined,
859864 };
860865
861 const path_len_bytes = @intCast(u16, mem.toSliceConst(u16, sub_path_w).len * 2);
866 const path_len_bytes = @intCast(u16, mem.lenZ(sub_path_w) * 2);
862867 var nt_name = w.UNICODE_STRING{
863868 .Length = path_len_bytes,
864869 .MaximumLength = path_len_bytes,
......@@ -916,9 +921,11 @@ pub const Dir = struct {
916921 };
917922 }
918923
924 pub const deleteFileC = @compileError("deprecated: renamed to deleteFileZ");
925
919926 /// Same as `deleteFile` except the parameter is null-terminated.
920 pub fn deleteFileC(self: Dir, sub_path_c: [*:0]const u8) DeleteFileError!void {
921 os.unlinkatC(self.fd, sub_path_c, 0) catch |err| switch (err) {
927 pub fn deleteFileZ(self: Dir, sub_path_c: [*:0]const u8) DeleteFileError!void {
928 os.unlinkatZ(self.fd, sub_path_c, 0) catch |err| switch (err) {
922929 error.DirNotEmpty => unreachable, // not passing AT_REMOVEDIR
923930 else => |e| return e,
924931 };
......@@ -957,12 +964,12 @@ pub const Dir = struct {
957964 return self.deleteDirW(&sub_path_w);
958965 }
959966 const sub_path_c = try os.toPosixPath(sub_path);
960 return self.deleteDirC(&sub_path_c);
967 return self.deleteDirZ(&sub_path_c);
961968 }
962969
963970 /// Same as `deleteDir` except the parameter is null-terminated.
964 pub fn deleteDirC(self: Dir, sub_path_c: [*:0]const u8) DeleteDirError!void {
965 os.unlinkatC(self.fd, sub_path_c, os.AT_REMOVEDIR) catch |err| switch (err) {
971 pub fn deleteDirZ(self: Dir, sub_path_c: [*:0]const u8) DeleteDirError!void {
972 os.unlinkatZ(self.fd, sub_path_c, os.AT_REMOVEDIR) catch |err| switch (err) {
966973 error.IsDir => unreachable, // not possible since we pass AT_REMOVEDIR
967974 else => |e| return e,
968975 };
......@@ -982,12 +989,14 @@ pub const Dir = struct {
982989 /// Asserts that the path parameter has no null bytes.
983990 pub fn readLink(self: Dir, sub_path: []const u8, buffer: *[MAX_PATH_BYTES]u8) ![]u8 {
984991 const sub_path_c = try os.toPosixPath(sub_path);
985 return self.readLinkC(&sub_path_c, buffer);
992 return self.readLinkZ(&sub_path_c, buffer);
986993 }
987994
995 pub const readLinkC = @compileError("deprecated: renamed to readLinkZ");
996
988997 /// Same as `readLink`, except the `pathname` parameter is null-terminated.
989 pub fn readLinkC(self: Dir, sub_path_c: [*:0]const u8, buffer: *[MAX_PATH_BYTES]u8) ![]u8 {
990 return os.readlinkatC(self.fd, sub_path_c, buffer);
998 pub fn readLinkZ(self: Dir, sub_path_c: [*:0]const u8, buffer: *[MAX_PATH_BYTES]u8) ![]u8 {
999 return os.readlinkatZ(self.fd, sub_path_c, buffer);
9911000 }
9921001
9931002 /// On success, caller owns returned buffer.
......@@ -1005,7 +1014,7 @@ pub const Dir = struct {
10051014 max_bytes: usize,
10061015 comptime A: u29,
10071016 ) ![]align(A) u8 {
1008 var file = try self.openRead(file_path);
1017 var file = try self.openFile(file_path, .{});
10091018 defer file.close();
10101019
10111020 const size = math.cast(usize, try file.getEndPos()) catch math.maxInt(usize);
......@@ -1329,9 +1338,9 @@ pub const Dir = struct {
13291338 pub fn atomicFile(self: Dir, dest_path: []const u8, options: AtomicFileOptions) !AtomicFile {
13301339 if (path.dirname(dest_path)) |dirname| {
13311340 const dir = try self.openDir(dirname, .{});
1332 return AtomicFile.init2(path.basename(dest_path), options.mode, dir, true);
1341 return AtomicFile.init(path.basename(dest_path), options.mode, dir, true);
13331342 } else {
1334 return AtomicFile.init2(dest_path, options.mode, self, false);
1343 return AtomicFile.init(dest_path, options.mode, self, false);
13351344 }
13361345 }
13371346};
......@@ -1358,9 +1367,11 @@ pub fn openFileAbsolute(absolute_path: []const u8, flags: File.OpenFlags) File.O
13581367 return cwd().openFile(absolute_path, flags);
13591368}
13601369
1370pub const openFileAbsoluteC = @compileError("deprecated: renamed to openFileAbsoluteZ");
1371
13611372/// Same as `openFileAbsolute` but the path parameter is null-terminated.
1362pub fn openFileAbsoluteC(absolute_path_c: [*:0]const u8, flags: File.OpenFlags) File.OpenError!File {
1363 assert(path.isAbsoluteC(absolute_path_c));
1373pub fn openFileAbsoluteZ(absolute_path_c: [*:0]const u8, flags: File.OpenFlags) File.OpenError!File {
1374 assert(path.isAbsoluteZ(absolute_path_c));
13641375 return cwd().openFileZ(absolute_path_c, flags);
13651376}
13661377
......@@ -1381,10 +1392,12 @@ pub fn createFileAbsolute(absolute_path: []const u8, flags: File.CreateFlags) Fi
13811392 return cwd().createFile(absolute_path, flags);
13821393}
13831394
1395pub const createFileAbsoluteC = @compileError("deprecated: renamed to createFileAbsoluteZ");
1396
13841397/// Same as `createFileAbsolute` but the path parameter is null-terminated.
1385pub fn createFileAbsoluteC(absolute_path_c: [*:0]const u8, flags: File.CreateFlags) File.OpenError!File {
1386 assert(path.isAbsoluteC(absolute_path_c));
1387 return cwd().createFileC(absolute_path_c, flags);
1398pub fn createFileAbsoluteZ(absolute_path_c: [*:0]const u8, flags: File.CreateFlags) File.OpenError!File {
1399 assert(path.isAbsoluteZ(absolute_path_c));
1400 return cwd().createFileZ(absolute_path_c, flags);
13881401}
13891402
13901403/// Same as `createFileAbsolute` but the path parameter is WTF-16 encoded.
......@@ -1402,10 +1415,12 @@ pub fn deleteFileAbsolute(absolute_path: []const u8) DeleteFileError!void {
14021415 return cwd().deleteFile(absolute_path);
14031416}
14041417
1418pub const deleteFileAbsoluteC = @compileError("deprecated: renamed to deleteFileAbsoluteZ");
1419
14051420/// Same as `deleteFileAbsolute` except the parameter is null-terminated.
1406pub fn deleteFileAbsoluteC(absolute_path_c: [*:0]const u8) DeleteFileError!void {
1407 assert(path.isAbsoluteC(absolute_path_c));
1408 return cwd().deleteFileC(absolute_path_c);
1421pub fn deleteFileAbsoluteZ(absolute_path_c: [*:0]const u8) DeleteFileError!void {
1422 assert(path.isAbsoluteZ(absolute_path_c));
1423 return cwd().deleteFileZ(absolute_path_c);
14091424}
14101425
14111426/// Same as `deleteFileAbsolute` except the parameter is WTF-16 encoded.
......@@ -1433,15 +1448,31 @@ pub fn deleteTreeAbsolute(absolute_path: []const u8) !void {
14331448 return dir.deleteTree(path.basename(absolute_path));
14341449}
14351450
1451/// Same as `Dir.readLink`, except it asserts the path is absolute.
1452pub fn readLinkAbsolute(pathname: []const u8, buffer: *[MAX_PATH_BYTES]u8) ![]u8 {
1453 assert(path.isAbsolute(pathname));
1454 return os.readlink(pathname, buffer);
1455}
1456
1457/// Same as `readLink`, except the path parameter is null-terminated.
1458pub fn readLinkAbsoluteZ(pathname_c: [*]const u8, buffer: *[MAX_PATH_BYTES]u8) ![]u8 {
1459 assert(path.isAbsoluteZ(pathname_c));
1460 return os.readlinkZ(pathname_c, buffer);
1461}
1462
1463pub const readLink = @compileError("deprecated; use Dir.readLink or readLinkAbsolute");
1464pub const readLinkC = @compileError("deprecated; use Dir.readLinkZ or readLinkAbsoluteZ");
1465
14361466pub const Walker = struct {
14371467 stack: std.ArrayList(StackItem),
1438 name_buffer: std.Buffer,
1468 name_buffer: std.ArrayList(u8),
14391469
14401470 pub const Entry = struct {
14411471 /// The containing directory. This can be used to operate directly on `basename`
14421472 /// rather than `path`, avoiding `error.NameTooLong` for deeply nested paths.
14431473 /// The directory remains open until `next` or `deinit` is called.
14441474 dir: Dir,
1475 /// TODO make this null terminated for API convenience
14451476 basename: []const u8,
14461477
14471478 path: []const u8,
......@@ -1460,12 +1491,12 @@ pub const Walker = struct {
14601491 while (true) {
14611492 if (self.stack.len == 0) return null;
14621493 // `top` becomes invalid after appending to `self.stack`.
1463 const top = &self.stack.toSlice()[self.stack.len - 1];
1494 const top = &self.stack.span()[self.stack.len - 1];
14641495 const dirname_len = top.dirname_len;
14651496 if (try top.dir_it.next()) |base| {
14661497 self.name_buffer.shrink(dirname_len);
1467 try self.name_buffer.appendByte(path.sep);
1468 try self.name_buffer.append(base.name);
1498 try self.name_buffer.append(path.sep);
1499 try self.name_buffer.appendSlice(base.name);
14691500 if (base.kind == .Directory) {
14701501 var new_dir = top.dir_it.dir.openDir(base.name, .{ .iterate = true }) catch |err| switch (err) {
14711502 error.NameTooLong => unreachable, // no path sep in base.name
......@@ -1475,14 +1506,14 @@ pub const Walker = struct {
14751506 errdefer new_dir.close();
14761507 try self.stack.append(StackItem{
14771508 .dir_it = new_dir.iterate(),
1478 .dirname_len = self.name_buffer.len(),
1509 .dirname_len = self.name_buffer.len,
14791510 });
14801511 }
14811512 }
14821513 return Entry{
14831514 .dir = top.dir_it.dir,
1484 .basename = self.name_buffer.toSliceConst()[dirname_len + 1 ..],
1485 .path = self.name_buffer.toSliceConst(),
1515 .basename = self.name_buffer.span()[dirname_len + 1 ..],
1516 .path = self.name_buffer.span(),
14861517 .kind = base.kind,
14871518 };
14881519 } else {
......@@ -1508,9 +1539,11 @@ pub fn walkPath(allocator: *Allocator, dir_path: []const u8) !Walker {
15081539 var dir = try cwd().openDir(dir_path, .{ .iterate = true });
15091540 errdefer dir.close();
15101541
1511 var name_buffer = try std.Buffer.init(allocator, dir_path);
1542 var name_buffer = std.ArrayList(u8).init(allocator);
15121543 errdefer name_buffer.deinit();
15131544
1545 try name_buffer.appendSlice(dir_path);
1546
15141547 var walker = Walker{
15151548 .stack = std.ArrayList(Walker.StackItem).init(allocator),
15161549 .name_buffer = name_buffer,
......@@ -1524,31 +1557,21 @@ pub fn walkPath(allocator: *Allocator, dir_path: []const u8) !Walker {
15241557 return walker;
15251558}
15261559
1527/// Deprecated; use `Dir.readLink`.
1528pub fn readLink(pathname: []const u8, buffer: *[MAX_PATH_BYTES]u8) ![]u8 {
1529 return os.readlink(pathname, buffer);
1530}
1531
1532/// Deprecated; use `Dir.readLinkC`.
1533pub fn readLinkC(pathname_c: [*]const u8, buffer: *[MAX_PATH_BYTES]u8) ![]u8 {
1534 return os.readlinkC(pathname_c, buffer);
1535}
1536
15371560pub const OpenSelfExeError = os.OpenError || os.windows.CreateFileError || SelfExePathError || os.FcntlError;
15381561
15391562pub fn openSelfExe() OpenSelfExeError!File {
15401563 if (builtin.os.tag == .linux) {
1541 return openFileAbsoluteC("/proc/self/exe", .{});
1564 return openFileAbsoluteZ("/proc/self/exe", .{});
15421565 }
15431566 if (builtin.os.tag == .windows) {
15441567 const wide_slice = selfExePathW();
15451568 const prefixed_path_w = try os.windows.wToPrefixedFileW(wide_slice);
1546 return cwd().openReadW(&prefixed_path_w);
1569 return cwd().openFileW(&prefixed_path_w, .{});
15471570 }
15481571 var buf: [MAX_PATH_BYTES]u8 = undefined;
15491572 const self_exe_path = try selfExePath(&buf);
15501573 buf[self_exe_path.len] = 0;
1551 return openFileAbsoluteC(self_exe_path[0..self_exe_path.len :0].ptr, .{});
1574 return openFileAbsoluteZ(self_exe_path[0..self_exe_path.len :0].ptr, .{});
15521575}
15531576
15541577test "openSelfExe" {
......@@ -1582,23 +1605,23 @@ pub fn selfExePath(out_buffer: *[MAX_PATH_BYTES]u8) SelfExePathError![]u8 {
15821605 var u32_len: u32 = out_buffer.len;
15831606 const rc = std.c._NSGetExecutablePath(out_buffer, &u32_len);
15841607 if (rc != 0) return error.NameTooLong;
1585 return mem.toSlice(u8, @ptrCast([*:0]u8, out_buffer));
1608 return mem.spanZ(@ptrCast([*:0]u8, out_buffer));
15861609 }
15871610 switch (builtin.os.tag) {
1588 .linux => return os.readlinkC("/proc/self/exe", out_buffer),
1611 .linux => return os.readlinkZ("/proc/self/exe", out_buffer),
15891612 .freebsd, .dragonfly => {
15901613 var mib = [4]c_int{ os.CTL_KERN, os.KERN_PROC, os.KERN_PROC_PATHNAME, -1 };
15911614 var out_len: usize = out_buffer.len;
15921615 try os.sysctl(&mib, out_buffer, &out_len, null, 0);
15931616 // TODO could this slice from 0 to out_len instead?
1594 return mem.toSlice(u8, @ptrCast([*:0]u8, out_buffer));
1617 return mem.spanZ(@ptrCast([*:0]u8, out_buffer));
15951618 },
15961619 .netbsd => {
15971620 var mib = [4]c_int{ os.CTL_KERN, os.KERN_PROC_ARGS, -1, os.KERN_PROC_PATHNAME };
15981621 var out_len: usize = out_buffer.len;
15991622 try os.sysctl(&mib, out_buffer, &out_len, null, 0);
16001623 // TODO could this slice from 0 to out_len instead?
1601 return mem.toSlice(u8, @ptrCast([*:0]u8, out_buffer));
1624 return mem.spanZ(@ptrCast([*:0]u8, out_buffer));
16021625 },
16031626 .windows => {
16041627 const utf16le_slice = selfExePathW();
......@@ -1613,7 +1636,7 @@ pub fn selfExePath(out_buffer: *[MAX_PATH_BYTES]u8) SelfExePathError![]u8 {
16131636/// The result is UTF16LE-encoded.
16141637pub fn selfExePathW() [:0]const u16 {
16151638 const image_path_name = &os.windows.peb().ProcessParameters.ImagePathName;
1616 return mem.toSliceConst(u16, @ptrCast([*:0]const u16, image_path_name.Buffer));
1639 return mem.spanZ(@ptrCast([*:0]const u16, image_path_name.Buffer));
16171640}
16181641
16191642/// `selfExeDirPath` except allocates the result on the heap.
lib/std/fs/file.zig+1-1
......@@ -110,7 +110,7 @@ pub const File = struct {
110110 if (self.isTty()) {
111111 if (self.handle == os.STDOUT_FILENO or self.handle == os.STDERR_FILENO) {
112112 // Use getenvC to workaround https://github.com/ziglang/zig/issues/3511
113 if (os.getenvC("TERM")) |term| {
113 if (os.getenvZ("TERM")) |term| {
114114 if (std.mem.eql(u8, term, "dumb"))
115115 return false;
116116 }
lib/std/fs/get_app_data_dir.zig+1-1
......@@ -24,7 +24,7 @@ pub fn getAppDataDir(allocator: *mem.Allocator, appname: []const u8) GetAppDataD
2424 )) {
2525 os.windows.S_OK => {
2626 defer os.windows.ole32.CoTaskMemFree(@ptrCast(*c_void, dir_path_ptr));
27 const global_dir = unicode.utf16leToUtf8Alloc(allocator, mem.toSliceConst(u16, dir_path_ptr)) catch |err| switch (err) {
27 const global_dir = unicode.utf16leToUtf8Alloc(allocator, mem.spanZ(dir_path_ptr)) catch |err| switch (err) {
2828 error.UnexpectedSecondSurrogateHalf => return error.AppDataDirUnavailable,
2929 error.ExpectedSecondSurrogateHalf => return error.AppDataDirUnavailable,
3030 error.DanglingSurrogateHalf => return error.AppDataDirUnavailable,
lib/std/fs/path.zig+14-8
......@@ -128,11 +128,13 @@ test "join" {
128128 testJoinPosix(&[_][]const u8{ "a/", "/c" }, "a/c");
129129}
130130
131pub fn isAbsoluteC(path_c: [*:0]const u8) bool {
131pub const isAbsoluteC = @compileError("deprecated: renamed to isAbsoluteZ");
132
133pub fn isAbsoluteZ(path_c: [*:0]const u8) bool {
132134 if (builtin.os.tag == .windows) {
133 return isAbsoluteWindowsC(path_c);
135 return isAbsoluteWindowsZ(path_c);
134136 } else {
135 return isAbsolutePosixC(path_c);
137 return isAbsolutePosixZ(path_c);
136138 }
137139}
138140
......@@ -172,19 +174,23 @@ pub fn isAbsoluteWindows(path: []const u8) bool {
172174}
173175
174176pub fn isAbsoluteWindowsW(path_w: [*:0]const u16) bool {
175 return isAbsoluteWindowsImpl(u16, mem.toSliceConst(u16, path_w));
177 return isAbsoluteWindowsImpl(u16, mem.spanZ(path_w));
176178}
177179
178pub fn isAbsoluteWindowsC(path_c: [*:0]const u8) bool {
179 return isAbsoluteWindowsImpl(u8, mem.toSliceConst(u8, path_c));
180pub const isAbsoluteWindowsC = @compileError("deprecated: renamed to isAbsoluteWindowsZ");
181
182pub fn isAbsoluteWindowsZ(path_c: [*:0]const u8) bool {
183 return isAbsoluteWindowsImpl(u8, mem.spanZ(path_c));
180184}
181185
182186pub fn isAbsolutePosix(path: []const u8) bool {
183187 return path.len > 0 and path[0] == sep_posix;
184188}
185189
186pub fn isAbsolutePosixC(path_c: [*:0]const u8) bool {
187 return isAbsolutePosix(mem.toSliceConst(u8, path_c));
190pub const isAbsolutePosixC = @compileError("deprecated: renamed to isAbsolutePosixZ");
191
192pub fn isAbsolutePosixZ(path_c: [*:0]const u8) bool {
193 return isAbsolutePosix(mem.spanZ(path_c));
188194}
189195
190196test "isAbsoluteWindows" {
lib/std/fs/watch.zig+1-1
......@@ -326,7 +326,7 @@ pub fn Watch(comptime V: type) type {
326326 var basename_with_null_consumed = false;
327327 defer if (!basename_with_null_consumed) self.allocator.free(basename_with_null);
328328
329 const wd = try os.inotify_add_watchC(
329 const wd = try os.inotify_add_watchZ(
330330 self.os_data.inotify_fd,
331331 dirname_with_null.ptr,
332332 os.linux.IN_CLOSE_WRITE | os.linux.IN_ONLYDIR | os.linux.IN_EXCL_UNLINK,
lib/std/hash/adler.zig+29-8
......@@ -42,18 +42,23 @@ pub const Adler32 = struct {
4242
4343 s2 %= base;
4444 } else {
45 const n = nmax / 16; // note: 16 | nmax
46
4547 var i: usize = 0;
46 while (i + nmax <= input.len) : (i += nmax) {
47 const n = nmax / 16; // note: 16 | nmax
4848
49 while (i + nmax <= input.len) {
4950 var rounds: usize = 0;
5051 while (rounds < n) : (rounds += 1) {
5152 comptime var j: usize = 0;
5253 inline while (j < 16) : (j += 1) {
53 s1 +%= input[i + n * j];
54 s1 +%= input[i + j];
5455 s2 +%= s1;
5556 }
57 i += 16;
5658 }
59
60 s1 %= base;
61 s2 %= base;
5762 }
5863
5964 if (i < input.len) {
......@@ -89,19 +94,35 @@ pub const Adler32 = struct {
8994};
9095
9196test "adler32 sanity" {
92 testing.expect(Adler32.hash("a") == 0x620062);
93 testing.expect(Adler32.hash("example") == 0xbc002ed);
97 testing.expectEqual(@as(u32, 0x620062), Adler32.hash("a"));
98 testing.expectEqual(@as(u32, 0xbc002ed), Adler32.hash("example"));
9499}
95100
96101test "adler32 long" {
97102 const long1 = [_]u8{1} ** 1024;
98 testing.expect(Adler32.hash(long1[0..]) == 0x06780401);
103 testing.expectEqual(@as(u32, 0x06780401), Adler32.hash(long1[0..]));
99104
100105 const long2 = [_]u8{1} ** 1025;
101 testing.expect(Adler32.hash(long2[0..]) == 0x0a7a0402);
106 testing.expectEqual(@as(u32, 0x0a7a0402), Adler32.hash(long2[0..]));
102107}
103108
104109test "adler32 very long" {
105110 const long = [_]u8{1} ** 5553;
106 testing.expect(Adler32.hash(long[0..]) == 0x707f15b2);
111 testing.expectEqual(@as(u32, 0x707f15b2), Adler32.hash(long[0..]));
112}
113
114test "adler32 very long with variation" {
115 const long = comptime blk: {
116 @setEvalBranchQuota(7000);
117 var result: [6000]u8 = undefined;
118
119 var i: usize = 0;
120 while (i < result.len) : (i += 1) {
121 result[i] = @truncate(u8, i);
122 }
123
124 break :blk result;
125 };
126
127 testing.expectEqual(@as(u32, 0x5af38d6e), std.hash.Adler32.hash(long[0..]));
107128}
lib/std/heap.zig+1-2
......@@ -51,8 +51,7 @@ var wasm_page_allocator_state = Allocator{
5151 .shrinkFn = WasmPageAllocator.shrink,
5252};
5353
54/// Deprecated. Use `page_allocator`.
55pub const direct_allocator = page_allocator;
54pub const direct_allocator = @compileError("deprecated; use std.heap.page_allocator");
5655
5756const PageAllocator = struct {
5857 fn alloc(allocator: *Allocator, n: usize, alignment: u29) error{OutOfMemory}![]u8 {
lib/std/http/headers.zig+8-8
......@@ -129,7 +129,7 @@ pub const Headers = struct {
129129 self.index.deinit();
130130 }
131131 {
132 for (self.data.toSliceConst()) |entry| {
132 for (self.data.span()) |entry| {
133133 entry.deinit();
134134 }
135135 self.data.deinit();
......@@ -141,14 +141,14 @@ pub const Headers = struct {
141141 errdefer other.deinit();
142142 try other.data.ensureCapacity(self.data.len);
143143 try other.index.initCapacity(self.index.entries.len);
144 for (self.data.toSliceConst()) |entry| {
144 for (self.data.span()) |entry| {
145145 try other.append(entry.name, entry.value, entry.never_index);
146146 }
147147 return other;
148148 }
149149
150150 pub fn toSlice(self: Self) []const HeaderEntry {
151 return self.data.toSliceConst();
151 return self.data.span();
152152 }
153153
154154 pub fn append(self: *Self, name: []const u8, value: []const u8, never_index: ?bool) !void {
......@@ -279,7 +279,7 @@ pub const Headers = struct {
279279
280280 const buf = try allocator.alloc(HeaderEntry, dex.len);
281281 var n: usize = 0;
282 for (dex.toSliceConst()) |idx| {
282 for (dex.span()) |idx| {
283283 buf[n] = self.data.at(idx);
284284 n += 1;
285285 }
......@@ -302,7 +302,7 @@ pub const Headers = struct {
302302 // adapted from mem.join
303303 const total_len = blk: {
304304 var sum: usize = dex.len - 1; // space for separator(s)
305 for (dex.toSliceConst()) |idx|
305 for (dex.span()) |idx|
306306 sum += self.data.at(idx).value.len;
307307 break :blk sum;
308308 };
......@@ -334,7 +334,7 @@ pub const Headers = struct {
334334 }
335335 }
336336 { // fill up indexes again; we know capacity is fine from before
337 for (self.data.toSliceConst()) |entry, i| {
337 for (self.data.span()) |entry, i| {
338338 var dex = &self.index.get(entry.name).?.value;
339339 dex.appendAssumeCapacity(i);
340340 }
......@@ -495,8 +495,8 @@ test "Headers.getIndices" {
495495 try h.append("set-cookie", "y=2", null);
496496
497497 testing.expect(null == h.getIndices("not-present"));
498 testing.expectEqualSlices(usize, &[_]usize{0}, h.getIndices("foo").?.toSliceConst());
499 testing.expectEqualSlices(usize, &[_]usize{ 1, 2 }, h.getIndices("set-cookie").?.toSliceConst());
498 testing.expectEqualSlices(usize, &[_]usize{0}, h.getIndices("foo").?.span());
499 testing.expectEqualSlices(usize, &[_]usize{ 1, 2 }, h.getIndices("set-cookie").?.span());
500500}
501501
502502test "Headers.get" {
lib/std/io.zig+17-10
......@@ -128,16 +128,6 @@ pub const BufferedAtomicFile = @import("io/buffered_atomic_file.zig").BufferedAt
128128
129129pub const StreamSource = @import("io/stream_source.zig").StreamSource;
130130
131/// Deprecated; use `std.fs.Dir.writeFile`.
132pub fn writeFile(path: []const u8, data: []const u8) !void {
133 return fs.cwd().writeFile(path, data);
134}
135
136/// Deprecated; use `std.fs.Dir.readFileAlloc`.
137pub fn readFileAlloc(allocator: *mem.Allocator, path: []const u8) ![]u8 {
138 return fs.cwd().readFileAlloc(allocator, path, math.maxInt(usize));
139}
140
141131/// An OutStream that doesn't write to anything.
142132pub const null_out_stream = @as(NullOutStream, .{ .context = {} });
143133
......@@ -151,5 +141,22 @@ test "null_out_stream" {
151141}
152142
153143test "" {
144 _ = @import("io/bit_in_stream.zig");
145 _ = @import("io/bit_out_stream.zig");
146 _ = @import("io/buffered_atomic_file.zig");
147 _ = @import("io/buffered_in_stream.zig");
148 _ = @import("io/buffered_out_stream.zig");
149 _ = @import("io/c_out_stream.zig");
150 _ = @import("io/counting_out_stream.zig");
151 _ = @import("io/fixed_buffer_stream.zig");
152 _ = @import("io/in_stream.zig");
153 _ = @import("io/out_stream.zig");
154 _ = @import("io/peek_stream.zig");
155 _ = @import("io/seekable_stream.zig");
156 _ = @import("io/serialization.zig");
157 _ = @import("io/stream_source.zig");
154158 _ = @import("io/test.zig");
155159}
160
161pub const writeFile = @compileError("deprecated: use std.fs.Dir.writeFile with math.maxInt(usize)");
162pub const readFileAlloc = @compileError("deprecated: use std.fs.Dir.readFileAlloc");
lib/std/io/buffered_atomic_file.zig+2-1
......@@ -15,6 +15,7 @@ pub const BufferedAtomicFile = struct {
1515
1616 /// TODO when https://github.com/ziglang/zig/issues/2761 is solved
1717 /// this API will not need an allocator
18 /// TODO integrate this with Dir API
1819 pub fn create(allocator: *mem.Allocator, dest_path: []const u8) !*BufferedAtomicFile {
1920 var self = try allocator.create(BufferedAtomicFile);
2021 self.* = BufferedAtomicFile{
......@@ -25,7 +26,7 @@ pub const BufferedAtomicFile = struct {
2526 };
2627 errdefer allocator.destroy(self);
2728
28 self.atomic_file = try fs.AtomicFile.init(dest_path, File.default_mode);
29 self.atomic_file = try fs.cwd().atomicFile(dest_path, .{});
2930 errdefer self.atomic_file.deinit();
3031
3132 self.file_stream = self.atomic_file.file.outStream();
lib/std/io/c_out_stream.zig+2-2
......@@ -36,9 +36,9 @@ test "" {
3636 const out_file = std.c.fopen(filename, "w") orelse return error.UnableToOpenTestFile;
3737 defer {
3838 _ = std.c.fclose(out_file);
39 fs.cwd().deleteFileC(filename) catch {};
39 std.fs.cwd().deleteFileZ(filename) catch {};
4040 }
4141
42 const out_stream = &io.COutStream.init(out_file).stream;
42 const out_stream = cOutStream(out_file);
4343 try out_stream.print("hi: {}\n", .{@as(i32, 123)});
4444}
lib/std/io/in_stream.zig+1-8
......@@ -3,7 +3,6 @@ const builtin = std.builtin;
33const math = std.math;
44const assert = std.debug.assert;
55const mem = std.mem;
6const Buffer = std.Buffer;
76const testing = std.testing;
87
98pub fn InStream(
......@@ -48,13 +47,7 @@ pub fn InStream(
4847 if (amt_read < buf.len) return error.EndOfStream;
4948 }
5049
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 }
50 pub const readAllBuffer = @compileError("deprecated; use readAllArrayList()");
5851
5952 /// Appends to the `std.ArrayList` contents by reading from the stream until end of stream is found.
6053 /// If the number of bytes appended would exceed `max_append_size`, `error.StreamTooLong` is returned
lib/std/io/peek_stream.zig+4-4
......@@ -24,7 +24,7 @@ pub fn PeekStream(
2424 .Static => struct {
2525 pub fn init(base: InStreamType) Self {
2626 return .{
27 .base = base,
27 .unbuffered_in_stream = base,
2828 .fifo = FifoType.init(),
2929 };
3030 }
......@@ -32,7 +32,7 @@ pub fn PeekStream(
3232 .Slice => struct {
3333 pub fn init(base: InStreamType, buf: []u8) Self {
3434 return .{
35 .base = base,
35 .unbuffered_in_stream = base,
3636 .fifo = FifoType.init(buf),
3737 };
3838 }
......@@ -40,7 +40,7 @@ pub fn PeekStream(
4040 .Dynamic => struct {
4141 pub fn init(base: InStreamType, allocator: *mem.Allocator) Self {
4242 return .{
43 .base = base,
43 .unbuffered_in_stream = base,
4444 .fifo = FifoType.init(allocator),
4545 };
4646 }
......@@ -61,7 +61,7 @@ pub fn PeekStream(
6161 if (dest_index == dest.len) return dest_index;
6262
6363 // ask the backing stream for more
64 dest_index += try self.base.read(dest[dest_index..]);
64 dest_index += try self.unbuffered_in_stream.read(dest[dest_index..]);
6565 return dest_index;
6666 }
6767
lib/std/io/serialization.zig+50-49
......@@ -5,6 +5,7 @@ const assert = std.debug.assert;
55const math = std.math;
66const meta = std.meta;
77const trait = meta.trait;
8const testing = std.testing;
89
910pub const Packing = enum {
1011 /// Pack data to byte alignment
......@@ -273,7 +274,7 @@ pub fn Serializer(comptime endian: builtin.Endian, comptime packing: Packing, co
273274 if (comptime trait.hasFn("serialize")(T)) return T.serialize(value, self);
274275
275276 if (comptime trait.isPacked(T) and packing != .Bit) {
276 var packed_serializer = Serializer(endian, .Bit, Error).init(self.out_stream);
277 var packed_serializer = Serializer(endian, .Bit, OutStreamType).init(self.out_stream);
277278 try packed_serializer.serialize(value);
278279 try packed_serializer.flush();
279280 return;
......@@ -364,28 +365,28 @@ fn testIntSerializerDeserializer(comptime endian: builtin.Endian, comptime packi
364365
365366 var data_mem: [total_bytes]u8 = undefined;
366367 var out = io.fixedBufferStream(&data_mem);
367 var serializer = serializer(endian, packing, out.outStream());
368 var _serializer = serializer(endian, packing, out.outStream());
368369
369370 var in = io.fixedBufferStream(&data_mem);
370 var deserializer = Deserializer(endian, packing, in.inStream());
371 var _deserializer = deserializer(endian, packing, in.inStream());
371372
372373 comptime var i = 0;
373374 inline while (i <= max_test_bitsize) : (i += 1) {
374375 const U = std.meta.IntType(false, i);
375376 const S = std.meta.IntType(true, i);
376 try serializer.serializeInt(@as(U, i));
377 if (i != 0) try serializer.serializeInt(@as(S, -1)) else try serializer.serialize(@as(S, 0));
377 try _serializer.serializeInt(@as(U, i));
378 if (i != 0) try _serializer.serializeInt(@as(S, -1)) else try _serializer.serialize(@as(S, 0));
378379 }
379 try serializer.flush();
380 try _serializer.flush();
380381
381382 i = 0;
382383 inline while (i <= max_test_bitsize) : (i += 1) {
383384 const U = std.meta.IntType(false, i);
384385 const S = std.meta.IntType(true, i);
385 const x = try deserializer.deserializeInt(U);
386 const y = try deserializer.deserializeInt(S);
387 expect(x == @as(U, i));
388 if (i != 0) expect(y == @as(S, -1)) else expect(y == 0);
386 const x = try _deserializer.deserializeInt(U);
387 const y = try _deserializer.deserializeInt(S);
388 testing.expect(x == @as(U, i));
389 if (i != 0) testing.expect(y == @as(S, -1)) else testing.expect(y == 0);
389390 }
390391
391392 const u8_bit_count = comptime meta.bitCount(u8);
......@@ -395,7 +396,7 @@ fn testIntSerializerDeserializer(comptime endian: builtin.Endian, comptime packi
395396 const extra_packed_byte = @boolToInt(total_bits % u8_bit_count > 0);
396397 const total_packed_bytes = (total_bits / u8_bit_count) + extra_packed_byte;
397398
398 expect(in.pos == if (packing == .Bit) total_packed_bytes else total_bytes);
399 testing.expect(in.pos == if (packing == .Bit) total_packed_bytes else total_bytes);
399400
400401 //Verify that empty error set works with serializer.
401402 //deserializer is covered by FixedBufferStream
......@@ -421,35 +422,35 @@ fn testIntSerializerDeserializerInfNaN(
421422 var data_mem: [mem_size]u8 = undefined;
422423
423424 var out = io.fixedBufferStream(&data_mem);
424 var serializer = serializer(endian, packing, out.outStream());
425 var _serializer = serializer(endian, packing, out.outStream());
425426
426427 var in = io.fixedBufferStream(&data_mem);
427 var deserializer = deserializer(endian, packing, in.inStream());
428 var _deserializer = deserializer(endian, packing, in.inStream());
428429
429430 //@TODO: isInf/isNan not currently implemented for f128.
430 try serializer.serialize(std.math.nan(f16));
431 try serializer.serialize(std.math.inf(f16));
432 try serializer.serialize(std.math.nan(f32));
433 try serializer.serialize(std.math.inf(f32));
434 try serializer.serialize(std.math.nan(f64));
435 try serializer.serialize(std.math.inf(f64));
431 try _serializer.serialize(std.math.nan(f16));
432 try _serializer.serialize(std.math.inf(f16));
433 try _serializer.serialize(std.math.nan(f32));
434 try _serializer.serialize(std.math.inf(f32));
435 try _serializer.serialize(std.math.nan(f64));
436 try _serializer.serialize(std.math.inf(f64));
436437 //try serializer.serialize(std.math.nan(f128));
437438 //try serializer.serialize(std.math.inf(f128));
438 const nan_check_f16 = try deserializer.deserialize(f16);
439 const inf_check_f16 = try deserializer.deserialize(f16);
440 const nan_check_f32 = try deserializer.deserialize(f32);
441 deserializer.alignToByte();
442 const inf_check_f32 = try deserializer.deserialize(f32);
443 const nan_check_f64 = try deserializer.deserialize(f64);
444 const inf_check_f64 = try deserializer.deserialize(f64);
439 const nan_check_f16 = try _deserializer.deserialize(f16);
440 const inf_check_f16 = try _deserializer.deserialize(f16);
441 const nan_check_f32 = try _deserializer.deserialize(f32);
442 _deserializer.alignToByte();
443 const inf_check_f32 = try _deserializer.deserialize(f32);
444 const nan_check_f64 = try _deserializer.deserialize(f64);
445 const inf_check_f64 = try _deserializer.deserialize(f64);
445446 //const nan_check_f128 = try deserializer.deserialize(f128);
446447 //const inf_check_f128 = try deserializer.deserialize(f128);
447 expect(std.math.isNan(nan_check_f16));
448 expect(std.math.isInf(inf_check_f16));
449 expect(std.math.isNan(nan_check_f32));
450 expect(std.math.isInf(inf_check_f32));
451 expect(std.math.isNan(nan_check_f64));
452 expect(std.math.isInf(inf_check_f64));
448 testing.expect(std.math.isNan(nan_check_f16));
449 testing.expect(std.math.isInf(inf_check_f16));
450 testing.expect(std.math.isNan(nan_check_f32));
451 testing.expect(std.math.isInf(inf_check_f32));
452 testing.expect(std.math.isNan(nan_check_f64));
453 testing.expect(std.math.isInf(inf_check_f64));
453454 //expect(std.math.isNan(nan_check_f128));
454455 //expect(std.math.isInf(inf_check_f128));
455456}
......@@ -461,8 +462,8 @@ test "Serializer/Deserializer Int: Inf/NaN" {
461462 try testIntSerializerDeserializerInfNaN(.Little, .Bit);
462463}
463464
464fn testAlternateSerializer(self: var, serializer: var) !void {
465 try serializer.serialize(self.f_f16);
465fn testAlternateSerializer(self: var, _serializer: var) !void {
466 try _serializer.serialize(self.f_f16);
466467}
467468
468469fn testSerializerDeserializer(comptime endian: builtin.Endian, comptime packing: io.Packing) !void {
......@@ -502,8 +503,8 @@ fn testSerializerDeserializer(comptime endian: builtin.Endian, comptime packing:
502503 f_f16: f16,
503504 f_unused_u32: u32,
504505
505 pub fn deserialize(self: *@This(), deserializer: var) !void {
506 try deserializer.deserializeInto(&self.f_f16);
506 pub fn deserialize(self: *@This(), _deserializer: var) !void {
507 try _deserializer.deserializeInto(&self.f_f16);
507508 self.f_unused_u32 = 47;
508509 }
509510
......@@ -550,15 +551,15 @@ fn testSerializerDeserializer(comptime endian: builtin.Endian, comptime packing:
550551
551552 var data_mem: [@sizeOf(MyStruct)]u8 = undefined;
552553 var out = io.fixedBufferStream(&data_mem);
553 var serializer = serializer(endian, packing, out.outStream());
554 var _serializer = serializer(endian, packing, out.outStream());
554555
555556 var in = io.fixedBufferStream(&data_mem);
556 var deserializer = deserializer(endian, packing, in.inStream());
557 var _deserializer = deserializer(endian, packing, in.inStream());
557558
558 try serializer.serialize(my_inst);
559 try _serializer.serialize(my_inst);
559560
560 const my_copy = try deserializer.deserialize(MyStruct);
561 expect(meta.eql(my_copy, my_inst));
561 const my_copy = try _deserializer.deserialize(MyStruct);
562 testing.expect(meta.eql(my_copy, my_inst));
562563}
563564
564565test "Serializer/Deserializer generic" {
......@@ -584,18 +585,18 @@ fn testBadData(comptime endian: builtin.Endian, comptime packing: io.Packing) !v
584585 };
585586
586587 var data_mem: [4]u8 = undefined;
587 var out = io.fixedBufferStream.init(&data_mem);
588 var serializer = serializer(endian, packing, out.outStream());
588 var out = io.fixedBufferStream(&data_mem);
589 var _serializer = serializer(endian, packing, out.outStream());
589590
590591 var in = io.fixedBufferStream(&data_mem);
591 var deserializer = deserializer(endian, packing, in.inStream());
592 var _deserializer = deserializer(endian, packing, in.inStream());
592593
593 try serializer.serialize(@as(u14, 3));
594 expectError(error.InvalidEnumTag, deserializer.deserialize(A));
594 try _serializer.serialize(@as(u14, 3));
595 testing.expectError(error.InvalidEnumTag, _deserializer.deserialize(A));
595596 out.pos = 0;
596 try serializer.serialize(@as(u14, 3));
597 try serializer.serialize(@as(u14, 88));
598 expectError(error.InvalidEnumTag, deserializer.deserialize(C));
597 try _serializer.serialize(@as(u14, 3));
598 try _serializer.serialize(@as(u14, 88));
599 testing.expectError(error.InvalidEnumTag, _deserializer.deserialize(C));
599600}
600601
601602test "Deserializer bad data" {
lib/std/json.zig+328-95
......@@ -1233,42 +1233,119 @@ pub const Value = union(enum) {
12331233 Array: Array,
12341234 Object: ObjectMap,
12351235
1236 pub fn jsonStringify(
1237 value: @This(),
1238 options: StringifyOptions,
1239 out_stream: var,
1240 ) @TypeOf(out_stream).Error!void {
1241 switch (value) {
1242 .Null => try stringify(null, options, out_stream),
1243 .Bool => |inner| try stringify(inner, options, out_stream),
1244 .Integer => |inner| try stringify(inner, options, out_stream),
1245 .Float => |inner| try stringify(inner, options, out_stream),
1246 .String => |inner| try stringify(inner, options, out_stream),
1247 .Array => |inner| try stringify(inner.span(), options, out_stream),
1248 .Object => |inner| {
1249 try out_stream.writeByte('{');
1250 var field_output = false;
1251 var child_options = options;
1252 if (child_options.whitespace) |*child_whitespace| {
1253 child_whitespace.indent_level += 1;
1254 }
1255 var it = inner.iterator();
1256 while (it.next()) |entry| {
1257 if (!field_output) {
1258 field_output = true;
1259 } else {
1260 try out_stream.writeByte(',');
1261 }
1262 if (child_options.whitespace) |child_whitespace| {
1263 try out_stream.writeByte('\n');
1264 try child_whitespace.outputIndent(out_stream);
1265 }
1266
1267 try stringify(entry.key, options, out_stream);
1268 try out_stream.writeByte(':');
1269 if (child_options.whitespace) |child_whitespace| {
1270 if (child_whitespace.separator) {
1271 try out_stream.writeByte(' ');
1272 }
1273 }
1274 try stringify(entry.value, child_options, out_stream);
1275 }
1276 if (field_output) {
1277 if (options.whitespace) |whitespace| {
1278 try out_stream.writeByte('\n');
1279 try whitespace.outputIndent(out_stream);
1280 }
1281 }
1282 try out_stream.writeByte('}');
1283 },
1284 }
1285 }
1286
12361287 pub fn dump(self: Value) void {
12371288 var held = std.debug.getStderrMutex().acquire();
12381289 defer held.release();
12391290
12401291 const stderr = std.debug.getStderrStream();
1241 self.dumpStream(stderr, 1024) catch return;
1292 std.json.stringify(self, std.json.StringifyOptions{ .whitespace = null }, stderr) catch return;
12421293 }
1294};
12431295
1244 pub fn dumpIndent(self: Value, comptime indent: usize) void {
1245 if (indent == 0) {
1246 self.dump();
1247 } else {
1248 var held = std.debug.getStderrMutex().acquire();
1249 defer held.release();
1250
1251 const stderr = std.debug.getStderrStream();
1252 self.dumpStreamIndent(indent, stderr, 1024) catch return;
1253 }
1296test "Value.jsonStringify" {
1297 {
1298 var buffer: [10]u8 = undefined;
1299 var fbs = std.io.fixedBufferStream(&buffer);
1300 try @as(Value, .Null).jsonStringify(.{}, fbs.outStream());
1301 testing.expectEqualSlices(u8, fbs.getWritten(), "null");
12541302 }
1255
1256 pub fn dumpStream(self: @This(), stream: var, comptime max_depth: usize) !void {
1257 var w = std.json.WriteStream(@TypeOf(stream).Child, max_depth).init(stream);
1258 w.newline = "";
1259 w.one_indent = "";
1260 w.space = "";
1261 try w.emitJson(self);
1303 {
1304 var buffer: [10]u8 = undefined;
1305 var fbs = std.io.fixedBufferStream(&buffer);
1306 try (Value{ .Bool = true }).jsonStringify(.{}, fbs.outStream());
1307 testing.expectEqualSlices(u8, fbs.getWritten(), "true");
12621308 }
1263
1264 pub fn dumpStreamIndent(self: @This(), comptime indent: usize, stream: var, comptime max_depth: usize) !void {
1265 var one_indent = " " ** indent;
1266
1267 var w = std.json.WriteStream(@TypeOf(stream).Child, max_depth).init(stream);
1268 w.one_indent = one_indent;
1269 try w.emitJson(self);
1309 {
1310 var buffer: [10]u8 = undefined;
1311 var fbs = std.io.fixedBufferStream(&buffer);
1312 try (Value{ .Integer = 42 }).jsonStringify(.{}, fbs.outStream());
1313 testing.expectEqualSlices(u8, fbs.getWritten(), "42");
12701314 }
1271};
1315 {
1316 var buffer: [10]u8 = undefined;
1317 var fbs = std.io.fixedBufferStream(&buffer);
1318 try (Value{ .Float = 42 }).jsonStringify(.{}, fbs.outStream());
1319 testing.expectEqualSlices(u8, fbs.getWritten(), "4.2e+01");
1320 }
1321 {
1322 var buffer: [10]u8 = undefined;
1323 var fbs = std.io.fixedBufferStream(&buffer);
1324 try (Value{ .String = "weeee" }).jsonStringify(.{}, fbs.outStream());
1325 testing.expectEqualSlices(u8, fbs.getWritten(), "\"weeee\"");
1326 }
1327 {
1328 var buffer: [10]u8 = undefined;
1329 var fbs = std.io.fixedBufferStream(&buffer);
1330 try (Value{
1331 .Array = Array.fromOwnedSlice(undefined, &[_]Value{
1332 .{ .Integer = 1 },
1333 .{ .Integer = 2 },
1334 .{ .Integer = 3 },
1335 }),
1336 }).jsonStringify(.{}, fbs.outStream());
1337 testing.expectEqualSlices(u8, fbs.getWritten(), "[1,2,3]");
1338 }
1339 {
1340 var buffer: [10]u8 = undefined;
1341 var fbs = std.io.fixedBufferStream(&buffer);
1342 var obj = ObjectMap.init(testing.allocator);
1343 defer obj.deinit();
1344 try obj.putNoClobber("a", .{ .String = "b" });
1345 try (Value{ .Object = obj }).jsonStringify(.{}, fbs.outStream());
1346 testing.expectEqualSlices(u8, fbs.getWritten(), "{\"a\":\"b\"}");
1347 }
1348}
12721349
12731350pub const ParseOptions = struct {
12741351 allocator: ?*Allocator = null,
......@@ -1658,9 +1735,6 @@ test "parse into tagged union" {
16581735}
16591736
16601737test "parseFree descends into tagged union" {
1661 // tagged unions are broken on arm64: https://github.com/ziglang/zig/issues/4492
1662 if (std.builtin.arch == .aarch64) return error.SkipZigTest;
1663
16641738 var fail_alloc = testing.FailingAllocator.init(testing.allocator, 1);
16651739 const options = ParseOptions{ .allocator = &fail_alloc.allocator };
16661740 const T = union(enum) {
......@@ -1947,7 +2021,7 @@ pub const Parser = struct {
19472021 }
19482022
19492023 fn pushToParent(p: *Parser, value: *const Value) !void {
1950 switch (p.stack.toSlice()[p.stack.len - 1]) {
2024 switch (p.stack.span()[p.stack.len - 1]) {
19512025 // Object Parent -> [ ..., object, <key>, value ]
19522026 Value.String => |key| {
19532027 _ = p.stack.pop();
......@@ -2244,11 +2318,86 @@ test "string copy option" {
22442318}
22452319
22462320pub const StringifyOptions = struct {
2247 // TODO: indentation options?
2248 // TODO: make escaping '/' in strings optional?
2249 // TODO: allow picking if []u8 is string or array?
2321 pub const Whitespace = struct {
2322 /// How many indentation levels deep are we?
2323 indent_level: usize = 0,
2324
2325 pub const Indentation = union(enum) {
2326 Space: u8,
2327 Tab: void,
2328 };
2329
2330 /// What character(s) should be used for indentation?
2331 indent: Indentation = Indentation{ .Space = 4 },
2332
2333 fn outputIndent(
2334 whitespace: @This(),
2335 out_stream: var,
2336 ) @TypeOf(out_stream).Error!void {
2337 var char: u8 = undefined;
2338 var n_chars: usize = undefined;
2339 switch (whitespace.indent) {
2340 .Space => |n_spaces| {
2341 char = ' ';
2342 n_chars = n_spaces;
2343 },
2344 .Tab => {
2345 char = '\t';
2346 n_chars = 1;
2347 },
2348 }
2349 n_chars *= whitespace.indent_level;
2350 try out_stream.writeByteNTimes(char, n_chars);
2351 }
2352
2353 /// After a colon, should whitespace be inserted?
2354 separator: bool = true,
2355 };
2356
2357 /// Controls the whitespace emitted
2358 whitespace: ?Whitespace = null,
2359
2360 /// Should []u8 be serialised as a string? or an array?
2361 pub const StringOptions = union(enum) {
2362 Array,
2363
2364 /// String output options
2365 const StringOutputOptions = struct {
2366 /// Should '/' be escaped in strings?
2367 escape_solidus: bool = false,
2368
2369 /// Should unicode characters be escaped in strings?
2370 escape_unicode: bool = false,
2371 };
2372 String: StringOutputOptions,
2373 };
2374
2375 string: StringOptions = StringOptions{ .String = .{} },
22502376};
22512377
2378fn outputUnicodeEscape(
2379 codepoint: u21,
2380 out_stream: var,
2381) !void {
2382 if (codepoint <= 0xFFFF) {
2383 // If the character is in the Basic Multilingual Plane (U+0000 through U+FFFF),
2384 // then it may be represented as a six-character sequence: a reverse solidus, followed
2385 // by the lowercase letter u, followed by four hexadecimal digits that encode the character's code point.
2386 try out_stream.writeAll("\\u");
2387 try std.fmt.formatIntValue(codepoint, "x", std.fmt.FormatOptions{ .width = 4, .fill = '0' }, out_stream);
2388 } else {
2389 assert(codepoint <= 0x10FFFF);
2390 // To escape an extended character that is not in the Basic Multilingual Plane,
2391 // the character is represented as a 12-character sequence, encoding the UTF-16 surrogate pair.
2392 const high = @intCast(u16, (codepoint - 0x10000) >> 10) + 0xD800;
2393 const low = @intCast(u16, codepoint & 0x3FF) + 0xDC00;
2394 try out_stream.writeAll("\\u");
2395 try std.fmt.formatIntValue(high, "x", std.fmt.FormatOptions{ .width = 4, .fill = '0' }, out_stream);
2396 try out_stream.writeAll("\\u");
2397 try std.fmt.formatIntValue(low, "x", std.fmt.FormatOptions{ .width = 4, .fill = '0' }, out_stream);
2398 }
2399}
2400
22522401pub fn stringify(
22532402 value: var,
22542403 options: StringifyOptions,
......@@ -2265,11 +2414,14 @@ pub fn stringify(
22652414 .Bool => {
22662415 return out_stream.writeAll(if (value) "true" else "false");
22672416 },
2417 .Null => {
2418 return out_stream.writeAll("null");
2419 },
22682420 .Optional => {
22692421 if (value) |payload| {
22702422 return try stringify(payload, options, out_stream);
22712423 } else {
2272 return out_stream.writeAll("null");
2424 return try stringify(null, options, out_stream);
22732425 }
22742426 },
22752427 .Enum => {
......@@ -2300,8 +2452,12 @@ pub fn stringify(
23002452 return value.jsonStringify(options, out_stream);
23012453 }
23022454
2303 try out_stream.writeAll("{");
2455 try out_stream.writeByte('{');
23042456 comptime var field_output = false;
2457 var child_options = options;
2458 if (child_options.whitespace) |*child_whitespace| {
2459 child_whitespace.indent_level += 1;
2460 }
23052461 inline for (S.fields) |Field, field_i| {
23062462 // don't include void fields
23072463 if (Field.field_type == void) continue;
......@@ -2309,14 +2465,28 @@ pub fn stringify(
23092465 if (!field_output) {
23102466 field_output = true;
23112467 } else {
2312 try out_stream.writeAll(",");
2468 try out_stream.writeByte(',');
2469 }
2470 if (child_options.whitespace) |child_whitespace| {
2471 try out_stream.writeByte('\n');
2472 try child_whitespace.outputIndent(out_stream);
23132473 }
2314
23152474 try stringify(Field.name, options, out_stream);
2316 try out_stream.writeAll(":");
2317 try stringify(@field(value, Field.name), options, out_stream);
2475 try out_stream.writeByte(':');
2476 if (child_options.whitespace) |child_whitespace| {
2477 if (child_whitespace.separator) {
2478 try out_stream.writeByte(' ');
2479 }
2480 }
2481 try stringify(@field(value, Field.name), child_options, out_stream);
2482 }
2483 if (field_output) {
2484 if (options.whitespace) |whitespace| {
2485 try out_stream.writeByte('\n');
2486 try whitespace.outputIndent(out_stream);
2487 }
23182488 }
2319 try out_stream.writeAll("}");
2489 try out_stream.writeByte('}');
23202490 return;
23212491 },
23222492 .Pointer => |ptr_info| switch (ptr_info.size) {
......@@ -2332,17 +2502,26 @@ pub fn stringify(
23322502 },
23332503 // TODO: .Many when there is a sentinel (waiting for https://github.com/ziglang/zig/pull/3972)
23342504 .Slice => {
2335 if (ptr_info.child == u8 and std.unicode.utf8ValidateSlice(value)) {
2336 try out_stream.writeAll("\"");
2505 if (ptr_info.child == u8 and options.string == .String and std.unicode.utf8ValidateSlice(value)) {
2506 try out_stream.writeByte('\"');
23372507 var i: usize = 0;
23382508 while (i < value.len) : (i += 1) {
23392509 switch (value[i]) {
2340 // normal ascii characters
2341 0x20...0x21, 0x23...0x2E, 0x30...0x5B, 0x5D...0x7F => try out_stream.writeAll(value[i .. i + 1]),
2342 // control characters with short escapes
2510 // normal ascii character
2511 0x20...0x21, 0x23...0x2E, 0x30...0x5B, 0x5D...0x7F => |c| try out_stream.writeByte(c),
2512 // only 2 characters that *must* be escaped
23432513 '\\' => try out_stream.writeAll("\\\\"),
23442514 '\"' => try out_stream.writeAll("\\\""),
2345 '/' => try out_stream.writeAll("\\/"),
2515 // solidus is optional to escape
2516 '/' => {
2517 if (options.string.String.escape_solidus) {
2518 try out_stream.writeAll("\\/");
2519 } else {
2520 try out_stream.writeByte('\\');
2521 }
2522 },
2523 // control characters with short escapes
2524 // TODO: option to switch between unicode and 'short' forms?
23462525 0x8 => try out_stream.writeAll("\\b"),
23472526 0xC => try out_stream.writeAll("\\f"),
23482527 '\n' => try out_stream.writeAll("\\n"),
......@@ -2350,39 +2529,43 @@ pub fn stringify(
23502529 '\t' => try out_stream.writeAll("\\t"),
23512530 else => {
23522531 const ulen = std.unicode.utf8ByteSequenceLength(value[i]) catch unreachable;
2353 const codepoint = std.unicode.utf8Decode(value[i .. i + ulen]) catch unreachable;
2354 if (codepoint <= 0xFFFF) {
2355 // If the character is in the Basic Multilingual Plane (U+0000 through U+FFFF),
2356 // then it may be represented as a six-character sequence: a reverse solidus, followed
2357 // by the lowercase letter u, followed by four hexadecimal digits that encode the character's code point.
2358 try out_stream.writeAll("\\u");
2359 try std.fmt.formatIntValue(codepoint, "x", std.fmt.FormatOptions{ .width = 4, .fill = '0' }, out_stream);
2532 // control characters (only things left with 1 byte length) should always be printed as unicode escapes
2533 if (ulen == 1 or options.string.String.escape_unicode) {
2534 const codepoint = std.unicode.utf8Decode(value[i .. i + ulen]) catch unreachable;
2535 try outputUnicodeEscape(codepoint, out_stream);
23602536 } else {
2361 // To escape an extended character that is not in the Basic Multilingual Plane,
2362 // the character is represented as a 12-character sequence, encoding the UTF-16 surrogate pair.
2363 const high = @intCast(u16, (codepoint - 0x10000) >> 10) + 0xD800;
2364 const low = @intCast(u16, codepoint & 0x3FF) + 0xDC00;
2365 try out_stream.writeAll("\\u");
2366 try std.fmt.formatIntValue(high, "x", std.fmt.FormatOptions{ .width = 4, .fill = '0' }, out_stream);
2367 try out_stream.writeAll("\\u");
2368 try std.fmt.formatIntValue(low, "x", std.fmt.FormatOptions{ .width = 4, .fill = '0' }, out_stream);
2537 try out_stream.writeAll(value[i .. i + ulen]);
23692538 }
23702539 i += ulen - 1;
23712540 },
23722541 }
23732542 }
2374 try out_stream.writeAll("\"");
2543 try out_stream.writeByte('\"');
23752544 return;
23762545 }
23772546
2378 try out_stream.writeAll("[");
2547 try out_stream.writeByte('[');
2548 var child_options = options;
2549 if (child_options.whitespace) |*whitespace| {
2550 whitespace.indent_level += 1;
2551 }
23792552 for (value) |x, i| {
23802553 if (i != 0) {
2381 try out_stream.writeAll(",");
2554 try out_stream.writeByte(',');
2555 }
2556 if (child_options.whitespace) |child_whitespace| {
2557 try out_stream.writeByte('\n');
2558 try child_whitespace.outputIndent(out_stream);
23822559 }
2383 try stringify(x, options, out_stream);
2560 try stringify(x, child_options, out_stream);
23842561 }
2385 try out_stream.writeAll("]");
2562 if (value.len != 0) {
2563 if (options.whitespace) |whitespace| {
2564 try out_stream.writeByte('\n');
2565 try whitespace.outputIndent(out_stream);
2566 }
2567 }
2568 try out_stream.writeByte(']');
23862569 return;
23872570 },
23882571 else => @compileError("Unable to stringify type '" ++ @typeName(T) ++ "'"),
......@@ -2393,7 +2576,7 @@ pub fn stringify(
23932576 unreachable;
23942577}
23952578
2396fn teststringify(expected: []const u8, value: var) !void {
2579fn teststringify(expected: []const u8, value: var, options: StringifyOptions) !void {
23972580 const ValidationOutStream = struct {
23982581 const Self = @This();
23992582 pub const OutStream = std.io.OutStream(*Self, Error, write);
......@@ -2445,55 +2628,105 @@ fn teststringify(expected: []const u8, value: var) !void {
24452628 };
24462629
24472630 var vos = ValidationOutStream.init(expected);
2448 try stringify(value, StringifyOptions{}, vos.outStream());
2631 try stringify(value, options, vos.outStream());
24492632 if (vos.expected_remaining.len > 0) return error.NotEnoughData;
24502633}
24512634
24522635test "stringify basic types" {
2453 try teststringify("false", false);
2454 try teststringify("true", true);
2455 try teststringify("null", @as(?u8, null));
2456 try teststringify("null", @as(?*u32, null));
2457 try teststringify("42", 42);
2458 try teststringify("4.2e+01", 42.0);
2459 try teststringify("42", @as(u8, 42));
2460 try teststringify("42", @as(u128, 42));
2461 try teststringify("4.2e+01", @as(f32, 42));
2462 try teststringify("4.2e+01", @as(f64, 42));
2636 try teststringify("false", false, StringifyOptions{});
2637 try teststringify("true", true, StringifyOptions{});
2638 try teststringify("null", @as(?u8, null), StringifyOptions{});
2639 try teststringify("null", @as(?*u32, null), StringifyOptions{});
2640 try teststringify("42", 42, StringifyOptions{});
2641 try teststringify("4.2e+01", 42.0, StringifyOptions{});
2642 try teststringify("42", @as(u8, 42), StringifyOptions{});
2643 try teststringify("42", @as(u128, 42), StringifyOptions{});
2644 try teststringify("4.2e+01", @as(f32, 42), StringifyOptions{});
2645 try teststringify("4.2e+01", @as(f64, 42), StringifyOptions{});
24632646}
24642647
24652648test "stringify string" {
2466 try teststringify("\"hello\"", "hello");
2467 try teststringify("\"with\\nescapes\\r\"", "with\nescapes\r");
2468 try teststringify("\"with unicode\\u0001\"", "with unicode\u{1}");
2469 try teststringify("\"with unicode\\u0080\"", "with unicode\u{80}");
2470 try teststringify("\"with unicode\\u00ff\"", "with unicode\u{FF}");
2471 try teststringify("\"with unicode\\u0100\"", "with unicode\u{100}");
2472 try teststringify("\"with unicode\\u0800\"", "with unicode\u{800}");
2473 try teststringify("\"with unicode\\u8000\"", "with unicode\u{8000}");
2474 try teststringify("\"with unicode\\ud799\"", "with unicode\u{D799}");
2475 try teststringify("\"with unicode\\ud800\\udc00\"", "with unicode\u{10000}");
2476 try teststringify("\"with unicode\\udbff\\udfff\"", "with unicode\u{10FFFF}");
2649 try teststringify("\"hello\"", "hello", StringifyOptions{});
2650 try teststringify("\"with\\nescapes\\r\"", "with\nescapes\r", StringifyOptions{});
2651 try teststringify("\"with\\nescapes\\r\"", "with\nescapes\r", StringifyOptions{ .string = .{ .String = .{ .escape_unicode = true } } });
2652 try teststringify("\"with unicode\\u0001\"", "with unicode\u{1}", StringifyOptions{});
2653 try teststringify("\"with unicode\\u0001\"", "with unicode\u{1}", StringifyOptions{ .string = .{ .String = .{ .escape_unicode = true } } });
2654 try teststringify("\"with unicode\u{80}\"", "with unicode\u{80}", StringifyOptions{});
2655 try teststringify("\"with unicode\\u0080\"", "with unicode\u{80}", StringifyOptions{ .string = .{ .String = .{ .escape_unicode = true } } });
2656 try teststringify("\"with unicode\u{FF}\"", "with unicode\u{FF}", StringifyOptions{});
2657 try teststringify("\"with unicode\\u00ff\"", "with unicode\u{FF}", StringifyOptions{ .string = .{ .String = .{ .escape_unicode = true } } });
2658 try teststringify("\"with unicode\u{100}\"", "with unicode\u{100}", StringifyOptions{});
2659 try teststringify("\"with unicode\\u0100\"", "with unicode\u{100}", StringifyOptions{ .string = .{ .String = .{ .escape_unicode = true } } });
2660 try teststringify("\"with unicode\u{800}\"", "with unicode\u{800}", StringifyOptions{});
2661 try teststringify("\"with unicode\\u0800\"", "with unicode\u{800}", StringifyOptions{ .string = .{ .String = .{ .escape_unicode = true } } });
2662 try teststringify("\"with unicode\u{8000}\"", "with unicode\u{8000}", StringifyOptions{});
2663 try teststringify("\"with unicode\\u8000\"", "with unicode\u{8000}", StringifyOptions{ .string = .{ .String = .{ .escape_unicode = true } } });
2664 try teststringify("\"with unicode\u{D799}\"", "with unicode\u{D799}", StringifyOptions{});
2665 try teststringify("\"with unicode\\ud799\"", "with unicode\u{D799}", StringifyOptions{ .string = .{ .String = .{ .escape_unicode = true } } });
2666 try teststringify("\"with unicode\u{10000}\"", "with unicode\u{10000}", StringifyOptions{});
2667 try teststringify("\"with unicode\\ud800\\udc00\"", "with unicode\u{10000}", StringifyOptions{ .string = .{ .String = .{ .escape_unicode = true } } });
2668 try teststringify("\"with unicode\u{10FFFF}\"", "with unicode\u{10FFFF}", StringifyOptions{});
2669 try teststringify("\"with unicode\\udbff\\udfff\"", "with unicode\u{10FFFF}", StringifyOptions{ .string = .{ .String = .{ .escape_unicode = true } } });
24772670}
24782671
24792672test "stringify tagged unions" {
24802673 try teststringify("42", union(enum) {
24812674 Foo: u32,
24822675 Bar: bool,
2483 }{ .Foo = 42 });
2676 }{ .Foo = 42 }, StringifyOptions{});
24842677}
24852678
24862679test "stringify struct" {
24872680 try teststringify("{\"foo\":42}", struct {
24882681 foo: u32,
2489 }{ .foo = 42 });
2682 }{ .foo = 42 }, StringifyOptions{});
2683}
2684
2685test "stringify struct with indentation" {
2686 try teststringify(
2687 \\{
2688 \\ "foo": 42,
2689 \\ "bar": [
2690 \\ 1,
2691 \\ 2,
2692 \\ 3
2693 \\ ]
2694 \\}
2695 ,
2696 struct {
2697 foo: u32,
2698 bar: [3]u32,
2699 }{
2700 .foo = 42,
2701 .bar = .{ 1, 2, 3 },
2702 },
2703 StringifyOptions{
2704 .whitespace = .{},
2705 },
2706 );
2707 try teststringify(
2708 "{\n\t\"foo\":42,\n\t\"bar\":[\n\t\t1,\n\t\t2,\n\t\t3\n\t]\n}",
2709 struct {
2710 foo: u32,
2711 bar: [3]u32,
2712 }{
2713 .foo = 42,
2714 .bar = .{ 1, 2, 3 },
2715 },
2716 StringifyOptions{
2717 .whitespace = .{
2718 .indent = .Tab,
2719 .separator = false,
2720 },
2721 },
2722 );
24902723}
24912724
24922725test "stringify struct with void field" {
24932726 try teststringify("{\"foo\":42}", struct {
24942727 foo: u32,
24952728 bar: void = {},
2496 }{ .foo = 42 });
2729 }{ .foo = 42 }, StringifyOptions{});
24972730}
24982731
24992732test "stringify array of structs" {
......@@ -2504,7 +2737,7 @@ test "stringify array of structs" {
25042737 MyStruct{ .foo = 42 },
25052738 MyStruct{ .foo = 100 },
25062739 MyStruct{ .foo = 1000 },
2507 });
2740 }, StringifyOptions{});
25082741}
25092742
25102743test "stringify struct with custom stringifier" {
......@@ -2518,7 +2751,7 @@ test "stringify struct with custom stringifier" {
25182751 ) !void {
25192752 try out_stream.writeAll("[\"something special\",");
25202753 try stringify(42, options, out_stream);
2521 try out_stream.writeAll("]");
2754 try out_stream.writeByte(']');
25222755 }
2523 }{ .foo = 42 });
2756 }{ .foo = 42 }, StringifyOptions{});
25242757}
lib/std/json/test.zig+3-5
......@@ -1751,11 +1751,9 @@ test "i_number_double_huge_neg_exp" {
17511751}
17521752
17531753test "i_number_huge_exp" {
1754 return error.SkipZigTest;
1755 // FIXME Integer overflow in parseFloat
1756 // any(
1757 // \\[0.4e00669999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999969999999006]
1758 // );
1754 any(
1755 \\[0.4e00669999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999969999999006]
1756 );
17591757}
17601758
17611759test "i_number_neg_int_huge_exp" {
lib/std/json/write_stream.zig+27-59
......@@ -21,14 +21,10 @@ pub fn WriteStream(comptime OutStream: type, comptime max_depth: usize) type {
2121
2222 pub const Stream = OutStream;
2323
24 /// The string used for indenting.
25 one_indent: []const u8 = " ",
26
27 /// The string used as a newline character.
28 newline: []const u8 = "\n",
29
30 /// The string used as spacing.
31 space: []const u8 = " ",
24 whitespace: std.json.StringifyOptions.Whitespace = std.json.StringifyOptions.Whitespace{
25 .indent_level = 0,
26 .indent = .{ .Space = 1 },
27 },
3228
3329 stream: OutStream,
3430 state_index: usize,
......@@ -49,12 +45,14 @@ pub fn WriteStream(comptime OutStream: type, comptime max_depth: usize) type {
4945 assert(self.state[self.state_index] == State.Value); // need to call arrayElem or objectField
5046 try self.stream.writeByte('[');
5147 self.state[self.state_index] = State.ArrayStart;
48 self.whitespace.indent_level += 1;
5249 }
5350
5451 pub fn beginObject(self: *Self) !void {
5552 assert(self.state[self.state_index] == State.Value); // need to call arrayElem or objectField
5653 try self.stream.writeByte('{');
5754 self.state[self.state_index] = State.ObjectStart;
55 self.whitespace.indent_level += 1;
5856 }
5957
6058 pub fn arrayElem(self: *Self) !void {
......@@ -90,8 +88,10 @@ pub fn WriteStream(comptime OutStream: type, comptime max_depth: usize) type {
9088 self.pushState(.Value);
9189 try self.indent();
9290 try self.writeEscapedString(name);
93 try self.stream.writeAll(":");
94 try self.stream.writeAll(self.space);
91 try self.stream.writeByte(':');
92 if (self.whitespace.separator) {
93 try self.stream.writeByte(' ');
94 }
9595 },
9696 }
9797 }
......@@ -103,10 +103,12 @@ pub fn WriteStream(comptime OutStream: type, comptime max_depth: usize) type {
103103 .ObjectStart => unreachable,
104104 .Object => unreachable,
105105 .ArrayStart => {
106 self.whitespace.indent_level -= 1;
106107 try self.stream.writeByte(']');
107108 self.popState();
108109 },
109110 .Array => {
111 self.whitespace.indent_level -= 1;
110112 try self.indent();
111113 self.popState();
112114 try self.stream.writeByte(']');
......@@ -121,10 +123,12 @@ pub fn WriteStream(comptime OutStream: type, comptime max_depth: usize) type {
121123 .ArrayStart => unreachable,
122124 .Array => unreachable,
123125 .ObjectStart => {
126 self.whitespace.indent_level -= 1;
124127 try self.stream.writeByte('}');
125128 self.popState();
126129 },
127130 .Object => {
131 self.whitespace.indent_level -= 1;
128132 try self.indent();
129133 self.popState();
130134 try self.stream.writeByte('}');
......@@ -134,17 +138,13 @@ pub fn WriteStream(comptime OutStream: type, comptime max_depth: usize) type {
134138
135139 pub fn emitNull(self: *Self) !void {
136140 assert(self.state[self.state_index] == State.Value);
137 try self.stream.writeAll("null");
141 try self.stringify(null);
138142 self.popState();
139143 }
140144
141145 pub fn emitBool(self: *Self, value: bool) !void {
142146 assert(self.state[self.state_index] == State.Value);
143 if (value) {
144 try self.stream.writeAll("true");
145 } else {
146 try self.stream.writeAll("false");
147 }
147 try self.stringify(value);
148148 self.popState();
149149 }
150150
......@@ -185,57 +185,19 @@ pub fn WriteStream(comptime OutStream: type, comptime max_depth: usize) type {
185185 }
186186
187187 fn writeEscapedString(self: *Self, string: []const u8) !void {
188 try self.stream.writeByte('"');
189 for (string) |s| {
190 switch (s) {
191 '"' => try self.stream.writeAll("\\\""),
192 '\t' => try self.stream.writeAll("\\t"),
193 '\r' => try self.stream.writeAll("\\r"),
194 '\n' => try self.stream.writeAll("\\n"),
195 8 => try self.stream.writeAll("\\b"),
196 12 => try self.stream.writeAll("\\f"),
197 '\\' => try self.stream.writeAll("\\\\"),
198 else => try self.stream.writeByte(s),
199 }
200 }
201 try self.stream.writeByte('"');
188 assert(std.unicode.utf8ValidateSlice(string));
189 try self.stringify(string);
202190 }
203191
204192 /// Writes the complete json into the output stream
205193 pub fn emitJson(self: *Self, json: std.json.Value) Stream.Error!void {
206 switch (json) {
207 .Null => try self.emitNull(),
208 .Bool => |inner| try self.emitBool(inner),
209 .Integer => |inner| try self.emitNumber(inner),
210 .Float => |inner| try self.emitNumber(inner),
211 .String => |inner| try self.emitString(inner),
212 .Array => |inner| {
213 try self.beginArray();
214 for (inner.toSliceConst()) |elem| {
215 try self.arrayElem();
216 try self.emitJson(elem);
217 }
218 try self.endArray();
219 },
220 .Object => |inner| {
221 try self.beginObject();
222 var it = inner.iterator();
223 while (it.next()) |entry| {
224 try self.objectField(entry.key);
225 try self.emitJson(entry.value);
226 }
227 try self.endObject();
228 },
229 }
194 try self.stringify(json);
230195 }
231196
232197 fn indent(self: *Self) !void {
233198 assert(self.state_index >= 1);
234 try self.stream.writeAll(self.newline);
235 var i: usize = 0;
236 while (i < self.state_index - 1) : (i += 1) {
237 try self.stream.writeAll(self.one_indent);
238 }
199 try self.stream.writeByte('\n');
200 try self.whitespace.outputIndent(self.stream);
239201 }
240202
241203 fn pushState(self: *Self, state: State) void {
......@@ -246,6 +208,12 @@ pub fn WriteStream(comptime OutStream: type, comptime max_depth: usize) type {
246208 fn popState(self: *Self) void {
247209 self.state_index -= 1;
248210 }
211
212 fn stringify(self: *Self, value: var) !void {
213 try std.json.stringify(value, std.json.StringifyOptions{
214 .whitespace = self.whitespace,
215 }, self.stream);
216 }
249217 };
250218}
251219
lib/std/mem.zig+51-28
......@@ -341,11 +341,7 @@ pub fn zeroes(comptime T: type) T {
341341 }
342342 },
343343 .Array => |info| {
344 var array: T = undefined;
345 for (array) |*element| {
346 element.* = zeroes(info.child);
347 }
348 return array;
344 return [_]info.child{zeroes(info.child)} ** info.len;
349345 },
350346 .Vector,
351347 .ErrorUnion,
......@@ -496,15 +492,8 @@ pub fn eql(comptime T: type, a: []const T, b: []const T) bool {
496492 return true;
497493}
498494
499/// Deprecated. Use `spanZ`.
500pub fn toSliceConst(comptime T: type, ptr: [*:0]const T) [:0]const T {
501 return ptr[0..lenZ(ptr) :0];
502}
503
504/// Deprecated. Use `spanZ`.
505pub fn toSlice(comptime T: type, ptr: [*:0]T) [:0]T {
506 return ptr[0..lenZ(ptr) :0];
507}
495pub const toSliceConst = @compileError("deprecated; use std.mem.spanZ");
496pub const toSlice = @compileError("deprecated; use std.mem.spanZ");
508497
509498/// Takes a pointer to an array, a sentinel-terminated pointer, or a slice, and
510499/// returns a slice. If there is a sentinel on the input type, there will be a
......@@ -512,36 +501,54 @@ pub fn toSlice(comptime T: type, ptr: [*:0]T) [:0]T {
512501/// the constness of the input type. `[*c]` pointers are assumed to be 0-terminated,
513502/// and assumed to not allow null.
514503pub fn Span(comptime T: type) type {
515 var ptr_info = @typeInfo(T).Pointer;
516 switch (ptr_info.size) {
517 .One => switch (@typeInfo(ptr_info.child)) {
518 .Array => |info| {
519 ptr_info.child = info.child;
520 ptr_info.sentinel = info.sentinel;
521 },
522 else => @compileError("invalid type given to std.mem.Span"),
504 switch(@typeInfo(T)) {
505 .Optional => |optional_info| {
506 return ?Span(optional_info.child);
523507 },
524 .C => {
525 ptr_info.sentinel = 0;
526 ptr_info.is_allowzero = false;
508 .Pointer => |ptr_info| {
509 var new_ptr_info = ptr_info;
510 switch (ptr_info.size) {
511 .One => switch (@typeInfo(ptr_info.child)) {
512 .Array => |info| {
513 new_ptr_info.child = info.child;
514 new_ptr_info.sentinel = info.sentinel;
515 },
516 else => @compileError("invalid type given to std.mem.Span"),
517 },
518 .C => {
519 new_ptr_info.sentinel = 0;
520 new_ptr_info.is_allowzero = false;
521 },
522 .Many, .Slice => {},
523 }
524 new_ptr_info.size = .Slice;
525 return @Type(std.builtin.TypeInfo{ .Pointer = new_ptr_info });
527526 },
528 .Many, .Slice => {},
527 else => @compileError("invalid type given to std.mem.Span"),
529528 }
530 ptr_info.size = .Slice;
531 return @Type(std.builtin.TypeInfo{ .Pointer = ptr_info });
532529}
533530
534531test "Span" {
535532 testing.expect(Span(*[5]u16) == []u16);
533 testing.expect(Span(?*[5]u16) == ?[]u16);
536534 testing.expect(Span(*const [5]u16) == []const u16);
535 testing.expect(Span(?*const [5]u16) == ?[]const u16);
537536 testing.expect(Span([]u16) == []u16);
537 testing.expect(Span(?[]u16) == ?[]u16);
538538 testing.expect(Span([]const u8) == []const u8);
539 testing.expect(Span(?[]const u8) == ?[]const u8);
539540 testing.expect(Span([:1]u16) == [:1]u16);
541 testing.expect(Span(?[:1]u16) == ?[:1]u16);
540542 testing.expect(Span([:1]const u8) == [:1]const u8);
543 testing.expect(Span(?[:1]const u8) == ?[:1]const u8);
541544 testing.expect(Span([*:1]u16) == [:1]u16);
545 testing.expect(Span(?[*:1]u16) == ?[:1]u16);
542546 testing.expect(Span([*:1]const u8) == [:1]const u8);
547 testing.expect(Span(?[*:1]const u8) == ?[:1]const u8);
543548 testing.expect(Span([*c]u16) == [:0]u16);
549 testing.expect(Span(?[*c]u16) == ?[:0]u16);
544550 testing.expect(Span([*c]const u8) == [:0]const u8);
551 testing.expect(Span(?[*c]const u8) == ?[:0]const u8);
545552}
546553
547554/// Takes a pointer to an array, a sentinel-terminated pointer, or a slice, and
......@@ -552,6 +559,13 @@ test "Span" {
552559/// When there is both a sentinel and an array length or slice length, the
553560/// length value is used instead of the sentinel.
554561pub fn span(ptr: var) Span(@TypeOf(ptr)) {
562 if (@typeInfo(@TypeOf(ptr)) == .Optional) {
563 if (ptr) |non_null| {
564 return span(non_null);
565 } else {
566 return null;
567 }
568 }
555569 const Result = Span(@TypeOf(ptr));
556570 const l = len(ptr);
557571 if (@typeInfo(Result).Pointer.sentinel) |s| {
......@@ -566,12 +580,20 @@ test "span" {
566580 const ptr = @as([*:3]u16, array[0..2 :3]);
567581 testing.expect(eql(u16, span(ptr), &[_]u16{ 1, 2 }));
568582 testing.expect(eql(u16, span(&array), &[_]u16{ 1, 2, 3, 4, 5 }));
583 testing.expectEqual(@as(?[:0]u16, null), span(@as(?[*:0]u16, null)));
569584}
570585
571586/// Same as `span`, except when there is both a sentinel and an array
572587/// length or slice length, scans the memory for the sentinel value
573588/// rather than using the length.
574589pub fn spanZ(ptr: var) Span(@TypeOf(ptr)) {
590 if (@typeInfo(@TypeOf(ptr)) == .Optional) {
591 if (ptr) |non_null| {
592 return spanZ(non_null);
593 } else {
594 return null;
595 }
596 }
575597 const Result = Span(@TypeOf(ptr));
576598 const l = lenZ(ptr);
577599 if (@typeInfo(Result).Pointer.sentinel) |s| {
......@@ -586,6 +608,7 @@ test "spanZ" {
586608 const ptr = @as([*:3]u16, array[0..2 :3]);
587609 testing.expect(eql(u16, spanZ(ptr), &[_]u16{ 1, 2 }));
588610 testing.expect(eql(u16, spanZ(&array), &[_]u16{ 1, 2, 3, 4, 5 }));
611 testing.expectEqual(@as(?[:0]u16, null), spanZ(@as(?[*:0]u16, null)));
589612}
590613
591614/// Takes a pointer to an array, an array, a sentinel-terminated pointer,
lib/std/net.zig+26-27
......@@ -397,13 +397,12 @@ pub const AddressList = struct {
397397
398398/// All memory allocated with `allocator` will be freed before this function returns.
399399pub fn tcpConnectToHost(allocator: *mem.Allocator, name: []const u8, port: u16) !fs.File {
400 const list = getAddressList(allocator, name, port);
400 const list = try getAddressList(allocator, name, port);
401401 defer list.deinit();
402402
403 const addrs = list.addrs.toSliceConst();
404 if (addrs.len == 0) return error.UnknownHostName;
403 if (list.addrs.len == 0) return error.UnknownHostName;
405404
406 return tcpConnectToAddress(addrs[0], port);
405 return tcpConnectToAddress(list.addrs[0]);
407406}
408407
409408pub fn tcpConnectToAddress(address: Address) !fs.File {
......@@ -491,7 +490,7 @@ pub fn getAddressList(allocator: *mem.Allocator, name: []const u8, port: u16) !*
491490
492491 if (info.canonname) |n| {
493492 if (result.canon_name == null) {
494 result.canon_name = try mem.dupe(arena, u8, mem.toSliceConst(u8, n));
493 result.canon_name = try mem.dupe(arena, u8, mem.spanZ(n));
495494 }
496495 }
497496 i += 1;
......@@ -505,7 +504,7 @@ pub fn getAddressList(allocator: *mem.Allocator, name: []const u8, port: u16) !*
505504 var lookup_addrs = std.ArrayList(LookupAddr).init(allocator);
506505 defer lookup_addrs.deinit();
507506
508 var canon = std.Buffer.initNull(arena);
507 var canon = std.ArrayListSentineled(u8, 0).initNull(arena);
509508 defer canon.deinit();
510509
511510 try linuxLookupName(&lookup_addrs, &canon, name, family, flags, port);
......@@ -515,7 +514,7 @@ pub fn getAddressList(allocator: *mem.Allocator, name: []const u8, port: u16) !*
515514 result.canon_name = canon.toOwnedSlice();
516515 }
517516
518 for (lookup_addrs.toSliceConst()) |lookup_addr, i| {
517 for (lookup_addrs.span()) |lookup_addr, i| {
519518 result.addrs[i] = lookup_addr.addr;
520519 assert(result.addrs[i].getPort() == port);
521520 }
......@@ -540,7 +539,7 @@ const DAS_ORDER_SHIFT = 0;
540539
541540fn linuxLookupName(
542541 addrs: *std.ArrayList(LookupAddr),
543 canon: *std.Buffer,
542 canon: *std.ArrayListSentineled(u8, 0),
544543 opt_name: ?[]const u8,
545544 family: os.sa_family_t,
546545 flags: u32,
......@@ -568,7 +567,7 @@ fn linuxLookupName(
568567 // No further processing is needed if there are fewer than 2
569568 // results or if there are only IPv4 results.
570569 if (addrs.len == 1 or family == os.AF_INET) return;
571 const all_ip4 = for (addrs.toSliceConst()) |addr| {
570 const all_ip4 = for (addrs.span()) |addr| {
572571 if (addr.addr.any.family != os.AF_INET) break false;
573572 } else true;
574573 if (all_ip4) return;
......@@ -580,7 +579,7 @@ fn linuxLookupName(
580579 // So far the label/precedence table cannot be customized.
581580 // This implementation is ported from musl libc.
582581 // A more idiomatic "ziggy" implementation would be welcome.
583 for (addrs.toSlice()) |*addr, i| {
582 for (addrs.span()) |*addr, i| {
584583 var key: i32 = 0;
585584 var sa6: os.sockaddr_in6 = undefined;
586585 @memset(@ptrCast([*]u8, &sa6), 0, @sizeOf(os.sockaddr_in6));
......@@ -645,7 +644,7 @@ fn linuxLookupName(
645644 key |= (MAXADDRS - @intCast(i32, i)) << DAS_ORDER_SHIFT;
646645 addr.sortkey = key;
647646 }
648 std.sort.sort(LookupAddr, addrs.toSlice(), addrCmpLessThan);
647 std.sort.sort(LookupAddr, addrs.span(), addrCmpLessThan);
649648}
650649
651650const Policy = struct {
......@@ -799,12 +798,12 @@ fn linuxLookupNameFromNull(
799798
800799fn linuxLookupNameFromHosts(
801800 addrs: *std.ArrayList(LookupAddr),
802 canon: *std.Buffer,
801 canon: *std.ArrayListSentineled(u8, 0),
803802 name: []const u8,
804803 family: os.sa_family_t,
805804 port: u16,
806805) !void {
807 const file = fs.openFileAbsoluteC("/etc/hosts", .{}) catch |err| switch (err) {
806 const file = fs.openFileAbsoluteZ("/etc/hosts", .{}) catch |err| switch (err) {
808807 error.FileNotFound,
809808 error.NotDir,
810809 error.AccessDenied,
......@@ -869,7 +868,7 @@ pub fn isValidHostName(hostname: []const u8) bool {
869868
870869fn linuxLookupNameFromDnsSearch(
871870 addrs: *std.ArrayList(LookupAddr),
872 canon: *std.Buffer,
871 canon: *std.ArrayListSentineled(u8, 0),
873872 name: []const u8,
874873 family: os.sa_family_t,
875874 port: u16,
......@@ -888,7 +887,7 @@ fn linuxLookupNameFromDnsSearch(
888887 const search = if (rc.search.isNull() or dots >= rc.ndots or mem.endsWith(u8, name, "."))
889888 &[_]u8{}
890889 else
891 rc.search.toSliceConst();
890 rc.search.span();
892891
893892 var canon_name = name;
894893
......@@ -901,14 +900,14 @@ fn linuxLookupNameFromDnsSearch(
901900 // name is not a CNAME record) and serves as a buffer for passing
902901 // the full requested name to name_from_dns.
903902 try canon.resize(canon_name.len);
904 mem.copy(u8, canon.toSlice(), canon_name);
905 try canon.appendByte('.');
903 mem.copy(u8, canon.span(), canon_name);
904 try canon.append('.');
906905
907906 var tok_it = mem.tokenize(search, " \t");
908907 while (tok_it.next()) |tok| {
909908 canon.shrink(canon_name.len + 1);
910 try canon.append(tok);
911 try linuxLookupNameFromDns(addrs, canon, canon.toSliceConst(), family, rc, port);
909 try canon.appendSlice(tok);
910 try linuxLookupNameFromDns(addrs, canon, canon.span(), family, rc, port);
912911 if (addrs.len != 0) return;
913912 }
914913
......@@ -918,13 +917,13 @@ fn linuxLookupNameFromDnsSearch(
918917
919918const dpc_ctx = struct {
920919 addrs: *std.ArrayList(LookupAddr),
921 canon: *std.Buffer,
920 canon: *std.ArrayListSentineled(u8, 0),
922921 port: u16,
923922};
924923
925924fn linuxLookupNameFromDns(
926925 addrs: *std.ArrayList(LookupAddr),
927 canon: *std.Buffer,
926 canon: *std.ArrayListSentineled(u8, 0),
928927 name: []const u8,
929928 family: os.sa_family_t,
930929 rc: ResolvConf,
......@@ -979,7 +978,7 @@ const ResolvConf = struct {
979978 attempts: u32,
980979 ndots: u32,
981980 timeout: u32,
982 search: std.Buffer,
981 search: std.ArrayListSentineled(u8, 0),
983982 ns: std.ArrayList(LookupAddr),
984983
985984 fn deinit(rc: *ResolvConf) void {
......@@ -994,14 +993,14 @@ const ResolvConf = struct {
994993fn getResolvConf(allocator: *mem.Allocator, rc: *ResolvConf) !void {
995994 rc.* = ResolvConf{
996995 .ns = std.ArrayList(LookupAddr).init(allocator),
997 .search = std.Buffer.initNull(allocator),
996 .search = std.ArrayListSentineled(u8, 0).initNull(allocator),
998997 .ndots = 1,
999998 .timeout = 5,
1000999 .attempts = 2,
10011000 };
10021001 errdefer rc.deinit();
10031002
1004 const file = fs.openFileAbsoluteC("/etc/resolv.conf", .{}) catch |err| switch (err) {
1003 const file = fs.openFileAbsoluteZ("/etc/resolv.conf", .{}) catch |err| switch (err) {
10051004 error.FileNotFound,
10061005 error.NotDir,
10071006 error.AccessDenied,
......@@ -1080,9 +1079,9 @@ fn resMSendRc(
10801079 defer ns_list.deinit();
10811080
10821081 try ns_list.resize(rc.ns.len);
1083 const ns = ns_list.toSlice();
1082 const ns = ns_list.span();
10841083
1085 for (rc.ns.toSliceConst()) |iplit, i| {
1084 for (rc.ns.span()) |iplit, i| {
10861085 ns[i] = iplit.addr;
10871086 assert(ns[i].getPort() == 53);
10881087 if (iplit.addr.any.family != os.AF_INET) {
......@@ -1266,7 +1265,7 @@ fn dnsParseCallback(ctx: dpc_ctx, rr: u8, data: []const u8, packet: []const u8)
12661265 var tmp: [256]u8 = undefined;
12671266 // Returns len of compressed name. strlen to get canon name.
12681267 _ = try os.dn_expand(packet, data, &tmp);
1269 const canon_name = mem.toSliceConst(u8, @ptrCast([*:0]const u8, &tmp));
1268 const canon_name = mem.spanZ(@ptrCast([*:0]const u8, &tmp));
12701269 if (isValidHostName(canon_name)) {
12711270 try ctx.canon.replaceContents(canon_name);
12721271 }
lib/std/os.zig+105-83
......@@ -163,7 +163,7 @@ pub fn getrandom(buffer: []u8) GetRandomError!void {
163163}
164164
165165fn getRandomBytesDevURandom(buf: []u8) !void {
166 const fd = try openC("/dev/urandom", O_RDONLY | O_CLOEXEC, 0);
166 const fd = try openZ("/dev/urandom", O_RDONLY | O_CLOEXEC, 0);
167167 defer close(fd);
168168
169169 const st = try fstat(fd);
......@@ -853,13 +853,15 @@ pub const OpenError = error{
853853/// TODO support windows
854854pub fn open(file_path: []const u8, flags: u32, perm: usize) OpenError!fd_t {
855855 const file_path_c = try toPosixPath(file_path);
856 return openC(&file_path_c, flags, perm);
856 return openZ(&file_path_c, flags, perm);
857857}
858858
859pub const openC = @compileError("deprecated: renamed to openZ");
860
859861/// Open and possibly create a file. Keeps trying if it gets interrupted.
860862/// See also `open`.
861863/// TODO support windows
862pub fn openC(file_path: [*:0]const u8, flags: u32, perm: usize) OpenError!fd_t {
864pub fn openZ(file_path: [*:0]const u8, flags: u32, perm: usize) OpenError!fd_t {
863865 while (true) {
864866 const rc = system.open(file_path, flags, perm);
865867 switch (errno(rc)) {
......@@ -895,14 +897,16 @@ pub fn openC(file_path: [*:0]const u8, flags: u32, perm: usize) OpenError!fd_t {
895897/// TODO support windows
896898pub fn openat(dir_fd: fd_t, file_path: []const u8, flags: u32, mode: mode_t) OpenError!fd_t {
897899 const file_path_c = try toPosixPath(file_path);
898 return openatC(dir_fd, &file_path_c, flags, mode);
900 return openatZ(dir_fd, &file_path_c, flags, mode);
899901}
900902
903pub const openatC = @compileError("deprecated: renamed to openatZ");
904
901905/// Open and possibly create a file. Keeps trying if it gets interrupted.
902906/// `file_path` is relative to the open directory handle `dir_fd`.
903907/// See also `openat`.
904908/// TODO support windows
905pub fn openatC(dir_fd: fd_t, file_path: [*:0]const u8, flags: u32, mode: mode_t) OpenError!fd_t {
909pub fn openatZ(dir_fd: fd_t, file_path: [*:0]const u8, flags: u32, mode: mode_t) OpenError!fd_t {
906910 while (true) {
907911 const rc = system.openat(dir_fd, file_path, flags, mode);
908912 switch (errno(rc)) {
......@@ -959,8 +963,7 @@ pub const ExecveError = error{
959963 NameTooLong,
960964} || UnexpectedError;
961965
962/// Deprecated in favor of `execveZ`.
963pub const execveC = execveZ;
966pub const execveC = @compileError("deprecated: use execveZ");
964967
965968/// Like `execve` except the parameters are null-terminated,
966969/// matching the syscall API on all targets. This removes the need for an allocator.
......@@ -992,8 +995,7 @@ pub fn execveZ(
992995 }
993996}
994997
995/// Deprecated in favor of `execvpeZ`.
996pub const execvpeC = execvpeZ;
998pub const execvpeC = @compileError("deprecated in favor of execvpeZ");
997999
9981000pub const Arg0Expand = enum {
9991001 expand,
......@@ -1012,7 +1014,7 @@ pub fn execvpeZ_expandArg0(
10121014 },
10131015 envp: [*:null]const ?[*:0]const u8,
10141016) ExecveError {
1015 const file_slice = mem.toSliceConst(u8, file);
1017 const file_slice = mem.spanZ(file);
10161018 if (mem.indexOfScalar(u8, file_slice, '/') != null) return execveZ(file, child_argv, envp);
10171019
10181020 const PATH = getenvZ("PATH") orelse "/usr/local/bin:/bin/:/usr/bin";
......@@ -1076,7 +1078,7 @@ pub fn execvpe_expandArg0(
10761078 mem.set(?[*:0]u8, argv_buf, null);
10771079 defer {
10781080 for (argv_buf) |arg| {
1079 const arg_buf = if (arg) |ptr| mem.toSlice(u8, ptr) else break;
1081 const arg_buf = mem.spanZ(arg) orelse break;
10801082 allocator.free(arg_buf);
10811083 }
10821084 allocator.free(argv_buf);
......@@ -1189,30 +1191,32 @@ pub fn getenv(key: []const u8) ?[]const u8 {
11891191 return null;
11901192}
11911193
1192/// Deprecated in favor of `getenvZ`.
1193pub const getenvC = getenvZ;
1194pub const getenvC = @compileError("Deprecated in favor of `getenvZ`");
11941195
11951196/// Get an environment variable with a null-terminated name.
11961197/// See also `getenv`.
11971198pub fn getenvZ(key: [*:0]const u8) ?[]const u8 {
11981199 if (builtin.link_libc) {
11991200 const value = system.getenv(key) orelse return null;
1200 return mem.toSliceConst(u8, value);
1201 return mem.spanZ(value);
12011202 }
12021203 if (builtin.os.tag == .windows) {
12031204 @compileError("std.os.getenvZ is unavailable for Windows because environment string is in WTF-16 format. See std.process.getEnvVarOwned for cross-platform API or std.os.getenvW for Windows-specific API.");
12041205 }
1205 return getenv(mem.toSliceConst(u8, key));
1206 return getenv(mem.spanZ(key));
12061207}
12071208
12081209/// Windows-only. Get an environment variable with a null-terminated, WTF-16 encoded name.
12091210/// See also `getenv`.
1211/// This function first attempts a case-sensitive lookup. If no match is found, and `key`
1212/// is ASCII, then it attempts a second case-insensitive lookup.
12101213pub fn getenvW(key: [*:0]const u16) ?[:0]const u16 {
12111214 if (builtin.os.tag != .windows) {
12121215 @compileError("std.os.getenvW is a Windows-only API");
12131216 }
1214 const key_slice = mem.toSliceConst(u16, key);
1217 const key_slice = mem.spanZ(key);
12151218 const ptr = windows.peb().ProcessParameters.Environment;
1219 var ascii_match: ?[:0]const u16 = null;
12161220 var i: usize = 0;
12171221 while (ptr[i] != 0) {
12181222 const key_start = i;
......@@ -1228,9 +1232,20 @@ pub fn getenvW(key: [*:0]const u16) ?[:0]const u16 {
12281232
12291233 if (mem.eql(u16, key_slice, this_key)) return this_value;
12301234
1235 ascii_check: {
1236 if (ascii_match != null) break :ascii_check;
1237 if (key_slice.len != this_key.len) break :ascii_check;
1238 for (key_slice) |a_c, key_index| {
1239 const a = math.cast(u8, a_c) catch break :ascii_check;
1240 const b = math.cast(u8, this_key[key_index]) catch break :ascii_check;
1241 if (std.ascii.toLower(a) != std.ascii.toLower(b)) break :ascii_check;
1242 }
1243 ascii_match = this_value;
1244 }
1245
12311246 i += 1; // skip over null byte
12321247 }
1233 return null;
1248 return ascii_match;
12341249}
12351250
12361251pub const GetCwdError = error{
......@@ -1250,7 +1265,7 @@ pub fn getcwd(out_buffer: []u8) GetCwdError![]u8 {
12501265 break :blk errno(system.getcwd(out_buffer.ptr, out_buffer.len));
12511266 };
12521267 switch (err) {
1253 0 => return mem.toSlice(u8, @ptrCast([*:0]u8, out_buffer.ptr)),
1268 0 => return mem.spanZ(@ptrCast([*:0]u8, out_buffer.ptr)),
12541269 EFAULT => unreachable,
12551270 EINVAL => unreachable,
12561271 ENOENT => return error.CurrentWorkingDirectoryUnlinked,
......@@ -1288,13 +1303,15 @@ pub fn symlink(target_path: []const u8, sym_link_path: []const u8) SymLinkError!
12881303 } else {
12891304 const target_path_c = try toPosixPath(target_path);
12901305 const sym_link_path_c = try toPosixPath(sym_link_path);
1291 return symlinkC(&target_path_c, &sym_link_path_c);
1306 return symlinkZ(&target_path_c, &sym_link_path_c);
12921307 }
12931308}
12941309
1310pub const symlinkC = @compileError("deprecated: renamed to symlinkZ");
1311
12951312/// This is the same as `symlink` except the parameters are null-terminated pointers.
12961313/// See also `symlink`.
1297pub fn symlinkC(target_path: [*:0]const u8, sym_link_path: [*:0]const u8) SymLinkError!void {
1314pub fn symlinkZ(target_path: [*:0]const u8, sym_link_path: [*:0]const u8) SymLinkError!void {
12981315 if (builtin.os.tag == .windows) {
12991316 const target_path_w = try windows.cStrToPrefixedFileW(target_path);
13001317 const sym_link_path_w = try windows.cStrToPrefixedFileW(sym_link_path);
......@@ -1323,10 +1340,12 @@ pub fn symlinkC(target_path: [*:0]const u8, sym_link_path: [*:0]const u8) SymLin
13231340pub fn symlinkat(target_path: []const u8, newdirfd: fd_t, sym_link_path: []const u8) SymLinkError!void {
13241341 const target_path_c = try toPosixPath(target_path);
13251342 const sym_link_path_c = try toPosixPath(sym_link_path);
1326 return symlinkatC(target_path_c, newdirfd, sym_link_path_c);
1343 return symlinkatZ(target_path_c, newdirfd, sym_link_path_c);
13271344}
13281345
1329pub fn symlinkatC(target_path: [*:0]const u8, newdirfd: fd_t, sym_link_path: [*:0]const u8) SymLinkError!void {
1346pub const symlinkatC = @compileError("deprecated: renamed to symlinkatZ");
1347
1348pub fn symlinkatZ(target_path: [*:0]const u8, newdirfd: fd_t, sym_link_path: [*:0]const u8) SymLinkError!void {
13301349 switch (errno(system.symlinkat(target_path, newdirfd, sym_link_path))) {
13311350 0 => return,
13321351 EFAULT => unreachable,
......@@ -1375,12 +1394,14 @@ pub fn unlink(file_path: []const u8) UnlinkError!void {
13751394 return windows.DeleteFileW(&file_path_w);
13761395 } else {
13771396 const file_path_c = try toPosixPath(file_path);
1378 return unlinkC(&file_path_c);
1397 return unlinkZ(&file_path_c);
13791398 }
13801399}
13811400
1401pub const unlinkC = @compileError("deprecated: renamed to unlinkZ");
1402
13821403/// Same as `unlink` except the parameter is a null terminated UTF8-encoded string.
1383pub fn unlinkC(file_path: [*:0]const u8) UnlinkError!void {
1404pub fn unlinkZ(file_path: [*:0]const u8) UnlinkError!void {
13841405 if (builtin.os.tag == .windows) {
13851406 const file_path_w = try windows.cStrToPrefixedFileW(file_path);
13861407 return windows.DeleteFileW(&file_path_w);
......@@ -1417,11 +1438,13 @@ pub fn unlinkat(dirfd: fd_t, file_path: []const u8, flags: u32) UnlinkatError!vo
14171438 return unlinkatW(dirfd, &file_path_w, flags);
14181439 }
14191440 const file_path_c = try toPosixPath(file_path);
1420 return unlinkatC(dirfd, &file_path_c, flags);
1441 return unlinkatZ(dirfd, &file_path_c, flags);
14211442}
14221443
1444pub const unlinkatC = @compileError("deprecated: renamed to unlinkatZ");
1445
14231446/// Same as `unlinkat` but `file_path` is a null-terminated string.
1424pub fn unlinkatC(dirfd: fd_t, file_path_c: [*:0]const u8, flags: u32) UnlinkatError!void {
1447pub fn unlinkatZ(dirfd: fd_t, file_path_c: [*:0]const u8, flags: u32) UnlinkatError!void {
14251448 if (builtin.os.tag == .windows) {
14261449 const file_path_w = try windows.cStrToPrefixedFileW(file_path_c);
14271450 return unlinkatW(dirfd, &file_path_w, flags);
......@@ -1459,7 +1482,7 @@ pub fn unlinkatW(dirfd: fd_t, sub_path_w: [*:0]const u16, flags: u32) UnlinkatEr
14591482 else
14601483 @as(w.ULONG, w.FILE_DELETE_ON_CLOSE | w.FILE_NON_DIRECTORY_FILE);
14611484
1462 const path_len_bytes = @intCast(u16, mem.toSliceConst(u16, sub_path_w).len * 2);
1485 const path_len_bytes = @intCast(u16, mem.lenZ(sub_path_w) * 2);
14631486 var nt_name = w.UNICODE_STRING{
14641487 .Length = path_len_bytes,
14651488 .MaximumLength = path_len_bytes,
......@@ -1543,12 +1566,14 @@ pub fn rename(old_path: []const u8, new_path: []const u8) RenameError!void {
15431566 } else {
15441567 const old_path_c = try toPosixPath(old_path);
15451568 const new_path_c = try toPosixPath(new_path);
1546 return renameC(&old_path_c, &new_path_c);
1569 return renameZ(&old_path_c, &new_path_c);
15471570 }
15481571}
15491572
1573pub const renameC = @compileError("deprecated: renamed to renameZ");
1574
15501575/// Same as `rename` except the parameters are null-terminated byte arrays.
1551pub fn renameC(old_path: [*:0]const u8, new_path: [*:0]const u8) RenameError!void {
1576pub fn renameZ(old_path: [*:0]const u8, new_path: [*:0]const u8) RenameError!void {
15521577 if (builtin.os.tag == .windows) {
15531578 const old_path_w = try windows.cStrToPrefixedFileW(old_path);
15541579 const new_path_w = try windows.cStrToPrefixedFileW(new_path);
......@@ -1715,11 +1740,13 @@ pub fn mkdirat(dir_fd: fd_t, sub_dir_path: []const u8, mode: u32) MakeDirError!v
17151740 return mkdiratW(dir_fd, &sub_dir_path_w, mode);
17161741 } else {
17171742 const sub_dir_path_c = try toPosixPath(sub_dir_path);
1718 return mkdiratC(dir_fd, &sub_dir_path_c, mode);
1743 return mkdiratZ(dir_fd, &sub_dir_path_c, mode);
17191744 }
17201745}
17211746
1722pub fn mkdiratC(dir_fd: fd_t, sub_dir_path: [*:0]const u8, mode: u32) MakeDirError!void {
1747pub const mkdiratC = @compileError("deprecated: renamed to mkdiratZ");
1748
1749pub fn mkdiratZ(dir_fd: fd_t, sub_dir_path: [*:0]const u8, mode: u32) MakeDirError!void {
17231750 if (builtin.os.tag == .windows) {
17241751 const sub_dir_path_w = try windows.cStrToPrefixedFileW(sub_dir_path);
17251752 return mkdiratW(dir_fd, &sub_dir_path_w, mode);
......@@ -1810,12 +1837,14 @@ pub fn rmdir(dir_path: []const u8) DeleteDirError!void {
18101837 return windows.RemoveDirectoryW(&dir_path_w);
18111838 } else {
18121839 const dir_path_c = try toPosixPath(dir_path);
1813 return rmdirC(&dir_path_c);
1840 return rmdirZ(&dir_path_c);
18141841 }
18151842}
18161843
1844pub const rmdirC = @compileError("deprecated: renamed to rmdirZ");
1845
18171846/// Same as `rmdir` except the parameter is null-terminated.
1818pub fn rmdirC(dir_path: [*:0]const u8) DeleteDirError!void {
1847pub fn rmdirZ(dir_path: [*:0]const u8) DeleteDirError!void {
18191848 if (builtin.os.tag == .windows) {
18201849 const dir_path_w = try windows.cStrToPrefixedFileW(dir_path);
18211850 return windows.RemoveDirectoryW(&dir_path_w);
......@@ -1857,12 +1886,14 @@ pub fn chdir(dir_path: []const u8) ChangeCurDirError!void {
18571886 @compileError("TODO implement chdir for Windows");
18581887 } else {
18591888 const dir_path_c = try toPosixPath(dir_path);
1860 return chdirC(&dir_path_c);
1889 return chdirZ(&dir_path_c);
18611890 }
18621891}
18631892
1893pub const chdirC = @compileError("deprecated: renamed to chdirZ");
1894
18641895/// Same as `chdir` except the parameter is null-terminated.
1865pub fn chdirC(dir_path: [*:0]const u8) ChangeCurDirError!void {
1896pub fn chdirZ(dir_path: [*:0]const u8) ChangeCurDirError!void {
18661897 if (builtin.os.tag == .windows) {
18671898 const dir_path_w = try windows.cStrToPrefixedFileW(dir_path);
18681899 @compileError("TODO implement chdir for Windows");
......@@ -1919,12 +1950,14 @@ pub fn readlink(file_path: []const u8, out_buffer: []u8) ReadLinkError![]u8 {
19191950 @compileError("TODO implement readlink for Windows");
19201951 } else {
19211952 const file_path_c = try toPosixPath(file_path);
1922 return readlinkC(&file_path_c, out_buffer);
1953 return readlinkZ(&file_path_c, out_buffer);
19231954 }
19241955}
19251956
1957pub const readlinkC = @compileError("deprecated: renamed to readlinkZ");
1958
19261959/// Same as `readlink` except `file_path` is null-terminated.
1927pub fn readlinkC(file_path: [*:0]const u8, out_buffer: []u8) ReadLinkError![]u8 {
1960pub fn readlinkZ(file_path: [*:0]const u8, out_buffer: []u8) ReadLinkError![]u8 {
19281961 if (builtin.os.tag == .windows) {
19291962 const file_path_w = try windows.cStrToPrefixedFileW(file_path);
19301963 @compileError("TODO implement readlink for Windows");
......@@ -1945,7 +1978,9 @@ pub fn readlinkC(file_path: [*:0]const u8, out_buffer: []u8) ReadLinkError![]u8
19451978 }
19461979}
19471980
1948pub fn readlinkatC(dirfd: fd_t, file_path: [*:0]const u8, out_buffer: []u8) ReadLinkError![]u8 {
1981pub const readlinkatC = @compileError("deprecated: renamed to readlinkatZ");
1982
1983pub fn readlinkatZ(dirfd: fd_t, file_path: [*:0]const u8, out_buffer: []u8) ReadLinkError![]u8 {
19491984 if (builtin.os.tag == .windows) {
19501985 const file_path_w = try windows.cStrToPrefixedFileW(file_path);
19511986 @compileError("TODO implement readlink for Windows");
......@@ -2044,7 +2079,7 @@ pub fn isatty(handle: fd_t) bool {
20442079 }
20452080 if (builtin.os.tag == .linux) {
20462081 var wsz: linux.winsize = undefined;
2047 return linux.syscall3(linux.SYS_ioctl, @bitCast(usize, @as(isize, handle)), linux.TIOCGWINSZ, @ptrToInt(&wsz)) == 0;
2082 return linux.syscall3(.ioctl, @bitCast(usize, @as(isize, handle)), linux.TIOCGWINSZ, @ptrToInt(&wsz)) == 0;
20482083 }
20492084 unreachable;
20502085}
......@@ -2532,14 +2567,7 @@ pub const FStatError = error{
25322567pub fn fstat(fd: fd_t) FStatError!Stat {
25332568 var stat: Stat = undefined;
25342569
2535 const symbol_name = if (comptime std.Target.current.isDarwin())
2536 "fstat$INODE64"
2537 else if (std.Target.current.os.tag == .netbsd)
2538 "__fstat50"
2539 else
2540 "fstat";
2541
2542 switch (errno(@field(system, symbol_name)(fd, &stat))) {
2570 switch (errno(system.fstat(fd, &stat))) {
25432571 0 => return stat,
25442572 EINVAL => unreachable,
25452573 EBADF => unreachable, // Always a race condition.
......@@ -2553,10 +2581,12 @@ const FStatAtError = FStatError || error{NameTooLong};
25532581
25542582pub fn fstatat(dirfd: fd_t, pathname: []const u8, flags: u32) FStatAtError![]Stat {
25552583 const pathname_c = try toPosixPath(pathname);
2556 return fstatatC(dirfd, &pathname_c, flags);
2584 return fstatatZ(dirfd, &pathname_c, flags);
25572585}
25582586
2559pub fn fstatatC(dirfd: fd_t, pathname: [*:0]const u8, flags: u32) FStatAtError!Stat {
2587pub const fstatatC = @compileError("deprecated: renamed to fstatatZ");
2588
2589pub fn fstatatZ(dirfd: fd_t, pathname: [*:0]const u8, flags: u32) FStatAtError!Stat {
25602590 var stat: Stat = undefined;
25612591 switch (errno(system.fstatat(dirfd, pathname, &stat, flags))) {
25622592 0 => return stat,
......@@ -2668,11 +2698,13 @@ pub const INotifyAddWatchError = error{
26682698/// add a watch to an initialized inotify instance
26692699pub fn inotify_add_watch(inotify_fd: i32, pathname: []const u8, mask: u32) INotifyAddWatchError!i32 {
26702700 const pathname_c = try toPosixPath(pathname);
2671 return inotify_add_watchC(inotify_fd, &pathname_c, mask);
2701 return inotify_add_watchZ(inotify_fd, &pathname_c, mask);
26722702}
26732703
2704pub const inotify_add_watchC = @compileError("deprecated: renamed to inotify_add_watchZ");
2705
26742706/// Same as `inotify_add_watch` except pathname is null-terminated.
2675pub fn inotify_add_watchC(inotify_fd: i32, pathname: [*:0]const u8, mask: u32) INotifyAddWatchError!i32 {
2707pub fn inotify_add_watchZ(inotify_fd: i32, pathname: [*:0]const u8, mask: u32) INotifyAddWatchError!i32 {
26762708 const rc = system.inotify_add_watch(inotify_fd, pathname, mask);
26772709 switch (errno(rc)) {
26782710 0 => return @intCast(i32, rc),
......@@ -2829,11 +2861,10 @@ pub fn access(path: []const u8, mode: u32) AccessError!void {
28292861 return;
28302862 }
28312863 const path_c = try toPosixPath(path);
2832 return accessC(&path_c, mode);
2864 return accessZ(&path_c, mode);
28332865}
28342866
2835/// Deprecated in favor of `accessZ`.
2836pub const accessC = accessZ;
2867pub const accessC = @compileError("Deprecated in favor of `accessZ`");
28372868
28382869/// Same as `access` except `path` is null-terminated.
28392870pub fn accessZ(path: [*:0]const u8, mode: u32) AccessError!void {
......@@ -2920,7 +2951,7 @@ pub fn faccessatW(dirfd: fd_t, sub_path_w: [*:0]const u16, mode: u32, flags: u32
29202951 return;
29212952 }
29222953
2923 const path_len_bytes = math.cast(u16, mem.toSliceConst(u16, sub_path_w).len * 2) catch |err| switch (err) {
2954 const path_len_bytes = math.cast(u16, mem.lenZ(sub_path_w) * 2) catch |err| switch (err) {
29242955 error.Overflow => return error.NameTooLong,
29252956 };
29262957 var nt_name = windows.UNICODE_STRING{
......@@ -3019,7 +3050,9 @@ pub fn sysctl(
30193050 }
30203051}
30213052
3022pub fn sysctlbynameC(
3053pub const sysctlbynameC = @compileError("deprecated: renamed to sysctlbynameZ");
3054
3055pub fn sysctlbynameZ(
30233056 name: [*:0]const u8,
30243057 oldp: ?*c_void,
30253058 oldlenp: ?*usize,
......@@ -3224,23 +3257,25 @@ pub fn realpath(pathname: []const u8, out_buffer: *[MAX_PATH_BYTES]u8) RealPathE
32243257 return realpathW(&pathname_w, out_buffer);
32253258 }
32263259 const pathname_c = try toPosixPath(pathname);
3227 return realpathC(&pathname_c, out_buffer);
3260 return realpathZ(&pathname_c, out_buffer);
32283261}
32293262
3263pub const realpathC = @compileError("deprecated: renamed realpathZ");
3264
32303265/// Same as `realpath` except `pathname` is null-terminated.
3231pub fn realpathC(pathname: [*:0]const u8, out_buffer: *[MAX_PATH_BYTES]u8) RealPathError![]u8 {
3266pub fn realpathZ(pathname: [*:0]const u8, out_buffer: *[MAX_PATH_BYTES]u8) RealPathError![]u8 {
32323267 if (builtin.os.tag == .windows) {
32333268 const pathname_w = try windows.cStrToPrefixedFileW(pathname);
32343269 return realpathW(&pathname_w, out_buffer);
32353270 }
32363271 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);
3272 const fd = try openZ(pathname, linux.O_PATH | linux.O_NONBLOCK | linux.O_CLOEXEC, 0);
32383273 defer close(fd);
32393274
32403275 var procfs_buf: ["/proc/self/fd/-2147483648".len:0]u8 = undefined;
32413276 const proc_path = std.fmt.bufPrint(procfs_buf[0..], "/proc/self/fd/{}\x00", .{fd}) catch unreachable;
32423277
3243 return readlinkC(@ptrCast([*:0]const u8, proc_path.ptr), out_buffer);
3278 return readlinkZ(@ptrCast([*:0]const u8, proc_path.ptr), out_buffer);
32443279 }
32453280 const result_path = std.c.realpath(pathname, out_buffer) orelse switch (std.c._errno().*) {
32463281 EINVAL => unreachable,
......@@ -3255,7 +3290,7 @@ pub fn realpathC(pathname: [*:0]const u8, out_buffer: *[MAX_PATH_BYTES]u8) RealP
32553290 EIO => return error.InputOutput,
32563291 else => |err| return unexpectedErrno(@intCast(usize, err)),
32573292 };
3258 return mem.toSlice(u8, result_path);
3293 return mem.spanZ(result_path);
32593294}
32603295
32613296/// Same as `realpath` except `pathname` is null-terminated and UTF16LE-encoded.
......@@ -3399,12 +3434,7 @@ pub fn clock_gettime(clk_id: i32, tp: *timespec) ClockGetTimeError!void {
33993434 return;
34003435 }
34013436
3402 const symbol_name = if (std.Target.current.os.tag == .netbsd)
3403 "__clock_gettime50"
3404 else
3405 "clock_gettime";
3406
3407 switch (errno(@field(system, symbol_name)(clk_id, tp))) {
3437 switch (errno(system.clock_gettime(clk_id, tp))) {
34083438 0 => return,
34093439 EFAULT => unreachable,
34103440 EINVAL => return error.UnsupportedClock,
......@@ -3426,12 +3456,7 @@ pub fn clock_getres(clk_id: i32, res: *timespec) ClockGetTimeError!void {
34263456 return;
34273457 }
34283458
3429 const symbol_name = if (std.Target.current.os.tag == .netbsd)
3430 "__clock_getres50"
3431 else
3432 "clock_getres";
3433
3434 switch (errno(@field(system, symbol_name)(clk_id, res))) {
3459 switch (errno(system.clock_getres(clk_id, res))) {
34353460 0 => return,
34363461 EFAULT => unreachable,
34373462 EINVAL => return error.UnsupportedClock,
......@@ -3497,12 +3522,7 @@ pub const SigaltstackError = error{
34973522} || UnexpectedError;
34983523
34993524pub fn sigaltstack(ss: ?*stack_t, old_ss: ?*stack_t) SigaltstackError!void {
3500 const symbol_name = if (std.Target.current.os.tag == .netbsd)
3501 "__sigaltstack14"
3502 else
3503 "sigaltstack";
3504
3505 switch (errno(@field(system, symbol_name)(ss, old_ss))) {
3525 switch (errno(system.sigaltstack(ss, old_ss))) {
35063526 0 => return,
35073527 EFAULT => unreachable,
35083528 EINVAL => unreachable,
......@@ -3564,7 +3584,7 @@ pub const GetHostNameError = error{PermissionDenied} || UnexpectedError;
35643584pub fn gethostname(name_buffer: *[HOST_NAME_MAX]u8) GetHostNameError![]u8 {
35653585 if (builtin.link_libc) {
35663586 switch (errno(system.gethostname(name_buffer, name_buffer.len))) {
3567 0 => return mem.toSlice(u8, @ptrCast([*:0]u8, name_buffer)),
3587 0 => return mem.spanZ(@ptrCast([*:0]u8, name_buffer)),
35683588 EFAULT => unreachable,
35693589 ENAMETOOLONG => unreachable, // HOST_NAME_MAX prevents this
35703590 EPERM => return error.PermissionDenied,
......@@ -3573,7 +3593,7 @@ pub fn gethostname(name_buffer: *[HOST_NAME_MAX]u8) GetHostNameError![]u8 {
35733593 }
35743594 if (builtin.os.tag == .linux) {
35753595 const uts = uname();
3576 const hostname = mem.toSliceConst(u8, @ptrCast([*:0]const u8, &uts.nodename));
3596 const hostname = mem.spanZ(@ptrCast([*:0]const u8, &uts.nodename));
35773597 mem.copy(u8, name_buffer, hostname);
35783598 return name_buffer[0..hostname.len];
35793599 }
......@@ -4260,7 +4280,9 @@ pub const MemFdCreateError = error{
42604280 SystemOutdated,
42614281} || UnexpectedError;
42624282
4263pub fn memfd_createC(name: [*:0]const u8, flags: u32) MemFdCreateError!fd_t {
4283pub const memfd_createC = @compileError("deprecated: renamed to memfd_createZ");
4284
4285pub fn memfd_createZ(name: [*:0]const u8, flags: u32) MemFdCreateError!fd_t {
42644286 // memfd_create is available only in glibc versions starting with 2.27.
42654287 const use_c = std.c.versionCheck(.{ .major = 2, .minor = 27, .patch = 0 }).ok;
42664288 const sys = if (use_c) std.c else linux;
......@@ -4291,7 +4313,7 @@ fn toMemFdPath(name: []const u8) ![MFD_MAX_NAME_LEN:0]u8 {
42914313
42924314pub fn memfd_create(name: []const u8, flags: u32) !fd_t {
42934315 const name_t = try toMemFdPath(name);
4294 return memfd_createC(&name_t, flags);
4316 return memfd_createZ(&name_t, flags);
42954317}
42964318
42974319pub fn getrusage(who: i32) rusage {
lib/std/os/bits/linux.zig+128-25
......@@ -88,11 +88,29 @@ pub const FUTEX_PRIVATE_FLAG = 128;
8888
8989pub const FUTEX_CLOCK_REALTIME = 256;
9090
91pub const PROT_NONE = 0;
92pub const PROT_READ = 1;
93pub const PROT_WRITE = 2;
94pub const PROT_EXEC = 4;
91/// page can not be accessed
92pub const PROT_NONE = 0x0;
93
94/// page can be read
95pub const PROT_READ = 0x1;
96
97/// page can be written
98pub const PROT_WRITE = 0x2;
99
100/// page can be executed
101pub const PROT_EXEC = 0x4;
102
103/// page may be used for atomic ops
104pub const PROT_SEM = switch (builtin.arch) {
105 // TODO: also xtensa
106 .mips, .mipsel, .mips64, .mips64el => 0x10,
107 else => 0x8,
108};
109
110/// mprotect flag: extend change to start of growsdown vma
95111pub const PROT_GROWSDOWN = 0x01000000;
112
113/// mprotect flag: extend change to end of growsup vma
96114pub const PROT_GROWSUP = 0x02000000;
97115
98116/// Share changes
......@@ -617,6 +635,11 @@ pub const CLONE_IO = 0x80000000;
617635/// Clear any signal handler and reset to SIG_DFL.
618636pub const CLONE_CLEAR_SIGHAND = 0x100000000;
619637
638// cloning flags intersect with CSIGNAL so can be used with unshare and clone3 syscalls only.
639
640/// New time namespace
641pub const CLONE_NEWTIME = 0x00000080;
642
620643pub const EFD_SEMAPHORE = 1;
621644pub const EFD_CLOEXEC = O_CLOEXEC;
622645pub const EFD_NONBLOCK = O_NONBLOCK;
......@@ -790,13 +813,13 @@ pub const app_mask: sigset_t = [2]u32{ 0xfffffffc, 0x7fffffff } ++ [_]u32{0xffff
790813pub const k_sigaction = if (is_mips)
791814 extern struct {
792815 flags: usize,
793 sigaction: ?extern fn (i32, *siginfo_t, *c_void) void,
816 sigaction: ?extern fn (i32, *siginfo_t, ?*c_void) void,
794817 mask: [4]u32,
795818 restorer: extern fn () void,
796819 }
797820else
798821 extern struct {
799 sigaction: ?extern fn (i32, *siginfo_t, *c_void) void,
822 sigaction: ?extern fn (i32, *siginfo_t, ?*c_void) void,
800823 flags: usize,
801824 restorer: extern fn () void,
802825 mask: [2]u32,
......@@ -804,15 +827,17 @@ else
804827
805828/// Renamed from `sigaction` to `Sigaction` to avoid conflict with the syscall.
806829pub const Sigaction = extern struct {
807 sigaction: ?extern fn (i32, *siginfo_t, *c_void) void,
830 pub const sigaction_fn = fn (i32, *siginfo_t, ?*c_void) callconv(.C) void;
831 sigaction: ?sigaction_fn,
808832 mask: sigset_t,
809833 flags: u32,
810834 restorer: ?extern fn () void = null,
811835};
812836
813pub const SIG_ERR = @intToPtr(extern fn (i32, *siginfo_t, *c_void) void, maxInt(usize));
814pub const SIG_DFL = @intToPtr(?extern fn (i32, *siginfo_t, *c_void) void, 0);
815pub const SIG_IGN = @intToPtr(extern fn (i32, *siginfo_t, *c_void) void, 1);
837pub const SIG_ERR = @intToPtr(?Sigaction.sigaction_fn, maxInt(usize));
838pub const SIG_DFL = @intToPtr(?Sigaction.sigaction_fn, 0);
839pub const SIG_IGN = @intToPtr(?Sigaction.sigaction_fn, 1);
840
816841pub const empty_sigset = [_]u32{0} ** sigset_t.len;
817842
818843pub const in_port_t = u16;
......@@ -1125,7 +1150,8 @@ pub const io_uring_params = extern struct {
11251150 sq_thread_cpu: u32,
11261151 sq_thread_idle: u32,
11271152 features: u32,
1128 resv: [4]u32,
1153 wq_fd: u32,
1154 resv: [3]u32,
11291155 sq_off: io_sqring_offsets,
11301156 cq_off: io_cqring_offsets,
11311157};
......@@ -1135,6 +1161,8 @@ pub const io_uring_params = extern struct {
11351161pub const IORING_FEAT_SINGLE_MMAP = 1 << 0;
11361162pub const IORING_FEAT_NODROP = 1 << 1;
11371163pub const IORING_FEAT_SUBMIT_STABLE = 1 << 2;
1164pub const IORING_FEAT_RW_CUR_POS = 1 << 3;
1165pub const IORING_FEAT_CUR_PERSONALITY = 1 << 4;
11381166
11391167// io_uring_params.flags
11401168
......@@ -1150,6 +1178,12 @@ pub const IORING_SETUP_SQ_AFF = 1 << 2;
11501178/// app defines CQ size
11511179pub const IORING_SETUP_CQSIZE = 1 << 3;
11521180
1181/// clamp SQ/CQ ring sizes
1182pub const IORING_SETUP_CLAMP = 1 << 4;
1183
1184/// attach to existing wq
1185pub const IORING_SETUP_ATTACH_WQ = 1 << 5;
1186
11531187pub const io_sqring_offsets = extern struct {
11541188 /// offset of ring head
11551189 head: u32,
......@@ -1192,7 +1226,7 @@ pub const io_cqring_offsets = extern struct {
11921226};
11931227
11941228pub const io_uring_sqe = extern struct {
1195 opcode: u8,
1229 opcode: IORING_OP,
11961230 flags: u8,
11971231 ioprio: u16,
11981232 fd: i32,
......@@ -1212,31 +1246,53 @@ pub const io_uring_sqe = extern struct {
12121246 timeout_flags: u32,
12131247 accept_flags: u32,
12141248 cancel_flags: u32,
1249 open_flags: u32,
1250 statx_flags: u32,
1251 fadvise_flags: u32,
12151252 };
12161253 union2: union2,
12171254 user_data: u64,
12181255 pub const union3 = extern union {
1219 buf_index: u16,
1256 struct1: extern struct {
1257 /// index into fixed buffers, if used
1258 buf_index: u16,
1259
1260 /// personality to use, if used
1261 personality: u16,
1262 },
12201263 __pad2: [3]u64,
12211264 };
12221265 union3: union3,
12231266};
12241267
1268pub const IOSQE_BIT = extern enum {
1269 FIXED_FILE,
1270 IO_DRAIN,
1271 IO_LINK,
1272 IO_HARDLINK,
1273 ASYNC,
1274
1275 _,
1276};
1277
12251278// io_uring_sqe.flags
12261279
12271280/// use fixed fileset
1228pub const IOSQE_FIXED_FILE = 1 << 0;
1281pub const IOSQE_FIXED_FILE = 1 << IOSQE_BIT.FIXED_FILE;
12291282
12301283/// issue after inflight IO
1231pub const IOSQE_IO_DRAIN = 1 << 1;
1284pub const IOSQE_IO_DRAIN = 1 << IOSQE_BIT.IO_DRAIN;
12321285
12331286/// links next sqe
1234pub const IOSQE_IO_LINK = 1 << 2;
1287pub const IOSQE_IO_LINK = 1 << IOSQE_BIT.IO_LINK;
12351288
12361289/// like LINK, but stronger
1237pub const IOSQE_IO_HARDLINK = 1 << 3;
1290pub const IOSQE_IO_HARDLINK = 1 << IOSQE_BIT.IO_HARDLINK;
1291
1292/// always go async
1293pub const IOSQE_ASYNC = 1 << IOSQE_BIT.ASYNC;
12381294
1239pub const IORING_OP = extern enum {
1295pub const IORING_OP = extern enum(u8) {
12401296 NOP,
12411297 READV,
12421298 WRITEV,
......@@ -1254,6 +1310,19 @@ pub const IORING_OP = extern enum {
12541310 ASYNC_CANCEL,
12551311 LINK_TIMEOUT,
12561312 CONNECT,
1313 FALLOCATE,
1314 OPENAT,
1315 CLOSE,
1316 FILES_UPDATE,
1317 STATX,
1318 READ,
1319 WRITE,
1320 FADVISE,
1321 MADVISE,
1322 SEND,
1323 RECV,
1324 OPENAT2,
1325 EPOLL_CTL,
12571326
12581327 _,
12591328};
......@@ -1283,13 +1352,21 @@ pub const IORING_ENTER_GETEVENTS = 1 << 0;
12831352pub const IORING_ENTER_SQ_WAKEUP = 1 << 1;
12841353
12851354// io_uring_register opcodes and arguments
1286pub const IORING_REGISTER_BUFFERS = 0;
1287pub const IORING_UNREGISTER_BUFFERS = 1;
1288pub const IORING_REGISTER_FILES = 2;
1289pub const IORING_UNREGISTER_FILES = 3;
1290pub const IORING_REGISTER_EVENTFD = 4;
1291pub const IORING_UNREGISTER_EVENTFD = 5;
1292pub const IORING_REGISTER_FILES_UPDATE = 6;
1355pub const IORING_REGISTER = extern enum(u32) {
1356 REGISTER_BUFFERS,
1357 UNREGISTER_BUFFERS,
1358 REGISTER_FILES,
1359 UNREGISTER_FILES,
1360 REGISTER_EVENTFD,
1361 UNREGISTER_EVENTFD,
1362 REGISTER_FILES_UPDATE,
1363 REGISTER_EVENTFD_ASYNC,
1364 REGISTER_PROBE,
1365 REGISTER_PERSONALITY,
1366 UNREGISTER_PERSONALITY,
1367
1368 _,
1369};
12931370
12941371pub const io_uring_files_update = struct {
12951372 offset: u32,
......@@ -1297,6 +1374,32 @@ pub const io_uring_files_update = struct {
12971374 fds: u64,
12981375};
12991376
1377pub const IO_URING_OP_SUPPORTED = 1 << 0;
1378
1379pub const io_uring_probe_op = struct {
1380 op: IORING_OP,
1381
1382 resv: u8,
1383
1384 /// IO_URING_OP_* flags
1385 flags: u16,
1386
1387 resv2: u32,
1388};
1389
1390pub const io_uring_probe = struct {
1391 /// last opcode supported
1392 last_op: IORING_OP,
1393
1394 /// Number of io_uring_probe_op following
1395 ops_len: u8,
1396
1397 resv: u16,
1398 resv2: u32[3],
1399
1400 // Followed by up to `ops_len` io_uring_probe_op structures
1401};
1402
13001403pub const utsname = extern struct {
13011404 sysname: [64:0]u8,
13021405 nodename: [64:0]u8,
lib/std/os/bits/linux/arm-eabi.zig+404-398
......@@ -10,404 +10,410 @@ const uid_t = linux.uid_t;
1010const gid_t = linux.gid_t;
1111const pid_t = linux.pid_t;
1212
13pub const SYS_restart_syscall = 0;
14pub const SYS_exit = 1;
15pub const SYS_fork = 2;
16pub const SYS_read = 3;
17pub const SYS_write = 4;
18pub const SYS_open = 5;
19pub const SYS_close = 6;
20pub const SYS_creat = 8;
21pub const SYS_link = 9;
22pub const SYS_unlink = 10;
23pub const SYS_execve = 11;
24pub const SYS_chdir = 12;
25pub const SYS_mknod = 14;
26pub const SYS_chmod = 15;
27pub const SYS_lchown = 16;
28pub const SYS_lseek = 19;
29pub const SYS_getpid = 20;
30pub const SYS_mount = 21;
31pub const SYS_setuid = 23;
32pub const SYS_getuid = 24;
33pub const SYS_ptrace = 26;
34pub const SYS_pause = 29;
35pub const SYS_access = 33;
36pub const SYS_nice = 34;
37pub const SYS_sync = 36;
38pub const SYS_kill = 37;
39pub const SYS_rename = 38;
40pub const SYS_mkdir = 39;
41pub const SYS_rmdir = 40;
42pub const SYS_dup = 41;
43pub const SYS_pipe = 42;
44pub const SYS_times = 43;
45pub const SYS_brk = 45;
46pub const SYS_setgid = 46;
47pub const SYS_getgid = 47;
48pub const SYS_geteuid = 49;
49pub const SYS_getegid = 50;
50pub const SYS_acct = 51;
51pub const SYS_umount2 = 52;
52pub const SYS_ioctl = 54;
53pub const SYS_fcntl = 55;
54pub const SYS_setpgid = 57;
55pub const SYS_umask = 60;
56pub const SYS_chroot = 61;
57pub const SYS_ustat = 62;
58pub const SYS_dup2 = 63;
59pub const SYS_getppid = 64;
60pub const SYS_getpgrp = 65;
61pub const SYS_setsid = 66;
62pub const SYS_sigaction = 67;
63pub const SYS_setreuid = 70;
64pub const SYS_setregid = 71;
65pub const SYS_sigsuspend = 72;
66pub const SYS_sigpending = 73;
67pub const SYS_sethostname = 74;
68pub const SYS_setrlimit = 75;
69pub const SYS_getrusage = 77;
70pub const SYS_gettimeofday = 78;
71pub const SYS_settimeofday = 79;
72pub const SYS_getgroups = 80;
73pub const SYS_setgroups = 81;
74pub const SYS_symlink = 83;
75pub const SYS_readlink = 85;
76pub const SYS_uselib = 86;
77pub const SYS_swapon = 87;
78pub const SYS_reboot = 88;
79pub const SYS_munmap = 91;
80pub const SYS_truncate = 92;
81pub const SYS_ftruncate = 93;
82pub const SYS_fchmod = 94;
83pub const SYS_fchown = 95;
84pub const SYS_getpriority = 96;
85pub const SYS_setpriority = 97;
86pub const SYS_statfs = 99;
87pub const SYS_fstatfs = 100;
88pub const SYS_syslog = 103;
89pub const SYS_setitimer = 104;
90pub const SYS_getitimer = 105;
91pub const SYS_stat = 106;
92pub const SYS_lstat = 107;
93pub const SYS_fstat = 108;
94pub const SYS_vhangup = 111;
95pub const SYS_wait4 = 114;
96pub const SYS_swapoff = 115;
97pub const SYS_sysinfo = 116;
98pub const SYS_fsync = 118;
99pub const SYS_sigreturn = 119;
100pub const SYS_clone = 120;
101pub const SYS_setdomainname = 121;
102pub const SYS_uname = 122;
103pub const SYS_adjtimex = 124;
104pub const SYS_mprotect = 125;
105pub const SYS_sigprocmask = 126;
106pub const SYS_init_module = 128;
107pub const SYS_delete_module = 129;
108pub const SYS_quotactl = 131;
109pub const SYS_getpgid = 132;
110pub const SYS_fchdir = 133;
111pub const SYS_bdflush = 134;
112pub const SYS_sysfs = 135;
113pub const SYS_personality = 136;
114pub const SYS_setfsuid = 138;
115pub const SYS_setfsgid = 139;
116pub const SYS__llseek = 140;
117pub const SYS_getdents = 141;
118pub const SYS__newselect = 142;
119pub const SYS_flock = 143;
120pub const SYS_msync = 144;
121pub const SYS_readv = 145;
122pub const SYS_writev = 146;
123pub const SYS_getsid = 147;
124pub const SYS_fdatasync = 148;
125pub const SYS__sysctl = 149;
126pub const SYS_mlock = 150;
127pub const SYS_munlock = 151;
128pub const SYS_mlockall = 152;
129pub const SYS_munlockall = 153;
130pub const SYS_sched_setparam = 154;
131pub const SYS_sched_getparam = 155;
132pub const SYS_sched_setscheduler = 156;
133pub const SYS_sched_getscheduler = 157;
134pub const SYS_sched_yield = 158;
135pub const SYS_sched_get_priority_max = 159;
136pub const SYS_sched_get_priority_min = 160;
137pub const SYS_sched_rr_get_interval = 161;
138pub const SYS_nanosleep = 162;
139pub const SYS_mremap = 163;
140pub const SYS_setresuid = 164;
141pub const SYS_getresuid = 165;
142pub const SYS_poll = 168;
143pub const SYS_nfsservctl = 169;
144pub const SYS_setresgid = 170;
145pub const SYS_getresgid = 171;
146pub const SYS_prctl = 172;
147pub const SYS_rt_sigreturn = 173;
148pub const SYS_rt_sigaction = 174;
149pub const SYS_rt_sigprocmask = 175;
150pub const SYS_rt_sigpending = 176;
151pub const SYS_rt_sigtimedwait = 177;
152pub const SYS_rt_sigqueueinfo = 178;
153pub const SYS_rt_sigsuspend = 179;
154pub const SYS_pread64 = 180;
155pub const SYS_pwrite64 = 181;
156pub const SYS_chown = 182;
157pub const SYS_getcwd = 183;
158pub const SYS_capget = 184;
159pub const SYS_capset = 185;
160pub const SYS_sigaltstack = 186;
161pub const SYS_sendfile = 187;
162pub const SYS_vfork = 190;
163pub const SYS_ugetrlimit = 191;
164pub const SYS_mmap2 = 192;
165pub const SYS_truncate64 = 193;
166pub const SYS_ftruncate64 = 194;
167pub const SYS_stat64 = 195;
168pub const SYS_lstat64 = 196;
169pub const SYS_fstat64 = 197;
170pub const SYS_lchown32 = 198;
171pub const SYS_getuid32 = 199;
172pub const SYS_getgid32 = 200;
173pub const SYS_geteuid32 = 201;
174pub const SYS_getegid32 = 202;
175pub const SYS_setreuid32 = 203;
176pub const SYS_setregid32 = 204;
177pub const SYS_getgroups32 = 205;
178pub const SYS_setgroups32 = 206;
179pub const SYS_fchown32 = 207;
180pub const SYS_setresuid32 = 208;
181pub const SYS_getresuid32 = 209;
182pub const SYS_setresgid32 = 210;
183pub const SYS_getresgid32 = 211;
184pub const SYS_chown32 = 212;
185pub const SYS_setuid32 = 213;
186pub const SYS_setgid32 = 214;
187pub const SYS_setfsuid32 = 215;
188pub const SYS_setfsgid32 = 216;
189pub const SYS_getdents64 = 217;
190pub const SYS_pivot_root = 218;
191pub const SYS_mincore = 219;
192pub const SYS_madvise = 220;
193pub const SYS_fcntl64 = 221;
194pub const SYS_gettid = 224;
195pub const SYS_readahead = 225;
196pub const SYS_setxattr = 226;
197pub const SYS_lsetxattr = 227;
198pub const SYS_fsetxattr = 228;
199pub const SYS_getxattr = 229;
200pub const SYS_lgetxattr = 230;
201pub const SYS_fgetxattr = 231;
202pub const SYS_listxattr = 232;
203pub const SYS_llistxattr = 233;
204pub const SYS_flistxattr = 234;
205pub const SYS_removexattr = 235;
206pub const SYS_lremovexattr = 236;
207pub const SYS_fremovexattr = 237;
208pub const SYS_tkill = 238;
209pub const SYS_sendfile64 = 239;
210pub const SYS_futex = 240;
211pub const SYS_sched_setaffinity = 241;
212pub const SYS_sched_getaffinity = 242;
213pub const SYS_io_setup = 243;
214pub const SYS_io_destroy = 244;
215pub const SYS_io_getevents = 245;
216pub const SYS_io_submit = 246;
217pub const SYS_io_cancel = 247;
218pub const SYS_exit_group = 248;
219pub const SYS_lookup_dcookie = 249;
220pub const SYS_epoll_create = 250;
221pub const SYS_epoll_ctl = 251;
222pub const SYS_epoll_wait = 252;
223pub const SYS_remap_file_pages = 253;
224pub const SYS_set_tid_address = 256;
225pub const SYS_timer_create = 257;
226pub const SYS_timer_settime = 258;
227pub const SYS_timer_gettime = 259;
228pub const SYS_timer_getoverrun = 260;
229pub const SYS_timer_delete = 261;
230pub const SYS_clock_settime = 262;
231pub const SYS_clock_gettime = 263;
232pub const SYS_clock_getres = 264;
233pub const SYS_clock_nanosleep = 265;
234pub const SYS_statfs64 = 266;
235pub const SYS_fstatfs64 = 267;
236pub const SYS_tgkill = 268;
237pub const SYS_utimes = 269;
238pub const SYS_fadvise64_64 = 270;
239pub const SYS_arm_fadvise64_64 = 270;
240pub const SYS_pciconfig_iobase = 271;
241pub const SYS_pciconfig_read = 272;
242pub const SYS_pciconfig_write = 273;
243pub const SYS_mq_open = 274;
244pub const SYS_mq_unlink = 275;
245pub const SYS_mq_timedsend = 276;
246pub const SYS_mq_timedreceive = 277;
247pub const SYS_mq_notify = 278;
248pub const SYS_mq_getsetattr = 279;
249pub const SYS_waitid = 280;
250pub const SYS_socket = 281;
251pub const SYS_bind = 282;
252pub const SYS_connect = 283;
253pub const SYS_listen = 284;
254pub const SYS_accept = 285;
255pub const SYS_getsockname = 286;
256pub const SYS_getpeername = 287;
257pub const SYS_socketpair = 288;
258pub const SYS_send = 289;
259pub const SYS_sendto = 290;
260pub const SYS_recv = 291;
261pub const SYS_recvfrom = 292;
262pub const SYS_shutdown = 293;
263pub const SYS_setsockopt = 294;
264pub const SYS_getsockopt = 295;
265pub const SYS_sendmsg = 296;
266pub const SYS_recvmsg = 297;
267pub const SYS_semop = 298;
268pub const SYS_semget = 299;
269pub const SYS_semctl = 300;
270pub const SYS_msgsnd = 301;
271pub const SYS_msgrcv = 302;
272pub const SYS_msgget = 303;
273pub const SYS_msgctl = 304;
274pub const SYS_shmat = 305;
275pub const SYS_shmdt = 306;
276pub const SYS_shmget = 307;
277pub const SYS_shmctl = 308;
278pub const SYS_add_key = 309;
279pub const SYS_request_key = 310;
280pub const SYS_keyctl = 311;
281pub const SYS_semtimedop = 312;
282pub const SYS_vserver = 313;
283pub const SYS_ioprio_set = 314;
284pub const SYS_ioprio_get = 315;
285pub const SYS_inotify_init = 316;
286pub const SYS_inotify_add_watch = 317;
287pub const SYS_inotify_rm_watch = 318;
288pub const SYS_mbind = 319;
289pub const SYS_get_mempolicy = 320;
290pub const SYS_set_mempolicy = 321;
291pub const SYS_openat = 322;
292pub const SYS_mkdirat = 323;
293pub const SYS_mknodat = 324;
294pub const SYS_fchownat = 325;
295pub const SYS_futimesat = 326;
296pub const SYS_fstatat64 = 327;
297pub const SYS_unlinkat = 328;
298pub const SYS_renameat = 329;
299pub const SYS_linkat = 330;
300pub const SYS_symlinkat = 331;
301pub const SYS_readlinkat = 332;
302pub const SYS_fchmodat = 333;
303pub const SYS_faccessat = 334;
304pub const SYS_pselect6 = 335;
305pub const SYS_ppoll = 336;
306pub const SYS_unshare = 337;
307pub const SYS_set_robust_list = 338;
308pub const SYS_get_robust_list = 339;
309pub const SYS_splice = 340;
310pub const SYS_sync_file_range2 = 341;
311pub const SYS_arm_sync_file_range = 341;
312pub const SYS_tee = 342;
313pub const SYS_vmsplice = 343;
314pub const SYS_move_pages = 344;
315pub const SYS_getcpu = 345;
316pub const SYS_epoll_pwait = 346;
317pub const SYS_kexec_load = 347;
318pub const SYS_utimensat = 348;
319pub const SYS_signalfd = 349;
320pub const SYS_timerfd_create = 350;
321pub const SYS_eventfd = 351;
322pub const SYS_fallocate = 352;
323pub const SYS_timerfd_settime = 353;
324pub const SYS_timerfd_gettime = 354;
325pub const SYS_signalfd4 = 355;
326pub const SYS_eventfd2 = 356;
327pub const SYS_epoll_create1 = 357;
328pub const SYS_dup3 = 358;
329pub const SYS_pipe2 = 359;
330pub const SYS_inotify_init1 = 360;
331pub const SYS_preadv = 361;
332pub const SYS_pwritev = 362;
333pub const SYS_rt_tgsigqueueinfo = 363;
334pub const SYS_perf_event_open = 364;
335pub const SYS_recvmmsg = 365;
336pub const SYS_accept4 = 366;
337pub const SYS_fanotify_init = 367;
338pub const SYS_fanotify_mark = 368;
339pub const SYS_prlimit64 = 369;
340pub const SYS_name_to_handle_at = 370;
341pub const SYS_open_by_handle_at = 371;
342pub const SYS_clock_adjtime = 372;
343pub const SYS_syncfs = 373;
344pub const SYS_sendmmsg = 374;
345pub const SYS_setns = 375;
346pub const SYS_process_vm_readv = 376;
347pub const SYS_process_vm_writev = 377;
348pub const SYS_kcmp = 378;
349pub const SYS_finit_module = 379;
350pub const SYS_sched_setattr = 380;
351pub const SYS_sched_getattr = 381;
352pub const SYS_renameat2 = 382;
353pub const SYS_seccomp = 383;
354pub const SYS_getrandom = 384;
355pub const SYS_memfd_create = 385;
356pub const SYS_bpf = 386;
357pub const SYS_execveat = 387;
358pub const SYS_userfaultfd = 388;
359pub const SYS_membarrier = 389;
360pub const SYS_mlock2 = 390;
361pub const SYS_copy_file_range = 391;
362pub const SYS_preadv2 = 392;
363pub const SYS_pwritev2 = 393;
364pub const SYS_pkey_mprotect = 394;
365pub const SYS_pkey_alloc = 395;
366pub const SYS_pkey_free = 396;
367pub const SYS_statx = 397;
368pub const SYS_rseq = 398;
369pub const SYS_io_pgetevents = 399;
370pub const SYS_migrate_pages = 400;
371pub const SYS_kexec_file_load = 401;
372pub const SYS_clock_gettime64 = 403;
373pub const SYS_clock_settime64 = 404;
374pub const SYS_clock_adjtime64 = 405;
375pub const SYS_clock_getres_time64 = 406;
376pub const SYS_clock_nanosleep_time64 = 407;
377pub const SYS_timer_gettime64 = 408;
378pub const SYS_timer_settime64 = 409;
379pub const SYS_timerfd_gettime64 = 410;
380pub const SYS_timerfd_settime64 = 411;
381pub const SYS_utimensat_time64 = 412;
382pub const SYS_pselect6_time64 = 413;
383pub const SYS_ppoll_time64 = 414;
384pub const SYS_io_pgetevents_time64 = 416;
385pub const SYS_recvmmsg_time64 = 417;
386pub const SYS_mq_timedsend_time64 = 418;
387pub const SYS_mq_timedreceive_time64 = 419;
388pub const SYS_semtimedop_time64 = 420;
389pub const SYS_rt_sigtimedwait_time64 = 421;
390pub const SYS_futex_time64 = 422;
391pub const SYS_sched_rr_get_interval_time64 = 423;
392pub const SYS_pidfd_send_signal = 424;
393pub const SYS_io_uring_setup = 425;
394pub const SYS_io_uring_enter = 426;
395pub const SYS_io_uring_register = 427;
396pub const SYS_open_tree = 428;
397pub const SYS_move_mount = 429;
398pub const SYS_fsopen = 430;
399pub const SYS_fsconfig = 431;
400pub const SYS_fsmount = 432;
401pub const SYS_fspick = 433;
402pub const SYS_pidfd_open = 434;
403pub const SYS_clone3 = 435;
404
405pub const SYS_breakpoint = 0x0f0001;
406pub const SYS_cacheflush = 0x0f0002;
407pub const SYS_usr26 = 0x0f0003;
408pub const SYS_usr32 = 0x0f0004;
409pub const SYS_set_tls = 0x0f0005;
410pub const SYS_get_tls = 0x0f0006;
13pub const SYS = extern enum(usize) {
14 restart_syscall = 0,
15 exit = 1,
16 fork = 2,
17 read = 3,
18 write = 4,
19 open = 5,
20 close = 6,
21 creat = 8,
22 link = 9,
23 unlink = 10,
24 execve = 11,
25 chdir = 12,
26 mknod = 14,
27 chmod = 15,
28 lchown = 16,
29 lseek = 19,
30 getpid = 20,
31 mount = 21,
32 setuid = 23,
33 getuid = 24,
34 ptrace = 26,
35 pause = 29,
36 access = 33,
37 nice = 34,
38 sync = 36,
39 kill = 37,
40 rename = 38,
41 mkdir = 39,
42 rmdir = 40,
43 dup = 41,
44 pipe = 42,
45 times = 43,
46 brk = 45,
47 setgid = 46,
48 getgid = 47,
49 geteuid = 49,
50 getegid = 50,
51 acct = 51,
52 umount2 = 52,
53 ioctl = 54,
54 fcntl = 55,
55 setpgid = 57,
56 umask = 60,
57 chroot = 61,
58 ustat = 62,
59 dup2 = 63,
60 getppid = 64,
61 getpgrp = 65,
62 setsid = 66,
63 sigaction = 67,
64 setreuid = 70,
65 setregid = 71,
66 sigsuspend = 72,
67 sigpending = 73,
68 sethostname = 74,
69 setrlimit = 75,
70 getrusage = 77,
71 gettimeofday = 78,
72 settimeofday = 79,
73 getgroups = 80,
74 setgroups = 81,
75 symlink = 83,
76 readlink = 85,
77 uselib = 86,
78 swapon = 87,
79 reboot = 88,
80 munmap = 91,
81 truncate = 92,
82 ftruncate = 93,
83 fchmod = 94,
84 fchown = 95,
85 getpriority = 96,
86 setpriority = 97,
87 statfs = 99,
88 fstatfs = 100,
89 syslog = 103,
90 setitimer = 104,
91 getitimer = 105,
92 stat = 106,
93 lstat = 107,
94 fstat = 108,
95 vhangup = 111,
96 wait4 = 114,
97 swapoff = 115,
98 sysinfo = 116,
99 fsync = 118,
100 sigreturn = 119,
101 clone = 120,
102 setdomainname = 121,
103 uname = 122,
104 adjtimex = 124,
105 mprotect = 125,
106 sigprocmask = 126,
107 init_module = 128,
108 delete_module = 129,
109 quotactl = 131,
110 getpgid = 132,
111 fchdir = 133,
112 bdflush = 134,
113 sysfs = 135,
114 personality = 136,
115 setfsuid = 138,
116 setfsgid = 139,
117 _llseek = 140,
118 getdents = 141,
119 _newselect = 142,
120 flock = 143,
121 msync = 144,
122 readv = 145,
123 writev = 146,
124 getsid = 147,
125 fdatasync = 148,
126 _sysctl = 149,
127 mlock = 150,
128 munlock = 151,
129 mlockall = 152,
130 munlockall = 153,
131 sched_setparam = 154,
132 sched_getparam = 155,
133 sched_setscheduler = 156,
134 sched_getscheduler = 157,
135 sched_yield = 158,
136 sched_get_priority_max = 159,
137 sched_get_priority_min = 160,
138 sched_rr_get_interval = 161,
139 nanosleep = 162,
140 mremap = 163,
141 setresuid = 164,
142 getresuid = 165,
143 poll = 168,
144 nfsservctl = 169,
145 setresgid = 170,
146 getresgid = 171,
147 prctl = 172,
148 rt_sigreturn = 173,
149 rt_sigaction = 174,
150 rt_sigprocmask = 175,
151 rt_sigpending = 176,
152 rt_sigtimedwait = 177,
153 rt_sigqueueinfo = 178,
154 rt_sigsuspend = 179,
155 pread64 = 180,
156 pwrite64 = 181,
157 chown = 182,
158 getcwd = 183,
159 capget = 184,
160 capset = 185,
161 sigaltstack = 186,
162 sendfile = 187,
163 vfork = 190,
164 ugetrlimit = 191,
165 mmap2 = 192,
166 truncate64 = 193,
167 ftruncate64 = 194,
168 stat64 = 195,
169 lstat64 = 196,
170 fstat64 = 197,
171 lchown32 = 198,
172 getuid32 = 199,
173 getgid32 = 200,
174 geteuid32 = 201,
175 getegid32 = 202,
176 setreuid32 = 203,
177 setregid32 = 204,
178 getgroups32 = 205,
179 setgroups32 = 206,
180 fchown32 = 207,
181 setresuid32 = 208,
182 getresuid32 = 209,
183 setresgid32 = 210,
184 getresgid32 = 211,
185 chown32 = 212,
186 setuid32 = 213,
187 setgid32 = 214,
188 setfsuid32 = 215,
189 setfsgid32 = 216,
190 getdents64 = 217,
191 pivot_root = 218,
192 mincore = 219,
193 madvise = 220,
194 fcntl64 = 221,
195 gettid = 224,
196 readahead = 225,
197 setxattr = 226,
198 lsetxattr = 227,
199 fsetxattr = 228,
200 getxattr = 229,
201 lgetxattr = 230,
202 fgetxattr = 231,
203 listxattr = 232,
204 llistxattr = 233,
205 flistxattr = 234,
206 removexattr = 235,
207 lremovexattr = 236,
208 fremovexattr = 237,
209 tkill = 238,
210 sendfile64 = 239,
211 futex = 240,
212 sched_setaffinity = 241,
213 sched_getaffinity = 242,
214 io_setup = 243,
215 io_destroy = 244,
216 io_getevents = 245,
217 io_submit = 246,
218 io_cancel = 247,
219 exit_group = 248,
220 lookup_dcookie = 249,
221 epoll_create = 250,
222 epoll_ctl = 251,
223 epoll_wait = 252,
224 remap_file_pages = 253,
225 set_tid_address = 256,
226 timer_create = 257,
227 timer_settime = 258,
228 timer_gettime = 259,
229 timer_getoverrun = 260,
230 timer_delete = 261,
231 clock_settime = 262,
232 clock_gettime = 263,
233 clock_getres = 264,
234 clock_nanosleep = 265,
235 statfs64 = 266,
236 fstatfs64 = 267,
237 tgkill = 268,
238 utimes = 269,
239 fadvise64_64 = 270,
240 arm_fadvise64_64 = 270,
241 pciconfig_iobase = 271,
242 pciconfig_read = 272,
243 pciconfig_write = 273,
244 mq_open = 274,
245 mq_unlink = 275,
246 mq_timedsend = 276,
247 mq_timedreceive = 277,
248 mq_notify = 278,
249 mq_getsetattr = 279,
250 waitid = 280,
251 socket = 281,
252 bind = 282,
253 connect = 283,
254 listen = 284,
255 accept = 285,
256 getsockname = 286,
257 getpeername = 287,
258 socketpair = 288,
259 send = 289,
260 sendto = 290,
261 recv = 291,
262 recvfrom = 292,
263 shutdown = 293,
264 setsockopt = 294,
265 getsockopt = 295,
266 sendmsg = 296,
267 recvmsg = 297,
268 semop = 298,
269 semget = 299,
270 semctl = 300,
271 msgsnd = 301,
272 msgrcv = 302,
273 msgget = 303,
274 msgctl = 304,
275 shmat = 305,
276 shmdt = 306,
277 shmget = 307,
278 shmctl = 308,
279 add_key = 309,
280 request_key = 310,
281 keyctl = 311,
282 semtimedop = 312,
283 vserver = 313,
284 ioprio_set = 314,
285 ioprio_get = 315,
286 inotify_init = 316,
287 inotify_add_watch = 317,
288 inotify_rm_watch = 318,
289 mbind = 319,
290 get_mempolicy = 320,
291 set_mempolicy = 321,
292 openat = 322,
293 mkdirat = 323,
294 mknodat = 324,
295 fchownat = 325,
296 futimesat = 326,
297 fstatat64 = 327,
298 unlinkat = 328,
299 renameat = 329,
300 linkat = 330,
301 symlinkat = 331,
302 readlinkat = 332,
303 fchmodat = 333,
304 faccessat = 334,
305 pselect6 = 335,
306 ppoll = 336,
307 unshare = 337,
308 set_robust_list = 338,
309 get_robust_list = 339,
310 splice = 340,
311 sync_file_range2 = 341,
312 arm_sync_file_range = 341,
313 tee = 342,
314 vmsplice = 343,
315 move_pages = 344,
316 getcpu = 345,
317 epoll_pwait = 346,
318 kexec_load = 347,
319 utimensat = 348,
320 signalfd = 349,
321 timerfd_create = 350,
322 eventfd = 351,
323 fallocate = 352,
324 timerfd_settime = 353,
325 timerfd_gettime = 354,
326 signalfd4 = 355,
327 eventfd2 = 356,
328 epoll_create1 = 357,
329 dup3 = 358,
330 pipe2 = 359,
331 inotify_init1 = 360,
332 preadv = 361,
333 pwritev = 362,
334 rt_tgsigqueueinfo = 363,
335 perf_event_open = 364,
336 recvmmsg = 365,
337 accept4 = 366,
338 fanotify_init = 367,
339 fanotify_mark = 368,
340 prlimit64 = 369,
341 name_to_handle_at = 370,
342 open_by_handle_at = 371,
343 clock_adjtime = 372,
344 syncfs = 373,
345 sendmmsg = 374,
346 setns = 375,
347 process_vm_readv = 376,
348 process_vm_writev = 377,
349 kcmp = 378,
350 finit_module = 379,
351 sched_setattr = 380,
352 sched_getattr = 381,
353 renameat2 = 382,
354 seccomp = 383,
355 getrandom = 384,
356 memfd_create = 385,
357 bpf = 386,
358 execveat = 387,
359 userfaultfd = 388,
360 membarrier = 389,
361 mlock2 = 390,
362 copy_file_range = 391,
363 preadv2 = 392,
364 pwritev2 = 393,
365 pkey_mprotect = 394,
366 pkey_alloc = 395,
367 pkey_free = 396,
368 statx = 397,
369 rseq = 398,
370 io_pgetevents = 399,
371 migrate_pages = 400,
372 kexec_file_load = 401,
373 clock_gettime64 = 403,
374 clock_settime64 = 404,
375 clock_adjtime64 = 405,
376 clock_getres_time64 = 406,
377 clock_nanosleep_time64 = 407,
378 timer_gettime64 = 408,
379 timer_settime64 = 409,
380 timerfd_gettime64 = 410,
381 timerfd_settime64 = 411,
382 utimensat_time64 = 412,
383 pselect6_time64 = 413,
384 ppoll_time64 = 414,
385 io_pgetevents_time64 = 416,
386 recvmmsg_time64 = 417,
387 mq_timedsend_time64 = 418,
388 mq_timedreceive_time64 = 419,
389 semtimedop_time64 = 420,
390 rt_sigtimedwait_time64 = 421,
391 futex_time64 = 422,
392 sched_rr_get_interval_time64 = 423,
393 pidfd_send_signal = 424,
394 io_uring_setup = 425,
395 io_uring_enter = 426,
396 io_uring_register = 427,
397 open_tree = 428,
398 move_mount = 429,
399 fsopen = 430,
400 fsconfig = 431,
401 fsmount = 432,
402 fspick = 433,
403 pidfd_open = 434,
404 clone3 = 435,
405 openat2 = 437,
406 pidfd_getfd = 438,
407
408 breakpoint = 0x0f0001,
409 cacheflush = 0x0f0002,
410 usr26 = 0x0f0003,
411 usr32 = 0x0f0004,
412 set_tls = 0x0f0005,
413 get_tls = 0x0f0006,
414
415 _,
416};
411417
412418pub const MMAP2_UNIT = 4096;
413419
lib/std/os/bits/linux/arm64.zig+296-291
......@@ -11,298 +11,303 @@ const gid_t = linux.gid_t;
1111const pid_t = linux.pid_t;
1212const stack_t = linux.stack_t;
1313const sigset_t = linux.sigset_t;
14pub const SYS = extern enum(usize) {
15 io_setup = 0,
16 io_destroy = 1,
17 io_submit = 2,
18 io_cancel = 3,
19 io_getevents = 4,
20 setxattr = 5,
21 lsetxattr = 6,
22 fsetxattr = 7,
23 getxattr = 8,
24 lgetxattr = 9,
25 fgetxattr = 10,
26 listxattr = 11,
27 llistxattr = 12,
28 flistxattr = 13,
29 removexattr = 14,
30 lremovexattr = 15,
31 fremovexattr = 16,
32 getcwd = 17,
33 lookup_dcookie = 18,
34 eventfd2 = 19,
35 epoll_create1 = 20,
36 epoll_ctl = 21,
37 epoll_pwait = 22,
38 dup = 23,
39 dup3 = 24,
40 fcntl = 25,
41 inotify_init1 = 26,
42 inotify_add_watch = 27,
43 inotify_rm_watch = 28,
44 ioctl = 29,
45 ioprio_set = 30,
46 ioprio_get = 31,
47 flock = 32,
48 mknodat = 33,
49 mkdirat = 34,
50 unlinkat = 35,
51 symlinkat = 36,
52 linkat = 37,
53 renameat = 38,
54 umount2 = 39,
55 mount = 40,
56 pivot_root = 41,
57 nfsservctl = 42,
58 statfs = 43,
59 fstatfs = 44,
60 truncate = 45,
61 ftruncate = 46,
62 fallocate = 47,
63 faccessat = 48,
64 chdir = 49,
65 fchdir = 50,
66 chroot = 51,
67 fchmod = 52,
68 fchmodat = 53,
69 fchownat = 54,
70 fchown = 55,
71 openat = 56,
72 close = 57,
73 vhangup = 58,
74 pipe2 = 59,
75 quotactl = 60,
76 getdents64 = 61,
77 lseek = 62,
78 read = 63,
79 write = 64,
80 readv = 65,
81 writev = 66,
82 pread64 = 67,
83 pwrite64 = 68,
84 preadv = 69,
85 pwritev = 70,
86 sendfile = 71,
87 pselect6 = 72,
88 ppoll = 73,
89 signalfd4 = 74,
90 vmsplice = 75,
91 splice = 76,
92 tee = 77,
93 readlinkat = 78,
94 fstatat = 79,
95 fstat = 80,
96 sync = 81,
97 fsync = 82,
98 fdatasync = 83,
99 sync_file_range2 = 84,
100 sync_file_range = 84,
101 timerfd_create = 85,
102 timerfd_settime = 86,
103 timerfd_gettime = 87,
104 utimensat = 88,
105 acct = 89,
106 capget = 90,
107 capset = 91,
108 personality = 92,
109 exit = 93,
110 exit_group = 94,
111 waitid = 95,
112 set_tid_address = 96,
113 unshare = 97,
114 futex = 98,
115 set_robust_list = 99,
116 get_robust_list = 100,
117 nanosleep = 101,
118 getitimer = 102,
119 setitimer = 103,
120 kexec_load = 104,
121 init_module = 105,
122 delete_module = 106,
123 timer_create = 107,
124 timer_gettime = 108,
125 timer_getoverrun = 109,
126 timer_settime = 110,
127 timer_delete = 111,
128 clock_settime = 112,
129 clock_gettime = 113,
130 clock_getres = 114,
131 clock_nanosleep = 115,
132 syslog = 116,
133 ptrace = 117,
134 sched_setparam = 118,
135 sched_setscheduler = 119,
136 sched_getscheduler = 120,
137 sched_getparam = 121,
138 sched_setaffinity = 122,
139 sched_getaffinity = 123,
140 sched_yield = 124,
141 sched_get_priority_max = 125,
142 sched_get_priority_min = 126,
143 sched_rr_get_interval = 127,
144 restart_syscall = 128,
145 kill = 129,
146 tkill = 130,
147 tgkill = 131,
148 sigaltstack = 132,
149 rt_sigsuspend = 133,
150 rt_sigaction = 134,
151 rt_sigprocmask = 135,
152 rt_sigpending = 136,
153 rt_sigtimedwait = 137,
154 rt_sigqueueinfo = 138,
155 rt_sigreturn = 139,
156 setpriority = 140,
157 getpriority = 141,
158 reboot = 142,
159 setregid = 143,
160 setgid = 144,
161 setreuid = 145,
162 setuid = 146,
163 setresuid = 147,
164 getresuid = 148,
165 setresgid = 149,
166 getresgid = 150,
167 setfsuid = 151,
168 setfsgid = 152,
169 times = 153,
170 setpgid = 154,
171 getpgid = 155,
172 getsid = 156,
173 setsid = 157,
174 getgroups = 158,
175 setgroups = 159,
176 uname = 160,
177 sethostname = 161,
178 setdomainname = 162,
179 getrlimit = 163,
180 setrlimit = 164,
181 getrusage = 165,
182 umask = 166,
183 prctl = 167,
184 getcpu = 168,
185 gettimeofday = 169,
186 settimeofday = 170,
187 adjtimex = 171,
188 getpid = 172,
189 getppid = 173,
190 getuid = 174,
191 geteuid = 175,
192 getgid = 176,
193 getegid = 177,
194 gettid = 178,
195 sysinfo = 179,
196 mq_open = 180,
197 mq_unlink = 181,
198 mq_timedsend = 182,
199 mq_timedreceive = 183,
200 mq_notify = 184,
201 mq_getsetattr = 185,
202 msgget = 186,
203 msgctl = 187,
204 msgrcv = 188,
205 msgsnd = 189,
206 semget = 190,
207 semctl = 191,
208 semtimedop = 192,
209 semop = 193,
210 shmget = 194,
211 shmctl = 195,
212 shmat = 196,
213 shmdt = 197,
214 socket = 198,
215 socketpair = 199,
216 bind = 200,
217 listen = 201,
218 accept = 202,
219 connect = 203,
220 getsockname = 204,
221 getpeername = 205,
222 sendto = 206,
223 recvfrom = 207,
224 setsockopt = 208,
225 getsockopt = 209,
226 shutdown = 210,
227 sendmsg = 211,
228 recvmsg = 212,
229 readahead = 213,
230 brk = 214,
231 munmap = 215,
232 mremap = 216,
233 add_key = 217,
234 request_key = 218,
235 keyctl = 219,
236 clone = 220,
237 execve = 221,
238 mmap = 222,
239 fadvise64 = 223,
240 swapon = 224,
241 swapoff = 225,
242 mprotect = 226,
243 msync = 227,
244 mlock = 228,
245 munlock = 229,
246 mlockall = 230,
247 munlockall = 231,
248 mincore = 232,
249 madvise = 233,
250 remap_file_pages = 234,
251 mbind = 235,
252 get_mempolicy = 236,
253 set_mempolicy = 237,
254 migrate_pages = 238,
255 move_pages = 239,
256 rt_tgsigqueueinfo = 240,
257 perf_event_open = 241,
258 accept4 = 242,
259 recvmmsg = 243,
260 arch_specific_syscall = 244,
261 wait4 = 260,
262 prlimit64 = 261,
263 fanotify_init = 262,
264 fanotify_mark = 263,
265 clock_adjtime = 266,
266 syncfs = 267,
267 setns = 268,
268 sendmmsg = 269,
269 process_vm_readv = 270,
270 process_vm_writev = 271,
271 kcmp = 272,
272 finit_module = 273,
273 sched_setattr = 274,
274 sched_getattr = 275,
275 renameat2 = 276,
276 seccomp = 277,
277 getrandom = 278,
278 memfd_create = 279,
279 bpf = 280,
280 execveat = 281,
281 userfaultfd = 282,
282 membarrier = 283,
283 mlock2 = 284,
284 copy_file_range = 285,
285 preadv2 = 286,
286 pwritev2 = 287,
287 pkey_mprotect = 288,
288 pkey_alloc = 289,
289 pkey_free = 290,
290 statx = 291,
291 io_pgetevents = 292,
292 rseq = 293,
293 kexec_file_load = 294,
294 pidfd_send_signal = 424,
295 io_uring_setup = 425,
296 io_uring_enter = 426,
297 io_uring_register = 427,
298 open_tree = 428,
299 move_mount = 429,
300 fsopen = 430,
301 fsconfig = 431,
302 fsmount = 432,
303 fspick = 433,
304 pidfd_open = 434,
305 clone3 = 435,
306 openat2 = 437,
307 pidfd_getfd = 438,
14308
15pub const SYS_io_setup = 0;
16pub const SYS_io_destroy = 1;
17pub const SYS_io_submit = 2;
18pub const SYS_io_cancel = 3;
19pub const SYS_io_getevents = 4;
20pub const SYS_setxattr = 5;
21pub const SYS_lsetxattr = 6;
22pub const SYS_fsetxattr = 7;
23pub const SYS_getxattr = 8;
24pub const SYS_lgetxattr = 9;
25pub const SYS_fgetxattr = 10;
26pub const SYS_listxattr = 11;
27pub const SYS_llistxattr = 12;
28pub const SYS_flistxattr = 13;
29pub const SYS_removexattr = 14;
30pub const SYS_lremovexattr = 15;
31pub const SYS_fremovexattr = 16;
32pub const SYS_getcwd = 17;
33pub const SYS_lookup_dcookie = 18;
34pub const SYS_eventfd2 = 19;
35pub const SYS_epoll_create1 = 20;
36pub const SYS_epoll_ctl = 21;
37pub const SYS_epoll_pwait = 22;
38pub const SYS_dup = 23;
39pub const SYS_dup3 = 24;
40pub const SYS_fcntl = 25;
41pub const SYS_inotify_init1 = 26;
42pub const SYS_inotify_add_watch = 27;
43pub const SYS_inotify_rm_watch = 28;
44pub const SYS_ioctl = 29;
45pub const SYS_ioprio_set = 30;
46pub const SYS_ioprio_get = 31;
47pub const SYS_flock = 32;
48pub const SYS_mknodat = 33;
49pub const SYS_mkdirat = 34;
50pub const SYS_unlinkat = 35;
51pub const SYS_symlinkat = 36;
52pub const SYS_linkat = 37;
53pub const SYS_renameat = 38;
54pub const SYS_umount2 = 39;
55pub const SYS_mount = 40;
56pub const SYS_pivot_root = 41;
57pub const SYS_nfsservctl = 42;
58pub const SYS_statfs = 43;
59pub const SYS_fstatfs = 44;
60pub const SYS_truncate = 45;
61pub const SYS_ftruncate = 46;
62pub const SYS_fallocate = 47;
63pub const SYS_faccessat = 48;
64pub const SYS_chdir = 49;
65pub const SYS_fchdir = 50;
66pub const SYS_chroot = 51;
67pub const SYS_fchmod = 52;
68pub const SYS_fchmodat = 53;
69pub const SYS_fchownat = 54;
70pub const SYS_fchown = 55;
71pub const SYS_openat = 56;
72pub const SYS_close = 57;
73pub const SYS_vhangup = 58;
74pub const SYS_pipe2 = 59;
75pub const SYS_quotactl = 60;
76pub const SYS_getdents64 = 61;
77pub const SYS_lseek = 62;
78pub const SYS_read = 63;
79pub const SYS_write = 64;
80pub const SYS_readv = 65;
81pub const SYS_writev = 66;
82pub const SYS_pread64 = 67;
83pub const SYS_pwrite64 = 68;
84pub const SYS_preadv = 69;
85pub const SYS_pwritev = 70;
86pub const SYS_sendfile = 71;
87pub const SYS_pselect6 = 72;
88pub const SYS_ppoll = 73;
89pub const SYS_signalfd4 = 74;
90pub const SYS_vmsplice = 75;
91pub const SYS_splice = 76;
92pub const SYS_tee = 77;
93pub const SYS_readlinkat = 78;
94pub const SYS_fstatat = 79;
95pub const SYS_fstat = 80;
96pub const SYS_sync = 81;
97pub const SYS_fsync = 82;
98pub const SYS_fdatasync = 83;
99pub const SYS_sync_file_range2 = 84;
100pub const SYS_sync_file_range = 84;
101pub const SYS_timerfd_create = 85;
102pub const SYS_timerfd_settime = 86;
103pub const SYS_timerfd_gettime = 87;
104pub const SYS_utimensat = 88;
105pub const SYS_acct = 89;
106pub const SYS_capget = 90;
107pub const SYS_capset = 91;
108pub const SYS_personality = 92;
109pub const SYS_exit = 93;
110pub const SYS_exit_group = 94;
111pub const SYS_waitid = 95;
112pub const SYS_set_tid_address = 96;
113pub const SYS_unshare = 97;
114pub const SYS_futex = 98;
115pub const SYS_set_robust_list = 99;
116pub const SYS_get_robust_list = 100;
117pub const SYS_nanosleep = 101;
118pub const SYS_getitimer = 102;
119pub const SYS_setitimer = 103;
120pub const SYS_kexec_load = 104;
121pub const SYS_init_module = 105;
122pub const SYS_delete_module = 106;
123pub const SYS_timer_create = 107;
124pub const SYS_timer_gettime = 108;
125pub const SYS_timer_getoverrun = 109;
126pub const SYS_timer_settime = 110;
127pub const SYS_timer_delete = 111;
128pub const SYS_clock_settime = 112;
129pub const SYS_clock_gettime = 113;
130pub const SYS_clock_getres = 114;
131pub const SYS_clock_nanosleep = 115;
132pub const SYS_syslog = 116;
133pub const SYS_ptrace = 117;
134pub const SYS_sched_setparam = 118;
135pub const SYS_sched_setscheduler = 119;
136pub const SYS_sched_getscheduler = 120;
137pub const SYS_sched_getparam = 121;
138pub const SYS_sched_setaffinity = 122;
139pub const SYS_sched_getaffinity = 123;
140pub const SYS_sched_yield = 124;
141pub const SYS_sched_get_priority_max = 125;
142pub const SYS_sched_get_priority_min = 126;
143pub const SYS_sched_rr_get_interval = 127;
144pub const SYS_restart_syscall = 128;
145pub const SYS_kill = 129;
146pub const SYS_tkill = 130;
147pub const SYS_tgkill = 131;
148pub const SYS_sigaltstack = 132;
149pub const SYS_rt_sigsuspend = 133;
150pub const SYS_rt_sigaction = 134;
151pub const SYS_rt_sigprocmask = 135;
152pub const SYS_rt_sigpending = 136;
153pub const SYS_rt_sigtimedwait = 137;
154pub const SYS_rt_sigqueueinfo = 138;
155pub const SYS_rt_sigreturn = 139;
156pub const SYS_setpriority = 140;
157pub const SYS_getpriority = 141;
158pub const SYS_reboot = 142;
159pub const SYS_setregid = 143;
160pub const SYS_setgid = 144;
161pub const SYS_setreuid = 145;
162pub const SYS_setuid = 146;
163pub const SYS_setresuid = 147;
164pub const SYS_getresuid = 148;
165pub const SYS_setresgid = 149;
166pub const SYS_getresgid = 150;
167pub const SYS_setfsuid = 151;
168pub const SYS_setfsgid = 152;
169pub const SYS_times = 153;
170pub const SYS_setpgid = 154;
171pub const SYS_getpgid = 155;
172pub const SYS_getsid = 156;
173pub const SYS_setsid = 157;
174pub const SYS_getgroups = 158;
175pub const SYS_setgroups = 159;
176pub const SYS_uname = 160;
177pub const SYS_sethostname = 161;
178pub const SYS_setdomainname = 162;
179pub const SYS_getrlimit = 163;
180pub const SYS_setrlimit = 164;
181pub const SYS_getrusage = 165;
182pub const SYS_umask = 166;
183pub const SYS_prctl = 167;
184pub const SYS_getcpu = 168;
185pub const SYS_gettimeofday = 169;
186pub const SYS_settimeofday = 170;
187pub const SYS_adjtimex = 171;
188pub const SYS_getpid = 172;
189pub const SYS_getppid = 173;
190pub const SYS_getuid = 174;
191pub const SYS_geteuid = 175;
192pub const SYS_getgid = 176;
193pub const SYS_getegid = 177;
194pub const SYS_gettid = 178;
195pub const SYS_sysinfo = 179;
196pub const SYS_mq_open = 180;
197pub const SYS_mq_unlink = 181;
198pub const SYS_mq_timedsend = 182;
199pub const SYS_mq_timedreceive = 183;
200pub const SYS_mq_notify = 184;
201pub const SYS_mq_getsetattr = 185;
202pub const SYS_msgget = 186;
203pub const SYS_msgctl = 187;
204pub const SYS_msgrcv = 188;
205pub const SYS_msgsnd = 189;
206pub const SYS_semget = 190;
207pub const SYS_semctl = 191;
208pub const SYS_semtimedop = 192;
209pub const SYS_semop = 193;
210pub const SYS_shmget = 194;
211pub const SYS_shmctl = 195;
212pub const SYS_shmat = 196;
213pub const SYS_shmdt = 197;
214pub const SYS_socket = 198;
215pub const SYS_socketpair = 199;
216pub const SYS_bind = 200;
217pub const SYS_listen = 201;
218pub const SYS_accept = 202;
219pub const SYS_connect = 203;
220pub const SYS_getsockname = 204;
221pub const SYS_getpeername = 205;
222pub const SYS_sendto = 206;
223pub const SYS_recvfrom = 207;
224pub const SYS_setsockopt = 208;
225pub const SYS_getsockopt = 209;
226pub const SYS_shutdown = 210;
227pub const SYS_sendmsg = 211;
228pub const SYS_recvmsg = 212;
229pub const SYS_readahead = 213;
230pub const SYS_brk = 214;
231pub const SYS_munmap = 215;
232pub const SYS_mremap = 216;
233pub const SYS_add_key = 217;
234pub const SYS_request_key = 218;
235pub const SYS_keyctl = 219;
236pub const SYS_clone = 220;
237pub const SYS_execve = 221;
238pub const SYS_mmap = 222;
239pub const SYS_fadvise64 = 223;
240pub const SYS_swapon = 224;
241pub const SYS_swapoff = 225;
242pub const SYS_mprotect = 226;
243pub const SYS_msync = 227;
244pub const SYS_mlock = 228;
245pub const SYS_munlock = 229;
246pub const SYS_mlockall = 230;
247pub const SYS_munlockall = 231;
248pub const SYS_mincore = 232;
249pub const SYS_madvise = 233;
250pub const SYS_remap_file_pages = 234;
251pub const SYS_mbind = 235;
252pub const SYS_get_mempolicy = 236;
253pub const SYS_set_mempolicy = 237;
254pub const SYS_migrate_pages = 238;
255pub const SYS_move_pages = 239;
256pub const SYS_rt_tgsigqueueinfo = 240;
257pub const SYS_perf_event_open = 241;
258pub const SYS_accept4 = 242;
259pub const SYS_recvmmsg = 243;
260pub const SYS_arch_specific_syscall = 244;
261pub const SYS_wait4 = 260;
262pub const SYS_prlimit64 = 261;
263pub const SYS_fanotify_init = 262;
264pub const SYS_fanotify_mark = 263;
265pub const SYS_clock_adjtime = 266;
266pub const SYS_syncfs = 267;
267pub const SYS_setns = 268;
268pub const SYS_sendmmsg = 269;
269pub const SYS_process_vm_readv = 270;
270pub const SYS_process_vm_writev = 271;
271pub const SYS_kcmp = 272;
272pub const SYS_finit_module = 273;
273pub const SYS_sched_setattr = 274;
274pub const SYS_sched_getattr = 275;
275pub const SYS_renameat2 = 276;
276pub const SYS_seccomp = 277;
277pub const SYS_getrandom = 278;
278pub const SYS_memfd_create = 279;
279pub const SYS_bpf = 280;
280pub const SYS_execveat = 281;
281pub const SYS_userfaultfd = 282;
282pub const SYS_membarrier = 283;
283pub const SYS_mlock2 = 284;
284pub const SYS_copy_file_range = 285;
285pub const SYS_preadv2 = 286;
286pub const SYS_pwritev2 = 287;
287pub const SYS_pkey_mprotect = 288;
288pub const SYS_pkey_alloc = 289;
289pub const SYS_pkey_free = 290;
290pub const SYS_statx = 291;
291pub const SYS_io_pgetevents = 292;
292pub const SYS_rseq = 293;
293pub const SYS_kexec_file_load = 294;
294pub const SYS_pidfd_send_signal = 424;
295pub const SYS_io_uring_setup = 425;
296pub const SYS_io_uring_enter = 426;
297pub const SYS_io_uring_register = 427;
298pub const SYS_open_tree = 428;
299pub const SYS_move_mount = 429;
300pub const SYS_fsopen = 430;
301pub const SYS_fsconfig = 431;
302pub const SYS_fsmount = 432;
303pub const SYS_fspick = 433;
304pub const SYS_pidfd_open = 434;
305pub const SYS_clone3 = 435;
309 _,
310};
306311
307312pub const O_CREAT = 0o100;
308313pub const O_EXCL = 0o200;
lib/std/os/bits/linux/errno-generic.zig+27
......@@ -368,6 +368,33 @@ pub const ENOMEDIUM = 123;
368368/// Wrong medium type
369369pub const EMEDIUMTYPE = 124;
370370
371/// Operation canceled
372pub const ECANCELED = 125;
373
374/// Required key not available
375pub const ENOKEY = 126;
376
377/// Key has expired
378pub const EKEYEXPIRED = 127;
379
380/// Key has been revoked
381pub const EKEYREVOKED = 128;
382
383/// Key was rejected by service
384pub const EKEYREJECTED = 129;
385
386// for robust mutexes
387/// Owner died
388pub const EOWNERDEAD = 130;
389/// State not recoverable
390pub const ENOTRECOVERABLE = 131;
391
392/// Operation not possible due to RF-kill
393pub const ERFKILL = 132;
394
395/// Memory page has hardware error
396pub const EHWPOISON = 133;
397
371398// nameserver query return codes
372399
373400/// DNS server returned answer with no data
lib/std/os/bits/linux/i386.zig+429-423
......@@ -12,429 +12,435 @@ const pid_t = linux.pid_t;
1212const stack_t = linux.stack_t;
1313const sigset_t = linux.sigset_t;
1414
15pub const SYS_restart_syscall = 0;
16pub const SYS_exit = 1;
17pub const SYS_fork = 2;
18pub const SYS_read = 3;
19pub const SYS_write = 4;
20pub const SYS_open = 5;
21pub const SYS_close = 6;
22pub const SYS_waitpid = 7;
23pub const SYS_creat = 8;
24pub const SYS_link = 9;
25pub const SYS_unlink = 10;
26pub const SYS_execve = 11;
27pub const SYS_chdir = 12;
28pub const SYS_time = 13;
29pub const SYS_mknod = 14;
30pub const SYS_chmod = 15;
31pub const SYS_lchown = 16;
32pub const SYS_break = 17;
33pub const SYS_oldstat = 18;
34pub const SYS_lseek = 19;
35pub const SYS_getpid = 20;
36pub const SYS_mount = 21;
37pub const SYS_umount = 22;
38pub const SYS_setuid = 23;
39pub const SYS_getuid = 24;
40pub const SYS_stime = 25;
41pub const SYS_ptrace = 26;
42pub const SYS_alarm = 27;
43pub const SYS_oldfstat = 28;
44pub const SYS_pause = 29;
45pub const SYS_utime = 30;
46pub const SYS_stty = 31;
47pub const SYS_gtty = 32;
48pub const SYS_access = 33;
49pub const SYS_nice = 34;
50pub const SYS_ftime = 35;
51pub const SYS_sync = 36;
52pub const SYS_kill = 37;
53pub const SYS_rename = 38;
54pub const SYS_mkdir = 39;
55pub const SYS_rmdir = 40;
56pub const SYS_dup = 41;
57pub const SYS_pipe = 42;
58pub const SYS_times = 43;
59pub const SYS_prof = 44;
60pub const SYS_brk = 45;
61pub const SYS_setgid = 46;
62pub const SYS_getgid = 47;
63pub const SYS_signal = 48;
64pub const SYS_geteuid = 49;
65pub const SYS_getegid = 50;
66pub const SYS_acct = 51;
67pub const SYS_umount2 = 52;
68pub const SYS_lock = 53;
69pub const SYS_ioctl = 54;
70pub const SYS_fcntl = 55;
71pub const SYS_mpx = 56;
72pub const SYS_setpgid = 57;
73pub const SYS_ulimit = 58;
74pub const SYS_oldolduname = 59;
75pub const SYS_umask = 60;
76pub const SYS_chroot = 61;
77pub const SYS_ustat = 62;
78pub const SYS_dup2 = 63;
79pub const SYS_getppid = 64;
80pub const SYS_getpgrp = 65;
81pub const SYS_setsid = 66;
82pub const SYS_sigaction = 67;
83pub const SYS_sgetmask = 68;
84pub const SYS_ssetmask = 69;
85pub const SYS_setreuid = 70;
86pub const SYS_setregid = 71;
87pub const SYS_sigsuspend = 72;
88pub const SYS_sigpending = 73;
89pub const SYS_sethostname = 74;
90pub const SYS_setrlimit = 75;
91pub const SYS_getrlimit = 76;
92pub const SYS_getrusage = 77;
93pub const SYS_gettimeofday = 78;
94pub const SYS_settimeofday = 79;
95pub const SYS_getgroups = 80;
96pub const SYS_setgroups = 81;
97pub const SYS_select = 82;
98pub const SYS_symlink = 83;
99pub const SYS_oldlstat = 84;
100pub const SYS_readlink = 85;
101pub const SYS_uselib = 86;
102pub const SYS_swapon = 87;
103pub const SYS_reboot = 88;
104pub const SYS_readdir = 89;
105pub const SYS_mmap = 90;
106pub const SYS_munmap = 91;
107pub const SYS_truncate = 92;
108pub const SYS_ftruncate = 93;
109pub const SYS_fchmod = 94;
110pub const SYS_fchown = 95;
111pub const SYS_getpriority = 96;
112pub const SYS_setpriority = 97;
113pub const SYS_profil = 98;
114pub const SYS_statfs = 99;
115pub const SYS_fstatfs = 100;
116pub const SYS_ioperm = 101;
117pub const SYS_socketcall = 102;
118pub const SYS_syslog = 103;
119pub const SYS_setitimer = 104;
120pub const SYS_getitimer = 105;
121pub const SYS_stat = 106;
122pub const SYS_lstat = 107;
123pub const SYS_fstat = 108;
124pub const SYS_olduname = 109;
125pub const SYS_iopl = 110;
126pub const SYS_vhangup = 111;
127pub const SYS_idle = 112;
128pub const SYS_vm86old = 113;
129pub const SYS_wait4 = 114;
130pub const SYS_swapoff = 115;
131pub const SYS_sysinfo = 116;
132pub const SYS_ipc = 117;
133pub const SYS_fsync = 118;
134pub const SYS_sigreturn = 119;
135pub const SYS_clone = 120;
136pub const SYS_setdomainname = 121;
137pub const SYS_uname = 122;
138pub const SYS_modify_ldt = 123;
139pub const SYS_adjtimex = 124;
140pub const SYS_mprotect = 125;
141pub const SYS_sigprocmask = 126;
142pub const SYS_create_module = 127;
143pub const SYS_init_module = 128;
144pub const SYS_delete_module = 129;
145pub const SYS_get_kernel_syms = 130;
146pub const SYS_quotactl = 131;
147pub const SYS_getpgid = 132;
148pub const SYS_fchdir = 133;
149pub const SYS_bdflush = 134;
150pub const SYS_sysfs = 135;
151pub const SYS_personality = 136;
152pub const SYS_afs_syscall = 137;
153pub const SYS_setfsuid = 138;
154pub const SYS_setfsgid = 139;
155pub const SYS__llseek = 140;
156pub const SYS_getdents = 141;
157pub const SYS__newselect = 142;
158pub const SYS_flock = 143;
159pub const SYS_msync = 144;
160pub const SYS_readv = 145;
161pub const SYS_writev = 146;
162pub const SYS_getsid = 147;
163pub const SYS_fdatasync = 148;
164pub const SYS__sysctl = 149;
165pub const SYS_mlock = 150;
166pub const SYS_munlock = 151;
167pub const SYS_mlockall = 152;
168pub const SYS_munlockall = 153;
169pub const SYS_sched_setparam = 154;
170pub const SYS_sched_getparam = 155;
171pub const SYS_sched_setscheduler = 156;
172pub const SYS_sched_getscheduler = 157;
173pub const SYS_sched_yield = 158;
174pub const SYS_sched_get_priority_max = 159;
175pub const SYS_sched_get_priority_min = 160;
176pub const SYS_sched_rr_get_interval = 161;
177pub const SYS_nanosleep = 162;
178pub const SYS_mremap = 163;
179pub const SYS_setresuid = 164;
180pub const SYS_getresuid = 165;
181pub const SYS_vm86 = 166;
182pub const SYS_query_module = 167;
183pub const SYS_poll = 168;
184pub const SYS_nfsservctl = 169;
185pub const SYS_setresgid = 170;
186pub const SYS_getresgid = 171;
187pub const SYS_prctl = 172;
188pub const SYS_rt_sigreturn = 173;
189pub const SYS_rt_sigaction = 174;
190pub const SYS_rt_sigprocmask = 175;
191pub const SYS_rt_sigpending = 176;
192pub const SYS_rt_sigtimedwait = 177;
193pub const SYS_rt_sigqueueinfo = 178;
194pub const SYS_rt_sigsuspend = 179;
195pub const SYS_pread64 = 180;
196pub const SYS_pwrite64 = 181;
197pub const SYS_chown = 182;
198pub const SYS_getcwd = 183;
199pub const SYS_capget = 184;
200pub const SYS_capset = 185;
201pub const SYS_sigaltstack = 186;
202pub const SYS_sendfile = 187;
203pub const SYS_getpmsg = 188;
204pub const SYS_putpmsg = 189;
205pub const SYS_vfork = 190;
206pub const SYS_ugetrlimit = 191;
207pub const SYS_mmap2 = 192;
208pub const SYS_truncate64 = 193;
209pub const SYS_ftruncate64 = 194;
210pub const SYS_stat64 = 195;
211pub const SYS_lstat64 = 196;
212pub const SYS_fstat64 = 197;
213pub const SYS_lchown32 = 198;
214pub const SYS_getuid32 = 199;
215pub const SYS_getgid32 = 200;
216pub const SYS_geteuid32 = 201;
217pub const SYS_getegid32 = 202;
218pub const SYS_setreuid32 = 203;
219pub const SYS_setregid32 = 204;
220pub const SYS_getgroups32 = 205;
221pub const SYS_setgroups32 = 206;
222pub const SYS_fchown32 = 207;
223pub const SYS_setresuid32 = 208;
224pub const SYS_getresuid32 = 209;
225pub const SYS_setresgid32 = 210;
226pub const SYS_getresgid32 = 211;
227pub const SYS_chown32 = 212;
228pub const SYS_setuid32 = 213;
229pub const SYS_setgid32 = 214;
230pub const SYS_setfsuid32 = 215;
231pub const SYS_setfsgid32 = 216;
232pub const SYS_pivot_root = 217;
233pub const SYS_mincore = 218;
234pub const SYS_madvise = 219;
235pub const SYS_getdents64 = 220;
236pub const SYS_fcntl64 = 221;
237pub const SYS_gettid = 224;
238pub const SYS_readahead = 225;
239pub const SYS_setxattr = 226;
240pub const SYS_lsetxattr = 227;
241pub const SYS_fsetxattr = 228;
242pub const SYS_getxattr = 229;
243pub const SYS_lgetxattr = 230;
244pub const SYS_fgetxattr = 231;
245pub const SYS_listxattr = 232;
246pub const SYS_llistxattr = 233;
247pub const SYS_flistxattr = 234;
248pub const SYS_removexattr = 235;
249pub const SYS_lremovexattr = 236;
250pub const SYS_fremovexattr = 237;
251pub const SYS_tkill = 238;
252pub const SYS_sendfile64 = 239;
253pub const SYS_futex = 240;
254pub const SYS_sched_setaffinity = 241;
255pub const SYS_sched_getaffinity = 242;
256pub const SYS_set_thread_area = 243;
257pub const SYS_get_thread_area = 244;
258pub const SYS_io_setup = 245;
259pub const SYS_io_destroy = 246;
260pub const SYS_io_getevents = 247;
261pub const SYS_io_submit = 248;
262pub const SYS_io_cancel = 249;
263pub const SYS_fadvise64 = 250;
264pub const SYS_exit_group = 252;
265pub const SYS_lookup_dcookie = 253;
266pub const SYS_epoll_create = 254;
267pub const SYS_epoll_ctl = 255;
268pub const SYS_epoll_wait = 256;
269pub const SYS_remap_file_pages = 257;
270pub const SYS_set_tid_address = 258;
271pub const SYS_timer_create = 259;
272pub const SYS_timer_settime = SYS_timer_create + 1;
273pub const SYS_timer_gettime = SYS_timer_create + 2;
274pub const SYS_timer_getoverrun = SYS_timer_create + 3;
275pub const SYS_timer_delete = SYS_timer_create + 4;
276pub const SYS_clock_settime = SYS_timer_create + 5;
277pub const SYS_clock_gettime = SYS_timer_create + 6;
278pub const SYS_clock_getres = SYS_timer_create + 7;
279pub const SYS_clock_nanosleep = SYS_timer_create + 8;
280pub const SYS_statfs64 = 268;
281pub const SYS_fstatfs64 = 269;
282pub const SYS_tgkill = 270;
283pub const SYS_utimes = 271;
284pub const SYS_fadvise64_64 = 272;
285pub const SYS_vserver = 273;
286pub const SYS_mbind = 274;
287pub const SYS_get_mempolicy = 275;
288pub const SYS_set_mempolicy = 276;
289pub const SYS_mq_open = 277;
290pub const SYS_mq_unlink = SYS_mq_open + 1;
291pub const SYS_mq_timedsend = SYS_mq_open + 2;
292pub const SYS_mq_timedreceive = SYS_mq_open + 3;
293pub const SYS_mq_notify = SYS_mq_open + 4;
294pub const SYS_mq_getsetattr = SYS_mq_open + 5;
295pub const SYS_kexec_load = 283;
296pub const SYS_waitid = 284;
297pub const SYS_add_key = 286;
298pub const SYS_request_key = 287;
299pub const SYS_keyctl = 288;
300pub const SYS_ioprio_set = 289;
301pub const SYS_ioprio_get = 290;
302pub const SYS_inotify_init = 291;
303pub const SYS_inotify_add_watch = 292;
304pub const SYS_inotify_rm_watch = 293;
305pub const SYS_migrate_pages = 294;
306pub const SYS_openat = 295;
307pub const SYS_mkdirat = 296;
308pub const SYS_mknodat = 297;
309pub const SYS_fchownat = 298;
310pub const SYS_futimesat = 299;
311pub const SYS_fstatat64 = 300;
312pub const SYS_unlinkat = 301;
313pub const SYS_renameat = 302;
314pub const SYS_linkat = 303;
315pub const SYS_symlinkat = 304;
316pub const SYS_readlinkat = 305;
317pub const SYS_fchmodat = 306;
318pub const SYS_faccessat = 307;
319pub const SYS_pselect6 = 308;
320pub const SYS_ppoll = 309;
321pub const SYS_unshare = 310;
322pub const SYS_set_robust_list = 311;
323pub const SYS_get_robust_list = 312;
324pub const SYS_splice = 313;
325pub const SYS_sync_file_range = 314;
326pub const SYS_tee = 315;
327pub const SYS_vmsplice = 316;
328pub const SYS_move_pages = 317;
329pub const SYS_getcpu = 318;
330pub const SYS_epoll_pwait = 319;
331pub const SYS_utimensat = 320;
332pub const SYS_signalfd = 321;
333pub const SYS_timerfd_create = 322;
334pub const SYS_eventfd = 323;
335pub const SYS_fallocate = 324;
336pub const SYS_timerfd_settime = 325;
337pub const SYS_timerfd_gettime = 326;
338pub const SYS_signalfd4 = 327;
339pub const SYS_eventfd2 = 328;
340pub const SYS_epoll_create1 = 329;
341pub const SYS_dup3 = 330;
342pub const SYS_pipe2 = 331;
343pub const SYS_inotify_init1 = 332;
344pub const SYS_preadv = 333;
345pub const SYS_pwritev = 334;
346pub const SYS_rt_tgsigqueueinfo = 335;
347pub const SYS_perf_event_open = 336;
348pub const SYS_recvmmsg = 337;
349pub const SYS_fanotify_init = 338;
350pub const SYS_fanotify_mark = 339;
351pub const SYS_prlimit64 = 340;
352pub const SYS_name_to_handle_at = 341;
353pub const SYS_open_by_handle_at = 342;
354pub const SYS_clock_adjtime = 343;
355pub const SYS_syncfs = 344;
356pub const SYS_sendmmsg = 345;
357pub const SYS_setns = 346;
358pub const SYS_process_vm_readv = 347;
359pub const SYS_process_vm_writev = 348;
360pub const SYS_kcmp = 349;
361pub const SYS_finit_module = 350;
362pub const SYS_sched_setattr = 351;
363pub const SYS_sched_getattr = 352;
364pub const SYS_renameat2 = 353;
365pub const SYS_seccomp = 354;
366pub const SYS_getrandom = 355;
367pub const SYS_memfd_create = 356;
368pub const SYS_bpf = 357;
369pub const SYS_execveat = 358;
370pub const SYS_socket = 359;
371pub const SYS_socketpair = 360;
372pub const SYS_bind = 361;
373pub const SYS_connect = 362;
374pub const SYS_listen = 363;
375pub const SYS_accept4 = 364;
376pub const SYS_getsockopt = 365;
377pub const SYS_setsockopt = 366;
378pub const SYS_getsockname = 367;
379pub const SYS_getpeername = 368;
380pub const SYS_sendto = 369;
381pub const SYS_sendmsg = 370;
382pub const SYS_recvfrom = 371;
383pub const SYS_recvmsg = 372;
384pub const SYS_shutdown = 373;
385pub const SYS_userfaultfd = 374;
386pub const SYS_membarrier = 375;
387pub const SYS_mlock2 = 376;
388pub const SYS_copy_file_range = 377;
389pub const SYS_preadv2 = 378;
390pub const SYS_pwritev2 = 379;
391pub const SYS_pkey_mprotect = 380;
392pub const SYS_pkey_alloc = 381;
393pub const SYS_pkey_free = 382;
394pub const SYS_statx = 383;
395pub const SYS_arch_prctl = 384;
396pub const SYS_io_pgetevents = 385;
397pub const SYS_rseq = 386;
398pub const SYS_semget = 393;
399pub const SYS_semctl = 394;
400pub const SYS_shmget = 395;
401pub const SYS_shmctl = 396;
402pub const SYS_shmat = 397;
403pub const SYS_shmdt = 398;
404pub const SYS_msgget = 399;
405pub const SYS_msgsnd = 400;
406pub const SYS_msgrcv = 401;
407pub const SYS_msgctl = 402;
408pub const SYS_clock_gettime64 = 403;
409pub const SYS_clock_settime64 = 404;
410pub const SYS_clock_adjtime64 = 405;
411pub const SYS_clock_getres_time64 = 406;
412pub const SYS_clock_nanosleep_time64 = 407;
413pub const SYS_timer_gettime64 = 408;
414pub const SYS_timer_settime64 = 409;
415pub const SYS_timerfd_gettime64 = 410;
416pub const SYS_timerfd_settime64 = 411;
417pub const SYS_utimensat_time64 = 412;
418pub const SYS_pselect6_time64 = 413;
419pub const SYS_ppoll_time64 = 414;
420pub const SYS_io_pgetevents_time64 = 416;
421pub const SYS_recvmmsg_time64 = 417;
422pub const SYS_mq_timedsend_time64 = 418;
423pub const SYS_mq_timedreceive_time64 = 419;
424pub const SYS_semtimedop_time64 = 420;
425pub const SYS_rt_sigtimedwait_time64 = 421;
426pub const SYS_futex_time64 = 422;
427pub const SYS_sched_rr_get_interval_time64 = 423;
428pub const SYS_pidfd_send_signal = 424;
429pub const SYS_io_uring_setup = 425;
430pub const SYS_io_uring_enter = 426;
431pub const SYS_io_uring_register = 427;
432pub const SYS_open_tree = 428;
433pub const SYS_move_mount = 429;
434pub const SYS_fsopen = 430;
435pub const SYS_fsconfig = 431;
436pub const SYS_fsmount = 432;
437pub const SYS_fspick = 433;
15pub const SYS = extern enum(usize) {
16 restart_syscall = 0,
17 exit = 1,
18 fork = 2,
19 read = 3,
20 write = 4,
21 open = 5,
22 close = 6,
23 waitpid = 7,
24 creat = 8,
25 link = 9,
26 unlink = 10,
27 execve = 11,
28 chdir = 12,
29 time = 13,
30 mknod = 14,
31 chmod = 15,
32 lchown = 16,
33 @"break" = 17,
34 oldstat = 18,
35 lseek = 19,
36 getpid = 20,
37 mount = 21,
38 umount = 22,
39 setuid = 23,
40 getuid = 24,
41 stime = 25,
42 ptrace = 26,
43 alarm = 27,
44 oldfstat = 28,
45 pause = 29,
46 utime = 30,
47 stty = 31,
48 gtty = 32,
49 access = 33,
50 nice = 34,
51 ftime = 35,
52 sync = 36,
53 kill = 37,
54 rename = 38,
55 mkdir = 39,
56 rmdir = 40,
57 dup = 41,
58 pipe = 42,
59 times = 43,
60 prof = 44,
61 brk = 45,
62 setgid = 46,
63 getgid = 47,
64 signal = 48,
65 geteuid = 49,
66 getegid = 50,
67 acct = 51,
68 umount2 = 52,
69 lock = 53,
70 ioctl = 54,
71 fcntl = 55,
72 mpx = 56,
73 setpgid = 57,
74 ulimit = 58,
75 oldolduname = 59,
76 umask = 60,
77 chroot = 61,
78 ustat = 62,
79 dup2 = 63,
80 getppid = 64,
81 getpgrp = 65,
82 setsid = 66,
83 sigaction = 67,
84 sgetmask = 68,
85 ssetmask = 69,
86 setreuid = 70,
87 setregid = 71,
88 sigsuspend = 72,
89 sigpending = 73,
90 sethostname = 74,
91 setrlimit = 75,
92 getrlimit = 76,
93 getrusage = 77,
94 gettimeofday = 78,
95 settimeofday = 79,
96 getgroups = 80,
97 setgroups = 81,
98 select = 82,
99 symlink = 83,
100 oldlstat = 84,
101 readlink = 85,
102 uselib = 86,
103 swapon = 87,
104 reboot = 88,
105 readdir = 89,
106 mmap = 90,
107 munmap = 91,
108 truncate = 92,
109 ftruncate = 93,
110 fchmod = 94,
111 fchown = 95,
112 getpriority = 96,
113 setpriority = 97,
114 profil = 98,
115 statfs = 99,
116 fstatfs = 100,
117 ioperm = 101,
118 socketcall = 102,
119 syslog = 103,
120 setitimer = 104,
121 getitimer = 105,
122 stat = 106,
123 lstat = 107,
124 fstat = 108,
125 olduname = 109,
126 iopl = 110,
127 vhangup = 111,
128 idle = 112,
129 vm86old = 113,
130 wait4 = 114,
131 swapoff = 115,
132 sysinfo = 116,
133 ipc = 117,
134 fsync = 118,
135 sigreturn = 119,
136 clone = 120,
137 setdomainname = 121,
138 uname = 122,
139 modify_ldt = 123,
140 adjtimex = 124,
141 mprotect = 125,
142 sigprocmask = 126,
143 create_module = 127,
144 init_module = 128,
145 delete_module = 129,
146 get_kernel_syms = 130,
147 quotactl = 131,
148 getpgid = 132,
149 fchdir = 133,
150 bdflush = 134,
151 sysfs = 135,
152 personality = 136,
153 afs_syscall = 137,
154 setfsuid = 138,
155 setfsgid = 139,
156 _llseek = 140,
157 getdents = 141,
158 _newselect = 142,
159 flock = 143,
160 msync = 144,
161 readv = 145,
162 writev = 146,
163 getsid = 147,
164 fdatasync = 148,
165 _sysctl = 149,
166 mlock = 150,
167 munlock = 151,
168 mlockall = 152,
169 munlockall = 153,
170 sched_setparam = 154,
171 sched_getparam = 155,
172 sched_setscheduler = 156,
173 sched_getscheduler = 157,
174 sched_yield = 158,
175 sched_get_priority_max = 159,
176 sched_get_priority_min = 160,
177 sched_rr_get_interval = 161,
178 nanosleep = 162,
179 mremap = 163,
180 setresuid = 164,
181 getresuid = 165,
182 vm86 = 166,
183 query_module = 167,
184 poll = 168,
185 nfsservctl = 169,
186 setresgid = 170,
187 getresgid = 171,
188 prctl = 172,
189 rt_sigreturn = 173,
190 rt_sigaction = 174,
191 rt_sigprocmask = 175,
192 rt_sigpending = 176,
193 rt_sigtimedwait = 177,
194 rt_sigqueueinfo = 178,
195 rt_sigsuspend = 179,
196 pread64 = 180,
197 pwrite64 = 181,
198 chown = 182,
199 getcwd = 183,
200 capget = 184,
201 capset = 185,
202 sigaltstack = 186,
203 sendfile = 187,
204 getpmsg = 188,
205 putpmsg = 189,
206 vfork = 190,
207 ugetrlimit = 191,
208 mmap2 = 192,
209 truncate64 = 193,
210 ftruncate64 = 194,
211 stat64 = 195,
212 lstat64 = 196,
213 fstat64 = 197,
214 lchown32 = 198,
215 getuid32 = 199,
216 getgid32 = 200,
217 geteuid32 = 201,
218 getegid32 = 202,
219 setreuid32 = 203,
220 setregid32 = 204,
221 getgroups32 = 205,
222 setgroups32 = 206,
223 fchown32 = 207,
224 setresuid32 = 208,
225 getresuid32 = 209,
226 setresgid32 = 210,
227 getresgid32 = 211,
228 chown32 = 212,
229 setuid32 = 213,
230 setgid32 = 214,
231 setfsuid32 = 215,
232 setfsgid32 = 216,
233 pivot_root = 217,
234 mincore = 218,
235 madvise = 219,
236 getdents64 = 220,
237 fcntl64 = 221,
238 gettid = 224,
239 readahead = 225,
240 setxattr = 226,
241 lsetxattr = 227,
242 fsetxattr = 228,
243 getxattr = 229,
244 lgetxattr = 230,
245 fgetxattr = 231,
246 listxattr = 232,
247 llistxattr = 233,
248 flistxattr = 234,
249 removexattr = 235,
250 lremovexattr = 236,
251 fremovexattr = 237,
252 tkill = 238,
253 sendfile64 = 239,
254 futex = 240,
255 sched_setaffinity = 241,
256 sched_getaffinity = 242,
257 set_thread_area = 243,
258 get_thread_area = 244,
259 io_setup = 245,
260 io_destroy = 246,
261 io_getevents = 247,
262 io_submit = 248,
263 io_cancel = 249,
264 fadvise64 = 250,
265 exit_group = 252,
266 lookup_dcookie = 253,
267 epoll_create = 254,
268 epoll_ctl = 255,
269 epoll_wait = 256,
270 remap_file_pages = 257,
271 set_tid_address = 258,
272 timer_create = 259,
273 timer_settime, // SYS_timer_create + 1
274 timer_gettime, // SYS_timer_create + 2
275 timer_getoverrun, // SYS_timer_create + 3
276 timer_delete, // SYS_timer_create + 4
277 clock_settime, // SYS_timer_create + 5
278 clock_gettime, // SYS_timer_create + 6
279 clock_getres, // SYS_timer_create + 7
280 clock_nanosleep, // SYS_timer_create + 8
281 statfs64 = 268,
282 fstatfs64 = 269,
283 tgkill = 270,
284 utimes = 271,
285 fadvise64_64 = 272,
286 vserver = 273,
287 mbind = 274,
288 get_mempolicy = 275,
289 set_mempolicy = 276,
290 mq_open = 277,
291 mq_unlink, // SYS_mq_open + 1
292 mq_timedsend, // SYS_mq_open + 2
293 mq_timedreceive, // SYS_mq_open + 3
294 mq_notify, // SYS_mq_open + 4
295 mq_getsetattr, // SYS_mq_open + 5
296 kexec_load = 283,
297 waitid = 284,
298 add_key = 286,
299 request_key = 287,
300 keyctl = 288,
301 ioprio_set = 289,
302 ioprio_get = 290,
303 inotify_init = 291,
304 inotify_add_watch = 292,
305 inotify_rm_watch = 293,
306 migrate_pages = 294,
307 openat = 295,
308 mkdirat = 296,
309 mknodat = 297,
310 fchownat = 298,
311 futimesat = 299,
312 fstatat64 = 300,
313 unlinkat = 301,
314 renameat = 302,
315 linkat = 303,
316 symlinkat = 304,
317 readlinkat = 305,
318 fchmodat = 306,
319 faccessat = 307,
320 pselect6 = 308,
321 ppoll = 309,
322 unshare = 310,
323 set_robust_list = 311,
324 get_robust_list = 312,
325 splice = 313,
326 sync_file_range = 314,
327 tee = 315,
328 vmsplice = 316,
329 move_pages = 317,
330 getcpu = 318,
331 epoll_pwait = 319,
332 utimensat = 320,
333 signalfd = 321,
334 timerfd_create = 322,
335 eventfd = 323,
336 fallocate = 324,
337 timerfd_settime = 325,
338 timerfd_gettime = 326,
339 signalfd4 = 327,
340 eventfd2 = 328,
341 epoll_create1 = 329,
342 dup3 = 330,
343 pipe2 = 331,
344 inotify_init1 = 332,
345 preadv = 333,
346 pwritev = 334,
347 rt_tgsigqueueinfo = 335,
348 perf_event_open = 336,
349 recvmmsg = 337,
350 fanotify_init = 338,
351 fanotify_mark = 339,
352 prlimit64 = 340,
353 name_to_handle_at = 341,
354 open_by_handle_at = 342,
355 clock_adjtime = 343,
356 syncfs = 344,
357 sendmmsg = 345,
358 setns = 346,
359 process_vm_readv = 347,
360 process_vm_writev = 348,
361 kcmp = 349,
362 finit_module = 350,
363 sched_setattr = 351,
364 sched_getattr = 352,
365 renameat2 = 353,
366 seccomp = 354,
367 getrandom = 355,
368 memfd_create = 356,
369 bpf = 357,
370 execveat = 358,
371 socket = 359,
372 socketpair = 360,
373 bind = 361,
374 connect = 362,
375 listen = 363,
376 accept4 = 364,
377 getsockopt = 365,
378 setsockopt = 366,
379 getsockname = 367,
380 getpeername = 368,
381 sendto = 369,
382 sendmsg = 370,
383 recvfrom = 371,
384 recvmsg = 372,
385 shutdown = 373,
386 userfaultfd = 374,
387 membarrier = 375,
388 mlock2 = 376,
389 copy_file_range = 377,
390 preadv2 = 378,
391 pwritev2 = 379,
392 pkey_mprotect = 380,
393 pkey_alloc = 381,
394 pkey_free = 382,
395 statx = 383,
396 arch_prctl = 384,
397 io_pgetevents = 385,
398 rseq = 386,
399 semget = 393,
400 semctl = 394,
401 shmget = 395,
402 shmctl = 396,
403 shmat = 397,
404 shmdt = 398,
405 msgget = 399,
406 msgsnd = 400,
407 msgrcv = 401,
408 msgctl = 402,
409 clock_gettime64 = 403,
410 clock_settime64 = 404,
411 clock_adjtime64 = 405,
412 clock_getres_time64 = 406,
413 clock_nanosleep_time64 = 407,
414 timer_gettime64 = 408,
415 timer_settime64 = 409,
416 timerfd_gettime64 = 410,
417 timerfd_settime64 = 411,
418 utimensat_time64 = 412,
419 pselect6_time64 = 413,
420 ppoll_time64 = 414,
421 io_pgetevents_time64 = 416,
422 recvmmsg_time64 = 417,
423 mq_timedsend_time64 = 418,
424 mq_timedreceive_time64 = 419,
425 semtimedop_time64 = 420,
426 rt_sigtimedwait_time64 = 421,
427 futex_time64 = 422,
428 sched_rr_get_interval_time64 = 423,
429 pidfd_send_signal = 424,
430 io_uring_setup = 425,
431 io_uring_enter = 426,
432 io_uring_register = 427,
433 open_tree = 428,
434 move_mount = 429,
435 fsopen = 430,
436 fsconfig = 431,
437 fsmount = 432,
438 fspick = 433,
439 openat2 = 437,
440 pidfd_getfd = 438,
441
442 _,
443};
438444
439445pub const O_CREAT = 0o100;
440446pub const O_EXCL = 0o200;
lib/std/os/bits/linux/mipsel.zig+376-369
......@@ -7,375 +7,382 @@ const uid_t = linux.uid_t;
77const gid_t = linux.gid_t;
88const pid_t = linux.pid_t;
99
10pub const SYS_Linux = 4000;
11pub const SYS_syscall = (SYS_Linux + 0);
12pub const SYS_exit = (SYS_Linux + 1);
13pub const SYS_fork = (SYS_Linux + 2);
14pub const SYS_read = (SYS_Linux + 3);
15pub const SYS_write = (SYS_Linux + 4);
16pub const SYS_open = (SYS_Linux + 5);
17pub const SYS_close = (SYS_Linux + 6);
18pub const SYS_waitpid = (SYS_Linux + 7);
19pub const SYS_creat = (SYS_Linux + 8);
20pub const SYS_link = (SYS_Linux + 9);
21pub const SYS_unlink = (SYS_Linux + 10);
22pub const SYS_execve = (SYS_Linux + 11);
23pub const SYS_chdir = (SYS_Linux + 12);
24pub const SYS_time = (SYS_Linux + 13);
25pub const SYS_mknod = (SYS_Linux + 14);
26pub const SYS_chmod = (SYS_Linux + 15);
27pub const SYS_lchown = (SYS_Linux + 16);
28pub const SYS_break = (SYS_Linux + 17);
29pub const SYS_unused18 = (SYS_Linux + 18);
30pub const SYS_lseek = (SYS_Linux + 19);
31pub const SYS_getpid = (SYS_Linux + 20);
32pub const SYS_mount = (SYS_Linux + 21);
33pub const SYS_umount = (SYS_Linux + 22);
34pub const SYS_setuid = (SYS_Linux + 23);
35pub const SYS_getuid = (SYS_Linux + 24);
36pub const SYS_stime = (SYS_Linux + 25);
37pub const SYS_ptrace = (SYS_Linux + 26);
38pub const SYS_alarm = (SYS_Linux + 27);
39pub const SYS_unused28 = (SYS_Linux + 28);
40pub const SYS_pause = (SYS_Linux + 29);
41pub const SYS_utime = (SYS_Linux + 30);
42pub const SYS_stty = (SYS_Linux + 31);
43pub const SYS_gtty = (SYS_Linux + 32);
44pub const SYS_access = (SYS_Linux + 33);
45pub const SYS_nice = (SYS_Linux + 34);
46pub const SYS_ftime = (SYS_Linux + 35);
47pub const SYS_sync = (SYS_Linux + 36);
48pub const SYS_kill = (SYS_Linux + 37);
49pub const SYS_rename = (SYS_Linux + 38);
50pub const SYS_mkdir = (SYS_Linux + 39);
51pub const SYS_rmdir = (SYS_Linux + 40);
52pub const SYS_dup = (SYS_Linux + 41);
53pub const SYS_pipe = (SYS_Linux + 42);
54pub const SYS_times = (SYS_Linux + 43);
55pub const SYS_prof = (SYS_Linux + 44);
56pub const SYS_brk = (SYS_Linux + 45);
57pub const SYS_setgid = (SYS_Linux + 46);
58pub const SYS_getgid = (SYS_Linux + 47);
59pub const SYS_signal = (SYS_Linux + 48);
60pub const SYS_geteuid = (SYS_Linux + 49);
61pub const SYS_getegid = (SYS_Linux + 50);
62pub const SYS_acct = (SYS_Linux + 51);
63pub const SYS_umount2 = (SYS_Linux + 52);
64pub const SYS_lock = (SYS_Linux + 53);
65pub const SYS_ioctl = (SYS_Linux + 54);
66pub const SYS_fcntl = (SYS_Linux + 55);
67pub const SYS_mpx = (SYS_Linux + 56);
68pub const SYS_setpgid = (SYS_Linux + 57);
69pub const SYS_ulimit = (SYS_Linux + 58);
70pub const SYS_unused59 = (SYS_Linux + 59);
71pub const SYS_umask = (SYS_Linux + 60);
72pub const SYS_chroot = (SYS_Linux + 61);
73pub const SYS_ustat = (SYS_Linux + 62);
74pub const SYS_dup2 = (SYS_Linux + 63);
75pub const SYS_getppid = (SYS_Linux + 64);
76pub const SYS_getpgrp = (SYS_Linux + 65);
77pub const SYS_setsid = (SYS_Linux + 66);
78pub const SYS_sigaction = (SYS_Linux + 67);
79pub const SYS_sgetmask = (SYS_Linux + 68);
80pub const SYS_ssetmask = (SYS_Linux + 69);
81pub const SYS_setreuid = (SYS_Linux + 70);
82pub const SYS_setregid = (SYS_Linux + 71);
83pub const SYS_sigsuspend = (SYS_Linux + 72);
84pub const SYS_sigpending = (SYS_Linux + 73);
85pub const SYS_sethostname = (SYS_Linux + 74);
86pub const SYS_setrlimit = (SYS_Linux + 75);
87pub const SYS_getrlimit = (SYS_Linux + 76);
88pub const SYS_getrusage = (SYS_Linux + 77);
89pub const SYS_gettimeofday = (SYS_Linux + 78);
90pub const SYS_settimeofday = (SYS_Linux + 79);
91pub const SYS_getgroups = (SYS_Linux + 80);
92pub const SYS_setgroups = (SYS_Linux + 81);
93pub const SYS_reserved82 = (SYS_Linux + 82);
94pub const SYS_symlink = (SYS_Linux + 83);
95pub const SYS_unused84 = (SYS_Linux + 84);
96pub const SYS_readlink = (SYS_Linux + 85);
97pub const SYS_uselib = (SYS_Linux + 86);
98pub const SYS_swapon = (SYS_Linux + 87);
99pub const SYS_reboot = (SYS_Linux + 88);
100pub const SYS_readdir = (SYS_Linux + 89);
101pub const SYS_mmap = (SYS_Linux + 90);
102pub const SYS_munmap = (SYS_Linux + 91);
103pub const SYS_truncate = (SYS_Linux + 92);
104pub const SYS_ftruncate = (SYS_Linux + 93);
105pub const SYS_fchmod = (SYS_Linux + 94);
106pub const SYS_fchown = (SYS_Linux + 95);
107pub const SYS_getpriority = (SYS_Linux + 96);
108pub const SYS_setpriority = (SYS_Linux + 97);
109pub const SYS_profil = (SYS_Linux + 98);
110pub const SYS_statfs = (SYS_Linux + 99);
111pub const SYS_fstatfs = (SYS_Linux + 100);
112pub const SYS_ioperm = (SYS_Linux + 101);
113pub const SYS_socketcall = (SYS_Linux + 102);
114pub const SYS_syslog = (SYS_Linux + 103);
115pub const SYS_setitimer = (SYS_Linux + 104);
116pub const SYS_getitimer = (SYS_Linux + 105);
117pub const SYS_stat = (SYS_Linux + 106);
118pub const SYS_lstat = (SYS_Linux + 107);
119pub const SYS_fstat = (SYS_Linux + 108);
120pub const SYS_unused109 = (SYS_Linux + 109);
121pub const SYS_iopl = (SYS_Linux + 110);
122pub const SYS_vhangup = (SYS_Linux + 111);
123pub const SYS_idle = (SYS_Linux + 112);
124pub const SYS_vm86 = (SYS_Linux + 113);
125pub const SYS_wait4 = (SYS_Linux + 114);
126pub const SYS_swapoff = (SYS_Linux + 115);
127pub const SYS_sysinfo = (SYS_Linux + 116);
128pub const SYS_ipc = (SYS_Linux + 117);
129pub const SYS_fsync = (SYS_Linux + 118);
130pub const SYS_sigreturn = (SYS_Linux + 119);
131pub const SYS_clone = (SYS_Linux + 120);
132pub const SYS_setdomainname = (SYS_Linux + 121);
133pub const SYS_uname = (SYS_Linux + 122);
134pub const SYS_modify_ldt = (SYS_Linux + 123);
135pub const SYS_adjtimex = (SYS_Linux + 124);
136pub const SYS_mprotect = (SYS_Linux + 125);
137pub const SYS_sigprocmask = (SYS_Linux + 126);
138pub const SYS_create_module = (SYS_Linux + 127);
139pub const SYS_init_module = (SYS_Linux + 128);
140pub const SYS_delete_module = (SYS_Linux + 129);
141pub const SYS_get_kernel_syms = (SYS_Linux + 130);
142pub const SYS_quotactl = (SYS_Linux + 131);
143pub const SYS_getpgid = (SYS_Linux + 132);
144pub const SYS_fchdir = (SYS_Linux + 133);
145pub const SYS_bdflush = (SYS_Linux + 134);
146pub const SYS_sysfs = (SYS_Linux + 135);
147pub const SYS_personality = (SYS_Linux + 136);
148pub const SYS_afs_syscall = (SYS_Linux + 137);
149pub const SYS_setfsuid = (SYS_Linux + 138);
150pub const SYS_setfsgid = (SYS_Linux + 139);
151pub const SYS__llseek = (SYS_Linux + 140);
152pub const SYS_getdents = (SYS_Linux + 141);
153pub const SYS__newselect = (SYS_Linux + 142);
154pub const SYS_flock = (SYS_Linux + 143);
155pub const SYS_msync = (SYS_Linux + 144);
156pub const SYS_readv = (SYS_Linux + 145);
157pub const SYS_writev = (SYS_Linux + 146);
158pub const SYS_cacheflush = (SYS_Linux + 147);
159pub const SYS_cachectl = (SYS_Linux + 148);
160pub const SYS_sysmips = (SYS_Linux + 149);
161pub const SYS_unused150 = (SYS_Linux + 150);
162pub const SYS_getsid = (SYS_Linux + 151);
163pub const SYS_fdatasync = (SYS_Linux + 152);
164pub const SYS__sysctl = (SYS_Linux + 153);
165pub const SYS_mlock = (SYS_Linux + 154);
166pub const SYS_munlock = (SYS_Linux + 155);
167pub const SYS_mlockall = (SYS_Linux + 156);
168pub const SYS_munlockall = (SYS_Linux + 157);
169pub const SYS_sched_setparam = (SYS_Linux + 158);
170pub const SYS_sched_getparam = (SYS_Linux + 159);
171pub const SYS_sched_setscheduler = (SYS_Linux + 160);
172pub const SYS_sched_getscheduler = (SYS_Linux + 161);
173pub const SYS_sched_yield = (SYS_Linux + 162);
174pub const SYS_sched_get_priority_max = (SYS_Linux + 163);
175pub const SYS_sched_get_priority_min = (SYS_Linux + 164);
176pub const SYS_sched_rr_get_interval = (SYS_Linux + 165);
177pub const SYS_nanosleep = (SYS_Linux + 166);
178pub const SYS_mremap = (SYS_Linux + 167);
179pub const SYS_accept = (SYS_Linux + 168);
180pub const SYS_bind = (SYS_Linux + 169);
181pub const SYS_connect = (SYS_Linux + 170);
182pub const SYS_getpeername = (SYS_Linux + 171);
183pub const SYS_getsockname = (SYS_Linux + 172);
184pub const SYS_getsockopt = (SYS_Linux + 173);
185pub const SYS_listen = (SYS_Linux + 174);
186pub const SYS_recv = (SYS_Linux + 175);
187pub const SYS_recvfrom = (SYS_Linux + 176);
188pub const SYS_recvmsg = (SYS_Linux + 177);
189pub const SYS_send = (SYS_Linux + 178);
190pub const SYS_sendmsg = (SYS_Linux + 179);
191pub const SYS_sendto = (SYS_Linux + 180);
192pub const SYS_setsockopt = (SYS_Linux + 181);
193pub const SYS_shutdown = (SYS_Linux + 182);
194pub const SYS_socket = (SYS_Linux + 183);
195pub const SYS_socketpair = (SYS_Linux + 184);
196pub const SYS_setresuid = (SYS_Linux + 185);
197pub const SYS_getresuid = (SYS_Linux + 186);
198pub const SYS_query_module = (SYS_Linux + 187);
199pub const SYS_poll = (SYS_Linux + 188);
200pub const SYS_nfsservctl = (SYS_Linux + 189);
201pub const SYS_setresgid = (SYS_Linux + 190);
202pub const SYS_getresgid = (SYS_Linux + 191);
203pub const SYS_prctl = (SYS_Linux + 192);
204pub const SYS_rt_sigreturn = (SYS_Linux + 193);
205pub const SYS_rt_sigaction = (SYS_Linux + 194);
206pub const SYS_rt_sigprocmask = (SYS_Linux + 195);
207pub const SYS_rt_sigpending = (SYS_Linux + 196);
208pub const SYS_rt_sigtimedwait = (SYS_Linux + 197);
209pub const SYS_rt_sigqueueinfo = (SYS_Linux + 198);
210pub const SYS_rt_sigsuspend = (SYS_Linux + 199);
211pub const SYS_pread64 = (SYS_Linux + 200);
212pub const SYS_pwrite64 = (SYS_Linux + 201);
213pub const SYS_chown = (SYS_Linux + 202);
214pub const SYS_getcwd = (SYS_Linux + 203);
215pub const SYS_capget = (SYS_Linux + 204);
216pub const SYS_capset = (SYS_Linux + 205);
217pub const SYS_sigaltstack = (SYS_Linux + 206);
218pub const SYS_sendfile = (SYS_Linux + 207);
219pub const SYS_getpmsg = (SYS_Linux + 208);
220pub const SYS_putpmsg = (SYS_Linux + 209);
221pub const SYS_mmap2 = (SYS_Linux + 210);
222pub const SYS_truncate64 = (SYS_Linux + 211);
223pub const SYS_ftruncate64 = (SYS_Linux + 212);
224pub const SYS_stat64 = (SYS_Linux + 213);
225pub const SYS_lstat64 = (SYS_Linux + 214);
226pub const SYS_fstat64 = (SYS_Linux + 215);
227pub const SYS_pivot_root = (SYS_Linux + 216);
228pub const SYS_mincore = (SYS_Linux + 217);
229pub const SYS_madvise = (SYS_Linux + 218);
230pub const SYS_getdents64 = (SYS_Linux + 219);
231pub const SYS_fcntl64 = (SYS_Linux + 220);
232pub const SYS_reserved221 = (SYS_Linux + 221);
233pub const SYS_gettid = (SYS_Linux + 222);
234pub const SYS_readahead = (SYS_Linux + 223);
235pub const SYS_setxattr = (SYS_Linux + 224);
236pub const SYS_lsetxattr = (SYS_Linux + 225);
237pub const SYS_fsetxattr = (SYS_Linux + 226);
238pub const SYS_getxattr = (SYS_Linux + 227);
239pub const SYS_lgetxattr = (SYS_Linux + 228);
240pub const SYS_fgetxattr = (SYS_Linux + 229);
241pub const SYS_listxattr = (SYS_Linux + 230);
242pub const SYS_llistxattr = (SYS_Linux + 231);
243pub const SYS_flistxattr = (SYS_Linux + 232);
244pub const SYS_removexattr = (SYS_Linux + 233);
245pub const SYS_lremovexattr = (SYS_Linux + 234);
246pub const SYS_fremovexattr = (SYS_Linux + 235);
247pub const SYS_tkill = (SYS_Linux + 236);
248pub const SYS_sendfile64 = (SYS_Linux + 237);
249pub const SYS_futex = (SYS_Linux + 238);
250pub const SYS_sched_setaffinity = (SYS_Linux + 239);
251pub const SYS_sched_getaffinity = (SYS_Linux + 240);
252pub const SYS_io_setup = (SYS_Linux + 241);
253pub const SYS_io_destroy = (SYS_Linux + 242);
254pub const SYS_io_getevents = (SYS_Linux + 243);
255pub const SYS_io_submit = (SYS_Linux + 244);
256pub const SYS_io_cancel = (SYS_Linux + 245);
257pub const SYS_exit_group = (SYS_Linux + 246);
258pub const SYS_lookup_dcookie = (SYS_Linux + 247);
259pub const SYS_epoll_create = (SYS_Linux + 248);
260pub const SYS_epoll_ctl = (SYS_Linux + 249);
261pub const SYS_epoll_wait = (SYS_Linux + 250);
262pub const SYS_remap_file_pages = (SYS_Linux + 251);
263pub const SYS_set_tid_address = (SYS_Linux + 252);
264pub const SYS_restart_syscall = (SYS_Linux + 253);
265pub const SYS_fadvise64 = (SYS_Linux + 254);
266pub const SYS_statfs64 = (SYS_Linux + 255);
267pub const SYS_fstatfs64 = (SYS_Linux + 256);
268pub const SYS_timer_create = (SYS_Linux + 257);
269pub const SYS_timer_settime = (SYS_Linux + 258);
270pub const SYS_timer_gettime = (SYS_Linux + 259);
271pub const SYS_timer_getoverrun = (SYS_Linux + 260);
272pub const SYS_timer_delete = (SYS_Linux + 261);
273pub const SYS_clock_settime = (SYS_Linux + 262);
274pub const SYS_clock_gettime = (SYS_Linux + 263);
275pub const SYS_clock_getres = (SYS_Linux + 264);
276pub const SYS_clock_nanosleep = (SYS_Linux + 265);
277pub const SYS_tgkill = (SYS_Linux + 266);
278pub const SYS_utimes = (SYS_Linux + 267);
279pub const SYS_mbind = (SYS_Linux + 268);
280pub const SYS_get_mempolicy = (SYS_Linux + 269);
281pub const SYS_set_mempolicy = (SYS_Linux + 270);
282pub const SYS_mq_open = (SYS_Linux + 271);
283pub const SYS_mq_unlink = (SYS_Linux + 272);
284pub const SYS_mq_timedsend = (SYS_Linux + 273);
285pub const SYS_mq_timedreceive = (SYS_Linux + 274);
286pub const SYS_mq_notify = (SYS_Linux + 275);
287pub const SYS_mq_getsetattr = (SYS_Linux + 276);
288pub const SYS_vserver = (SYS_Linux + 277);
289pub const SYS_waitid = (SYS_Linux + 278);
290pub const SYS_add_key = (SYS_Linux + 280);
291pub const SYS_request_key = (SYS_Linux + 281);
292pub const SYS_keyctl = (SYS_Linux + 282);
293pub const SYS_set_thread_area = (SYS_Linux + 283);
294pub const SYS_inotify_init = (SYS_Linux + 284);
295pub const SYS_inotify_add_watch = (SYS_Linux + 285);
296pub const SYS_inotify_rm_watch = (SYS_Linux + 286);
297pub const SYS_migrate_pages = (SYS_Linux + 287);
298pub const SYS_openat = (SYS_Linux + 288);
299pub const SYS_mkdirat = (SYS_Linux + 289);
300pub const SYS_mknodat = (SYS_Linux + 290);
301pub const SYS_fchownat = (SYS_Linux + 291);
302pub const SYS_futimesat = (SYS_Linux + 292);
303pub const SYS_fstatat64 = (SYS_Linux + 293);
304pub const SYS_unlinkat = (SYS_Linux + 294);
305pub const SYS_renameat = (SYS_Linux + 295);
306pub const SYS_linkat = (SYS_Linux + 296);
307pub const SYS_symlinkat = (SYS_Linux + 297);
308pub const SYS_readlinkat = (SYS_Linux + 298);
309pub const SYS_fchmodat = (SYS_Linux + 299);
310pub const SYS_faccessat = (SYS_Linux + 300);
311pub const SYS_pselect6 = (SYS_Linux + 301);
312pub const SYS_ppoll = (SYS_Linux + 302);
313pub const SYS_unshare = (SYS_Linux + 303);
314pub const SYS_splice = (SYS_Linux + 304);
315pub const SYS_sync_file_range = (SYS_Linux + 305);
316pub const SYS_tee = (SYS_Linux + 306);
317pub const SYS_vmsplice = (SYS_Linux + 307);
318pub const SYS_move_pages = (SYS_Linux + 308);
319pub const SYS_set_robust_list = (SYS_Linux + 309);
320pub const SYS_get_robust_list = (SYS_Linux + 310);
321pub const SYS_kexec_load = (SYS_Linux + 311);
322pub const SYS_getcpu = (SYS_Linux + 312);
323pub const SYS_epoll_pwait = (SYS_Linux + 313);
324pub const SYS_ioprio_set = (SYS_Linux + 314);
325pub const SYS_ioprio_get = (SYS_Linux + 315);
326pub const SYS_utimensat = (SYS_Linux + 316);
327pub const SYS_signalfd = (SYS_Linux + 317);
328pub const SYS_timerfd = (SYS_Linux + 318);
329pub const SYS_eventfd = (SYS_Linux + 319);
330pub const SYS_fallocate = (SYS_Linux + 320);
331pub const SYS_timerfd_create = (SYS_Linux + 321);
332pub const SYS_timerfd_gettime = (SYS_Linux + 322);
333pub const SYS_timerfd_settime = (SYS_Linux + 323);
334pub const SYS_signalfd4 = (SYS_Linux + 324);
335pub const SYS_eventfd2 = (SYS_Linux + 325);
336pub const SYS_epoll_create1 = (SYS_Linux + 326);
337pub const SYS_dup3 = (SYS_Linux + 327);
338pub const SYS_pipe2 = (SYS_Linux + 328);
339pub const SYS_inotify_init1 = (SYS_Linux + 329);
340pub const SYS_preadv = (SYS_Linux + 330);
341pub const SYS_pwritev = (SYS_Linux + 331);
342pub const SYS_rt_tgsigqueueinfo = (SYS_Linux + 332);
343pub const SYS_perf_event_open = (SYS_Linux + 333);
344pub const SYS_accept4 = (SYS_Linux + 334);
345pub const SYS_recvmmsg = (SYS_Linux + 335);
346pub const SYS_fanotify_init = (SYS_Linux + 336);
347pub const SYS_fanotify_mark = (SYS_Linux + 337);
348pub const SYS_prlimit64 = (SYS_Linux + 338);
349pub const SYS_name_to_handle_at = (SYS_Linux + 339);
350pub const SYS_open_by_handle_at = (SYS_Linux + 340);
351pub const SYS_clock_adjtime = (SYS_Linux + 341);
352pub const SYS_syncfs = (SYS_Linux + 342);
353pub const SYS_sendmmsg = (SYS_Linux + 343);
354pub const SYS_setns = (SYS_Linux + 344);
355pub const SYS_process_vm_readv = (SYS_Linux + 345);
356pub const SYS_process_vm_writev = (SYS_Linux + 346);
357pub const SYS_kcmp = (SYS_Linux + 347);
358pub const SYS_finit_module = (SYS_Linux + 348);
359pub const SYS_sched_setattr = (SYS_Linux + 349);
360pub const SYS_sched_getattr = (SYS_Linux + 350);
361pub const SYS_renameat2 = (SYS_Linux + 351);
362pub const SYS_seccomp = (SYS_Linux + 352);
363pub const SYS_getrandom = (SYS_Linux + 353);
364pub const SYS_memfd_create = (SYS_Linux + 354);
365pub const SYS_bpf = (SYS_Linux + 355);
366pub const SYS_execveat = (SYS_Linux + 356);
367pub const SYS_userfaultfd = (SYS_Linux + 357);
368pub const SYS_membarrier = (SYS_Linux + 358);
369pub const SYS_mlock2 = (SYS_Linux + 359);
370pub const SYS_copy_file_range = (SYS_Linux + 360);
371pub const SYS_preadv2 = (SYS_Linux + 361);
372pub const SYS_pwritev2 = (SYS_Linux + 362);
373pub const SYS_pkey_mprotect = (SYS_Linux + 363);
374pub const SYS_pkey_alloc = (SYS_Linux + 364);
375pub const SYS_pkey_free = (SYS_Linux + 365);
376pub const SYS_statx = (SYS_Linux + 366);
377pub const SYS_rseq = (SYS_Linux + 367);
378pub const SYS_io_pgetevents = (SYS_Linux + 368);
10pub const SYS = extern enum(usize) {
11 pub const Linux = 4000;
12
13 syscall = Linux + 0,
14 exit = Linux + 1,
15 fork = Linux + 2,
16 read = Linux + 3,
17 write = Linux + 4,
18 open = Linux + 5,
19 close = Linux + 6,
20 waitpid = Linux + 7,
21 creat = Linux + 8,
22 link = Linux + 9,
23 unlink = Linux + 10,
24 execve = Linux + 11,
25 chdir = Linux + 12,
26 time = Linux + 13,
27 mknod = Linux + 14,
28 chmod = Linux + 15,
29 lchown = Linux + 16,
30 @"break" = Linux + 17,
31 unused18 = Linux + 18,
32 lseek = Linux + 19,
33 getpid = Linux + 20,
34 mount = Linux + 21,
35 umount = Linux + 22,
36 setuid = Linux + 23,
37 getuid = Linux + 24,
38 stime = Linux + 25,
39 ptrace = Linux + 26,
40 alarm = Linux + 27,
41 unused28 = Linux + 28,
42 pause = Linux + 29,
43 utime = Linux + 30,
44 stty = Linux + 31,
45 gtty = Linux + 32,
46 access = Linux + 33,
47 nice = Linux + 34,
48 ftime = Linux + 35,
49 sync = Linux + 36,
50 kill = Linux + 37,
51 rename = Linux + 38,
52 mkdir = Linux + 39,
53 rmdir = Linux + 40,
54 dup = Linux + 41,
55 pipe = Linux + 42,
56 times = Linux + 43,
57 prof = Linux + 44,
58 brk = Linux + 45,
59 setgid = Linux + 46,
60 getgid = Linux + 47,
61 signal = Linux + 48,
62 geteuid = Linux + 49,
63 getegid = Linux + 50,
64 acct = Linux + 51,
65 umount2 = Linux + 52,
66 lock = Linux + 53,
67 ioctl = Linux + 54,
68 fcntl = Linux + 55,
69 mpx = Linux + 56,
70 setpgid = Linux + 57,
71 ulimit = Linux + 58,
72 unused59 = Linux + 59,
73 umask = Linux + 60,
74 chroot = Linux + 61,
75 ustat = Linux + 62,
76 dup2 = Linux + 63,
77 getppid = Linux + 64,
78 getpgrp = Linux + 65,
79 setsid = Linux + 66,
80 sigaction = Linux + 67,
81 sgetmask = Linux + 68,
82 ssetmask = Linux + 69,
83 setreuid = Linux + 70,
84 setregid = Linux + 71,
85 sigsuspend = Linux + 72,
86 sigpending = Linux + 73,
87 sethostname = Linux + 74,
88 setrlimit = Linux + 75,
89 getrlimit = Linux + 76,
90 getrusage = Linux + 77,
91 gettimeofday = Linux + 78,
92 settimeofday = Linux + 79,
93 getgroups = Linux + 80,
94 setgroups = Linux + 81,
95 reserved82 = Linux + 82,
96 symlink = Linux + 83,
97 unused84 = Linux + 84,
98 readlink = Linux + 85,
99 uselib = Linux + 86,
100 swapon = Linux + 87,
101 reboot = Linux + 88,
102 readdir = Linux + 89,
103 mmap = Linux + 90,
104 munmap = Linux + 91,
105 truncate = Linux + 92,
106 ftruncate = Linux + 93,
107 fchmod = Linux + 94,
108 fchown = Linux + 95,
109 getpriority = Linux + 96,
110 setpriority = Linux + 97,
111 profil = Linux + 98,
112 statfs = Linux + 99,
113 fstatfs = Linux + 100,
114 ioperm = Linux + 101,
115 socketcall = Linux + 102,
116 syslog = Linux + 103,
117 setitimer = Linux + 104,
118 getitimer = Linux + 105,
119 stat = Linux + 106,
120 lstat = Linux + 107,
121 fstat = Linux + 108,
122 unused109 = Linux + 109,
123 iopl = Linux + 110,
124 vhangup = Linux + 111,
125 idle = Linux + 112,
126 vm86 = Linux + 113,
127 wait4 = Linux + 114,
128 swapoff = Linux + 115,
129 sysinfo = Linux + 116,
130 ipc = Linux + 117,
131 fsync = Linux + 118,
132 sigreturn = Linux + 119,
133 clone = Linux + 120,
134 setdomainname = Linux + 121,
135 uname = Linux + 122,
136 modify_ldt = Linux + 123,
137 adjtimex = Linux + 124,
138 mprotect = Linux + 125,
139 sigprocmask = Linux + 126,
140 create_module = Linux + 127,
141 init_module = Linux + 128,
142 delete_module = Linux + 129,
143 get_kernel_syms = Linux + 130,
144 quotactl = Linux + 131,
145 getpgid = Linux + 132,
146 fchdir = Linux + 133,
147 bdflush = Linux + 134,
148 sysfs = Linux + 135,
149 personality = Linux + 136,
150 afs_syscall = Linux + 137,
151 setfsuid = Linux + 138,
152 setfsgid = Linux + 139,
153 _llseek = Linux + 140,
154 getdents = Linux + 141,
155 _newselect = Linux + 142,
156 flock = Linux + 143,
157 msync = Linux + 144,
158 readv = Linux + 145,
159 writev = Linux + 146,
160 cacheflush = Linux + 147,
161 cachectl = Linux + 148,
162 sysmips = Linux + 149,
163 unused150 = Linux + 150,
164 getsid = Linux + 151,
165 fdatasync = Linux + 152,
166 _sysctl = Linux + 153,
167 mlock = Linux + 154,
168 munlock = Linux + 155,
169 mlockall = Linux + 156,
170 munlockall = Linux + 157,
171 sched_setparam = Linux + 158,
172 sched_getparam = Linux + 159,
173 sched_setscheduler = Linux + 160,
174 sched_getscheduler = Linux + 161,
175 sched_yield = Linux + 162,
176 sched_get_priority_max = Linux + 163,
177 sched_get_priority_min = Linux + 164,
178 sched_rr_get_interval = Linux + 165,
179 nanosleep = Linux + 166,
180 mremap = Linux + 167,
181 accept = Linux + 168,
182 bind = Linux + 169,
183 connect = Linux + 170,
184 getpeername = Linux + 171,
185 getsockname = Linux + 172,
186 getsockopt = Linux + 173,
187 listen = Linux + 174,
188 recv = Linux + 175,
189 recvfrom = Linux + 176,
190 recvmsg = Linux + 177,
191 send = Linux + 178,
192 sendmsg = Linux + 179,
193 sendto = Linux + 180,
194 setsockopt = Linux + 181,
195 shutdown = Linux + 182,
196 socket = Linux + 183,
197 socketpair = Linux + 184,
198 setresuid = Linux + 185,
199 getresuid = Linux + 186,
200 query_module = Linux + 187,
201 poll = Linux + 188,
202 nfsservctl = Linux + 189,
203 setresgid = Linux + 190,
204 getresgid = Linux + 191,
205 prctl = Linux + 192,
206 rt_sigreturn = Linux + 193,
207 rt_sigaction = Linux + 194,
208 rt_sigprocmask = Linux + 195,
209 rt_sigpending = Linux + 196,
210 rt_sigtimedwait = Linux + 197,
211 rt_sigqueueinfo = Linux + 198,
212 rt_sigsuspend = Linux + 199,
213 pread64 = Linux + 200,
214 pwrite64 = Linux + 201,
215 chown = Linux + 202,
216 getcwd = Linux + 203,
217 capget = Linux + 204,
218 capset = Linux + 205,
219 sigaltstack = Linux + 206,
220 sendfile = Linux + 207,
221 getpmsg = Linux + 208,
222 putpmsg = Linux + 209,
223 mmap2 = Linux + 210,
224 truncate64 = Linux + 211,
225 ftruncate64 = Linux + 212,
226 stat64 = Linux + 213,
227 lstat64 = Linux + 214,
228 fstat64 = Linux + 215,
229 pivot_root = Linux + 216,
230 mincore = Linux + 217,
231 madvise = Linux + 218,
232 getdents64 = Linux + 219,
233 fcntl64 = Linux + 220,
234 reserved221 = Linux + 221,
235 gettid = Linux + 222,
236 readahead = Linux + 223,
237 setxattr = Linux + 224,
238 lsetxattr = Linux + 225,
239 fsetxattr = Linux + 226,
240 getxattr = Linux + 227,
241 lgetxattr = Linux + 228,
242 fgetxattr = Linux + 229,
243 listxattr = Linux + 230,
244 llistxattr = Linux + 231,
245 flistxattr = Linux + 232,
246 removexattr = Linux + 233,
247 lremovexattr = Linux + 234,
248 fremovexattr = Linux + 235,
249 tkill = Linux + 236,
250 sendfile64 = Linux + 237,
251 futex = Linux + 238,
252 sched_setaffinity = Linux + 239,
253 sched_getaffinity = Linux + 240,
254 io_setup = Linux + 241,
255 io_destroy = Linux + 242,
256 io_getevents = Linux + 243,
257 io_submit = Linux + 244,
258 io_cancel = Linux + 245,
259 exit_group = Linux + 246,
260 lookup_dcookie = Linux + 247,
261 epoll_create = Linux + 248,
262 epoll_ctl = Linux + 249,
263 epoll_wait = Linux + 250,
264 remap_file_pages = Linux + 251,
265 set_tid_address = Linux + 252,
266 restart_syscall = Linux + 253,
267 fadvise64 = Linux + 254,
268 statfs64 = Linux + 255,
269 fstatfs64 = Linux + 256,
270 timer_create = Linux + 257,
271 timer_settime = Linux + 258,
272 timer_gettime = Linux + 259,
273 timer_getoverrun = Linux + 260,
274 timer_delete = Linux + 261,
275 clock_settime = Linux + 262,
276 clock_gettime = Linux + 263,
277 clock_getres = Linux + 264,
278 clock_nanosleep = Linux + 265,
279 tgkill = Linux + 266,
280 utimes = Linux + 267,
281 mbind = Linux + 268,
282 get_mempolicy = Linux + 269,
283 set_mempolicy = Linux + 270,
284 mq_open = Linux + 271,
285 mq_unlink = Linux + 272,
286 mq_timedsend = Linux + 273,
287 mq_timedreceive = Linux + 274,
288 mq_notify = Linux + 275,
289 mq_getsetattr = Linux + 276,
290 vserver = Linux + 277,
291 waitid = Linux + 278,
292 add_key = Linux + 280,
293 request_key = Linux + 281,
294 keyctl = Linux + 282,
295 set_thread_area = Linux + 283,
296 inotify_init = Linux + 284,
297 inotify_add_watch = Linux + 285,
298 inotify_rm_watch = Linux + 286,
299 migrate_pages = Linux + 287,
300 openat = Linux + 288,
301 mkdirat = Linux + 289,
302 mknodat = Linux + 290,
303 fchownat = Linux + 291,
304 futimesat = Linux + 292,
305 fstatat64 = Linux + 293,
306 unlinkat = Linux + 294,
307 renameat = Linux + 295,
308 linkat = Linux + 296,
309 symlinkat = Linux + 297,
310 readlinkat = Linux + 298,
311 fchmodat = Linux + 299,
312 faccessat = Linux + 300,
313 pselect6 = Linux + 301,
314 ppoll = Linux + 302,
315 unshare = Linux + 303,
316 splice = Linux + 304,
317 sync_file_range = Linux + 305,
318 tee = Linux + 306,
319 vmsplice = Linux + 307,
320 move_pages = Linux + 308,
321 set_robust_list = Linux + 309,
322 get_robust_list = Linux + 310,
323 kexec_load = Linux + 311,
324 getcpu = Linux + 312,
325 epoll_pwait = Linux + 313,
326 ioprio_set = Linux + 314,
327 ioprio_get = Linux + 315,
328 utimensat = Linux + 316,
329 signalfd = Linux + 317,
330 timerfd = Linux + 318,
331 eventfd = Linux + 319,
332 fallocate = Linux + 320,
333 timerfd_create = Linux + 321,
334 timerfd_gettime = Linux + 322,
335 timerfd_settime = Linux + 323,
336 signalfd4 = Linux + 324,
337 eventfd2 = Linux + 325,
338 epoll_create1 = Linux + 326,
339 dup3 = Linux + 327,
340 pipe2 = Linux + 328,
341 inotify_init1 = Linux + 329,
342 preadv = Linux + 330,
343 pwritev = Linux + 331,
344 rt_tgsigqueueinfo = Linux + 332,
345 perf_event_open = Linux + 333,
346 accept4 = Linux + 334,
347 recvmmsg = Linux + 335,
348 fanotify_init = Linux + 336,
349 fanotify_mark = Linux + 337,
350 prlimit64 = Linux + 338,
351 name_to_handle_at = Linux + 339,
352 open_by_handle_at = Linux + 340,
353 clock_adjtime = Linux + 341,
354 syncfs = Linux + 342,
355 sendmmsg = Linux + 343,
356 setns = Linux + 344,
357 process_vm_readv = Linux + 345,
358 process_vm_writev = Linux + 346,
359 kcmp = Linux + 347,
360 finit_module = Linux + 348,
361 sched_setattr = Linux + 349,
362 sched_getattr = Linux + 350,
363 renameat2 = Linux + 351,
364 seccomp = Linux + 352,
365 getrandom = Linux + 353,
366 memfd_create = Linux + 354,
367 bpf = Linux + 355,
368 execveat = Linux + 356,
369 userfaultfd = Linux + 357,
370 membarrier = Linux + 358,
371 mlock2 = Linux + 359,
372 copy_file_range = Linux + 360,
373 preadv2 = Linux + 361,
374 pwritev2 = Linux + 362,
375 pkey_mprotect = Linux + 363,
376 pkey_alloc = Linux + 364,
377 pkey_free = Linux + 365,
378 statx = Linux + 366,
379 rseq = Linux + 367,
380 io_pgetevents = Linux + 368,
381 openat2 = Linux + 437,
382 pidfd_getfd = Linux + 438,
383
384 _,
385};
379386
380387pub const O_CREAT = 0o0400;
381388pub const O_EXCL = 0o02000;
lib/std/os/bits/linux/riscv64.zig+298-292
......@@ -4,300 +4,306 @@ const uid_t = std.os.linux.uid_t;
44const gid_t = std.os.linux.gid_t;
55const pid_t = std.os.linux.pid_t;
66
7pub const SYS_io_setup = 0;
8pub const SYS_io_destroy = 1;
9pub const SYS_io_submit = 2;
10pub const SYS_io_cancel = 3;
11pub const SYS_io_getevents = 4;
12pub const SYS_setxattr = 5;
13pub const SYS_lsetxattr = 6;
14pub const SYS_fsetxattr = 7;
15pub const SYS_getxattr = 8;
16pub const SYS_lgetxattr = 9;
17pub const SYS_fgetxattr = 10;
18pub const SYS_listxattr = 11;
19pub const SYS_llistxattr = 12;
20pub const SYS_flistxattr = 13;
21pub const SYS_removexattr = 14;
22pub const SYS_lremovexattr = 15;
23pub const SYS_fremovexattr = 16;
24pub const SYS_getcwd = 17;
25pub const SYS_lookup_dcookie = 18;
26pub const SYS_eventfd2 = 19;
27pub const SYS_epoll_create1 = 20;
28pub const SYS_epoll_ctl = 21;
29pub const SYS_epoll_pwait = 22;
30pub const SYS_dup = 23;
31pub const SYS_dup3 = 24;
32pub const SYS_fcntl = 25;
33pub const SYS_inotify_init1 = 26;
34pub const SYS_inotify_add_watch = 27;
35pub const SYS_inotify_rm_watch = 28;
36pub const SYS_ioctl = 29;
37pub const SYS_ioprio_set = 30;
38pub const SYS_ioprio_get = 31;
39pub const SYS_flock = 32;
40pub const SYS_mknodat = 33;
41pub const SYS_mkdirat = 34;
42pub const SYS_unlinkat = 35;
43pub const SYS_symlinkat = 36;
44pub const SYS_linkat = 37;
45pub const SYS_umount2 = 39;
46pub const SYS_mount = 40;
47pub const SYS_pivot_root = 41;
48pub const SYS_nfsservctl = 42;
49pub const SYS_statfs = 43;
50pub const SYS_fstatfs = 44;
51pub const SYS_truncate = 45;
52pub const SYS_ftruncate = 46;
53pub const SYS_fallocate = 47;
54pub const SYS_faccessat = 48;
55pub const SYS_chdir = 49;
56pub const SYS_fchdir = 50;
57pub const SYS_chroot = 51;
58pub const SYS_fchmod = 52;
59pub const SYS_fchmodat = 53;
60pub const SYS_fchownat = 54;
61pub const SYS_fchown = 55;
62pub const SYS_openat = 56;
63pub const SYS_close = 57;
64pub const SYS_vhangup = 58;
65pub const SYS_pipe2 = 59;
66pub const SYS_quotactl = 60;
67pub const SYS_getdents64 = 61;
68pub const SYS_lseek = 62;
69pub const SYS_read = 63;
70pub const SYS_write = 64;
71pub const SYS_readv = 65;
72pub const SYS_writev = 66;
73pub const SYS_pread64 = 67;
74pub const SYS_pwrite64 = 68;
75pub const SYS_preadv = 69;
76pub const SYS_pwritev = 70;
77pub const SYS_sendfile = 71;
78pub const SYS_pselect6 = 72;
79pub const SYS_ppoll = 73;
80pub const SYS_signalfd4 = 74;
81pub const SYS_vmsplice = 75;
82pub const SYS_splice = 76;
83pub const SYS_tee = 77;
84pub const SYS_readlinkat = 78;
85pub const SYS_fstatat = 79;
86pub const SYS_fstat = 80;
87pub const SYS_sync = 81;
88pub const SYS_fsync = 82;
89pub const SYS_fdatasync = 83;
90pub const SYS_sync_file_range = 84;
91pub const SYS_timerfd_create = 85;
92pub const SYS_timerfd_settime = 86;
93pub const SYS_timerfd_gettime = 87;
94pub const SYS_utimensat = 88;
95pub const SYS_acct = 89;
96pub const SYS_capget = 90;
97pub const SYS_capset = 91;
98pub const SYS_personality = 92;
99pub const SYS_exit = 93;
100pub const SYS_exit_group = 94;
101pub const SYS_waitid = 95;
102pub const SYS_set_tid_address = 96;
103pub const SYS_unshare = 97;
104pub const SYS_futex = 98;
105pub const SYS_set_robust_list = 99;
106pub const SYS_get_robust_list = 100;
107pub const SYS_nanosleep = 101;
108pub const SYS_getitimer = 102;
109pub const SYS_setitimer = 103;
110pub const SYS_kexec_load = 104;
111pub const SYS_init_module = 105;
112pub const SYS_delete_module = 106;
113pub const SYS_timer_create = 107;
114pub const SYS_timer_gettime = 108;
115pub const SYS_timer_getoverrun = 109;
116pub const SYS_timer_settime = 110;
117pub const SYS_timer_delete = 111;
118pub const SYS_clock_settime = 112;
119pub const SYS_clock_gettime = 113;
120pub const SYS_clock_getres = 114;
121pub const SYS_clock_nanosleep = 115;
122pub const SYS_syslog = 116;
123pub const SYS_ptrace = 117;
124pub const SYS_sched_setparam = 118;
125pub const SYS_sched_setscheduler = 119;
126pub const SYS_sched_getscheduler = 120;
127pub const SYS_sched_getparam = 121;
128pub const SYS_sched_setaffinity = 122;
129pub const SYS_sched_getaffinity = 123;
130pub const SYS_sched_yield = 124;
131pub const SYS_sched_get_priority_max = 125;
132pub const SYS_sched_get_priority_min = 126;
133pub const SYS_sched_rr_get_interval = 127;
134pub const SYS_restart_syscall = 128;
135pub const SYS_kill = 129;
136pub const SYS_tkill = 130;
137pub const SYS_tgkill = 131;
138pub const SYS_sigaltstack = 132;
139pub const SYS_rt_sigsuspend = 133;
140pub const SYS_rt_sigaction = 134;
141pub const SYS_rt_sigprocmask = 135;
142pub const SYS_rt_sigpending = 136;
143pub const SYS_rt_sigtimedwait = 137;
144pub const SYS_rt_sigqueueinfo = 138;
145pub const SYS_rt_sigreturn = 139;
146pub const SYS_setpriority = 140;
147pub const SYS_getpriority = 141;
148pub const SYS_reboot = 142;
149pub const SYS_setregid = 143;
150pub const SYS_setgid = 144;
151pub const SYS_setreuid = 145;
152pub const SYS_setuid = 146;
153pub const SYS_setresuid = 147;
154pub const SYS_getresuid = 148;
155pub const SYS_setresgid = 149;
156pub const SYS_getresgid = 150;
157pub const SYS_setfsuid = 151;
158pub const SYS_setfsgid = 152;
159pub const SYS_times = 153;
160pub const SYS_setpgid = 154;
161pub const SYS_getpgid = 155;
162pub const SYS_getsid = 156;
163pub const SYS_setsid = 157;
164pub const SYS_getgroups = 158;
165pub const SYS_setgroups = 159;
166pub const SYS_uname = 160;
167pub const SYS_sethostname = 161;
168pub const SYS_setdomainname = 162;
169pub const SYS_getrlimit = 163;
170pub const SYS_setrlimit = 164;
171pub const SYS_getrusage = 165;
172pub const SYS_umask = 166;
173pub const SYS_prctl = 167;
174pub const SYS_getcpu = 168;
175pub const SYS_gettimeofday = 169;
176pub const SYS_settimeofday = 170;
177pub const SYS_adjtimex = 171;
178pub const SYS_getpid = 172;
179pub const SYS_getppid = 173;
180pub const SYS_getuid = 174;
181pub const SYS_geteuid = 175;
182pub const SYS_getgid = 176;
183pub const SYS_getegid = 177;
184pub const SYS_gettid = 178;
185pub const SYS_sysinfo = 179;
186pub const SYS_mq_open = 180;
187pub const SYS_mq_unlink = 181;
188pub const SYS_mq_timedsend = 182;
189pub const SYS_mq_timedreceive = 183;
190pub const SYS_mq_notify = 184;
191pub const SYS_mq_getsetattr = 185;
192pub const SYS_msgget = 186;
193pub const SYS_msgctl = 187;
194pub const SYS_msgrcv = 188;
195pub const SYS_msgsnd = 189;
196pub const SYS_semget = 190;
197pub const SYS_semctl = 191;
198pub const SYS_semtimedop = 192;
199pub const SYS_semop = 193;
200pub const SYS_shmget = 194;
201pub const SYS_shmctl = 195;
202pub const SYS_shmat = 196;
203pub const SYS_shmdt = 197;
204pub const SYS_socket = 198;
205pub const SYS_socketpair = 199;
206pub const SYS_bind = 200;
207pub const SYS_listen = 201;
208pub const SYS_accept = 202;
209pub const SYS_connect = 203;
210pub const SYS_getsockname = 204;
211pub const SYS_getpeername = 205;
212pub const SYS_sendto = 206;
213pub const SYS_recvfrom = 207;
214pub const SYS_setsockopt = 208;
215pub const SYS_getsockopt = 209;
216pub const SYS_shutdown = 210;
217pub const SYS_sendmsg = 211;
218pub const SYS_recvmsg = 212;
219pub const SYS_readahead = 213;
220pub const SYS_brk = 214;
221pub const SYS_munmap = 215;
222pub const SYS_mremap = 216;
223pub const SYS_add_key = 217;
224pub const SYS_request_key = 218;
225pub const SYS_keyctl = 219;
226pub const SYS_clone = 220;
227pub const SYS_execve = 221;
228pub const SYS_mmap = 222;
229pub const SYS_fadvise64 = 223;
230pub const SYS_swapon = 224;
231pub const SYS_swapoff = 225;
232pub const SYS_mprotect = 226;
233pub const SYS_msync = 227;
234pub const SYS_mlock = 228;
235pub const SYS_munlock = 229;
236pub const SYS_mlockall = 230;
237pub const SYS_munlockall = 231;
238pub const SYS_mincore = 232;
239pub const SYS_madvise = 233;
240pub const SYS_remap_file_pages = 234;
241pub const SYS_mbind = 235;
242pub const SYS_get_mempolicy = 236;
243pub const SYS_set_mempolicy = 237;
244pub const SYS_migrate_pages = 238;
245pub const SYS_move_pages = 239;
246pub const SYS_rt_tgsigqueueinfo = 240;
247pub const SYS_perf_event_open = 241;
248pub const SYS_accept4 = 242;
249pub const SYS_recvmmsg = 243;
7pub const SYS = extern enum(usize) {
8 io_setup = 0,
9 io_destroy = 1,
10 io_submit = 2,
11 io_cancel = 3,
12 io_getevents = 4,
13 setxattr = 5,
14 lsetxattr = 6,
15 fsetxattr = 7,
16 getxattr = 8,
17 lgetxattr = 9,
18 fgetxattr = 10,
19 listxattr = 11,
20 llistxattr = 12,
21 flistxattr = 13,
22 removexattr = 14,
23 lremovexattr = 15,
24 fremovexattr = 16,
25 getcwd = 17,
26 lookup_dcookie = 18,
27 eventfd2 = 19,
28 epoll_create1 = 20,
29 epoll_ctl = 21,
30 epoll_pwait = 22,
31 dup = 23,
32 dup3 = 24,
33 fcntl = 25,
34 inotify_init1 = 26,
35 inotify_add_watch = 27,
36 inotify_rm_watch = 28,
37 ioctl = 29,
38 ioprio_set = 30,
39 ioprio_get = 31,
40 flock = 32,
41 mknodat = 33,
42 mkdirat = 34,
43 unlinkat = 35,
44 symlinkat = 36,
45 linkat = 37,
46 umount2 = 39,
47 mount = 40,
48 pivot_root = 41,
49 nfsservctl = 42,
50 statfs = 43,
51 fstatfs = 44,
52 truncate = 45,
53 ftruncate = 46,
54 fallocate = 47,
55 faccessat = 48,
56 chdir = 49,
57 fchdir = 50,
58 chroot = 51,
59 fchmod = 52,
60 fchmodat = 53,
61 fchownat = 54,
62 fchown = 55,
63 openat = 56,
64 close = 57,
65 vhangup = 58,
66 pipe2 = 59,
67 quotactl = 60,
68 getdents64 = 61,
69 lseek = 62,
70 read = 63,
71 write = 64,
72 readv = 65,
73 writev = 66,
74 pread64 = 67,
75 pwrite64 = 68,
76 preadv = 69,
77 pwritev = 70,
78 sendfile = 71,
79 pselect6 = 72,
80 ppoll = 73,
81 signalfd4 = 74,
82 vmsplice = 75,
83 splice = 76,
84 tee = 77,
85 readlinkat = 78,
86 fstatat = 79,
87 fstat = 80,
88 sync = 81,
89 fsync = 82,
90 fdatasync = 83,
91 sync_file_range = 84,
92 timerfd_create = 85,
93 timerfd_settime = 86,
94 timerfd_gettime = 87,
95 utimensat = 88,
96 acct = 89,
97 capget = 90,
98 capset = 91,
99 personality = 92,
100 exit = 93,
101 exit_group = 94,
102 waitid = 95,
103 set_tid_address = 96,
104 unshare = 97,
105 futex = 98,
106 set_robust_list = 99,
107 get_robust_list = 100,
108 nanosleep = 101,
109 getitimer = 102,
110 setitimer = 103,
111 kexec_load = 104,
112 init_module = 105,
113 delete_module = 106,
114 timer_create = 107,
115 timer_gettime = 108,
116 timer_getoverrun = 109,
117 timer_settime = 110,
118 timer_delete = 111,
119 clock_settime = 112,
120 clock_gettime = 113,
121 clock_getres = 114,
122 clock_nanosleep = 115,
123 syslog = 116,
124 ptrace = 117,
125 sched_setparam = 118,
126 sched_setscheduler = 119,
127 sched_getscheduler = 120,
128 sched_getparam = 121,
129 sched_setaffinity = 122,
130 sched_getaffinity = 123,
131 sched_yield = 124,
132 sched_get_priority_max = 125,
133 sched_get_priority_min = 126,
134 sched_rr_get_interval = 127,
135 restart_syscall = 128,
136 kill = 129,
137 tkill = 130,
138 tgkill = 131,
139 sigaltstack = 132,
140 rt_sigsuspend = 133,
141 rt_sigaction = 134,
142 rt_sigprocmask = 135,
143 rt_sigpending = 136,
144 rt_sigtimedwait = 137,
145 rt_sigqueueinfo = 138,
146 rt_sigreturn = 139,
147 setpriority = 140,
148 getpriority = 141,
149 reboot = 142,
150 setregid = 143,
151 setgid = 144,
152 setreuid = 145,
153 setuid = 146,
154 setresuid = 147,
155 getresuid = 148,
156 setresgid = 149,
157 getresgid = 150,
158 setfsuid = 151,
159 setfsgid = 152,
160 times = 153,
161 setpgid = 154,
162 getpgid = 155,
163 getsid = 156,
164 setsid = 157,
165 getgroups = 158,
166 setgroups = 159,
167 uname = 160,
168 sethostname = 161,
169 setdomainname = 162,
170 getrlimit = 163,
171 setrlimit = 164,
172 getrusage = 165,
173 umask = 166,
174 prctl = 167,
175 getcpu = 168,
176 gettimeofday = 169,
177 settimeofday = 170,
178 adjtimex = 171,
179 getpid = 172,
180 getppid = 173,
181 getuid = 174,
182 geteuid = 175,
183 getgid = 176,
184 getegid = 177,
185 gettid = 178,
186 sysinfo = 179,
187 mq_open = 180,
188 mq_unlink = 181,
189 mq_timedsend = 182,
190 mq_timedreceive = 183,
191 mq_notify = 184,
192 mq_getsetattr = 185,
193 msgget = 186,
194 msgctl = 187,
195 msgrcv = 188,
196 msgsnd = 189,
197 semget = 190,
198 semctl = 191,
199 semtimedop = 192,
200 semop = 193,
201 shmget = 194,
202 shmctl = 195,
203 shmat = 196,
204 shmdt = 197,
205 socket = 198,
206 socketpair = 199,
207 bind = 200,
208 listen = 201,
209 accept = 202,
210 connect = 203,
211 getsockname = 204,
212 getpeername = 205,
213 sendto = 206,
214 recvfrom = 207,
215 setsockopt = 208,
216 getsockopt = 209,
217 shutdown = 210,
218 sendmsg = 211,
219 recvmsg = 212,
220 readahead = 213,
221 brk = 214,
222 munmap = 215,
223 mremap = 216,
224 add_key = 217,
225 request_key = 218,
226 keyctl = 219,
227 clone = 220,
228 execve = 221,
229 mmap = 222,
230 fadvise64 = 223,
231 swapon = 224,
232 swapoff = 225,
233 mprotect = 226,
234 msync = 227,
235 mlock = 228,
236 munlock = 229,
237 mlockall = 230,
238 munlockall = 231,
239 mincore = 232,
240 madvise = 233,
241 remap_file_pages = 234,
242 mbind = 235,
243 get_mempolicy = 236,
244 set_mempolicy = 237,
245 migrate_pages = 238,
246 move_pages = 239,
247 rt_tgsigqueueinfo = 240,
248 perf_event_open = 241,
249 accept4 = 242,
250 recvmmsg = 243,
250251
251pub const SYS_arch_specific_syscall = 244;
252pub const SYS_riscv_flush_icache = SYS_arch_specific_syscall + 15;
252 pub const arch_specific_syscall = 244;
253 riscv_flush_icache = arch_specific_syscall + 15,
253254
254pub const SYS_wait4 = 260;
255pub const SYS_prlimit64 = 261;
256pub const SYS_fanotify_init = 262;
257pub const SYS_fanotify_mark = 263;
258pub const SYS_name_to_handle_at = 264;
259pub const SYS_open_by_handle_at = 265;
260pub const SYS_clock_adjtime = 266;
261pub const SYS_syncfs = 267;
262pub const SYS_setns = 268;
263pub const SYS_sendmmsg = 269;
264pub const SYS_process_vm_readv = 270;
265pub const SYS_process_vm_writev = 271;
266pub const SYS_kcmp = 272;
267pub const SYS_finit_module = 273;
268pub const SYS_sched_setattr = 274;
269pub const SYS_sched_getattr = 275;
270pub const SYS_renameat2 = 276;
271pub const SYS_seccomp = 277;
272pub const SYS_getrandom = 278;
273pub const SYS_memfd_create = 279;
274pub const SYS_bpf = 280;
275pub const SYS_execveat = 281;
276pub const SYS_userfaultfd = 282;
277pub const SYS_membarrier = 283;
278pub const SYS_mlock2 = 284;
279pub const SYS_copy_file_range = 285;
280pub const SYS_preadv2 = 286;
281pub const SYS_pwritev2 = 287;
282pub const SYS_pkey_mprotect = 288;
283pub const SYS_pkey_alloc = 289;
284pub const SYS_pkey_free = 290;
285pub const SYS_statx = 291;
286pub const SYS_io_pgetevents = 292;
287pub const SYS_rseq = 293;
288pub const SYS_kexec_file_load = 294;
289pub const SYS_pidfd_send_signal = 424;
290pub const SYS_io_uring_setup = 425;
291pub const SYS_io_uring_enter = 426;
292pub const SYS_io_uring_register = 427;
293pub const SYS_open_tree = 428;
294pub const SYS_move_mount = 429;
295pub const SYS_fsopen = 430;
296pub const SYS_fsconfig = 431;
297pub const SYS_fsmount = 432;
298pub const SYS_fspick = 433;
299pub const SYS_pidfd_open = 434;
300pub const SYS_clone3 = 435;
255 wait4 = 260,
256 prlimit64 = 261,
257 fanotify_init = 262,
258 fanotify_mark = 263,
259 name_to_handle_at = 264,
260 open_by_handle_at = 265,
261 clock_adjtime = 266,
262 syncfs = 267,
263 setns = 268,
264 sendmmsg = 269,
265 process_vm_readv = 270,
266 process_vm_writev = 271,
267 kcmp = 272,
268 finit_module = 273,
269 sched_setattr = 274,
270 sched_getattr = 275,
271 renameat2 = 276,
272 seccomp = 277,
273 getrandom = 278,
274 memfd_create = 279,
275 bpf = 280,
276 execveat = 281,
277 userfaultfd = 282,
278 membarrier = 283,
279 mlock2 = 284,
280 copy_file_range = 285,
281 preadv2 = 286,
282 pwritev2 = 287,
283 pkey_mprotect = 288,
284 pkey_alloc = 289,
285 pkey_free = 290,
286 statx = 291,
287 io_pgetevents = 292,
288 rseq = 293,
289 kexec_file_load = 294,
290 pidfd_send_signal = 424,
291 io_uring_setup = 425,
292 io_uring_enter = 426,
293 io_uring_register = 427,
294 open_tree = 428,
295 move_mount = 429,
296 fsopen = 430,
297 fsconfig = 431,
298 fsmount = 432,
299 fspick = 433,
300 pidfd_open = 434,
301 clone3 = 435,
302 openat2 = 437,
303 pidfd_getfd = 438,
304
305 _,
306};
301307
302308pub const O_CREAT = 0o100;
303309pub const O_EXCL = 0o200;
lib/std/os/bits/linux/x86_64.zig+354-348
......@@ -14,354 +14,360 @@ const iovec_const = linux.iovec_const;
1414
1515pub const mode_t = usize;
1616
17pub const SYS_read = 0;
18pub const SYS_write = 1;
19pub const SYS_open = 2;
20pub const SYS_close = 3;
21pub const SYS_stat = 4;
22pub const SYS_fstat = 5;
23pub const SYS_lstat = 6;
24pub const SYS_poll = 7;
25pub const SYS_lseek = 8;
26pub const SYS_mmap = 9;
27pub const SYS_mprotect = 10;
28pub const SYS_munmap = 11;
29pub const SYS_brk = 12;
30pub const SYS_rt_sigaction = 13;
31pub const SYS_rt_sigprocmask = 14;
32pub const SYS_rt_sigreturn = 15;
33pub const SYS_ioctl = 16;
34pub const SYS_pread = 17;
35pub const SYS_pwrite = 18;
36pub const SYS_readv = 19;
37pub const SYS_writev = 20;
38pub const SYS_access = 21;
39pub const SYS_pipe = 22;
40pub const SYS_select = 23;
41pub const SYS_sched_yield = 24;
42pub const SYS_mremap = 25;
43pub const SYS_msync = 26;
44pub const SYS_mincore = 27;
45pub const SYS_madvise = 28;
46pub const SYS_shmget = 29;
47pub const SYS_shmat = 30;
48pub const SYS_shmctl = 31;
49pub const SYS_dup = 32;
50pub const SYS_dup2 = 33;
51pub const SYS_pause = 34;
52pub const SYS_nanosleep = 35;
53pub const SYS_getitimer = 36;
54pub const SYS_alarm = 37;
55pub const SYS_setitimer = 38;
56pub const SYS_getpid = 39;
57pub const SYS_sendfile = 40;
58pub const SYS_socket = 41;
59pub const SYS_connect = 42;
60pub const SYS_accept = 43;
61pub const SYS_sendto = 44;
62pub const SYS_recvfrom = 45;
63pub const SYS_sendmsg = 46;
64pub const SYS_recvmsg = 47;
65pub const SYS_shutdown = 48;
66pub const SYS_bind = 49;
67pub const SYS_listen = 50;
68pub const SYS_getsockname = 51;
69pub const SYS_getpeername = 52;
70pub const SYS_socketpair = 53;
71pub const SYS_setsockopt = 54;
72pub const SYS_getsockopt = 55;
73pub const SYS_clone = 56;
74pub const SYS_fork = 57;
75pub const SYS_vfork = 58;
76pub const SYS_execve = 59;
77pub const SYS_exit = 60;
78pub const SYS_wait4 = 61;
79pub const SYS_kill = 62;
80pub const SYS_uname = 63;
81pub const SYS_semget = 64;
82pub const SYS_semop = 65;
83pub const SYS_semctl = 66;
84pub const SYS_shmdt = 67;
85pub const SYS_msgget = 68;
86pub const SYS_msgsnd = 69;
87pub const SYS_msgrcv = 70;
88pub const SYS_msgctl = 71;
89pub const SYS_fcntl = 72;
90pub const SYS_flock = 73;
91pub const SYS_fsync = 74;
92pub const SYS_fdatasync = 75;
93pub const SYS_truncate = 76;
94pub const SYS_ftruncate = 77;
95pub const SYS_getdents = 78;
96pub const SYS_getcwd = 79;
97pub const SYS_chdir = 80;
98pub const SYS_fchdir = 81;
99pub const SYS_rename = 82;
100pub const SYS_mkdir = 83;
101pub const SYS_rmdir = 84;
102pub const SYS_creat = 85;
103pub const SYS_link = 86;
104pub const SYS_unlink = 87;
105pub const SYS_symlink = 88;
106pub const SYS_readlink = 89;
107pub const SYS_chmod = 90;
108pub const SYS_fchmod = 91;
109pub const SYS_chown = 92;
110pub const SYS_fchown = 93;
111pub const SYS_lchown = 94;
112pub const SYS_umask = 95;
113pub const SYS_gettimeofday = 96;
114pub const SYS_getrlimit = 97;
115pub const SYS_getrusage = 98;
116pub const SYS_sysinfo = 99;
117pub const SYS_times = 100;
118pub const SYS_ptrace = 101;
119pub const SYS_getuid = 102;
120pub const SYS_syslog = 103;
121pub const SYS_getgid = 104;
122pub const SYS_setuid = 105;
123pub const SYS_setgid = 106;
124pub const SYS_geteuid = 107;
125pub const SYS_getegid = 108;
126pub const SYS_setpgid = 109;
127pub const SYS_getppid = 110;
128pub const SYS_getpgrp = 111;
129pub const SYS_setsid = 112;
130pub const SYS_setreuid = 113;
131pub const SYS_setregid = 114;
132pub const SYS_getgroups = 115;
133pub const SYS_setgroups = 116;
134pub const SYS_setresuid = 117;
135pub const SYS_getresuid = 118;
136pub const SYS_setresgid = 119;
137pub const SYS_getresgid = 120;
138pub const SYS_getpgid = 121;
139pub const SYS_setfsuid = 122;
140pub const SYS_setfsgid = 123;
141pub const SYS_getsid = 124;
142pub const SYS_capget = 125;
143pub const SYS_capset = 126;
144pub const SYS_rt_sigpending = 127;
145pub const SYS_rt_sigtimedwait = 128;
146pub const SYS_rt_sigqueueinfo = 129;
147pub const SYS_rt_sigsuspend = 130;
148pub const SYS_sigaltstack = 131;
149pub const SYS_utime = 132;
150pub const SYS_mknod = 133;
151pub const SYS_uselib = 134;
152pub const SYS_personality = 135;
153pub const SYS_ustat = 136;
154pub const SYS_statfs = 137;
155pub const SYS_fstatfs = 138;
156pub const SYS_sysfs = 139;
157pub const SYS_getpriority = 140;
158pub const SYS_setpriority = 141;
159pub const SYS_sched_setparam = 142;
160pub const SYS_sched_getparam = 143;
161pub const SYS_sched_setscheduler = 144;
162pub const SYS_sched_getscheduler = 145;
163pub const SYS_sched_get_priority_max = 146;
164pub const SYS_sched_get_priority_min = 147;
165pub const SYS_sched_rr_get_interval = 148;
166pub const SYS_mlock = 149;
167pub const SYS_munlock = 150;
168pub const SYS_mlockall = 151;
169pub const SYS_munlockall = 152;
170pub const SYS_vhangup = 153;
171pub const SYS_modify_ldt = 154;
172pub const SYS_pivot_root = 155;
173pub const SYS__sysctl = 156;
174pub const SYS_prctl = 157;
175pub const SYS_arch_prctl = 158;
176pub const SYS_adjtimex = 159;
177pub const SYS_setrlimit = 160;
178pub const SYS_chroot = 161;
179pub const SYS_sync = 162;
180pub const SYS_acct = 163;
181pub const SYS_settimeofday = 164;
182pub const SYS_mount = 165;
183pub const SYS_umount2 = 166;
184pub const SYS_swapon = 167;
185pub const SYS_swapoff = 168;
186pub const SYS_reboot = 169;
187pub const SYS_sethostname = 170;
188pub const SYS_setdomainname = 171;
189pub const SYS_iopl = 172;
190pub const SYS_ioperm = 173;
191pub const SYS_create_module = 174;
192pub const SYS_init_module = 175;
193pub const SYS_delete_module = 176;
194pub const SYS_get_kernel_syms = 177;
195pub const SYS_query_module = 178;
196pub const SYS_quotactl = 179;
197pub const SYS_nfsservctl = 180;
198pub const SYS_getpmsg = 181;
199pub const SYS_putpmsg = 182;
200pub const SYS_afs_syscall = 183;
201pub const SYS_tuxcall = 184;
202pub const SYS_security = 185;
203pub const SYS_gettid = 186;
204pub const SYS_readahead = 187;
205pub const SYS_setxattr = 188;
206pub const SYS_lsetxattr = 189;
207pub const SYS_fsetxattr = 190;
208pub const SYS_getxattr = 191;
209pub const SYS_lgetxattr = 192;
210pub const SYS_fgetxattr = 193;
211pub const SYS_listxattr = 194;
212pub const SYS_llistxattr = 195;
213pub const SYS_flistxattr = 196;
214pub const SYS_removexattr = 197;
215pub const SYS_lremovexattr = 198;
216pub const SYS_fremovexattr = 199;
217pub const SYS_tkill = 200;
218pub const SYS_time = 201;
219pub const SYS_futex = 202;
220pub const SYS_sched_setaffinity = 203;
221pub const SYS_sched_getaffinity = 204;
222pub const SYS_set_thread_area = 205;
223pub const SYS_io_setup = 206;
224pub const SYS_io_destroy = 207;
225pub const SYS_io_getevents = 208;
226pub const SYS_io_submit = 209;
227pub const SYS_io_cancel = 210;
228pub const SYS_get_thread_area = 211;
229pub const SYS_lookup_dcookie = 212;
230pub const SYS_epoll_create = 213;
231pub const SYS_epoll_ctl_old = 214;
232pub const SYS_epoll_wait_old = 215;
233pub const SYS_remap_file_pages = 216;
234pub const SYS_getdents64 = 217;
235pub const SYS_set_tid_address = 218;
236pub const SYS_restart_syscall = 219;
237pub const SYS_semtimedop = 220;
238pub const SYS_fadvise64 = 221;
239pub const SYS_timer_create = 222;
240pub const SYS_timer_settime = 223;
241pub const SYS_timer_gettime = 224;
242pub const SYS_timer_getoverrun = 225;
243pub const SYS_timer_delete = 226;
244pub const SYS_clock_settime = 227;
245pub const SYS_clock_gettime = 228;
246pub const SYS_clock_getres = 229;
247pub const SYS_clock_nanosleep = 230;
248pub const SYS_exit_group = 231;
249pub const SYS_epoll_wait = 232;
250pub const SYS_epoll_ctl = 233;
251pub const SYS_tgkill = 234;
252pub const SYS_utimes = 235;
253pub const SYS_vserver = 236;
254pub const SYS_mbind = 237;
255pub const SYS_set_mempolicy = 238;
256pub const SYS_get_mempolicy = 239;
257pub const SYS_mq_open = 240;
258pub const SYS_mq_unlink = 241;
259pub const SYS_mq_timedsend = 242;
260pub const SYS_mq_timedreceive = 243;
261pub const SYS_mq_notify = 244;
262pub const SYS_mq_getsetattr = 245;
263pub const SYS_kexec_load = 246;
264pub const SYS_waitid = 247;
265pub const SYS_add_key = 248;
266pub const SYS_request_key = 249;
267pub const SYS_keyctl = 250;
268pub const SYS_ioprio_set = 251;
269pub const SYS_ioprio_get = 252;
270pub const SYS_inotify_init = 253;
271pub const SYS_inotify_add_watch = 254;
272pub const SYS_inotify_rm_watch = 255;
273pub const SYS_migrate_pages = 256;
274pub const SYS_openat = 257;
275pub const SYS_mkdirat = 258;
276pub const SYS_mknodat = 259;
277pub const SYS_fchownat = 260;
278pub const SYS_futimesat = 261;
279pub const SYS_newfstatat = 262;
280pub const SYS_fstatat = 262;
281pub const SYS_unlinkat = 263;
282pub const SYS_renameat = 264;
283pub const SYS_linkat = 265;
284pub const SYS_symlinkat = 266;
285pub const SYS_readlinkat = 267;
286pub const SYS_fchmodat = 268;
287pub const SYS_faccessat = 269;
288pub const SYS_pselect6 = 270;
289pub const SYS_ppoll = 271;
290pub const SYS_unshare = 272;
291pub const SYS_set_robust_list = 273;
292pub const SYS_get_robust_list = 274;
293pub const SYS_splice = 275;
294pub const SYS_tee = 276;
295pub const SYS_sync_file_range = 277;
296pub const SYS_vmsplice = 278;
297pub const SYS_move_pages = 279;
298pub const SYS_utimensat = 280;
299pub const SYS_epoll_pwait = 281;
300pub const SYS_signalfd = 282;
301pub const SYS_timerfd_create = 283;
302pub const SYS_eventfd = 284;
303pub const SYS_fallocate = 285;
304pub const SYS_timerfd_settime = 286;
305pub const SYS_timerfd_gettime = 287;
306pub const SYS_accept4 = 288;
307pub const SYS_signalfd4 = 289;
308pub const SYS_eventfd2 = 290;
309pub const SYS_epoll_create1 = 291;
310pub const SYS_dup3 = 292;
311pub const SYS_pipe2 = 293;
312pub const SYS_inotify_init1 = 294;
313pub const SYS_preadv = 295;
314pub const SYS_pwritev = 296;
315pub const SYS_rt_tgsigqueueinfo = 297;
316pub const SYS_perf_event_open = 298;
317pub const SYS_recvmmsg = 299;
318pub const SYS_fanotify_init = 300;
319pub const SYS_fanotify_mark = 301;
320pub const SYS_prlimit64 = 302;
321pub const SYS_name_to_handle_at = 303;
322pub const SYS_open_by_handle_at = 304;
323pub const SYS_clock_adjtime = 305;
324pub const SYS_syncfs = 306;
325pub const SYS_sendmmsg = 307;
326pub const SYS_setns = 308;
327pub const SYS_getcpu = 309;
328pub const SYS_process_vm_readv = 310;
329pub const SYS_process_vm_writev = 311;
330pub const SYS_kcmp = 312;
331pub const SYS_finit_module = 313;
332pub const SYS_sched_setattr = 314;
333pub const SYS_sched_getattr = 315;
334pub const SYS_renameat2 = 316;
335pub const SYS_seccomp = 317;
336pub const SYS_getrandom = 318;
337pub const SYS_memfd_create = 319;
338pub const SYS_kexec_file_load = 320;
339pub const SYS_bpf = 321;
340pub const SYS_execveat = 322;
341pub const SYS_userfaultfd = 323;
342pub const SYS_membarrier = 324;
343pub const SYS_mlock2 = 325;
344pub const SYS_copy_file_range = 326;
345pub const SYS_preadv2 = 327;
346pub const SYS_pwritev2 = 328;
347pub const SYS_pkey_mprotect = 329;
348pub const SYS_pkey_alloc = 330;
349pub const SYS_pkey_free = 331;
350pub const SYS_statx = 332;
351pub const SYS_io_pgetevents = 333;
352pub const SYS_rseq = 334;
353pub const SYS_pidfd_send_signal = 424;
354pub const SYS_io_uring_setup = 425;
355pub const SYS_io_uring_enter = 426;
356pub const SYS_io_uring_register = 427;
357pub const SYS_open_tree = 428;
358pub const SYS_move_mount = 429;
359pub const SYS_fsopen = 430;
360pub const SYS_fsconfig = 431;
361pub const SYS_fsmount = 432;
362pub const SYS_fspick = 433;
363pub const SYS_pidfd_open = 434;
364pub const SYS_clone3 = 435;
17pub const SYS = extern enum(usize) {
18 read = 0,
19 write = 1,
20 open = 2,
21 close = 3,
22 stat = 4,
23 fstat = 5,
24 lstat = 6,
25 poll = 7,
26 lseek = 8,
27 mmap = 9,
28 mprotect = 10,
29 munmap = 11,
30 brk = 12,
31 rt_sigaction = 13,
32 rt_sigprocmask = 14,
33 rt_sigreturn = 15,
34 ioctl = 16,
35 pread = 17,
36 pwrite = 18,
37 readv = 19,
38 writev = 20,
39 access = 21,
40 pipe = 22,
41 select = 23,
42 sched_yield = 24,
43 mremap = 25,
44 msync = 26,
45 mincore = 27,
46 madvise = 28,
47 shmget = 29,
48 shmat = 30,
49 shmctl = 31,
50 dup = 32,
51 dup2 = 33,
52 pause = 34,
53 nanosleep = 35,
54 getitimer = 36,
55 alarm = 37,
56 setitimer = 38,
57 getpid = 39,
58 sendfile = 40,
59 socket = 41,
60 connect = 42,
61 accept = 43,
62 sendto = 44,
63 recvfrom = 45,
64 sendmsg = 46,
65 recvmsg = 47,
66 shutdown = 48,
67 bind = 49,
68 listen = 50,
69 getsockname = 51,
70 getpeername = 52,
71 socketpair = 53,
72 setsockopt = 54,
73 getsockopt = 55,
74 clone = 56,
75 fork = 57,
76 vfork = 58,
77 execve = 59,
78 exit = 60,
79 wait4 = 61,
80 kill = 62,
81 uname = 63,
82 semget = 64,
83 semop = 65,
84 semctl = 66,
85 shmdt = 67,
86 msgget = 68,
87 msgsnd = 69,
88 msgrcv = 70,
89 msgctl = 71,
90 fcntl = 72,
91 flock = 73,
92 fsync = 74,
93 fdatasync = 75,
94 truncate = 76,
95 ftruncate = 77,
96 getdents = 78,
97 getcwd = 79,
98 chdir = 80,
99 fchdir = 81,
100 rename = 82,
101 mkdir = 83,
102 rmdir = 84,
103 creat = 85,
104 link = 86,
105 unlink = 87,
106 symlink = 88,
107 readlink = 89,
108 chmod = 90,
109 fchmod = 91,
110 chown = 92,
111 fchown = 93,
112 lchown = 94,
113 umask = 95,
114 gettimeofday = 96,
115 getrlimit = 97,
116 getrusage = 98,
117 sysinfo = 99,
118 times = 100,
119 ptrace = 101,
120 getuid = 102,
121 syslog = 103,
122 getgid = 104,
123 setuid = 105,
124 setgid = 106,
125 geteuid = 107,
126 getegid = 108,
127 setpgid = 109,
128 getppid = 110,
129 getpgrp = 111,
130 setsid = 112,
131 setreuid = 113,
132 setregid = 114,
133 getgroups = 115,
134 setgroups = 116,
135 setresuid = 117,
136 getresuid = 118,
137 setresgid = 119,
138 getresgid = 120,
139 getpgid = 121,
140 setfsuid = 122,
141 setfsgid = 123,
142 getsid = 124,
143 capget = 125,
144 capset = 126,
145 rt_sigpending = 127,
146 rt_sigtimedwait = 128,
147 rt_sigqueueinfo = 129,
148 rt_sigsuspend = 130,
149 sigaltstack = 131,
150 utime = 132,
151 mknod = 133,
152 uselib = 134,
153 personality = 135,
154 ustat = 136,
155 statfs = 137,
156 fstatfs = 138,
157 sysfs = 139,
158 getpriority = 140,
159 setpriority = 141,
160 sched_setparam = 142,
161 sched_getparam = 143,
162 sched_setscheduler = 144,
163 sched_getscheduler = 145,
164 sched_get_priority_max = 146,
165 sched_get_priority_min = 147,
166 sched_rr_get_interval = 148,
167 mlock = 149,
168 munlock = 150,
169 mlockall = 151,
170 munlockall = 152,
171 vhangup = 153,
172 modify_ldt = 154,
173 pivot_root = 155,
174 _sysctl = 156,
175 prctl = 157,
176 arch_prctl = 158,
177 adjtimex = 159,
178 setrlimit = 160,
179 chroot = 161,
180 sync = 162,
181 acct = 163,
182 settimeofday = 164,
183 mount = 165,
184 umount2 = 166,
185 swapon = 167,
186 swapoff = 168,
187 reboot = 169,
188 sethostname = 170,
189 setdomainname = 171,
190 iopl = 172,
191 ioperm = 173,
192 create_module = 174,
193 init_module = 175,
194 delete_module = 176,
195 get_kernel_syms = 177,
196 query_module = 178,
197 quotactl = 179,
198 nfsservctl = 180,
199 getpmsg = 181,
200 putpmsg = 182,
201 afs_syscall = 183,
202 tuxcall = 184,
203 security = 185,
204 gettid = 186,
205 readahead = 187,
206 setxattr = 188,
207 lsetxattr = 189,
208 fsetxattr = 190,
209 getxattr = 191,
210 lgetxattr = 192,
211 fgetxattr = 193,
212 listxattr = 194,
213 llistxattr = 195,
214 flistxattr = 196,
215 removexattr = 197,
216 lremovexattr = 198,
217 fremovexattr = 199,
218 tkill = 200,
219 time = 201,
220 futex = 202,
221 sched_setaffinity = 203,
222 sched_getaffinity = 204,
223 set_thread_area = 205,
224 io_setup = 206,
225 io_destroy = 207,
226 io_getevents = 208,
227 io_submit = 209,
228 io_cancel = 210,
229 get_thread_area = 211,
230 lookup_dcookie = 212,
231 epoll_create = 213,
232 epoll_ctl_old = 214,
233 epoll_wait_old = 215,
234 remap_file_pages = 216,
235 getdents64 = 217,
236 set_tid_address = 218,
237 restart_syscall = 219,
238 semtimedop = 220,
239 fadvise64 = 221,
240 timer_create = 222,
241 timer_settime = 223,
242 timer_gettime = 224,
243 timer_getoverrun = 225,
244 timer_delete = 226,
245 clock_settime = 227,
246 clock_gettime = 228,
247 clock_getres = 229,
248 clock_nanosleep = 230,
249 exit_group = 231,
250 epoll_wait = 232,
251 epoll_ctl = 233,
252 tgkill = 234,
253 utimes = 235,
254 vserver = 236,
255 mbind = 237,
256 set_mempolicy = 238,
257 get_mempolicy = 239,
258 mq_open = 240,
259 mq_unlink = 241,
260 mq_timedsend = 242,
261 mq_timedreceive = 243,
262 mq_notify = 244,
263 mq_getsetattr = 245,
264 kexec_load = 246,
265 waitid = 247,
266 add_key = 248,
267 request_key = 249,
268 keyctl = 250,
269 ioprio_set = 251,
270 ioprio_get = 252,
271 inotify_init = 253,
272 inotify_add_watch = 254,
273 inotify_rm_watch = 255,
274 migrate_pages = 256,
275 openat = 257,
276 mkdirat = 258,
277 mknodat = 259,
278 fchownat = 260,
279 futimesat = 261,
280 newfstatat = 262,
281 fstatat = 262,
282 unlinkat = 263,
283 renameat = 264,
284 linkat = 265,
285 symlinkat = 266,
286 readlinkat = 267,
287 fchmodat = 268,
288 faccessat = 269,
289 pselect6 = 270,
290 ppoll = 271,
291 unshare = 272,
292 set_robust_list = 273,
293 get_robust_list = 274,
294 splice = 275,
295 tee = 276,
296 sync_file_range = 277,
297 vmsplice = 278,
298 move_pages = 279,
299 utimensat = 280,
300 epoll_pwait = 281,
301 signalfd = 282,
302 timerfd_create = 283,
303 eventfd = 284,
304 fallocate = 285,
305 timerfd_settime = 286,
306 timerfd_gettime = 287,
307 accept4 = 288,
308 signalfd4 = 289,
309 eventfd2 = 290,
310 epoll_create1 = 291,
311 dup3 = 292,
312 pipe2 = 293,
313 inotify_init1 = 294,
314 preadv = 295,
315 pwritev = 296,
316 rt_tgsigqueueinfo = 297,
317 perf_event_open = 298,
318 recvmmsg = 299,
319 fanotify_init = 300,
320 fanotify_mark = 301,
321 prlimit64 = 302,
322 name_to_handle_at = 303,
323 open_by_handle_at = 304,
324 clock_adjtime = 305,
325 syncfs = 306,
326 sendmmsg = 307,
327 setns = 308,
328 getcpu = 309,
329 process_vm_readv = 310,
330 process_vm_writev = 311,
331 kcmp = 312,
332 finit_module = 313,
333 sched_setattr = 314,
334 sched_getattr = 315,
335 renameat2 = 316,
336 seccomp = 317,
337 getrandom = 318,
338 memfd_create = 319,
339 kexec_file_load = 320,
340 bpf = 321,
341 execveat = 322,
342 userfaultfd = 323,
343 membarrier = 324,
344 mlock2 = 325,
345 copy_file_range = 326,
346 preadv2 = 327,
347 pwritev2 = 328,
348 pkey_mprotect = 329,
349 pkey_alloc = 330,
350 pkey_free = 331,
351 statx = 332,
352 io_pgetevents = 333,
353 rseq = 334,
354 pidfd_send_signal = 424,
355 io_uring_setup = 425,
356 io_uring_enter = 426,
357 io_uring_register = 427,
358 open_tree = 428,
359 move_mount = 429,
360 fsopen = 430,
361 fsconfig = 431,
362 fsmount = 432,
363 fspick = 433,
364 pidfd_open = 434,
365 clone3 = 435,
366 openat2 = 437,
367 pidfd_getfd = 438,
368
369 _,
370};
365371
366372pub const O_CREAT = 0o100;
367373pub const O_EXCL = 0o200;
lib/std/os/bits/netbsd.zig+114-26
......@@ -1,12 +1,22 @@
11const std = @import("../../std.zig");
2const builtin = std.builtin;
23const maxInt = std.math.maxInt;
34
5pub const blkcnt_t = i64;
6pub const blksize_t = i32;
7pub const clock_t = u32;
8pub const dev_t = u64;
49pub const fd_t = i32;
5pub const pid_t = i32;
6pub const mode_t = u32;
10pub const gid_t = u32;
711pub const ino_t = u64;
12pub const mode_t = u32;
13pub const nlink_t = u32;
814pub const off_t = i64;
15pub const pid_t = i32;
916pub const socklen_t = u32;
17pub const time_t = i64;
18pub const uid_t = u32;
19pub const lwpid_t = i32;
1020
1121/// Renamed from `kevent` to `Kevent` to avoid conflict with function name.
1222pub const Kevent = extern struct {
......@@ -145,23 +155,20 @@ pub const msghdr_const = extern struct {
145155/// in C, macros are used to hide the differences. Here we use
146156/// methods to accomplish this.
147157pub const Stat = extern struct {
148 dev: u64,
149 mode: u32,
158 dev: dev_t,
159 mode: mode_t,
150160 ino: ino_t,
151 nlink: usize,
152
153 uid: u32,
154 gid: u32,
155 rdev: u64,
156
161 nlink: nlink_t,
162 uid: uid_t,
163 gid: gid_t,
164 rdev: dev_t,
157165 atim: timespec,
158166 mtim: timespec,
159167 ctim: timespec,
160168 birthtim: timespec,
161
162169 size: off_t,
163 blocks: i64,
164 blksize: isize,
170 blocks: blkcnt_t,
171 blksize: blksize_t,
165172 flags: u32,
166173 gen: u32,
167174 __spare: [2]u32,
......@@ -184,12 +191,14 @@ pub const timespec = extern struct {
184191 tv_nsec: isize,
185192};
186193
194pub const MAXNAMLEN = 511;
195
187196pub const dirent = extern struct {
188 d_fileno: u64,
197 d_fileno: ino_t,
189198 d_reclen: u16,
190199 d_namlen: u16,
191200 d_type: u8,
192 d_name: [512]u8,
201 d_name: [MAXNAMLEN:0]u8,
193202
194203 pub fn reclen(self: dirent) u16 {
195204 return self.d_reclen;
......@@ -697,23 +706,74 @@ pub const winsize = extern struct {
697706
698707const NSIG = 32;
699708
700pub const SIG_ERR = @intToPtr(extern fn (i32) void, maxInt(usize));
701pub const SIG_DFL = @intToPtr(extern fn (i32) void, 0);
702pub const SIG_IGN = @intToPtr(extern fn (i32) void, 1);
709pub const SIG_ERR = @intToPtr(?Sigaction.sigaction_fn, maxInt(usize));
710pub const SIG_DFL = @intToPtr(?Sigaction.sigaction_fn, 0);
711pub const SIG_IGN = @intToPtr(?Sigaction.sigaction_fn, 1);
703712
704713/// Renamed from `sigaction` to `Sigaction` to avoid conflict with the syscall.
705714pub const Sigaction = extern struct {
715 pub const sigaction_fn = fn (i32, *siginfo_t, ?*c_void) callconv(.C) void;
706716 /// signal handler
707 __sigaction_u: extern union {
708 __sa_handler: extern fn (i32) void,
709 __sa_sigaction: extern fn (i32, *__siginfo, usize) void,
710 },
717 sigaction: ?sigaction_fn,
718 /// signal mask to apply
719 mask: sigset_t,
720 /// signal options
721 flags: u32,
722};
711723
712 /// see signal options
713 sa_flags: u32,
724pub const sigval_t = extern union {
725 int: i32,
726 ptr: ?*c_void,
727};
714728
715 /// signal mask to apply
716 sa_mask: sigset_t,
729pub const siginfo_t = extern union {
730 pad: [128]u8,
731 info: _ksiginfo,
732};
733
734pub const _ksiginfo = extern struct {
735 signo: i32,
736 code: i32,
737 errno: i32,
738 // 64bit architectures insert 4bytes of padding here, this is done by
739 // correctly aligning the reason field
740 reason: extern union {
741 rt: extern struct {
742 pid: pid_t,
743 uid: uid_t,
744 value: sigval_t,
745 },
746 child: extern struct {
747 pid: pid_t,
748 uid: uid_t,
749 status: i32,
750 utime: clock_t,
751 stime: clock_t,
752 },
753 fault: extern struct {
754 addr: ?*c_void,
755 trap: i32,
756 trap2: i32,
757 trap3: i32,
758 },
759 poll: extern struct {
760 band: i32,
761 fd: i32,
762 },
763 syscall: extern struct {
764 sysnum: i32,
765 retval: [2]i32,
766 @"error": i32,
767 args: [8]u64,
768 },
769 ptrace_state: extern struct {
770 pe_report_event: i32,
771 option: extern union {
772 pe_other_pid: pid_t,
773 pe_lwp: lwpid_t,
774 },
775 },
776 } align(@sizeOf(usize)),
717777};
718778
719779pub const _SIG_WORDS = 4;
......@@ -736,6 +796,34 @@ pub const sigset_t = extern struct {
736796 __bits: [_SIG_WORDS]u32,
737797};
738798
799pub const empty_sigset = sigset_t{ .__bits = [_]u32{0} ** _SIG_WORDS };
800
801// XXX x86_64 specific
802pub const mcontext_t = extern struct {
803 gregs: [26]u64,
804 mc_tlsbase: u64,
805 fpregs: [512]u8 align(8),
806};
807
808pub const REG_RBP = 12;
809pub const REG_RIP = 21;
810pub const REG_RSP = 24;
811
812pub const ucontext_t = extern struct {
813 flags: u32,
814 link: ?*ucontext_t,
815 sigmask: sigset_t,
816 stack: stack_t,
817 mcontext: mcontext_t,
818 __pad: [switch (builtin.arch) {
819 .i386 => 4,
820 .mips, .mipsel, .mips64, .mips64el => 14,
821 .arm, .armeb, .thumb, .thumbeb => 1,
822 .sparc, .sparcel, .sparcv9 => if (@sizeOf(usize) == 4) 43 else 8,
823 else => 0,
824 }]u32,
825};
826
739827pub const EPERM = 1; // Operation not permitted
740828pub const ENOENT = 2; // No such file or directory
741829pub const ESRCH = 3; // No such process
lib/std/os/linux.zig+228-228
......@@ -53,46 +53,46 @@ pub fn getErrno(r: usize) u12 {
5353}
5454
5555pub fn dup2(old: i32, new: i32) usize {
56 if (@hasDecl(@This(), "SYS_dup2")) {
57 return syscall2(SYS_dup2, @bitCast(usize, @as(isize, old)), @bitCast(usize, @as(isize, new)));
56 if (@hasField(SYS, "dup2")) {
57 return syscall2(.dup2, @bitCast(usize, @as(isize, old)), @bitCast(usize, @as(isize, new)));
5858 } else {
5959 if (old == new) {
6060 if (std.debug.runtime_safety) {
61 const rc = syscall2(SYS_fcntl, @bitCast(usize, @as(isize, old)), F_GETFD);
61 const rc = syscall2(.fcntl, @bitCast(usize, @as(isize, old)), F_GETFD);
6262 if (@bitCast(isize, rc) < 0) return rc;
6363 }
6464 return @intCast(usize, old);
6565 } else {
66 return syscall3(SYS_dup3, @bitCast(usize, @as(isize, old)), @bitCast(usize, @as(isize, new)), 0);
66 return syscall3(.dup3, @bitCast(usize, @as(isize, old)), @bitCast(usize, @as(isize, new)), 0);
6767 }
6868 }
6969}
7070
7171pub fn dup3(old: i32, new: i32, flags: u32) usize {
72 return syscall3(SYS_dup3, @bitCast(usize, @as(isize, old)), @bitCast(usize, @as(isize, new)), flags);
72 return syscall3(.dup3, @bitCast(usize, @as(isize, old)), @bitCast(usize, @as(isize, new)), flags);
7373}
7474
7575pub fn chdir(path: [*:0]const u8) usize {
76 return syscall1(SYS_chdir, @ptrToInt(path));
76 return syscall1(.chdir, @ptrToInt(path));
7777}
7878
7979pub fn fchdir(fd: fd_t) usize {
80 return syscall1(SYS_fchdir, @bitCast(usize, @as(isize, fd)));
80 return syscall1(.fchdir, @bitCast(usize, @as(isize, fd)));
8181}
8282
8383pub fn chroot(path: [*:0]const u8) usize {
84 return syscall1(SYS_chroot, @ptrToInt(path));
84 return syscall1(.chroot, @ptrToInt(path));
8585}
8686
8787pub fn execve(path: [*:0]const u8, argv: [*:null]const ?[*:0]const u8, envp: [*:null]const ?[*:0]const u8) usize {
88 return syscall3(SYS_execve, @ptrToInt(path), @ptrToInt(argv), @ptrToInt(envp));
88 return syscall3(.execve, @ptrToInt(path), @ptrToInt(argv), @ptrToInt(envp));
8989}
9090
9191pub fn fork() usize {
92 if (@hasDecl(@This(), "SYS_fork")) {
93 return syscall0(SYS_fork);
92 if (@hasField(SYS, "fork")) {
93 return syscall0(.fork);
9494 } else {
95 return syscall2(SYS_clone, SIGCHLD, 0);
95 return syscall2(.clone, SIGCHLD, 0);
9696 }
9797}
9898
......@@ -102,7 +102,7 @@ pub fn fork() usize {
102102/// the compiler is not aware of how vfork affects control flow and you may
103103/// see different results in optimized builds.
104104pub inline fn vfork() usize {
105 return @call(.{ .modifier = .always_inline }, syscall0, .{SYS_vfork});
105 return @call(.{ .modifier = .always_inline }, syscall0, .{.vfork});
106106}
107107
108108pub fn futimens(fd: i32, times: *const [2]timespec) usize {
......@@ -110,24 +110,24 @@ pub fn futimens(fd: i32, times: *const [2]timespec) usize {
110110}
111111
112112pub fn utimensat(dirfd: i32, path: ?[*:0]const u8, times: *const [2]timespec, flags: u32) usize {
113 return syscall4(SYS_utimensat, @bitCast(usize, @as(isize, dirfd)), @ptrToInt(path), @ptrToInt(times), flags);
113 return syscall4(.utimensat, @bitCast(usize, @as(isize, dirfd)), @ptrToInt(path), @ptrToInt(times), flags);
114114}
115115
116116pub fn futex_wait(uaddr: *const i32, futex_op: u32, val: i32, timeout: ?*timespec) usize {
117 return syscall4(SYS_futex, @ptrToInt(uaddr), futex_op, @bitCast(u32, val), @ptrToInt(timeout));
117 return syscall4(.futex, @ptrToInt(uaddr), futex_op, @bitCast(u32, val), @ptrToInt(timeout));
118118}
119119
120120pub fn futex_wake(uaddr: *const i32, futex_op: u32, val: i32) usize {
121 return syscall3(SYS_futex, @ptrToInt(uaddr), futex_op, @bitCast(u32, val));
121 return syscall3(.futex, @ptrToInt(uaddr), futex_op, @bitCast(u32, val));
122122}
123123
124124pub fn getcwd(buf: [*]u8, size: usize) usize {
125 return syscall2(SYS_getcwd, @ptrToInt(buf), size);
125 return syscall2(.getcwd, @ptrToInt(buf), size);
126126}
127127
128128pub fn getdents(fd: i32, dirp: [*]u8, len: usize) usize {
129129 return syscall3(
130 SYS_getdents,
130 .getdents,
131131 @bitCast(usize, @as(isize, fd)),
132132 @ptrToInt(dirp),
133133 std.math.min(len, maxInt(c_int)),
......@@ -136,7 +136,7 @@ pub fn getdents(fd: i32, dirp: [*]u8, len: usize) usize {
136136
137137pub fn getdents64(fd: i32, dirp: [*]u8, len: usize) usize {
138138 return syscall3(
139 SYS_getdents64,
139 .getdents64,
140140 @bitCast(usize, @as(isize, fd)),
141141 @ptrToInt(dirp),
142142 std.math.min(len, maxInt(c_int)),
......@@ -144,61 +144,61 @@ pub fn getdents64(fd: i32, dirp: [*]u8, len: usize) usize {
144144}
145145
146146pub fn inotify_init1(flags: u32) usize {
147 return syscall1(SYS_inotify_init1, flags);
147 return syscall1(.inotify_init1, flags);
148148}
149149
150150pub fn inotify_add_watch(fd: i32, pathname: [*:0]const u8, mask: u32) usize {
151 return syscall3(SYS_inotify_add_watch, @bitCast(usize, @as(isize, fd)), @ptrToInt(pathname), mask);
151 return syscall3(.inotify_add_watch, @bitCast(usize, @as(isize, fd)), @ptrToInt(pathname), mask);
152152}
153153
154154pub fn inotify_rm_watch(fd: i32, wd: i32) usize {
155 return syscall2(SYS_inotify_rm_watch, @bitCast(usize, @as(isize, fd)), @bitCast(usize, @as(isize, wd)));
155 return syscall2(.inotify_rm_watch, @bitCast(usize, @as(isize, fd)), @bitCast(usize, @as(isize, wd)));
156156}
157157
158158pub fn readlink(noalias path: [*:0]const u8, noalias buf_ptr: [*]u8, buf_len: usize) usize {
159 if (@hasDecl(@This(), "SYS_readlink")) {
160 return syscall3(SYS_readlink, @ptrToInt(path), @ptrToInt(buf_ptr), buf_len);
159 if (@hasField(SYS, "readlink")) {
160 return syscall3(.readlink, @ptrToInt(path), @ptrToInt(buf_ptr), buf_len);
161161 } else {
162 return syscall4(SYS_readlinkat, @bitCast(usize, @as(isize, AT_FDCWD)), @ptrToInt(path), @ptrToInt(buf_ptr), buf_len);
162 return syscall4(.readlinkat, @bitCast(usize, @as(isize, AT_FDCWD)), @ptrToInt(path), @ptrToInt(buf_ptr), buf_len);
163163 }
164164}
165165
166166pub fn readlinkat(dirfd: i32, noalias path: [*:0]const u8, noalias buf_ptr: [*]u8, buf_len: usize) usize {
167 return syscall4(SYS_readlinkat, @bitCast(usize, @as(isize, dirfd)), @ptrToInt(path), @ptrToInt(buf_ptr), buf_len);
167 return syscall4(.readlinkat, @bitCast(usize, @as(isize, dirfd)), @ptrToInt(path), @ptrToInt(buf_ptr), buf_len);
168168}
169169
170170pub fn mkdir(path: [*:0]const u8, mode: u32) usize {
171 if (@hasDecl(@This(), "SYS_mkdir")) {
172 return syscall2(SYS_mkdir, @ptrToInt(path), mode);
171 if (@hasField(SYS, "mkdir")) {
172 return syscall2(.mkdir, @ptrToInt(path), mode);
173173 } else {
174 return syscall3(SYS_mkdirat, @bitCast(usize, @as(isize, AT_FDCWD)), @ptrToInt(path), mode);
174 return syscall3(.mkdirat, @bitCast(usize, @as(isize, AT_FDCWD)), @ptrToInt(path), mode);
175175 }
176176}
177177
178178pub fn mkdirat(dirfd: i32, path: [*:0]const u8, mode: u32) usize {
179 return syscall3(SYS_mkdirat, @bitCast(usize, @as(isize, dirfd)), @ptrToInt(path), mode);
179 return syscall3(.mkdirat, @bitCast(usize, @as(isize, dirfd)), @ptrToInt(path), mode);
180180}
181181
182182pub fn mount(special: [*:0]const u8, dir: [*:0]const u8, fstype: [*:0]const u8, flags: u32, data: usize) usize {
183 return syscall5(SYS_mount, @ptrToInt(special), @ptrToInt(dir), @ptrToInt(fstype), flags, data);
183 return syscall5(.mount, @ptrToInt(special), @ptrToInt(dir), @ptrToInt(fstype), flags, data);
184184}
185185
186186pub fn umount(special: [*:0]const u8) usize {
187 return syscall2(SYS_umount2, @ptrToInt(special), 0);
187 return syscall2(.umount2, @ptrToInt(special), 0);
188188}
189189
190190pub fn umount2(special: [*:0]const u8, flags: u32) usize {
191 return syscall2(SYS_umount2, @ptrToInt(special), flags);
191 return syscall2(.umount2, @ptrToInt(special), flags);
192192}
193193
194194pub fn mmap(address: ?[*]u8, length: usize, prot: usize, flags: u32, fd: i32, offset: u64) usize {
195 if (@hasDecl(@This(), "SYS_mmap2")) {
195 if (@hasField(SYS, "mmap2")) {
196196 // Make sure the offset is also specified in multiples of page size
197197 if ((offset & (MMAP2_UNIT - 1)) != 0)
198198 return @bitCast(usize, @as(isize, -EINVAL));
199199
200200 return syscall6(
201 SYS_mmap2,
201 .mmap2,
202202 @ptrToInt(address),
203203 length,
204204 prot,
......@@ -208,7 +208,7 @@ pub fn mmap(address: ?[*]u8, length: usize, prot: usize, flags: u32, fd: i32, of
208208 );
209209 } else {
210210 return syscall6(
211 SYS_mmap,
211 .mmap,
212212 @ptrToInt(address),
213213 length,
214214 prot,
......@@ -220,19 +220,19 @@ pub fn mmap(address: ?[*]u8, length: usize, prot: usize, flags: u32, fd: i32, of
220220}
221221
222222pub fn mprotect(address: [*]const u8, length: usize, protection: usize) usize {
223 return syscall3(SYS_mprotect, @ptrToInt(address), length, protection);
223 return syscall3(.mprotect, @ptrToInt(address), length, protection);
224224}
225225
226226pub fn munmap(address: [*]const u8, length: usize) usize {
227 return syscall2(SYS_munmap, @ptrToInt(address), length);
227 return syscall2(.munmap, @ptrToInt(address), length);
228228}
229229
230230pub fn poll(fds: [*]pollfd, n: nfds_t, timeout: i32) usize {
231 if (@hasDecl(@This(), "SYS_poll")) {
232 return syscall3(SYS_poll, @ptrToInt(fds), n, @bitCast(u32, timeout));
231 if (@hasField(SYS, "poll")) {
232 return syscall3(.poll, @ptrToInt(fds), n, @bitCast(u32, timeout));
233233 } else {
234234 return syscall6(
235 SYS_ppoll,
235 .ppoll,
236236 @ptrToInt(fds),
237237 n,
238238 @ptrToInt(if (timeout >= 0)
......@@ -250,12 +250,12 @@ pub fn poll(fds: [*]pollfd, n: nfds_t, timeout: i32) usize {
250250}
251251
252252pub fn read(fd: i32, buf: [*]u8, count: usize) usize {
253 return syscall3(SYS_read, @bitCast(usize, @as(isize, fd)), @ptrToInt(buf), count);
253 return syscall3(.read, @bitCast(usize, @as(isize, fd)), @ptrToInt(buf), count);
254254}
255255
256256pub fn preadv(fd: i32, iov: [*]const iovec, count: usize, offset: u64) usize {
257257 return syscall5(
258 SYS_preadv,
258 .preadv,
259259 @bitCast(usize, @as(isize, fd)),
260260 @ptrToInt(iov),
261261 count,
......@@ -266,7 +266,7 @@ pub fn preadv(fd: i32, iov: [*]const iovec, count: usize, offset: u64) usize {
266266
267267pub fn preadv2(fd: i32, iov: [*]const iovec, count: usize, offset: u64, flags: kernel_rwf) usize {
268268 return syscall6(
269 SYS_preadv2,
269 .preadv2,
270270 @bitCast(usize, @as(isize, fd)),
271271 @ptrToInt(iov),
272272 count,
......@@ -277,16 +277,16 @@ pub fn preadv2(fd: i32, iov: [*]const iovec, count: usize, offset: u64, flags: k
277277}
278278
279279pub fn readv(fd: i32, iov: [*]const iovec, count: usize) usize {
280 return syscall3(SYS_readv, @bitCast(usize, @as(isize, fd)), @ptrToInt(iov), count);
280 return syscall3(.readv, @bitCast(usize, @as(isize, fd)), @ptrToInt(iov), count);
281281}
282282
283283pub fn writev(fd: i32, iov: [*]const iovec_const, count: usize) usize {
284 return syscall3(SYS_writev, @bitCast(usize, @as(isize, fd)), @ptrToInt(iov), count);
284 return syscall3(.writev, @bitCast(usize, @as(isize, fd)), @ptrToInt(iov), count);
285285}
286286
287287pub fn pwritev(fd: i32, iov: [*]const iovec_const, count: usize, offset: u64) usize {
288288 return syscall5(
289 SYS_pwritev,
289 .pwritev,
290290 @bitCast(usize, @as(isize, fd)),
291291 @ptrToInt(iov),
292292 count,
......@@ -297,7 +297,7 @@ pub fn pwritev(fd: i32, iov: [*]const iovec_const, count: usize, offset: u64) us
297297
298298pub fn pwritev2(fd: i32, iov: [*]const iovec_const, count: usize, offset: u64, flags: kernel_rwf) usize {
299299 return syscall6(
300 SYS_pwritev2,
300 .pwritev2,
301301 @bitCast(usize, @as(isize, fd)),
302302 @ptrToInt(iov),
303303 count,
......@@ -308,30 +308,30 @@ pub fn pwritev2(fd: i32, iov: [*]const iovec_const, count: usize, offset: u64, f
308308}
309309
310310pub fn rmdir(path: [*:0]const u8) usize {
311 if (@hasDecl(@This(), "SYS_rmdir")) {
312 return syscall1(SYS_rmdir, @ptrToInt(path));
311 if (@hasField(SYS, "rmdir")) {
312 return syscall1(.rmdir, @ptrToInt(path));
313313 } else {
314 return syscall3(SYS_unlinkat, @bitCast(usize, @as(isize, AT_FDCWD)), @ptrToInt(path), AT_REMOVEDIR);
314 return syscall3(.unlinkat, @bitCast(usize, @as(isize, AT_FDCWD)), @ptrToInt(path), AT_REMOVEDIR);
315315 }
316316}
317317
318318pub fn symlink(existing: [*:0]const u8, new: [*:0]const u8) usize {
319 if (@hasDecl(@This(), "SYS_symlink")) {
320 return syscall2(SYS_symlink, @ptrToInt(existing), @ptrToInt(new));
319 if (@hasField(SYS, "symlink")) {
320 return syscall2(.symlink, @ptrToInt(existing), @ptrToInt(new));
321321 } else {
322 return syscall3(SYS_symlinkat, @ptrToInt(existing), @bitCast(usize, @as(isize, AT_FDCWD)), @ptrToInt(new));
322 return syscall3(.symlinkat, @ptrToInt(existing), @bitCast(usize, @as(isize, AT_FDCWD)), @ptrToInt(new));
323323 }
324324}
325325
326326pub fn symlinkat(existing: [*:0]const u8, newfd: i32, newpath: [*:0]const u8) usize {
327 return syscall3(SYS_symlinkat, @ptrToInt(existing), @bitCast(usize, @as(isize, newfd)), @ptrToInt(newpath));
327 return syscall3(.symlinkat, @ptrToInt(existing), @bitCast(usize, @as(isize, newfd)), @ptrToInt(newpath));
328328}
329329
330330pub fn pread(fd: i32, buf: [*]u8, count: usize, offset: u64) usize {
331 if (@hasDecl(@This(), "SYS_pread64")) {
331 if (@hasField(SYS, "pread64")) {
332332 if (require_aligned_register_pair) {
333333 return syscall6(
334 SYS_pread64,
334 .pread64,
335335 @bitCast(usize, @as(isize, fd)),
336336 @ptrToInt(buf),
337337 count,
......@@ -341,7 +341,7 @@ pub fn pread(fd: i32, buf: [*]u8, count: usize, offset: u64) usize {
341341 );
342342 } else {
343343 return syscall5(
344 SYS_pread64,
344 .pread64,
345345 @bitCast(usize, @as(isize, fd)),
346346 @ptrToInt(buf),
347347 count,
......@@ -351,7 +351,7 @@ pub fn pread(fd: i32, buf: [*]u8, count: usize, offset: u64) usize {
351351 }
352352 } else {
353353 return syscall4(
354 SYS_pread,
354 .pread,
355355 @bitCast(usize, @as(isize, fd)),
356356 @ptrToInt(buf),
357357 count,
......@@ -361,40 +361,40 @@ pub fn pread(fd: i32, buf: [*]u8, count: usize, offset: u64) usize {
361361}
362362
363363pub fn access(path: [*:0]const u8, mode: u32) usize {
364 if (@hasDecl(@This(), "SYS_access")) {
365 return syscall2(SYS_access, @ptrToInt(path), mode);
364 if (@hasField(SYS, "access")) {
365 return syscall2(.access, @ptrToInt(path), mode);
366366 } else {
367 return syscall4(SYS_faccessat, @bitCast(usize, @as(isize, AT_FDCWD)), @ptrToInt(path), mode, 0);
367 return syscall4(.faccessat, @bitCast(usize, @as(isize, AT_FDCWD)), @ptrToInt(path), mode, 0);
368368 }
369369}
370370
371371pub fn faccessat(dirfd: i32, path: [*:0]const u8, mode: u32, flags: u32) usize {
372 return syscall4(SYS_faccessat, @bitCast(usize, @as(isize, dirfd)), @ptrToInt(path), mode, flags);
372 return syscall4(.faccessat, @bitCast(usize, @as(isize, dirfd)), @ptrToInt(path), mode, flags);
373373}
374374
375375pub fn pipe(fd: *[2]i32) usize {
376376 if (comptime builtin.arch.isMIPS()) {
377377 return syscall_pipe(fd);
378 } else if (@hasDecl(@This(), "SYS_pipe")) {
379 return syscall1(SYS_pipe, @ptrToInt(fd));
378 } else if (@hasField(SYS, "pipe")) {
379 return syscall1(.pipe, @ptrToInt(fd));
380380 } else {
381 return syscall2(SYS_pipe2, @ptrToInt(fd), 0);
381 return syscall2(.pipe2, @ptrToInt(fd), 0);
382382 }
383383}
384384
385385pub fn pipe2(fd: *[2]i32, flags: u32) usize {
386 return syscall2(SYS_pipe2, @ptrToInt(fd), flags);
386 return syscall2(.pipe2, @ptrToInt(fd), flags);
387387}
388388
389389pub fn write(fd: i32, buf: [*]const u8, count: usize) usize {
390 return syscall3(SYS_write, @bitCast(usize, @as(isize, fd)), @ptrToInt(buf), count);
390 return syscall3(.write, @bitCast(usize, @as(isize, fd)), @ptrToInt(buf), count);
391391}
392392
393393pub fn ftruncate(fd: i32, length: u64) usize {
394 if (@hasDecl(@This(), "SYS_ftruncate64")) {
394 if (@hasField(SYS, "ftruncate64")) {
395395 if (require_aligned_register_pair) {
396396 return syscall4(
397 SYS_ftruncate64,
397 .ftruncate64,
398398 @bitCast(usize, @as(isize, fd)),
399399 0,
400400 @truncate(usize, length),
......@@ -402,7 +402,7 @@ pub fn ftruncate(fd: i32, length: u64) usize {
402402 );
403403 } else {
404404 return syscall3(
405 SYS_ftruncate64,
405 .ftruncate64,
406406 @bitCast(usize, @as(isize, fd)),
407407 @truncate(usize, length),
408408 @truncate(usize, length >> 32),
......@@ -410,7 +410,7 @@ pub fn ftruncate(fd: i32, length: u64) usize {
410410 }
411411 } else {
412412 return syscall2(
413 SYS_ftruncate,
413 .ftruncate,
414414 @bitCast(usize, @as(isize, fd)),
415415 @truncate(usize, length),
416416 );
......@@ -418,10 +418,10 @@ pub fn ftruncate(fd: i32, length: u64) usize {
418418}
419419
420420pub fn pwrite(fd: i32, buf: [*]const u8, count: usize, offset: usize) usize {
421 if (@hasDecl(@This(), "SYS_pwrite64")) {
421 if (@hasField(SYS, "pwrite64")) {
422422 if (require_aligned_register_pair) {
423423 return syscall6(
424 SYS_pwrite64,
424 .pwrite64,
425425 @bitCast(usize, @as(isize, fd)),
426426 @ptrToInt(buf),
427427 count,
......@@ -431,7 +431,7 @@ pub fn pwrite(fd: i32, buf: [*]const u8, count: usize, offset: usize) usize {
431431 );
432432 } else {
433433 return syscall5(
434 SYS_pwrite64,
434 .pwrite64,
435435 @bitCast(usize, @as(isize, fd)),
436436 @ptrToInt(buf),
437437 count,
......@@ -441,7 +441,7 @@ pub fn pwrite(fd: i32, buf: [*]const u8, count: usize, offset: usize) usize {
441441 }
442442 } else {
443443 return syscall4(
444 SYS_pwrite,
444 .pwrite,
445445 @bitCast(usize, @as(isize, fd)),
446446 @ptrToInt(buf),
447447 count,
......@@ -451,19 +451,19 @@ pub fn pwrite(fd: i32, buf: [*]const u8, count: usize, offset: usize) usize {
451451}
452452
453453pub fn rename(old: [*:0]const u8, new: [*:0]const u8) usize {
454 if (@hasDecl(@This(), "SYS_rename")) {
455 return syscall2(SYS_rename, @ptrToInt(old), @ptrToInt(new));
456 } else if (@hasDecl(@This(), "SYS_renameat")) {
457 return syscall4(SYS_renameat, @bitCast(usize, @as(isize, AT_FDCWD)), @ptrToInt(old), @bitCast(usize, @as(isize, AT_FDCWD)), @ptrToInt(new));
454 if (@hasField(SYS, "rename")) {
455 return syscall2(.rename, @ptrToInt(old), @ptrToInt(new));
456 } else if (@hasField(SYS, "renameat")) {
457 return syscall4(.renameat, @bitCast(usize, @as(isize, AT_FDCWD)), @ptrToInt(old), @bitCast(usize, @as(isize, AT_FDCWD)), @ptrToInt(new));
458458 } else {
459 return syscall5(SYS_renameat2, @bitCast(usize, @as(isize, AT_FDCWD)), @ptrToInt(old), @bitCast(usize, @as(isize, AT_FDCWD)), @ptrToInt(new), 0);
459 return syscall5(.renameat2, @bitCast(usize, @as(isize, AT_FDCWD)), @ptrToInt(old), @bitCast(usize, @as(isize, AT_FDCWD)), @ptrToInt(new), 0);
460460 }
461461}
462462
463463pub fn renameat(oldfd: i32, oldpath: [*]const u8, newfd: i32, newpath: [*]const u8) usize {
464 if (@hasDecl(@This(), "SYS_renameat")) {
464 if (@hasField(SYS, "renameat")) {
465465 return syscall4(
466 SYS_renameat,
466 .renameat,
467467 @bitCast(usize, @as(isize, oldfd)),
468468 @ptrToInt(oldpath),
469469 @bitCast(usize, @as(isize, newfd)),
......@@ -471,7 +471,7 @@ pub fn renameat(oldfd: i32, oldpath: [*]const u8, newfd: i32, newpath: [*]const
471471 );
472472 } else {
473473 return syscall5(
474 SYS_renameat2,
474 .renameat2,
475475 @bitCast(usize, @as(isize, oldfd)),
476476 @ptrToInt(oldpath),
477477 @bitCast(usize, @as(isize, newfd)),
......@@ -483,7 +483,7 @@ pub fn renameat(oldfd: i32, oldpath: [*]const u8, newfd: i32, newpath: [*]const
483483
484484pub fn renameat2(oldfd: i32, oldpath: [*:0]const u8, newfd: i32, newpath: [*:0]const u8, flags: u32) usize {
485485 return syscall5(
486 SYS_renameat2,
486 .renameat2,
487487 @bitCast(usize, @as(isize, oldfd)),
488488 @ptrToInt(oldpath),
489489 @bitCast(usize, @as(isize, newfd)),
......@@ -493,11 +493,11 @@ pub fn renameat2(oldfd: i32, oldpath: [*:0]const u8, newfd: i32, newpath: [*:0]c
493493}
494494
495495pub fn open(path: [*:0]const u8, flags: u32, perm: usize) usize {
496 if (@hasDecl(@This(), "SYS_open")) {
497 return syscall3(SYS_open, @ptrToInt(path), flags, perm);
496 if (@hasField(SYS, "open")) {
497 return syscall3(.open, @ptrToInt(path), flags, perm);
498498 } else {
499499 return syscall4(
500 SYS_openat,
500 .openat,
501501 @bitCast(usize, @as(isize, AT_FDCWD)),
502502 @ptrToInt(path),
503503 flags,
......@@ -507,32 +507,32 @@ pub fn open(path: [*:0]const u8, flags: u32, perm: usize) usize {
507507}
508508
509509pub fn create(path: [*:0]const u8, perm: usize) usize {
510 return syscall2(SYS_creat, @ptrToInt(path), perm);
510 return syscall2(.creat, @ptrToInt(path), perm);
511511}
512512
513513pub fn openat(dirfd: i32, path: [*:0]const u8, flags: u32, mode: usize) usize {
514514 // dirfd could be negative, for example AT_FDCWD is -100
515 return syscall4(SYS_openat, @bitCast(usize, @as(isize, dirfd)), @ptrToInt(path), flags, mode);
515 return syscall4(.openat, @bitCast(usize, @as(isize, dirfd)), @ptrToInt(path), flags, mode);
516516}
517517
518518/// See also `clone` (from the arch-specific include)
519519pub fn clone5(flags: usize, child_stack_ptr: usize, parent_tid: *i32, child_tid: *i32, newtls: usize) usize {
520 return syscall5(SYS_clone, flags, child_stack_ptr, @ptrToInt(parent_tid), @ptrToInt(child_tid), newtls);
520 return syscall5(.clone, flags, child_stack_ptr, @ptrToInt(parent_tid), @ptrToInt(child_tid), newtls);
521521}
522522
523523/// See also `clone` (from the arch-specific include)
524524pub fn clone2(flags: u32, child_stack_ptr: usize) usize {
525 return syscall2(SYS_clone, flags, child_stack_ptr);
525 return syscall2(.clone, flags, child_stack_ptr);
526526}
527527
528528pub fn close(fd: i32) usize {
529 return syscall1(SYS_close, @bitCast(usize, @as(isize, fd)));
529 return syscall1(.close, @bitCast(usize, @as(isize, fd)));
530530}
531531
532532/// Can only be called on 32 bit systems. For 64 bit see `lseek`.
533533pub fn llseek(fd: i32, offset: u64, result: ?*u64, whence: usize) usize {
534534 return syscall5(
535 SYS__llseek,
535 ._llseek,
536536 @bitCast(usize, @as(isize, fd)),
537537 @truncate(usize, offset >> 32),
538538 @truncate(usize, offset),
......@@ -543,53 +543,53 @@ pub fn llseek(fd: i32, offset: u64, result: ?*u64, whence: usize) usize {
543543
544544/// Can only be called on 64 bit systems. For 32 bit see `llseek`.
545545pub fn lseek(fd: i32, offset: i64, whence: usize) usize {
546 return syscall3(SYS_lseek, @bitCast(usize, @as(isize, fd)), @bitCast(usize, offset), whence);
546 return syscall3(.lseek, @bitCast(usize, @as(isize, fd)), @bitCast(usize, offset), whence);
547547}
548548
549549pub fn exit(status: i32) noreturn {
550 _ = syscall1(SYS_exit, @bitCast(usize, @as(isize, status)));
550 _ = syscall1(.exit, @bitCast(usize, @as(isize, status)));
551551 unreachable;
552552}
553553
554554pub fn exit_group(status: i32) noreturn {
555 _ = syscall1(SYS_exit_group, @bitCast(usize, @as(isize, status)));
555 _ = syscall1(.exit_group, @bitCast(usize, @as(isize, status)));
556556 unreachable;
557557}
558558
559559pub fn getrandom(buf: [*]u8, count: usize, flags: u32) usize {
560 return syscall3(SYS_getrandom, @ptrToInt(buf), count, flags);
560 return syscall3(.getrandom, @ptrToInt(buf), count, flags);
561561}
562562
563563pub fn kill(pid: pid_t, sig: i32) usize {
564 return syscall2(SYS_kill, @bitCast(usize, @as(isize, pid)), @bitCast(usize, @as(isize, sig)));
564 return syscall2(.kill, @bitCast(usize, @as(isize, pid)), @bitCast(usize, @as(isize, sig)));
565565}
566566
567567pub fn tkill(tid: pid_t, sig: i32) usize {
568 return syscall2(SYS_tkill, @bitCast(usize, @as(isize, tid)), @bitCast(usize, @as(isize, sig)));
568 return syscall2(.tkill, @bitCast(usize, @as(isize, tid)), @bitCast(usize, @as(isize, sig)));
569569}
570570
571571pub fn tgkill(tgid: pid_t, tid: pid_t, sig: i32) usize {
572 return syscall2(SYS_tgkill, @bitCast(usize, @as(isize, tgid)), @bitCast(usize, @as(isize, tid)), @bitCast(usize, @as(isize, sig)));
572 return syscall2(.tgkill, @bitCast(usize, @as(isize, tgid)), @bitCast(usize, @as(isize, tid)), @bitCast(usize, @as(isize, sig)));
573573}
574574
575575pub fn unlink(path: [*:0]const u8) usize {
576 if (@hasDecl(@This(), "SYS_unlink")) {
577 return syscall1(SYS_unlink, @ptrToInt(path));
576 if (@hasField(SYS, "unlink")) {
577 return syscall1(.unlink, @ptrToInt(path));
578578 } else {
579 return syscall3(SYS_unlinkat, @bitCast(usize, @as(isize, AT_FDCWD)), @ptrToInt(path), 0);
579 return syscall3(.unlinkat, @bitCast(usize, @as(isize, AT_FDCWD)), @ptrToInt(path), 0);
580580 }
581581}
582582
583583pub fn unlinkat(dirfd: i32, path: [*:0]const u8, flags: u32) usize {
584 return syscall3(SYS_unlinkat, @bitCast(usize, @as(isize, dirfd)), @ptrToInt(path), flags);
584 return syscall3(.unlinkat, @bitCast(usize, @as(isize, dirfd)), @ptrToInt(path), flags);
585585}
586586
587587pub fn waitpid(pid: pid_t, status: *u32, flags: u32) usize {
588 return syscall4(SYS_wait4, @bitCast(usize, @as(isize, pid)), @ptrToInt(status), flags, 0);
588 return syscall4(.wait4, @bitCast(usize, @as(isize, pid)), @ptrToInt(status), flags, 0);
589589}
590590
591591pub fn fcntl(fd: fd_t, cmd: i32, arg: usize) usize {
592 return syscall3(SYS_fcntl, @bitCast(usize, @as(isize, fd)), @bitCast(usize, @as(isize, cmd)), arg);
592 return syscall3(.fcntl, @bitCast(usize, @as(isize, fd)), @bitCast(usize, @as(isize, cmd)), arg);
593593}
594594
595595var vdso_clock_gettime = @ptrCast(?*const c_void, init_vdso_clock_gettime);
......@@ -609,7 +609,7 @@ pub fn clock_gettime(clk_id: i32, tp: *timespec) usize {
609609 }
610610 }
611611 }
612 return syscall2(SYS_clock_gettime, @bitCast(usize, @as(isize, clk_id)), @ptrToInt(tp));
612 return syscall2(.clock_gettime, @bitCast(usize, @as(isize, clk_id)), @ptrToInt(tp));
613613}
614614
615615fn init_vdso_clock_gettime(clk: i32, ts: *timespec) callconv(.C) usize {
......@@ -626,86 +626,86 @@ fn init_vdso_clock_gettime(clk: i32, ts: *timespec) callconv(.C) usize {
626626}
627627
628628pub fn clock_getres(clk_id: i32, tp: *timespec) usize {
629 return syscall2(SYS_clock_getres, @bitCast(usize, @as(isize, clk_id)), @ptrToInt(tp));
629 return syscall2(.clock_getres, @bitCast(usize, @as(isize, clk_id)), @ptrToInt(tp));
630630}
631631
632632pub fn clock_settime(clk_id: i32, tp: *const timespec) usize {
633 return syscall2(SYS_clock_settime, @bitCast(usize, @as(isize, clk_id)), @ptrToInt(tp));
633 return syscall2(.clock_settime, @bitCast(usize, @as(isize, clk_id)), @ptrToInt(tp));
634634}
635635
636636pub fn gettimeofday(tv: *timeval, tz: *timezone) usize {
637 return syscall2(SYS_gettimeofday, @ptrToInt(tv), @ptrToInt(tz));
637 return syscall2(.gettimeofday, @ptrToInt(tv), @ptrToInt(tz));
638638}
639639
640640pub fn settimeofday(tv: *const timeval, tz: *const timezone) usize {
641 return syscall2(SYS_settimeofday, @ptrToInt(tv), @ptrToInt(tz));
641 return syscall2(.settimeofday, @ptrToInt(tv), @ptrToInt(tz));
642642}
643643
644644pub fn nanosleep(req: *const timespec, rem: ?*timespec) usize {
645 return syscall2(SYS_nanosleep, @ptrToInt(req), @ptrToInt(rem));
645 return syscall2(.nanosleep, @ptrToInt(req), @ptrToInt(rem));
646646}
647647
648648pub fn setuid(uid: u32) usize {
649 if (@hasDecl(@This(), "SYS_setuid32")) {
650 return syscall1(SYS_setuid32, uid);
649 if (@hasField(SYS, "setuid32")) {
650 return syscall1(.setuid32, uid);
651651 } else {
652 return syscall1(SYS_setuid, uid);
652 return syscall1(.setuid, uid);
653653 }
654654}
655655
656656pub fn setgid(gid: u32) usize {
657 if (@hasDecl(@This(), "SYS_setgid32")) {
658 return syscall1(SYS_setgid32, gid);
657 if (@hasField(SYS, "setgid32")) {
658 return syscall1(.setgid32, gid);
659659 } else {
660 return syscall1(SYS_setgid, gid);
660 return syscall1(.setgid, gid);
661661 }
662662}
663663
664664pub fn setreuid(ruid: u32, euid: u32) usize {
665 if (@hasDecl(@This(), "SYS_setreuid32")) {
666 return syscall2(SYS_setreuid32, ruid, euid);
665 if (@hasField(SYS, "setreuid32")) {
666 return syscall2(.setreuid32, ruid, euid);
667667 } else {
668 return syscall2(SYS_setreuid, ruid, euid);
668 return syscall2(.setreuid, ruid, euid);
669669 }
670670}
671671
672672pub fn setregid(rgid: u32, egid: u32) usize {
673 if (@hasDecl(@This(), "SYS_setregid32")) {
674 return syscall2(SYS_setregid32, rgid, egid);
673 if (@hasField(SYS, "setregid32")) {
674 return syscall2(.setregid32, rgid, egid);
675675 } else {
676 return syscall2(SYS_setregid, rgid, egid);
676 return syscall2(.setregid, rgid, egid);
677677 }
678678}
679679
680680pub fn getuid() u32 {
681 if (@hasDecl(@This(), "SYS_getuid32")) {
682 return @as(u32, syscall0(SYS_getuid32));
681 if (@hasField(SYS, "getuid32")) {
682 return @as(u32, syscall0(.getuid32));
683683 } else {
684 return @as(u32, syscall0(SYS_getuid));
684 return @as(u32, syscall0(.getuid));
685685 }
686686}
687687
688688pub fn getgid() u32 {
689 if (@hasDecl(@This(), "SYS_getgid32")) {
690 return @as(u32, syscall0(SYS_getgid32));
689 if (@hasField(SYS, "getgid32")) {
690 return @as(u32, syscall0(.getgid32));
691691 } else {
692 return @as(u32, syscall0(SYS_getgid));
692 return @as(u32, syscall0(.getgid));
693693 }
694694}
695695
696696pub fn geteuid() u32 {
697 if (@hasDecl(@This(), "SYS_geteuid32")) {
698 return @as(u32, syscall0(SYS_geteuid32));
697 if (@hasField(SYS, "geteuid32")) {
698 return @as(u32, syscall0(.geteuid32));
699699 } else {
700 return @as(u32, syscall0(SYS_geteuid));
700 return @as(u32, syscall0(.geteuid));
701701 }
702702}
703703
704704pub fn getegid() u32 {
705 if (@hasDecl(@This(), "SYS_getegid32")) {
706 return @as(u32, syscall0(SYS_getegid32));
705 if (@hasField(SYS, "getegid32")) {
706 return @as(u32, syscall0(.getegid32));
707707 } else {
708 return @as(u32, syscall0(SYS_getegid));
708 return @as(u32, syscall0(.getegid));
709709 }
710710}
711711
......@@ -718,63 +718,63 @@ pub fn setegid(egid: u32) usize {
718718}
719719
720720pub fn getresuid(ruid: *u32, euid: *u32, suid: *u32) usize {
721 if (@hasDecl(@This(), "SYS_getresuid32")) {
722 return syscall3(SYS_getresuid32, @ptrToInt(ruid), @ptrToInt(euid), @ptrToInt(suid));
721 if (@hasField(SYS, "getresuid32")) {
722 return syscall3(.getresuid32, @ptrToInt(ruid), @ptrToInt(euid), @ptrToInt(suid));
723723 } else {
724 return syscall3(SYS_getresuid, @ptrToInt(ruid), @ptrToInt(euid), @ptrToInt(suid));
724 return syscall3(.getresuid, @ptrToInt(ruid), @ptrToInt(euid), @ptrToInt(suid));
725725 }
726726}
727727
728728pub fn getresgid(rgid: *u32, egid: *u32, sgid: *u32) usize {
729 if (@hasDecl(@This(), "SYS_getresgid32")) {
730 return syscall3(SYS_getresgid32, @ptrToInt(rgid), @ptrToInt(egid), @ptrToInt(sgid));
729 if (@hasField(SYS, "getresgid32")) {
730 return syscall3(.getresgid32, @ptrToInt(rgid), @ptrToInt(egid), @ptrToInt(sgid));
731731 } else {
732 return syscall3(SYS_getresgid, @ptrToInt(rgid), @ptrToInt(egid), @ptrToInt(sgid));
732 return syscall3(.getresgid, @ptrToInt(rgid), @ptrToInt(egid), @ptrToInt(sgid));
733733 }
734734}
735735
736736pub fn setresuid(ruid: u32, euid: u32, suid: u32) usize {
737 if (@hasDecl(@This(), "SYS_setresuid32")) {
738 return syscall3(SYS_setresuid32, ruid, euid, suid);
737 if (@hasField(SYS, "setresuid32")) {
738 return syscall3(.setresuid32, ruid, euid, suid);
739739 } else {
740 return syscall3(SYS_setresuid, ruid, euid, suid);
740 return syscall3(.setresuid, ruid, euid, suid);
741741 }
742742}
743743
744744pub fn setresgid(rgid: u32, egid: u32, sgid: u32) usize {
745 if (@hasDecl(@This(), "SYS_setresgid32")) {
746 return syscall3(SYS_setresgid32, rgid, egid, sgid);
745 if (@hasField(SYS, "setresgid32")) {
746 return syscall3(.setresgid32, rgid, egid, sgid);
747747 } else {
748 return syscall3(SYS_setresgid, rgid, egid, sgid);
748 return syscall3(.setresgid, rgid, egid, sgid);
749749 }
750750}
751751
752752pub fn getgroups(size: usize, list: *u32) usize {
753 if (@hasDecl(@This(), "SYS_getgroups32")) {
754 return syscall2(SYS_getgroups32, size, @ptrToInt(list));
753 if (@hasField(SYS, "getgroups32")) {
754 return syscall2(.getgroups32, size, @ptrToInt(list));
755755 } else {
756 return syscall2(SYS_getgroups, size, @ptrToInt(list));
756 return syscall2(.getgroups, size, @ptrToInt(list));
757757 }
758758}
759759
760760pub fn setgroups(size: usize, list: *const u32) usize {
761 if (@hasDecl(@This(), "SYS_setgroups32")) {
762 return syscall2(SYS_setgroups32, size, @ptrToInt(list));
761 if (@hasField(SYS, "setgroups32")) {
762 return syscall2(.setgroups32, size, @ptrToInt(list));
763763 } else {
764 return syscall2(SYS_setgroups, size, @ptrToInt(list));
764 return syscall2(.setgroups, size, @ptrToInt(list));
765765 }
766766}
767767
768768pub fn getpid() pid_t {
769 return @bitCast(pid_t, @truncate(u32, syscall0(SYS_getpid)));
769 return @bitCast(pid_t, @truncate(u32, syscall0(.getpid)));
770770}
771771
772772pub fn gettid() pid_t {
773 return @bitCast(pid_t, @truncate(u32, syscall0(SYS_gettid)));
773 return @bitCast(pid_t, @truncate(u32, syscall0(.gettid)));
774774}
775775
776776pub fn sigprocmask(flags: u32, noalias set: ?*const sigset_t, noalias oldset: ?*sigset_t) usize {
777 return syscall4(SYS_rt_sigprocmask, flags, @ptrToInt(set), @ptrToInt(oldset), NSIG / 8);
777 return syscall4(.rt_sigprocmask, flags, @ptrToInt(set), @ptrToInt(oldset), NSIG / 8);
778778}
779779
780780pub fn sigaction(sig: u6, noalias act: *const Sigaction, noalias oact: ?*Sigaction) usize {
......@@ -792,7 +792,7 @@ pub fn sigaction(sig: u6, noalias act: *const Sigaction, noalias oact: ?*Sigacti
792792 var ksa_old: k_sigaction = undefined;
793793 const ksa_mask_size = @sizeOf(@TypeOf(ksa_old.mask));
794794 @memcpy(@ptrCast([*]u8, &ksa.mask), @ptrCast([*]const u8, &act.mask), ksa_mask_size);
795 const result = syscall4(SYS_rt_sigaction, sig, @ptrToInt(&ksa), @ptrToInt(&ksa_old), ksa_mask_size);
795 const result = syscall4(.rt_sigaction, sig, @ptrToInt(&ksa), @ptrToInt(&ksa_old), ksa_mask_size);
796796 const err = getErrno(result);
797797 if (err != 0) {
798798 return result;
......@@ -819,42 +819,42 @@ pub fn getsockname(fd: i32, noalias addr: *sockaddr, noalias len: *socklen_t) us
819819 if (builtin.arch == .i386) {
820820 return socketcall(SC_getsockname, &[3]usize{ @bitCast(usize, @as(isize, fd)), @ptrToInt(addr), @ptrToInt(len) });
821821 }
822 return syscall3(SYS_getsockname, @bitCast(usize, @as(isize, fd)), @ptrToInt(addr), @ptrToInt(len));
822 return syscall3(.getsockname, @bitCast(usize, @as(isize, fd)), @ptrToInt(addr), @ptrToInt(len));
823823}
824824
825825pub fn getpeername(fd: i32, noalias addr: *sockaddr, noalias len: *socklen_t) usize {
826826 if (builtin.arch == .i386) {
827827 return socketcall(SC_getpeername, &[3]usize{ @bitCast(usize, @as(isize, fd)), @ptrToInt(addr), @ptrToInt(len) });
828828 }
829 return syscall3(SYS_getpeername, @bitCast(usize, @as(isize, fd)), @ptrToInt(addr), @ptrToInt(len));
829 return syscall3(.getpeername, @bitCast(usize, @as(isize, fd)), @ptrToInt(addr), @ptrToInt(len));
830830}
831831
832832pub fn socket(domain: u32, socket_type: u32, protocol: u32) usize {
833833 if (builtin.arch == .i386) {
834834 return socketcall(SC_socket, &[3]usize{ domain, socket_type, protocol });
835835 }
836 return syscall3(SYS_socket, domain, socket_type, protocol);
836 return syscall3(.socket, domain, socket_type, protocol);
837837}
838838
839839pub fn setsockopt(fd: i32, level: u32, optname: u32, optval: [*]const u8, optlen: socklen_t) usize {
840840 if (builtin.arch == .i386) {
841841 return socketcall(SC_setsockopt, &[5]usize{ @bitCast(usize, @as(isize, fd)), level, optname, @ptrToInt(optval), @intCast(usize, optlen) });
842842 }
843 return syscall5(SYS_setsockopt, @bitCast(usize, @as(isize, fd)), level, optname, @ptrToInt(optval), @intCast(usize, optlen));
843 return syscall5(.setsockopt, @bitCast(usize, @as(isize, fd)), level, optname, @ptrToInt(optval), @intCast(usize, optlen));
844844}
845845
846846pub fn getsockopt(fd: i32, level: u32, optname: u32, noalias optval: [*]u8, noalias optlen: *socklen_t) usize {
847847 if (builtin.arch == .i386) {
848848 return socketcall(SC_getsockopt, &[5]usize{ @bitCast(usize, @as(isize, fd)), level, optname, @ptrToInt(optval), @ptrToInt(optlen) });
849849 }
850 return syscall5(SYS_getsockopt, @bitCast(usize, @as(isize, fd)), level, optname, @ptrToInt(optval), @ptrToInt(optlen));
850 return syscall5(.getsockopt, @bitCast(usize, @as(isize, fd)), level, optname, @ptrToInt(optval), @ptrToInt(optlen));
851851}
852852
853853pub fn sendmsg(fd: i32, msg: *msghdr_const, flags: u32) usize {
854854 if (builtin.arch == .i386) {
855855 return socketcall(SC_sendmsg, &[3]usize{ @bitCast(usize, @as(isize, fd)), @ptrToInt(msg), flags });
856856 }
857 return syscall3(SYS_sendmsg, @bitCast(usize, @as(isize, fd)), @ptrToInt(msg), flags);
857 return syscall3(.sendmsg, @bitCast(usize, @as(isize, fd)), @ptrToInt(msg), flags);
858858}
859859
860860pub fn sendmmsg(fd: i32, msgvec: [*]mmsghdr_const, vlen: u32, flags: u32) usize {
......@@ -872,7 +872,7 @@ pub fn sendmmsg(fd: i32, msgvec: [*]mmsghdr_const, vlen: u32, flags: u32) usize
872872 // batch-send all messages up to the current message
873873 if (next_unsent < i) {
874874 const batch_size = i - next_unsent;
875 const r = syscall4(SYS_sendmmsg, @bitCast(usize, @as(isize, fd)), @ptrToInt(&msgvec[next_unsent]), batch_size, flags);
875 const r = syscall4(.sendmmsg, @bitCast(usize, @as(isize, fd)), @ptrToInt(&msgvec[next_unsent]), batch_size, flags);
876876 if (getErrno(r) != 0) return next_unsent;
877877 if (r < batch_size) return next_unsent + r;
878878 }
......@@ -888,68 +888,68 @@ pub fn sendmmsg(fd: i32, msgvec: [*]mmsghdr_const, vlen: u32, flags: u32) usize
888888 }
889889 if (next_unsent < kvlen or next_unsent == 0) { // want to make sure at least one syscall occurs (e.g. to trigger MSG_EOR)
890890 const batch_size = kvlen - next_unsent;
891 const r = syscall4(SYS_sendmmsg, @bitCast(usize, @as(isize, fd)), @ptrToInt(&msgvec[next_unsent]), batch_size, flags);
891 const r = syscall4(.sendmmsg, @bitCast(usize, @as(isize, fd)), @ptrToInt(&msgvec[next_unsent]), batch_size, flags);
892892 if (getErrno(r) != 0) return r;
893893 return next_unsent + r;
894894 }
895895 return kvlen;
896896 }
897 return syscall4(SYS_sendmmsg, @bitCast(usize, @as(isize, fd)), @ptrToInt(msgvec), vlen, flags);
897 return syscall4(.sendmmsg, @bitCast(usize, @as(isize, fd)), @ptrToInt(msgvec), vlen, flags);
898898}
899899
900900pub fn connect(fd: i32, addr: *const c_void, len: socklen_t) usize {
901901 if (builtin.arch == .i386) {
902902 return socketcall(SC_connect, &[3]usize{ @bitCast(usize, @as(isize, fd)), @ptrToInt(addr), len });
903903 }
904 return syscall3(SYS_connect, @bitCast(usize, @as(isize, fd)), @ptrToInt(addr), len);
904 return syscall3(.connect, @bitCast(usize, @as(isize, fd)), @ptrToInt(addr), len);
905905}
906906
907907pub fn recvmsg(fd: i32, msg: *msghdr, flags: u32) usize {
908908 if (builtin.arch == .i386) {
909909 return socketcall(SC_recvmsg, &[3]usize{ @bitCast(usize, @as(isize, fd)), @ptrToInt(msg), flags });
910910 }
911 return syscall3(SYS_recvmsg, @bitCast(usize, @as(isize, fd)), @ptrToInt(msg), flags);
911 return syscall3(.recvmsg, @bitCast(usize, @as(isize, fd)), @ptrToInt(msg), flags);
912912}
913913
914914pub fn recvfrom(fd: i32, noalias buf: [*]u8, len: usize, flags: u32, noalias addr: ?*sockaddr, noalias alen: ?*socklen_t) usize {
915915 if (builtin.arch == .i386) {
916916 return socketcall(SC_recvfrom, &[6]usize{ @bitCast(usize, @as(isize, fd)), @ptrToInt(buf), len, flags, @ptrToInt(addr), @ptrToInt(alen) });
917917 }
918 return syscall6(SYS_recvfrom, @bitCast(usize, @as(isize, fd)), @ptrToInt(buf), len, flags, @ptrToInt(addr), @ptrToInt(alen));
918 return syscall6(.recvfrom, @bitCast(usize, @as(isize, fd)), @ptrToInt(buf), len, flags, @ptrToInt(addr), @ptrToInt(alen));
919919}
920920
921921pub fn shutdown(fd: i32, how: i32) usize {
922922 if (builtin.arch == .i386) {
923923 return socketcall(SC_shutdown, &[2]usize{ @bitCast(usize, @as(isize, fd)), @bitCast(usize, @as(isize, how)) });
924924 }
925 return syscall2(SYS_shutdown, @bitCast(usize, @as(isize, fd)), @bitCast(usize, @as(isize, how)));
925 return syscall2(.shutdown, @bitCast(usize, @as(isize, fd)), @bitCast(usize, @as(isize, how)));
926926}
927927
928928pub fn bind(fd: i32, addr: *const sockaddr, len: socklen_t) usize {
929929 if (builtin.arch == .i386) {
930930 return socketcall(SC_bind, &[3]usize{ @bitCast(usize, @as(isize, fd)), @ptrToInt(addr), @intCast(usize, len) });
931931 }
932 return syscall3(SYS_bind, @bitCast(usize, @as(isize, fd)), @ptrToInt(addr), @intCast(usize, len));
932 return syscall3(.bind, @bitCast(usize, @as(isize, fd)), @ptrToInt(addr), @intCast(usize, len));
933933}
934934
935935pub fn listen(fd: i32, backlog: u32) usize {
936936 if (builtin.arch == .i386) {
937937 return socketcall(SC_listen, &[2]usize{ @bitCast(usize, @as(isize, fd)), backlog });
938938 }
939 return syscall2(SYS_listen, @bitCast(usize, @as(isize, fd)), backlog);
939 return syscall2(.listen, @bitCast(usize, @as(isize, fd)), backlog);
940940}
941941
942942pub fn sendto(fd: i32, buf: [*]const u8, len: usize, flags: u32, addr: ?*const sockaddr, alen: socklen_t) usize {
943943 if (builtin.arch == .i386) {
944944 return socketcall(SC_sendto, &[6]usize{ @bitCast(usize, @as(isize, fd)), @ptrToInt(buf), len, flags, @ptrToInt(addr), @intCast(usize, alen) });
945945 }
946 return syscall6(SYS_sendto, @bitCast(usize, @as(isize, fd)), @ptrToInt(buf), len, flags, @ptrToInt(addr), @intCast(usize, alen));
946 return syscall6(.sendto, @bitCast(usize, @as(isize, fd)), @ptrToInt(buf), len, flags, @ptrToInt(addr), @intCast(usize, alen));
947947}
948948
949949pub fn sendfile(outfd: i32, infd: i32, offset: ?*i64, count: usize) usize {
950 if (@hasDecl(@This(), "SYS_sendfile64")) {
950 if (@hasField(SYS, "sendfile64")) {
951951 return syscall4(
952 SYS_sendfile64,
952 .sendfile64,
953953 @bitCast(usize, @as(isize, outfd)),
954954 @bitCast(usize, @as(isize, infd)),
955955 @ptrToInt(offset),
......@@ -957,7 +957,7 @@ pub fn sendfile(outfd: i32, infd: i32, offset: ?*i64, count: usize) usize {
957957 );
958958 } else {
959959 return syscall4(
960 SYS_sendfile,
960 .sendfile,
961961 @bitCast(usize, @as(isize, outfd)),
962962 @bitCast(usize, @as(isize, infd)),
963963 @ptrToInt(offset),
......@@ -970,7 +970,7 @@ pub fn socketpair(domain: i32, socket_type: i32, protocol: i32, fd: [2]i32) usiz
970970 if (builtin.arch == .i386) {
971971 return socketcall(SC_socketpair, &[4]usize{ @intCast(usize, domain), @intCast(usize, socket_type), @intCast(usize, protocol), @ptrToInt(&fd[0]) });
972972 }
973 return syscall4(SYS_socketpair, @intCast(usize, domain), @intCast(usize, socket_type), @intCast(usize, protocol), @ptrToInt(&fd[0]));
973 return syscall4(.socketpair, @intCast(usize, domain), @intCast(usize, socket_type), @intCast(usize, protocol), @ptrToInt(&fd[0]));
974974}
975975
976976pub fn accept(fd: i32, noalias addr: *sockaddr, noalias len: *socklen_t) usize {
......@@ -984,45 +984,45 @@ pub fn accept4(fd: i32, noalias addr: *sockaddr, noalias len: *socklen_t, flags:
984984 if (builtin.arch == .i386) {
985985 return socketcall(SC_accept4, &[4]usize{ @bitCast(usize, @as(isize, fd)), @ptrToInt(addr), @ptrToInt(len), flags });
986986 }
987 return syscall4(SYS_accept4, @bitCast(usize, @as(isize, fd)), @ptrToInt(addr), @ptrToInt(len), flags);
987 return syscall4(.accept4, @bitCast(usize, @as(isize, fd)), @ptrToInt(addr), @ptrToInt(len), flags);
988988}
989989
990990pub fn fstat(fd: i32, stat_buf: *Stat) usize {
991 if (@hasDecl(@This(), "SYS_fstat64")) {
992 return syscall2(SYS_fstat64, @bitCast(usize, @as(isize, fd)), @ptrToInt(stat_buf));
991 if (@hasField(SYS, "fstat64")) {
992 return syscall2(.fstat64, @bitCast(usize, @as(isize, fd)), @ptrToInt(stat_buf));
993993 } else {
994 return syscall2(SYS_fstat, @bitCast(usize, @as(isize, fd)), @ptrToInt(stat_buf));
994 return syscall2(.fstat, @bitCast(usize, @as(isize, fd)), @ptrToInt(stat_buf));
995995 }
996996}
997997
998998pub fn stat(pathname: [*:0]const u8, statbuf: *Stat) usize {
999 if (@hasDecl(@This(), "SYS_stat64")) {
1000 return syscall2(SYS_stat64, @ptrToInt(pathname), @ptrToInt(statbuf));
999 if (@hasField(SYS, "stat64")) {
1000 return syscall2(.stat64, @ptrToInt(pathname), @ptrToInt(statbuf));
10011001 } else {
1002 return syscall2(SYS_stat, @ptrToInt(pathname), @ptrToInt(statbuf));
1002 return syscall2(.stat, @ptrToInt(pathname), @ptrToInt(statbuf));
10031003 }
10041004}
10051005
10061006pub fn lstat(pathname: [*:0]const u8, statbuf: *Stat) usize {
1007 if (@hasDecl(@This(), "SYS_lstat64")) {
1008 return syscall2(SYS_lstat64, @ptrToInt(pathname), @ptrToInt(statbuf));
1007 if (@hasField(SYS, "lstat64")) {
1008 return syscall2(.lstat64, @ptrToInt(pathname), @ptrToInt(statbuf));
10091009 } else {
1010 return syscall2(SYS_lstat, @ptrToInt(pathname), @ptrToInt(statbuf));
1010 return syscall2(.lstat, @ptrToInt(pathname), @ptrToInt(statbuf));
10111011 }
10121012}
10131013
10141014pub fn fstatat(dirfd: i32, path: [*:0]const u8, stat_buf: *Stat, flags: u32) usize {
1015 if (@hasDecl(@This(), "SYS_fstatat64")) {
1016 return syscall4(SYS_fstatat64, @bitCast(usize, @as(isize, dirfd)), @ptrToInt(path), @ptrToInt(stat_buf), flags);
1015 if (@hasField(SYS, "fstatat64")) {
1016 return syscall4(.fstatat64, @bitCast(usize, @as(isize, dirfd)), @ptrToInt(path), @ptrToInt(stat_buf), flags);
10171017 } else {
1018 return syscall4(SYS_fstatat, @bitCast(usize, @as(isize, dirfd)), @ptrToInt(path), @ptrToInt(stat_buf), flags);
1018 return syscall4(.fstatat, @bitCast(usize, @as(isize, dirfd)), @ptrToInt(path), @ptrToInt(stat_buf), flags);
10191019 }
10201020}
10211021
10221022pub fn statx(dirfd: i32, path: [*]const u8, flags: u32, mask: u32, statx_buf: *Statx) usize {
1023 if (@hasDecl(@This(), "SYS_statx")) {
1023 if (@hasField(SYS, "statx")) {
10241024 return syscall5(
1025 SYS_statx,
1025 .statx,
10261026 @bitCast(usize, @as(isize, dirfd)),
10271027 @ptrToInt(path),
10281028 flags,
......@@ -1034,59 +1034,59 @@ pub fn statx(dirfd: i32, path: [*]const u8, flags: u32, mask: u32, statx_buf: *S
10341034}
10351035
10361036pub fn listxattr(path: [*:0]const u8, list: [*]u8, size: usize) usize {
1037 return syscall3(SYS_listxattr, @ptrToInt(path), @ptrToInt(list), size);
1037 return syscall3(.listxattr, @ptrToInt(path), @ptrToInt(list), size);
10381038}
10391039
10401040pub fn llistxattr(path: [*:0]const u8, list: [*]u8, size: usize) usize {
1041 return syscall3(SYS_llistxattr, @ptrToInt(path), @ptrToInt(list), size);
1041 return syscall3(.llistxattr, @ptrToInt(path), @ptrToInt(list), size);
10421042}
10431043
10441044pub fn flistxattr(fd: usize, list: [*]u8, size: usize) usize {
1045 return syscall3(SYS_flistxattr, fd, @ptrToInt(list), size);
1045 return syscall3(.flistxattr, fd, @ptrToInt(list), size);
10461046}
10471047
10481048pub fn getxattr(path: [*:0]const u8, name: [*:0]const u8, value: [*]u8, size: usize) usize {
1049 return syscall4(SYS_getxattr, @ptrToInt(path), @ptrToInt(name), @ptrToInt(value), size);
1049 return syscall4(.getxattr, @ptrToInt(path), @ptrToInt(name), @ptrToInt(value), size);
10501050}
10511051
10521052pub fn lgetxattr(path: [*:0]const u8, name: [*:0]const u8, value: [*]u8, size: usize) usize {
1053 return syscall4(SYS_lgetxattr, @ptrToInt(path), @ptrToInt(name), @ptrToInt(value), size);
1053 return syscall4(.lgetxattr, @ptrToInt(path), @ptrToInt(name), @ptrToInt(value), size);
10541054}
10551055
10561056pub fn fgetxattr(fd: usize, name: [*:0]const u8, value: [*]u8, size: usize) usize {
1057 return syscall4(SYS_lgetxattr, fd, @ptrToInt(name), @ptrToInt(value), size);
1057 return syscall4(.lgetxattr, fd, @ptrToInt(name), @ptrToInt(value), size);
10581058}
10591059
10601060pub fn setxattr(path: [*:0]const u8, name: [*:0]const u8, value: *const void, size: usize, flags: usize) usize {
1061 return syscall5(SYS_setxattr, @ptrToInt(path), @ptrToInt(name), @ptrToInt(value), size, flags);
1061 return syscall5(.setxattr, @ptrToInt(path), @ptrToInt(name), @ptrToInt(value), size, flags);
10621062}
10631063
10641064pub fn lsetxattr(path: [*:0]const u8, name: [*:0]const u8, value: *const void, size: usize, flags: usize) usize {
1065 return syscall5(SYS_lsetxattr, @ptrToInt(path), @ptrToInt(name), @ptrToInt(value), size, flags);
1065 return syscall5(.lsetxattr, @ptrToInt(path), @ptrToInt(name), @ptrToInt(value), size, flags);
10661066}
10671067
10681068pub fn fsetxattr(fd: usize, name: [*:0]const u8, value: *const void, size: usize, flags: usize) usize {
1069 return syscall5(SYS_fsetxattr, fd, @ptrToInt(name), @ptrToInt(value), size, flags);
1069 return syscall5(.fsetxattr, fd, @ptrToInt(name), @ptrToInt(value), size, flags);
10701070}
10711071
10721072pub fn removexattr(path: [*:0]const u8, name: [*:0]const u8) usize {
1073 return syscall2(SYS_removexattr, @ptrToInt(path), @ptrToInt(name));
1073 return syscall2(.removexattr, @ptrToInt(path), @ptrToInt(name));
10741074}
10751075
10761076pub fn lremovexattr(path: [*:0]const u8, name: [*:0]const u8) usize {
1077 return syscall2(SYS_lremovexattr, @ptrToInt(path), @ptrToInt(name));
1077 return syscall2(.lremovexattr, @ptrToInt(path), @ptrToInt(name));
10781078}
10791079
10801080pub fn fremovexattr(fd: usize, name: [*:0]const u8) usize {
1081 return syscall2(SYS_fremovexattr, fd, @ptrToInt(name));
1081 return syscall2(.fremovexattr, fd, @ptrToInt(name));
10821082}
10831083
10841084pub fn sched_yield() usize {
1085 return syscall0(SYS_sched_yield);
1085 return syscall0(.sched_yield);
10861086}
10871087
10881088pub fn sched_getaffinity(pid: pid_t, size: usize, set: *cpu_set_t) usize {
1089 const rc = syscall3(SYS_sched_getaffinity, @bitCast(usize, @as(isize, pid)), size, @ptrToInt(set));
1089 const rc = syscall3(.sched_getaffinity, @bitCast(usize, @as(isize, pid)), size, @ptrToInt(set));
10901090 if (@bitCast(isize, rc) < 0) return rc;
10911091 if (rc < size) @memset(@ptrCast([*]u8, set) + rc, 0, size - rc);
10921092 return 0;
......@@ -1097,11 +1097,11 @@ pub fn epoll_create() usize {
10971097}
10981098
10991099pub fn epoll_create1(flags: usize) usize {
1100 return syscall1(SYS_epoll_create1, flags);
1100 return syscall1(.epoll_create1, flags);
11011101}
11021102
11031103pub fn epoll_ctl(epoll_fd: i32, op: u32, fd: i32, ev: ?*epoll_event) usize {
1104 return syscall4(SYS_epoll_ctl, @bitCast(usize, @as(isize, epoll_fd)), @intCast(usize, op), @bitCast(usize, @as(isize, fd)), @ptrToInt(ev));
1104 return syscall4(.epoll_ctl, @bitCast(usize, @as(isize, epoll_fd)), @intCast(usize, op), @bitCast(usize, @as(isize, fd)), @ptrToInt(ev));
11051105}
11061106
11071107pub fn epoll_wait(epoll_fd: i32, events: [*]epoll_event, maxevents: u32, timeout: i32) usize {
......@@ -1110,7 +1110,7 @@ pub fn epoll_wait(epoll_fd: i32, events: [*]epoll_event, maxevents: u32, timeout
11101110
11111111pub fn epoll_pwait(epoll_fd: i32, events: [*]epoll_event, maxevents: u32, timeout: i32, sigmask: ?*sigset_t) usize {
11121112 return syscall6(
1113 SYS_epoll_pwait,
1113 .epoll_pwait,
11141114 @bitCast(usize, @as(isize, epoll_fd)),
11151115 @ptrToInt(events),
11161116 @intCast(usize, maxevents),
......@@ -1121,11 +1121,11 @@ pub fn epoll_pwait(epoll_fd: i32, events: [*]epoll_event, maxevents: u32, timeou
11211121}
11221122
11231123pub fn eventfd(count: u32, flags: u32) usize {
1124 return syscall2(SYS_eventfd2, count, flags);
1124 return syscall2(.eventfd2, count, flags);
11251125}
11261126
11271127pub fn timerfd_create(clockid: i32, flags: u32) usize {
1128 return syscall2(SYS_timerfd_create, @bitCast(usize, @as(isize, clockid)), flags);
1128 return syscall2(.timerfd_create, @bitCast(usize, @as(isize, clockid)), flags);
11291129}
11301130
11311131pub const itimerspec = extern struct {
......@@ -1134,59 +1134,59 @@ pub const itimerspec = extern struct {
11341134};
11351135
11361136pub fn timerfd_gettime(fd: i32, curr_value: *itimerspec) usize {
1137 return syscall2(SYS_timerfd_gettime, @bitCast(usize, @as(isize, fd)), @ptrToInt(curr_value));
1137 return syscall2(.timerfd_gettime, @bitCast(usize, @as(isize, fd)), @ptrToInt(curr_value));
11381138}
11391139
11401140pub fn timerfd_settime(fd: i32, flags: u32, new_value: *const itimerspec, old_value: ?*itimerspec) usize {
1141 return syscall4(SYS_timerfd_settime, @bitCast(usize, @as(isize, fd)), flags, @ptrToInt(new_value), @ptrToInt(old_value));
1141 return syscall4(.timerfd_settime, @bitCast(usize, @as(isize, fd)), flags, @ptrToInt(new_value), @ptrToInt(old_value));
11421142}
11431143
11441144pub fn unshare(flags: usize) usize {
1145 return syscall1(SYS_unshare, flags);
1145 return syscall1(.unshare, flags);
11461146}
11471147
11481148pub fn capget(hdrp: *cap_user_header_t, datap: *cap_user_data_t) usize {
1149 return syscall2(SYS_capget, @ptrToInt(hdrp), @ptrToInt(datap));
1149 return syscall2(.capget, @ptrToInt(hdrp), @ptrToInt(datap));
11501150}
11511151
11521152pub fn capset(hdrp: *cap_user_header_t, datap: *const cap_user_data_t) usize {
1153 return syscall2(SYS_capset, @ptrToInt(hdrp), @ptrToInt(datap));
1153 return syscall2(.capset, @ptrToInt(hdrp), @ptrToInt(datap));
11541154}
11551155
11561156pub fn sigaltstack(ss: ?*stack_t, old_ss: ?*stack_t) usize {
1157 return syscall2(SYS_sigaltstack, @ptrToInt(ss), @ptrToInt(old_ss));
1157 return syscall2(.sigaltstack, @ptrToInt(ss), @ptrToInt(old_ss));
11581158}
11591159
11601160pub fn uname(uts: *utsname) usize {
1161 return syscall1(SYS_uname, @ptrToInt(uts));
1161 return syscall1(.uname, @ptrToInt(uts));
11621162}
11631163
11641164pub fn io_uring_setup(entries: u32, p: *io_uring_params) usize {
1165 return syscall2(SYS_io_uring_setup, entries, @ptrToInt(p));
1165 return syscall2(.io_uring_setup, entries, @ptrToInt(p));
11661166}
11671167
11681168pub fn io_uring_enter(fd: i32, to_submit: u32, min_complete: u32, flags: u32, sig: ?*sigset_t) usize {
1169 return syscall6(SYS_io_uring_enter, @bitCast(usize, @as(isize, fd)), to_submit, min_complete, flags, @ptrToInt(sig), NSIG / 8);
1169 return syscall6(.io_uring_enter, @bitCast(usize, @as(isize, fd)), to_submit, min_complete, flags, @ptrToInt(sig), NSIG / 8);
11701170}
11711171
1172pub fn io_uring_register(fd: i32, opcode: u32, arg: ?*const c_void, nr_args: u32) usize {
1173 return syscall4(SYS_io_uring_register, @bitCast(usize, @as(isize, fd)), opcode, @ptrToInt(arg), nr_args);
1172pub fn io_uring_register(fd: i32, opcode: IORING_REGISTER, arg: ?*const c_void, nr_args: u32) usize {
1173 return syscall4(.io_uring_register, @bitCast(usize, @as(isize, fd)), @enumToInt(opcode), @ptrToInt(arg), nr_args);
11741174}
11751175
11761176pub fn memfd_create(name: [*:0]const u8, flags: u32) usize {
1177 return syscall2(SYS_memfd_create, @ptrToInt(name), flags);
1177 return syscall2(.memfd_create, @ptrToInt(name), flags);
11781178}
11791179
11801180pub fn getrusage(who: i32, usage: *rusage) usize {
1181 return syscall2(SYS_getrusage, @bitCast(usize, @as(isize, who)), @ptrToInt(usage));
1181 return syscall2(.getrusage, @bitCast(usize, @as(isize, who)), @ptrToInt(usage));
11821182}
11831183
11841184pub fn tcgetattr(fd: fd_t, termios_p: *termios) usize {
1185 return syscall3(SYS_ioctl, @bitCast(usize, @as(isize, fd)), TCGETS, @ptrToInt(termios_p));
1185 return syscall3(.ioctl, @bitCast(usize, @as(isize, fd)), TCGETS, @ptrToInt(termios_p));
11861186}
11871187
11881188pub fn tcsetattr(fd: fd_t, optional_action: TCSA, termios_p: *const termios) usize {
1189 return syscall3(SYS_ioctl, @bitCast(usize, @as(isize, fd)), TCSETS + @enumToInt(optional_action), @ptrToInt(termios_p));
1189 return syscall3(.ioctl, @bitCast(usize, @as(isize, fd)), TCSETS + @enumToInt(optional_action), @ptrToInt(termios_p));
11901190}
11911191
11921192test "" {
lib/std/os/linux/arm-eabi.zig+16-16
......@@ -1,36 +1,36 @@
11usingnamespace @import("../bits.zig");
22
3pub fn syscall0(number: usize) usize {
3pub fn syscall0(number: SYS) usize {
44 return asm volatile ("svc #0"
55 : [ret] "={r0}" (-> usize)
6 : [number] "{r7}" (number)
6 : [number] "{r7}" (@enumToInt(number))
77 : "memory"
88 );
99}
1010
11pub fn syscall1(number: usize, arg1: usize) usize {
11pub fn syscall1(number: SYS, arg1: usize) usize {
1212 return asm volatile ("svc #0"
1313 : [ret] "={r0}" (-> usize)
14 : [number] "{r7}" (number),
14 : [number] "{r7}" (@enumToInt(number)),
1515 [arg1] "{r0}" (arg1)
1616 : "memory"
1717 );
1818}
1919
20pub fn syscall2(number: usize, arg1: usize, arg2: usize) usize {
20pub fn syscall2(number: SYS, arg1: usize, arg2: usize) usize {
2121 return asm volatile ("svc #0"
2222 : [ret] "={r0}" (-> usize)
23 : [number] "{r7}" (number),
23 : [number] "{r7}" (@enumToInt(number)),
2424 [arg1] "{r0}" (arg1),
2525 [arg2] "{r1}" (arg2)
2626 : "memory"
2727 );
2828}
2929
30pub fn syscall3(number: usize, arg1: usize, arg2: usize, arg3: usize) usize {
30pub fn syscall3(number: SYS, arg1: usize, arg2: usize, arg3: usize) usize {
3131 return asm volatile ("svc #0"
3232 : [ret] "={r0}" (-> usize)
33 : [number] "{r7}" (number),
33 : [number] "{r7}" (@enumToInt(number)),
3434 [arg1] "{r0}" (arg1),
3535 [arg2] "{r1}" (arg2),
3636 [arg3] "{r2}" (arg3)
......@@ -38,10 +38,10 @@ pub fn syscall3(number: usize, arg1: usize, arg2: usize, arg3: usize) usize {
3838 );
3939}
4040
41pub fn syscall4(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize) usize {
41pub fn syscall4(number: SYS, arg1: usize, arg2: usize, arg3: usize, arg4: usize) usize {
4242 return asm volatile ("svc #0"
4343 : [ret] "={r0}" (-> usize)
44 : [number] "{r7}" (number),
44 : [number] "{r7}" (@enumToInt(number)),
4545 [arg1] "{r0}" (arg1),
4646 [arg2] "{r1}" (arg2),
4747 [arg3] "{r2}" (arg3),
......@@ -50,10 +50,10 @@ pub fn syscall4(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usiz
5050 );
5151}
5252
53pub fn syscall5(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize, arg5: usize) usize {
53pub fn syscall5(number: SYS, arg1: usize, arg2: usize, arg3: usize, arg4: usize, arg5: usize) usize {
5454 return asm volatile ("svc #0"
5555 : [ret] "={r0}" (-> usize)
56 : [number] "{r7}" (number),
56 : [number] "{r7}" (@enumToInt(number)),
5757 [arg1] "{r0}" (arg1),
5858 [arg2] "{r1}" (arg2),
5959 [arg3] "{r2}" (arg3),
......@@ -64,7 +64,7 @@ pub fn syscall5(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usiz
6464}
6565
6666pub fn syscall6(
67 number: usize,
67 number: SYS,
6868 arg1: usize,
6969 arg2: usize,
7070 arg3: usize,
......@@ -74,7 +74,7 @@ pub fn syscall6(
7474) usize {
7575 return asm volatile ("svc #0"
7676 : [ret] "={r0}" (-> usize)
77 : [number] "{r7}" (number),
77 : [number] "{r7}" (@enumToInt(number)),
7878 [arg1] "{r0}" (arg1),
7979 [arg2] "{r1}" (arg2),
8080 [arg3] "{r2}" (arg3),
......@@ -91,7 +91,7 @@ pub extern fn clone(func: extern fn (arg: usize) u8, stack: usize, flags: u32, a
9191pub fn restore() callconv(.Naked) void {
9292 return asm volatile ("svc #0"
9393 :
94 : [number] "{r7}" (@as(usize, SYS_sigreturn))
94 : [number] "{r7}" (@enumToInt(SYS.sigreturn))
9595 : "memory"
9696 );
9797}
......@@ -99,7 +99,7 @@ pub fn restore() callconv(.Naked) void {
9999pub fn restore_rt() callconv(.Naked) void {
100100 return asm volatile ("svc #0"
101101 :
102 : [number] "{r7}" (@as(usize, SYS_rt_sigreturn))
102 : [number] "{r7}" (@enumToInt(SYS.rt_sigreturn))
103103 : "memory"
104104 );
105105}
lib/std/os/linux/arm64.zig+15-15
......@@ -1,36 +1,36 @@
11usingnamespace @import("../bits.zig");
22
3pub fn syscall0(number: usize) usize {
3pub fn syscall0(number: SYS) usize {
44 return asm volatile ("svc #0"
55 : [ret] "={x0}" (-> usize)
6 : [number] "{x8}" (number)
6 : [number] "{x8}" (@enumToInt(number))
77 : "memory", "cc"
88 );
99}
1010
11pub fn syscall1(number: usize, arg1: usize) usize {
11pub fn syscall1(number: SYS, arg1: usize) usize {
1212 return asm volatile ("svc #0"
1313 : [ret] "={x0}" (-> usize)
14 : [number] "{x8}" (number),
14 : [number] "{x8}" (@enumToInt(number)),
1515 [arg1] "{x0}" (arg1)
1616 : "memory", "cc"
1717 );
1818}
1919
20pub fn syscall2(number: usize, arg1: usize, arg2: usize) usize {
20pub fn syscall2(number: SYS, arg1: usize, arg2: usize) usize {
2121 return asm volatile ("svc #0"
2222 : [ret] "={x0}" (-> usize)
23 : [number] "{x8}" (number),
23 : [number] "{x8}" (@enumToInt(number)),
2424 [arg1] "{x0}" (arg1),
2525 [arg2] "{x1}" (arg2)
2626 : "memory", "cc"
2727 );
2828}
2929
30pub fn syscall3(number: usize, arg1: usize, arg2: usize, arg3: usize) usize {
30pub fn syscall3(number: SYS, arg1: usize, arg2: usize, arg3: usize) usize {
3131 return asm volatile ("svc #0"
3232 : [ret] "={x0}" (-> usize)
33 : [number] "{x8}" (number),
33 : [number] "{x8}" (@enumToInt(number)),
3434 [arg1] "{x0}" (arg1),
3535 [arg2] "{x1}" (arg2),
3636 [arg3] "{x2}" (arg3)
......@@ -38,10 +38,10 @@ pub fn syscall3(number: usize, arg1: usize, arg2: usize, arg3: usize) usize {
3838 );
3939}
4040
41pub fn syscall4(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize) usize {
41pub fn syscall4(number: SYS, arg1: usize, arg2: usize, arg3: usize, arg4: usize) usize {
4242 return asm volatile ("svc #0"
4343 : [ret] "={x0}" (-> usize)
44 : [number] "{x8}" (number),
44 : [number] "{x8}" (@enumToInt(number)),
4545 [arg1] "{x0}" (arg1),
4646 [arg2] "{x1}" (arg2),
4747 [arg3] "{x2}" (arg3),
......@@ -50,10 +50,10 @@ pub fn syscall4(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usiz
5050 );
5151}
5252
53pub fn syscall5(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize, arg5: usize) usize {
53pub fn syscall5(number: SYS, arg1: usize, arg2: usize, arg3: usize, arg4: usize, arg5: usize) usize {
5454 return asm volatile ("svc #0"
5555 : [ret] "={x0}" (-> usize)
56 : [number] "{x8}" (number),
56 : [number] "{x8}" (@enumToInt(number)),
5757 [arg1] "{x0}" (arg1),
5858 [arg2] "{x1}" (arg2),
5959 [arg3] "{x2}" (arg3),
......@@ -64,7 +64,7 @@ pub fn syscall5(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usiz
6464}
6565
6666pub fn syscall6(
67 number: usize,
67 number: SYS,
6868 arg1: usize,
6969 arg2: usize,
7070 arg3: usize,
......@@ -74,7 +74,7 @@ pub fn syscall6(
7474) usize {
7575 return asm volatile ("svc #0"
7676 : [ret] "={x0}" (-> usize)
77 : [number] "{x8}" (number),
77 : [number] "{x8}" (@enumToInt(number)),
7878 [arg1] "{x0}" (arg1),
7979 [arg2] "{x1}" (arg2),
8080 [arg3] "{x2}" (arg3),
......@@ -93,7 +93,7 @@ pub const restore = restore_rt;
9393pub fn restore_rt() callconv(.Naked) void {
9494 return asm volatile ("svc #0"
9595 :
96 : [number] "{x8}" (@as(usize, SYS_rt_sigreturn))
96 : [number] "{x8}" (@enumToInt(SYS.rt_sigreturn))
9797 : "memory", "cc"
9898 );
9999}
lib/std/os/linux/i386.zig+17-17
......@@ -1,36 +1,36 @@
11usingnamespace @import("../bits.zig");
22
3pub fn syscall0(number: usize) usize {
3pub fn syscall0(number: SYS) usize {
44 return asm volatile ("int $0x80"
55 : [ret] "={eax}" (-> usize)
6 : [number] "{eax}" (number)
6 : [number] "{eax}" (@enumToInt(number))
77 : "memory"
88 );
99}
1010
11pub fn syscall1(number: usize, arg1: usize) usize {
11pub fn syscall1(number: SYS, arg1: usize) usize {
1212 return asm volatile ("int $0x80"
1313 : [ret] "={eax}" (-> usize)
14 : [number] "{eax}" (number),
14 : [number] "{eax}" (@enumToInt(number)),
1515 [arg1] "{ebx}" (arg1)
1616 : "memory"
1717 );
1818}
1919
20pub fn syscall2(number: usize, arg1: usize, arg2: usize) usize {
20pub fn syscall2(number: SYS, arg1: usize, arg2: usize) usize {
2121 return asm volatile ("int $0x80"
2222 : [ret] "={eax}" (-> usize)
23 : [number] "{eax}" (number),
23 : [number] "{eax}" (@enumToInt(number)),
2424 [arg1] "{ebx}" (arg1),
2525 [arg2] "{ecx}" (arg2)
2626 : "memory"
2727 );
2828}
2929
30pub fn syscall3(number: usize, arg1: usize, arg2: usize, arg3: usize) usize {
30pub fn syscall3(number: SYS, arg1: usize, arg2: usize, arg3: usize) usize {
3131 return asm volatile ("int $0x80"
3232 : [ret] "={eax}" (-> usize)
33 : [number] "{eax}" (number),
33 : [number] "{eax}" (@enumToInt(number)),
3434 [arg1] "{ebx}" (arg1),
3535 [arg2] "{ecx}" (arg2),
3636 [arg3] "{edx}" (arg3)
......@@ -38,10 +38,10 @@ pub fn syscall3(number: usize, arg1: usize, arg2: usize, arg3: usize) usize {
3838 );
3939}
4040
41pub fn syscall4(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize) usize {
41pub fn syscall4(number: SYS, arg1: usize, arg2: usize, arg3: usize, arg4: usize) usize {
4242 return asm volatile ("int $0x80"
4343 : [ret] "={eax}" (-> usize)
44 : [number] "{eax}" (number),
44 : [number] "{eax}" (@enumToInt(number)),
4545 [arg1] "{ebx}" (arg1),
4646 [arg2] "{ecx}" (arg2),
4747 [arg3] "{edx}" (arg3),
......@@ -50,10 +50,10 @@ pub fn syscall4(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usiz
5050 );
5151}
5252
53pub fn syscall5(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize, arg5: usize) usize {
53pub fn syscall5(number: SYS, arg1: usize, arg2: usize, arg3: usize, arg4: usize, arg5: usize) usize {
5454 return asm volatile ("int $0x80"
5555 : [ret] "={eax}" (-> usize)
56 : [number] "{eax}" (number),
56 : [number] "{eax}" (@enumToInt(number)),
5757 [arg1] "{ebx}" (arg1),
5858 [arg2] "{ecx}" (arg2),
5959 [arg3] "{edx}" (arg3),
......@@ -64,7 +64,7 @@ pub fn syscall5(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usiz
6464}
6565
6666pub fn syscall6(
67 number: usize,
67 number: SYS,
6868 arg1: usize,
6969 arg2: usize,
7070 arg3: usize,
......@@ -84,7 +84,7 @@ pub fn syscall6(
8484 \\ pop %%ebp
8585 \\ add $4, %%esp
8686 : [ret] "={eax}" (-> usize)
87 : [number] "{eax}" (number),
87 : [number] "{eax}" (@enumToInt(number)),
8888 [arg1] "{ebx}" (arg1),
8989 [arg2] "{ecx}" (arg2),
9090 [arg3] "{edx}" (arg3),
......@@ -98,7 +98,7 @@ pub fn syscall6(
9898pub fn socketcall(call: usize, args: [*]usize) usize {
9999 return asm volatile ("int $0x80"
100100 : [ret] "={eax}" (-> usize)
101 : [number] "{eax}" (@as(usize, SYS_socketcall)),
101 : [number] "{eax}" (@enumToInt(SYS.socketcall)),
102102 [arg1] "{ebx}" (call),
103103 [arg2] "{ecx}" (@ptrToInt(args))
104104 : "memory"
......@@ -111,7 +111,7 @@ pub extern fn clone(func: extern fn (arg: usize) u8, stack: usize, flags: u32, a
111111pub fn restore() callconv(.Naked) void {
112112 return asm volatile ("int $0x80"
113113 :
114 : [number] "{eax}" (@as(usize, SYS_sigreturn))
114 : [number] "{eax}" (@enumToInt(SYS.sigreturn))
115115 : "memory"
116116 );
117117}
......@@ -119,7 +119,7 @@ pub fn restore() callconv(.Naked) void {
119119pub fn restore_rt() callconv(.Naked) void {
120120 return asm volatile ("int $0x80"
121121 :
122 : [number] "{eax}" (@as(usize, SYS_rt_sigreturn))
122 : [number] "{eax}" (@enumToInt(SYS.rt_sigreturn))
123123 : "memory"
124124 );
125125}
lib/std/os/linux/mipsel.zig+17-17
......@@ -1,13 +1,13 @@
11usingnamespace @import("../bits.zig");
22
3pub fn syscall0(number: usize) usize {
3pub fn syscall0(number: SYS) usize {
44 return asm volatile (
55 \\ syscall
66 \\ blez $7, 1f
77 \\ subu $2, $0, $2
88 \\ 1:
99 : [ret] "={$2}" (-> usize)
10 : [number] "{$2}" (number)
10 : [number] "{$2}" (@enumToInt(number))
1111 : "memory", "cc", "$7"
1212 );
1313}
......@@ -26,46 +26,46 @@ pub fn syscall_pipe(fd: *[2]i32) usize {
2626 \\ sw $3, 4($4)
2727 \\ 2:
2828 : [ret] "={$2}" (-> usize)
29 : [number] "{$2}" (@as(usize, SYS_pipe))
29 : [number] "{$2}" (@enumToInt(SYS.pipe))
3030 : "memory", "cc", "$7"
3131 );
3232}
3333
34pub fn syscall1(number: usize, arg1: usize) usize {
34pub fn syscall1(number: SYS, arg1: usize) usize {
3535 return asm volatile (
3636 \\ syscall
3737 \\ blez $7, 1f
3838 \\ subu $2, $0, $2
3939 \\ 1:
4040 : [ret] "={$2}" (-> usize)
41 : [number] "{$2}" (number),
41 : [number] "{$2}" (@enumToInt(number)),
4242 [arg1] "{$4}" (arg1)
4343 : "memory", "cc", "$7"
4444 );
4545}
4646
47pub fn syscall2(number: usize, arg1: usize, arg2: usize) usize {
47pub fn syscall2(number: SYS, arg1: usize, arg2: usize) usize {
4848 return asm volatile (
4949 \\ syscall
5050 \\ blez $7, 1f
5151 \\ subu $2, $0, $2
5252 \\ 1:
5353 : [ret] "={$2}" (-> usize)
54 : [number] "{$2}" (number),
54 : [number] "{$2}" (@enumToInt(number)),
5555 [arg1] "{$4}" (arg1),
5656 [arg2] "{$5}" (arg2)
5757 : "memory", "cc", "$7"
5858 );
5959}
6060
61pub fn syscall3(number: usize, arg1: usize, arg2: usize, arg3: usize) usize {
61pub fn syscall3(number: SYS, arg1: usize, arg2: usize, arg3: usize) usize {
6262 return asm volatile (
6363 \\ syscall
6464 \\ blez $7, 1f
6565 \\ subu $2, $0, $2
6666 \\ 1:
6767 : [ret] "={$2}" (-> usize)
68 : [number] "{$2}" (number),
68 : [number] "{$2}" (@enumToInt(number)),
6969 [arg1] "{$4}" (arg1),
7070 [arg2] "{$5}" (arg2),
7171 [arg3] "{$6}" (arg3)
......@@ -73,14 +73,14 @@ pub fn syscall3(number: usize, arg1: usize, arg2: usize, arg3: usize) usize {
7373 );
7474}
7575
76pub fn syscall4(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize) usize {
76pub fn syscall4(number: SYS, arg1: usize, arg2: usize, arg3: usize, arg4: usize) usize {
7777 return asm volatile (
7878 \\ syscall
7979 \\ blez $7, 1f
8080 \\ subu $2, $0, $2
8181 \\ 1:
8282 : [ret] "={$2}" (-> usize)
83 : [number] "{$2}" (number),
83 : [number] "{$2}" (@enumToInt(number)),
8484 [arg1] "{$4}" (arg1),
8585 [arg2] "{$5}" (arg2),
8686 [arg3] "{$6}" (arg3),
......@@ -89,7 +89,7 @@ pub fn syscall4(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usiz
8989 );
9090}
9191
92pub fn syscall5(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize, arg5: usize) usize {
92pub fn syscall5(number: SYS, arg1: usize, arg2: usize, arg3: usize, arg4: usize, arg5: usize) usize {
9393 return asm volatile (
9494 \\ .set noat
9595 \\ subu $sp, $sp, 24
......@@ -100,7 +100,7 @@ pub fn syscall5(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usiz
100100 \\ subu $2, $0, $2
101101 \\ 1:
102102 : [ret] "={$2}" (-> usize)
103 : [number] "{$2}" (number),
103 : [number] "{$2}" (@enumToInt(number)),
104104 [arg1] "{$4}" (arg1),
105105 [arg2] "{$5}" (arg2),
106106 [arg3] "{$6}" (arg3),
......@@ -111,7 +111,7 @@ pub fn syscall5(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usiz
111111}
112112
113113pub fn syscall6(
114 number: usize,
114 number: SYS,
115115 arg1: usize,
116116 arg2: usize,
117117 arg3: usize,
......@@ -130,7 +130,7 @@ pub fn syscall6(
130130 \\ subu $2, $0, $2
131131 \\ 1:
132132 : [ret] "={$2}" (-> usize)
133 : [number] "{$2}" (number),
133 : [number] "{$2}" (@enumToInt(number)),
134134 [arg1] "{$4}" (arg1),
135135 [arg2] "{$5}" (arg2),
136136 [arg3] "{$6}" (arg3),
......@@ -147,7 +147,7 @@ pub extern fn clone(func: extern fn (arg: usize) u8, stack: usize, flags: u32, a
147147pub fn restore() callconv(.Naked) void {
148148 return asm volatile ("syscall"
149149 :
150 : [number] "{$2}" (@as(usize, SYS_sigreturn))
150 : [number] "{$2}" (@enumToInt(SYS.sigreturn))
151151 : "memory", "cc", "$7"
152152 );
153153}
......@@ -155,7 +155,7 @@ pub fn restore() callconv(.Naked) void {
155155pub fn restore_rt() callconv(.Naked) void {
156156 return asm volatile ("syscall"
157157 :
158 : [number] "{$2}" (@as(usize, SYS_rt_sigreturn))
158 : [number] "{$2}" (@enumToInt(SYS.rt_sigreturn))
159159 : "memory", "cc", "$7"
160160 );
161161}
lib/std/os/linux/riscv64.zig+15-15
......@@ -1,36 +1,36 @@
11usingnamespace @import("../bits.zig");
22
3pub fn syscall0(number: usize) usize {
3pub fn syscall0(number: SYS) usize {
44 return asm volatile ("ecall"
55 : [ret] "={x10}" (-> usize)
6 : [number] "{x17}" (number)
6 : [number] "{x17}" (@enumToInt(number))
77 : "memory"
88 );
99}
1010
11pub fn syscall1(number: usize, arg1: usize) usize {
11pub fn syscall1(number: SYS, arg1: usize) usize {
1212 return asm volatile ("ecall"
1313 : [ret] "={x10}" (-> usize)
14 : [number] "{x17}" (number),
14 : [number] "{x17}" (@enumToInt(number)),
1515 [arg1] "{x10}" (arg1)
1616 : "memory"
1717 );
1818}
1919
20pub fn syscall2(number: usize, arg1: usize, arg2: usize) usize {
20pub fn syscall2(number: SYS, arg1: usize, arg2: usize) usize {
2121 return asm volatile ("ecall"
2222 : [ret] "={x10}" (-> usize)
23 : [number] "{x17}" (number),
23 : [number] "{x17}" (@enumToInt(number)),
2424 [arg1] "{x10}" (arg1),
2525 [arg2] "{x11}" (arg2)
2626 : "memory"
2727 );
2828}
2929
30pub fn syscall3(number: usize, arg1: usize, arg2: usize, arg3: usize) usize {
30pub fn syscall3(number: SYS, arg1: usize, arg2: usize, arg3: usize) usize {
3131 return asm volatile ("ecall"
3232 : [ret] "={x10}" (-> usize)
33 : [number] "{x17}" (number),
33 : [number] "{x17}" (@enumToInt(number)),
3434 [arg1] "{x10}" (arg1),
3535 [arg2] "{x11}" (arg2),
3636 [arg3] "{x12}" (arg3)
......@@ -38,10 +38,10 @@ pub fn syscall3(number: usize, arg1: usize, arg2: usize, arg3: usize) usize {
3838 );
3939}
4040
41pub fn syscall4(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize) usize {
41pub fn syscall4(number: SYS, arg1: usize, arg2: usize, arg3: usize, arg4: usize) usize {
4242 return asm volatile ("ecall"
4343 : [ret] "={x10}" (-> usize)
44 : [number] "{x17}" (number),
44 : [number] "{x17}" (@enumToInt(number)),
4545 [arg1] "{x10}" (arg1),
4646 [arg2] "{x11}" (arg2),
4747 [arg3] "{x12}" (arg3),
......@@ -50,10 +50,10 @@ pub fn syscall4(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usiz
5050 );
5151}
5252
53pub fn syscall5(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize, arg5: usize) usize {
53pub fn syscall5(number: SYS, arg1: usize, arg2: usize, arg3: usize, arg4: usize, arg5: usize) usize {
5454 return asm volatile ("ecall"
5555 : [ret] "={x10}" (-> usize)
56 : [number] "{x17}" (number),
56 : [number] "{x17}" (@enumToInt(number)),
5757 [arg1] "{x10}" (arg1),
5858 [arg2] "{x11}" (arg2),
5959 [arg3] "{x12}" (arg3),
......@@ -64,7 +64,7 @@ pub fn syscall5(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usiz
6464}
6565
6666pub fn syscall6(
67 number: usize,
67 number: SYS,
6868 arg1: usize,
6969 arg2: usize,
7070 arg3: usize,
......@@ -74,7 +74,7 @@ pub fn syscall6(
7474) usize {
7575 return asm volatile ("ecall"
7676 : [ret] "={x10}" (-> usize)
77 : [number] "{x17}" (number),
77 : [number] "{x17}" (@enumToInt(number)),
7878 [arg1] "{x10}" (arg1),
7979 [arg2] "{x11}" (arg2),
8080 [arg3] "{x12}" (arg3),
......@@ -92,7 +92,7 @@ pub const restore = restore_rt;
9292pub fn restore_rt() callconv(.Naked) void {
9393 return asm volatile ("ecall"
9494 :
95 : [number] "{x17}" (@as(usize, SYS_rt_sigreturn))
95 : [number] "{x17}" (@enumToInt(SYS.rt_sigreturn))
9696 : "memory"
9797 );
9898}
lib/std/os/linux/tls.zig+4-4
......@@ -122,7 +122,7 @@ pub fn setThreadPointer(addr: usize) void {
122122 .seg_not_present = 0,
123123 .useable = 1,
124124 };
125 const rc = std.os.linux.syscall1(std.os.linux.SYS_set_thread_area, @ptrToInt(&user_desc));
125 const rc = std.os.linux.syscall1(.set_thread_area, @ptrToInt(&user_desc));
126126 assert(rc == 0);
127127
128128 const gdt_entry_number = user_desc.entry_number;
......@@ -135,7 +135,7 @@ pub fn setThreadPointer(addr: usize) void {
135135 );
136136 },
137137 .x86_64 => {
138 const rc = std.os.linux.syscall2(std.os.linux.SYS_arch_prctl, std.os.linux.ARCH_SET_FS, addr);
138 const rc = std.os.linux.syscall2(.arch_prctl, std.os.linux.ARCH_SET_FS, addr);
139139 assert(rc == 0);
140140 },
141141 .aarch64 => {
......@@ -146,7 +146,7 @@ pub fn setThreadPointer(addr: usize) void {
146146 );
147147 },
148148 .arm => {
149 const rc = std.os.linux.syscall1(std.os.linux.SYS_set_tls, addr);
149 const rc = std.os.linux.syscall1(.set_tls, addr);
150150 assert(rc == 0);
151151 },
152152 .riscv64 => {
......@@ -157,7 +157,7 @@ pub fn setThreadPointer(addr: usize) void {
157157 );
158158 },
159159 .mipsel => {
160 const rc = std.os.linux.syscall1(std.os.linux.SYS_set_thread_area, addr);
160 const rc = std.os.linux.syscall1(.set_thread_area, addr);
161161 assert(rc == 0);
162162 },
163163 else => @compileError("Unsupported architecture"),
lib/std/os/linux/vdso.zig+3-3
......@@ -22,7 +22,7 @@ pub fn lookup(vername: []const u8, name: []const u8) usize {
2222 }) {
2323 const this_ph = @intToPtr(*elf.Phdr, ph_addr);
2424 switch (this_ph.p_type) {
25 // On WSL1 as well as older kernels, the VDSO ELF image is pre-linked in the upper half
25 // On WSL1 as well as older kernels, the VDSO ELF image is pre-linked in the upper half
2626 // of the memory space (e.g. p_vaddr = 0xffffffffff700000 on WSL1).
2727 // Wrapping operations are used on this line as well as subsequent calculations relative to base
2828 // (lines 47, 78) to ensure no overflow check is tripped.
......@@ -70,7 +70,7 @@ pub fn lookup(vername: []const u8, name: []const u8) usize {
7070 if (0 == (@as(u32, 1) << @intCast(u5, syms[i].st_info >> 4) & OK_BINDS)) continue;
7171 if (0 == syms[i].st_shndx) continue;
7272 const sym_name = @ptrCast([*:0]const u8, strings + syms[i].st_name);
73 if (!mem.eql(u8, name, mem.toSliceConst(u8, sym_name))) continue;
73 if (!mem.eql(u8, name, mem.spanZ(sym_name))) continue;
7474 if (maybe_versym) |versym| {
7575 if (!checkver(maybe_verdef.?, versym[i], vername, strings))
7676 continue;
......@@ -93,5 +93,5 @@ fn checkver(def_arg: *elf.Verdef, vsym_arg: i32, vername: []const u8, strings: [
9393 }
9494 const aux = @intToPtr(*elf.Verdaux, @ptrToInt(def) + def.vd_aux);
9595 const vda_name = @ptrCast([*:0]const u8, strings + aux.vda_name);
96 return mem.eql(u8, vername, mem.toSliceConst(u8, vda_name));
96 return mem.eql(u8, vername, mem.spanZ(vda_name));
9797}
lib/std/os/linux/x86_64.zig+15-15
......@@ -1,36 +1,36 @@
11usingnamespace @import("../bits.zig");
22
3pub fn syscall0(number: usize) usize {
3pub fn syscall0(number: SYS) usize {
44 return asm volatile ("syscall"
55 : [ret] "={rax}" (-> usize)
6 : [number] "{rax}" (number)
6 : [number] "{rax}" (@enumToInt(number))
77 : "rcx", "r11", "memory"
88 );
99}
1010
11pub fn syscall1(number: usize, arg1: usize) usize {
11pub fn syscall1(number: SYS, arg1: usize) usize {
1212 return asm volatile ("syscall"
1313 : [ret] "={rax}" (-> usize)
14 : [number] "{rax}" (number),
14 : [number] "{rax}" (@enumToInt(number)),
1515 [arg1] "{rdi}" (arg1)
1616 : "rcx", "r11", "memory"
1717 );
1818}
1919
20pub fn syscall2(number: usize, arg1: usize, arg2: usize) usize {
20pub fn syscall2(number: SYS, arg1: usize, arg2: usize) usize {
2121 return asm volatile ("syscall"
2222 : [ret] "={rax}" (-> usize)
23 : [number] "{rax}" (number),
23 : [number] "{rax}" (@enumToInt(number)),
2424 [arg1] "{rdi}" (arg1),
2525 [arg2] "{rsi}" (arg2)
2626 : "rcx", "r11", "memory"
2727 );
2828}
2929
30pub fn syscall3(number: usize, arg1: usize, arg2: usize, arg3: usize) usize {
30pub fn syscall3(number: SYS, arg1: usize, arg2: usize, arg3: usize) usize {
3131 return asm volatile ("syscall"
3232 : [ret] "={rax}" (-> usize)
33 : [number] "{rax}" (number),
33 : [number] "{rax}" (@enumToInt(number)),
3434 [arg1] "{rdi}" (arg1),
3535 [arg2] "{rsi}" (arg2),
3636 [arg3] "{rdx}" (arg3)
......@@ -38,10 +38,10 @@ pub fn syscall3(number: usize, arg1: usize, arg2: usize, arg3: usize) usize {
3838 );
3939}
4040
41pub fn syscall4(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize) usize {
41pub fn syscall4(number: SYS, arg1: usize, arg2: usize, arg3: usize, arg4: usize) usize {
4242 return asm volatile ("syscall"
4343 : [ret] "={rax}" (-> usize)
44 : [number] "{rax}" (number),
44 : [number] "{rax}" (@enumToInt(number)),
4545 [arg1] "{rdi}" (arg1),
4646 [arg2] "{rsi}" (arg2),
4747 [arg3] "{rdx}" (arg3),
......@@ -50,10 +50,10 @@ pub fn syscall4(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usiz
5050 );
5151}
5252
53pub fn syscall5(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize, arg5: usize) usize {
53pub fn syscall5(number: SYS, arg1: usize, arg2: usize, arg3: usize, arg4: usize, arg5: usize) usize {
5454 return asm volatile ("syscall"
5555 : [ret] "={rax}" (-> usize)
56 : [number] "{rax}" (number),
56 : [number] "{rax}" (@enumToInt(number)),
5757 [arg1] "{rdi}" (arg1),
5858 [arg2] "{rsi}" (arg2),
5959 [arg3] "{rdx}" (arg3),
......@@ -64,7 +64,7 @@ pub fn syscall5(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usiz
6464}
6565
6666pub fn syscall6(
67 number: usize,
67 number: SYS,
6868 arg1: usize,
6969 arg2: usize,
7070 arg3: usize,
......@@ -74,7 +74,7 @@ pub fn syscall6(
7474) usize {
7575 return asm volatile ("syscall"
7676 : [ret] "={rax}" (-> usize)
77 : [number] "{rax}" (number),
77 : [number] "{rax}" (@enumToInt(number)),
7878 [arg1] "{rdi}" (arg1),
7979 [arg2] "{rsi}" (arg2),
8080 [arg3] "{rdx}" (arg3),
......@@ -93,7 +93,7 @@ pub const restore = restore_rt;
9393pub fn restore_rt() callconv(.Naked) void {
9494 return asm volatile ("syscall"
9595 :
96 : [number] "{rax}" (@as(usize, SYS_rt_sigreturn))
96 : [number] "{rax}" (@enumToInt(SYS.rt_sigreturn))
9797 : "rcx", "r11", "memory"
9898 );
9999}
lib/std/os/test.zig+8-8
......@@ -18,8 +18,8 @@ const AtomicOrder = builtin.AtomicOrder;
1818
1919test "makePath, put some files in it, deleteTree" {
2020 try fs.cwd().makePath("os_test_tmp" ++ fs.path.sep_str ++ "b" ++ fs.path.sep_str ++ "c");
21 try io.writeFile("os_test_tmp" ++ fs.path.sep_str ++ "b" ++ fs.path.sep_str ++ "c" ++ fs.path.sep_str ++ "file.txt", "nonsense");
22 try io.writeFile("os_test_tmp" ++ fs.path.sep_str ++ "b" ++ fs.path.sep_str ++ "file2.txt", "blah");
21 try fs.cwd().writeFile("os_test_tmp" ++ fs.path.sep_str ++ "b" ++ fs.path.sep_str ++ "c" ++ fs.path.sep_str ++ "file.txt", "nonsense");
22 try fs.cwd().writeFile("os_test_tmp" ++ fs.path.sep_str ++ "b" ++ fs.path.sep_str ++ "file2.txt", "blah");
2323 try fs.cwd().deleteTree("os_test_tmp");
2424 if (fs.cwd().openDir("os_test_tmp", .{})) |dir| {
2525 @panic("expected error");
......@@ -36,8 +36,8 @@ test "access file" {
3636 expect(err == error.FileNotFound);
3737 }
3838
39 try io.writeFile("os_test_tmp" ++ fs.path.sep_str ++ "file.txt", "");
40 try os.access("os_test_tmp" ++ fs.path.sep_str ++ "file.txt", os.F_OK);
39 try fs.cwd().writeFile("os_test_tmp" ++ fs.path.sep_str ++ "file.txt", "");
40 try fs.cwd().access("os_test_tmp" ++ fs.path.sep_str ++ "file.txt", .{});
4141 try fs.cwd().deleteTree("os_test_tmp");
4242}
4343
......@@ -65,12 +65,12 @@ test "sendfile" {
6565 },
6666 };
6767
68 var src_file = try dir.createFileC("sendfile1.txt", .{ .read = true });
68 var src_file = try dir.createFileZ("sendfile1.txt", .{ .read = true });
6969 defer src_file.close();
7070
7171 try src_file.writevAll(&vecs);
7272
73 var dest_file = try dir.createFileC("sendfile2.txt", .{ .read = true });
73 var dest_file = try dir.createFileZ("sendfile2.txt", .{ .read = true });
7474 defer dest_file.close();
7575
7676 const header1 = "header1\n";
......@@ -192,12 +192,12 @@ test "AtomicFile" {
192192 \\ this is a test file
193193 ;
194194 {
195 var af = try fs.AtomicFile.init(test_out_file, File.default_mode);
195 var af = try fs.cwd().atomicFile(test_out_file, .{});
196196 defer af.deinit();
197197 try af.file.writeAll(test_content);
198198 try af.finish();
199199 }
200 const content = try io.readFileAlloc(testing.allocator, test_out_file);
200 const content = try fs.cwd().readFileAlloc(testing.allocator, test_out_file, 9999);
201201 defer testing.allocator.free(content);
202202 expect(mem.eql(u8, content, test_content));
203203
lib/std/os/windows.zig+5-5
......@@ -119,7 +119,7 @@ pub fn OpenFileW(
119119
120120 var result: HANDLE = undefined;
121121
122 const path_len_bytes = math.cast(u16, mem.toSliceConst(u16, sub_path_w).len * 2) catch |err| switch (err) {
122 const path_len_bytes = math.cast(u16, mem.lenZ(sub_path_w) * 2) catch |err| switch (err) {
123123 error.Overflow => return error.NameTooLong,
124124 };
125125 var nt_name = UNICODE_STRING{
......@@ -697,7 +697,7 @@ pub fn CreateDirectoryW(
697697 sub_path_w: [*:0]const u16,
698698 sa: ?*SECURITY_ATTRIBUTES,
699699) CreateDirectoryError!HANDLE {
700 const path_len_bytes = math.cast(u16, mem.toSliceConst(u16, sub_path_w).len * 2) catch |err| switch (err) {
700 const path_len_bytes = math.cast(u16, mem.lenZ(sub_path_w) * 2) catch |err| switch (err) {
701701 error.Overflow => return error.NameTooLong,
702702 };
703703 var nt_name = UNICODE_STRING{
......@@ -905,7 +905,7 @@ pub fn WSAStartup(majorVersion: u8, minorVersion: u8) !ws2_32.WSADATA {
905905 var wsadata: ws2_32.WSADATA = undefined;
906906 return switch (ws2_32.WSAStartup((@as(WORD, minorVersion) << 8) | majorVersion, &wsadata)) {
907907 0 => wsadata,
908 else => |err| unexpectedWSAError(@intToEnum(WinsockError, err)),
908 else => |err| unexpectedWSAError(@intToEnum(ws2_32.WinsockError, @intCast(u16, err))),
909909 };
910910}
911911
......@@ -1226,7 +1226,7 @@ pub fn nanoSecondsToFileTime(ns: i64) FILETIME {
12261226}
12271227
12281228pub fn cStrToPrefixedFileW(s: [*:0]const u8) ![PATH_MAX_WIDE:0]u16 {
1229 return sliceToPrefixedFileW(mem.toSliceConst(u8, s));
1229 return sliceToPrefixedFileW(mem.spanZ(s));
12301230}
12311231
12321232pub fn sliceToPrefixedFileW(s: []const u8) ![PATH_MAX_WIDE:0]u16 {
......@@ -1304,7 +1304,7 @@ pub fn unexpectedError(err: Win32Error) std.os.UnexpectedError {
13041304 return error.Unexpected;
13051305}
13061306
1307pub fn unexpectedWSAError(err: WinsockError) std.os.UnexpectedError {
1307pub fn unexpectedWSAError(err: ws2_32.WinsockError) std.os.UnexpectedError {
13081308 return unexpectedError(@intToEnum(Win32Error, @enumToInt(err)));
13091309}
13101310
lib/std/pdb.zig+1-1
......@@ -649,7 +649,7 @@ const MsfStream = struct {
649649 while (true) {
650650 const byte = try self.inStream().readByte();
651651 if (byte == 0) {
652 return list.toSlice();
652 return list.span();
653653 }
654654 try list.append(byte);
655655 }
lib/std/process.zig+7-7
......@@ -83,7 +83,7 @@ pub fn getEnvMap(allocator: *Allocator) !BufMap {
8383
8484 for (environ) |env| {
8585 if (env) |ptr| {
86 const pair = mem.toSlice(u8, ptr);
86 const pair = mem.spanZ(ptr);
8787 var parts = mem.separate(pair, "=");
8888 const key = parts.next().?;
8989 const value = parts.next().?;
......@@ -176,7 +176,7 @@ pub const ArgIteratorPosix = struct {
176176
177177 const s = os.argv[self.index];
178178 self.index += 1;
179 return mem.toSlice(u8, s);
179 return mem.spanZ(s);
180180 }
181181
182182 pub fn skip(self: *ArgIteratorPosix) bool {
......@@ -401,7 +401,7 @@ pub fn argsAlloc(allocator: *mem.Allocator) ![][]u8 {
401401
402402 var i: usize = 0;
403403 while (i < count) : (i += 1) {
404 result_slice[i] = mem.toSlice(u8, argv[i]);
404 result_slice[i] = mem.spanZ(argv[i]);
405405 }
406406
407407 return result_slice;
......@@ -422,8 +422,8 @@ pub fn argsAlloc(allocator: *mem.Allocator) ![][]u8 {
422422 try slice_list.append(arg.len);
423423 }
424424
425 const contents_slice = contents.toSliceConst();
426 const slice_sizes = slice_list.toSliceConst();
425 const contents_slice = contents.span();
426 const slice_sizes = slice_list.span();
427427 const slice_list_bytes = try math.mul(usize, @sizeOf([]u8), slice_sizes.len);
428428 const total_bytes = try math.add(usize, slice_list_bytes, contents_slice.len);
429429 const buf = try allocator.alignedAlloc(u8, @alignOf([]u8), total_bytes);
......@@ -636,7 +636,7 @@ pub fn getSelfExeSharedLibPaths(allocator: *Allocator) error{OutOfMemory}![][:0]
636636 fn callback(info: *os.dl_phdr_info, size: usize, list: *List) !void {
637637 const name = info.dlpi_name orelse return;
638638 if (name[0] == '/') {
639 const item = try mem.dupeZ(list.allocator, u8, mem.toSliceConst(u8, name));
639 const item = try mem.dupeZ(list.allocator, u8, mem.spanZ(name));
640640 errdefer list.allocator.free(item);
641641 try list.append(item);
642642 }
......@@ -657,7 +657,7 @@ pub fn getSelfExeSharedLibPaths(allocator: *Allocator) error{OutOfMemory}![][:0]
657657 var i: u32 = 0;
658658 while (i < img_count) : (i += 1) {
659659 const name = std.c._dyld_get_image_name(i);
660 const item = try mem.dupeZ(allocator, u8, mem.toSliceConst(u8, name));
660 const item = try mem.dupeZ(allocator, u8, mem.spanZ(name));
661661 errdefer allocator.free(item);
662662 try paths.append(item);
663663 }
lib/std/rand.zig+13-19
......@@ -59,7 +59,7 @@ pub const Random = struct {
5959 return @bitCast(T, unsigned_result);
6060 }
6161
62 /// Constant-time implementation off ::uintLessThan.
62 /// Constant-time implementation off `uintLessThan`.
6363 /// The results of this function may be biased.
6464 pub fn uintLessThanBiased(r: *Random, comptime T: type, less_than: T) T {
6565 comptime assert(T.is_signed == false);
......@@ -73,13 +73,13 @@ pub const Random = struct {
7373 }
7474
7575 /// Returns an evenly distributed random unsigned integer `0 <= i < less_than`.
76 /// This function assumes that the underlying ::fillFn produces evenly distributed values.
76 /// This function assumes that the underlying `fillFn` produces evenly distributed values.
7777 /// Within this assumption, the runtime of this function is exponentially distributed.
78 /// If ::fillFn were backed by a true random generator,
78 /// If `fillFn` were backed by a true random generator,
7979 /// the runtime of this function would technically be unbounded.
80 /// However, if ::fillFn is backed by any evenly distributed pseudo random number generator,
80 /// However, if `fillFn` is backed by any evenly distributed pseudo random number generator,
8181 /// this function is guaranteed to return.
82 /// If you need deterministic runtime bounds, use `::uintLessThanBiased`.
82 /// If you need deterministic runtime bounds, use `uintLessThanBiased`.
8383 pub fn uintLessThan(r: *Random, comptime T: type, less_than: T) T {
8484 comptime assert(T.is_signed == false);
8585 comptime assert(T.bit_count <= 64); // TODO: workaround: LLVM ERROR: Unsupported library call operation!
......@@ -116,7 +116,7 @@ pub const Random = struct {
116116 return @intCast(T, m >> Small.bit_count);
117117 }
118118
119 /// Constant-time implementation off ::uintAtMost.
119 /// Constant-time implementation off `uintAtMost`.
120120 /// The results of this function may be biased.
121121 pub fn uintAtMostBiased(r: *Random, comptime T: type, at_most: T) T {
122122 assert(T.is_signed == false);
......@@ -128,7 +128,7 @@ pub const Random = struct {
128128 }
129129
130130 /// Returns an evenly distributed random unsigned integer `0 <= i <= at_most`.
131 /// See ::uintLessThan, which this function uses in most cases,
131 /// See `uintLessThan`, which this function uses in most cases,
132132 /// for commentary on the runtime of this function.
133133 pub fn uintAtMost(r: *Random, comptime T: type, at_most: T) T {
134134 assert(T.is_signed == false);
......@@ -139,7 +139,7 @@ pub const Random = struct {
139139 return r.uintLessThan(T, at_most + 1);
140140 }
141141
142 /// Constant-time implementation off ::intRangeLessThan.
142 /// Constant-time implementation off `intRangeLessThan`.
143143 /// The results of this function may be biased.
144144 pub fn intRangeLessThanBiased(r: *Random, comptime T: type, at_least: T, less_than: T) T {
145145 assert(at_least < less_than);
......@@ -157,7 +157,7 @@ pub const Random = struct {
157157 }
158158
159159 /// Returns an evenly distributed random integer `at_least <= i < less_than`.
160 /// See ::uintLessThan, which this function uses in most cases,
160 /// See `uintLessThan`, which this function uses in most cases,
161161 /// for commentary on the runtime of this function.
162162 pub fn intRangeLessThan(r: *Random, comptime T: type, at_least: T, less_than: T) T {
163163 assert(at_least < less_than);
......@@ -174,7 +174,7 @@ pub const Random = struct {
174174 }
175175 }
176176
177 /// Constant-time implementation off ::intRangeAtMostBiased.
177 /// Constant-time implementation off `intRangeAtMostBiased`.
178178 /// The results of this function may be biased.
179179 pub fn intRangeAtMostBiased(r: *Random, comptime T: type, at_least: T, at_most: T) T {
180180 assert(at_least <= at_most);
......@@ -192,7 +192,7 @@ pub const Random = struct {
192192 }
193193
194194 /// Returns an evenly distributed random integer `at_least <= i <= at_most`.
195 /// See ::uintLessThan, which this function uses in most cases,
195 /// See `uintLessThan`, which this function uses in most cases,
196196 /// for commentary on the runtime of this function.
197197 pub fn intRangeAtMost(r: *Random, comptime T: type, at_least: T, at_most: T) T {
198198 assert(at_least <= at_most);
......@@ -209,15 +209,9 @@ pub const Random = struct {
209209 }
210210 }
211211
212 /// TODO: deprecated. use ::boolean or ::int instead.
213 pub fn scalar(r: *Random, comptime T: type) T {
214 return if (T == bool) r.boolean() else r.int(T);
215 }
212 pub const scalar = @compileError("deprecated; use boolean() or int() instead");
216213
217 /// TODO: deprecated. renamed to ::intRangeLessThan
218 pub fn range(r: *Random, comptime T: type, start: T, end: T) T {
219 return r.intRangeLessThan(T, start, end);
220 }
214 pub const range = @compileError("deprecated; use intRangeLessThan()");
221215
222216 /// Return a floating point value evenly distributed in the range [0, 1).
223217 pub fn float(r: *Random, comptime T: type) T {
lib/std/sort.zig+2-2
......@@ -1227,13 +1227,13 @@ test "sort fuzz testing" {
12271227var fixed_buffer_mem: [100 * 1024]u8 = undefined;
12281228
12291229fn fuzzTest(rng: *std.rand.Random) !void {
1230 const array_size = rng.range(usize, 0, 1000);
1230 const array_size = rng.intRangeLessThan(usize, 0, 1000);
12311231 var array = try testing.allocator.alloc(IdAndValue, array_size);
12321232 defer testing.allocator.free(array);
12331233 // populate with random data
12341234 for (array) |*item, index| {
12351235 item.id = index;
1236 item.value = rng.range(i32, 0, 100);
1236 item.value = rng.intRangeLessThan(i32, 0, 100);
12371237 }
12381238 sort(IdAndValue, array, cmpByValue);
12391239
lib/std/special/build_runner.zig+3-3
......@@ -116,7 +116,7 @@ pub fn main() !void {
116116 if (builder.validateUserInputDidItFail())
117117 return usageAndErr(builder, true, stderr_stream);
118118
119 builder.make(targets.toSliceConst()) catch |err| {
119 builder.make(targets.span()) catch |err| {
120120 switch (err) {
121121 error.InvalidStepName => {
122122 return usageAndErr(builder, true, stderr_stream);
......@@ -151,7 +151,7 @@ fn usage(builder: *Builder, already_ran_build: bool, out_stream: var) !void {
151151 , .{builder.zig_exe});
152152
153153 const allocator = builder.allocator;
154 for (builder.top_level_steps.toSliceConst()) |top_level_step| {
154 for (builder.top_level_steps.span()) |top_level_step| {
155155 const name = if (&top_level_step.step == builder.default_step)
156156 try fmt.allocPrint(allocator, "{} (default)", .{top_level_step.step.name})
157157 else
......@@ -174,7 +174,7 @@ fn usage(builder: *Builder, already_ran_build: bool, out_stream: var) !void {
174174 if (builder.available_options_list.len == 0) {
175175 try out_stream.print(" (none)\n", .{});
176176 } else {
177 for (builder.available_options_list.toSliceConst()) |option| {
177 for (builder.available_options_list.span()) |option| {
178178 const name = try fmt.allocPrint(allocator, " -D{}=[{}]", .{
179179 option.name,
180180 Builder.typeIdName(option.type_id),
lib/std/special/compiler_rt.zig+20-7
......@@ -10,13 +10,19 @@ comptime {
1010 const strong_linkage = if (is_test) builtin.GlobalLinkage.Internal else builtin.GlobalLinkage.Strong;
1111
1212 switch (builtin.arch) {
13 .i386, .x86_64 => @export(@import("compiler_rt/stack_probe.zig").zig_probe_stack, .{ .name = "__zig_probe_stack", .linkage = linkage }),
14 .aarch64, .aarch64_be, .aarch64_32 => {
15 @export(@import("compiler_rt/clear_cache.zig").clear_cache, .{ .name = "__clear_cache", .linkage = linkage });
16 },
13 .i386,
14 .x86_64,
15 => @export(@import("compiler_rt/stack_probe.zig").zig_probe_stack, .{
16 .name = "__zig_probe_stack",
17 .linkage = linkage,
18 }),
19
1720 else => {},
1821 }
1922
23 // __clear_cache manages its own logic about whether to be exported or not.
24 _ = @import("compiler_rt/clear_cache.zig").clear_cache;
25
2026 @export(@import("compiler_rt/compareXf2.zig").__lesf2, .{ .name = "__lesf2", .linkage = linkage });
2127 @export(@import("compiler_rt/compareXf2.zig").__ledf2, .{ .name = "__ledf2", .linkage = linkage });
2228 @export(@import("compiler_rt/compareXf2.zig").__letf2, .{ .name = "__letf2", .linkage = linkage });
......@@ -69,9 +75,12 @@ comptime {
6975 @export(@import("compiler_rt/divdf3.zig").__divdf3, .{ .name = "__divdf3", .linkage = linkage });
7076 @export(@import("compiler_rt/divtf3.zig").__divtf3, .{ .name = "__divtf3", .linkage = linkage });
7177
72 @export(@import("compiler_rt/ashlti3.zig").__ashlti3, .{ .name = "__ashlti3", .linkage = linkage });
73 @export(@import("compiler_rt/lshrti3.zig").__lshrti3, .{ .name = "__lshrti3", .linkage = linkage });
74 @export(@import("compiler_rt/ashrti3.zig").__ashrti3, .{ .name = "__ashrti3", .linkage = linkage });
78 @export(@import("compiler_rt/shift.zig").__ashldi3, .{ .name = "__ashldi3", .linkage = linkage });
79 @export(@import("compiler_rt/shift.zig").__ashlti3, .{ .name = "__ashlti3", .linkage = linkage });
80 @export(@import("compiler_rt/shift.zig").__ashrdi3, .{ .name = "__ashrdi3", .linkage = linkage });
81 @export(@import("compiler_rt/shift.zig").__ashrti3, .{ .name = "__ashrti3", .linkage = linkage });
82 @export(@import("compiler_rt/shift.zig").__lshrdi3, .{ .name = "__lshrdi3", .linkage = linkage });
83 @export(@import("compiler_rt/shift.zig").__lshrti3, .{ .name = "__lshrti3", .linkage = linkage });
7584
7685 @export(@import("compiler_rt/floatsiXf.zig").__floatsidf, .{ .name = "__floatsidf", .linkage = linkage });
7786 @export(@import("compiler_rt/floatsiXf.zig").__floatsisf, .{ .name = "__floatsisf", .linkage = linkage });
......@@ -229,6 +238,10 @@ comptime {
229238 @export(@import("compiler_rt/divsf3.zig").__aeabi_fdiv, .{ .name = "__aeabi_fdiv", .linkage = linkage });
230239 @export(@import("compiler_rt/divdf3.zig").__aeabi_ddiv, .{ .name = "__aeabi_ddiv", .linkage = linkage });
231240
241 @export(@import("compiler_rt/shift.zig").__aeabi_llsl, .{ .name = "__aeabi_llsl", .linkage = linkage });
242 @export(@import("compiler_rt/shift.zig").__aeabi_lasr, .{ .name = "__aeabi_lasr", .linkage = linkage });
243 @export(@import("compiler_rt/shift.zig").__aeabi_llsr, .{ .name = "__aeabi_llsr", .linkage = linkage });
244
232245 @export(@import("compiler_rt/compareXf2.zig").__aeabi_fcmpeq, .{ .name = "__aeabi_fcmpeq", .linkage = linkage });
233246 @export(@import("compiler_rt/compareXf2.zig").__aeabi_fcmplt, .{ .name = "__aeabi_fcmplt", .linkage = linkage });
234247 @export(@import("compiler_rt/compareXf2.zig").__aeabi_fcmple, .{ .name = "__aeabi_fcmple", .linkage = linkage });
lib/std/special/compiler_rt/ashldi3_test.zig created+32
......@@ -0,0 +1,32 @@
1const __ashldi3 = @import("shift.zig").__ashldi3;
2const testing = @import("std").testing;
3
4fn test__ashldi3(a: i64, b: i32, expected: u64) void {
5 const x = __ashldi3(a, b);
6 testing.expectEqual(@bitCast(i64, expected), x);
7}
8
9test "ashldi3" {
10 test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 0, 0x123456789ABCDEF);
11 test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 1, 0x2468ACF13579BDE);
12 test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 2, 0x48D159E26AF37BC);
13 test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 3, 0x91A2B3C4D5E6F78);
14 test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 4, 0x123456789ABCDEF0);
15
16 test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 28, 0x789ABCDEF0000000);
17 test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 29, 0xF13579BDE0000000);
18 test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 30, 0xE26AF37BC0000000);
19 test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 31, 0xC4D5E6F780000000);
20
21 test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 32, 0x89ABCDEF00000000);
22
23 test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 33, 0x13579BDE00000000);
24 test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 34, 0x26AF37BC00000000);
25 test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 35, 0x4D5E6F7800000000);
26 test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 36, 0x9ABCDEF000000000);
27
28 test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 60, 0xF000000000000000);
29 test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 61, 0xE000000000000000);
30 test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 62, 0xC000000000000000);
31 test__ashldi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 63, 0x8000000000000000);
32}
lib/std/special/compiler_rt/ashlti3.zig deleted-41
......@@ -1,41 +0,0 @@
1const builtin = @import("builtin");
2const compiler_rt = @import("../compiler_rt.zig");
3
4pub fn __ashlti3(a: i128, b: i32) callconv(.C) i128 {
5 var input = twords{ .all = a };
6 var result: twords = undefined;
7
8 if (b > 63) {
9 // 64 <= b < 128
10 result.s.low = 0;
11 result.s.high = input.s.low << @intCast(u6, b - 64);
12 } else {
13 // 0 <= b < 64
14 if (b == 0) return a;
15 result.s.low = input.s.low << @intCast(u6, b);
16 result.s.high = input.s.low >> @intCast(u6, 64 - b);
17 result.s.high |= input.s.high << @intCast(u6, b);
18 }
19
20 return result.all;
21}
22
23const twords = extern union {
24 all: i128,
25 s: S,
26
27 const S = if (builtin.endian == .Little)
28 struct {
29 low: u64,
30 high: u64,
31 }
32 else
33 struct {
34 high: u64,
35 low: u64,
36 };
37};
38
39test "import ashlti3" {
40 _ = @import("ashlti3_test.zig");
41}
lib/std/special/compiler_rt/ashlti3_test.zig+2-2
......@@ -1,9 +1,9 @@
1const __ashlti3 = @import("ashlti3.zig").__ashlti3;
1const __ashlti3 = @import("shift.zig").__ashlti3;
22const testing = @import("std").testing;
33
44fn test__ashlti3(a: i128, b: i32, expected: i128) void {
55 const x = __ashlti3(a, b);
6 testing.expect(x == expected);
6 testing.expectEqual(expected, x);
77}
88
99test "ashlti3" {
lib/std/special/compiler_rt/ashrdi3_test.zig created+55
......@@ -0,0 +1,55 @@
1const __ashrdi3 = @import("shift.zig").__ashrdi3;
2const testing = @import("std").testing;
3
4fn test__ashrdi3(a: i64, b: i32, expected: u64) void {
5 const x = __ashrdi3(a, b);
6 testing.expectEqual(@bitCast(i64, expected), x);
7}
8
9test "ashrdi3" {
10 test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 0, 0x123456789ABCDEF);
11 test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 1, 0x91A2B3C4D5E6F7);
12 test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 2, 0x48D159E26AF37B);
13 test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 3, 0x2468ACF13579BD);
14 test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 4, 0x123456789ABCDE);
15
16 test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 28, 0x12345678);
17 test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 29, 0x91A2B3C);
18 test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 30, 0x48D159E);
19 test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 31, 0x2468ACF);
20
21 test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 32, 0x1234567);
22
23 test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 33, 0x91A2B3);
24 test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 34, 0x48D159);
25 test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 35, 0x2468AC);
26 test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 36, 0x123456);
27
28 test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 60, 0);
29 test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 61, 0);
30 test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 62, 0);
31 test__ashrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 63, 0);
32
33 test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 0, 0xFEDCBA9876543210);
34 test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 1, 0xFF6E5D4C3B2A1908);
35 test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 2, 0xFFB72EA61D950C84);
36 test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 3, 0xFFDB97530ECA8642);
37 test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 4, 0xFFEDCBA987654321);
38
39 test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 28, 0xFFFFFFFFEDCBA987);
40 test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 29, 0xFFFFFFFFF6E5D4C3);
41 test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 30, 0xFFFFFFFFFB72EA61);
42 test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 31, 0xFFFFFFFFFDB97530);
43
44 test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 32, 0xFFFFFFFFFEDCBA98);
45
46 test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 33, 0xFFFFFFFFFF6E5D4C);
47 test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 34, 0xFFFFFFFFFFB72EA6);
48 test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 35, 0xFFFFFFFFFFDB9753);
49 test__ashrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 36, 0xFFFFFFFFFFEDCBA9);
50
51 test__ashrdi3(@bitCast(i64, @as(u64, 0xAEDCBA9876543210)), 60, 0xFFFFFFFFFFFFFFFA);
52 test__ashrdi3(@bitCast(i64, @as(u64, 0xAEDCBA9876543210)), 61, 0xFFFFFFFFFFFFFFFD);
53 test__ashrdi3(@bitCast(i64, @as(u64, 0xAEDCBA9876543210)), 62, 0xFFFFFFFFFFFFFFFE);
54 test__ashrdi3(@bitCast(i64, @as(u64, 0xAEDCBA9876543210)), 63, 0xFFFFFFFFFFFFFFFF);
55}
lib/std/special/compiler_rt/ashrti3.zig deleted-42
......@@ -1,42 +0,0 @@
1const builtin = @import("builtin");
2const compiler_rt = @import("../compiler_rt.zig");
3
4pub fn __ashrti3(a: i128, b: i32) callconv(.C) i128 {
5 var input = twords{ .all = a };
6 var result: twords = undefined;
7
8 if (b > 63) {
9 // 64 <= b < 128
10 result.s.low = input.s.high >> @intCast(u6, b - 64);
11 result.s.high = input.s.high >> 63;
12 } else {
13 // 0 <= b < 64
14 if (b == 0) return a;
15 result.s.low = input.s.high << @intCast(u6, 64 - b);
16 // Avoid sign-extension here
17 result.s.low |= @bitCast(i64, @bitCast(u64, input.s.low) >> @intCast(u6, b));
18 result.s.high = input.s.high >> @intCast(u6, b);
19 }
20
21 return result.all;
22}
23
24const twords = extern union {
25 all: i128,
26 s: S,
27
28 const S = if (builtin.endian == .Little)
29 struct {
30 low: i64,
31 high: i64,
32 }
33 else
34 struct {
35 high: i64,
36 low: i64,
37 };
38};
39
40test "import ashrti3" {
41 _ = @import("ashrti3_test.zig");
42}
lib/std/special/compiler_rt/ashrti3_test.zig+2-4
......@@ -1,11 +1,9 @@
1const __ashrti3 = @import("ashrti3.zig").__ashrti3;
1const __ashrti3 = @import("shift.zig").__ashrti3;
22const testing = @import("std").testing;
33
44fn test__ashrti3(a: i128, b: i32, expected: i128) void {
55 const x = __ashrti3(a, b);
6 // @import("std").debug.warn("got 0x{x}\nexp 0x{x}\n", .{@truncate(u64,
7 // @bitCast(u128, x) >> 64), @truncate(u64, @bitCast(u128, expected)) >> 64});
8 testing.expect(x == expected);
6 testing.expectEqual(expected, x);
97}
108
119test "ashrti3" {
lib/std/special/compiler_rt/clear_cache.zig+53-37
......@@ -26,6 +26,10 @@ pub fn clear_cache(start: usize, end: usize) callconv(.C) void {
2626 .mips, .mipsel, .mips64, .mips64el => true,
2727 else => false,
2828 };
29 const riscv = switch (arch) {
30 .riscv32, .riscv64 => true,
31 else => false,
32 };
2933 const powerpc64 = switch (arch) {
3034 .powerpc64, .powerpc64le => true,
3135 else => false,
......@@ -41,45 +45,42 @@ pub fn clear_cache(start: usize, end: usize) callconv(.C) void {
4145 if (x86) {
4246 // Intel processors have a unified instruction and data cache
4347 // so there is nothing to do
48 exportIt();
4449 } else if (os == .windows and (arm32 or arm64)) {
45 @compileError("TODO");
50 // TODO
4651 // FlushInstructionCache(GetCurrentProcess(), start, end - start);
52 // exportIt();
4753 } else if (arm32 and !apple) {
48 @compileError("TODO");
49 //#if defined(__FreeBSD__) || defined(__NetBSD__)
50 // struct arm_sync_icache_args arg;
51 //
52 // arg.addr = (uintptr_t)start;
53 // arg.len = (uintptr_t)end - (uintptr_t)start;
54 //
55 // sysarch(ARM_SYNC_ICACHE, &arg);
56 //#elif defined(__linux__)
57 //// We used to include asm/unistd.h for the __ARM_NR_cacheflush define, but
58 //// it also brought many other unused defines, as well as a dependency on
59 //// kernel headers to be installed.
60 ////
61 //// This value is stable at least since Linux 3.13 and should remain so for
62 //// compatibility reasons, warranting it's re-definition here.
63 //#define __ARM_NR_cacheflush 0x0f0002
64 // register int start_reg __asm("r0") = (int)(intptr_t)start;
65 // const register int end_reg __asm("r1") = (int)(intptr_t)end;
66 // const register int flags __asm("r2") = 0;
67 // const register int syscall_nr __asm("r7") = __ARM_NR_cacheflush;
68 // __asm __volatile("svc 0x0"
69 // : "=r"(start_reg)
70 // : "r"(syscall_nr), "r"(start_reg), "r"(end_reg), "r"(flags));
71 // assert(start_reg == 0 && "Cache flush syscall failed.");
72 //#else
73 // compilerrt_abort();
74 //#endif
54 switch (os) {
55 .freebsd, .netbsd => {
56 var arg = arm_sync_icache_args{
57 .addr = start,
58 .len = end - start,
59 };
60 const result = sysarch(ARM_SYNC_ICACHE, @ptrToInt(&arg));
61 std.debug.assert(result == 0);
62 exportIt();
63 },
64 .linux => {
65 const result = std.os.linux.syscall3(.cacheflush, start, end, 0);
66 std.debug.assert(result == 0);
67 exportIt();
68 },
69 else => {},
70 }
7571 } else if (os == .linux and mips) {
76 @compileError("TODO");
77 //const uintptr_t start_int = (uintptr_t)start;
78 //const uintptr_t end_int = (uintptr_t)end;
79 //syscall(__NR_cacheflush, start, (end_int - start_int), BCACHE);
72 const flags = 3; // ICACHE | DCACHE
73 const result = std.os.linux.syscall3(.cacheflush, start, end - start, flags);
74 std.debug.assert(result == 0);
75 exportIt();
8076 } else if (mips and os == .openbsd) {
81 @compileError("TODO");
77 // TODO
8278 //cacheflush(start, (uintptr_t)end - (uintptr_t)start, BCACHE);
79 // exportIt();
80 } else if (os == .linux and riscv) {
81 const result = std.os.linux.syscall3(.riscv_flush_icache, start, end - start, 0);
82 std.debug.assert(result == 0);
83 exportIt();
8384 } else if (arm64 and !apple) {
8485 // Get Cache Type Info.
8586 // TODO memoize this?
......@@ -118,8 +119,9 @@ pub fn clear_cache(start: usize, end: usize) callconv(.C) void {
118119 }
119120 }
120121 asm volatile ("isb sy");
122 exportIt();
121123 } else if (powerpc64) {
122 @compileError("TODO");
124 // TODO
123125 //const size_t line_size = 32;
124126 //const size_t len = (uintptr_t)end - (uintptr_t)start;
125127 //
......@@ -134,8 +136,9 @@ pub fn clear_cache(start: usize, end: usize) callconv(.C) void {
134136 //for (uintptr_t line = start_line; line < end_line; line += line_size)
135137 // __asm__ volatile("icbi 0, %0" : : "r"(line));
136138 //__asm__ volatile("isync");
139 // exportIt();
137140 } else if (sparc) {
138 @compileError("TODO");
141 // TODO
139142 //const size_t dword_size = 8;
140143 //const size_t len = (uintptr_t)end - (uintptr_t)start;
141144 //
......@@ -145,13 +148,26 @@ pub fn clear_cache(start: usize, end: usize) callconv(.C) void {
145148 //
146149 //for (uintptr_t dword = start_dword; dword < end_dword; dword += dword_size)
147150 // __asm__ volatile("flush %0" : : "r"(dword));
151 // exportIt();
148152 } else if (apple) {
149153 // On Darwin, sys_icache_invalidate() provides this functionality
150154 sys_icache_invalidate(start, end - start);
151 } else {
152 @compileError("no __clear_cache implementation available for this target");
155 exportIt();
153156 }
154157}
155158
159const linkage = if (std.builtin.is_test) std.builtin.GlobalLinkage.Internal else std.builtin.GlobalLinkage.Weak;
160
161fn exportIt() void {
162 @export(clear_cache, .{ .name = "__clear_cache", .linkage = linkage });
163}
164
156165// Darwin-only
157166extern fn sys_icache_invalidate(start: usize, len: usize) void;
167// BSD-only
168const arm_sync_icache_args = extern struct {
169 addr: usize, // Virtual start address
170 len: usize, // Region size
171};
172const ARM_SYNC_ICACHE = 0;
173extern "c" fn sysarch(number: i32, args: usize) i32;
lib/std/special/compiler_rt/lshrdi3_test.zig created+55
......@@ -0,0 +1,55 @@
1const __lshrdi3 = @import("shift.zig").__lshrdi3;
2const testing = @import("std").testing;
3
4fn test__lshrdi3(a: i64, b: i32, expected: u64) void {
5 const x = __lshrdi3(a, b);
6 testing.expectEqual(@bitCast(i64, expected), x);
7}
8
9test "lshrdi3" {
10 test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 0, 0x123456789ABCDEF);
11 test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 1, 0x91A2B3C4D5E6F7);
12 test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 2, 0x48D159E26AF37B);
13 test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 3, 0x2468ACF13579BD);
14 test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 4, 0x123456789ABCDE);
15
16 test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 28, 0x12345678);
17 test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 29, 0x91A2B3C);
18 test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 30, 0x48D159E);
19 test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 31, 0x2468ACF);
20
21 test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 32, 0x1234567);
22
23 test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 33, 0x91A2B3);
24 test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 34, 0x48D159);
25 test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 35, 0x2468AC);
26 test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 36, 0x123456);
27
28 test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 60, 0);
29 test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 61, 0);
30 test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 62, 0);
31 test__lshrdi3(@bitCast(i64, @as(u64, 0x0123456789ABCDEF)), 63, 0);
32
33 test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 0, 0xFEDCBA9876543210);
34 test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 1, 0x7F6E5D4C3B2A1908);
35 test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 2, 0x3FB72EA61D950C84);
36 test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 3, 0x1FDB97530ECA8642);
37 test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 4, 0xFEDCBA987654321);
38
39 test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 28, 0xFEDCBA987);
40 test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 29, 0x7F6E5D4C3);
41 test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 30, 0x3FB72EA61);
42 test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 31, 0x1FDB97530);
43
44 test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 32, 0xFEDCBA98);
45
46 test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 33, 0x7F6E5D4C);
47 test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 34, 0x3FB72EA6);
48 test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 35, 0x1FDB9753);
49 test__lshrdi3(@bitCast(i64, @as(u64, 0xFEDCBA9876543210)), 36, 0xFEDCBA9);
50
51 test__lshrdi3(@bitCast(i64, @as(u64, 0xAEDCBA9876543210)), 60, 0xA);
52 test__lshrdi3(@bitCast(i64, @as(u64, 0xAEDCBA9876543210)), 61, 0x5);
53 test__lshrdi3(@bitCast(i64, @as(u64, 0xAEDCBA9876543210)), 62, 0x2);
54 test__lshrdi3(@bitCast(i64, @as(u64, 0xAEDCBA9876543210)), 63, 0x1);
55}
lib/std/special/compiler_rt/lshrti3.zig deleted-41
......@@ -1,41 +0,0 @@
1const builtin = @import("builtin");
2const compiler_rt = @import("../compiler_rt.zig");
3
4pub fn __lshrti3(a: i128, b: i32) callconv(.C) i128 {
5 var input = twords{ .all = a };
6 var result: twords = undefined;
7
8 if (b > 63) {
9 // 64 <= b < 128
10 result.s.low = input.s.high >> @intCast(u6, b - 64);
11 result.s.high = 0;
12 } else {
13 // 0 <= b < 64
14 if (b == 0) return a;
15 result.s.low = input.s.high << @intCast(u6, 64 - b);
16 result.s.low |= input.s.low >> @intCast(u6, b);
17 result.s.high = input.s.high >> @intCast(u6, b);
18 }
19
20 return result.all;
21}
22
23const twords = extern union {
24 all: i128,
25 s: S,
26
27 const S = if (builtin.endian == .Little)
28 struct {
29 low: u64,
30 high: u64,
31 }
32 else
33 struct {
34 high: u64,
35 low: u64,
36 };
37};
38
39test "import lshrti3" {
40 _ = @import("lshrti3_test.zig");
41}
lib/std/special/compiler_rt/lshrti3_test.zig+2-2
......@@ -1,9 +1,9 @@
1const __lshrti3 = @import("lshrti3.zig").__lshrti3;
1const __lshrti3 = @import("shift.zig").__lshrti3;
22const testing = @import("std").testing;
33
44fn test__lshrti3(a: i128, b: i32, expected: i128) void {
55 const x = __lshrti3(a, b);
6 testing.expect(x == expected);
6 testing.expectEqual(expected, x);
77}
88
99test "lshrti3" {
lib/std/special/compiler_rt/shift.zig created+130
......@@ -0,0 +1,130 @@
1const std = @import("std");
2const builtin = std.builtin;
3const Log2Int = std.math.Log2Int;
4
5fn Dwords(comptime T: type, comptime signed_half: bool) type {
6 return extern union {
7 pub const HalfTU = std.meta.IntType(false, @divExact(T.bit_count, 2));
8 pub const HalfTS = std.meta.IntType(true, @divExact(T.bit_count, 2));
9 pub const HalfT = if (signed_half) HalfTS else HalfTU;
10
11 all: T,
12 s: if (builtin.endian == .Little)
13 struct { low: HalfT, high: HalfT }
14 else
15 struct { high: HalfT, low: HalfT },
16 };
17}
18
19// Arithmetic shift left
20// Precondition: 0 <= b < bits_in_dword
21pub fn ashlXi3(comptime T: type, a: T, b: i32) T {
22 const dwords = Dwords(T, false);
23 const S = Log2Int(dwords.HalfT);
24
25 const input = dwords{ .all = a };
26 var output: dwords = undefined;
27
28 if (b >= dwords.HalfT.bit_count) {
29 output.s.low = 0;
30 output.s.high = input.s.low << @intCast(S, b - dwords.HalfT.bit_count);
31 } else if (b == 0) {
32 return a;
33 } else {
34 output.s.low = input.s.low << @intCast(S, b);
35 output.s.high = input.s.high << @intCast(S, b);
36 output.s.high |= input.s.low >> @intCast(S, dwords.HalfT.bit_count - b);
37 }
38
39 return output.all;
40}
41
42// Arithmetic shift right
43// Precondition: 0 <= b < T.bit_count
44pub fn ashrXi3(comptime T: type, a: T, b: i32) T {
45 const dwords = Dwords(T, true);
46 const S = Log2Int(dwords.HalfT);
47
48 const input = dwords{ .all = a };
49 var output: dwords = undefined;
50
51 if (b >= dwords.HalfT.bit_count) {
52 output.s.high = input.s.high >> (dwords.HalfT.bit_count - 1);
53 output.s.low = input.s.high >> @intCast(S, b - dwords.HalfT.bit_count);
54 } else if (b == 0) {
55 return a;
56 } else {
57 output.s.high = input.s.high >> @intCast(S, b);
58 output.s.low = input.s.high << @intCast(S, dwords.HalfT.bit_count - b);
59 // Avoid sign-extension here
60 output.s.low |= @bitCast(
61 dwords.HalfT,
62 @bitCast(dwords.HalfTU, input.s.low) >> @intCast(S, b),
63 );
64 }
65
66 return output.all;
67}
68
69// Logical shift right
70// Precondition: 0 <= b < T.bit_count
71pub fn lshrXi3(comptime T: type, a: T, b: i32) T {
72 const dwords = Dwords(T, false);
73 const S = Log2Int(dwords.HalfT);
74
75 const input = dwords{ .all = a };
76 var output: dwords = undefined;
77
78 if (b >= dwords.HalfT.bit_count) {
79 output.s.high = 0;
80 output.s.low = input.s.high >> @intCast(S, b - dwords.HalfT.bit_count);
81 } else if (b == 0) {
82 return a;
83 } else {
84 output.s.high = input.s.high >> @intCast(S, b);
85 output.s.low = input.s.high << @intCast(S, dwords.HalfT.bit_count - b);
86 output.s.low |= input.s.low >> @intCast(S, b);
87 }
88
89 return output.all;
90}
91
92pub fn __ashldi3(a: i64, b: i32) callconv(.C) i64 {
93 return @call(.{ .modifier = .always_inline }, ashlXi3, .{ i64, a, b });
94}
95pub fn __ashlti3(a: i128, b: i32) callconv(.C) i128 {
96 return @call(.{ .modifier = .always_inline }, ashlXi3, .{ i128, a, b });
97}
98pub fn __ashrdi3(a: i64, b: i32) callconv(.C) i64 {
99 return @call(.{ .modifier = .always_inline }, ashrXi3, .{ i64, a, b });
100}
101pub fn __ashrti3(a: i128, b: i32) callconv(.C) i128 {
102 return @call(.{ .modifier = .always_inline }, ashrXi3, .{ i128, a, b });
103}
104pub fn __lshrdi3(a: i64, b: i32) callconv(.C) i64 {
105 return @call(.{ .modifier = .always_inline }, lshrXi3, .{ i64, a, b });
106}
107pub fn __lshrti3(a: i128, b: i32) callconv(.C) i128 {
108 return @call(.{ .modifier = .always_inline }, lshrXi3, .{ i128, a, b });
109}
110
111pub fn __aeabi_llsl(a: i64, b: i32) callconv(.AAPCS) i64 {
112 return __ashldi3(a, b);
113}
114pub fn __aeabi_lasr(a: i64, b: i32) callconv(.AAPCS) i64 {
115 return __ashrdi3(a, b);
116}
117pub fn __aeabi_llsr(a: i64, b: i32) callconv(.AAPCS) i64 {
118 return __lshrdi3(a, b);
119}
120
121test "" {
122 _ = @import("ashrdi3_test.zig");
123 _ = @import("ashrti3_test.zig");
124
125 _ = @import("ashldi3_test.zig");
126 _ = @import("ashlti3_test.zig");
127
128 _ = @import("lshrdi3_test.zig");
129 _ = @import("lshrti3_test.zig");
130}
lib/std/std.zig+1-1
......@@ -1,10 +1,10 @@
11pub const AlignedArrayList = @import("array_list.zig").AlignedArrayList;
22pub const ArrayList = @import("array_list.zig").ArrayList;
3pub const ArrayListSentineled = @import("array_list_sentineled.zig").ArrayListSentineled;
34pub const AutoHashMap = @import("hash_map.zig").AutoHashMap;
45pub const BloomFilter = @import("bloom_filter.zig").BloomFilter;
56pub const BufMap = @import("buf_map.zig").BufMap;
67pub const BufSet = @import("buf_set.zig").BufSet;
7pub const Buffer = @import("buffer.zig").Buffer;
88pub const ChildProcess = @import("child_process.zig").ChildProcess;
99pub const DynLib = @import("dynamic_library.zig").DynLib;
1010pub const HashMap = @import("hash_map.zig").HashMap;
lib/std/target.zig+4-4
......@@ -967,15 +967,15 @@ pub const Target = struct {
967967
968968 pub const stack_align = 16;
969969
970 pub fn zigTriple(self: Target, allocator: *mem.Allocator) ![:0]u8 {
970 pub fn zigTriple(self: Target, allocator: *mem.Allocator) ![]u8 {
971971 return std.zig.CrossTarget.fromTarget(self).zigTriple(allocator);
972972 }
973973
974 pub fn linuxTripleSimple(allocator: *mem.Allocator, cpu_arch: Cpu.Arch, os_tag: Os.Tag, abi: Abi) ![:0]u8 {
975 return std.fmt.allocPrint0(allocator, "{}-{}-{}", .{ @tagName(cpu_arch), @tagName(os_tag), @tagName(abi) });
974 pub fn linuxTripleSimple(allocator: *mem.Allocator, cpu_arch: Cpu.Arch, os_tag: Os.Tag, abi: Abi) ![]u8 {
975 return std.fmt.allocPrint(allocator, "{}-{}-{}", .{ @tagName(cpu_arch), @tagName(os_tag), @tagName(abi) });
976976 }
977977
978 pub fn linuxTriple(self: Target, allocator: *mem.Allocator) ![:0]u8 {
978 pub fn linuxTriple(self: Target, allocator: *mem.Allocator) ![]u8 {
979979 return linuxTripleSimple(allocator, self.cpu.arch, self.os.tag, self.abi);
980980 }
981981
lib/std/thread.zig+1-1
......@@ -464,7 +464,7 @@ pub const Thread = struct {
464464 var count: c_int = undefined;
465465 var count_len: usize = @sizeOf(c_int);
466466 const name = if (comptime std.Target.current.isDarwin()) "hw.logicalcpu" else "hw.ncpu";
467 os.sysctlbynameC(name, &count, &count_len, null, 0) catch |err| switch (err) {
467 os.sysctlbynameZ(name, &count, &count_len, null, 0) catch |err| switch (err) {
468468 error.NameTooLong, error.UnknownName => unreachable,
469469 else => |e| return e,
470470 };
lib/std/zig/cross_target.zig+18-8
......@@ -495,17 +495,19 @@ pub const CrossTarget = struct {
495495 return self.isNativeCpu() and self.isNativeOs() and self.abi == null;
496496 }
497497
498 pub fn zigTriple(self: CrossTarget, allocator: *mem.Allocator) error{OutOfMemory}![:0]u8 {
498 pub fn zigTriple(self: CrossTarget, allocator: *mem.Allocator) error{OutOfMemory}![]u8 {
499499 if (self.isNative()) {
500 return mem.dupeZ(allocator, u8, "native");
500 return mem.dupe(allocator, u8, "native");
501501 }
502502
503503 const arch_name = if (self.cpu_arch) |arch| @tagName(arch) else "native";
504504 const os_name = if (self.os_tag) |os_tag| @tagName(os_tag) else "native";
505505
506 var result = try std.Buffer.allocPrint(allocator, "{}-{}", .{ arch_name, os_name });
506 var result = std.ArrayList(u8).init(allocator);
507507 defer result.deinit();
508508
509 try result.outStream().print("{}-{}", .{ arch_name, os_name });
510
509511 // The zig target syntax does not allow specifying a max os version with no min, so
510512 // if either are present, we need the min.
511513 if (self.os_version_min != null or self.os_version_max != null) {
......@@ -532,13 +534,13 @@ pub const CrossTarget = struct {
532534 return result.toOwnedSlice();
533535 }
534536
535 pub fn allocDescription(self: CrossTarget, allocator: *mem.Allocator) ![:0]u8 {
537 pub fn allocDescription(self: CrossTarget, allocator: *mem.Allocator) ![]u8 {
536538 // TODO is there anything else worthy of the description that is not
537539 // already captured in the triple?
538540 return self.zigTriple(allocator);
539541 }
540542
541 pub fn linuxTriple(self: CrossTarget, allocator: *mem.Allocator) ![:0]u8 {
543 pub fn linuxTriple(self: CrossTarget, allocator: *mem.Allocator) ![]u8 {
542544 return Target.linuxTripleSimple(allocator, self.getCpuArch(), self.getOsTag(), self.getAbi());
543545 }
544546
......@@ -549,7 +551,7 @@ pub const CrossTarget = struct {
549551 pub const VcpkgLinkage = std.builtin.LinkMode;
550552
551553 /// Returned slice must be freed by the caller.
552 pub fn vcpkgTriplet(self: CrossTarget, allocator: *mem.Allocator, linkage: VcpkgLinkage) ![:0]u8 {
554 pub fn vcpkgTriplet(self: CrossTarget, allocator: *mem.Allocator, linkage: VcpkgLinkage) ![]u8 {
553555 const arch = switch (self.getCpuArch()) {
554556 .i386 => "x86",
555557 .x86_64 => "x64",
......@@ -580,7 +582,7 @@ pub const CrossTarget = struct {
580582 .Dynamic => "",
581583 };
582584
583 return std.fmt.allocPrint0(allocator, "{}-{}{}", .{ arch, os, static_suffix });
585 return std.fmt.allocPrint(allocator, "{}-{}{}", .{ arch, os, static_suffix });
584586 }
585587
586588 pub const Executor = union(enum) {
......@@ -763,7 +765,15 @@ test "CrossTarget.parse" {
763765
764766 const text = try cross_target.zigTriple(std.testing.allocator);
765767 defer std.testing.allocator.free(text);
766 std.testing.expectEqualSlices(u8, "native-native-gnu.2.1.1", text);
768
769 var buf: [256]u8 = undefined;
770 const triple = std.fmt.bufPrint(
771 buf[0..],
772 "native-native-{}.2.1.1",
773 .{@tagName(std.Target.current.abi)},
774 ) catch unreachable;
775
776 std.testing.expectEqualSlices(u8, triple, text);
767777 }
768778 {
769779 const cross_target = try CrossTarget.parse(.{
lib/std/zig/parser_test.zig+30-1
......@@ -373,6 +373,35 @@ test "zig fmt: correctly move doc comments on struct fields" {
373373 );
374374}
375375
376test "zig fmt: correctly space struct fields with doc comments" {
377 try testTransform(
378 \\pub const S = struct {
379 \\ /// A
380 \\ a: u8,
381 \\ /// B
382 \\ /// B (cont)
383 \\ b: u8,
384 \\
385 \\
386 \\ /// C
387 \\ c: u8,
388 \\};
389 \\
390 ,
391 \\pub const S = struct {
392 \\ /// A
393 \\ a: u8,
394 \\ /// B
395 \\ /// B (cont)
396 \\ b: u8,
397 \\
398 \\ /// C
399 \\ c: u8,
400 \\};
401 \\
402 );
403}
404
376405test "zig fmt: doc comments on param decl" {
377406 try testCanonical(
378407 \\pub const Allocator = struct {
......@@ -2924,7 +2953,7 @@ fn testParse(source: []const u8, allocator: *mem.Allocator, anything_changed: *b
29242953 return error.ParseError;
29252954 }
29262955
2927 var buffer = try std.Buffer.initSize(allocator, 0);
2956 var buffer = std.ArrayList(u8).init(allocator);
29282957 errdefer buffer.deinit();
29292958
29302959 anything_changed.* = try std.zig.render(allocator, buffer.outStream(), tree);
lib/std/zig/render.zig+6-2
......@@ -187,12 +187,16 @@ fn renderExtraNewline(tree: *ast.Tree, stream: var, start_col: *usize, node: *as
187187 const first_token = node.firstToken();
188188 var prev_token = first_token;
189189 if (prev_token == 0) return;
190 var newline_threshold: usize = 2;
190191 while (tree.tokens.at(prev_token - 1).id == .DocComment) {
192 if (tree.tokenLocation(tree.tokens.at(prev_token - 1).end, prev_token).line == 1) {
193 newline_threshold += 1;
194 }
191195 prev_token -= 1;
192196 }
193197 const prev_token_end = tree.tokens.at(prev_token - 1).end;
194198 const loc = tree.tokenLocation(prev_token_end, first_token);
195 if (loc.line >= 2) {
199 if (loc.line >= newline_threshold) {
196200 try stream.writeByte('\n');
197201 start_col.* = 0;
198202 }
......@@ -1527,7 +1531,7 @@ fn renderExpression(
15271531 try renderToken(tree, stream, callconv_rparen, indent, start_col, Space.Space); // )
15281532 } else if (cc_rewrite_str) |str| {
15291533 try stream.writeAll("callconv(");
1530 try stream.writeAll(mem.toSliceConst(u8, str));
1534 try stream.writeAll(mem.spanZ(str));
15311535 try stream.writeAll(") ");
15321536 }
15331537
lib/std/zig/system.zig+17-13
......@@ -119,7 +119,7 @@ pub const NativePaths = struct {
119119 }
120120
121121 fn deinitArray(array: *ArrayList([:0]u8)) void {
122 for (array.toSlice()) |item| {
122 for (array.span()) |item| {
123123 array.allocator.free(item);
124124 }
125125 array.deinit();
......@@ -201,7 +201,7 @@ pub const NativeTargetInfo = struct {
201201 switch (Target.current.os.tag) {
202202 .linux => {
203203 const uts = std.os.uname();
204 const release = mem.toSliceConst(u8, &uts.release);
204 const release = mem.spanZ(&uts.release);
205205 // The release field may have several other fields after the
206206 // kernel version
207207 const kernel_version = if (mem.indexOfScalar(u8, release, '-')) |pos|
......@@ -265,7 +265,7 @@ pub const NativeTargetInfo = struct {
265265 // The osproductversion sysctl was introduced first with
266266 // High Sierra, thankfully that's also the baseline that Zig
267267 // supports
268 std.os.sysctlbynameC(
268 std.os.sysctlbynameZ(
269269 "kern.osproductversion",
270270 &product_version,
271271 &size,
......@@ -460,7 +460,7 @@ pub const NativeTargetInfo = struct {
460460 return result;
461461 }
462462
463 const env_file = std.fs.openFileAbsoluteC("/usr/bin/env", .{}) catch |err| switch (err) {
463 const env_file = std.fs.openFileAbsoluteZ("/usr/bin/env", .{}) catch |err| switch (err) {
464464 error.NoSpaceLeft => unreachable,
465465 error.NameTooLong => unreachable,
466466 error.PathAlreadyExists => unreachable,
......@@ -515,7 +515,7 @@ pub const NativeTargetInfo = struct {
515515
516516 fn glibcVerFromSO(so_path: [:0]const u8) !std.builtin.Version {
517517 var link_buf: [std.os.PATH_MAX]u8 = undefined;
518 const link_name = std.os.readlinkC(so_path.ptr, &link_buf) catch |err| switch (err) {
518 const link_name = std.os.readlinkZ(so_path.ptr, &link_buf) catch |err| switch (err) {
519519 error.AccessDenied => return error.GnuLibCVersionUnavailable,
520520 error.FileSystem => return error.FileSystem,
521521 error.SymLinkLoop => return error.SymLinkLoop,
......@@ -625,9 +625,10 @@ pub const NativeTargetInfo = struct {
625625 const p_offset = elfInt(is_64, need_bswap, ph32.p_offset, ph64.p_offset);
626626 const p_filesz = elfInt(is_64, need_bswap, ph32.p_filesz, ph64.p_filesz);
627627 if (p_filesz > result.dynamic_linker.buffer.len) return error.NameTooLong;
628 _ = try preadMin(file, result.dynamic_linker.buffer[0..p_filesz], p_offset, p_filesz);
629 // PT_INTERP includes a null byte in p_filesz.
630 const len = p_filesz - 1;
628 const filesz = @intCast(usize, p_filesz);
629 _ = try preadMin(file, result.dynamic_linker.buffer[0..filesz], p_offset, filesz);
630 // PT_INTERP includes a null byte in filesz.
631 const len = filesz - 1;
631632 // dynamic_linker.max_byte is "max", not "len".
632633 // We know it will fit in u8 because we check against dynamic_linker.buffer.len above.
633634 result.dynamic_linker.max_byte = @intCast(u8, len - 1);
......@@ -648,7 +649,7 @@ pub const NativeTargetInfo = struct {
648649 {
649650 var dyn_off = elfInt(is_64, need_bswap, ph32.p_offset, ph64.p_offset);
650651 const p_filesz = elfInt(is_64, need_bswap, ph32.p_filesz, ph64.p_filesz);
651 const dyn_size: u64 = if (is_64) @sizeOf(elf.Elf64_Dyn) else @sizeOf(elf.Elf32_Dyn);
652 const dyn_size: usize = if (is_64) @sizeOf(elf.Elf64_Dyn) else @sizeOf(elf.Elf32_Dyn);
652653 const dyn_num = p_filesz / dyn_size;
653654 var dyn_buf: [16 * @sizeOf(elf.Elf64_Dyn)]u8 align(@alignOf(elf.Elf64_Dyn)) = undefined;
654655 var dyn_i: usize = 0;
......@@ -739,7 +740,7 @@ pub const NativeTargetInfo = struct {
739740 );
740741 const sh_name_off = elfInt(is_64, need_bswap, sh32.sh_name, sh64.sh_name);
741742 // TODO this pointer cast should not be necessary
742 const sh_name = mem.toSliceConst(u8, @ptrCast([*:0]u8, shstrtab[sh_name_off..].ptr));
743 const sh_name = mem.spanZ(@ptrCast([*:0]u8, shstrtab[sh_name_off..].ptr));
743744 if (mem.eql(u8, sh_name, ".dynstr")) {
744745 break :find_dyn_str .{
745746 .offset = elfInt(is_64, need_bswap, sh32.sh_offset, sh64.sh_offset),
......@@ -754,7 +755,10 @@ pub const NativeTargetInfo = struct {
754755 const strtab_read_len = try preadMin(file, &strtab_buf, ds.offset, shstrtab_len);
755756 const strtab = strtab_buf[0..strtab_read_len];
756757 // TODO this pointer cast should not be necessary
757 const rpath_list = mem.toSliceConst(u8, @ptrCast([*:0]u8, strtab[rpoff..].ptr));
758 const rpoff_usize = std.math.cast(usize, rpoff) catch |err| switch (err) {
759 error.Overflow => return error.InvalidElfFile,
760 };
761 const rpath_list = mem.spanZ(@ptrCast([*:0]u8, strtab[rpoff_usize..].ptr));
758762 var it = mem.tokenize(rpath_list, ":");
759763 while (it.next()) |rpath| {
760764 var dir = fs.cwd().openDir(rpath, .{}) catch |err| switch (err) {
......@@ -779,7 +783,7 @@ pub const NativeTargetInfo = struct {
779783 defer dir.close();
780784
781785 var link_buf: [std.os.PATH_MAX]u8 = undefined;
782 const link_name = std.os.readlinkatC(
786 const link_name = std.os.readlinkatZ(
783787 dir.fd,
784788 glibc_so_basename,
785789 &link_buf,
......@@ -814,7 +818,7 @@ pub const NativeTargetInfo = struct {
814818 }
815819
816820 fn preadMin(file: fs.File, buf: []u8, offset: u64, min_read_len: usize) !usize {
817 var i: u64 = 0;
821 var i: usize = 0;
818822 while (i < min_read_len) {
819823 const len = file.pread(buf[i .. buf.len - i], offset + i) catch |err| switch (err) {
820824 error.OperationAborted => unreachable, // Windows-only
src-self-hosted/clang_options_data.zig+85-50
......@@ -7,7 +7,7 @@ flagpd1("CC"),
77.{
88 .name = "E",
99 .syntax = .flag,
10 .zig_equivalent = .preprocess,
10 .zig_equivalent = .pp_or_asm,
1111 .pd1 = true,
1212 .pd2 = false,
1313 .psl = false,
......@@ -26,12 +26,26 @@ flagpd1("H"),
2626},
2727flagpd1("I-"),
2828flagpd1("M"),
29flagpd1("MD"),
29.{
30 .name = "MD",
31 .syntax = .flag,
32 .zig_equivalent = .dep_file,
33 .pd1 = true,
34 .pd2 = false,
35 .psl = false,
36},
3037flagpd1("MG"),
3138flagpd1("MM"),
3239flagpd1("MMD"),
3340flagpd1("MP"),
34flagpd1("MV"),
41.{
42 .name = "MV",
43 .syntax = .flag,
44 .zig_equivalent = .dep_file,
45 .pd1 = true,
46 .pd2 = false,
47 .psl = false,
48},
3549flagpd1("Mach"),
3650flagpd1("O0"),
3751flagpd1("O4"),
......@@ -53,7 +67,7 @@ flagpd1("Qy"),
5367.{
5468 .name = "S",
5569 .syntax = .flag,
56 .zig_equivalent = .driver_punt,
70 .zig_equivalent = .pp_or_asm,
5771 .pd1 = true,
5872 .pd2 = false,
5973 .psl = false,
......@@ -154,7 +168,7 @@ sepd1("Zlinker-input"),
154168.{
155169 .name = "E",
156170 .syntax = .flag,
157 .zig_equivalent = .preprocess,
171 .zig_equivalent = .pp_or_asm,
158172 .pd1 = true,
159173 .pd2 = false,
160174 .psl = true,
......@@ -490,7 +504,7 @@ sepd1("Zlinker-input"),
490504.{
491505 .name = "MD",
492506 .syntax = .flag,
493 .zig_equivalent = .other,
507 .zig_equivalent = .dep_file,
494508 .pd1 = true,
495509 .pd2 = false,
496510 .psl = true,
......@@ -1442,7 +1456,7 @@ sepd1("Zlinker-input"),
14421456.{
14431457 .name = "assemble",
14441458 .syntax = .flag,
1445 .zig_equivalent = .driver_punt,
1459 .zig_equivalent = .pp_or_asm,
14461460 .pd1 = false,
14471461 .pd2 = true,
14481462 .psl = false,
......@@ -1658,7 +1672,7 @@ sepd1("Zlinker-input"),
16581672.{
16591673 .name = "library-directory",
16601674 .syntax = .separate,
1661 .zig_equivalent = .other,
1675 .zig_equivalent = .lib_dir,
16621676 .pd1 = false,
16631677 .pd2 = true,
16641678 .psl = false,
......@@ -1770,7 +1784,7 @@ sepd1("Zlinker-input"),
17701784.{
17711785 .name = "preprocess",
17721786 .syntax = .flag,
1773 .zig_equivalent = .preprocess,
1787 .zig_equivalent = .pp_or_asm,
17741788 .pd1 = false,
17751789 .pd2 = true,
17761790 .psl = false,
......@@ -2554,14 +2568,7 @@ flagpd1("femulated-tls"),
25542568flagpd1("fencode-extended-block-signature"),
25552569sepd1("ferror-limit"),
25562570flagpd1("fescaping-block-tail-calls"),
2557.{
2558 .name = "fexceptions",
2559 .syntax = .flag,
2560 .zig_equivalent = .exceptions,
2561 .pd1 = true,
2562 .pd2 = false,
2563 .psl = false,
2564},
2571flagpd1("fexceptions"),
25652572flagpd1("fexperimental-isel"),
25662573flagpd1("fexperimental-new-constant-interpreter"),
25672574flagpd1("fexperimental-new-pass-manager"),
......@@ -2765,14 +2772,7 @@ flagpd1("fno-elide-type"),
27652772flagpd1("fno-eliminate-unused-debug-symbols"),
27662773flagpd1("fno-emulated-tls"),
27672774flagpd1("fno-escaping-block-tail-calls"),
2768.{
2769 .name = "fno-exceptions",
2770 .syntax = .flag,
2771 .zig_equivalent = .no_exceptions,
2772 .pd1 = true,
2773 .pd2 = false,
2774 .psl = false,
2775},
2775flagpd1("fno-exceptions"),
27762776flagpd1("fno-experimental-isel"),
27772777flagpd1("fno-experimental-new-pass-manager"),
27782778flagpd1("fno-fast-math"),
......@@ -2861,14 +2861,7 @@ flagpd1("fno-rewrite-includes"),
28612861flagpd1("fno-ropi"),
28622862flagpd1("fno-rounding-math"),
28632863flagpd1("fno-rtlib-add-rpath"),
2864.{
2865 .name = "fno-rtti",
2866 .syntax = .flag,
2867 .zig_equivalent = .no_rtti,
2868 .pd1 = true,
2869 .pd2 = false,
2870 .psl = false,
2871},
2864flagpd1("fno-rtti"),
28722865flagpd1("fno-rtti-data"),
28732866flagpd1("fno-rwpi"),
28742867flagpd1("fno-sanitize-address-poison-custom-array-cookie"),
......@@ -2996,7 +2989,14 @@ sepd1("fprofile-remapping-file"),
29962989flagpd1("fprofile-sample-accurate"),
29972990flagpd1("fprofile-sample-use"),
29982991flagpd1("fprofile-use"),
2999sepd1("framework"),
2992.{
2993 .name = "framework",
2994 .syntax = .separate,
2995 .zig_equivalent = .framework,
2996 .pd1 = true,
2997 .pd2 = false,
2998 .psl = false,
2999},
30003000flagpd1("freciprocal-math"),
30013001flagpd1("frecord-command-line"),
30023002flagpd1("ffree-form"),
......@@ -3016,14 +3016,7 @@ flagpd1("fno-frontend-optimize"),
30163016flagpd1("fropi"),
30173017flagpd1("frounding-math"),
30183018flagpd1("frtlib-add-rpath"),
3019.{
3020 .name = "frtti",
3021 .syntax = .flag,
3022 .zig_equivalent = .rtti,
3023 .pd1 = true,
3024 .pd2 = false,
3025 .psl = false,
3026},
3019flagpd1("frtti"),
30273020flagpd1("frwpi"),
30283021flagpd1("fsanitize-address-globals-dead-stripping"),
30293022flagpd1("fsanitize-address-poison-custom-array-cookie"),
......@@ -4562,7 +4555,7 @@ joinpd1("target-sdk-version="),
45624555.{
45634556 .name = "library-directory=",
45644557 .syntax = .joined,
4565 .zig_equivalent = .other,
4558 .zig_equivalent = .lib_dir,
45664559 .pd1 = false,
45674560 .pd2 = true,
45684561 .psl = false,
......@@ -5282,8 +5275,22 @@ joinpd1("fixit="),
52825275joinpd1("gstabs"),
52835276joinpd1("gxcoff"),
52845277jspd1("iquote"),
5285joinpd1("march="),
5286joinpd1("mtune="),
5278.{
5279 .name = "march=",
5280 .syntax = .joined,
5281 .zig_equivalent = .mcpu,
5282 .pd1 = true,
5283 .pd2 = false,
5284 .psl = false,
5285},
5286.{
5287 .name = "mtune=",
5288 .syntax = .joined,
5289 .zig_equivalent = .mcpu,
5290 .pd1 = true,
5291 .pd2 = false,
5292 .psl = false,
5293},
52875294.{
52885295 .name = "rtlib=",
52895296 .syntax = .joined,
......@@ -5348,7 +5355,14 @@ joinpd1("gcoff"),
53485355joinpd1("mabi="),
53495356joinpd1("mabs="),
53505357joinpd1("masm="),
5351joinpd1("mcpu="),
5358.{
5359 .name = "mcpu=",
5360 .syntax = .joined,
5361 .zig_equivalent = .mcpu,
5362 .pd1 = true,
5363 .pd2 = false,
5364 .psl = false,
5365},
53525366joinpd1("mfpu="),
53535367joinpd1("mhvx="),
53545368joinpd1("mmcu="),
......@@ -5441,7 +5455,14 @@ joinpd1("mtp="),
54415455joinpd1("gz="),
54425456joinpd1("A-"),
54435457joinpd1("G="),
5444jspd1("MF"),
5458.{
5459 .name = "MF",
5460 .syntax = .joined_or_separate,
5461 .zig_equivalent = .dep_file,
5462 .pd1 = true,
5463 .pd2 = false,
5464 .psl = false,
5465},
54455466jspd1("MJ"),
54465467jspd1("MQ"),
54475468jspd1("MT"),
......@@ -5656,11 +5677,25 @@ jspd1("MT"),
56565677jspd1("A"),
56575678jspd1("B"),
56585679jspd1("D"),
5659jspd1("F"),
5680.{
5681 .name = "F",
5682 .syntax = .joined_or_separate,
5683 .zig_equivalent = .framework_dir,
5684 .pd1 = true,
5685 .pd2 = false,
5686 .psl = false,
5687},
56605688jspd1("G"),
56615689jspd1("I"),
56625690jspd1("J"),
5663jspd1("L"),
5691.{
5692 .name = "L",
5693 .syntax = .joined_or_separate,
5694 .zig_equivalent = .lib_dir,
5695 .pd1 = true,
5696 .pd2 = false,
5697 .psl = false,
5698},
56645699.{
56655700 .name = "O",
56665701 .syntax = .joined,
......@@ -5694,7 +5729,7 @@ joinpd1("Z"),
56945729.{
56955730 .name = "F",
56965731 .syntax = .joined_or_separate,
5697 .zig_equivalent = .other,
5732 .zig_equivalent = .framework_dir,
56985733 .pd1 = true,
56995734 .pd2 = false,
57005735 .psl = true,
src-self-hosted/codegen.zig+14-14
......@@ -25,10 +25,10 @@ pub async fn renderToLlvm(comp: *Compilation, fn_val: *Value.Fn, code: *ir.Code)
2525
2626 const context = llvm_handle.node.data;
2727
28 const module = llvm.ModuleCreateWithNameInContext(comp.name.toSliceConst(), context) orelse return error.OutOfMemory;
28 const module = llvm.ModuleCreateWithNameInContext(comp.name.span(), context) orelse return error.OutOfMemory;
2929 defer llvm.DisposeModule(module);
3030
31 llvm.SetTarget(module, comp.llvm_triple.toSliceConst());
31 llvm.SetTarget(module, comp.llvm_triple.span());
3232 llvm.SetDataLayout(module, comp.target_layout_str);
3333
3434 if (comp.target.getObjectFormat() == .coff) {
......@@ -45,7 +45,7 @@ pub async fn renderToLlvm(comp: *Compilation, fn_val: *Value.Fn, code: *ir.Code)
4545
4646 // Don't use ZIG_VERSION_STRING here. LLVM misparses it when it includes
4747 // the git revision.
48 const producer = try std.Buffer.allocPrint(&code.arena.allocator, "zig {}.{}.{}", .{
48 const producer = try std.fmt.allocPrintZ(&code.arena.allocator, "zig {}.{}.{}", .{
4949 @as(u32, c.ZIG_VERSION_MAJOR),
5050 @as(u32, c.ZIG_VERSION_MINOR),
5151 @as(u32, c.ZIG_VERSION_PATCH),
......@@ -54,15 +54,15 @@ pub async fn renderToLlvm(comp: *Compilation, fn_val: *Value.Fn, code: *ir.Code)
5454 const runtime_version = 0;
5555 const compile_unit_file = llvm.CreateFile(
5656 dibuilder,
57 comp.name.toSliceConst(),
58 comp.root_package.root_src_dir.toSliceConst(),
57 comp.name.span(),
58 comp.root_package.root_src_dir.span(),
5959 ) orelse return error.OutOfMemory;
6060 const is_optimized = comp.build_mode != .Debug;
6161 const compile_unit = llvm.CreateCompileUnit(
6262 dibuilder,
6363 DW.LANG_C99,
6464 compile_unit_file,
65 producer.toSliceConst(),
65 producer,
6666 is_optimized,
6767 flags,
6868 runtime_version,
......@@ -109,14 +109,14 @@ pub async fn renderToLlvm(comp: *Compilation, fn_val: *Value.Fn, code: *ir.Code)
109109 if (llvm.TargetMachineEmitToFile(
110110 comp.target_machine,
111111 module,
112 output_path.toSliceConst(),
112 output_path.span(),
113113 llvm.EmitBinary,
114114 &err_msg,
115115 is_debug,
116116 is_small,
117117 )) {
118118 if (std.debug.runtime_safety) {
119 std.debug.panic("unable to write object file {}: {s}\n", .{ output_path.toSliceConst(), err_msg });
119 std.debug.panic("unable to write object file {}: {s}\n", .{ output_path.span(), err_msg });
120120 }
121121 return error.WritingObjectFileFailed;
122122 }
......@@ -127,7 +127,7 @@ pub async fn renderToLlvm(comp: *Compilation, fn_val: *Value.Fn, code: *ir.Code)
127127 llvm.DumpModule(ofile.module);
128128 }
129129 if (comp.verbose_link) {
130 std.debug.warn("created {}\n", .{output_path.toSliceConst()});
130 std.debug.warn("created {}\n", .{output_path.span()});
131131 }
132132}
133133
......@@ -150,7 +150,7 @@ pub fn renderToLlvmModule(ofile: *ObjectFile, fn_val: *Value.Fn, code: *ir.Code)
150150 const llvm_fn_type = try fn_val.base.typ.getLlvmType(ofile.arena, ofile.context);
151151 const llvm_fn = llvm.AddFunction(
152152 ofile.module,
153 fn_val.symbol_name.toSliceConst(),
153 fn_val.symbol_name.span(),
154154 llvm_fn_type,
155155 ) orelse return error.OutOfMemory;
156156
......@@ -211,7 +211,7 @@ pub fn renderToLlvmModule(ofile: *ObjectFile, fn_val: *Value.Fn, code: *ir.Code)
211211 const cur_ret_ptr = if (fn_type_normal.return_type.handleIsPtr()) llvm.GetParam(llvm_fn, 0) else null;
212212
213213 // build all basic blocks
214 for (code.basic_block_list.toSlice()) |bb| {
214 for (code.basic_block_list.span()) |bb| {
215215 bb.llvm_block = llvm.AppendBasicBlockInContext(
216216 ofile.context,
217217 llvm_fn,
......@@ -226,7 +226,7 @@ pub fn renderToLlvmModule(ofile: *ObjectFile, fn_val: *Value.Fn, code: *ir.Code)
226226 // TODO set up error return tracing
227227 // TODO allocate temporary stack values
228228
229 const var_list = fn_type.non_key.Normal.variable_list.toSliceConst();
229 const var_list = fn_type.non_key.Normal.variable_list.span();
230230 // create debug variable declarations for variables and allocate all local variables
231231 for (var_list) |var_scope, i| {
232232 const var_type = switch (var_scope.data) {
......@@ -306,9 +306,9 @@ pub fn renderToLlvmModule(ofile: *ObjectFile, fn_val: *Value.Fn, code: *ir.Code)
306306 //}
307307 }
308308
309 for (code.basic_block_list.toSlice()) |current_block| {
309 for (code.basic_block_list.span()) |current_block| {
310310 llvm.PositionBuilderAtEnd(ofile.builder, current_block.llvm_block);
311 for (current_block.instruction_list.toSlice()) |instruction| {
311 for (current_block.instruction_list.span()) |instruction| {
312312 if (instruction.ref_count == 0 and !instruction.hasSideEffects()) continue;
313313
314314 instruction.llvm_value = try instruction.render(ofile, fn_val);
src-self-hosted/compilation.zig+11-11
......@@ -2,7 +2,7 @@ const std = @import("std");
22const io = std.io;
33const mem = std.mem;
44const Allocator = mem.Allocator;
5const Buffer = std.Buffer;
5const ArrayListSentineled = std.ArrayListSentineled;
66const llvm = @import("llvm.zig");
77const c = @import("c.zig");
88const builtin = std.builtin;
......@@ -123,8 +123,8 @@ pub const LlvmHandle = struct {
123123
124124pub const Compilation = struct {
125125 zig_compiler: *ZigCompiler,
126 name: Buffer,
127 llvm_triple: Buffer,
126 name: ArrayListSentineled(u8, 0),
127 llvm_triple: ArrayListSentineled(u8, 0),
128128 root_src_path: ?[]const u8,
129129 target: std.Target,
130130 llvm_target: *llvm.Target,
......@@ -444,7 +444,7 @@ pub const Compilation = struct {
444444 comp.arena_allocator.deinit();
445445 }
446446
447 comp.name = try Buffer.init(comp.arena(), name);
447 comp.name = try ArrayListSentineled(u8, 0).init(comp.arena(), name);
448448 comp.llvm_triple = try util.getLLVMTriple(comp.arena(), target);
449449 comp.llvm_target = try util.llvmTargetFromTriple(comp.llvm_triple);
450450 comp.zig_std_dir = try fs.path.join(comp.arena(), &[_][]const u8{ zig_lib_dir, "std" });
......@@ -465,7 +465,7 @@ pub const Compilation = struct {
465465
466466 comp.target_machine = llvm.CreateTargetMachine(
467467 comp.llvm_target,
468 comp.llvm_triple.toSliceConst(),
468 comp.llvm_triple.span(),
469469 target_specific_cpu_args orelse "",
470470 target_specific_cpu_features orelse "",
471471 opt_level,
......@@ -1106,7 +1106,7 @@ pub const Compilation = struct {
11061106 }
11071107 }
11081108
1109 for (self.link_libs_list.toSliceConst()) |existing_lib| {
1109 for (self.link_libs_list.span()) |existing_lib| {
11101110 if (mem.eql(u8, name, existing_lib.name)) {
11111111 return existing_lib;
11121112 }
......@@ -1151,7 +1151,7 @@ pub const Compilation = struct {
11511151
11521152 /// If the temporary directory for this compilation has not been created, it creates it.
11531153 /// Then it creates a random file name in that dir and returns it.
1154 pub fn createRandomOutputPath(self: *Compilation, suffix: []const u8) !Buffer {
1154 pub fn createRandomOutputPath(self: *Compilation, suffix: []const u8) !ArrayListSentineled(u8, 0) {
11551155 const tmp_dir = try self.getTmpDir();
11561156 const file_prefix = self.getRandomFileName();
11571157
......@@ -1161,7 +1161,7 @@ pub const Compilation = struct {
11611161 const full_path = try fs.path.join(self.gpa(), &[_][]const u8{ tmp_dir, file_name[0..] });
11621162 errdefer self.gpa().free(full_path);
11631163
1164 return Buffer.fromOwnedSlice(self.gpa(), full_path);
1164 return ArrayListSentineled(u8, 0).fromOwnedSlice(self.gpa(), full_path);
11651165 }
11661166
11671167 /// If the temporary directory for this Compilation has not been created, creates it.
......@@ -1279,7 +1279,7 @@ fn generateDeclFn(comp: *Compilation, fn_decl: *Decl.Fn) !void {
12791279 const fn_type = try analyzeFnType(comp, tree_scope, fn_decl.base.parent_scope, fn_decl.fn_proto);
12801280 defer fn_type.base.base.deref(comp);
12811281
1282 var symbol_name = try std.Buffer.init(comp.gpa(), fn_decl.base.name);
1282 var symbol_name = try std.ArrayListSentineled(u8, 0).init(comp.gpa(), fn_decl.base.name);
12831283 var symbol_name_consumed = false;
12841284 errdefer if (!symbol_name_consumed) symbol_name.deinit();
12851285
......@@ -1371,7 +1371,7 @@ fn analyzeFnType(
13711371 var params = ArrayList(Type.Fn.Param).init(comp.gpa());
13721372 var params_consumed = false;
13731373 defer if (!params_consumed) {
1374 for (params.toSliceConst()) |param| {
1374 for (params.span()) |param| {
13751375 param.typ.base.deref(comp);
13761376 }
13771377 params.deinit();
......@@ -1426,7 +1426,7 @@ fn generateDeclFnProto(comp: *Compilation, fn_decl: *Decl.Fn) !void {
14261426 );
14271427 defer fn_type.base.base.deref(comp);
14281428
1429 var symbol_name = try std.Buffer.init(comp.gpa(), fn_decl.base.name);
1429 var symbol_name = try std.ArrayListSentineled(u8, 0).init(comp.gpa(), fn_decl.base.name);
14301430 var symbol_name_consumed = false;
14311431 defer if (!symbol_name_consumed) symbol_name.deinit();
14321432
src-self-hosted/dep_tokenizer.zig+59-59
......@@ -33,7 +33,7 @@ pub const Tokenizer = struct {
3333 break; // advance
3434 },
3535 else => {
36 self.state = State{ .target = try std.Buffer.initSize(&self.arena.allocator, 0) };
36 self.state = State{ .target = try std.ArrayListSentineled(u8, 0).initSize(&self.arena.allocator, 0) };
3737 },
3838 },
3939 .target => |*target| switch (char) {
......@@ -53,7 +53,7 @@ pub const Tokenizer = struct {
5353 break; // advance
5454 },
5555 else => {
56 try target.appendByte(char);
56 try target.append(char);
5757 break; // advance
5858 },
5959 },
......@@ -62,24 +62,24 @@ pub const Tokenizer = struct {
6262 return self.errorIllegalChar(self.index, char, "bad target escape", .{});
6363 },
6464 ' ', '#', '\\' => {
65 try target.appendByte(char);
65 try target.append(char);
6666 self.state = State{ .target = target.* };
6767 break; // advance
6868 },
6969 '$' => {
70 try target.append(self.bytes[self.index - 1 .. self.index]);
70 try target.appendSlice(self.bytes[self.index - 1 .. self.index]);
7171 self.state = State{ .target_dollar_sign = target.* };
7272 break; // advance
7373 },
7474 else => {
75 try target.append(self.bytes[self.index - 1 .. self.index + 1]);
75 try target.appendSlice(self.bytes[self.index - 1 .. self.index + 1]);
7676 self.state = State{ .target = target.* };
7777 break; // advance
7878 },
7979 },
8080 .target_dollar_sign => |*target| switch (char) {
8181 '$' => {
82 try target.appendByte(char);
82 try target.append(char);
8383 self.state = State{ .target = target.* };
8484 break; // advance
8585 },
......@@ -89,7 +89,7 @@ pub const Tokenizer = struct {
8989 },
9090 .target_colon => |*target| switch (char) {
9191 '\n', '\r' => {
92 const bytes = target.toSlice();
92 const bytes = target.span();
9393 if (bytes.len != 0) {
9494 self.state = State{ .lhs = {} };
9595 return Token{ .id = .target, .bytes = bytes };
......@@ -103,7 +103,7 @@ pub const Tokenizer = struct {
103103 break; // advance
104104 },
105105 else => {
106 const bytes = target.toSlice();
106 const bytes = target.span();
107107 if (bytes.len != 0) {
108108 self.state = State{ .rhs = {} };
109109 return Token{ .id = .target, .bytes = bytes };
......@@ -115,7 +115,7 @@ pub const Tokenizer = struct {
115115 },
116116 .target_colon_reverse_solidus => |*target| switch (char) {
117117 '\n', '\r' => {
118 const bytes = target.toSlice();
118 const bytes = target.span();
119119 if (bytes.len != 0) {
120120 self.state = State{ .lhs = {} };
121121 return Token{ .id = .target, .bytes = bytes };
......@@ -125,7 +125,7 @@ pub const Tokenizer = struct {
125125 continue;
126126 },
127127 else => {
128 try target.append(self.bytes[self.index - 2 .. self.index + 1]);
128 try target.appendSlice(self.bytes[self.index - 2 .. self.index + 1]);
129129 self.state = State{ .target = target.* };
130130 break;
131131 },
......@@ -144,11 +144,11 @@ pub const Tokenizer = struct {
144144 break; // advance
145145 },
146146 '"' => {
147 self.state = State{ .prereq_quote = try std.Buffer.initSize(&self.arena.allocator, 0) };
147 self.state = State{ .prereq_quote = try std.ArrayListSentineled(u8, 0).initSize(&self.arena.allocator, 0) };
148148 break; // advance
149149 },
150150 else => {
151 self.state = State{ .prereq = try std.Buffer.initSize(&self.arena.allocator, 0) };
151 self.state = State{ .prereq = try std.ArrayListSentineled(u8, 0).initSize(&self.arena.allocator, 0) };
152152 },
153153 },
154154 .rhs_continuation => switch (char) {
......@@ -175,24 +175,24 @@ pub const Tokenizer = struct {
175175 },
176176 .prereq_quote => |*prereq| switch (char) {
177177 '"' => {
178 const bytes = prereq.toSlice();
178 const bytes = prereq.span();
179179 self.index += 1;
180180 self.state = State{ .rhs = {} };
181181 return Token{ .id = .prereq, .bytes = bytes };
182182 },
183183 else => {
184 try prereq.appendByte(char);
184 try prereq.append(char);
185185 break; // advance
186186 },
187187 },
188188 .prereq => |*prereq| switch (char) {
189189 '\t', ' ' => {
190 const bytes = prereq.toSlice();
190 const bytes = prereq.span();
191191 self.state = State{ .rhs = {} };
192192 return Token{ .id = .prereq, .bytes = bytes };
193193 },
194194 '\n', '\r' => {
195 const bytes = prereq.toSlice();
195 const bytes = prereq.span();
196196 self.state = State{ .lhs = {} };
197197 return Token{ .id = .prereq, .bytes = bytes };
198198 },
......@@ -201,13 +201,13 @@ pub const Tokenizer = struct {
201201 break; // advance
202202 },
203203 else => {
204 try prereq.appendByte(char);
204 try prereq.append(char);
205205 break; // advance
206206 },
207207 },
208208 .prereq_continuation => |*prereq| switch (char) {
209209 '\n' => {
210 const bytes = prereq.toSlice();
210 const bytes = prereq.span();
211211 self.index += 1;
212212 self.state = State{ .rhs = {} };
213213 return Token{ .id = .prereq, .bytes = bytes };
......@@ -218,14 +218,14 @@ pub const Tokenizer = struct {
218218 },
219219 else => {
220220 // not continuation
221 try prereq.append(self.bytes[self.index - 1 .. self.index + 1]);
221 try prereq.appendSlice(self.bytes[self.index - 1 .. self.index + 1]);
222222 self.state = State{ .prereq = prereq.* };
223223 break; // advance
224224 },
225225 },
226226 .prereq_continuation_linefeed => |prereq| switch (char) {
227227 '\n' => {
228 const bytes = prereq.toSlice();
228 const bytes = prereq.span();
229229 self.index += 1;
230230 self.state = State{ .rhs = {} };
231231 return Token{ .id = .prereq, .bytes = bytes };
......@@ -249,7 +249,7 @@ pub const Tokenizer = struct {
249249 .rhs_continuation_linefeed,
250250 => {},
251251 .target => |target| {
252 return self.errorPosition(idx, target.toSlice(), "incomplete target", .{});
252 return self.errorPosition(idx, target.span(), "incomplete target", .{});
253253 },
254254 .target_reverse_solidus,
255255 .target_dollar_sign,
......@@ -258,7 +258,7 @@ pub const Tokenizer = struct {
258258 return self.errorIllegalChar(idx, self.bytes[idx], "incomplete escape", .{});
259259 },
260260 .target_colon => |target| {
261 const bytes = target.toSlice();
261 const bytes = target.span();
262262 if (bytes.len != 0) {
263263 self.index += 1;
264264 self.state = State{ .rhs = {} };
......@@ -268,7 +268,7 @@ pub const Tokenizer = struct {
268268 self.state = State{ .lhs = {} };
269269 },
270270 .target_colon_reverse_solidus => |target| {
271 const bytes = target.toSlice();
271 const bytes = target.span();
272272 if (bytes.len != 0) {
273273 self.index += 1;
274274 self.state = State{ .rhs = {} };
......@@ -278,20 +278,20 @@ pub const Tokenizer = struct {
278278 self.state = State{ .lhs = {} };
279279 },
280280 .prereq_quote => |prereq| {
281 return self.errorPosition(idx, prereq.toSlice(), "incomplete quoted prerequisite", .{});
281 return self.errorPosition(idx, prereq.span(), "incomplete quoted prerequisite", .{});
282282 },
283283 .prereq => |prereq| {
284 const bytes = prereq.toSlice();
284 const bytes = prereq.span();
285285 self.state = State{ .lhs = {} };
286286 return Token{ .id = .prereq, .bytes = bytes };
287287 },
288288 .prereq_continuation => |prereq| {
289 const bytes = prereq.toSlice();
289 const bytes = prereq.span();
290290 self.state = State{ .lhs = {} };
291291 return Token{ .id = .prereq, .bytes = bytes };
292292 },
293293 .prereq_continuation_linefeed => |prereq| {
294 const bytes = prereq.toSlice();
294 const bytes = prereq.span();
295295 self.state = State{ .lhs = {} };
296296 return Token{ .id = .prereq, .bytes = bytes };
297297 },
......@@ -300,29 +300,29 @@ pub const Tokenizer = struct {
300300 }
301301
302302 fn errorf(self: *Tokenizer, comptime fmt: []const u8, args: var) Error {
303 self.error_text = (try std.Buffer.allocPrint(&self.arena.allocator, fmt, args)).toSlice();
303 self.error_text = try std.fmt.allocPrintZ(&self.arena.allocator, fmt, args);
304304 return Error.InvalidInput;
305305 }
306306
307307 fn errorPosition(self: *Tokenizer, position: usize, bytes: []const u8, comptime fmt: []const u8, args: var) Error {
308 var buffer = try std.Buffer.initSize(&self.arena.allocator, 0);
308 var buffer = try std.ArrayListSentineled(u8, 0).initSize(&self.arena.allocator, 0);
309309 try buffer.outStream().print(fmt, args);
310 try buffer.append(" '");
311 var out = makeOutput(std.Buffer.append, &buffer);
310 try buffer.appendSlice(" '");
311 var out = makeOutput(std.ArrayListSentineled(u8, 0).appendSlice, &buffer);
312312 try printCharValues(&out, bytes);
313 try buffer.append("'");
313 try buffer.appendSlice("'");
314314 try buffer.outStream().print(" at position {}", .{position - (bytes.len - 1)});
315 self.error_text = buffer.toSlice();
315 self.error_text = buffer.span();
316316 return Error.InvalidInput;
317317 }
318318
319319 fn errorIllegalChar(self: *Tokenizer, position: usize, char: u8, comptime fmt: []const u8, args: var) Error {
320 var buffer = try std.Buffer.initSize(&self.arena.allocator, 0);
321 try buffer.append("illegal char ");
320 var buffer = try std.ArrayListSentineled(u8, 0).initSize(&self.arena.allocator, 0);
321 try buffer.appendSlice("illegal char ");
322322 try printUnderstandableChar(&buffer, char);
323323 try buffer.outStream().print(" at position {}", .{position});
324324 if (fmt.len != 0) try buffer.outStream().print(": " ++ fmt, args);
325 self.error_text = buffer.toSlice();
325 self.error_text = buffer.span();
326326 return Error.InvalidInput;
327327 }
328328
......@@ -333,18 +333,18 @@ pub const Tokenizer = struct {
333333
334334 const State = union(enum) {
335335 lhs: void,
336 target: std.Buffer,
337 target_reverse_solidus: std.Buffer,
338 target_dollar_sign: std.Buffer,
339 target_colon: std.Buffer,
340 target_colon_reverse_solidus: std.Buffer,
336 target: std.ArrayListSentineled(u8, 0),
337 target_reverse_solidus: std.ArrayListSentineled(u8, 0),
338 target_dollar_sign: std.ArrayListSentineled(u8, 0),
339 target_colon: std.ArrayListSentineled(u8, 0),
340 target_colon_reverse_solidus: std.ArrayListSentineled(u8, 0),
341341 rhs: void,
342342 rhs_continuation: void,
343343 rhs_continuation_linefeed: void,
344 prereq_quote: std.Buffer,
345 prereq: std.Buffer,
346 prereq_continuation: std.Buffer,
347 prereq_continuation_linefeed: std.Buffer,
344 prereq_quote: std.ArrayListSentineled(u8, 0),
345 prereq: std.ArrayListSentineled(u8, 0),
346 prereq_continuation: std.ArrayListSentineled(u8, 0),
347 prereq_continuation_linefeed: std.ArrayListSentineled(u8, 0),
348348 };
349349
350350 const Token = struct {
......@@ -841,31 +841,31 @@ fn depTokenizer(input: []const u8, expect: []const u8) !void {
841841 defer arena_allocator.deinit();
842842
843843 var it = Tokenizer.init(arena, input);
844 var buffer = try std.Buffer.initSize(arena, 0);
844 var buffer = try std.ArrayListSentineled(u8, 0).initSize(arena, 0);
845845 var i: usize = 0;
846846 while (true) {
847847 const r = it.next() catch |err| {
848848 switch (err) {
849849 Tokenizer.Error.InvalidInput => {
850 if (i != 0) try buffer.append("\n");
851 try buffer.append("ERROR: ");
852 try buffer.append(it.error_text);
850 if (i != 0) try buffer.appendSlice("\n");
851 try buffer.appendSlice("ERROR: ");
852 try buffer.appendSlice(it.error_text);
853853 },
854854 else => return err,
855855 }
856856 break;
857857 };
858858 const token = r orelse break;
859 if (i != 0) try buffer.append("\n");
860 try buffer.append(@tagName(token.id));
861 try buffer.append(" = {");
859 if (i != 0) try buffer.appendSlice("\n");
860 try buffer.appendSlice(@tagName(token.id));
861 try buffer.appendSlice(" = {");
862862 for (token.bytes) |b| {
863 try buffer.appendByte(printable_char_tab[b]);
863 try buffer.append(printable_char_tab[b]);
864864 }
865 try buffer.append("}");
865 try buffer.appendSlice("}");
866866 i += 1;
867867 }
868 const got: []const u8 = buffer.toSlice();
868 const got: []const u8 = buffer.span();
869869
870870 if (std.mem.eql(u8, expect, got)) {
871871 testing.expect(true);
......@@ -995,13 +995,13 @@ fn printCharValues(out: var, bytes: []const u8) !void {
995995 }
996996}
997997
998fn printUnderstandableChar(buffer: *std.Buffer, char: u8) !void {
998fn printUnderstandableChar(buffer: *std.ArrayListSentineled(u8, 0), char: u8) !void {
999999 if (!std.ascii.isPrint(char) or char == ' ') {
10001000 try buffer.outStream().print("\\x{X:2}", .{char});
10011001 } else {
1002 try buffer.append("'");
1003 try buffer.appendByte(printable_char_tab[char]);
1004 try buffer.append("'");
1002 try buffer.appendSlice("'");
1003 try buffer.append(printable_char_tab[char]);
1004 try buffer.appendSlice("'");
10051005 }
10061006}
10071007
src-self-hosted/errmsg.zig+2-2
......@@ -158,7 +158,7 @@ pub const Msg = struct {
158158 parse_error: *const ast.Error,
159159 ) !*Msg {
160160 const loc_token = parse_error.loc();
161 var text_buf = try std.Buffer.initSize(comp.gpa(), 0);
161 var text_buf = std.ArrayList(u8).init(comp.gpa());
162162 defer text_buf.deinit();
163163
164164 const realpath_copy = try mem.dupe(comp.gpa(), u8, tree_scope.root().realpath);
......@@ -197,7 +197,7 @@ pub const Msg = struct {
197197 realpath: []const u8,
198198 ) !*Msg {
199199 const loc_token = parse_error.loc();
200 var text_buf = try std.Buffer.initSize(allocator, 0);
200 var text_buf = std.ArrayList(u8).init(allocator);
201201 defer text_buf.deinit();
202202
203203 const realpath_copy = try mem.dupe(allocator, u8, realpath);
src-self-hosted/ir.zig+4-4
......@@ -965,9 +965,9 @@ pub const Code = struct {
965965
966966 pub fn dump(self: *Code) void {
967967 var bb_i: usize = 0;
968 for (self.basic_block_list.toSliceConst()) |bb| {
968 for (self.basic_block_list.span()) |bb| {
969969 std.debug.warn("{s}_{}:\n", .{ bb.name_hint, bb.debug_id });
970 for (bb.instruction_list.toSliceConst()) |instr| {
970 for (bb.instruction_list.span()) |instr| {
971971 std.debug.warn(" ", .{});
972972 instr.dump();
973973 std.debug.warn("\n", .{});
......@@ -978,7 +978,7 @@ pub const Code = struct {
978978 /// returns a ref-incremented value, or adds a compile error
979979 pub fn getCompTimeResult(self: *Code, comp: *Compilation) !*Value {
980980 const bb = self.basic_block_list.at(0);
981 for (bb.instruction_list.toSliceConst()) |inst| {
981 for (bb.instruction_list.span()) |inst| {
982982 if (inst.cast(Inst.Return)) |ret_inst| {
983983 const ret_value = ret_inst.params.return_value;
984984 if (ret_value.isCompTime()) {
......@@ -2585,6 +2585,6 @@ pub fn analyze(comp: *Compilation, old_code: *Code, expected_type: ?*Type) !*Cod
25852585 return ira.irb.finish();
25862586 }
25872587
2588 ira.irb.code.return_type = try ira.resolvePeerTypes(expected_type, ira.src_implicit_return_type_list.toSliceConst());
2588 ira.irb.code.return_type = try ira.resolvePeerTypes(expected_type, ira.src_implicit_return_type_list.span());
25892589 return ira.irb.finish();
25902590}
src-self-hosted/libc_installation.zig+20-24
......@@ -14,11 +14,11 @@ usingnamespace @import("windows_sdk.zig");
1414
1515/// See the render function implementation for documentation of the fields.
1616pub const LibCInstallation = struct {
17 include_dir: ?[:0]const u8 = null,
18 sys_include_dir: ?[:0]const u8 = null,
19 crt_dir: ?[:0]const u8 = null,
20 msvc_lib_dir: ?[:0]const u8 = null,
21 kernel32_lib_dir: ?[:0]const u8 = null,
17 include_dir: ?[]const u8 = null,
18 sys_include_dir: ?[]const u8 = null,
19 crt_dir: ?[]const u8 = null,
20 msvc_lib_dir: ?[]const u8 = null,
21 kernel32_lib_dir: ?[]const u8 = null,
2222
2323 pub const FindError = error{
2424 OutOfMemory,
......@@ -54,7 +54,7 @@ pub const LibCInstallation = struct {
5454 }
5555 }
5656
57 const contents = try std.io.readFileAlloc(allocator, libc_file);
57 const contents = try std.fs.cwd().readFileAlloc(allocator, libc_file, std.math.maxInt(usize));
5858 defer allocator.free(contents);
5959
6060 var it = std.mem.tokenize(contents, "\n");
......@@ -229,7 +229,7 @@ pub const LibCInstallation = struct {
229229 "-xc",
230230 dev_null,
231231 };
232 const exec_res = std.ChildProcess.exec2(.{
232 const exec_res = std.ChildProcess.exec(.{
233233 .allocator = allocator,
234234 .argv = &argv,
235235 .max_output_bytes = 1024 * 1024,
......@@ -327,15 +327,14 @@ pub const LibCInstallation = struct {
327327 var search_buf: [2]Search = undefined;
328328 const searches = fillSearch(&search_buf, sdk);
329329
330 var result_buf = try std.Buffer.initSize(allocator, 0);
330 var result_buf = std.ArrayList(u8).init(allocator);
331331 defer result_buf.deinit();
332332
333333 for (searches) |search| {
334334 result_buf.shrink(0);
335 const stream = result_buf.outStream();
336 try stream.print("{}\\Include\\{}\\ucrt", .{ search.path, search.version });
335 try result_buf.outStream().print("{}\\Include\\{}\\ucrt", .{ search.path, search.version });
337336
338 var dir = fs.cwd().openDir(result_buf.toSliceConst(), .{}) catch |err| switch (err) {
337 var dir = fs.cwd().openDir(result_buf.span(), .{}) catch |err| switch (err) {
339338 error.FileNotFound,
340339 error.NotDir,
341340 error.NoDevice,
......@@ -367,7 +366,7 @@ pub const LibCInstallation = struct {
367366 var search_buf: [2]Search = undefined;
368367 const searches = fillSearch(&search_buf, sdk);
369368
370 var result_buf = try std.Buffer.initSize(allocator, 0);
369 var result_buf = std.ArrayList(u8).init(allocator);
371370 defer result_buf.deinit();
372371
373372 const arch_sub_dir = switch (builtin.arch) {
......@@ -379,10 +378,9 @@ pub const LibCInstallation = struct {
379378
380379 for (searches) |search| {
381380 result_buf.shrink(0);
382 const stream = result_buf.outStream();
383 try stream.print("{}\\Lib\\{}\\ucrt\\{}", .{ search.path, search.version, arch_sub_dir });
381 try result_buf.outStream().print("{}\\Lib\\{}\\ucrt\\{}", .{ search.path, search.version, arch_sub_dir });
384382
385 var dir = fs.cwd().openDir(result_buf.toSliceConst(), .{}) catch |err| switch (err) {
383 var dir = fs.cwd().openDir(result_buf.span(), .{}) catch |err| switch (err) {
386384 error.FileNotFound,
387385 error.NotDir,
388386 error.NoDevice,
......@@ -422,7 +420,7 @@ pub const LibCInstallation = struct {
422420 var search_buf: [2]Search = undefined;
423421 const searches = fillSearch(&search_buf, sdk);
424422
425 var result_buf = try std.Buffer.initSize(allocator, 0);
423 var result_buf = std.ArrayList(u8).init(allocator);
426424 defer result_buf.deinit();
427425
428426 const arch_sub_dir = switch (builtin.arch) {
......@@ -437,7 +435,7 @@ pub const LibCInstallation = struct {
437435 const stream = result_buf.outStream();
438436 try stream.print("{}\\Lib\\{}\\um\\{}", .{ search.path, search.version, arch_sub_dir });
439437
440 var dir = fs.cwd().openDir(result_buf.toSliceConst(), .{}) catch |err| switch (err) {
438 var dir = fs.cwd().openDir(result_buf.span(), .{}) catch |err| switch (err) {
441439 error.FileNotFound,
442440 error.NotDir,
443441 error.NoDevice,
......@@ -470,12 +468,10 @@ pub const LibCInstallation = struct {
470468 const up1 = fs.path.dirname(msvc_lib_dir) orelse return error.LibCStdLibHeaderNotFound;
471469 const up2 = fs.path.dirname(up1) orelse return error.LibCStdLibHeaderNotFound;
472470
473 var result_buf = try std.Buffer.init(allocator, up2);
474 defer result_buf.deinit();
475
476 try result_buf.append("\\include");
471 const dir_path = try fs.path.join(allocator, &[_][]const u8{ up2, "include" });
472 errdefer allocator.free(dir_path);
477473
478 var dir = fs.cwd().openDir(result_buf.toSliceConst(), .{}) catch |err| switch (err) {
474 var dir = fs.cwd().openDir(dir_path, .{}) catch |err| switch (err) {
479475 error.FileNotFound,
480476 error.NotDir,
481477 error.NoDevice,
......@@ -490,7 +486,7 @@ pub const LibCInstallation = struct {
490486 else => return error.FileSystem,
491487 };
492488
493 self.sys_include_dir = result_buf.toOwnedSlice();
489 self.sys_include_dir = dir_path;
494490 }
495491
496492 fn findNativeMsvcLibDir(
......@@ -522,7 +518,7 @@ fn ccPrintFileName(args: CCPrintFileNameOptions) ![:0]u8 {
522518 defer allocator.free(arg1);
523519 const argv = [_][]const u8{ cc_exe, arg1 };
524520
525 const exec_res = std.ChildProcess.exec2(.{
521 const exec_res = std.ChildProcess.exec(.{
526522 .allocator = allocator,
527523 .argv = &argv,
528524 .max_output_bytes = 1024 * 1024,
src-self-hosted/link.zig+12-12
......@@ -15,10 +15,10 @@ const Context = struct {
1515 link_in_crt: bool,
1616
1717 link_err: error{OutOfMemory}!void,
18 link_msg: std.Buffer,
18 link_msg: std.ArrayListSentineled(u8, 0),
1919
2020 libc: *LibCInstallation,
21 out_file_path: std.Buffer,
21 out_file_path: std.ArrayListSentineled(u8, 0),
2222};
2323
2424pub fn link(comp: *Compilation) !void {
......@@ -34,9 +34,9 @@ pub fn link(comp: *Compilation) !void {
3434 };
3535 defer ctx.arena.deinit();
3636 ctx.args = std.ArrayList([*:0]const u8).init(&ctx.arena.allocator);
37 ctx.link_msg = std.Buffer.initNull(&ctx.arena.allocator);
37 ctx.link_msg = std.ArrayListSentineled(u8, 0).initNull(&ctx.arena.allocator);
3838
39 ctx.out_file_path = try std.Buffer.init(&ctx.arena.allocator, comp.name.toSliceConst());
39 ctx.out_file_path = try std.ArrayListSentineled(u8, 0).init(&ctx.arena.allocator, comp.name.span());
4040 switch (comp.kind) {
4141 .Exe => {
4242 try ctx.out_file_path.append(comp.target.exeFileExt());
......@@ -70,7 +70,7 @@ pub fn link(comp: *Compilation) !void {
7070 try constructLinkerArgs(&ctx);
7171
7272 if (comp.verbose_link) {
73 for (ctx.args.toSliceConst()) |arg, i| {
73 for (ctx.args.span()) |arg, i| {
7474 const space = if (i == 0) "" else " ";
7575 std.debug.warn("{}{s}", .{ space, arg });
7676 }
......@@ -78,7 +78,7 @@ pub fn link(comp: *Compilation) !void {
7878 }
7979
8080 const extern_ofmt = toExternObjectFormatType(comp.target.getObjectFormat());
81 const args_slice = ctx.args.toSlice();
81 const args_slice = ctx.args.span();
8282
8383 {
8484 // LLD is not thread-safe, so we grab a global lock.
......@@ -91,7 +91,7 @@ pub fn link(comp: *Compilation) !void {
9191 // TODO capture these messages and pass them through the system, reporting them through the
9292 // event system instead of printing them directly here.
9393 // perhaps try to parse and understand them.
94 std.debug.warn("{}\n", .{ctx.link_msg.toSliceConst()});
94 std.debug.warn("{}\n", .{ctx.link_msg.span()});
9595 }
9696 return error.LinkFailed;
9797 }
......@@ -173,7 +173,7 @@ fn constructLinkerArgsElf(ctx: *Context) !void {
173173 //}
174174
175175 try ctx.args.append("-o");
176 try ctx.args.append(ctx.out_file_path.toSliceConst());
176 try ctx.args.append(ctx.out_file_path.span());
177177
178178 if (ctx.link_in_crt) {
179179 const crt1o = if (ctx.comp.is_static) "crt1.o" else "Scrt1.o";
......@@ -291,7 +291,7 @@ fn constructLinkerArgsCoff(ctx: *Context) !void {
291291
292292 const is_library = ctx.comp.kind == .Lib;
293293
294 const out_arg = try std.fmt.allocPrint(&ctx.arena.allocator, "-OUT:{}\x00", .{ctx.out_file_path.toSliceConst()});
294 const out_arg = try std.fmt.allocPrint(&ctx.arena.allocator, "-OUT:{}\x00", .{ctx.out_file_path.span()});
295295 try ctx.args.append(@ptrCast([*:0]const u8, out_arg.ptr));
296296
297297 if (ctx.comp.haveLibC()) {
......@@ -394,7 +394,7 @@ fn constructLinkerArgsMachO(ctx: *Context) !void {
394394 }
395395
396396 try ctx.args.append("-o");
397 try ctx.args.append(ctx.out_file_path.toSliceConst());
397 try ctx.args.append(ctx.out_file_path.span());
398398
399399 if (shared) {
400400 try ctx.args.append("-headerpad_max_install_names");
......@@ -432,7 +432,7 @@ fn constructLinkerArgsMachO(ctx: *Context) !void {
432432
433433 // TODO
434434 //if (ctx.comp.target == Target.Native) {
435 // for (ctx.comp.link_libs_list.toSliceConst()) |lib| {
435 // for (ctx.comp.link_libs_list.span()) |lib| {
436436 // if (mem.eql(u8, lib.name, "c")) {
437437 // // on Darwin, libSystem has libc in it, but also you have to use it
438438 // // to make syscalls because the syscall numbers are not documented
......@@ -482,7 +482,7 @@ fn addFnObjects(ctx: *Context) !void {
482482 ctx.comp.gpa().destroy(node);
483483 continue;
484484 };
485 try ctx.args.append(fn_val.containing_object.toSliceConst());
485 try ctx.args.append(fn_val.containing_object.span());
486486 it = node.next;
487487 }
488488}
src-self-hosted/main.zig+7-7
......@@ -421,7 +421,7 @@ fn buildOutputType(allocator: *Allocator, args: []const []const u8, out_type: Co
421421 process.exit(1);
422422 }
423423
424 try ZigCompiler.setLlvmArgv(allocator, mllvm_flags.toSliceConst());
424 try ZigCompiler.setLlvmArgv(allocator, mllvm_flags.span());
425425
426426 const zig_lib_dir = introspect.resolveZigLibDir(allocator) catch process.exit(1);
427427 defer allocator.free(zig_lib_dir);
......@@ -448,14 +448,14 @@ fn buildOutputType(allocator: *Allocator, args: []const []const u8, out_type: Co
448448 comp.override_libc = &override_libc;
449449 }
450450
451 for (system_libs.toSliceConst()) |lib| {
451 for (system_libs.span()) |lib| {
452452 _ = try comp.addLinkLib(lib, true);
453453 }
454454
455455 comp.version = version;
456456 comp.is_test = false;
457457 comp.linker_script = linker_script;
458 comp.clang_argv = clang_argv_buf.toSliceConst();
458 comp.clang_argv = clang_argv_buf.span();
459459 comp.strip = strip;
460460
461461 comp.verbose_tokenize = verbose_tokenize;
......@@ -488,8 +488,8 @@ fn buildOutputType(allocator: *Allocator, args: []const []const u8, out_type: Co
488488 comp.emit_asm = emit_asm;
489489 comp.emit_llvm_ir = emit_llvm_ir;
490490 comp.emit_h = emit_h;
491 comp.assembly_files = assembly_files.toSliceConst();
492 comp.link_objects = link_objects.toSliceConst();
491 comp.assembly_files = assembly_files.span();
492 comp.link_objects = link_objects.span();
493493
494494 comp.start();
495495 processBuildEvents(comp, color);
......@@ -683,7 +683,7 @@ fn cmdFmt(allocator: *Allocator, args: []const []const u8) !void {
683683 };
684684
685685 var group = event.Group(FmtError!void).init(allocator);
686 for (input_files.toSliceConst()) |file_path| {
686 for (input_files.span()) |file_path| {
687687 try group.call(fmtPath, .{ &fmt, file_path, check_flag });
688688 }
689689 try group.wait();
......@@ -898,7 +898,7 @@ const CliPkg = struct {
898898 }
899899
900900 pub fn deinit(self: *CliPkg) void {
901 for (self.children.toSliceConst()) |child| {
901 for (self.children.span()) |child| {
902902 child.deinit();
903903 }
904904 self.children.deinit();
src-self-hosted/package.zig+5-5
......@@ -1,11 +1,11 @@
11const std = @import("std");
22const mem = std.mem;
33const assert = std.debug.assert;
4const Buffer = std.Buffer;
4const ArrayListSentineled = std.ArrayListSentineled;
55
66pub const Package = struct {
7 root_src_dir: Buffer,
8 root_src_path: Buffer,
7 root_src_dir: ArrayListSentineled(u8, 0),
8 root_src_path: ArrayListSentineled(u8, 0),
99
1010 /// relative to root_src_dir
1111 table: Table,
......@@ -17,8 +17,8 @@ pub const Package = struct {
1717 pub fn create(allocator: *mem.Allocator, root_src_dir: []const u8, root_src_path: []const u8) !*Package {
1818 const ptr = try allocator.create(Package);
1919 ptr.* = Package{
20 .root_src_dir = try Buffer.init(allocator, root_src_dir),
21 .root_src_path = try Buffer.init(allocator, root_src_path),
20 .root_src_dir = try ArrayListSentineled(u8, 0).init(allocator, root_src_dir),
21 .root_src_path = try ArrayListSentineled(u8, 0).init(allocator, root_src_path),
2222 .table = Table.init(allocator),
2323 };
2424 return ptr;
src-self-hosted/stage2.zig+57-55
......@@ -8,7 +8,7 @@ const fs = std.fs;
88const process = std.process;
99const Allocator = mem.Allocator;
1010const ArrayList = std.ArrayList;
11const Buffer = std.Buffer;
11const ArrayListSentineled = std.ArrayListSentineled;
1212const Target = std.Target;
1313const CrossTarget = std.zig.CrossTarget;
1414const self_hosted_main = @import("main.zig");
......@@ -188,14 +188,14 @@ fn fmtMain(argc: c_int, argv: [*]const [*:0]const u8) !void {
188188 const argc_usize = @intCast(usize, argc);
189189 var arg_i: usize = 0;
190190 while (arg_i < argc_usize) : (arg_i += 1) {
191 try args_list.append(mem.toSliceConst(u8, argv[arg_i]));
191 try args_list.append(mem.spanZ(argv[arg_i]));
192192 }
193193
194194 stdout = std.io.getStdOut().outStream();
195195 stderr_file = std.io.getStdErr();
196196 stderr = stderr_file.outStream();
197197
198 const args = args_list.toSliceConst()[2..];
198 const args = args_list.span()[2..];
199199
200200 var color: errmsg.Color = .Auto;
201201 var stdin_flag: bool = false;
......@@ -288,7 +288,7 @@ fn fmtMain(argc: c_int, argv: [*]const [*:0]const u8) !void {
288288 .allocator = allocator,
289289 };
290290
291 for (input_files.toSliceConst()) |file_path| {
291 for (input_files.span()) |file_path| {
292292 try fmtPath(&fmt, file_path, check_flag);
293293 }
294294 if (fmt.any_error) {
......@@ -321,7 +321,8 @@ fn fmtPath(fmt: *Fmt, file_path: []const u8, check_mode: bool) FmtError!void {
321321 if (fmt.seen.exists(file_path)) return;
322322 try fmt.seen.put(file_path);
323323
324 const source_code = io.readFileAlloc(fmt.allocator, file_path) catch |err| switch (err) {
324 const max = std.math.maxInt(usize);
325 const source_code = fs.cwd().readFileAlloc(fmt.allocator, file_path, max) catch |err| switch (err) {
325326 error.IsDir, error.AccessDenied => {
326327 // TODO make event based (and dir.next())
327328 var dir = try fs.cwd().openDir(file_path, .{ .iterate = true });
......@@ -413,12 +414,13 @@ fn printErrMsgToFile(
413414 const start_loc = tree.tokenLocationPtr(0, first_token);
414415 const end_loc = tree.tokenLocationPtr(first_token.end, last_token);
415416
416 var text_buf = try std.Buffer.initSize(allocator, 0);
417 const out_stream = &text_buf.outStream();
417 var text_buf = std.ArrayList(u8).init(allocator);
418 defer text_buf.deinit();
419 const out_stream = text_buf.outStream();
418420 try parse_error.render(&tree.tokens, out_stream);
419 const text = text_buf.toOwnedSlice();
421 const text = text_buf.span();
420422
421 const stream = &file.outStream();
423 const stream = file.outStream();
422424 try stream.print("{}:{}:{}: error: {}\n", .{ path, start_loc.line + 1, start_loc.column + 1, text });
423425
424426 if (!color_on) return;
......@@ -450,10 +452,10 @@ export fn stage2_DepTokenizer_deinit(self: *stage2_DepTokenizer) void {
450452
451453export fn stage2_DepTokenizer_next(self: *stage2_DepTokenizer) stage2_DepNextResult {
452454 const otoken = self.handle.next() catch {
453 const textz = std.Buffer.init(&self.handle.arena.allocator, self.handle.error_text) catch @panic("failed to create .d tokenizer error text");
455 const textz = std.ArrayListSentineled(u8, 0).init(&self.handle.arena.allocator, self.handle.error_text) catch @panic("failed to create .d tokenizer error text");
454456 return stage2_DepNextResult{
455457 .type_id = .error_,
456 .textz = textz.toSlice().ptr,
458 .textz = textz.span().ptr,
457459 };
458460 };
459461 const token = otoken orelse {
......@@ -462,13 +464,13 @@ export fn stage2_DepTokenizer_next(self: *stage2_DepTokenizer) stage2_DepNextRes
462464 .textz = undefined,
463465 };
464466 };
465 const textz = std.Buffer.init(&self.handle.arena.allocator, token.bytes) catch @panic("failed to create .d tokenizer token text");
467 const textz = std.ArrayListSentineled(u8, 0).init(&self.handle.arena.allocator, token.bytes) catch @panic("failed to create .d tokenizer token text");
466468 return stage2_DepNextResult{
467469 .type_id = switch (token.id) {
468470 .target => .target,
469471 .prereq => .prereq,
470472 },
471 .textz = textz.toSlice().ptr,
473 .textz = textz.span().ptr,
472474 };
473475}
474476
......@@ -575,7 +577,7 @@ fn detectNativeCpuWithLLVM(
575577 var result = Target.Cpu.baseline(arch);
576578
577579 if (llvm_cpu_name_z) |cpu_name_z| {
578 const llvm_cpu_name = mem.toSliceConst(u8, cpu_name_z);
580 const llvm_cpu_name = mem.spanZ(cpu_name_z);
579581
580582 for (arch.allCpuModels()) |model| {
581583 const this_llvm_name = model.llvm_name orelse continue;
......@@ -596,7 +598,7 @@ fn detectNativeCpuWithLLVM(
596598 const all_features = arch.allFeaturesList();
597599
598600 if (llvm_cpu_features_opt) |llvm_cpu_features| {
599 var it = mem.tokenize(mem.toSliceConst(u8, llvm_cpu_features), ",");
601 var it = mem.tokenize(mem.spanZ(llvm_cpu_features), ",");
600602 while (it.next()) |decorated_llvm_feat| {
601603 var op: enum {
602604 add,
......@@ -691,12 +693,11 @@ fn stage2CrossTarget(
691693 mcpu_oz: ?[*:0]const u8,
692694 dynamic_linker_oz: ?[*:0]const u8,
693695) !CrossTarget {
694 const zig_triple = if (zig_triple_oz) |zig_triple_z| mem.toSliceConst(u8, zig_triple_z) else "native";
695 const mcpu = if (mcpu_oz) |mcpu_z| mem.toSliceConst(u8, mcpu_z) else null;
696 const dynamic_linker = if (dynamic_linker_oz) |dl_z| mem.toSliceConst(u8, dl_z) else null;
696 const mcpu = mem.spanZ(mcpu_oz);
697 const dynamic_linker = mem.spanZ(dynamic_linker_oz);
697698 var diags: CrossTarget.ParseOptions.Diagnostics = .{};
698699 const target: CrossTarget = CrossTarget.parse(.{
699 .arch_os_abi = zig_triple,
700 .arch_os_abi = mem.spanZ(zig_triple_oz) orelse "native",
700701 .cpu_features = mcpu,
701702 .dynamic_linker = dynamic_linker,
702703 .diagnostics = &diags,
......@@ -743,15 +744,15 @@ fn stage2TargetParse(
743744
744745// ABI warning
745746const Stage2LibCInstallation = extern struct {
746 include_dir: [*:0]const u8,
747 include_dir: [*]const u8,
747748 include_dir_len: usize,
748 sys_include_dir: [*:0]const u8,
749 sys_include_dir: [*]const u8,
749750 sys_include_dir_len: usize,
750 crt_dir: [*:0]const u8,
751 crt_dir: [*]const u8,
751752 crt_dir_len: usize,
752 msvc_lib_dir: [*:0]const u8,
753 msvc_lib_dir: [*]const u8,
753754 msvc_lib_dir_len: usize,
754 kernel32_lib_dir: [*:0]const u8,
755 kernel32_lib_dir: [*]const u8,
755756 kernel32_lib_dir_len: usize,
756757
757758 fn initFromStage2(self: *Stage2LibCInstallation, libc: LibCInstallation) void {
......@@ -795,19 +796,19 @@ const Stage2LibCInstallation = extern struct {
795796 fn toStage2(self: Stage2LibCInstallation) LibCInstallation {
796797 var libc: LibCInstallation = .{};
797798 if (self.include_dir_len != 0) {
798 libc.include_dir = self.include_dir[0..self.include_dir_len :0];
799 libc.include_dir = self.include_dir[0..self.include_dir_len];
799800 }
800801 if (self.sys_include_dir_len != 0) {
801 libc.sys_include_dir = self.sys_include_dir[0..self.sys_include_dir_len :0];
802 libc.sys_include_dir = self.sys_include_dir[0..self.sys_include_dir_len];
802803 }
803804 if (self.crt_dir_len != 0) {
804 libc.crt_dir = self.crt_dir[0..self.crt_dir_len :0];
805 libc.crt_dir = self.crt_dir[0..self.crt_dir_len];
805806 }
806807 if (self.msvc_lib_dir_len != 0) {
807 libc.msvc_lib_dir = self.msvc_lib_dir[0..self.msvc_lib_dir_len :0];
808 libc.msvc_lib_dir = self.msvc_lib_dir[0..self.msvc_lib_dir_len];
808809 }
809810 if (self.kernel32_lib_dir_len != 0) {
810 libc.kernel32_lib_dir = self.kernel32_lib_dir[0..self.kernel32_lib_dir_len :0];
811 libc.kernel32_lib_dir = self.kernel32_lib_dir[0..self.kernel32_lib_dir_len];
811812 }
812813 return libc;
813814 }
......@@ -817,7 +818,7 @@ const Stage2LibCInstallation = extern struct {
817818export fn stage2_libc_parse(stage1_libc: *Stage2LibCInstallation, libc_file_z: [*:0]const u8) Error {
818819 stderr_file = std.io.getStdErr();
819820 stderr = stderr_file.outStream();
820 const libc_file = mem.toSliceConst(u8, libc_file_z);
821 const libc_file = mem.spanZ(libc_file_z);
821822 var libc = LibCInstallation.parse(std.heap.c_allocator, libc_file, stderr) catch |err| switch (err) {
822823 error.ParseError => return .SemanticAnalyzeFail,
823824 error.DiskQuota => return .DiskQuota,
......@@ -929,14 +930,14 @@ const Stage2Target = extern struct {
929930 var dynamic_linker: ?[*:0]u8 = null;
930931 const target = try crossTargetToTarget(cross_target, &dynamic_linker);
931932
932 var cache_hash = try std.Buffer.allocPrint(allocator, "{}\n{}\n", .{
933 var cache_hash = try std.ArrayListSentineled(u8, 0).allocPrint(allocator, "{}\n{}\n", .{
933934 target.cpu.model.name,
934935 target.cpu.features.asBytes(),
935936 });
936937 defer cache_hash.deinit();
937938
938939 const generic_arch_name = target.cpu.arch.genericName();
939 var cpu_builtin_str_buffer = try std.Buffer.allocPrint(allocator,
940 var cpu_builtin_str_buffer = try std.ArrayListSentineled(u8, 0).allocPrint(allocator,
940941 \\Cpu{{
941942 \\ .arch = .{},
942943 \\ .model = &Target.{}.cpu.{},
......@@ -951,7 +952,7 @@ const Stage2Target = extern struct {
951952 });
952953 defer cpu_builtin_str_buffer.deinit();
953954
954 var llvm_features_buffer = try std.Buffer.initSize(allocator, 0);
955 var llvm_features_buffer = try std.ArrayListSentineled(u8, 0).initSize(allocator, 0);
955956 defer llvm_features_buffer.deinit();
956957
957958 // Unfortunately we have to do the work twice, because Clang does not support
......@@ -966,17 +967,17 @@ const Stage2Target = extern struct {
966967
967968 if (feature.llvm_name) |llvm_name| {
968969 const plus_or_minus = "-+"[@boolToInt(is_enabled)];
969 try llvm_features_buffer.appendByte(plus_or_minus);
970 try llvm_features_buffer.append(llvm_name);
971 try llvm_features_buffer.append(",");
970 try llvm_features_buffer.append(plus_or_minus);
971 try llvm_features_buffer.appendSlice(llvm_name);
972 try llvm_features_buffer.appendSlice(",");
972973 }
973974
974975 if (is_enabled) {
975976 // TODO some kind of "zig identifier escape" function rather than
976977 // unconditionally using @"" syntax
977 try cpu_builtin_str_buffer.append(" .@\"");
978 try cpu_builtin_str_buffer.append(feature.name);
979 try cpu_builtin_str_buffer.append("\",\n");
978 try cpu_builtin_str_buffer.appendSlice(" .@\"");
979 try cpu_builtin_str_buffer.appendSlice(feature.name);
980 try cpu_builtin_str_buffer.appendSlice("\",\n");
980981 }
981982 }
982983
......@@ -995,16 +996,16 @@ const Stage2Target = extern struct {
995996 },
996997 }
997998
998 try cpu_builtin_str_buffer.append(
999 try cpu_builtin_str_buffer.appendSlice(
9991000 \\ }),
10001001 \\};
10011002 \\
10021003 );
10031004
1004 assert(mem.endsWith(u8, llvm_features_buffer.toSliceConst(), ","));
1005 assert(mem.endsWith(u8, llvm_features_buffer.span(), ","));
10051006 llvm_features_buffer.shrink(llvm_features_buffer.len() - 1);
10061007
1007 var os_builtin_str_buffer = try std.Buffer.allocPrint(allocator,
1008 var os_builtin_str_buffer = try std.ArrayListSentineled(u8, 0).allocPrint(allocator,
10081009 \\Os{{
10091010 \\ .tag = .{},
10101011 \\ .version_range = .{{
......@@ -1047,7 +1048,7 @@ const Stage2Target = extern struct {
10471048 .emscripten,
10481049 .uefi,
10491050 .other,
1050 => try os_builtin_str_buffer.append(" .none = {} }\n"),
1051 => try os_builtin_str_buffer.appendSlice(" .none = {} }\n"),
10511052
10521053 .freebsd,
10531054 .macosx,
......@@ -1123,10 +1124,10 @@ const Stage2Target = extern struct {
11231124 @tagName(target.os.version_range.windows.max),
11241125 }),
11251126 }
1126 try os_builtin_str_buffer.append("};\n");
1127 try os_builtin_str_buffer.appendSlice("};\n");
11271128
1128 try cache_hash.append(
1129 os_builtin_str_buffer.toSlice()[os_builtin_str_ver_start_index..os_builtin_str_buffer.len()],
1129 try cache_hash.appendSlice(
1130 os_builtin_str_buffer.span()[os_builtin_str_ver_start_index..os_builtin_str_buffer.len()],
11301131 );
11311132
11321133 const glibc_or_darwin_version = blk: {
......@@ -1238,10 +1239,10 @@ fn stage2DetectNativePaths(stage1_paths: *Stage2NativePaths) !void {
12381239 var paths = try std.zig.system.NativePaths.detect(std.heap.c_allocator);
12391240 errdefer paths.deinit();
12401241
1241 try convertSlice(paths.include_dirs.toSlice(), &stage1_paths.include_dirs_ptr, &stage1_paths.include_dirs_len);
1242 try convertSlice(paths.lib_dirs.toSlice(), &stage1_paths.lib_dirs_ptr, &stage1_paths.lib_dirs_len);
1243 try convertSlice(paths.rpaths.toSlice(), &stage1_paths.rpaths_ptr, &stage1_paths.rpaths_len);
1244 try convertSlice(paths.warnings.toSlice(), &stage1_paths.warnings_ptr, &stage1_paths.warnings_len);
1242 try convertSlice(paths.include_dirs.span(), &stage1_paths.include_dirs_ptr, &stage1_paths.include_dirs_len);
1243 try convertSlice(paths.lib_dirs.span(), &stage1_paths.lib_dirs_ptr, &stage1_paths.lib_dirs_len);
1244 try convertSlice(paths.rpaths.span(), &stage1_paths.rpaths_ptr, &stage1_paths.rpaths_len);
1245 try convertSlice(paths.warnings.span(), &stage1_paths.warnings_ptr, &stage1_paths.warnings_len);
12451246}
12461247
12471248fn convertSlice(slice: [][:0]u8, ptr: *[*][*:0]u8, len: *usize) !void {
......@@ -1285,18 +1286,19 @@ pub const ClangArgIterator = extern struct {
12851286 shared,
12861287 rdynamic,
12871288 wl,
1288 preprocess,
1289 pp_or_asm,
12891290 optimize,
12901291 debug,
12911292 sanitize,
12921293 linker_script,
12931294 verbose_cmds,
1294 exceptions,
1295 no_exceptions,
1296 rtti,
1297 no_rtti,
12981295 for_linker,
12991296 linker_input_z,
1297 lib_dir,
1298 mcpu,
1299 dep_file,
1300 framework_dir,
1301 framework,
13001302 };
13011303
13021304 const Args = struct {
src-self-hosted/test.zig+7-5
......@@ -88,8 +88,7 @@ pub const TestContext = struct {
8888 try std.fs.cwd().makePath(dirname);
8989 }
9090
91 // TODO async I/O
92 try std.io.writeFile(file1_path, source);
91 try std.fs.cwd().writeFile(file1_path, source);
9392
9493 var comp = try Compilation.create(
9594 &self.zig_compiler,
......@@ -122,8 +121,7 @@ pub const TestContext = struct {
122121 try std.fs.cwd().makePath(dirname);
123122 }
124123
125 // TODO async I/O
126 try std.io.writeFile(file1_path, source);
124 try std.fs.cwd().writeFile(file1_path, source);
127125
128126 var comp = try Compilation.create(
129127 &self.zig_compiler,
......@@ -156,7 +154,11 @@ pub const TestContext = struct {
156154 .Ok => {
157155 const argv = [_][]const u8{exe_file};
158156 // TODO use event loop
159 const child = try std.ChildProcess.exec(allocator, argv, null, null, 1024 * 1024);
157 const child = try std.ChildProcess.exec(.{
158 .allocator = allocator,
159 .argv = argv,
160 .max_output_bytes = 1024 * 1024,
161 });
160162 switch (child.term) {
161163 .Exited => |code| {
162164 if (code != 0) {
src-self-hosted/translate_c.zig+44-12
......@@ -209,7 +209,7 @@ const Scope = struct {
209209
210210pub const Context = struct {
211211 tree: *ast.Tree,
212 source_buffer: *std.Buffer,
212 source_buffer: *std.ArrayList(u8),
213213 err: Error,
214214 source_manager: *ZigClangSourceManager,
215215 decl_table: DeclTable,
......@@ -235,7 +235,7 @@ pub const Context = struct {
235235
236236 /// Convert a null-terminated C string to a slice allocated in the arena
237237 fn str(c: *Context, s: [*:0]const u8) ![]u8 {
238 return mem.dupe(c.a(), u8, mem.toSliceConst(u8, s));
238 return mem.dupe(c.a(), u8, mem.spanZ(s));
239239 }
240240
241241 /// Convert a clang source location to a file:line:column string
......@@ -275,7 +275,7 @@ pub fn translate(
275275
276276 const tree = try tree_arena.allocator.create(ast.Tree);
277277 tree.* = ast.Tree{
278 .source = undefined, // need to use Buffer.toOwnedSlice later
278 .source = undefined, // need to use toOwnedSlice later
279279 .root_node = undefined,
280280 .arena_allocator = tree_arena,
281281 .tokens = undefined, // can't reference the allocator yet
......@@ -296,7 +296,7 @@ pub fn translate(
296296 .eof_token = undefined,
297297 };
298298
299 var source_buffer = try std.Buffer.initSize(arena, 0);
299 var source_buffer = std.ArrayList(u8).init(arena);
300300
301301 var context = Context{
302302 .tree = tree,
......@@ -3845,7 +3845,9 @@ fn transCreateNodePtrType(
38453845}
38463846
38473847fn transCreateNodeAPInt(c: *Context, int: *const ZigClangAPSInt) !*ast.Node {
3848 const num_limbs = ZigClangAPSInt_getNumWords(int);
3848 const num_limbs = math.cast(usize, ZigClangAPSInt_getNumWords(int)) catch |err| switch (err) {
3849 error.Overflow => return error.OutOfMemory,
3850 };
38493851 var aps_int = int;
38503852 const is_negative = ZigClangAPSInt_isSigned(int) and ZigClangAPSInt_isNegative(int);
38513853 if (is_negative)
......@@ -3855,8 +3857,26 @@ fn transCreateNodeAPInt(c: *Context, int: *const ZigClangAPSInt) !*ast.Node {
38553857 big.negate();
38563858 defer big.deinit();
38573859 const data = ZigClangAPSInt_getRawData(aps_int);
3858 var i: @TypeOf(num_limbs) = 0;
3859 while (i < num_limbs) : (i += 1) big.limbs[i] = data[i];
3860 switch (@sizeOf(std.math.big.Limb)) {
3861 8 => {
3862 var i: usize = 0;
3863 while (i < num_limbs) : (i += 1) {
3864 big.limbs[i] = data[i];
3865 }
3866 },
3867 4 => {
3868 var limb_i: usize = 0;
3869 var data_i: usize = 0;
3870 while (limb_i < num_limbs) : ({
3871 limb_i += 2;
3872 data_i += 1;
3873 }) {
3874 big.limbs[limb_i] = @truncate(u32, data[data_i]);
3875 big.limbs[limb_i + 1] = @truncate(u32, data[data_i] >> 32);
3876 }
3877 },
3878 else => @compileError("unimplemented"),
3879 }
38603880 const str = big.toString(c.a(), 10) catch |err| switch (err) {
38613881 error.OutOfMemory => return error.OutOfMemory,
38623882 else => unreachable,
......@@ -4289,7 +4309,7 @@ fn makeRestorePoint(c: *Context) RestorePoint {
42894309 return RestorePoint{
42904310 .c = c,
42914311 .token_index = c.tree.tokens.len,
4292 .src_buf_index = c.source_buffer.len(),
4312 .src_buf_index = c.source_buffer.len,
42934313 };
42944314}
42954315
......@@ -4751,11 +4771,11 @@ fn appendToken(c: *Context, token_id: Token.Id, bytes: []const u8) !ast.TokenInd
47514771
47524772fn appendTokenFmt(c: *Context, token_id: Token.Id, comptime format: []const u8, args: var) !ast.TokenIndex {
47534773 assert(token_id != .Invalid);
4754 const start_index = c.source_buffer.len();
4774 const start_index = c.source_buffer.len;
47554775 errdefer c.source_buffer.shrink(start_index);
47564776
47574777 try c.source_buffer.outStream().print(format, args);
4758 const end_index = c.source_buffer.len();
4778 const end_index = c.source_buffer.len;
47594779 const token_index = c.tree.tokens.len;
47604780 const new_token = try c.tree.tokens.addOne();
47614781 errdefer c.tree.tokens.shrink(token_index);
......@@ -4765,7 +4785,7 @@ fn appendTokenFmt(c: *Context, token_id: Token.Id, comptime format: []const u8,
47654785 .start = start_index,
47664786 .end = end_index,
47674787 };
4768 try c.source_buffer.appendByte(' ');
4788 try c.source_buffer.append(' ');
47694789
47704790 return token_index;
47714791}
......@@ -5782,6 +5802,18 @@ fn parseCSuffixOpExpr(c: *Context, it: *CTokenList.Iterator, source: []const u8,
57825802 op_id = .Mod;
57835803 op_token = try appendToken(c, .Percent, "%");
57845804 },
5805 .StringLiteral => {
5806 op_id = .ArrayCat;
5807 op_token = try appendToken(c, .PlusPlus, "++");
5808
5809 _ = it.prev();
5810 },
5811 .Identifier => {
5812 op_id = .ArrayCat;
5813 op_token = try appendToken(c, .PlusPlus, "++");
5814
5815 _ = it.prev();
5816 },
57855817 else => {
57865818 _ = it.prev();
57875819 return node;
......@@ -5839,7 +5871,7 @@ fn parseCPrefixOpExpr(c: *Context, it: *CTokenList.Iterator, source: []const u8,
58395871
58405872fn tokenSlice(c: *Context, token: ast.TokenIndex) []u8 {
58415873 const tok = c.tree.tokens.at(token);
5842 const slice = c.source_buffer.toSlice()[tok.start..tok.end];
5874 const slice = c.source_buffer.span()[tok.start..tok.end];
58435875 return if (mem.startsWith(u8, slice, "@\""))
58445876 slice[2 .. slice.len - 1]
58455877 else
src-self-hosted/type.zig+2-2
......@@ -387,10 +387,10 @@ pub const Type = struct {
387387 };
388388 errdefer comp.gpa().destroy(self);
389389
390 var name_buf = try std.Buffer.initSize(comp.gpa(), 0);
390 var name_buf = std.ArrayList(u8).init(comp.gpa());
391391 defer name_buf.deinit();
392392
393 const name_stream = &std.io.BufferOutStream.init(&name_buf).stream;
393 const name_stream = name_buf.outStream();
394394
395395 switch (key.data) {
396396 .Generic => |generic| {
src-self-hosted/util.zig+7-7
......@@ -16,11 +16,11 @@ pub fn getDarwinArchString(self: Target) [:0]const u8 {
1616 }
1717}
1818
19pub fn llvmTargetFromTriple(triple: std.Buffer) !*llvm.Target {
19pub fn llvmTargetFromTriple(triple: [:0]const u8) !*llvm.Target {
2020 var result: *llvm.Target = undefined;
2121 var err_msg: [*:0]u8 = undefined;
22 if (llvm.GetTargetFromTriple(triple.toSlice(), &result, &err_msg) != 0) {
23 std.debug.warn("triple: {s} error: {s}\n", .{ triple.toSlice(), err_msg });
22 if (llvm.GetTargetFromTriple(triple, &result, &err_msg) != 0) {
23 std.debug.warn("triple: {s} error: {s}\n", .{ triple, err_msg });
2424 return error.UnsupportedTarget;
2525 }
2626 return result;
......@@ -34,14 +34,14 @@ pub fn initializeAllTargets() void {
3434 llvm.InitializeAllAsmParsers();
3535}
3636
37pub fn getLLVMTriple(allocator: *std.mem.Allocator, target: std.Target) !std.Buffer {
38 var result = try std.Buffer.initSize(allocator, 0);
39 errdefer result.deinit();
37pub fn getLLVMTriple(allocator: *std.mem.Allocator, target: std.Target) ![:0]u8 {
38 var result = try std.ArrayListSentineled(u8, 0).initSize(allocator, 0);
39 defer result.deinit();
4040
4141 try result.outStream().print(
4242 "{}-unknown-{}-{}",
4343 .{ @tagName(target.cpu.arch), @tagName(target.os.tag), @tagName(target.abi) },
4444 );
4545
46 return result;
46 return result.toOwnedSlice();
4747}
src-self-hosted/value.zig+9-9
......@@ -3,7 +3,7 @@ const Scope = @import("scope.zig").Scope;
33const Compilation = @import("compilation.zig").Compilation;
44const ObjectFile = @import("codegen.zig").ObjectFile;
55const llvm = @import("llvm.zig");
6const Buffer = std.Buffer;
6const ArrayListSentineled = std.ArrayListSentineled;
77const assert = std.debug.assert;
88
99/// Values are ref-counted, heap-allocated, and copy-on-write
......@@ -131,9 +131,9 @@ pub const Value = struct {
131131
132132 /// The main external name that is used in the .o file.
133133 /// TODO https://github.com/ziglang/zig/issues/265
134 symbol_name: Buffer,
134 symbol_name: ArrayListSentineled(u8, 0),
135135
136 pub fn create(comp: *Compilation, fn_type: *Type.Fn, symbol_name: Buffer) !*FnProto {
136 pub fn create(comp: *Compilation, fn_type: *Type.Fn, symbol_name: ArrayListSentineled(u8, 0)) !*FnProto {
137137 const self = try comp.gpa().create(FnProto);
138138 self.* = FnProto{
139139 .base = Value{
......@@ -156,7 +156,7 @@ pub const Value = struct {
156156 const llvm_fn_type = try self.base.typ.getLlvmType(ofile.arena, ofile.context);
157157 const llvm_fn = llvm.AddFunction(
158158 ofile.module,
159 self.symbol_name.toSliceConst(),
159 self.symbol_name.span(),
160160 llvm_fn_type,
161161 ) orelse return error.OutOfMemory;
162162
......@@ -171,7 +171,7 @@ pub const Value = struct {
171171
172172 /// The main external name that is used in the .o file.
173173 /// TODO https://github.com/ziglang/zig/issues/265
174 symbol_name: Buffer,
174 symbol_name: ArrayListSentineled(u8, 0),
175175
176176 /// parent should be the top level decls or container decls
177177 fndef_scope: *Scope.FnDef,
......@@ -183,13 +183,13 @@ pub const Value = struct {
183183 block_scope: ?*Scope.Block,
184184
185185 /// Path to the object file that contains this function
186 containing_object: Buffer,
186 containing_object: ArrayListSentineled(u8, 0),
187187
188188 link_set_node: *std.TailQueue(?*Value.Fn).Node,
189189
190190 /// Creates a Fn value with 1 ref
191191 /// Takes ownership of symbol_name
192 pub fn create(comp: *Compilation, fn_type: *Type.Fn, fndef_scope: *Scope.FnDef, symbol_name: Buffer) !*Fn {
192 pub fn create(comp: *Compilation, fn_type: *Type.Fn, fndef_scope: *Scope.FnDef, symbol_name: ArrayListSentineled(u8, 0)) !*Fn {
193193 const link_set_node = try comp.gpa().create(Compilation.FnLinkSet.Node);
194194 link_set_node.* = Compilation.FnLinkSet.Node{
195195 .data = null,
......@@ -209,7 +209,7 @@ pub const Value = struct {
209209 .child_scope = &fndef_scope.base,
210210 .block_scope = null,
211211 .symbol_name = symbol_name,
212 .containing_object = Buffer.initNull(comp.gpa()),
212 .containing_object = ArrayListSentineled(u8, 0).initNull(comp.gpa()),
213213 .link_set_node = link_set_node,
214214 };
215215 fn_type.base.base.ref();
......@@ -241,7 +241,7 @@ pub const Value = struct {
241241 const llvm_fn_type = try self.base.typ.getLlvmType(ofile.arena, ofile.context);
242242 const llvm_fn = llvm.AddFunction(
243243 ofile.module,
244 self.symbol_name.toSliceConst(),
244 self.symbol_name.span(),
245245 llvm_fn_type,
246246 ) orelse return error.OutOfMemory;
247247
src/all_types.hpp+30-4
......@@ -54,6 +54,16 @@ struct ResultLocCast;
5454struct ResultLocReturn;
5555struct IrExecutableGen;
5656
57enum FileExt {
58 FileExtUnknown,
59 FileExtAsm,
60 FileExtC,
61 FileExtCpp,
62 FileExtHeader,
63 FileExtLLVMIr,
64 FileExtLLVMBitCode,
65};
66
5767enum PtrLen {
5868 PtrLenUnknown,
5969 PtrLenSingle,
......@@ -1324,6 +1334,7 @@ struct ZigTypeFloat {
13241334 size_t bit_count;
13251335};
13261336
1337// Needs to have the same memory layout as ZigTypeVector
13271338struct ZigTypeArray {
13281339 ZigType *child_type;
13291340 uint64_t len;
......@@ -1512,12 +1523,17 @@ struct ZigTypeBoundFn {
15121523 ZigType *fn_type;
15131524};
15141525
1526// Needs to have the same memory layout as ZigTypeArray
15151527struct ZigTypeVector {
15161528 // The type must be a pointer, integer, bool, or float
15171529 ZigType *elem_type;
1518 uint32_t len;
1530 uint64_t len;
1531 size_t padding;
15191532};
15201533
1534// A lot of code is relying on ZigTypeArray and ZigTypeVector having the same layout/size
1535static_assert(sizeof(ZigTypeVector) == sizeof(ZigTypeArray), "Size of ZigTypeVector and ZigTypeArray do not match!");
1536
15211537enum ZigTypeId {
15221538 ZigTypeIdInvalid,
15231539 ZigTypeIdMetaType,
......@@ -1999,6 +2015,12 @@ enum WantCSanitize {
19992015 WantCSanitizeEnabled,
20002016};
20012017
2018enum OptionalBool {
2019 OptionalBoolNull,
2020 OptionalBoolFalse,
2021 OptionalBoolTrue,
2022};
2023
20022024struct CFile {
20032025 ZigList<const char *> args;
20042026 const char *source_path;
......@@ -2214,6 +2236,7 @@ struct CodeGen {
22142236 bool reported_bad_link_libc_error;
22152237 bool is_dynamic; // shared library rather than static library. dynamic musl rather than static musl.
22162238 bool need_frame_size_prefix_data;
2239 bool disable_c_depfile;
22172240
22182241 //////////////////////////// Participates in Input Parameter Cache Hash
22192242 /////// Note: there is a separate cache hash for builtin.zig, when adding fields,
......@@ -2242,6 +2265,9 @@ struct CodeGen {
22422265 const ZigTarget *zig_target;
22432266 TargetSubsystem subsystem; // careful using this directly; see detect_subsystem
22442267 ValgrindSupport valgrind_support;
2268 CodeModel code_model;
2269 OptionalBool linker_gc_sections;
2270 OptionalBool linker_allow_shlib_undefined;
22452271 bool strip_debug_symbols;
22462272 bool is_test_build;
22472273 bool is_single_threaded;
......@@ -2262,9 +2288,8 @@ struct CodeGen {
22622288 bool emit_asm;
22632289 bool emit_llvm_ir;
22642290 bool test_is_evented;
2265 bool cpp_rtti;
2266 bool cpp_exceptions;
2267 CodeModel code_model;
2291 bool linker_z_nodelete;
2292 bool linker_z_defs;
22682293
22692294 Buf *root_out_name;
22702295 Buf *test_filter;
......@@ -2273,6 +2298,7 @@ struct CodeGen {
22732298 Buf *zig_std_dir;
22742299 Buf *version_script_path;
22752300 Buf *override_soname;
2301 Buf *linker_optimization;
22762302
22772303 const char **llvm_argv;
22782304 size_t llvm_argv_len;
src/analyze.cpp+7-4
......@@ -363,6 +363,7 @@ bool type_is_resolved(ZigType *type_entry, ResolveStatus status) {
363363 case ResolveStatusLLVMFull:
364364 return type_entry->llvm_type != nullptr;
365365 }
366 zig_unreachable();
366367 case ZigTypeIdOpaque:
367368 return status < ResolveStatusSizeKnown;
368369 case ZigTypeIdPointer:
......@@ -381,6 +382,7 @@ bool type_is_resolved(ZigType *type_entry, ResolveStatus status) {
381382 case ResolveStatusLLVMFull:
382383 return type_entry->llvm_type != nullptr;
383384 }
385 zig_unreachable();
384386 case ZigTypeIdMetaType:
385387 case ZigTypeIdVoid:
386388 case ZigTypeIdBool:
......@@ -5156,6 +5158,7 @@ ZigType *get_vector_type(CodeGen *g, uint32_t len, ZigType *elem_type) {
51565158 }
51575159 entry->data.vector.len = len;
51585160 entry->data.vector.elem_type = elem_type;
5161 entry->data.vector.padding = 0;
51595162
51605163 buf_resize(&entry->name, 0);
51615164 buf_appendf(&entry->name, "@Vector(%u, %s)", len, buf_ptr(&elem_type->name));
......@@ -5358,7 +5361,7 @@ static uint32_t hash_const_val(ZigValue *const_val) {
53585361 return result;
53595362 }
53605363 case ZigTypeIdEnumLiteral:
5361 return buf_hash(const_val->data.x_enum_literal) * 2691276464;
5364 return buf_hash(const_val->data.x_enum_literal) * (uint32_t)2691276464;
53625365 case ZigTypeIdEnum:
53635366 {
53645367 uint32_t result = 31643936;
......@@ -5426,12 +5429,12 @@ static uint32_t hash_const_val(ZigValue *const_val) {
54265429 return 2709806591;
54275430 case ZigTypeIdOptional:
54285431 if (get_src_ptr_type(const_val->type) != nullptr) {
5429 return hash_const_val_ptr(const_val) * 1992916303;
5432 return hash_const_val_ptr(const_val) * (uint32_t)1992916303;
54305433 } else if (const_val->type->data.maybe.child_type->id == ZigTypeIdErrorSet) {
5431 return hash_const_val_error_set(const_val) * 3147031929;
5434 return hash_const_val_error_set(const_val) * (uint32_t)3147031929;
54325435 } else {
54335436 if (const_val->data.x_optional) {
5434 return hash_const_val(const_val->data.x_optional) * 1992916303;
5437 return hash_const_val(const_val->data.x_optional) * (uint32_t)1992916303;
54355438 } else {
54365439 return 4016830364;
54375440 }
src/analyze.hpp+1-7
......@@ -257,14 +257,8 @@ Error create_c_object_cache(CodeGen *g, CacheHash **out_cache_hash, bool verbose
257257LLVMTypeRef get_llvm_type(CodeGen *g, ZigType *type);
258258ZigLLVMDIType *get_llvm_di_type(CodeGen *g, ZigType *type);
259259
260enum CSourceKind {
261 CSourceKindAsm,
262 CSourceKindC,
263 CSourceKindCpp,
264};
265
266260void add_cc_args(CodeGen *g, ZigList<const char *> &args, const char *out_dep_path, bool translate_c,
267 CSourceKind source_kind);
261 FileExt source_kind);
268262
269263void src_assert(bool ok, AstNode *source_node);
270264bool is_container(ZigType *type_entry);
src/bigint.cpp+1-1
......@@ -1430,7 +1430,7 @@ void bigint_shr(BigInt *dest, const BigInt *op1, const BigInt *op2) {
14301430 uint64_t digit = op1_digits[op_digit_index];
14311431 size_t dest_digit_index = op_digit_index - digit_shift_count;
14321432 digits[dest_digit_index] = carry | (digit >> leftover_shift_count);
1433 carry = digit << (64 - leftover_shift_count);
1433 carry = (leftover_shift_count != 0) ? (digit << (64 - leftover_shift_count)) : 0;
14341434
14351435 if (dest_digit_index == 0) { break; }
14361436 op_digit_index -= 1;
src/buffer.hpp+1-4
......@@ -178,10 +178,7 @@ static inline bool buf_starts_with_str(Buf *buf, const char *str) {
178178}
179179
180180static inline bool buf_ends_with_mem(Buf *buf, const char *mem, size_t mem_len) {
181 if (buf_len(buf) < mem_len) {
182 return false;
183 }
184 return memcmp(buf_ptr(buf) + buf_len(buf) - mem_len, mem, mem_len) == 0;
181 return mem_ends_with_mem(buf_ptr(buf), buf_len(buf), mem, mem_len);
185182}
186183
187184static inline bool buf_ends_with_str(Buf *buf, const char *str) {
src/cache_hash.cpp+7-1
......@@ -27,11 +27,17 @@ void cache_init(CacheHash *ch, Buf *manifest_dir) {
2727void cache_mem(CacheHash *ch, const char *ptr, size_t len) {
2828 assert(ch->manifest_file_path == nullptr);
2929 assert(ptr != nullptr);
30 // + 1 to include the null byte
3130 blake2b_update(&ch->blake, ptr, len);
3231}
3332
33void cache_slice(CacheHash *ch, Slice<const char> slice) {
34 // mix the length into the hash so that two juxtaposed cached slices can't collide
35 cache_usize(ch, slice.len);
36 cache_mem(ch, slice.ptr, slice.len);
37}
38
3439void cache_str(CacheHash *ch, const char *ptr) {
40 // + 1 to include the null byte
3541 cache_mem(ch, ptr, strlen(ptr) + 1);
3642}
3743
src/cache_hash.hpp+1
......@@ -36,6 +36,7 @@ void cache_init(CacheHash *ch, Buf *manifest_dir);
3636
3737// Next, use the hash population functions to add the initial parameters.
3838void cache_mem(CacheHash *ch, const char *ptr, size_t len);
39void cache_slice(CacheHash *ch, Slice<const char> slice);
3940void cache_str(CacheHash *ch, const char *ptr);
4041void cache_int(CacheHash *ch, int x);
4142void cache_bool(CacheHash *ch, bool x);
src/codegen.cpp+82-89
......@@ -714,7 +714,7 @@ static LLVMValueRef get_arithmetic_overflow_fn(CodeGen *g, ZigType *operand_type
714714 };
715715
716716 if (operand_type->id == ZigTypeIdVector) {
717 sprintf(fn_name, "llvm.%s.with.overflow.v%" PRIu32 "i%" PRIu32, signed_str,
717 sprintf(fn_name, "llvm.%s.with.overflow.v%" PRIu64 "i%" PRIu32, signed_str,
718718 operand_type->data.vector.len, int_type->data.integral.bit_count);
719719
720720 LLVMTypeRef return_elem_types[] = {
......@@ -3954,8 +3954,9 @@ static void render_async_var_decls(CodeGen *g, Scope *scope) {
39543954 if (var->did_the_decl_codegen) {
39553955 render_decl_var(g, var);
39563956 }
3957 // fallthrough
39583957 }
3958 ZIG_FALLTHROUGH;
3959
39593960 case ScopeIdDecls:
39603961 case ScopeIdBlock:
39613962 case ScopeIdDefer:
......@@ -8784,8 +8785,6 @@ static Error define_builtin_compile_vars(CodeGen *g) {
87848785 cache_bool(&cache_hash, g->is_test_build);
87858786 cache_bool(&cache_hash, g->is_single_threaded);
87868787 cache_bool(&cache_hash, g->test_is_evented);
8787 cache_bool(&cache_hash, g->cpp_rtti);
8788 cache_bool(&cache_hash, g->cpp_exceptions);
87898788 cache_int(&cache_hash, g->code_model);
87908789 cache_int(&cache_hash, g->zig_target->is_native_os);
87918790 cache_int(&cache_hash, g->zig_target->is_native_cpu);
......@@ -9125,21 +9124,29 @@ static void detect_libc(CodeGen *g) {
91259124 g->libc_include_dir_len = 0;
91269125 g->libc_include_dir_list = heap::c_allocator.allocate<const char *>(dir_count);
91279126
9128 g->libc_include_dir_list[g->libc_include_dir_len] = g->libc->include_dir;
9127 g->libc_include_dir_list[g->libc_include_dir_len] = buf_ptr(buf_create_from_mem(
9128 g->libc->include_dir, g->libc->include_dir_len));
91299129 g->libc_include_dir_len += 1;
91309130
91319131 if (want_sys_dir) {
9132 g->libc_include_dir_list[g->libc_include_dir_len] = g->libc->sys_include_dir;
9132 g->libc_include_dir_list[g->libc_include_dir_len] = buf_ptr(buf_create_from_mem(
9133 g->libc->sys_include_dir, g->libc->sys_include_dir_len));
91339134 g->libc_include_dir_len += 1;
91349135 }
91359136
91369137 if (want_um_and_shared_dirs != 0) {
9137 g->libc_include_dir_list[g->libc_include_dir_len] = buf_ptr(buf_sprintf(
9138 "%s" OS_SEP ".." OS_SEP "um", g->libc->include_dir));
9138 Buf *include_dir_parent = buf_alloc();
9139 os_path_join(buf_create_from_mem(g->libc->include_dir, g->libc->include_dir_len),
9140 buf_create_from_str(".."), include_dir_parent);
9141
9142 Buf *buff1 = buf_alloc();
9143 os_path_join(include_dir_parent, buf_create_from_str("um"), buff1);
9144 g->libc_include_dir_list[g->libc_include_dir_len] = buf_ptr(buff1);
91399145 g->libc_include_dir_len += 1;
91409146
9141 g->libc_include_dir_list[g->libc_include_dir_len] = buf_ptr(buf_sprintf(
9142 "%s" OS_SEP ".." OS_SEP "shared", g->libc->include_dir));
9147 Buf *buff2 = buf_alloc();
9148 os_path_join(include_dir_parent, buf_create_from_str("shared"), buff2);
9149 g->libc_include_dir_list[g->libc_include_dir_len] = buf_ptr(buff2);
91439150 g->libc_include_dir_len += 1;
91449151 }
91459152 assert(g->libc_include_dir_len == dir_count);
......@@ -9163,20 +9170,13 @@ static void detect_libc(CodeGen *g) {
91639170
91649171// does not add the "cc" arg
91659172void add_cc_args(CodeGen *g, ZigList<const char *> &args, const char *out_dep_path,
9166 bool translate_c, CSourceKind source_kind)
9173 bool translate_c, FileExt source_kind)
91679174{
91689175 if (translate_c) {
91699176 args.append("-x");
91709177 args.append("c");
91719178 }
91729179
9173 if (source_kind != CSourceKindAsm && out_dep_path != nullptr) {
9174 args.append("-MD");
9175 args.append("-MV");
9176 args.append("-MF");
9177 args.append(out_dep_path);
9178 }
9179
91809180 args.append("-nostdinc");
91819181 args.append("-fno-spell-checking");
91829182
......@@ -9184,14 +9184,7 @@ void add_cc_args(CodeGen *g, ZigList<const char *> &args, const char *out_dep_pa
91849184 args.append("-ffunction-sections");
91859185 }
91869186
9187 if (translate_c) {
9188 if (source_kind != CSourceKindAsm) {
9189 // this gives us access to preprocessing entities, presumably at
9190 // the cost of performance
9191 args.append("-Xclang");
9192 args.append("-detailed-preprocessing-record");
9193 }
9194 } else {
9187 if (!translate_c) {
91959188 switch (g->err_color) {
91969189 case ErrColorAuto:
91979190 break;
......@@ -9225,24 +9218,25 @@ void add_cc_args(CodeGen *g, ZigList<const char *> &args, const char *out_dep_pa
92259218 args.append("-D_LIBCXXABI_DISABLE_VISIBILITY_ANNOTATIONS");
92269219 }
92279220
9228 // According to Rich Felker libc headers are supposed to go before C language headers.
9229 // However as noted by @dimenus, appending libc headers before c_headers breaks intrinsics
9230 // and other compiler specific items.
9231 args.append("-isystem");
9232 args.append(buf_ptr(g->zig_c_headers_dir));
9233
9234 for (size_t i = 0; i < g->libc_include_dir_len; i += 1) {
9235 const char *include_dir = g->libc_include_dir_list[i];
9236 args.append("-isystem");
9237 args.append(include_dir);
9238 }
9239
92409221 args.append("-target");
92419222 args.append(buf_ptr(&g->llvm_triple_str));
92429223
92439224 switch (source_kind) {
9244 case CSourceKindC:
9245 case CSourceKindCpp:
9225 case FileExtC:
9226 case FileExtCpp:
9227 case FileExtHeader:
9228 // According to Rich Felker libc headers are supposed to go before C language headers.
9229 // However as noted by @dimenus, appending libc headers before c_headers breaks intrinsics
9230 // and other compiler specific items.
9231 args.append("-isystem");
9232 args.append(buf_ptr(g->zig_c_headers_dir));
9233
9234 for (size_t i = 0; i < g->libc_include_dir_len; i += 1) {
9235 const char *include_dir = g->libc_include_dir_list[i];
9236 args.append("-isystem");
9237 args.append(include_dir);
9238 }
9239
92469240 if (g->zig_target->llvm_cpu_name != nullptr) {
92479241 args.append("-Xclang");
92489242 args.append("-target-cpu");
......@@ -9255,18 +9249,25 @@ void add_cc_args(CodeGen *g, ZigList<const char *> &args, const char *out_dep_pa
92559249 args.append("-Xclang");
92569250 args.append(g->zig_target->llvm_cpu_features);
92579251 }
9252 if (translate_c) {
9253 // this gives us access to preprocessing entities, presumably at
9254 // the cost of performance
9255 args.append("-Xclang");
9256 args.append("-detailed-preprocessing-record");
9257 }
9258 if (out_dep_path != nullptr) {
9259 args.append("-MD");
9260 args.append("-MV");
9261 args.append("-MF");
9262 args.append(out_dep_path);
9263 }
92589264 break;
9259 case CSourceKindAsm:
9265 case FileExtAsm:
9266 case FileExtLLVMIr:
9267 case FileExtLLVMBitCode:
9268 case FileExtUnknown:
92609269 break;
92619270 }
9262 if (source_kind == CSourceKindCpp) {
9263 if (!g->cpp_rtti) {
9264 args.append("-fno-rtti");
9265 }
9266 if (!g->cpp_exceptions) {
9267 args.append("-fno-exceptions");
9268 }
9269 }
92709271 for (size_t i = 0; i < g->zig_target->llvm_cpu_features_asm_len; i += 1) {
92719272 args.append(g->zig_target->llvm_cpu_features_asm_ptr[i]);
92729273 }
......@@ -9414,7 +9415,7 @@ void codegen_translate_c(CodeGen *g, Buf *full_path) {
94149415 }
94159416
94169417 ZigList<const char *> clang_argv = {0};
9417 add_cc_args(g, clang_argv, out_dep_path_cstr, true, CSourceKindC);
9418 add_cc_args(g, clang_argv, out_dep_path_cstr, true, FileExtC);
94189419
94199420 clang_argv.append(buf_ptr(full_path));
94209421
......@@ -9714,8 +9715,6 @@ Error create_c_object_cache(CodeGen *g, CacheHash **out_cache_hash, bool verbose
97149715 cache_bool(cache_hash, g->have_sanitize_c);
97159716 cache_bool(cache_hash, want_valgrind_support(g));
97169717 cache_bool(cache_hash, g->function_sections);
9717 cache_bool(cache_hash, g->cpp_rtti);
9718 cache_bool(cache_hash, g->cpp_exceptions);
97199718 cache_int(cache_hash, g->code_model);
97209719
97219720 for (size_t arg_i = 0; arg_i < g->clang_argv_len; arg_i += 1) {
......@@ -9754,15 +9753,6 @@ static void gen_c_object(CodeGen *g, Buf *self_exe_path, CFile *c_file) {
97549753 Buf *c_source_basename = buf_alloc();
97559754 os_path_split(c_source_file, nullptr, c_source_basename);
97569755
9757 CSourceKind c_source_kind;
9758 if (buf_ends_with_str(c_source_basename, ".s") ||
9759 buf_ends_with_str(c_source_basename, ".S"))
9760 {
9761 c_source_kind = CSourceKindAsm;
9762 } else {
9763 c_source_kind = CSourceKindC;
9764 }
9765
97669756 Stage2ProgressNode *child_prog_node = stage2_progress_start(g->sub_progress_node, buf_ptr(c_source_basename),
97679757 buf_len(c_source_basename), 0);
97689758
......@@ -9813,7 +9803,7 @@ static void gen_c_object(CodeGen *g, Buf *self_exe_path, CFile *c_file) {
98139803 exit(1);
98149804 }
98159805 }
9816 bool is_cache_miss = (buf_len(&digest) == 0);
9806 bool is_cache_miss = g->disable_c_depfile || (buf_len(&digest) == 0);
98179807 if (is_cache_miss) {
98189808 // we can't know the digest until we do the C compiler invocation, so we
98199809 // need a tmp filename.
......@@ -9828,14 +9818,14 @@ static void gen_c_object(CodeGen *g, Buf *self_exe_path, CFile *c_file) {
98289818 args.append(buf_ptr(self_exe_path));
98299819 args.append("clang");
98309820
9831 if (c_file->preprocessor_only_basename != nullptr) {
9832 args.append("-E");
9833 } else {
9821 if (c_file->preprocessor_only_basename == nullptr) {
98349822 args.append("-c");
98359823 }
98369824
9837 Buf *out_dep_path = buf_sprintf("%s.d", buf_ptr(out_obj_path));
9838 add_cc_args(g, args, buf_ptr(out_dep_path), false, c_source_kind);
9825 Buf *out_dep_path = g->disable_c_depfile ? nullptr : buf_sprintf("%s.d", buf_ptr(out_obj_path));
9826 const char *out_dep_path_cstr = (out_dep_path == nullptr) ? nullptr : buf_ptr(out_dep_path);
9827 FileExt ext = classify_file_ext(buf_ptr(c_source_basename), buf_len(c_source_basename));
9828 add_cc_args(g, args, out_dep_path_cstr, false, ext);
98399829
98409830 args.append("-o");
98419831 args.append(buf_ptr(out_obj_path));
......@@ -9856,22 +9846,24 @@ static void gen_c_object(CodeGen *g, Buf *self_exe_path, CFile *c_file) {
98569846 exit(1);
98579847 }
98589848
9859 // add the files depended on to the cache system
9860 if ((err = cache_add_dep_file(cache_hash, out_dep_path, true))) {
9861 // Don't treat the absence of the .d file as a fatal error, the
9862 // compiler may not produce one eg. when compiling .s files
9849 if (out_dep_path != nullptr) {
9850 // add the files depended on to the cache system
9851 if ((err = cache_add_dep_file(cache_hash, out_dep_path, true))) {
9852 // Don't treat the absence of the .d file as a fatal error, the
9853 // compiler may not produce one eg. when compiling .s files
9854 if (err != ErrorFileNotFound) {
9855 fprintf(stderr, "Failed to add C source dependencies to cache: %s\n", err_str(err));
9856 exit(1);
9857 }
9858 }
98639859 if (err != ErrorFileNotFound) {
9864 fprintf(stderr, "Failed to add C source dependencies to cache: %s\n", err_str(err));
9865 exit(1);
9860 os_delete_file(out_dep_path);
98669861 }
9867 }
9868 if (err != ErrorFileNotFound) {
9869 os_delete_file(out_dep_path);
9870 }
98719862
9872 if ((err = cache_final(cache_hash, &digest))) {
9873 fprintf(stderr, "Unable to finalize cache hash: %s\n", err_str(err));
9874 exit(1);
9863 if ((err = cache_final(cache_hash, &digest))) {
9864 fprintf(stderr, "Unable to finalize cache hash: %s\n", err_str(err));
9865 exit(1);
9866 }
98759867 }
98769868 artifact_dir = buf_alloc();
98779869 os_path_join(o_dir, &digest, artifact_dir);
......@@ -10550,8 +10542,6 @@ static Error check_cache(CodeGen *g, Buf *manifest_dir, Buf *digest) {
1055010542 cache_bool(ch, g->emit_bin);
1055110543 cache_bool(ch, g->emit_llvm_ir);
1055210544 cache_bool(ch, g->emit_asm);
10553 cache_bool(ch, g->cpp_rtti);
10554 cache_bool(ch, g->cpp_exceptions);
1055510545 cache_usize(ch, g->version_major);
1055610546 cache_usize(ch, g->version_minor);
1055710547 cache_usize(ch, g->version_patch);
......@@ -10560,14 +10550,19 @@ static Error check_cache(CodeGen *g, Buf *manifest_dir, Buf *digest) {
1056010550 cache_list_of_str(ch, g->lib_dirs.items, g->lib_dirs.length);
1056110551 cache_list_of_str(ch, g->framework_dirs.items, g->framework_dirs.length);
1056210552 if (g->libc) {
10563 cache_str(ch, g->libc->include_dir);
10564 cache_str(ch, g->libc->sys_include_dir);
10565 cache_str(ch, g->libc->crt_dir);
10566 cache_str(ch, g->libc->msvc_lib_dir);
10567 cache_str(ch, g->libc->kernel32_lib_dir);
10553 cache_slice(ch, Slice<const char>{g->libc->include_dir, g->libc->include_dir_len});
10554 cache_slice(ch, Slice<const char>{g->libc->sys_include_dir, g->libc->sys_include_dir_len});
10555 cache_slice(ch, Slice<const char>{g->libc->crt_dir, g->libc->crt_dir_len});
10556 cache_slice(ch, Slice<const char>{g->libc->msvc_lib_dir, g->libc->msvc_lib_dir_len});
10557 cache_slice(ch, Slice<const char>{g->libc->kernel32_lib_dir, g->libc->kernel32_lib_dir_len});
1056810558 }
1056910559 cache_buf_opt(ch, g->version_script_path);
1057010560 cache_buf_opt(ch, g->override_soname);
10561 cache_buf_opt(ch, g->linker_optimization);
10562 cache_int(ch, g->linker_gc_sections);
10563 cache_int(ch, g->linker_allow_shlib_undefined);
10564 cache_bool(ch, g->linker_z_nodelete);
10565 cache_bool(ch, g->linker_z_defs);
1057110566
1057210567 // gen_c_objects appends objects to g->link_objects which we want to include in the hash
1057310568 gen_c_objects(g);
......@@ -10856,8 +10851,6 @@ CodeGen *create_child_codegen(CodeGen *parent_gen, Buf *root_src_path, OutType o
1085610851 parent_gen->build_mode, parent_gen->zig_lib_dir, libc, get_global_cache_dir(), false, child_progress_node);
1085710852 child_gen->root_out_name = buf_create_from_str(name);
1085810853 child_gen->disable_gen_h = true;
10859 child_gen->cpp_rtti = parent_gen->cpp_rtti;
10860 child_gen->cpp_exceptions = parent_gen->cpp_exceptions;
1086110854 child_gen->want_stack_check = WantStackCheckDisabled;
1086210855 child_gen->want_sanitize_c = WantCSanitizeDisabled;
1086310856 child_gen->verbose_tokenize = parent_gen->verbose_tokenize;
src/compiler.cpp+22
......@@ -164,3 +164,25 @@ Buf *get_global_cache_dir(void) {
164164 buf_deinit(&app_data_dir);
165165 return &saved_global_cache_dir;
166166}
167
168FileExt classify_file_ext(const char *filename_ptr, size_t filename_len) {
169 if (mem_ends_with_str(filename_ptr, filename_len, ".c")) {
170 return FileExtC;
171 } else if (mem_ends_with_str(filename_ptr, filename_len, ".C") ||
172 mem_ends_with_str(filename_ptr, filename_len, ".cc") ||
173 mem_ends_with_str(filename_ptr, filename_len, ".cpp") ||
174 mem_ends_with_str(filename_ptr, filename_len, ".cxx"))
175 {
176 return FileExtCpp;
177 } else if (mem_ends_with_str(filename_ptr, filename_len, ".ll")) {
178 return FileExtLLVMIr;
179 } else if (mem_ends_with_str(filename_ptr, filename_len, ".bc")) {
180 return FileExtLLVMBitCode;
181 } else if (mem_ends_with_str(filename_ptr, filename_len, ".s") ||
182 mem_ends_with_str(filename_ptr, filename_len, ".S"))
183 {
184 return FileExtAsm;
185 }
186 // TODO look for .so, .so.X, .so.X.Y, .so.X.Y.Z
187 return FileExtUnknown;
188}
src/compiler.hpp+4-2
......@@ -8,8 +8,7 @@
88#ifndef ZIG_COMPILER_HPP
99#define ZIG_COMPILER_HPP
1010
11#include "buffer.hpp"
12#include "error.hpp"
11#include "all_types.hpp"
1312
1413Error get_compiler_id(Buf **result);
1514
......@@ -19,4 +18,7 @@ Buf *get_zig_std_dir(Buf *zig_lib_dir);
1918
2019Buf *get_global_cache_dir(void);
2120
21
22FileExt classify_file_ext(const char *filename_ptr, size_t filename_len);
23
2224#endif
src/dump_analysis.cpp+2-2
......@@ -80,7 +80,7 @@ static void jw_array_elem(JsonWriter *jw) {
8080 zig_unreachable();
8181 case JsonWriterStateArray:
8282 fprintf(jw->f, ",");
83 // fallthrough
83 ZIG_FALLTHROUGH;
8484 case JsonWriterStateArrayStart:
8585 jw->state[jw->state_index] = JsonWriterStateArray;
8686 jw_push_state(jw, JsonWriterStateValue);
......@@ -134,7 +134,7 @@ static void jw_object_field(JsonWriter *jw, const char *name) {
134134 zig_unreachable();
135135 case JsonWriterStateObject:
136136 fprintf(jw->f, ",");
137 // fallthrough
137 ZIG_FALLTHROUGH;
138138 case JsonWriterStateObjectStart:
139139 jw->state[jw->state_index] = JsonWriterStateObject;
140140 jw_push_state(jw, JsonWriterStateValue);
src/ir.cpp+73-32
......@@ -231,6 +231,7 @@ static ZigType *ir_resolve_atomic_operand_type(IrAnalyze *ira, IrInstGen *op);
231231static IrInstSrc *ir_lval_wrap(IrBuilderSrc *irb, Scope *scope, IrInstSrc *value, LVal lval, ResultLoc *result_loc);
232232static IrInstSrc *ir_expr_wrap(IrBuilderSrc *irb, Scope *scope, IrInstSrc *inst, ResultLoc *result_loc);
233233static ZigType *adjust_ptr_align(CodeGen *g, ZigType *ptr_type, uint32_t new_align);
234static ZigType *adjust_ptr_const(CodeGen *g, ZigType *ptr_type, bool is_const);
234235static ZigType *adjust_slice_align(CodeGen *g, ZigType *slice_type, uint32_t new_align);
235236static Error buf_read_value_bytes(IrAnalyze *ira, CodeGen *codegen, AstNode *source_node, uint8_t *buf, ZigValue *val);
236237static void buf_write_value_bytes(CodeGen *codegen, uint8_t *buf, ZigValue *val);
......@@ -11453,10 +11454,8 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted
1145311454 bool actual_allows_zero = ptr_allows_addr_zero(actual_type);
1145411455 bool wanted_is_c_ptr = wanted_type->id == ZigTypeIdPointer && wanted_type->data.pointer.ptr_len == PtrLenC;
1145511456 bool actual_is_c_ptr = actual_type->id == ZigTypeIdPointer && actual_type->data.pointer.ptr_len == PtrLenC;
11456 bool wanted_opt_or_ptr = wanted_ptr_type != nullptr &&
11457 (wanted_type->id == ZigTypeIdPointer || wanted_type->id == ZigTypeIdOptional);
11458 bool actual_opt_or_ptr = actual_ptr_type != nullptr &&
11459 (actual_type->id == ZigTypeIdPointer || actual_type->id == ZigTypeIdOptional);
11457 bool wanted_opt_or_ptr = wanted_ptr_type != nullptr && wanted_ptr_type->id == ZigTypeIdPointer;
11458 bool actual_opt_or_ptr = actual_ptr_type != nullptr && actual_ptr_type->id == ZigTypeIdPointer;
1146011459 if (wanted_opt_or_ptr && actual_opt_or_ptr) {
1146111460 bool ok_null_term_ptrs =
1146211461 wanted_ptr_type->data.pointer.sentinel == nullptr ||
......@@ -11844,6 +11843,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
1184411843
1184511844 bool any_are_null = (prev_inst->value->type->id == ZigTypeIdNull);
1184611845 bool convert_to_const_slice = false;
11846 bool make_the_slice_const = false;
1184711847 for (; i < instruction_count; i += 1) {
1184811848 IrInstGen *cur_inst = instructions[i];
1184911849 ZigType *cur_type = cur_inst->value->type;
......@@ -12357,12 +12357,12 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
1235712357 ZigType *slice_type = (prev_type->id == ZigTypeIdErrorUnion) ?
1235812358 prev_type->data.error_union.payload_type : prev_type;
1235912359 ZigType *slice_ptr_type = slice_type->data.structure.fields[slice_ptr_index]->type_entry;
12360 if ((slice_ptr_type->data.pointer.is_const || array_type->data.array.len == 0 ||
12361 !cur_type->data.pointer.is_const) &&
12362 types_match_const_cast_only(ira,
12363 slice_ptr_type->data.pointer.child_type,
12360 if (types_match_const_cast_only(ira, slice_ptr_type->data.pointer.child_type,
1236412361 array_type->data.array.child_type, source_node, false).id == ConstCastResultIdOk)
1236512362 {
12363 bool const_ok = (slice_ptr_type->data.pointer.is_const || array_type->data.array.len == 0 ||
12364 !cur_type->data.pointer.is_const);
12365 if (!const_ok) make_the_slice_const = true;
1236612366 convert_to_const_slice = false;
1236712367 continue;
1236812368 }
......@@ -12391,12 +12391,12 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
1239112391 break;
1239212392 }
1239312393 ZigType *slice_ptr_type = slice_type->data.structure.fields[slice_ptr_index]->type_entry;
12394 if ((slice_ptr_type->data.pointer.is_const || array_type->data.array.len == 0 ||
12395 !prev_type->data.pointer.is_const) &&
12396 types_match_const_cast_only(ira,
12397 slice_ptr_type->data.pointer.child_type,
12394 if (types_match_const_cast_only(ira, slice_ptr_type->data.pointer.child_type,
1239812395 array_type->data.array.child_type, source_node, false).id == ConstCastResultIdOk)
1239912396 {
12397 bool const_ok = (slice_ptr_type->data.pointer.is_const || array_type->data.array.len == 0 ||
12398 !prev_type->data.pointer.is_const);
12399 if (!const_ok) make_the_slice_const = true;
1240012400 prev_inst = cur_inst;
1240112401 convert_to_const_slice = false;
1240212402 continue;
......@@ -12408,8 +12408,6 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
1240812408 cur_type->data.pointer.child_type->id == ZigTypeIdArray &&
1240912409 prev_type->id == ZigTypeIdPointer && prev_type->data.pointer.ptr_len == PtrLenSingle &&
1241012410 prev_type->data.pointer.child_type->id == ZigTypeIdArray &&
12411 (cur_type->data.pointer.is_const || !prev_type->data.pointer.is_const ||
12412 prev_type->data.pointer.child_type->data.array.len == 0) &&
1241312411 (
1241412412 prev_type->data.pointer.child_type->data.array.sentinel == nullptr ||
1241512413 (cur_type->data.pointer.child_type->data.array.sentinel != nullptr &&
......@@ -12421,6 +12419,9 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
1242112419 prev_type->data.pointer.child_type->data.array.child_type,
1242212420 source_node, !cur_type->data.pointer.is_const).id == ConstCastResultIdOk)
1242312421 {
12422 bool const_ok = (cur_type->data.pointer.is_const || !prev_type->data.pointer.is_const ||
12423 prev_type->data.pointer.child_type->data.array.len == 0);
12424 if (!const_ok) make_the_slice_const = true;
1242412425 prev_inst = cur_inst;
1242512426 convert_to_const_slice = true;
1242612427 continue;
......@@ -12429,8 +12430,6 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
1242912430 prev_type->data.pointer.child_type->id == ZigTypeIdArray &&
1243012431 cur_type->id == ZigTypeIdPointer && cur_type->data.pointer.ptr_len == PtrLenSingle &&
1243112432 cur_type->data.pointer.child_type->id == ZigTypeIdArray &&
12432 (prev_type->data.pointer.is_const || !cur_type->data.pointer.is_const ||
12433 cur_type->data.pointer.child_type->data.array.len == 0) &&
1243412433 (
1243512434 cur_type->data.pointer.child_type->data.array.sentinel == nullptr ||
1243612435 (prev_type->data.pointer.child_type->data.array.sentinel != nullptr &&
......@@ -12442,6 +12441,9 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
1244212441 cur_type->data.pointer.child_type->data.array.child_type,
1244312442 source_node, !prev_type->data.pointer.is_const).id == ConstCastResultIdOk)
1244412443 {
12444 bool const_ok = (prev_type->data.pointer.is_const || !cur_type->data.pointer.is_const ||
12445 cur_type->data.pointer.child_type->data.array.len == 0);
12446 if (!const_ok) make_the_slice_const = true;
1244512447 convert_to_const_slice = true;
1244612448 continue;
1244712449 }
......@@ -12486,7 +12488,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
1248612488 src_assert(array_type->id == ZigTypeIdArray, source_node);
1248712489 ZigType *ptr_type = get_pointer_to_type_extra2(
1248812490 ira->codegen, array_type->data.array.child_type,
12489 prev_inst->value->type->data.pointer.is_const, false,
12491 prev_inst->value->type->data.pointer.is_const || make_the_slice_const, false,
1249012492 PtrLenUnknown,
1249112493 0, 0, 0, false,
1249212494 VECTOR_INDEX_NONE, nullptr, array_type->data.array.sentinel);
......@@ -12537,6 +12539,26 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
1253712539 return ira->codegen->builtin_types.entry_invalid;
1253812540 return get_optional_type(ira->codegen, prev_inst->value->type);
1253912541 }
12542 } else if (make_the_slice_const) {
12543 ZigType *slice_type;
12544 if (prev_inst->value->type->id == ZigTypeIdErrorUnion) {
12545 slice_type = prev_inst->value->type->data.error_union.payload_type;
12546 } else if (is_slice(prev_inst->value->type)) {
12547 slice_type = prev_inst->value->type;
12548 } else {
12549 zig_unreachable();
12550 }
12551 ZigType *slice_ptr_type = slice_type->data.structure.fields[slice_ptr_index]->type_entry;
12552 ZigType *adjusted_ptr_type = adjust_ptr_const(ira->codegen, slice_ptr_type, make_the_slice_const);
12553 ZigType *adjusted_slice_type = get_slice_type(ira->codegen, adjusted_ptr_type);
12554 if (prev_inst->value->type->id == ZigTypeIdErrorUnion) {
12555 return get_error_union_type(ira->codegen, prev_inst->value->type->data.error_union.err_set_type,
12556 adjusted_slice_type);
12557 } else if (is_slice(prev_inst->value->type)) {
12558 return adjusted_slice_type;
12559 } else {
12560 zig_unreachable();
12561 }
1254012562 } else {
1254112563 return prev_inst->value->type;
1254212564 }
......@@ -15929,7 +15951,7 @@ static IrInstGen *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInst *source_i
1592915951 if (op1->value->type->id == ZigTypeIdVector && op2->value->type->id == ZigTypeIdVector) {
1593015952 if (op1->value->type->data.vector.len != op2->value->type->data.vector.len) {
1593115953 ir_add_error(ira, source_instr,
15932 buf_sprintf("vector length mismatch: %" PRIu32 " and %" PRIu32,
15954 buf_sprintf("vector length mismatch: %" PRIu64 " and %" PRIu64,
1593315955 op1->value->type->data.vector.len, op2->value->type->data.vector.len));
1593415956 return ira->codegen->invalid_inst_gen;
1593515957 }
......@@ -18958,7 +18980,7 @@ static IrInstGen *ir_analyze_async_call(IrAnalyze *ira, IrInst* source_instr, Zi
1895818980 if (type_is_invalid(result_loc->value->type) || result_loc->value->type->id == ZigTypeIdUnreachable) {
1895918981 return result_loc;
1896018982 }
18961 result_loc = ir_implicit_cast2(ira, &call_result_loc->source_instruction->base, result_loc,
18983 result_loc = ir_implicit_cast2(ira, source_instr, result_loc,
1896218984 get_pointer_to_type(ira->codegen, frame_type, false));
1896318985 if (type_is_invalid(result_loc->value->type))
1896418986 return ira->codegen->invalid_inst_gen;
......@@ -19925,6 +19947,7 @@ static IrInstGen *ir_analyze_call_extra(IrAnalyze *ira, IrInst* source_instr,
1992519947 buf_sprintf("the specified modifier requires a comptime-known function"));
1992619948 return ira->codegen->invalid_inst_gen;
1992719949 }
19950 ZIG_FALLTHROUGH;
1992819951 default:
1992919952 break;
1993019953 }
......@@ -19943,14 +19966,16 @@ static IrInstGen *ir_analyze_call_extra(IrAnalyze *ira, IrInst* source_instr,
1994319966 return ira->codegen->invalid_inst_gen;
1994419967
1994519968 IrInstGen *stack = nullptr;
19969 IrInst *stack_src = nullptr;
1994619970 if (stack_is_non_null) {
1994719971 stack = ir_analyze_optional_value_payload_value(ira, source_instr, opt_stack, false);
1994819972 if (type_is_invalid(stack->value->type))
1994919973 return ira->codegen->invalid_inst_gen;
19974 stack_src = &stack->base;
1995019975 }
1995119976
1995219977 return ir_analyze_fn_call(ira, source_instr, fn, fn_type, fn_ref, first_arg_ptr, first_arg_ptr_src,
19953 modifier, stack, &stack->base, false, args_ptr, args_len, nullptr, result_loc);
19978 modifier, stack, stack_src, false, args_ptr, args_len, nullptr, result_loc);
1995419979}
1995519980
1995619981static IrInstGen *ir_analyze_instruction_call_extra(IrAnalyze *ira, IrInstSrcCallExtra *instruction) {
......@@ -20708,24 +20733,44 @@ static ZigType *adjust_slice_align(CodeGen *g, ZigType *slice_type, uint32_t new
2070820733
2070920734static ZigType *adjust_ptr_len(CodeGen *g, ZigType *ptr_type, PtrLen ptr_len) {
2071020735 assert(ptr_type->id == ZigTypeIdPointer);
20711 return get_pointer_to_type_extra(g,
20736 return get_pointer_to_type_extra2(g,
2071220737 ptr_type->data.pointer.child_type,
2071320738 ptr_type->data.pointer.is_const, ptr_type->data.pointer.is_volatile,
2071420739 ptr_len,
2071520740 ptr_type->data.pointer.explicit_alignment,
2071620741 ptr_type->data.pointer.bit_offset_in_host, ptr_type->data.pointer.host_int_bytes,
20717 ptr_type->data.pointer.allow_zero);
20742 ptr_type->data.pointer.allow_zero,
20743 ptr_type->data.pointer.vector_index,
20744 ptr_type->data.pointer.inferred_struct_field,
20745 ptr_type->data.pointer.sentinel);
2071820746}
2071920747
2072020748static ZigType *adjust_ptr_allow_zero(CodeGen *g, ZigType *ptr_type, bool allow_zero) {
2072120749 assert(ptr_type->id == ZigTypeIdPointer);
20722 return get_pointer_to_type_extra(g,
20750 return get_pointer_to_type_extra2(g,
2072320751 ptr_type->data.pointer.child_type,
2072420752 ptr_type->data.pointer.is_const, ptr_type->data.pointer.is_volatile,
2072520753 ptr_type->data.pointer.ptr_len,
2072620754 ptr_type->data.pointer.explicit_alignment,
2072720755 ptr_type->data.pointer.bit_offset_in_host, ptr_type->data.pointer.host_int_bytes,
20728 allow_zero);
20756 allow_zero,
20757 ptr_type->data.pointer.vector_index,
20758 ptr_type->data.pointer.inferred_struct_field,
20759 ptr_type->data.pointer.sentinel);
20760}
20761
20762static ZigType *adjust_ptr_const(CodeGen *g, ZigType *ptr_type, bool is_const) {
20763 assert(ptr_type->id == ZigTypeIdPointer);
20764 return get_pointer_to_type_extra2(g,
20765 ptr_type->data.pointer.child_type,
20766 is_const, ptr_type->data.pointer.is_volatile,
20767 ptr_type->data.pointer.ptr_len,
20768 ptr_type->data.pointer.explicit_alignment,
20769 ptr_type->data.pointer.bit_offset_in_host, ptr_type->data.pointer.host_int_bytes,
20770 ptr_type->data.pointer.allow_zero,
20771 ptr_type->data.pointer.vector_index,
20772 ptr_type->data.pointer.inferred_struct_field,
20773 ptr_type->data.pointer.sentinel);
2072920774}
2073020775
2073120776static Error compute_elem_align(IrAnalyze *ira, ZigType *elem_type, uint32_t base_ptr_align,
......@@ -20880,13 +20925,8 @@ static IrInstGen *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstSrcElemP
2088020925 if (instr_is_comptime(casted_elem_index)) {
2088120926 uint64_t index = bigint_as_u64(&casted_elem_index->value->data.x_bigint);
2088220927 if (array_type->id == ZigTypeIdArray) {
20883 uint64_t array_len = array_type->data.array.len;
20884 if (index == array_len && array_type->data.array.sentinel != nullptr) {
20885 ZigType *elem_type = array_type->data.array.child_type;
20886 IrInstGen *sentinel_elem = ir_const(ira, &elem_ptr_instruction->base.base, elem_type);
20887 copy_const_val(ira->codegen, sentinel_elem->value, array_type->data.array.sentinel);
20888 return ir_get_ref(ira, &elem_ptr_instruction->base.base, sentinel_elem, true, false);
20889 }
20928 uint64_t array_len = array_type->data.array.len +
20929 (array_type->data.array.sentinel != nullptr);
2089020930 if (index >= array_len) {
2089120931 ir_add_error_node(ira, elem_ptr_instruction->base.base.source_node,
2089220932 buf_sprintf("index %" ZIG_PRI_u64 " outside array of size %" ZIG_PRI_u64,
......@@ -25131,7 +25171,7 @@ static IrInstGen *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstSrcCImpo
2513125171
2513225172 ZigList<const char *> clang_argv = {0};
2513325173
25134 add_cc_args(ira->codegen, clang_argv, buf_ptr(tmp_dep_file), true, CSourceKindC);
25174 add_cc_args(ira->codegen, clang_argv, buf_ptr(tmp_dep_file), true, FileExtC);
2513525175
2513625176 clang_argv.append(buf_ptr(&tmp_c_file_path));
2513725177
......@@ -28128,6 +28168,7 @@ static void buf_write_value_bytes(CodeGen *codegen, uint8_t *buf, ZigValue *val)
2812828168 return;
2812928169 }
2813028170 }
28171 zig_unreachable();
2813128172 case ZigTypeIdOptional:
2813228173 zig_panic("TODO buf_write_value_bytes maybe type");
2813328174 case ZigTypeIdFn:
src/link.cpp+103-22
......@@ -651,6 +651,7 @@ static const char *build_libunwind(CodeGen *parent, Stage2ProgressNode *progress
651651 if (parent->is_single_threaded) {
652652 c_file->args.append("-D_LIBUNWIND_HAS_NO_THREADS");
653653 }
654 c_file->args.append("-Wno-bitwise-conditional-parentheses");
654655 c_source_files.append(c_file);
655656 }
656657 child_gen->c_source_files = c_source_files;
......@@ -1594,7 +1595,8 @@ static const char *get_libc_crt_file(CodeGen *parent, const char *file, Stage2Pr
15941595 } else {
15951596 assert(parent->libc != nullptr);
15961597 Buf *out_buf = buf_alloc();
1597 os_path_join(buf_create_from_str(parent->libc->crt_dir), buf_create_from_str(file), out_buf);
1598 os_path_join(buf_create_from_mem(parent->libc->crt_dir, parent->libc->crt_dir_len),
1599 buf_create_from_str(file), out_buf);
15981600 return buf_ptr(out_buf);
15991601 }
16001602}
......@@ -1767,8 +1769,17 @@ static void construct_linker_job_elf(LinkJob *lj) {
17671769 lj->args.append(g->linker_script);
17681770 }
17691771
1770 if (g->out_type != OutTypeObj) {
1771 lj->args.append("--gc-sections");
1772 switch (g->linker_gc_sections) {
1773 case OptionalBoolNull:
1774 if (g->out_type != OutTypeObj) {
1775 lj->args.append("--gc-sections");
1776 }
1777 break;
1778 case OptionalBoolTrue:
1779 lj->args.append("--gc-sections");
1780 break;
1781 case OptionalBoolFalse:
1782 break;
17721783 }
17731784
17741785 if (g->link_eh_frame_hdr) {
......@@ -1779,6 +1790,19 @@ static void construct_linker_job_elf(LinkJob *lj) {
17791790 lj->args.append("--export-dynamic");
17801791 }
17811792
1793 if (g->linker_optimization != nullptr) {
1794 lj->args.append(buf_ptr(g->linker_optimization));
1795 }
1796
1797 if (g->linker_z_nodelete) {
1798 lj->args.append("-z");
1799 lj->args.append("nodelete");
1800 }
1801 if (g->linker_z_defs) {
1802 lj->args.append("-z");
1803 lj->args.append("defs");
1804 }
1805
17821806 lj->args.append("-m");
17831807 lj->args.append(getLDMOption(g->zig_target));
17841808
......@@ -1859,7 +1883,7 @@ static void construct_linker_job_elf(LinkJob *lj) {
18591883 if (g->libc_link_lib != nullptr) {
18601884 if (g->libc != nullptr) {
18611885 lj->args.append("-L");
1862 lj->args.append(g->libc->crt_dir);
1886 lj->args.append(buf_ptr(buf_create_from_mem(g->libc->crt_dir, g->libc->crt_dir_len)));
18631887 }
18641888
18651889 if (g->have_dynamic_link && (is_dyn_lib || g->out_type == OutTypeExe)) {
......@@ -1903,7 +1927,7 @@ static void construct_linker_job_elf(LinkJob *lj) {
19031927 // libc is linked specially
19041928 continue;
19051929 }
1906 if (buf_eql_str(link_lib->name, "c++") || buf_eql_str(link_lib->name, "c++abi")) {
1930 if (target_is_libcpp_lib_name(g->zig_target, buf_ptr(link_lib->name))) {
19071931 // libc++ is linked specially
19081932 continue;
19091933 }
......@@ -1947,15 +1971,11 @@ static void construct_linker_job_elf(LinkJob *lj) {
19471971 lj->args.append("-lpthread");
19481972 }
19491973 } else if (target_is_glibc(g->zig_target)) {
1950 if (target_supports_libunwind(g->zig_target)) {
1951 lj->args.append(build_libunwind(g, lj->build_dep_prog_node));
1952 }
1974 lj->args.append(build_libunwind(g, lj->build_dep_prog_node));
19531975 add_glibc_libs(lj);
19541976 lj->args.append(get_libc_crt_file(g, "libc_nonshared.a", lj->build_dep_prog_node));
19551977 } else if (target_is_musl(g->zig_target)) {
1956 if (target_supports_libunwind(g->zig_target)) {
1957 lj->args.append(build_libunwind(g, lj->build_dep_prog_node));
1958 }
1978 lj->args.append(build_libunwind(g, lj->build_dep_prog_node));
19591979 lj->args.append(build_musl(g, lj->build_dep_prog_node));
19601980 } else if (g->libcpp_link_lib != nullptr) {
19611981 lj->args.append(build_libunwind(g, lj->build_dep_prog_node));
......@@ -1973,8 +1993,17 @@ static void construct_linker_job_elf(LinkJob *lj) {
19731993 }
19741994 }
19751995
1976 if (!g->zig_target->is_native_os) {
1977 lj->args.append("--allow-shlib-undefined");
1996 switch (g->linker_allow_shlib_undefined) {
1997 case OptionalBoolNull:
1998 if (!g->zig_target->is_native_os) {
1999 lj->args.append("--allow-shlib-undefined");
2000 }
2001 break;
2002 case OptionalBoolFalse:
2003 break;
2004 case OptionalBoolTrue:
2005 lj->args.append("--allow-shlib-undefined");
2006 break;
19782007 }
19792008}
19802009
......@@ -2384,14 +2413,26 @@ static void construct_linker_job_coff(LinkJob *lj) {
23842413 lj->args.append(buf_ptr(buf_sprintf("-OUT:%s", buf_ptr(&g->bin_file_output_path))));
23852414
23862415 if (g->libc_link_lib != nullptr && g->libc != nullptr) {
2387 lj->args.append(buf_ptr(buf_sprintf("-LIBPATH:%s", g->libc->crt_dir)));
2416 Buf *buff0 = buf_create_from_str("-LIBPATH:");
2417 buf_append_mem(buff0, g->libc->crt_dir, g->libc->crt_dir_len);
2418 lj->args.append(buf_ptr(buff0));
23882419
23892420 if (target_abi_is_gnu(g->zig_target->abi)) {
2390 lj->args.append(buf_ptr(buf_sprintf("-LIBPATH:%s", g->libc->sys_include_dir)));
2391 lj->args.append(buf_ptr(buf_sprintf("-LIBPATH:%s", g->libc->include_dir)));
2421 Buf *buff1 = buf_create_from_str("-LIBPATH:");
2422 buf_append_mem(buff1, g->libc->sys_include_dir, g->libc->sys_include_dir_len);
2423 lj->args.append(buf_ptr(buff1));
2424
2425 Buf *buff2 = buf_create_from_str("-LIBPATH:");
2426 buf_append_mem(buff2, g->libc->include_dir, g->libc->include_dir_len);
2427 lj->args.append(buf_ptr(buff2));
23922428 } else {
2393 lj->args.append(buf_ptr(buf_sprintf("-LIBPATH:%s", g->libc->msvc_lib_dir)));
2394 lj->args.append(buf_ptr(buf_sprintf("-LIBPATH:%s", g->libc->kernel32_lib_dir)));
2429 Buf *buff1 = buf_create_from_str("-LIBPATH:");
2430 buf_append_mem(buff1, g->libc->msvc_lib_dir, g->libc->msvc_lib_dir_len);
2431 lj->args.append(buf_ptr(buff1));
2432
2433 Buf *buff2 = buf_create_from_str("-LIBPATH:");
2434 buf_append_mem(buff2, g->libc->kernel32_lib_dir, g->libc->kernel32_lib_dir_len);
2435 lj->args.append(buf_ptr(buff2));
23952436 }
23962437 }
23972438
......@@ -2470,7 +2511,12 @@ static void construct_linker_job_coff(LinkJob *lj) {
24702511 if (buf_eql_str(link_lib->name, "c")) {
24712512 continue;
24722513 }
2473 if (buf_eql_str(link_lib->name, "c++") || buf_eql_str(link_lib->name, "c++abi")) {
2514 if (target_is_libcpp_lib_name(g->zig_target, buf_ptr(link_lib->name))) {
2515 // libc++ is linked specially
2516 continue;
2517 }
2518 if (g->libc == nullptr && target_is_libc_lib_name(g->zig_target, buf_ptr(link_lib->name))) {
2519 // these libraries are always linked below when targeting glibc
24742520 continue;
24752521 }
24762522 bool is_sys_lib = is_mingw_link_lib(link_lib->name);
......@@ -2521,10 +2567,34 @@ static void construct_linker_job_macho(LinkJob *lj) {
25212567 //lj->args.append("-error-limit=0");
25222568 lj->args.append("-demangle");
25232569
2570 switch (g->linker_gc_sections) {
2571 case OptionalBoolNull:
2572 // TODO why do we not follow the same logic of elf here?
2573 break;
2574 case OptionalBoolTrue:
2575 lj->args.append("--gc-sections");
2576 break;
2577 case OptionalBoolFalse:
2578 break;
2579 }
2580
25242581 if (g->linker_rdynamic) {
25252582 lj->args.append("-export_dynamic");
25262583 }
25272584
2585 if (g->linker_optimization != nullptr) {
2586 lj->args.append(buf_ptr(g->linker_optimization));
2587 }
2588
2589 if (g->linker_z_nodelete) {
2590 lj->args.append("-z");
2591 lj->args.append("nodelete");
2592 }
2593 if (g->linker_z_defs) {
2594 lj->args.append("-z");
2595 lj->args.append("defs");
2596 }
2597
25282598 bool is_lib = g->out_type == OutTypeLib;
25292599 bool is_dyn_lib = g->is_dynamic && is_lib;
25302600 if (is_lib && !g->is_dynamic) {
......@@ -2639,9 +2709,20 @@ static void construct_linker_job_macho(LinkJob *lj) {
26392709 // and change between versions.
26402710 // so we always link against libSystem
26412711 lj->args.append("-lSystem");
2642 } else {
2643 lj->args.append("-undefined");
2644 lj->args.append("dynamic_lookup");
2712 }
2713 switch (g->linker_allow_shlib_undefined) {
2714 case OptionalBoolNull:
2715 if (!g->zig_target->is_native_os) {
2716 lj->args.append("-undefined");
2717 lj->args.append("dynamic_lookup");
2718 }
2719 break;
2720 case OptionalBoolFalse:
2721 break;
2722 case OptionalBoolTrue:
2723 lj->args.append("-undefined");
2724 lj->args.append("dynamic_lookup");
2725 break;
26452726 }
26462727
26472728 for (size_t i = 0; i < g->framework_dirs.length; i += 1) {
src/main.cpp+97-43
......@@ -455,11 +455,15 @@ static int main0(int argc, char **argv) {
455455 const char *mcpu = nullptr;
456456 CodeModel code_model = CodeModelDefault;
457457 const char *override_soname = nullptr;
458 bool only_preprocess = false;
458 bool only_pp_or_asm = false;
459459 bool ensure_libc_on_non_freestanding = false;
460460 bool ensure_libcpp_on_non_freestanding = false;
461 bool cpp_rtti = true;
462 bool cpp_exceptions = true;
461 bool disable_c_depfile = false;
462 Buf *linker_optimization = nullptr;
463 OptionalBool linker_gc_sections = OptionalBoolNull;
464 OptionalBool linker_allow_shlib_undefined = OptionalBoolNull;
465 bool linker_z_nodelete = false;
466 bool linker_z_defs = false;
463467
464468 ZigList<const char *> llvm_argv = {0};
465469 llvm_argv.append("zig (LLVM option parsing)");
......@@ -617,20 +621,22 @@ static int main0(int argc, char **argv) {
617621 }
618622 break;
619623 case Stage2ClangArgPositional: {
620 Buf *arg_buf = buf_create_from_str(it.only_arg);
621 if (buf_ends_with_str(arg_buf, ".c") ||
622 buf_ends_with_str(arg_buf, ".C") ||
623 buf_ends_with_str(arg_buf, ".cc") ||
624 buf_ends_with_str(arg_buf, ".cpp") ||
625 buf_ends_with_str(arg_buf, ".cxx") ||
626 buf_ends_with_str(arg_buf, ".s") ||
627 buf_ends_with_str(arg_buf, ".S"))
628 {
629 CFile *c_file = heap::c_allocator.create<CFile>();
630 c_file->source_path = it.only_arg;
631 c_source_files.append(c_file);
632 } else {
633 objects.append(it.only_arg);
624 FileExt file_ext = classify_file_ext(it.only_arg, strlen(it.only_arg));
625 switch (file_ext) {
626 case FileExtAsm:
627 case FileExtC:
628 case FileExtCpp:
629 case FileExtLLVMIr:
630 case FileExtLLVMBitCode:
631 case FileExtHeader: {
632 CFile *c_file = heap::c_allocator.create<CFile>();
633 c_file->source_path = it.only_arg;
634 c_source_files.append(c_file);
635 break;
636 }
637 case FileExtUnknown:
638 objects.append(it.only_arg);
639 break;
634640 }
635641 break;
636642 }
......@@ -676,8 +682,12 @@ static int main0(int argc, char **argv) {
676682 }
677683 break;
678684 }
679 case Stage2ClangArgPreprocess:
680 only_preprocess = true;
685 case Stage2ClangArgPreprocessOrAsm:
686 // this handles both -E and -S
687 only_pp_or_asm = true;
688 for (size_t i = 0; i < it.other_args_len; i += 1) {
689 clang_argv.append(it.other_args_ptr[i]);
690 }
681691 break;
682692 case Stage2ClangArgOptimize:
683693 // alright what release mode do they want?
......@@ -688,7 +698,9 @@ static int main0(int argc, char **argv) {
688698 strcmp(it.only_arg, "O4") == 0)
689699 {
690700 build_mode = BuildModeFastRelease;
691 } else if (strcmp(it.only_arg, "Og") == 0) {
701 } else if (strcmp(it.only_arg, "Og") == 0 ||
702 strcmp(it.only_arg, "O0") == 0)
703 {
692704 build_mode = BuildModeDebug;
693705 } else {
694706 for (size_t i = 0; i < it.other_args_len; i += 1) {
......@@ -722,18 +734,6 @@ static int main0(int argc, char **argv) {
722734 verbose_cc = true;
723735 verbose_link = true;
724736 break;
725 case Stage2ClangArgExceptions:
726 cpp_exceptions = true;
727 break;
728 case Stage2ClangArgNoExceptions:
729 cpp_exceptions = false;
730 break;
731 case Stage2ClangArgRtti:
732 cpp_rtti = true;
733 break;
734 case Stage2ClangArgNoRtti:
735 cpp_rtti = false;
736 break;
737737 case Stage2ClangArgForLinker:
738738 linker_args.append(buf_create_from_str(it.only_arg));
739739 break;
......@@ -741,6 +741,24 @@ static int main0(int argc, char **argv) {
741741 linker_args.append(buf_create_from_str("-z"));
742742 linker_args.append(buf_create_from_str(it.only_arg));
743743 break;
744 case Stage2ClangArgLibDir:
745 lib_dirs.append(it.only_arg);
746 break;
747 case Stage2ClangArgMCpu:
748 mcpu = it.only_arg;
749 break;
750 case Stage2ClangArgDepFile:
751 disable_c_depfile = true;
752 for (size_t i = 0; i < it.other_args_len; i += 1) {
753 clang_argv.append(it.other_args_ptr[i]);
754 }
755 break;
756 case Stage2ClangArgFrameworkDir:
757 framework_dirs.append(it.only_arg);
758 break;
759 case Stage2ClangArgFramework:
760 frameworks.append(it.only_arg);
761 break;
744762 }
745763 }
746764 // Parse linker args
......@@ -802,6 +820,37 @@ static int main0(int argc, char **argv) {
802820 buf_eql_str(arg, "-export-dynamic"))
803821 {
804822 rdynamic = true;
823 } else if (buf_eql_str(arg, "--version-script")) {
824 i += 1;
825 if (i >= linker_args.length) {
826 fprintf(stderr, "expected linker arg after '%s'\n", buf_ptr(arg));
827 return EXIT_FAILURE;
828 }
829 version_script = linker_args.at(i);
830 } else if (buf_starts_with_str(arg, "-O")) {
831 linker_optimization = arg;
832 } else if (buf_eql_str(arg, "--gc-sections")) {
833 linker_gc_sections = OptionalBoolTrue;
834 } else if (buf_eql_str(arg, "--no-gc-sections")) {
835 linker_gc_sections = OptionalBoolFalse;
836 } else if (buf_eql_str(arg, "--allow-shlib-undefined")) {
837 linker_allow_shlib_undefined = OptionalBoolTrue;
838 } else if (buf_eql_str(arg, "--no-allow-shlib-undefined")) {
839 linker_allow_shlib_undefined = OptionalBoolFalse;
840 } else if (buf_eql_str(arg, "-z")) {
841 i += 1;
842 if (i >= linker_args.length) {
843 fprintf(stderr, "expected linker arg after '%s'\n", buf_ptr(arg));
844 return EXIT_FAILURE;
845 }
846 Buf *z_arg = linker_args.at(i);
847 if (buf_eql_str(z_arg, "nodelete")) {
848 linker_z_nodelete = true;
849 } else if (buf_eql_str(z_arg, "defs")) {
850 linker_z_defs = true;
851 } else {
852 fprintf(stderr, "warning: unsupported linker arg: -z %s\n", buf_ptr(z_arg));
853 }
805854 } else {
806855 fprintf(stderr, "warning: unsupported linker arg: %s\n", buf_ptr(arg));
807856 }
......@@ -811,7 +860,7 @@ static int main0(int argc, char **argv) {
811860 build_mode = BuildModeSafeRelease;
812861 }
813862
814 if (only_preprocess) {
863 if (only_pp_or_asm) {
815864 cmd = CmdBuild;
816865 out_type = OutTypeObj;
817866 emit_bin = false;
......@@ -1329,8 +1378,6 @@ static int main0(int argc, char **argv) {
13291378 LinkLib *link_lib = codegen_add_link_lib(g, buf_create_from_str(link_libs.at(i)));
13301379 link_lib->provided_explicitly = true;
13311380 }
1332 g->cpp_rtti = cpp_rtti;
1333 g->cpp_exceptions = cpp_exceptions;
13341381 g->subsystem = subsystem;
13351382 g->valgrind_support = valgrind_support;
13361383 g->want_pic = want_pic;
......@@ -1369,15 +1416,17 @@ static int main0(int argc, char **argv) {
13691416 return print_error_usage(arg0);
13701417 }
13711418
1372 bool any_non_c_link_libs = false;
1419 bool any_system_lib_dependencies = false;
13731420 for (size_t i = 0; i < link_libs.length; i += 1) {
1374 if (!target_is_libc_lib_name(&target, link_libs.at(i))) {
1375 any_non_c_link_libs = true;
1421 if (!target_is_libc_lib_name(&target, link_libs.at(i)) &&
1422 !target_is_libcpp_lib_name(&target, link_libs.at(i)))
1423 {
1424 any_system_lib_dependencies = true;
13761425 break;
13771426 }
13781427 }
13791428
1380 if (target.is_native_os && any_non_c_link_libs) {
1429 if (target.is_native_os && any_system_lib_dependencies) {
13811430 Error err;
13821431 Stage2NativePaths paths;
13831432 if ((err = stage2_detect_native_paths(&paths))) {
......@@ -1477,8 +1526,6 @@ static int main0(int argc, char **argv) {
14771526 }
14781527 CodeGen *g = codegen_create(main_pkg_path, zig_root_source_file, &target, out_type, build_mode,
14791528 override_lib_dir, libc, cache_dir_buf, cmd == CmdTest, root_progress_node);
1480 g->cpp_rtti = cpp_rtti;
1481 g->cpp_exceptions = cpp_exceptions;
14821529 if (llvm_argv.length >= 2) codegen_set_llvm_argv(g, llvm_argv.items + 1, llvm_argv.length - 2);
14831530 g->valgrind_support = valgrind_support;
14841531 g->link_eh_frame_hdr = link_eh_frame_hdr;
......@@ -1522,6 +1569,13 @@ static int main0(int argc, char **argv) {
15221569 g->system_linker_hack = system_linker_hack;
15231570 g->function_sections = function_sections;
15241571 g->code_model = code_model;
1572 g->disable_c_depfile = disable_c_depfile;
1573
1574 g->linker_optimization = linker_optimization;
1575 g->linker_gc_sections = linker_gc_sections;
1576 g->linker_allow_shlib_undefined = linker_allow_shlib_undefined;
1577 g->linker_z_nodelete = linker_z_nodelete;
1578 g->linker_z_defs = linker_z_defs;
15251579
15261580 if (override_soname) {
15271581 g->override_soname = buf_create_from_str(override_soname);
......@@ -1611,7 +1665,7 @@ static int main0(int argc, char **argv) {
16111665#endif
16121666 Buf *dest_path = buf_create_from_str(emit_bin_override_path);
16131667 Buf *source_path;
1614 if (only_preprocess) {
1668 if (only_pp_or_asm) {
16151669 source_path = buf_alloc();
16161670 Buf *pp_only_basename = buf_create_from_str(
16171671 c_source_files.at(0)->preprocessor_only_basename);
......@@ -1625,7 +1679,7 @@ static int main0(int argc, char **argv) {
16251679 buf_ptr(dest_path), err_str(err));
16261680 return main_exit(root_progress_node, EXIT_FAILURE);
16271681 }
1628 } else if (only_preprocess) {
1682 } else if (only_pp_or_asm) {
16291683#if defined(ZIG_OS_WINDOWS)
16301684 buf_replace(g->c_artifact_dir, '/', '\\');
16311685#endif
src/os.cpp+6-3
......@@ -1097,8 +1097,8 @@ static Error set_file_times(OsFile file, OsTimeStamp ts) {
10971097 return ErrorNone;
10981098#else
10991099 struct timespec times[2] = {
1100 { (time_t)ts.sec, (time_t)ts.nsec },
1101 { (time_t)ts.sec, (time_t)ts.nsec },
1100 { (time_t)ts.sec, (long)ts.nsec },
1101 { (time_t)ts.sec, (long)ts.nsec },
11021102 };
11031103 if (futimens(file, times) == -1) {
11041104 switch (errno) {
......@@ -1456,7 +1456,10 @@ static void init_rand() {
14561456 memcpy(&seed, bytes, sizeof(unsigned));
14571457 srand(seed);
14581458#elif defined(ZIG_OS_LINUX)
1459 srand(*((unsigned*)getauxval(AT_RANDOM)));
1459 unsigned char *ptr_random = (unsigned char*)getauxval(AT_RANDOM);
1460 unsigned seed;
1461 memcpy(&seed, ptr_random, sizeof(seed));
1462 srand(seed);
14601463#else
14611464 int fd = open("/dev/urandom", O_RDONLY|O_CLOEXEC);
14621465 if (fd == -1) {
src/stage2.h+6-5
......@@ -342,18 +342,19 @@ enum Stage2ClangArg {
342342 Stage2ClangArgShared,
343343 Stage2ClangArgRDynamic,
344344 Stage2ClangArgWL,
345 Stage2ClangArgPreprocess,
345 Stage2ClangArgPreprocessOrAsm,
346346 Stage2ClangArgOptimize,
347347 Stage2ClangArgDebug,
348348 Stage2ClangArgSanitize,
349349 Stage2ClangArgLinkerScript,
350350 Stage2ClangArgVerboseCmds,
351 Stage2ClangArgExceptions,
352 Stage2ClangArgNoExceptions,
353 Stage2ClangArgRtti,
354 Stage2ClangArgNoRtti,
355351 Stage2ClangArgForLinker,
356352 Stage2ClangArgLinkerInputZ,
353 Stage2ClangArgLibDir,
354 Stage2ClangArgMCpu,
355 Stage2ClangArgDepFile,
356 Stage2ClangArgFrameworkDir,
357 Stage2ClangArgFramework,
357358};
358359
359360// ABI warning
src/target.cpp+14-13
......@@ -624,6 +624,7 @@ uint32_t target_c_type_size_in_bits(const ZigTarget *target, CIntType id) {
624624 case CIntTypeCount:
625625 zig_unreachable();
626626 }
627 zig_unreachable();
627628 default:
628629 switch (id) {
629630 case CIntTypeShort:
......@@ -642,6 +643,7 @@ uint32_t target_c_type_size_in_bits(const ZigTarget *target, CIntType id) {
642643 zig_unreachable();
643644 }
644645 }
646 zig_unreachable();
645647 case OsLinux:
646648 case OsMacOSX:
647649 case OsFreeBSD:
......@@ -666,6 +668,7 @@ uint32_t target_c_type_size_in_bits(const ZigTarget *target, CIntType id) {
666668 case CIntTypeCount:
667669 zig_unreachable();
668670 }
671 zig_unreachable();
669672 case OsUefi:
670673 case OsWindows:
671674 switch (id) {
......@@ -683,6 +686,7 @@ uint32_t target_c_type_size_in_bits(const ZigTarget *target, CIntType id) {
683686 case CIntTypeCount:
684687 zig_unreachable();
685688 }
689 zig_unreachable();
686690 case OsIOS:
687691 switch (id) {
688692 case CIntTypeShort:
......@@ -699,6 +703,7 @@ uint32_t target_c_type_size_in_bits(const ZigTarget *target, CIntType id) {
699703 case CIntTypeCount:
700704 zig_unreachable();
701705 }
706 zig_unreachable();
702707 case OsAnanas:
703708 case OsCloudABI:
704709 case OsKFreeBSD:
......@@ -1207,6 +1212,15 @@ bool target_is_libc_lib_name(const ZigTarget *target, const char *name) {
12071212 if (strcmp(name, "c") == 0)
12081213 return true;
12091214
1215 if (target_abi_is_gnu(target->abi) && target->os == OsWindows) {
1216 // mingw-w64
1217
1218 if (strcmp(name, "m") == 0)
1219 return true;
1220
1221 return false;
1222 }
1223
12101224 if (target_abi_is_gnu(target->abi) || target_abi_is_musl(target->abi) || target_os_is_darwin(target->os)) {
12111225 if (strcmp(name, "m") == 0)
12121226 return true;
......@@ -1286,19 +1300,6 @@ const char *target_arch_musl_name(ZigLLVM_ArchType arch) {
12861300 }
12871301}
12881302
1289bool target_supports_libunwind(const ZigTarget *target) {
1290 switch (target->arch) {
1291 case ZigLLVM_arm:
1292 case ZigLLVM_armeb:
1293 case ZigLLVM_riscv32:
1294 case ZigLLVM_riscv64:
1295 return false;
1296 default:
1297 return true;
1298 }
1299 return true;
1300}
1301
13021303bool target_libc_needs_crti_crtn(const ZigTarget *target) {
13031304 if (target->arch == ZigLLVM_riscv32 || target->arch == ZigLLVM_riscv64 || target_is_android(target)) {
13041305 return false;
src/target.hpp-1
......@@ -119,7 +119,6 @@ bool target_supports_stack_probing(const ZigTarget *target);
119119bool target_supports_sanitize_c(const ZigTarget *target);
120120bool target_has_debug_info(const ZigTarget *target);
121121const char *target_arch_musl_name(ZigLLVM_ArchType arch);
122bool target_supports_libunwind(const ZigTarget *target);
123122
124123uint32_t target_arch_pointer_bit_width(ZigLLVM_ArchType arch);
125124uint32_t target_arch_largest_atomic_bits(ZigLLVM_ArchType arch);
src/tokenizer.cpp+12-3
......@@ -840,6 +840,7 @@ void tokenize(Buf *buf, Tokenization *out) {
840840 t.state = TokenizeStateStart;
841841 continue;
842842 }
843 break;
843844 case TokenizeStateSawSlash:
844845 switch (c) {
845846 case '/':
......@@ -1209,7 +1210,7 @@ void tokenize(Buf *buf, Tokenization *out) {
12091210 t.is_trailing_underscore = false;
12101211 t.state = TokenizeStateNumber;
12111212 }
1212 // fall through
1213 ZIG_FALLTHROUGH;
12131214 case TokenizeStateNumber:
12141215 {
12151216 if (c == '_') {
......@@ -1291,7 +1292,7 @@ void tokenize(Buf *buf, Tokenization *out) {
12911292 t.is_trailing_underscore = false;
12921293 t.state = TokenizeStateFloatFraction;
12931294 }
1294 // fall through
1295 ZIG_FALLTHROUGH;
12951296 case TokenizeStateFloatFraction:
12961297 {
12971298 if (c == '_') {
......@@ -1350,7 +1351,7 @@ void tokenize(Buf *buf, Tokenization *out) {
13501351 t.is_trailing_underscore = false;
13511352 t.state = TokenizeStateFloatExponentNumber;
13521353 }
1353 // fall through
1354 ZIG_FALLTHROUGH;
13541355 case TokenizeStateFloatExponentNumber:
13551356 {
13561357 if (c == '_') {
......@@ -1494,9 +1495,17 @@ void tokenize(Buf *buf, Tokenization *out) {
14941495 tokenize_error(&t, "unexpected EOF");
14951496 break;
14961497 case TokenizeStateLineComment:
1498 break;
14971499 case TokenizeStateSawSlash2:
1500 cancel_token(&t);
1501 break;
14981502 case TokenizeStateSawSlash3:
1503 set_token_id(&t, t.cur_tok, TokenIdDocComment);
1504 end_token(&t);
1505 break;
14991506 case TokenizeStateSawSlashBang:
1507 set_token_id(&t, t.cur_tok, TokenIdContainerDocComment);
1508 end_token(&t);
15001509 break;
15011510 }
15021511 if (t.state != TokenizeStateError) {
src/util.hpp+9
......@@ -100,6 +100,15 @@ static inline bool is_power_of_2(uint64_t x) {
100100 return x != 0 && ((x & (~x + 1)) == x);
101101}
102102
103static inline bool mem_ends_with_mem(const char *mem, size_t mem_len, const char *end, size_t end_len) {
104 if (mem_len < end_len) return false;
105 return memcmp(mem + mem_len - end_len, end, end_len) == 0;
106}
107
108static inline bool mem_ends_with_str(const char *mem, size_t mem_len, const char *str) {
109 return mem_ends_with_mem(mem, mem_len, str, strlen(str));
110}
111
103112static inline uint64_t round_to_next_power_of_2(uint64_t x) {
104113 --x;
105114 x |= x >> 1;
src/util_base.hpp+10
......@@ -64,4 +64,14 @@ static inline void zig_assert(bool ok, const char *file, int line, const char *f
6464#undef assert
6565#define assert(ok) zig_assert(ok, __FILE__, __LINE__, __func__)
6666
67#if defined(_MSC_VER)
68#define ZIG_FALLTHROUGH
69#elif defined(__clang__)
70#define ZIG_FALLTHROUGH [[clang::fallthrough]]
71#elif defined(__GNUC__)
72#define ZIG_FALLTHROUGH __attribute__((fallthrough))
73#else
74#define ZIG_FALLTHROUGH
75#endif
76
6777#endif
src/zig_clang.h+2
......@@ -52,6 +52,8 @@ struct ZigClangAPValue {
5252 // experimentally-derived size of clang::APValue::DataType
5353#if defined(_WIN32) && defined(_MSC_VER)
5454 char Data[52];
55#elif defined(__i386__)
56 char Data[48];
5557#else
5658 char Data[68];
5759#endif
test/cli.zig+8-3
......@@ -59,7 +59,12 @@ fn printCmd(cwd: []const u8, argv: []const []const u8) void {
5959
6060fn exec(cwd: []const u8, argv: []const []const u8) !ChildProcess.ExecResult {
6161 const max_output_size = 100 * 1024;
62 const result = ChildProcess.exec(a, argv, cwd, null, max_output_size) catch |err| {
62 const result = ChildProcess.exec(.{
63 .allocator = a,
64 .argv = argv,
65 .cwd = cwd,
66 .max_output_bytes = max_output_size,
67 }) catch |err| {
6368 std.debug.warn("The following command failed:\n", .{});
6469 printCmd(cwd, argv);
6570 return err;
......@@ -101,7 +106,7 @@ fn testGodboltApi(zig_exe: []const u8, dir_path: []const u8) anyerror!void {
101106 const example_zig_path = try fs.path.join(a, &[_][]const u8{ dir_path, "example.zig" });
102107 const example_s_path = try fs.path.join(a, &[_][]const u8{ dir_path, "example.s" });
103108
104 try std.io.writeFile(example_zig_path,
109 try fs.cwd().writeFile(example_zig_path,
105110 \\// Type your code here, or load an example.
106111 \\export fn square(num: i32) i32 {
107112 \\ return num * num;
......@@ -124,7 +129,7 @@ fn testGodboltApi(zig_exe: []const u8, dir_path: []const u8) anyerror!void {
124129 };
125130 _ = try exec(dir_path, &args);
126131
127 const out_asm = try std.io.readFileAlloc(a, example_s_path);
132 const out_asm = try std.fs.cwd().readFileAlloc(a, example_s_path, std.math.maxInt(usize));
128133 testing.expect(std.mem.indexOf(u8, out_asm, "square:") != null);
129134 testing.expect(std.mem.indexOf(u8, out_asm, "mov\teax, edi") != null);
130135 testing.expect(std.mem.indexOf(u8, out_asm, "imul\teax, edi") != null);
test/compile_errors.zig+52-1
......@@ -2,6 +2,19 @@ const tests = @import("tests.zig");
22const std = @import("std");
33
44pub fn addCases(cases: *tests.CompileErrorContext) void {
5 cases.addTest("cast between ?T where T is not a pointer",
6 \\pub const fnty1 = ?fn (i8) void;
7 \\pub const fnty2 = ?fn (u64) void;
8 \\export fn entry() void {
9 \\ var a: fnty1 = undefined;
10 \\ var b: fnty2 = undefined;
11 \\ a = b;
12 \\}
13 , &[_][]const u8{
14 "tmp.zig:6:9: error: expected type '?fn(i8) void', found '?fn(u64) void'",
15 "tmp.zig:6:9: note: optional type child 'fn(u64) void' cannot cast into optional type child 'fn(i8) void'",
16 });
17
518 cases.addTest("unused variable error on errdefer",
619 \\fn foo() !void {
720 \\ errdefer |a| unreachable;
......@@ -1188,7 +1201,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
11881201 \\ suspend;
11891202 \\}
11901203 , &[_][]const u8{
1191 "tmp.zig:3:5: error: expected type '*@Frame(bar)', found '*@Frame(foo)'",
1204 "tmp.zig:3:13: error: expected type '*@Frame(bar)', found '*@Frame(foo)'",
11921205 });
11931206
11941207 cases.add("@Frame() of generic function",
......@@ -6806,4 +6819,42 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
68066819 , &[_][]const u8{
68076820 "tmp.zig:2:27: error: type 'u32' does not support array initialization",
68086821 });
6822
6823 cases.add("issue #2687: coerce from undefined array pointer to slice",
6824 \\export fn foo1() void {
6825 \\ const a: *[1]u8 = undefined;
6826 \\ var b: []u8 = a;
6827 \\}
6828 \\export fn foo2() void {
6829 \\ comptime {
6830 \\ var a: *[1]u8 = undefined;
6831 \\ var b: []u8 = a;
6832 \\ }
6833 \\}
6834 \\export fn foo3() void {
6835 \\ comptime {
6836 \\ const a: *[1]u8 = undefined;
6837 \\ var b: []u8 = a;
6838 \\ }
6839 \\}
6840 , &[_][]const u8{
6841 "tmp.zig:3:19: error: use of undefined value here causes undefined behavior",
6842 "tmp.zig:8:23: error: use of undefined value here causes undefined behavior",
6843 "tmp.zig:14:23: error: use of undefined value here causes undefined behavior",
6844 });
6845
6846 cases.add("issue #3818: bitcast from parray/slice to u16",
6847 \\export fn foo1() void {
6848 \\ var bytes = [_]u8{1, 2};
6849 \\ const word: u16 = @bitCast(u16, bytes[0..]);
6850 \\}
6851 \\export fn foo2() void {
6852 \\ var bytes: []u8 = &[_]u8{1, 2};
6853 \\ const word: u16 = @bitCast(u16, bytes);
6854 \\}
6855 , &[_][]const u8{
6856 "tmp.zig:3:42: error: unable to @bitCast from pointer type '*[2]u8'",
6857 "tmp.zig:7:32: error: destination type 'u16' has size 2 but source type '[]u8' has size 16",
6858 "tmp.zig:7:37: note: referenced here",
6859 });
68096860}
test/src/compare_output.zig+4-4
......@@ -91,7 +91,7 @@ pub const CompareOutputContext = struct {
9191 const b = self.b;
9292
9393 const write_src = b.addWriteFiles();
94 for (case.sources.toSliceConst()) |src_file| {
94 for (case.sources.span()) |src_file| {
9595 write_src.add(src_file.filename, src_file.source);
9696 }
9797
......@@ -105,7 +105,7 @@ pub const CompareOutputContext = struct {
105105 }
106106
107107 const exe = b.addExecutable("test", null);
108 exe.addAssemblyFileFromWriteFileStep(write_src, case.sources.toSliceConst()[0].filename);
108 exe.addAssemblyFileFromWriteFileStep(write_src, case.sources.span()[0].filename);
109109
110110 const run = exe.run();
111111 run.addArgs(case.cli_args);
......@@ -125,7 +125,7 @@ pub const CompareOutputContext = struct {
125125 if (mem.indexOf(u8, annotated_case_name, filter) == null) continue;
126126 }
127127
128 const basename = case.sources.toSliceConst()[0].filename;
128 const basename = case.sources.span()[0].filename;
129129 const exe = b.addExecutableFromWriteFileStep("test", write_src, basename);
130130 exe.setBuildMode(mode);
131131 if (case.link_libc) {
......@@ -146,7 +146,7 @@ pub const CompareOutputContext = struct {
146146 if (mem.indexOf(u8, annotated_case_name, filter) == null) return;
147147 }
148148
149 const basename = case.sources.toSliceConst()[0].filename;
149 const basename = case.sources.span()[0].filename;
150150 const exe = b.addExecutableFromWriteFileStep("test", write_src, basename);
151151 if (case.link_libc) {
152152 exe.linkSystemLibrary("c");
test/src/run_translated_c.zig+2-2
......@@ -82,13 +82,13 @@ pub const RunTranslatedCContext = struct {
8282 }
8383
8484 const write_src = b.addWriteFiles();
85 for (case.sources.toSliceConst()) |src_file| {
85 for (case.sources.span()) |src_file| {
8686 write_src.add(src_file.filename, src_file.source);
8787 }
8888 const translate_c = b.addTranslateC(.{
8989 .write_file = .{
9090 .step = write_src,
91 .basename = case.sources.toSliceConst()[0].filename,
91 .basename = case.sources.span()[0].filename,
9292 },
9393 });
9494 translate_c.step.name = b.fmt("{} translate-c", .{annotated_case_name});
test/src/translate_c.zig+3-3
......@@ -105,20 +105,20 @@ pub const TranslateCContext = struct {
105105 }
106106
107107 const write_src = b.addWriteFiles();
108 for (case.sources.toSliceConst()) |src_file| {
108 for (case.sources.span()) |src_file| {
109109 write_src.add(src_file.filename, src_file.source);
110110 }
111111
112112 const translate_c = b.addTranslateC(.{
113113 .write_file = .{
114114 .step = write_src,
115 .basename = case.sources.toSliceConst()[0].filename,
115 .basename = case.sources.span()[0].filename,
116116 },
117117 });
118118 translate_c.step.name = annotated_case_name;
119119 translate_c.setTarget(case.target);
120120
121 const check_file = translate_c.addCheckFile(case.expected_lines.toSliceConst());
121 const check_file = translate_c.addCheckFile(case.expected_lines.span());
122122
123123 self.step.dependOn(&check_file.step);
124124 }
test/stage1/behavior.zig+3
......@@ -41,6 +41,9 @@ comptime {
4141 _ = @import("behavior/bugs/3586.zig");
4242 _ = @import("behavior/bugs/3742.zig");
4343 _ = @import("behavior/bugs/4560.zig");
44 _ = @import("behavior/bugs/4769_a.zig");
45 _ = @import("behavior/bugs/4769_b.zig");
46 _ = @import("behavior/bugs/4769_c.zig");
4447 _ = @import("behavior/bugs/394.zig");
4548 _ = @import("behavior/bugs/421.zig");
4649 _ = @import("behavior/bugs/529.zig");
test/stage1/behavior/array.zig+14-5
......@@ -31,14 +31,23 @@ fn getArrayLen(a: []const u32) usize {
3131test "array with sentinels" {
3232 const S = struct {
3333 fn doTheTest(is_ct: bool) void {
34 var zero_sized: [0:0xde]u8 = [_:0xde]u8{};
35 expectEqual(@as(u8, 0xde), zero_sized[0]);
36 // Disabled at runtime because of
37 // https://github.com/ziglang/zig/issues/4372
3834 if (is_ct) {
35 var zero_sized: [0:0xde]u8 = [_:0xde]u8{};
36 // Disabled at runtime because of
37 // https://github.com/ziglang/zig/issues/4372
38 expectEqual(@as(u8, 0xde), zero_sized[0]);
3939 var reinterpreted = @ptrCast(*[1]u8, &zero_sized);
4040 expectEqual(@as(u8, 0xde), reinterpreted[0]);
4141 }
42 var arr: [3:0x55]u8 = undefined;
43 // Make sure the sentinel pointer is pointing after the last element
44 if (!is_ct) {
45 const sentinel_ptr = @ptrToInt(&arr[3]);
46 const last_elem_ptr = @ptrToInt(&arr[2]);
47 expectEqual(@as(usize, 1), sentinel_ptr - last_elem_ptr);
48 }
49 // Make sure the sentinel is writeable
50 arr[3] = 0x55;
4251 }
4352 };
4453
......@@ -372,7 +381,7 @@ test "access the null element of a null terminated array" {
372381 const S = struct {
373382 fn doTheTest() void {
374383 var array: [4:0]u8 = .{ 'a', 'o', 'e', 'u' };
375 comptime expect(array[4] == 0);
384 expect(array[4] == 0);
376385 var len: usize = 4;
377386 expect(array[len] == 0);
378387 }
test/stage1/behavior/atomics.zig-2
......@@ -190,8 +190,6 @@ fn testAtomicRmwInt() void {
190190 _ = @atomicRmw(u8, &x, .Xor, 2, .SeqCst);
191191 expect(x == 0xfd);
192192
193 // TODO https://github.com/ziglang/zig/issues/4724
194 if (builtin.arch == .mipsel) return;
195193 _ = @atomicRmw(u8, &x, .Max, 1, .SeqCst);
196194 expect(x == 0xfd);
197195 _ = @atomicRmw(u8, &x, .Min, 1, .SeqCst);
test/stage1/behavior/bugs/4769_a.zig created+1
......@@ -0,0 +1 @@
1//
\ No newline at end of file
test/stage1/behavior/bugs/4769_b.zig created+1
......@@ -0,0 +1 @@
1//!
\ No newline at end of file
test/stage1/behavior/bugs/4769_c.zig created+1
......@@ -0,0 +1 @@
1///
\ No newline at end of file
test/stage1/behavior/cast.zig+16-1
......@@ -329,7 +329,7 @@ fn testCastPtrOfArrayToSliceAndPtr() void {
329329test "cast *[1][*]const u8 to [*]const ?[*]const u8" {
330330 const window_name = [1][*]const u8{"window name"};
331331 const x: [*]const ?[*]const u8 = &window_name;
332 expect(mem.eql(u8, std.mem.toSliceConst(u8, @ptrCast([*:0]const u8, x[0].?)), "window name"));
332 expect(mem.eql(u8, std.mem.spanZ(@ptrCast([*:0]const u8, x[0].?)), "window name"));
333333}
334334
335335test "@intCast comptime_int" {
......@@ -790,3 +790,18 @@ test "assignment to optional pointer result loc" {
790790 var foo: struct { ptr: ?*c_void } = .{ .ptr = &global_struct };
791791 expect(foo.ptr.? == @ptrCast(*c_void, &global_struct));
792792}
793
794test "peer type resolve string lit with sentinel-terminated mutable slice" {
795 var array: [4:0]u8 = undefined;
796 array[4] = 0; // TODO remove this when #4372 is solved
797 var slice: [:0]u8 = array[0..4 :0];
798 comptime expect(@TypeOf(slice, "hi") == [:0]const u8);
799 comptime expect(@TypeOf("hi", slice) == [:0]const u8);
800}
801
802test "peer type resolve array pointers, one of them const" {
803 var array1: [4]u8 = undefined;
804 const array2: [5]u8 = undefined;
805 comptime expect(@TypeOf(&array1, &array2) == []const u8);
806 comptime expect(@TypeOf(&array2, &array1) == []const u8);
807}
test/stage1/behavior/pointers.zig+1-1
......@@ -225,7 +225,7 @@ test "null terminated pointer" {
225225 var zero_ptr: [*:0]const u8 = @ptrCast([*:0]const u8, &array_with_zero);
226226 var no_zero_ptr: [*]const u8 = zero_ptr;
227227 var zero_ptr_again = @ptrCast([*:0]const u8, no_zero_ptr);
228 expect(std.mem.eql(u8, std.mem.toSliceConst(u8, zero_ptr_again), "hello"));
228 expect(std.mem.eql(u8, std.mem.spanZ(zero_ptr_again), "hello"));
229229 }
230230 };
231231 S.doTheTest();
test/standalone/brace_expansion/main.zig+24-24
......@@ -4,7 +4,7 @@ const mem = std.mem;
44const debug = std.debug;
55const assert = debug.assert;
66const testing = std.testing;
7const Buffer = std.Buffer;
7const ArrayListSentineled = std.ArrayListSentineled;
88const ArrayList = std.ArrayList;
99const maxInt = std.math.maxInt;
1010
......@@ -111,7 +111,7 @@ fn parse(tokens: *const ArrayList(Token), token_index: *usize) ParseError!Node {
111111 }
112112}
113113
114fn expandString(input: []const u8, output: *Buffer) !void {
114fn expandString(input: []const u8, output: *ArrayListSentineled(u8, 0)) !void {
115115 const tokens = try tokenize(input);
116116 if (tokens.len == 1) {
117117 return output.resize(0);
......@@ -125,52 +125,52 @@ fn expandString(input: []const u8, output: *Buffer) !void {
125125 else => return error.InvalidInput,
126126 }
127127
128 var result_list = ArrayList(Buffer).init(global_allocator);
128 var result_list = ArrayList(ArrayListSentineled(u8, 0)).init(global_allocator);
129129 defer result_list.deinit();
130130
131131 try expandNode(root, &result_list);
132132
133133 try output.resize(0);
134 for (result_list.toSliceConst()) |buf, i| {
134 for (result_list.span()) |buf, i| {
135135 if (i != 0) {
136 try output.appendByte(' ');
136 try output.append(' ');
137137 }
138 try output.append(buf.toSliceConst());
138 try output.appendSlice(buf.span());
139139 }
140140}
141141
142142const ExpandNodeError = error{OutOfMemory};
143143
144fn expandNode(node: Node, output: *ArrayList(Buffer)) ExpandNodeError!void {
144fn expandNode(node: Node, output: *ArrayList(ArrayListSentineled(u8, 0))) ExpandNodeError!void {
145145 assert(output.len == 0);
146146 switch (node) {
147147 Node.Scalar => |scalar| {
148 try output.append(try Buffer.init(global_allocator, scalar));
148 try output.append(try ArrayListSentineled(u8, 0).init(global_allocator, scalar));
149149 },
150150 Node.Combine => |pair| {
151151 const a_node = pair[0];
152152 const b_node = pair[1];
153153
154 var child_list_a = ArrayList(Buffer).init(global_allocator);
154 var child_list_a = ArrayList(ArrayListSentineled(u8, 0)).init(global_allocator);
155155 try expandNode(a_node, &child_list_a);
156156
157 var child_list_b = ArrayList(Buffer).init(global_allocator);
157 var child_list_b = ArrayList(ArrayListSentineled(u8, 0)).init(global_allocator);
158158 try expandNode(b_node, &child_list_b);
159159
160 for (child_list_a.toSliceConst()) |buf_a| {
161 for (child_list_b.toSliceConst()) |buf_b| {
162 var combined_buf = try Buffer.initFromBuffer(buf_a);
163 try combined_buf.append(buf_b.toSliceConst());
160 for (child_list_a.span()) |buf_a| {
161 for (child_list_b.span()) |buf_b| {
162 var combined_buf = try ArrayListSentineled(u8, 0).initFromBuffer(buf_a);
163 try combined_buf.appendSlice(buf_b.span());
164164 try output.append(combined_buf);
165165 }
166166 }
167167 },
168168 Node.List => |list| {
169 for (list.toSliceConst()) |child_node| {
170 var child_list = ArrayList(Buffer).init(global_allocator);
169 for (list.span()) |child_node| {
170 var child_list = ArrayList(ArrayListSentineled(u8, 0)).init(global_allocator);
171171 try expandNode(child_node, &child_list);
172172
173 for (child_list.toSliceConst()) |buf| {
173 for (child_list.span()) |buf| {
174174 try output.append(buf);
175175 }
176176 }
......@@ -187,17 +187,17 @@ pub fn main() !void {
187187
188188 global_allocator = &arena.allocator;
189189
190 var stdin_buf = try Buffer.initSize(global_allocator, 0);
190 var stdin_buf = try ArrayListSentineled(u8, 0).initSize(global_allocator, 0);
191191 defer stdin_buf.deinit();
192192
193193 var stdin_adapter = stdin_file.inStream();
194194 try stdin_adapter.stream.readAllBuffer(&stdin_buf, maxInt(usize));
195195
196 var result_buf = try Buffer.initSize(global_allocator, 0);
196 var result_buf = try ArrayListSentineled(u8, 0).initSize(global_allocator, 0);
197197 defer result_buf.deinit();
198198
199 try expandString(stdin_buf.toSlice(), &result_buf);
200 try stdout_file.write(result_buf.toSliceConst());
199 try expandString(stdin_buf.span(), &result_buf);
200 try stdout_file.write(result_buf.span());
201201}
202202
203203test "invalid inputs" {
......@@ -218,7 +218,7 @@ test "invalid inputs" {
218218}
219219
220220fn expectError(test_input: []const u8, expected_err: anyerror) void {
221 var output_buf = Buffer.initSize(global_allocator, 0) catch unreachable;
221 var output_buf = ArrayListSentineled(u8, 0).initSize(global_allocator, 0) catch unreachable;
222222 defer output_buf.deinit();
223223
224224 testing.expectError(expected_err, expandString(test_input, &output_buf));
......@@ -251,10 +251,10 @@ test "valid inputs" {
251251}
252252
253253fn expectExpansion(test_input: []const u8, expected_result: []const u8) void {
254 var result = Buffer.initSize(global_allocator, 0) catch unreachable;
254 var result = ArrayListSentineled(u8, 0).initSize(global_allocator, 0) catch unreachable;
255255 defer result.deinit();
256256
257257 expandString(test_input, &result) catch unreachable;
258258
259 testing.expectEqualSlices(u8, expected_result, result.toSlice());
259 testing.expectEqualSlices(u8, expected_result, result.span());
260260}
test/standalone/guess_number/main.zig+1-1
......@@ -17,7 +17,7 @@ pub fn main() !void {
1717 const seed = std.mem.readIntNative(u64, &seed_bytes);
1818 var prng = std.rand.DefaultPrng.init(seed);
1919
20 const answer = prng.random.range(u8, 0, 100) + 1;
20 const answer = prng.random.intRangeLessThan(u8, 0, 100) + 1;
2121
2222 while (true) {
2323 try stdout.print("\nGuess a number between 1 and 100: ", .{});
test/tests.zig+32-33
......@@ -4,7 +4,6 @@ const debug = std.debug;
44const warn = debug.warn;
55const build = std.build;
66const CrossTarget = std.zig.CrossTarget;
7const Buffer = std.Buffer;
87const io = std.io;
98const fs = std.fs;
109const mem = std.mem;
......@@ -583,7 +582,7 @@ pub const StackTracesContext = struct {
583582
584583 warn("Test {}/{} {}...", .{ self.test_index + 1, self.context.test_index, self.name });
585584
586 const child = std.ChildProcess.init(args.toSliceConst(), b.allocator) catch unreachable;
585 const child = std.ChildProcess.init(args.span(), b.allocator) catch unreachable;
587586 defer child.deinit();
588587
589588 child.stdin_behavior = .Ignore;
......@@ -592,7 +591,7 @@ pub const StackTracesContext = struct {
592591 child.env_map = b.env_map;
593592
594593 if (b.verbose) {
595 printInvocation(args.toSliceConst());
594 printInvocation(args.span());
596595 }
597596 child.spawn() catch |err| debug.panic("Unable to spawn {}: {}\n", .{ full_exe_path, @errorName(err) });
598597
......@@ -614,23 +613,23 @@ pub const StackTracesContext = struct {
614613 code,
615614 expect_code,
616615 });
617 printInvocation(args.toSliceConst());
616 printInvocation(args.span());
618617 return error.TestFailed;
619618 }
620619 },
621620 .Signal => |signum| {
622621 warn("Process {} terminated on signal {}\n", .{ full_exe_path, signum });
623 printInvocation(args.toSliceConst());
622 printInvocation(args.span());
624623 return error.TestFailed;
625624 },
626625 .Stopped => |signum| {
627626 warn("Process {} stopped on signal {}\n", .{ full_exe_path, signum });
628 printInvocation(args.toSliceConst());
627 printInvocation(args.span());
629628 return error.TestFailed;
630629 },
631630 .Unknown => |code| {
632631 warn("Process {} terminated unexpectedly with error code {}\n", .{ full_exe_path, code });
633 printInvocation(args.toSliceConst());
632 printInvocation(args.span());
634633 return error.TestFailed;
635634 },
636635 }
......@@ -640,7 +639,7 @@ pub const StackTracesContext = struct {
640639 // - replace address with symbolic string
641640 // - skip empty lines
642641 const got: []const u8 = got_result: {
643 var buf = try Buffer.initSize(b.allocator, 0);
642 var buf = ArrayList(u8).init(b.allocator);
644643 defer buf.deinit();
645644 if (stderr.len != 0 and stderr[stderr.len - 1] == '\n') stderr = stderr[0 .. stderr.len - 1];
646645 var it = mem.separate(stderr, "\n");
......@@ -652,21 +651,21 @@ pub const StackTracesContext = struct {
652651 var pos: usize = if (std.Target.current.os.tag == .windows) 2 else 0;
653652 for (delims) |delim, i| {
654653 marks[i] = mem.indexOfPos(u8, line, pos, delim) orelse {
655 try buf.append(line);
656 try buf.append("\n");
654 try buf.appendSlice(line);
655 try buf.appendSlice("\n");
657656 continue :process_lines;
658657 };
659658 pos = marks[i] + delim.len;
660659 }
661660 pos = mem.lastIndexOfScalar(u8, line[0..marks[0]], fs.path.sep) orelse {
662 try buf.append(line);
663 try buf.append("\n");
661 try buf.appendSlice(line);
662 try buf.appendSlice("\n");
664663 continue :process_lines;
665664 };
666 try buf.append(line[pos + 1 .. marks[2] + delims[2].len]);
667 try buf.append(" [address]");
668 try buf.append(line[marks[3]..]);
669 try buf.append("\n");
665 try buf.appendSlice(line[pos + 1 .. marks[2] + delims[2].len]);
666 try buf.appendSlice(" [address]");
667 try buf.appendSlice(line[marks[3]..]);
668 try buf.appendSlice("\n");
670669 }
671670 break :got_result buf.toOwnedSlice();
672671 };
......@@ -785,7 +784,7 @@ pub const CompileErrorContext = struct {
785784 } else {
786785 try zig_args.append("build-obj");
787786 }
788 const root_src_basename = self.case.sources.toSliceConst()[0].filename;
787 const root_src_basename = self.case.sources.span()[0].filename;
789788 try zig_args.append(self.write_src.getOutputPath(root_src_basename));
790789
791790 zig_args.append("--name") catch unreachable;
......@@ -809,10 +808,10 @@ pub const CompileErrorContext = struct {
809808 warn("Test {}/{} {}...", .{ self.test_index + 1, self.context.test_index, self.name });
810809
811810 if (b.verbose) {
812 printInvocation(zig_args.toSliceConst());
811 printInvocation(zig_args.span());
813812 }
814813
815 const child = std.ChildProcess.init(zig_args.toSliceConst(), b.allocator) catch unreachable;
814 const child = std.ChildProcess.init(zig_args.span(), b.allocator) catch unreachable;
816815 defer child.deinit();
817816
818817 child.env_map = b.env_map;
......@@ -822,11 +821,11 @@ pub const CompileErrorContext = struct {
822821
823822 child.spawn() catch |err| debug.panic("Unable to spawn {}: {}\n", .{ zig_args.items[0], @errorName(err) });
824823
825 var stdout_buf = Buffer.initNull(b.allocator);
826 var stderr_buf = Buffer.initNull(b.allocator);
824 var stdout_buf = ArrayList(u8).init(b.allocator);
825 var stderr_buf = ArrayList(u8).init(b.allocator);
827826
828 child.stdout.?.inStream().readAllBuffer(&stdout_buf, max_stdout_size) catch unreachable;
829 child.stderr.?.inStream().readAllBuffer(&stderr_buf, max_stdout_size) catch unreachable;
827 child.stdout.?.inStream().readAllArrayList(&stdout_buf, max_stdout_size) catch unreachable;
828 child.stderr.?.inStream().readAllArrayList(&stderr_buf, max_stdout_size) catch unreachable;
830829
831830 const term = child.wait() catch |err| {
832831 debug.panic("Unable to spawn {}: {}\n", .{ zig_args.items[0], @errorName(err) });
......@@ -834,19 +833,19 @@ pub const CompileErrorContext = struct {
834833 switch (term) {
835834 .Exited => |code| {
836835 if (code == 0) {
837 printInvocation(zig_args.toSliceConst());
836 printInvocation(zig_args.span());
838837 return error.CompilationIncorrectlySucceeded;
839838 }
840839 },
841840 else => {
842841 warn("Process {} terminated unexpectedly\n", .{b.zig_exe});
843 printInvocation(zig_args.toSliceConst());
842 printInvocation(zig_args.span());
844843 return error.TestFailed;
845844 },
846845 }
847846
848 const stdout = stdout_buf.toSliceConst();
849 const stderr = stderr_buf.toSliceConst();
847 const stdout = stdout_buf.span();
848 const stderr = stderr_buf.span();
850849
851850 if (stdout.len != 0) {
852851 warn(
......@@ -875,12 +874,12 @@ pub const CompileErrorContext = struct {
875874
876875 if (!ok) {
877876 warn("\n======== Expected these compile errors: ========\n", .{});
878 for (self.case.expected_errors.toSliceConst()) |expected| {
877 for (self.case.expected_errors.span()) |expected| {
879878 warn("{}\n", .{expected});
880879 }
881880 }
882881 } else {
883 for (self.case.expected_errors.toSliceConst()) |expected| {
882 for (self.case.expected_errors.span()) |expected| {
884883 if (mem.indexOf(u8, stderr, expected) == null) {
885884 warn(
886885 \\
......@@ -980,7 +979,7 @@ pub const CompileErrorContext = struct {
980979 if (mem.indexOf(u8, annotated_case_name, filter) == null) return;
981980 }
982981 const write_src = b.addWriteFiles();
983 for (case.sources.toSliceConst()) |src_file| {
982 for (case.sources.span()) |src_file| {
984983 write_src.add(src_file.filename, src_file.source);
985984 }
986985
......@@ -1027,7 +1026,7 @@ pub const StandaloneContext = struct {
10271026 zig_args.append("--verbose") catch unreachable;
10281027 }
10291028
1030 const run_cmd = b.addSystemCommand(zig_args.toSliceConst());
1029 const run_cmd = b.addSystemCommand(zig_args.span());
10311030
10321031 const log_step = b.addLog("PASS {}\n", .{annotated_case_name});
10331032 log_step.step.dependOn(&run_cmd.step);
......@@ -1127,7 +1126,7 @@ pub const GenHContext = struct {
11271126 const full_h_path = self.obj.getOutputHPath();
11281127 const actual_h = try io.readFileAlloc(b.allocator, full_h_path);
11291128
1130 for (self.case.expected_lines.toSliceConst()) |expected_line| {
1129 for (self.case.expected_lines.span()) |expected_line| {
11311130 if (mem.indexOf(u8, actual_h, expected_line) == null) {
11321131 warn(
11331132 \\
......@@ -1188,7 +1187,7 @@ pub const GenHContext = struct {
11881187 }
11891188
11901189 const write_src = b.addWriteFiles();
1191 for (case.sources.toSliceConst()) |src_file| {
1190 for (case.sources.span()) |src_file| {
11921191 write_src.add(src_file.filename, src_file.source);
11931192 }
11941193
test/translate_c.zig+39
......@@ -2808,4 +2808,43 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
28082808 \\ return if (x > y) x else y;
28092809 \\}
28102810 });
2811
2812 cases.add("string concatenation in macros",
2813 \\#define FOO "hello"
2814 \\#define BAR FOO " world"
2815 \\#define BAZ "oh, " FOO
2816 , &[_][]const u8{
2817 \\pub const FOO = "hello";
2818 ,
2819 \\pub const BAR = FOO ++ " world";
2820 ,
2821 \\pub const BAZ = "oh, " ++ FOO;
2822 });
2823
2824 cases.add("string concatenation in macros: two defines",
2825 \\#define FOO "hello"
2826 \\#define BAZ " world"
2827 \\#define BAR FOO BAZ
2828 , &[_][]const u8{
2829 \\pub const FOO = "hello";
2830 ,
2831 \\pub const BAZ = " world";
2832 ,
2833 \\pub const BAR = FOO ++ BAZ;
2834 });
2835
2836 cases.add("string concatenation in macros: two strings",
2837 \\#define FOO "a" "b"
2838 \\#define BAR FOO "c"
2839 , &[_][]const u8{
2840 \\pub const FOO = "a" ++ "b";
2841 ,
2842 \\pub const BAR = FOO ++ "c";
2843 });
2844
2845 cases.add("string concatenation in macros: three strings",
2846 \\#define FOO "a" "b" "c"
2847 , &[_][]const u8{
2848 \\pub const FOO = "a" ++ ("b" ++ "c");
2849 });
28112850}
tools/merge_anal_dumps.zig+12-12
......@@ -183,13 +183,13 @@ const Dump = struct {
183183 try mergeSameStrings(&self.zig_version, zig_version);
184184 try mergeSameStrings(&self.root_name, root_name);
185185
186 for (params.get("builds").?.value.Array.toSliceConst()) |json_build| {
186 for (params.get("builds").?.value.Array.span()) |json_build| {
187187 const target = json_build.Object.get("target").?.value.String;
188188 try self.targets.append(target);
189189 }
190190
191191 // Merge files. If the string matches, it's the same file.
192 const other_files = root.Object.get("files").?.value.Array.toSliceConst();
192 const other_files = root.Object.get("files").?.value.Array.span();
193193 var other_file_to_mine = std.AutoHashMap(usize, usize).init(self.a());
194194 for (other_files) |other_file, i| {
195195 const gop = try self.file_map.getOrPut(other_file.String);
......@@ -201,7 +201,7 @@ const Dump = struct {
201201 }
202202
203203 // Merge AST nodes. If the file id, line, and column all match, it's the same AST node.
204 const other_ast_nodes = root.Object.get("astNodes").?.value.Array.toSliceConst();
204 const other_ast_nodes = root.Object.get("astNodes").?.value.Array.span();
205205 var other_ast_node_to_mine = std.AutoHashMap(usize, usize).init(self.a());
206206 for (other_ast_nodes) |other_ast_node_json, i| {
207207 const other_file_id = jsonObjInt(other_ast_node_json, "file");
......@@ -221,9 +221,9 @@ const Dump = struct {
221221 // convert fields lists
222222 for (other_ast_nodes) |other_ast_node_json, i| {
223223 const my_node_index = other_ast_node_to_mine.get(i).?.value;
224 const my_node = &self.node_list.toSlice()[my_node_index];
224 const my_node = &self.node_list.span()[my_node_index];
225225 if (other_ast_node_json.Object.get("fields")) |fields_json_kv| {
226 const other_fields = fields_json_kv.value.Array.toSliceConst();
226 const other_fields = fields_json_kv.value.Array.span();
227227 my_node.fields = try self.a().alloc(usize, other_fields.len);
228228 for (other_fields) |other_field_index, field_i| {
229229 const other_index = @intCast(usize, other_field_index.Integer);
......@@ -233,7 +233,7 @@ const Dump = struct {
233233 }
234234
235235 // Merge errors. If the AST Node matches, it's the same error value.
236 const other_errors = root.Object.get("errors").?.value.Array.toSliceConst();
236 const other_errors = root.Object.get("errors").?.value.Array.span();
237237 var other_error_to_mine = std.AutoHashMap(usize, usize).init(self.a());
238238 for (other_errors) |other_error_json, i| {
239239 const other_src_id = jsonObjInt(other_error_json, "src");
......@@ -253,7 +253,7 @@ const Dump = struct {
253253 // First we identify all the simple types and merge those.
254254 // Example: void, type, noreturn
255255 // We can also do integers and floats.
256 const other_types = root.Object.get("types").?.value.Array.toSliceConst();
256 const other_types = root.Object.get("types").?.value.Array.span();
257257 var other_types_to_mine = std.AutoHashMap(usize, usize).init(self.a());
258258 for (other_types) |other_type_json, i| {
259259 const type_kind = jsonObjInt(other_type_json, "kind");
......@@ -336,7 +336,7 @@ const Dump = struct {
336336
337337 try jw.objectField("builds");
338338 try jw.beginArray();
339 for (self.targets.toSliceConst()) |target| {
339 for (self.targets.span()) |target| {
340340 try jw.arrayElem();
341341 try jw.beginObject();
342342 try jw.objectField("target");
......@@ -349,7 +349,7 @@ const Dump = struct {
349349
350350 try jw.objectField("types");
351351 try jw.beginArray();
352 for (self.type_list.toSliceConst()) |t| {
352 for (self.type_list.span()) |t| {
353353 try jw.arrayElem();
354354 try jw.beginObject();
355355
......@@ -379,7 +379,7 @@ const Dump = struct {
379379
380380 try jw.objectField("errors");
381381 try jw.beginArray();
382 for (self.error_list.toSliceConst()) |zig_error| {
382 for (self.error_list.span()) |zig_error| {
383383 try jw.arrayElem();
384384 try jw.beginObject();
385385
......@@ -395,7 +395,7 @@ const Dump = struct {
395395
396396 try jw.objectField("astNodes");
397397 try jw.beginArray();
398 for (self.node_list.toSliceConst()) |node| {
398 for (self.node_list.span()) |node| {
399399 try jw.arrayElem();
400400 try jw.beginObject();
401401
......@@ -425,7 +425,7 @@ const Dump = struct {
425425
426426 try jw.objectField("files");
427427 try jw.beginArray();
428 for (self.file_list.toSliceConst()) |file| {
428 for (self.file_list.span()) |file| {
429429 try jw.arrayElem();
430430 try jw.emitString(file);
431431 }
tools/process_headers.zig+4-4
......@@ -324,7 +324,7 @@ pub fn main() !void {
324324 },
325325 .os = .linux,
326326 };
327 search: for (search_paths.toSliceConst()) |search_path| {
327 search: for (search_paths.span()) |search_path| {
328328 var sub_path: []const []const u8 = undefined;
329329 switch (vendor) {
330330 .musl => {
......@@ -414,13 +414,13 @@ pub fn main() !void {
414414 try contents_list.append(contents);
415415 }
416416 }
417 std.sort.sort(*Contents, contents_list.toSlice(), Contents.hitCountLessThan);
417 std.sort.sort(*Contents, contents_list.span(), Contents.hitCountLessThan);
418418 var best_contents = contents_list.popOrNull().?;
419419 if (best_contents.hit_count > 1) {
420420 // worth it to make it generic
421421 const full_path = try std.fs.path.join(allocator, &[_][]const u8{ out_dir, generic_name, path_kv.key });
422422 try std.fs.cwd().makePath(std.fs.path.dirname(full_path).?);
423 try std.io.writeFile(full_path, best_contents.bytes);
423 try std.fs.cwd().writeFile(full_path, best_contents.bytes);
424424 best_contents.is_generic = true;
425425 while (contents_list.popOrNull()) |contender| {
426426 if (contender.hit_count > 1) {
......@@ -447,7 +447,7 @@ pub fn main() !void {
447447 });
448448 const full_path = try std.fs.path.join(allocator, &[_][]const u8{ out_dir, out_subpath, path_kv.key });
449449 try std.fs.cwd().makePath(std.fs.path.dirname(full_path).?);
450 try std.io.writeFile(full_path, contents.bytes);
450 try std.fs.cwd().writeFile(full_path, contents.bytes);
451451 }
452452 }
453453}
tools/update_clang_options.zig+37-13
......@@ -96,19 +96,19 @@ const known_options = [_]KnownOpt{
9696 },
9797 .{
9898 .name = "E",
99 .ident = "preprocess",
99 .ident = "pp_or_asm",
100100 },
101101 .{
102102 .name = "preprocess",
103 .ident = "preprocess",
103 .ident = "pp_or_asm",
104104 },
105105 .{
106106 .name = "S",
107 .ident = "driver_punt",
107 .ident = "pp_or_asm",
108108 },
109109 .{
110110 .name = "assemble",
111 .ident = "driver_punt",
111 .ident = "pp_or_asm",
112112 },
113113 .{
114114 .name = "O1",
......@@ -175,20 +175,44 @@ const known_options = [_]KnownOpt{
175175 .ident = "verbose_cmds",
176176 },
177177 .{
178 .name = "fexceptions",
179 .ident = "exceptions",
178 .name = "L",
179 .ident = "lib_dir",
180 },
181 .{
182 .name = "library-directory",
183 .ident = "lib_dir",
184 },
185 .{
186 .name = "mcpu",
187 .ident = "mcpu",
188 },
189 .{
190 .name = "march",
191 .ident = "mcpu",
192 },
193 .{
194 .name = "mtune",
195 .ident = "mcpu",
196 },
197 .{
198 .name = "MD",
199 .ident = "dep_file",
200 },
201 .{
202 .name = "MV",
203 .ident = "dep_file",
180204 },
181205 .{
182 .name = "fno-exceptions",
183 .ident = "no_exceptions",
206 .name = "MF",
207 .ident = "dep_file",
184208 },
185209 .{
186 .name = "frtti",
187 .ident = "rtti",
210 .name = "F",
211 .ident = "framework_dir",
188212 },
189213 .{
190 .name = "fno-rtti",
191 .ident = "no_rtti",
214 .name = "framework",
215 .ident = "framework",
192216 },
193217};
194218
......@@ -239,7 +263,7 @@ pub fn main() anyerror!void {
239263 try std.fmt.allocPrint(allocator, "-I={}/clang/include/clang/Driver", .{llvm_src_root}),
240264 };
241265
242 const child_result = try std.ChildProcess.exec2(.{
266 const child_result = try std.ChildProcess.exec(.{
243267 .allocator = allocator,
244268 .argv = &child_args,
245269 .max_output_bytes = 100 * 1024 * 1024,
tools/update_glibc.zig+7-7
......@@ -223,15 +223,15 @@ pub fn main() !void {
223223 var list = std.ArrayList([]const u8).init(allocator);
224224 var it = global_fn_set.iterator();
225225 while (it.next()) |kv| try list.append(kv.key);
226 std.sort.sort([]const u8, list.toSlice(), strCmpLessThan);
227 break :blk list.toSliceConst();
226 std.sort.sort([]const u8, list.span(), strCmpLessThan);
227 break :blk list.span();
228228 };
229229 const global_ver_list = blk: {
230230 var list = std.ArrayList([]const u8).init(allocator);
231231 var it = global_ver_set.iterator();
232232 while (it.next()) |kv| try list.append(kv.key);
233 std.sort.sort([]const u8, list.toSlice(), versionLessThan);
234 break :blk list.toSliceConst();
233 std.sort.sort([]const u8, list.span(), versionLessThan);
234 break :blk list.span();
235235 };
236236 {
237237 const vers_txt_path = try fs.path.join(allocator, &[_][]const u8{ glibc_out_dir, "vers.txt" });
......@@ -264,13 +264,13 @@ pub fn main() !void {
264264 for (abi_lists) |*abi_list, abi_index| {
265265 const kv = target_functions.get(@ptrToInt(abi_list)).?;
266266 const fn_vers_list = &kv.value.fn_vers_list;
267 for (kv.value.list.toSliceConst()) |*ver_fn| {
267 for (kv.value.list.span()) |*ver_fn| {
268268 const gop = try fn_vers_list.getOrPut(ver_fn.name);
269269 if (!gop.found_existing) {
270270 gop.kv.value = std.ArrayList(usize).init(allocator);
271271 }
272272 const ver_index = global_ver_set.get(ver_fn.ver).?.value;
273 if (std.mem.indexOfScalar(usize, gop.kv.value.toSliceConst(), ver_index) == null) {
273 if (std.mem.indexOfScalar(usize, gop.kv.value.span(), ver_index) == null) {
274274 try gop.kv.value.append(ver_index);
275275 }
276276 }
......@@ -297,7 +297,7 @@ pub fn main() !void {
297297 try abilist_txt.writeByte('\n');
298298 continue;
299299 };
300 for (kv.value.toSliceConst()) |ver_index, it_i| {
300 for (kv.value.span()) |ver_index, it_i| {
301301 if (it_i != 0) try abilist_txt.writeByte(' ');
302302 try abilist_txt.print("{d}", .{ver_index});
303303 }