[pypy-commit] pypy default: Sprinkle some RLocks here and there randomly, trying to avoid the

arigo noreply at buildbot.pypy.org
Mon Jan 28 15:52:24 CET 2013


Author: Armin Rigo <arigo at tunes.org>
Branch: 
Changeset: r60611:2bb610b6bf93
Date: 2013-01-28 15:52 +0100
http://bitbucket.org/pypy/pypy/changeset/2bb610b6bf93/

Log:	Sprinkle some RLocks here and there randomly, trying to avoid the
	occasional crashes in module/thread's test_interrupt_main.

diff --git a/rpython/rtyper/lltypesystem/ll2ctypes.py b/rpython/rtyper/lltypesystem/ll2ctypes.py
--- a/rpython/rtyper/lltypesystem/ll2ctypes.py
+++ b/rpython/rtyper/lltypesystem/ll2ctypes.py
@@ -32,6 +32,15 @@
 except ImportError:
     class tlsobject(object):
         pass
+try:
+    from threading import RLock
+except ImportError:
+    class RLock(object):
+        def __enter__(self):
+            pass
+        def __exit__(self, *args):
+            pass
+rlock = RLock()
 
 _POSIX = os.name == "posix"
 _MS_WINDOWS = os.name == "nt"
@@ -694,10 +703,11 @@
         return None
 
 def lltype2ctypes(llobj, normalize=True):
-    """Convert the lltype object 'llobj' to its ctypes equivalent.
-    'normalize' should only be False in tests, where we want to
-    inspect the resulting ctypes object manually.
-    """
+  """Convert the lltype object 'llobj' to its ctypes equivalent.
+  'normalize' should only be False in tests, where we want to
+  inspect the resulting ctypes object manually.
+  """
+  with rlock:
     if isinstance(llobj, lltype._uninitialized):
         return uninitialized2ctypes(llobj.TYPE)
     if isinstance(llobj, llmemory.AddressAsInt):
@@ -875,9 +885,10 @@
     return llobj
 
 def ctypes2lltype(T, cobj):
-    """Convert the ctypes object 'cobj' to its lltype equivalent.
-    'T' is the expected lltype type.
-    """
+  """Convert the ctypes object 'cobj' to its lltype equivalent.
+  'T' is the expected lltype type.
+  """
+  with rlock:
     if T is lltype.Void:
         return None
     if isinstance(T, lltype.Typedef):
@@ -1176,10 +1187,11 @@
         #self.funcptr = ...  set later
 
     def __call__(self, *argvalues):
-        if self.trampoline is None:
-            # lazily build the corresponding ctypes function object
-            cfunc = get_ctypes_callable(self.funcptr, self.calling_conv)
-            self.trampoline = get_ctypes_trampoline(self.FUNCTYPE, cfunc)
+        with rlock:
+            if self.trampoline is None:
+                # lazily build the corresponding ctypes function object
+                cfunc = get_ctypes_callable(self.funcptr, self.calling_conv)
+                self.trampoline = get_ctypes_trampoline(self.FUNCTYPE, cfunc)
         # perform the call
         return self.trampoline(*argvalues)
 
@@ -1215,8 +1227,9 @@
         return ctypes2lltype(RESULT, cres)
     return invoke_via_ctypes
 
+
 def force_cast(RESTYPE, value):
-    """Cast a value to a result type, trying to use the same rules as C."""
+  with rlock:
     if not isinstance(RESTYPE, lltype.LowLevelType):
         raise TypeError("rffi.cast() first arg should be a TYPE")
     if isinstance(value, llmemory.AddressAsInt):


More information about the pypy-commit mailing list