From 29b209ceea3059aadc86efdd7a6a3b42be924904 Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Sun, 11 Oct 2020 23:51:22 -0400 Subject: [PATCH] [bindings] Expose a _clone fn for every struct that derive(Clone)s --- c-bindings-gen/src/main.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/c-bindings-gen/src/main.rs b/c-bindings-gen/src/main.rs index 4edad55d..b4a148fb 100644 --- a/c-bindings-gen/src/main.rs +++ b/c-bindings-gen/src/main.rs @@ -450,6 +450,10 @@ fn writeln_opaque(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; } } -- 2.30.2