Commit 0a88352689
lib/std/fs/file.zig
@@ -20,7 +20,7 @@ pub const File = struct {
/// or, more specifically, whether the I/O is blocking.
io_mode: io.Mode,
- /// Even when std.io.mode is async, it is still sometimes desirable to perform blocking I/O, although
+ /// Even when 'std.io.mode' is async, it is still sometimes desirable to perform blocking I/O, although
/// not by default. For example, when printing a stack trace to stderr.
async_block_allowed: @TypeOf(async_block_allowed_no) = async_block_allowed_no,
@@ -40,6 +40,11 @@ pub const File = struct {
pub const OpenFlags = struct {
read: bool = true,
write: bool = false,
+
+ /// This prevents `O_NONBLOCK` from being passed even if `std.io.is_async`.
+ /// It allows the use of `noasync` when calling functions related to opening
+ /// the file, reading, and writing.
+ always_blocking: bool = false,
};
/// TODO https://github.com/ziglang/zig/issues/3802
lib/std/debug.zig
@@ -811,22 +811,22 @@ pub fn openElfDebugInfo(allocator: *mem.Allocator, elf_file_path: []const u8) !M
const mapped_mem = try mapWholeFile(elf_file_path);
var seekable_stream = io.SliceSeekableInStream.init(mapped_mem);
- var efile = try elf.Elf.openStream(
+ var efile = try noasync elf.Elf.openStream(
allocator,
@ptrCast(*DW.DwarfSeekableStream, &seekable_stream.seekable_stream),
@ptrCast(*DW.DwarfInStream, &seekable_stream.stream),
);
- defer efile.close();
+ defer noasync efile.close();
- const debug_info = (try efile.findSection(".debug_info")) orelse
+ const debug_info = (try noasync efile.findSection(".debug_info")) orelse
return error.MissingDebugInfo;
- const debug_abbrev = (try efile.findSection(".debug_abbrev")) orelse
+ const debug_abbrev = (try noasync efile.findSection(".debug_abbrev")) orelse
return error.MissingDebugInfo;
- const debug_str = (try efile.findSection(".debug_str")) orelse
+ const debug_str = (try noasync efile.findSection(".debug_str")) orelse
return error.MissingDebugInfo;
- const debug_line = (try efile.findSection(".debug_line")) orelse
+ const debug_line = (try noasync efile.findSection(".debug_line")) orelse
return error.MissingDebugInfo;
- const opt_debug_ranges = try efile.findSection(".debug_ranges");
+ const opt_debug_ranges = try noasync efile.findSection(".debug_ranges");
var di = DW.DwarfInfo{
.endian = efile.endian,
@@ -840,7 +840,7 @@ pub fn openElfDebugInfo(allocator: *mem.Allocator, elf_file_path: []const u8) !M
null,
};
- try DW.openDwarfDebugInfo(&di, allocator);
+ try noasync DW.openDwarfDebugInfo(&di, allocator);
return ModuleDebugInfo{
.base_address = undefined,
@@ -983,8 +983,8 @@ const MachoSymbol = struct {
};
fn mapWholeFile(path: []const u8) ![]const u8 {
- const file = try fs.openFileAbsolute(path, .{});
- defer file.close();
+ const file = try noasync fs.openFileAbsolute(path, .{ .always_blocking = true });
+ defer noasync file.close();
const file_len = try math.cast(usize, try file.getEndPos());
const mapped_mem = try os.mmap(
@@ -1565,14 +1565,14 @@ pub const ModuleDebugInfo = switch (builtin.os) {
// Translate the VA into an address into this object
const relocated_address = address - self.base_address;
- if (self.dwarf.findCompileUnit(relocated_address)) |compile_unit| {
+ if (noasync self.dwarf.findCompileUnit(relocated_address)) |compile_unit| {
return SymbolInfo{
- .symbol_name = self.dwarf.getSymbolName(relocated_address) orelse "???",
+ .symbol_name = noasync self.dwarf.getSymbolName(relocated_address) orelse "???",
.compile_unit_name = compile_unit.die.getAttrString(&self.dwarf, DW.AT_name) catch |err| switch (err) {
error.MissingDebugInfo, error.InvalidDebugInfo => "???",
else => return err,
},
- .line_info = self.dwarf.getLineNumberInfo(compile_unit.*, relocated_address) catch |err| switch (err) {
+ .line_info = noasync self.dwarf.getLineNumberInfo(compile_unit.*, relocated_address) catch |err| switch (err) {
error.MissingDebugInfo, error.InvalidDebugInfo => null,
else => return err,
},
lib/std/fs.zig
@@ -731,11 +731,18 @@ pub const Dir = struct {
@as(u32, os.O_WRONLY)
else
@as(u32, os.O_RDONLY);
- const fd = if (need_async_thread)
+ const fd = if (need_async_thread and !flags.always_blocking)
try std.event.Loop.instance.?.openatZ(self.fd, sub_path, os_flags, 0)
else
try os.openatC(self.fd, sub_path, os_flags, 0);
- return File{ .handle = fd, .io_mode = .blocking };
+ return File{
+ .handle = fd,
+ .io_mode = .blocking,
+ .async_block_allowed = if (flags.always_blocking)
+ File.async_block_allowed_yes
+ else
+ File.async_block_allowed_no,
+ };
}
/// Same as `openFile` but Windows-only and the path parameter is