mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
merge revision(s) r47288: [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] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_1@47486 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
5545b8b459
commit
8f01a27817
4 changed files with 42 additions and 7 deletions
|
@ -1,3 +1,9 @@
|
||||||
|
Wed Sep 10 03:29:48 2014 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
|
* 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 03:17:13 2014 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
Wed Sep 10 03:17:13 2014 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
* enc/trans/euckr-tbl.rb (EUCKR_TO_UCS_TBL): add missing euro and
|
* enc/trans/euckr-tbl.rb (EUCKR_TO_UCS_TBL): add missing euro and
|
||||||
|
|
32
io.c
32
io.c
|
@ -590,6 +590,8 @@ is_socket(int fd, VALUE path)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
static const char closed_stream[] = "closed stream";
|
||||||
|
|
||||||
void
|
void
|
||||||
rb_eof_error(void)
|
rb_eof_error(void)
|
||||||
{
|
{
|
||||||
|
@ -616,7 +618,7 @@ rb_io_check_closed(rb_io_t *fptr)
|
||||||
{
|
{
|
||||||
rb_io_check_initialized(fptr);
|
rb_io_check_initialized(fptr);
|
||||||
if (fptr->fd < 0) {
|
if (fptr->fd < 0) {
|
||||||
rb_raise(rb_eIOError, "closed stream");
|
rb_raise(rb_eIOError, closed_stream);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1075,7 +1077,7 @@ int
|
||||||
rb_io_wait_readable(int f)
|
rb_io_wait_readable(int f)
|
||||||
{
|
{
|
||||||
if (f < 0) {
|
if (f < 0) {
|
||||||
rb_raise(rb_eIOError, "closed stream");
|
rb_raise(rb_eIOError, closed_stream);
|
||||||
}
|
}
|
||||||
switch (errno) {
|
switch (errno) {
|
||||||
case EINTR:
|
case EINTR:
|
||||||
|
@ -1101,7 +1103,7 @@ int
|
||||||
rb_io_wait_writable(int f)
|
rb_io_wait_writable(int f)
|
||||||
{
|
{
|
||||||
if (f < 0) {
|
if (f < 0) {
|
||||||
rb_raise(rb_eIOError, "closed stream");
|
rb_raise(rb_eIOError, closed_stream);
|
||||||
}
|
}
|
||||||
switch (errno) {
|
switch (errno) {
|
||||||
case EINTR:
|
case EINTR:
|
||||||
|
@ -4062,7 +4064,7 @@ finish_writeconv(rb_io_t *fptr, int noalloc)
|
||||||
}
|
}
|
||||||
if (rb_io_wait_writable(fptr->fd)) {
|
if (rb_io_wait_writable(fptr->fd)) {
|
||||||
if (fptr->fd < 0)
|
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;
|
goto retry;
|
||||||
}
|
}
|
||||||
return noalloc ? Qtrue : INT2NUM(errno);
|
return noalloc ? Qtrue : INT2NUM(errno);
|
||||||
|
@ -4344,13 +4346,31 @@ rb_io_close_m(VALUE io)
|
||||||
static VALUE
|
static VALUE
|
||||||
io_call_close(VALUE io)
|
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
|
static VALUE
|
||||||
io_close(VALUE io)
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -2995,4 +2995,13 @@ End
|
||||||
ensure
|
ensure
|
||||||
t.kill
|
t.kill
|
||||||
end
|
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
|
end
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#define RUBY_VERSION "2.1.2"
|
#define RUBY_VERSION "2.1.2"
|
||||||
#define RUBY_RELEASE_DATE "2014-09-10"
|
#define RUBY_RELEASE_DATE "2014-09-10"
|
||||||
#define RUBY_PATCHLEVEL 231
|
#define RUBY_PATCHLEVEL 232
|
||||||
|
|
||||||
#define RUBY_RELEASE_YEAR 2014
|
#define RUBY_RELEASE_YEAR 2014
|
||||||
#define RUBY_RELEASE_MONTH 9
|
#define RUBY_RELEASE_MONTH 9
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue