From 1a8d41e57932833d94b6c9f32d69c8de0e64d29d Mon Sep 17 00:00:00 2001 From: "Erlend E. Aasland" Date: Mon, 29 May 2023 13:53:10 +0200 Subject: [PATCH 1/6] gh-89886: Rely on HAVE_SYS_TIME_H Quoting autoconf (v2.71): All current systems provide time.h; it need not be checked for. Not all systems provide sys/time.h, but those that do, all allow you to include it and time.h simultaneously. --- Modules/expat/xmlparse.c | 1 + Modules/readline.c | 3 +++ Modules/resource.c | 3 +++ configure | 10 +--------- configure.ac | 10 +++------- pyconfig.h.in | 3 --- 6 files changed, 11 insertions(+), 19 deletions(-) diff --git a/Modules/expat/xmlparse.c b/Modules/expat/xmlparse.c index b6c2eca97567ba..2f24bdea41faf8 100644 --- a/Modules/expat/xmlparse.c +++ b/Modules/expat/xmlparse.c @@ -85,6 +85,7 @@ #ifdef _WIN32 # define getpid GetCurrentProcessId #else +// HAVE_SYS_TIME_H is enforced by configure # include /* gettimeofday() */ # include /* getpid() */ # include /* getpid() */ diff --git a/Modules/readline.c b/Modules/readline.c index fdb6356e1c84b5..2824105a187586 100644 --- a/Modules/readline.c +++ b/Modules/readline.c @@ -11,7 +11,10 @@ #include #include #include // free() +#ifdef HAVE_SYS_TIME_H #include +#endif +#include #if defined(HAVE_SETLOCALE) /* GNU readline() mistakenly sets the LC_CTYPE locale. diff --git a/Modules/resource.c b/Modules/resource.c index 2a8158c9be5359..3c89468c48c56e 100644 --- a/Modules/resource.c +++ b/Modules/resource.c @@ -1,7 +1,10 @@ #include "Python.h" #include +#ifdef HAVE_SYS_TIME_H #include +#endif +#include #include #include #include diff --git a/configure b/configure index acb832d417bfcc..3980645caacfea 100755 --- a/configure +++ b/configure @@ -19284,14 +19284,6 @@ fi done -if test "x$ac_cv_header_sys_time_h" = xyes; then : - - -$as_echo "#define TIME_WITH_SYS_TIME 1" >>confdefs.h - - -fi - # checks for structures { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether struct tm is in sys/time.h or time.h" >&5 $as_echo_n "checking whether struct tm is in sys/time.h or time.h... " >&6; } @@ -26089,7 +26081,7 @@ $as_echo_n "checking for stdlib extension module _elementtree... " >&6; } if test "$py_cv_module__elementtree" != "n/a"; then : if true; then : - if true; then : + if test "$ac_cv_header_sys_time_h" = "yes"; then : py_cv_module__elementtree=yes else py_cv_module__elementtree=missing diff --git a/configure.ac b/configure.ac index 14e8533df7e501..f8388847e4ea56 100644 --- a/configure.ac +++ b/configure.ac @@ -5236,12 +5236,6 @@ fi AC_CHECK_FUNCS(getnameinfo) -dnl autoconf 2.71 deprecates AC_HEADER_TIME, keep for backwards compatibility -dnl TIME_WITH_SYS_TIME works on all supported systems that have sys/time.h -AS_VAR_IF([ac_cv_header_sys_time_h], [yes], [ - AC_DEFINE([TIME_WITH_SYS_TIME], 1, [Define to 1 if you can safely include both and .]) -]) - # checks for structures AC_STRUCT_TM AC_STRUCT_TIMEZONE @@ -7201,7 +7195,9 @@ PY_STDLIB_MOD([termios], [], [test "$ac_cv_header_termios_h" = yes]) dnl _elementtree loads libexpat via CAPI hook in pyexpat PY_STDLIB_MOD([pyexpat], [], [], [$LIBEXPAT_CFLAGS], [$LIBEXPAT_LDFLAGS]) -PY_STDLIB_MOD([_elementtree], [], [], [$LIBEXPAT_CFLAGS], []) +PY_STDLIB_MOD([_elementtree], + [], [test "$ac_cv_header_sys_time_h" = "yes"], + [$LIBEXPAT_CFLAGS], []) PY_STDLIB_MOD_SIMPLE([_codecs_cn]) PY_STDLIB_MOD_SIMPLE([_codecs_hk]) PY_STDLIB_MOD_SIMPLE([_codecs_iso2022]) diff --git a/pyconfig.h.in b/pyconfig.h.in index 694fea93cf7a51..cbfd63c46c1648 100644 --- a/pyconfig.h.in +++ b/pyconfig.h.in @@ -1682,9 +1682,6 @@ /* Library needed by timemodule.c: librt may be needed for clock_gettime() */ #undef TIMEMODULE_LIB -/* Define to 1 if you can safely include both and . */ -#undef TIME_WITH_SYS_TIME - /* Define to 1 if your declares `struct tm'. */ #undef TM_IN_SYS_TIME From de000c6fe7af2a9eb6019813244752f546d6b0cb Mon Sep 17 00:00:00 2001 From: "Erlend E. Aasland" Date: Mon, 29 May 2023 14:08:35 +0200 Subject: [PATCH 2/6] Fixup pyexpat detection --- configure | 9 +++++++-- configure.ac | 11 +++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/configure b/configure index 3980645caacfea..64f1f940945c4c 100755 --- a/configure +++ b/configure @@ -12621,6 +12621,11 @@ fi +if test "x$ac_cv_header_sys_time_h" = xyes; then : + have_libexpat=yes + +fi + have_libffi=missing if test "x$ac_sys_system" = xDarwin; then : @@ -26047,7 +26052,7 @@ $as_echo_n "checking for stdlib extension module pyexpat... " >&6; } if test "$py_cv_module_pyexpat" != "n/a"; then : if true; then : - if true; then : + if test "$have_libexpat" = "yes"; then : py_cv_module_pyexpat=yes else py_cv_module_pyexpat=missing @@ -26081,7 +26086,7 @@ $as_echo_n "checking for stdlib extension module _elementtree... " >&6; } if test "$py_cv_module__elementtree" != "n/a"; then : if true; then : - if test "$ac_cv_header_sys_time_h" = "yes"; then : + if test "$have_libexpat" = "yes"; then : py_cv_module__elementtree=yes else py_cv_module__elementtree=missing diff --git a/configure.ac b/configure.ac index f8388847e4ea56..cc038e6fe628ce 100644 --- a/configure.ac +++ b/configure.ac @@ -3735,6 +3735,11 @@ AS_VAR_IF([with_system_expat], [yes], [ AC_SUBST([LIBEXPAT_CFLAGS]) AC_SUBST([LIBEXPAT_INTERNAL]) +AS_VAR_IF( + [ac_cv_header_sys_time_h], [yes], + [AS_VAR_SET([have_libexpat], [yes])] +) + dnl detect libffi have_libffi=missing AS_VAR_IF([ac_sys_system], [Darwin], [ @@ -7194,9 +7199,11 @@ PY_STDLIB_MOD([syslog], [], [test "$ac_cv_header_syslog_h" = yes]) PY_STDLIB_MOD([termios], [], [test "$ac_cv_header_termios_h" = yes]) dnl _elementtree loads libexpat via CAPI hook in pyexpat -PY_STDLIB_MOD([pyexpat], [], [], [$LIBEXPAT_CFLAGS], [$LIBEXPAT_LDFLAGS]) +PY_STDLIB_MOD([pyexpat], + [], [test "$have_libexpat" = "yes"], + [$LIBEXPAT_CFLAGS], [$LIBEXPAT_LDFLAGS]) PY_STDLIB_MOD([_elementtree], - [], [test "$ac_cv_header_sys_time_h" = "yes"], + [], [test "$have_libexpat" = "yes"], [$LIBEXPAT_CFLAGS], []) PY_STDLIB_MOD_SIMPLE([_codecs_cn]) PY_STDLIB_MOD_SIMPLE([_codecs_hk]) From 92350d7846d780a8b2ce35c6909fc183ae76c520 Mon Sep 17 00:00:00 2001 From: "Erlend E. Aasland" Date: Tue, 30 May 2023 22:47:05 +0200 Subject: [PATCH 3/6] Address review: remove confusingly named 'have_libexpat' Simply use ac_cv_header_sys_time_h for PY_STDLIB_MOD --- configure | 9 ++------- configure.ac | 9 ++------- 2 files changed, 4 insertions(+), 14 deletions(-) diff --git a/configure b/configure index 64f1f940945c4c..15f0b842ed5d4f 100755 --- a/configure +++ b/configure @@ -12621,11 +12621,6 @@ fi -if test "x$ac_cv_header_sys_time_h" = xyes; then : - have_libexpat=yes - -fi - have_libffi=missing if test "x$ac_sys_system" = xDarwin; then : @@ -26052,7 +26047,7 @@ $as_echo_n "checking for stdlib extension module pyexpat... " >&6; } if test "$py_cv_module_pyexpat" != "n/a"; then : if true; then : - if test "$have_libexpat" = "yes"; then : + if test "$ac_cv_header_sys_time_h" = "yes"; then : py_cv_module_pyexpat=yes else py_cv_module_pyexpat=missing @@ -26086,7 +26081,7 @@ $as_echo_n "checking for stdlib extension module _elementtree... " >&6; } if test "$py_cv_module__elementtree" != "n/a"; then : if true; then : - if test "$have_libexpat" = "yes"; then : + if test "$ac_cv_header_sys_time_h" = "yes"; then : py_cv_module__elementtree=yes else py_cv_module__elementtree=missing diff --git a/configure.ac b/configure.ac index cc038e6fe628ce..f49f6db5f4ecc9 100644 --- a/configure.ac +++ b/configure.ac @@ -3735,11 +3735,6 @@ AS_VAR_IF([with_system_expat], [yes], [ AC_SUBST([LIBEXPAT_CFLAGS]) AC_SUBST([LIBEXPAT_INTERNAL]) -AS_VAR_IF( - [ac_cv_header_sys_time_h], [yes], - [AS_VAR_SET([have_libexpat], [yes])] -) - dnl detect libffi have_libffi=missing AS_VAR_IF([ac_sys_system], [Darwin], [ @@ -7200,10 +7195,10 @@ PY_STDLIB_MOD([termios], [], [test "$ac_cv_header_termios_h" = yes]) dnl _elementtree loads libexpat via CAPI hook in pyexpat PY_STDLIB_MOD([pyexpat], - [], [test "$have_libexpat" = "yes"], + [], [test "$ac_cv_header_sys_time_h" = "yes"], [$LIBEXPAT_CFLAGS], [$LIBEXPAT_LDFLAGS]) PY_STDLIB_MOD([_elementtree], - [], [test "$have_libexpat" = "yes"], + [], [test "$ac_cv_header_sys_time_h" = "yes"], [$LIBEXPAT_CFLAGS], []) PY_STDLIB_MOD_SIMPLE([_codecs_cn]) PY_STDLIB_MOD_SIMPLE([_codecs_hk]) From e3271f567d2ac22f49493f91f5ac463767ff1d30 Mon Sep 17 00:00:00 2001 From: "Erlend E. Aasland" Date: Wed, 31 May 2023 21:44:46 +0200 Subject: [PATCH 4/6] Revert _elementtree change --- configure.ac | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/configure.ac b/configure.ac index d6580b56d27633..fd33ab26664e5c 100644 --- a/configure.ac +++ b/configure.ac @@ -7293,9 +7293,7 @@ dnl _elementtree loads libexpat via CAPI hook in pyexpat PY_STDLIB_MOD([pyexpat], [], [test "$ac_cv_header_sys_time_h" = "yes"], [$LIBEXPAT_CFLAGS], [$LIBEXPAT_LDFLAGS]) -PY_STDLIB_MOD([_elementtree], - [], [test "$ac_cv_header_sys_time_h" = "yes"], - [$LIBEXPAT_CFLAGS], []) +PY_STDLIB_MOD([_elementtree], [], [], [$LIBEXPAT_CFLAGS], []) PY_STDLIB_MOD_SIMPLE([_codecs_cn]) PY_STDLIB_MOD_SIMPLE([_codecs_hk]) PY_STDLIB_MOD_SIMPLE([_codecs_iso2022]) From 00b82b79ff513aa451ad4e7a6939bea662ae2a22 Mon Sep 17 00:00:00 2001 From: "Erlend E. Aasland" Date: Wed, 31 May 2023 21:45:37 +0200 Subject: [PATCH 5/6] Regen --- configure | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure b/configure index f4d57091104d65..7300eb0bf14753 100755 --- a/configure +++ b/configure @@ -26069,7 +26069,7 @@ $as_echo_n "checking for stdlib extension module _elementtree... " >&6; } if test "$py_cv_module__elementtree" != "n/a"; then : if true; then : - if test "$ac_cv_header_sys_time_h" = "yes"; then : + if true; then : py_cv_module__elementtree=yes else py_cv_module__elementtree=missing From 3988c9c4b20da281c7710ffefa76032eaa63912f Mon Sep 17 00:00:00 2001 From: "Erlend E. Aasland" Date: Wed, 31 May 2023 21:49:05 +0200 Subject: [PATCH 6/6] Revert expat change --- Modules/expat/xmlparse.c | 1 - 1 file changed, 1 deletion(-) diff --git a/Modules/expat/xmlparse.c b/Modules/expat/xmlparse.c index 2f24bdea41faf8..b6c2eca97567ba 100644 --- a/Modules/expat/xmlparse.c +++ b/Modules/expat/xmlparse.c @@ -85,7 +85,6 @@ #ifdef _WIN32 # define getpid GetCurrentProcessId #else -// HAVE_SYS_TIME_H is enforced by configure # include /* gettimeofday() */ # include /* getpid() */ # include /* getpid() */