Skip to content

Commit 7dae01e

Browse files
committed
[GR-18163] T_FILE should be for IO instances, not just File (#2662)
PullRequest: truffleruby/3366
2 parents b8867bd + 0b46762 commit 7dae01e

File tree

4 files changed

+25
-1
lines changed

4 files changed

+25
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ Compatibility:
3535
* Implement specializations for immutable ruby objects for ObjectSpace methods (@bjfish).
3636
* Use `$PAGER` for `--help` and `--help*`, similar to CRuby (#2542, @Strech).
3737
* Ensure all headers are warnings-free (#2662, @eregon).
38+
* All `IO` instances should have `T_FILE` as their `rb_type()`, not only `File` instances (#2662, @eregon).
3839

3940
Performance:
4041

lib/truffle/truffle/cext.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ def rb_tr_find_type(value)
215215
T_HASH
216216
when Struct
217217
T_STRUCT
218-
when File
218+
when IO
219219
T_FILE
220220
when Complex
221221
T_COMPLEX

spec/ruby/optional/capi/ext/object_spec.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,13 @@ static VALUE so_is_rb_type_p_data(VALUE self, VALUE obj) {
301301
return Qfalse;
302302
}
303303

304+
static VALUE so_is_rb_type_p_file(VALUE self, VALUE obj) {
305+
if(rb_type_p(obj, T_FILE)) {
306+
return Qtrue;
307+
}
308+
return Qfalse;
309+
}
310+
304311
static VALUE so_is_builtin_type_object(VALUE self, VALUE obj) {
305312
if(BUILTIN_TYPE(obj) == T_OBJECT) {
306313
return Qtrue;
@@ -478,6 +485,7 @@ void Init_object_spec(void) {
478485
rb_define_method(cls, "rb_is_rb_type_p_module", so_is_rb_type_p_module, 1);
479486
rb_define_method(cls, "rb_is_rb_type_p_class", so_is_rb_type_p_class, 1);
480487
rb_define_method(cls, "rb_is_rb_type_p_data", so_is_rb_type_p_data, 1);
488+
rb_define_method(cls, "rb_is_rb_type_p_file", so_is_rb_type_p_file, 1);
481489
rb_define_method(cls, "rb_is_builtin_type_object", so_is_builtin_type_object, 1);
482490
rb_define_method(cls, "rb_is_builtin_type_array", so_is_builtin_type_array, 1);
483491
rb_define_method(cls, "rb_is_builtin_type_module", so_is_builtin_type_module, 1);

spec/ruby/optional/capi/object_spec.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,21 @@ class DescArray < Array
513513
@o.rb_is_type_class(ObjectTest).should == true
514514
@o.rb_is_type_data(Time.now).should == true
515515
end
516+
517+
it "returns T_FILE for instances of IO and subclasses" do
518+
STDERR.class.should == IO
519+
@o.rb_is_rb_type_p_file(STDERR).should == true
520+
521+
File.open(__FILE__) do |f|
522+
f.class.should == File
523+
@o.rb_is_rb_type_p_file(f).should == true
524+
end
525+
526+
require 'socket'
527+
TCPServer.open(0) do |s|
528+
@o.rb_is_rb_type_p_file(s).should == true
529+
end
530+
end
516531
end
517532

518533
describe "rb_check_type" do

0 commit comments

Comments
 (0)