-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Replace std::os::raw::c_ssize_t
with std::os::raw::c_ptrdiff_t
#90421
Replace std::os::raw::c_ssize_t
with std::os::raw::c_ptrdiff_t
#90421
Conversation
Actually, the numbers in #88345 (comment) has me leaning towards "only expose size_t because it significantly more important and other use cases can reach for something like Another argument in favor of this: bindgen had need for a |
I don't think it makes sense to change this and not I'd suggest that we just leave these unstable until we settle the question of whether we support |
(Also, props for the branch name.) |
I think you misunderstood this PR (sorry if I'm mistaken) — it's not intended to be a semantic change, beyond exposing a type that's more portable. In particular, The C standard even includes "The result of subtracting two pointers is not representable in an object of type ptrdiff_t" in the list behaviors left explicitly undefined, which seems to explicitly be a carve-out to allow targets While I can't find a stddef.h for a CHERI system, this document https://www.cl.cam.ac.uk/techreports/UCAM-CL-TR-947.pdf indicates that on CHERI
It also notes:
which calls out not confusing it with @chorman0773 indicated to me that this is also true for the proposed W65 ABI. That is to say, I don't know that this would come with any equivalent change to ... That said, the more I think about it, the more I'm inclined to think that |
Thank you for clarifying; I did indeed mix up ptrdiff_t with intptr_t. (I also wonder if it would ever not be the same as ssize_t.) That said, it's still not at all clear to me why isize should be exposed as c_ptrdiff_t and not as c_ssize_t. It sounds like on unix platforms it's called ssize_t, and on Windows it's called SSIZE_T, with the only difference being capitalization. I think it's reasonable to expose both types as c_ssize_t. I think we should also expose c_ptrdiff_t, though. I would be happy to r+ a PR adding that type (under the same feature). That way, whatever integer type people encounter in a C API, they can use the corresponding FFI type rather than a less-self-documenting type they think may be equivalent. |
I've updated the PR with this. |
@bors r+ |
📌 Commit 8d19819 has been approved by |
☀️ Test successful - checks-actions |
Finished benchmarking commit (87ec568): comparison url. Summary: This benchmark run did not return any relevant changes. If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf. @rustbot label: -perf-regression |
The discussions in #88345 brought up that
ssize_t
is not actually the signed index type defined in stddef.h, but instead it'sptrdiff_t
. It seems pretty clear that the use ofssize_t
here was a mistake on my part, and that if we're going to bother having a isize-alike for FFI instd::os::raw
, it should beptrdiff_t
and notssize_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 eitherssize_t
orptrdiff_t
, so I'm going to update the tracking issue's list of unresolved questions to note that perhaps we only wantc_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 removec_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)