Skip to content

Commit

Permalink
Merge pull request #3831 from amitmurthy/amitm/show
Browse files Browse the repository at this point in the history
show(o::Any) handles circular references
  • Loading branch information
amitmurthy committed Jun 9, 2014
2 parents cb9fca4 + ea7c5aa commit af9ec2b
Showing 1 changed file with 31 additions and 9 deletions.
40 changes: 31 additions & 9 deletions base/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,39 @@ function show(io::IO, x::ANY)
show(io, t)
print(io, '(')
if t.names !== () || t.size==0
n = length(t.names)
for i=1:n
f = t.names[i]
if !isdefined(x, f)
print(io, undef_ref_str)
recorded = false
oid = object_id(x)
shown_set = get(task_local_storage(), :SHOWNSET, nothing)
if shown_set == nothing
shown_set = Set()
task_local_storage(:SHOWNSET, shown_set)
end

try
if oid in shown_set
print(io, "#= circular reference =#")
else
show(io, x.(i))
end
if i < n
print(io, ',')
push!(shown_set, oid)
recorded = true

n = length(t.names)
for i=1:n
f = t.names[i]
if !isdefined(x, f)
print(io, undef_ref_str)
else
show(io, x.(f))
end
if i < n
print(io, ',')
end
end
end
catch e
rethrow(e)

finally
if recorded delete!(shown_set, oid) end
end
else
nb = t.size
Expand Down

0 comments on commit af9ec2b

Please sign in to comment.