-
Notifications
You must be signed in to change notification settings - Fork 47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add some missing FFI safe types #42
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -130,7 +130,14 @@ The following types are considered C-compatible: | |
- `repr(C)`-annotated `struct`, | ||
- `repr(C)` or `repr(Int)`-annotated `enum` with at least one variant and only | ||
fieldless variants (where `Int` is an integral primitive type), | ||
- pointers. | ||
- pointers, | ||
- an `Option<T>` where `T` is either | ||
- `core::ptr::NonNull<U>` and `U` is a `Sized` C-compatible type, then it is | ||
compatible to a `*const T` and `*mut T` pointer; | ||
- `core::num::NonZero*`, then is compatible to the corresponding integral | ||
primitive type; | ||
- a `repr(transparent)`-annotated `struct` with only one field, where that | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're allowed to have more than one field if one is a align-1 ZST. This is common for PhantomData, for example. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're even allowed to have an arbitrary amount of align-1 ZSTs, however this seemed very similar to the ZST restrictions below. The list style itself is not exactly exhaustive in either case. I have not yet seen any such use in ffi in the wild whereas I did find use for all other cases that I've listed. |
||
field has a C-compatible type. | ||
|
||
The following types are not C-compatible: | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The part with the pointers (such as
*mut U
) forget to express theU
is aSized
... invariant thatOption<ptr::NonNull<U>>
do.I'd weaken the C-compatible bound on
U
, but explicit theSized
requirement: