Page MenuHomeFreeBSD

sys/time: rework saturation ifdef to avoid direct arch ref
Needs RevisionPublic

Authored by rlibby on Wed, Apr 15, 9:24 AM.
Tags
None
Referenced Files
F153426975: D56401.diff
Tue, Apr 21, 2:50 AM
F153383593: D56401.id175544.diff
Mon, Apr 20, 8:25 PM
Unknown Object (File)
Mon, Apr 20, 7:30 AM
Unknown Object (File)
Sun, Apr 19, 6:03 PM
Unknown Object (File)
Sun, Apr 19, 10:17 AM
Unknown Object (File)
Sat, Apr 18, 6:43 PM
Unknown Object (File)
Sat, Apr 18, 5:13 AM
Unknown Object (File)
Sat, Apr 18, 4:37 AM

Details

Summary

Suggested by: kib
Fixes: 00dccc3164c6 ("sys/time: appease gcc -Wtype-limits")

Test Plan

make tinderbox

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped
Build Status
Buildable 72213
Build 69096: arc lint + arc unit

Event Timeline

rlibby added reviewers: kib, jfree, imp.

Did you considered using SIZEOF_LONG and SIZEOF_INT instead of 8/4?

In D56401#1291100, @kib wrote:

Did you considered using SIZEOF_LONG and SIZEOF_INT instead of 8/4?

I hadn't, but looking at it now...

It seems directly defining __SIZEOF_TIME_T in terms of __SIZEOF_LONG__ and __SIZEOF_INT__ would require also knowing how int64_t is actually defined for a given arch. For example if some arch (maybe arm?) uses int64_t for time_t but where __SIZEOF_LONG__ might be 4, we would then need to test for that and then in that case actually make it __SIZEOF_LONG_LONG__, right?

We could add __SIZEOF_INT64_T etc to sys/sys/_types.h and define them in terms of __SIZEOF_LONG__ etc, and then #define __SIZEOF_TIME_T __SIZEOF_INT64. Maybe that would make sense if there were some other use or consumer?

In D56401#1291100, @kib wrote:

Did you considered using SIZEOF_LONG and SIZEOF_INT instead of 8/4?

I hadn't, but looking at it now...

It seems directly defining __SIZEOF_TIME_T in terms of __SIZEOF_LONG__ and __SIZEOF_INT__ would require also knowing how int64_t is actually defined for a given arch. For example if some arch (maybe arm?) uses int64_t for time_t but where __SIZEOF_LONG__ might be 4, we would then need to test for that and then in that case actually make it __SIZEOF_LONG_LONG__, right?

We could add __SIZEOF_INT64_T etc to sys/sys/_types.h and define them in terms of __SIZEOF_LONG__ etc, and then #define __SIZEOF_TIME_T __SIZEOF_INT64. Maybe that would make sense if there were some other use or consumer?

I mean add __SIZEOF_TIME_T in the same location in machine/_type.h where time_t is defined. Of course it must use the same __SIZEOF_<uppercase type name> as the type used for time_t.
But I do not insist.

In D56401#1291397, @kib wrote:

Of course it must use the same __SIZEOF_<uppercase type name> as the type used for time_t.

But which type is that? The basic type for int64_t is defined in sys/sys/_types.h according to __SIZEOF_LONG__, not directly in machine/_types.h. Maybe the problem I'm imagining doesn't exist, but my worry is that on some arch we might have to

#if __SIZEOF_LONG__ == 8
#define __SIZEOF_TIME_T __SIZEOF_LONG__
#else
#define __SIZEOF_TIME_T __SIZEOF_LONG_LONG__
#endif

as sys/sys/_types.h does, and if we're going to do that, should we just define __SIZEOF_INT64_T in sys/sys/types.h?

Do you see this as potentially being useful for more CPP definitions?

In D56401#1291397, @kib wrote:

Of course it must use the same __SIZEOF_<uppercase type name> as the type used for time_t.

But which type is that? The basic type for int64_t is defined in sys/sys/_types.h according to __SIZEOF_LONG__, not directly in machine/_types.h. Maybe the problem I'm imagining doesn't exist, but my worry is that on some arch we might have to

#if __SIZEOF_LONG__ == 8
#define __SIZEOF_TIME_T __SIZEOF_LONG__
#else
#define __SIZEOF_TIME_T __SIZEOF_LONG_LONG__
#endif

as sys/sys/_types.h does, and if we're going to do that, should we just define __SIZEOF_INT64_T in sys/sys/types.h?

It is per arch. E.g. it is SIZEOF_LONG on amd64, but SIZEOF_LONG_LONG on arm, and SIZEOF_INT on i386.

Do you see this as potentially being useful for more CPP definitions?

In fact I might want SIZEOF_TIME32_T as well, for compat32.

So what's wrong with the #ifdef i386 that we're going to tear down in the near future?
This seems to be way over-engineering a solution to a bogus gcc warning.
I'd really rather have #ifdef _KERNEL around the two sat functions instead of this over-engineering.

imp requested changes to this revision.Wed, Apr 15, 5:15 PM
imp added inline comments.
sys/sys/time.h
359

Or maybe just _ts.tv_sec >= INT_MAX and <= INT_MIN here, and accept the issue markj pointed out that you could have up to a second of truncation when _ts.tv_sec == INT_MAX/INT_MIN.

This revision now requires changes to proceed.Wed, Apr 15, 5:15 PM

I don't feel strongly about it, beyond wanting the gcc build to work. If @kib and @imp you guys don't agree on the direction here, my inclination is just to leave it as it is after 00dccc3164c6dff38350a1baeeea7238acf2efc3 and move on.

I would much prefer the SIZEOF approach. It is much cleaner IMO, and it makes some more things possible with compat32, after addition of SIZEOF_TIME32_T.
I will not block any kind of commit, of course.