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.
This commit is contained in:
Victor Stinner 2021-06-29 16:39:29 +02:00 committed by GitHub
parent 50148cacfa
commit 823460daa9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 0 deletions

View File

@ -1065,6 +1065,12 @@ static PyGetSetDef type_getsets[] = {
static PyObject * static PyObject *
type_repr(PyTypeObject *type) type_repr(PyTypeObject *type)
{ {
if (type->tp_name == NULL) {
// type_repr() called before the type is fully initialized
// by PyType_Ready().
return PyUnicode_FromFormat("<class at %p>", type);
}
PyObject *mod, *name, *rtn; PyObject *mod, *name, *rtn;
mod = type_module(type, NULL); mod = type_module(type, NULL);