From 2eaaeea01ce0ad1bead7ffe8bfbe10f06fa8c9d2 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sun, 22 Jan 2023 14:45:14 +0100 Subject: [PATCH 45/47] Resolve conflicts for functions introduced in Android API level 29. * lib/time.in.h (timespec_get): Consider REPLACE_TIMESPEC_GET. Disable _GL_CXXALIASWARN invocation on non-glibc systems. * m4/time_h.m4 (gl_TIME_H_DEFAULTS): Initialize REPLACE_TIMESPEC_GET. * modules/time (Makefile.am): Substitute REPLACE_TIMESPEC_GET. * m4/gettime.m4 (gl_CHECK_FUNC_TIMESPEC_GET): Set also gl_cv_onwards_func_timespec_get. * m4/timespec_get.m4 (gl_FUNC_TIMESPEC_GET): Conditionally set REPLACE_TIMESPEC_GET. * modules/timespec_get (Depends-on, configure.ac): Consider REPLACE_TIMESPEC_GET. --- ChangeLog | 15 +++++++++++++++ lib/time.in.h | 16 ++++++++++++++-- m4/gettime.m4 | 35 ++++++++++++++++++++++++----------- m4/time_h.m4 | 3 ++- m4/timespec_get.m4 | 5 ++++- modules/time | 1 + modules/timespec_get | 5 +++-- 7 files changed, 63 insertions(+), 17 deletions(-) diff --git a/ChangeLog b/ChangeLog index d06ffacce2..1ce418acc0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +2023-01-22 Bruno Haible + + Resolve conflicts for functions introduced in Android API level 29. + + * lib/time.in.h (timespec_get): Consider REPLACE_TIMESPEC_GET. Disable + _GL_CXXALIASWARN invocation on non-glibc systems. + * m4/time_h.m4 (gl_TIME_H_DEFAULTS): Initialize REPLACE_TIMESPEC_GET. + * modules/time (Makefile.am): Substitute REPLACE_TIMESPEC_GET. + * m4/gettime.m4 (gl_CHECK_FUNC_TIMESPEC_GET): Set also + gl_cv_onwards_func_timespec_get. + * m4/timespec_get.m4 (gl_FUNC_TIMESPEC_GET): Conditionally set + REPLACE_TIMESPEC_GET. + * modules/timespec_get (Depends-on, configure.ac): Consider + REPLACE_TIMESPEC_GET. + 2023-01-22 Bruno Haible Resolve conflicts for functions introduced in Android API level 28. diff --git a/lib/time.in.h b/lib/time.in.h index fa0c6351b2..87cda21413 100644 --- a/lib/time.in.h +++ b/lib/time.in.h @@ -112,12 +112,24 @@ 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@ +# if @REPLACE_TIMESPEC_GET@ +# if !(defined __cplusplus && defined GNULIB_NAMESPACE) +# undef timespec_get +# 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 +# if __GLIBC__ >= 2 _GL_CXXALIASWARN (timespec_get); +# endif # endif /* Set *TS to the current time resolution, and return BASE. diff --git a/m4/gettime.m4 b/m4/gettime.m4 index 7e353fcd00..ec1f97ee0d 100644 --- a/m4/gettime.m4 +++ b/m4/gettime.m4 @@ -1,4 +1,4 @@ -# gettime.m4 serial 13 +# gettime.m4 serial 14 dnl Copyright (C) 2002, 2004-2006, 2009-2023 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -18,9 +18,11 @@ AC_DEFUN([gl_GETTIME], ]) dnl Tests whether the function timespec_get exists. -dnl Sets gl_cv_func_timespec_get. +dnl Sets gl_cv_func_timespec_get and gl_cv_onwards_func_timespec_get. AC_DEFUN([gl_CHECK_FUNC_TIMESPEC_GET], [ + AC_REQUIRE([AC_CANONICAL_HOST]) + dnl Persuade OpenBSD to declare timespec_get(). AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS]) @@ -29,21 +31,32 @@ AC_DEFUN([gl_CHECK_FUNC_TIMESPEC_GET], dnl But at the same time, we need to notice a missing declaration, like dnl gl_CHECK_FUNCS_ANDROID does. AC_CHECK_DECL([timespec_get], , , [[#include ]]) - if test $ac_cv_have_decl_timespec_get = yes; then - AC_CACHE_CHECK([for timespec_get], [gl_cv_func_timespec_get], - [AC_LINK_IFELSE( + AC_CACHE_CHECK([for timespec_get], [gl_cv_onwards_func_timespec_get], + [if test $ac_cv_have_decl_timespec_get = yes; then + AC_LINK_IFELSE( [AC_LANG_PROGRAM( [[#include struct timespec ts; ]], [[return timespec_get (&ts, 0);]]) ], - [gl_cv_func_timespec_get=yes], - [gl_cv_func_timespec_get=no]) - ]) - else - gl_cv_func_timespec_get=no - fi + [gl_cv_onwards_func_timespec_get=yes], + [gl_cv_onwards_func_timespec_get=no]) + else + gl_cv_onwards_func_timespec_get=no + fi + case "$host_os" in + linux*-android*) + if test $gl_cv_onwards_func_timespec_get = no; then + gl_cv_onwards_func_timespec_get='future OS version' + fi + ;; + esac + ]) + case "$gl_cv_onwards_func_timespec_get" in + future*) gl_cv_func_timespec_get=no ;; + *) gl_cv_func_timespec_get=$gl_cv_onwards_func_timespec_get ;; + esac ]) AC_DEFUN([gl_GETTIME_RES], diff --git a/m4/time_h.m4 b/m4/time_h.m4 index f6bf3a4f30..b74870c3d0 100644 --- a/m4/time_h.m4 +++ b/m4/time_h.m4 @@ -2,7 +2,7 @@ # Copyright (C) 2000-2001, 2003-2007, 2009-2023 Free Software Foundation, Inc. -# serial 20 +# serial 21 # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -170,6 +170,7 @@ AC_DEFUN([gl_TIME_H_DEFAULTS], REPLACE_NANOSLEEP=GNULIB_PORTCHECK; AC_SUBST([REPLACE_NANOSLEEP]) REPLACE_STRFTIME=GNULIB_PORTCHECK; AC_SUBST([REPLACE_STRFTIME]) REPLACE_TIMEGM=GNULIB_PORTCHECK; AC_SUBST([REPLACE_TIMEGM]) + REPLACE_TIMESPEC_GET=GNULIB_PORTCHECK; AC_SUBST([REPLACE_TIMESPEC_GET]) REPLACE_TZSET=GNULIB_PORTCHECK; AC_SUBST([REPLACE_TZSET]) dnl Hack so that the time module doesn't depend on the sys_time module. diff --git a/m4/timespec_get.m4 b/m4/timespec_get.m4 index 866ba5003a..61e4bc378b 100644 --- a/m4/timespec_get.m4 +++ b/m4/timespec_get.m4 @@ -1,4 +1,4 @@ -# timespec_get.m4 serial 3 +# timespec_get.m4 serial 4 dnl Copyright (C) 2021-2023 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -14,5 +14,8 @@ AC_DEFUN([gl_FUNC_TIMESPEC_GET], AC_REQUIRE([gl_CHECK_FUNC_TIMESPEC_GET]) if test $gl_cv_func_timespec_get != yes; then HAVE_TIMESPEC_GET=0 + case "$gl_cv_onwards_func_timespec_get" in + future*) REPLACE_TIMESPEC_GET=1 ;; + esac fi ]) diff --git a/modules/time b/modules/time index ae8471bb9e..75ff3a4d8c 100644 --- a/modules/time +++ b/modules/time @@ -60,6 +60,7 @@ time.h: time.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $( -e 's|@''REPLACE_NANOSLEEP''@|$(REPLACE_NANOSLEEP)|g' \ -e 's|@''REPLACE_STRFTIME''@|$(REPLACE_STRFTIME)|g' \ -e 's|@''REPLACE_TIMEGM''@|$(REPLACE_TIMEGM)|g' \ + -e 's|@''REPLACE_TIMESPEC_GET''@|$(REPLACE_TIMESPEC_GET)|g' \ -e 's|@''REPLACE_TZSET''@|$(REPLACE_TZSET)|g' \ -e 's|@''PTHREAD_H_DEFINES_STRUCT_TIMESPEC''@|$(PTHREAD_H_DEFINES_STRUCT_TIMESPEC)|g' \ -e 's|@''SYS_TIME_H_DEFINES_STRUCT_TIMESPEC''@|$(SYS_TIME_H_DEFINES_STRUCT_TIMESPEC)|g' \ diff --git a/modules/timespec_get b/modules/timespec_get index b1b33b494d..7b3dc3b01d 100644 --- a/modules/timespec_get +++ b/modules/timespec_get @@ -8,11 +8,12 @@ m4/timespec_get.m4 Depends-on: time extensions -gettime [test $HAVE_TIMESPEC_GET = 0] +gettime [test $HAVE_TIMESPEC_GET = 0 || test $REPLACE_TIMESPEC_GET = 1] configure.ac: gl_FUNC_TIMESPEC_GET -gl_CONDITIONAL([GL_COND_OBJ_TIMESPEC_GET], [test $HAVE_TIMESPEC_GET = 0]) +gl_CONDITIONAL([GL_COND_OBJ_TIMESPEC_GET], + [test $HAVE_TIMESPEC_GET = 0 || test $REPLACE_TIMESPEC_GET = 1]) gl_TIME_MODULE_INDICATOR([timespec_get]) Makefile.am: -- 2.34.1