| author | |
| committer | |
| log | dc28f5c3ec61a525d45d9f07a666e62f6598ed0a |
| tree | 45daf6a6a98bc0828412fd807eebd2e84e34511a |
| parent | 351b57497b1cf2ea6ee72a3c7cfdb84b924bb368 |
| parent | 557eb414eee96201d1ae01b15ebf8955eca1da6d |
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 @@ |
| 10 | 10 | # -andrewrk |
| 11 | 11 | |
| 12 | 12 | zig-cache/ |
| 13 | zig-out/ | |
| 13 | 14 | /release/ |
| 14 | 15 | /debug/ |
| 15 | 16 | /build/ |
BRANCH_TODO+1-1| ... | ... | @@ -1,5 +1,5 @@ |
| 1 | * decouple AstGen from Module, Compilation | |
| 2 | 1 | * modify dbg_stmt ZIR instructions to have line/column rather than node indexes |
| 2 | * decouple AstGen from Module, Compilation | |
| 3 | 3 | * AstGen threadlocal |
| 4 | 4 | * extern "foo" for vars and for functions |
| 5 | 5 | * 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 { |
| 2861 | 2861 | expect(args.b); |
| 2862 | 2862 | expect(args.s[0] == 'h'); |
| 2863 | 2863 | 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#} | |
| 2877 | const std = @import("std"); | |
| 2878 | const expect = std.testing.expect; | |
| 2879 | ||
| 2880 | test "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'); | |
| 2864 | 2895 | } |
| 2865 | 2896 | {#code_end#} |
| 2866 | 2897 | {#header_close#} |
| ... | ... | @@ -9997,7 +10028,7 @@ pub fn build(b: *Builder) void { |
| 9997 | 10028 | {#code_end#} |
| 9998 | 10029 | <p class="file">terminal</p> |
| 9999 | 10030 | <pre><code class="shell">$ zig build |
| 10000 | $ ./zig-cache/bin/test | |
| 10031 | $ ./zig-out/bin/test | |
| 10001 | 10032 | all your base are belong to us</code></pre> |
| 10002 | 10033 | {#see_also|Targets|Zig Build System#} |
| 10003 | 10034 | {#header_close#} |
lib/std/build.zig+2-1| ... | ... | @@ -195,7 +195,8 @@ pub const Builder = struct { |
| 195 | 195 | self.install_prefix = install_prefix orelse "/usr"; |
| 196 | 196 | self.install_path = fs.path.join(self.allocator, &[_][]const u8{ dest_dir, self.install_prefix }) catch unreachable; |
| 197 | 197 | } 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); | |
| 199 | 200 | self.install_path = self.install_prefix; |
| 200 | 201 | } |
| 201 | 202 | 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 { |
| 384 | 384 | const last_length = lengths[i - 1]; |
| 385 | 385 | const repeat = 3 + (try self.readBits(2)); |
| 386 | 386 | const last_index = i + repeat; |
| 387 | if (last_index > lengths.len) | |
| 388 | return error.InvalidLength; | |
| 387 | 389 | while (i < last_index) : (i += 1) { |
| 388 | 390 | lengths[i] = last_length; |
| 389 | 391 | } |
| ... | ... | @@ -655,3 +657,19 @@ pub fn InflateStream(comptime ReaderType: type) type { |
| 655 | 657 | pub fn inflateStream(reader: anytype, window_slice: []u8) InflateStream(@TypeOf(reader)) { |
| 656 | 658 | return InflateStream(@TypeOf(reader)).init(reader, window_slice); |
| 657 | 659 | } |
| 660 | ||
| 661 | test "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 { |
| 292 | 292 | return _carry128(&r); |
| 293 | 293 | } |
| 294 | 294 | |
| 295 | fn _sq(a: Fe, double: bool) callconv(.Inline) Fe { | |
| 295 | fn _sq(a: Fe, comptime double: bool) callconv(.Inline) Fe { | |
| 296 | 296 | var ax: [5]u128 = undefined; |
| 297 | 297 | var r: [5]u128 = undefined; |
| 298 | 298 | comptime var i = 0; |
lib/std/crypto/poly1305.zig+1-1| ... | ... | @@ -39,7 +39,7 @@ pub const Poly1305 = struct { |
| 39 | 39 | }; |
| 40 | 40 | } |
| 41 | 41 | |
| 42 | fn blocks(st: *Poly1305, m: []const u8, last: bool) void { | |
| 42 | fn blocks(st: *Poly1305, m: []const u8, comptime last: bool) void { | |
| 43 | 43 | const hibit: u64 = if (last) 0 else 1 << 40; |
| 44 | 44 | const r0 = st.r[0]; |
| 45 | 45 | const r1 = st.r[1]; |
lib/std/os.zig+6-4| ... | ... | @@ -1049,7 +1049,7 @@ pub const OpenError = error{ |
| 1049 | 1049 | } || UnexpectedError; |
| 1050 | 1050 | |
| 1051 | 1051 | /// Open and possibly create a file. Keeps trying if it gets interrupted. |
| 1052 | /// See also `openC`. | |
| 1052 | /// See also `openZ`. | |
| 1053 | 1053 | pub fn open(file_path: []const u8, flags: u32, perm: mode_t) OpenError!fd_t { |
| 1054 | 1054 | if (std.Target.current.os.tag == .windows) { |
| 1055 | 1055 | 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 |
| 1147 | 1147 | |
| 1148 | 1148 | /// Open and possibly create a file. Keeps trying if it gets interrupted. |
| 1149 | 1149 | /// `file_path` is relative to the open directory handle `dir_fd`. |
| 1150 | /// See also `openatC`. | |
| 1150 | /// See also `openatZ`. | |
| 1151 | 1151 | pub fn openat(dir_fd: fd_t, file_path: []const u8, flags: u32, mode: mode_t) OpenError!fd_t { |
| 1152 | 1152 | if (builtin.os.tag == .wasi) { |
| 1153 | 1153 | @compileError("use openatWasi instead"); |
| ... | ... | @@ -1754,7 +1754,7 @@ pub const UnlinkError = error{ |
| 1754 | 1754 | } || UnexpectedError; |
| 1755 | 1755 | |
| 1756 | 1756 | /// Delete a name and possibly the file it refers to. |
| 1757 | /// See also `unlinkC`. | |
| 1757 | /// See also `unlinkZ`. | |
| 1758 | 1758 | pub fn unlink(file_path: []const u8) UnlinkError!void { |
| 1759 | 1759 | if (builtin.os.tag == .wasi) { |
| 1760 | 1760 | @compileError("unlink is not supported in WASI; use unlinkat instead"); |
| ... | ... | @@ -3419,7 +3419,7 @@ pub fn fstat(fd: fd_t) FStatError!Stat { |
| 3419 | 3419 | } |
| 3420 | 3420 | } |
| 3421 | 3421 | |
| 3422 | pub const FStatAtError = FStatError || error{ NameTooLong, FileNotFound }; | |
| 3422 | pub const FStatAtError = FStatError || error{ NameTooLong, FileNotFound, SymLinkLoop }; | |
| 3423 | 3423 | |
| 3424 | 3424 | /// Similar to `fstat`, but returns stat of a resource pointed to by `pathname` |
| 3425 | 3425 | /// which is relative to `dirfd` handle. |
| ... | ... | @@ -3466,8 +3466,10 @@ pub fn fstatatZ(dirfd: fd_t, pathname: [*:0]const u8, flags: u32) FStatAtError!S |
| 3466 | 3466 | EBADF => unreachable, // Always a race condition. |
| 3467 | 3467 | ENOMEM => return error.SystemResources, |
| 3468 | 3468 | EACCES => return error.AccessDenied, |
| 3469 | EPERM => return error.AccessDenied, | |
| 3469 | 3470 | EFAULT => unreachable, |
| 3470 | 3471 | ENAMETOOLONG => return error.NameTooLong, |
| 3472 | ELOOP => return error.SymLinkLoop, | |
| 3471 | 3473 | ENOENT => return error.FileNotFound, |
| 3472 | 3474 | ENOTDIR => return error.FileNotFound, |
| 3473 | 3475 | else => |err| return unexpectedErrno(err), |
lib/std/special/build_runner.zig+3-3| ... | ... | @@ -82,9 +82,9 @@ pub fn main() !void { |
| 82 | 82 | builder.verbose = true; |
| 83 | 83 | } else if (mem.eql(u8, arg, "-h") or mem.eql(u8, arg, "--help")) { |
| 84 | 84 | 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")) { | |
| 86 | 86 | install_prefix = nextArg(args, &arg_idx) orelse { |
| 87 | warn("Expected argument after --prefix\n\n", .{}); | |
| 87 | warn("Expected argument after {s}\n\n", .{arg}); | |
| 88 | 88 | return usageAndErr(builder, false, stderr_stream); |
| 89 | 89 | }; |
| 90 | 90 | } else if (mem.eql(u8, arg, "--search-prefix")) { |
| ... | ... | @@ -188,7 +188,7 @@ fn usage(builder: *Builder, already_ran_build: bool, out_stream: anytype) !void |
| 188 | 188 | \\General Options: |
| 189 | 189 | \\ -h, --help Print this help and exit |
| 190 | 190 | \\ --verbose Print commands before executing them |
| 191 | \\ --prefix [path] Override default install prefix | |
| 191 | \\ -p, --prefix [path] Override default install prefix | |
| 192 | 192 | \\ --search-prefix [path] Add a path to look for binaries, libraries, headers |
| 193 | 193 | \\ --color [auto|off|on] Enable or disable colored error messages |
| 194 | 194 | \\ |
src/main.zig+1-1| ... | ... | @@ -687,7 +687,7 @@ fn buildOutputType( |
| 687 | 687 | extra_cflags.shrinkRetainingCapacity(0); |
| 688 | 688 | while (true) { |
| 689 | 689 | i += 1; |
| 690 | if (i + 1 >= args.len) fatal("expected -- after -cflags", .{}); | |
| 690 | if (i >= args.len) fatal("expected -- after -cflags", .{}); | |
| 691 | 691 | if (mem.eql(u8, args[i], "--")) break; |
| 692 | 692 | try extra_cflags.append(args[i]); |
| 693 | 693 | } |