summaryrefslogtreecommitdiff
path: root/io.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-08-26 08:12:48 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-08-26 08:12:48 +0000
commitfebf2cefb3b69dd859b3c81e0512d0bae9b315ea (patch)
tree506cfc9c79be0e3963d46022de70aeadf230dda4 /io.c
parenteec0176d149576bfc8dc90bedf502013752977b2 (diff)
downloadruby-febf2cefb3b69dd859b3c81e0512d0bae9b315ea.tar.gz
io.c: do not swallow exceptions at end of block
* io.c (io_close): ignore only "closed stream" IOError and NoMethodError, do not swallow other exceptions at the end of block. [ruby-core:64463] [Bug #10153] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47288 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'io.c')
-rw-r--r--io.c32
1 files changed, 26 insertions, 6 deletions
diff --git a/io.c b/io.c
index f2a59bab77..81d35fd862 100644
--- a/io.c
+++ b/io.c
@@ -616,6 +616,8 @@ is_socket(int fd, VALUE path)
}
#endif
+static const char closed_stream[] = "closed stream";
+
void
rb_eof_error(void)
{
@@ -642,7 +644,7 @@ rb_io_check_closed(rb_io_t *fptr)
{
rb_io_check_initialized(fptr);
if (fptr->fd < 0) {
- rb_raise(rb_eIOError, "closed stream");
+ rb_raise(rb_eIOError, closed_stream);
}
}
@@ -1124,7 +1126,7 @@ int
rb_io_wait_readable(int f)
{
if (f < 0) {
- rb_raise(rb_eIOError, "closed stream");
+ rb_raise(rb_eIOError, closed_stream);
}
switch (errno) {
case EINTR:
@@ -1150,7 +1152,7 @@ int
rb_io_wait_writable(int f)
{
if (f < 0) {
- rb_raise(rb_eIOError, "closed stream");
+ rb_raise(rb_eIOError, closed_stream);
}
switch (errno) {
case EINTR:
@@ -4164,7 +4166,7 @@ finish_writeconv(rb_io_t *fptr, int noalloc)
}
if (rb_io_wait_writable(fptr->fd)) {
if (fptr->fd < 0)
- return noalloc ? Qtrue : rb_exc_new3(rb_eIOError, rb_str_new_cstr("closed stream"));
+ return noalloc ? Qtrue : rb_exc_new3(rb_eIOError, rb_str_new_cstr(closed_stream));
goto retry;
}
return noalloc ? Qtrue : INT2NUM(errno);
@@ -4446,13 +4448,31 @@ rb_io_close_m(VALUE io)
static VALUE
io_call_close(VALUE io)
{
- return rb_funcall(io, rb_intern("close"), 0, 0);
+ rb_check_funcall(io, rb_intern("close"), 0, 0);
+ return io;
+}
+
+static VALUE
+ignore_closed_stream(VALUE io, VALUE exc)
+{
+ enum {mesg_len = sizeof(closed_stream)-1};
+ VALUE mesg = rb_attr_get(exc, rb_intern("mesg"));
+ if (!RB_TYPE_P(mesg, T_STRING) ||
+ RSTRING_LEN(mesg) != mesg_len ||
+ memcmp(RSTRING_PTR(mesg), closed_stream, mesg_len)) {
+ rb_exc_raise(exc);
+ }
+ return io;
}
static VALUE
io_close(VALUE io)
{
- return rb_rescue(io_call_close, io, 0, 0);
+ VALUE closed = rb_check_funcall(io, rb_intern("closed?"), 0, 0);
+ if (closed != Qundef && RTEST(closed)) return io;
+ rb_rescue2(io_call_close, io, ignore_closed_stream, io,
+ rb_eIOError, (VALUE)0);
+ return io;
}
/*