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

ruby-changes:34655

From: usa <ko1@a...>
Date: Mon, 7 Jul 2014 12:43:30 +0900 (JST)
Subject: [ruby-changes:34655] usa:r46738 (ruby_2_0_0): merge revision(s) 46360, 46372: [Backport #8625]

usa	2014-07-07 12:43:19 +0900 (Mon, 07 Jul 2014)

  New Revision: 46738

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

  Log:
    merge revision(s) 46360,46372: [Backport #8625]
    
    * io.c (io_setstrbuf, io_read): should not shorten the given buffer until
      read succeeds.  [ruby-core:55951] [Bug #8625]
    
    * io.c (read_all): truncate the buffer before appending read data,
      instead of truncating before reading.
      [ruby-core:55951] [Bug #8625]

  Modified directories:
    branches/ruby_2_0_0/
  Modified files:
    branches/ruby_2_0_0/ChangeLog
    branches/ruby_2_0_0/io.c
    branches/ruby_2_0_0/test/ruby/test_io.rb
    branches/ruby_2_0_0/test/ruby/test_pipe.rb
    branches/ruby_2_0_0/version.h
Index: ruby_2_0_0/ChangeLog
===================================================================
--- ruby_2_0_0/ChangeLog	(revision 46737)
+++ ruby_2_0_0/ChangeLog	(revision 46738)
@@ -1,3 +1,14 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/ChangeLog#L1
+Mon Jul  7 12:39:34 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]
+
+Mon Jul  7 12:39:34 2014  Nobuyoshi Nakada  <nobu@r...>
+
+	* io.c (io_setstrbuf, io_read): should not shorten the given buffer until
+	  read succeeds.  [ruby-core:55951] [Bug #8625]
+
 Mon Jul  7 12:16:54 2014  Shugo Maeda  <shugo@r...>
 
 	* lib/net/ftp.rb (gets, readline): read lines without LF properly.
Index: ruby_2_0_0/io.c
===================================================================
--- ruby_2_0_0/io.c	(revision 46737)
+++ ruby_2_0_0/io.c	(revision 46738)
@@ -2254,9 +2254,6 @@ io_setstrbuf(VALUE *str, long len) https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/io.c#L2254
 	long clen = RSTRING_LEN(s);
 	if (clen >= len) {
 	    rb_str_modify(s);
-	    if (clen != len) {
-		rb_str_set_len(s, len);
-	    }
 	    return;
 	}
 	len -= clen;
@@ -2283,23 +2280,27 @@ read_all(rb_io_t *fptr, long siz, VALUE https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/io.c#L2280
     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);
             }
         }
@@ -2727,7 +2728,10 @@ io_read(int argc, VALUE *argv, VALUE io) https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/io.c#L2728
 
     GetOpenFile(io, fptr);
     rb_io_check_byte_readable(fptr);
-    if (len == 0) return str;
+    if (len == 0) {
+	io_set_read_length(str, 0);
+	return str;
+    }
 
     READ_CHECK(fptr);
 #if defined(RUBY_TEST_CRLF_ENVIRONMENT) || defined(_WIN32)
Index: ruby_2_0_0/version.h
===================================================================
--- ruby_2_0_0/version.h	(revision 46737)
+++ ruby_2_0_0/version.h	(revision 46738)
@@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/version.h#L1
 #define RUBY_VERSION "2.0.0"
 #define RUBY_RELEASE_DATE "2014-07-07"
-#define RUBY_PATCHLEVEL 521
+#define RUBY_PATCHLEVEL 522
 
 #define RUBY_RELEASE_YEAR 2014
 #define RUBY_RELEASE_MONTH 7
Index: ruby_2_0_0/test/ruby/test_pipe.rb
===================================================================
--- ruby_2_0_0/test/ruby/test_pipe.rb	(revision 46737)
+++ ruby_2_0_0/test/ruby/test_pipe.rb	(revision 46738)
@@ -13,4 +13,17 @@ class TestPipe < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/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
Index: ruby_2_0_0/test/ruby/test_io.rb
===================================================================
--- ruby_2_0_0/test/ruby/test_io.rb	(revision 46737)
+++ ruby_2_0_0/test/ruby/test_io.rb	(revision 46738)
@@ -1105,6 +1105,14 @@ class TestIO < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/test/ruby/test_io.rb#L1105
       t.value
       assert_equal("", s)
     end
+    with_pipe do |r, w|
+      s = "xxx"
+      t = Thread.new {r.read(2, s)}
+      Thread.pass until t.stop?
+      t.kill
+      t.value
+      assert_equal("xxx", s)
+    end
   end
 
   def test_write_nonblock

Property changes on: ruby_2_0_0
___________________________________________________________________
Modified: svn:mergeinfo
   Merged /trunk:r46360,46372


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

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