summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog7
-rw-r--r--file.c2
-rw-r--r--hash.c45
-rw-r--r--lib/cgi.rb2
-rw-r--r--test/drb/drbtest.rb2
5 files changed, 51 insertions, 7 deletions
diff --git a/ChangeLog b/ChangeLog
index 4cc96ab..57abeb7 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+Fri Oct 24 23:26:34 2003 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * hash.c (rb_hash_each): Hash#each should yield single value.
+ [ruby-talk:84420]
+
+ * hash.c (env_each): ditto for ENV.each.
+
Thu Oct 23 20:25:32 2003 GOTOU Yuuzou <gotoyuzo@notwork.org>
* lib/webrick/server.rb (GenericServer#start): should rescue
diff --git a/file.c b/file.c
index 4f78b81..3fe8150 100644
--- a/file.c
+++ b/file.c
@@ -97,7 +97,7 @@ rb_file_path(obj)
{
OpenFile *fptr;
- GetOpenFile(obj, fptr);
+ fptr = RFILE(rb_io_taint_check(obj))->fptr;
if (!fptr->path) return Qnil;
return rb_str_new2(fptr->path);
}
diff --git a/hash.c b/hash.c
index 1e8a44e..245f6fb 100644
--- a/hash.c
+++ b/hash.c
@@ -671,6 +671,23 @@ rb_hash_each_pair(hash)
return hash;
}
+static enum st_retval
+each_i(key, value)
+ VALUE key, value;
+{
+ if (key == Qundef) return ST_CONTINUE;
+ rb_yield(rb_assoc_new(key, value));
+ return ST_CONTINUE;
+}
+
+static VALUE
+rb_hash_each(hash)
+ VALUE hash;
+{
+ rb_hash_foreach(hash, each_i, 0);
+ return hash;
+}
+
static int
to_a_i(key, value, ary)
VALUE key, value, ary;
@@ -1340,8 +1357,9 @@ env_each_value(ehash)
}
static VALUE
-env_each(ehash)
+env_each_i(ehash, values)
VALUE ehash;
+ int values;
{
char **env;
VALUE ary = rb_ary_new();
@@ -1359,12 +1377,31 @@ env_each(ehash)
FREE_ENVIRON(environ);
for (i=0; i<RARRAY(ary)->len; i+=2) {
- rb_yield_values(2, RARRAY(ary)->ptr[i], RARRAY(ary)->ptr[i+1]);
+ if (values) {
+ rb_yield_values(2, RARRAY(ary)->ptr[i], RARRAY(ary)->ptr[i+1]);
+ }
+ else {
+ rb_yield(rb_assoc_new(RARRAY(ary)->ptr[i], RARRAY(ary)->ptr[i+1]));
+ }
}
return ehash;
}
static VALUE
+env_each(ehash)
+ VALUE ehash;
+{
+ return env_each_i(ehash, Qfalse);
+}
+
+static VALUE
+env_each_pair(ehash)
+ VALUE ehash;
+{
+ return env_each_i(ehash, Qtrue);
+}
+
+static VALUE
env_reject_bang()
{
volatile VALUE keys;
@@ -1779,7 +1816,7 @@ Init_Hash()
rb_define_method(rb_cHash,"length", rb_hash_size, 0);
rb_define_method(rb_cHash,"empty?", rb_hash_empty_p, 0);
- rb_define_method(rb_cHash,"each", rb_hash_each_pair, 0);
+ rb_define_method(rb_cHash,"each", rb_hash_each, 0);
rb_define_method(rb_cHash,"each_value", rb_hash_each_value, 0);
rb_define_method(rb_cHash,"each_key", rb_hash_each_key, 0);
rb_define_method(rb_cHash,"each_pair", rb_hash_each_pair, 0);
@@ -1819,7 +1856,7 @@ Init_Hash()
rb_define_singleton_method(envtbl,"[]=", env_aset, 2);
rb_define_singleton_method(envtbl,"store", env_aset, 2);
rb_define_singleton_method(envtbl,"each", env_each, 0);
- rb_define_singleton_method(envtbl,"each_pair", env_each, 0);
+ rb_define_singleton_method(envtbl,"each_pair", env_each_pair, 0);
rb_define_singleton_method(envtbl,"each_key", env_each_key, 0);
rb_define_singleton_method(envtbl,"each_value", env_each_value, 0);
rb_define_singleton_method(envtbl,"delete", env_delete_m, 1);
diff --git a/lib/cgi.rb b/lib/cgi.rb
index a55c9ca..c380f9a 100644
--- a/lib/cgi.rb
+++ b/lib/cgi.rb
@@ -1027,7 +1027,7 @@ class CGI
buf = buf.sub(/\A((?:.|\n)*?)(?:#{EOL})?#{boundary}(#{EOL}|--)/n) do
body.print $1
- if "--" == $2
+ if "--" == $2 or EOL == $2
content_length = -1
end
""
diff --git a/test/drb/drbtest.rb b/test/drb/drbtest.rb
index cc3c4d4..128acf7 100644
--- a/test/drb/drbtest.rb
+++ b/test/drb/drbtest.rb
@@ -213,7 +213,7 @@ module DRbCore
end
def test_10_yield_undumped
- @there.xarray2_hash.each do |k, v|
+ @there.xarray2_hash.each_pair do |k, v|
assert_kind_of(String, k)
assert_kind_of(DRbObject, v)
end