diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-08-23 04:01:39 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-08-23 04:01:39 +0000 |
commit | 1fe73fc948c5f511d3c6a7b4dfb7fe61348ab169 (patch) | |
tree | 50a76c204eeac144a58da9fb61f0e9561033b73d | |
parent | 9b2d518a6f74abaa73734ecf8bce80ab422867d6 (diff) | |
download | ruby-1fe73fc948c5f511d3c6a7b4dfb7fe61348ab169.tar.gz |
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]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59649 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | gc.c | 3 | ||||
-rw-r--r-- | test/ruby/test_gc.rb | 23 |
2 files changed, 26 insertions, 0 deletions
@@ -2782,17 +2782,20 @@ run_finalizer(rb_objspace_t *objspace, VALUE obj, VALUE table) 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); diff --git a/test/ruby/test_gc.rb b/test/ruby/test_gc.rb index fa4d779069..f72a59aaf8 100644 --- a/test/ruby/test_gc.rb +++ b/test/ruby/test_gc.rb @@ -420,4 +420,27 @@ class TestGc < Test::Unit::TestCase 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 |