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

ruby-changes:7627

From: nobu <ko1@a...>
Date: Fri, 5 Sep 2008 18:38:12 +0900 (JST)
Subject: [ruby-changes:7627] Ruby:r19148 (trunk): * io.c (copy_stream_fallback_body): use read method unless readpartial

nobu	2008-09-05 18:37:55 +0900 (Fri, 05 Sep 2008)

  New Revision: 19148

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

  Log:
    * io.c (copy_stream_fallback_body): use read method unless readpartial
      is available.  [ruby-dev:36124]

  Modified files:
    trunk/ChangeLog
    trunk/io.c
    trunk/test/fileutils/test_fileutils.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 19147)
+++ ChangeLog	(revision 19148)
@@ -1,3 +1,8 @@
+Fri Sep  5 18:37:52 2008  Nobuyoshi Nakada  <nobu@r...>
+
+	* io.c (copy_stream_fallback_body): use read method unless readpartial
+	  is available.  [ruby-dev:36124]
+
 Fri Sep  5 18:16:31 2008  Nobuyoshi Nakada  <nobu@r...>
 
 	* ext/iconv/iconv.c (iconv_create): strips glibc style option before
Index: io.c
===================================================================
--- io.c	(revision 19147)
+++ io.c	(revision 19148)
@@ -7216,7 +7216,14 @@
     VALUE buf = rb_str_buf_new(buflen);
     long rest = stp->copy_length;
     off_t off = stp->src_offset;
+    ID read_method = id_readpartial;
 
+    if (stp->src_fd == -1) {
+	if (!rb_respond_to(stp->src, read_method)) {
+	    read_method = id_read;
+	}
+    }
+
     while (1) {
         long numwrote;
         long l;
@@ -7229,7 +7236,7 @@
             l = buflen < rest ? buflen : rest;
         }
         if (stp->src_fd == -1) {
-            rb_funcall(stp->src, id_readpartial, 2, INT2FIX(l), buf);
+            rb_funcall(stp->src, read_method, 2, INT2FIX(l), buf);
         }
         else {
             ssize_t ss;
@@ -7248,6 +7255,9 @@
         numwrote = NUM2LONG(n);
         stp->total += numwrote;
         rest -= numwrote;
+	if (read_method == id_read && RSTRING_LEN(buf) == 0) {
+	    break;
+	}
     }
 
     return Qnil;
Index: test/fileutils/test_fileutils.rb
===================================================================
--- test/fileutils/test_fileutils.rb	(revision 19147)
+++ test/fileutils/test_fileutils.rb	(revision 19148)
@@ -977,8 +977,8 @@
       @f = f
     end
 
-    def read(n)
-      @f.read(n)
+    def read(*args)
+      @f.read(*args)
     end
 
     def write(str)

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

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