Skip to content

Commit

Permalink
[GR-18163] Declare rb_io_mode() and rb_io_path() and add specs
Browse files Browse the repository at this point in the history
PullRequest: truffleruby/4086
  • Loading branch information
eregon committed Dec 8, 2023
2 parents 070598d + 1c8de1a commit b7cb7fe
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 2 deletions.
6 changes: 6 additions & 0 deletions lib/cext/include/ruby/io.h
Original file line number Diff line number Diff line change
Expand Up @@ -724,6 +724,12 @@ void rb_io_set_nonblock(rb_io_t *fptr);
*/
int rb_io_descriptor(VALUE io);

#ifdef TRUFFLERUBY
// These functions come from 3.3 but truffleruby already implements them
VALUE rb_io_path(VALUE io);
int rb_io_mode(VALUE io);
#endif

/**
* This function breaks down the option hash that `IO#initialize` takes into
* components. This is an implementation detail of rb_io_extract_modeenc()
Expand Down
2 changes: 1 addition & 1 deletion lib/cext/include/truffleruby/truffleruby-abi-version.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
// $RUBY_VERSION must be the same as TruffleRuby.LANGUAGE_VERSION.
// $ABI_NUMBER starts at 1 and is incremented for every ABI-incompatible change.

#define TRUFFLERUBY_ABI_VERSION "3.2.2.7"
#define TRUFFLERUBY_ABI_VERSION "3.2.2.8"

#endif
14 changes: 14 additions & 0 deletions spec/ruby/optional/capi/ext/io_spec.c
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,16 @@ VALUE io_spec_mode_sync_flag(VALUE self, VALUE io) {
}
}

#if defined(RUBY_VERSION_IS_3_3) || defined(TRUFFLERUBY)
static VALUE io_spec_rb_io_mode(VALUE self, VALUE io) {
return INT2FIX(rb_io_mode(io));
}

static VALUE io_spec_rb_io_path(VALUE self, VALUE io) {
return rb_io_path(io);
}
#endif

void Init_io_spec(void) {
VALUE cls = rb_define_class("CApiIOSpecs", rb_cObject);
rb_define_method(cls, "GetOpenFile_fd", io_spec_GetOpenFile_fd, 1);
Expand Down Expand Up @@ -372,6 +382,10 @@ void Init_io_spec(void) {
rb_define_method(cls, "rb_cloexec_open", io_spec_rb_cloexec_open, 3);
rb_define_method(cls, "errno=", io_spec_errno_set, 1);
rb_define_method(cls, "rb_io_mode_sync_flag", io_spec_mode_sync_flag, 1);
#if defined(RUBY_VERSION_IS_3_3) || defined(TRUFFLERUBY)
rb_define_method(cls, "rb_io_mode", io_spec_rb_io_mode, 1);
rb_define_method(cls, "rb_io_path", io_spec_rb_io_path, 1);
#endif
}

#ifdef __cplusplus
Expand Down
19 changes: 18 additions & 1 deletion spec/ruby/optional/capi/io_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -440,10 +440,27 @@
end
end
end

ruby_version_is "3.3" do
describe "rb_io_mode" do
it "returns the mode" do
(@o.rb_io_mode(@r_io) & 0b11).should == 0b01
(@o.rb_io_mode(@w_io) & 0b11).should == 0b10
(@o.rb_io_mode(@rw_io) & 0b11).should == 0b11
end
end

describe "rb_io_path" do
it "returns the IO#path" do
@o.rb_io_path(@r_io).should == @r_io.path
@o.rb_io_path(@rw_io).should == @rw_io.path
@o.rb_io_path(@rw_io).should == @name
end
end
end
end

describe "rb_fd_fix_cloexec" do

before :each do
@o = CApiIOSpecs.new

Expand Down
2 changes: 2 additions & 0 deletions spec/truffleruby.next-specs
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ spec/ruby/core/nil/nil_spec.rb

spec/ruby/core/warning/element_reference_spec.rb
spec/ruby/core/warning/element_set_spec.rb

spec/ruby/optional/capi/io_spec.rb

0 comments on commit b7cb7fe

Please sign in to comment.