From 2f3fa385dbc5aec0e5c4e4fb4de6742b079aca4e Mon Sep 17 00:00:00 2001 From: yugui Date: Wed, 28 Oct 2009 14:15:24 +0000 Subject: [PATCH] merges r24579 and r24581 from trunk into ruby_1_9_1. -- * compile.c (NODE_RETURN): fire return event at explicit return. [ruby-dev:38701] -- * test/ruby/test_settracefunc.rb (test_return, test_return2): add two tests for [ruby-dev:38701] and [ruby-core:24463]. -- * parse.y (reduce_nodes_gen): preserve NODE_FL_NEWLINE flag during node reducing. [ruby-core:24463] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_1@25537 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 15 ++++++ compile.c | 1 + parse.y | 4 ++ test/ruby/test_settracefunc.rb | 83 ++++++++++++++++++++++++++++++++++ version.h | 2 +- 5 files changed, 104 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index ced69f5822..4ebbe5cba4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +Thu Aug 20 23:39:51 2009 Yusuke Endoh + + * parse.y (reduce_nodes_gen): preserve NODE_FL_NEWLINE flag during + node reducing. [ruby-core:24463] + +Wed Aug 19 02:54:01 2009 Yusuke Endoh + + * test/ruby/test_settracefunc.rb (test_return, test_return2): add two + tests for [ruby-dev:38701] and [ruby-core:24463]. + +Wed Aug 19 01:08:34 2009 Yusuke Endoh + + * compile.c (NODE_RETURN): fire return event at explicit return. + [ruby-dev:38701] + Tue Aug 18 11:37:24 2009 wanabe * vm_insnhelper.c (vm_call_cfunc): ensure hook c-return. diff --git a/compile.c b/compile.c index de710d88db..313e3eb460 100644 --- a/compile.c +++ b/compile.c @@ -4212,6 +4212,7 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node, int poped) if (is->type == ISEQ_TYPE_METHOD) { add_ensure_iseq(ret, iseq, 1); + ADD_TRACE(ret, nd_line(node), RUBY_EVENT_RETURN); ADD_INSN(ret, nd_line(node), leave); ADD_ADJUST_RESTORE(ret, splabel); diff --git a/parse.y b/parse.y index 466eba01ab..ec09c018c2 100644 --- a/parse.y +++ b/parse.y @@ -8459,6 +8459,7 @@ reduce_nodes_gen(struct parser_params *parser, NODE **body) (reduce_nodes(&node->n1), body = &node->n2, 1)) while (node) { + int newline = node->flags & NODE_FL_NEWLINE; switch (nd_type(node)) { end: case NODE_NIL: @@ -8466,9 +8467,11 @@ reduce_nodes_gen(struct parser_params *parser, NODE **body) return; case NODE_RETURN: *body = node = node->nd_stts; + if (newline && node) node->flags |= NODE_FL_NEWLINE; continue; case NODE_BEGIN: *body = node = node->nd_body; + if (newline && node) node->flags |= NODE_FL_NEWLINE; continue; case NODE_BLOCK: body = &node->nd_end->nd_head; @@ -8492,6 +8495,7 @@ reduce_nodes_gen(struct parser_params *parser, NODE **body) return; } node = *body; + if (newline && node) node->flags |= NODE_FL_NEWLINE; } #undef subnodes diff --git a/test/ruby/test_settracefunc.rb b/test/ruby/test_settracefunc.rb index 9486163770..7fd7cc6534 100644 --- a/test/ruby/test_settracefunc.rb +++ b/test/ruby/test_settracefunc.rb @@ -129,6 +129,89 @@ class TestSetTraceFunc < Test::Unit::TestCase assert_equal([], events) end + def test_return # [ruby-dev:38701] + events = [] + eval <<-EOF.gsub(/^.*?: /, "") + 1: set_trace_func(Proc.new { |event, file, lineno, mid, binding, klass| + 2: events << [event, lineno, mid, klass] + 3: }) + 4: def foo(a) + 5: return if a + 6: return + 7: end + 8: foo(true) + 9: foo(false) + 10: set_trace_func(nil) + EOF + assert_equal(["c-return", 3, :set_trace_func, Kernel], + events.shift) + assert_equal(["line", 4, __method__, self.class], + events.shift) + assert_equal(["c-call", 4, :method_added, Module], + events.shift) + assert_equal(["c-return", 4, :method_added, Module], + events.shift) + assert_equal(["line", 8, __method__, self.class], + events.shift) + assert_equal(["call", 4, :foo, self.class], + events.shift) + assert_equal(["line", 5, :foo, self.class], + events.shift) + assert_equal(["return", 5, :foo, self.class], + events.shift) + assert_equal(["line", 9, :test_return, self.class], + events.shift) + assert_equal(["call", 4, :foo, self.class], + events.shift) + assert_equal(["line", 5, :foo, self.class], + events.shift) + assert_equal(["return", 7, :foo, self.class], + events.shift) + assert_equal(["line", 10, :test_return, self.class], + events.shift) + assert_equal(["c-call", 10, :set_trace_func, Kernel], + events.shift) + assert_equal([], events) + end + + def test_return2 # [ruby-core:24463] + events = [] + eval <<-EOF.gsub(/^.*?: /, "") + 1: set_trace_func(Proc.new { |event, file, lineno, mid, binding, klass| + 2: events << [event, lineno, mid, klass] + 3: }) + 4: def foo + 5: a = 5 + 6: return a + 7: end + 8: foo + 9: set_trace_func(nil) + EOF + assert_equal(["c-return", 3, :set_trace_func, Kernel], + events.shift) + assert_equal(["line", 4, __method__, self.class], + events.shift) + assert_equal(["c-call", 4, :method_added, Module], + events.shift) + assert_equal(["c-return", 4, :method_added, Module], + events.shift) + assert_equal(["line", 8, __method__, self.class], + events.shift) + assert_equal(["call", 4, :foo, self.class], + events.shift) + assert_equal(["line", 5, :foo, self.class], + events.shift) + assert_equal(["line", 6, :foo, self.class], + events.shift) + assert_equal(["return", 7, :foo, self.class], + events.shift) + assert_equal(["line", 9, :test_return2, self.class], + events.shift) + assert_equal(["c-call", 9, :set_trace_func, Kernel], + events.shift) + assert_equal([], events) + end + def test_raise events = [] eval <<-EOF.gsub(/^.*?: /, "") diff --git a/version.h b/version.h index b029f873d4..7a66965cf6 100644 --- a/version.h +++ b/version.h @@ -1,5 +1,5 @@ #define RUBY_VERSION "1.9.1" -#define RUBY_PATCHLEVEL 296 +#define RUBY_PATCHLEVEL 297 #define RUBY_VERSION_MAJOR 1 #define RUBY_VERSION_MINOR 9 #define RUBY_VERSION_TEENY 1