summaryrefslogtreecommitdiff
path: root/hash.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-08-01 20:16:53 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-08-01 20:16:53 +0000
commitcdacb127fc82920afed967222716d6775273432a (patch)
treee03d777bdac7dd2a882e7848a8b2f7c3b73f09ee /hash.c
parentbaf02b9a6330acff09c80f27cfc2e7b8536f5f68 (diff)
* 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
Diffstat (limited to 'hash.c')
-rw-r--r--hash.c54
1 files changed, 25 insertions, 29 deletions
diff --git a/hash.c b/hash.c
index 1a4ab1e..1e8a44e 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; 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