summaryrefslogtreecommitdiffstats
path: root/Modules/collectionsmodule.c
diff options
context:
space:
mode:
authorAmaury Forgeot d'Arc <amauryfa@gmail.com>2008-02-08 01:05:21 (GMT)
committerAmaury Forgeot d'Arc <amauryfa@gmail.com>2008-02-08 01:05:21 (GMT)
commit3e5f8a6975cb7f7c3dc9f84686f27c49bc4aa75a (patch)
treeea8428d58e9dc2798ad2374042caea5ee9bee6d4 /Modules/collectionsmodule.c
parentec4301e60f8380d696115b598fea88cea239947c (diff)
downloadcpython-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.c12
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;