Repository navigation
io: pread/pwrite, sysopen, dup, initialize, encodings & positioning conformance (core/io +56) - #593
Merged
Merged
Conversation
…ct (core/io) Advance MRI-Ruby-4.0.x core/io conformance, reading MRI io.c (v3_4_0) and the ruby/spec expectations for each method: - IO#pread / IO#pwrite (io.c rb_io_pread/rb_io_pwrite): coerce maxlen/offset with #to_int (NUM2SIZET/NUM2OFFT) and the buffer with #to_str (io_setstrbuf → StringValue), pwrite coerces the object with #to_s (rb_obj_as_string); the maxlen==0 early return leaves a given buffer's bytes untouched. pread 14->22, pwrite 5->9. - IO.sysopen (io.c rb_io_s_sysopen): open the path into a buffered stream, register a synthetic descriptor (so IO.for_fd can wrap it) and return it; #to_path coerces the path. sysopen 0->5. - IO#dup (io.c rb_io_dup): an independent IO on a fresh descriptor with its own open/close state and the autoclose + close-on-exec flags always set, plus IO#close_on_exec? / #close_on_exec=. dup 1->7. - IO#initialize (io.c rb_io_initialize): reassociate the receiver with a descriptor, coercing the fd with #to_int and raising EBADF/IOError/TypeError as MRI does; the fd-adoption logic is shared with IO.for_fd/new via a new ioAdoptDescriptor helper. initialize 1->7. - IO#to_io (returns self), IO#path / IO#to_path (rb_io_path, incl. the "<STDOUT>" pseudo-paths and IO.new's path: option) and IO#inspect (rb_io_inspect, "#<Class:fd N>" / path / "(closed)"). to_io 0->2, path 0->1, to_path 0->1, inspect 0->3. All changes verified byte-for-byte against MRI Ruby 4.0.5. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…re/io)
Continue MRI-Ruby-4.0.x core/io conformance, reading MRI io.c (v3_4_0) and the
ruby/spec expectations:
- IO#set_encoding (io.c io_encoding_set): enforce the 1..2 arity over the
positional args (a trailing econv-options Hash is separated first), coerce a
non-String/non-Encoding first argument with #to_str before the "ext:int"
split, and drop an internal encoding equal to the external one (enc == enc2 =>
enc2 = NULL). set_encoding 21->26.
- IO#ungetbyte (io.c rb_io_ungetbyte): reduce an Integer/Bignum modulo 256 to a
single byte (never RangeError) and coerce any other value with #to_str
(StringValue), so a non-coercible argument is an "into String" TypeError — the
pinned StringIO#ungetbyte([]) test is updated to the MRI-verified message.
ungetbyte 3->6.
- Standard streams carry their real access half: $stdout/$stderr are write-only
and $stdin read-only, so a read of $stdout / a write to $stdin raises IOError
("not opened for reading"/"...writing"), matching MRI's fd modes. This also
gives IO#ungetbyte its "not opened for reading" IOError.
- IO#to_i is a true alias of IO#fileno (equal UnboundMethods), and IO mixes in
Enumerable. to_i 0->1, io 1->2.
100% coverage on internal/vm; all changes verified byte-for-byte against MRI
Ruby 4.0.5.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…re/io) Continue MRI-Ruby-4.0.x core/io conformance (MRI io.c v3_4_0 + ruby/spec): - IO#lineno / #lineno= (io.c rb_io_lineno / rb_io_set_lineno): a real IO must be char-readable, so a closed stream raises "closed stream" and a write-only one "not opened for reading"; a StringIO still tolerates both (strio has no such check). lineno 7->12. - IO#pos= / IO#seek (NUM2OFFT): a Bignum too large for the off_t position raises RangeError "bignum too big to convert into 'long long'" rather than a TypeError. pos 7->8, seek 14->15. - IO#lineno= (NUM2INT): the line number is a C int, so a Bignum raises "bignum too big to convert into 'long'" and an in-range Integer that still overflows the int raises "integer N too big to convert to 'int'". 100% coverage on internal/vm; all changes verified byte-for-byte against MRI Ruby 4.0.5. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…ore/io) IO#sysread (io.c rb_io_sysread), reading MRI io.c v3_4_0 + ruby/spec: coerce the optional output buffer with #to_str (io_setstrbuf → StringValue); a zero-length read returns the buffer untouched (or a fresh ""); and an end-of-file read empties the given buffer (io_set_read_length to 0) before raising EOFError. sysread 13->16 (the remaining fail needs read-buffer bookkeeping after a buffered read). 100% coverage on internal/vm; verified byte-for-byte against MRI Ruby 4.0.5. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
tannevaled
added a commit
that referenced
this pull request
Sep 8, 2026
…594) Wave-19 merged three bibliography-first conformance PRs: - #593 core/io: pread/pwrite, sysopen, dup, initialize/reopen, to_io/path/ inspect, set_encoding, ungetbyte, lineno, sysread, std-stream halves — +56. - #591 core/file+dir: File::Stat surface, ftype, chmod/umask/truncate/rename errno + coercion, realpath ELOOP, Dir Enumerable + entries/children/foreach/ each_child (fixing a nil-pointer crash) — core/file +22, core/dir +29. - #592 core/kernel: respond_to?/eql?/remove_instance_variable mirrored on Kernel, then/yield_self blockless Enumerator — +8. Measured total on merged main: 19773 passing. Local measure at TIMEOUT=25; CI runs TIMEOUT=60 so its total is >= this floor. Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Advances MRI-Ruby-4.0.x conformance of the
core/iosurface, reading MRIio.c(v3_4_0) and the ruby/spec expectations for each method and verifying every change byte-for-byte against MRI Ruby 4.0.5. core/io ruby/spec examples: 898 → 954 passing (+56).Methods fixed (with the reference read for each)
Descriptors & construction
IO#pread/IO#pwrite(rb_io_pread/rb_io_pwrite): coerce maxlen/offset with#to_int(NUM2SIZET/NUM2OFFT) and the buffer with#to_str(io_setstrbuf→StringValue);pwritecoerces its object with#to_s(rb_obj_as_string); themaxlen==0early return leaves a given buffer's bytes untouched. pread 14→22, pwrite 5→9IO.sysopen(rb_io_s_sysopen): open the path into a buffered stream, register a synthetic descriptor (soIO.for_fdcan wrap it), return it;#to_pathcoerces the path. 0→5IO#dup(rb_io_dup): an independent IO on a fresh descriptor with its own open/close state and the autoclose + close-on-exec flags always set, plusIO#close_on_exec?/#close_on_exec=. 1→7IO#initialize(rb_io_initialize): reassociate the receiver with a descriptor, coercing the fd with#to_intand raising EBADF/IOError/TypeError as MRI does; the fd-adoption logic is shared withIO.for_fd/newvia a newioAdoptDescriptorhelper. 1→7IO#to_io(returns self),IO#path/IO#to_path(rb_io_path, incl. the<STDOUT>pseudo-paths andIO.new'spath:option),IO#inspect(rb_io_inspect:#<Class:fd N>/ path /(closed)). to_io 0→2, path 0→1, to_path 0→1, inspect 0→3Encodings
IO#set_encoding(io_encoding_set): enforce the 1..2 arity (a trailing econv-options Hash is separated first), coerce a non-String/non-Encoding first argument with#to_strbefore theext:intsplit, and drop an internal encoding equal to the external one (enc == enc2 ⇒ enc2 = NULL). 21→26IO#ungetbyte(rb_io_ungetbyte): reduce an Integer/Bignum modulo 256 to one byte (never RangeError) and coerce any other value with#to_str. 3→6Positioning & line numbers
IO#lineno/#lineno=(rb_io_lineno/rb_io_set_lineno): a real IO must be char-readable (closed/write-only raises; a StringIO does not);#lineno=is a C int, so it range-checks (RangeError for a Bignum, or an in-range Integer that overflows the int). 7→12IO#pos=/IO#seek(NUM2OFFT): a Bignum too large for the off_t position raises RangeError rather than a TypeError. pos 7→8, seek 14→15IO#sysread(rb_io_sysread):#to_str-coerce the buffer, return it untouched for length 0, and empty it before an EOFError. 13→16Standard streams & misc
$stdout/$stderrare write-only and$stdinread-only, so a read of$stdout/ a write to$stdinraises IOError, matching MRI's fd modes (this also givesungetbyteits "not opened for reading" error).IO#to_iis a true alias ofIO#fileno(equalUnboundMethods);IOmixes inEnumerable. to_i 0→1, io 1→2One pinned test (
StringIO#ungetbyte([])) is updated to the MRI-verified "into String" message, sinceungetbytenow coerces withStringValue.Verification
go build ./..., fullgo test ./...(only the pre-existing 127.0.0.1:1 network tests fail), wasip1 build — all green.internal/vm(new whiteboxio_wave19_test.go),gofmtclean.🤖 Generated with Claude Code