Skip to content

Commit 3245270

Browse files
author
Erlend Egeberg Aasland
authored
bpo-45847: Port _posixshmem to PY_STDLIB_MOD (GH-29738)
1 parent dd8ce9e commit 3245270

File tree

5 files changed

+98
-70
lines changed

5 files changed

+98
-70
lines changed

Modules/Setup.stdlib.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,9 @@
122122
@MODULE_SYSLOG_TRUE@syslog syslogmodule.c
123123
@MODULE_TERMIOS_TRUE@termios termios.c
124124

125+
# multiprocessing
126+
@MODULE__POSIXSHMEM_TRUE@_posixshmem _multiprocessing/posixshmem.c
127+
125128

126129
############################################################################
127130
# Modules with third party dependencies

configure

Lines changed: 73 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -710,6 +710,8 @@ MODULE_OSSAUDIODEV_FALSE
710710
MODULE_OSSAUDIODEV_TRUE
711711
MODULE_GRP_FALSE
712712
MODULE_GRP_TRUE
713+
MODULE__POSIXSHMEM_FALSE
714+
MODULE__POSIXSHMEM_TRUE
713715
MODULE_MMAP_FALSE
714716
MODULE_MMAP_TRUE
715717
MODULE_FCNTL_FALSE
@@ -20030,9 +20032,14 @@ fi
2003020032

2003120033
# checks for POSIX shared memory, used by Modules/_multiprocessing/posixshmem.c
2003220034
# shm_* may only be available if linking against librt
20033-
save_LIBS="$LIBS"
20034-
save_includes_default="$ac_includes_default"
20035-
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing shm_open" >&5
20035+
POSIXSHMEM_CFLAGS='-I$(srcdir)/Modules/_multiprocessing'
20036+
save_CFLAGS=$CFLAGS
20037+
save_CPPFLAGS=$CPPFLAGS
20038+
save_LDFLAGS=$LDFLAGS
20039+
save_LIBS=$LIBS
20040+
20041+
20042+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing shm_open" >&5
2003620043
$as_echo_n "checking for library containing shm_open... " >&6; }
2003720044
if ${ac_cv_search_shm_open+:} false; then :
2003820045
$as_echo_n "(cached) " >&6
@@ -20088,47 +20095,41 @@ if test "$ac_res" != no; then :
2008820095

2008920096
fi
2009020097

20091-
if test "$ac_cv_search_shm_open" = "-lrt"; then
20092-
20093-
$as_echo "#define SHM_NEEDS_LIBRT 1" >>confdefs.h
20094-
20095-
fi
20096-
for ac_header in sys/mman.h
20097-
do :
20098-
ac_fn_c_check_header_mongrel "$LINENO" "sys/mman.h" "ac_cv_header_sys_mman_h" "$ac_includes_default"
20099-
if test "x$ac_cv_header_sys_mman_h" = xyes; then :
20100-
cat >>confdefs.h <<_ACEOF
20101-
#define HAVE_SYS_MMAN_H 1
20102-
_ACEOF
20103-
20098+
if test "x$ac_cv_search_shm_open" = x-lrt; then :
20099+
POSIXSHMEM_LIBS="-lrt"
2010420100
fi
2010520101

20106-
done
20107-
20108-
# temporarily override ac_includes_default for AC_CHECK_FUNCS below
20109-
ac_includes_default="\
20110-
${ac_includes_default}
20111-
#ifndef __cplusplus
20112-
# ifdef HAVE_SYS_MMAN_H
20113-
# include <sys/mman.h>
20114-
# endif
20115-
#endif
20116-
"
20117-
for ac_func in shm_open shm_unlink
20102+
save_ac_includes_default=$ac_includes_default
20103+
ac_includes_default="\
20104+
${ac_includes_default}
20105+
#ifndef __cplusplus
20106+
# ifdef HAVE_SYS_MMAN_H
20107+
# include <sys/mman.h>
20108+
# endif
20109+
#endif
20110+
"
20111+
for ac_func in shm_open shm_unlink
2011820112
do :
2011920113
as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
2012020114
ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"
2012120115
if eval test \"x\$"$as_ac_var"\" = x"yes"; then :
2012220116
cat >>confdefs.h <<_ACEOF
2012320117
#define `$as_echo "HAVE_$ac_func" | $as_tr_cpp` 1
2012420118
_ACEOF
20125-
20119+
have_posix_shmem=yes
20120+
else
20121+
have_posix_shmem=no
2012620122
fi
2012720123
done
2012820124

20129-
# we don't want to link with librt always, restore LIBS
20130-
LIBS="$save_LIBS"
20131-
ac_includes_default="$save_includes_default"
20125+
ac_includes_default=$save_ac_includes_default
20126+
20127+
CFLAGS=$save_CFLAGS
20128+
CPPFLAGS=$save_CPPFLAGS
20129+
LDFLAGS=$save_LDFLAGS
20130+
LIBS=$save_LIBS
20131+
20132+
2013220133

2013320134
# Check for usable OpenSSL
2013420135

@@ -21072,6 +21073,42 @@ fi
2107221073
$as_echo "$py_cv_module_mmap" >&6; }
2107321074

2107421075

21076+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for stdlib extension module _posixshmem" >&5
21077+
$as_echo_n "checking for stdlib extension module _posixshmem... " >&6; }
21078+
case $py_stdlib_not_available in #(
21079+
*_posixshmem*) :
21080+
py_cv_module__posixshmem=n/a ;; #(
21081+
*) :
21082+
if true; then :
21083+
if test "$have_posix_shmem" = "yes"; then :
21084+
py_cv_module__posixshmem=yes
21085+
else
21086+
py_cv_module__posixshmem=missing
21087+
fi
21088+
else
21089+
py_cv_module__posixshmem=disabled
21090+
fi
21091+
;;
21092+
esac
21093+
as_fn_append MODULE_BLOCK "MODULE__POSIXSHMEM=$py_cv_module__posixshmem$as_nl"
21094+
if test "x$py_cv_module__posixshmem" = xyes; then :
21095+
21096+
as_fn_append MODULE_BLOCK "MODULE__POSIXSHMEM_CFLAGS=$POSIXSHMEM_CFLAGS$as_nl"
21097+
as_fn_append MODULE_BLOCK "MODULE__POSIXSHMEM_LDFLAGS=$POSIXSHMEM_LIBS$as_nl"
21098+
21099+
fi
21100+
if test "$py_cv_module__posixshmem" = yes; then
21101+
MODULE__POSIXSHMEM_TRUE=
21102+
MODULE__POSIXSHMEM_FALSE='#'
21103+
else
21104+
MODULE__POSIXSHMEM_TRUE='#'
21105+
MODULE__POSIXSHMEM_FALSE=
21106+
fi
21107+
21108+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $py_cv_module__posixshmem" >&5
21109+
$as_echo "$py_cv_module__posixshmem" >&6; }
21110+
21111+
2107521112

2107621113
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for stdlib extension module grp" >&5
2107721114
$as_echo_n "checking for stdlib extension module grp... " >&6; }
@@ -22621,6 +22658,10 @@ if test -z "${MODULE_MMAP_TRUE}" && test -z "${MODULE_MMAP_FALSE}"; then
2262122658
as_fn_error $? "conditional \"MODULE_MMAP\" was never defined.
2262222659
Usually this means the macro was only invoked conditionally." "$LINENO" 5
2262322660
fi
22661+
if test -z "${MODULE__POSIXSHMEM_TRUE}" && test -z "${MODULE__POSIXSHMEM_FALSE}"; then
22662+
as_fn_error $? "conditional \"MODULE__POSIXSHMEM\" was never defined.
22663+
Usually this means the macro was only invoked conditionally." "$LINENO" 5
22664+
fi
2262422665
if test -z "${MODULE_GRP_TRUE}" && test -z "${MODULE_GRP_FALSE}"; then
2262522666
as_fn_error $? "conditional \"MODULE_GRP\" was never defined.
2262622667
Usually this means the macro was only invoked conditionally." "$LINENO" 5

