Merged revisions 76566 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k

................
  r76566 | mark.dickinson | 2009-11-28 12:48:43 +0000 (Sat, 28 Nov 2009) | 18 lines

  Merged revisions 76432,76558 via svnmerge from
  svn+ssh://pythondev@svn.python.org/python/trunk

  ........
    r76432 | mark.dickinson | 2009-11-20 19:30:22 +0000 (Fri, 20 Nov 2009) | 5 lines

    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.
  ........
    r76558 | mark.dickinson | 2009-11-28 10:44:20 +0000 (Sat, 28 Nov 2009) | 4 lines

    Issue #7272, continued:  don't re-use existing HAVE_BROKEN_POSIX_SEMAPHORES
    to indicate that semaphores aren't available;  define a new variable
    POSIX_SEMAPHORES_NOT_ENABLED instead.
  ........
................
diff --git a/Modules/_multiprocessing/multiprocessing.c b/Modules/_multiprocessing/multiprocessing.c
index afa2599..b09fb25 100644
--- a/Modules/_multiprocessing/multiprocessing.c
+++ b/Modules/_multiprocessing/multiprocessing.c
@@ -263,7 +263,8 @@
 	Py_INCREF(&ConnectionType);	
 	PyModule_AddObject(module, "Connection", (PyObject*)&ConnectionType);
 
-#if defined(MS_WINDOWS) || defined(HAVE_SEM_OPEN)
+#if defined(MS_WINDOWS) ||						\
+  (defined(HAVE_SEM_OPEN) && !defined(POSIX_SEMAPHORES_NOT_ENABLED))
 	/* Add SemLock type to module */
 	if (PyType_Ready(&SemLockType) < 0)
 		return NULL;
@@ -311,7 +312,7 @@
 		Py_DECREF(temp); Py_DECREF(value); return NULL; }	  \
 	Py_DECREF(value)
 	
-#ifdef HAVE_SEM_OPEN
+#if defined(HAVE_SEM_OPEN) && !defined(POSIX_SEMAPHORES_NOT_ENABLED)
 	ADD_FLAG(HAVE_SEM_OPEN);
 #endif
 #ifdef HAVE_SEM_TIMEDWAIT
diff --git a/Modules/_multiprocessing/multiprocessing.h b/Modules/_multiprocessing/multiprocessing.h
index 7a79d6e..3dd0199 100644
--- a/Modules/_multiprocessing/multiprocessing.h
+++ b/Modules/_multiprocessing/multiprocessing.h
@@ -27,7 +27,7 @@
 #  include <sys/socket.h>
 #  include <sys/uio.h>
 #  include <arpa/inet.h>             /* htonl() and ntohl() */
-#  ifdef HAVE_SEM_OPEN
+#  if defined(HAVE_SEM_OPEN) && !defined(POSIX_SEMAPHORES_NOT_ENABLED)
 #    include <semaphore.h>
      typedef sem_t *SEM_HANDLE;
 #  endif
diff --git a/configure b/configure
index 5079e84..a07d519 100755
--- a/configure
+++ b/configure
@@ -1,5 +1,5 @@
 #! /bin/sh
-# From configure.in Revision: 75727 .
+# From configure.in Revision: 76406 .
 # Guess values for system-dependent variables and create Makefiles.
 # Generated by GNU Autoconf 2.61 for python 3.1.
 #
@@ -3802,7 +3802,7 @@
   { echo "$as_me:$LINENO: result: no" >&5
 echo "${ECHO_T}no" >&6; }
 fi
-rm -f -r conftest*
+rm -f conftest*
 
 
 
@@ -5350,7 +5350,7 @@
 else
   ac_cv_header_stdc=no
 fi
-rm -f -r conftest*
+rm -f conftest*
 
 fi
 
@@ -5371,7 +5371,7 @@
 else
   ac_cv_header_stdc=no
 fi
-rm -f -r conftest*
+rm -f conftest*
 
 fi
 
@@ -6469,7 +6469,7 @@
 
 
 fi
-rm -f -r conftest*
+rm -f conftest*
 
 { echo "$as_me:$LINENO: result: $was_it_defined" >&5
 echo "${ECHO_T}$was_it_defined" >&6; }
@@ -6999,7 +6999,7 @@
 else
   ac_cv_type_uid_t=no
 fi
-rm -f -r conftest*
+rm -f conftest*
 
 fi
 { echo "$as_me:$LINENO: result: $ac_cv_type_uid_t" >&5
@@ -14409,7 +14409,7 @@
 else
   unistd_defines_pthreads=no
 fi
-rm -f -r conftest*
+rm -f conftest*
 
     { echo "$as_me:$LINENO: result: $unistd_defines_pthreads" >&5
 echo "${ECHO_T}$unistd_defines_pthreads" >&6; }
@@ -15877,7 +15877,7 @@
   $EGREP "yes" >/dev/null 2>&1; then
   ipv6type=$i
 fi
-rm -f -r conftest*
+rm -f conftest*
 
 			;;
 		kame)
@@ -15900,7 +15900,7 @@
 				ipv6libdir=/usr/local/v6/lib
 				ipv6trylibc=yes
 fi
-rm -f -r conftest*
+rm -f conftest*
 
 			;;
 		linux-glibc)
@@ -15921,7 +15921,7 @@
   ipv6type=$i;
 				ipv6trylibc=yes
 fi
-rm -f -r conftest*
+rm -f conftest*
 
 			;;
 		linux-inet6)
