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

ruby-changes:34548

From: nagachika <ko1@a...>
Date: Tue, 1 Jul 2014 03:12:12 +0900 (JST)
Subject: [ruby-changes:34548] nagachika:r46629 (ruby_2_1): merge revision(s) r46360, r46372: [Backport #8625]

nagachika	2014-07-01 03:12:05 +0900 (Tue, 01 Jul 2014)

  New Revision: 46629

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

  Log:
    merge revision(s) r46360,r46372: [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_1/
  Modified files:
    branches/ruby_2_1/ChangeLog
    branches/ruby_2_1/io.c
    branches/ruby_2_1/test/ruby/test_io.rb
    branches/ruby_2_1/test/ruby/test_pipe.rb
    branches/ruby_2_1/version.h
Index: ruby_2_1/ChangeLog
===================================================================
--- ruby_2_1/ChangeLog	(revision 46628)
+++ ruby_2_1/ChangeLog	(revision 46629)
@@ -1,3 +1,14 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_1/ChangeLog#L1
+Tue Jul  1 03:05:22 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]
+
+Tue Jul  1 03:05:22 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 Jun 30 03:15:59 2014  Nobuyoshi Nakada  <nobu@r...>
 
 	* vm.c (core_hash_merge_kwd): should return the result hash, which
Index: ruby_2_1/io.c
===================================================================
--- ruby_2_1/io.c	(revision 46628)
+++ ruby_2_1/io.c	(revision 46629)
@@ -2291,9 +2291,6 @@ io_setstrbuf(VALUE *str, long len) https://github.com/ruby/ruby/blob/trunk/ruby_2_1/io.c#L2291
 	long clen = RSTRING_LEN(s);
 	if (clen >= len) {
 	    rb_str_modify(s);
-	    if (clen != len) {
-		rb_str_set_len(s, len);
-	    }
 	    return;
 	}
 	len -= clen;
@@ -2320,23 +2317,27 @@ read_all(rb_io_t *fptr, long siz, VALUE https://github.com/ruby/ruby/blob/trunk/ruby_2_1/io.c#L2317
     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);
             }
         }
@@ -2807,7 +2808,10 @@ io_read(int argc, VALUE *argv, VALUE io) https://github.com/ruby/ruby/blob/trunk/ruby_2_1/io.c#L2808
 
     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_1/version.h
===================================================================
--- ruby_2_1/version.h	(revision 46628)
+++ ruby_2_1/version.h	(revision 46629)
@@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_1/version.h#L1
 #define RUBY_VERSION "2.1.2"
 #define RUBY_RELEASE_DATE "2014-07-01"
-#define RUBY_PATCHLEVEL 158
+#define RUBY_PATCHLEVEL 159
 
 #define RUBY_RELEASE_YEAR 2014
 #define RUBY_RELEASE_MONTH 7
Index: ruby_2_1/test/ruby/test_pipe.rb
===================================================================
--- ruby_2_1/test/ruby/test_pipe.rb	(revision 46628)
+++ ruby_2_1/test/ruby/test_pipe.rb	(revision 46629)
@@ -13,4 +13,17 @@ class TestPipe < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/ruby_2_1/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_1/test/ruby/test_io.rb
===================================================================
--- ruby_2_1/test/ruby/test_io.rb	(revision 46628)
+++ ruby_2_1/test/ruby/test_io.rb	(revision 46629)
@@ -1224,6 +1224,14 @@ class TestIO < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/ruby_2_1/test/ruby/test_io.rb#L1224
       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_1
___________________________________________________________________
Modified: svn:mergeinfo
   Merged /trunk:r46360,46372


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

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