ruby-changes:47531
From: nobu <ko1@a...>
Date: Wed, 23 Aug 2017 11:26:08 +0900 (JST)
Subject: [ruby-changes:47531] nobu:r59647 (trunk): gc.c: run all finalizers
nobu 2017-08-23 11:26:02 +0900 (Wed, 23 Aug 2017) New Revision: 59647 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=59647 Log: gc.c: run all finalizers * gc.c (run_finalizer): revert r59155 partially. finalizing loop should continue even after an exception is rescued. Modified files: trunk/gc.c trunk/test/ruby/test_gc.rb Index: test/ruby/test_gc.rb =================================================================== --- test/ruby/test_gc.rb (revision 59646) +++ test/ruby/test_gc.rb (revision 59647) @@ -397,4 +397,26 @@ class TestGc < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_gc.rb#L397 ObjectSpace.each_object{|o| case o when Module then o.instance_methods end} end end + + def test_exception_in_finalizer + result = [] + c1 = proc do + result << :c1 + raise + end + c2 = proc do + result << :c2 + raise + end + tap { + tap { + obj = Object.new + ObjectSpace.define_finalizer(obj, c1) + ObjectSpace.define_finalizer(obj, c2) + obj = nil + } + } + GC.start + assert_equal([:c1, :c2], result) + end end Index: gc.c =================================================================== --- gc.c (revision 59646) +++ gc.c (revision 59647) @@ -2796,16 +2796,15 @@ run_finalizer(rb_objspace_t *objspace, V https://github.com/ruby/ruby/blob/trunk/gc.c#L2796 saved.finished = 0; TH_PUSH_TAG(th); - if ((state = TH_EXEC_TAG()) == TAG_NONE) { - for (i = saved.finished; - RESTORE_FINALIZER(), i<RARRAY_LEN(table); - saved.finished = ++i) { - run_single_final(RARRAY_AREF(table, i), saved.objid); - } - } - else { + state = TH_EXEC_TAG(); + if (state != TAG_NONE) { ++saved.finished; /* skip failed finalizer */ } + for (i = saved.finished; + RESTORE_FINALIZER(), i<RARRAY_LEN(table); + saved.finished = ++i) { + run_single_final(RARRAY_AREF(table, i), saved.objid); + } TH_POP_TAG(); #undef RESTORE_FINALIZER } -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/