From e55b415c2fa001bd91d8706c5492d2cb28393f88 Mon Sep 17 00:00:00 2001 From: usa Date: Wed, 9 Aug 2017 13:29:42 +0000 Subject: merge revision(s) 59202: [Backport #13690] compile.c: disallow next in once * compile.c (iseq_compile_each0): turned dregx context in "once" into "guarded" type from "block" type, to disallow `next`, `break`, `redo` as well as outside "once". [ruby-core:81805] [Bug #13690] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_3@59553 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 13 +++++++++++++ compile.c | 5 ++++- test/ruby/test_exception.rb | 11 ----------- test/ruby/test_syntax.rb | 8 ++++++++ version.h | 2 +- 5 files changed, 26 insertions(+), 13 deletions(-) diff --git a/ChangeLog b/ChangeLog index 7c61b73bfb..4104203254 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +Wed Aug 9 22:27:23 2017 NAKAMURA Usaku + + * test/ruby/test_syntax.rb (test_invalid_{break,next}): use + assert_in_out_err instead of assert_syntax_error because on ruby_2_3 + assert_syntax_error uses eval. + +Wed Aug 9 22:27:23 2017 Nobuyoshi Nakada + + * compile.c (iseq_compile_each0): turned dregx context in "once" + into "guarded" type from "block" type, to disallow `next`, + `break`, `redo` as well as outside "once". + [Bug #13690] + Wed Aug 9 21:28:34 2017 NAKAMURA Usaku * test/ruby/test_process.rb (test_rlimit_{name,value}): test in UTF-8 diff --git a/compile.c b/compile.c index d6eda2f553..0aea3acd92 100644 --- a/compile.c +++ b/compile.c @@ -28,6 +28,8 @@ #undef RUBY_UNTYPED_DATA_WARNING #define RUBY_UNTYPED_DATA_WARNING 0 +#define ISEQ_TYPE_ONCE_GUARD ISEQ_TYPE_DEFINED_GUARD + #define FIXNUM_INC(n, i) ((n)+(INT2FIX(i)&~FIXNUM_FLAG)) #define FIXNUM_OR(n, i) ((n)|INT2FIX(i)) @@ -5489,7 +5491,8 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node, int poped) int ic_index = iseq->body->is_size++; NODE *dregx_node = NEW_NODE(NODE_DREGX, node->u1.value, node->u2.value, node->u3.value); NODE *block_node = NEW_NODE(NODE_SCOPE, 0, dregx_node, 0); - const rb_iseq_t * block_iseq = NEW_CHILD_ISEQ(block_node, make_name_for_block(iseq), ISEQ_TYPE_BLOCK, line); + const rb_iseq_t *block_iseq = NEW_CHILD_ISEQ(block_node, make_name_for_block(iseq), + ISEQ_TYPE_ONCE_GUARD, line); ADD_INSN2(ret, line, once, block_iseq, INT2FIX(ic_index)); diff --git a/test/ruby/test_exception.rb b/test/ruby/test_exception.rb index 90ed39de2a..165f679e76 100644 --- a/test/ruby/test_exception.rb +++ b/test/ruby/test_exception.rb @@ -905,15 +905,4 @@ $stderr = $stdout; raise "\x82\xa0"') do |outs, errs, status| } end; end - - def test_break_in_once - assert_separately([], "#{<<-"begin;"}\n#{<<~'end;'}") - begin; - obj = Object.new - def obj.try - /#{break}/o - end - assert_raise(LocalJumpError, /proc-closure/) {obj.try} - end; - end end diff --git a/test/ruby/test_syntax.rb b/test/ruby/test_syntax.rb index eba5f6d851..56ea659191 100644 --- a/test/ruby/test_syntax.rb +++ b/test/ruby/test_syntax.rb @@ -453,8 +453,16 @@ WARN } end + def test_invalid_break + assert_syntax_error("def m; break; end", /Invalid break/) + assert_in_out_err([], '/#{break}/', [], /Invalid break \(SyntaxError\)$/) + assert_in_out_err([], '/#{break}/o', [], /Invalid break \(SyntaxError\)$/) + end + def test_invalid_next assert_syntax_error("def m; next; end", /Invalid next/) + assert_in_out_err([], '/#{next}/', [], /Invalid next \(SyntaxError\)$/) + assert_in_out_err([], '/#{next}/o', [], /Invalid next \(SyntaxError\)$/) end def test_lambda_with_space diff --git a/version.h b/version.h index d6662b1b86..3d12b34ac2 100644 --- a/version.h +++ b/version.h @@ -1,6 +1,6 @@ #define RUBY_VERSION "2.3.5" #define RUBY_RELEASE_DATE "2017-08-09" -#define RUBY_PATCHLEVEL 362 +#define RUBY_PATCHLEVEL 363 #define RUBY_RELEASE_YEAR 2017 #define RUBY_RELEASE_MONTH 8 -- cgit v1.2.3