diff options
author | Paul Eggert <eggert@cs.ucla.edu> | 2017-11-02 13:18:16 -0700 |
---|---|---|
committer | Paul Eggert <eggert@cs.ucla.edu> | 2017-11-02 13:21:33 -0700 |
commit | 04bc1410c26884bfed9fd7ba7376491023df03fc (patch) | |
tree | b3db4ad7a884f5796c0bd0e147bd46aee8577a1f /lib/timespec.h | |
parent | 6b08ad5263bc063c79666ffe2bd5ed9ab77a00a0 (diff) | |
download | emacs-04bc1410c26884bfed9fd7ba7376491023df03fc.tar.gz |
Merge from Gnulib
This incorporates:
2017-10-29 timespec: prefer ‘assume’ to ‘assure’
2017-10-27 timespec.h: use "assure" to avoid a spurious warning
2017-10-09 getopt-posix: Fix build failure if ac_cv_header_getopt_h=no
* build-aux/config.guess, build-aux/config.sub:
* lib/timespec.h, lib/unistd.in.h:
Copy from Gnulib.
Diffstat (limited to 'lib/timespec.h')
-rw-r--r-- | lib/timespec.h | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/lib/timespec.h b/lib/timespec.h index 3831301578e..cc34067374f 100644 --- a/lib/timespec.h +++ b/lib/timespec.h @@ -33,6 +33,8 @@ _GL_INLINE_HEADER_BEGIN extern "C" { #endif +#include "verify.h" + /* Resolution of timespec timestamps (in units per second), and log base 10 of the resolution. */ @@ -67,23 +69,29 @@ make_timespec (time_t s, long int ns) any platform of interest to the GNU project, since all such platforms have 32-bit int or wider. - Replacing "(int) (a.tv_nsec - b.tv_nsec)" with something like + Replacing "a.tv_nsec - b.tv_nsec" with something like "a.tv_nsec < b.tv_nsec ? -1 : a.tv_nsec > b.tv_nsec" would cause this function to work in some cases where the above assumption is violated, but not in all cases (e.g., a.tv_sec==1, a.tv_nsec==-2, b.tv_sec==0, b.tv_nsec==999999999) and is arguably not worth the extra instructions. Using a subtraction has the advantage of detecting some invalid cases on platforms that detect integer - overflow. - - The (int) cast avoids a gcc -Wconversion warning. */ + overflow. */ _GL_TIMESPEC_INLINE int _GL_ATTRIBUTE_PURE timespec_cmp (struct timespec a, struct timespec b) { - return (a.tv_sec < b.tv_sec ? -1 - : a.tv_sec > b.tv_sec ? 1 - : (int) (a.tv_nsec - b.tv_nsec)); + if (a.tv_sec < b.tv_sec) + return -1; + if (a.tv_sec > b.tv_sec) + return 1; + + /* Pacify gcc -Wstrict-overflow (bleeding-edge circa 2017-10-02). See: + http://lists.gnu.org/archive/html/bug-gnulib/2017-10/msg00006.html */ + assume (-1 <= a.tv_nsec && a.tv_nsec <= 2 * TIMESPEC_RESOLUTION); + assume (-1 <= b.tv_nsec && b.tv_nsec <= 2 * TIMESPEC_RESOLUTION); + + return a.tv_nsec - b.tv_nsec; } /* Return -1, 0, 1, depending on the sign of A. A.tv_nsec must be |