Skip to content

Commit 87ec568

Browse files
committed
Auto merge of rust-lang#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 rust-lang#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)
2 parents 3802025 + 8d19819 commit 87ec568

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

library/std/src/os/raw/mod.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,14 @@ pub use core::ffi::c_void;
165165
#[unstable(feature = "c_size_t", issue = "88345")]
166166
pub type c_size_t = usize;
167167

168-
/// Equivalent to C's `ssize_t` type, from `stddef.h` (or `cstddef` for C++).
168+
/// Equivalent to C's `ptrdiff_t` type, from `stddef.h` (or `cstddef` for C++).
169+
///
170+
/// This type is currently always [`isize`], however in the future there may be
171+
/// platforms where this is not the case.
172+
#[unstable(feature = "c_size_t", issue = "88345")]
173+
pub type c_ptrdiff_t = isize;
174+
175+
/// Equivalent to C's `ssize_t` (on POSIX) or `SSIZE_T` (on Windows) type.
169176
///
170177
/// This type is currently always [`isize`], however in the future there may be
171178
/// platforms where this is not the case.

0 commit comments

Comments
 (0)