From 2e5d698538ea132a4dcd46d924c071227b5f4956 Mon Sep 17 00:00:00 2001 From: nobu Date: Tue, 27 May 2014 02:12:59 +0000 Subject: [PATCH] io.c: no error on frozen IO * io.c (rb_io_fileno, rb_io_inspect): non-modification does not error on frozen IO. [ruby-dev:48241] [Bug #9865] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46151 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 5 +++++ io.c | 6 +++--- test/ruby/test_io.rb | 10 ++++++++++ 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1bafb70ef8..39230dd9b3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Tue May 27 11:12:56 2014 Nobuyoshi Nakada + + * io.c (rb_io_fileno, rb_io_inspect): non-modification does not + error on frozen IO. [ruby-dev:48241] [Bug #9865] + Tue May 27 00:00:21 2014 yui-knk * insns.def (defineclass): fix typo in the instruction comment. diff --git a/io.c b/io.c index 18a0e2cb2e..61a77d7a25 100644 --- a/io.c +++ b/io.c @@ -1996,10 +1996,10 @@ rb_io_fdatasync(VALUE io) static VALUE rb_io_fileno(VALUE io) { - rb_io_t *fptr; + rb_io_t *fptr = RFILE(io)->fptr; int fd; - GetOpenFile(io, fptr); + rb_io_check_closed(fptr); fd = fptr->fd; return INT2FIX(fd); } @@ -2051,7 +2051,7 @@ rb_io_inspect(VALUE obj) VALUE result; static const char closed[] = " (closed)"; - fptr = RFILE(rb_io_taint_check(obj))->fptr; + fptr = RFILE(obj)->fptr; if (!fptr) return rb_any_to_s(obj); result = rb_str_new_cstr("#<"); rb_str_append(result, rb_class_name(CLASS_OF(obj))); diff --git a/test/ruby/test_io.rb b/test/ruby/test_io.rb index 79a4bb4599..0d5671a267 100644 --- a/test/ruby/test_io.rb +++ b/test/ruby/test_io.rb @@ -1122,6 +1122,8 @@ class TestIO < Test::Unit::TestCase def test_inspect with_pipe do |r, w| assert_match(/^#$/, r.inspect) + r.freeze + assert_match(/^#$/, r.inspect) end end @@ -2786,6 +2788,14 @@ End assert_equal(2, $stderr.fileno) end + def test_frozen_fileno + bug9865 = '[ruby-dev:48241] [Bug #9865]' + with_pipe do |r,w| + fd = r.fileno + assert_equal(fd, r.freeze.fileno, bug9865) + end + end + def test_sysread_locktmp bug6099 = '[ruby-dev:45297]' buf = " " * 100