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

ruby-changes:41456

From: nobu <ko1@a...>
Date: Thu, 14 Jan 2016 11:44:36 +0900 (JST)
Subject: [ruby-changes:41456] nobu:r53530 (trunk): variable.c: $1..$9 in global_variables

nobu	2016-01-14 11:45:03 +0900 (Thu, 14 Jan 2016)

  New Revision: 53530

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

  Log:
    variable.c: $1..$9 in global_variables
    
    * variable.c (rb_f_global_variables): add $1..$9 only if $~ is
      set.  fix the condition removed at r14014.

  Modified files:
    trunk/ChangeLog
    trunk/test/ruby/test_variable.rb
    trunk/variable.c
Index: variable.c
===================================================================
--- variable.c	(revision 53529)
+++ variable.c	(revision 53530)
@@ -880,14 +880,16 @@ VALUE https://github.com/ruby/ruby/blob/trunk/variable.c#L880
 rb_f_global_variables(void)
 {
     VALUE ary = rb_ary_new();
-    char buf[2];
-    int i;
 
     rb_id_table_foreach(rb_global_tbl, gvar_i, (void *)ary);
-    buf[0] = '$';
-    for (i = 1; i <= 9; ++i) {
-	buf[1] = (char)(i + '0');
-	rb_ary_push(ary, ID2SYM(rb_intern2(buf, 2)));
+    if (!NIL_P(rb_backref_get())) {
+	char buf[2];
+	int i;
+	buf[0] = '$';
+	for (i = 1; i <= 9; ++i) {
+	    buf[1] = (char)(i + '0');
+	    rb_ary_push(ary, ID2SYM(rb_intern2(buf, 2)));
+	}
     }
     return ary;
 }
Index: test/ruby/test_variable.rb
===================================================================
--- test/ruby/test_variable.rb	(revision 53529)
+++ test/ruby/test_variable.rb	(revision 53530)
@@ -100,6 +100,16 @@ class TestVariable < Test::Unit::TestCas https://github.com/ruby/ruby/blob/trunk/test/ruby/test_variable.rb#L100
     assert_equal([:x, :bug9486], x)
   end
 
+  def test_global_variables
+    gv = global_variables
+    assert_empty(gv.grep(/\A(?!\$)/))
+    assert_nil($~)
+    assert_not_include(gv, :$1)
+    /.*/ =~ "global"
+    assert_not_nil($~)
+    assert_include(global_variables-gv, :$1)
+  end
+
   def test_global_variable_0
     assert_in_out_err(["-e", "$0='t'*1000;print $0"], "", /\At+\z/, [])
   end
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 53529)
+++ ChangeLog	(revision 53530)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Thu Jan 14 11:44:29 2016  Nobuyoshi Nakada  <nobu@r...>
+
+	* variable.c (rb_f_global_variables): add $1..$9 only if $~ is
+	  set.  fix the condition removed at r14014.
+
 Wed Jan 13 17:21:45 2016  SHIBATA Hiroshi  <hsbt@r...>
 
 	* .travis.yml: removed commented-out code.

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

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