[pypy-svn] r46699 - pypy/dist/pypy/interpreter

arigo at codespeak.net arigo at codespeak.net
Mon Sep 17 18:31:00 CEST 2007


Author: arigo
Date: Mon Sep 17 18:30:59 2007
New Revision: 46699

Modified:
   pypy/dist/pypy/interpreter/baseobjspace.py
Log:
Avoid importing pypy.module.thread if unnecessary
(the import crashes on non-Linux platforms).


Modified: pypy/dist/pypy/interpreter/baseobjspace.py
==============================================================================
--- pypy/dist/pypy/interpreter/baseobjspace.py	(original)
+++ pypy/dist/pypy/interpreter/baseobjspace.py	Mon Sep 17 18:30:59 2007
@@ -438,15 +438,20 @@
         """Return an interp-level Lock object if threads are enabled,
         and a dummy object if they are not."""
         if self.config.objspace.usemodules.thread:
-            from pypy.module.thread.ll_thread import allocate_lock, error
-            try:
-                return allocate_lock()
-            except error:
-                raise OperationError(self.w_RuntimeError,
-                                     self.wrap("out of resources"))
+            # we use a sub-function to avoid putting the 'import' statement
+            # here, where the flow space would see it even if thread=False
+            return self.__allocate_lock()
         else:
             return dummy_lock
 
+    def __allocate_lock(self):
+        from pypy.module.thread.ll_thread import allocate_lock, error
+        try:
+            return allocate_lock()
+        except error:
+            raise OperationError(self.w_RuntimeError,
+                                 self.wrap("out of resources"))
+
     # Following is a friendly interface to common object space operations
     # that can be defined in term of more primitive ones.  Subclasses
     # may also override specific functions for performance.



More information about the Pypy-commit mailing list