ruby-changes:47533
From: nobu <ko1@a...>
Date: Wed, 23 Aug 2017 13:01:45 +0900 (JST)
Subject: [ruby-changes:47533] nobu:r59649 (trunk): gc.c: restore cfp at finalizer
nobu 2017-08-23 13:01:39 +0900 (Wed, 23 Aug 2017) New Revision: 59649 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=59649 Log: gc.c: restore cfp at finalizer * gc.c (run_finalizer): restore cfp for the case an exception raised in a finalizer. [ruby-core:82432] [Bug #13832] Modified files: trunk/gc.c trunk/test/ruby/test_gc.rb Index: gc.c =================================================================== --- gc.c (revision 59648) +++ gc.c (revision 59649) @@ -2782,17 +2782,20 @@ run_finalizer(rb_objspace_t *objspace, V https://github.com/ruby/ruby/blob/trunk/gc.c#L2782 volatile struct { VALUE errinfo; VALUE objid; + rb_control_frame_t *cfp; long finished; int safe; } saved; rb_thread_t *const th = GET_THREAD(); #define RESTORE_FINALIZER() (\ + th->ec.cfp = saved.cfp, \ rb_set_safe_level_force(saved.safe), \ rb_set_errinfo(saved.errinfo)) saved.safe = rb_safe_level(); saved.errinfo = rb_errinfo(); saved.objid = nonspecial_obj_id(obj); + saved.cfp = th->ec.cfp; saved.finished = 0; TH_PUSH_TAG(th); Index: test/ruby/test_gc.rb =================================================================== --- test/ruby/test_gc.rb (revision 59648) +++ test/ruby/test_gc.rb (revision 59649) @@ -420,4 +420,27 @@ class TestGc < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_gc.rb#L420 skip "finalizers did not get run" if result.empty? assert_equal([:c1, :c2], result) end + + def test_exception_in_finalizer_method + @result = [] + def self.c1(x) + @result << :c1 + raise + end + def self.c2(x) + @result << :c2 + raise + end + tap { + tap { + obj = Object.new + ObjectSpace.define_finalizer(obj, method(:c1)) + ObjectSpace.define_finalizer(obj, method(:c2)) + obj = nil + } + } + GC.start + skip "finalizers did not get run" if @result.empty? + assert_equal([:c1, :c2], @result) + end end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/