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

ruby-changes:12322

From: nobu <ko1@a...>
Date: Fri, 10 Jul 2009 16:30:28 +0900 (JST)
Subject: [ruby-changes:12322] Ruby:r24017 (trunk): * array.c (recursive_join): use obj to tell if recursion occurs.

nobu	2009-07-10 16:30:08 +0900 (Fri, 10 Jul 2009)

  New Revision: 24017

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=24017

  Log:
    * array.c (recursive_join): use obj to tell if recursion occurs.
      [ruby-core:24150]
    * enum.c (enum_join): reverted r23966.  [ruby-core:24196]

  Modified files:
    trunk/ChangeLog
    trunk/array.c
    trunk/enum.c
    trunk/test/ruby/test_array.rb
    trunk/test/ruby/test_enum.rb

Index: array.c
===================================================================
--- array.c	(revision 24016)
+++ array.c	(revision 24017)
@@ -1519,7 +1519,7 @@
 
 extern VALUE rb_output_fs;
 
-static void ary_join_1(VALUE ary, VALUE sep, long i, VALUE result);
+static void ary_join_1(VALUE obj, VALUE ary, VALUE sep, long i, VALUE result);
 
 static VALUE
 recursive_join(VALUE obj, VALUE argp, int recur)
@@ -1533,7 +1533,7 @@
 	rb_str_buf_cat_ascii(result, "[...]");
     }
     else {
-	ary_join_1(ary, sep, 0, result);
+	ary_join_1(obj, ary, sep, 0, result);
     }
     return Qnil;
 }
@@ -1555,7 +1555,7 @@
 }
 
 static void
-ary_join_1(VALUE ary, VALUE sep, long i, VALUE result)
+ary_join_1(VALUE obj, VALUE ary, VALUE sep, long i, VALUE result)
 {
     VALUE val, tmp;
 
@@ -1581,7 +1581,7 @@
 		args[0] = val;
 		args[1] = sep;
 		args[2] = result;
-		rb_exec_recursive(recursive_join, ary, (VALUE)args);
+		rb_exec_recursive(recursive_join, obj, (VALUE)args);
 	    }
 	    break;
 	  default:
@@ -1592,6 +1592,7 @@
 	    }
 	    tmp = rb_check_convert_type(val, T_ARRAY, "Array", "to_a");
 	    if (!NIL_P(tmp)) {
+		obj = val;
 		val = tmp;
 		goto ary_join;
 	    }
@@ -1626,7 +1627,7 @@
 	    if (taint) OBJ_TAINT(result);
 	    if (untrust) OBJ_UNTRUST(result);
 	    ary_join_0(ary, sep, i, result);
-	    ary_join_1(ary, sep, i, result);
+	    ary_join_1(ary, ary, sep, i, result);
 	    return result;
 	}
 
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 24016)
+++ ChangeLog	(revision 24017)
@@ -1,3 +1,10 @@
+Fri Jul 10 16:30:03 2009  Nobuyoshi Nakada  <nobu@r...>
+
+	* array.c (recursive_join): use obj to tell if recursion occurs.
+	  [ruby-core:24150]
+
+	* enum.c (enum_join): reverted r23966.  [ruby-core:24196]
+
 Fri Jul 10 14:41:34 2009  NARUSE, Yui  <naruse@r...>
 
 	* marshal.c (r_object0): set encoding only if the encoding
@@ -2,2 +9,3 @@
 	  is not US-ASCII.
+
 Fri Jul 10 14:44:03 2009  Nobuyoshi Nakada  <nobu@r...>
Index: enum.c
===================================================================
--- enum.c	(revision 24016)
+++ enum.c	(revision 24017)
@@ -1802,35 +1802,6 @@
     return Qnil;		/* not reached */
 }
 
-static VALUE
-join_i(VALUE i, VALUE args, int argc, VALUE *argv)
-{
-    VALUE *arg = (VALUE *)args;
-    ENUM_WANT_SVALUE();
-    if (!arg[0]) {
-	arg[0] = rb_usascii_str_new(0, 0);
-    }
-    else if (!NIL_P(arg[1])) {
-	rb_str_buf_append(arg[0], arg[1]);
-    }
-    return rb_str_buf_append(arg[0], rb_obj_as_string(i));
-}
-
-VALUE
-rb_enum_join(VALUE obj, VALUE sep)
-{
-    VALUE args[2];
-
-    args[0] = 0;
-    args[1] = sep;
-    if (!NIL_P(sep)) StringValue(args[1]);
-    rb_block_call(obj, id_each, 0, 0, join_i, (VALUE)args);
-    if (!args[0]) args[0] = rb_str_new(0, 0);
-    OBJ_INFECT(args[0], obj);
-
-    return args[0];
-}
-
 /*
  *  call-seq:
  *     enum.join(sep=$,)    -> str
@@ -1847,7 +1818,7 @@
     rb_scan_args(argc, argv, "01", &sep);
     if (NIL_P(sep)) sep = rb_output_fs;
 
-    return rb_enum_join(obj, sep);
+    return rb_ary_join(enum_to_a(0, 0, obj), sep);
 }
 
 /*
Index: test/ruby/test_array.rb
===================================================================
--- test/ruby/test_array.rb	(revision 24016)
+++ test/ruby/test_array.rb	(revision 24017)
@@ -1491,6 +1491,11 @@
     a = []
     a << a
     assert_equal("[...]", a.join)
+
+    def (a = Object.new).to_a
+      [self]
+    end
+    assert_equal("[...]", [a].join, , '[ruby-core:24150]')
   end
 
   def test_to_a2
Index: test/ruby/test_enum.rb
===================================================================
--- test/ruby/test_enum.rb	(revision 24016)
+++ test/ruby/test_enum.rb	(revision 24017)
@@ -295,14 +295,23 @@
     assert_equal("123", (1..3).join())
     assert_raise(TypeError, '[ruby-core:24172]') {("a".."c").join(1)}
     class << (e = Object.new.extend(Enumerable))
-      def to_s
-        "e"
-      end
       def each
         yield self
       end
     end
-    assert_equal("e", e.join(""))
+    assert_equal("[...]", e.join(""), '[ruby-core:24150]')
+    assert_equal("[...]", [e].join(""), '[ruby-core:24150]')
+    e = Class.new {
+      include Enumerable
+      def initialize(*args)
+        @e = args
+      end
+      def each
+        @e.each {|e| yield e}
+      end
+    }
+    e = e.new(1, e.new(2, e.new(3, e.new(4, 5))))
+    assert_equal("1:2:3:4:5", e.join(':'), '[ruby-core:24196]')
   ensure
     $, = ofs
   end

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

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