authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-04-30 23:13:17-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-04-30 23:13:17-07:00
logdc28f5c3ec61a525d45d9f07a666e62f6598ed0a
tree45daf6a6a98bc0828412fd807eebd2e84e34511a
parent351b57497b1cf2ea6ee72a3c7cfdb84b924bb368
parent557eb414eee96201d1ae01b15ebf8955eca1da6d

Merge remote-tracking branch 'origin/master' into stage2-whole-file-astgen

Conflicts: lib/std/crypto/25519/field.zig lib/std/crypto/poly1305.zig I had resolved those by removing `comptime` but master branch decided to make the parameters `comptime`. This also pulls in the updated default `zig build` install directory.

10 files changed, 66 insertions(+), 13 deletions(-)

.gitignore+1
......@@ -10,6 +10,7 @@
1010# -andrewrk
1111
1212zig-cache/
13zig-out/
1314/release/
1415/debug/
1516/build/
BRANCH_TODO+1-1
......@@ -1,5 +1,5 @@
1 * decouple AstGen from Module, Compilation
21 * modify dbg_stmt ZIR instructions to have line/column rather than node indexes
2 * decouple AstGen from Module, Compilation
33 * AstGen threadlocal
44 * extern "foo" for vars and for functions
55 * namespace decls table can't reference ZIR memory because it can get modified on updates
doc/langref.html.in+32-1
......@@ -2861,6 +2861,37 @@ fn dump(args: anytype) void {
28612861 expect(args.b);
28622862 expect(args.s[0] == 'h');
28632863 expect(args.s[1] == 'i');
2864}
2865 {#code_end#}
2866 <p>
2867 Anonymous structs can be created without specifying field names, and are referred to as "tuples".
2868 </p>
2869 <p>
2870 The fields are implicitly named using numbers starting from 0. Because their names are integers,
2871 the {#syntax#}@"0"{#endsyntax#} syntax must be used to access them. Names inside {#syntax#}@""{#endsyntax#} are always recognised as identifiers.
2872 </p>
2873 <p>
2874 Like arrays, tuples have a .len field, can be indexed and work with the ++ and ** operators. They can also be iterated over with {#link|inline for#}.
2875 </p>
2876 {#code_begin|test|tuple#}
2877const std = @import("std");
2878const expect = std.testing.expect;
2879
2880test "tuple" {
2881 const values = .{
2882 @as(u32, 1234),
2883 @as(f64, 12.34),
2884 true,
2885 "hi",
2886 } ++ .{false} ** 2;
2887 expect(values[0] == 1234);
2888 expect(values[4] == false);
2889 inline for (values) |v, i| {
2890 if (i != 2) continue;
2891 expect(v);
2892 }
2893 expect(values.len == 6);
2894 expect(values.@"3"[0] == 'h');
28642895}
28652896 {#code_end#}
28662897 {#header_close#}
......@@ -9997,7 +10028,7 @@ pub fn build(b: *Builder) void {
999710028 {#code_end#}
999810029 <p class="file">terminal</p>
999910030 <pre><code class="shell">$ zig build
10000$ ./zig-cache/bin/test
10031$ ./zig-out/bin/test
1000110032all your base are belong to us</code></pre>
1000210033 {#see_also|Targets|Zig Build System#}
1000310034 {#header_close#}
lib/std/build.zig+2-1
......@@ -195,7 +195,8 @@ pub const Builder = struct {
195195 self.install_prefix = install_prefix orelse "/usr";
196196 self.install_path = fs.path.join(self.allocator, &[_][]const u8{ dest_dir, self.install_prefix }) catch unreachable;
197197 } else {
198 self.install_prefix = install_prefix orelse self.cache_root;
198 self.install_prefix = install_prefix orelse
199 (fs.path.join(self.allocator, &[_][]const u8{ self.build_root, "zig-out" }) catch unreachable);
199200 self.install_path = self.install_prefix;
200201 }
201202 self.lib_dir = fs.path.join(self.allocator, &[_][]const u8{ self.install_path, "lib" }) catch unreachable;
lib/std/compress/deflate.zig+18
......@@ -384,6 +384,8 @@ pub fn InflateStream(comptime ReaderType: type) type {
384384 const last_length = lengths[i - 1];
385385 const repeat = 3 + (try self.readBits(2));
386386 const last_index = i + repeat;
387 if (last_index > lengths.len)
388 return error.InvalidLength;
387389 while (i < last_index) : (i += 1) {
388390 lengths[i] = last_length;
389391 }
......@@ -655,3 +657,19 @@ pub fn InflateStream(comptime ReaderType: type) type {
655657pub fn inflateStream(reader: anytype, window_slice: []u8) InflateStream(@TypeOf(reader)) {
656658 return InflateStream(@TypeOf(reader)).init(reader, window_slice);
657659}
660
661test "lengths overflow" {
662 // malformed final dynamic block, tries to write 321 code lengths (MAXCODES is 316)
663 // f dy hlit hdist hclen 16 17 18 0 (18) x138 (18) x138 (18) x39 (16) x6
664 // 1 10 11101 11101 0000 010 010 010 010 (11) 1111111 (11) 1111111 (11) 0011100 (01) 11
665 const stream = [_]u8{
666 0b11101101, 0b00011101, 0b00100100, 0b11101001, 0b11111111, 0b11111111, 0b00111001, 0b00001110
667 };
668
669 const reader = std.io.fixedBufferStream(&stream).reader();
670 var window: [0x8000]u8 = undefined;
671 var inflate = inflateStream(reader, &window);
672
673 var buf: [1]u8 = undefined;
674 std.testing.expectError(error.InvalidLength, inflate.read(&buf));
675}
lib/std/crypto/25519/field.zig+1-1
......@@ -292,7 +292,7 @@ pub const Fe = struct {
292292 return _carry128(&r);
293293 }
294294
295 fn _sq(a: Fe, double: bool) callconv(.Inline) Fe {
295 fn _sq(a: Fe, comptime double: bool) callconv(.Inline) Fe {
296296 var ax: [5]u128 = undefined;
297297 var r: [5]u128 = undefined;
298298 comptime var i = 0;
lib/std/crypto/poly1305.zig+1-1
......@@ -39,7 +39,7 @@ pub const Poly1305 = struct {
3939 };
4040 }
4141
42 fn blocks(st: *Poly1305, m: []const u8, last: bool) void {
42 fn blocks(st: *Poly1305, m: []const u8, comptime last: bool) void {
4343 const hibit: u64 = if (last) 0 else 1 << 40;
4444 const r0 = st.r[0];
4545 const r1 = st.r[1];
lib/std/os.zig+6-4
......@@ -1049,7 +1049,7 @@ pub const OpenError = error{
10491049} || UnexpectedError;
10501050
10511051/// Open and possibly create a file. Keeps trying if it gets interrupted.
1052/// See also `openC`.
1052/// See also `openZ`.
10531053pub fn open(file_path: []const u8, flags: u32, perm: mode_t) OpenError!fd_t {
10541054 if (std.Target.current.os.tag == .windows) {
10551055 const file_path_w = try windows.sliceToPrefixedFileW(file_path);
......@@ -1147,7 +1147,7 @@ pub fn openW(file_path_w: []const u16, flags: u32, perm: mode_t) OpenError!fd_t
11471147
11481148/// Open and possibly create a file. Keeps trying if it gets interrupted.
11491149/// `file_path` is relative to the open directory handle `dir_fd`.
1150/// See also `openatC`.
1150/// See also `openatZ`.
11511151pub fn openat(dir_fd: fd_t, file_path: []const u8, flags: u32, mode: mode_t) OpenError!fd_t {
11521152 if (builtin.os.tag == .wasi) {
11531153 @compileError("use openatWasi instead");
......@@ -1754,7 +1754,7 @@ pub const UnlinkError = error{
17541754} || UnexpectedError;
17551755
17561756/// Delete a name and possibly the file it refers to.
1757/// See also `unlinkC`.
1757/// See also `unlinkZ`.
17581758pub fn unlink(file_path: []const u8) UnlinkError!void {
17591759 if (builtin.os.tag == .wasi) {
17601760 @compileError("unlink is not supported in WASI; use unlinkat instead");
......@@ -3419,7 +3419,7 @@ pub fn fstat(fd: fd_t) FStatError!Stat {
34193419 }
34203420}
34213421
3422pub const FStatAtError = FStatError || error{ NameTooLong, FileNotFound };
3422pub const FStatAtError = FStatError || error{ NameTooLong, FileNotFound, SymLinkLoop };
34233423
34243424/// Similar to `fstat`, but returns stat of a resource pointed to by `pathname`
34253425/// which is relative to `dirfd` handle.
......@@ -3466,8 +3466,10 @@ pub fn fstatatZ(dirfd: fd_t, pathname: [*:0]const u8, flags: u32) FStatAtError!S
34663466 EBADF => unreachable, // Always a race condition.
34673467 ENOMEM => return error.SystemResources,
34683468 EACCES => return error.AccessDenied,
3469 EPERM => return error.AccessDenied,
34693470 EFAULT => unreachable,
34703471 ENAMETOOLONG => return error.NameTooLong,
3472 ELOOP => return error.SymLinkLoop,
34713473 ENOENT => return error.FileNotFound,
34723474 ENOTDIR => return error.FileNotFound,
34733475 else => |err| return unexpectedErrno(err),
lib/std/special/build_runner.zig+3-3
......@@ -82,9 +82,9 @@ pub fn main() !void {
8282 builder.verbose = true;
8383 } else if (mem.eql(u8, arg, "-h") or mem.eql(u8, arg, "--help")) {
8484 return usage(builder, false, stdout_stream);
85 } else if (mem.eql(u8, arg, "--prefix")) {
85 } else if (mem.eql(u8, arg, "-p") or mem.eql(u8, arg, "--prefix")) {
8686 install_prefix = nextArg(args, &arg_idx) orelse {
87 warn("Expected argument after --prefix\n\n", .{});
87 warn("Expected argument after {s}\n\n", .{arg});
8888 return usageAndErr(builder, false, stderr_stream);
8989 };
9090 } else if (mem.eql(u8, arg, "--search-prefix")) {
......@@ -188,7 +188,7 @@ fn usage(builder: *Builder, already_ran_build: bool, out_stream: anytype) !void
188188 \\General Options:
189189 \\ -h, --help Print this help and exit
190190 \\ --verbose Print commands before executing them
191 \\ --prefix [path] Override default install prefix
191 \\ -p, --prefix [path] Override default install prefix
192192 \\ --search-prefix [path] Add a path to look for binaries, libraries, headers
193193 \\ --color [auto|off|on] Enable or disable colored error messages
194194 \\
src/main.zig+1-1
......@@ -687,7 +687,7 @@ fn buildOutputType(
687687 extra_cflags.shrinkRetainingCapacity(0);
688688 while (true) {
689689 i += 1;
690 if (i + 1 >= args.len) fatal("expected -- after -cflags", .{});
690 if (i >= args.len) fatal("expected -- after -cflags", .{});
691691 if (mem.eql(u8, args[i], "--")) break;
692692 try extra_cflags.append(args[i]);
693693 }