On 9/4/22 17:00, Bruno Haible wrote:
But I am lazy here, as 'timespec_get' is usually not the kind of function that people will call from an extern inline function.
timespec_get is so new that I wouldn't expect it to be called from anywhere. Still, this business of "static inline" for standard functions is trouble, as I have run into problems with that sort of thing elsewhere.
How about something like the attached patch? It's just a stab at fixing the bug (since I can't test it), but I can polish it if this sort of thing would work. As part of the polish, the MSVC timespec_get bug should be documented in the Gnulib manual.
diff --git a/lib/time.in.h b/lib/time.in.h index 6d4c771963..4bd5488edc 100644 --- a/lib/time.in.h +++ b/lib/time.in.h @@ -112,11 +112,22 @@ struct __time_t_must_be_integral { /* Set *TS to the current time, and return BASE. Upon failure, return 0. */ # if @GNULIB_TIMESPEC_GET@ -# if ! @HAVE_TIMESPEC_GET@ +# ifdef _MSC_VER +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# define timespec_get rpl_timespec_get +# endif +_GL_FUNCDECL_RPL (timespec_get, int, + (struct timespec *ts, int base) + _GL_ARG_NONNULL ((1))); +_GL_CXXALIAS_RPL (timespec_get, int, + (struct timespec *ts, int base)); +# else +# if ! @HAVE_TIMESPEC_GET@ _GL_FUNCDECL_SYS (timespec_get, int, (struct timespec *ts, int base) _GL_ARG_NONNULL ((1))); -# endif +# endif _GL_CXXALIAS_SYS (timespec_get, int, (struct timespec *ts, int base)); +# endif _GL_CXXALIASWARN (timespec_get); # endif diff --git a/m4/gettime.m4 b/m4/gettime.m4 index c3e0713b57..f0aeb4d0e4 100644 --- a/m4/gettime.m4 +++ b/m4/gettime.m4 @@ -1,4 +1,4 @@ -# gettime.m4 serial 12 +# gettime.m4 serial 11 dnl Copyright (C) 2002, 2004-2006, 2009-2022 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -9,34 +9,7 @@ AC_DEFUN([gl_GETTIME], dnl Prerequisites of lib/gettime.c. AC_REQUIRE([gl_CLOCK_TIME]) AC_REQUIRE([gl_TIMESPEC]) - - AC_REQUIRE([gl_CHECK_FUNC_TIMESPEC_GET]) - if test $gl_cv_func_timespec_get = yes; then - AC_DEFINE([HAVE_TIMESPEC_GET], [1], - [Define if you have the timespec_get function.]) - fi -]) - -dnl Tests whether the function timespec_get exists. -dnl Sets gl_cv_func_timespec_get. -AC_DEFUN([gl_CHECK_FUNC_TIMESPEC_GET], -[ - dnl Persuade OpenBSD <time.h> to declare timespec_get(). - AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS]) - - dnl We can't use AC_CHECK_FUNC here, because timespec_get() is defined as a - dnl static inline function in <time.h> on MSVC 14. - AC_CACHE_CHECK([for timespec_get], [gl_cv_func_timespec_get], - [AC_LINK_IFELSE( - [AC_LANG_PROGRAM( - [[#include <time.h> - struct timespec ts; - ]], - [[return timespec_get (&ts, 0);]]) - ], - [gl_cv_func_timespec_get=yes], - [gl_cv_func_timespec_get=no]) - ]) + AC_CHECK_FUNCS_ONCE([timespec_get]) ]) AC_DEFUN([gl_GETTIME_RES], diff --git a/m4/timespec_get.m4 b/m4/timespec_get.m4 index acea56d626..cc5ce299de 100644 --- a/m4/timespec_get.m4 +++ b/m4/timespec_get.m4 @@ -1,4 +1,4 @@ -# timespec_get.m4 serial 3 +# timespec_get.m4 serial 2 dnl Copyright (C) 2021-2022 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -11,8 +11,8 @@ AC_DEFUN([gl_FUNC_TIMESPEC_GET], dnl Persuade OpenBSD <time.h> to declare timespec_get(). AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS]) - AC_REQUIRE([gl_CHECK_FUNC_TIMESPEC_GET]) - if test $gl_cv_func_timespec_get != yes; then + AC_CHECK_FUNCS_ONCE([timespec_get]) + if test $ac_cv_func_timespec_get != yes; then HAVE_TIMESPEC_GET=0 fi ])