From 8827488fcd556e6e95d97e838f781e6141ebde8c 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 d0f487b911..e537755a33 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 cdbb0fd182..1a2ca61c00 100644 --- a/lib/std/Io/Threaded.zig +++ b/lib/std/Io/Threaded.zig @@ -2764,12 +2764,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); } @@ -3692,10 +3687,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, }; @@ -3715,10 +3707,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), @@ -4289,10 +4278,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, }; @@ -4315,10 +4301,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( @@ -8414,7 +8397,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), } } @@ -14602,9 +14585,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, }; } @@ -15738,7 +15721,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 5da6111079..5ccc46778b 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;