Skip to content

Commit

Permalink
add dump method for Ptr (#26880)
Browse files Browse the repository at this point in the history
* add dump method for Ptr

Currently `dump(x::Ptr)` will print the type of the pointer twice, e.g.
```Ptr{Nothing} Ptr{Nothing} @0x0000000120f1d2d0```
This adds an overload so that it only prints once.

* add test

* fix test

* newline
  • Loading branch information
jekbradbury authored and KristofferC committed May 14, 2018
1 parent 66c7b7d commit 098f40f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
1 change: 1 addition & 0 deletions base/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1651,6 +1651,7 @@ dump(io::IOContext, x::Module, n::Int, indent) = print(io, "Module ", x)
dump(io::IOContext, x::String, n::Int, indent) = (print(io, "String "); show(io, x))
dump(io::IOContext, x::Symbol, n::Int, indent) = print(io, typeof(x), " ", x)
dump(io::IOContext, x::Union, n::Int, indent) = print(io, x)
dump(io::IOContext, x::Ptr, n::Int, indent) = print(io, x)

function dump_elts(io::IOContext, x::Array, n::Int, indent, i0, i1)
for i in i0:i1
Expand Down
3 changes: 3 additions & 0 deletions test/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -802,6 +802,9 @@ end
let repr = sprint(dump, Union{Integer, Float32})
@test repr == "Union{Integer, Float32}\n" || repr == "Union{Float32, Integer}\n"
end
let repr = sprint(dump, Ptr{UInt8}(UInt(1)))
@test repr == "Ptr{UInt8} @$(Base.repr(UInt(1)))\n"
end
let repr = sprint(dump, Core.svec())
@test repr == "empty SimpleVector\n"
end
Expand Down

0 comments on commit 098f40f

Please sign in to comment.