mirror of
https://github.com/python/cpython.git
synced 2025-11-13 23:46:24 +00:00
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().
This commit is contained in:
parent
012b69cb30
commit
719841e2fb
1 changed files with 2 additions and 1 deletions
|
|
@ -199,7 +199,8 @@ type_call(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||||
if (!PyType_IsSubtype(obj->ob_type, type))
|
if (!PyType_IsSubtype(obj->ob_type, type))
|
||||||
return obj;
|
return obj;
|
||||||
type = obj->ob_type;
|
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) {
|
type->tp_init(obj, args, kwds) < 0) {
|
||||||
Py_DECREF(obj);
|
Py_DECREF(obj);
|
||||||
obj = NULL;
|
obj = NULL;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue