mirror of
https://codeberg.org/ziglang/zig.git
synced 2026-04-27 19:09:47 +03:00
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
This commit is contained in:
@@ -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,
|
||||
|
||||
+9
-27
@@ -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 .{},
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user