Open CGMossa opened 10 months ago
Hello. I was asked to look at this issue but I don't have any wider context of your specific project.
That said, I'd advise the following:
/// S-expression data that is opaque to Rust
#[repr(transparent)]
pub struct SEXPREC(c_void);
// if you want this alias too
pub type s_object = SEXPREC;
I'm genuinely not sure why the Nomicon is concerned with the value itself being Send/Sync or not because pointers to it will naturally be !Send and !Sync. The c_void
field will also correctly make the type Unpin.
Thanks! My use case requires pub type SEXP = *mut SEXPREC;
.
So
/// S-expression data that is opaque to Rust
#[repr(transparent)]
pub struct SEXPREC(c_void);
// if you want this alias too
pub type SEXP = *mut SEXPREC;
Is it possible to make bindgen produce this pattern?
I haven't used bindgen in years, I just make bindings by hand generally. You would probably have to file an issue to make them support this.
I agree that the current codegen for opaque types is unnecessarily dangerous and should be changed to follow the current nomicon guidelines.
We have a pointer type to an opaque type in our FFI project.
Bindgen generates this definition for the opaque type:
But then I was reading https://stackoverflow.com/questions/38315383/whats-the-rust-idiom-to-define-a-field-pointing-to-a-c-opaque-pointer, and https://doc.rust-lang.org/nomicon/ffi.html#representing-opaque-structs, which says that the definition of the above should really be:
Is this something I should replace the bindgen-version with this?
Lastly, I merely have these in the C-headers:
with no definition of
s_object
, and I'm quite certain this is intended behavior.