-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Make makedev
, major
, minor
const
#4208
base: main
Are you sure you want to change the base?
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 |
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.
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 🙏 |
Description
This PR marks all
makedev
,major
,minor
re-implementations (except Solarish) asconst fn
and testsmajor
andminor
against 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
major
andminor
inunsafe
blocks on MacOS, whereas on Linux these blocks are not needed. Unnecessaryunsafe
blocks produce a warning that one silences with#[allow(unused_unsafe)]
. All of that confuses code reviewers and creates unnecessary noise.makedev
,major
andminor
are 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/semver
have been updated*LAST
or*MAX
areincluded (see #3131)
cd libc-test && cargo test --target mytarget
);especially relevant for platforms that may not be checked in CI