summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2002-05-24 21:40:08 (GMT)
committerGuido van Rossum <guido@python.org>2002-05-24 21:40:08 (GMT)
commit9fc8a29663268a3ed5b8db15c4b7b7786f80e13e (patch)
tree7f22a30e0645c62f2dd4e2d3b4e0ce9d82cb2eb0
parenta2a206b917d7634fa43be1d4062b03f1f4404300 (diff)
downloadcpython-9fc8a29663268a3ed5b8db15c4b7b7786f80e13e.zip
cpython-9fc8a29663268a3ed5b8db15c4b7b7786f80e13e.tar.gz
cpython-9fc8a29663268a3ed5b8db15c4b7b7786f80e13e.tar.bz2
Fix for SF bug 551412. When _PyType_Lookup() is called on a type
whose tp_mro hasn't been initialized, it would dump core. Fix this by checking for NULL and calling PyType_Ready(). Will fix this in 2.2.1 too.
-rw-r--r--Lib/test/test_descr.py16
-rw-r--r--Objects/typeobject.c6
2 files changed, 22 insertions, 0 deletions
diff --git a/Lib/test/test_descr.py b/Lib/test/test_descr.py
index e7e4a8f..faa9d89 100644
--- a/Lib/test/test_descr.py
+++ b/Lib/test/test_descr.py
@@ -3019,7 +3019,23 @@ def string_exceptions():
except:
raise TestFailed, "string subclass allowed as exception"
+def do_this_first():
+ if verbose:
+ print "Testing SF bug 551412 ..."
+ # This dumps core when SF bug 551412 isn't fixed --
+ # but only when test_descr.py is run separately.
+ # (That can't be helped -- as soon as PyType_Ready()
+ # is called for PyLong_Type, the bug is gone.)
+ class UserLong(object):
+ def __pow__(self, *args):
+ pass
+ try:
+ pow(0L, UserLong(), 0L)
+ except:
+ pass
+
def test_main():
+ do_this_first()
class_docstrings()
lists()
dicts()
diff --git a/Objects/typeobject.c b/Objects/typeobject.c
index 61cbeae..af133ea 100644
--- a/Objects/typeobject.c
+++ b/Objects/typeobject.c
@@ -1221,6 +1221,12 @@ _PyType_Lookup(PyTypeObject *type, PyObject *name)
/* Look in tp_dict of types in MRO */
mro = type->tp_mro;
+ if (mro == NULL) {
+ if (PyType_Ready(type) < 0)
+ return NULL;
+ mro = type->tp_mro;
+ assert(mro != NULL);
+ }
assert(PyTuple_Check(mro));
n = PyTuple_GET_SIZE(mro);
for (i = 0; i < n; i++) {