authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-10-21 13:55:26-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-10-29 06:20:51-07:00
log00a3123fbe79d9bb74b2c877130579299d2ba5ba
treed4a5b531f5d255abe903e3e0c7cb565a0a2245c0
parentab003cd0545e54e66410b8e67136d4ef079b3198

std.process.Child: update for std.Io changes


3 files changed, 22 insertions(+), 16 deletions(-)

lib/std/Io/Threaded.zig+9-10
......@@ -211,7 +211,6 @@ pub fn io(t: *Threaded) Io {
211211 else => dirOpenFilePosix,
212212 },
213213 .dirOpenDir = switch (builtin.os.tag) {
214 .windows => dirOpenDirWindows,
215214 .wasi => dirOpenDirWasi,
216215 .haiku => dirOpenDirHaiku,
217216 else => dirOpenDirPosix,
......@@ -2035,6 +2034,11 @@ fn dirOpenDirPosix(
20352034) Io.Dir.OpenError!Io.Dir {
20362035 const t: *Threaded = @ptrCast(@alignCast(userdata));
20372036
2037 if (is_windows) {
2038 const sub_path_w = try windows.sliceToPrefixedFileW(dir.handle, sub_path);
2039 return dirOpenDirWindows(t, dir, sub_path_w.span(), options);
2040 }
2041
20382042 var path_buffer: [posix.PATH_MAX]u8 = undefined;
20392043 const sub_path_posix = try pathToPosix(sub_path, &path_buffer);
20402044
......@@ -2123,19 +2127,13 @@ fn dirOpenDirHaiku(
21232127 }
21242128}
21252129
2126fn dirOpenDirWindows(
2127 userdata: ?*anyopaque,
2130pub fn dirOpenDirWindows(
2131 t: *Io.Threaded,
21282132 dir: Io.Dir,
2129 sub_path: []const u8,
2133 sub_path_w: [:0]const u16,
21302134 options: Io.Dir.OpenOptions,
21312135) Io.Dir.OpenError!Io.Dir {
2132 const t: *Threaded = @ptrCast(@alignCast(userdata));
2133 try t.checkCancel();
2134
21352136 const w = windows;
2136 const sub_path_w_array = try w.sliceToPrefixedFileW(dir.handle, sub_path);
2137 const sub_path_w = sub_path_w_array.span();
2138
21392137 // TODO remove some of these flags if options.access_sub_paths is false
21402138 const base_flags = w.STANDARD_RIGHTS_READ | w.FILE_READ_ATTRIBUTES | w.FILE_READ_EA |
21412139 w.SYNCHRONIZE | w.FILE_TRAVERSE;
......@@ -2158,6 +2156,7 @@ fn dirOpenDirWindows(
21582156 const open_reparse_point: w.DWORD = if (!options.follow_symlinks) w.FILE_OPEN_REPARSE_POINT else 0x0;
21592157 var io_status_block: w.IO_STATUS_BLOCK = undefined;
21602158 var result: Io.Dir = .{ .handle = undefined };
2159 try t.checkCancel();
21612160 const rc = w.ntdll.NtCreateFile(
21622161 &result.handle,
21632162 access_mask,
lib/std/posix.zig+1-2
......@@ -3769,7 +3769,6 @@ pub fn connect(sock: socket_t, sock_addr: *const sockaddr, len: socklen_t) Conne
37693769 .SUCCESS => return,
37703770 .ACCES => return error.AccessDenied,
37713771 .PERM => return error.PermissionDenied,
3772 .ADDRINUSE => return error.AddressInUse,
37733772 .ADDRNOTAVAIL => return error.AddressUnavailable,
37743773 .AFNOSUPPORT => return error.AddressFamilyUnsupported,
37753774 .AGAIN, .INPROGRESS => return error.WouldBlock,
......@@ -3779,7 +3778,7 @@ pub fn connect(sock: socket_t, sock_addr: *const sockaddr, len: socklen_t) Conne
37793778 .CONNRESET => return error.ConnectionResetByPeer,
37803779 .FAULT => unreachable, // The socket structure address is outside the user's address space.
37813780 .INTR => continue,
3782 .ISCONN => return error.AlreadyConnected, // The socket is already connected.
3781 .ISCONN => @panic("AlreadyConnected"), // The socket is already connected.
37833782 .HOSTUNREACH => return error.NetworkUnreachable,
37843783 .NETUNREACH => return error.NetworkUnreachable,
37853784 .NOTSOCK => unreachable, // The file descriptor sockfd does not refer to a socket.
lib/std/process/Child.zig+12-4
......@@ -1084,16 +1084,24 @@ fn windowsCreateProcessPathExt(
10841084 // or a version with a supported PATHEXT appended. We then try calling CreateProcessW
10851085 // with the found versions in the appropriate order.
10861086
1087 // In the future, child process execution needs to move to Io implementation.
1088 // Under those conditions, here we will have access to lower level directory
1089 // opening function knowing which implementation we are in. Here, we imitate
1090 // that scenario.
1091 var threaded: std.Io.Threaded = .init_single_threaded;
1092 const io = threaded.io();
1093
10871094 var dir = dir: {
10881095 // needs to be null-terminated
10891096 try dir_buf.append(allocator, 0);
10901097 defer dir_buf.shrinkRetainingCapacity(dir_path_len);
10911098 const dir_path_z = dir_buf.items[0 .. dir_buf.items.len - 1 :0];
10921099 const prefixed_path = try windows.wToPrefixedFileW(null, dir_path_z);
1093 break :dir fs.cwd().openDirW(prefixed_path.span().ptr, .{ .iterate = true }) catch
1094 return error.FileNotFound;
1100 break :dir threaded.dirOpenDirWindows(.cwd(), prefixed_path.span(), .{
1101 .iterate = true,
1102 }) catch return error.FileNotFound;
10951103 };
1096 defer dir.close();
1104 defer dir.close(io);
10971105
10981106 // Add wildcard and null-terminator
10991107 try app_buf.append(allocator, '*');
......@@ -1127,7 +1135,7 @@ fn windowsCreateProcessPathExt(
11271135 .Buffer = @constCast(app_name_wildcard.ptr),
11281136 };
11291137 const rc = windows.ntdll.NtQueryDirectoryFile(
1130 dir.fd,
1138 dir.handle,
11311139 null,
11321140 null,
11331141 null,