aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2025-12-14 16:46:08 -0800
committerAndrew Kelley <andrew@ziglang.org>2025-12-23 22:15:09 -0800
commit4458e423bf2d2cf485031d1f527e407bfc9113df (patch)
tree346c1463c8bbf76bf690a056e2851754e8661dae
parent2a40c1b556d7ed7811d3d2432dce8ba5d7c2e753 (diff)
downloadzig-4458e423bf2d2cf485031d1f527e407bfc9113df.tar.gz
zig-4458e423bf2d2cf485031d1f527e407bfc9113df.zip
link.MappedFile: update statx usage
-rw-r--r--lib/std/Io/Threaded.zig18
-rw-r--r--lib/std/testing.zig7
-rw-r--r--lib/std/zig/ErrorBundle.zig5
-rw-r--r--lib/std/zig/parser_test.zig4
-rw-r--r--src/link/MappedFile.zig48
-rw-r--r--src/main.zig18
6 files changed, 69 insertions, 31 deletions
diff --git a/lib/std/Io/Threaded.zig b/lib/std/Io/Threaded.zig
index f4f42cc39f..d9ef36cfda 100644
--- a/lib/std/Io/Threaded.zig
+++ b/lib/std/Io/Threaded.zig
@@ -1822,6 +1822,11 @@ fn dirStatFileLinux(
const t: *Threaded = @ptrCast(@alignCast(userdata));
const current_thread = Thread.getCurrent(t);
const linux = std.os.linux;
+ const use_c = std.c.versionCheck(if (builtin.abi.isAndroid())
+ .{ .major = 30, .minor = 0, .patch = 0 }
+ else
+ .{ .major = 2, .minor = 28, .patch = 0 });
+ const sys = if (use_c) std.c else std.os.linux;
var path_buffer: [posix.PATH_MAX]u8 = undefined;
const sub_path_posix = try pathToPosix(sub_path, &path_buffer);
@@ -1832,14 +1837,14 @@ fn dirStatFileLinux(
try current_thread.beginSyscall();
while (true) {
var statx = std.mem.zeroes(linux.Statx);
- const rc = linux.statx(
+ const rc = sys.statx(
dir.handle,
sub_path_posix,
flags,
.{ .TYPE = true, .MODE = true, .ATIME = true, .MTIME = true, .CTIME = true, .INO = true, .SIZE = true },
&statx,
);
- switch (linux.errno(rc)) {
+ switch (sys.errno(rc)) {
.SUCCESS => {
current_thread.endSyscall();
assert(statx.mask.TYPE);
@@ -2076,18 +2081,23 @@ fn fileStatLinux(userdata: ?*anyopaque, file: File) File.StatError!File.Stat {
const t: *Threaded = @ptrCast(@alignCast(userdata));
const current_thread = Thread.getCurrent(t);
const linux = std.os.linux;
+ const use_c = std.c.versionCheck(if (builtin.abi.isAndroid())
+ .{ .major = 30, .minor = 0, .patch = 0 }
+ else
+ .{ .major = 2, .minor = 28, .patch = 0 });
+ const sys = if (use_c) std.c else std.os.linux;
try current_thread.beginSyscall();
while (true) {
var statx = std.mem.zeroes(linux.Statx);
- const rc = linux.statx(
+ const rc = sys.statx(
file.handle,
"",
linux.AT.EMPTY_PATH,
.{ .TYPE = true, .MODE = true, .ATIME = true, .MTIME = true, .CTIME = true, .INO = true, .SIZE = true },
&statx,
);
- switch (linux.errno(rc)) {
+ switch (sys.errno(rc)) {
.SUCCESS => {
current_thread.endSyscall();
assert(statx.mask.TYPE);
diff --git a/lib/std/testing.zig b/lib/std/testing.zig
index 64ea3d1a4d..be6f316804 100644
--- a/lib/std/testing.zig
+++ b/lib/std/testing.zig
@@ -1148,9 +1148,10 @@ pub fn checkAllAllocationFailures(backing_allocator: std.mem.Allocator, comptime
break :x failing_allocator_inst.alloc_index;
};
- var fail_index: usize = 0;
- while (fail_index < needed_alloc_count) : (fail_index += 1) {
- var failing_allocator_inst = std.testing.FailingAllocator.init(backing_allocator, .{ .fail_index = fail_index });
+ for (0..needed_alloc_count) |fail_index| {
+ var failing_allocator_inst = std.testing.FailingAllocator.init(backing_allocator, .{
+ .fail_index = fail_index,
+ });
args.@"0" = failing_allocator_inst.allocator();
if (@call(.auto, test_fn, args)) |_| {
diff --git a/lib/std/zig/ErrorBundle.zig b/lib/std/zig/ErrorBundle.zig
index 0342874cf9..907256c2e4 100644
--- a/lib/std/zig/ErrorBundle.zig
+++ b/lib/std/zig/ErrorBundle.zig
@@ -168,7 +168,10 @@ pub fn renderToStderr(eb: ErrorBundle, io: Io, options: RenderOptions, color: st
var buffer: [256]u8 = undefined;
const stderr = try io.lockStderrWriter(&buffer);
defer io.unlockStderrWriter();
- try renderToWriter(eb, options, &stderr.interface, color.getTtyConf(stderr.mode));
+ renderToWriter(eb, options, &stderr.interface, color.getTtyConf(stderr.mode)) catch |err| switch (err) {
+ error.WriteFailed => return stderr.interface.err.?,
+ else => |e| return e,
+ };
}
pub fn renderToWriter(
diff --git a/lib/std/zig/parser_test.zig b/lib/std/zig/parser_test.zig
index 5318eab2df..6c11c3021b 100644
--- a/lib/std/zig/parser_test.zig
+++ b/lib/std/zig/parser_test.zig
@@ -6362,9 +6362,9 @@ fn testParse(io: Io, source: [:0]const u8, allocator: Allocator, anything_change
return formatted;
}
fn testTransformImpl(
- io: Io,
allocator: Allocator,
fba: *std.heap.FixedBufferAllocator,
+ io: Io,
source: [:0]const u8,
expected_source: []const u8,
) !void {
@@ -6386,7 +6386,7 @@ fn testTransform(source: [:0]const u8, expected_source: []const u8) !void {
const io = std.testing.io;
var fixed_allocator = std.heap.FixedBufferAllocator.init(fixed_buffer_mem[0..]);
return std.testing.checkAllAllocationFailures(fixed_allocator.allocator(), testTransformImpl, .{
- io, &fixed_allocator, source, expected_source,
+ &fixed_allocator, io, source, expected_source,
});
}
fn testCanonical(source: [:0]const u8) !void {
diff --git a/src/link/MappedFile.zig b/src/link/MappedFile.zig
index 06767b3709..dca3dca503 100644
--- a/src/link/MappedFile.zig
+++ b/src/link/MappedFile.zig
@@ -1,3 +1,4 @@
+/// TODO add a mapped file abstraction to std.Io
const MappedFile = @This();
const builtin = @import("builtin");
@@ -74,18 +75,41 @@ pub fn init(file: std.Io.File, gpa: std.mem.Allocator, io: Io) !MappedFile {
};
}
if (is_linux) {
- const statx = try linux.wrapped.statx(
- mf.file.handle,
- "",
- std.posix.AT.EMPTY_PATH,
- .{ .TYPE = true, .SIZE = true, .BLOCKS = true },
- );
- assert(statx.mask.TYPE);
- assert(statx.mask.SIZE);
- assert(statx.mask.BLOCKS);
-
- if (!std.posix.S.ISREG(statx.mode)) return error.PathAlreadyExists;
- break :stat .{ statx.size, @max(std.heap.pageSize(), statx.blksize) };
+ const use_c = std.c.versionCheck(if (builtin.abi.isAndroid())
+ .{ .major = 30, .minor = 0, .patch = 0 }
+ else
+ .{ .major = 2, .minor = 28, .patch = 0 });
+ const sys = if (use_c) std.c else std.os.linux;
+ while (true) {
+ var statx = std.mem.zeroes(linux.Statx);
+ const rc = sys.statx(
+ mf.file.handle,
+ "",
+ std.posix.AT.EMPTY_PATH,
+ .{ .TYPE = true, .SIZE = true, .BLOCKS = true },
+ &statx,
+ );
+ switch (sys.errno(rc)) {
+ .SUCCESS => {
+ assert(statx.mask.TYPE);
+ assert(statx.mask.SIZE);
+ assert(statx.mask.BLOCKS);
+ if (!std.posix.S.ISREG(statx.mode)) return error.PathAlreadyExists;
+ break :stat .{ statx.size, @max(std.heap.pageSize(), statx.blksize) };
+ },
+ .INTR => continue,
+ .ACCES => return error.AccessDenied,
+ .BADF => if (std.debug.runtime_safety) unreachable else return error.Unexpected,
+ .FAULT => if (std.debug.runtime_safety) unreachable else return error.Unexpected,
+ .INVAL => if (std.debug.runtime_safety) unreachable else return error.Unexpected,
+ .LOOP => return error.SymLinkLoop,
+ .NAMETOOLONG => return error.NameTooLong,
+ .NOENT => return error.FileNotFound,
+ .NOTDIR => return error.FileNotFound,
+ .NOMEM => return error.SystemResources,
+ else => |err| return std.posix.unexpectedErrno(err),
+ }
+ }
}
const stat = try std.posix.fstat(mf.file.handle);
if (!std.posix.S.ISREG(stat.mode)) return error.PathAlreadyExists;
diff --git a/src/main.zig b/src/main.zig
index f735f671c6..56a014bb92 100644
--- a/src/main.zig
+++ b/src/main.zig
@@ -4607,7 +4607,7 @@ fn updateModule(comp: *Compilation, color: Color, prog_node: std.Progress.Node)
if (errors.errorMessageCount() > 0) {
const io = comp.io;
- errors.renderToStderr(io, .{}, color);
+ try errors.renderToStderr(io, .{}, color);
return error.CompileErrorsReported;
}
}
@@ -4660,7 +4660,7 @@ fn cmdTranslateC(
return;
} else {
const color: Color = .auto;
- result.errors.renderToStderr(io, .{}, color);
+ result.errors.renderToStderr(io, .{}, color) catch {};
process.exit(1);
}
}
@@ -5281,7 +5281,7 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8)
if (fetch.error_bundle.root_list.items.len > 0) {
var errors = try fetch.error_bundle.toOwnedBundle("");
- errors.renderToStderr(io, .{}, color);
+ errors.renderToStderr(io, .{}, color) catch {};
process.exit(1);
}
@@ -6213,7 +6213,7 @@ fn cmdAstCheck(arena: Allocator, io: Io, args: []const []const u8) !void {
try wip_errors.init(arena);
try wip_errors.addZirErrorMessages(zir, tree, source, display_path);
var error_bundle = try wip_errors.toOwnedBundle("");
- error_bundle.renderToStderr(io, .{}, color);
+ try error_bundle.renderToStderr(io, .{}, color);
if (zir.loweringFailed()) {
process.exit(1);
}
@@ -6284,7 +6284,7 @@ fn cmdAstCheck(arena: Allocator, io: Io, args: []const []const u8) !void {
try wip_errors.init(arena);
try wip_errors.addZoirErrorMessages(zoir, tree, source, display_path);
var error_bundle = try wip_errors.toOwnedBundle("");
- error_bundle.renderToStderr(io, .{}, color);
+ error_bundle.renderToStderr(io, .{}, color) catch {};
process.exit(1);
}
@@ -6558,7 +6558,7 @@ fn cmdChangelist(arena: Allocator, io: Io, args: []const []const u8) !void {
try wip_errors.init(arena);
try wip_errors.addZirErrorMessages(old_zir, old_tree, old_source, old_source_path);
var error_bundle = try wip_errors.toOwnedBundle("");
- error_bundle.renderToStderr(io, .{}, color);
+ error_bundle.renderToStderr(io, .{}, color) catch {};
process.exit(1);
}
@@ -6570,7 +6570,7 @@ fn cmdChangelist(arena: Allocator, io: Io, args: []const []const u8) !void {
try wip_errors.init(arena);
try wip_errors.addZirErrorMessages(new_zir, new_tree, new_source, new_source_path);
var error_bundle = try wip_errors.toOwnedBundle("");
- error_bundle.renderToStderr(io, .{}, color);
+ error_bundle.renderToStderr(io, .{}, color) catch {};
process.exit(1);
}
@@ -7006,7 +7006,7 @@ fn cmdFetch(
if (fetch.error_bundle.root_list.items.len > 0) {
var errors = try fetch.error_bundle.toOwnedBundle("");
- errors.renderToStderr(io, .{}, color);
+ errors.renderToStderr(io, .{}, color) catch {};
process.exit(1);
}
@@ -7363,7 +7363,7 @@ fn loadManifest(
var error_bundle = try wip_errors.toOwnedBundle("");
defer error_bundle.deinit(gpa);
- error_bundle.renderToStderr(io, .{}, options.color);
+ error_bundle.renderToStderr(io, .{}, options.color) catch {};
process.exit(2);
}