X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=genbindings.py;h=3a6551430cd3fb40bea6f437120582bb3b11799f;hb=22f5f4208b1f3b5542292250f1612b944f5cd7fd;hp=20c09fab9496340064defc9e75fb7edd6583d552;hpb=6884c87ff29249df35c246e86e4d6e38bc930d34;p=ldk-java diff --git a/genbindings.py b/genbindings.py index 20c09fab..3a655143 100755 --- a/genbindings.py +++ b/genbindings.py @@ -201,7 +201,7 @@ def java_c_types(fn_arg, ret_arr_len): elif fn_arg.startswith("uint16_t"): mapped_type = consts.c_type_map['uint16_t'] java_ty = mapped_type[0] - c_ty = "jshort" + c_ty = "int16_t" fn_ty_arg = "S" fn_arg = fn_arg[8:].strip() is_primitive = True @@ -214,13 +214,14 @@ def java_c_types(fn_arg, ret_arr_len): is_primitive = True elif fn_arg.startswith("uint64_t") or fn_arg.startswith("uintptr_t"): # TODO: uintptr_t is arch-dependent :( - mapped_type = consts.c_type_map['long'] + mapped_type = consts.c_type_map['uint64_t'] java_ty = mapped_type[0] - c_ty = "int64_t" fn_ty_arg = "J" if fn_arg.startswith("uint64_t"): + c_ty = "int64_t" fn_arg = fn_arg[8:].strip() else: + c_ty = "intptr_t" fn_arg = fn_arg[9:].strip() is_primitive = True elif is_const and fn_arg.startswith("char *"): @@ -331,13 +332,9 @@ fn_ret_arr_regex = re.compile("(.*) \(\*(.*)\((.*)\)\)\[([0-9]*)\];$") reg_fn_regex = re.compile("([A-Za-z_0-9\* ]* \*?)([a-zA-Z_0-9]*)\((.*)\);$") clone_fns = set() constructor_fns = {} -c_array_class_caches = set() - from gen_type_mapping import TypeMappingGenerator -type_mapping_generator = TypeMappingGenerator(java_c_types, consts, c_array_class_caches, opaque_structs, clone_fns, unitary_enums, trait_structs, complex_enums, result_types, tuple_types) - - +type_mapping_generator = TypeMappingGenerator(java_c_types, consts, opaque_structs, clone_fns, unitary_enums, trait_structs, complex_enums, result_types, tuple_types) with open(sys.argv[1]) as in_h: for line in in_h: @@ -919,20 +916,8 @@ with open(sys.argv[1]) as in_h, open(sys.argv[2], "w") as out_java: if is_opaque: opaque_structs.add(struct_name) with open(f"{sys.argv[3]}/structs/{struct_name.replace('LDK', '')}{consts.file_ext}", "w") as out_java_struct: - out_java_struct.write(consts.hu_struct_file_prefix) - out_java_struct.write("public class " + struct_name.replace("LDK","") + " extends CommonBase") - if struct_name.startswith("LDKLocked"): - out_java_struct.write(" implements AutoCloseable") - out_java_struct.write(" {\n") - out_java_struct.write("\t" + struct_name.replace("LDK", "") + "(Object _dummy, long ptr) { super(ptr); }\n") - if struct_name.startswith("LDKLocked"): - out_java_struct.write("\t@Override public void close() {\n") - else: - out_java_struct.write("\t@Override @SuppressWarnings(\"deprecation\")\n") - out_java_struct.write("\tprotected void finalize() throws Throwable {\n") - out_java_struct.write("\t\tsuper.finalize();\n") - out_java_struct.write("\t\tif (ptr != 0) { bindings." + struct_name.replace("LDK","") + "_free(ptr); }\n") - out_java_struct.write("\t}\n\n") + out_opaque_struct_human = consts.map_opaque_struct(struct_name) + out_java_struct.write(out_opaque_struct_human) elif result_contents is not None: assert result_contents in result_ptr_struct_items res_ty, err_ty = result_ptr_struct_items[result_contents] @@ -958,7 +943,8 @@ with open(sys.argv[1]) as in_h, open(sys.argv[2], "w") as out_java: write_c("\t\tret->data = NULL;\n") write_c("\t} else {\n") write_c("\t\tret->data = MALLOC(sizeof(" + vec_ty + ") * ret->datalen, \"" + struct_name + " Data\");\n") - write_c("\t\t" + ty_info.c_ty + " *java_elems = " + consts.get_native_arr_ptr_call[0] + "elems" + consts.get_native_arr_ptr_call[1] + ";\n") + native_arr_ptr_call = consts.get_native_arr_ptr_call(ty_info.ty_info) + write_c("\t\t" + ty_info.c_ty + " *java_elems = " + native_arr_ptr_call[0] + "elems" + native_arr_ptr_call[1] + ";\n") write_c("\t\tfor (size_t i = 0; i < ret->datalen; i++) {\n") if ty_info.arg_conv is not None: write_c("\t\t\t" + ty_info.c_ty + " arr_elem = java_elems[i];\n") @@ -968,7 +954,7 @@ with open(sys.argv[1]) as in_h, open(sys.argv[2], "w") as out_java: else: write_c("\t\t\tret->data[i] = java_elems[i];\n") write_c("\t\t}\n") - cleanup = consts.release_native_arr_ptr_call("elems", "java_elems") + cleanup = consts.release_native_arr_ptr_call(ty_info.ty_info, "elems", "java_elems") if cleanup is not None: write_c("\t\t" + cleanup + ";\n") write_c("\t}\n") @@ -1058,5 +1044,5 @@ with open(sys.argv[1]) as in_h, open(sys.argv[2], "w") as out_java: out_java_struct.write("}\n") with open(sys.argv[4], "w") as out_c: out_c.write(consts.c_file_pfx) - out_c.write(consts.init_str(c_array_class_caches)) + out_c.write(consts.init_str()) out_c.write(c_file)