ruby-changes:39632
From: ko1 <ko1@a...>
Date: Fri, 28 Aug 2015 10:20:51 +0900 (JST)
Subject: [ruby-changes:39632] ko1:r51713 (trunk): * vm.c (hook_before_rewind): prevent kicking :return event while
ko1 2015-08-28 10:20:32 +0900 (Fri, 28 Aug 2015) New Revision: 51713 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=51713 Log: * vm.c (hook_before_rewind): prevent kicking :return event while finishing vm_exec func because invoke_block_from_c() kick a :return event for bmethods. [Bug #11492] * test/ruby/test_settracefunc.rb: add a test. Modified files: trunk/ChangeLog trunk/test/ruby/test_settracefunc.rb trunk/vm.c Index: ChangeLog =================================================================== --- ChangeLog (revision 51712) +++ ChangeLog (revision 51713) @@ -1,3 +1,12 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Fri Aug 28 10:16:20 2015 Koichi Sasada <ko1@a...> + + * vm.c (hook_before_rewind): prevent kicking :return event while + finishing vm_exec func because invoke_block_from_c() kick a :return + event for bmethods. + [Bug #11492] + + * test/ruby/test_settracefunc.rb: add a test. + Thu Aug 27 18:05:42 2015 SHIBATA Hiroshi <hsbt@r...> * lib/webrick/server.rb: use IO::NULL instead of '/dev/null' Index: vm.c =================================================================== --- vm.c (revision 51712) +++ vm.c (revision 51713) @@ -1332,7 +1332,7 @@ vm_frametype_name(const rb_control_frame https://github.com/ruby/ruby/blob/trunk/vm.c#L1332 #endif static void -hook_before_rewind(rb_thread_t *th, rb_control_frame_t *cfp) +hook_before_rewind(rb_thread_t *th, rb_control_frame_t *cfp, int will_finish_vm_exec) { switch (VM_FRAME_TYPE(th->cfp)) { case VM_FRAME_MAGIC_METHOD: @@ -1343,9 +1343,13 @@ hook_before_rewind(rb_thread_t *th, rb_c https://github.com/ruby/ruby/blob/trunk/vm.c#L1343 case VM_FRAME_MAGIC_LAMBDA: if (VM_FRAME_TYPE_BMETHOD_P(th->cfp)) { EXEC_EVENT_HOOK(th, RUBY_EVENT_B_RETURN, th->cfp->self, 0, 0, Qnil); - EXEC_EVENT_HOOK_AND_POP_FRAME(th, RUBY_EVENT_RETURN, th->cfp->self, - rb_vm_frame_method_entry(th->cfp)->called_id, - rb_vm_frame_method_entry(th->cfp)->owner, Qnil); + + if (!will_finish_vm_exec) { + /* kick RUBY_EVENT_RETURN at invoke_block_from_c() for bmethod */ + EXEC_EVENT_HOOK_AND_POP_FRAME(th, RUBY_EVENT_RETURN, th->cfp->self, + rb_vm_frame_method_entry(th->cfp)->called_id, + rb_vm_frame_method_entry(th->cfp)->owner, Qnil); + } } else { EXEC_EVENT_HOOK_AND_POP_FRAME(th, RUBY_EVENT_B_RETURN, th->cfp->self, 0, 0, Qnil); @@ -1531,7 +1535,7 @@ vm_exec(rb_thread_t *th) https://github.com/ruby/ruby/blob/trunk/vm.c#L1535 if (!catch_iseq) { th->errinfo = Qnil; result = THROW_DATA_VAL(err); - hook_before_rewind(th, th->cfp); + hook_before_rewind(th, th->cfp, TRUE); vm_pop_frame(th); goto finish_vme; } @@ -1671,7 +1675,7 @@ vm_exec(rb_thread_t *th) https://github.com/ruby/ruby/blob/trunk/vm.c#L1675 } else { /* skip frame */ - hook_before_rewind(th, th->cfp); + hook_before_rewind(th, th->cfp, FALSE); if (VM_FRAME_TYPE_FINISH_P(th->cfp)) { vm_pop_frame(th); Index: test/ruby/test_settracefunc.rb =================================================================== --- test/ruby/test_settracefunc.rb (revision 51712) +++ test/ruby/test_settracefunc.rb (revision 51713) @@ -1211,6 +1211,74 @@ class TestSetTraceFunc < Test::Unit::Tes https://github.com/ruby/ruby/blob/trunk/test/ruby/test_settracefunc.rb#L1211 end end + class C11492 + define_method(:foo_return){ + return true + } + define_method(:foo_break){ + break true + } + end + + def test_define_method_on_return + # return + events = [] + obj = C11492.new + TracePoint.new(:call, :return){|tp| + next unless target_thread? + events << [tp.event, tp.method_id] + }.enable{ + obj.foo_return + } + assert_equal([[:call, :foo_return], [:return, :foo_return]], events, 'Bug #11492') + + # break + events = [] + obj = C11492.new + TracePoint.new(:call, :return){|tp| + next unless target_thread? + events << [tp.event, tp.method_id] + }.enable{ + obj.foo_break + } + assert_equal([[:call, :foo_break], [:return, :foo_break]], events, 'Bug #11492') + + # set_trace_func + # return + events = [] + begin + set_trace_func(lambda{|event, file, lineno, mid, binding, klass| + next unless target_thread? + case event + when 'call', 'return' + events << [event, mid] + end + }) + obj.foo_return + set_trace_func(nil) + + assert_equal([['call', :foo_return], ['return', :foo_return]], events, 'Bug #11492') + ensure + end + + # break + events = [] + begin + set_trace_func(lambda{|event, file, lineno, mid, binding, klass| + next unless target_thread? + case event + when 'call', 'return' + events << [event, mid] + end + }) + obj.foo_break + set_trace_func(nil) + + assert_equal([['call', :foo_break], ['return', :foo_break]], events, 'Bug #11492') + ensure + end + end + def test_recursive assert_in_out_err([], %q{\ TracePoint.new(:c_call){|tp| -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/