Skip to content

Commit

Permalink
serialize pointers as NULL. fixes #13122
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffBezanson committed Oct 26, 2015
1 parent cf5f23a commit 77b2527
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
6 changes: 5 additions & 1 deletion base/docs/helpdb.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 1 addition & 3 deletions base/serialize.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion test/serialize.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

5 comments on commit 77b2527

@andreasnoack
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great. Let's tag 0.5 😛

@jakebolewski
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tkelman can we backport this?

@tkelman
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Jeff added the label at #13122 (comment), though the issue got reopened then reclosed with a second commit so I'm assuming both fixes should be backported. @JeffBezanson can you confirm?

@JeffBezanson
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes.

@yuyichao
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing doc sync...

Please sign in to comment.