phosphorus icon indicating copy to clipboard operation
phosphorus copied to clipboard

generated structs should be `#repr(C)` and the `_priv` field should be a `[u8; 0]`

Open i509VCB opened this issue 3 years ago • 1 comments

I noticed the structs generated, such as __GLSync, are generated as follows:

#[doc(hidden)]
pub struct __GLsync {
    _priv: u8,
}

Although this type is only ever used as a pointer, it disagrees with the FFI chapter of the nomicon: https://doc.rust-lang.org/nomicon/ffi.html#representing-opaque-structs

The nomicon says such as type should be #[repr(C)] and should have a field of [u8; 0] to ensure it is impossible to instantiate. The PhantomPinned appears to ensure you can't pin the thing either.

i509VCB avatar Feb 26 '22 04:02 i509VCB

Those types are never passed over FFI, just an opaque pointer to them, so it's fine.

Lokathor avatar Feb 26 '22 14:02 Lokathor