Skip to content
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

Use of ptr::NonNull in FFI #49220

Closed
kornelski opened this issue Mar 20, 2018 · 2 comments
Closed

Use of ptr::NonNull in FFI #49220

kornelski opened this issue Mar 20, 2018 · 2 comments
Labels
A-ffi Area: Foreign Function Interface (FFI) C-enhancement Category: An issue proposing an enhancement or a PR with one. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Comments

@kornelski
Copy link
Contributor

kornelski commented Mar 20, 2018

I think it would be interesting to use ptr::NonNull to explicitly document FFI arguments that aren't allowed to be NULL, so that e.g.:

extern "C" fn call_me_from_c(without_nulls: ptr::NonNull<c_char>)

could be an implementation for:

void call_me_from_c(char *without_nulls) __attribute__((nonnull));

However, ptr::NonNull doesn't have #[repr(transparent)], so I'm not sure if that is sound. Whether it's supposed to be used this way or not, it may be worth explicitly documenting it. Currently its docs don't say anything about FFI compatibility.

@pietroalbini pietroalbini added C-enhancement Category: An issue proposing an enhancement or a PR with one. A-ffi Area: Foreign Function Interface (FFI) T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. labels Mar 21, 2018
@mattico
Copy link
Contributor

mattico commented Mar 21, 2018

cc #27730

@RReverser
Copy link
Contributor

NonNull has repr(transparent) now, so I assume this can be closed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ffi Area: Foreign Function Interface (FFI) C-enhancement Category: An issue proposing an enhancement or a PR with one. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants