Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bpo-45847: Port _posixshmem to PY_STDLIB_MOD (GH-29738) #29738

Merged
merged 3 commits into from
Nov 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Modules/Setup.stdlib.in
Original file line number Diff line number Diff line change
Expand Up @@ -122,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
Expand Down
105 changes: 73 additions & 32 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -20030,9 +20032,14 @@ 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
POSIXSHMEM_CFLAGS='-I$(srcdir)/Modules/_multiprocessing'
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
Expand Down Expand Up @@ -20088,47 +20095,41 @@ 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 <sys/mman.h>
# 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 <sys/mman.h>
# 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"
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

Expand Down Expand Up @@ -21072,6 +21073,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_CFLAGS=$POSIXSHMEM_CFLAGS$as_nl"
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; }
Expand Down Expand Up @@ -22621,6 +22658,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
Expand Down
42 changes: 21 additions & 21 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -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 <sys/mman.h>
# 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 <sys/mman.h>
# 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])
Expand Down Expand Up @@ -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"],
erlend-aasland marked this conversation as resolved.
Show resolved Hide resolved
[$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])
Expand Down
3 changes: 0 additions & 3 deletions pyconfig.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
15 changes: 1 addition & 14 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down