[pypy-svn] r49719 - pypy/dist/pypy/objspace

arigo at codespeak.net arigo at codespeak.net
Thu Dec 13 16:03:28 CET 2007


Author: arigo
Date: Thu Dec 13 16:03:28 2007
New Revision: 49719

Modified:
   pypy/dist/pypy/objspace/trace.py
Log:
Always return the same result from getexecutioncontext().
The _file module, at least, uses that result as an identifier
for the current thread.


Modified: pypy/dist/pypy/objspace/trace.py
==============================================================================
--- pypy/dist/pypy/objspace/trace.py	(original)
+++ pypy/dist/pypy/objspace/trace.py	Thu Dec 13 16:03:28 2007
@@ -165,7 +165,7 @@
 
         def __getattribute__(self, name):
             obj = super(Trace, self).__getattribute__(name)
-            if name in ["_result", "_in_cache",
+            if name in ["_result", "_in_cache", "_ect_cache",
                         "_tracing", "_config_options"]:
                 return obj
 
@@ -189,6 +189,7 @@
 
         def settrace(self):
             self._result = TraceResult(self, **self._config_options)
+            self._ect_cache = {}
             self._tracing = True
 
         def unsettrace(self):
@@ -200,8 +201,13 @@
         def getexecutioncontext(self):
             ec = super(Trace, self).getexecutioncontext()
             if not self._in_cache:
-                assert not isinstance(ec, ExecutionContextTracer)
-                ec = ExecutionContextTracer(self._result, ec)
+                try:
+                    ect = self._ect_cache[ec]
+                except KeyError:
+                    assert not isinstance(ec, ExecutionContextTracer)
+                    ect = ExecutionContextTracer(self._result, ec)
+                    self._ect_cache[ec] = ect
+                return ect
             return ec
         
         # XXX Rename
@@ -210,7 +216,8 @@
             space.__class__ = space.__oldclass__
             del space.__oldclass__
 
-            for k in ["_result", "_in_cache", "_config_options", "_operations"]:
+            for k in ["_result", "_in_cache", "_ect_cache",
+                      "_config_options", "_operations"]:
                 if hasattr(self, k):
                     delattr(self, k)
             
@@ -221,6 +228,7 @@
     from pypy.tool.traceconfig import config
     space._tracing = False
     space._result = None
+    space._ect_cache = {}
     space._in_cache = 0
     space._config_options = config
 



More information about the Pypy-commit mailing list