-
Notifications
You must be signed in to change notification settings - Fork 64
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
linux/timerfd: stop explicitly casting to c_long for timespec.tv_nsec #189
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -71,19 +71,15 @@ impl TimerFd { | |||||
{ | ||||||
spec.it_value.tv_sec = dur.as_secs() as libc::time_t; | ||||||
} | ||||||
// nsec always fits in i32 because subsec_nanos is defined to be less than one billion. | ||||||
let nsec = dur.subsec_nanos() as i32; | ||||||
spec.it_value.tv_nsec = libc::c_long::from(nsec); | ||||||
spec.it_value.tv_nsec = dur.subsec_nanos() as _; | ||||||
|
||||||
if let Some(int) = interval { | ||||||
// https://github.com/rust-lang/libc/issues/1848 | ||||||
#[cfg_attr(target_env = "musl", allow(deprecated))] | ||||||
{ | ||||||
spec.it_interval.tv_sec = int.as_secs() as libc::time_t; | ||||||
} | ||||||
// nsec always fits in i32 because subsec_nanos is defined to be less than one billion. | ||||||
let nsec = int.subsec_nanos() as i32; | ||||||
spec.it_interval.tv_nsec = libc::c_long::from(nsec); | ||||||
spec.it_interval.tv_nsec = int.subsec_nanos() as _; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Duplicate of 7f7d0f1#r1168297816
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Once again, this is 2nd day since I looked what rust is, to begin with, so I know nothing about the right constructs required here. I'm fine as long as it works. "My" version has been suggested by someone on IRC, - I didn't even know rust requires explicit type conversion between two different integer types. FWIW, this issue happens on x32 only. On all the other platforms, timespec.tv_nsec is of long datatype. It is documented as being long. But on x32 it is int64_t. Apparently this is a bug in the architecture specifications. Also, x32 is a very rare thing. Still, I like the code without explicit integer conversion more. It might also be a good idea to retain the comment which was previously there. |
||||||
} | ||||||
|
||||||
// SAFETY: Safe because this doesn't modify any memory and we check the return value. | ||||||
|
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.
Very much personal preference but I find
as _
to be quite unreadable.