[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: bug#54764: encode-time: make DST and TIMEZONE fields of the list arg
From: |
Bernhard Voelker |
Subject: |
Re: bug#54764: encode-time: make DST and TIMEZONE fields of the list argument optional ones |
Date: |
Sat, 23 Apr 2022 16:35:41 +0200 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.7.0 |
On 4/20/22 20:19, Paul Eggert wrote:
> diff --git a/lib/gettime-res.c b/lib/gettime-res.c
> index 611f83ad27..bb4d0b191d 100644
> --- a/lib/gettime-res.c
> +++ b/lib/gettime-res.c
> @@ -53,6 +53,8 @@ gettime_res (void)
>
> long int hz = TIMESPEC_HZ;
> long int r = hz * res.tv_sec + res.tv_nsec;
> + struct timespec earlier;
> + earlier.tv_nsec = -1;
>
> /* On some platforms, clock_getres (CLOCK_REALTIME, ...) yields a
> too-large resolution, under the mistaken theory that it should
> @@ -61,9 +63,22 @@ gettime_res (void)
> resolution. Work around the problem with high probability by
> trying clock_gettime several times and observing the resulting
> bounds on resolution. */
> - for (int i = 0; 1 < r && i < 32; i++)
> + int nsamples = 32;
> + for (int i = 0; 1 < r && i < nsamples; i++)
> {
> - struct timespec now = current_timespec ();
> + /* If successive timestamps disagree the clock resolution must
> + be small, so exit the inner loop to check this sample.
> + Otherwise, arrange for the outer loop to exit but continue
> + the inner-loop search for a differing timestamp sample. */
> + struct timespec now;
> + for (;; i = nsamples)
> + {
> + now = current_timespec ();
> + if (earlier.tv_nsec != now.tv_nsec || earlier.tv_sec != now.tv_sec)
> + break;
> + }
> + earlier = now;
> +
> r = gcd (r, now.tv_nsec ? now.tv_nsec : hz);
> }
lib/gettime-res.c: In function 'gettime_res':
lib/gettime-res.c:77:46: error: 'earlier.tv_sec' may be used uninitialized in
this function \
[-Werror=maybe-uninitialized]
77 | if (earlier.tv_nsec != now.tv_nsec || earlier.tv_sec !=
now.tv_sec)
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
We know that earlier.tv_sec is set when tv_nsec is set, but the compiler does
not,
obviously. Considering the nested loops, I'd say initializing tv_sec doesn't
harm performance-wise.
Have a nice day,
Berny
- Re: bug#54764: encode-time: make DST and TIMEZONE fields of the list argument optional ones, (continued)
- Re: bug#54764: encode-time: make DST and TIMEZONE fields of the list argument optional ones, Paul Eggert, 2022/04/20
- Re: bug#54764: encode-time: make DST and TIMEZONE fields of the list argument optional ones, Eli Zaretskii, 2022/04/20
- Re: bug#54764: encode-time: make DST and TIMEZONE fields of the list argument optional ones, Paul Eggert, 2022/04/20
- Re: bug#54764: encode-time: make DST and TIMEZONE fields of the list argument optional ones, Eli Zaretskii, 2022/04/20
- Re: bug#54764: encode-time: make DST and TIMEZONE fields of the list argument optional ones, Paul Eggert, 2022/04/20
- Re: bug#54764: encode-time: make DST and TIMEZONE fields of the list argument optional ones, Eli Zaretskii, 2022/04/20
- Re: bug#54764: encode-time: make DST and TIMEZONE fields of the list argument optional ones, Paul Eggert, 2022/04/20
- Re: bug#54764: encode-time: make DST and TIMEZONE fields of the list argument optional ones, Eli Zaretskii, 2022/04/21
- Re: bug#54764: encode-time: make DST and TIMEZONE fields of the list argument optional ones, Paul Eggert, 2022/04/21
- Re: bug#54764: encode-time: make DST and TIMEZONE fields of the list argument optional ones, Eli Zaretskii, 2022/04/22
- Re: bug#54764: encode-time: make DST and TIMEZONE fields of the list argument optional ones,
Bernhard Voelker <=
- Re: bug#54764: encode-time: make DST and TIMEZONE fields of the list argument optional ones, Max Nikulin, 2022/04/20
- Re: bug#54764: encode-time: make DST and TIMEZONE fields of the list argument optional ones, Paul Eggert, 2022/04/20
- Re: bug#54764: encode-time: make DST and TIMEZONE fields of the list argument optional ones, Max Nikulin, 2022/04/25
- Re: bug#54764: encode-time: make DST and TIMEZONE fields of the list argument optional ones, Paul Eggert, 2022/04/25
- Re: bug#54764: encode-time: make DST and TIMEZONE fields of the list argument optional ones, Paul Eggert, 2022/04/25
- Re: bug#54764: encode-time: make DST and TIMEZONE fields of the list argument optional ones, Max Nikulin, 2022/04/30
- Re: bug#54764: encode-time: make DST and TIMEZONE fields of the list argument optional ones, Paul Eggert, 2022/04/30
Re: bug#54764: encode-time: make DST and TIMEZONE fields of the list argument optional ones, Max Nikulin, 2022/04/13
Re: bug#54764: encode-time: make DST and TIMEZONE fields of the list argument optional ones, Max Nikulin, 2022/04/16