Skip to content

Commit 8e03cb1

Browse files
authored
Random: show method for MersenneTwister: invalidation resistance (#57913)
Avoid using or constructing the vector with nonconcrete element type. Should make the sysimage more resistant to method invalidation.
1 parent d6fdbf5 commit 8e03cb1

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

stdlib/Random/src/RNGs.jl

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -147,21 +147,26 @@ function show(io::IO, rng::MersenneTwister)
147147
end
148148
print(io, MersenneTwister, "(", repr(rng.seed), ", (")
149149
# state
150-
adv = Integer[rng.adv_jump, rng.adv]
150+
sep = ", "
151+
show(io, rng.adv_jump)
152+
print(io, sep)
153+
show(io, rng.adv)
151154
if rng.adv_vals != -1 || rng.adv_ints != -1
152-
if rng.adv_vals == -1
153-
@assert rng.idxF == MT_CACHE_F
154-
push!(adv, 0, 0) # "(0, 0)" is nicer on the eyes than (-1, 1002)
155-
else
156-
push!(adv, rng.adv_vals, rng.idxF)
157-
end
155+
# "(0, 0)" is nicer on the eyes than (-1, 1002)
156+
s = rng.adv_vals != -1
157+
print(io, sep)
158+
show(io, s ? rng.adv_vals : zero(rng.adv_vals))
159+
print(io, sep)
160+
show(io, s ? rng.idxF : zero(rng.idxF))
158161
end
159162
if rng.adv_ints != -1
160163
idxI = (length(rng.ints)*16 - rng.idxI) / 8 # 8 represents one Int64
161164
idxI = Int(idxI) # idxI should always be an integer when using public APIs
162-
push!(adv, rng.adv_ints, idxI)
165+
print(io, sep)
166+
show(io, rng.adv_ints)
167+
print(io, sep)
168+
show(io, idxI)
163169
end
164-
join(io, adv, ", ")
165170
print(io, "))")
166171
end
167172

0 commit comments

Comments
 (0)