-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Add explicit cast to nsec in android platforms #82139
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 explicit cast to nsec in android platforms #82139
Conversation
CC @phausler |
struct timespec ts = { | ||
.tv_sec = sec, | ||
.tv_sec = static_cast<time_t>(sec), |
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.
Hmm, doesn't this silently truncate? I do like the idea of merging the paths.
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.
time_t should be 64 bits on modern macos. This is why teh compiler was not complaining on the implicit cast. but yes it will truncate on Android, which i am assuming is ok for this use case.
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.
Wouldn't that move the time backwards then?
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.
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.
time_t
is 64 bits on every 64-bit platform I know of (thankfully) and that includes Darwin. It could silently truncate on a 32-bit system, but I don't think those can in practical terms handle such high time_t
values anyway.
Basically, yes it could truncate but by the time (2038) that becomes an issue, the platforms in question are hosed anyway.
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.
Note that the C standard defines timespec::tv_sec
as a value of type time_t
anyway, so good luck not truncating it. https://en.cppreference.com/w/c/chrono/timespec
f5d8c14
to
ed59cb4
Compare
ed59cb4
to
43b49dd
Compare
@swift-ci please smoke test |
I am seeing a build error for Android for invalid narrowing after #79139, #82154 did add a special case for non-windows, non-apple platform. but did not account for nsec implicit casting from
long long
tolong
. still seeing build errors on android.