Skip to content

Commit 29b209c

Browse files
committed
[bindings] Expose a _clone fn for every struct that derive(Clone)s
1 parent faa8ec5 commit 29b209c

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

c-bindings-gen/src/main.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,10 @@ fn writeln_opaque<W: std::io::Write>(w: &mut W, ident: &syn::Ident, struct_name:
450450
writeln!(w, "pub(crate) extern \"C\" fn {}_clone_void(this_ptr: *const c_void) -> *mut c_void {{", struct_name).unwrap();
451451
writeln!(w, "\tBox::into_raw(Box::new(unsafe {{ (*(this_ptr as *mut native{})).clone() }})) as *mut c_void", struct_name).unwrap();
452452
writeln!(w, "}}").unwrap();
453+
writeln!(w, "#[no_mangle]").unwrap();
454+
writeln!(w, "pub extern \"C\" fn {}_clone(orig: &{}) -> {} {{", struct_name, struct_name, struct_name).unwrap();
455+
writeln!(w, "\t{} {{ inner: Box::into_raw(Box::new(unsafe {{ &*orig.inner }}.clone())), is_owned: true }}", struct_name).unwrap();
456+
writeln!(w, "}}").unwrap();
453457
break 'attr_loop;
454458
}
455459
}

0 commit comments

Comments
 (0)