Skip to content

Commit 1852c47

Browse files
committed
Add some additional writing hooks which C# needs
1 parent b410ce4 commit 1852c47

File tree

3 files changed

+19
-11
lines changed

3 files changed

+19
-11
lines changed

genbindings.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ def java_c_types(fn_arg, ret_arr_len):
264264
fn_arg = fn_arg[4:].strip()
265265
is_primitive = True
266266
elif fn_arg.startswith("bool"):
267-
java_ty = "boolean"
267+
java_ty = consts.c_type_map['bool'][0]
268268
c_ty = "jboolean"
269269
fn_ty_arg = "Z"
270270
arr_ty = "bool"
@@ -1059,6 +1059,7 @@ def map_tuple(struct_name, field_lines):
10591059
with open(f"{sys.argv[3]}/structs/TxOut{consts.file_ext}", "w") as out_java_struct:
10601060
out_java_struct.write(consts.hu_struct_file_prefix)
10611061
out_java_struct.write(consts.txout_defn)
1062+
out_java_struct.write(consts.hu_struct_file_suffix)
10621063
fn_line = "struct LDKCVec_u8Z TxOut_get_script_pubkey (struct LDKTxOut* thing)"
10631064
write_c(fn_line + " {")
10641065
write_c("\treturn CVec_u8Z_clone(&thing->script_pubkey);")
@@ -1073,6 +1074,7 @@ def map_tuple(struct_name, field_lines):
10731074
with open(f"{sys.argv[3]}/structs/BigEndianScalar{consts.file_ext}", "w") as out_java_struct:
10741075
out_java_struct.write(consts.hu_struct_file_prefix)
10751076
out_java_struct.write(consts.scalar_defn)
1077+
out_java_struct.write(consts.hu_struct_file_suffix)
10761078
fn_line = "struct LDKThirtyTwoBytes BigEndianScalar_get_bytes (struct LDKBigEndianScalar* thing)"
10771079
write_c(fn_line + " {\n")
10781080
write_c("\tLDKThirtyTwoBytes ret = { .data = *thing->big_endian_bytes };\n")
@@ -1123,23 +1125,23 @@ def map_tuple(struct_name, field_lines):
11231125
else:
11241126
assert(line == "\n")
11251127

1126-
out_java.write(consts.bindings_footer)
1128+
out_java.write(consts.bindings_footer())
11271129
for struct_name in opaque_structs:
11281130
with open(f"{sys.argv[3]}/structs/{struct_name.replace('LDK', '')}{consts.file_ext}", "a") as out_java_struct:
1129-
out_java_struct.write("}\n")
1131+
out_java_struct.write("}\n" + consts.hu_struct_file_suffix)
11301132
for struct_name in trait_structs:
11311133
with open(f"{sys.argv[3]}/structs/{struct_name.replace('LDK', '')}{consts.file_ext}", "a") as out_java_struct:
1132-
out_java_struct.write("}\n")
1134+
out_java_struct.write("}\n" + consts.hu_struct_file_suffix)
11331135
for struct_name in complex_enums:
11341136
with open(f"{sys.argv[3]}/structs/{struct_name.replace('LDK', '').replace('COption', 'Option')}{consts.file_ext}", "a") as out_java_struct:
1135-
out_java_struct.write("}\n")
1137+
out_java_struct.write("}\n" + consts.hu_struct_file_suffix)
11361138
for struct_name in result_types:
11371139
with open(f"{sys.argv[3]}/structs/{struct_name.replace('LDKCResult', 'Result')}{consts.file_ext}", "a") as out_java_struct:
1138-
out_java_struct.write("}\n")
1140+
out_java_struct.write("}\n" + consts.hu_struct_file_suffix)
11391141
for struct_name in tuple_types:
11401142
struct_hu_name = struct_name.replace("LDKC2Tuple", "TwoTuple").replace("LDKC3Tuple", "ThreeTuple")
11411143
with open(f"{sys.argv[3]}/structs/{struct_hu_name}{consts.file_ext}", "a") as out_java_struct:
1142-
out_java_struct.write("}\n")
1144+
out_java_struct.write("}\n" + consts.hu_struct_file_suffix)
11431145

11441146
with open(f"{sys.argv[4]}/bindings.c.body", "w") as out_c:
11451147
out_c.write(consts.c_file_pfx)

java_strings.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ def __init__(self, DEBUG: bool, target: Target, **kwargs):
1111
self.target = target
1212
self.c_array_class_caches = set()
1313
self.c_type_map = dict(
14+
bool = ['boolean'],
1415
uint8_t = ['byte'],
1516
uint16_t = ['short'],
1617
uint32_t = ['int'],
@@ -84,8 +85,6 @@ def __init__(self, DEBUG: bool, target: Target, **kwargs):
8485
}
8586
}"""
8687

87-
self.bindings_footer = "}\n"
88-
8988
self.util_fn_pfx = """package org.ldk.structs;
9089
import org.ldk.impl.bindings;
9190
import org.ldk.enums.*;
@@ -474,6 +473,7 @@ class CommonBase {
474473
import javax.annotation.Nullable;
475474
476475
"""
476+
self.hu_struct_file_suffix = ""
477477
self.c_fn_ty_pfx = "JNIEXPORT "
478478
self.c_fn_args_pfx = "JNIEnv *env, jclass clz"
479479
self.file_ext = ".java"
@@ -488,6 +488,9 @@ class CommonBase {
488488
self.is_arr_some_check = ("", " != NULL")
489489
self.get_native_arr_len_call = ("(*env)->GetArrayLength(env, ", ")")
490490

491+
def bindings_footer(self):
492+
return "}\n"
493+
491494
def construct_jenv(self):
492495
res = "JNIEnv *env;\n"
493496
res += "jint get_jenv_res = (*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_6);\n"

typescript_strings.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ def __init__(self, DEBUG: bool, target: Target, outdir: str, **kwargs):
1717
self.function_ptr_counter = 0
1818
self.function_ptrs = {}
1919
self.c_type_map = dict(
20+
bool = ['boolean', 'boolean', 'XXX'],
2021
uint8_t = ['number', 'number', 'Uint8Array'],
2122
uint16_t = ['number', 'number', 'Uint16Array'],
2223
uint32_t = ['number', 'number', 'Uint32Array'],
@@ -352,8 +353,6 @@ def __init__(self, DEBUG: bool, target: Target, outdir: str, **kwargs):
352353
return "<git_version_ldk_garbagecollected>";
353354
}"""
354355

355-
self.bindings_footer = ""
356-
357356
self.common_base = """
358357
function freer(f: () => void) { f() }
359358
const finalizer = new FinalizationRegistry(freer);
@@ -697,6 +696,7 @@ def __init__(self, DEBUG: bool, target: Target, outdir: str, **kwargs):
697696
import * as bindings from '../bindings.mjs'
698697
699698
"""
699+
self.hu_struct_file_suffix = ""
700700
self.util_fn_pfx = self.hu_struct_file_prefix + "\nexport class UtilMethods extends CommonBase {\n"
701701
self.util_fn_sfx = "}"
702702
self.c_fn_ty_pfx = ""
@@ -712,6 +712,9 @@ def __init__(self, DEBUG: bool, target: Target, outdir: str, **kwargs):
712712
self.is_arr_some_check = ("", " != 0")
713713
self.get_native_arr_len_call = ("", "->arr_len")
714714

715+
def bindings_footer(self):
716+
return ""
717+
715718
def release_native_arr_ptr_call(self, ty_info, arr_var, arr_ptr_var):
716719
return None
717720
def create_native_arr_call(self, arr_len, ty_info):

0 commit comments

Comments
 (0)