summaryrefslogtreecommitdiffstats
path: root/Objects/tupleobject.c
diff options
context:
space:
mode:
Diffstat (limited to 'Objects/tupleobject.c')
-rw-r--r--Objects/tupleobject.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/Objects/tupleobject.c b/Objects/tupleobject.c
index 222f362..c22785d 100644
--- a/Objects/tupleobject.c
+++ b/Objects/tupleobject.c
@@ -195,13 +195,25 @@ tuplerepr(PyTupleObject *v)
if (n == 0)
return PyUnicode_FromString("()");
+ /* While not mutable, it is still possible to end up with a cycle in a
+ tuple through an object that stores itself within a tuple (and thus
+ infinitely asks for the repr of itself). This should only be
+ possible within a type. */
+ i = Py_ReprEnter((PyObject *)v);
+ if (i != 0) {
+ return i > 0 ? PyString_FromString("(...)") : NULL;
+ }
+
pieces = PyTuple_New(n);
if (pieces == NULL)
return NULL;
/* Do repr() on each element. */
for (i = 0; i < n; ++i) {
+ if (Py_EnterRecursiveCall(" while getting the repr of a tuple"))
+ goto Done;
s = PyObject_Repr(v->ob_item[i]);
+ Py_LeaveRecursiveCall();
if (s == NULL)
goto Done;
PyTuple_SET_ITEM(pieces, i, s);
@@ -236,6 +248,7 @@ tuplerepr(PyTupleObject *v)
Done:
Py_DECREF(pieces);
+ Py_ReprLeave((PyObject *)v);
return result;
}