From cdacb127fc82920afed967222716d6775273432a Mon Sep 17 00:00:00 2001 From: matz Date: Fri, 1 Aug 2003 20:16:53 +0000 Subject: * class.c (rb_obj_singleton_methods): should not go up to ancestors unless the recursive flag is set. [ruby-list:38007] * hash.c (env_each_key): use env_keys to avoid environment modify on the fly. * hash.c (env_each_value): use env_values for safety. * hash.c (env_each): allocate environment array first. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@4277 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- hash.c | 54 +++++++++++++++++++++++++----------------------------- 1 file changed, 25 insertions(+), 29 deletions(-) (limited to 'hash.c') diff --git a/hash.c b/hash.c index 1a4ab1edbb..1e8a44e967 100644 --- a/hash.c +++ b/hash.c @@ -1296,21 +1296,16 @@ env_keys() } static VALUE -env_each_key(hash) - VALUE hash; +env_each_key(ehash) + VALUE ehash; { - char **env; + VALUE keys = env_keys(); + long i; - env = GET_ENVIRON(environ); - while (*env) { - char *s = strchr(*env, '='); - if (s) { - rb_yield(env_str_new(*env, s-*env)); - } - env++; + for (i=0; ilen; i++) { + rb_yield(RARRAY(keys)->ptr[i]); } - FREE_ENVIRON(environ); - return Qnil; + return ehash; } static VALUE @@ -1332,40 +1327,41 @@ env_values() } static VALUE -env_each_value(hash) - VALUE hash; +env_each_value(ehash) + VALUE ehash; { - char **env; + VALUE values = env_values(); + long i; - env = GET_ENVIRON(environ); - while (*env) { - char *s = strchr(*env, '='); - if (s) { - rb_yield(env_str_new2(s+1)); - } - env++; + for (i=0; ilen; i++) { + rb_yield(RARRAY(values)->ptr[i]); } - FREE_ENVIRON(environ); - return Qnil; + return ehash; } static VALUE -env_each(hash) - VALUE hash; +env_each(ehash) + VALUE ehash; { char **env; + VALUE ary = rb_ary_new(); + long i; env = GET_ENVIRON(environ); while (*env) { char *s = strchr(*env, '='); if (s) { - rb_yield_values(2, env_str_new(*env, s-*env), - env_str_new2(s+1)); + rb_ary_push(ary, env_str_new(*env, s-*env)); + rb_ary_push(ary, env_str_new2(s+1)); } env++; } FREE_ENVIRON(environ); - return Qnil; + + for (i=0; ilen; i+=2) { + rb_yield_values(2, RARRAY(ary)->ptr[i], RARRAY(ary)->ptr[i+1]); + } + return ehash; } static VALUE -- cgit v1.2.3