configure.ac

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5875,27 +5875,24 @@ AS_VAR_IF([ac_cv_func_getrandom], [yes], [
58755875

58765876
# checks for POSIX shared memory, used by Modules/_multiprocessing/posixshmem.c
58775877
# shm_* may only be available if linking against librt
5878-
save_LIBS="$LIBS"
5879-
save_includes_default="$ac_includes_default"
5880-
AC_SEARCH_LIBS(shm_open, rt)
5881-
if test "$ac_cv_search_shm_open" = "-lrt"; then
5882-
AC_DEFINE(SHM_NEEDS_LIBRT, 1,
5883-
[Define to 1 if you must link with -lrt for shm_open().])
5884-
fi
5885-
AC_CHECK_HEADERS(sys/mman.h)
5886-
# temporarily override ac_includes_default for AC_CHECK_FUNCS below
5887-
ac_includes_default="\
5888-
${ac_includes_default}
5889-
#ifndef __cplusplus
5890-
# ifdef HAVE_SYS_MMAN_H
5891-
# include <sys/mman.h>
5892-
# endif
5893-
#endif
5894-
"
5895-
AC_CHECK_FUNCS([shm_open shm_unlink])
5896-
# we don't want to link with librt always, restore LIBS
5897-
LIBS="$save_LIBS"
5898-
ac_includes_default="$save_includes_default"
5878+
POSIXSHMEM_CFLAGS='-I$(srcdir)/Modules/_multiprocessing'
5879+
WITH_SAVE_ENV([
5880+
AC_SEARCH_LIBS([shm_open], [rt])
5881+
AS_VAR_IF([ac_cv_search_shm_open], [-lrt], [POSIXSHMEM_LIBS="-lrt"])
5882+
5883+
dnl Temporarily override ac_includes_default for AC_CHECK_FUNCS below.
5884+
_SAVE_VAR([ac_includes_default])
5885+
ac_includes_default="\
5886+
${ac_includes_default}
5887+
#ifndef __cplusplus
5888+
# ifdef HAVE_SYS_MMAN_H
5889+
# include <sys/mman.h>
5890+
# endif
5891+
#endif
5892+
"
5893+
AC_CHECK_FUNCS([shm_open shm_unlink], [have_posix_shmem=yes], [have_posix_shmem=no])
5894+
_RESTORE_VAR([ac_includes_default])
5895+
])
58995896

59005897
# Check for usable OpenSSL
59015898
AX_CHECK_OPENSSL([have_openssl=yes],[have_openssl=no])
@@ -6251,6 +6248,9 @@ PY_STDLIB_MOD([fcntl],
62516248
[], [$FCNTL_LIBS])
62526249
PY_STDLIB_MOD([mmap],
62536250
[], [test "$ac_cv_header_sys_mman_h" = "yes" -a "$ac_cv_header_sys_stat_h" = "yes"])
6251+
PY_STDLIB_MOD([_posixshmem],
6252+
[], [test "$have_posix_shmem" = "yes"],
6253+
[$POSIXSHMEM_CFLAGS], [$POSIXSHMEM_LIBS])
62546254

62556255
dnl platform specific extensions
62566256
PY_STDLIB_MOD([grp], [], [test "$ac_cv_func_getgrgid" = yes -o "$ac_cv_func_getgrgid_r" = yes])

pyconfig.h.in

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1469,9 +1469,6 @@
14691469
/* Define if setpgrp() must be called as setpgrp(0, 0). */
14701470
#undef SETPGRP_HAVE_ARG
14711471

1472-
/* Define to 1 if you must link with -lrt for shm_open(). */
1473-
#undef SHM_NEEDS_LIBRT
1474-
14751472
/* Define if i>>j for signed int i does not extend the sign bit when i < 0 */
14761473
#undef SIGNED_RIGHT_SHIFT_ZERO_FILLS
14771474

setup.py

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1397,20 +1397,7 @@ def detect_multiprocessing(self):
13971397
self.add(Extension('_multiprocessing', multiprocessing_srcs,
13981398
include_dirs=["Modules/_multiprocessing"]))
13991399

1400-
if (not MS_WINDOWS and
1401-
sysconfig.get_config_var('HAVE_SHM_OPEN') and
1402-
sysconfig.get_config_var('HAVE_SHM_UNLINK')):
1403-
posixshmem_srcs = ['_multiprocessing/posixshmem.c']
1404-
libs = []
1405-
if sysconfig.get_config_var('SHM_NEEDS_LIBRT'):
1406-
# need to link with librt to get shm_open()
1407-
libs.append('rt')
1408-
self.add(Extension('_posixshmem', posixshmem_srcs,
1409-
define_macros={},
1410-
libraries=libs,
1411-
include_dirs=["Modules/_multiprocessing"]))
1412-
else:
1413-
self.missing.append('_posixshmem')
1400+
self.addext(Extension('_posixshmem', ['_multiprocessing/posixshmem.c']))
14141401

14151402
def detect_uuid(self):
14161403
# Build the _uuid module if possible

0 commit comments

Comments
 (0)