aboutsummaryrefslogtreecommitdiffstats
path: root/io.c
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 /io.c
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
Diffstat (limited to 'io.c')
-rw-r--r--io.c16
1 files changed, 8 insertions, 8 deletions
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;