1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

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]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_1@46629 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nagachika 2014-06-30 18:12:05 +00:00
parent 09cf452926
commit 428a637f0f
5 changed files with 41 additions and 5 deletions

View file

@ -1,3 +1,14 @@
Tue Jul 1 03:05:22 2014 Nobuyoshi Nakada <nobu@ruby-lang.org>
* 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@ruby-lang.org>
* 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@ruby-lang.org>
* vm.c (core_hash_merge_kwd): should return the result hash, which

12
io.c
View file

@ -2291,9 +2291,6 @@ io_setstrbuf(VALUE *str, long len)
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 str)
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)
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)

View file

@ -1224,6 +1224,14 @@ class TestIO < Test::Unit::TestCase
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

View file

@ -13,4 +13,17 @@ class TestPipe < Test::Unit::TestCase
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

View file

@ -1,6 +1,6 @@
#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