[前][次][番号順一覧][スレッド一覧]

ruby-changes:34515

From: nagachika <ko1@a...>
Date: Sat, 28 Jun 2014 14:52:06 +0900 (JST)
Subject: [ruby-changes:34515] nagachika:r46596 (ruby_2_1): merge revision(s) r45845, r45846, r45847: [Backport #9486]

nagachika	2014-06-28 14:51:57 +0900 (Sat, 28 Jun 2014)

  New Revision: 46596

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=46596

  Log:
    merge revision(s) r45845,r45846,r45847: [Backport #9486]
    
    * parse.y (local_tbl_gen): remove local variables duplicated with
      arguments.
    
    * parse.y (new_bv_gen): no duplicated names, if already added in
      shadowing_lvar().
      [ruby-core:60501] [Bug #9486]

  Modified directories:
    branches/ruby_2_1/
  Modified files:
    branches/ruby_2_1/ChangeLog
    branches/ruby_2_1/parse.y
    branches/ruby_2_1/test/ruby/test_variable.rb
    branches/ruby_2_1/version.h
Index: ruby_2_1/ChangeLog
===================================================================
--- ruby_2_1/ChangeLog	(revision 46595)
+++ ruby_2_1/ChangeLog	(revision 46596)
@@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_1/ChangeLog#L1
+Sat Jun 28 14:37:17 2014  Nobuyoshi Nakada  <nobu@r...>
+
+	* parse.y (local_tbl_gen): remove local variables duplicated with
+	  arguments.
+	  [ruby-core:60501] [Bug #9486]
+
 Tue Jun 24 00:21:58 2014  Koichi Sasada  <ko1@a...>
 
 	* eval.c (rb_using_refinement): add write-barriers for
Index: ruby_2_1/parse.y
===================================================================
--- ruby_2_1/parse.y	(revision 46595)
+++ ruby_2_1/parse.y	(revision 46596)
@@ -8751,10 +8751,10 @@ is_private_local_id(ID name) https://github.com/ruby/ruby/blob/trunk/ruby_2_1/parse.y#L8751
 
 #define LVAR_USED ((ID)1 << (sizeof(ID) * CHAR_BIT - 1))
 
-static ID
-shadowing_lvar_gen(struct parser_params *parser, ID name)
+static int
+shadowing_lvar_0(struct parser_params *parser, ID name)
 {
-    if (is_private_local_id(name)) return name;
+    if (is_private_local_id(name)) return 1;
     if (dyna_in_block()) {
 	if (dvar_curr(name)) {
 	    yyerror("duplicated argument name");
@@ -8765,6 +8765,7 @@ shadowing_lvar_gen(struct parser_params https://github.com/ruby/ruby/blob/trunk/ruby_2_1/parse.y#L8765
 	    if (lvtbl->used) {
 		vtable_add(lvtbl->used, (ID)ruby_sourceline | LVAR_USED);
 	    }
+	    return 0;
 	}
     }
     else {
@@ -8772,6 +8773,13 @@ shadowing_lvar_gen(struct parser_params https://github.com/ruby/ruby/blob/trunk/ruby_2_1/parse.y#L8773
 	    yyerror("duplicated argument name");
 	}
     }
+    return 1;
+}
+
+static ID
+shadowing_lvar_gen(struct parser_params *parser, ID name)
+{
+    shadowing_lvar_0(parser, name);
     return name;
 }
 
@@ -8784,7 +8792,7 @@ new_bv_gen(struct parser_params *parser, https://github.com/ruby/ruby/blob/trunk/ruby_2_1/parse.y#L8792
 		      rb_id2name(name));
 	return;
     }
-    shadowing_lvar(name);
+    if (!shadowing_lvar_0(parser, name)) return;
     dyna_var(name);
 }
 
@@ -9687,30 +9695,25 @@ local_pop_gen(struct parser_params *pars https://github.com/ruby/ruby/blob/trunk/ruby_2_1/parse.y#L9695
 
 #ifndef RIPPER
 static ID*
-vtable_tblcpy(ID *buf, const struct vtable *src)
-{
-    int i, cnt = vtable_size(src);
-
-    if (cnt > 0) {
-        buf[0] = cnt;
-        for (i = 0; i < cnt; i++) {
-            buf[i] = src->tbl[i];
-        }
-        return buf;
-    }
-    return 0;
-}
-
-static ID*
 local_tbl_gen(struct parser_params *parser)
 {
-    int cnt = vtable_size(lvtbl->args) + vtable_size(lvtbl->vars);
+    int cnt_args = vtable_size(lvtbl->args);
+    int cnt_vars = vtable_size(lvtbl->vars);
+    int cnt = cnt_args + cnt_vars;
+    int i, j;
     ID *buf;
 
     if (cnt <= 0) return 0;
     buf = ALLOC_N(ID, cnt + 1);
-    vtable_tblcpy(buf+1, lvtbl->args);
-    vtable_tblcpy(buf+vtable_size(lvtbl->args)+1, lvtbl->vars);
+    MEMCPY(buf+1, lvtbl->args->tbl, ID, cnt_args);
+    /* remove IDs duplicated to warn shadowing */
+    for (i = 0, j = cnt_args+1; i < cnt_vars; ++i) {
+	ID id = lvtbl->vars->tbl[i];
+	if (!vtable_included(lvtbl->args, id)) {
+	    buf[j++] = id;
+	}
+    }
+    if (--j < cnt) REALLOC_N(buf, ID, (cnt = j) + 1);
     buf[0] = cnt;
     return buf;
 }
Index: ruby_2_1/version.h
===================================================================
--- ruby_2_1/version.h	(revision 46595)
+++ ruby_2_1/version.h	(revision 46596)
@@ -1,10 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_1/version.h#L1
 #define RUBY_VERSION "2.1.2"
-#define RUBY_RELEASE_DATE "2014-06-24"
-#define RUBY_PATCHLEVEL 142
+#define RUBY_RELEASE_DATE "2014-06-28"
+#define RUBY_PATCHLEVEL 143
 
 #define RUBY_RELEASE_YEAR 2014
 #define RUBY_RELEASE_MONTH 6
-#define RUBY_RELEASE_DAY 24
+#define RUBY_RELEASE_DAY 28
 
 #include "ruby/version.h"
 
Index: ruby_2_1/test/ruby/test_variable.rb
===================================================================
--- ruby_2_1/test/ruby/test_variable.rb	(revision 46595)
+++ ruby_2_1/test/ruby/test_variable.rb	(revision 46596)
@@ -83,6 +83,18 @@ class TestVariable < Test::Unit::TestCas https://github.com/ruby/ruby/blob/trunk/ruby_2_1/test/ruby/test_variable.rb#L83
     end.call
   end
 
+  def test_shadowing_local_variables
+    bug9486 = '[ruby-core:60501] [Bug #9486]'
+    x = tap {|x| break local_variables}
+    assert_equal([:x, :bug9486, :x], x)
+  end
+
+  def test_shadowing_block_local_variables
+    bug9486 = '[ruby-core:60501] [Bug #9486]'
+    x = tap {|;x| break local_variables}
+    assert_equal([:x, :bug9486, :x], x)
+  end
+
   def test_global_variable_0
     assert_in_out_err(["-e", "$0='t'*1000;print $0"], "", /\At+\z/, [])
   end

Property changes on: ruby_2_1
___________________________________________________________________
Modified: svn:mergeinfo
   Merged /trunk:r45845-45847


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]