diff options
author | Guido van Rossum <guido@python.org> | 2008-04-10 22:43:58 +0000 |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2008-04-10 22:43:58 +0000 |
commit | aa975432d4456c69e1b1fd2a335f01261175f798 (patch) | |
tree | 55a0db3a38cee1d9b440c9e878906ed82fcea3ca /Objects/tupleobject.c | |
parent | a6add69a63385da3e8abf34023b671137479bf5a (diff) | |
download | cpython-git-aa975432d4456c69e1b1fd2a335f01261175f798.tar.gz |
- Issue #1686386: Tuple's tp_repr did not take into account the possibility of
having a self-referential tuple, which is possible from C code. Nor did
object's tp_str consider that a type's tp_str could do something that could
lead to an inifinite recursion. Py_ReprEnter() and Py_EnterRecursiveCall(),
respectively, fixed the issues. (Backport of r58288 from trunk to 2.5.)
Diffstat (limited to 'Objects/tupleobject.c')
-rw-r--r-- | Objects/tupleobject.c | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/Objects/tupleobject.c b/Objects/tupleobject.c index 6f3711f1f4..56a1024fa1 100644 --- a/Objects/tupleobject.c +++ b/Objects/tupleobject.c @@ -208,6 +208,15 @@ tuplerepr(PyTupleObject *v) PyObject *s, *temp; PyObject *pieces, *result = NULL; + /* 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; + } + n = v->ob_size; if (n == 0) return PyString_FromString("()"); @@ -218,7 +227,10 @@ tuplerepr(PyTupleObject *v) /* 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); @@ -253,6 +265,7 @@ tuplerepr(PyTupleObject *v) Done: Py_DECREF(pieces); + Py_ReprLeave((PyObject *)v); return result; } |