1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

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.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53530 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2016-01-14 02:45:03 +00:00
parent d5c5d5c778
commit 7e825eeefc
3 changed files with 23 additions and 6 deletions

View file

@ -1,3 +1,8 @@
Thu Jan 14 11:44:29 2016 Nobuyoshi Nakada <nobu@ruby-lang.org>
* 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@ruby-lang.org> Wed Jan 13 17:21:45 2016 SHIBATA Hiroshi <hsbt@ruby-lang.org>
* .travis.yml: removed commented-out code. * .travis.yml: removed commented-out code.

View file

@ -100,6 +100,16 @@ class TestVariable < Test::Unit::TestCase
assert_equal([:x, :bug9486], x) assert_equal([:x, :bug9486], x)
end 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 def test_global_variable_0
assert_in_out_err(["-e", "$0='t'*1000;print $0"], "", /\At+\z/, []) assert_in_out_err(["-e", "$0='t'*1000;print $0"], "", /\At+\z/, [])
end end

View file

@ -880,14 +880,16 @@ VALUE
rb_f_global_variables(void) rb_f_global_variables(void)
{ {
VALUE ary = rb_ary_new(); VALUE ary = rb_ary_new();
char buf[2];
int i;
rb_id_table_foreach(rb_global_tbl, gvar_i, (void *)ary); rb_id_table_foreach(rb_global_tbl, gvar_i, (void *)ary);
buf[0] = '$'; if (!NIL_P(rb_backref_get())) {
for (i = 1; i <= 9; ++i) { char buf[2];
buf[1] = (char)(i + '0'); int i;
rb_ary_push(ary, ID2SYM(rb_intern2(buf, 2))); buf[0] = '$';
for (i = 1; i <= 9; ++i) {
buf[1] = (char)(i + '0');
rb_ary_push(ary, ID2SYM(rb_intern2(buf, 2)));
}
} }
return ary; return ary;
} }