authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-12-14 16:46:08-08:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-12-23 22:15:09-08:00
log4458e423bf2d2cf485031d1f527e407bfc9113df
tree346c1463c8bbf76bf690a056e2851754e8661dae
parent2a40c1b556d7ed7811d3d2432dce8ba5d7c2e753

link.MappedFile: update statx usage


6 files changed, 69 insertions(+), 31 deletions(-)

lib/std/Io/Threaded.zig+14-4
......@@ -1822,6 +1822,11 @@ fn dirStatFileLinux(
18221822 const t: *Threaded = @ptrCast(@alignCast(userdata));
18231823 const current_thread = Thread.getCurrent(t);
18241824 const linux = std.os.linux;
1825 const use_c = std.c.versionCheck(if (builtin.abi.isAndroid())
1826 .{ .major = 30, .minor = 0, .patch = 0 }
1827 else
1828 .{ .major = 2, .minor = 28, .patch = 0 });
1829 const sys = if (use_c) std.c else std.os.linux;
18251830
18261831 var path_buffer: [posix.PATH_MAX]u8 = undefined;
18271832 const sub_path_posix = try pathToPosix(sub_path, &path_buffer);
......@@ -1832,14 +1837,14 @@ fn dirStatFileLinux(
18321837 try current_thread.beginSyscall();
18331838 while (true) {
18341839 var statx = std.mem.zeroes(linux.Statx);
1835 const rc = linux.statx(
1840 const rc = sys.statx(
18361841 dir.handle,
18371842 sub_path_posix,
18381843 flags,
18391844 .{ .TYPE = true, .MODE = true, .ATIME = true, .MTIME = true, .CTIME = true, .INO = true, .SIZE = true },
18401845 &statx,
18411846 );
1842 switch (linux.errno(rc)) {
1847 switch (sys.errno(rc)) {
18431848 .SUCCESS => {
18441849 current_thread.endSyscall();
18451850 assert(statx.mask.TYPE);
......@@ -2076,18 +2081,23 @@ fn fileStatLinux(userdata: ?*anyopaque, file: File) File.StatError!File.Stat {
20762081 const t: *Threaded = @ptrCast(@alignCast(userdata));
20772082 const current_thread = Thread.getCurrent(t);
20782083 const linux = std.os.linux;
2084 const use_c = std.c.versionCheck(if (builtin.abi.isAndroid())
2085 .{ .major = 30, .minor = 0, .patch = 0 }
2086 else
2087 .{ .major = 2, .minor = 28, .patch = 0 });
2088 const sys = if (use_c) std.c else std.os.linux;
20792089
20802090 try current_thread.beginSyscall();
20812091 while (true) {
20822092 var statx = std.mem.zeroes(linux.Statx);
2083 const rc = linux.statx(
2093 const rc = sys.statx(
20842094 file.handle,
20852095 "",
20862096 linux.AT.EMPTY_PATH,
20872097 .{ .TYPE = true, .MODE = true, .ATIME = true, .MTIME = true, .CTIME = true, .INO = true, .SIZE = true },
20882098 &statx,
20892099 );
2090 switch (linux.errno(rc)) {
2100 switch (sys.errno(rc)) {
20912101 .SUCCESS => {
20922102 current_thread.endSyscall();
20932103 assert(statx.mask.TYPE);
lib/std/testing.zig+4-3
......@@ -1148,9 +1148,10 @@ pub fn checkAllAllocationFailures(backing_allocator: std.mem.Allocator, comptime
11481148 break :x failing_allocator_inst.alloc_index;
11491149 };
11501150
1151 var fail_index: usize = 0;
1152 while (fail_index < needed_alloc_count) : (fail_index += 1) {
1153 var failing_allocator_inst = std.testing.FailingAllocator.init(backing_allocator, .{ .fail_index = fail_index });
1151 for (0..needed_alloc_count) |fail_index| {
1152 var failing_allocator_inst = std.testing.FailingAllocator.init(backing_allocator, .{
1153 .fail_index = fail_index,
1154 });
11541155 args.@"0" = failing_allocator_inst.allocator();
11551156
11561157 if (@call(.auto, test_fn, args)) |_| {
lib/std/zig/ErrorBundle.zig+4-1
......@@ -168,7 +168,10 @@ pub fn renderToStderr(eb: ErrorBundle, io: Io, options: RenderOptions, color: st
168168 var buffer: [256]u8 = undefined;
169169 const stderr = try io.lockStderrWriter(&buffer);
170170 defer io.unlockStderrWriter();
171 try renderToWriter(eb, options, &stderr.interface, color.getTtyConf(stderr.mode));
171 renderToWriter(eb, options, &stderr.interface, color.getTtyConf(stderr.mode)) catch |err| switch (err) {
172 error.WriteFailed => return stderr.interface.err.?,
173 else => |e| return e,
174 };
172175}
173176
174177pub fn renderToWriter(
lib/std/zig/parser_test.zig+2-2
......@@ -6362,9 +6362,9 @@ fn testParse(io: Io, source: [:0]const u8, allocator: Allocator, anything_change
63626362 return formatted;
63636363}
63646364fn testTransformImpl(
6365 io: Io,
63666365 allocator: Allocator,
63676366 fba: *std.heap.FixedBufferAllocator,
6367 io: Io,
63686368 source: [:0]const u8,
63696369 expected_source: []const u8,
63706370) !void {
......@@ -6386,7 +6386,7 @@ fn testTransform(source: [:0]const u8, expected_source: []const u8) !void {
63866386 const io = std.testing.io;
63876387 var fixed_allocator = std.heap.FixedBufferAllocator.init(fixed_buffer_mem[0..]);
63886388 return std.testing.checkAllAllocationFailures(fixed_allocator.allocator(), testTransformImpl, .{
6389 io, &fixed_allocator, source, expected_source,
6389 &fixed_allocator, io, source, expected_source,
63906390 });
63916391}
63926392fn testCanonical(source: [:0]const u8) !void {
src/link/MappedFile.zig+36-12
......@@ -1,3 +1,4 @@
1/// TODO add a mapped file abstraction to std.Io
12const MappedFile = @This();
23
34const builtin = @import("builtin");
......@@ -74,18 +75,41 @@ pub fn init(file: std.Io.File, gpa: std.mem.Allocator, io: Io) !MappedFile {
7475 };
7576 }
7677 if (is_linux) {
77 const statx = try linux.wrapped.statx(
78 mf.file.handle,
79 "",
80 std.posix.AT.EMPTY_PATH,
81 .{ .TYPE = true, .SIZE = true, .BLOCKS = true },
82 );
83 assert(statx.mask.TYPE);
84 assert(statx.mask.SIZE);
85 assert(statx.mask.BLOCKS);
86
87 if (!std.posix.S.ISREG(statx.mode)) return error.PathAlreadyExists;
88 break :stat .{ statx.size, @max(std.heap.pageSize(), statx.blksize) };
78 const use_c = std.c.versionCheck(if (builtin.abi.isAndroid())
79 .{ .major = 30, .minor = 0, .patch = 0 }
80 else
81 .{ .major = 2, .minor = 28, .patch = 0 });
82 const sys = if (use_c) std.c else std.os.linux;
83 while (true) {
84 var statx = std.mem.zeroes(linux.Statx);
85 const rc = sys.statx(
86 mf.file.handle,
87 "",
88 std.posix.AT.EMPTY_PATH,
89 .{ .TYPE = true, .SIZE = true, .BLOCKS = true },
90 &statx,
91 );
92 switch (sys.errno(rc)) {
93 .SUCCESS => {
94 assert(statx.mask.TYPE);
95 assert(statx.mask.SIZE);
96 assert(statx.mask.BLOCKS);
97 if (!std.posix.S.ISREG(statx.mode)) return error.PathAlreadyExists;
98 break :stat .{ statx.size, @max(std.heap.pageSize(), statx.blksize) };
99 },
100 .INTR => continue,
101 .ACCES => return error.AccessDenied,
102 .BADF => if (std.debug.runtime_safety) unreachable else return error.Unexpected,
103 .FAULT => if (std.debug.runtime_safety) unreachable else return error.Unexpected,
104 .INVAL => if (std.debug.runtime_safety) unreachable else return error.Unexpected,
105 .LOOP => return error.SymLinkLoop,
106 .NAMETOOLONG => return error.NameTooLong,
107 .NOENT => return error.FileNotFound,
108 .NOTDIR => return error.FileNotFound,
109 .NOMEM => return error.SystemResources,
110 else => |err| return std.posix.unexpectedErrno(err),
111 }
112 }
89113 }
90114 const stat = try std.posix.fstat(mf.file.handle);
91115 if (!std.posix.S.ISREG(stat.mode)) return error.PathAlreadyExists;
src/main.zig+9-9
......@@ -4607,7 +4607,7 @@ fn updateModule(comp: *Compilation, color: Color, prog_node: std.Progress.Node)
46074607
46084608 if (errors.errorMessageCount() > 0) {
46094609 const io = comp.io;
4610 errors.renderToStderr(io, .{}, color);
4610 try errors.renderToStderr(io, .{}, color);
46114611 return error.CompileErrorsReported;
46124612 }
46134613}
......@@ -4660,7 +4660,7 @@ fn cmdTranslateC(
46604660 return;
46614661 } else {
46624662 const color: Color = .auto;
4663 result.errors.renderToStderr(io, .{}, color);
4663 result.errors.renderToStderr(io, .{}, color) catch {};
46644664 process.exit(1);
46654665 }
46664666 }
......@@ -5281,7 +5281,7 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8)
52815281
52825282 if (fetch.error_bundle.root_list.items.len > 0) {
52835283 var errors = try fetch.error_bundle.toOwnedBundle("");
5284 errors.renderToStderr(io, .{}, color);
5284 errors.renderToStderr(io, .{}, color) catch {};
52855285 process.exit(1);
52865286 }
52875287
......@@ -6213,7 +6213,7 @@ fn cmdAstCheck(arena: Allocator, io: Io, args: []const []const u8) !void {
62136213 try wip_errors.init(arena);
62146214 try wip_errors.addZirErrorMessages(zir, tree, source, display_path);
62156215 var error_bundle = try wip_errors.toOwnedBundle("");
6216 error_bundle.renderToStderr(io, .{}, color);
6216 try error_bundle.renderToStderr(io, .{}, color);
62176217 if (zir.loweringFailed()) {
62186218 process.exit(1);
62196219 }
......@@ -6284,7 +6284,7 @@ fn cmdAstCheck(arena: Allocator, io: Io, args: []const []const u8) !void {
62846284 try wip_errors.init(arena);
62856285 try wip_errors.addZoirErrorMessages(zoir, tree, source, display_path);
62866286 var error_bundle = try wip_errors.toOwnedBundle("");
6287 error_bundle.renderToStderr(io, .{}, color);
6287 error_bundle.renderToStderr(io, .{}, color) catch {};
62886288 process.exit(1);
62896289 }
62906290
......@@ -6558,7 +6558,7 @@ fn cmdChangelist(arena: Allocator, io: Io, args: []const []const u8) !void {
65586558 try wip_errors.init(arena);
65596559 try wip_errors.addZirErrorMessages(old_zir, old_tree, old_source, old_source_path);
65606560 var error_bundle = try wip_errors.toOwnedBundle("");
6561 error_bundle.renderToStderr(io, .{}, color);
6561 error_bundle.renderToStderr(io, .{}, color) catch {};
65626562 process.exit(1);
65636563 }
65646564
......@@ -6570,7 +6570,7 @@ fn cmdChangelist(arena: Allocator, io: Io, args: []const []const u8) !void {
65706570 try wip_errors.init(arena);
65716571 try wip_errors.addZirErrorMessages(new_zir, new_tree, new_source, new_source_path);
65726572 var error_bundle = try wip_errors.toOwnedBundle("");
6573 error_bundle.renderToStderr(io, .{}, color);
6573 error_bundle.renderToStderr(io, .{}, color) catch {};
65746574 process.exit(1);
65756575 }
65766576
......@@ -7006,7 +7006,7 @@ fn cmdFetch(
70067006
70077007 if (fetch.error_bundle.root_list.items.len > 0) {
70087008 var errors = try fetch.error_bundle.toOwnedBundle("");
7009 errors.renderToStderr(io, .{}, color);
7009 errors.renderToStderr(io, .{}, color) catch {};
70107010 process.exit(1);
70117011 }
70127012
......@@ -7363,7 +7363,7 @@ fn loadManifest(
73637363
73647364 var error_bundle = try wip_errors.toOwnedBundle("");
73657365 defer error_bundle.deinit(gpa);
7366 error_bundle.renderToStderr(io, .{}, options.color);
7366 error_bundle.renderToStderr(io, .{}, options.color) catch {};
73677367
73687368 process.exit(2);
73697369 }