| author | |
| committer | |
| log | e2c04a46518f1c75076e642f56ae9d5bae3da3f3 |
| tree | 8c2c5bd3a71aa4a0c06eda4d0ef9e78173d4eabe |
| parent | 2fee64ceb08328ccc9f98879a544eae971248493 |
10 files changed, 41 insertions(+), 52 deletions(-)
lib/compiler/resinator/main.zig+1-1| ... | @@ -633,7 +633,7 @@ fn getIncludePaths( | ... | @@ -633,7 +633,7 @@ fn getIncludePaths( |
| 633 | }; | 633 | }; |
| 634 | const target = std.zig.resolveTargetQueryOrFatal(io, target_query); | 634 | const target = std.zig.resolveTargetQueryOrFatal(io, target_query); |
| 635 | const is_native_abi = target_query.isNativeAbi(); | 635 | const is_native_abi = target_query.isNativeAbi(); |
| 636 | const detected_libc = std.zig.LibCDirs.detect(arena, io, zig_lib_dir, &target, is_native_abi, true, null) catch { | 636 | const detected_libc = std.zig.LibCDirs.detect(arena, io, zig_lib_dir, &target, is_native_abi, true, null, environ_map) catch { |
| 637 | if (includes == .any) { | 637 | if (includes == .any) { |
| 638 | // fall back to mingw | 638 | // fall back to mingw |
| 639 | includes = .gnu; | 639 | includes = .gnu; |
lib/std/process/Environ.zig+5-2| ... | @@ -542,14 +542,17 @@ pub fn getPosix(environ: Environ, key: []const u8) ?[:0]const u8 { | ... | @@ -542,14 +542,17 @@ pub fn getPosix(environ: Environ, key: []const u8) ?[:0]const u8 { |
| 542 | /// * `contains` | 542 | /// * `contains` |
| 543 | pub fn getWindows(environ: Environ, key: [*:0]const u16) ?[:0]const u16 { | 543 | pub fn getWindows(environ: Environ, key: [*:0]const u16) ?[:0]const u16 { |
| 544 | comptime assert(native_os == .windows); | 544 | comptime assert(native_os == .windows); |
| 545 | comptime assert(@TypeOf(environ.block) == void); | ||
| 545 | 546 | ||
| 546 | // '=' anywhere but the start makes this an invalid environment variable name. | 547 | // '=' anywhere but the start makes this an invalid environment variable name. |
| 547 | const key_slice = mem.sliceTo(key, 0); | 548 | const key_slice = mem.sliceTo(key, 0); |
| 548 | if (key_slice.len > 0 and mem.findScalar(u16, key_slice[1..], '=') != null) return null; | 549 | if (key_slice.len > 0 and mem.findScalar(u16, key_slice[1..], '=') != null) return null; |
| 549 | 550 | ||
| 551 | const ptr = std.os.windows.peb().ProcessParameters.Environment; | ||
| 552 | |||
| 550 | var i: usize = 0; | 553 | var i: usize = 0; |
| 551 | while (environ.block[i] != 0) { | 554 | while (ptr[i] != 0) { |
| 552 | const key_value = mem.sliceTo(environ.block[i..], 0); | 555 | const key_value = mem.sliceTo(ptr[i..], 0); |
| 553 | 556 | ||
| 554 | // There are some special environment variables that start with =, | 557 | // There are some special environment variables that start with =, |
| 555 | // so we need a special case to not treat = as a key/value separator | 558 | // so we need a special case to not treat = as a key/value separator |
test/standalone/windows_argv/fuzz.zig+10-14| ... | @@ -3,19 +3,15 @@ const builtin = @import("builtin"); | ... | @@ -3,19 +3,15 @@ const builtin = @import("builtin"); |
| 3 | const windows = std.os.windows; | 3 | const windows = std.os.windows; |
| 4 | const Allocator = std.mem.Allocator; | 4 | const Allocator = std.mem.Allocator; |
| 5 | 5 | ||
| 6 | pub fn main() !void { | 6 | pub fn main(init: std.process.Init) !void { |
| 7 | var gpa: std.heap.GeneralPurposeAllocator(.{}) = .init; | 7 | const gpa = init.gpa; |
| 8 | defer std.debug.assert(gpa.deinit() == .ok); | 8 | const args = try init.minimal.args.toSlice(init.arena.allocator()); |
| 9 | const allocator = gpa.allocator(); | ||
| 10 | |||
| 11 | const args = try std.process.argsAlloc(allocator); | ||
| 12 | defer std.process.argsFree(allocator, args); | ||
| 13 | 9 | ||
| 14 | if (args.len < 2) return error.MissingArgs; | 10 | if (args.len < 2) return error.MissingArgs; |
| 15 | 11 | ||
| 16 | const verify_path_wtf8 = args[1]; | 12 | const verify_path_wtf8 = args[1]; |
| 17 | const verify_path_w = try std.unicode.wtf8ToWtf16LeAllocZ(allocator, verify_path_wtf8); | 13 | const verify_path_w = try std.unicode.wtf8ToWtf16LeAllocZ(gpa, verify_path_wtf8); |
| 18 | defer allocator.free(verify_path_w); | 14 | defer gpa.free(verify_path_w); |
| 19 | 15 | ||
| 20 | const iterations: u64 = iterations: { | 16 | const iterations: u64 = iterations: { |
| 21 | if (args.len < 3) break :iterations 0; | 17 | if (args.len < 3) break :iterations 0; |
| ... | @@ -41,14 +37,14 @@ pub fn main() !void { | ... | @@ -41,14 +37,14 @@ pub fn main() !void { |
| 41 | std.debug.print("rand seed: {}\n", .{seed}); | 37 | std.debug.print("rand seed: {}\n", .{seed}); |
| 42 | } | 38 | } |
| 43 | 39 | ||
| 44 | var cmd_line_w_buf = std.array_list.Managed(u16).init(allocator); | 40 | var cmd_line_w_buf = std.array_list.Managed(u16).init(gpa); |
| 45 | defer cmd_line_w_buf.deinit(); | 41 | defer cmd_line_w_buf.deinit(); |
| 46 | 42 | ||
| 47 | var i: u64 = 0; | 43 | var i: u64 = 0; |
| 48 | var errors: u64 = 0; | 44 | var errors: u64 = 0; |
| 49 | while (iterations == 0 or i < iterations) { | 45 | while (iterations == 0 or i < iterations) { |
| 50 | const cmd_line_w = try randomCommandLineW(allocator, rand); | 46 | const cmd_line_w = try randomCommandLineW(gpa, rand); |
| 51 | defer allocator.free(cmd_line_w); | 47 | defer gpa.free(cmd_line_w); |
| 52 | 48 | ||
| 53 | // avoid known difference for 0-length command lines | 49 | // avoid known difference for 0-length command lines |
| 54 | if (cmd_line_w.len == 0 or cmd_line_w[0] == '\x00') continue; | 50 | if (cmd_line_w.len == 0 or cmd_line_w[0] == '\x00') continue; |
| ... | @@ -56,8 +52,8 @@ pub fn main() !void { | ... | @@ -56,8 +52,8 @@ pub fn main() !void { |
| 56 | const exit_code = try spawnVerify(verify_path_w, cmd_line_w); | 52 | const exit_code = try spawnVerify(verify_path_w, cmd_line_w); |
| 57 | if (exit_code != 0) { | 53 | if (exit_code != 0) { |
| 58 | std.debug.print(">>> found discrepancy <<<\n", .{}); | 54 | std.debug.print(">>> found discrepancy <<<\n", .{}); |
| 59 | const cmd_line_wtf8 = try std.unicode.wtf16LeToWtf8Alloc(allocator, cmd_line_w); | 55 | const cmd_line_wtf8 = try std.unicode.wtf16LeToWtf8Alloc(gpa, cmd_line_w); |
| 60 | defer allocator.free(cmd_line_wtf8); | 56 | defer gpa.free(cmd_line_wtf8); |
| 61 | std.debug.print("\"{f}\"\n\n", .{std.zig.fmtString(cmd_line_wtf8)}); | 57 | std.debug.print("\"{f}\"\n\n", .{std.zig.fmtString(cmd_line_wtf8)}); |
| 62 | 58 | ||
| 63 | errors += 1; | 59 | errors += 1; |
test/standalone/windows_argv/lib.zig+5-2| ... | @@ -5,7 +5,7 @@ export fn verify(argc: c_int, argv: [*]const [*:0]const u16) c_int { | ... | @@ -5,7 +5,7 @@ export fn verify(argc: c_int, argv: [*]const [*:0]const u16) c_int { |
| 5 | const argv_slice = argv[0..@intCast(argc)]; | 5 | const argv_slice = argv[0..@intCast(argc)]; |
| 6 | testArgv(argv_slice) catch |err| switch (err) { | 6 | testArgv(argv_slice) catch |err| switch (err) { |
| 7 | error.OutOfMemory => @panic("oom"), | 7 | error.OutOfMemory => @panic("oom"), |
| 8 | error.Overflow => @panic("bytes needed to contain args would overflow usize"), | 8 | error.Unexpected => @panic("unexpected error"), |
| 9 | error.ArgvMismatch => return 0, | 9 | error.ArgvMismatch => return 0, |
| 10 | }; | 10 | }; |
| 11 | return 1; | 11 | return 1; |
| ... | @@ -16,7 +16,10 @@ fn testArgv(expected_args: []const [*:0]const u16) !void { | ... | @@ -16,7 +16,10 @@ fn testArgv(expected_args: []const [*:0]const u16) !void { |
| 16 | defer arena_state.deinit(); | 16 | defer arena_state.deinit(); |
| 17 | const allocator = arena_state.allocator(); | 17 | const allocator = arena_state.allocator(); |
| 18 | 18 | ||
| 19 | const args = try std.process.argsAlloc(allocator); | 19 | const cmd_line = std.os.windows.peb().ProcessParameters.CommandLine; |
| 20 | const cmd_line_w = cmd_line.Buffer.?[0..@divExact(cmd_line.Length, 2)]; | ||
| 21 | const raw_args: std.process.Args = .{ .vector = cmd_line_w }; | ||
| 22 | const args = try raw_args.toSlice(allocator); | ||
| 20 | var wtf8_buf = std.array_list.Managed(u8).init(allocator); | 23 | var wtf8_buf = std.array_list.Managed(u8).init(allocator); |
| 21 | 24 | ||
| 22 | var eql = true; | 25 | var eql = true; |
test/standalone/windows_bat_args/echo-args.zig+4-7| ... | @@ -1,15 +1,12 @@ | ... | @@ -1,15 +1,12 @@ |
| 1 | const std = @import("std"); | 1 | const std = @import("std"); |
| 2 | 2 | ||
| 3 | pub fn main() !void { | 3 | pub fn main(init: std.process.Init) !void { |
| 4 | var arena_state = std.heap.ArenaAllocator.init(std.heap.page_allocator); | 4 | const arena = init.arena.allocator(); |
| 5 | defer arena_state.deinit(); | 5 | const io = init.io; |
| 6 | const arena = arena_state.allocator(); | 6 | const args = try init.minimal.args.toSlice(arena); |
| 7 | |||
| 8 | const io = std.Options.debug_io; | ||
| 9 | 7 | ||
| 10 | var stdout_writer = std.Io.File.stdout().writerStreaming(io, &.{}); | 8 | var stdout_writer = std.Io.File.stdout().writerStreaming(io, &.{}); |
| 11 | const stdout = &stdout_writer.interface; | 9 | const stdout = &stdout_writer.interface; |
| 12 | var args = try std.process.argsAlloc(arena); | ||
| 13 | for (args[1..], 1..) |arg, i| { | 10 | for (args[1..], 1..) |arg, i| { |
| 14 | try stdout.writeAll(arg); | 11 | try stdout.writeAll(arg); |
| 15 | if (i != args.len - 1) try stdout.writeByte('\x00'); | 12 | if (i != args.len - 1) try stdout.writeByte('\x00'); |
test/standalone/windows_bat_args/fuzz.zig+1-1| ... | @@ -8,7 +8,7 @@ pub fn main(init: std.process.Init) !void { | ... | @@ -8,7 +8,7 @@ pub fn main(init: std.process.Init) !void { |
| 8 | const gpa = init.gpa; | 8 | const gpa = init.gpa; |
| 9 | const io = init.io; | 9 | const io = init.io; |
| 10 | 10 | ||
| 11 | var it = try init.minimal.argsAllocator(gpa); | 11 | var it = try init.minimal.args.iterateAllocator(gpa); |
| 12 | defer it.deinit(); | 12 | defer it.deinit(); |
| 13 | _ = it.next() orelse unreachable; // skip binary name | 13 | _ = it.next() orelse unreachable; // skip binary name |
| 14 | const child_exe_path_orig = it.next() orelse unreachable; | 14 | const child_exe_path_orig = it.next() orelse unreachable; |
test/standalone/windows_bat_args/test.zig+2-2| ... | @@ -6,7 +6,7 @@ pub fn main(init: std.process.Init) !void { | ... | @@ -6,7 +6,7 @@ pub fn main(init: std.process.Init) !void { |
| 6 | const gpa = init.gpa; | 6 | const gpa = init.gpa; |
| 7 | const io = init.io; | 7 | const io = init.io; |
| 8 | 8 | ||
| 9 | var it = try init.minimal.argsAllocator(gpa); | 9 | var it = try init.minimal.args.iterateAllocator(gpa); |
| 10 | defer it.deinit(); | 10 | defer it.deinit(); |
| 11 | _ = it.next() orelse unreachable; // skip binary name | 11 | _ = it.next() orelse unreachable; // skip binary name |
| 12 | const child_exe_path_orig = it.next() orelse unreachable; | 12 | const child_exe_path_orig = it.next() orelse unreachable; |
| ... | @@ -105,7 +105,7 @@ pub fn main(init: std.process.Init) !void { | ... | @@ -105,7 +105,7 @@ pub fn main(init: std.process.Init) !void { |
| 105 | try std.testing.expectError(error.FileNotFound, testExecBat(gpa, io, absolute_with_trailing, &.{"abc"}, null)); | 105 | try std.testing.expectError(error.FileNotFound, testExecBat(gpa, io, absolute_with_trailing, &.{"abc"}, null)); |
| 106 | 106 | ||
| 107 | var env = env: { | 107 | var env = env: { |
| 108 | var env = try std.process.getEnvMap(gpa); | 108 | var env = try init.environ_map.clone(gpa); |
| 109 | errdefer env.deinit(); | 109 | errdefer env.deinit(); |
| 110 | // No escaping | 110 | // No escaping |
| 111 | try env.put("FOO", "123"); | 111 | try env.put("FOO", "123"); |
test/standalone/windows_paths/relative.zig+6-13| ... | @@ -1,21 +1,14 @@ | ... | @@ -1,21 +1,14 @@ |
| 1 | const std = @import("std"); | 1 | const std = @import("std"); |
| 2 | 2 | ||
| 3 | pub fn main() !void { | 3 | pub fn main(init: std.process.Init) !void { |
| 4 | var gpa: std.heap.GeneralPurposeAllocator(.{}) = .init; | 4 | const arena = init.arena.allocator(); |
| 5 | defer std.debug.assert(gpa.deinit() == .ok); | 5 | const args = try init.minimal.args.toSlice(arena); |
| 6 | const allocator = gpa.allocator(); | 6 | const io = init.io; |
| 7 | 7 | const cwd_path = try std.process.getCwdAlloc(arena); | |
| 8 | const args = try std.process.argsAlloc(allocator); | ||
| 9 | defer std.process.argsFree(allocator, args); | ||
| 10 | 8 | ||
| 11 | if (args.len < 3) return error.MissingArgs; | 9 | if (args.len < 3) return error.MissingArgs; |
| 12 | 10 | ||
| 13 | var threaded: std.Io.Threaded = .init(allocator, .{}); | 11 | const relative = try std.fs.path.relative(arena, cwd_path, init.environ_map, args[1], args[2]); |
| 14 | defer threaded.deinit(); | ||
| 15 | const io = threaded.io(); | ||
| 16 | |||
| 17 | const relative = try std.fs.path.relative(allocator, args[1], args[2]); | ||
| 18 | defer allocator.free(relative); | ||
| 19 | 12 | ||
| 20 | var stdout_writer = std.Io.File.stdout().writerStreaming(io, &.{}); | 13 | var stdout_writer = std.Io.File.stdout().writerStreaming(io, &.{}); |
| 21 | const stdout = &stdout_writer.interface; | 14 | const stdout = &stdout_writer.interface; |
test/standalone/windows_paths/test.zig+4-8| ... | @@ -1,17 +1,13 @@ | ... | @@ -1,17 +1,13 @@ |
| 1 | const std = @import("std"); | 1 | const std = @import("std"); |
| 2 | const Io = std.Io; | 2 | const Io = std.Io; |
| 3 | 3 | ||
| 4 | pub fn main() anyerror!void { | 4 | pub fn main(init: std.process.Init) !void { |
| 5 | var arena_state = std.heap.ArenaAllocator.init(std.heap.page_allocator); | 5 | const arena = init.arena.allocator(); |
| 6 | defer arena_state.deinit(); | 6 | const args = try init.minimal.args.toSlice(arena); |
| 7 | const arena = arena_state.allocator(); | 7 | const io = init.io; |
| 8 | |||
| 9 | const args = try std.process.argsAlloc(arena); | ||
| 10 | 8 | ||
| 11 | if (args.len < 2) return error.MissingArgs; | 9 | if (args.len < 2) return error.MissingArgs; |
| 12 | 10 | ||
| 13 | const io = std.Io.Threaded.global_single_threaded.ioBasic(); | ||
| 14 | |||
| 15 | const exe_path = args[1]; | 11 | const exe_path = args[1]; |
| 16 | 12 | ||
| 17 | const cwd_path = try std.process.getCwdAlloc(arena); | 13 | const cwd_path = try std.process.getCwdAlloc(arena); |
test/standalone/windows_spawn/main.zig+3-2| ... | @@ -8,8 +8,9 @@ const utf16Literal = std.unicode.utf8ToUtf16LeStringLiteral; | ... | @@ -8,8 +8,9 @@ const utf16Literal = std.unicode.utf8ToUtf16LeStringLiteral; |
| 8 | pub fn main(init: std.process.Init) !void { | 8 | pub fn main(init: std.process.Init) !void { |
| 9 | const gpa = init.gpa; | 9 | const gpa = init.gpa; |
| 10 | const io = init.io; | 10 | const io = init.io; |
| 11 | const process_cwd_path = try std.process.getCwdAlloc(init.arena.allocator()); | ||
| 11 | 12 | ||
| 12 | var it = try init.minimal.argsAllocator(gpa); | 13 | var it = try init.minimal.args.iterateAllocator(gpa); |
| 13 | defer it.deinit(); | 14 | defer it.deinit(); |
| 14 | _ = it.next() orelse unreachable; // skip binary name | 15 | _ = it.next() orelse unreachable; // skip binary name |
| 15 | const hello_exe_cache_path = it.next() orelse unreachable; | 16 | const hello_exe_cache_path = it.next() orelse unreachable; |
| ... | @@ -23,7 +24,7 @@ pub fn main(init: std.process.Init) !void { | ... | @@ -23,7 +24,7 @@ pub fn main(init: std.process.Init) !void { |
| 23 | defer gpa.free(tmp_absolute_path_w); | 24 | defer gpa.free(tmp_absolute_path_w); |
| 24 | const cwd_absolute_path = try Io.Dir.cwd().realPathFileAlloc(io, ".", gpa); | 25 | const cwd_absolute_path = try Io.Dir.cwd().realPathFileAlloc(io, ".", gpa); |
| 25 | defer gpa.free(cwd_absolute_path); | 26 | defer gpa.free(cwd_absolute_path); |
| 26 | const tmp_relative_path = try std.fs.path.relative(gpa, cwd_absolute_path, tmp_absolute_path); | 27 | const tmp_relative_path = try std.fs.path.relative(gpa, process_cwd_path, init.environ_map, cwd_absolute_path, tmp_absolute_path); |
| 27 | defer gpa.free(tmp_relative_path); | 28 | defer gpa.free(tmp_relative_path); |
| 28 | 29 | ||
| 29 | // Clear PATH | 30 | // Clear PATH |