From: Matt Corallo Date: Sun, 16 Jan 2022 22:25:20 +0000 (+0000) Subject: [TS] Wrap `aligned_alloc` as well as other malloc's. X-Git-Tag: v0.0.105.0~5^2~13 X-Git-Url: http://git.bitcoin.ninja/index.cgi?p=ldk-java;a=commitdiff_plain;h=03aa3308e672027e8a0be8365a7fc13e195a5c67 [TS] Wrap `aligned_alloc` as well as other malloc's. --- diff --git a/genbindings.sh b/genbindings.sh index 3d6ea6bc..9d42bbbd 100755 --- a/genbindings.sh +++ b/genbindings.sh @@ -203,7 +203,7 @@ else # We only need malloc and assert/abort, but for now just use WASI for those: #EXTRA_LINK=/usr/lib/wasm32-wasi/libc.a EXTRA_LINK= - [ "$3" != "false" ] && COMPILE="$COMPILE -Wl,-wrap,calloc -Wl,-wrap,realloc -Wl,-wrap,reallocarray -Wl,-wrap,malloc -Wl,-wrap,free" + [ "$3" != "false" ] && COMPILE="$COMPILE -Wl,-wrap,calloc -Wl,-wrap,realloc -Wl,-wrap,reallocarray -Wl,-wrap,malloc -Wl,-wrap,aligned_alloc -Wl,-wrap,free" if [ "$3" = "true" ]; then WASM_FILE=liblightningjs_debug.wasm $COMPILE -o liblightningjs_debug.wasm -g -I"$1"/lightning-c-bindings/include/ ts/bindings.c "$1"/lightning-c-bindings/target/wasm32-wasi/debug/libldk.a $EXTRA_LINK diff --git a/typescript_strings.py b/typescript_strings.py index 2979481d..7d63af91 100644 --- a/typescript_strings.py +++ b/typescript_strings.py @@ -376,8 +376,9 @@ typedef struct allocation { static allocation* allocation_ll = NULL; static allocation* freed_ll = NULL; -void* __real_malloc(size_t len); -void* __real_calloc(size_t nmemb, size_t len); +extern void* __real_malloc(size_t len); +extern void* __real_calloc(size_t nmemb, size_t len); +extern void* __real_aligned_alloc(size_t alignment, size_t size); static void new_allocation(void* res, const char* struct_name, int lineno) { allocation* new_alloc = __real_malloc(sizeof(allocation)); new_alloc->ptr = res; @@ -450,6 +451,11 @@ void* __wrap_calloc(size_t nmemb, size_t len) { new_allocation(res, "calloc call", 0); return res; } +void* __wrap_aligned_alloc(size_t alignment, size_t size) { + void* res = __real_aligned_alloc(alignment, size); + new_allocation(res, "aligned_alloc call", 0); + return res; +} void __wrap_free(void* ptr) { if (ptr == NULL) return; alloc_freed(ptr, 0);