Skip to content

Commit

Permalink
Merge pull request #593 from JuliaIO/dev
Browse files Browse the repository at this point in the history
bugfix & version bump & changelog
  • Loading branch information
JonasIsensee authored Sep 8, 2024
2 parents cd2b137 + e207167 commit 3647927
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 10 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 0.5.1
- Bugfix and added test for bug introduced in v0.5.0

## 0.5.0
- Improved encoding of committed datatypes.
This fixes longstanding issues but new files will not be loaded correctly with JLD2 versions prior to `v0.5.0`.
Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "JLD2"
uuid = "033835bb-8acc-5ee8-8aae-3f567f8a3819"
version = "0.5.0"
version = "0.5.1"

[deps]
FileIO = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549"
Expand Down
13 changes: 8 additions & 5 deletions src/data/reconstructing_datatypes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,10 @@ end
function constructrr(f::JLDFile, u::Upgrade, dt::CompoundDatatype,
attrs::Vector{ReadAttribute},
hard_failure::Bool=false)
rodr = reconstruct_odr(f, dt, read_field_datatypes(f, dt, attrs))
T2 = NamedTuple{tuple(dt.names...), typeof(rodr).parameters[2]}
field_datatypes = read_field_datatypes(f, dt, attrs)
rodr = reconstruct_odr(f, dt, field_datatypes)
fnames = tuple((Symbol(k) for k in keys(field_datatypes))...)
T2 = NamedTuple{fnames, typeof(rodr).parameters[2]}
return (ReadRepresentation{u.target, CustomSerialization{T2, rodr}}(), false)
end

Expand Down Expand Up @@ -612,12 +614,13 @@ function reconstruct_compound(f::JLDFile, T::String, dt::H5Datatype,
field_datatypes::OrderedDict{String,RelOffset})
rodr = reconstruct_odr(f, dt, field_datatypes)
_, types, odrs = unpack_odr(rodr)
fnames = tuple((Symbol(k) for k in keys(field_datatypes))...,)
if !any(jlconvert_canbeuninitialized(ReadRepresentation{types[i], odrs[i]}()) for i = 1:length(types))
rt = ReconstructedStatic{Symbol(T), tuple(dt.names...), Tuple{types...}}
odr = OnDiskRepresentation{(0,), Tuple{NamedTuple{tuple(dt.names...),Tuple{types...}}}, Tuple{rodr}, dt.size}()
rt = ReconstructedStatic{Symbol(T), fnames, Tuple{types...}}
odr = OnDiskRepresentation{(0,), Tuple{NamedTuple{fnames,Tuple{types...}}}, Tuple{rodr}, dt.size}()
return (ReadRepresentation{rt, odr}(), false)
end
T = ReconstructedMutable{Symbol(T), tuple(dt.names...), Tuple{types...}}
T = ReconstructedMutable{Symbol(T), fnames, Tuple{types...}}
return ReadRepresentation{T, rodr}(), false
end

Expand Down
6 changes: 3 additions & 3 deletions test/Artifacts.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[testfiles]
git-tree-sha1 = "f258e1c3d2c53482fc7609571540f590c15d8f0f"
git-tree-sha1 = "898220ce869d52019b7029899bda91f21e6d86b8"
lazy = true

[[testfiles.download]]
sha256 = "ddf05bb0b3b982959334fcc2dfc1dc64abafae54c3b24343fb51b5db845c6d94"
url = "https://github.com/JonasIsensee/JLD2TestFiles/archive/refs/tags/v0.1.5.tar.gz"
sha256 = "69bd4577477b9cd18b888322495ddc1edae109f70be5d0b073e5af4d3bf4b867"
url = "https://github.com/JonasIsensee/JLD2TestFiles/archive/refs/tags/v0.1.6.tar.gz"
25 changes: 24 additions & 1 deletion test/test_files.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ update Artifacts.toml:
lazy=true)
update artifact string below to reflect new version number
=#
testfiles = artifact"testfiles/JLD2TestFiles-0.1.5/artifacts"
testfiles = artifact"testfiles/JLD2TestFiles-0.1.6/artifacts"

@testset "HDF5 compat test files" begin
# These are test files copied from the HDF5.jl test suite
Expand Down Expand Up @@ -269,4 +269,27 @@ end
@test getproperty(data["tms"], Symbol(1)) == 1
@test data["s"] == (a = 1,)
@test data["ds"].kvvec[1] == (; first = "a", second = (a = 1,))
end

@testset "Reconstruct struct with singleton fields" begin
fn = joinpath(testfiles,"singleton_struct_fields.jld2")
if VERSION v"1.7"
@test_warn "type Main.MissingStruct does not exist in workspace; reconstructing" ms = load(fn, "ms")
else # @test_warn works differently on 1.6
ms = load(fn, "ms")
end
@test ms.a == 1
@test ms.b === nothing
@test ms.c === missing
@test ms.d == 2.0
@test typeof(ms).parameters[1] == :MissingStruct

@test_nowarn ms = load(fn, "ms"; typemap=Dict("Main.MissingStruct" => JLD2.Upgrade(NamedTuple)))
@test ms.a == 1
@test ms.b === nothing
@test ms.c === missing
@test ms.d == 2.0

ms = load(fn, "ms"; plain=true)
@test ms == (; a=1, d=2.0)
end

2 comments on commit 3647927

@JonasIsensee
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

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

Registration pull request created: JuliaRegistries/General/114771

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.5.1 -m "<description of version>" 3647927e85d1fc832d460f7c05bb197c98eac3a4
git push origin v0.5.1

Please sign in to comment.