]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Fix for SF 742911. We now clear the weakrefs *before* calling __del__
authorGuido van Rossum <guido@python.org>
Thu, 29 May 2003 14:28:22 +0000 (14:28 +0000)
committerGuido van Rossum <guido@python.org>
Thu, 29 May 2003 14:28:22 +0000 (14:28 +0000)
or emptying __dict__, just as we do for classic classes.

Objects/typeobject.c

index ade9171a59912b1c478e33170197627ef131de95..a150f5d5e499b593a3fa591916357440a6596254 100644 (file)
@@ -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);