Fix PyObject_Repr(): don't call PyUnicode_READY() if res is NULL

This commit is contained in:
Victor Stinner 2011-12-01 03:22:44 +01:00
parent b37b17423b
commit 0a54cf12a0
1 changed files with 3 additions and 1 deletions

View File

@ -378,7 +378,9 @@ PyObject_Repr(PyObject *v)
return PyUnicode_FromFormat("<%s object at %p>",
v->ob_type->tp_name, v);
res = (*v->ob_type->tp_repr)(v);
if (res != NULL && !PyUnicode_Check(res)) {
if (res == NULL)
return NULL;
if (!PyUnicode_Check(res)) {
PyErr_Format(PyExc_TypeError,
"__repr__ returned non-string (type %.200s)",
res->ob_type->tp_name);