mirror of
https://codeberg.org/ziglang/zig.git
synced 2026-04-27 19:09:47 +03:00
link.MappedFile: update statx usage
This commit is contained in:
+14
-4
@@ -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);
|
||||
|
||||
+4
-3
@@ -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)) |_| {
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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 {
|
||||
|
||||
+36
-12
@@ -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;
|
||||
|
||||
+9
-9
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user