diff options
Diffstat (limited to 'lib/std')
| -rw-r--r-- | lib/std/debug.zig | 34 | ||||
| -rw-r--r-- | lib/std/mem.zig | 4 |
2 files changed, 21 insertions, 17 deletions
diff --git a/lib/std/debug.zig b/lib/std/debug.zig index 9b24e1acd3..76685666ad 100644 --- a/lib/std/debug.zig +++ b/lib/std/debug.zig @@ -219,7 +219,7 @@ pub fn panic(comptime format: []const u8, args: var) noreturn { } /// TODO multithreaded awareness -var panicking: u8 = 0; // TODO make this a bool +var panicking: u8 = 0; pub fn panicExtra(trace: ?*const builtin.StackTrace, first_trace_addr: ?usize, comptime format: []const u8, args: var) noreturn { @setCold(true); @@ -230,21 +230,25 @@ pub fn panicExtra(trace: ?*const builtin.StackTrace, first_trace_addr: ?usize, c resetSegfaultHandler(); } - if (@atomicRmw(u8, &panicking, builtin.AtomicRmwOp.Xchg, 1, builtin.AtomicOrder.SeqCst) == 1) { - // Panicked during a panic. - - // TODO detect if a different thread caused the panic, because in that case - // we would want to return here instead of calling abort, so that the thread - // which first called panic can finish printing a stack trace. - os.abort(); - } - const stderr = getStderrStream(); - stderr.print(format ++ "\n", args) catch os.abort(); - if (trace) |t| { - dumpStackTrace(t.*); + switch (@atomicRmw(u8, &panicking, .Add, 1, .SeqCst)) { + 0 => { + const stderr = getStderrStream(); + stderr.print(format ++ "\n", args) catch os.abort(); + if (trace) |t| { + dumpStackTrace(t.*); + } + dumpCurrentStackTrace(first_trace_addr); + }, + 1 => { + // TODO detect if a different thread caused the panic, because in that case + // we would want to return here instead of calling abort, so that the thread + // which first called panic can finish printing a stack trace. + warn("Panicked during a panic. Aborting.\n", .{}); + }, + else => { + // Panicked while printing "Panicked during a panic." + }, } - dumpCurrentStackTrace(first_trace_addr); - os.abort(); } diff --git a/lib/std/mem.zig b/lib/std/mem.zig index 824ab2f556..133e3b8a2d 100644 --- a/lib/std/mem.zig +++ b/lib/std/mem.zig @@ -364,11 +364,11 @@ pub fn len(comptime T: type, ptr: [*:0]const T) usize { } pub fn toSliceConst(comptime T: type, ptr: [*:0]const T) [:0]const T { - return ptr[0..len(T, ptr)]; + return ptr[0..len(T, ptr) :0]; } pub fn toSlice(comptime T: type, ptr: [*:0]T) [:0]T { - return ptr[0..len(T, ptr)]; + return ptr[0..len(T, ptr) :0]; } /// Returns true if all elements in a slice are equal to the scalar value provided |
