diff options
author | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 1999-02-24 04:31:29 +0000 |
---|---|---|
committer | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 1999-02-24 04:31:29 +0000 |
commit | 3976feed73bf4ec27183824870ee077c2b5b00b1 (patch) | |
tree | cb461ab9246a2c8e13d373a8c2d2e6378e4db9cc /hash.c | |
parent | 51fa86ece2d2b0f72c86c70fe1314e412c7a9e68 (diff) |
990224
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_3@405 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'hash.c')
-rw-r--r-- | hash.c | 68 |
1 files changed, 50 insertions, 18 deletions
@@ -12,6 +12,7 @@ #include "ruby.h" #include "st.h" +#include "util.h" #include "rubysig.h" #include <sys/types.h> @@ -131,7 +132,7 @@ rb_hash_foreach_iter(key, value, arg) st_table *tbl = RHASH(arg->hash)->tbl; struct st_table_entry **bins = tbl->bins; - if (key == Qnil) return ST_CONTINUE; + if (value == Qnil) return ST_CONTINUE; status = (*arg->func)(key, value, arg->arg); if (RHASH(arg->hash)->tbl != tbl || RHASH(arg->hash)->tbl->bins != bins){ rb_raise(rb_eIndexError, "rehash occurred during iteration"); @@ -432,7 +433,7 @@ shift_i(key, value, var) VALUE key, value; struct shift_var *var; { - if (key == Qnil) return ST_CONTINUE; + if (value == Qnil) return ST_CONTINUE; if (var->stop) return ST_STOP; var->stop = 1; var->key = key; @@ -458,7 +459,7 @@ static int delete_if_i(key, value) VALUE key, value; { - if (key == Qnil) return ST_CONTINUE; + if (value == Qnil) return ST_CONTINUE; if (RTEST(rb_yield(rb_assoc_new(key, value)))) return ST_DELETE; return ST_CONTINUE; @@ -548,7 +549,7 @@ static int each_value_i(key, value) VALUE key, value; { - if (key == Qnil) return ST_CONTINUE; + if (value == Qnil) return ST_CONTINUE; rb_yield(value); return ST_CONTINUE; } @@ -565,7 +566,7 @@ static int each_key_i(key, value) VALUE key, value; { - if (key == Qnil) return ST_CONTINUE; + if (value == Qnil) return ST_CONTINUE; rb_yield(key); return ST_CONTINUE; } @@ -582,7 +583,7 @@ static int each_pair_i(key, value) VALUE key, value; { - if (key == Qnil) return ST_CONTINUE; + if (value == Qnil) return ST_CONTINUE; rb_yield(rb_assoc_new(key, value)); return ST_CONTINUE; } @@ -599,7 +600,7 @@ static int to_a_i(key, value, ary) VALUE key, value, ary; { - if (key == Qnil) return ST_CONTINUE; + if (value == Qnil) return ST_CONTINUE; rb_ary_push(ary, rb_assoc_new(key, value)); return ST_CONTINUE; } @@ -629,7 +630,7 @@ inspect_i(key, value, str) { VALUE str2; - if (key == Qnil) return ST_CONTINUE; + if (value == Qnil) return ST_CONTINUE; if (RSTRING(str)->len > 1) { rb_str_cat(str, ", ", 2); } @@ -691,7 +692,7 @@ static int keys_i(key, value, ary) VALUE key, value, ary; { - if (key == Qnil) return ST_CONTINUE; + if (value == Qnil) return ST_CONTINUE; rb_ary_push(ary, key); return ST_CONTINUE; } @@ -712,7 +713,7 @@ static int values_i(key, value, ary) VALUE key, value, ary; { - if (key == Qnil) return ST_CONTINUE; + if (value == Qnil) return ST_CONTINUE; rb_ary_push(ary, value); return ST_CONTINUE; } @@ -744,7 +745,7 @@ static int rb_hash_search_value(key, value, data) VALUE key, value, *data; { - if (key == Qnil) return ST_CONTINUE; + if (value == Qnil) return ST_CONTINUE; if (rb_equal(value, data[1])) { data[0] = Qtrue; return ST_STOP; @@ -777,7 +778,7 @@ equal_i(key, val1, data) { VALUE val2; - if (key == Qnil) return ST_CONTINUE; + if (val1 == Qnil) return ST_CONTINUE; if (!st_lookup(data->tbl, key, &val2)) { data->result = Qfalse; return ST_STOP; @@ -811,7 +812,7 @@ rb_hash_invert_i(key, value, hash) VALUE key, value; VALUE hash; { - if (key == Qnil) return ST_CONTINUE; + if (value == Qnil) return ST_CONTINUE; rb_hash_aset(hash, value, key); return ST_CONTINUE; } @@ -831,7 +832,7 @@ rb_hash_update_i(key, value, hash) VALUE key, value; VALUE hash; { - if (key == Qnil) return ST_CONTINUE; + if (value == Qnil) return ST_CONTINUE; rb_hash_aset(hash, key, value); return ST_CONTINUE; } @@ -852,6 +853,24 @@ extern char **environ; #endif static char **origenviron; +void +ruby_unsetenv(name) + char *name; +{ + int i, len; + + len = strlen(name); + for(i=0; environ[i]; i++) { + if (strncmp(environ[i], name, len) == 0 && environ[i][len] == '=') { + break; + } + } + while (environ[i]) { + environ[i] = environ[i+1]; + i++; + } +} + static VALUE env_delete(obj, name) VALUE obj, name; @@ -861,7 +880,9 @@ env_delete(obj, name) rb_secure(4); nam = STR2CSTR(name); - if (strcmp(nam, "PATH") == 0) path_tainted = 0; + if (strcmp(nam, "PATH") == 0 && !OBJ_TAINTED(name)) { + path_tainted = 0; + } len = strlen(nam); for(i=0; environ[i]; i++) { if (strncmp(environ[i], nam, len) == 0 && environ[i][len] == '=') { @@ -991,8 +1012,8 @@ char *nam; return i; } -static void -my_setenv(name, value) +void +ruby_setenv(name, value) char *name; char *value; { @@ -1098,6 +1119,17 @@ my_setenv(name, value) #endif /* WIN32 */ } +void +ruby_setenv2(name, value) + char *name; + char *value; +{ + if (value == NULL) { + ruby_unsetenv(name); + } + ruby_setenv(name, value); +} + static VALUE rb_f_setenv(obj, nm, val) VALUE obj, nm, val; @@ -1121,7 +1153,7 @@ rb_f_setenv(obj, nm, val) if (strlen(value) != vlen) rb_raise(rb_eArgError, "Bad environment value"); - my_setenv(name, value); + ruby_setenv(name, value); if (strcmp(name, "PATH") == 0) { if (OBJ_TAINTED(val)) { /* already tainted, no check */ |