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...@@ -811,22 +811,22 @@ pub fn openElfDebugInfo(allocator: *mem.Allocator, elf_file_path: []const u8) !M
811 const mapped_mem = try mapWholeFile(elf_file_path);811 const mapped_mem = try mapWholeFile(elf_file_path);
812812
813 var seekable_stream = io.SliceSeekableInStream.init(mapped_mem);813 var seekable_stream = io.SliceSeekableInStream.init(mapped_mem);
814 var efile = try elf.Elf.openStream(814 var efile = try noasync elf.Elf.openStream(
815 allocator,815 allocator,
816 @ptrCast(*DW.DwarfSeekableStream, &seekable_stream.seekable_stream),816 @ptrCast(*DW.DwarfSeekableStream, &seekable_stream.seekable_stream),
817 @ptrCast(*DW.DwarfInStream, &seekable_stream.stream),817 @ptrCast(*DW.DwarfInStream, &seekable_stream.stream),
818 );818 );
819 defer efile.close();819 defer noasync efile.close();
820820
821 const debug_info = (try efile.findSection(".debug_info")) orelse821 const debug_info = (try noasync efile.findSection(".debug_info")) orelse
822 return error.MissingDebugInfo;822 return error.MissingDebugInfo;
823 const debug_abbrev = (try efile.findSection(".debug_abbrev")) orelse823 const debug_abbrev = (try noasync efile.findSection(".debug_abbrev")) orelse
824 return error.MissingDebugInfo;824 return error.MissingDebugInfo;
825 const debug_str = (try efile.findSection(".debug_str")) orelse825 const debug_str = (try noasync efile.findSection(".debug_str")) orelse
826 return error.MissingDebugInfo;826 return error.MissingDebugInfo;
827 const debug_line = (try efile.findSection(".debug_line")) orelse827 const debug_line = (try noasync efile.findSection(".debug_line")) orelse
828 return error.MissingDebugInfo;828 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
831 var di = DW.DwarfInfo{831 var di = DW.DwarfInfo{
832 .endian = efile.endian,832 .endian = efile.endian,
...@@ -840,7 +840,7 @@ pub fn openElfDebugInfo(allocator: *mem.Allocator, elf_file_path: []const u8) !M...@@ -840,7 +840,7 @@ pub fn openElfDebugInfo(allocator: *mem.Allocator, elf_file_path: []const u8) !M
840 null,840 null,
841 };841 };
842842
843 try DW.openDwarfDebugInfo(&di, allocator);843 try noasync DW.openDwarfDebugInfo(&di, allocator);
844844
845 return ModuleDebugInfo{845 return ModuleDebugInfo{
846 .base_address = undefined,846 .base_address = undefined,
...@@ -983,8 +983,8 @@ const MachoSymbol = struct {...@@ -983,8 +983,8 @@ const MachoSymbol = struct {
983};983};
984984
985fn mapWholeFile(path: []const u8) ![]const u8 {985fn mapWholeFile(path: []const u8) ![]const u8 {
986 const file = try fs.openFileAbsolute(path, .{});986 const file = try noasync fs.openFileAbsolute(path, .{ .always_blocking = true });
987 defer file.close();987 defer noasync file.close();
988988
989 const file_len = try math.cast(usize, try file.getEndPos());989 const file_len = try math.cast(usize, try file.getEndPos());
990 const mapped_mem = try os.mmap(990 const mapped_mem = try os.mmap(
...@@ -1565,14 +1565,14 @@ pub const ModuleDebugInfo = switch (builtin.os) {...@@ -1565,14 +1565,14 @@ pub const ModuleDebugInfo = switch (builtin.os) {
1565 // Translate the VA into an address into this object1565 // Translate the VA into an address into this object
1566 const relocated_address = address - self.base_address;1566 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| {
1569 return SymbolInfo{1569 return SymbolInfo{
1570 .symbol_name = self.dwarf.getSymbolName(relocated_address) orelse "???",1570 .symbol_name = noasync self.dwarf.getSymbolName(relocated_address) orelse "???",
1571 .compile_unit_name = compile_unit.die.getAttrString(&self.dwarf, DW.AT_name) catch |err| switch (err) {1571 .compile_unit_name = compile_unit.die.getAttrString(&self.dwarf, DW.AT_name) catch |err| switch (err) {
1572 error.MissingDebugInfo, error.InvalidDebugInfo => "???",1572 error.MissingDebugInfo, error.InvalidDebugInfo => "???",
1573 else => return err,1573 else => return err,
1574 },1574 },
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) {
1576 error.MissingDebugInfo, error.InvalidDebugInfo => null,1576 error.MissingDebugInfo, error.InvalidDebugInfo => null,
1577 else => return err,1577 else => return err,
1578 },1578 },
lib/std/fs.zig+9-2
...@@ -731,11 +731,18 @@ pub const Dir = struct {...@@ -731,11 +731,18 @@ pub const Dir = struct {
731 @as(u32, os.O_WRONLY)731 @as(u32, os.O_WRONLY)
732 else732 else
733 @as(u32, os.O_RDONLY);733 @as(u32, os.O_RDONLY);
734 const fd = if (need_async_thread)734 const fd = if (need_async_thread and !flags.always_blocking)
735 try std.event.Loop.instance.?.openatZ(self.fd, sub_path, os_flags, 0)735 try std.event.Loop.instance.?.openatZ(self.fd, sub_path, os_flags, 0)
736 else736 else
737 try os.openatC(self.fd, sub_path, os_flags, 0);737 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 };
739 }746 }
740747
741 /// Same as `openFile` but Windows-only and the path parameter is748 /// 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 {...@@ -20,7 +20,7 @@ pub const File = struct {
20 /// or, more specifically, whether the I/O is blocking.20 /// or, more specifically, whether the I/O is blocking.
21 io_mode: io.Mode,21 io_mode: io.Mode,
2222
23 /// Even when std.io.mode is async, it is still sometimes desirable to perform blocking I/O, although23 /// Even when 'std.io.mode' is async, it is still sometimes desirable to perform blocking I/O, although
24 /// not by default. For example, when printing a stack trace to stderr.24 /// not by default. For example, when printing a stack trace to stderr.
25 async_block_allowed: @TypeOf(async_block_allowed_no) = async_block_allowed_no,25 async_block_allowed: @TypeOf(async_block_allowed_no) = async_block_allowed_no,
2626
...@@ -40,6 +40,11 @@ pub const File = struct {...@@ -40,6 +40,11 @@ pub const File = struct {
40 pub const OpenFlags = struct {40 pub const OpenFlags = struct {
41 read: bool = true,41 read: bool = true,
42 write: bool = false,42 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,
43 };48 };
4449
45 /// TODO https://github.com/ziglang/zig/issues/380250 /// TODO https://github.com/ziglang/zig/issues/3802