-
Notifications
You must be signed in to change notification settings - Fork 348
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
Add localtime_r shim #3461
Add localtime_r shim #3461
Conversation
Thanks for the thorough review! I need a little bit more time to fully address them, and will mark this pr as ready after that. |
Sorry for submitting so many comments one go, I didn't notice that these comments are under pending, and only visible to me :( |
There are merge commits (commits with multiple parents) in your changes. We have a no merge policy so these commits will need to be removed for this pull request to be merged. You can start a rebase with the following commands:
The following commits are merge commits: |
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.
Thanks! We're entering the final polishing stage of this PR. :)
@rustbot author
src/shims/time.rs
Outdated
let tm_hour = dt.hour(); | ||
let tm_mday = dt.day(); | ||
let tm_mon = dt.month0(); | ||
let tm_year = dt.year().saturating_sub(1900); |
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.
Is it even possible for this to overflow? Why use saturating arithmetic?
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.
Since i32
maximum value is 2147483647
, should be impossible to overflow, at least not soon :). But I use this because the compiler will produce arithmetic side effect warning if I do
let tm_year = dt.year() - 1900;
So this is mainly to eliminate the warning.
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.
The intended way to eliminate the warning is checked_sub().unwrap()
This comment was marked as duplicate.
This comment was marked as duplicate.
There are merge commits (commits with multiple parents) in your changes. We have a no merge policy so these commits will need to be removed for this pull request to be merged. You can start a rebase with the following commands:
The following commits are merge commits (since this message was last posted): |
@rustbot ready |
tests/pass-dep/shims/libc-misc.rs
Outdated
let res_tm: libc::tm; | ||
unsafe { | ||
res_tm = *res; | ||
} | ||
// The returned value should match the pointer passed in. |
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.
Instead of comparing everything a second time, can't you just check that res
is equal to &mut tm
(as in, ptr::eq
)?
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.
Yeah, this makes sense.
There are merge commits (commits with multiple parents) in your changes. We have a no merge policy so these commits will need to be removed for this pull request to be merged. You can start a rebase with the following commands:
The following commits are merge commits (since this message was last posted): |
All right, looks good. Thanks! Please rebase and squash. |
c0a60f3
to
90b408c
Compare
@bors r+ |
☀️ Test successful - checks-actions |
1 similar comment
☀️ Test successful - checks-actions |
localtime_r
shim as mentioned in Shim wishlist #2057Note:
tm_zone
,tm_gmtoff
might not be consistent withlibc::localtime_r
as custom implementation is provided throughchrono
. Due to the lack of daylight saving information inchrono
,is_dst
value will always be-1
.