* io.c (flush_before_seek): check io_fflush result.
(rb_io_check_readable): ditto. (rb_io_flush): ditto. (rb_io_fsync): ditto. (remain_size): ditto. (rb_io_write_nonblock): ditto. (finish_writeconv): ditto. (fptr_finalize): ditto. (io_reopen): ditto. (rb_io_reopen): ditto. (copy_stream_body): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@20989 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
ad558a3a7f
commit
db0a659012
14
ChangeLog
14
ChangeLog
@ -1,3 +1,17 @@
|
|||||||
|
Thu Dec 25 16:23:31 2008 Tanaka Akira <akr@fsij.org>
|
||||||
|
|
||||||
|
* io.c (flush_before_seek): check io_fflush result.
|
||||||
|
(rb_io_check_readable): ditto.
|
||||||
|
(rb_io_flush): ditto.
|
||||||
|
(rb_io_fsync): ditto.
|
||||||
|
(remain_size): ditto.
|
||||||
|
(rb_io_write_nonblock): ditto.
|
||||||
|
(finish_writeconv): ditto.
|
||||||
|
(fptr_finalize): ditto.
|
||||||
|
(io_reopen): ditto.
|
||||||
|
(rb_io_reopen): ditto.
|
||||||
|
(copy_stream_body): ditto.
|
||||||
|
|
||||||
Thu Dec 25 15:54:00 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
|
Thu Dec 25 15:54:00 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
|
||||||
|
|
||||||
* io.c (io_fflush): flush write buffer without write lock in
|
* io.c (io_fflush): flush write buffer without write lock in
|
||||||
|
42
io.c
42
io.c
@ -340,7 +340,8 @@ io_ungetbyte(VALUE str, rb_io_t *fptr)
|
|||||||
static rb_io_t *
|
static rb_io_t *
|
||||||
flush_before_seek(rb_io_t *fptr)
|
flush_before_seek(rb_io_t *fptr)
|
||||||
{
|
{
|
||||||
io_fflush(fptr);
|
if (io_fflush(fptr) < 0)
|
||||||
|
rb_sys_fail(0);
|
||||||
io_unread(fptr);
|
io_unread(fptr);
|
||||||
errno = 0;
|
errno = 0;
|
||||||
return fptr;
|
return fptr;
|
||||||
@ -365,12 +366,14 @@ rb_io_check_readable(rb_io_t *fptr)
|
|||||||
rb_raise(rb_eIOError, "not opened for reading");
|
rb_raise(rb_eIOError, "not opened for reading");
|
||||||
}
|
}
|
||||||
if (fptr->wbuf_len) {
|
if (fptr->wbuf_len) {
|
||||||
io_fflush(fptr);
|
if (io_fflush(fptr) < 0)
|
||||||
|
rb_sys_fail(0);
|
||||||
}
|
}
|
||||||
if (fptr->tied_io_for_writing) {
|
if (fptr->tied_io_for_writing) {
|
||||||
rb_io_t *wfptr;
|
rb_io_t *wfptr;
|
||||||
GetOpenFile(fptr->tied_io_for_writing, wfptr);
|
GetOpenFile(fptr->tied_io_for_writing, wfptr);
|
||||||
io_fflush(wfptr);
|
if (io_fflush(wfptr) < 0)
|
||||||
|
rb_sys_fail(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -988,7 +991,8 @@ rb_io_flush(VALUE io)
|
|||||||
GetOpenFile(io, fptr);
|
GetOpenFile(io, fptr);
|
||||||
|
|
||||||
if (fptr->mode & FMODE_WRITABLE) {
|
if (fptr->mode & FMODE_WRITABLE) {
|
||||||
io_fflush(fptr);
|
if (io_fflush(fptr) < 0)
|
||||||
|
rb_sys_fail(0);
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
fsync(fptr->fd);
|
fsync(fptr->fd);
|
||||||
#endif
|
#endif
|
||||||
@ -1284,7 +1288,8 @@ rb_io_fsync(VALUE io)
|
|||||||
io = GetWriteIO(io);
|
io = GetWriteIO(io);
|
||||||
GetOpenFile(io, fptr);
|
GetOpenFile(io, fptr);
|
||||||
|
|
||||||
io_fflush(fptr);
|
if (io_fflush(fptr) < 0)
|
||||||
|
rb_sys_fail(0);
|
||||||
if (fsync(fptr->fd) < 0)
|
if (fsync(fptr->fd) < 0)
|
||||||
rb_sys_fail_path(fptr->pathv);
|
rb_sys_fail_path(fptr->pathv);
|
||||||
return INT2FIX(0);
|
return INT2FIX(0);
|
||||||
@ -1466,7 +1471,8 @@ remain_size(rb_io_t *fptr)
|
|||||||
#endif
|
#endif
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
io_fflush(fptr);
|
if (io_fflush(fptr) < 0)
|
||||||
|
rb_sys_fail(0);
|
||||||
pos = lseek(fptr->fd, 0, SEEK_CUR);
|
pos = lseek(fptr->fd, 0, SEEK_CUR);
|
||||||
if (st.st_size >= pos && pos >= 0) {
|
if (st.st_size >= pos && pos >= 0) {
|
||||||
siz += st.st_size - pos;
|
siz += st.st_size - pos;
|
||||||
@ -1907,7 +1913,8 @@ rb_io_write_nonblock(VALUE io, VALUE str)
|
|||||||
GetOpenFile(io, fptr);
|
GetOpenFile(io, fptr);
|
||||||
rb_io_check_writable(fptr);
|
rb_io_check_writable(fptr);
|
||||||
|
|
||||||
io_fflush(fptr);
|
if (io_fflush(fptr) < 0)
|
||||||
|
rb_sys_fail(0);
|
||||||
|
|
||||||
rb_io_set_nonblock(fptr);
|
rb_io_set_nonblock(fptr);
|
||||||
n = write(fptr->fd, RSTRING_PTR(str), RSTRING_LEN(str));
|
n = write(fptr->fd, RSTRING_PTR(str), RSTRING_LEN(str));
|
||||||
@ -3075,7 +3082,8 @@ finish_writeconv(rb_io_t *fptr, int noraise)
|
|||||||
res = econv_destination_buffer_full;
|
res = econv_destination_buffer_full;
|
||||||
while (res == econv_destination_buffer_full) {
|
while (res == econv_destination_buffer_full) {
|
||||||
if (fptr->wbuf_len == fptr->wbuf_capa) {
|
if (fptr->wbuf_len == fptr->wbuf_capa) {
|
||||||
io_fflush(fptr);
|
if (io_fflush(fptr) < 0 && !noraise)
|
||||||
|
rb_sys_fail(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
ds = dp = (unsigned char *)fptr->wbuf + fptr->wbuf_off + fptr->wbuf_len;
|
ds = dp = (unsigned char *)fptr->wbuf + fptr->wbuf_off + fptr->wbuf_len;
|
||||||
@ -3123,7 +3131,8 @@ fptr_finalize(rb_io_t *fptr, int noraise)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (fptr->wbuf_len) {
|
if (fptr->wbuf_len) {
|
||||||
io_fflush(fptr);
|
if (io_fflush(fptr) < 0 && !noraise)
|
||||||
|
rb_sys_fail(0);
|
||||||
}
|
}
|
||||||
if (IS_PREP_STDIO(fptr) ||
|
if (IS_PREP_STDIO(fptr) ||
|
||||||
fptr->fd <= 2) {
|
fptr->fd <= 2) {
|
||||||
@ -5224,10 +5233,12 @@ io_reopen(VALUE io, VALUE nfile)
|
|||||||
pos = io_tell(orig);
|
pos = io_tell(orig);
|
||||||
}
|
}
|
||||||
if (orig->mode & FMODE_WRITABLE) {
|
if (orig->mode & FMODE_WRITABLE) {
|
||||||
io_fflush(orig);
|
if (io_fflush(orig) < 0)
|
||||||
|
rb_sys_fail(0);
|
||||||
}
|
}
|
||||||
if (fptr->mode & FMODE_WRITABLE) {
|
if (fptr->mode & FMODE_WRITABLE) {
|
||||||
io_fflush(fptr);
|
if (io_fflush(fptr) < 0)
|
||||||
|
rb_sys_fail(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* copy rb_io_t structure */
|
/* copy rb_io_t structure */
|
||||||
@ -5340,7 +5351,8 @@ rb_io_reopen(int argc, VALUE *argv, VALUE file)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (fptr->mode & FMODE_WRITABLE) {
|
if (fptr->mode & FMODE_WRITABLE) {
|
||||||
io_fflush(fptr);
|
if (io_fflush(fptr) < 0)
|
||||||
|
rb_sys_fail(0);
|
||||||
}
|
}
|
||||||
fptr->rbuf_off = fptr->rbuf_len = 0;
|
fptr->rbuf_off = fptr->rbuf_len = 0;
|
||||||
|
|
||||||
@ -7768,8 +7780,10 @@ copy_stream_body(VALUE arg)
|
|||||||
str = rb_str_buf_new(len);
|
str = rb_str_buf_new(len);
|
||||||
rb_str_resize(str,len);
|
rb_str_resize(str,len);
|
||||||
read_buffered_data(RSTRING_PTR(str), len, src_fptr);
|
read_buffered_data(RSTRING_PTR(str), len, src_fptr);
|
||||||
if (dst_fptr) /* IO or filename */
|
if (dst_fptr) { /* IO or filename */
|
||||||
io_binwrite(str, dst_fptr, 0);
|
if (io_binwrite(str, dst_fptr, 0) < 0)
|
||||||
|
rb_sys_fail(0);
|
||||||
|
}
|
||||||
else /* others such as StringIO */
|
else /* others such as StringIO */
|
||||||
rb_io_write(stp->dst, str);
|
rb_io_write(stp->dst, str);
|
||||||
stp->total += len;
|
stp->total += len;
|
||||||
|
@ -1249,13 +1249,13 @@ class TestIO < Test::Unit::TestCase
|
|||||||
def test_initialize
|
def test_initialize
|
||||||
t = make_tempfile
|
t = make_tempfile
|
||||||
|
|
||||||
fd = IO.sysopen(t.path)
|
fd = IO.sysopen(t.path, "w")
|
||||||
assert_kind_of(Integer, fd)
|
assert_kind_of(Integer, fd)
|
||||||
f = IO.new(fd, "w")
|
f = IO.new(fd, "w")
|
||||||
f.write("FOO\n")
|
f.write("FOO\n")
|
||||||
f.close
|
f.close
|
||||||
|
|
||||||
assert_equal("foo\nbar\nbaz\n", File.read(t.path))
|
assert_equal("FOO\n", File.read(t.path))
|
||||||
|
|
||||||
f = open(t.path)
|
f = open(t.path)
|
||||||
assert_raise(RuntimeError) do
|
assert_raise(RuntimeError) do
|
||||||
|
Loading…
x
Reference in New Issue
Block a user