You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#13 added language to call out that Option<&T> is FFI-safe as long as *const T is FFI-safe. Based on rust-lang/rust#40913, it seems that the preferred way of expressing nullable function pointers (returned via FFI) is using Option<fn> (or I guess Option<extern "C" fn> since function pointers set by C code are presumably also C-ABI).
If my understanding is correct, shall we add this to the Nomicon? I'm happy to send a PR if that's desired.
Also, are Option<&T> and Option<extern "C" fn> an exhaustive list of repr(C) FFI-safe enums with fields, or are there other exceptions to document as well?
The text was updated successfully, but these errors were encountered:
Actually, it looks like this is covered by the nullable pointer optimization section, which specifically mentions function pointers (along with &T, &mut T, and boxes). I wonder if it's worth including a forward pointer to the more comprehensive section in the bullet added in #13 (cc: @geofft).
If possible the clarified language on other-reprs should link to the nullable pointer optimization. I'm thinking the wording should be something like:
If T is an FFI-safe non-nullable pointer type, Option<T> is guaranteed to have the same layout and ABI as T and is therefore also FFI-safe. As of this writing, this covers &, &mut, and function pointers.
Relatively new to Rust, and reading through the Nomicon to make sure I build a new FFI module safely. I noticed one omission in https://github.com/rust-lang-nursery/nomicon/blob/master/src/other-reprs.md.
#13 added language to call out that
Option<&T>
is FFI-safe as long as*const T
is FFI-safe. Based on rust-lang/rust#40913, it seems that the preferred way of expressing nullable function pointers (returned via FFI) is usingOption<fn>
(or I guessOption<extern "C" fn>
since function pointers set by C code are presumably also C-ABI).If my understanding is correct, shall we add this to the Nomicon? I'm happy to send a PR if that's desired.
Also, are
Option<&T>
andOption<extern "C" fn>
an exhaustive list ofrepr(C)
FFI-safe enums with fields, or are there other exceptions to document as well?The text was updated successfully, but these errors were encountered: