[#42369] [BUG: trunk] Lazy sweep and ObjectSpace.each_object — SASADA Koichi <ko1@...>

 ささだです。

14 messages 2010/10/13

[#42375] [Ruby 1.9-Feature#3946][Open] Array#packのqQ指定子に機種依存サイズフラグ!を追加 — Yui NARUSE <redmine@...>

Feature #3946: Array#packのqQ指定子に機種依存サイズフラグ!を追加

19 messages 2010/10/14
[#42380] Re: [Ruby 1.9-Feature#3946][Open] Array#packのqQ指定子に機種依存サイズフラグ!を追加 — Tanaka Akira <akr@...> 2010/10/14

2010年10月14日15:36 Yui NARUSE <redmine@ruby-lang.org>:

[#42381] Re: [Ruby 1.9-Feature#3946][Open] Array#packのqQ指定子に機種依存サイズフラグ!を追加 — "NARUSE, Yui" <naruse@...> 2010/10/14

(2010/10/14 21:07), Tanaka Akira wrote:

[#42619] [Ruby 1.9-Feature#3946][Open] Array#packのqQ指定子に機種依存サイズフラグ!を追加 — Usaku NAKAMURA <redmine@...> 2010/11/25

チケット #3946 が更新されました。 (by Usaku NAKAMURA)

[#42376] [Ruby 1.9-Feature#3947][Open] Array#packのにエンディアン指定修飾子</>を追加 — Yui NARUSE <redmine@...>

Feature #3947: Array#packのにエンディアン指定修飾子</>を追加

9 messages 2010/10/14

[#42464] [Ruby 1.9-Bug#3990][Assigned] tests of rexml/rss reports many errors and failures without iconv — Usaku NAKAMURA <redmine@...>

Bug #3990: tests of rexml/rss reports many errors and failures without iconv

40 messages 2010/10/27
[#42500] [Ruby 1.9-Bug#3990][Closed] tests of rexml/rss reports many errors and failures without iconv — Kouhei Sutou <redmine@...> 2010/10/30

チケット #3990 が更新されました。 (by Kouhei Sutou)

[#42510] Re: [Ruby 1.9-Bug#3990][Closed] tests of rexml/rss reports many errors and failures without iconv — "NARUSE, Yui" <naruse@...> 2010/11/01

成瀬です。

[#42514] Re: [Ruby 1.9-Bug#3990][Closed] tests of rexml/rss reports many errors and failures without iconv — Kouhei Sutou <kou@...> 2010/11/02

須藤です。

[#42515] Re: [Ruby 1.9-Bug#3990][Closed] tests of rexml/rss reports many errors and failures without iconv — "NARUSE, Yui" <naruse@...> 2010/11/02

(2010/11/02 21:50), Kouhei Sutou wrote:

[#42516] Re: [Ruby 1.9-Bug#3990][Closed] tests of rexml/rss reports many errors and failures without iconv — Kouhei Sutou <kou@...> 2010/11/02

須藤です。

[#42517] Re: [Ruby 1.9-Bug#3990][Closed] tests of rexml/rss reports many errors and failures without iconv — "NARUSE, Yui" <naruse@...> 2010/11/02

成瀬です。

[#42518] Re: [Ruby 1.9-Bug#3990][Closed] tests of rexml/rss reports many errors and failures without iconv — Kouhei Sutou <kou@...> 2010/11/02

須藤です。

[#42519] Re: [Ruby 1.9-Bug#3990][Closed] tests of rexml/rss reports many errors and failures without iconv — "NARUSE, Yui" <naruse@...> 2010/11/03

成瀬です。

[#42543] Re: [Ruby 1.9-Bug#3990][Closed] tests of rexml/rss reports many errors and failures without iconv — Kouhei Sutou <kou@...> 2010/11/06

須藤です。

[#42548] Re: [Ruby 1.9-Bug#3990][Closed] tests of rexml/rss reports many errors and failures without iconv — "NARUSE, Yui" <naruse@...> 2010/11/07

(2010/11/06 12:10), Kouhei Sutou wrote:

[#42549] Re: [Ruby 1.9-Bug#3990][Closed] tests of rexml/rss reports many errors and failures without iconv — Kouhei Sutou <kou@...> 2010/11/07

須藤です。

[#42572] Re: [Ruby 1.9-Bug#3990][Closed] tests of rexml/rss reports many errors and failures without iconv — "NARUSE, Yui" <naruse@...> 2010/11/13

成瀬です。

[#42592] Re: [Ruby 1.9-Bug#3990][Closed] tests of rexml/rss reports many errors and failures without iconv — Kouhei Sutou <kou@...> 2010/11/18

須藤です。

[#42593] Re: [Ruby 1.9-Bug#3990][Closed] tests of rexml/rss reports many errors and failures without iconv — "NARUSE, Yui" <naruse@...> 2010/11/18

成瀬です。

[#42607] Re: [Ruby 1.9-Bug#3990][Closed] tests of rexml/rss reports many errors and failures without iconv — Kouhei Sutou <kou@...> 2010/11/20

須藤です。

[#42608] Re: [Ruby 1.9-Bug#3990][Closed] tests of rexml/rss reports many errors and failures without iconv — "NARUSE, Yui" <naruse@...> 2010/11/20

成瀬です。

[#42610] Re: [Ruby 1.9-Bug#3990][Closed] tests of rexml/rss reports many errors and failures without iconv — Kouhei Sutou <kou@...> 2010/11/20

須藤です。

[#42611] Re: [Ruby 1.9-Bug#3990][Closed] tests of rexml/rss reports many errors and failures without iconv — "NARUSE, Yui" <naruse@...> 2010/11/20

成瀬です。

[#42613] Re: [Ruby 1.9-Bug#3990][Closed] tests of rexml/rss reports many errors and failures without iconv — Kouhei Sutou <kou@...> 2010/11/21

須藤です。

[#42614] Re: [Ruby 1.9-Bug#3990][Closed] tests of rexml/rss reports many errors and failures without iconv — "NARUSE, Yui" <naruse@...> 2010/11/21

成瀬です。

[ruby-dev:42476] [trunk:feature] Hash#update with Enumerable

From: Nobuyoshi Nakada <nobu@...>
Date: 2010-10-28 09:14:47 UTC
List: ruby-dev #42476
なかだです。

今のところHash#updateはHashしか受け付けませんが、Enumerableまで
受け付けるように拡張するのはどうでしょうか。


diff --git i/hash.c w/hash.c
index 873219a..8d0c72a 100644
--- i/hash.c
+++ w/hash.c
@@ -1748,6 +1748,45 @@ rb_hash_update_block_i(VALUE key, VALUE value, VALUE hash)
     return ST_CONTINUE;
 }
 
+static VALUE
+rb_enum_update_i(VALUE obj, VALUE hash, int argc, VALUE *argv)
+{
+    if (argc == 1 && RB_TYPE_P(obj, T_ARRAY)) {
+	argc = RARRAY_LEN(obj);
+	argv = RARRAY_PTR(obj);
+    }
+    if (argc == 2) {
+	st_insert(RHASH(hash)->ntbl, argv[0], argv[1]);
+    }
+    return Qnil;
+}
+
+static VALUE
+rb_enum_update_block_i(VALUE obj, VALUE hash, int argc, VALUE *argv)
+{
+    VALUE key, value = Qundef, oldval;
+    if (argc == 1 && RB_TYPE_P(obj, T_ARRAY)) {
+	argc = RARRAY_LEN(obj);
+	argv = RARRAY_PTR(obj);
+    }
+    switch (argc) {
+      case 2:
+	value = argv[1];
+      case 1:
+	key = argv[0];
+	oldval = rb_hash_lookup2(hash, key, Qundef);
+	if (oldval != Qundef) {
+	    value = rb_yield_values(argc + 1, key, oldval, value);
+	}
+	else if (value == Qundef) {
+	    value = rb_yield(key);
+	}
+	st_insert(RHASH(hash)->ntbl, key, value);
+	break;
+    }
+    return Qnil;
+}
+
 /*
  *  call-seq:
  *     hsh.merge!(other_hash)                                 -> hsh
@@ -1769,13 +1808,36 @@ rb_hash_update_block_i(VALUE key, VALUE value, VALUE hash)
  *     h2 = { "b" => 254, "c" => 300 }
  *     h1.merge!(h2) { |key, v1, v2| v1 }
  *                     #=> {"a"=>100, "b"=>200, "c"=>300}
+ *
+ *  If <i>other_hash</i> is not a Hash but an Enumerable, its #each
+ *  method should yield [key, newval] pairs or mere key.  In the latter
+ *  case, thegiven block is always called regardless oldval, but without
+ *  newval.
+ *
+ *     h1 = { "a" => 100, "b" => 200 }
+ *     e1 = [["b", 254], ["c", 300]]
+ *     h1.merge!(e1) { |key, *v| v }
+ *                     #=> {"a"=>100, "b"=>[200,254], "c"=>300}
+ *
+ *     h1 = { "a" => 100, "b" => 200 }
+ *     e1 = [["b"], ["c"]]
+ *     h1.merge!(e1) { |key, v1, v2| v1 }
+ *                     #=> {"a"=>100, "b"=>[200], "c"=>[]}
  */
 
 static VALUE
 rb_hash_update(VALUE hash1, VALUE hash2)
 {
+    VALUE tmp;
     rb_hash_modify(hash1);
-    hash2 = to_hash(hash2);
+    tmp = rb_check_hash_type(hash2);
+    if (NIL_P(tmp)) {
+	VALUE (*bfunc)(ANYARGS) = rb_block_given_p() ?
+	    rb_enum_update_block_i : rb_enum_update_i;
+	rb_each_call(hash2, 0, 0, bfunc, hash1);
+	return hash1;
+    }
+    hash2 = tmp;
     if (rb_block_given_p()) {
 	rb_hash_foreach(hash2, rb_hash_update_block_i, hash1);
     }
diff --git i/include/ruby/ruby.h w/include/ruby/ruby.h
index 4a3e0ff..aa7808b 100644
--- i/include/ruby/ruby.h
+++ w/include/ruby/ruby.h
@@ -1164,6 +1164,7 @@ PRINTF_ARGS(void rb_compile_warn(const char *, int, const char*, ...), 3, 4);
 typedef VALUE rb_block_call_func(VALUE, VALUE, int, VALUE*);
 
 VALUE rb_each(VALUE);
+VALUE rb_each_call(VALUE,int,VALUE*,VALUE(*)(ANYARGS),VALUE);
 VALUE rb_yield(VALUE);
 VALUE rb_yield_values(int n, ...);
 VALUE rb_yield_values2(int n, const VALUE *argv);
diff --git i/vm_eval.c w/vm_eval.c
index 05fd3fa..6f93897 100644
--- i/vm_eval.c
+++ w/vm_eval.c
@@ -947,6 +947,12 @@ rb_each(VALUE obj)
     return rb_call(obj, idEach, 0, 0, CALL_FCALL);
 }
 
+VALUE
+rb_each_call(VALUE obj, int argc, VALUE *argv, VALUE (*bl_proc)(ANYARGS), VALUE arg)
+{
+    return rb_block_call(obj, idEach, argc, argv, bl_proc, arg);
+}
+
 static VALUE
 eval_string_with_cref(VALUE self, VALUE src, VALUE scope, NODE *cref, const char *volatile file, volatile int line)
 {


-- 
--- 僕の前にBugはない。
--- 僕の後ろにBugはできる。
    中田 伸悦


In This Thread

Prev Next