diff options
| author | Andrew Kelley <superjoe30@gmail.com> | 2017-10-15 16:03:32 -0400 |
|---|---|---|
| committer | Andrew Kelley <superjoe30@gmail.com> | 2017-10-15 16:03:32 -0400 |
| commit | bb169a7b36a658ed463787655df54e3f59133d98 (patch) | |
| tree | 773587c8f8d31ff2d892d37ad8bcc3f6e1d319a5 /std | |
| parent | 1fe1e6eeaf2f6157133546d49be6b0e0c1da3dd3 (diff) | |
| download | zig-bb169a7b36a658ed463787655df54e3f59133d98.tar.gz zig-bb169a7b36a658ed463787655df54e3f59133d98.zip | |
fix child process stdio piping behavior on windows
Diffstat (limited to 'std')
| -rw-r--r-- | std/io.zig | 2 | ||||
| -rw-r--r-- | std/os/child_process.zig | 21 | ||||
| -rw-r--r-- | std/os/windows/index.zig | 2 |
3 files changed, 16 insertions, 9 deletions
diff --git a/std/io.zig b/std/io.zig index dc396834e9..54cefb804c 100644 --- a/std/io.zig +++ b/std/io.zig @@ -313,8 +313,8 @@ pub const InStream = struct { else => error.Unexpected, }; } - if (amt_read == 0) return index; index += amt_read; + if (amt_read < want_read_count) return index; } return index; } else { diff --git a/std/os/child_process.zig b/std/os/child_process.zig index 7e4348fb1b..9a7a295069 100644 --- a/std/os/child_process.zig +++ b/std/os/child_process.zig @@ -433,7 +433,7 @@ pub const ChildProcess = struct { } fn spawnWindows(self: &ChildProcess) -> %void { - var saAttr = windows.SECURITY_ATTRIBUTES { + const saAttr = windows.SECURITY_ATTRIBUTES { .nLength = @sizeOf(windows.SECURITY_ATTRIBUTES), .bInheritHandle = windows.TRUE, .lpSecurityDescriptor = null, @@ -459,7 +459,7 @@ pub const ChildProcess = struct { var g_hChildStd_IN_Wr: ?windows.HANDLE = null; switch (self.stdin_behavior) { StdIo.Pipe => { - %return windowsMakePipeIn(&g_hChildStd_IN_Rd, &g_hChildStd_IN_Wr, &saAttr); + %return windowsMakePipeIn(&g_hChildStd_IN_Rd, &g_hChildStd_IN_Wr, saAttr); }, StdIo.Ignore => { g_hChildStd_IN_Rd = nul_handle; @@ -477,7 +477,7 @@ pub const ChildProcess = struct { var g_hChildStd_OUT_Wr: ?windows.HANDLE = null; switch (self.stdout_behavior) { StdIo.Pipe => { - %return windowsMakePipeOut(&g_hChildStd_OUT_Rd, &g_hChildStd_OUT_Wr, &saAttr); + %return windowsMakePipeOut(&g_hChildStd_OUT_Rd, &g_hChildStd_OUT_Wr, saAttr); }, StdIo.Ignore => { g_hChildStd_OUT_Wr = nul_handle; @@ -495,7 +495,7 @@ pub const ChildProcess = struct { var g_hChildStd_ERR_Wr: ?windows.HANDLE = null; switch (self.stderr_behavior) { StdIo.Pipe => { - %return windowsMakePipeOut(&g_hChildStd_ERR_Rd, &g_hChildStd_ERR_Wr, &saAttr); + %return windowsMakePipeOut(&g_hChildStd_ERR_Rd, &g_hChildStd_ERR_Wr, saAttr); }, StdIo.Ignore => { g_hChildStd_ERR_Wr = nul_handle; @@ -675,7 +675,12 @@ fn windowsDestroyPipe(rd: ?windows.HANDLE, wr: ?windows.HANDLE) { if (wr) |h| os.windowsClose(h); } -fn windowsMakePipe(rd: &windows.HANDLE, wr: &windows.HANDLE, sattr: &windows.SECURITY_ATTRIBUTES) -> %void { + +// TODO: workaround for bug where the `const` from `&const` is dropped when the type is +// a namespace field lookup +const SECURITY_ATTRIBUTES = windows.SECURITY_ATTRIBUTES; + +fn windowsMakePipe(rd: &windows.HANDLE, wr: &windows.HANDLE, sattr: &const SECURITY_ATTRIBUTES) -> %void { if (windows.CreatePipe(rd, wr, sattr, 0) == 0) { const err = windows.GetLastError(); return switch (err) { @@ -693,19 +698,21 @@ fn windowsSetHandleInfo(h: windows.HANDLE, mask: windows.DWORD, flags: windows.D } } -fn windowsMakePipeIn(rd: &?windows.HANDLE, wr: &?windows.HANDLE, sattr: &windows.SECURITY_ATTRIBUTES) -> %void { +fn windowsMakePipeIn(rd: &?windows.HANDLE, wr: &?windows.HANDLE, sattr: &const SECURITY_ATTRIBUTES) -> %void { var rd_h: windows.HANDLE = undefined; var wr_h: windows.HANDLE = undefined; %return windowsMakePipe(&rd_h, &wr_h, sattr); + %defer windowsDestroyPipe(rd_h, wr_h); %return windowsSetHandleInfo(wr_h, windows.HANDLE_FLAG_INHERIT, 0); *rd = rd_h; *wr = wr_h; } -fn windowsMakePipeOut(rd: &?windows.HANDLE, wr: &?windows.HANDLE, sattr: &windows.SECURITY_ATTRIBUTES) -> %void { +fn windowsMakePipeOut(rd: &?windows.HANDLE, wr: &?windows.HANDLE, sattr: &const SECURITY_ATTRIBUTES) -> %void { var rd_h: windows.HANDLE = undefined; var wr_h: windows.HANDLE = undefined; %return windowsMakePipe(&rd_h, &wr_h, sattr); + %defer windowsDestroyPipe(rd_h, wr_h); %return windowsSetHandleInfo(rd_h, windows.HANDLE_FLAG_INHERIT, 0); *rd = rd_h; *wr = wr_h; diff --git a/std/os/windows/index.zig b/std/os/windows/index.zig index 290953a5da..a398deb0b3 100644 --- a/std/os/windows/index.zig +++ b/std/os/windows/index.zig @@ -18,7 +18,7 @@ pub extern "kernel32" stdcallcc fn CreateFileA(lpFileName: LPCSTR, dwDesiredAcce dwFlagsAndAttributes: DWORD, hTemplateFile: ?HANDLE) -> HANDLE; pub extern "kernel32" stdcallcc fn CreatePipe(hReadPipe: &HANDLE, hWritePipe: &HANDLE, - lpPipeAttributes: &SECURITY_ATTRIBUTES, nSize: DWORD) -> BOOL; + lpPipeAttributes: &const SECURITY_ATTRIBUTES, nSize: DWORD) -> BOOL; pub extern "kernel32" stdcallcc fn CreateProcessA(lpApplicationName: ?LPCSTR, lpCommandLine: LPSTR, lpProcessAttributes: ?&SECURITY_ATTRIBUTES, lpThreadAttributes: ?&SECURITY_ATTRIBUTES, bInheritHandles: BOOL, |
