mirror of https://github.com/python/cpython
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:
parent
50148cacfa
commit
823460daa9
|
@ -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);
|
||||||
|
|
Loading…
Reference in New Issue