[pypy-svn] r40983 - pypy/dist/pypy/tool

pedronis at codespeak.net pedronis at codespeak.net
Wed Mar 21 22:23:02 CET 2007


Author: pedronis
Date: Wed Mar 21 22:23:02 2007
New Revision: 40983

Modified:
   pypy/dist/pypy/tool/cache.py
Log:
sanity checking code that we don't end up with recursive invocation of the cache building code
for the same entry.

The problem fixed by 40961 would have exploded more cleanly and clearly with this.



Modified: pypy/dist/pypy/tool/cache.py
==============================================================================
--- pypy/dist/pypy/tool/cache.py	(original)
+++ pypy/dist/pypy/tool/cache.py	Wed Mar 21 22:23:02 2007
@@ -29,13 +29,21 @@
 class Cache(object):
     def __init__(self):
         self.content = {}
+        self._building = {}
 
     def getorbuild(self, key):
         try:
             return self.content[key]
         except KeyError:
-            result = self._build(key)
-            self.content[key] = result
+            if key in self._building:
+                raise Exception, "%s recursive building of %r" % (
+                    self, key)
+            self._building[key] = True
+            try:
+                result = self._build(key)
+                self.content[key] = result
+            finally:
+                del self._building[key]
             self._ready(result)
             return result
     getorbuild._annspecialcase_ = "specialize:memo"



More information about the Pypy-commit mailing list