-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Provide C FFI types via core::ffi, not just in std #94503
Conversation
r? @kennytm (rust-highfive has picked a reviewer for you, use r? to override) |
r? @Amanieu |
This comment has been minimized.
This comment has been minimized.
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.
I would like to see some additional C types here, specifically all the ones that are defined in stddef.h
and stdint.h
. These two headers are part of the freestanding subset of C which has no OS dependencies.
Specifically I would like to see the C99 fixed-width integer types and:
wchar_t
char8_t
,char16_t
,char32_t
max_align_t
The idea is that anyone interface with C code should be able to blindly use the equivalent c_*
type without having to think too much about what the exact equivalent Rust type is.
@Amanieu I'd absolutely love to add more C FFI types, but I really don't want this PR to do anything more than move the types we already have. Similarly, the I'm trying to make zero semantic changes here apart from the move, to make this easy to review and approve. |
0974b39
to
06db9fa
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
core can't depend on external crates the way std can. Rather than revert usage of cfg_if, add a copy of it to core. This does not export our copy, even unstably; such a change could occur in a later commit.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
r=me once CI passes |
459f3f3
to
34ada45
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
The ability to interoperate with C code via FFI is not limited to crates using std; this allows using these types without std. The existing types in `std::os::raw` become type aliases for the ones in `core::ffi`. This uses type aliases rather than re-exports, to allow the std types to remain stable while the core types are unstable. This also moves the currently unstable `NonZero_` variants and `c_size_t`/`c_ssize_t`/`c_ptrdiff_t` types to `core::ffi`, while leaving them unstable.
This comment has been minimized.
This comment has been minimized.
When CStr moves to core with an alias in std, this can link to `crate::ffi::CStr`. However, linking in the reverse direction (from core to std) requires a relative path, and that path can't work from both core::ffi and std::os::raw (different number of `../` traversals required).
📌 Commit 75c3e9c has been approved by |
…askrgr Rollup of 9 pull requests Successful merges: - rust-lang#94464 (Suggest adding a new lifetime parameter when two elided lifetimes should match up for traits and impls.) - rust-lang#94476 (7 - Make more use of `let_chains`) - rust-lang#94478 (Fix panic when handling intra doc links generated from macro) - rust-lang#94482 (compiler: fix some typos) - rust-lang#94490 (Update books) - rust-lang#94496 (tests: accept llvm intrinsic in align-checking test) - rust-lang#94498 (9 - Make more use of `let_chains`) - rust-lang#94503 (Provide C FFI types via core::ffi, not just in std) - rust-lang#94513 (update Miri) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
Tracking issue: #94501
The ability to interoperate with C code via FFI is not limited to crates
using std; this allows using these types without std.
The existing types in
std::os::raw
become type aliases for the ones incore::ffi
. This uses type aliases rather than re-exports, to allow thestd types to remain stable while the core types are unstable.
This also moves the currently unstable
NonZero_
variants andc_size_t
/c_ssize_t
/c_ptrdiff_t
types tocore::ffi
, while leavingthem unstable.
Historically, we didn't do this because these types are target-dependent.
However,
core
itself is also target-dependent.core
should not callany OS services, but it knows the target and the target's ABI.