* io.c (rb_io_close_read, rb_io_close_write): don't raise after
  close same as IO#close.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49961 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2015-03-13 06:03:25 +00:00
Родитель 3338bc99e5
Коммит 89bfc9b70b
3 изменённых файлов: 22 добавлений и 8 удалений

Просмотреть файл

@ -1,3 +1,8 @@
Fri Mar 13 15:03:20 2015 Nobuyoshi Nakada <nobu@ruby-lang.org>
* io.c (rb_io_close_read, rb_io_close_write): don't raise after
close same as IO#close.
Fri Mar 13 12:29:07 2015 Tanaka Akira <akr@fsij.org>
* test/readline/test_readline.rb: Restore environment variables:

16
io.c
Просмотреть файл

@ -4528,7 +4528,8 @@ rb_io_close_read(VALUE io)
rb_io_t *fptr;
VALUE write_io;
GetOpenFile(io, fptr);
fptr = rb_io_get_fptr(rb_io_taint_check(io));
if (fptr->fd < 0) return Qnil;
if (is_socket(fptr->fd, fptr->pathv)) {
#ifndef SHUT_RD
# define SHUT_RD 0
@ -4544,20 +4545,19 @@ rb_io_close_read(VALUE io)
write_io = GetWriteIO(io);
if (io != write_io) {
rb_io_t *wfptr;
GetOpenFile(write_io, wfptr);
wfptr = rb_io_get_fptr(rb_io_taint_check(write_io));
wfptr->pid = fptr->pid;
fptr->pid = 0;
RFILE(io)->fptr = wfptr;
/* bind to write_io temporarily to get rid of memory/fd leak */
fptr->tied_io_for_writing = 0;
fptr->mode &= ~FMODE_DUPLEX;
RFILE(write_io)->fptr = fptr;
rb_io_fptr_cleanup(fptr, FALSE);
/* should not finalize fptr because another thread may be reading it */
return Qnil;
}
if (fptr->mode & FMODE_WRITABLE) {
if ((fptr->mode & (FMODE_DUPLEX|FMODE_WRITABLE)) == FMODE_WRITABLE) {
rb_raise(rb_eIOError, "closing non-duplex IO for reading");
}
return rb_io_close(io);
@ -4589,7 +4589,8 @@ rb_io_close_write(VALUE io)
VALUE write_io;
write_io = GetWriteIO(io);
GetOpenFile(write_io, fptr);
fptr = rb_io_get_fptr(rb_io_taint_check(write_io));
if (fptr->fd < 0) return Qnil;
if (is_socket(fptr->fd, fptr->pathv)) {
#ifndef SHUT_WR
# define SHUT_WR 1
@ -4602,14 +4603,13 @@ rb_io_close_write(VALUE io)
return Qnil;
}
if (fptr->mode & FMODE_READABLE) {
if ((fptr->mode & (FMODE_DUPLEX|FMODE_READABLE)) == FMODE_READABLE) {
rb_raise(rb_eIOError, "closing non-duplex IO for writing");
}
if (io != write_io) {
GetOpenFile(io, fptr);
fptr = rb_io_get_fptr(rb_io_taint_check(io));
fptr->tied_io_for_writing = 0;
fptr->mode &= ~FMODE_DUPLEX;
}
rb_io_close(write_io);
return Qnil;

Просмотреть файл

@ -1364,6 +1364,9 @@ class TestIO < Test::Unit::TestCase
f.close_read
f.write "foobarbaz"
assert_raise(IOError) { f.read }
assert_nothing_raised(IOError) {f.close_read}
assert_nothing_raised(IOError) {f.close}
assert_nothing_raised(IOError) {f.close_read}
end
end
@ -1371,6 +1374,9 @@ class TestIO < Test::Unit::TestCase
with_pipe do |r, w|
r.close_read
assert_raise(Errno::EPIPE) { w.write "foobarbaz" }
assert_nothing_raised(IOError) {r.close_read}
assert_nothing_raised(IOError) {r.close}
assert_nothing_raised(IOError) {r.close_read}
end
end
@ -1398,6 +1404,9 @@ class TestIO < Test::Unit::TestCase
f.write "foobarbaz"
f.close_write
assert_equal("foobarbaz", f.read)
assert_nothing_raised(IOError) {f.close_write}
assert_nothing_raised(IOError) {f.close}
assert_nothing_raised(IOError) {f.close_write}
end
end