Commit 1f18075f
1f18075f73b3Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 2 files · ~2 modified
Description
feat(codegen): $stdout.flush / STDOUT.flush (and stderr variants)
Compiles $stdout.flush, $stderr.flush, STDOUT.flush, STDERR.flush to the corresponding fflush() call instead of warning "cannot resolve call to 'flush' on int (emitting 0)".
Motivation: on Windows / MSYS2 mingw64 ruby, stdio is fully buffered when stdout is a pipe and ruby doesn't auto-flush before system() the way Linux does. make test runs each .rb under command substitution, so the system-test repro printed hello_from_system before the surrounding putses. Letting test code request an explicit flush fixes the order on the reference side; the spinel binary already emits fflush(stdout) before the system() call.
Also adds the explicit flush to test/system.rb.
Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]
Details
- Commit
- 1f18075f73b3
- Parent
- d920667f4cc7
spinel_codegen.rbmodifiedView file
end end end # $stdout.flush / $stderr.flush / STDOUT.flush / STDERR.flush. # Important on Windows where stdio is fully-buffered when stdout # is a pipe — without an explicit flush, output written via puts # before a `system(...)` call appears after the child process's # output. The expression-context system path already emits # fflush(stdout) implicitly; this lets user code do the same # explicitly. if mname == "flush" && recv >= 0 stream = "" if @nd_type[recv] == "GlobalVariableReadNode" if @nd_name[recv] == "$stdout" stream = "stdout" elsif @nd_name[recv] == "$stderr" stream = "stderr" end elsif @nd_type[recv] == "ConstantReadNode" if @nd_name[recv] == "STDOUT" stream = "stdout" elsif @nd_name[recv] == "STDERR" stream = "stderr" end end if stream != "" emit(" fflush(" + stream + ");") return 1 end end if mname == "print" if recv < 0 compile_print(nid)test/system.rbmodifiedView file
Loading diff…