diff options
| author | Amaury Forgeot d'Arc <amauryfa@gmail.com> | 2008-02-08 01:05:21 (GMT) |
|---|---|---|
| committer | Amaury Forgeot d'Arc <amauryfa@gmail.com> | 2008-02-08 01:05:21 (GMT) |
| commit | 3e5f8a6975cb7f7c3dc9f84686f27c49bc4aa75a (patch) | |
| tree | ea8428d58e9dc2798ad2374042caea5ee9bee6d4 /Modules/collectionsmodule.c | |
| parent | ec4301e60f8380d696115b598fea88cea239947c (diff) | |
| download | cpython-3e5f8a6975cb7f7c3dc9f84686f27c49bc4aa75a.zip cpython-3e5f8a6975cb7f7c3dc9f84686f27c49bc4aa75a.tar.gz cpython-3e5f8a6975cb7f7c3dc9f84686f27c49bc4aa75a.tar.bz2 | |
issue 2045: Infinite recursion when printing a subclass of defaultdict,
if default_factory is set to a bound method.
Backport of r60663.
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 9d128fc..dd3c0b7 100644 --- a/Modules/collectionsmodule.c +++ b/Modules/collectionsmodule.c @@ -1217,7 +1217,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; |
