]> git.bitcoin.ninja Git - ldk-java/commitdiff
Add some additional writing hooks which C# needs
authorMatt Corallo <git@bluematt.me>
Mon, 2 Jan 2023 01:04:45 +0000 (01:04 +0000)
committerMatt Corallo <git@bluematt.me>
Wed, 11 Jan 2023 21:14:44 +0000 (21:14 +0000)
genbindings.py
java_strings.py
typescript_strings.py

index a7dc0181b499353a30a18eb91235a13eb6405eb3..69230264a4b0d6c63c4e8a4127312f8ead763746 100755 (executable)
@@ -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)
index fcf9edd29e43cd331fd62c6217e5f5ead03542ee..d956e0e11678ba66e3db3bbe4b2f7a941a8263cd 100644 (file)
@@ -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"
index 98cb9c3359589af27ccf74a13bde915c421da3de..77ae1d0a035b580fb59854b361b1fd318b2347e4 100644 (file)
@@ -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 "<git_version_ldk_garbagecollected>";
 }"""
 
-        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):