Skip to content

time: Typedef time_t to uint64_t if CONFIG_SYSTEM_TIME64 is defined - #4693

Closed
anjiahao1 wants to merge 0 commit into
apache:masterfrom
anjiahao1:time
Closed

anjiahao1 wants to merge 0 commit into
apache:masterfrom
anjiahao1:time

Conversation

@anjiahao1

@anjiahao1 anjiahao1 commented Oct 19, 2021 •

Copy link
Copy Markdown
Contributor

Summary

time_t:add unsigned integer define time_t

Impact

Testing

dailytest

@yamt

yamt commented Oct 19, 2021

Copy link
Copy Markdown
Contributor

follow posix,use int64_t inside of time_t

which part of posix?

@anjiahao1

Copy link
Copy Markdown
Contributor Author

follow posix,use int64_t inside of time_t

which part of posix?

clock_settime(clockid_t clock_id, FAR const struct timespec *tp)

if use a tp->tv_sec = -1
before will return ok,now return EINVAL

@yamt

yamt commented Oct 19, 2021

Copy link
Copy Markdown
Contributor

follow posix,use int64_t inside of time_t

which part of posix?

clock_settime(clockid_t clock_id, FAR const struct timespec *tp)

if use a tp->tv_sec = -1 before will return ok,now return EINVAL

can you give me pointers to the relevant parts of the posix?

@anjiahao1

Copy link
Copy Markdown
Contributor Author

follow posix,use int64_t inside of time_t

which part of posix?

clock_settime(clockid_t clock_id, FAR const struct timespec *tp)
if use a tp->tv_sec = -1 before will return ok,now return EINVAL

can you give me pointers to the relevant parts of the posix?

https://man7.org/linux/man-pages/man3/clock_settime.3.html

@yamt

yamt commented Oct 19, 2021

Copy link
Copy Markdown
Contributor

follow posix,use int64_t inside of time_t

which part of posix?

clock_settime(clockid_t clock_id, FAR const struct timespec *tp)
if use a tp->tv_sec = -1 before will return ok,now return EINVAL

can you give me pointers to the relevant parts of the posix?

https://man7.org/linux/man-pages/man3/clock_settime.3.html

isn't it linux-specific documentation?

do you mean you interpreted the following part to mean tv_sec should be signed?

        EINVAL (clock_settime()): tp.tv_sec is negative or tp.tv_nsec is
              outside the range [0..999,999,999].

@anjiahao1

anjiahao1 commented Oct 19, 2021 •

Copy link
Copy Markdown
Contributor Author

follow posix,use int64_t inside of time_t

which part of posix?

clock_settime(clockid_t clock_id, FAR const struct timespec *tp)
if use a tp->tv_sec = -1 before will return ok,now return EINVAL

can you give me pointers to the relevant parts of the posix?

https://man7.org/linux/man-pages/man3/clock_settime.3.html

isn't it linux-specific documentation?

do you mean you interpreted the following part to mean tv_sec should be signed?

        EINVAL (clock_settime()): tp.tv_sec is negative or tp.tv_nsec is
              outside the range [0..999,999,999].

yse,i use man p clock_settime see
EINVAL (clock_settime()): tp.tv_sec is negative or tp.tv_nsec is outside the range [0..999,999,999].

@yamt yamt left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

as far as i know, unsigned time_t is allowed by posix.
this change requires more explanation than "follow posix".

@xiaoxiang781216

Copy link
Copy Markdown
Contributor

as far as i know, unsigned time_t is allowed by posix. this change requires more explanation than "follow posix".

ISO-C allow signed or unsigned time_t, but POSIX require the signed integer:
https://pubs.opengroup.org/onlinepubs/009695399/basedefs/sys/types.h.html
From this thread:
https://stackoverflow.com/questions/471248/what-is-time-t-ultimately-a-typedef-to
Most Unix variant OS use signed integer represent time_t, so it's better to follow the common practice to improve the compability.

@patacongo

Copy link
Copy Markdown
Contributor

This will break several architectures that do not support 64-bit long long types. This includes all of the ZiLOG architectures. This logic all needs to conditioned on CONFIG_HAVE_LONG_LONG.

