mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
allow cycles throught the __dict__ slot to be cleared (closes #1469629)
Patch from Armin, test from me.
This commit is contained in:
parent
1ae230aa1a
commit
52c424343d
3 changed files with 27 additions and 4 deletions
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue