Skip to content

Commit 274e2b1

Browse files
nsajkoKristofferC
authored andcommitted
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. (cherry picked from commit 8e03cb1)
1 parent 0265357 commit 274e2b1

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
@@ -151,21 +151,26 @@ function show(io::IO, rng::MersenneTwister)
151151
end
152152
print(io, MersenneTwister, "(", seed_str, ", (")
153153
# state
154-
adv = Integer[rng.adv_jump, rng.adv]
154+
sep = ", "
155+
show(io, rng.adv_jump)
156+
print(io, sep)
157+
show(io, rng.adv)
155158
if rng.adv_vals != -1 || rng.adv_ints != -1
156-
if rng.adv_vals == -1
157-
@assert rng.idxF == MT_CACHE_F
158-
push!(adv, 0, 0) # "(0, 0)" is nicer on the eyes than (-1, 1002)
159-
else
160-
push!(adv, rng.adv_vals, rng.idxF)
161-
end
159+
# "(0, 0)" is nicer on the eyes than (-1, 1002)
160+
s = rng.adv_vals != -1
161+
print(io, sep)
162+
show(io, s ? rng.adv_vals : zero(rng.adv_vals))
163+
print(io, sep)
164+
show(io, s ? rng.idxF : zero(rng.idxF))
162165
end
163166
if rng.adv_ints != -1
164167
idxI = (length(rng.ints)*16 - rng.idxI) / 8 # 8 represents one Int64
165168
idxI = Int(idxI) # idxI should always be an integer when using public APIs
166-
push!(adv, rng.adv_ints, idxI)
169+
print(io, sep)
170+
show(io, rng.adv_ints)
171+
print(io, sep)
172+
show(io, idxI)
167173
end
168-
join(io, adv, ", ")
169174
print(io, "))")
170175
end
171176

0 commit comments

Comments
 (0)