[Python-checkins] python/dist/src/Modules gcmodule.c,2.61,2.62
tim_one@users.sourceforge.net
tim_one@users.sourceforge.net
Sat, 05 Apr 2003 10:40:53 -0800
Update of /cvsroot/python/python/dist/src/Modules
In directory sc8-pr-cvs1:/tmp/cvs-serv29089/Modules
Modified Files:
gcmodule.c
Log Message:
move_finalizers(): Rewrote. It's not necessary for this routine
to special-case classic classes, or to worry about refcounts;
has_finalizer() deleted the current object iff the first entry in
the unreachable list has changed. I don't believe it was correct
to check for ob_refcnt == 1, either: the dealloc routine would get
called by Py_DECREF then, but there's nothing to stop the dealloc
routine from ressurecting the object, and then gc would remain at
the head of the unreachable list despite that its refcount temporarily
fell to 0 (and that would lead to an infinite loop in move_finalizers()).
I'm still worried about has_finalizer() resurrecting other objects
in the unreachable list: what's to stop them from getting collected?
Index: gcmodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/gcmodule.c,v
retrieving revision 2.61
retrieving revision 2.62
diff -C2 -d -r2.61 -r2.62
*** gcmodule.c 5 Apr 2003 17:35:54 -0000 2.61
--- gcmodule.c 5 Apr 2003 18:40:50 -0000 2.62
***************
*** 362,366 ****
}
! /* Move all objects out of unreachable and into collectable or finalizers.
*/
static void
--- 362,374 ----
}
! /* Move all objects out of unreachable, into collectable or finalizers.
! * It's possible that some objects will get collected (via refcount falling
! * to 0), or resurrected, as a side effect of checking for __del__ methods.
! * After, finalizers contains all the objects from unreachable that haven't
! * been collected by magic, and that have a finalizer. gc_refs is
! * GC_REACHABLE for all of those. collectable contains all the remaining
! * objects from unreachable, and gc_refs remains GC_TENTATIVELY_UNREACHABLE
! * for those (we're still not sure they're reclaimable after this! Some
! * may yet by reachable *from* the objects in finalizers).
*/
static void
***************
*** 373,406 ****
int finalizer;
! if (PyInstance_Check(op)) {
! /* The HasAttr() check may run enough Python
! code to deallocate the object or make it
! reachable again. INCREF the object before
! calling HasAttr() to guard against the client
! code deallocating the object.
! */
! Py_INCREF(op);
! finalizer = PyObject_HasAttr(op, delstr);
! if (op->ob_refcnt == 1) {
! /* The object will be deallocated.
! Nothing left to do.
! */
! Py_DECREF(op);
! continue;
! }
! Py_DECREF(op);
! }
! else
! finalizer = has_finalizer(op);
! if (finalizer) {
! gc_list_remove(gc);
! gc_list_append(gc, finalizers);
! gc->gc.gc_refs = GC_REACHABLE;
! }
! else {
gc_list_remove(gc);
! gc_list_append(gc, collectable);
! /* XXX change gc_refs? */
}
}
}
--- 381,397 ----
int finalizer;
! assert(IS_TENTATIVELY_UNREACHABLE(op));
!
! finalizer = has_finalizer(op);
! if (unreachable->gc.gc_next == gc) {
gc_list_remove(gc);
! if (finalizer) {
! gc_list_append(gc, finalizers);
! gc->gc.gc_refs = GC_REACHABLE;
! }
! else
! gc_list_append(gc, collectable);
}
+ /* else has_finalizer() deleted op via side effect */
}
}