Skip to content

Commit c4920e8

Browse files
committed
Issue #7272: Add configure test to detect whether sem_open works
properly, and use this to skip test_multiprocessing on platforms where sem_open raises a signal. This should fix some FreeBSD buildbot failures for test_multiprocessing.
1 parent ab44226 commit c4920e8

6 files changed

Lines changed: 127 additions & 5 deletions

File tree

‎Lib/test/test_multiprocessing.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import socket
1818
import random
1919
import logging
20-
import test_support
20+
from test import test_support
2121
from StringIO import StringIO
2222

2323

‎Modules/_multiprocessing/multiprocessing.c‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,8 @@ init_multiprocessing(void)
250250
Py_INCREF(&ConnectionType);
251251
PyModule_AddObject(module, "Connection", (PyObject*)&ConnectionType);
252252

253-
#if defined(MS_WINDOWS) || defined(HAVE_SEM_OPEN)
253+
#if defined(MS_WINDOWS) || \
254+
(defined(HAVE_SEM_OPEN) && !defined(HAVE_BROKEN_POSIX_SEMAPHORES))
254255
/* Add SemLock type to module */
255256
if (PyType_Ready(&SemLockType) < 0)
256257
return;
@@ -297,7 +298,7 @@ init_multiprocessing(void)
297298
Py_DECREF(temp); Py_DECREF(value); return; } \
298299
Py_DECREF(value)
299300

300-
#ifdef HAVE_SEM_OPEN
301+
#if defined(HAVE_SEM_OPEN) && !defined(HAVE_BROKEN_POSIX_SEMAPHORES)
301302
ADD_FLAG(HAVE_SEM_OPEN);
302303
#endif
303304
#ifdef HAVE_SEM_TIMEDWAIT

‎Modules/_multiprocessing/multiprocessing.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
# include <sys/socket.h>
2828
# include <sys/uio.h>
2929
# include <arpa/inet.h> /* htonl() and ntohl() */
30-
# ifdef HAVE_SEM_OPEN
30+
# if defined(HAVE_SEM_OPEN) && !defined(HAVE_BROKEN_POSIX_SEMAPHORES)
3131
# include <semaphore.h>
3232
typedef sem_t *SEM_HANDLE;
3333
# endif

‎configure‎

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23782,6 +23782,91 @@ fi
2378223782
LIBS_SAVE=$LIBS
2378323783
LIBS="$LIBS $LIBM"
2378423784

23785+
# For multiprocessing module, check that sem_open
23786+
# actually works. For FreeBSD versions <= 7.2,
23787+
# the kernel module that provides POSIX semaphores
23788+
# isn't loaded by default, so an attempt to call
23789+
# sem_open results in a 'Signal 12' error.
23790+
{ echo "$as_me:$LINENO: checking whether POSIX semaphores are enabled" >&5
23791+
echo $ECHO_N "checking whether POSIX semaphores are enabled... $ECHO_C" >&6; }
23792+
if test "${ac_cv_posix_semaphores_enabled+set}" = set; then
23793+
echo $ECHO_N "(cached) $ECHO_C" >&6
23794+
else
23795+
if test "$cross_compiling" = yes; then
23796+
ac_cv_posix_semaphores_enabled=yes
23797+
else
23798+
cat >conftest.$ac_ext <<_ACEOF
23799+
/* confdefs.h. */
23800+
_ACEOF
23801+
cat confdefs.h >>conftest.$ac_ext
23802+
cat >>conftest.$ac_ext <<_ACEOF
23803+
/* end confdefs.h. */
23804+
23805+
#include <unistd.h>
23806+
#include <fcntl.h>
23807+
#include <stdio.h>
23808+
#include <semaphore.h>
23809+
#include <sys/stat.h>
23810+
23811+
int main(void) {
23812+
sem_t *a = sem_open("/autoconf", O_CREAT, S_IRUSR|S_IWUSR, 0);
23813+
if (a == SEM_FAILED) {
23814+
perror("sem_open");
23815+
return 1;
23816+
}
23817+
sem_close(a);
23818+
return 0;
23819+
}
23820+
23821+
_ACEOF
23822+
rm -f conftest$ac_exeext
23823+
if { (ac_try="$ac_link"
23824+
case "(($ac_try" in
23825+
*\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
23826+
*) ac_try_echo=$ac_try;;
23827+
esac
23828+
eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
23829+
(eval "$ac_link") 2>&5
23830+
ac_status=$?
23831+
echo "$as_me:$LINENO: \$? = $ac_status" >&5
23832+
(exit $ac_status); } && { ac_try='./conftest$ac_exeext'
23833+
{ (case "(($ac_try" in
23834+
*\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
23835+
*) ac_try_echo=$ac_try;;
23836+
esac
23837+
eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
23838+
(eval "$ac_try") 2>&5
23839+
ac_status=$?
23840+
echo "$as_me:$LINENO: \$? = $ac_status" >&5
23841+
(exit $ac_status); }; }; then
23842+
ac_cv_posix_semaphores_enabled=yes
23843+
else
23844+
echo "$as_me: program exited with status $ac_status" >&5
23845+
echo "$as_me: failed program was:" >&5
23846+
sed 's/^/| /' conftest.$ac_ext >&5
23847+
23848+
( exit $ac_status )
23849+
ac_cv_posix_semaphores_enabled=no
23850+
fi
23851+
rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext
23852+
fi
23853+
23854+
23855+
23856+
fi
23857+
23858+
{ echo "$as_me:$LINENO: result: $ac_cv_posix_semaphores_enabled" >&5
23859+
echo "${ECHO_T}$ac_cv_posix_semaphores_enabled" >&6; }
23860+
if test $ac_cv_posix_semaphores_enabled = no
23861+
then
23862+
23863+
cat >>confdefs.h <<\_ACEOF
23864+
#define HAVE_BROKEN_POSIX_SEMAPHORES 1
23865+
_ACEOF
23866+
23867+
fi
23868+
23869+
2378523870
# Multiprocessing check for broken sem_getvalue
2378623871
{ echo "$as_me:$LINENO: checking for broken sem_getvalue" >&5
2378723872
echo $ECHO_N "checking for broken sem_getvalue... $ECHO_C" >&6; }

