authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-02-26 13:17:38-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-02-26 13:17:38-05:00
log0a8835268915feab561bdb68adb17aed76b9708f
tree718d061c406bf75c9ef81047798f08fc0ae046b7
parent2b33e27e1c72703deb50bef5c486b86130a75687
signaturelock-open Commit is signed but in an unrecognized format.

fix behavior tests with --test-evented-io


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

lib/std/debug.zig+13-13
......@@ -811,22 +811,22 @@ pub fn openElfDebugInfo(allocator: *mem.Allocator, elf_file_path: []const u8) !M
811811 const mapped_mem = try mapWholeFile(elf_file_path);
812812
813813 var seekable_stream = io.SliceSeekableInStream.init(mapped_mem);
814 var efile = try elf.Elf.openStream(
814 var efile = try noasync elf.Elf.openStream(
815815 allocator,
816816 @ptrCast(*DW.DwarfSeekableStream, &seekable_stream.seekable_stream),
817817 @ptrCast(*DW.DwarfInStream, &seekable_stream.stream),
818818 );
819 defer efile.close();
819 defer noasync efile.close();
820820
821 const debug_info = (try efile.findSection(".debug_info")) orelse
821 const debug_info = (try noasync efile.findSection(".debug_info")) orelse
822822 return error.MissingDebugInfo;
823 const debug_abbrev = (try efile.findSection(".debug_abbrev")) orelse
823 const debug_abbrev = (try noasync efile.findSection(".debug_abbrev")) orelse
824824 return error.MissingDebugInfo;
825 const debug_str = (try efile.findSection(".debug_str")) orelse
825 const debug_str = (try noasync efile.findSection(".debug_str")) orelse
826826 return error.MissingDebugInfo;
827 const debug_line = (try efile.findSection(".debug_line")) orelse
827 const debug_line = (try noasync efile.findSection(".debug_line")) orelse
828828 return error.MissingDebugInfo;
829 const opt_debug_ranges = try efile.findSection(".debug_ranges");
829 const opt_debug_ranges = try noasync efile.findSection(".debug_ranges");
830830
831831 var di = DW.DwarfInfo{
832832 .endian = efile.endian,
......@@ -840,7 +840,7 @@ pub fn openElfDebugInfo(allocator: *mem.Allocator, elf_file_path: []const u8) !M
840840 null,
841841 };
842842
843 try DW.openDwarfDebugInfo(&di, allocator);
843 try noasync DW.openDwarfDebugInfo(&di, allocator);
844844
845845 return ModuleDebugInfo{
846846 .base_address = undefined,
......@@ -983,8 +983,8 @@ const MachoSymbol = struct {
983983};
984984
985985fn mapWholeFile(path: []const u8) ![]const u8 {
986 const file = try fs.openFileAbsolute(path, .{});
987 defer file.close();
986 const file = try noasync fs.openFileAbsolute(path, .{ .always_blocking = true });
987 defer noasync file.close();
988988
989989 const file_len = try math.cast(usize, try file.getEndPos());
990990 const mapped_mem = try os.mmap(
......@@ -1565,14 +1565,14 @@ pub const ModuleDebugInfo = switch (builtin.os) {
15651565 // Translate the VA into an address into this object
15661566 const relocated_address = address - self.base_address;
15671567
1568 if (self.dwarf.findCompileUnit(relocated_address)) |compile_unit| {
1568 if (noasync self.dwarf.findCompileUnit(relocated_address)) |compile_unit| {
15691569 return SymbolInfo{
1570 .symbol_name = self.dwarf.getSymbolName(relocated_address) orelse "???",
1570 .symbol_name = noasync self.dwarf.getSymbolName(relocated_address) orelse "???",
15711571 .compile_unit_name = compile_unit.die.getAttrString(&self.dwarf, DW.AT_name) catch |err| switch (err) {
15721572 error.MissingDebugInfo, error.InvalidDebugInfo => "???",
15731573 else => return err,
15741574 },
1575 .line_info = self.dwarf.getLineNumberInfo(compile_unit.*, relocated_address) catch |err| switch (err) {
1575 .line_info = noasync self.dwarf.getLineNumberInfo(compile_unit.*, relocated_address) catch |err| switch (err) {
15761576 error.MissingDebugInfo, error.InvalidDebugInfo => null,
15771577 else => return err,
15781578 },
lib/std/fs.zig+9-2
......@@ -731,11 +731,18 @@ pub const Dir = struct {
731731 @as(u32, os.O_WRONLY)
732732 else
733733 @as(u32, os.O_RDONLY);
734 const fd = if (need_async_thread)
734 const fd = if (need_async_thread and !flags.always_blocking)
735735 try std.event.Loop.instance.?.openatZ(self.fd, sub_path, os_flags, 0)
736736 else
737737 try os.openatC(self.fd, sub_path, os_flags, 0);
738 return File{ .handle = fd, .io_mode = .blocking };
738 return File{
739 .handle = fd,
740 .io_mode = .blocking,
741 .async_block_allowed = if (flags.always_blocking)
742 File.async_block_allowed_yes
743 else
744 File.async_block_allowed_no,
745 };
739746 }
740747
741748 /// Same as `openFile` but Windows-only and the path parameter is
lib/std/fs/file.zig+6-1
......@@ -20,7 +20,7 @@ pub const File = struct {
2020 /// or, more specifically, whether the I/O is blocking.
2121 io_mode: io.Mode,
2222
23 /// Even when std.io.mode is async, it is still sometimes desirable to perform blocking I/O, although
23 /// Even when 'std.io.mode' is async, it is still sometimes desirable to perform blocking I/O, although
2424 /// not by default. For example, when printing a stack trace to stderr.
2525 async_block_allowed: @TypeOf(async_block_allowed_no) = async_block_allowed_no,
2626
......@@ -40,6 +40,11 @@ pub const File = struct {
4040 pub const OpenFlags = struct {
4141 read: bool = true,
4242 write: bool = false,
43
44 /// This prevents `O_NONBLOCK` from being passed even if `std.io.is_async`.
45 /// It allows the use of `noasync` when calling functions related to opening
46 /// the file, reading, and writing.
47 always_blocking: bool = false,
4348 };
4449
4550 /// TODO https://github.com/ziglang/zig/issues/3802