[pypy-svn] r75605 - in pypy/branch/fast-forward/pypy/interpreter: . test
benjamin at codespeak.net
benjamin at codespeak.net
Fri Jun 25 21:40:54 CEST 2010
Author: benjamin
Date: Fri Jun 25 21:40:50 2010
New Revision: 75605
Modified:
pypy/branch/fast-forward/pypy/interpreter/nestedscope.py
pypy/branch/fast-forward/pypy/interpreter/test/test_nestedscope.py
Log:
prevent locals() from leaking outer scopes into classes
Modified: pypy/branch/fast-forward/pypy/interpreter/nestedscope.py
==============================================================================
--- pypy/branch/fast-forward/pypy/interpreter/nestedscope.py (original)
+++ pypy/branch/fast-forward/pypy/interpreter/nestedscope.py Fri Jun 25 21:40:50 2010
@@ -2,6 +2,7 @@
from pypy.interpreter import function, pycode, pyframe
from pypy.interpreter.baseobjspace import Wrappable
from pypy.interpreter.mixedmodule import MixedModule
+from pypy.interpreter.astcompiler import consts
from pypy.rlib import jit
from pypy.tool.uid import uid
@@ -122,7 +123,9 @@
super_fast2locals(self)
# cellvars are values exported to inner scopes
# freevars are values coming from outer scopes
- freevarnames = self.pycode.co_cellvars + self.pycode.co_freevars
+ freevarnames = self.pycode.co_cellvars
+ if self.pycode.co_flags & consts.CO_OPTIMIZED:
+ freevarnames.extend(self.pycode.co_freevars)
for i in range(len(freevarnames)):
name = freevarnames[i]
cell = self.cells[i]
Modified: pypy/branch/fast-forward/pypy/interpreter/test/test_nestedscope.py
==============================================================================
--- pypy/branch/fast-forward/pypy/interpreter/test/test_nestedscope.py (original)
+++ pypy/branch/fast-forward/pypy/interpreter/test/test_nestedscope.py Fri Jun 25 21:40:50 2010
@@ -79,3 +79,13 @@
g = f()
raises(ValueError, "g.func_closure[0].cell_contents")
+
+ def test_leaking_class_locals(self):
+ def f(x):
+ class X:
+ x = 12
+ def f(self):
+ return x
+ locals()
+ return X
+ assert f(1).x == 12
More information about the Pypy-commit
mailing list