zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit e0b635e825b72e1308dd0e2bbee578dafe62d9dc (tree)
parent 0cce115476628ad1bb266309225efa5714d56321
Author: Andrew Kelley <superjoe30@gmail.com>
Date:   Sat, 22 Apr 2017 11:36:42 -0400

std.os.ChildProcess: fix closing wrong file descriptors

Diffstat:
Mstd/os/child_process.zig | 5++---
Mtest/tests.zig | 34++++++++++++++++++----------------
2 files changed, 20 insertions(+), 19 deletions(-)

diff --git a/std/os/child_process.zig b/std/os/child_process.zig @@ -66,10 +66,9 @@ pub const ChildProcess = struct { break; } - // TODO oops! test (self.stdin) |*stdin| { stdin.close(); } - test (self.stdin) |*stdout| { stdout.close(); } - test (self.stdin) |*stderr| { stderr.close(); } + test (self.stdout) |*stdout| { stdout.close(); } + test (self.stderr) |*stderr| { stderr.close(); } // Write @maxValue(ErrInt) to the write end of the err_pipe. This is after // waitpid, so this write is guaranteed to be after the child diff --git a/test/tests.zig b/test/tests.zig @@ -195,6 +195,12 @@ pub const CompareOutputContext = struct { debug.panic("Unable to spawn {}: {}\n", full_exe_path, @errorName(err)); }; + var stdout = Buffer.initNull(b.allocator); + var stderr = Buffer.initNull(b.allocator); + + %%(??child.stdout).readAll(&stdout); + %%(??child.stderr).readAll(&stderr); + const term = child.wait() %% |err| { debug.panic("Unable to spawn {}: {}\n", full_exe_path, @errorName(err)); }; @@ -211,11 +217,6 @@ pub const CompareOutputContext = struct { }, }; - var stdout = Buffer.initNull(b.allocator); - var stderr = Buffer.initNull(b.allocator); - - %%(??child.stdout).readAll(&stdout); - %%(??child.stderr).readAll(&stderr); if (!mem.eql(u8, self.expected_output, stdout.toSliceConst())) { %%io.stderr.printf( @@ -521,6 +522,12 @@ pub const CompileErrorContext = struct { debug.panic("Unable to spawn {}: {}\n", b.zig_exe, @errorName(err)); }; + var stdout_buf = Buffer.initNull(b.allocator); + var stderr_buf = Buffer.initNull(b.allocator); + + %%(??child.stdout).readAll(&stdout_buf); + %%(??child.stderr).readAll(&stderr_buf); + const term = child.wait() %% |err| { debug.panic("Unable to spawn {}: {}\n", b.zig_exe, @errorName(err)); }; @@ -537,11 +544,6 @@ pub const CompileErrorContext = struct { }, }; - var stdout_buf = Buffer.initNull(b.allocator); - var stderr_buf = Buffer.initNull(b.allocator); - - %%(??child.stdout).readAll(&stdout_buf); - %%(??child.stderr).readAll(&stderr_buf); const stdout = stdout_buf.toSliceConst(); const stderr = stderr_buf.toSliceConst(); @@ -783,6 +785,12 @@ pub const ParseHContext = struct { debug.panic("Unable to spawn {}: {}\n", b.zig_exe, @errorName(err)); }; + var stdout_buf = Buffer.initNull(b.allocator); + var stderr_buf = Buffer.initNull(b.allocator); + + %%(??child.stdout).readAll(&stdout_buf); + %%(??child.stderr).readAll(&stderr_buf); + const term = child.wait() %% |err| { debug.panic("Unable to spawn {}: {}\n", b.zig_exe, @errorName(err)); }; @@ -803,12 +811,6 @@ pub const ParseHContext = struct { }, }; - var stdout_buf = Buffer.initNull(b.allocator); - var stderr_buf = Buffer.initNull(b.allocator); - - %%(??child.stdout).readAll(&stdout_buf); - %%(??child.stderr).readAll(&stderr_buf); - const stdout = stdout_buf.toSliceConst(); const stderr = stderr_buf.toSliceConst();