authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-05-29 16:39:47-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-05-29 18:30:09-04:00
log89a97a7a278e69a440fd35665d4f1af864d023d9
tree364c995c839ac3521522c2f9ca83368a162d8c66
parentc209da1589f50dee9e961f64cb389d0b4e485aba

cleanups


3 files changed, 15 insertions(+), 9 deletions(-)

lib/std/debug.zig+10-4
......@@ -673,6 +673,7 @@ pub fn openSelfDebugInfo(allocator: *mem.Allocator) anyerror!DebugInfo {
673673/// This takes ownership of coff_file: users of this function should not close
674674/// it themselves, even on error.
675675/// TODO resources https://github.com/ziglang/zig/issues/4353
676/// TODO it's weird to take ownership even on error, rework this code.
676677fn readCoffDebugInfo(allocator: *mem.Allocator, coff_file: File) !ModuleDebugInfo {
677678 nosuspend {
678679 errdefer coff_file.close();
......@@ -855,6 +856,7 @@ fn chopSlice(ptr: []const u8, offset: u64, size: u64) ![]const u8 {
855856/// This takes ownership of elf_file: users of this function should not close
856857/// it themselves, even on error.
857858/// TODO resources https://github.com/ziglang/zig/issues/4353
859/// TODO it's weird to take ownership even on error, rework this code.
858860pub fn readElfDebugInfo(allocator: *mem.Allocator, elf_file: File) !ModuleDebugInfo {
859861 nosuspend {
860862 const mapped_mem = try mapWholeFile(elf_file);
......@@ -926,6 +928,7 @@ pub fn readElfDebugInfo(allocator: *mem.Allocator, elf_file: File) !ModuleDebugI
926928/// TODO resources https://github.com/ziglang/zig/issues/4353
927929/// This takes ownership of coff_file: users of this function should not close
928930/// it themselves, even on error.
931/// TODO it's weird to take ownership even on error, rework this code.
929932fn readMachODebugInfo(allocator: *mem.Allocator, macho_file: File) !ModuleDebugInfo {
930933 const mapped_mem = try mapWholeFile(macho_file);
931934
......@@ -1060,6 +1063,9 @@ const MachoSymbol = struct {
10601063 }
10611064};
10621065
1066/// `file` is expected to have been opened with .intended_io_mode == .blocking.
1067/// Takes ownership of file, even on error.
1068/// TODO it's weird to take ownership even on error, rework this code.
10631069fn mapWholeFile(file: File) ![]align(mem.page_size) const u8 {
10641070 nosuspend {
10651071 defer file.close();
......@@ -1144,7 +1150,7 @@ pub const DebugInfo = struct {
11441150 errdefer self.allocator.destroy(obj_di);
11451151
11461152 const macho_path = mem.spanZ(std.c._dyld_get_image_name(i));
1147 const macho_file = fs.cwd().openFile(macho_path, .{ .always_blocking = true }) catch |err| switch (err) {
1153 const macho_file = fs.cwd().openFile(macho_path, .{ .intended_io_mode = .blocking }) catch |err| switch (err) {
11481154 error.FileNotFound => return error.MissingDebugInfo,
11491155 else => return err,
11501156 };
......@@ -1290,9 +1296,9 @@ pub const DebugInfo = struct {
12901296 errdefer self.allocator.destroy(obj_di);
12911297
12921298 const elf_file = (if (ctx.name.len > 0)
1293 fs.cwd().openFile(ctx.name, .{ .always_blocking = true })
1299 fs.cwd().openFile(ctx.name, .{ .intended_io_mode = .blocking })
12941300 else
1295 fs.openSelfExe(.{ .always_blocking = true })) catch |err| switch (err) {
1301 fs.openSelfExe(.{ .intended_io_mode = .blocking })) catch |err| switch (err) {
12961302 error.FileNotFound => return error.MissingDebugInfo,
12971303 else => return err,
12981304 };
......@@ -1333,7 +1339,7 @@ pub const ModuleDebugInfo = switch (builtin.os.tag) {
13331339 }
13341340
13351341 fn loadOFile(self: *@This(), o_file_path: []const u8) !DW.DwarfInfo {
1336 const o_file = try fs.cwd().openFile(o_file_path, .{ .always_blocking = true });
1342 const o_file = try fs.cwd().openFile(o_file_path, .{ .intended_io_mode = .blocking });
13371343 const mapped_mem = try mapWholeFile(o_file);
13381344
13391345 const hdr = @ptrCast(
lib/std/fs.zig+3-3
......@@ -1323,7 +1323,7 @@ pub const Dir = struct {
13231323 var cleanup_dir = true;
13241324 defer if (cleanup_dir) dir.close();
13251325
1326 // Likely valid use of MAX_PATH_BYTES, as dir_name_buf will only
1326 // Valid use of MAX_PATH_BYTES because dir_name_buf will only
13271327 // ever store a single path component that was returned from the
13281328 // filesystem.
13291329 var dir_name_buf: [MAX_PATH_BYTES]u8 = undefined;
......@@ -1785,14 +1785,14 @@ pub fn openSelfExe(flags: File.OpenFlags) OpenSelfExeError!File {
17851785 if (builtin.os.tag == .windows) {
17861786 const wide_slice = selfExePathW();
17871787 const prefixed_path_w = try os.windows.wToPrefixedFileW(wide_slice);
1788 return cwd().openFileW(prefix_path_w.span(), flags);
1788 return cwd().openFileW(prefixed_path_w.span(), flags);
17891789 }
17901790 // Use of MAX_PATH_BYTES here is valid as the resulting path is immediately
17911791 // opened with no modification.
17921792 var buf: [MAX_PATH_BYTES]u8 = undefined;
17931793 const self_exe_path = try selfExePath(&buf);
17941794 buf[self_exe_path.len] = 0;
1795 return openFileAbsoluteZ(self_exe_path[0..self_exe_path.len :0].ptr, flags);
1795 return openFileAbsoluteZ(buf[0..self_exe_path.len :0].ptr, flags);
17961796}
17971797
17981798pub const SelfExePathError = os.ReadLinkError || os.SysCtlError;
lib/std/process.zig+2-2
......@@ -31,7 +31,7 @@ pub fn getCwdAlloc(allocator: *Allocator) ![]u8 {
3131 while (true) {
3232 if (os.getcwd(current_buf)) |slice| {
3333 return mem.dupe(allocator, u8, slice);
34 } else |err| switch(err) {
34 } else |err| switch (err) {
3535 error.NameTooLong => {
3636 // The path is too long to fit in stack_buf. Allocate geometrically
3737 // increasing buffers until we find one that works
......@@ -40,7 +40,7 @@ pub fn getCwdAlloc(allocator: *Allocator) ![]u8 {
4040 current_buf = try allocator.alloc(u8, new_capacity);
4141 heap_buf = current_buf;
4242 },
43 else => return err,
43 else => |e| return e,
4444 }
4545 }
4646}