X Tutup
Skip to content

Commit 5741c45

Browse files
authored
bpo-35903: Use autoconfig to probe for shm_open() and shm_unlink(). (#11765)
Use autoconfig to probe for shm_open() and shm_unlink(). Set SHM_NEEDS_LIBRT if we must link with librt to get the shm_* functions. Change setup.py to use the autoconfig defines. These changes should make it more likely that _multiprocessing/posixshmem.c gets built correctly on different platforms.
1 parent 64360ad commit 5741c45

File tree

4 files changed

+142
-3
lines changed

4 files changed

+142
-3
lines changed

configure

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16862,6 +16862,108 @@ $as_echo "#define HAVE_GETRANDOM 1" >>confdefs.h
1686216862

1686316863
fi
1686416864

16865+
# checks for POSIX shared memory, used by Modules/_multiprocessing/posixshmem.c
16866+
# shm_* may only be available if linking against librt
16867+
save_LIBS="$LIBS"
16868+
save_includes_default="$ac_includes_default"
16869+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing shm_open" >&5
16870+
$as_echo_n "checking for library containing shm_open... " >&6; }
16871+
if ${ac_cv_search_shm_open+:} false; then :
16872+
$as_echo_n "(cached) " >&6
16873+
else
16874+
ac_func_search_save_LIBS=$LIBS
16875+
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
16876+
/* end confdefs.h. */
16877+
16878+
/* Override any GCC internal prototype to avoid an error.
16879+
Use char because int might match the return type of a GCC
16880+
builtin and then its argument prototype would still apply. */
16881+
#ifdef __cplusplus
16882+
extern "C"
16883+
#endif
16884+
char shm_open ();
16885+
int
16886+
main ()
16887+
{
16888+
return shm_open ();
16889+
;
16890+
return 0;
16891+
}
16892+
_ACEOF
16893+
for ac_lib in '' rt; do
16894+
if test -z "$ac_lib"; then
16895+
ac_res="none required"
16896+
else
16897+
ac_res=-l$ac_lib
16898+
LIBS="-l$ac_lib $ac_func_search_save_LIBS"
16899+
fi
16900+
if ac_fn_c_try_link "$LINENO"; then :
16901+
ac_cv_search_shm_open=$ac_res
16902+
fi
16903+
rm -f core conftest.err conftest.$ac_objext \
16904+
conftest$ac_exeext
16905+
if ${ac_cv_search_shm_open+:} false; then :
16906+
break
16907+
fi
16908+
done
16909+
if ${ac_cv_search_shm_open+:} false; then :
16910+
16911+
else
16912+
ac_cv_search_shm_open=no
16913+
fi
16914+
rm conftest.$ac_ext
16915+
LIBS=$ac_func_search_save_LIBS
16916+
fi
16917+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_search_shm_open" >&5
16918+
$as_echo "$ac_cv_search_shm_open" >&6; }
16919+
ac_res=$ac_cv_search_shm_open
16920+
if test "$ac_res" != no; then :
16921+
test "$ac_res" = "none required" || LIBS="$ac_res $LIBS"
16922+
16923+
fi
16924+
16925+
if test "$ac_cv_search_shm_open" = "-lrt"; then
16926+
16927+
$as_echo "#define SHM_NEEDS_LIBRT 1" >>confdefs.h
16928+
16929+
fi
16930+
for ac_header in sys/mman.h
16931+
do :
16932+
ac_fn_c_check_header_mongrel "$LINENO" "sys/mman.h" "ac_cv_header_sys_mman_h" "$ac_includes_default"
16933+
if test "x$ac_cv_header_sys_mman_h" = xyes; then :
16934+
cat >>confdefs.h <<_ACEOF
16935+
#define HAVE_SYS_MMAN_H 1
16936+
_ACEOF
16937+
16938+
fi
16939+
16940+
done
16941+
16942+
# temporarily override ac_includes_default for AC_CHECK_FUNCS below
16943+
ac_includes_default="\
16944+
${ac_includes_default}
16945+
#ifndef __cplusplus
16946+
# ifdef HAVE_SYS_MMAN_H
16947+
# include <sys/mman.h>
16948+
# endif
16949+
#endif
16950+
"
16951+
for ac_func in shm_open shm_unlink
16952+
do :
16953+
as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
16954+
ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"
16955+
if eval test \"x\$"$as_ac_var"\" = x"yes"; then :
16956+
cat >>confdefs.h <<_ACEOF
16957+
#define `$as_echo "HAVE_$ac_func" | $as_tr_cpp` 1
16958+
_ACEOF
16959+
16960+
fi
16961+
done
16962+
16963+
# we don't want to link with librt always, restore LIBS
16964+
LIBS="$save_LIBS"
16965+
ac_includes_default="$save_includes_default"
16966+
1686516967
# Check for usable OpenSSL
1686616968

