From: <pj...@us...> - 2008-10-11 06:42:42
|
Revision: 5372 http://jython.svn.sourceforge.net/jython/?rev=5372&view=rev Author: pjenvey Date: 2008-10-11 06:42:35 +0000 (Sat, 11 Oct 2008) Log Message: ----------- fix solid_base potentially resolving the wrong type when called before the mro was initialized. caused best_base to blowup with a TypeError Modified Paths: -------------- trunk/jython/Lib/test/test_class_jy.py trunk/jython/src/org/python/core/PyType.java Modified: trunk/jython/Lib/test/test_class_jy.py =================================================================== --- trunk/jython/Lib/test/test_class_jy.py 2008-10-11 05:08:23 UTC (rev 5371) +++ trunk/jython/Lib/test/test_class_jy.py 2008-10-11 06:42:35 UTC (rev 5372) @@ -152,7 +152,17 @@ keys.sort() self.assertEqual(str(keys), "['__doc__', '__module__', 'moo']") + def test_metaclass_and_slotted_base(self): + class Meta(type): + pass + class SlottedBase(object): + __slots__ = 'foo' + # A regression up until 2.5a3: Defining Bar would cause a + # TypeError "mro() returned base with unsuitable layout ('Bar')" + class Bar(SlottedBase): + __metaclass__ = Meta + class ClassNamelessModuleTestCase(unittest.TestCase): def setUp(self): @@ -298,6 +308,7 @@ class Bar(object): self.assertEqual(__module__, module_name) + class ClassMetaclassRepr(unittest.TestCase): """Verifies #1131 is fixed""" def test_repr_with_metaclass(self): Modified: trunk/jython/src/org/python/core/PyType.java =================================================================== --- trunk/jython/src/org/python/core/PyType.java 2008-10-11 05:08:23 UTC (rev 5371) +++ trunk/jython/src/org/python/core/PyType.java 2008-10-11 06:42:35 UTC (rev 5372) @@ -47,7 +47,7 @@ private PyObject dict; /** __mro__, the method resolution. order */ - private PyObject[] mro = new PyObject[0]; + private PyObject[] mro = null; /** __flags__, the type's options. */ private long tp_flags; @@ -645,7 +645,7 @@ @ExposedGet(name = "__mro__") public PyTuple getMro() { - return new PyTuple(mro); + return mro == null ? Py.EmptyTuple : new PyTuple(mro); } @ExposedGet(name = "__flags__") @@ -929,11 +929,24 @@ public boolean isSubType(PyType supertype) { PyObject[] mro = this.mro; - for (int i = 0; i < mro.length; i++) { - if (mro[i] == supertype) + if (mro != null) { + for (PyObject base : mro) { + if (base == supertype) { + return true; + } + } + return false; + } + + // we're not completely initilized yet; follow tp_base + PyType type = this; + do { + if (type == supertype) { return true; - } - return false; + } + type = type.base; + } while (type != null); + return supertype == PyObject.TYPE; } /** @@ -945,6 +958,9 @@ */ public PyObject lookup(String name) { PyObject[] mro = this.mro; + if (mro == null) { + return null; + } for (int i = 0; i < mro.length; i++) { PyObject dict = mro[i].fastGetDict(); if (dict != null) { @@ -958,6 +974,9 @@ public PyObject lookup_where(String name, PyObject[] where) { PyObject[] mro = this.mro; + if (mro == null) { + return null; + } for (int i = 0; i < mro.length; i++) { PyObject t = mro[i]; PyObject dict = t.fastGetDict(); @@ -974,6 +993,9 @@ public PyObject super_lookup(PyType ref, String name) { PyObject[] mro = this.mro; + if (mro == null) { + return null; + } int i; for (i = 0; i < mro.length; i++) { if (mro[i] == ref) @@ -1235,6 +1257,9 @@ protected void __rawdir__(PyDictionary accum) { PyObject[] mro = this.mro; + if (mro == null) { + return; + } for (int i = 0; i < mro.length; i++) { mro[i].addKeys(accum, "__dict__"); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |