Drop clone on tuple-field-fetching
authorMatt Corallo <git@bluematt.me>
Sat, 13 Aug 2022 01:34:03 +0000 (01:34 +0000)
committerMatt Corallo <git@bluematt.me>
Sat, 13 Aug 2022 18:07:26 +0000 (18:07 +0000)
Early in the lifetime of the bindings here tuple-field-fetching
had memory tracking issues which appear to have been solved now.
Thus, we can go ahead and drop the clone, at least for has-inner
types.

Fixes #84.

genbindings.py

index 7ff9069b25d36b8ec0109e1a0dd7af1d36ccff6d..b8e58bc5b0e24a20c1e51a909b52965042650cb7 100755 (executable)
@@ -816,7 +816,13 @@ with open(sys.argv[1]) as in_h, open(f"{sys.argv[2]}/bindings{consts.file_ext}",
         owned_fn_defn = field_decl + " " + struct_name.replace("LDK", "") + "_get_" + field_name + "(" + struct_name + " *NONNULL_PTR owner)"
 
         holds_ref = False
-        if field_ty.rust_obj is not None and field_ty.rust_obj.replace("LDK", "") + "_clone" in clone_fns:
+        if field_ty.rust_obj is not None and field_ty.rust_obj in opaque_structs:
+            fn_defn = owned_fn_defn
+            write_c("static inline " + fn_defn + "{\n")
+            write_c("\t" + field_ty.rust_obj + " ret = " + accessor[0] + "owner" + accessor[1] + ";\n")
+            write_c("\tret.is_owned = false;\n")
+            write_c("\treturn ret;\n")
+        elif field_ty.rust_obj is not None and field_ty.rust_obj.replace("LDK", "") + "_clone" in clone_fns:
             fn_defn = owned_fn_defn
             write_c("static inline " + fn_defn + "{\n")
             if check_sfx is not None: