summaryrefslogtreecommitdiff
path: root/Objects/object.c
diff options
context:
space:
mode:
Diffstat (limited to 'Objects/object.c')
-rw-r--r--Objects/object.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/Objects/object.c b/Objects/object.c
index 71e5641e96..af7be01fbb 100644
--- a/Objects/object.c
+++ b/Objects/object.c
@@ -403,7 +403,12 @@ _PyObject_Str(PyObject *v)
if (v->ob_type->tp_str == NULL)
return PyObject_Repr(v);
+ /* It is possible for a type to have a tp_str representation that loops
+ infinitely. */
+ if (Py_EnterRecursiveCall(" while getting the str of an object"))
+ return NULL;
res = (*v->ob_type->tp_str)(v);
+ Py_LeaveRecursiveCall();
if (res == NULL)
return NULL;
type_ok = PyString_Check(res);
@@ -2141,4 +2146,3 @@ _PyTrash_destroy_chain(void)
#ifdef __cplusplus
}
#endif
-