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

Discuss the WrapperStruct(UnsafeCell<some_c_struct>)FFI pattern #385

Open
tgross35 opened this issue Nov 11, 2022 · 0 comments
Open

Discuss the WrapperStruct(UnsafeCell<some_c_struct>)FFI pattern #385

tgross35 opened this issue Nov 11, 2022 · 0 comments

Comments

@tgross35
Copy link
Contributor

Hey everyone,

I’d like to suggest adding the interior mutability FFI wrapper pattern to the FFI section, which usually looks something like this

#[repr(transparent)]
WrapperStruct(UnsafeCell<some_c_struct>)

This is used in e.g. the Linux kernel safe wrapper

I didn’t really understand it at first, but somebody explained it extremely well on Discord. Some of the explanation could likely be copied and pasted https://discord.com/channels/273534239310479360/818964227783262209/1040580112330002443

In general, I think the FFI section could use some updating, to be less of “this is how you call C functions” to more of “this is how you wrap a C API and make it safe”, since that’s what a lot of people are doing now as Rust works in to existing C projects. But that’s a big change, suitable for a separate issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant