[Zope-Checkins] CVS: Zope/lib/python/RestrictedPython - MutatingWalker.py:1.5.74.1 RCompile_2_1.py:1.2.76.1

Shane Hathaway shane@cvs.zope.org
Thu, 8 Aug 2002 14:49:55 -0400


Update of /cvs-repository/Zope/lib/python/RestrictedPython
In directory cvs.zope.org:/tmp/cvs-serv20389

Modified Files:
      Tag: shane-leaks-repair-branch
	MutatingWalker.py RCompile_2_1.py 
Log Message:
With much help from Cyclops, removed all the cyclic references in the compiler
package that can be discovered by the unit tests.  Used weak references in most
places, _break_cr() methods in other places, and even a "tuple lookalike" in
one place.

There may be other cycles, but they aren't likely to be so frequent.

Note that this corrects only the Python 2.1 version of the compiler.
Python 2.2's compiler will have to be fixed independently.


=== Zope/lib/python/RestrictedPython/MutatingWalker.py 1.5 => 1.5.74.1 ===
--- Zope/lib/python/RestrictedPython/MutatingWalker.py:1.5	Fri Dec 21 14:34:47 2001
+++ Zope/lib/python/RestrictedPython/MutatingWalker.py	Thu Aug  8 14:49:25 2002
@@ -70,6 +70,14 @@
             self._cache[klass] = meth
         return meth(node, self)
 
+    def _break_cr(self):
+        # Break circular references for faster garbage collection
+        del self.visitor
+        del self._cache
+
 def walk(tree, visitor):
-    return MutatingWalker(visitor).dispatchNode(tree)
+    w = MutatingWalker(visitor)
+    res = w.dispatchNode(tree)
+    w._break_cr()
+    return res
 


=== Zope/lib/python/RestrictedPython/RCompile_2_1.py 1.2 => 1.2.76.1 ===
--- Zope/lib/python/RestrictedPython/RCompile_2_1.py:1.2	Fri Dec 21 14:34:47 2001
+++ Zope/lib/python/RestrictedPython/RCompile_2_1.py	Thu Aug  8 14:49:25 2002
@@ -30,12 +30,15 @@
 from compiler_2_1.transformer import Transformer
 
 def tryParsing(source, mode):
+    t = Transformer()
     if mode == 'eval':
-        parser = Transformer().parseexpr
+        parser = t.parseexpr
     else:
-        parser = Transformer().parsesuite
+        parser = t.parsesuite
     try:
-        return parser(source), None
+        res = parser(source), None
+        t._break_cr()
+        return res
     except ParserError:
         return None, getSyntaxError(source, mode)