From 7253910df83611f0c2aa4f6c5a5718680b9aea60 Mon Sep 17 00:00:00 2001 From: matz Date: Sat, 28 Mar 1998 10:57:41 +0000 Subject: 1.1b9_05 bug fix git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/v1_1r@143 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- variable.c | 43 ++++++++++++++++--------------------------- 1 file changed, 16 insertions(+), 27 deletions(-) (limited to 'variable.c') diff --git a/variable.c b/variable.c index fa3a79516f..0827ebbec6 100644 --- a/variable.c +++ b/variable.c @@ -640,12 +640,12 @@ rb_gvar_defined(entry) } static int -gvar_i(key, entry, ary) +var_i(key, entry, ary) ID key; struct global_entry *entry; VALUE ary; { - ary_push(ary, str_new2(rb_id2name(entry->id))); + ary_push(ary, str_new2(rb_id2name(key))); return ST_CONTINUE; } @@ -653,13 +653,15 @@ VALUE f_global_variables() { VALUE ary = ary_new(); - char buf[3]; - char *s = "^&`'+123456789"; - - st_foreach(global_tbl, gvar_i, ary); - while (*s) { - sprintf(buf, "$%c", *s++); - ary_push(ary, str_new2(buf)); + char buf[4]; + char *s = "&`'+123456789"; + + st_foreach(global_tbl, var_i, ary); + if (!NIL_P(backref_get())) { + while (*s) { + sprintf(buf, "$%c", *s++); + ary_push(ary, str_new2(buf)); + } } return ary; } @@ -746,36 +748,23 @@ rb_ivar_defined(obj, id) return FALSE; } -static int -ivar_i(key, value, hash) - ID key; - VALUE value; - VALUE hash; -{ - if (rb_is_instance_id(key)) { - hash_aset(hash, str_new2(rb_id2name(key)), value); - } - return ST_CONTINUE; -} - VALUE obj_instance_variables(obj) VALUE obj; { - VALUE hash = hash_new(); + VALUE ary; switch (TYPE(obj)) { case T_OBJECT: case T_CLASS: case T_MODULE: + ary = ary_new(); if (ROBJECT(obj)->iv_tbl) { - st_foreach(ROBJECT(obj)->iv_tbl, ivar_i, hash); + st_foreach(ROBJECT(obj)->iv_tbl, var_i, ary); } - break; - default: - break; + return ary; } - return hash; + return Qnil; } VALUE -- cgit v1.2.3