diff options
author | Guido van Rossum <guido@python.org> | 2003-05-29 14:29:23 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2003-05-29 14:29:23 (GMT) |
commit | 1987c6693bbd83e27202ff8c1a8a3f8d53ecc5ed (patch) | |
tree | 3df86814ccbee958248fe23f3421d506dd36d5b6 /Objects | |
parent | aabe0b3e343dc2b169d72d6a62ee6b624d34134f (diff) | |
download | cpython-1987c6693bbd83e27202ff8c1a8a3f8d53ecc5ed.zip cpython-1987c6693bbd83e27202ff8c1a8a3f8d53ecc5ed.tar.gz cpython-1987c6693bbd83e27202ff8c1a8a3f8d53ecc5ed.tar.bz2 |
Fix for SF 742911. We now clear the weakrefs *before* calling __del__
or emptying __dict__, just as we do for classic classes.
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/typeobject.c | 23 |
1 files changed, 12 insertions, 11 deletions
diff --git a/Objects/typeobject.c b/Objects/typeobject.c index 18b50fc..93f34ed 100644 --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -638,13 +638,6 @@ subtype_dealloc(PyObject *self) --_PyTrash_delete_nesting; _PyObject_GC_TRACK(self); /* We'll untrack for real later */ - /* Maybe call finalizer; exit early if resurrected */ - if (type->tp_del) { - type->tp_del(self); - if (self->ob_refcnt > 0) - goto endlabel; - } - /* Find the nearest base with a different tp_dealloc and clear slots while we're at it */ base = type; @@ -655,6 +648,18 @@ subtype_dealloc(PyObject *self) assert(base); } + /* If we added a weaklist, we clear it. Do this *before* calling + the finalizer (__del__) or clearing the instance dict. */ + if (type->tp_weaklistoffset && !base->tp_weaklistoffset) + PyObject_ClearWeakRefs(self); + + /* Maybe call finalizer; exit early if resurrected */ + if (type->tp_del) { + type->tp_del(self); + if (self->ob_refcnt > 0) + goto endlabel; + } + /* If we added a dict, DECREF it */ if (type->tp_dictoffset && !base->tp_dictoffset) { PyObject **dictptr = _PyObject_GetDictPtr(self); @@ -667,10 +672,6 @@ subtype_dealloc(PyObject *self) } } - /* If we added weaklist, we clear it */ - if (type->tp_weaklistoffset && !base->tp_weaklistoffset) - PyObject_ClearWeakRefs(self); - /* Finalize GC if the base doesn't do GC and we do */ if (!PyType_IS_GC(base)) _PyObject_GC_UNTRACK(self); |