Skip to content

Commit a25e4ce

Browse files
committed
Support 4-tuples
1 parent 2e1354c commit a25e4ce

5 files changed

+14
-10
lines changed

csharp_strings.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1179,7 +1179,7 @@ def map_opaque_struct(self, struct_name, struct_doc_comment):
11791179
out_opaque_struct_human = ""
11801180
out_opaque_struct_human += self.hu_struct_file_prefix
11811181
out_opaque_struct_human += "\n/**\n * " + struct_doc_comment.replace("\n", "\n * ") + "\n */\n"
1182-
hu_name = struct_name.replace("LDKC2Tuple", "TwoTuple").replace("LDKC3Tuple", "ThreeTuple").replace("LDK", "")
1182+
hu_name = struct_name.replace("LDKC2Tuple", "TwoTuple").replace("LDKC3Tuple", "ThreeTuple").replace("LDKC4Tuple", "FourTuple").replace("LDK", "")
11831183
out_opaque_struct_human += ("public class " + hu_name + " : CommonBase")
11841184
if struct_name.startswith("LDKLocked") or struct_name.startswith("LDKReadOnly"):
11851185
out_opaque_struct_human += (", IDisposable")

genbindings.py

+10-6
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,7 @@ def java_c_types(fn_arg, ret_arr_len):
403403
java_hu_ty = java_hu_ty.replace("LDKCResult", "Result")
404404
java_hu_ty = java_hu_ty.replace("LDKC2Tuple", "TwoTuple")
405405
java_hu_ty = java_hu_ty.replace("LDKC3Tuple", "ThreeTuple")
406+
java_hu_ty = java_hu_ty.replace("LDKC4Tuple", "FourTuple")
406407
java_hu_ty = java_hu_ty.replace("LDK", "")
407408
fn_ty_arg = "J"
408409
fn_arg = ma.group(2).strip()
@@ -571,14 +572,17 @@ def map_fn_with_ref_option(line, re_match, ret_arr_len, c_call_string, doc_comme
571572
struct_meth = method_name.rsplit("Z", 1)[0][1:] + "Z"
572573
expected_struct = "LDKC" + struct_meth
573574
struct_meth_name = method_name[len(struct_meth) + 1:].strip("_")
574-
elif method_name.startswith("C2Tuple") or method_name.startswith("C3Tuple"):
575+
elif method_name.startswith("C2Tuple") or method_name.startswith("C3Tuple") or method_name.startswith("C4Tuple"):
575576
tuple_name = method_name.rsplit("Z", 1)[0][2:] + "Z"
576577
if method_name.startswith("C2Tuple"):
577578
struct_meth = "Two" + tuple_name
578579
expected_struct = "LDKC2" + tuple_name
579-
else:
580+
elif method_name.startswith("C3Tuple"):
580581
struct_meth = "Three" + tuple_name
581582
expected_struct = "LDKC3" + tuple_name
583+
else:
584+
struct_meth = "Four" + tuple_name
585+
expected_struct = "LDKC4" + tuple_name
582586
struct_meth_name = method_name[len(tuple_name) + 2:].strip("_")
583587
else:
584588
struct_meth = method_name.split("_")[0]
@@ -666,7 +670,7 @@ def map_fn_with_ref_option(line, re_match, ret_arr_len, c_call_string, doc_comme
666670
not method_name.startswith("_") and
667671
method_name != "check_platform" and method_name != "Result_read" and
668672
not expected_struct in unitary_enums and
669-
((not method_name.startswith("C2Tuple_") and not method_name.startswith("C3Tuple_"))
673+
((not method_name.startswith("C2Tuple_") and not method_name.startswith("C3Tuple_") and not method_name.startswith("C4Tuple_"))
670674
or method_name.endswith("_read")))
671675

672676
# If we're adding a static method, and it returns a primitive or an array of primitives,
@@ -909,7 +913,7 @@ def create_getter(struct_name, field_decl, field_name, accessor, check_sfx):
909913
map_fn_with_ref_option(dummy_line, reg_fn_regex.match(dummy_line), None, None, "", holds_ref)
910914

911915
def map_tuple(struct_name, field_lines):
912-
human_ty = struct_name.replace("LDKC2Tuple", "TwoTuple").replace("LDKC3Tuple", "ThreeTuple")
916+
human_ty = struct_name.replace("LDKC2Tuple", "TwoTuple").replace("LDKC3Tuple", "ThreeTuple").replace("LDKC4Tuple", "FourTuple")
913917
with open(f"{sys.argv[3]}/structs/{human_ty}{consts.file_ext}", "w") as out_java_struct:
914918
out_java_struct.write(consts.map_tuple(struct_name))
915919
ty_list = []
@@ -1008,7 +1012,7 @@ def map_tuple(struct_name, field_lines):
10081012
vec_ty_match = line_indicates_vec_regex.match(struct_line)
10091013
if vec_ty_match is not None and struct_name.startswith("LDKCVec_"):
10101014
vec_ty = vec_ty_match.group(2)
1011-
elif struct_name.startswith("LDKC2Tuple_") or struct_name.startswith("LDKC3Tuple_"):
1015+
elif struct_name.startswith("LDKC2Tuple_") or struct_name.startswith("LDKC3Tuple_") or struct_name.startswith("LDKC4Tuple_"):
10121016
is_tuple = True
10131017
trait_fn_match = line_indicates_trait_regex.match(struct_line)
10141018
if trait_fn_match is not None:
@@ -1186,7 +1190,7 @@ def map_tuple(struct_name, field_lines):
11861190
with open(f"{sys.argv[3]}/structs/{struct_name.replace('LDKCResult', 'Result')}{consts.file_ext}", "a") as out_java_struct:
11871191
out_java_struct.write("}\n" + consts.hu_struct_file_suffix)
11881192
for struct_name in tuple_types:
1189-
struct_hu_name = struct_name.replace("LDKC2Tuple", "TwoTuple").replace("LDKC3Tuple", "ThreeTuple")
1193+
struct_hu_name = struct_name.replace("LDKC2Tuple", "TwoTuple").replace("LDKC3Tuple", "ThreeTuple").replace("LDKC4Tuple", "FourTuple")
11901194
with open(f"{sys.argv[3]}/structs/{struct_hu_name}{consts.file_ext}", "a") as out_java_struct:
11911195
out_java_struct.write("}\n" + consts.hu_struct_file_suffix)
11921196

java_strings.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1390,7 +1390,7 @@ def map_opaque_struct(self, struct_name, struct_doc_comment):
13901390
out_opaque_struct_human += self.hu_struct_file_prefix
13911391
out_opaque_struct_human += "\n/**\n * " + struct_doc_comment.replace("\n", "\n * ") + "\n */\n"
13921392
out_opaque_struct_human += "@SuppressWarnings(\"unchecked\") // We correctly assign various generic arrays\n"
1393-
hu_name = struct_name.replace("LDKC2Tuple", "TwoTuple").replace("LDKC3Tuple", "ThreeTuple").replace("LDK", "")
1393+
hu_name = struct_name.replace("LDKC2Tuple", "TwoTuple").replace("LDKC4Tuple", "FourTuple").replace("LDKC3Tuple", "ThreeTuple").replace("LDK", "")
13941394
out_opaque_struct_human += ("public class " + hu_name + " extends CommonBase")
13951395
if struct_name.startswith("LDKLocked") or struct_name.startswith("LDKReadOnly"):
13961396
out_opaque_struct_human += (" implements AutoCloseable")

python_strings.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1291,7 +1291,7 @@ def map_complex_enum(self, struct_name, variant_list, camel_to_snake, enum_doc_c
12911291
def map_opaque_struct(self, struct_name, struct_doc_comment):
12921292
method_header = ""
12931293

1294-
hu_name = struct_name.replace("LDKC2Tuple", "TwoTuple").replace("LDKC3Tuple", "ThreeTuple").replace("LDK", "")
1294+
hu_name = struct_name.replace("LDKC2Tuple", "TwoTuple").replace("LDKC3Tuple", "ThreeTuple").replace("LDKC4Tuple", "FourTuple").replace("LDK", "")
12951295
out_opaque_struct_human = f"{self.hu_struct_file_prefix}"
12961296
extra_docs = ""
12971297
extra_body = ""

typescript_strings.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1409,7 +1409,7 @@ def map_complex_enum(self, struct_name, variant_list, camel_to_snake, enum_doc_c
14091409
def map_opaque_struct(self, struct_name, struct_doc_comment):
14101410
method_header = ""
14111411

1412-
hu_name = struct_name.replace("LDKC2Tuple", "TwoTuple").replace("LDKC3Tuple", "ThreeTuple").replace("LDK", "")
1412+
hu_name = struct_name.replace("LDKC2Tuple", "TwoTuple").replace("LDKC3Tuple", "ThreeTuple").replace("LDKC4Tuple", "FourTuple").replace("LDK", "")
14131413
out_opaque_struct_human = f"{self.hu_struct_file_prefix}"
14141414
constructor_body = "super(ptr, bindings." + struct_name.replace("LDK","") + "_free);"
14151415
extra_docs = ""

0 commit comments

Comments
 (0)