authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-12-12 17:18:29-08:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-12-23 22:15:09-08:00
loge68ae8d7a1e78a25392e271d7ca894e0f09aa218
treeb22e9e6b67cc782635e614e0a010179f5c3c4d7d
parent54e4a3456ce2d5a497a166b94737fe5407052921

update uses of std.debug.lockStdErr


4 files changed, 31 insertions(+), 26 deletions(-)

lib/compiler/test_runner.zig+12-5
......@@ -405,15 +405,22 @@ pub fn fuzz(
405405 testOne(ctx, input.toSlice()) catch |err| switch (err) {
406406 error.SkipZigTest => return,
407407 else => {
408 std.debug.lockStdErr();
409 if (@errorReturnTrace()) |trace| std.debug.dumpStackTrace(trace);
410 std.debug.print("failed with error.{t}\n", .{err});
408 const stderr = std.debug.lockStderrWriter(&.{});
409 p: {
410 if (@errorReturnTrace()) |trace| {
411 std.debug.writeStackTrace(trace, &stderr.interface, stderr.mode) catch break :p;
412 }
413 stderr.interface.print("failed with error.{t}\n", .{err}) catch break :p;
414 stderr.interface.flush() catch break :p;
415 }
416 stderr.interface.flush() catch {};
411417 std.process.exit(1);
412418 },
413419 };
414420 if (log_err_count != 0) {
415 std.debug.lockStdErr();
416 std.debug.print("error logs detected\n", .{});
421 const stderr = std.debug.lockStderrWriter(&.{});
422 stderr.interface.print("error logs detected\n", .{}) catch {};
423 stderr.interface.flush() catch {};
417424 std.process.exit(1);
418425 }
419426 }
lib/std/debug/simple_panic.zig+3-3
......@@ -14,9 +14,9 @@ const std = @import("../std.zig");
1414pub fn call(msg: []const u8, ra: ?usize) noreturn {
1515 @branchHint(.cold);
1616 _ = ra;
17 std.debug.lockStdErr();
18 const stderr: std.Io.File = .stderr();
19 stderr.writeAll(msg) catch {};
17 const stderr = std.debug.lockStderrWriter(&.{});
18 stderr.interface.writeAll(msg) catch {};
19 stderr.interface.flush(msg) catch {};
2020 @trap();
2121}
2222
lib/std/process.zig+11-13
......@@ -1841,21 +1841,19 @@ pub fn totalSystemMemory() TotalSystemMemoryError!u64 {
18411841 }
18421842}
18431843
1844/// Indicate that we are now terminating with a successful exit code.
1845/// In debug builds, this is a no-op, so that the calling code's
1846/// cleanup mechanisms are tested and so that external tools that
1847/// check for resource leaks can be accurate. In release builds, this
1848/// calls exit(0), and does not return.
1849pub fn cleanExit() void {
1850 if (builtin.mode == .Debug) {
1851 return;
1852 } else {
1853 std.debug.lockStdErr();
1854 exit(0);
1855 }
1844/// Indicate intent to terminate with a successful exit code.
1845///
1846/// In debug builds, this is a no-op, so that the calling code's cleanup
1847/// mechanisms are tested and so that external tools checking for resource
1848/// leaks can be accurate. In release builds, this calls `exit` with code zero,
1849/// and does not return.
1850pub fn cleanExit(io: Io) void {
1851 if (builtin.mode == .Debug) return;
1852 _ = io.lockStderrWriter(&.{});
1853 exit(0);
18561854}
18571855
1858/// Raise the open file descriptor limit.
1856/// Request ability to have more open file descriptors simultaneously.
18591857///
18601858/// On some systems, this raises the limit before seeing ProcessFdQuotaExceeded
18611859/// errors. On other systems, this does nothing.
src/main.zig+5-5
......@@ -4429,12 +4429,12 @@ fn runOrTest(
44294429 // the error message and invocation below.
44304430 if (process.can_execv and arg_mode == .run) {
44314431 // execv releases the locks; no need to destroy the Compilation here.
4432 std.debug.lockStdErr();
4432 _ = std.debug.lockStderrWriter(&.{});
44334433 const err = process.execve(gpa, argv.items, &env_map);
4434 std.debug.unlockStdErr();
4434 std.debug.unlockStderrWriter();
44354435 try warnAboutForeignBinaries(io, arena, arg_mode, target, link_libc);
44364436 const cmd = try std.mem.join(arena, " ", argv.items);
4437 fatal("the following command failed to execve with '{s}':\n{s}", .{ @errorName(err), cmd });
4437 fatal("the following command failed to execve with '{t}':\n{s}", .{ err, cmd });
44384438 } else if (process.can_spawn) {
44394439 var child = std.process.Child.init(argv.items, gpa);
44404440 child.env_map = &env_map;
......@@ -4448,8 +4448,8 @@ fn runOrTest(
44484448 comp_destroyed.* = true;
44494449
44504450 const term_result = t: {
4451 std.debug.lockStdErr();
4452 defer std.debug.unlockStdErr();
4451 _ = std.debug.lockStderrWriter();
4452 defer std.debug.unlockStderrWriter();
44534453 break :t child.spawnAndWait(io);
44544454 };
44554455 const term = term_result catch |err| {