X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=gen_type_mapping.py;h=39ee2605a88804d24ef707c468ded6d84aed760c;hb=f95cc8ba7d61d65aa37e6448e6a083edc6e72fc1;hp=81bb0f99b8ebcaa5236073fa627514c8d224a212;hpb=0d48e557e83ef085cc92c2de63b9c81c061ce78c;p=ldk-java diff --git a/gen_type_mapping.py b/gen_type_mapping.py index 81bb0f99..39ee2605 100644 --- a/gen_type_mapping.py +++ b/gen_type_mapping.py @@ -371,18 +371,21 @@ class TypeMappingGenerator: # underlying unlike Vecs, and it gives Java more freedom. base_conv = base_conv + "\nFREE((void*)" + ty_info.var_name + ");" if ty_info.rust_obj in self.complex_enums: + to_hu_conv_sfx = "" if needs_full_clone and (ty_info.rust_obj.replace("LDK", "") + "_clone") not in self.clone_fns: # We really need a full clone here, but for now we just implement # a manual clone explicitly for Options - if ty_info.rust_obj.startswith("LDKCOption"): + if ty_info.contains_trait: + assert ty_info.rust_obj.startswith("LDKCOption") # We don't support contained traits for anything else yet optional_ty = ty_info.rust_obj[11:-1] - if "LDK" + optional_ty in self.trait_structs: - base_conv += "\nif (" + ty_info.var_name + "_conv.tag == " + ty_info.rust_obj + "_Some) {" - base_conv += "\n\t// Manually implement clone for Java trait instances" - optional_ty_info = self.java_c_types("LDK" + optional_ty + " " + ty_info.var_name, None) - base_conv += self.consts.trait_struct_inc_refcnt(optional_ty_info).\ - replace("\n", "\n\t").replace(ty_info.var_name + "_conv", ty_info.var_name + "_conv.some") - base_conv += "\n}" + assert "LDK" + optional_ty in self.trait_structs # We don't support contained traits for anything else yet + to_hu_conv_sfx = "this.ptrs_to.add(" + ty_info.var_name + ")" + base_conv += "\nif (" + ty_info.var_name + "_conv.tag == " + ty_info.rust_obj + "_Some) {" + base_conv += "\n\t// Manually implement clone for Java trait instances" + optional_ty_info = self.java_c_types("LDK" + optional_ty + " " + ty_info.var_name, None) + base_conv += self.consts.trait_struct_inc_refcnt(optional_ty_info).\ + replace("\n", "\n\t").replace(ty_info.var_name + "_conv", ty_info.var_name + "_conv.some") + base_conv += "\n}" ret_conv = ("uint64_t " + ty_info.var_name + "_ref = ((uint64_t)&", ") | 1;") if not holds_ref: ret_conv = (ty_info.rust_obj + " *" + ty_info.var_name + "_copy = MALLOC(sizeof(" + ty_info.rust_obj + "), \"" + ty_info.rust_obj + "\");\n", "") @@ -392,7 +395,7 @@ class TypeMappingGenerator: arg_conv = base_conv, arg_conv_name = ty_info.var_name + "_conv", arg_conv_cleanup = None, ret_conv = ret_conv, ret_conv_name = ty_info.var_name + "_ref", to_hu_conv = ty_info.java_hu_ty + " " + ty_info.var_name + "_hu_conv = " + ty_info.java_hu_ty + ".constr_from_ptr(" + ty_info.var_name + ");\n" + ty_info.var_name + "_hu_conv.ptrs_to.add(this);", - to_hu_conv_name = ty_info.var_name + "_hu_conv", from_hu_conv = (ty_info.var_name + ".ptr", "")) + to_hu_conv_name = ty_info.var_name + "_hu_conv", from_hu_conv = (ty_info.var_name + ".ptr", to_hu_conv_sfx)) if ty_info.rust_obj in self.result_types: if holds_ref: # If we're trying to return a ref, we have to clone.