From: Victor Stinner Date: Tue, 29 Jun 2021 14:39:29 +0000 (+0200) Subject: bpo-44531: Fix type_repr() if tp_name is NULL (GH-26948) X-Git-Tag: v3.11.0a1~766 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=823460daa9fab3d0cf00ec553d1e35635ef73d40;p=thirdparty%2FPython%2Fcpython.git bpo-44531: Fix type_repr() if tp_name is NULL (GH-26948) Allow to call type_repr() on a type which is not fully initialized yet. This fix helps debugging crashes occurring early at Python initialization. --- diff --git a/Objects/typeobject.c b/Objects/typeobject.c index 3c766e9230e2..8ee4e813ee52 100644 --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -1065,6 +1065,12 @@ static PyGetSetDef type_getsets[] = { static PyObject * type_repr(PyTypeObject *type) { + if (type->tp_name == NULL) { + // type_repr() called before the type is fully initialized + // by PyType_Ready(). + return PyUnicode_FromFormat("", type); + } + PyObject *mod, *name, *rtn; mod = type_module(type, NULL);