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

ruby-changes:26063

From: nobu <ko1@a...>
Date: Sat, 1 Dec 2012 19:25:17 +0900 (JST)
Subject: [ruby-changes:26063] nobu:r38120 (trunk): io.c: recurse for the argument

nobu	2012-12-01 19:24:12 +0900 (Sat, 01 Dec 2012)

  New Revision: 38120

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

  Log:
    io.c: recurse for the argument
    
    * io.c (rb_io_puts): recurse for the argument itself, not converted
      array elements.  [ruby-core:42444] [Bug #5986]

  Modified files:
    trunk/ChangeLog
    trunk/io.c
    trunk/test/ruby/test_io.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 38119)
+++ ChangeLog	(revision 38120)
@@ -1,3 +1,8 @@
+Sat Dec  1 19:24:09 2012  Nobuyoshi Nakada  <nobu@r...>
+
+	* io.c (rb_io_puts): recurse for the argument itself, not converted
+	  array elements.  [ruby-core:42444] [Bug #5986]
+
 Sat Dec  1 19:01:36 2012  Nobuyoshi Nakada  <nobu@r...>
 
 	* marshal.c (w_object, r_object0): call private marshal methods.
Index: io.c
===================================================================
--- io.c	(revision 38119)
+++ io.c	(revision 38120)
@@ -6660,13 +6660,15 @@
     if (recur) {
 	tmp = rb_str_new2("[...]");
 	rb_io_puts(1, &tmp, out);
-	return Qnil;
+	return Qtrue;
     }
+    ary = rb_check_array_type(ary);
+    if (NIL_P(ary)) return Qfalse;
     for (i=0; i<RARRAY_LEN(ary); i++) {
 	tmp = RARRAY_PTR(ary)[i];
 	rb_io_puts(1, &tmp, out);
     }
-    return Qnil;
+    return Qtrue;
 }
 
 /*
@@ -6705,9 +6707,7 @@
 	    line = argv[i];
 	    goto string;
 	}
-	line = rb_check_array_type(argv[i]);
-	if (!NIL_P(line)) {
-	    rb_exec_recursive(io_puts_ary, line, out);
+	if (rb_exec_recursive(io_puts_ary, argv[i], out)) {
 	    continue;
 	}
 	line = rb_obj_as_string(argv[i]);
Index: test/ruby/test_io.rb
===================================================================
--- test/ruby/test_io.rb	(revision 38119)
+++ test/ruby/test_io.rb	(revision 38120)
@@ -2583,5 +2583,17 @@
       end
     end
   end
+
+  def test_puts_recursive_ary
+    bug5986 = '[ruby-core:42444]'
+    c = Class.new {
+      def to_ary
+        [self]
+      end
+    }
+    s = StringIO.new
+    s.puts(c.new)
+    assert_equal("[...]\n", s.string, bug5986)
+  end
 end
 

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

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