-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Make makedev, major, minor const
#4208
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
Conversation
|
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @tgross35 (or someone else) some time within the next two weeks. Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (
|
|
Some changes occurred in OpenBSD module cc @semarie |
|
After testing with the CI I found and fixed a bug in emscripten's |
libc-test/test/makedev.rs
Outdated
| assert_eq!(libc::major(dev), major as _); | ||
| let minor = unsafe { minor_ffi(dev) }; | ||
| assert_eq!(libc::minor(dev), minor as _); |
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.
Could you name the types here rather than using _?
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 wish I could, but the return type can be c_int, c_uint, major_t, minor_t depending on the platform.
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.
Sorry for the late review, but could you change both the LHS and RHS to be as i64? At least that gives a concrete size so we don't have any chance of wrapping (in case some obscure platform has a major_t smaller than int).
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 tried casting them to i64 and the test failed on FreeBSD. Ended up casting to proper target-specific types.
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.
Maybe it would be nice to keep the bitwise or terms of the rust code in the same order as they appear in musl for easier validation?
| } | ||
|
|
||
| safe_f! { | ||
| pub {const} fn makedev(major: c_uint, minor: c_uint) -> crate::dev_t { |
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.
Emscripten has actual functions for these in addition to macros so it would be possible to call out to them. But it would be a lot slower than this.
|
Otherwise it looks good to me. |
Thanks for pointing this out! I've changed the order. Kindly re-requesting the review 🙏 |
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 have one request but otherwise lgtm
libc-test/test/makedev.rs
Outdated
| assert_eq!(libc::major(dev), major as _); | ||
| let minor = unsafe { minor_ffi(dev) }; | ||
| assert_eq!(libc::minor(dev), minor as _); |
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.
Sorry for the late review, but could you change both the LHS and RHS to be as i64? At least that gives a concrete size so we don't have any chance of wrapping (in case some obscure platform has a major_t smaller than int).
|
Some changes occurred in the Android module cc @maurer |
|
Thanks for the updates, that's even better. Please squash and this should be ready to merge. |
3064c91 to
37c3333
Compare
Done. |
(backport <rust-lang#4208>) (cherry picked from commit 37c3333)
(backport <rust-lang#4208>) (cherry picked from commit 37c3333)
(backport <rust-lang#4208>) (cherry picked from commit 37c3333)
(backport <rust-lang#4208>) (cherry picked from commit 37c3333)
libc 0.2.171 makes all `major`, `minor`, `makedev` into `const fn` (rust-lang/libc#4208). So drop `unsafe`.
libc 0.2.171 makes all `major`, `minor`, `makedev` into `const fn` (rust-lang/libc#4208). So drop `unsafe`.
Description
This PR marks all
makedev,major,minorre-implementations (except Solarish) asconst fnand testsmajorandminoragainst their C counterparts (macros). This PR closely follows the work that was done in this commit.The motivation behind this PR is to make Rust code that uses these three functions consistent across different platforms. To give a concrete example: currently one has to wrap
majorandminorinunsafeblocks on MacOS, whereas on Linux these blocks are not needed. Unnecessaryunsafeblocks produce a warning that one silences with#[allow(unused_unsafe)]. All of that confuses code reviewers and creates unnecessary noise.makedev,majorandminorare macros on most Unixes, there is no need for them to be unsafe.As far as I understand these changes do not break existing code: changing unsafe functions to const only produce warnings but not compilation errors.
@rustbot label stable-nominated
Sources
None.
Checklist
libc-test/semverhave been updated*LASTor*MAXareincluded (see #3131)
cd libc-test && cargo test --target mytarget);especially relevant for platforms that may not be checked in CI