summaryrefslogtreecommitdiff
path: root/vm_eval.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-07-01 17:57:37 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-07-01 17:57:37 +0000
commit1a2b90d5e6c7b6ecd1d4c0ba9445fb730b39776b (patch)
tree973b19a521528d0a87c2c77e7f57cd6707f1cb38 /vm_eval.c
parent0fdb18e513b53e71911c57a7b5fddd86c3a17704 (diff)
vm.c: rb_vm_env_local_variables
* vm.c (rb_vm_env_local_variables): returns array of local variable name symbols in the environment by envval. * proc.c (bind_local_variables): use rb_vm_env_local_variables. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46648 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'vm_eval.c')
-rw-r--r--vm_eval.c28
1 files changed, 20 insertions, 8 deletions
diff --git a/vm_eval.c b/vm_eval.c
index 6b38d40d93..a67c75cb6d 100644
--- a/vm_eval.c
+++ b/vm_eval.c
@@ -1876,6 +1876,24 @@ rb_catch_protect(VALUE t, rb_block_call_func *func, VALUE data, int *stateptr)
return val;
}
+static void
+local_var_list_init(struct local_var_list *vars)
+{
+ vars->tbl = rb_hash_new();
+ RHASH(vars->tbl)->ntbl = st_init_numtable(); /* compare_by_identity */
+ RBASIC_CLEAR_CLASS(vars->tbl);
+}
+
+static VALUE
+local_var_list_finish(struct local_var_list *vars)
+{
+ /* TODO: not to depend on the order of st_table */
+ VALUE ary = rb_hash_keys(vars->tbl);
+ rb_hash_clear(vars->tbl);
+ vars->tbl = 0;
+ return ary;
+}
+
static int
local_var_list_update(st_data_t *key, st_data_t *value, st_data_t arg, int existing)
{
@@ -1912,15 +1930,12 @@ static VALUE
rb_f_local_variables(void)
{
struct local_var_list vars;
- VALUE ary;
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));
int i;
- vars.tbl = rb_hash_new();
- RHASH(vars.tbl)->ntbl = st_init_numtable(); /* compare_by_identity */
- RBASIC_CLEAR_CLASS(vars.tbl);
+ local_var_list_init(&vars);
while (cfp) {
if (cfp->iseq) {
for (i = 0; i < cfp->iseq->local_table_size; i++) {
@@ -1944,10 +1959,7 @@ rb_f_local_variables(void)
break;
}
}
- /* TODO: not to depend on the order of st_table */
- ary = rb_hash_keys(vars.tbl);
- rb_hash_clear(vars.tbl);
- return ary;
+ return local_var_list_finish(&vars);
}
/*