Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions .github/workflows/elixir.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,31 @@ jobs:
run: |
zig fmt --check src
zig fmt --check kinda_example/native/zig-src
- name: Run tests (example with gdb)
working-directory: ./kinda_example
- name: Install gdb
run: |
sudo apt update
sudo apt install -y gdb
- name: Run tests (example with gdb and stack trace)
working-directory: ./kinda_example
run: |
bash ../scripts/gdb.sh test
env:
KINDA_DUMP_STACK_TRACE: "1"
- name: Run tests (example with gdb)
working-directory: ./kinda_example
run: |
bash ../scripts/gdb.sh test
- name: Run tests (example)
working-directory: ./kinda_example
run: |
mix test --force
- name: Run tests (example with stack trace)
continue-on-error: true
working-directory: ./kinda_example
run: |
mix test --force
env:
KINDA_DUMP_STACK_TRACE: "1"
- name: Precompile
working-directory: ./kinda_example
env:
Expand Down
9 changes: 9 additions & 0 deletions src/result.zig
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,20 @@ const beam = @import("beam");
const e = @import("erl_nif").c;
const std = @import("std");

pub fn is_stack_trace_enabled() bool {
var value: [256]u8 = undefined;
var value_size: usize = value.len;
return e.enif_getenv("KINDA_DUMP_STACK_TRACE", &value[0], &value_size) == 0;
}

pub fn nif_with_flags(comptime name: [*c]const u8, comptime arity: usize, comptime f: anytype, comptime flags: u32) type {
const ns = "Elixir.";
return struct {
fn exported(env: beam.env, n: c_int, args: [*c]const beam.term) callconv(.c) beam.term {
return f(env, n, args) catch |err| {
if (is_stack_trace_enabled()) {
std.debug.dumpStackTrace(@errorReturnTrace().?.*);
}
return beam.raise_exception(env, ns ++ "Kinda.CallError", err);
};
}
Expand Down
Loading