Raise TypeError for bad IO::Buffer.map argument (#8728)
* Raise TypeError when IO::Buffer.map argument is neither IO nor implements #fileno * Use UNREACHABLE_CODE Co-authored-by: Nobuyoshi Nakada <nobu@ruby-lang.org> * Use macro for undef check Co-authored-by: Nobuyoshi Nakada <nobu@ruby-lang.org> --------- Co-authored-by: Nobuyoshi Nakada <nobu@ruby-lang.org>
This commit is contained in:
parent
0e62802c3b
commit
55d954721e
9
io.c
9
io.c
@ -2870,10 +2870,17 @@ rb_io_descriptor(VALUE io)
|
|||||||
return fptr->fd;
|
return fptr->fd;
|
||||||
}
|
}
|
||||||
else {
|
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
|
int
|
||||||
rb_io_mode(VALUE io)
|
rb_io_mode(VALUE io)
|
||||||
{
|
{
|
||||||
|
@ -80,7 +80,7 @@ class TestIOBuffer < Test::Unit::TestCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_file_mapped_invalid
|
def test_file_mapped_invalid
|
||||||
assert_raise NoMethodError do
|
assert_raise TypeError do
|
||||||
IO::Buffer.map("foobar")
|
IO::Buffer.map("foobar")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user