Skip to content

Commit a6a305e

Browse files
committed
showcompact(::RefValue) prints the contained object compactly
1 parent 2e88083 commit a6a305e

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

base/refpointer.jl

+7
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,10 @@ setindex!(b::RefValue, x) = (b.x = x; b)
7070
setindex!(b::RefArray, x) = (b.x[b.i] = x; b)
7171

7272
###
73+
74+
function showcompact(io::IO, b::RefValue)
75+
show(io, typeof(b))
76+
print(io, "(")
77+
showcompact(io, b.x)
78+
print(io, ")")
79+
end

test/ccall.jl

+10
Original file line numberDiff line numberDiff line change
@@ -209,3 +209,13 @@ for (t,v) in ((Complex{Int32},:ci32),(Complex{Int64},:ci64),
209209
#b = ccall(cfunction($fname,Any,(Ref{Any},)),Any,(Ref{Any},),$v) # unimplemented
210210
end
211211
end
212+
213+
let pif = Float64(pi), r = Ref(pif)
214+
io = IOBuffer()
215+
show(io, r)
216+
@test takebuf_string(io) == string("Base.RefValue{Float64}(",pif,")")
217+
showcompact(io, r)
218+
str = takebuf_string(io)
219+
showcompact(io, pif)
220+
@test str == string("Base.RefValue{Float64}(",takebuf_string(io),")")
221+
end

0 commit comments

Comments
 (0)