From 7cbcc5ef17b8036b2e99980e227c7ca0d44dba7f Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Fri, 12 Aug 2022 23:08:17 +0000 Subject: [PATCH] Switch 32-bit platforms to using 64-bit "pointers" This much more cleanly fixes the issue described in the previous commit by simply using 64-bit integers to represent pointers on 32-bit platforms, letting us store the required flag bit in the top 32-bits that are always free. It does, however, imply changing the entire call semantics for TypeScript to use BigInts for pointers, rather than numbers. --- gen_type_mapping.py | 20 ++++++------ genbindings.py | 21 +++++++------ java_strings.py | 3 ++ ts/js-wasm.h | 6 ++++ typescript_strings.py | 71 +++++++++++++++++++++++++++---------------- 5 files changed, 74 insertions(+), 47 deletions(-) diff --git a/gen_type_mapping.py b/gen_type_mapping.py index e6f7514e..ccb5f817 100644 --- a/gen_type_mapping.py +++ b/gen_type_mapping.py @@ -282,7 +282,7 @@ class TypeMappingGenerator: ty_info.var_name = "ret" if ty_info.rust_obj in self.opaque_structs: - from_hu_conv = (ty_info.var_name + " == null ? 0 : " + self.consts.get_ptr(ty_info.var_name), self.consts.add_ref("this", ty_info.var_name)) + from_hu_conv = (ty_info.var_name + " == null ? " + self.consts.native_zero_ptr + " : " + self.consts.get_ptr(ty_info.var_name), self.consts.add_ref("this", ty_info.var_name)) opaque_arg_conv = ty_info.rust_obj + " " + ty_info.var_name + "_conv;\n" opaque_arg_conv = opaque_arg_conv + ty_info.var_name + "_conv.inner = untag_ptr(" + ty_info.var_name + ");\n" opaque_arg_conv += ty_info.var_name + "_conv.is_owned = ptr_is_owned(" + ty_info.var_name + ");\n" @@ -298,7 +298,7 @@ class TypeMappingGenerator: if holds_ref: opaque_arg_conv += "\n" + ty_info.var_name + "_conv = " + ty_info.rust_obj.replace("LDK", "") + "_clone(&" + ty_info.var_name + "_conv);" else: - from_hu_conv = (ty_info.var_name + " == null ? 0 : " + ty_info.var_name + ".clone_ptr()", "") + from_hu_conv = (ty_info.var_name + " == null ? " + self.consts.native_zero_ptr + " : " + ty_info.var_name + ".clone_ptr()", "") elif ty_info.passed_as_ptr: opaque_arg_conv += "\n// WARNING: we need a move here but no clone is available for " + ty_info.rust_obj + "\n" # TODO: Once we support features cloning (which just isn't in C yet), we can make this a compile error instead! @@ -380,7 +380,7 @@ class TypeMappingGenerator: if holds_ref: base_conv += "\n" + ty_info.var_name + "_conv = " + ty_info.rust_obj.replace("LDK", "") + "_clone(&" + ty_info.var_name + "_conv);" else: - from_hu_conv = (ty_info.var_name + " == null ? 0 : " + ty_info.var_name + ".clone_ptr()", "") + from_hu_conv = (ty_info.var_name + " == null ? " + self.consts.native_zero_ptr + " : " + ty_info.var_name + ".clone_ptr()", "") base_conv += "\n" + "FREE(untag_ptr(" + ty_info.var_name + "));" else: base_conv = base_conv + self.consts.trait_struct_inc_refcnt(ty_info) @@ -389,7 +389,7 @@ class TypeMappingGenerator: else: base_conv = base_conv + "\n" + "FREE(untag_ptr(" + ty_info.var_name + "));" if from_hu_conv is None: - from_hu_conv = (ty_info.var_name + " == null ? 0 : " + self.consts.get_ptr(ty_info.var_name), "") + from_hu_conv = (ty_info.var_name + " == null ? " + self.consts.native_zero_ptr + " : " + self.consts.get_ptr(ty_info.var_name), "") from_hu_conv = (from_hu_conv[0], self.consts.add_ref("this", ty_info.var_name)) return ConvInfo(ty_info = ty_info, arg_name = ty_info.var_name, arg_conv = base_conv, arg_conv_name = ty_info.var_name + "_conv", arg_conv_cleanup = None, @@ -408,7 +408,7 @@ class TypeMappingGenerator: if holds_ref: base_conv += "\n" + ty_info.var_name + "_conv = " + ty_info.rust_obj.replace("LDK", "") + "_clone((" + ty_info.rust_obj + "*)untag_ptr(" + ty_info.var_name + "));" else: - from_hu_conv = (ty_info.var_name + " == null ? 0 : " + ty_info.var_name + ".clone_ptr()", "") + from_hu_conv = (ty_info.var_name + " == null ? " + self.consts.native_zero_ptr + " : " + ty_info.var_name + ".clone_ptr()", "") base_conv += "\n" + "FREE(untag_ptr(" + ty_info.var_name + "));" elif needs_full_clone: base_conv = base_conv + "\n// WARNING: we may need a move here but no clone is available for " + ty_info.rust_obj @@ -456,7 +456,7 @@ class TypeMappingGenerator: else: ret_conv = (ty_info.rust_obj + "* " + ty_info.var_name + "_conv = MALLOC(sizeof(" + ty_info.rust_obj + "), \"" + ty_info.rust_obj + "\");\n*" + ty_info.var_name + "_conv = ", ";") if from_hu_conv is None: - from_hu_conv = (ty_info.var_name + " != null ? " + self.consts.get_ptr(ty_info.var_name) + " : 0", "") + from_hu_conv = (ty_info.var_name + " != null ? " + self.consts.get_ptr(ty_info.var_name) + " : " + self.consts.native_zero_ptr, "") return ConvInfo(ty_info = ty_info, arg_name = ty_info.var_name, arg_conv = base_conv, arg_conv_name = ty_info.var_name + "_conv", arg_conv_cleanup = None, ret_conv = ret_conv, ret_conv_name = "tag_ptr(" + ty_info.var_name + "_conv, true)", @@ -482,7 +482,7 @@ class TypeMappingGenerator: else: to_hu_conv_sfx = "" if from_hu_conv is None: - from_hu_conv = (ty_info.var_name + " != null ? " + self.consts.get_ptr(ty_info.var_name) + " : 0", "") + from_hu_conv = (ty_info.var_name + " != null ? " + self.consts.get_ptr(ty_info.var_name) + " : " + self.consts.native_zero_ptr, "") return ConvInfo(ty_info = ty_info, arg_name = ty_info.var_name, arg_conv = base_conv, arg_conv_name = ty_info.var_name + "_conv", arg_conv_cleanup = None, ret_conv = ret_conv, ret_conv_name = ret_conv_name, @@ -535,7 +535,7 @@ class TypeMappingGenerator: ret_conv = ret_conv, ret_conv_name = "ref_" + ty_info.var_name, to_hu_conv = self.consts.var_decl_statement(ty_info.java_hu_ty, ty_info.var_name + "_hu_conv", ty_info.java_hu_ty + ".constr_from_ptr(" + ty_info.var_name + ")") + ";", to_hu_conv_name = ty_info.var_name + "_hu_conv", - from_hu_conv = (ty_info.var_name + " == null ? 0 : " + self.consts.get_ptr(ty_info.var_name), from_hu_sfx)) + from_hu_conv = (ty_info.var_name + " == null ? " + self.consts.native_zero_ptr + " : " + self.consts.get_ptr(ty_info.var_name), from_hu_sfx)) elif ty_info.rust_obj in self.trait_structs: if ty_info.nonnull_ptr: arg_conv = "void* " + ty_info.var_name + "_ptr = untag_ptr(" + ty_info.var_name + ");\n" @@ -564,7 +564,7 @@ class TypeMappingGenerator: ret_conv_name = "tag_ptr(" + ty_info.var_name + "_clone, true)", to_hu_conv = self.consts.var_decl_statement(ty_info.java_hu_ty, "ret_hu_conv", "new " + ty_info.java_hu_ty + "(null, " + ty_info.var_name + ")") + ";\n" + self.consts.add_ref("ret_hu_conv", "this") + ";", to_hu_conv_name = "ret_hu_conv", - from_hu_conv = (ty_info.var_name + " == null ? 0 : " + self.consts.get_ptr(ty_info.var_name), "")) + from_hu_conv = (ty_info.var_name + " == null ? " + self.consts.native_zero_ptr + " : " + self.consts.get_ptr(ty_info.var_name), "")) else: return ConvInfo(ty_info = ty_info, arg_name = ty_info.var_name, arg_conv = arg_conv, arg_conv_name = arg_conv_name, arg_conv_cleanup = None, @@ -572,7 +572,7 @@ class TypeMappingGenerator: ret_conv_name = "ret_" + ty_info.var_name, to_hu_conv = self.consts.var_decl_statement(ty_info.java_hu_ty, "ret_hu_conv", "new " + ty_info.java_hu_ty + "(null, " + ty_info.var_name + ")") + ";\n" + self.consts.add_ref("ret_hu_conv", "this") + ";", to_hu_conv_name = "ret_hu_conv", - from_hu_conv = (ty_info.var_name + " == null ? 0 : " + self.consts.get_ptr(ty_info.var_name), self.consts.add_ref("this", ty_info.var_name))) + from_hu_conv = (ty_info.var_name + " == null ? " + self.consts.native_zero_ptr + " : " + self.consts.get_ptr(ty_info.var_name), self.consts.add_ref("this", ty_info.var_name))) ret_conv = (self.consts.ptr_c_ty + " ret_" + ty_info.var_name + " = tag_ptr(", ", true);") if holds_ref: ret_conv = (ret_conv[0], ", false);") diff --git a/genbindings.py b/genbindings.py index a7c0a20f..7ff9069b 100755 --- a/genbindings.py +++ b/genbindings.py @@ -302,8 +302,8 @@ def java_c_types(fn_arg, ret_arr_len): arr_ty = "uint64_t" fn_arg = fn_arg[8:].strip() else: - java_ty = consts.ptr_native_ty - c_ty = consts.ptr_c_ty + java_ty = consts.usize_native_ty + c_ty = consts.usize_c_ty arr_ty = "uintptr_t" rust_obj = "uintptr_t" fn_arg = fn_arg[9:].strip() @@ -437,10 +437,11 @@ clone_fns.add("ThirtyTwoBytes_clone") write_c("static inline struct LDKThirtyTwoBytes ThirtyTwoBytes_clone(const struct LDKThirtyTwoBytes *orig) { struct LDKThirtyTwoBytes ret; memcpy(ret.data, orig->data, 32); return ret; }\n\n") -write_c("static inline void* untag_ptr(uintptr_t ptr) {\n") +write_c("static inline void* untag_ptr(uint64_t ptr) {\n") write_c("\tif (ptr < 4096) return (void*)ptr;\n") write_c("\tif (sizeof(void*) == 4) {\n") -write_c("\t\treturn (void*)(ptr & ~1);\n") +write_c("\t\t// For 32-bit systems, store pointers as 64-bit ints and use the 31st bit\n") +write_c("\t\treturn (void*)(uintptr_t)ptr;\n") write_c("\t} else {\n") write_c("\t\t// For 64-bit systems, assume the top byte is used for tagging, then\n") write_c("\t\t// use bit 9 ^ bit 10.\n") @@ -456,10 +457,10 @@ write_c("\t\treturn (void*)p;\n") write_c("\t}\n") write_c("}\n") -write_c("static inline bool ptr_is_owned(uintptr_t ptr) {\n") +write_c("static inline bool ptr_is_owned(uint64_t ptr) {\n") write_c("\tif(ptr < 4096) return true;\n") write_c("\tif (sizeof(void*) == 4) {\n") -write_c("\t\treturn (ptr & 1) ? true : false;\n") +write_c("\t\treturn ptr & (1ULL << 32);\n") write_c("\t} else {\n") write_c("\t\tuintptr_t ninth_bit = (((uintptr_t)ptr) & (1ULL << 55)) >> 55;\n") write_c("\t\tuintptr_t tenth_bit = (((uintptr_t)ptr) & (1ULL << 54)) >> 54;\n") @@ -472,10 +473,10 @@ write_c("\t\treturn (ninth_bit ^ tenth_bit) ? true : false;\n") write_c("\t}\n") write_c("}\n") -write_c("static inline uintptr_t tag_ptr(const void* ptr, bool is_owned) {\n") +write_c("static inline uint64_t tag_ptr(const void* ptr, bool is_owned) {\n") write_c("\tif ((uintptr_t)ptr < 4096) return (uint64_t)ptr;\n") write_c("\tif (sizeof(void*) == 4) {\n") -write_c("\t\treturn ((uintptr_t)ptr) | (is_owned ? 1 : 0);\n") +write_c("\t\treturn (((uint64_t)ptr) | ((is_owned ? 1ULL : 0) << 32));\n") write_c("\t} else {\n") write_c("\t\tCHECK(sizeof(uintptr_t) == 8);\n") write_c("\t\tuintptr_t tenth_bit = (((uintptr_t)ptr) & (1ULL << 54)) >> 54;\n") @@ -538,13 +539,13 @@ with open(sys.argv[1]) as in_h, open(f"{sys.argv[2]}/bindings{consts.file_ext}", return_type_info = type_mapping_generator.map_type(method_return_type.strip() + " ret", True, ret_arr_len, False, force_holds_ref) if method_name.endswith("_clone") and expected_struct not in unitary_enums: - meth_line = "uintptr_t " + expected_struct.replace("LDK", "") + "_clone_ptr(" + expected_struct + " *NONNULL_PTR arg)" + meth_line = "uint64_t " + expected_struct.replace("LDK", "") + "_clone_ptr(" + expected_struct + " *NONNULL_PTR arg)" write_c("static inline " + meth_line + " {\n") write_c("\t" + return_type_info.ret_conv[0].replace("\n", "\n\t")) write_c(method_name + "(arg)") write_c(return_type_info.ret_conv[1].replace("\n", "\n\t")) write_c("\n\treturn " + return_type_info.ret_conv_name + ";\n}\n") - map_fn(meth_line + ";\n", re.compile("(uintptr_t) ([A-Za-z_0-9]*)\((.*)\)").match(meth_line), None, None, None) + map_fn(meth_line + ";\n", re.compile("(uint64_t) ([A-Za-z_0-9]*)\((.*)\)").match(meth_line), None, None, None) argument_types = [] default_constructor_args = {} diff --git a/java_strings.py b/java_strings.py index 4951efa9..bcfc1f37 100644 --- a/java_strings.py +++ b/java_strings.py @@ -555,6 +555,9 @@ import javax.annotation.Nullable; self.file_ext = ".java" self.ptr_c_ty = "int64_t" self.ptr_native_ty = "long" + self.usize_c_ty = "int64_t" + self.usize_native_ty = "long" + self.native_zero_ptr = "0" self.result_c_ty = "jclass" self.ptr_arr = "jobjectArray" self.is_arr_some_check = ("", " != NULL") diff --git a/ts/js-wasm.h b/ts/js-wasm.h index 41db531d..1c9c3b22 100644 --- a/ts/js-wasm.h +++ b/ts/js-wasm.h @@ -39,8 +39,14 @@ typedef uint32_t JSValue; DECL_IMPORT(u, u, u, u, u, u) DECL_IMPORT(b, u, u, u, u, u) +DECL_IMPORT(b, b, u, u, u, u) +DECL_IMPORT(b, b, b, u, u, u) +DECL_IMPORT(b, b, b, b, u, u) DECL_IMPORT(b, b, b, b, b, b) +DECL_IMPORT(u, b, u, u, b, u) DECL_IMPORT(u, b, u, u, u, u) +DECL_IMPORT(u, b, b, u, u, u) DECL_IMPORT(u, u, b, u, u, u) +DECL_IMPORT(u, u, b, u, b, u) #endif diff --git a/typescript_strings.py b/typescript_strings.py index 56589bfb..e4d4c3eb 100644 --- a/typescript_strings.py +++ b/typescript_strings.py @@ -125,7 +125,8 @@ async function finishInitializeWasm(wasmInstance: WebAssembly.Instance) { isWasmInitialized = true; } -const fn_list = ["uuuuuu", "buuuuu", "bbbbbb", "ubuuuu", "uubuuu"]; +const fn_list = ["uuuuuu", "buuuuu", "bbuuuu", "bbbuuu", "bbbbuu", + "bbbbbb", "ubuubu", "ubuuuu", "ubbuuu", "uubuuu", "uububu"]; /* @internal */ export async function initializeWasmFromUint8Array(wasmBinary: Uint8Array) { @@ -253,6 +254,12 @@ export function decodeUint64Array (arrayPointer: number, free = true): bigint[] export function freeWasmMemory(pointer: number) { wasm.TS_free(pointer); } +/* @internal */ +export function getU64ArrayElem(arrayPointer: number, idx: number): bigint { + const actualArrayViewer = new BigUint64Array(wasm.memory.buffer, arrayPointer + 8, idx + 1); + return actualArrayViewer[idx]; +} + /* @internal */ export function getU32ArrayElem(arrayPointer: number, idx: number): number { const actualArrayViewer = new Uint32Array(wasm.memory.buffer, arrayPointer + 8, idx + 1); @@ -322,18 +329,18 @@ export async function initializeWasmFromBinary(bin: Uint8Array) { self.common_base = """ function freer(f: () => void) { f() } const finalizer = new FinalizationRegistry(freer); -function get_freeer(ptr: number, free_fn: (ptr: number) => void) { +function get_freeer(ptr: bigint, free_fn: (ptr: bigint) => void) { return () => { free_fn(ptr); } } export class CommonBase { - protected ptr: number; + protected ptr: bigint; protected ptrs_to: object[] = []; - protected constructor(ptr: number, free_fn: (ptr: number) => void) { + protected constructor(ptr: bigint, free_fn: (ptr: bigint) => void) { this.ptr = ptr; - if (Number.isFinite(ptr) && ptr != 0){ + if (ptr != 0n){ finalizer.register(this, get_freeer(ptr, free_fn), this); } } @@ -347,7 +354,7 @@ export class CommonBase { return o.ptr; } protected static set_null_skip_free(o: CommonBase) { - o.ptr = 0; + o.ptr = 0n; // @ts-ignore TypeScript is wrong about the returnvalue of unregister here! const did_unregister: boolean = finalizer.unregister(o); if (!did_unregister) @@ -385,7 +392,7 @@ export class UnqualifiedError { public value: bigint; /* @internal */ - public constructor(_dummy: object, ptr: number) { + public constructor(_dummy: object, ptr: bigint) { super(ptr, bindings.TxOut_free); this.script_pubkey = bindings.decodeUint8Array(bindings.TxOut_get_script_pubkey(ptr)); this.value = bindings.TxOut_get_value(ptr); @@ -592,6 +599,7 @@ _Static_assert(sizeof(void*) == 4, "Pointers mut be 32 bits"); } DECL_ARR_TYPE(int64_t, int64_t); +DECL_ARR_TYPE(uint64_t, uint64_t); DECL_ARR_TYPE(int8_t, int8_t); DECL_ARR_TYPE(uint32_t, uint32_t); DECL_ARR_TYPE(void*, ptr); @@ -650,8 +658,11 @@ import * as bindings from '../bindings.mjs' self.util_fn_sfx = "}" self.c_fn_ty_pfx = "" self.file_ext = ".mts" - self.ptr_c_ty = "uint32_t" - self.ptr_native_ty = "number" + self.ptr_c_ty = "uint64_t" + self.ptr_native_ty = "bigint" + self.usize_c_ty = "uint32_t" + self.usize_native_ty = "number" + self.native_zero_ptr = "0n" self.result_c_ty = "uint32_t" self.ptr_arr = "ptrArray" self.is_arr_some_check = ("", " != 0") @@ -694,7 +705,7 @@ import * as bindings from '../bindings.mjs' def map_hu_array_elems(self, arr_name, conv_name, arr_ty, elem_ty): if elem_ty.rust_obj == "LDKu5": return arr_name + " != null ? bindings.uint5ArrToBytes(" + arr_name + ") : null" - assert elem_ty.c_ty == "uint32_t" or elem_ty.c_ty.endswith("Array") + assert elem_ty.c_ty == "uint64_t" or elem_ty.c_ty.endswith("Array") return arr_name + " != null ? " + arr_name + ".map(" + conv_name + " => " + elem_ty.from_hu_conv[0] + ") : null" def str_ref_to_native_call(self, var_name, str_len): @@ -715,8 +726,10 @@ import * as bindings from '../bindings.mjs' def get_java_arr_len(self, arr_name): return "bindings.getArrayLength(" + arr_name + ")" def get_java_arr_elem(self, elem_ty, arr_name, idx): - if elem_ty.c_ty == "uint32_t" or elem_ty.c_ty == "uintptr_t" or elem_ty.c_ty.endswith("Array"): + if elem_ty.c_ty.endswith("Array") or elem_ty.c_ty == "uintptr_t": return "bindings.getU32ArrayElem(" + arr_name + ", " + idx + ")" + elif elem_ty.c_ty == "uint64_t": + return "bindings.getU64ArrayElem(" + arr_name + ", " + idx + ")" elif elem_ty.rust_obj == "LDKu5": return "bindings.getU8ArrayElem(" + arr_name + ", " + idx + ")" else: @@ -737,7 +750,7 @@ import * as bindings from '../bindings.mjs' return ("bindings.encodeUint8Array(" + inner + ")", "") elif mapped_ty.c_ty == "uint32_t": return ("bindings.encodeUint32Array(" + inner + ")", "") - elif mapped_ty.c_ty == "int64_t": + elif mapped_ty.c_ty == "int64_t" or mapped_ty.c_ty == "uint64_t": return ("bindings.encodeUint64Array(" + inner + ")", "") else: print(mapped_ty.c_ty) @@ -938,7 +951,7 @@ export class {struct_name.replace("LDK","")} extends CommonBase {{ public bindings_instance?: bindings.{struct_name}; /* @internal */ - constructor(_dummy: object, ptr: number) {{ + constructor(_dummy: object, ptr: bigint) {{ super(ptr, bindings.{struct_name.replace("LDK","")}_free); this.bindings_instance = null; }} @@ -948,7 +961,7 @@ export class {struct_name.replace("LDK","")} extends CommonBase {{ const impl_holder: {struct_name}Holder = new {struct_name}Holder(); let structImplementation = {{ {out_interface_implementation_overrides} }} as bindings.{struct_name}; -{super_constructor_statements} const ptr: number = bindings.{struct_name}_new(structImplementation{bindings_instantiator}); +{super_constructor_statements} const ptr: bigint = bindings.{struct_name}_new(structImplementation{bindings_instantiator}); impl_holder.held = new {struct_name.replace("LDK", "")}(null, ptr); impl_holder.held.bindings_instance = structImplementation; @@ -980,7 +993,7 @@ export class {struct_name.replace("LDK","")} extends CommonBase {{ else: out_typescript_bindings += f", {var[1]}: {var[0]}" - out_typescript_bindings += f"""): number {{ + out_typescript_bindings += f"""): bigint {{ if(!isWasmInitialized) {{ throw new Error("initializeWasm() must be awaited first!"); }} @@ -1061,8 +1074,12 @@ export class {struct_name.replace("LDK","")} extends CommonBase {{ for idx, arg_info in enumerate(fn_line.args_ty): if arg_info.ret_conv is not None: - out_c += ", (uint32_t)" + arg_info.ret_conv_name + if arg_info.c_ty.endswith("Array"): + out_c += ", (uint32_t)" + arg_info.ret_conv_name + else: + out_c += ", " + arg_info.ret_conv_name else: + assert False # TODO: Would we need some conversion here? out_c += ", (uint32_t)" + arg_info.arg_name for i in range(0, 6 - len(fn_line.args_ty)): out_c += ", 0" @@ -1133,7 +1150,7 @@ export class {struct_name.replace("LDK","")} extends CommonBase {{ out_c = out_c + "\treturn ret;\n" out_c = out_c + "}\n" - out_c = out_c + self.c_fn_ty_pfx + "long " + self.c_fn_name_define_pfx(struct_name + "_new", True) + "JSValue o" + out_c = out_c + self.c_fn_ty_pfx + "uint64_t " + self.c_fn_name_define_pfx(struct_name + "_new", True) + "JSValue o" for var in flattened_field_var_conversions: if isinstance(var, ConvInfo): out_c = out_c + ", " + var.c_ty + " " + var.arg_name @@ -1171,9 +1188,9 @@ export class {struct_name.replace("LDK","")} extends CommonBase {{ java_hu_class = "/**\n * " + enum_doc_comment.replace("\n", "\n * ") + "\n */\n" java_hu_class += "export class " + java_hu_type + " extends CommonBase {\n" - java_hu_class += "\tprotected constructor(_dummy: object, ptr: number) { super(ptr, bindings." + bindings_type + "_free); }\n" + java_hu_class += "\tprotected constructor(_dummy: object, ptr: bigint) { super(ptr, bindings." + bindings_type + "_free); }\n" java_hu_class += "\t/* @internal */\n" - java_hu_class += f"\tpublic static constr_from_ptr(ptr: number): {java_hu_type} {{\n" + java_hu_class += f"\tpublic static constr_from_ptr(ptr: bigint): {java_hu_type} {{\n" java_hu_class += f"\t\tconst raw_ty: number = bindings." + struct_name + "_ty_from_ptr(ptr);\n" out_c += self.c_fn_ty_pfx + "uint32_t" + self.c_fn_name_define_pfx(struct_name + "_ty_from_ptr", True) + self.ptr_c_ty + " ptr) {\n" out_c += "\t" + struct_name + " *obj = (" + struct_name + "*)untag_ptr(ptr);\n" @@ -1202,13 +1219,13 @@ export class {struct_name.replace("LDK","")} extends CommonBase {{ else: hu_conv_body += f"\t\tthis.{field_ty.arg_name} = bindings.{struct_name}_{var.var_name}_get_{field_ty.arg_name}(ptr);\n" java_hu_subclasses += "\t/* @internal */\n" - java_hu_subclasses += "\tpublic constructor(ptr: number) {\n\t\tsuper(null, ptr);\n" + java_hu_subclasses += "\tpublic constructor(ptr: bigint) {\n\t\tsuper(null, ptr);\n" java_hu_subclasses = java_hu_subclasses + hu_conv_body java_hu_subclasses = java_hu_subclasses + "\t}\n}\n" var_idx += 1 out_java += "}\n" java_hu_class += "\t\t\tdefault:\n\t\t\t\tthrow new Error('oops, this should be unreachable'); // Unreachable without extending the (internal) bindings interface\n\t\t}\n\t}\n\n" - out_java += self.fn_call_body(struct_name + "_ty_from_ptr", "uint32_t", "number", "ptr: number", "ptr") + out_java += self.fn_call_body(struct_name + "_ty_from_ptr", "uint32_t", "number", "ptr: bigint", "ptr") out_c += ("\t\tdefault: abort();\n") out_c += ("\t}\n}\n") @@ -1232,7 +1249,7 @@ export class {struct_name.replace("LDK","")} extends CommonBase {{ else: out_c += "\treturn " + "obj->" + camel_to_snake(var.var_name) + "." + field_map.arg_name + ";\n" out_c += "}\n" - out_java += self.fn_call_body(fn_name, field_map.c_ty, field_map.java_ty, "ptr: number", "ptr") + out_java += self.fn_call_body(fn_name, field_map.c_ty, field_map.java_ty, "ptr: bigint", "ptr") out_java_enum += java_hu_class self.struct_file_suffixes[java_hu_type] = java_hu_subclasses self.obj_defined([java_hu_type], "structs") @@ -1263,7 +1280,7 @@ export class {struct_name.replace("LDK","")} extends CommonBase {{ */ export class {hu_name} extends CommonBase {implementations}{{ /* @internal */ - public constructor(_dummy: object, ptr: number) {{ + public constructor(_dummy: object, ptr: bigint) {{ {constructor_body} }}{extra_body} @@ -1282,7 +1299,7 @@ export class {hu_name} extends CommonBase {implementations}{{ suffixes += "\tpublic res: " + res_map.java_hu_ty + ";\n" suffixes += f""" /* @internal */ - public constructor(_dummy: object, ptr: number) {{ + public constructor(_dummy: object, ptr: bigint) {{ super(_dummy, ptr); """ if res_map.java_hu_ty == "void": @@ -1300,7 +1317,7 @@ export class {hu_name} extends CommonBase {implementations}{{ suffixes += "\tpublic err: " + err_map.java_hu_ty + ";\n" suffixes += f""" /* @internal */ - public constructor(_dummy: object, ptr: number) {{ + public constructor(_dummy: object, ptr: bigint) {{ super(_dummy, ptr); """ if err_map.java_hu_ty == "void": @@ -1319,11 +1336,11 @@ export class {hu_name} extends CommonBase {implementations}{{ return f"""{self.hu_struct_file_prefix} export class {human_ty} extends CommonBase {{ - protected constructor(_dummy: object, ptr: number) {{ + protected constructor(_dummy: object, ptr: bigint) {{ super(ptr, bindings.{struct_name.replace("LDK","")}_free); }} /* @internal */ - public static constr_from_ptr(ptr: number): {human_ty} {{ + public static constr_from_ptr(ptr: bigint): {human_ty} {{ if (bindings.{struct_name.replace("LDK", "")}_is_ok(ptr)) {{ return new {human_ty}_OK(null, ptr); }} else {{ -- 2.39.5