Skip to content

C API: rb_io_t for GetOpenFile, IO waits, fd sets - #243

Merged
Largo merged 1 commit into
masterfrom
capi-batch2
Nov 20, 2026
Merged

Largo merged 1 commit into
masterfrom
capi-batch2

Conversation

@Largo

@Largo Largo commented Nov 19, 2026

Copy link
Copy Markdown
Owner

Stacked on #242 (base capi-batch1); retarget to master once that merges.

Extensions that use GetOpenFile / RB_IO_POINTER read RFILE(io)->fptr. ruby/spec's io specs failed on everything that goes through it. They also failed on the rb_io_maybe_wait family, rb_fd_* and rb_thread_fd_select, which were all NotImplementedError stubs.

  • rb_io_t: an IO's handle slot now points at a native struct rb_io, which rb_io_taint_check fills in with self, fd, the FMODE_* mode and pathv. The shim compiles the layout from the headers (rb_ir_io_layout). The rb_io_t * functions find the IO again through fptr->self: rb_io_check_closed/readable/writable, rb_io_set_nonblock.
  • Waits:
    • rb_io_wait goes through IO.select.
    • rb_io_maybe_wait* and the descriptor waits (rb_io_wait_readable(fd), rb_wait_for_single_fd, rb_thread_wait_fd) are in C, where errno.h has the platform's values.
    • rb_thread_fd_select selects in 100 ms slices with rb_thread_check_ints in between. That way Thread#raise and #kill still reach a thread waiting there.
  • Ports of thread.c and io.c: rb_fd_*, rb_cloexec_*, rb_fd_fix_cloexec.

Specs

spec/optional/capi on Linux:

failures + errors
#242 221
this PR 168

None of the remaining failures are new. io_spec.rb now has 1 failure out of 85 examples: rb_fd_fix_cloexec. That one needs File#fileno to be the OS descriptor, and IronRuby's is a virtual one for files.

Extensions that use GetOpenFile/RB_IO_POINTER read RFILE(io)->fptr, and
ruby/spec's io specs failed on everything that goes through it, plus the
rb_io_maybe_wait family, rb_fd_* and rb_thread_fd_select, all of which
were NotImplementedError stubs.

- An IO's handle slot now points at a native struct rb_io that
  rb_io_taint_check fills in (self, fd, FMODE_* mode, pathv). The layout
  comes from the shim, compiled from the headers, so C# does not repeat
  it. The rb_io_t* functions (rb_io_check_closed/readable/writable,
  rb_io_set_nonblock) find the IO again through fptr->self.
- rb_io_wait goes through IO.select. rb_io_maybe_wait* and the
  descriptor waits are in C, where errno.h has the platform's values.
- rb_thread_fd_select selects in 100ms slices with rb_thread_check_ints
  in between, so Thread#raise and #kill still reach a waiting thread.
- rb_fd_*, rb_cloexec_*, rb_fd_fix_cloexec follow thread.c and io.c.

capi specs: 221 failures and errors -> 168, none new. io_spec.rb is
down to rb_fd_fix_cloexec, which needs File#fileno to be the OS
descriptor.
@coderabbitai

coderabbitai Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

Explain Change →

Caution

Review failed

The pull request is closed.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

@Largo
Largo changed the base branch from capi-batch1 to master November 20, 2026 07:27
@Largo
Largo merged commit a5485a3 into master Nov 20, 2026
6 of 7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant