Skip to content

Commit b7cb7fe

Browse files
committed
[GR-18163] Declare rb_io_mode() and rb_io_path() and add specs
PullRequest: truffleruby/4086
2 parents 070598d + 1c8de1a commit b7cb7fe

File tree

5 files changed

+41
-2
lines changed

5 files changed

+41
-2
lines changed

lib/cext/include/ruby/io.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -724,6 +724,12 @@ void rb_io_set_nonblock(rb_io_t *fptr);
724724
*/
725725
int rb_io_descriptor(VALUE io);
726726

727+
#ifdef TRUFFLERUBY
728+
// These functions come from 3.3 but truffleruby already implements them
729+
VALUE rb_io_path(VALUE io);
730+
int rb_io_mode(VALUE io);
731+
#endif
732+
727733
/**
728734
* This function breaks down the option hash that `IO#initialize` takes into
729735
* components. This is an implementation detail of rb_io_extract_modeenc()

lib/cext/include/truffleruby/truffleruby-abi-version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@
1010
// $RUBY_VERSION must be the same as TruffleRuby.LANGUAGE_VERSION.
1111
// $ABI_NUMBER starts at 1 and is incremented for every ABI-incompatible change.
1212

13-
#define TRUFFLERUBY_ABI_VERSION "3.2.2.7"
13+
#define TRUFFLERUBY_ABI_VERSION "3.2.2.8"
1414

1515
#endif

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,16 @@ VALUE io_spec_mode_sync_flag(VALUE self, VALUE io) {
339339
}
340340
}
341341

342+
#if defined(RUBY_VERSION_IS_3_3) || defined(TRUFFLERUBY)
343+
static VALUE io_spec_rb_io_mode(VALUE self, VALUE io) {
344+
return INT2FIX(rb_io_mode(io));
345+
}
346+
347+
static VALUE io_spec_rb_io_path(VALUE self, VALUE io) {
348+
return rb_io_path(io);
349+
}
350+
#endif
351+
342352
void Init_io_spec(void) {
343353
VALUE cls = rb_define_class("CApiIOSpecs", rb_cObject);
344354
rb_define_method(cls, "GetOpenFile_fd", io_spec_GetOpenFile_fd, 1);
@@ -372,6 +382,10 @@ void Init_io_spec(void) {
372382
rb_define_method(cls, "rb_cloexec_open", io_spec_rb_cloexec_open, 3);
373383
rb_define_method(cls, "errno=", io_spec_errno_set, 1);
374384
rb_define_method(cls, "rb_io_mode_sync_flag", io_spec_mode_sync_flag, 1);
385+
#if defined(RUBY_VERSION_IS_3_3) || defined(TRUFFLERUBY)
386+
rb_define_method(cls, "rb_io_mode", io_spec_rb_io_mode, 1);
387+
rb_define_method(cls, "rb_io_path", io_spec_rb_io_path, 1);
388+
#endif
375389
}
376390

377391
#ifdef __cplusplus

spec/ruby/optional/capi/io_spec.rb

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,10 +440,27 @@
440440
end
441441
end
442442
end
443+
444+
ruby_version_is "3.3" do
445+
describe "rb_io_mode" do
446+
it "returns the mode" do
447+
(@o.rb_io_mode(@r_io) & 0b11).should == 0b01
448+
(@o.rb_io_mode(@w_io) & 0b11).should == 0b10
449+
(@o.rb_io_mode(@rw_io) & 0b11).should == 0b11
450+
end
451+
end
452+
453+
describe "rb_io_path" do
454+
it "returns the IO#path" do
455+
@o.rb_io_path(@r_io).should == @r_io.path
456+
@o.rb_io_path(@rw_io).should == @rw_io.path
457+
@o.rb_io_path(@rw_io).should == @name
458+
end
459+
end
460+
end
443461
end
444462

445463
describe "rb_fd_fix_cloexec" do
446-
447464
before :each do
448465
@o = CApiIOSpecs.new
449466

spec/truffleruby.next-specs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,5 @@ spec/ruby/core/nil/nil_spec.rb
1111

1212
spec/ruby/core/warning/element_reference_spec.rb
1313
spec/ruby/core/warning/element_set_spec.rb
14+
15+
spec/ruby/optional/capi/io_spec.rb

0 commit comments

Comments
 (0)