From 13f0b628d7520f7a1777e39fbc6ce7b075e4bd47 Mon Sep 17 00:00:00 2001 From: ko1 Date: Thu, 19 Jun 2014 22:09:23 +0000 Subject: [PATCH] * compile.c (rb_iseq_compile_node): put start label of block after trace (b_call). [Bug #9964] * test/ruby/test_settracefunc.rb: add a test. added assert_consistent_call_return() method check call/return consistency. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46471 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 11 ++++++++ compile.c | 2 +- test/ruby/test_settracefunc.rb | 48 ++++++++++++++++++++++++++++++++++ 3 files changed, 60 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index df3e8a2189..afb92e220e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +Fri Jun 20 07:07:28 2014 Koichi Sasada + + * compile.c (rb_iseq_compile_node): put start label of block after + trace (b_call). + [Bug #9964] + + * test/ruby/test_settracefunc.rb: add a test. + + added assert_consistent_call_return() method check call/return + consistency. + Fri Jun 20 05:26:27 2014 Koichi Sasada * vm_eval.c (rb_catch_protect): fix same problem of [Bug #9961]. diff --git a/compile.c b/compile.c index a04ddd02d0..6c71a8586f 100644 --- a/compile.c +++ b/compile.c @@ -483,8 +483,8 @@ rb_iseq_compile_node(VALUE self, NODE *node) LABEL *start = iseq->compile_data->start_label = NEW_LABEL(0); LABEL *end = iseq->compile_data->end_label = NEW_LABEL(0); - ADD_LABEL(ret, start); ADD_TRACE(ret, FIX2INT(iseq->location.first_lineno), RUBY_EVENT_B_CALL); + ADD_LABEL(ret, start); COMPILE(ret, "block body", node->nd_body); ADD_LABEL(ret, end); ADD_TRACE(ret, nd_line(node), RUBY_EVENT_B_RETURN); diff --git a/test/ruby/test_settracefunc.rb b/test/ruby/test_settracefunc.rb index 5d46fc3b08..3bbe5b3eea 100644 --- a/test/ruby/test_settracefunc.rb +++ b/test/ruby/test_settracefunc.rb @@ -1308,4 +1308,52 @@ class TestSetTraceFunc < Test::Unit::TestCase [:c_return, :===], [:b_return, :test_rb_rescue]], events end + + def method_prefix event + case event + when :call, :return + :n + when :c_call, :c_return + :c + when :b_call, :b_return + :b + end + end + + def method_label tp + "#{method_prefix(tp.event)}##{tp.method_id}" + end + + def assert_consistent_call_return message='', check_events: nil + check_events ||= %i(a_call a_return) + call_events = [] + return_events = [] + + TracePoint.new(*check_events){|tp| + next unless target_thread? + + case tp.event.to_s + when /call/ + call_events << method_label(tp) + when /return/ + return_events << method_label(tp) + end + }.enable do + yield + end + + assert_equal false, call_events.empty? + assert_equal false, return_events.empty? + assert_equal call_events, return_events.reverse, message + end + + def test_b_call_with_redo + assert_consistent_call_return do + i = 0 + 1.times{ + break if (i+=1) > 10 + redo + } + end + end end