Skip to content
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

Merged
merged 1 commit into from
Apr 22, 2024
Merged

Add localtime_r shim #3461

merged 1 commit into from
Apr 22, 2024

Conversation

tiif
Copy link
Contributor

@tiif tiif commented Apr 11, 2024

Note:

  • tm_zone, tm_gmtoff might not be consistent with libc::localtime_r as custom implementation is provided through chrono. Due to the lack of daylight saving information in chrono, is_dst value will always be -1.

src/shims/time.rs Outdated Show resolved Hide resolved
src/shims/time.rs Outdated Show resolved Hide resolved
@tiif
Copy link
Contributor Author

tiif commented Apr 14, 2024

@RalfJung @oli-obk If memory leak in tm_zone string is a concern, would it be better if we just don't update the tm_zone field at all? The implementation provided is not accurate most of the time anyway since I didn't manage to use timezone abbreviation, I put something like +08 instead.

Cargo.toml Outdated Show resolved Hide resolved
src/shims/time.rs Outdated Show resolved Hide resolved
src/shims/time.rs Outdated Show resolved Hide resolved
src/shims/time.rs Outdated Show resolved Hide resolved
src/shims/time.rs Outdated Show resolved Hide resolved
src/shims/time.rs Outdated Show resolved Hide resolved
src/shims/time.rs Outdated Show resolved Hide resolved
src/shims/time.rs Outdated Show resolved Hide resolved
src/shims/time.rs Outdated Show resolved Hide resolved
src/shims/time.rs Outdated Show resolved Hide resolved
src/shims/time.rs Outdated Show resolved Hide resolved
@tiif
Copy link
Contributor Author

tiif commented Apr 15, 2024

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.

src/shims/time.rs Outdated Show resolved Hide resolved
src/shims/time.rs Outdated Show resolved Hide resolved
src/shims/time.rs Outdated Show resolved Hide resolved
src/shims/time.rs Outdated Show resolved Hide resolved
src/shims/time.rs Outdated Show resolved Hide resolved
src/shims/time.rs Outdated Show resolved Hide resolved
src/shims/time.rs Outdated Show resolved Hide resolved
src/shims/time.rs Outdated Show resolved Hide resolved
@tiif
Copy link
Contributor Author

tiif commented Apr 16, 2024

Sorry for submitting so many comments one go, I didn't notice that these comments are under pending, and only visible to me :(

@tiif tiif marked this pull request as ready for review April 16, 2024 07:14
@rustbot
Copy link
Collaborator

rustbot commented Apr 16, 2024

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:

$ # rebase
$ git rebase -i master
$ # delete any merge commits in the editor that appears
$ git push --force-with-lease

The following commits are merge commits:

Cargo.toml Outdated Show resolved Hide resolved
@tiif tiif requested a review from RalfJung April 16, 2024 14:10
Copy link
Member

@RalfJung RalfJung left a 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 Show resolved Hide resolved
src/shims/time.rs Show resolved Hide resolved
src/shims/time.rs Show resolved Hide resolved
src/shims/time.rs Outdated Show resolved Hide resolved
let tm_hour = dt.hour();
let tm_mday = dt.day();
let tm_mon = dt.month0();
let tm_year = dt.year().saturating_sub(1900);
Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Member

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()

tests/pass-dep/shims/libc-misc.rs Outdated Show resolved Hide resolved
tests/pass-dep/shims/libc-misc.rs Outdated Show resolved Hide resolved
tests/pass-dep/shims/libc-misc.rs Outdated Show resolved Hide resolved
tests/pass-dep/shims/libc-misc.rs Outdated Show resolved Hide resolved
tests/pass-dep/shims/libc-misc.rs Outdated Show resolved Hide resolved
@rustbot rustbot added S-waiting-on-author Status: Waiting for the PR author to address review comments labels Apr 18, 2024
@RalfJung

This comment was marked as duplicate.

@rustbot
Copy link
Collaborator

rustbot commented Apr 20, 2024

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:

$ # rebase
$ git rebase -i master
$ # delete any merge commits in the editor that appears
$ git push --force-with-lease

The following commits are merge commits (since this message was last posted):

src/shims/time.rs Show resolved Hide resolved
@tiif
Copy link
Contributor Author

tiif commented Apr 20, 2024

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Waiting for a review to complete and removed S-waiting-on-author Status: Waiting for the PR author to address review comments labels Apr 20, 2024
let res_tm: libc::tm;
unsafe {
res_tm = *res;
}
// The returned value should match the pointer passed in.
Copy link
Member

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)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, this makes sense.

src/shims/time.rs Outdated Show resolved Hide resolved
@rustbot
Copy link
Collaborator

rustbot commented Apr 22, 2024

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:

$ # rebase
$ git rebase -i master
$ # delete any merge commits in the editor that appears
$ git push --force-with-lease

The following commits are merge commits (since this message was last posted):

@RalfJung
Copy link
Member

All right, looks good. Thanks! Please rebase and squash.

@RalfJung
Copy link
Member

@bors r+

@bors
Copy link
Contributor

bors commented Apr 22, 2024

📌 Commit 90b408c has been approved by RalfJung

It is now in the queue for this repository.

@bors
Copy link
Contributor

bors commented Apr 22, 2024

⌛ Testing commit 90b408c with merge 8870881...

@tiif
Copy link
Contributor Author

tiif commented Apr 22, 2024

Thanks @RalfJung and @oli-obk for mentoring this PR! I really learned a lot from the detailed suggestion and discovered a lot of new Rust syntax that I never used before. I will be away preparing for final exams until 1 May, and I will start working on socketpair by then.

@bors
Copy link
Contributor

bors commented Apr 22, 2024

☀️ Test successful - checks-actions
Approved by: RalfJung
Pushing 8870881 to master...

1 similar comment
@bors
Copy link
Contributor

bors commented Apr 22, 2024

☀️ Test successful - checks-actions
Approved by: RalfJung
Pushing 8870881 to master...

@bors bors merged commit 8870881 into rust-lang:master Apr 22, 2024
8 checks passed
@tiif tiif deleted the add_localtime_r_shim branch November 5, 2024 14:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Waiting for a review to complete
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants