summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--io.c9
-rw-r--r--test/ruby/test_io_buffer.rb2
2 files changed, 9 insertions, 2 deletions
diff --git a/io.c b/io.c
index f4698a2cd5..28b5abb1c5 100644
--- a/io.c
+++ b/io.c
@@ -2870,8 +2870,15 @@ rb_io_descriptor(VALUE io)
return fptr->fd;
}
else {
- return RB_NUM2INT(rb_funcall(io, id_fileno, 0));
+ VALUE fileno = rb_check_funcall(io, id_fileno, 0, NULL);
+ if (!UNDEF_P(fileno)) {
+ return RB_NUM2INT(fileno);
+ }
}
+
+ rb_raise(rb_eTypeError, "expected IO or #fileno, %"PRIsVALUE" given", rb_obj_class(io));
+
+ UNREACHABLE_RETURN(-1);
}
int
diff --git a/test/ruby/test_io_buffer.rb b/test/ruby/test_io_buffer.rb
index 1b4a09dd20..dea8388d7d 100644
--- a/test/ruby/test_io_buffer.rb
+++ b/test/ruby/test_io_buffer.rb
@@ -80,7 +80,7 @@ class TestIOBuffer < Test::Unit::TestCase
end
def test_file_mapped_invalid
- assert_raise NoMethodError do
+ assert_raise TypeError do
IO::Buffer.map("foobar")
end
end