aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-03-13 06:03:25 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-03-13 06:03:25 +0000
commit89bfc9b70b05ac598d24bb712222b79fb9af1880 (patch)
tree160c5a58d96db412e5d8c99d90cccdf66b29d06d
parent3338bc99e5163813cfe129844bcf397a77d4b916 (diff)
downloadruby-89bfc9b70b05ac598d24bb712222b79fb9af1880.tar.gz
io.c: don't raise after close
* 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
-rw-r--r--ChangeLog5
-rw-r--r--io.c16
-rw-r--r--test/ruby/test_io.rb9
3 files changed, 22 insertions, 8 deletions
diff --git a/ChangeLog b/ChangeLog
index f26b3f783b..fa841fef56 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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:
diff --git a/io.c b/io.c
index 06c3f8f7d6..3ac591a113 100644
--- a/io.c
+++ b/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;
diff --git a/test/ruby/test_io.rb b/test/ruby/test_io.rb
index 600373a06c..81b99d55d1 100644
--- a/test/ruby/test_io.rb
+++ b/test/ruby/test_io.rb
@@ -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