ruby-changes:35421
From: usa <ko1@a...>
Date: Wed, 10 Sep 2014 12:36:39 +0900 (JST)
Subject: [ruby-changes:35421] usa:r47503 (ruby_2_0_0): merge revision(s) 47288: [Backport #10153]
usa 2014-09-10 12:36:25 +0900 (Wed, 10 Sep 2014) New Revision: 47503 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=47503 Log: merge revision(s) 47288: [Backport #10153] * 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] Modified directories: branches/ruby_2_0_0/ Modified files: branches/ruby_2_0_0/ChangeLog branches/ruby_2_0_0/io.c branches/ruby_2_0_0/test/ruby/test_io.rb branches/ruby_2_0_0/version.h Index: ruby_2_0_0/ChangeLog =================================================================== --- ruby_2_0_0/ChangeLog (revision 47502) +++ ruby_2_0_0/ChangeLog (revision 47503) @@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/ChangeLog#L1 +Wed Sep 10 12:34:34 2014 Nobuyoshi Nakada <nobu@r...> + + * 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] + Wed Sep 10 12:27:08 2014 Nobuyoshi Nakada <nobu@r...> * enc/trans/euckr-tbl.rb (EUCKR_TO_UCS_TBL): add missing euro and Index: ruby_2_0_0/io.c =================================================================== --- ruby_2_0_0/io.c (revision 47502) +++ ruby_2_0_0/io.c (revision 47503) @@ -577,6 +577,8 @@ is_socket(int fd, VALUE path) https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/io.c#L577 } #endif +static const char closed_stream[] = "closed stream"; + void rb_eof_error(void) { @@ -611,7 +613,7 @@ rb_io_check_closed(rb_io_t *fptr) https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/io.c#L613 { rb_io_check_initialized(fptr); if (fptr->fd < 0) { - rb_raise(rb_eIOError, "closed stream"); + rb_raise(rb_eIOError, closed_stream); } } @@ -1070,7 +1072,7 @@ int https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/io.c#L1072 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: @@ -1096,7 +1098,7 @@ int https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/io.c#L1098 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: @@ -4003,7 +4005,7 @@ finish_writeconv(rb_io_t *fptr, int noal https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/io.c#L4005 } 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); @@ -4288,13 +4290,31 @@ rb_io_close_m(VALUE io) https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/io.c#L4290 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; } /* Index: ruby_2_0_0/version.h =================================================================== --- ruby_2_0_0/version.h (revision 47502) +++ ruby_2_0_0/version.h (revision 47503) @@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/version.h#L1 #define RUBY_VERSION "2.0.0" #define RUBY_RELEASE_DATE "2014-09-10" -#define RUBY_PATCHLEVEL 564 +#define RUBY_PATCHLEVEL 565 #define RUBY_RELEASE_YEAR 2014 #define RUBY_RELEASE_MONTH 9 Index: ruby_2_0_0/test/ruby/test_io.rb =================================================================== --- ruby_2_0_0/test/ruby/test_io.rb (revision 47502) +++ ruby_2_0_0/test/ruby/test_io.rb (revision 47503) @@ -2800,4 +2800,13 @@ End https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/test/ruby/test_io.rb#L2800 ensure t.kill end + + def test_exception_at_close + bug10153 = '[ruby-core:64463] [Bug #10153] exception in close at the end of block' + assert_raise(Errno::EBADF, bug10153) do + IO.pipe do |r, w| + assert_nothing_raised {IO.open(w.fileno) {}} + end + end + end end Property changes on: ruby_2_0_0 ___________________________________________________________________ Modified: svn:mergeinfo Merged /trunk:r47288 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/