Repository navigation
kernel: Kernel#putc + #p/#print/#puts forward to $stdout (core/kernel +15) - #604
Merged
Merged
Conversation
… +15) Kernel#p/#print/#puts/#putc did not honour a reassigned or mocked $stdout, #p lost the array return value and rendered container elements through the built-in formatter instead of dispatching #inspect, and Kernel#putc was missing entirely. - Add Kernel#putc: coerces its argument like rb_io_putc (a String's first character, else the low byte of #to_int; nil/false/true raise TypeError) and delivers the one-character String through $stdout#write, so a mocked $stdout or a closed stream (IOError) is observed. Registered in the module_function set so it is a private instance method of Kernel and a public Kernel module method. - Kernel#puts forwards to $stdout.puts (rb_f_puts) so a reassigned/mocked $stdout receives the call, with the recv==$stdout guard writing straight to the object to avoid recursing. - Kernel#print writes through $stdout#write (rb_f_print -> rb_io_print), applying $_ (no-arg), the field separator $, and the record separator $\. - Kernel#p returns the argument for one, a new Array for several, and renders each value through its own #inspect (rb_inspect), coercing a non-String result with #to_s (rb_obj_as_string) — so an overridden #inspect and per-element Array/Hash #inspect are honoured. - A $stdout that answers no #write (which MRI rejects at assignment but rbgo tolerates) falls back to the underlying stream rather than raising. References: ruby/ruby v3_4_0 io.c (rb_f_putc, rb_f_puts, rb_f_print, rb_io_print, rb_io_putc), object.c (rb_inspect, rb_obj_as_string). Verified byte-for-byte against MRI 4.0.5. Updated one stale pinned test (p of a non-String #inspect now coerces via #to_s, as MRI does). core/kernel: putc 0->11, p 6->8, print 3->4, puts 2->3; ruby/spec core/kernel passing 1829 -> 1844. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
tannevaled
force-pushed
the
wave22/kernel
branch
2 times, most recently
from
September 10, 2026 09:25
f131dfe to
861bc4d
Compare
…erwise pInspect dispatched #inspect unconditionally. The Go-backed binding values (Matrix, NDArray, IPAddr, BigDecimal, Date, Bag, Rolify) register no Ruby #inspect of their own, so dispatch rendered them through the generic one and left every Go Inspect() unreachable — 0.0% on the CI merged profile, dropping the 100% coverage gate below the line on both POSIX lanes while windows (same tests, no gate) stayed green. Dispatch for RObject and for Array/Hash — whose Ruby #inspect renders each element through the element's own #inspect, so still shows an overridden one — and use the value's Go Inspect() otherwise, as inspectStr does. Verified vs MRI 4.0.5 (10/10): IPAddr/BigDecimal/Date render byte-identically; overridden #inspect on a plain object, on a built-in subclass, a non-String #inspect coerced with #to_s, and per-element inspect inside both Array and Hash all match. Every binding Inspect() is back at 100.0%, level with main. core/kernel +15. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
tannevaled
force-pushed
the
wave22/kernel
branch
from
September 10, 2026 09:33
861bc4d to
83ae0b4
Compare
tannevaled
added a commit
that referenced
this pull request
Sep 10, 2026
…606) First run past 20,000 passing ruby/spec examples. Wave-22 merged three bibliography-first conformance PRs: - #605 core/io: IO.pipe encodings, IO#write/write_nonblock transcoding, bom| handling, off_t RangeError, IO.foreach $./$_, IO#readpartial, IO.copy_stream with duck-typed sources and destinations — +77. - #604 core/kernel: Kernel#putc (new), #p/#print/#puts forwarding through $stdout so a mocked stream observes them, #p rendering per MRI rb_inspect — +15. - #603 VM: OpOpenSingletonClass now resets defaultVis, so a private in one 'class << self' body no longer leaks into a later reopened one — +4. Measured total on merged main: 20093 passing. Local measure at TIMEOUT=25; CI runs TIMEOUT=60 so its total is >= this floor. Co-authored-by: Claude Opus 5 (1M context) <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.
What
Kernel output methods did not honour a reassigned or mocked
$stdout,#plost its multi-argument return value and rendered container elements through the built-in formatter, andKernel#putcwas missing entirely.Kernel#putc— new. Coerces its argument likerb_io_putc(a String's first character, else the low byte of#to_int;nil/false/trueraiseTypeError) and delivers the one-character String through$stdout#write, so a mocked$stdoutor a closed stream (IOError) is observed. Registered in themodule_functionset → private instance method ofKerneland publicKernelmodule method.Kernel#puts— forwards to$stdout.puts(rb_f_puts) so a reassigned/mocked$stdoutreceives the call, with therecv==$stdoutguard writing straight to the object to avoid recursing.Kernel#print— writes through$stdout#write(rb_f_print→rb_io_print), applying$_(no-arg), field separator$,and record separator$\.Kernel#p— returns the argument for one, a newArrayfor several, and renders each value through its own#inspect(rb_inspect), coercing a non-String result with#to_s(rb_obj_as_string) — so an overridden#inspectand per-elementArray/Hash#inspectare honoured.$stdoutanswering no#write(which MRI rejects at assignment but rbgo tolerates) falls back to the underlying stream rather than raising.Bibliography
ruby/ruby
v3_4_0:io.c(rb_f_putc,rb_f_puts,rb_f_print,rb_io_print,rb_io_putc),object.c(rb_inspect,rb_obj_as_string). ruby/speccore/kernel/{putc,p,print,puts}_spec.rbandshared/io/putc.rb. Every change verified byte-for-byte against MRI 4.0.5.Result (ruby/spec
core/kernel, MRI 4.0.5 oracle)Suite total: 1829 → 1844 passing (+15); fail 194→184, error 128→123, no regressions. The one remaining
p_specfailure ("flushes output if receiver is a File", a# TODOin ruby/spec itself) is File write-buffering, out of scope here.Tests / gates
go build ./...andGOWORK=off go test ./...green (pre-existing127.0.0.1:1network tests aside).nativeP/nativePrint/nativePuts/pInspectand theputcclosure).gofmt -l internal/vm/empty; wasip1 build OK.pof a non-String#inspectnow coerces via#to_s, matching MRI).🤖 Generated with Claude Code