1686716969
found=false

configure.ac

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5443,6 +5443,30 @@ if test "$have_getrandom" = yes; then
54435443
[Define to 1 if the getrandom() function is available])
54445444
fi
54455445

5446+
# checks for POSIX shared memory, used by Modules/_multiprocessing/posixshmem.c
5447+
# shm_* may only be available if linking against librt
5448+
save_LIBS="$LIBS"
5449+
save_includes_default="$ac_includes_default"
5450+
AC_SEARCH_LIBS(shm_open, rt)
5451+
if test "$ac_cv_search_shm_open" = "-lrt"; then
5452+
AC_DEFINE(SHM_NEEDS_LIBRT, 1,
5453+
[Define to 1 if you must link with -lrt for shm_open().])
5454+
fi
5455+
AC_CHECK_HEADERS(sys/mman.h)
5456+
# temporarily override ac_includes_default for AC_CHECK_FUNCS below
5457+
ac_includes_default="\
5458+
${ac_includes_default}
5459+
#ifndef __cplusplus
5460+
# ifdef HAVE_SYS_MMAN_H
5461+
# include <sys/mman.h>
5462+
# endif
5463+
#endif
5464+
"
5465+
AC_CHECK_FUNCS([shm_open shm_unlink])
5466+
# we don't want to link with librt always, restore LIBS
5467+
LIBS="$save_LIBS"
5468+
ac_includes_default="$save_includes_default"
5469+
54465470
# Check for usable OpenSSL
54475471
AX_CHECK_OPENSSL([have_openssl=yes],[have_openssl=no])
54485472

pyconfig.h.in

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,18 @@
144144
/* Define to 1 if you have the `copysign' function. */
145145
#undef HAVE_COPYSIGN
146146

147+
/* Define to 1 if you must link with -lrt for shm_open(). */
148+
#undef SHM_NEEDS_LIBRT
149+
150+
/* Define to 1 if you have the <sys/mman.h> header file. */
151+
#undef HAVE_SYS_MMAN_H
152+
153+
/* Define to 1 if you have the shm_open syscall */
154+
#undef HAVE_SHM_OPEN
155+
156+
/* Define to 1 if you have the shm_unlink syscall */
157+
#undef HAVE_SHM_UNLINK
158+
147159
/* Define to 1 if you have the <crypt.h> header file. */
148160
#undef HAVE_CRYPT_H
149161

setup.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1592,12 +1592,13 @@ class db_found(Exception): pass
15921592
if (sysconfig.get_config_var('HAVE_SEM_OPEN') and not
15931593
sysconfig.get_config_var('POSIX_SEMAPHORES_NOT_ENABLED')):
15941594
multiprocessing_srcs.append('_multiprocessing/semaphore.c')
1595-
if (self.compiler.find_library_file(lib_dirs, 'rt') or
1596-
host_platform != 'cygwin'):
1595+
if (sysconfig.get_config_var('HAVE_SHM_OPEN') and
1596+
sysconfig.get_config_var('HAVE_SHM_UNLINK')):
15971597
posixshmem_srcs = [ '_multiprocessing/posixshmem.c',
15981598
]
15991599
libs = []
1600-
if self.compiler.find_library_file(lib_dirs, 'rt'):
1600+
if sysconfig.get_config_var('SHM_NEEDS_LIBRT'):
1601+
# need to link with librt to get shm_open()
16011602
libs.append('rt')
16021603
exts.append( Extension('_posixshmem', posixshmem_srcs,
16031604
define_macros={},

0 commit comments

Comments
 (0)
X Tutup