X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=csharp_strings.py;h=e1c2708e82e32ebcce0ea8dabe509c012675397a;hb=dbcef74f9feb03aa6d8d0ee07854740cac926f6b;hp=b25549a9aa80b5862f41f3649b879082e340ee1d;hpb=239d70ea23fdf148440dfedf9479944dc0fbf394;p=ldk-java diff --git a/csharp_strings.py b/csharp_strings.py index b25549a9..e1c2708e 100644 --- a/csharp_strings.py +++ b/csharp_strings.py @@ -3,7 +3,9 @@ from enum import Enum import sys class Target(Enum): - CSHARP = 1, + WINDOWS = 1, + LINUX = 2, + PTHREAD = 3, def first_to_lower(string: str) -> str: first = string[0] @@ -188,7 +190,25 @@ public class CommonBase { self.c_file_pfx = self.c_file_pfx + "#include \n#define DEBUG_PRINT(...) fprintf(stderr, __VA_ARGS__)\n" - if not DEBUG or sys.platform == "darwin": + if self.target == Target.WINDOWS: + self.c_file_pfx = self.c_file_pfx + """#include +static HANDLE process_heap = NULL; +static inline void* init_heap() { + if (UNLIKELY(process_heap == NULL)) { + // Assume pointer writes wont tear, which is true where we need it. + process_heap = GetProcessHeap(); + } +} +static inline void* MALLOC(size_t a, const char* _) { + init_heap(); + return HeapAlloc(process_heap, HEAP_ZERO_MEMORY, a); +} +#define do_MALLOC(a, b, _c) MALLOC(a, b) +#define FREE(p) if ((uint64_t)(p) > 4096) { init_heap(); HeapFree(process_heap, 0, p); } +#define CHECK_ACCESS(p) +#define CHECK_INNER_FIELD_ACCESS_OR_NULL(v) +""" + elif not DEBUG or self.target != Target.LINUX: self.c_file_pfx = self.c_file_pfx + """#define do_MALLOC(a, _b, _c) malloc(a) #define MALLOC(a, _) malloc(a) #define FREE(p) if ((uint64_t)(p) > 4096) { free(p); } @@ -214,7 +234,7 @@ void __attribute__((constructor)) debug_log_version() { } """ - if sys.platform != "darwin": + if self.target == Target.LINUX: self.c_file_pfx += """ // Running a leak check across all the allocations and frees of the JDK is a mess, // so instead we implement our own naive leak checker here, relying on the -wrap @@ -561,7 +581,7 @@ int CS_LDK_register_{fn_suffix}_invoker(invoker_{fn_suffix} invoker) {{ elif elem_ty.rust_obj == "LDKU5": return "InternalUtils.getU8ArrayElem(" + arr_name + ", " + idx + ")" elif elem_ty.rust_obj == "LDKStr": - return "InternalUtils.getU32ArrayElem(" + arr_name + ", " + idx + ")" + return "InternalUtils.getU64ArrayElem(" + arr_name + ", " + idx + ")" else: assert False