From: Neal Norwitz Date: Mon, 16 Jun 2003 23:38:00 +0000 (+0000) Subject: Backport 2.237 by Guido: X-Git-Tag: 2.2~64 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=dad043e364fdfbcdc20e77329e086d8166460b5e;p=thirdparty%2FPython%2Fcpython.git Backport 2.237 by Guido: - SF patch 751998 fixes an unwanted side effect of the previous fix for SF bug 742860 (the next item). --- diff --git a/Objects/typeobject.c b/Objects/typeobject.c index 45c95793c14e..20ec8a2dfd16 100644 --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -431,24 +431,33 @@ subtype_dealloc(PyObject *self) /* 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 */ + /* Find the nearest base with a different tp_dealloc */ type = self->ob_type; base = type; while ((basedealloc = base->tp_dealloc) == subtype_dealloc) { - if (base->ob_size) - clear_slots(base, self); base = base->tp_base; assert(base); } - /* If we added weaklist, we clear it */ + /* If we added a weaklist, we clear it. Do this *before* calling + the finalizer (__del__), clearing slots, or clearing the instance + dict. */ + if (type->tp_weaklistoffset && !base->tp_weaklistoffset) PyObject_ClearWeakRefs(self); if (call_finalizer(self) < 0) return; + /* Clear slots up to the nearest base with a different tp_dealloc */ + base = type; + while ((basedealloc = base->tp_dealloc) == subtype_dealloc) { + if (base->ob_size) + clear_slots(base, self); + base = base->tp_base; + assert(base); + } + /* If we added a dict, DECREF it */ if (type->tp_dictoffset && !base->tp_dictoffset) { PyObject **dictptr = _PyObject_GetDictPtr(self);