ruby-changes:6880
From: nobu <ko1@a...>
Date: Thu, 7 Aug 2008 05:10:42 +0900 (JST)
Subject: [ruby-changes:6880] Ruby:r18398 (trunk): * gc.c (run_final): runs finalizers with the object terminated.
nobu 2008-08-07 05:06:05 +0900 (Thu, 07 Aug 2008) New Revision: 18398 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=18398 Log: * gc.c (run_final): runs finalizers with the object terminated. * gc.c (rb_gc_call_finalizer_at_exit): keeps finalized objects from linking to freelist. Modified files: trunk/ChangeLog trunk/gc.c Index: ChangeLog =================================================================== --- ChangeLog (revision 18397) +++ ChangeLog (revision 18398) @@ -1,3 +1,10 @@ +Thu Aug 7 05:06:03 2008 Nobuyoshi Nakada <nobu@r...> + + * gc.c (run_final): runs finalizers with the object terminated. + + * gc.c (rb_gc_call_finalizer_at_exit): keeps finalized objects from + linking to freelist. + Thu Aug 7 04:43:14 2008 NARUSE, Yui <naruse@r...> * enc/depend: for build in other than srcdir. Index: gc.c =================================================================== --- gc.c (revision 18397) +++ gc.c (revision 18398) @@ -1509,6 +1509,7 @@ if (FL_TEST(obj, FL_EXIVAR)) { rb_free_generic_ivar((VALUE)obj); + FL_UNSET(obj, FL_EXIVAR); } switch (BUILTIN_TYPE(obj)) { @@ -2042,6 +2043,7 @@ VALUE args[3], table, objid; objid = rb_obj_id(obj); /* make obj into id */ + RBASIC(obj)->klass = 0; if (RDATA(obj)->dfree) { (*RDATA(obj)->dfree)(DATA_PTR(obj)); @@ -2085,16 +2087,18 @@ chain_finalized_object(st_data_t key, st_data_t val, st_data_t arg) { RVALUE *p = (RVALUE *)key, **final_list = (RVALUE **)arg; - if ((p->as.basic.flags & (FL_FINALIZE|FL_MARK)) == FL_FINALIZE) { + if (p->as.basic.flags & FL_FINALIZE) { if (BUILTIN_TYPE(p) != T_DEFERRED) { p->as.free.flags = FL_MARK | T_DEFERRED; /* remain marked */ RDATA(p)->dfree = 0; } p->as.free.next = *final_list; *final_list = p; + return ST_CONTINUE; + } + else { return ST_DELETE; } - return ST_CONTINUE; } void @@ -2105,21 +2109,22 @@ size_t i; /* run finalizers */ - if (need_call_final) { - do { - p = deferred_final_list; - deferred_final_list = 0; - finalize_list(objspace, p); - mark_tbl(objspace, finalizer_table, 0); + if (finalizer_table) { + p = deferred_final_list; + deferred_final_list = 0; + finalize_list(objspace, p); + while (finalizer_table->num_entries > 0) { + RVALUE *final_list = 0; st_foreach(finalizer_table, chain_finalized_object, - (st_data_t)&deferred_final_list); - } while (deferred_final_list); - if (finalizer_table->num_entries) { - rb_warning("%d finalizer%s left not-invoked due to self-reference", - finalizer_table->num_entries, - finalizer_table->num_entries > 1 ? "s" : ""); + (st_data_t)&final_list); + if (!(p = final_list)) break; + do { + final_list = p->as.free.next; + run_final(objspace, (VALUE)p); + } while ((p = final_list) != 0); } st_free_table(finalizer_table); + finalizer_table = 0; } /* finalizers are part of garbage collection */ during_gc++; -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/