Commits

Anonymous committed 6468f0e

Fix for SF 742911. We now clear the weakrefs *before* calling __del__
or emptying __dict__, just as we do for classic classes.

  • Participants
  • Parent commits c3a0207
  • Branches 2.2

Comments (0)

Files changed (1)

Objects/typeobject.c

 	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 */
 		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);
 		}
 	}
 
-	/* 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);