From 693b2ffd5cc5b17aedb58aed6b12237659a9dcb7 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Wed, 21 Jan 2026 19:08:52 -0800 Subject: [PATCH] std: back out the flags field of Io.File For now, let us refrain from putting the sync mode into the Io.File struct, and document that to do concurrent batch operations, any Windows file handles must be in asynchronous mode. The consequences for violating this requirement is neither illegal behavior, nor an error, but that concurrency is lost. In other words, deadlock might occur. This prevents the addition of flags field. partial revert of 2faf14200f58ee72ec3a13e894d765f59e6483a9 --- lib/std/Io/File.zig | 15 --------------- lib/std/Io/Threaded.zig | 36 +++++++++--------------------------- lib/std/Progress.zig | 1 - 3 files changed, 9 insertions(+), 43 deletions(-) diff --git a/lib/std/Io/File.zig b/lib/std/Io/File.zig index b49f40157bcefb93086f77204367da7012e73a7a..6323a39454194e58be8a53e4f8f9879cfc1daa0e 100644 --- a/lib/std/Io/File.zig +++ b/lib/std/Io/File.zig @@ -10,20 +10,8 @@ const assert = std.debug.assert; const Dir = std.Io.Dir; handle: Handle, -flags: Flags = .{}, pub const Handle = std.posix.fd_t; -pub const Flags = switch (native_os) { - .windows => packed struct(u1) { - /// * true: opened with MODE.IO.ASYNCHRONOUS - /// * false: opened with SYNCHRONOUS_ALERT or SYNCHRONOUS_NONALERT, or - /// not a file. - /// This is default-initialized to false as a workaround for - /// https://codeberg.org/ziglang/zig/issues/30842 - nonblocking: bool = false, - }, - else => packed struct(u0) {}, -}; pub const Reader = @import("File/Reader.zig"); pub const Writer = @import("File/Writer.zig"); @@ -89,7 +77,6 @@ pub fn stdout() File { return switch (native_os) { .windows => .{ .handle = std.os.windows.peb().ProcessParameters.hStdOutput, - .flags = .{ .nonblocking = false }, }, else => .{ .handle = std.posix.STDOUT_FILENO, @@ -101,7 +88,6 @@ pub fn stderr() File { return switch (native_os) { .windows => .{ .handle = std.os.windows.peb().ProcessParameters.hStdError, - .flags = .{ .nonblocking = false }, }, else => .{ .handle = std.posix.STDERR_FILENO, @@ -113,7 +99,6 @@ pub fn stdin() File { return switch (native_os) { .windows => .{ .handle = std.os.windows.peb().ProcessParameters.hStdInput, - .flags = .{ .nonblocking = false }, }, else => .{ .handle = std.posix.STDIN_FILENO, diff --git a/lib/std/Io/Threaded.zig b/lib/std/Io/Threaded.zig index 9e4b5e6991050785dce1e998181b29e9ea2bc134..d40c4a8481fc6bb5341e75faa99fa0318a6adfa4 100644 --- a/lib/std/Io/Threaded.zig +++ b/lib/std/Io/Threaded.zig @@ -2759,12 +2759,7 @@ fn dirCreateDirPathOpenWasi( fn dirStat(userdata: ?*anyopaque, dir: Dir) Dir.StatError!Dir.Stat { const t: *Threaded = @ptrCast(@alignCast(userdata)); - const file: File = if (is_windows) .{ - .handle = dir.handle, - .flags = .{ .nonblocking = false }, - } else .{ - .handle = dir.handle, - }; + const file: File = .{ .handle = dir.handle }; return fileStat(t, file); } @@ -3686,10 +3681,7 @@ fn dirCreateFileWindows( errdefer windows.CloseHandle(handle); const exclusive = switch (flags.lock) { - .none => return .{ - .handle = handle, - .flags = .{ .nonblocking = false }, - }, + .none => return .{ .handle = handle }, .shared => false, .exclusive => true, }; @@ -3709,10 +3701,7 @@ fn dirCreateFileWindows( )) { .SUCCESS => { syscall.finish(); - return .{ - .handle = handle, - .flags = .{ .nonblocking = false }, - }; + return .{ .handle = handle }; }, .INSUFFICIENT_RESOURCES => return syscall.fail(error.SystemResources), .LOCK_NOT_GRANTED => return syscall.fail(error.WouldBlock), @@ -4287,10 +4276,7 @@ pub fn dirOpenFileWtf16( errdefer w.CloseHandle(handle); const exclusive = switch (flags.lock) { - .none => return .{ - .handle = handle, - .flags = .{ .nonblocking = false }, - }, + .none => return .{ .handle = handle }, .shared => false, .exclusive => true, }; @@ -4313,10 +4299,7 @@ pub fn dirOpenFileWtf16( .ACCESS_VIOLATION => |err| return syscall.ntstatusBug(err), // bad io_status_block pointer else => |status| return syscall.unexpectedNtstatus(status), }; - return .{ - .handle = handle, - .flags = .{ .nonblocking = false }, - }; + return .{ .handle = handle }; } fn dirOpenFileWasi( @@ -8271,7 +8254,7 @@ fn fileReadStreamingWindows(file: File, data: []const []u8) File.Reader.Error!us try syscall.checkCancel(); continue; }, - .INVALID_PARAMETER => |err| return syscall.ntstatusBug(err), // wrong value for flags.nonblocking + .INVALID_PARAMETER => |err| return syscall.ntstatusBug(err), // streaming read of async mode file else => |status| return syscall.unexpectedNtstatus(status), } } @@ -14363,9 +14346,9 @@ fn processSpawnWindows(userdata: ?*anyopaque, options: process.SpawnOptions) pro return .{ .id = piProcInfo.hProcess, .thread_handle = piProcInfo.hThread, - .stdin = if (g_hChildStd_IN_Wr) |h| .{ .handle = h, .flags = .{ .nonblocking = true } } else null, - .stdout = if (g_hChildStd_OUT_Rd) |h| .{ .handle = h, .flags = .{ .nonblocking = true } } else null, - .stderr = if (g_hChildStd_ERR_Rd) |h| .{ .handle = h, .flags = .{ .nonblocking = true } } else null, + .stdin = if (g_hChildStd_IN_Wr) |h| .{ .handle = h } else null, + .stdout = if (g_hChildStd_OUT_Rd) |h| .{ .handle = h } else null, + .stderr = if (g_hChildStd_ERR_Rd) |h| .{ .handle = h } else null, .request_resource_usage_statistics = options.request_resource_usage_statistics, }; } @@ -15499,7 +15482,6 @@ fn progressParentFile(userdata: ?*anyopaque) std.Progress.ParentFileError!File { .pointer => @ptrFromInt(int), else => return error.UnsupportedOperation, }, - .flags = if (is_windows) .{ .nonblocking = true } else .{}, }; } diff --git a/lib/std/Progress.zig b/lib/std/Progress.zig index 5da61110796cd72016782b78ae7b83561ec0083d..5ccc46778b43d0260ee1a6323e13eae20e31a2c9 100644 --- a/lib/std/Progress.zig +++ b/lib/std/Progress.zig @@ -979,7 +979,6 @@ fn serializeIpc(start_serialized_len: usize, serialized_buffer: *Serialized.Buff if (main_parent == .unused) continue; const file: Io.File = .{ .handle = main_storage.getIpcFd() orelse continue, - .flags = if (is_windows) .{ .nonblocking = true } else .{}, }; const opt_saved_metadata = findOld(file.handle, old_ipc_metadata_fds, old_ipc_metadata); var bytes_read: usize = 0; -- 2.54.0