update uses of std.debug.lockStdErr

This commit is contained in:
Andrew Kelley 2025-12-12 17:18:29 -08:00
parent 54e4a3456c
commit e68ae8d7a1
4 changed files with 31 additions and 26 deletions

View file

@ -405,15 +405,22 @@ pub fn fuzz(
testOne(ctx, input.toSlice()) catch |err| switch (err) {
error.SkipZigTest => return,
else => {
std.debug.lockStdErr();
if (@errorReturnTrace()) |trace| std.debug.dumpStackTrace(trace);
std.debug.print("failed with error.{t}\n", .{err});
const stderr = std.debug.lockStderrWriter(&.{});
p: {
if (@errorReturnTrace()) |trace| {
std.debug.writeStackTrace(trace, &stderr.interface, stderr.mode) catch break :p;
}
stderr.interface.print("failed with error.{t}\n", .{err}) catch break :p;
stderr.interface.flush() catch break :p;
}
stderr.interface.flush() catch {};
std.process.exit(1);
},
};
if (log_err_count != 0) {
std.debug.lockStdErr();
std.debug.print("error logs detected\n", .{});
const stderr = std.debug.lockStderrWriter(&.{});
stderr.interface.print("error logs detected\n", .{}) catch {};
stderr.interface.flush() catch {};
std.process.exit(1);
}
}

View file

@ -14,9 +14,9 @@ const std = @import("../std.zig");
pub fn call(msg: []const u8, ra: ?usize) noreturn {
@branchHint(.cold);
_ = ra;
std.debug.lockStdErr();
const stderr: std.Io.File = .stderr();
stderr.writeAll(msg) catch {};
const stderr = std.debug.lockStderrWriter(&.{});
stderr.interface.writeAll(msg) catch {};
stderr.interface.flush(msg) catch {};
@trap();
}

View file

@ -1841,21 +1841,19 @@ pub fn totalSystemMemory() TotalSystemMemoryError!u64 {
}
}
/// Indicate that we are now terminating with a successful exit code.
/// In debug builds, this is a no-op, so that the calling code's
/// cleanup mechanisms are tested and so that external tools that
/// check for resource leaks can be accurate. In release builds, this
/// calls exit(0), and does not return.
pub fn cleanExit() void {
if (builtin.mode == .Debug) {
return;
} else {
std.debug.lockStdErr();
exit(0);
}
/// Indicate intent to terminate with a successful exit code.
///
/// In debug builds, this is a no-op, so that the calling code's cleanup
/// mechanisms are tested and so that external tools checking for resource
/// leaks can be accurate. In release builds, this calls `exit` with code zero,
/// and does not return.
pub fn cleanExit(io: Io) void {
if (builtin.mode == .Debug) return;
_ = io.lockStderrWriter(&.{});
exit(0);
}
/// Raise the open file descriptor limit.
/// Request ability to have more open file descriptors simultaneously.
///
/// On some systems, this raises the limit before seeing ProcessFdQuotaExceeded
/// errors. On other systems, this does nothing.

View file

@ -4429,12 +4429,12 @@ fn runOrTest(
// the error message and invocation below.
if (process.can_execv and arg_mode == .run) {
// execv releases the locks; no need to destroy the Compilation here.
std.debug.lockStdErr();
_ = std.debug.lockStderrWriter(&.{});
const err = process.execve(gpa, argv.items, &env_map);
std.debug.unlockStdErr();
std.debug.unlockStderrWriter();
try warnAboutForeignBinaries(io, arena, arg_mode, target, link_libc);
const cmd = try std.mem.join(arena, " ", argv.items);
fatal("the following command failed to execve with '{s}':\n{s}", .{ @errorName(err), cmd });
fatal("the following command failed to execve with '{t}':\n{s}", .{ err, cmd });
} else if (process.can_spawn) {
var child = std.process.Child.init(argv.items, gpa);
child.env_map = &env_map;
@ -4448,8 +4448,8 @@ fn runOrTest(
comp_destroyed.* = true;
const term_result = t: {
std.debug.lockStdErr();
defer std.debug.unlockStdErr();
_ = std.debug.lockStderrWriter();
defer std.debug.unlockStderrWriter();
break :t child.spawnAndWait(io);
};
const term = term_result catch |err| {