From: Jeremy Hylton Date: Tue, 16 Jul 2002 19:42:21 +0000 (+0000) Subject: The object returned by tp_new() may not have a tp_init. X-Git-Tag: v2.2.2b1~265 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=ea21ac976751a9a6c2204cc35be1fef97815435b;p=thirdparty%2FPython%2Fcpython.git The object returned by tp_new() may not have a tp_init. If the object is an ExtensionClass, for example, the slot is not even defined. So we must check that the type has the slot (implied by HAVE_CLASS) before calling tp_init(). --- diff --git a/Objects/typeobject.c b/Objects/typeobject.c index e8c7ea7aef51..a599127aa22e 100644 --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -190,7 +190,8 @@ type_call(PyTypeObject *type, PyObject *args, PyObject *kwds) (PyDict_Check(kwds) && PyDict_Size(kwds) == 0))) return obj; type = obj->ob_type; - if (type->tp_init != NULL && + if (PyType_HasFeature(type, Py_TPFLAGS_HAVE_CLASS) && + type->tp_init != NULL && type->tp_init(obj, args, kwds) < 0) { Py_DECREF(obj); obj = NULL;