Mercurial > cpython-lru_cache-weakref
diff Objects/typeobject.c @ 75487:c7623da4e2af 2.7
allow cycles throught the __dict__ slot to be cleared (closes #1469629)
Patch from Armin, test from me.
| author | Benjamin Peterson <benjamin@python.org> |
|---|---|
| date | Wed, 07 Mar 2012 18:41:11 -0600 |
| parents | da1d7f8cd487 |
| children | d1cf6008a565 |
line wrap: on
line diff
--- a/Objects/typeobject.c Wed Mar 07 21:00:44 2012 +0100 +++ b/Objects/typeobject.c Wed Mar 07 18:41:11 2012 -0600 @@ -876,8 +876,13 @@ 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);
