authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-01-08 00:21:57-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-01-08 00:21:57-07:00
log25d2e7fce04d5cbe63331cc56ab7bafe89c249c4
tree2380175bc0463a770649ca4b46b63a51febd6375
parentad7a09d95a3867ac9d8230c4b9694f711d09390e

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

1 files changed, 12 insertions(+), 4 deletions(-)

lib/std/debug.zig+12-4
......@@ -105,11 +105,15 @@ pub fn getSelfDebugInfo() !*DebugInfo {
105105}
106106
107107/// Tries to print a hexadecimal view of the bytes, unbuffered, and ignores any error returned.
108pub fn hexdump(bytes: []const u8) void {
109 hexdump_internal(bytes) catch {};
108/// Obtains the stderr mutex while dumping.
109pub fn dump_hex(bytes: []const u8) void {
110 stderr_mutex.lock();
111 defer stderr_mutex.unlock();
112 dump_hex_fallible(bytes) catch {};
110113}
111114
112fn hexdump_internal(bytes: []const u8) !void {
115/// Prints a hexadecimal view of the bytes, unbuffered, returning any error that occurs.
116pub fn dump_hex_fallible(bytes: []const u8) !void {
113117 const stderr = std.io.getStdErr();
114118 const ttyconf = std.io.tty.detectConfig(stderr);
115119 const writer = stderr.writer();
......@@ -140,7 +144,7 @@ fn hexdump_internal(bytes: []const u8) !void {
140144 if (std.ascii.isPrint(byte)) {
141145 try writer.writeByte(byte);
142146 } else {
143 // TODO: remove this `if` when https://github.com/ziglang/zig/issues/7600 is fixed
147 // Related: https://github.com/ziglang/zig/issues/7600
144148 if (ttyconf == .windows_api) {
145149 try writer.writeByte('.');
146150 continue;
......@@ -2831,3 +2835,7 @@ pub fn ConfigurableTrace(comptime size: usize, comptime stack_frame_count: usize
28312835 }
28322836 };
28332837}
2838
2839test {
2840 _ = &dump_hex;
2841}