X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=genbindings.py;h=1ade1705010d1f9055fe236b0be157cb9c091146;hb=2eb87ba813b7b6c1669a8a0d900a2baa67bfea3e;hp=b8e58bc5b0e24a20c1e51a909b52965042650cb7;hpb=d4ebc8460b78ba0e16bdc07fe2e53851686ac352;p=ldk-java diff --git a/genbindings.py b/genbindings.py index b8e58bc5..1ade1705 100755 --- a/genbindings.py +++ b/genbindings.py @@ -607,7 +607,7 @@ with open(sys.argv[1]) as in_h, open(f"{sys.argv[2]}/bindings{consts.file_ext}", expected_struct in complex_enums or expected_struct in complex_enums or expected_struct in result_types or expected_struct in tuple_types) and not is_free impl_on_utils = not impl_on_struct and (not is_free and not method_name.endswith("_clone") and - not method_name.startswith("TxOut") and + not method_name.startswith("TxOut") and not method_name.startswith("BigEndianScalar") and not method_name.startswith("_") and method_name != "check_platform" and method_name != "Result_read" and not expected_struct in unitary_enums and @@ -1054,8 +1054,27 @@ with open(sys.argv[1]) as in_h, open(f"{sys.argv[2]}/bindings{consts.file_ext}", write_c("\treturn thing->value;") write_c("}") map_fn(fn_line + "\n", re.compile("(.*) (TxOut_get_value) \((.*)\)").match(fn_line), None, None, None) + elif struct_name == "LDKBigEndianScalar": + 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) + 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") + write_c("\treturn ret;\n") + write_c("}\n") + map_fn(fn_line + "\n", re.compile("(.*) (BigEndianScalar_get_bytes) \((.*)\)").match(fn_line), None, None, None) + + # We need to be able to FREE a heap-allocated BigEndianScalar, but because + # there's nothing heap-allocated inside it the C bindings don't bother + # exposing a `_free` method. Instead, we have to manually write one here, + # though it doesn't need to do anything, the autogenerated wrapper will do + # the required FREE. + fn_line = "static void BigEndianScalar_free (struct LDKBigEndianScalar thing)" + write_c(fn_line + " {}\n") + map_fn(fn_line + "\n", re.compile("static (.*) (BigEndianScalar_free) \((.*)\)").match(fn_line), None, None, None) else: - pass # Everything remaining is a byte[] or some form + pass # Everything remaining is a byte[] of some form cur_block_obj = None else: fn_ptr = fn_ptr_regex.match(line)