Comment thread include/sys/types.h Resolved
@yamt

yamt commented Oct 19, 2021 •

Copy link
Copy Markdown
Contributor

as far as i know, unsigned time_t is allowed by posix. this change requires more explanation than "follow posix".

ISO-C allow signed or unsigned time_t, but POSIX require the signed integer: https://pubs.opengroup.org/onlinepubs/009695399/basedefs/sys/types.h.html

the page says:

time_t and clock_t shall be integer or real-floating types.

iirc the more recent versions of posix require it to be an integer.
but i'm not aware of a version which requires signed.

From this thread: https://stackoverflow.com/questions/471248/what-is-time-t-ultimately-a-typedef-to Most Unix variant OS use signed integer represent time_t, so it's better to follow the common practice to improve the compability.

i tend to agree, while i have a vague concern about using 64-bit types for small devices.

@xiaoxiang781216

Copy link
Copy Markdown
Contributor

This will break several architectures that do not support 64-bit long long types. This includes all of the ZiLOG architectures. This logic all needs to conditioned on CONFIG_HAVE_LONG_LONG.

int64_t tyoedef is guarded by CONFIG_SYSTEM_TIME64, so it is not real issue.

@xiaoxiang781216

Copy link
Copy Markdown
Contributor

as far as i know, unsigned time_t is allowed by posix. this change requires more explanation than "follow posix".

ISO-C allow signed or unsigned time_t, but POSIX require the signed integer: https://pubs.opengroup.org/onlinepubs/009695399/basedefs/sys/types.h.html

the page says:

time_t and clock_t shall be integer or real-floating types.

iirc the more recent versions of posix require it to be an integer. but i'm not aware of a version which requires signed.

Here the integer ahould mean signed, since other place use unsigned integer in the same page.

From this thread: https://stackoverflow.com/questions/471248/what-is-time-t-ultimately-a-typedef-to Most Unix variant OS use signed integer represent time_t, so it's better to follow the common practice to improve the compability.

i tend to agree, while i have a vague concern about using 64-bit types for small devices.

time_t is still int32_t if CONFIG_SYSTEM_TIME64 isnot defined.

@yamt

yamt commented Oct 19, 2021

Copy link
Copy Markdown
Contributor

as far as i know, unsigned time_t is allowed by posix. this change requires more explanation than "follow posix".

ISO-C allow signed or unsigned time_t, but POSIX require the signed integer: https://pubs.opengroup.org/onlinepubs/009695399/basedefs/sys/types.h.html

the page says:

time_t and clock_t shall be integer or real-floating types.

iirc the more recent versions of posix require it to be an integer. but i'm not aware of a version which requires signed.

Here the integer ahould mean signed, since other place use unsigned integer in the same page.

no. the page actually uses three kinds.

  • integer
  • signed integer
  • unsigned integer

From this thread: https://stackoverflow.com/questions/471248/what-is-time-t-ultimately-a-typedef-to Most Unix variant OS use signed integer represent time_t, so it's better to follow the common practice to improve the compability.

i tend to agree, while i have a vague concern about using 64-bit types for small devices.

time_t is still int32_t if CONFIG_SYSTEM_TIME64 isnot defined.

if we need 32 bit version, it should be unsigned, as int32_t will wrap too soon.
i guess 64 bit version should be unsigned too because it should be consistent within nuttx.

@xiaoxiang781216

Copy link
Copy Markdown
Contributor

as far as i know, unsigned time_t is allowed by posix. this change requires more explanation than "follow posix".

ISO-C allow signed or unsigned time_t, but POSIX require the signed integer: https://pubs.opengroup.org/onlinepubs/009695399/basedefs/sys/types.h.html

the page says:

time_t and clock_t shall be integer or real-floating types.

iirc the more recent versions of posix require it to be an integer. but i'm not aware of a version which requires signed.

Here the integer ahould mean signed, since other place use unsigned integer in the same page.

no. the page actually uses three kinds.

  • integer
  • signed integer
  • unsigned integer

You are right.

