summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2012-03-08 00:41:11 (GMT)
committerBenjamin Peterson <benjamin@python.org>2012-03-08 00:41:11 (GMT)
commita8d458560e961bd45c5a8900f964cb9c7d95e475 (patch)
treea2811a393996db01d99a714241a2056a7063e037 /Objects
parentec17afdfdac9aa30fc4ec8e6a5153474ab8d32f4 (diff)
downloadcpython-a8d458560e961bd45c5a8900f964cb9c7d95e475.zip
cpython-a8d458560e961bd45c5a8900f964cb9c7d95e475.tar.gz
cpython-a8d458560e961bd45c5a8900f964cb9c7d95e475.tar.bz2
allow cycles throught the __dict__ slot to be cleared (closes #1469629)
Patch from Armin, test from me.
Diffstat (limited to 'Objects')
-rw-r--r--Objects/typeobject.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/Objects/typeobject.c b/Objects/typeobject.c
index 3db02ed..ce1d42b 100644
--- a/Objects/typeobject.c
+++ b/Objects/typeobject.c
@@ -876,8 +876,13 @@ subtype_clear(PyObject *self)
assert(base);
}
- /* There's no need to clear the instance dict (if any);
- the collector will call its tp_clear handler. */
+ /* Clear the instance dict (if any), to break cycles involving only
+ __dict__ slots (as in the case 'self.__dict__ is self'). */
+ if (type->tp_dictoffset != base->tp_dictoffset) {
+ PyObject **dictptr = _PyObject_GetDictPtr(self);
+ if (dictptr && *dictptr)
+ Py_CLEAR(*dictptr);
+ }
if (baseclear)
return baseclear(self);