mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-23 23:34:48 +00:00
Auto merge of #90421 - thomcc:friendship-ended-with-ssize_t-now-ptrdiff_t-is-my-best-friend, r=joshtriplett
Replace `std::os::raw::c_ssize_t` with `std::os::raw::c_ptrdiff_t` The discussions in #88345 brought up that `ssize_t` is not actually the signed index type defined in stddef.h, but instead it's `ptrdiff_t`. It seems pretty clear that the use of `ssize_t` here was a mistake on my part, and that if we're going to bother having a isize-alike for FFI in `std::os::raw`, it should be `ptrdiff_t` and not `ssize_t`. Anyway, both this and `c_size_t` are dubious in the face of the discussion in https://internals.rust-lang.org/t/pre-rfc-usize-is-not-size-t/15369, and any RFC/project-group/etc that handles those issues there should contend with these types in some manner, but that doesn't mean we shouldn't fix something wrong like this, even if it is unstable. All that said, `size_t` is *vastly* more common in function signatures than either `ssize_t` or `ptrdiff_t`, so I'm going to update the tracking issue's list of unresolved questions to note that perhaps we only want `c_size_t` — I mostly added the signed version for symmetry, rather than to meet a need. (Given this, I'm also fine with modifying this patch to instead remove `c_ssize_t` without a replacement) CC `@magicant` (who brought the issue up) CC `@chorman0773` (who has a significantly firmer grasp on the minutae of the C standard than I do) r? `@joshtriplett` (original reviewer, active in the discussions around this)
This commit is contained in:
commit
87ec5680c9
@ -165,7 +165,14 @@ pub use core::ffi::c_void;
|
||||
#[unstable(feature = "c_size_t", issue = "88345")]
|
||||
pub type c_size_t = usize;
|
||||
|
||||
/// Equivalent to C's `ssize_t` type, from `stddef.h` (or `cstddef` for C++).
|
||||
/// Equivalent to C's `ptrdiff_t` type, from `stddef.h` (or `cstddef` for C++).
|
||||
///
|
||||
/// This type is currently always [`isize`], however in the future there may be
|
||||
/// platforms where this is not the case.
|
||||
#[unstable(feature = "c_size_t", issue = "88345")]
|
||||
pub type c_ptrdiff_t = isize;
|
||||
|
||||
/// Equivalent to C's `ssize_t` (on POSIX) or `SSIZE_T` (on Windows) type.
|
||||
///
|
||||
/// This type is currently always [`isize`], however in the future there may be
|
||||
/// platforms where this is not the case.
|
||||
|
Loading…
Reference in New Issue
Block a user