Skip to content

Use of ptr::NonNull in FFI #49220

Closed
Closed
@kornelski

Description

@kornelski

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-FFIArea: Foreign function interface (FFI)C-enhancementCategory: An issue proposing an enhancement or a PR with one.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions