summaryrefslogtreecommitdiffstats
path: root/Objects/object.c
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2018-02-02 14:29:02 (GMT)
committerGitHub <noreply@github.com>2018-02-02 14:29:02 (GMT)
commitb7a2c17be8411bc4c7a2babdc650074c14204aa8 (patch)
treee3816d8aa190bb23b8fa362deeb36153f05e9369 /Objects/object.c
parentb60f43a0e6052b29517931eea591b0b29903f382 (diff)
downloadcpython-b7a2c17be8411bc4c7a2babdc650074c14204aa8.zip
cpython-b7a2c17be8411bc4c7a2babdc650074c14204aa8.tar.gz
cpython-b7a2c17be8411bc4c7a2babdc650074c14204aa8.tar.bz2
[2.7] bpo-32137: The repr of deeply nested dict now raises a RuntimeError (GH-4570) (#5493)
instead of crashing due to a stack overflow. This perhaps will fix similar problems in other extension types. (cherry picked from commit 1fb72d2ad243c965d4432b4e93884064001a2607)
Diffstat (limited to 'Objects/object.c')
-rw-r--r--Objects/object.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/Objects/object.c b/Objects/object.c
index 7a28218..65366b0 100644
--- a/Objects/object.c
+++ b/Objects/object.c
@@ -378,7 +378,12 @@ PyObject_Repr(PyObject *v)
Py_TYPE(v)->tp_name, v);
else {
PyObject *res;
+ /* It is possible for a type to have a tp_repr representation that
+ loops infinitely. */
+ if (Py_EnterRecursiveCall(" while getting the repr of an object"))
+ return NULL;
res = (*Py_TYPE(v)->tp_repr)(v);
+ Py_LeaveRecursiveCall();
if (res == NULL)
return NULL;
#ifdef Py_USING_UNICODE