Skip to content

Commit

Permalink
add method for mutable custom serialization (#537)
Browse files Browse the repository at this point in the history
  • Loading branch information
JonasIsensee authored Jan 19, 2024
1 parent 15eaa50 commit 6760bd4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/data/custom_serialization.jl
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ jlconvert_canbeuninitialized(::ReadRepresentation{T,CustomSerialization{S,ODR}})
jlconvert_isinitialized(::ReadRepresentation{T,CustomSerialization{S,ODR}}, ptr::Ptr) where {T,S,ODR} =
jlconvert_isinitialized(ReadRepresentation{S,ODR}(), ptr)

function jlconvert(::ReadRepresentation{T,CustomSerialization{S,RelOffset}},
f::JLDFile, ptr::Ptr, header_offset::RelOffset) where {T,S}
# Concerns objects whose custom serialization is itself only referenced by a RelOffset
# This be important when the original object is mutable
offset = jlunsafe_load(pconvert(Ptr{RelOffset}, ptr))
return rconvert(T, load_dataset(f, offset))
end

function jlconvert(::ReadRepresentation{T,CustomSerialization{S,ODR}},
f::JLDFile, ptr::Ptr, header_offset::RelOffset) where {T,S,ODR}
Expand Down
10 changes: 10 additions & 0 deletions test/loadsave.jl
Original file line number Diff line number Diff line change
Expand Up @@ -739,4 +739,14 @@ end
jldsave("testopempty.jld2"; op)
@test op == load("testopempty.jld2", "op")
end
end

@testset "Issue #536 reading directly after writing" begin
cd(mktempdir()) do
x = (1, Dict(2=>3))
jldopen("test.jld2", "w") do f
f["x"] = x
@test x == f["x"]
end
end
end

0 comments on commit 6760bd4

Please sign in to comment.