[Python-checkins] r60057 - python/trunk/Objects/classobject.c

guido.van.rossum python-checkins at python.org
Fri Jan 18 21:56:31 CET 2008


Author: guido.van.rossum
Date: Fri Jan 18 21:56:30 2008
New Revision: 60057

Modified:
   python/trunk/Objects/classobject.c
Log:
Fix an edge case whereby the __del__() method of a classic class could
create a new weakref to the object.


Modified: python/trunk/Objects/classobject.c
==============================================================================
--- python/trunk/Objects/classobject.c	(original)
+++ python/trunk/Objects/classobject.c	Fri Jan 18 21:56:30 2008
@@ -646,6 +646,16 @@
 	 */
 	assert(inst->ob_refcnt > 0);
 	if (--inst->ob_refcnt == 0) {
+
+		/* New weakrefs could be created during the finalizer call.
+		    If this occurs, clear them out without calling their
+		    finalizers since they might rely on part of the object
+		    being finalized that has already been destroyed. */
+		while (inst->in_weakreflist != NULL) {
+			_PyWeakref_ClearRef((PyWeakReference *)
+                                            (inst->in_weakreflist));
+		}
+
 		Py_DECREF(inst->in_class);
 		Py_XDECREF(inst->in_dict);
 		PyObject_GC_Del(inst);


More information about the Python-checkins mailing list