@@ -15959,7 +15959,7 @@
 				ipv6lib=inet6;
 				ipv6libdir=/usr/local/v6/lib
 fi
-rm -f -r conftest*
+rm -f conftest*
 
 			;;
 		v6d)
@@ -15982,7 +15982,7 @@
 				ipv6libdir=/usr/local/v6/lib;
 				BASECFLAGS="-I/usr/local/v6/include $BASECFLAGS"
 fi
-rm -f -r conftest*
+rm -f conftest*
 
 			;;
 		zeta)
@@ -16004,7 +16004,7 @@
 				ipv6lib=inet6;
 				ipv6libdir=/usr/local/v6/lib
 fi
-rm -f -r conftest*
+rm -f conftest*
 
 			;;
 		esac
@@ -22531,6 +22531,90 @@
 
 LIBS=$LIBS_SAVE
 
+# For multiprocessing module, check that sem_open
+# actually works.  For FreeBSD versions <= 7.2,
+# the kernel module that provides POSIX semaphores
+# isn't loaded by default, so an attempt to call
+# sem_open results in a 'Signal 12' error.
+{ echo "$as_me:$LINENO: checking whether POSIX semaphores are enabled" >&5
+echo $ECHO_N "checking whether POSIX semaphores are enabled... $ECHO_C" >&6; }
+if test "${ac_cv_posix_semaphores_enabled+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  if test "$cross_compiling" = yes; then
+  ac_cv_posix_semaphores_enabled=yes
+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);
+  if (a == SEM_FAILED) {
+    perror("sem_open");
+    return 1;
+  }
+  sem_close(a);
+  return 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
+  ac_cv_posix_semaphores_enabled=yes
+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 )
+ac_cv_posix_semaphores_enabled=no
+fi
+rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext
+fi
+
+
+
+fi
+
+{ echo "$as_me:$LINENO: result: $ac_cv_posix_semaphores_enabled" >&5
+echo "${ECHO_T}$ac_cv_posix_semaphores_enabled" >&6; }
+if test $ac_cv_posix_semaphores_enabled = no
+then
+
+cat >>confdefs.h <<\_ACEOF
+#define POSIX_SEMAPHORES_NOT_ENABLED 1
+_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; }
@@ -23989,7 +24073,7 @@
 _ACEOF
 
 fi
-rm -f -r conftest*
+rm -f conftest*
 
   cat >conftest.$ac_ext <<_ACEOF
 /* confdefs.h.  */
@@ -24008,7 +24092,7 @@
 _ACEOF
 
 fi
-rm -f -r conftest*
+rm -f conftest*
 
 fi
 
@@ -24278,7 +24362,7 @@
 _ACEOF
 
 fi
-rm -f -r conftest*
+rm -f conftest*
 
 fi
 
diff --git a/configure.in b/configure.in
index 1d024cd..09714d5 100644
--- a/configure.in
+++ b/configure.in
@@ -3338,6 +3338,40 @@
 
 LIBS=$LIBS_SAVE
 
+# For multiprocessing module, check that sem_open
+# actually works.  For FreeBSD versions <= 7.2,
+# the kernel module that provides POSIX semaphores
+# isn't loaded by default, so an attempt to call
+# sem_open results in a 'Signal 12' error.
+AC_MSG_CHECKING(whether POSIX semaphores are enabled)
+AC_CACHE_VAL(ac_cv_posix_semaphores_enabled,
+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);
+  if (a == SEM_FAILED) {
+    perror("sem_open");
+    return 1;
+  }
+  sem_close(a);
+  return 0;
+}
+], ac_cv_posix_semaphores_enabled=yes,
+   ac_cv_posix_semaphores_enabled=no,
+   ac_cv_posix_semaphores_enabled=yes)
+)
+AC_MSG_RESULT($ac_cv_posix_semaphores_enabled)
+if test $ac_cv_posix_semaphores_enabled = no
+then
+  AC_DEFINE(POSIX_SEMAPHORES_NOT_ENABLED, 1,
+            [Define if POSIX semaphores aren't enabled on your system])
+fi
+
 # Multiprocessing check for broken sem_getvalue
 AC_MSG_CHECKING(for broken sem_getvalue)
 AC_TRY_RUN([
diff --git a/pyconfig.h.in b/pyconfig.h.in
index 5c2d3d8..f0ae92d 100644
--- a/pyconfig.h.in
+++ b/pyconfig.h.in
@@ -895,6 +895,9 @@
 /* Define to the version of this package. */
 #undef PACKAGE_VERSION
 
+/* Define if POSIX semaphores aren't enabled on your system */
+#undef POSIX_SEMAPHORES_NOT_ENABLED
+
 /* Defined if PTHREAD_SCOPE_SYSTEM supported. */
 #undef PTHREAD_SYSTEM_SCHED_SUPPORTED
 
diff --git a/setup.py b/setup.py
index f696e9f..8670766 100644
--- a/setup.py
+++ b/setup.py
@@ -1191,7 +1191,8 @@
             multiprocessing_srcs = [ '_multiprocessing/multiprocessing.c',
                                      '_multiprocessing/socket_connection.c'
                                    ]
-            if sysconfig.get_config_var('HAVE_SEM_OPEN'):
+            if (sysconfig.get_config_var('HAVE_SEM_OPEN') and not
+                sysconfig.get_config_var('POSIX_SEMAPHORES_NOT_ENABLED')):
                 multiprocessing_srcs.append('_multiprocessing/semaphore.c')
 
         if sysconfig.get_config_var('WITH_THREAD'):