From this thread: https://stackoverflow.com/questions/471248/what-is-time-t-ultimately-a-typedef-to Most Unix variant OS use signed integer represent time_t, so it's better to follow the common practice to improve the compability.

i tend to agree, while i have a vague concern about using 64-bit types for small devices.

time_t is still int32_t if CONFIG_SYSTEM_TIME64 isnot defined.

if we need 32 bit version, it should be unsigned, as int32_t will wrap too soon. i guess 64 bit version should be unsigned too because it should be consistent within nuttx.

Yes, int32_t will wrap at 2038(https://en.wikipedia.org/wiki/Year_2038_problem).

@juniskane

Copy link
Copy Markdown
Contributor

iirc the more recent versions of posix require it to be an integer. but i'm not aware of a version which requires signed.

Here the integer ahould mean signed, since other place use unsigned integer in the same page.

Most recent version here:
https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/sys_types.h.html
says "time_t shall be an integer type". (This is marked as C extension, because ISO C also allows floating point time_t)

I fail to see how rest of page using unsigned integer could be relevant, as the technical term "integer type" has a precisely defined meaning in ISO 9899:1999 (C99 standard, incorporated to Open Group spec by reference) section 6.2.5, clause 17: "The type char, the signed and unsigned integer types, and the enumerated types are collectively called integer types. The integer and real floating types are collectively called real types."

I haven't looked inside this commit, but the claim that this is needed to "follow POSIX" in commit message's summary line is incorrect.

@patacongo

Copy link
Copy Markdown
Contributor

int64_t tyoedef is guarded by CONFIG_SYSTEM_TIME64, so it is not real issue.

It is an issue because CONFIG_SYSTEM_TIME64 value is not effected by CONFIG_HAVE_LONG_LONG; the first is defined by the configuration, the second by compiler.h. nuttx/clock.h "fixes" any inconsistency. However, nuttx/clock.h that is not included by sys/types.h.

@anjiahao1 anjiahao1 changed the title time:follow POSIX use int64_t to define time_t time_t:add unsigned integer define time_t Oct 19, 2021
@xiaoxiang781216
xiaoxiang781216 force-pushed the time branch 2 times, most recently from ca59692 to 86b7305 Compare October 19, 2021 12:42
@xiaoxiang781216

Copy link
Copy Markdown
Contributor

int64_t tyoedef is guarded by CONFIG_SYSTEM_TIME64, so it is not real issue.

It is an issue because CONFIG_SYSTEM_TIME64 value is not effected by CONFIG_HAVE_LONG_LONG; the first is defined by the configuration, the second by compiler.h. nuttx/clock.h "fixes" any inconsistency. However, nuttx/clock.h that is not included by sys/types.h.

Move the CONFIG_HAVE_LONG_LONG check to sys/types.h

@xiaoxiang781216

Copy link
Copy Markdown
Contributor

if we need 32 bit version, it should be unsigned, as int32_t will wrap too soon. i guess 64 bit version should be unsigned too because it should be consistent within nuttx.

Ok, change to uint32_t/uint64_t

@xiaoxiang781216 xiaoxiang781216 changed the title time_t:add unsigned integer define time_t time: Typedef time_t to uint64_t if CONFIG_SYSTEM_TIME64 is defined Oct 19, 2021
Comment thread include/time.h Resolved
@patacongo

Copy link
Copy Markdown
Contributor

if we need 32 bit version, it should be unsigned, as int32_t will wrap too soon. i guess 64 bit version should be unsigned too because it should be consistent within nuttx.

Yes, int32_t will wrap at 2038(https://en.wikipedia.org/wiki/Year_2038_problem).

Negative time is never used in NuttX. Negative time could arise in applications as a consequence of arithmetic operations, but that would be a non-portable behavior of the application because POSIX permits unsigned time_t. For portability, applications should always cast to an appropriate time before performing signed operations.

With unsigned time_t, the range is doubled. Instead of 2038 (1970 + 68) then it should overflow at (1970 + 2*68) = 2,206. Prior to that date, the upper 32-bits of a 64-bit time_t will always be zero. So a 64-bit is totally wasteful until then. The effect is no just limited to time_t parameters, but to the size of all structures that include a time_t field.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants