Skip to content

IO.new / IO.for_fd: wrap a descriptor via the synthetic fd table - #483

Merged
tannevaled merged 1 commit into
mainfrom
feat/io-for-fd
Aug 29, 2026
Merged

tannevaled merged 1 commit into
mainfrom
feat/io-for-fd

Conversation

@tannevaled

Copy link
Copy Markdown
Contributor

rbgo has no real OS file descriptors, so #fileno hands out synthetic ones and
now records the stream in a per-VM fd table. IO.new(fd, mode = nil, **opts) and
IO.for_fd look a descriptor up there: an unknown one raises Errno::EBADF, and
a live one yields a fresh IO carrying the mode's read/write intent and its
encoding (from the "mode:ext[:int]" string or the :mode /
:external_encoding / :internal_encoding / :encoding options). The fd
argument is coerced with #to_int, and the arity is 1..2.

Verified against ruby 4.0.6. Whole-package coverage stays at 100%; the ruby/spec
ratchet floor rises 16180 → 16240 (core/io for_fd 0 → 33, new 7 → 33, +59
aggregate, zero regressions in a per-file sweep). Real-fd round-trips (writing
through one IO and reading the bytes back through another on the same fd) remain
out of reach of the in-memory model.

🤖 Generated with Claude Code

rbgo has no real OS file descriptors, so #fileno hands out synthetic ones and now
records the stream in a per-VM fd table. IO.new(fd, mode = nil, **opts) and
IO.for_fd look a descriptor up there: an unknown one raises Errno::EBADF, and a
live one yields a fresh IO carrying the mode's read/write intent and its encoding
(from the "mode:ext[:int]" string or the :mode / :external_encoding /
:internal_encoding / :encoding options). The fd argument is coerced with #to_int,
and the arity is 1..2.

Verified against ruby 4.0.6. Whole-package coverage stays at 100%; the ruby/spec
floor rises 16180 -> 16240 (core/io for_fd 0 -> 33, new 7 -> 33). Real-fd
round-trips (writing through one IO and reading the bytes back through another on
the same fd) remain out of reach of the in-memory model.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@tannevaled
tannevaled merged commit cf90c17 into main Aug 29, 2026
7 checks passed
@tannevaled
tannevaled deleted the feat/io-for-fd branch August 29, 2026 18:03
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