diff options
author | Benjamin Peterson <benjamin@python.org> | 2012-03-08 00:41:11 (GMT) |
---|---|---|
committer | Benjamin Peterson <benjamin@python.org> | 2012-03-08 00:41:11 (GMT) |
commit | a8d458560e961bd45c5a8900f964cb9c7d95e475 (patch) | |
tree | a2811a393996db01d99a714241a2056a7063e037 /Objects | |
parent | ec17afdfdac9aa30fc4ec8e6a5153474ab8d32f4 (diff) | |
download | cpython-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.c | 9 |
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); |