set up a UB handler thanks to zig

activated in debug and safe release modes.
master
alex 2 years ago
parent 7fe58b82f5
commit fc4e65b479

@ -4,10 +4,16 @@ pub fn build(b: *std.build.Builder) void {
const target = b.standardTargetOptions(.{}); const target = b.standardTargetOptions(.{});
const mode = b.standardReleaseOptions(); const mode = b.standardReleaseOptions();
const libsegfault = b.addStaticLibrary("segfault", "src/segfault.zig");
libsegfault.setTarget(target);
libsegfault.setBuildMode(mode);
libsegfault.force_pic = true;
const exe = b.addExecutable("st", null); const exe = b.addExecutable("st", null);
exe.setTarget(target); exe.setTarget(target);
exe.setBuildMode(mode); exe.setBuildMode(mode);
exe.install(); exe.install();
exe.linkLibrary(libsegfault);
exe.linkSystemLibrary("fontconfig"); exe.linkSystemLibrary("fontconfig");
exe.linkSystemLibrary("freetype2"); exe.linkSystemLibrary("freetype2");
exe.linkSystemLibrary("Xft"); exe.linkSystemLibrary("Xft");

@ -0,0 +1,8 @@
const std = @import("std");
/// installs a segfault handler on supported platforms in debug and safe modes.
/// while a zig main does this automatically, a C main will want to call this explicitly.
/// hence, the export for C call convention.
export fn setupSegfaultHandler() void {
std.debug.maybeEnableSegfaultHandler();
}

5
x.c

@ -61,6 +61,8 @@ static void zoomabs(const Arg *);
static void zoomreset(const Arg *); static void zoomreset(const Arg *);
static void ttysend(const Arg *); static void ttysend(const Arg *);
extern void setupSegfaultHandler(void);
/* config.h for applying patches and the configuration. */ /* config.h for applying patches and the configuration. */
#include "config.h" #include "config.h"
@ -2103,6 +2105,9 @@ usage(void)
int int
main(int argc, char *argv[]) main(int argc, char *argv[])
{ {
// install zig's UB handler.
setupSegfaultHandler();
xw.l = xw.t = 0; xw.l = xw.t = 0;
xw.isfixed = False; xw.isfixed = False;
xsetcursor(cursorshape); xsetcursor(cursorshape);

Loading…
Cancel
Save