Repository navigation
io: read/write/seek/gets closed-stream + coercion conformance (core/io +48) - #588
Merged
Merged
Conversation
…coercion (+25 core/io)
Read/positioning surface conformance for core/io:
- IO#each_codepoint: moved from the StringIO-only block to the shared read
protocol (defStringIORead) so File/IO carry it, not only StringIO
(rb_io_each_codepoint, io.c:4887). each_codepoint_spec 0->10.
- IO#seek / IO#sysseek: accept the :SET/:CUR/:END (and :DATA/:HOLE) whence
symbols via a new seekWhence helper mirroring interpret_seek_whence
(io.c:2449); sysseek now coerces its offset through #to_int (NUM2OFFT).
seek 11->14, sysseek 5->10.
- IO#pos / IO#pos=: raise IOError "closed stream" on a real IO/File but not on
StringIO (MRI: StringIO#pos tolerates a closed stream). pos 5->7.
- IO#lineno=: coerce via #to_int so a Float truncates and a #to_int object is
accepted (rb_io_set_lineno, io.c:4422; NUM2INT). lineno 4->7.
- IO#ungetc: coerce a non-Integer argument with #to_str (StringValue) so nil
and non-String objects raise the conversion TypeError (rb_io_ungetc,
io.c:5230). ungetc 8->10.
core/io: pass 923->948, fail 268->262, error 238->219.
ruby/spec: core/io/{each_codepoint,seek,sysseek,pos,lineno,ungetc}_spec.rb
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…ngIO StringIO diverges from IO on the two branches wave18 just widened, so gate them on ioIsStringIO to keep StringIO byte-for-byte with MRI: - StringIO#seek (strio_seek) rejects a Symbol whence with the Integer TypeError; only IO#seek honours :SET/:CUR/:END. - StringIO#ungetc(nil) (strio_ungetc) is a no-op, whereas IO#ungetc(nil) raises via StringValue; the #to_str coercion and plain-Object TypeError are shared. Verified against MRI 4.0.5: StringIO#seek(1,:CUR) -> TypeError, StringIO#ungetc(nil) -> nil. stringio corpus unchanged (579 pass); core/io still 948. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…DERR sync default (+9 core/io)
MRI raises IOError on a closed (or, for eof?, non-readable) stream; add the
guards, keeping StringIO's tolerant behaviour where it diverges:
- IO#eof? runs ioCheckReadable, so a closed stream, a #close_read'd stream, or a
write-only ("w") File all raise IOError as in MRI (rb_io_eof). eof 12->15.
- IO#flush / IO#fsync / IO#tty? raise IOError "closed stream" on a real IO/File
via the new ioClosedRealIO; StringIO#flush/#fsync/#tty? stay no-raise.
flush 0->1, fsync 1->2, tty 1->2.
- IO#sync / IO#sync= raise IOError on a closed real IO (StringIO overrides both
in defStringIOExtra, so the guard only reaches a real IO). sync 5->8.
- STDERR is synchronous by default (STDERR.sync == true), unlike STDOUT.
Verified against MRI 4.0.5 (File raises, StringIO does not for
flush/fsync/sync/tty?; both raise for eof?). stringio corpus unchanged (579);
core/io pass 948->957.
ruby/spec: core/io/{eof,flush,fsync,sync,tty}_spec.rb
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
… to disk (+9 core/io)
- IO#putc (rb_io_putc, io.c): write the single character through self.#write so a
subclass' / mock's #write observes it; a String yields its first character and
a non-String is coerced with NUM2CHR (#to_int, low byte) so nil/false/true
raise TypeError. Returns the original argument. putc 4->9.
- IO#printf (rb_io_printf): coerce the format with #to_str (StringValue) instead
of Go-level to_s, so a #to_str format object formats correctly. printf 1->3.
- writeBytes: when o.sync is set, a File's buffered write is flushed to disk
immediately, so File.read observes it before #close (MRI sync semantics).
write 29->30; also carries printf's file-visible output.
core/io pass 957->966; stringio 579->580 (no regression).
ruby/spec: core/io/{putc,printf,write}_spec.rb, shared/io/putc.rb
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…t EINVAL, gets-family arity (+5 core/io)
- IO#rewind raises IOError on a closed real IO/File (StringIO tolerates it).
- IO#autoclose? / IO#autoclose= raise IOError on a closed IO (IO/File-only
methods, so no StringIO gating needed).
- IO.binread reaches a negative offset through rb_io_seek and raises
Errno::EINVAL "Invalid argument @ rb_io_seek - <path>", whereas IO.read
validates it in Ruby (ArgumentError) — verified against MRI 4.0.5.
- gets/readline/each_line (resolveGetsArgs) reject more than two positional
arguments with ArgumentError "wrong number of arguments (given N, expected
0..2)" (chomp: is a stripped keyword).
core/io pass 966->971; stringio 580 (no regression).
ruby/spec: core/io/{rewind,autoclose,binread,each_line}_spec.rb
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…rage) The wave-18 io work added seekWhence, ioIsStringIO, ioClosedRealIO and new branches in writeBytes/resolveGetsArgs/ioReadFile/defIOSeekable without tests, dropping the merged-coverage total below the 100% gate. Cover every new branch: seekWhence (all whences + int + TypeError), the StringIO-vs-real-IO closed-stream guards, and the File sync-write / closed pos·pos=·autoclose / symbolic seek / gets-EOF / over-arity gets / binread negative-offset paths — each asserted byte-for-byte vs MRI 4.0.5. defStringIORead's remaining 99.5% is pre-existing (identical on main). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
tannevaled
added a commit
that referenced
this pull request
Sep 7, 2026
…590) Wave-18 merged three bibliography-first conformance PRs: - #587 core/regexp: consume the n/u/e/s encoding modifiers now recorded by go-ruby-parser v0.1.8 (cross-repo #23) — core/regexp +12, language/regexp +6. - #588 core/io: read/write/positioning/iteration surface (gets/each/seek symbol whence/closed-stream guards/putc/sync/binread) — core/io +48. - #589 core/kernel: Integer/Float coercion messages, default Object#inspect with the object address + ivars, Object#<=> via #== with a Comparable#== recursion guard (fixing a stack overflow), at_exit no-block ArgumentError — core/kernel +16. Measured total on merged main: 19651 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.
Wave-18 core/io: the read/write/positioning/iteration surface on top of the fd-based constructors from a prior wave.
core/io: 849 → 897 (+48), verified byte-for-byte vs MRI 4.0.5. Files: io.go, io_class.go, io_descriptors.go (5 commits).
Fixes (each read against ruby/ruby v3_4_0 io.c): each_codepoint on IO/File, symbol whence (:SET/:CUR/:END/:DATA/:HOLE) for seek/sysseek, lineno=/ungetc coercion; IOError on closed stream for eof?/flush/fsync/sync/tty?/rewind; putc via #write + printf/putc argument coercion; sync=true flushes to disk; STDERR sync default; binread negative-offset EINVAL; gets-family arity; StringIO tolerates pos on a closed stream while a real IO raises.
Gates:
go build ./..., fullgo test ./...(no non-network failure), gofmt clean, wasip1 build. Coverage: whitebox tests to be confirmed by the CI merged-coverage gate — if it flags new helpers (seekWhence/ioIsStringIO/ioClosedRealIO) I'll add targeted tests. FLOOR untouched.🤖 Generated with Claude Code