Skip to content

Commit

Permalink
* vm.c (vm_exec): check other events when RETURN is thrown.
Browse files Browse the repository at this point in the history
  [Bug ruby#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
  • Loading branch information
ko1 committed Apr 10, 2015
1 parent 9a96807 commit 93df5a0
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 29 deletions.
7 changes: 7 additions & 0 deletions ChangeLog
@@ -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.
Expand Down
20 changes: 20 additions & 0 deletions test/ruby/test_settracefunc.rb
Expand Up @@ -1332,4 +1332,24 @@ def test_no_duplicate_line_events
}
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 changes: 27 additions & 29 deletions vm.c
Expand Up @@ -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
Expand Down Expand Up @@ -1415,7 +1439,6 @@ vm_frametype_name(const rb_control_frame_t *cfp)
};
*/


static VALUE
vm_exec(rb_thread_t *th)
{
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 93df5a0

Please sign in to comment.