Fix short, push trait struct refcnt increment down to lang
[ldk-java] / gen_type_mapping.py
index d78057b6a3a29acba9b18c57ead2ba7cba5b1ff1..fe2aed21397c45a2e26b39b2333fd90fdfb83fb7 100644 (file)
@@ -17,7 +17,8 @@ class TypeMappingGenerator:
 
     def map_type(self, fn_arg, print_void, ret_arr_len, is_free, holds_ref):
         ty_info = self.java_c_types(fn_arg, ret_arr_len)
-        return self.map_type_with_info(ty_info, print_void, ret_arr_len, is_free, holds_ref)
+        mapped_info = self.map_type_with_info(ty_info, print_void, ret_arr_len, is_free, holds_ref)
+        return mapped_info
 
     def map_type_with_info(self, ty_info, print_void, ret_arr_len, is_free, holds_ref):
         if ty_info.c_ty == "void":
@@ -274,9 +275,7 @@ class TypeMappingGenerator:
                         if needs_full_clone and (ty_info.rust_obj.replace("LDK", "") + "_clone") in self.clone_fns:
                             base_conv = base_conv + "\n" + ty_info.var_name + "_conv = " + ty_info.rust_obj.replace("LDK", "") + "_clone(" + ty_info.var_name + ");"
                         else:
-                            base_conv = base_conv + "\nif (" + ty_info.var_name + "_conv.free == " + ty_info.rust_obj + "_JCalls_free) {\n"
-                            base_conv = base_conv + "\t// If this_arg is a JCalls struct, then we need to increment the refcnt in it.\n"
-                            base_conv = base_conv + "\t" + ty_info.rust_obj + "_JCalls_clone(" + ty_info.var_name + "_conv.this_arg);\n}"
+                            base_conv = base_conv + self.consts.trait_struct_inc_refcnt(ty_info)
                             if needs_full_clone:
                                 base_conv = base_conv + "// Warning: we may need a move here but can't do a full clone!\n"