summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-05-07 02:25:43 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-05-07 02:25:43 +0000
commit11eb87013653ba6d2321ecf4db07fb052fe19a98 (patch)
tree50e25af0b8ca68222fd4af9e73779720b67e7b08
parentc8dbc43de6003e6d97bd5d7043598a481c4fa694 (diff)
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. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45850 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog7
-rw-r--r--test/ruby/test_variable.rb4
-rw-r--r--vm.c2
-rw-r--r--vm_eval.c8
4 files changed, 15 insertions, 6 deletions
diff --git a/ChangeLog b/ChangeLog
index 8938866..762d8b5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+Wed May 7 11:25:41 2014 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * 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@ruby-lang.org>
* parse.y (new_bv_gen): no duplicated names, if already added in
diff --git a/test/ruby/test_variable.rb b/test/ruby/test_variable.rb
index e6730f8..1c9b601 100644
--- a/test/ruby/test_variable.rb
+++ b/test/ruby/test_variable.rb
@@ -86,13 +86,13 @@ class TestVariable < Test::Unit::TestCase
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)
diff --git a/vm.c b/vm.c
index af5bcb2..4d41575 100644
--- a/vm.c
+++ b/vm.c
@@ -523,7 +523,7 @@ collect_local_variables_in_iseq(rb_iseq_t *iseq, const VALUE vars)
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;
diff --git a/vm_eval.c b/vm_eval.c
index f12e5d0..90acd5e 100644
--- a/vm_eval.c
+++ b/vm_eval.c
@@ -1886,7 +1886,7 @@ rb_catch_protect(VALUE t, rb_block_call_func *func, VALUE data, int *stateptr)
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)
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)
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);
}
/*