-
Notifications
You must be signed in to change notification settings - Fork 46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Define apicheck function to use a Zig panic #71
Comments
this is doable from consumer code: pub fn main() void {
// ...
var act: std.posix.Sigaction = .{
.handler = .{ .handler = handleAbrt },
.mask = switch (builtin.os.tag) {
.macos => 0,
.linux => std.posix.empty_sigset,
else => @compileError("os not supported"),
},
.flags = 0,
};
std.posix.sigaction(std.posix.SIG.ABRT, &act, null) catch {}; // if it doesn't work, we just crash the old way lol
// ...
}
fn handleAbrt(_: c_int) callconv(.C) noreturn {
@call(.always_inline, std.debug.panic, .{ "assertion failed!!", .{} });
} |
here's a slightly better solution (zig 0.13, tested only on macOS so far): pub fn main() void {
// ...
const act: if (builtin.mode == .Debug) std.posix.Sigaction = if (builtin.mode == .Debug) .{
.handler = .{
.handler = struct {
fn handleAbrt(_: c_int) callconv(.C) noreturn {
std.debug.dumpCurrentStackTrace(@returnAddress());
std.process.exit(1);
}
}.handleAbrt,
},
.mask = if (builtin.os.tag == .linux) std.posix.empty_sigset else 0,
.flags = 0,
};
if (builtin.mode == .Debug) try std.posix.sigaction(std.posix.SIG.ABRT, &act, null);
// ...
} this has the advantage that a stack trace is dumped in addition to the Lua library's assertion message. one disadvantage is that if other code (like for example |
From a quick glance at the Lua sources, it may be possible to override the use of assert.h for the API check with a custom function. If so, this would make api checks much more easy to debug with zig panics and stack traces.
The text was updated successfully, but these errors were encountered: