summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-07-30 16:37:33 +0000
committernagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-07-30 16:37:33 +0000
commite0c00fccc47fbf473768cc84d808c2de06b1e69f (patch)
treedf1428e37687b4dd318aa252d8495708bdd30764
parentd22cfb2fdb900cdbc732a3667b5706130905a21c (diff)
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. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_1@47013 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog11
-rw-r--r--test/ruby/test_settracefunc.rb21
-rw-r--r--version.h2
-rw-r--r--vm.c28
-rw-r--r--vm_insnhelper.c6
5 files changed, 52 insertions, 16 deletions
diff --git a/ChangeLog b/ChangeLog
index 3782c3f714..e97de41aef 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+Thu Jul 31 01:22:43 2014 Koichi Sasada <ko1@atdot.net>
+
+ * 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@atdot.net>
* vm_core.h: add VM_FRAME_MAGIC_RESCUE to recognize normal block or
diff --git a/test/ruby/test_settracefunc.rb b/test/ruby/test_settracefunc.rb
index cee9029304..bcdde70860 100644
--- a/test/ruby/test_settracefunc.rb
+++ b/test/ruby/test_settracefunc.rb
@@ -383,7 +383,7 @@ class TestSetTraceFunc < Test::Unit::TestCase
[["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::TestCase
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
diff --git a/version.h b/version.h
index 6c888dbf65..2b2d7fd5fd 100644
--- a/version.h
+++ b/version.h
@@ -1,6 +1,6 @@
#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
diff --git a/vm.c b/vm.c
index 38c346ffda..922140e7f8 100644
--- a/vm.c
+++ b/vm.c
@@ -717,15 +717,17 @@ invoke_block_from_c(rb_thread_t *th, const rb_block_t *block,
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, const rb_block_t *block,
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, const rb_block_t *block,
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);
diff --git a/vm_insnhelper.c b/vm_insnhelper.c
index 9e1dbe16a9..c9c91b0fc7 100644
--- a/vm_insnhelper.c
+++ b/vm_insnhelper.c
@@ -1593,17 +1593,11 @@ vm_call_bmethod_body(rb_thread_t *th, rb_call_info_t *ci, const VALUE *argv)
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;
}