[Python-checkins] r71009 - in python/trunk: Modules/_multiprocessing/multiprocessing.c Modules/_multiprocessing/multiprocessing.h Modules/_multiprocessing/semaphore.c configure configure.in pyconfig.h.in setup.py

jesse.noller python-checkins at python.org
Thu Apr 2 02:03:28 CEST 2009


Author: jesse.noller
Date: Thu Apr  2 02:03:28 2009
New Revision: 71009

Log:
issue5545: Switch to Autoconf for multiprocessing; special thanks to Martin Lowis for help

Modified:
   python/trunk/Modules/_multiprocessing/multiprocessing.c
   python/trunk/Modules/_multiprocessing/multiprocessing.h
   python/trunk/Modules/_multiprocessing/semaphore.c
   python/trunk/configure
   python/trunk/configure.in
   python/trunk/pyconfig.h.in
   python/trunk/setup.py

Modified: python/trunk/Modules/_multiprocessing/multiprocessing.c
==============================================================================
--- python/trunk/Modules/_multiprocessing/multiprocessing.c	(original)
+++ python/trunk/Modules/_multiprocessing/multiprocessing.c	Thu Apr  2 02:03:28 2009
@@ -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 @@
 	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;

Modified: python/trunk/Modules/_multiprocessing/multiprocessing.h
==============================================================================
--- python/trunk/Modules/_multiprocessing/multiprocessing.h	(original)
+++ python/trunk/Modules/_multiprocessing/multiprocessing.h	Thu Apr  2 02:03:28 2009
@@ -27,7 +27,7 @@
 #  include <sys/socket.h>
 #  include <sys/uio.h>
 #  include <arpa/inet.h>             /* htonl() and ntohl() */
-#  if HAVE_SEM_OPEN
+#  ifdef HAVE_SEM_OPEN
 #    include <semaphore.h>
      typedef sem_t *SEM_HANDLE;
 #  endif

Modified: python/trunk/Modules/_multiprocessing/semaphore.c
==============================================================================
--- python/trunk/Modules/_multiprocessing/semaphore.c	(original)
+++ python/trunk/Modules/_multiprocessing/semaphore.c	Thu Apr  2 02:03:28 2009
@@ -197,11 +197,11 @@
 #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 @@
 		}
 		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 @@
 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 @@
 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;

Modified: python/trunk/configure
==============================================================================
--- python/trunk/configure	(original)
+++ python/trunk/configure	Thu Apr  2 02:03:28 2009
@@ -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 @@
 
 
 
+
+
+
+
 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 @@
  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 @@
 
 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 <unistd.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <semaphore.h>
+#include <sys/stat.h>
+
+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.

Modified: python/trunk/configure.in
==============================================================================
--- python/trunk/configure.in	(original)
+++ python/trunk/configure.in	Thu Apr  2 02:03:28 2009
@@ -2474,7 +2474,8 @@
  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 @@
   [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 <unistd.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <semaphore.h>
+#include <sys/stat.h>
+
+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.

Modified: python/trunk/pyconfig.h.in
==============================================================================
--- python/trunk/pyconfig.h.in	(original)
+++ python/trunk/pyconfig.h.in	Thu Apr  2 02:03:28 2009
@@ -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
 

Modified: python/trunk/setup.py
==============================================================================
--- python/trunk/setup.py	(original)
+++ python/trunk/setup.py	Thu Apr  2 02:03:28 2009
@@ -1245,56 +1245,29 @@
             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 @@
             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'):


More information about the Python-checkins mailing list