Skip to content

Commit 2e5ba76

Browse files
committed
windows + mac fixes + shortening test code
1 parent 5772f92 commit 2e5ba76

File tree

1 file changed

+16
-29
lines changed

1 file changed

+16
-29
lines changed

test/standalone/childprocess_extrapipe/parent.zig

Lines changed: 16 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -9,30 +9,15 @@ const child_process = std.child_process;
99

1010
const windowsPtrDigits: usize = std.math.log10(math.maxInt(usize));
1111
const otherPtrDigits: usize = std.math.log10(math.maxInt(u32)) + 1; // +1 for sign
12-
const handleCharSize = size: {
13-
if (builtin.target.os.tag == .windows) {
14-
break :size windowsPtrDigits;
15-
} else {
16-
break :size otherPtrDigits;
17-
}
18-
};
12+
const handleCharSize = if (builtin.target.os.tag == .windows) windowsPtrDigits else otherPtrDigits;
1913

2014
/// assert: buf can store the handle
2115
fn handleToString(handle: os.fd_t, buf: []u8) std.fmt.BufPrintError![]u8 {
2216
var s_handle: []u8 = undefined;
23-
const handle_int = handle: {
24-
if (builtin.target.os.tag == .windows) {
25-
// handle is *anyopaque and there is no other way to cast
26-
break :handle @ptrToInt(handle);
27-
} else {
28-
break :handle handle;
29-
}
30-
};
31-
s_handle = try std.fmt.bufPrint(
32-
buf[0..],
33-
"{d}",
34-
.{handle_int},
35-
);
17+
const handle_int =
18+
// handle is *anyopaque or an integer on unix-likes Kernels.
19+
if (builtin.target.os.tag == .windows) @ptrToInt(handle) else handle;
20+
s_handle = try std.fmt.bufPrint(buf[0..], "{d}", .{handle_int});
3621
return s_handle;
3722
}
3823

@@ -54,19 +39,20 @@ pub fn main() !void {
5439
.bInheritHandle = windows.TRUE,
5540
.lpSecurityDescriptor = null,
5641
};
57-
try child_process.windowsMakeAsyncPipe(
58-
&pipe[0],
59-
&pipe[1],
60-
&saAttr,
61-
.parent_to_child,
62-
);
42+
try child_process.windowsMakeAsyncPipe(&pipe[0], &pipe[1], &saAttr, .parent_to_child);
6343
} else {
6444
pipe = try os.pipe(); // leaks on default
6545
}
6646

6747
// write pipe to string + add to command
6848
var buf: [handleCharSize]u8 = comptime [_]u8{0} ** handleCharSize;
69-
const s_handle = try handleToString(pipe[0], &buf); // read side of pipe
49+
50+
const s_handle =
51+
if (builtin.os.tag == .windows)
52+
try handleToString(pipe[0].?, &buf) // read side of pipe
53+
else
54+
try handleToString(pipe[0], &buf);
55+
7056
var child_proc = ChildProcess.init(
7157
&.{ child_path, s_handle },
7258
gpa,
@@ -76,8 +62,9 @@ pub fn main() !void {
7662
if (comptime builtin.target.isDarwin()) {
7763
{
7864
child_proc.posix_actions = try os.posix_spawn.Actions.init();
79-
errdefer os.posix_actions.Attr.deinit();
80-
try child_proc.posix_actions.close(pipe[0]);
65+
errdefer child_proc.posix_actions.?.deinit();
66+
try child_proc.posix_actions.?.close(pipe[0]);
67+
errdefer child_proc.posix_actions.?.deinit();
8168
}
8269
}
8370
defer if (comptime !builtin.target.isDarwin()) {

0 commit comments

Comments
 (0)