ruby-changes:40227
From: nagachika <ko1@a...>
Date: Wed, 28 Oct 2015 00:23:53 +0900 (JST)
Subject: [ruby-changes:40227] nagachika:r52308 (ruby_2_2): merge revision(s) 51713: [Backport #11492]
nagachika 2015-10-28 00:23:35 +0900 (Wed, 28 Oct 2015) New Revision: 52308 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=52308 Log: merge revision(s) 51713: [Backport #11492] * 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 directories: branches/ruby_2_2/ Modified files: branches/ruby_2_2/ChangeLog branches/ruby_2_2/test/ruby/test_settracefunc.rb branches/ruby_2_2/version.h branches/ruby_2_2/vm.c Index: ruby_2_2/ChangeLog =================================================================== --- ruby_2_2/ChangeLog (revision 52307) +++ ruby_2_2/ChangeLog (revision 52308) @@ -1,3 +1,12 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_2/ChangeLog#L1 +Tue Oct 27 23:58:32 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. + Tue Oct 27 23:38:26 2015 Nobuyoshi Nakada <nobu@r...> * configure.in: check for libunwind.h, which is not available in Index: ruby_2_2/vm.c =================================================================== --- ruby_2_2/vm.c (revision 52307) +++ ruby_2_2/vm.c (revision 52308) @@ -1294,7 +1294,7 @@ vm_frametype_name(const rb_control_frame https://github.com/ruby/ruby/blob/trunk/ruby_2_2/vm.c#L1294 #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: @@ -1305,7 +1305,13 @@ hook_before_rewind(rb_thread_t *th, rb_c https://github.com/ruby/ruby/blob/trunk/ruby_2_2/vm.c#L1305 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, th->cfp->me->called_id, th->cfp->me->klass, 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, + th->cfp->me->called_id, + th->cfp->me->klass, Qnil); + } } else { EXEC_EVENT_HOOK_AND_POP_FRAME(th, RUBY_EVENT_B_RETURN, th->cfp->self, 0, 0, Qnil); @@ -1486,7 +1492,7 @@ vm_exec(rb_thread_t *th) https://github.com/ruby/ruby/blob/trunk/ruby_2_2/vm.c#L1492 if (!catch_iseqval) { th->errinfo = Qnil; result = GET_THROWOBJ_VAL(err); - hook_before_rewind(th, th->cfp); + hook_before_rewind(th, th->cfp, TRUE); vm_pop_frame(th); goto finish_vme; } @@ -1629,7 +1635,7 @@ vm_exec(rb_thread_t *th) https://github.com/ruby/ruby/blob/trunk/ruby_2_2/vm.c#L1635 } 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: ruby_2_2/version.h =================================================================== --- ruby_2_2/version.h (revision 52307) +++ ruby_2_2/version.h (revision 52308) @@ -1,10 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_2/version.h#L1 #define RUBY_VERSION "2.2.4" -#define RUBY_RELEASE_DATE "2015-10-27" -#define RUBY_PATCHLEVEL 182 +#define RUBY_RELEASE_DATE "2015-10-28" +#define RUBY_PATCHLEVEL 183 #define RUBY_RELEASE_YEAR 2015 #define RUBY_RELEASE_MONTH 10 -#define RUBY_RELEASE_DAY 27 +#define RUBY_RELEASE_DAY 28 #include "ruby/version.h" Index: ruby_2_2/test/ruby/test_settracefunc.rb =================================================================== --- ruby_2_2/test/ruby/test_settracefunc.rb (revision 52307) +++ ruby_2_2/test/ruby/test_settracefunc.rb (revision 52308) @@ -1211,6 +1211,74 @@ class TestSetTraceFunc < Test::Unit::Tes https://github.com/ruby/ruby/blob/trunk/ruby_2_2/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_ruby_status [], %q{ stack = [] Property changes on: ruby_2_2 ___________________________________________________________________ Modified: svn:mergeinfo Merged /trunk:r51713 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/