mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* vm.c (vm_exec): check other events when RETURN is thrown.
[Bug #10724] * test/ruby/test_settracefunc.rb: add a test. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50206 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
9a968078bc
commit
93df5a0a90
3 changed files with 54 additions and 29 deletions
|
@ -1,3 +1,10 @@
|
|||
Fri Apr 10 17:27:58 2015 Koichi Sasada <ko1@atdot.net>
|
||||
|
||||
* vm.c (vm_exec): check other events when RETURN is thrown.
|
||||
[Bug #10724]
|
||||
|
||||
* test/ruby/test_settracefunc.rb: add a test.
|
||||
|
||||
Fri Apr 10 11:44:09 2015 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* ext/date/extconf.rb: check warnings.
|
||||
|
|
|
@ -1332,4 +1332,24 @@ class TestSetTraceFunc < Test::Unit::TestCase
|
|||
}
|
||||
assert_equal [__LINE__ - 3, __LINE__ - 2], lines, 'Bug #10449'
|
||||
end
|
||||
|
||||
class Bug10724
|
||||
def initialize
|
||||
loop{return}
|
||||
end
|
||||
end
|
||||
|
||||
def test_throwing_return_with_finish_frame
|
||||
target_th = Thread.current
|
||||
evs = []
|
||||
|
||||
TracePoint.new(:call, :return){|tp|
|
||||
return if Thread.current != target_th
|
||||
evs << tp.event
|
||||
}.enable{
|
||||
a = Bug10724.new
|
||||
}
|
||||
|
||||
assert_equal([:call, :return], evs)
|
||||
end
|
||||
end
|
||||
|
|
56
vm.c
56
vm.c
|
@ -1317,6 +1317,30 @@ vm_frametype_name(const rb_control_frame_t *cfp)
|
|||
}
|
||||
#endif
|
||||
|
||||
static void
|
||||
hook_before_rewind(rb_thread_t *th, rb_control_frame_t *cfp)
|
||||
{
|
||||
switch (VM_FRAME_TYPE(th->cfp)) {
|
||||
case VM_FRAME_MAGIC_METHOD:
|
||||
RUBY_DTRACE_METHOD_RETURN_HOOK(th, 0, 0);
|
||||
EXEC_EVENT_HOOK_AND_POP_FRAME(th, RUBY_EVENT_RETURN, th->cfp->self, 0, 0, Qnil);
|
||||
break;
|
||||
case VM_FRAME_MAGIC_BLOCK:
|
||||
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);
|
||||
}
|
||||
else {
|
||||
EXEC_EVENT_HOOK_AND_POP_FRAME(th, RUBY_EVENT_B_RETURN, th->cfp->self, 0, 0, Qnil);
|
||||
}
|
||||
break;
|
||||
case VM_FRAME_MAGIC_CLASS:
|
||||
EXEC_EVENT_HOOK_AND_POP_FRAME(th, RUBY_EVENT_END, th->cfp->self, 0, 0, Qnil);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* evaluator body */
|
||||
|
||||
/* finish
|
||||
|
@ -1415,7 +1439,6 @@ vm_frametype_name(const rb_control_frame_t *cfp)
|
|||
};
|
||||
*/
|
||||
|
||||
|
||||
static VALUE
|
||||
vm_exec(rb_thread_t *th)
|
||||
{
|
||||
|
@ -1486,15 +1509,9 @@ vm_exec(rb_thread_t *th)
|
|||
}
|
||||
}
|
||||
if (!catch_iseqval) {
|
||||
result = THROW_DATA_VAL(err);
|
||||
th->errinfo = Qnil;
|
||||
|
||||
switch (VM_FRAME_TYPE(cfp)) {
|
||||
case VM_FRAME_MAGIC_LAMBDA:
|
||||
EXEC_EVENT_HOOK_AND_POP_FRAME(th, RUBY_EVENT_B_RETURN, th->cfp->self, 0, 0, Qnil);
|
||||
break;
|
||||
}
|
||||
|
||||
result = THROW_DATA_VAL(err);
|
||||
hook_before_rewind(th, th->cfp);
|
||||
vm_pop_frame(th);
|
||||
goto finish_vme;
|
||||
}
|
||||
|
@ -1638,26 +1655,7 @@ vm_exec(rb_thread_t *th)
|
|||
}
|
||||
else {
|
||||
/* skip frame */
|
||||
|
||||
switch (VM_FRAME_TYPE(th->cfp)) {
|
||||
case VM_FRAME_MAGIC_METHOD:
|
||||
RUBY_DTRACE_METHOD_RETURN_HOOK(th, 0, 0);
|
||||
EXEC_EVENT_HOOK_AND_POP_FRAME(th, RUBY_EVENT_RETURN, th->cfp->self, 0, 0, Qnil);
|
||||
break;
|
||||
case VM_FRAME_MAGIC_BLOCK:
|
||||
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);
|
||||
}
|
||||
else {
|
||||
EXEC_EVENT_HOOK_AND_POP_FRAME(th, RUBY_EVENT_B_RETURN, th->cfp->self, 0, 0, Qnil);
|
||||
}
|
||||
break;
|
||||
case VM_FRAME_MAGIC_CLASS:
|
||||
EXEC_EVENT_HOOK_AND_POP_FRAME(th, RUBY_EVENT_END, th->cfp->self, 0, 0, Qnil);
|
||||
break;
|
||||
}
|
||||
hook_before_rewind(th, th->cfp);
|
||||
|
||||
if (VM_FRAME_TYPE_FINISH_P(th->cfp)) {
|
||||
vm_pop_frame(th);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue