diff --git a/base/docs/helpdb.jl b/base/docs/helpdb.jl index 7f5f5fdc5b4eb..d0d27c7152f79 100644 --- a/base/docs/helpdb.jl +++ b/base/docs/helpdb.jl @@ -4160,7 +4160,11 @@ pipeline(command) doc""" serialize(stream, value) -Write an arbitrary value to a stream in an opaque format, such that it can be read back by `deserialize`. The read-back value will be as identical as possible to the original. In general, this process will not work if the reading and writing are done by different versions of Julia, or an instance of Julia with a different system image. +Write an arbitrary value to a stream in an opaque format, such that it can be read back by `deserialize`. +The read-back value will be as identical as possible to the original. +In general, this process will not work if the reading and writing are done by different versions of Julia, +or an instance of Julia with a different system image. +`Ptr` values are serialized as all-zero bit patterns (`NULL`). """ serialize diff --git a/base/serialize.jl b/base/serialize.jl index c48bc4f61040a..39e4140d08217 100644 --- a/base/serialize.jl +++ b/base/serialize.jl @@ -102,7 +102,7 @@ end serialize(s::SerializationState, x::Bool) = x ? writetag(s.io, TRUE_TAG) : writetag(s.io, FALSE_TAG) -serialize(s::SerializationState, ::Ptr) = error("cannot serialize a pointer") +serialize(s::SerializationState, p::Ptr) = serialize_any(s, oftype(p, C_NULL)) serialize(s::SerializationState, ::Tuple{}) = writetag(s.io, EMPTYTUPLE_TAG) @@ -651,8 +651,6 @@ function deserialize_datatype(s::SerializationState) deserialize(s, t) end -deserialize{T}(s::SerializationState, ::Type{Ptr{T}}) = convert(Ptr{T}, 0) - function deserialize(s::SerializationState, ::Type{Task}) t = Task(()->nothing) deserialize_cycle(s, t) diff --git a/test/serialize.jl b/test/serialize.jl index b24e08fe2ffa9..6b339c4c87fd4 100644 --- a/test/serialize.jl +++ b/test/serialize.jl @@ -39,7 +39,9 @@ end # Ptr create_serialization_stream() do s - @test_throws ErrorException serialize(s, C_NULL) + serialize(s, C_NULL) + seekstart(s) + @test deserialize(s) === C_NULL end # Integer