]> granicus.if.org Git - python/commitdiff
Fix for SF bug 551412. When _PyType_Lookup() is called on a type
authorGuido van Rossum <guido@python.org>
Fri, 24 May 2002 21:40:08 +0000 (21:40 +0000)
committerGuido van Rossum <guido@python.org>
Fri, 24 May 2002 21:40:08 +0000 (21:40 +0000)
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.

Lib/test/test_descr.py
Objects/typeobject.c

index e7e4a8f2bb80d2b255dae0fe0b0baa59e7bb2b49..faa9d89bdc86f644eea25c09fffbd49cba06177c 100644 (file)
@@ -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()
index 61cbeae377782d9e96ba07149891658c45b36f9c..af133eadc2f9aefb76fbfde84802a2ce6f9e0aac 100644 (file)
@@ -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++) {