[bindings] Expose a _clone fn for every struct that derive(Clone)s
authorMatt Corallo <git@bluematt.me>
Mon, 12 Oct 2020 03:51:22 +0000 (23:51 -0400)
committerMatt Corallo <git@bluematt.me>
Mon, 23 Nov 2020 16:08:34 +0000 (11:08 -0500)
c-bindings-gen/src/main.rs

index 4edad55d1fb9ff9ae071802e76ba5287e77b46dc..b4a148fbafcb967e34ffd426cf74cdbb9ddc6086 100644 (file)
@@ -450,6 +450,10 @@ fn writeln_opaque<W: std::io::Write>(w: &mut W, ident: &syn::Ident, struct_name:
                                                                        writeln!(w, "pub(crate) extern \"C\" fn {}_clone_void(this_ptr: *const c_void) -> *mut c_void {{", struct_name).unwrap();
                                                                        writeln!(w, "\tBox::into_raw(Box::new(unsafe {{ (*(this_ptr as *mut native{})).clone() }})) as *mut c_void", struct_name).unwrap();
                                                                        writeln!(w, "}}").unwrap();
+                                                                       writeln!(w, "#[no_mangle]").unwrap();
+                                                                       writeln!(w, "pub extern \"C\" fn {}_clone(orig: &{}) -> {} {{", struct_name, struct_name, struct_name).unwrap();
+                                                                       writeln!(w, "\t{} {{ inner: Box::into_raw(Box::new(unsafe {{ &*orig.inner }}.clone())), is_owned: true }}", struct_name).unwrap();
+                                                                       writeln!(w, "}}").unwrap();
                                                                        break 'attr_loop;
                                                                }
                                                        }