aboutsummaryrefslogtreecommitdiff
path: root/lib/std/debug.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2024-07-04 23:13:22 -0400
committerGitHub <noreply@github.com>2024-07-04 23:13:22 -0400
commit0f8561d099e4d08be0a6e547dd88f21026504490 (patch)
tree69bdcb7800608daed4a8908406623f3bab38f0e4 /lib/std/debug.zig
parent790b8428a26457e7ed9ea20485b9d3085011b989 (diff)
parent74346b0f79ca4bf67d61008030c7cc3565bff3f9 (diff)
downloadzig-0f8561d099e4d08be0a6e547dd88f21026504490.tar.gz
zig-0f8561d099e4d08be0a6e547dd88f21026504490.zip
Merge pull request #20487 from ziglang/incremental-serialization
Zcu: extract serializable state from File
Diffstat (limited to 'lib/std/debug.zig')
-rw-r--r--lib/std/debug.zig24
1 files changed, 17 insertions, 7 deletions
diff --git a/lib/std/debug.zig b/lib/std/debug.zig
index f7dc462421..fb6609b8b1 100644
--- a/lib/std/debug.zig
+++ b/lib/std/debug.zig
@@ -398,20 +398,30 @@ pub fn dumpStackTrace(stack_trace: std.builtin.StackTrace) void {
}
}
-/// This function invokes undefined behavior when `ok` is `false`.
+/// Invokes detectable illegal behavior when `ok` is `false`.
+///
/// In Debug and ReleaseSafe modes, calls to this function are always
/// generated, and the `unreachable` statement triggers a panic.
-/// In ReleaseFast and ReleaseSmall modes, calls to this function are
-/// optimized away, and in fact the optimizer is able to use the assertion
-/// in its heuristics.
-/// Inside a test block, it is best to use the `std.testing` module rather
-/// than this function, because this function may not detect a test failure
-/// in ReleaseFast and ReleaseSmall mode. Outside of a test block, this assert
+///
+/// In ReleaseFast and ReleaseSmall modes, calls to this function are optimized
+/// away, and in fact the optimizer is able to use the assertion in its
+/// heuristics.
+///
+/// Inside a test block, it is best to use the `std.testing` module rather than
+/// this function, because this function may not detect a test failure in
+/// ReleaseFast and ReleaseSmall mode. Outside of a test block, this assert
/// function is the correct function to use.
pub fn assert(ok: bool) void {
if (!ok) unreachable; // assertion failure
}
+/// Invokes detectable illegal behavior when the provided slice is not mapped
+/// or lacks read permissions.
+pub fn assertReadable(slice: []const volatile u8) void {
+ if (!runtime_safety) return;
+ for (slice) |*byte| _ = byte.*;
+}
+
pub fn panic(comptime format: []const u8, args: anytype) noreturn {
@setCold(true);