From: Matt Corallo Date: Mon, 2 Jan 2023 01:04:45 +0000 (+0000) Subject: Add some additional writing hooks which C# needs X-Git-Tag: v0.0.113.0^2~12 X-Git-Url: http://git.bitcoin.ninja/index.cgi?p=ldk-java;a=commitdiff_plain;h=1852c471e433c02edcae4803ba52bfec05c5631c Add some additional writing hooks which C# needs --- diff --git a/genbindings.py b/genbindings.py index a7dc0181..69230264 100755 --- a/genbindings.py +++ b/genbindings.py @@ -264,7 +264,7 @@ def java_c_types(fn_arg, ret_arr_len): fn_arg = fn_arg[4:].strip() is_primitive = True elif fn_arg.startswith("bool"): - java_ty = "boolean" + java_ty = consts.c_type_map['bool'][0] c_ty = "jboolean" fn_ty_arg = "Z" arr_ty = "bool" @@ -1059,6 +1059,7 @@ with open(sys.argv[1]) as in_h, open(f"{sys.argv[2]}/bindings{consts.file_ext}", with open(f"{sys.argv[3]}/structs/TxOut{consts.file_ext}", "w") as out_java_struct: out_java_struct.write(consts.hu_struct_file_prefix) out_java_struct.write(consts.txout_defn) + out_java_struct.write(consts.hu_struct_file_suffix) fn_line = "struct LDKCVec_u8Z TxOut_get_script_pubkey (struct LDKTxOut* thing)" write_c(fn_line + " {") write_c("\treturn CVec_u8Z_clone(&thing->script_pubkey);") @@ -1073,6 +1074,7 @@ with open(sys.argv[1]) as in_h, open(f"{sys.argv[2]}/bindings{consts.file_ext}", with open(f"{sys.argv[3]}/structs/BigEndianScalar{consts.file_ext}", "w") as out_java_struct: out_java_struct.write(consts.hu_struct_file_prefix) out_java_struct.write(consts.scalar_defn) + out_java_struct.write(consts.hu_struct_file_suffix) fn_line = "struct LDKThirtyTwoBytes BigEndianScalar_get_bytes (struct LDKBigEndianScalar* thing)" write_c(fn_line + " {\n") write_c("\tLDKThirtyTwoBytes ret = { .data = *thing->big_endian_bytes };\n") @@ -1123,23 +1125,23 @@ with open(sys.argv[1]) as in_h, open(f"{sys.argv[2]}/bindings{consts.file_ext}", else: assert(line == "\n") - out_java.write(consts.bindings_footer) + out_java.write(consts.bindings_footer()) for struct_name in opaque_structs: with open(f"{sys.argv[3]}/structs/{struct_name.replace('LDK', '')}{consts.file_ext}", "a") as out_java_struct: - out_java_struct.write("}\n") + out_java_struct.write("}\n" + consts.hu_struct_file_suffix) for struct_name in trait_structs: with open(f"{sys.argv[3]}/structs/{struct_name.replace('LDK', '')}{consts.file_ext}", "a") as out_java_struct: - out_java_struct.write("}\n") + out_java_struct.write("}\n" + consts.hu_struct_file_suffix) for struct_name in complex_enums: with open(f"{sys.argv[3]}/structs/{struct_name.replace('LDK', '').replace('COption', 'Option')}{consts.file_ext}", "a") as out_java_struct: - out_java_struct.write("}\n") + out_java_struct.write("}\n" + consts.hu_struct_file_suffix) for struct_name in result_types: with open(f"{sys.argv[3]}/structs/{struct_name.replace('LDKCResult', 'Result')}{consts.file_ext}", "a") as out_java_struct: - out_java_struct.write("}\n") + out_java_struct.write("}\n" + consts.hu_struct_file_suffix) for struct_name in tuple_types: struct_hu_name = struct_name.replace("LDKC2Tuple", "TwoTuple").replace("LDKC3Tuple", "ThreeTuple") with open(f"{sys.argv[3]}/structs/{struct_hu_name}{consts.file_ext}", "a") as out_java_struct: - out_java_struct.write("}\n") + out_java_struct.write("}\n" + consts.hu_struct_file_suffix) with open(f"{sys.argv[4]}/bindings.c.body", "w") as out_c: out_c.write(consts.c_file_pfx) diff --git a/java_strings.py b/java_strings.py index fcf9edd2..d956e0e1 100644 --- a/java_strings.py +++ b/java_strings.py @@ -11,6 +11,7 @@ class Consts: self.target = target self.c_array_class_caches = set() self.c_type_map = dict( + bool = ['boolean'], uint8_t = ['byte'], uint16_t = ['short'], uint32_t = ['int'], @@ -84,8 +85,6 @@ public class version { } }""" - self.bindings_footer = "}\n" - self.util_fn_pfx = """package org.ldk.structs; import org.ldk.impl.bindings; import org.ldk.enums.*; @@ -474,6 +473,7 @@ import java.lang.ref.Reference; import javax.annotation.Nullable; """ + self.hu_struct_file_suffix = "" self.c_fn_ty_pfx = "JNIEXPORT " self.c_fn_args_pfx = "JNIEnv *env, jclass clz" self.file_ext = ".java" @@ -488,6 +488,9 @@ import javax.annotation.Nullable; self.is_arr_some_check = ("", " != NULL") self.get_native_arr_len_call = ("(*env)->GetArrayLength(env, ", ")") + def bindings_footer(self): + return "}\n" + def construct_jenv(self): res = "JNIEnv *env;\n" res += "jint get_jenv_res = (*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_6);\n" diff --git a/typescript_strings.py b/typescript_strings.py index 98cb9c33..77ae1d0a 100644 --- a/typescript_strings.py +++ b/typescript_strings.py @@ -17,6 +17,7 @@ class Consts: self.function_ptr_counter = 0 self.function_ptrs = {} self.c_type_map = dict( + bool = ['boolean', 'boolean', 'XXX'], uint8_t = ['number', 'number', 'Uint8Array'], uint16_t = ['number', 'number', 'Uint16Array'], uint32_t = ['number', 'number', 'Uint32Array'], @@ -352,8 +353,6 @@ export async function initializeWasmFromBinary(bin: Uint8Array) { return ""; }""" - self.bindings_footer = "" - self.common_base = """ function freer(f: () => void) { f() } const finalizer = new FinalizationRegistry(freer); @@ -697,6 +696,7 @@ import { CommonBase, UInt5, WitnessVersion, UnqualifiedError } from './CommonBas import * as bindings from '../bindings.mjs' """ + self.hu_struct_file_suffix = "" self.util_fn_pfx = self.hu_struct_file_prefix + "\nexport class UtilMethods extends CommonBase {\n" self.util_fn_sfx = "}" self.c_fn_ty_pfx = "" @@ -712,6 +712,9 @@ import * as bindings from '../bindings.mjs' self.is_arr_some_check = ("", " != 0") self.get_native_arr_len_call = ("", "->arr_len") + def bindings_footer(self): + return "" + def release_native_arr_ptr_call(self, ty_info, arr_var, arr_ptr_var): return None def create_native_arr_call(self, arr_len, ty_info):