From 355b1264b80506dddb536dc338ed91e061032309 Mon Sep 17 00:00:00 2001 From: Jesse Noller Date: Thu, 2 Apr 2009 00:03:28 +0000 Subject: issue5545: Switch to Autoconf for multiprocessing; special thanks to Martin Lowis for help --- Modules/_multiprocessing/multiprocessing.c | 8 ++- Modules/_multiprocessing/multiprocessing.h | 2 +- Modules/_multiprocessing/semaphore.c | 10 ++-- configure | 89 +++++++++++++++++++++++++++++- configure.in | 30 +++++++++- pyconfig.h.in | 15 +++++ setup.py | 42 +++----------- 7 files changed, 151 insertions(+), 45 deletions(-) diff --git a/Modules/_multiprocessing/multiprocessing.c b/Modules/_multiprocessing/multiprocessing.c index 48049c7..9008f31 100644 --- a/Modules/_multiprocessing/multiprocessing.c +++ b/Modules/_multiprocessing/multiprocessing.c @@ -8,6 +8,12 @@ #include "multiprocessing.h" +#ifdef SCM_RIGHTS + #define HAVE_FD_TRANSFER 1 +#else + #define HAVE_FD_TRANSFER 0 +#endif + PyObject *create_win32_namespace(void); PyObject *pickle_dumps, *pickle_loads, *pickle_protocol; @@ -244,7 +250,7 @@ init_multiprocessing(void) Py_INCREF(&ConnectionType); PyModule_AddObject(module, "Connection", (PyObject*)&ConnectionType); -#if defined(MS_WINDOWS) || HAVE_SEM_OPEN +#if defined(MS_WINDOWS) || defined(HAVE_SEM_OPEN) /* Add SemLock type to module */ if (PyType_Ready(&SemLockType) < 0) return; diff --git a/Modules/_multiprocessing/multiprocessing.h b/Modules/_multiprocessing/multiprocessing.h index 4f4f9d7..f6ab994 100644 --- a/Modules/_multiprocessing/multiprocessing.h +++ b/Modules/_multiprocessing/multiprocessing.h @@ -27,7 +27,7 @@ # include # include # include /* htonl() and ntohl() */ -# if HAVE_SEM_OPEN +# ifdef HAVE_SEM_OPEN # include typedef sem_t *SEM_HANDLE; # endif diff --git a/Modules/_multiprocessing/semaphore.c b/Modules/_multiprocessing/semaphore.c index 2c2fb10..d282b77 100644 --- a/Modules/_multiprocessing/semaphore.c +++ b/Modules/_multiprocessing/semaphore.c @@ -197,11 +197,11 @@ semlock_release(SemLockObject *self, PyObject *args) #define SEM_GETVALUE(sem, pval) sem_getvalue(sem, pval) #define SEM_UNLINK(name) sem_unlink(name) -#if HAVE_BROKEN_SEM_UNLINK +#ifndef HAVE_SEM_UNLINK # define sem_unlink(name) 0 #endif -#if !HAVE_SEM_TIMEDWAIT +#ifndef HAVE_SEM_TIMEDWAIT # define sem_timedwait(sem,deadline) sem_timedwait_save(sem,deadline,_save) int @@ -348,7 +348,7 @@ semlock_release(SemLockObject *self, PyObject *args) } assert(self->count == 1); } else { -#if HAVE_BROKEN_SEM_GETVALUE +#ifdef HAVE_BROKEN_SEM_GETVALUE /* We will only check properly the maxvalue == 1 case */ if (self->maxvalue == 1) { /* make sure that already locked */ @@ -494,7 +494,7 @@ semlock_ismine(SemLockObject *self) static PyObject * semlock_getvalue(SemLockObject *self) { -#if HAVE_BROKEN_SEM_GETVALUE +#ifdef HAVE_BROKEN_SEM_GETVALUE PyErr_SetNone(PyExc_NotImplementedError); return NULL; #else @@ -512,7 +512,7 @@ semlock_getvalue(SemLockObject *self) static PyObject * semlock_iszero(SemLockObject *self) { -#if HAVE_BROKEN_SEM_GETVALUE +#ifdef HAVE_BROKEN_SEM_GETVALUE if (sem_trywait(self->handle) < 0) { if (errno == EAGAIN) Py_RETURN_TRUE; diff --git a/configure b/configure index 82542b3..17b932d 100755 --- a/configure +++ b/configure @@ -1,5 +1,5 @@ #! /bin/sh -# From configure.in Revision: 70730 . +# From configure.in Revision: 70903 . # Guess values for system-dependent variables and create Makefiles. # Generated by GNU Autoconf 2.61 for python 2.7. # @@ -16570,6 +16570,10 @@ echo "${ECHO_T}MACHDEP_OBJS" >&6; } + + + + for ac_func in alarm setitimer getitimer bind_textdomain_codeset chown \ clock confstr ctermid execv fchmod fchown fork fpathconf ftime ftruncate \ gai_strerror getgroups getlogin getloadavg getpeername getpgid getpid \ @@ -16577,7 +16581,8 @@ for ac_func in alarm setitimer getitimer bind_textdomain_codeset chown \ kill killpg lchmod lchown lstat mkfifo mknod mktime \ mremap nice pathconf pause plock poll pthread_init \ putenv readlink realpath \ - select setegid seteuid setgid \ + select sem_open sem_timedwait sem_getvalue sem_unlink setegid seteuid \ + setgid \ setlocale setregid setreuid setsid setpgid setpgrp setuid setvbuf snprintf \ sigaction siginterrupt sigrelse strftime \ sysconf tcgetpgrp tcsetpgrp tempnam timegm times tmpfile tmpnam tmpnam_r \ @@ -21999,6 +22004,86 @@ _ACEOF fi +# Multiprocessing check for broken sem_getvalue +{ echo "$as_me:$LINENO: checking for broken sem_getvalue" >&5 +echo $ECHO_N "checking for broken sem_getvalue... $ECHO_C" >&6; } +if test "$cross_compiling" = yes; then + { { echo "$as_me:$LINENO: error: cannot run test program while cross compiling +See \`config.log' for more details." >&5 +echo "$as_me: error: cannot run test program while cross compiling +See \`config.log' for more details." >&2;} + { (exit 1); exit 1; }; } +else + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + +#include +#include +#include +#include +#include + +int main(void){ + sem_t *a = sem_open("/autoconf", O_CREAT, S_IRUSR|S_IWUSR, 0); + int count; + int res; + if(a==SEM_FAILED){ + perror("sem_open"); + return 1; + + } + res = sem_getvalue(a, &count); + sem_close(a); + return res==-1 ? 1 : 0; +} + + +_ACEOF +rm -f conftest$ac_exeext +if { (ac_try="$ac_link" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_link") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && { ac_try='./conftest$ac_exeext' + { (case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + { echo "$as_me:$LINENO: result: no" >&5 +echo "${ECHO_T}no" >&6; } +else + echo "$as_me: program exited with status $ac_status" >&5 +echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + +( exit $ac_status ) +{ echo "$as_me:$LINENO: result: yes" >&5 +echo "${ECHO_T}yes" >&6; } + +cat >>confdefs.h <<\_ACEOF +#define HAVE_BROKEN_SEM_GETVALUE 1 +_ACEOF + + +fi +rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext +fi + + # On FreeBSD 6.2, it appears that tanh(-0.) returns 0. instead of # -0. on some architectures. diff --git a/configure.in b/configure.in index 69ae036..5505dfb 100644 --- a/configure.in +++ b/configure.in @@ -2474,7 +2474,8 @@ AC_CHECK_FUNCS(alarm setitimer getitimer bind_textdomain_codeset chown \ kill killpg lchmod lchown lstat mkfifo mknod mktime \ mremap nice pathconf pause plock poll pthread_init \ putenv readlink realpath \ - select setegid seteuid setgid \ + select sem_open sem_timedwait sem_getvalue sem_unlink setegid seteuid \ + setgid \ setlocale setregid setreuid setsid setpgid setpgrp setuid setvbuf snprintf \ sigaction siginterrupt sigrelse strftime \ sysconf tcgetpgrp tcsetpgrp tempnam timegm times tmpfile tmpnam tmpnam_r \ @@ -3195,6 +3196,33 @@ then [Define if arithmetic is subject to x87-style double rounding issue]) fi +# Multiprocessing check for broken sem_getvalue +AC_MSG_CHECKING(for broken sem_getvalue) +AC_TRY_RUN([ +#include +#include +#include +#include +#include + +int main(void){ + sem_t *a = sem_open("/autoconf", O_CREAT, S_IRUSR|S_IWUSR, 0); + int count; + int res; + if(a==SEM_FAILED){ + perror("sem_open"); + return 1; + + } + res = sem_getvalue(a, &count); + sem_close(a); + return res==-1 ? 1 : 0; +} +] +,AC_MSG_RESULT(no), + AC_MSG_RESULT(yes) + AC_DEFINE(HAVE_BROKEN_SEM_GETVALUE, 1, define to 1 if your sem_getvalue is broken.) +) # On FreeBSD 6.2, it appears that tanh(-0.) returns 0. instead of # -0. on some architectures. diff --git a/pyconfig.h.in b/pyconfig.h.in index 5c51808..a7f1ab1 100644 --- a/pyconfig.h.in +++ b/pyconfig.h.in @@ -73,6 +73,9 @@ /* Define if pthread_sigmask() does not work on your system. */ #undef HAVE_BROKEN_PTHREAD_SIGMASK +/* define to 1 if your sem_getvalue is broken. */ +#undef HAVE_BROKEN_SEM_GETVALUE + /* Define this if you have the type _Bool. */ #undef HAVE_C99_BOOL @@ -504,6 +507,18 @@ /* Define to 1 if you have the `select' function. */ #undef HAVE_SELECT +/* Define to 1 if you have the `sem_getvalue' function. */ +#undef HAVE_SEM_GETVALUE + +/* Define to 1 if you have the `sem_open' function. */ +#undef HAVE_SEM_OPEN + +/* Define to 1 if you have the `sem_timedwait' function. */ +#undef HAVE_SEM_TIMEDWAIT + +/* Define to 1 if you have the `sem_unlink' function. */ +#undef HAVE_SEM_UNLINK + /* Define to 1 if you have the `setegid' function. */ #undef HAVE_SETEGID diff --git a/setup.py b/setup.py index d3b39ba..dbbbd57 100644 --- a/setup.py +++ b/setup.py @@ -1245,56 +1245,29 @@ class PyBuildExt(build_ext): libraries = ['ws2_32'] elif platform == 'darwin': # Mac OSX - macros = dict( - HAVE_SEM_OPEN=1, - HAVE_SEM_TIMEDWAIT=0, - HAVE_FD_TRANSFER=1, - HAVE_BROKEN_SEM_GETVALUE=1 - ) + macros = dict() libraries = [] elif platform == 'cygwin': # Cygwin - macros = dict( - HAVE_SEM_OPEN=1, - HAVE_SEM_TIMEDWAIT=1, - HAVE_FD_TRANSFER=0, - HAVE_BROKEN_SEM_UNLINK=1 - ) + macros = dict() libraries = [] elif platform in ('freebsd4', 'freebsd5', 'freebsd6', 'freebsd7', 'freebsd8'): # FreeBSD's P1003.1b semaphore support is very experimental # and has many known problems. (as of June 2008) - macros = dict( # FreeBSD - HAVE_SEM_OPEN=0, - HAVE_SEM_TIMEDWAIT=0, - HAVE_FD_TRANSFER=1, - ) + macros = dict() libraries = [] elif platform.startswith('openbsd'): - macros = dict( # OpenBSD - HAVE_SEM_OPEN=0, # Not implemented - HAVE_SEM_TIMEDWAIT=0, - HAVE_FD_TRANSFER=1, - ) + macros = dict() libraries = [] elif platform.startswith('netbsd'): - macros = dict( # at least NetBSD 5 - HAVE_SEM_OPEN=1, - HAVE_SEM_TIMEDWAIT=0, - HAVE_FD_TRANSFER=1, - HAVE_BROKEN_SEM_GETVALUE=1 - ) + macros = dict() libraries = [] else: # Linux and other unices - macros = dict( - HAVE_SEM_OPEN=1, - HAVE_SEM_TIMEDWAIT=1, - HAVE_FD_TRANSFER=1 - ) + macros = dict() libraries = ['rt'] if platform == 'win32': @@ -1309,8 +1282,7 @@ class PyBuildExt(build_ext): multiprocessing_srcs = [ '_multiprocessing/multiprocessing.c', '_multiprocessing/socket_connection.c' ] - - if macros.get('HAVE_SEM_OPEN', False): + if sysconfig.get_config_var('HAVE_SEM_OPEN'): multiprocessing_srcs.append('_multiprocessing/semaphore.c') if sysconfig.get_config_var('WITH_THREAD'): -- cgit v0.12