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

ruby-changes:34291

From: nobu <ko1@a...>
Date: Sat, 7 Jun 2014 12:52:02 +0900 (JST)
Subject: [ruby-changes:34291] nobu:r46372 (trunk): io.c: truncate before appending

nobu	2014-06-07 12:51:57 +0900 (Sat, 07 Jun 2014)

  New Revision: 46372

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

  Log:
    io.c: truncate before appending
    
    * io.c (read_all): truncate the buffer before appending read data,
      instead of truncating before reading.
      [ruby-core:55951] [Bug #8625]

  Modified files:
    trunk/ChangeLog
    trunk/io.c
    trunk/test/ruby/test_pipe.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 46371)
+++ ChangeLog	(revision 46372)
@@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sat Jun  7 12:51:51 2014  Nobuyoshi Nakada  <nobu@r...>
+
+	* io.c (read_all): truncate the buffer before appending read data,
+	  instead of truncating before reading.
+	  [ruby-core:55951] [Bug #8625]
+
 Sat Jun  7 12:28:53 2014  Nobuyoshi Nakada  <nobu@r...>
 
 	* ext/digest/digest.c (rb_digest_instance_equal): no need to call
Index: io.c
===================================================================
--- io.c	(revision 46371)
+++ io.c	(revision 46372)
@@ -2398,23 +2398,27 @@ read_all(rb_io_t *fptr, long siz, VALUE https://github.com/ruby/ruby/blob/trunk/io.c#L2398
     int cr;
 
     if (NEED_READCONV(fptr)) {
+	int first = !NIL_P(str);
 	SET_BINARY_MODE(fptr);
 	io_setstrbuf(&str,0);
         make_readconv(fptr, 0);
         while (1) {
             VALUE v;
             if (fptr->cbuf.len) {
+		if (first) rb_str_set_len(str, first = 0);
                 io_shift_cbuf(fptr, fptr->cbuf.len, &str);
             }
             v = fill_cbuf(fptr, 0);
             if (v != MORE_CHAR_SUSPENDED && v != MORE_CHAR_FINISHED) {
                 if (fptr->cbuf.len) {
+		    if (first) rb_str_set_len(str, first = 0);
                     io_shift_cbuf(fptr, fptr->cbuf.len, &str);
                 }
                 rb_exc_raise(v);
             }
             if (v == MORE_CHAR_FINISHED) {
                 clear_readconv(fptr);
+		if (first) rb_str_set_len(str, first = 0);
                 return io_enc_str(str, fptr);
             }
         }
Index: test/ruby/test_pipe.rb
===================================================================
--- test/ruby/test_pipe.rb	(revision 46371)
+++ test/ruby/test_pipe.rb	(revision 46372)
@@ -13,4 +13,17 @@ class TestPipe < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_pipe.rb#L13
       r.close
     end
   end
+  class WithConversion < self
+    def open_file(content)
+      r, w = IO.pipe
+      w << content
+      w.close
+      r.set_encoding("us-ascii:utf-8")
+      begin
+        yield r
+      ensure
+        r.close
+      end
+    end
+  end
 end

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

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