[pypy-svn] r62856 - in pypy/branch/speedup-globals/pypy/objspace/std: . test
cfbolz at codespeak.net
cfbolz at codespeak.net
Wed Mar 11 13:16:35 CET 2009
Author: cfbolz
Date: Wed Mar 11 13:16:33 2009
New Revision: 62856
Modified:
pypy/branch/speedup-globals/pypy/objspace/std/celldict.py
pypy/branch/speedup-globals/pypy/objspace/std/test/test_celldict.py
Log:
fix a corner-case
Modified: pypy/branch/speedup-globals/pypy/objspace/std/celldict.py
==============================================================================
--- pypy/branch/speedup-globals/pypy/objspace/std/celldict.py (original)
+++ pypy/branch/speedup-globals/pypy/objspace/std/celldict.py Wed Mar 11 13:16:33 2009
@@ -34,11 +34,14 @@
self.unshadowed_builtins[name] = builtin_impl
def invalidate_unshadowed_builtin(self, name):
- # XXX what if the builtin was deleted in the meantime?
impl = self.unshadowed_builtins[name]
- cell = impl.content[name]
- w_value = cell.invalidate()
- cell = impl.content[name] = ModuleCell(w_value)
+ try:
+ cell = impl.content[name]
+ except KeyError:
+ pass
+ else:
+ w_value = cell.invalidate()
+ cell = impl.content[name] = ModuleCell(w_value)
def setitem(self, w_key, w_value):
space = self.space
Modified: pypy/branch/speedup-globals/pypy/objspace/std/test/test_celldict.py
==============================================================================
--- pypy/branch/speedup-globals/pypy/objspace/std/test/test_celldict.py (original)
+++ pypy/branch/speedup-globals/pypy/objspace/std/test/test_celldict.py Wed Mar 11 13:16:33 2009
@@ -123,6 +123,39 @@
finally:
__builtins__.len = orig_len
+ def test_override_builtins2(self):
+ import sys, __builtin__
+ mod1 = type(sys)("abc")
+ glob1 = mod1.__dict__
+ self.impl_used(mod1.__dict__)
+ def f():
+ return l(x)
+ code = f.func_code
+ f1 = type(f)(f.func_code, glob1)
+ mod1.x = []
+ __builtin__.l = len
+ try:
+ assert not self.is_in_cache(code, glob1, "l")
+ assert not self.is_in_cache(code, glob1, "x")
+ assert f1() == 0
+ assert self.is_in_cache(code, glob1, "l")
+ assert self.is_in_cache(code, glob1, "x")
+ assert f1() == 0
+ mod1.x.append(1)
+ assert f1() == 1
+ assert self.is_in_cache(code, glob1, "l")
+ assert self.is_in_cache(code, glob1, "x")
+ del __builtin__.l
+ mod1.l = len
+ mod1.x.append(1)
+ assert not self.is_in_cache(code, glob1, "l")
+ assert f1() == 2
+ assert self.is_in_cache(code, glob1, "l")
+ assert self.is_in_cache(code, glob1, "x")
+ finally:
+ if hasattr(__builtins__, "l"):
+ del __builtins__.l
+
def test_generator(self):
import sys, __builtin__
mod1 = type(sys)("abc")
More information about the Pypy-commit
mailing list