authorgravatar for 37453713+ominitay@users.noreply.github.comominitay <37453713+ominitay@users.noreply.github.com> 2022-01-30 13:22:49+00:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-02-14 22:44:17+02:00
log7b938767bb18535a870d0460c9f4d9e3d93ab053
treef885eeb9b7a76e02a8fa1c086eb0cfa696a6819d
parent1e49d1fca89a0fce1604a8188257fa6ea2749338

std.os: throw compile error for `argv` on Windows

On Windows, `argv` is not populated by start code, and instead left as undefined. This is problematic, and can lead to incorrect programs compiling, but panicking when trying to access `argv`. This change causes these programs to produce a compile error on Windows instead, which is far preferable to a runtime panic.

1 files changed, 7 insertions(+), 3 deletions(-)

lib/std/os.zig+7-3
......@@ -218,9 +218,13 @@ pub const socket_t = if (builtin.os.tag == .windows) windows.ws2_32.SOCKET else
218218pub var environ: [][*:0]u8 = undefined;
219219
220220/// Populated by startup code before main().
221/// Not available on Windows. See `std.process.args`
222/// for obtaining the process arguments.
223pub var argv: [][*:0]u8 = undefined;
221/// Not available on WASI or Windows without libc. See `std.process.argsAlloc`
222/// or `std.process.argsWithAllocator` for a cross-platform alternative.
223pub var argv: [][*:0]u8 = if (builtin.link_libc) undefined else switch (builtin.os.tag) {
224 .windows => @compileError("argv isn't supported on Windows: use std.process.argsAlloc instead"),
225 .wasi => @compileError("argv isn't supported on WASI: use std.process.argsAlloc instead"),
226 else => undefined,
227};
224228
225229/// To obtain errno, call this function with the return value of the
226230/// system function call. For some systems this will obtain the value directly