Map size_t to usize by default and check compatibility [Rebased]#2278
Merged
pvdrz merged 1 commit intorust-lang:masterfrom Sep 24, 2022
Merged
Map size_t to usize by default and check compatibility [Rebased]#2278pvdrz merged 1 commit intorust-lang:masterfrom
pvdrz merged 1 commit intorust-lang:masterfrom
Conversation
emilio
approved these changes
Sep 24, 2022
Contributor
emilio
left a comment
There was a problem hiding this comment.
Looks good to me with that. Thanks!
| layout.align == ctx.target_pointer_size(), | ||
| "Target platform requires --no-size_t-is-usize" | ||
| ); | ||
| } |
Contributor
There was a problem hiding this comment.
Can we add the relevant values to the assertion error? Something like:
"Target platform requires --no-size_t-is-usize. {} size ({}) or align ({}) doesn't match target pointer size ({})", spelling, layout.size, layout.align, ctx.target_pointer_size()`
Contributor
|
@pvdrz you should have the ability to merge this when ready, lmk if that doesn't work for some reason. Please squash the rustfmt commit? |
Contributor
Author
|
@emilio I'll do the change you asked and squash everything then. |
…ng#1901, rust-lang#1903) This addresses the underlying issue identified in rust-lang#1671, that size_t (integer that can hold any object size) isn't guaranteed to match usize, which is defined more like uintptr_t (integer that can hold any pointer). However, on almost all platforms, this is true, and in fact Rust already uses usize extensively in contexts where size_t would be more appropriate, such as slice indexing. So, it's better for ergonomics when interfacing with C code to map the C size_t type to usize. (See also discussion in rust-lang/rust#65473 about how usize really should be defined as size_t, not uintptr_t.) The previous fix for rust-lang#1671 removed the special case for size_t and defaulted to binding it as a normal typedef. This change effectively reverts that and goes back to mapping size_t to usize (and ssize_t to isize), but also ensures that if size_t is emitted, the typedef'd type of size_t in fact is compatible with usize (defined by checking that the size and alignment match the target pointer width). For (hypothetical) platforms where this is not true, or for compatibility with the default behavior of bindgen between 0.53 and this commit, onwards, you can disable this mapping with --no-size_t-is-usize.
Closed
dspicher
added a commit
to dspicher/xlsxwriter-rs
that referenced
this pull request
Nov 30, 2022
`size_t` has been aligned with `usize` [1], rendering the cast unnecessary. [1] rust-lang/rust-bindgen#2278
Aeradriel
pushed a commit
to Aeradriel/xlsxwriter-rs
that referenced
this pull request
May 26, 2023
`size_t` has been aligned with `usize` [1], rendering the cast unnecessary. [1] rust-lang/rust-bindgen#2278
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Rebased version of #2062