Skip to content

Commit

Permalink
Fix and test the SimpleVector writing code
Browse files Browse the repository at this point in the history
  • Loading branch information
simonster committed Apr 25, 2015
1 parent e7e0594 commit ad00d79
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/jld_types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -306,9 +306,10 @@ if VERSION >= v"0.4.0-dev+4319"
end

gen_h5convert(::JldFile, ::Type{SimpleVector}) = nothing
h5convert!(out::Ptr, ::JldFile, x::SimpleVector, ::JldWriteSession) =
unsafe_store!(convert(Ptr{HDF5.HDF5ReferenceObj}, out), write_ref(parent::JldFile, [x...], wsession::JldWriteSession))
h5convert!(out::Ptr, parent::JldFile, x::SimpleVector, wsession::JldWriteSession) =
unsafe_store!(convert(Ptr{HDF5.HDF5ReferenceObj}, out), write_ref(parent, [x...], wsession))

push!(BUILTIN_TYPES, SimpleVector)
function jlconvert(::Type{SimpleVector}, file::JldFile, ptr::Ptr)
Base.svec(read_ref(file, unsafe_load(convert(Ptr{HDF5.HDF5ReferenceObj}, ptr)))...)
end
Expand Down
8 changes: 8 additions & 0 deletions test/jld.jl
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,12 @@ bitsparamint16 = BitsParams{@compat Int16(1)}()
# Tuple of tuples
tuple_of_tuples = (1, 2, (3, 4, [5, 6]), [7, 8])

# SimpleVector
if VERSION >= v"0.4.0-dev+4319"
simplevec = Base.svec(1, 2, Int64, "foo")
iseq(x::SimpleVector, y::SimpleVector) = collect(x) == collect(y)
end

iseq(x,y) = isequal(x,y)
iseq(x::MyStruct, y::MyStruct) = (x.len == y.len && x.data == y.data)
iseq(x::MyImmutable, y::MyImmutable) = (isequal(x.x, y.x) && isequal(x.y, y.y) && isequal(x.z, y.z))
Expand Down Expand Up @@ -387,6 +393,7 @@ for compress in (true,false)
@write fid bitsparamint
@write fid bitsparamuint
@write fid tuple_of_tuples
VERSION >= v"0.4.0-dev+4319" && @write fid simplevec

# Make sure we can create groups (i.e., use HDF5 features)
g = g_create(fid, "mygroup")
Expand Down Expand Up @@ -515,6 +522,7 @@ for compress in (true,false)
@check fidr bitsparamint
@check fidr bitsparamuint
@check fidr tuple_of_tuples
VERSION >= v"0.4.0-dev+4319" && @check fidr simplevec

x1 = read(fidr, "group1/x")
@assert x1 == Any[1]
Expand Down

0 comments on commit ad00d79

Please sign in to comment.