11from bindingstypes import *
22from enum import Enum
3+ import sys
34
45class Target (Enum ):
56 JAVA = 1 ,
@@ -126,13 +127,15 @@ class CommonBase {
126127 else :
127128 self .c_file_pfx = self .c_file_pfx + "#define DEBUG_PRINT(...) fprintf(stderr, __VA_ARGS__)\n "
128129
129- if not DEBUG :
130+ if not DEBUG or sys . platform == "darwin" :
130131 self .c_file_pfx = self .c_file_pfx + """#define MALLOC(a, _) malloc(a)
131132#define FREE(p) if ((uint64_t)(p) > 1024) { free(p); }
132- #define DO_ASSERT(a) (void)(a)
133+ """
134+ if not DEBUG :
135+ self .c_file_pfx += """#define DO_ASSERT(a) (void)(a)
133136#define CHECK(a)
134137"""
135- else :
138+ if DEBUG :
136139 self .c_file_pfx = self .c_file_pfx + """#include <assert.h>
137140// Always run a, then assert it is true:
138141#define DO_ASSERT(a) do { bool _assert_val = (a); assert(_assert_val); } while(0)
@@ -146,16 +149,19 @@ class CommonBase {
146149 DEBUG_PRINT("LDK C Bindings version did not match the header we built against\\ n");
147150 DEBUG_PRINT("Loaded LDK-Java Bindings with LDK %s and LDK-C-Bindings %s\\ n", check_get_ldk_version(), check_get_ldk_bindings_version());
148151}
152+ """
149153
154+ if sys .platform != "darwin" :
155+ self .c_file_pfx += """
150156// Running a leak check across all the allocations and frees of the JDK is a mess,
151157// so instead we implement our own naive leak checker here, relying on the -wrap
152158// linker option to wrap malloc/calloc/realloc/free, tracking everyhing allocated
153159// and free'd in Rust or C across the generated bindings shared library.
154160#include <threads.h>
155161"""
156162
157- if self .target == Target .ANDROID :
158- self .c_file_pfx = self .c_file_pfx + """
163+ if self .target == Target .ANDROID :
164+ self .c_file_pfx = self .c_file_pfx + """
159165#include <unwind.h>
160166#include <dlfcn.h>
161167
@@ -196,9 +202,9 @@ class CommonBase {
196202 }
197203}
198204"""
199- else :
200- self .c_file_pfx = self .c_file_pfx + "#include <execinfo.h>\n "
201- self .c_file_pfx = self .c_file_pfx + """
205+ else :
206+ self .c_file_pfx = self .c_file_pfx + "#include <execinfo.h>\n "
207+ self .c_file_pfx = self .c_file_pfx + """
202208#include <unistd.h>
203209static mtx_t allocation_mtx;
204210
0 commit comments