* io.c (io_fread, io_getpartial, rb_io_sysread): set buffer size
after check if readable, which can cause thread switch. [ruby-dev:45297][Bug #6099] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@34846 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
007b7fcdcf
commit
9b02a72d71
@ -1,3 +1,9 @@
|
|||||||
|
Tue Feb 28 18:33:30 2012 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
|
* io.c (io_fread, io_getpartial, rb_io_sysread): set buffer size
|
||||||
|
after check if readable, which can cause thread switch.
|
||||||
|
[ruby-dev:45297][Bug #6099]
|
||||||
|
|
||||||
Tue Feb 28 17:16:01 2012 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
Tue Feb 28 17:16:01 2012 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
* lib/time.rb (Time#xmlschema): use strftime specifiers instead of
|
* lib/time.rb (Time#xmlschema): use strftime specifiers instead of
|
||||||
|
5
io.c
5
io.c
@ -1872,11 +1872,14 @@ io_bufread(char *ptr, long len, rb_io_t *fptr)
|
|||||||
return len - n;
|
return len - n;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void io_setstrbuf(VALUE *str, long len);
|
||||||
|
|
||||||
static long
|
static long
|
||||||
io_fread(VALUE str, long offset, long size, rb_io_t *fptr)
|
io_fread(VALUE str, long offset, long size, rb_io_t *fptr)
|
||||||
{
|
{
|
||||||
long len;
|
long len;
|
||||||
|
|
||||||
|
io_setstrbuf(&str, offset + size);
|
||||||
rb_str_locktmp(str);
|
rb_str_locktmp(str);
|
||||||
len = io_bufread(RSTRING_PTR(str) + offset, size, fptr);
|
len = io_bufread(RSTRING_PTR(str) + offset, size, fptr);
|
||||||
rb_str_unlocktmp(str);
|
rb_str_unlocktmp(str);
|
||||||
@ -2208,6 +2211,7 @@ io_getpartial(int argc, VALUE *argv, VALUE io, int nonblock)
|
|||||||
if (nonblock) {
|
if (nonblock) {
|
||||||
rb_io_set_nonblock(fptr);
|
rb_io_set_nonblock(fptr);
|
||||||
}
|
}
|
||||||
|
io_setstrbuf(&str, len);
|
||||||
rb_str_locktmp(str);
|
rb_str_locktmp(str);
|
||||||
n = rb_read_internal(fptr->fd, RSTRING_PTR(str), len);
|
n = rb_read_internal(fptr->fd, RSTRING_PTR(str), len);
|
||||||
rb_str_unlocktmp(str);
|
rb_str_unlocktmp(str);
|
||||||
@ -4269,6 +4273,7 @@ rb_io_sysread(int argc, VALUE *argv, VALUE io)
|
|||||||
rb_thread_wait_fd(fptr->fd);
|
rb_thread_wait_fd(fptr->fd);
|
||||||
rb_io_check_closed(fptr);
|
rb_io_check_closed(fptr);
|
||||||
|
|
||||||
|
io_setstrbuf(&str, ilen);
|
||||||
rb_str_locktmp(str);
|
rb_str_locktmp(str);
|
||||||
n = rb_read_internal(fptr->fd, RSTRING_PTR(str), ilen);
|
n = rb_read_internal(fptr->fd, RSTRING_PTR(str), ilen);
|
||||||
rb_str_unlocktmp(str);
|
rb_str_unlocktmp(str);
|
||||||
|
@ -2240,4 +2240,37 @@ End
|
|||||||
assert_equal(1, $stdout.fileno)
|
assert_equal(1, $stdout.fileno)
|
||||||
assert_equal(2, $stderr.fileno)
|
assert_equal(2, $stderr.fileno)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_sysread_locktmp
|
||||||
|
bug6099 = '[ruby-dev:45297]'
|
||||||
|
buf = " " * 100
|
||||||
|
data = "a" * 100
|
||||||
|
with_pipe do |r,w|
|
||||||
|
th = Thread.new {r.sysread(100, buf)}
|
||||||
|
Thread.pass until th.stop?
|
||||||
|
buf.replace("")
|
||||||
|
assert_empty(buf)
|
||||||
|
w.write(data)
|
||||||
|
Thread.pass while th.alive?
|
||||||
|
th.join
|
||||||
|
end
|
||||||
|
assert_equal(data, buf)
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_readpartial_locktmp
|
||||||
|
bug6099 = '[ruby-dev:45297]'
|
||||||
|
buf = " " * 100
|
||||||
|
data = "a" * 100
|
||||||
|
with_pipe do |r,w|
|
||||||
|
r.fcntl(Fcntl::F_SETFL, Fcntl::O_NONBLOCK)
|
||||||
|
th = Thread.new {r.readpartial(100, buf)}
|
||||||
|
Thread.pass until th.stop?
|
||||||
|
buf.replace("")
|
||||||
|
assert_empty(buf)
|
||||||
|
w.write(data)
|
||||||
|
Thread.pass while th.alive?
|
||||||
|
th.join
|
||||||
|
end
|
||||||
|
assert_equal(data, buf)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user