-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
types.h: time_t as int64_t #14460
base: master
Are you sure you want to change the base?
types.h: time_t as int64_t #14460
Conversation
I think it was discussed some time ago, but I don't remember about the consensus: if it should be unsigned or signed. I think signed makes sense |
ALL other POSIX OS use signed integer, and we already find the compatibility issue, so it's better to follow their convention to improve the compatibility. |
does getActiveTime return something which is not time_t? |
otoh it breaks compatibility with nuttx itself. |
@GUIDINGLI |
Which kernel code does depend on the unsigned time_t? Anyway, we need ensure the code owned by NuttX working for time_t which could be signed/unsigned or 32/64bit. But many userspace library comes from *nix, they may never try or encounter the unsigned time_t before since all POSIX OS except NuttX define time_t to signed. if we make it unsigned, we should deprecate 32-bit time_t, IMO. Actually, we never ship the product which define time_t to 32bit. It's fragile and hard to handle 2038 issue with 32bit integer. |
i meant, our own 32-bit time_t is unsigned even if we merge this PR.
i meant we == nuttx. i agree it doesn't make much sense to ship a product with 32-bit time_t anymore. |
@GUIDINGLI @acassis @xiaoxiang781216 Update time_t to int32_t & int64_t either in TIME32 or TIME64 |
@acassis @xiaoxiang781216 @yamt @jkivilin |
I always prefer to align the implemented define behavior with other popular POSIX OS to improve the compatibility. |
#else | ||
typedef uint32_t clock_t; | ||
typedef uint32_t time_t; /* Holds time in seconds */ | ||
typedef int32_t time_t; /* Holds time in seconds */ |
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.
this makes 32-bit time_t almost unusable. if we make this change, we should make a bold statement to users.
i feel a few days is too short for this kind of change. please wait for at least a week. also, please make a bold announcement with the explanation of implications (especially negative ones) on the mailing list. |
i still think it's better for nuttx to keep time_t unsigned until we actually drop 32-bit time_t support. |
934fee0
to
5f6286c
Compare
The following code will generate warnings: auto now = time(nullptr); auto last_active_time = GetEventService(self->ctx_)->getActiveTime(); if (last_active_time + 60 * 1000 / 1000 <= now) { src/ams/../controller/controller_timer.h: In lambda function: src/ams/../controller/controller_timer.h:117:57: warning: comparison of integer expressions of different signedness: 'long long int' and 'long long unsigned int' [-Wsign-compare] 117 | if (last_active_time + 60 * 1000 / 1000 <= now) { reference: https://www.gnu.org/software/libc/manual/html_node/Time-Types.html On POSIX-conformant systems, time_t is an integer type. Signed-off-by: ligd <[email protected]>
Are you kidding? This is putting a HUGE number of unknown projects at risk. You dont know which unknown projects are using unsigned 32 bits timestamps out there. This will be a major and dangerous regression for them. This change requires these project to be EXTRA careful about how they handle time comparisons. AT LEAST, please, add an explicit #warning "32 bit time_t is now signed" that triggers when CONFIG_SYSTEM_TIME64 is not defined. Pretty please. |
@xiaoxiang781216 please wait before merging this PR. @yamt and @slorquet are against this change. I think compatibility with other OS is good, but the Y2038 BUG is a big concern here! |
Also, can someone be technically explicit about what this means?
|
@xiaoxiang781216 is there some way to show the warning at end of the compilation? Maybe #warning will be ignored because people doesn't see it during the build process |
year 2038 problem comes from the fact that the max value is decreased from 4294967295 (Sunday, February 7, 2106 6:28:15 AM) to 2147483647 (Tuesday, January 19, 2038 3:14:07 AM) Good remark Alan. One, or several, ways to reliably warn the user is enough for me to accept this change. I oppose doing this in a way that users will not notice. edit: warning could be amended with a suggestion to upgrade code to 64-bit timestamps. |
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.
- Please wait until discussion is resolved (here and on the mailing list).
- This is a big breaking change, should not be enforced, nor self-merged.
- "CI" as Impact and Testing description of the PR is unacceptable for this kind of change.
- Introduction of Y2038 problem seems the biggest impact of the 32-bit time after that change. Could you please grep and identify impacted projects in nuttx and nuttx-apps repo?
Please be mindful of your words.
As I said in the mail list:
Lots of bug are report on this, after the SUB they suppose result will be < 0, but compare failed caused by the time_t to unsigned.
Accept this, added |
@slorquet |
@xiaoxiang781216 Yep, I am aware of it, but as said on the mailing list I think the signed cast when comparing variables that can roll over is a must. In all cases if everyone agree that signedness of time_t should be a kconfig option that defaults to the legacy state, I'm completely ok with it. Making it an option gives stability to projects while allowing the use of the new feature. |
|
@GUIDINGLI please update as the discussion in email list. |
There is no final decision yet but it would help the decision with the proof-of-concept:
[1] https://pubs.opengroup.org/onlinepubs/9799919799/ |
It is not "the default", it is the exact with of time_t as specified by POSIX 2024. It is not a choice. It is not an option. It is the POSIX required size. |
I see, so we end up with simply |
Petty hard to escape that interpretation. I would have preferred a little more efficient use of memory. Like setting aside some bits for better time resolution now that we have more bits than needed. |
Summary
types.h: time_t as int64_t
The following code will generate errors:
auto now = time(nullptr);
auto last_active_time = GetEventService(self->ctx_)->getActiveTime(); if (last_active_time + 60 * 1000 / 1000 <= now) {
src/ams/../controller/controller_timer.h: In lambda function: src/ams/../controller/controller_timer.h:117:57: warning: comparison of integer expressions of different signedness: 'long long int' and 'long long unsigned int' [-Wsign-compare]
117 | if (last_active_time + 60 * 1000 / 1000 <= now) {
ref:
https://www.gnu.org/software/libc/manual/html_node/Time-Types.html
On POSIX-conformant systems, time_t is an integer type.
Advantage:
For the most POSIX applications they assume the time_t as signed and do compare with 0.
The code will become more compatible after this modification.
Disadvantage:
year 2038 problem
Someone think time_t will be overflow when set int32_t, should think his code should open TIME64 or handle the overflow himself.
Impact
32 bit time_t is now signed
This will cause Y2038 problem, if your system has this problem, you should open TIME64 or handle the overflow.
‘ put things right once and for all ’
Testing
CI