[前][次][番号順一覧][スレッド一覧]

ruby-changes:3174

From: ko1@a...
Date: 25 Dec 2007 15:01:39 +0900
Subject: [ruby-changes:3174] matz - Ruby:r14667 (trunk): * enum.c (enum_yield): when multiple values yielded from #each

matz	2007-12-25 15:01:22 +0900 (Tue, 25 Dec 2007)

  New Revision: 14667

  Modified files:
    trunk/ChangeLog
    trunk/enum.c
    trunk/ext/dbm/extconf.rb

  Log:
    * enum.c (enum_yield): when multiple values yielded from #each
      pack them into an array.  [ruby-dev:32708]
    
    * enum.c: all method but all?, any?, one? and none? passed packed
      multiple values to the block.

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/ChangeLog?r1=14667&r2=14666
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/ext/dbm/extconf.rb?r1=14667&r2=14666
  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/enum.c?r1=14667&r2=14666

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 14666)
+++ ChangeLog	(revision 14667)
@@ -1,3 +1,11 @@
+Tue Dec 25 15:00:33 2007  Yukihiro Matsumoto  <matz@r...>
+
+	* enum.c (enum_yield): when multiple values yielded from #each
+	  pack them into an array.  [ruby-dev:32708]
+
+	* enum.c: all method but all?, any?, one? and none? passed packed
+	  multiple values to the block.
+
 Tue Dec 25 14:57:00 2007  Nobuyoshi Nakada  <nobu@r...>
 
 	* common.mk (COMMONOBJS): transcode_data_*.c moved under enc/trans.
Index: enum.c
===================================================================
--- enum.c	(revision 14666)
+++ enum.c	(revision 14667)
@@ -18,19 +18,33 @@
 static ID id_each, id_eqq, id_cmp, id_next;
 
 static VALUE
-grep_i(VALUE i, VALUE *arg)
+enum_values_pack(int argc, VALUE *argv)
 {
+    if (argc == 0) return Qnil;
+    if (argc == 1) return argv[0];
+    return rb_ary_new4(argc, argv);
+}
+
+static VALUE
+enum_yield(int argc, VALUE *argv)
+{
+    return rb_yield(enum_values_pack(argc, argv));
+}
+
+static VALUE
+grep_i(VALUE i, VALUE *arg, int argc, VALUE *argv)
+{
     if (RTEST(rb_funcall(arg[0], id_eqq, 1, i))) {
-	rb_ary_push(arg[1], i);
+	rb_ary_push(arg[1], enum_values_pack(argc, argv));
     }
     return Qnil;
 }
 
 static VALUE
-grep_iter_i(VALUE i, VALUE *arg)
+grep_iter_i(VALUE i, VALUE *arg, int argc, VALUE *argv)
 {
     if (RTEST(rb_funcall(arg[0], id_eqq, 1, i))) {
-	rb_ary_push(arg[1], rb_yield(i));
+	rb_ary_push(arg[1], enum_yield(argc, argv));
     }
     return Qnil;
 }
@@ -77,9 +91,9 @@
 }
 
 static VALUE
-count_iter_i(VALUE i, long *n)
+count_iter_i(VALUE i, long *n, int argc, VALUE *argv)
 {
-    if (RTEST(rb_yield(i))) {
+    if (RTEST(enum_yield(argc, argv))) {
 	(*n)++;
     }
     return Qnil;
@@ -130,9 +144,9 @@
 }
 
 static VALUE
-find_i(VALUE i, VALUE *memo)
+find_i(VALUE i, VALUE *memo, int argc, VALUE *argv)
 {
-    if (RTEST(rb_yield(i))) {
+    if (RTEST(enum_yield(argc, argv))) {
 	*memo = i;
 	rb_iter_break();
     }
@@ -173,9 +187,9 @@
 }
 
 static VALUE
-find_index_i(VALUE i, VALUE *memo)
+find_index_i(VALUE i, VALUE *memo, int argc, VALUE *argv)
 {
-    if (RTEST(rb_yield(i))) {
+    if (RTEST(enum_yield(argc, argv))) {
 	memo[0] = UINT2NUM(memo[1]);
 	rb_iter_break();
     }
@@ -212,9 +226,9 @@
 }
 
 static VALUE
-find_all_i(VALUE i, VALUE ary)
+find_all_i(VALUE i, VALUE ary, int argc, VALUE *argv)
 {
-    if (RTEST(rb_yield(i))) {
+    if (RTEST(enum_yield(argc, argv))) {
 	rb_ary_push(ary, i);
     }
     return Qnil;
@@ -247,9 +261,9 @@
 }
 
 static VALUE
-reject_i(VALUE i, VALUE ary)
+reject_i(VALUE i, VALUE ary, int argc, VALUE *argv)
 {
-    if (!RTEST(rb_yield(i))) {
+    if (!RTEST(enum_yield(argc, argv))) {
 	rb_ary_push(ary, i);
     }
     return Qnil;
@@ -280,9 +294,9 @@
 }
 
 static VALUE
-collect_i(VALUE i, VALUE ary)
+collect_i(VALUE i, VALUE ary, int argc, VALUE *argv)
 {
-    rb_ary_push(ary, rb_yield(i));
+    rb_ary_push(ary, enum_yield(argc, argv));
 
     return Qnil;
 }
@@ -342,25 +356,25 @@
 }
 
 static VALUE
-inject_i(VALUE i, VALUE p)
+inject_i(VALUE i, VALUE p, int argc, VALUE *argv)
 {
     VALUE *memo = (VALUE *)p;
     if (memo[0] == Qundef) {
 	memo[0] = i;
     }
     else {
-	memo[0] = rb_yield_values(2, memo[0], i);
+	memo[0] = rb_yield_values(2, memo[0], enum_values_pack(argc, argv));
     }
     return Qnil;
 }
 
 static VALUE
-inject_op_i(VALUE i, VALUE p)
+inject_op_i(VALUE i, VALUE p, int argc, VALUE *argv)
 {
     VALUE *memo = (VALUE *)p;
 
     if (memo[0] == Qundef) {
-	memo[0] = i;
+	memo[0] = enum_values_pack(argc, argv);
     }
     else {
 	memo[0] = rb_funcall(memo[0], (ID)memo[1], 1, i);
@@ -417,7 +431,7 @@
 enum_inject(int argc, VALUE *argv, VALUE obj)
 {
     VALUE memo[2];
-    VALUE (*iter)(VALUE, VALUE) = inject_i;
+    VALUE (*iter)(VALUE, VALUE, int, VALUE*) = inject_i;
 
     switch (rb_scan_args(argc, argv, "02", &memo[0], &memo[1])) {
       case 0:
@@ -445,9 +459,9 @@
 }
 
 static VALUE
-partition_i(VALUE i, VALUE *ary)
+partition_i(VALUE i, VALUE *ary, int argc, VALUE *argv)
 {
-    if (RTEST(rb_yield(i))) {
+    if (RTEST(enum_yield(argc, argv))) {
 	rb_ary_push(ary[0], i);
     }
     else {
@@ -483,9 +497,9 @@
 }
 
 static VALUE
-group_by_i(VALUE i, VALUE hash)
+group_by_i(VALUE i, VALUE hash, int argc, VALUE *argv)
 {
-    VALUE group = rb_yield(i);
+    VALUE group = enum_yield(argc, argv);
     VALUE values;
 
     values = rb_hash_aref(hash, group);
@@ -599,12 +613,12 @@
 }
 
 static VALUE
-sort_by_i(VALUE i, VALUE ary)
+sort_by_i(VALUE i, VALUE ary, int argc, VALUE *argv)
 {
     VALUE v;
     NODE *memo;
 
-    v = rb_yield(i);
+    v = enum_yield(argc, argv);
     if (RBASIC(ary)->klass) {
 	rb_raise(rb_eRuntimeError, "sort_by reentered");
     }
@@ -1130,11 +1144,11 @@
 }
 
 static VALUE
-min_by_i(VALUE i, VALUE *memo)
+min_by_i(VALUE i, VALUE *memo, int argc, VALUE *argv)
 {
     VALUE v;
 
-    v = rb_yield(i);
+    v = enum_yield(argc, argv);
     if (memo[0] == Qundef) {
 	memo[0] = v;
 	memo[1] = i;
@@ -1171,11 +1185,11 @@
 }
 
 static VALUE
-max_by_i(VALUE i, VALUE *memo)
+max_by_i(VALUE i, VALUE *memo, int argc, VALUE *argv)
 {
     VALUE v;
 
-    v = rb_yield(i);
+    v = enum_yield(argc, argv);
     if (memo[0] == Qundef) {
 	memo[0] = v;
 	memo[1] = i;
@@ -1212,11 +1226,11 @@
 }
 
 static VALUE
-minmax_by_i(VALUE i, VALUE *memo)
+minmax_by_i(VALUE i, VALUE *memo, int argc, VALUE *argv)
 {
     VALUE v;
 
-    v = rb_yield(i);
+    v = enum_yield(argc, argv);
     if (memo[0] == Qundef) {
 	memo[0] = v;
 	memo[1] = v;
@@ -1298,11 +1312,11 @@
 }
 
 static VALUE
-each_with_index_i(VALUE val, VALUE memo)
+each_with_index_i(VALUE i, VALUE memo, int argc, VALUE *argv)
 {
     long n = (*(VALUE *)memo)++;
 
-    return rb_yield_values(2, val, INT2NUM(n));
+    return rb_yield_values(2, enum_values_pack(argc, argv), INT2NUM(n));
 }
 
 /*
@@ -1334,7 +1348,7 @@
 
 
 static VALUE
-zip_i(VALUE val, NODE *memo)
+zip_i(VALUE val, NODE *memo, int argc, VALUE *argv)
 {
     volatile VALUE result = memo->u1.value;
     volatile VALUE args = memo->u2.value;
@@ -1342,7 +1356,7 @@
     int i;
 
     tmp = rb_ary_new2(RARRAY_LEN(args) + 1);
-    rb_ary_store(tmp, 0, val);
+    rb_ary_store(tmp, 0, enum_values_pack(argc, argv));
     for (i=0; i<RARRAY_LEN(args); i++) {
 	VALUE v = rb_funcall(RARRAY_PTR(args)[i], id_next, 0, 0);
 	rb_ary_push(tmp, v);
@@ -1434,9 +1448,9 @@
 
 
 static VALUE
-take_while_i(VALUE i, VALUE *ary)
+take_while_i(VALUE i, VALUE *ary, int argc, VALUE *argv)
 {
-    if (!RTEST(rb_yield(i))) rb_iter_break();
+    if (!RTEST(enum_yield(argc, argv))) rb_iter_break();
     rb_ary_push(*ary, i);
     return Qnil;
 }
@@ -1501,9 +1515,9 @@
 
 
 static VALUE
-drop_while_i(VALUE i, VALUE *args)
+drop_while_i(VALUE i, VALUE *args, int argc, VALUE *argv)
 {
-    if (!args[1] && !RTEST(rb_yield(i))) {
+    if (!args[1] && !RTEST(enum_yield(argc, argv))) {
 	args[1] = Qtrue;
     }
     if (args[1]) {
@@ -1538,10 +1552,10 @@
 }
 
 static VALUE
-cycle_i(VALUE i, VALUE ary)
+cycle_i(VALUE i, VALUE ary, int argc, VALUE *argv)
 {
     rb_ary_push(ary, i);
-    rb_yield(i);
+    enum_yield(argc, argv);
     return Qnil;
 }
 
Index: ext/dbm/extconf.rb
===================================================================
--- ext/dbm/extconf.rb	(revision 14666)
+++ ext/dbm/extconf.rb	(revision 14667)
@@ -36,7 +36,7 @@
   db_prefix ||= ""
 
   if (have_library(db, db_prefix+"dbm_open") || have_func(db_prefix+"dbm_open")) and
-      hdr = self.fetch(db, ["ndbm.h"]).find {|hdr| have_type("DBM", hdr, hsearch)}
+      hdr = self.fetch(db, ["ndbm.h"]).find {|h| have_type("DBM", h, hsearch)}
     have_func(db_prefix+"dbm_clearerr") unless have_gdbm
     $defs << hsearch if hsearch
     $defs << '-DDBM_HDR="<'+hdr+'>"'

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml

[前][次][番号順一覧][スレッド一覧]