X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=genbindings.py;h=3d5bac974c5b563cd50d1d84dfe3d6d2b5199f59;hb=d2a89f05dbc2f27fe9aece9d55e7ea627080186f;hp=32980aa3c4e7cf8071ebcff248bac9d1ca9993d2;hpb=061af94fdcd85acba1cbaed29cba0e9a3a1fd6b4;p=ldk-java diff --git a/genbindings.py b/genbindings.py index 32980aa3..3d5bac97 100755 --- a/genbindings.py +++ b/genbindings.py @@ -260,6 +260,7 @@ def java_c_types(fn_arg, ret_arr_len): fn_ty_arg = "Ljava/lang/String;" fn_arg = fn_arg[6:].strip() elif fn_arg.startswith("LDKStr"): + rust_obj = "LDKStr" java_ty = "String" c_ty = "jstring" fn_ty_arg = "Ljava/lang/String;" @@ -408,7 +409,7 @@ with open(sys.argv[1]) as in_h, open(sys.argv[2], "w") as out_java: else: struct_meth = method_name.split("_")[0] - return_type_info = type_mapping_generator.map_type(method_return_type, True, ret_arr_len, False, False) + return_type_info = type_mapping_generator.map_type(method_return_type.strip() + " ret", True, ret_arr_len, False, False) argument_types = [] default_constructor_args = {} @@ -468,8 +469,8 @@ with open(sys.argv[1]) as in_h, open(sys.argv[2], "w") as out_java: or expected_struct in complex_enums or expected_cstruct in complex_enums or expected_cstruct in result_types) and not is_free: out_java_struct = open(f"{sys.argv[3]}/structs/{struct_meth}{consts.file_ext}", "a") - elif method_name.startswith("C2Tuple_") and method_name.endswith("_read"): - struct_meth = method_name.rsplit("_", 1)[0] + elif (method_name.startswith("C2Tuple_") and method_name.endswith("_read")) or \ + (return_type_info.rust_obj is not None and "Result" in return_type_info.rust_obj and "from" in method_name): out_java_struct = open(f"{sys.argv[3]}/structs/UtilMethods{consts.file_ext}", "a") if out_java_struct is not None: out_java_struct.write(out_java_struct_delta) @@ -512,7 +513,7 @@ with open(sys.argv[1]) as in_h, open(sys.argv[2], "w") as out_java: if "LDK" + variant_name in union_enum_items: enum_var_lines = union_enum_items["LDK" + variant_name] for idx, field in enumerate(enum_var_lines): - if idx != 0 and idx < len(enum_var_lines) - 2: + if idx != 0 and idx < len(enum_var_lines) - 2 and field.strip() != "": fields.append(type_mapping_generator.map_type(field.strip(' ;'), False, None, False, True)) enum_variants.append(ComplexEnumVariantInfo(variant_name, fields, False)) elif camel_to_snake(variant_name) in inline_enum_variants: @@ -545,7 +546,7 @@ with open(sys.argv[1]) as in_h, open(sys.argv[2], "w") as out_java: field_fns = [] for fn_docs, fn_line in trait_fn_lines: - ret_ty_info = type_mapping_generator.map_type(fn_line.group(2), True, None, False, False) + ret_ty_info = type_mapping_generator.map_type(fn_line.group(2).strip() + " ret", True, None, False, False) is_const = fn_line.group(4) is not None arg_tys = [] @@ -888,6 +889,8 @@ with open(sys.argv[1]) as in_h, open(sys.argv[2], "w") as out_java: line = line.strip() if line.startswith("struct "): line = line[7:] + elif line.startswith("enum "): + line = line[5:] split = line.split(" ") assert len(split) == 2 tuple_variants[split[1].strip(";")] = split[0]