kivikakk / libpcre.zig

Zig bindings to libpcre
https://hrzn.ee/kivikakk/libpcre.zig
MIT License
20 stars 6 forks source link

Segfault at address 0x0 #19

Open ubermanu opened 1 month ago

ubermanu commented 1 month ago

I have a segfault when using libpcre.zig as a module, any idea?

also, cloning the repo and running tests locally seems to be ok

zig version: 0.12.0 system: arch

$ zig build run
Segmentation fault at address 0x0
???:?:?: 0x0 in ??? (???)
run
└─ run zig-pcre-test failure
error: the following command terminated unexpectedly:
Build Summary: 5/7 steps succeeded; 1 failed (disable with --summary none)
run transitive failure
└─ run zig-pcre-test failure
...

build.zig:

const pcre_pkg = b.dependency(
    "libpcre.zig",
    .{ .optimize = optimize, .target = target },
);
const pcre_mod = pcre_pkg.module("libpcre");
exe.root_module.addImport("pcre", pcre_mod);

main.zig:

const std = @import("std");
const Regex = @import("pcre").Regex;

pub fn main() !void {
    var re = try Regex.compile("\\w+", .{});
    defer re.deinit();

    if (try re.matches("test", .{})) |capture| {
        std.debug.print("{}\n", .{capture});
    }
}
kivikakk commented 1 month ago

No idea. Could you try adding pcre_mod.linkSystemLibrary("pcre"); (or "libpcre") to your build.zig? Either that, or build an executable with zig build, and then run it in gdb or lldb to see where the NULL access occurs.