aboutsummaryrefslogtreecommitdiff
path: root/lib/std
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2024-01-08 00:21:57 -0700
committerAndrew Kelley <andrew@ziglang.org>2024-01-08 00:21:57 -0700
commit25d2e7fce04d5cbe63331cc56ab7bafe89c249c4 (patch)
tree2380175bc0463a770649ca4b46b63a51febd6375 /lib/std
parentad7a09d95a3867ac9d8230c4b9694f711d09390e (diff)
downloadzig-25d2e7fce04d5cbe63331cc56ab7bafe89c249c4.tar.gz
zig-25d2e7fce04d5cbe63331cc56ab7bafe89c249c4.zip
fixups from previous commit
* rename the functions * make the other function public and give it a better name * interact with stderr_mutex * std lib test coverage
Diffstat (limited to 'lib/std')
-rw-r--r--lib/std/debug.zig16
1 files changed, 12 insertions, 4 deletions
diff --git a/lib/std/debug.zig b/lib/std/debug.zig
index 4d7c7ed9a3..4670c49dfa 100644
--- a/lib/std/debug.zig
+++ b/lib/std/debug.zig
@@ -105,11 +105,15 @@ pub fn getSelfDebugInfo() !*DebugInfo {
}
/// Tries to print a hexadecimal view of the bytes, unbuffered, and ignores any error returned.
-pub fn hexdump(bytes: []const u8) void {
- hexdump_internal(bytes) catch {};
+/// Obtains the stderr mutex while dumping.
+pub fn dump_hex(bytes: []const u8) void {
+ stderr_mutex.lock();
+ defer stderr_mutex.unlock();
+ dump_hex_fallible(bytes) catch {};
}
-fn hexdump_internal(bytes: []const u8) !void {
+/// Prints a hexadecimal view of the bytes, unbuffered, returning any error that occurs.
+pub fn dump_hex_fallible(bytes: []const u8) !void {
const stderr = std.io.getStdErr();
const ttyconf = std.io.tty.detectConfig(stderr);
const writer = stderr.writer();
@@ -140,7 +144,7 @@ fn hexdump_internal(bytes: []const u8) !void {
if (std.ascii.isPrint(byte)) {
try writer.writeByte(byte);
} else {
- // TODO: remove this `if` when https://github.com/ziglang/zig/issues/7600 is fixed
+ // Related: https://github.com/ziglang/zig/issues/7600
if (ttyconf == .windows_api) {
try writer.writeByte('.');
continue;
@@ -2831,3 +2835,7 @@ pub fn ConfigurableTrace(comptime size: usize, comptime stack_frame_count: usize
}
};
}
+
+test {
+ _ = &dump_hex;
+}