I have an external ABI for FFI with the following
#[repr(C)]
#[derive(Debug)]
pub struct Schema {
name: *const ::std::os::raw::c_char,
children: *mut *mut Schema,
release: ::std::option::Option<unsafe extern "C" fn(arg1: *mut Schema)>,
private_data: *mut ::std::os::raw::c_void,
}
where release is a callback to release, which is responsible for releasing all members, potentially recursively. The provided rules are that the release is expected to be called when the struct should be freed.
We want to use and share the data inside this struct across multiple objects. I only receive a pointer *mut Schema with this struct.
How do I correctly handle this?
I tried a couple of things:
Wrap under an Arc
Arc<Schema>to share.impl Drop for Schemaand call the release from it.
Challenge: I will need to deference the pointer to wrap it in the Arc, which requires Copy; Copy and Drop are incompatible
Wrap the pointer under an Arc
Arc<*mut Schema>orArc<&'static mut Schema>to share.
Challenge: I was unable to correctly drop this struct, as there is no callback I can use for it.
Any ideas?