X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=gen_type_mapping.py;h=b285ab34477554b4f60f3822b7b6093bd444ded0;hb=1a849ce9a84a17a58ba0e19cb60dfdf95242356b;hp=fb810c92319b6f3b9152db84b9419c1e25c60691;hpb=5e2e8f6fdee605dd8e1c674f054d64f1085691fc;p=ldk-java diff --git a/gen_type_mapping.py b/gen_type_mapping.py index fb810c92..b285ab34 100644 --- a/gen_type_mapping.py +++ b/gen_type_mapping.py @@ -183,11 +183,7 @@ class TypeMappingGenerator: to_hu_conv = None to_hu_conv_name = None if subty.to_hu_conv is not None: - base_ty = ty_info.subty.java_hu_ty.split("[")[0].split("<")[0] - to_hu_conv = self.consts.var_decl_statement(ty_info.java_hu_ty, conv_name + "_arr", "new " + base_ty + "[" + arr_name + ".length]") - if "[" in ty_info.subty.java_hu_ty.split("<")[0]: - # Do a bit of a dance to move any excess [] to the end - to_hu_conv += "[" + ty_info.subty.java_hu_ty.split("<")[0].split("[")[1] + to_hu_conv = self.consts.var_decl_statement(ty_info.java_hu_ty, conv_name + "_arr", self.consts.constr_hu_array(ty_info, arr_name + ".length")) to_hu_conv += ";\n" + self.consts.for_n_in_range(idxc, "0", arr_name + ".length") + "\n" to_hu_conv += "\t" + self.consts.var_decl_statement(subty.java_ty, conv_name, arr_name + "[" + idxc + "]") + ";\n" to_hu_conv += "\t" + subty.to_hu_conv.replace("\n", "\n\t") + "\n" @@ -204,7 +200,7 @@ class TypeMappingGenerator: return ConvInfo(ty_info = ty_info, arg_name = ty_info.var_name, arg_conv = arg_conv, arg_conv_name = arg_conv_name, arg_conv_cleanup = arg_conv_cleanup, ret_conv = ret_conv, ret_conv_name = arr_name + "_arr", to_hu_conv = to_hu_conv, to_hu_conv_name = to_hu_conv_name, from_hu_conv = from_hu_conv) - elif ty_info.java_ty == "String": + elif ty_info.java_fn_ty_arg == "Ljava/lang/String;": assert not is_nullable if not is_free: arg_conv = "LDKStr " + ty_info.var_name + "_conv = " + self.consts.str_ref_to_c_call(ty_info.var_name) + ";" @@ -213,6 +209,7 @@ class TypeMappingGenerator: arg_conv = "LDKStr dummy = { .chars = NULL, .len = 0, .chars_is_owned = false };" arg_conv_name = "dummy" if ty_info.arr_access is None: + assert False return ConvInfo(ty_info = ty_info, arg_name = ty_info.var_name, arg_conv = arg_conv, arg_conv_name = arg_conv_name, arg_conv_cleanup = None, ret_conv = ("const char* " + ty_info.var_name + "_str = ", @@ -223,11 +220,17 @@ class TypeMappingGenerator: free_str = "" if not holds_ref: free_str = "\nStr_free(" + ty_info.var_name + "_str);" + to_hu_conv = self.consts.str_to_hu_conv(ty_info.var_name) + to_hu_conv_name = None + if to_hu_conv is not None: + to_hu_conv_name = ty_info.var_name + "_conv" return ConvInfo(ty_info = ty_info, arg_name = ty_info.var_name, arg_conv = arg_conv, arg_conv_name = arg_conv_name, arg_conv_cleanup = None, ret_conv = ("LDKStr " + ty_info.var_name + "_str = ", ";\njstring " + ty_info.var_name + "_conv = " + self.consts.str_ref_to_native_call(ty_info.var_name + "_str." + ty_info.arr_access, ty_info.var_name + "_str." + ty_info.arr_len) + ";" + free_str), - ret_conv_name = ty_info.var_name + "_conv", to_hu_conv = None, to_hu_conv_name = None, from_hu_conv = None) + ret_conv_name = ty_info.var_name + "_conv", + to_hu_conv=to_hu_conv, to_hu_conv_name=to_hu_conv_name, + from_hu_conv = self.consts.str_from_hu_conv(ty_info.var_name)) elif ty_info.var_name == "" and not print_void: # We don't have a parameter name, and want one, just call it arg if not ty_info.is_native_primitive: @@ -538,9 +541,12 @@ class TypeMappingGenerator: to_hu_conv = self.consts.var_decl_statement(ty_info.java_hu_ty, "ret_hu_conv", "new " + ty_info.java_hu_ty + "(null, " + ty_info.var_name + ")") + ";\n" + self.consts.add_ref("ret_hu_conv", "this") + ";", to_hu_conv_name = "ret_hu_conv", from_hu_conv = (ty_info.var_name + " == null ? 0 : " + self.consts.get_ptr(ty_info.var_name), self.consts.add_ref("this", ty_info.var_name))) + ret_conv = ("uint64_t ret_" + ty_info.var_name + " = (uint64_t)", ";") + if holds_ref: + ret_conv = (ret_conv[0], " | 1;") return ConvInfo(ty_info = ty_info, arg_name = ty_info.var_name, arg_conv = ty_info.rust_obj + "* " + ty_info.var_name + "_conv = (" + ty_info.rust_obj + "*)(" + ty_info.var_name + " & ~1);", arg_conv_name = ty_info.var_name + "_conv", arg_conv_cleanup = None, - ret_conv = ("uint64_t ret_" + ty_info.var_name + " = (uint64_t)", ";"), ret_conv_name = "ret_" + ty_info.var_name, + ret_conv = ret_conv, ret_conv_name = "ret_" + ty_info.var_name, to_hu_conv = "TODO 3", to_hu_conv_name = None, from_hu_conv = None) # its a pointer, no conv needed assert False # We should have handled every case by now.