Skip to content

Commit 34a8ee6

Browse files
committed
Don't interpolate stdout in printf macro to avoid precompilation issues
Fixes #37665. The subtle issue here was the at-printf macro using the `stdout` variable at _macro-expansion-time_ and interpolating it into the final `Printf.format` expanded call. If `stdout` was rebound between expansion time and usage time, then we saw ugly libuv errors (segfaults). This would happen mainly when a `Printf.@printf` call was precompiled directly, so the macro expansion was precompiled and led to the messed up `stdout` usage at runtime. The fix is to just not interpolate `stdout` at macro-expansion time, but have the expanded call use the global `stdout` at runtime.
1 parent 24c468d commit 34a8ee6

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

stdlib/Printf/src/Printf.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -758,9 +758,8 @@ julia> @printf "%.0f %.1f %f\\n" 0.5 0.025 -0.0078125
758758
"""
759759
macro printf(io_or_fmt, args...)
760760
if io_or_fmt isa String
761-
io = stdout
762761
fmt = Format(io_or_fmt)
763-
return esc(:($Printf.format($io, $fmt, $(args...))))
762+
return esc(:($Printf.format(stdout, $fmt, $(args...))))
764763
else
765764
io = io_or_fmt
766765
isempty(args) && throw(ArgumentError("must provide required format string"))

0 commit comments

Comments
 (0)