authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-04-22 11:36:42-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-04-22 11:36:42-04:00
loge0b635e825b72e1308dd0e2bbee578dafe62d9dc
treeaa9bc22da7198c04a8b3d2cf1dea5280a21bb1cd
parent0cce115476628ad1bb266309225efa5714d56321

std.os.ChildProcess: fix closing wrong file descriptors


2 files changed, 20 insertions(+), 19 deletions(-)

std/os/child_process.zig+2-3
......@@ -66,10 +66,9 @@ pub const ChildProcess = struct {
6666 break;
6767 }
6868
69 // TODO oops!
7069 test (self.stdin) |*stdin| { stdin.close(); }
71 test (self.stdin) |*stdout| { stdout.close(); }
72 test (self.stdin) |*stderr| { stderr.close(); }
70 test (self.stdout) |*stdout| { stdout.close(); }
71 test (self.stderr) |*stderr| { stderr.close(); }
7372
7473 // Write @maxValue(ErrInt) to the write end of the err_pipe. This is after
7574 // waitpid, so this write is guaranteed to be after the child
test/tests.zig+18-16
......@@ -195,6 +195,12 @@ pub const CompareOutputContext = struct {
195195 debug.panic("Unable to spawn {}: {}\n", full_exe_path, @errorName(err));
196196 };
197197
198 var stdout = Buffer.initNull(b.allocator);
199 var stderr = Buffer.initNull(b.allocator);
200
201 %%(??child.stdout).readAll(&stdout);
202 %%(??child.stderr).readAll(&stderr);
203
198204 const term = child.wait() %% |err| {
199205 debug.panic("Unable to spawn {}: {}\n", full_exe_path, @errorName(err));
200206 };
......@@ -211,11 +217,6 @@ pub const CompareOutputContext = struct {
211217 },
212218 };
213219
214 var stdout = Buffer.initNull(b.allocator);
215 var stderr = Buffer.initNull(b.allocator);
216
217 %%(??child.stdout).readAll(&stdout);
218 %%(??child.stderr).readAll(&stderr);
219220
220221 if (!mem.eql(u8, self.expected_output, stdout.toSliceConst())) {
221222 %%io.stderr.printf(
......@@ -521,6 +522,12 @@ pub const CompileErrorContext = struct {
521522 debug.panic("Unable to spawn {}: {}\n", b.zig_exe, @errorName(err));
522523 };
523524
525 var stdout_buf = Buffer.initNull(b.allocator);
526 var stderr_buf = Buffer.initNull(b.allocator);
527
528 %%(??child.stdout).readAll(&stdout_buf);
529 %%(??child.stderr).readAll(&stderr_buf);
530
524531 const term = child.wait() %% |err| {
525532 debug.panic("Unable to spawn {}: {}\n", b.zig_exe, @errorName(err));
526533 };
......@@ -537,11 +544,6 @@ pub const CompileErrorContext = struct {
537544 },
538545 };
539546
540 var stdout_buf = Buffer.initNull(b.allocator);
541 var stderr_buf = Buffer.initNull(b.allocator);
542
543 %%(??child.stdout).readAll(&stdout_buf);
544 %%(??child.stderr).readAll(&stderr_buf);
545547
546548 const stdout = stdout_buf.toSliceConst();
547549 const stderr = stderr_buf.toSliceConst();
......@@ -783,6 +785,12 @@ pub const ParseHContext = struct {
783785 debug.panic("Unable to spawn {}: {}\n", b.zig_exe, @errorName(err));
784786 };
785787
788 var stdout_buf = Buffer.initNull(b.allocator);
789 var stderr_buf = Buffer.initNull(b.allocator);
790
791 %%(??child.stdout).readAll(&stdout_buf);
792 %%(??child.stderr).readAll(&stderr_buf);
793
786794 const term = child.wait() %% |err| {
787795 debug.panic("Unable to spawn {}: {}\n", b.zig_exe, @errorName(err));
788796 };
......@@ -803,12 +811,6 @@ pub const ParseHContext = struct {
803811 },
804812 };
805813
806 var stdout_buf = Buffer.initNull(b.allocator);
807 var stderr_buf = Buffer.initNull(b.allocator);
808
809 %%(??child.stdout).readAll(&stdout_buf);
810 %%(??child.stderr).readAll(&stderr_buf);
811
812814 const stdout = stdout_buf.toSliceConst();
813815 const stderr = stderr_buf.toSliceConst();
814816