ruby-changes:33769
From: nobu <ko1@a...>
Date: Wed, 7 May 2014 11:25:50 +0900 (JST)
Subject: [ruby-changes:33769] nobu:r45850 (trunk): vm_eval.c: exclude hidden variables
nobu 2014-05-07 11:25:43 +0900 (Wed, 07 May 2014) New Revision: 45850 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=45850 Log: vm_eval.c: exclude hidden variables * vm_eval.c (rb_f_local_variables): exclude variables hidden by shadowing. [ruby-core:60501] [Bug #9486] * vm.c (collect_local_variables_in_iseq): ditto. Modified files: trunk/ChangeLog trunk/test/ruby/test_variable.rb trunk/vm.c trunk/vm_eval.c Index: ChangeLog =================================================================== --- ChangeLog (revision 45849) +++ ChangeLog (revision 45850) @@ -1,3 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Wed May 7 11:25:41 2014 Nobuyoshi Nakada <nobu@r...> + + * vm_eval.c (rb_f_local_variables): exclude variables hidden by + shadowing. [ruby-core:60501] [Bug #9486] + + * vm.c (collect_local_variables_in_iseq): ditto. + Tue May 6 23:29:05 2014 Nobuyoshi Nakada <nobu@r...> * parse.y (new_bv_gen): no duplicated names, if already added in Index: vm_eval.c =================================================================== --- vm_eval.c (revision 45849) +++ vm_eval.c (revision 45850) @@ -1886,7 +1886,7 @@ rb_catch_protect(VALUE t, rb_block_call_ https://github.com/ruby/ruby/blob/trunk/vm_eval.c#L1886 static VALUE rb_f_local_variables(void) { - VALUE vars = rb_ary_new(); + VALUE vars = rb_hash_new(); rb_thread_t *th = GET_THREAD(); rb_control_frame_t *cfp = vm_get_ruby_level_caller_cfp(th, RUBY_VM_PREVIOUS_CONTROL_FRAME(th->cfp)); @@ -1900,7 +1900,7 @@ rb_f_local_variables(void) https://github.com/ruby/ruby/blob/trunk/vm_eval.c#L1900 const char *vname = rb_id2name(lid); /* should skip temporary variable */ if (vname) { - rb_ary_push(vars, ID2SYM(lid)); + rb_hash_aset(vars, ID2SYM(lid), Qtrue); } } } @@ -1922,7 +1922,9 @@ rb_f_local_variables(void) https://github.com/ruby/ruby/blob/trunk/vm_eval.c#L1922 break; } } - return vars; + /* TODO: rb_hash_keys() directly, or something not to depend on + * the order of st_table */ + return rb_funcallv(vars, rb_intern("keys"), 0, 0); } /* Index: vm.c =================================================================== --- vm.c (revision 45849) +++ vm.c (revision 45850) @@ -523,7 +523,7 @@ collect_local_variables_in_iseq(rb_iseq_ https://github.com/ruby/ruby/blob/trunk/vm.c#L523 for (i = 0; i < iseq->local_table_size; i++) { ID lid = iseq->local_table[i]; if (rb_is_local_id(lid)) { - rb_ary_push(vars, ID2SYM(lid)); + rb_hash_aset(vars, ID2SYM(lid), Qtrue); } } return 1; Index: test/ruby/test_variable.rb =================================================================== --- test/ruby/test_variable.rb (revision 45849) +++ test/ruby/test_variable.rb (revision 45850) @@ -86,13 +86,13 @@ class TestVariable < Test::Unit::TestCas https://github.com/ruby/ruby/blob/trunk/test/ruby/test_variable.rb#L86 def test_shadowing_local_variables bug9486 = '[ruby-core:60501] [Bug #9486]' x = tap {|x| break local_variables} - assert_equal([:x, :bug9486, :x], x) + assert_equal([:x, :bug9486], 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) + assert_equal([:x, :bug9486], x) end def local_variables_of(bind) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/