-
Notifications
You must be signed in to change notification settings - Fork 59
Are raw pointers to sized types usable in C FFI ? #99
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
Comments
C doesn't guarantee that |
Pointers to sized types, references to sized types, I don't think we guarantee anything with respect to |
https://docs.rs/libc/0.2.50/libc/type.size_t.html says that libc defines
Because of this, the Rust compiler allows implicit conversion between Thus, things are over-constrained. I suggest that this all be qualified to "platforms where |
The only thing we guarantee about If we ever add a target where So I don't think we have to say anything about |
I bet there's a lot of (FFI-using) code that both assumes that Rust pointers and references are the same size as a C pointer and also assumes that Stepping back from that, I think the broader issue is this: Rust doesn't currently support any ABI where a C pointer isn't just an address, like a CHERI-based system. It is unclear what would need to change in Rust to support such an ABI, basically because we (IMO wrongly) overloaded |
It was widely assumed since before 1.0 when the types were renamed from |
There is a lot of code in the wild that assumes a lot of non-portable things to be true because that's a valid assumption for all platforms that that code cares about, and that's ok.
We explicitly guarantee that
I don't think this is the right issue to discuss adding / removing guarantees to |
AFAICT we don't mention this explicitly anywhere.
https://github.com/rust-lang/unsafe-code-guidelines/blob/master/reference/src/layout/pointers.md#representation mentions that they are one word in size, but maybe we should spell out that they are layout compatible with C pointers (including alignment) to make it clear that's ok to use raw pointers in C FFI.
The text was updated successfully, but these errors were encountered: