diff options
| author | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2003-08-01 20:16:53 +0000 |
|---|---|---|
| committer | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2003-08-01 20:16:53 +0000 |
| commit | 55c60fa4a1c9f6476795670aab0ba595a640f377 (patch) | |
| tree | e03d777bdac7dd2a882e7848a8b2f7c3b73f09ee /hash.c | |
| parent | 8d826f9e27d8899c51393c37a0af31b52edad351 (diff) | |
| download | ruby-55c60fa4a1c9f6476795670aab0ba595a640f377.tar.gz ruby-55c60fa4a1c9f6476795670aab0ba595a640f377.tar.xz ruby-55c60fa4a1c9f6476795670aab0ba595a640f377.zip | |
* 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: http://svn.ruby-lang.org/repos/ruby/trunk@4277 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'hash.c')
| -rw-r--r-- | hash.c | 54 |
1 files changed, 25 insertions, 29 deletions
@@ -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; i<RARRAY(keys)->len; 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; i<RARRAY(values)->len; 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; i<RARRAY(ary)->len; i+=2) { + rb_yield_values(2, RARRAY(ary)->ptr[i], RARRAY(ary)->ptr[i+1]); + } + return ehash; } static VALUE |
