[pypy-svn] r32570 - in pypy/dist/pypy: annotation rpython rpython/test
pedronis at codespeak.net
pedronis at codespeak.net
Thu Sep 21 20:44:44 CEST 2006
Author: pedronis
Date: Thu Sep 21 20:44:42 2006
New Revision: 32570
Modified:
pypy/dist/pypy/annotation/classdef.py
pypy/dist/pypy/rpython/rpbc.py
pypy/dist/pypy/rpython/test/test_rpbc.py
Log:
the optiomisation trying to use singletons for exception without attributes was not checking for attrs in parents
in the hierarchy. Fix and test.
Modified: pypy/dist/pypy/annotation/classdef.py
==============================================================================
--- pypy/dist/pypy/annotation/classdef.py (original)
+++ pypy/dist/pypy/annotation/classdef.py Thu Sep 21 20:44:42 2006
@@ -208,6 +208,12 @@
def __repr__(self):
return "<ClassDef '%s'>" % (self.name,)
+ def has_no_attrs(self):
+ for clsdef in self.getmro():
+ if clsdef.attrs:
+ return False
+ return True
+
def commonbase(self, other):
other1 = other
while other is not None and not self.issubclass(other):
Modified: pypy/dist/pypy/rpython/rpbc.py
==============================================================================
--- pypy/dist/pypy/rpython/rpbc.py (original)
+++ pypy/dist/pypy/rpython/rpbc.py Thu Sep 21 20:44:42 2006
@@ -670,7 +670,7 @@
if (isinstance(s_init, annmodel.SomeImpossibleValue) and
classdef.classdesc.is_exception_class() and
- not classdef.attrs):
+ classdef.has_no_attrs()):
# special case for instanciating simple built-in
# exceptions: always return the same prebuilt instance,
# and ignore any arguments passed to the contructor.
Modified: pypy/dist/pypy/rpython/test/test_rpbc.py
==============================================================================
--- pypy/dist/pypy/rpython/test/test_rpbc.py (original)
+++ pypy/dist/pypy/rpython/test/test_rpbc.py Thu Sep 21 20:44:42 2006
@@ -1379,6 +1379,28 @@
res = self.interpret(f, [])
assert res == 12
+ def test_exception_with_non_empty_baseclass(self):
+ class BE(Exception):
+ pass
+ class E1(BE):
+ pass
+ class E2(BE):
+ pass
+ def f(x):
+ if x:
+ e = E1()
+ else:
+ e = E2()
+ witness = E1()
+ witness.x = 42
+ e.x = 3
+ return witness.x
+
+ res = self.interpret(f, [0])
+ assert res == 42
+ res = self.interpret(f, [1])
+ assert res == 42
+
# We don't care about the following test_hlinvoke tests working on
# ootype. Maybe later. This kind of thing is only used in rdict
More information about the Pypy-commit
mailing list