‎configure.in‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3387,6 +3387,41 @@ fi
33873387
LIBS_SAVE=$LIBS
33883388
LIBS="$LIBS $LIBM"
33893389

3390+
# For multiprocessing module, check that sem_open
3391+
# actually works. For FreeBSD versions <= 7.2,
3392+
# the kernel module that provides POSIX semaphores
3393+
# isn't loaded by default, so an attempt to call
3394+
# sem_open results in a 'Signal 12' error.
3395+
AC_MSG_CHECKING(whether POSIX semaphores are enabled)
3396+
AC_CACHE_VAL(ac_cv_posix_semaphores_enabled,
3397+
AC_TRY_RUN([
3398+
#include <unistd.h>
3399+
#include <fcntl.h>
3400+
#include <stdio.h>
3401+
#include <semaphore.h>
3402+
#include <sys/stat.h>
3403+
3404+
int main(void) {
3405+
sem_t *a = sem_open("/autoconf", O_CREAT, S_IRUSR|S_IWUSR, 0);
3406+
if (a == SEM_FAILED) {
3407+
perror("sem_open");
3408+
return 1;
3409+
}
3410+
sem_close(a);
3411+
return 0;
3412+
}
3413+
], ac_cv_posix_semaphores_enabled=yes,
3414+
ac_cv_posix_semaphores_enabled=no,
3415+
ac_cv_posix_semaphores_enabled=yes)
3416+
)
3417+
AC_MSG_RESULT($ac_cv_posix_semaphores_enabled)
3418+
if test $ac_cv_posix_semaphores_enabled = no
3419+
then
3420+
AC_DEFINE(HAVE_BROKEN_POSIX_SEMAPHORES, 1,
3421+
[Define if the Posix semaphores do not work on your system])
3422+
fi
3423+
3424+
33903425
# Multiprocessing check for broken sem_getvalue
33913426
AC_MSG_CHECKING(for broken sem_getvalue)
33923427
AC_CACHE_VAL(ac_cv_broken_sem_getvalue,

‎setup.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1315,7 +1315,8 @@ class db_found(Exception): pass
13151315
multiprocessing_srcs = [ '_multiprocessing/multiprocessing.c',
13161316
'_multiprocessing/socket_connection.c'
13171317
]
1318-
if sysconfig.get_config_var('HAVE_SEM_OPEN'):
1318+
if (sysconfig.get_config_var('HAVE_SEM_OPEN') and not
1319+
sysconfig.get_config_var('HAVE_BROKEN_POSIX_SEMAPHORES')):
13191320
multiprocessing_srcs.append('_multiprocessing/semaphore.c')
13201321

13211322
if sysconfig.get_config_var('WITH_THREAD'):

0 commit comments

Comments
 (0)