From: Guido van Rossum Date: Thu, 29 May 2003 14:28:22 +0000 (+0000) Subject: Fix for SF 742911. We now clear the weakrefs *before* calling __del__ X-Git-Tag: v2.2.3~18 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=f9622d1cf019072036f5a11f793bb3274ae6026a;p=thirdparty%2FPython%2Fcpython.git Fix for SF 742911. We now clear the weakrefs *before* calling __del__ or emptying __dict__, just as we do for classic classes. --- diff --git a/Objects/typeobject.c b/Objects/typeobject.c index ade9171a5991..a150f5d5e499 100644 --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -429,10 +429,7 @@ subtype_dealloc(PyObject *self) PyTypeObject *type, *base; destructor basedealloc; - /* This exists so we can DECREF self->ob_type */ - - if (call_finalizer(self) < 0) - return; + /* This function exists so we can DECREF self->ob_type */ /* Find the nearest base with a different tp_dealloc and clear slots while we're at it */ @@ -445,6 +442,13 @@ subtype_dealloc(PyObject *self) assert(base); } + /* If we added weaklist, we clear it */ + if (type->tp_weaklistoffset && !base->tp_weaklistoffset) + PyObject_ClearWeakRefs(self); + + if (call_finalizer(self) < 0) + return; + /* If we added a dict, DECREF it */ if (type->tp_dictoffset && !base->tp_dictoffset) { PyObject **dictptr = _PyObject_GetDictPtr(self); @@ -457,10 +461,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(type) && !PyType_IS_GC(base)) _PyObject_GC_UNTRACK(self);