]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Backport 2.237 by Guido:
authorNeal Norwitz <nnorwitz@gmail.com>
Mon, 16 Jun 2003 23:38:00 +0000 (23:38 +0000)
committerNeal Norwitz <nnorwitz@gmail.com>
Mon, 16 Jun 2003 23:38:00 +0000 (23:38 +0000)
- SF patch 751998 fixes an unwanted side effect of the previous fix
  for SF bug 742860 (the next item).

Objects/typeobject.c

index 45c95793c14ee7c99237e7e7485d7458232ea510..20ec8a2dfd1649381f78ca5827d7e421b777529b 100644 (file)
@@ -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);