From 504315db69efff2bc4e7ecc9868ef5c5f1c80da1 Mon Sep 17 00:00:00 2001 From: "Erlend E. Aasland" Date: Mon, 22 Nov 2021 21:33:19 +0100 Subject: [PATCH 1/3] bpo-45847: Port _posixshmem to PY_STDLIB_MOD --- Modules/Setup.stdlib.in | 1 + configure | 104 +++++++++++++++++++++++++++------------- configure.ac | 42 ++++++++-------- pyconfig.h.in | 3 -- setup.py | 15 +----- 5 files changed, 95 insertions(+), 70 deletions(-) diff --git a/Modules/Setup.stdlib.in b/Modules/Setup.stdlib.in index 9de0096c067837..73e4dcf24c6606 100644 --- a/Modules/Setup.stdlib.in +++ b/Modules/Setup.stdlib.in @@ -113,6 +113,7 @@ @MODULE_NIS_TRUE@nis nismodule.c # needs sys/soundcard.h or linux/soundcard.h (Linux, FreeBSD) @MODULE_OSSAUDIODEV_TRUE@ossaudiodev ossaudiodev.c +@MODULE__POSIXSHMEM_TRUE@_posixshmem _multiprocessing/posixshmem.c @MODULE__POSIXSUBPROCESS_TRUE@_posixsubprocess _posixsubprocess.c @MODULE_RESOURCE_TRUE@resource resource.c @MODULE_SELECT_TRUE@select selectmodule.c diff --git a/configure b/configure index 630102585e87e7..c6606734e7e825 100755 --- a/configure +++ b/configure @@ -710,6 +710,8 @@ MODULE_OSSAUDIODEV_FALSE MODULE_OSSAUDIODEV_TRUE MODULE_GRP_FALSE MODULE_GRP_TRUE +MODULE__POSIXSHMEM_FALSE +MODULE__POSIXSHMEM_TRUE MODULE_MMAP_FALSE MODULE_MMAP_TRUE MODULE_FCNTL_FALSE @@ -20030,9 +20032,13 @@ fi # checks for POSIX shared memory, used by Modules/_multiprocessing/posixshmem.c # shm_* may only be available if linking against librt -save_LIBS="$LIBS" -save_includes_default="$ac_includes_default" -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing shm_open" >&5 +save_CFLAGS=$CFLAGS +save_CPPFLAGS=$CPPFLAGS +save_LDFLAGS=$LDFLAGS +save_LIBS=$LIBS + + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing shm_open" >&5 $as_echo_n "checking for library containing shm_open... " >&6; } if ${ac_cv_search_shm_open+:} false; then : $as_echo_n "(cached) " >&6 @@ -20088,33 +20094,20 @@ if test "$ac_res" != no; then : fi -if test "$ac_cv_search_shm_open" = "-lrt"; then - -$as_echo "#define SHM_NEEDS_LIBRT 1" >>confdefs.h - -fi -for ac_header in sys/mman.h -do : - ac_fn_c_check_header_mongrel "$LINENO" "sys/mman.h" "ac_cv_header_sys_mman_h" "$ac_includes_default" -if test "x$ac_cv_header_sys_mman_h" = xyes; then : - cat >>confdefs.h <<_ACEOF -#define HAVE_SYS_MMAN_H 1 -_ACEOF - + if test "x$ac_cv_search_shm_open" = x-lrt; then : + POSIXSHMEM_LIBS="-lrt" fi -done - -# temporarily override ac_includes_default for AC_CHECK_FUNCS below -ac_includes_default="\ -${ac_includes_default} -#ifndef __cplusplus -# ifdef HAVE_SYS_MMAN_H -# include -# endif -#endif -" -for ac_func in shm_open shm_unlink + save_ac_includes_default=$ac_includes_default + ac_includes_default="\ + ${ac_includes_default} + #ifndef __cplusplus + # ifdef HAVE_SYS_MMAN_H + # include + # endif + #endif + " + for ac_func in shm_open shm_unlink do : as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh` ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var" @@ -20122,13 +20115,20 @@ if eval test \"x\$"$as_ac_var"\" = x"yes"; then : cat >>confdefs.h <<_ACEOF #define `$as_echo "HAVE_$ac_func" | $as_tr_cpp` 1 _ACEOF - + have_posix_shmem=yes +else + have_posix_shmem=no fi done -# we don't want to link with librt always, restore LIBS -LIBS="$save_LIBS" -ac_includes_default="$save_includes_default" + ac_includes_default=$save_ac_includes_default + +CFLAGS=$save_CFLAGS +CPPFLAGS=$save_CPPFLAGS +LDFLAGS=$save_LDFLAGS +LIBS=$save_LIBS + + # Check for usable OpenSSL @@ -21072,6 +21072,42 @@ fi $as_echo "$py_cv_module_mmap" >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for stdlib extension module _posixshmem" >&5 +$as_echo_n "checking for stdlib extension module _posixshmem... " >&6; } + case $py_stdlib_not_available in #( + *_posixshmem*) : + py_cv_module__posixshmem=n/a ;; #( + *) : + if true; then : + if test "$have_posix_shmem" = "yes"; then : + py_cv_module__posixshmem=yes +else + py_cv_module__posixshmem=missing +fi +else + py_cv_module__posixshmem=disabled +fi + ;; +esac + as_fn_append MODULE_BLOCK "MODULE__POSIXSHMEM=$py_cv_module__posixshmem$as_nl" + if test "x$py_cv_module__posixshmem" = xyes; then : + + + as_fn_append MODULE_BLOCK "MODULE__POSIXSHMEM_LDFLAGS=$POSIXSHMEM_LIBS$as_nl" + +fi + if test "$py_cv_module__posixshmem" = yes; then + MODULE__POSIXSHMEM_TRUE= + MODULE__POSIXSHMEM_FALSE='#' +else + MODULE__POSIXSHMEM_TRUE='#' + MODULE__POSIXSHMEM_FALSE= +fi + + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $py_cv_module__posixshmem" >&5 +$as_echo "$py_cv_module__posixshmem" >&6; } + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for stdlib extension module grp" >&5 $as_echo_n "checking for stdlib extension module grp... " >&6; } @@ -22621,6 +22657,10 @@ if test -z "${MODULE_MMAP_TRUE}" && test -z "${MODULE_MMAP_FALSE}"; then as_fn_error $? "conditional \"MODULE_MMAP\" was never defined. Usually this means the macro was only invoked conditionally." "$LINENO" 5 fi +if test -z "${MODULE__POSIXSHMEM_TRUE}" && test -z "${MODULE__POSIXSHMEM_FALSE}"; then + as_fn_error $? "conditional \"MODULE__POSIXSHMEM\" was never defined. +Usually this means the macro was only invoked conditionally." "$LINENO" 5 +fi if test -z "${MODULE_GRP_TRUE}" && test -z "${MODULE_GRP_FALSE}"; then as_fn_error $? "conditional \"MODULE_GRP\" was never defined. Usually this means the macro was only invoked conditionally." "$LINENO" 5 diff --git a/configure.ac b/configure.ac index 34a2c694ddfc25..a161a8cf885456 100644 --- a/configure.ac +++ b/configure.ac @@ -5875,27 +5875,24 @@ AS_VAR_IF([ac_cv_func_getrandom], [yes], [ # checks for POSIX shared memory, used by Modules/_multiprocessing/posixshmem.c # shm_* may only be available if linking against librt -save_LIBS="$LIBS" -save_includes_default="$ac_includes_default" -AC_SEARCH_LIBS(shm_open, rt) -if test "$ac_cv_search_shm_open" = "-lrt"; then - AC_DEFINE(SHM_NEEDS_LIBRT, 1, - [Define to 1 if you must link with -lrt for shm_open().]) -fi -AC_CHECK_HEADERS(sys/mman.h) -# temporarily override ac_includes_default for AC_CHECK_FUNCS below -ac_includes_default="\ -${ac_includes_default} -#ifndef __cplusplus -# ifdef HAVE_SYS_MMAN_H -# include -# endif -#endif -" -AC_CHECK_FUNCS([shm_open shm_unlink]) -# we don't want to link with librt always, restore LIBS -LIBS="$save_LIBS" -ac_includes_default="$save_includes_default" +POSIXSHMEM_CFLAGS='-I$(srcdir)/Modules/_multiprocessing' +WITH_SAVE_ENV([ + AC_SEARCH_LIBS([shm_open], [rt]) + AS_VAR_IF([ac_cv_search_shm_open], [-lrt], [POSIXSHMEM_LIBS="-lrt"]) + + dnl Temporarily override ac_includes_default for AC_CHECK_FUNCS below. + _SAVE_VAR([ac_includes_default]) + ac_includes_default="\ + ${ac_includes_default} + #ifndef __cplusplus + # ifdef HAVE_SYS_MMAN_H + # include + # endif + #endif + " + AC_CHECK_FUNCS([shm_open shm_unlink], [have_posix_shmem=yes], [have_posix_shmem=no]) + _RESTORE_VAR([ac_includes_default]) +]) # Check for usable OpenSSL AX_CHECK_OPENSSL([have_openssl=yes],[have_openssl=no]) @@ -6251,6 +6248,9 @@ PY_STDLIB_MOD([fcntl], [], [$FCNTL_LIBS]) PY_STDLIB_MOD([mmap], [], [test "$ac_cv_header_sys_mman_h" = "yes" -a "$ac_cv_header_sys_stat_h" = "yes"]) +PY_STDLIB_MOD([_posixshmem], + [], [test "$have_posix_shmem" = "yes"], + [$POSIXSHMEM_CFLAGS], [$POSIXSHMEM_LIBS]) dnl platform specific extensions PY_STDLIB_MOD([grp], [], [test "$ac_cv_func_getgrgid" = yes -o "$ac_cv_func_getgrgid_r" = yes]) diff --git a/pyconfig.h.in b/pyconfig.h.in index bb9ae4c3dbc82e..67f27c2b17e3b4 100644 --- a/pyconfig.h.in +++ b/pyconfig.h.in @@ -1469,9 +1469,6 @@ /* Define if setpgrp() must be called as setpgrp(0, 0). */ #undef SETPGRP_HAVE_ARG -/* Define to 1 if you must link with -lrt for shm_open(). */ -#undef SHM_NEEDS_LIBRT - /* Define if i>>j for signed int i does not extend the sign bit when i < 0 */ #undef SIGNED_RIGHT_SHIFT_ZERO_FILLS diff --git a/setup.py b/setup.py index 98a20150c1e0be..72497de5c0d3ac 100644 --- a/setup.py +++ b/setup.py @@ -1397,20 +1397,7 @@ def detect_multiprocessing(self): self.add(Extension('_multiprocessing', multiprocessing_srcs, include_dirs=["Modules/_multiprocessing"])) - if (not MS_WINDOWS and - sysconfig.get_config_var('HAVE_SHM_OPEN') and - sysconfig.get_config_var('HAVE_SHM_UNLINK')): - posixshmem_srcs = ['_multiprocessing/posixshmem.c'] - libs = [] - if sysconfig.get_config_var('SHM_NEEDS_LIBRT'): - # need to link with librt to get shm_open() - libs.append('rt') - self.add(Extension('_posixshmem', posixshmem_srcs, - define_macros={}, - libraries=libs, - include_dirs=["Modules/_multiprocessing"])) - else: - self.missing.append('_posixshmem') + self.addext(Extension('_posixshmem', ['_multiprocessing/posixshmem.c'])) def detect_uuid(self): # Build the _uuid module if possible From 3af2b63df6141c04ba0c51a431ff0ef5209b9203 Mon Sep 17 00:00:00 2001 From: "Erlend E. Aasland" Date: Wed, 24 Nov 2021 00:26:03 +0100 Subject: [PATCH 2/3] regen configure --- configure | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/configure b/configure index c6606734e7e825..70c94a4e24d602 100755 --- a/configure +++ b/configure @@ -20032,6 +20032,7 @@ fi # checks for POSIX shared memory, used by Modules/_multiprocessing/posixshmem.c # shm_* may only be available if linking against librt +POSIXSHMEM_CFLAGS='-I$(srcdir)/Modules/_multiprocessing' save_CFLAGS=$CFLAGS save_CPPFLAGS=$CPPFLAGS save_LDFLAGS=$LDFLAGS @@ -21092,7 +21093,7 @@ esac as_fn_append MODULE_BLOCK "MODULE__POSIXSHMEM=$py_cv_module__posixshmem$as_nl" if test "x$py_cv_module__posixshmem" = xyes; then : - + as_fn_append MODULE_BLOCK "MODULE__POSIXSHMEM_CFLAGS=$POSIXSHMEM_CFLAGS$as_nl" as_fn_append MODULE_BLOCK "MODULE__POSIXSHMEM_LDFLAGS=$POSIXSHMEM_LIBS$as_nl" fi From e1c12a0d5a7e555ecbedd4dfae05ff72e686a86d Mon Sep 17 00:00:00 2001 From: "Erlend E. Aasland" Date: Wed, 24 Nov 2021 00:29:35 +0100 Subject: [PATCH 3/3] Move posixshmem to 'multiprocessing' section --- Modules/Setup.stdlib.in | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Modules/Setup.stdlib.in b/Modules/Setup.stdlib.in index 73e4dcf24c6606..e999775caf3f7c 100644 --- a/Modules/Setup.stdlib.in +++ b/Modules/Setup.stdlib.in @@ -113,7 +113,6 @@ @MODULE_NIS_TRUE@nis nismodule.c # needs sys/soundcard.h or linux/soundcard.h (Linux, FreeBSD) @MODULE_OSSAUDIODEV_TRUE@ossaudiodev ossaudiodev.c -@MODULE__POSIXSHMEM_TRUE@_posixshmem _multiprocessing/posixshmem.c @MODULE__POSIXSUBPROCESS_TRUE@_posixsubprocess _posixsubprocess.c @MODULE_RESOURCE_TRUE@resource resource.c @MODULE_SELECT_TRUE@select selectmodule.c @@ -123,6 +122,9 @@ @MODULE_SYSLOG_TRUE@syslog syslogmodule.c @MODULE_TERMIOS_TRUE@termios termios.c +# multiprocessing +@MODULE__POSIXSHMEM_TRUE@_posixshmem _multiprocessing/posixshmem.c + ############################################################################ # Modules with third party dependencies