[pypy-svn] pypy default: Fix HAVE_BROKEN_SEM_GETVALUE to make SemLock._get_value behave as expected on

bivab commits-noreply at bitbucket.org
Sat Jan 22 13:02:04 CET 2011


Author: David Schneider <david.schneider at picle.org>
Branch: 
Changeset: r41213:2448de42e2f3
Date: 2011-01-22 13:00 +0100
http://bitbucket.org/pypy/pypy/changeset/2448de42e2f3/

Log:	Fix HAVE_BROKEN_SEM_GETVALUE to make SemLock._get_value behave as
	expected on mac os by raising a NotImplementedError and update the
	tests correspondingly

diff --git a/pypy/module/_multiprocessing/test/test_semaphore.py b/pypy/module/_multiprocessing/test/test_semaphore.py
--- a/pypy/module/_multiprocessing/test/test_semaphore.py
+++ b/pypy/module/_multiprocessing/test/test_semaphore.py
@@ -11,6 +11,7 @@
 
     def test_semaphore(self):
         from _multiprocessing import SemLock
+        import sys
         assert SemLock.SEM_VALUE_MAX > 10
 
         kind = self.SEMAPHORE
@@ -22,12 +23,18 @@
         assert isinstance(sem.handle, (int, long))
 
         assert sem._count() == 0
-        assert sem._get_value() == 1
+        if sys.platform == 'darwin':
+            raises(NotImplementedError, 'sem._get_value()')
+        else:
+            assert sem._get_value() == 1
         assert sem._is_zero() == False
         sem.acquire()
         assert sem._is_mine()
         assert sem._count() == 1
-        assert sem._get_value() == 0
+        if sys.platform == 'darwin':
+            raises(NotImplementedError, 'sem._get_value()')
+        else:
+            assert sem._get_value() == 0
         assert sem._is_zero() == True
         sem.release()
         assert sem._count() == 0

diff --git a/pypy/module/_multiprocessing/interp_semaphore.py b/pypy/module/_multiprocessing/interp_semaphore.py
--- a/pypy/module/_multiprocessing/interp_semaphore.py
+++ b/pypy/module/_multiprocessing/interp_semaphore.py
@@ -52,6 +52,7 @@
         SEM_FAILED = platform.ConstantInteger('SEM_FAILED')
         SEM_VALUE_MAX = platform.ConstantInteger('SEM_VALUE_MAX')
         SEM_TIMED_WAIT = platform.Has('sem_timedwait')
+        SEM_GETVALUE = platform.Has('sem_getvalue')
 
     config = platform.configure(CConfig)
     TIMEVAL        = config['TIMEVAL']
@@ -62,7 +63,7 @@
     SEM_FAILED     = rffi.cast(SEM_T, config['SEM_FAILED'])
     SEM_VALUE_MAX  = config['SEM_VALUE_MAX']
     SEM_TIMED_WAIT = config['SEM_TIMED_WAIT']
-    HAVE_BROKEN_SEM_GETVALUE = False
+    HAVE_BROKEN_SEM_GETVALUE = config['SEM_GETVALUE']
 
     def external(name, args, result):
         return rffi.llexternal(name, args, result,
@@ -367,7 +368,8 @@
 
     def semlock_getvalue(self, space):
         if HAVE_BROKEN_SEM_GETVALUE:
-            raise OperationError(space.w_NotImplementedError)
+            raise OperationError(space.w_NotImplementedError, space.wrap(
+                        'sem_getvalue is not implemented on this system'))
         else:
             val = sem_getvalue(self.handle)
             # some posix implementations use negative numbers to indicate


More information about the Pypy-commit mailing list