diff options
author | Amaury Forgeot d'Arc <amauryfa@gmail.com> | 2008-02-08 00:56:02 +0000 |
---|---|---|
committer | Amaury Forgeot d'Arc <amauryfa@gmail.com> | 2008-02-08 00:56:02 +0000 |
commit | b01aa430d5bf82c59c1440e3384a00845cf1b4a2 (patch) | |
tree | c659ffb420a9c69de820a5587afc3d3c52e9d016 /Modules/_collectionsmodule.c | |
parent | 48397d6c2273769c26f4b8cef2a839a74d0da1a5 (diff) | |
download | cpython-git-b01aa430d5bf82c59c1440e3384a00845cf1b4a2.tar.gz |
issue 2045: Infinite recursion when printing a subclass of defaultdict,
if default_factory is set to a bound method.
Will backport.
Diffstat (limited to 'Modules/_collectionsmodule.c')
-rw-r--r-- | Modules/_collectionsmodule.c | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/Modules/_collectionsmodule.c b/Modules/_collectionsmodule.c index 05b03b7c55..67700de728 100644 --- a/Modules/_collectionsmodule.c +++ b/Modules/_collectionsmodule.c @@ -1300,7 +1300,17 @@ defdict_repr(defdictobject *dd) if (dd->default_factory == NULL) defrepr = PyString_FromString("None"); else - defrepr = PyObject_Repr(dd->default_factory); + { + int status = Py_ReprEnter(dd->default_factory); + if (status != 0) { + if (status < 0) + return NULL; + defrepr = PyString_FromString("..."); + } + else + defrepr = PyObject_Repr(dd->default_factory); + Py_ReprLeave(dd->default_factory); + } if (defrepr == NULL) { Py_DECREF(baserepr); return NULL; |