Skip to content

Commit

Permalink
fix serializer bug in undefined fields in immutables
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffBezanson committed Feb 21, 2015
1 parent 79f2185 commit 083722d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
7 changes: 3 additions & 4 deletions base/serialize.jl
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ function deserialize(s, t::DataType)
nf = length(t.names)
if nf == 0
return ccall(:jl_new_struct, Any, (Any,Any...), t)
elseif !t.mutable
elseif isbits(t)
if nf == 1
return ccall(:jl_new_struct, Any, (Any,Any...), t, deserialize(s))
elseif nf == 2
Expand All @@ -548,15 +548,14 @@ function deserialize(s, t::DataType)
return ccall(:jl_new_struct, Any, (Any,Any...), t, f1, f2, f3)
else
flds = Any[ deserialize(s) for i = 1:nf ]
return ccall(:jl_new_structv, Any, (Any,Ptr{Void},UInt32),
t, flds, nf)
return ccall(:jl_new_structv, Any, (Any,Ptr{Void},UInt32), t, flds, nf)
end
else
x = ccall(:jl_new_struct_uninit, Any, (Any,), t)
for i in 1:length(t.names)
tag = int32(read(s, UInt8))
if tag==0 || !is(deser_tag[tag], UndefRefTag)
setfield!(x, i, handle_deserialize(s, tag))
ccall(:jl_set_nth_field, Void, (Any, Csize_t, Any), x, i-1, handle_deserialize(s, tag))
end
end
return x
Expand Down
11 changes: 10 additions & 1 deletion test/serialize.jl
Original file line number Diff line number Diff line change
Expand Up @@ -263,4 +263,13 @@ create_serialization_stream() do s # user-defined type array
r = deserialize(s)
@test r.state == :failed
@test isa(t.exception, ErrorException)
end
end

# corner case: undefined inside immutable type
create_serialization_stream() do s
serialize(s, Nullable{Any}())
seekstart(s)
n = deserialize(s)
@test isa(n, Nullable)
@test !isdefined(n, :value)
end

0 comments on commit 083722d

Please sign in to comment.