export xfree() to Nim

This commit is contained in:
Ștefan Talpalaru 2020-02-11 03:39:19 +01:00
parent ebbe604a27
commit c868d1b62f
No known key found for this signature in database
GPG Key ID: CBF7934204F1B6F9
4 changed files with 7 additions and 2 deletions

View File

@ -42,7 +42,7 @@ proc getBacktrace*(): string {.noinline.} =
result = newString(btLen)
if btLen > 0:
copyMem(addr(result[0]), bt, btLen)
c_free(bt)
xfree_backtrace_c(bt)
when defined(nimStackTraceOverride):
registerStackTraceOverride(getBacktrace)

View File

@ -46,7 +46,7 @@ static void *xmalloc(size_t size)
return res;
}
static void xfree(void *ptr)
void xfree(void *ptr)
{
if (ptr == NULL) {
fprintf(stderr, "BUG: xfree() received a NULL pointer.\n");

View File

@ -18,6 +18,8 @@ extern "C" {
// The returned string needs to be freed by the caller.
char *get_backtrace_c(void) __attribute__((noinline));
void xfree(void *ptr);
#ifdef __cplusplus
} // extern "C"
#endif

View File

@ -13,3 +13,6 @@
proc get_backtrace_c*(): cstring {.importc: "get_backtrace_c",
header: "libbacktrace_wrapper.h".}
proc xfree_backtrace_c*(p: pointer) {.importc: "xfree",
header: "libbacktrace_wrapper.h".}