mozilla / cbindgen

A project for generating C bindings from Rust code
Mozilla Public License 2.0
2.37k stars 306 forks source link

Opaque type for Mutex #930

Open ultimaweapon opened 7 months ago

ultimaweapon commented 7 months ago

Is it possible for cbindgen to automatically generate an opaque type for Mutex for this function?

#[no_mangle]
pub unsafe extern "C-unwind" fn foo(bar: *const Mutex<Bar>) {}

What I got from this is something like without opaque type for Mutex:

struct Bar;

void foo(const Mutex<Bar> *bar);
ultimaweapon commented 7 months ago

I need something like this but don't know how to configure the cbindgen::Builder to achieve this result.

emilio commented 5 months ago

Send a patch adding it to Parse::add_std_types to get what you want. Alternatively, add the raw forward declaration using one of the other config options?

ultimaweapon commented 5 months ago

Thank you for the response. I'll send a patch when I have time to work on this.

dwlsalmeida commented 3 days ago

@emilio Why do we automatically generate opaque types for non repr(C) structs, but have to manually list out the std types we want to consider as opaque?

Also, shouldn't we add an option to force a type to be opaque? I guess that would solve the problem more generally, because then someone could just say they want Mutex to be opaque through cbindgen.toml.