allow cycles throught the __dict__ slot to be cleared (closes #1469629)

Patch from Armin, test from me.
This commit is contained in:
Benjamin Peterson 2012-03-07 18:41:11 -06:00
parent 1ae230aa1a
commit 52c424343d
3 changed files with 27 additions and 4 deletions

View file

@ -830,8 +830,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);