ruby-changes:34930
From: nagachika <ko1@a...>
Date: Thu, 31 Jul 2014 01:37:42 +0900 (JST)
Subject: [ruby-changes:34930] nagachika:r47013 (ruby_2_1): merge revision(s) r46464: [Backport #9959]
nagachika 2014-07-31 01:37:33 +0900 (Thu, 31 Jul 2014) New Revision: 47013 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=47013 Log: merge revision(s) r46464: [Backport #9959] * vm.c (invoke_block_from_c): move call/return event timing for bmethod. It can invoke inconsistent call event if this call raises argument error. [Bug #9959] * vm_insnhelper.c (vm_call_bmethod_body): ditto. * test/ruby/test_settracefunc.rb: add a test. Modified directories: branches/ruby_2_1/ Modified files: branches/ruby_2_1/ChangeLog branches/ruby_2_1/test/ruby/test_settracefunc.rb branches/ruby_2_1/version.h branches/ruby_2_1/vm.c branches/ruby_2_1/vm_insnhelper.c Index: ruby_2_1/ChangeLog =================================================================== --- ruby_2_1/ChangeLog (revision 47012) +++ ruby_2_1/ChangeLog (revision 47013) @@ -1,3 +1,14 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_1/ChangeLog#L1 +Thu Jul 31 01:22:43 2014 Koichi Sasada <ko1@a...> + + * vm.c (invoke_block_from_c): move call/return event timing for + bmethod. It can invoke inconsistent call event if this call raises + argument error. + [Bug #9959] + + * vm_insnhelper.c (vm_call_bmethod_body): ditto. + + * test/ruby/test_settracefunc.rb: add a test. + Thu Jul 31 01:12:55 2014 Koichi Sasada <ko1@a...> * vm_core.h: add VM_FRAME_MAGIC_RESCUE to recognize normal block or Index: ruby_2_1/vm.c =================================================================== --- ruby_2_1/vm.c (revision 47012) +++ ruby_2_1/vm.c (revision 47013) @@ -717,15 +717,17 @@ invoke_block_from_c(rb_thread_t *th, con https://github.com/ruby/ruby/blob/trunk/ruby_2_1/vm.c#L717 const rb_block_t *blockptr, const NODE *cref, VALUE defined_class) { - if (SPECIAL_CONST_P(block->iseq)) + if (SPECIAL_CONST_P(block->iseq)) { return Qnil; + } else if (BUILTIN_TYPE(block->iseq) != T_NODE) { + VALUE ret; const rb_iseq_t *iseq = block->iseq; const rb_control_frame_t *cfp; int i, opt_pc, arg_size = iseq->arg_size; - int type = block_proc_is_lambda(block->proc) ? - VM_FRAME_MAGIC_LAMBDA : VM_FRAME_MAGIC_BLOCK; - + int type = block_proc_is_lambda(block->proc) ? VM_FRAME_MAGIC_LAMBDA : VM_FRAME_MAGIC_BLOCK; + const rb_method_entry_t *me = th->passed_bmethod_me; + th->passed_bmethod_me = 0; cfp = th->cfp; for (i=0; i<argc; i++) { @@ -735,15 +737,17 @@ invoke_block_from_c(rb_thread_t *th, con https://github.com/ruby/ruby/blob/trunk/ruby_2_1/vm.c#L737 opt_pc = vm_yield_setup_args(th, iseq, argc, cfp->sp, blockptr, type == VM_FRAME_MAGIC_LAMBDA); - if (th->passed_bmethod_me != 0) { + if (me != 0) { /* bmethod */ vm_push_frame(th, iseq, type | VM_FRAME_FLAG_FINISH | VM_FRAME_FLAG_BMETHOD, self, defined_class, VM_ENVVAL_PREV_EP_PTR(block->ep), iseq->iseq_encoded + opt_pc, cfp->sp + arg_size, iseq->local_size - arg_size, - th->passed_bmethod_me, iseq->stack_max); - th->passed_bmethod_me = 0; + me, iseq->stack_max); + + RUBY_DTRACE_METHOD_ENTRY_HOOK(th, me->klass, me->called_id); + EXEC_EVENT_HOOK(th, RUBY_EVENT_CALL, self, me->called_id, me->klass, Qnil); } else { vm_push_frame(th, iseq, type | VM_FRAME_FLAG_FINISH, @@ -758,7 +762,15 @@ invoke_block_from_c(rb_thread_t *th, con https://github.com/ruby/ruby/blob/trunk/ruby_2_1/vm.c#L762 th->cfp->ep[-1] = (VALUE)cref; } - return vm_exec(th); + ret = vm_exec(th); + + if (me) { + /* bmethod */ + EXEC_EVENT_HOOK(th, RUBY_EVENT_RETURN, self, me->called_id, me->klass, ret); + RUBY_DTRACE_METHOD_RETURN_HOOK(th, me->klass, me->called_id); + } + + return ret; } else { return vm_yield_with_cfunc(th, block, self, argc, argv, blockptr); Index: ruby_2_1/version.h =================================================================== --- ruby_2_1/version.h (revision 47012) +++ ruby_2_1/version.h (revision 47013) @@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_1/version.h#L1 #define RUBY_VERSION "2.1.2" #define RUBY_RELEASE_DATE "2014-07-31" -#define RUBY_PATCHLEVEL 184 +#define RUBY_PATCHLEVEL 185 #define RUBY_RELEASE_YEAR 2014 #define RUBY_RELEASE_MONTH 7 Index: ruby_2_1/vm_insnhelper.c =================================================================== --- ruby_2_1/vm_insnhelper.c (revision 47012) +++ ruby_2_1/vm_insnhelper.c (revision 47013) @@ -1593,17 +1593,11 @@ vm_call_bmethod_body(rb_thread_t *th, rb https://github.com/ruby/ruby/blob/trunk/ruby_2_1/vm_insnhelper.c#L1593 rb_proc_t *proc; VALUE val; - RUBY_DTRACE_METHOD_ENTRY_HOOK(th, ci->me->klass, ci->me->called_id); - EXEC_EVENT_HOOK(th, RUBY_EVENT_CALL, ci->recv, ci->me->called_id, ci->me->klass, Qnil); - /* control block frame */ th->passed_bmethod_me = ci->me; GetProcPtr(ci->me->def->body.proc, proc); val = vm_invoke_proc(th, proc, ci->recv, ci->defined_class, ci->argc, argv, ci->blockptr); - EXEC_EVENT_HOOK(th, RUBY_EVENT_RETURN, ci->recv, ci->me->called_id, ci->me->klass, val); - RUBY_DTRACE_METHOD_RETURN_HOOK(th, ci->me->klass, ci->me->called_id); - return val; } Index: ruby_2_1/test/ruby/test_settracefunc.rb =================================================================== --- ruby_2_1/test/ruby/test_settracefunc.rb (revision 47012) +++ ruby_2_1/test/ruby/test_settracefunc.rb (revision 47013) @@ -383,7 +383,7 @@ class TestSetTraceFunc < Test::Unit::Tes https://github.com/ruby/ruby/blob/trunk/ruby_2_1/test/ruby/test_settracefunc.rb#L383 [["c-return", 3, :set_trace_func, Kernel], ["line", 6, __method__, self.class], - ["call", 6, :foobar, FooBar], + ["call", 1, :foobar, FooBar], ["return", 6, :foobar, FooBar], ["line", 7, __method__, self.class], ["c-call", 7, :set_trace_func, Kernel]].each{|e| @@ -1232,4 +1232,23 @@ class TestSetTraceFunc < Test::Unit::Tes https://github.com/ruby/ruby/blob/trunk/ruby_2_1/test/ruby/test_settracefunc.rb#L1232 trace.disable end end + + define_method(:method_test_argument_error_on_bmethod){|correct_key: 1|} + + def test_argument_error_on_bmethod + events = [] + curr_thread = Thread.current + TracePoint.new(:call, :return){|tp| + next if curr_thread != Thread.current + events << [tp.event, tp.method_id] + }.enable do + begin + method_test_argument_error_on_bmethod(wrong_key: 2) + rescue => e + # ignore + end + end + + assert_equal [], events # should be empty. + end end Property changes on: ruby_2_1 ___________________________________________________________________ Modified: svn:mergeinfo Merged /trunk:r46464 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/