From 0ec2783e8c7e13d43820a985cfadcf8e6f3562a7 Mon Sep 17 00:00:00 2001 From: Jonas Isensee Date: Sun, 8 Sep 2024 20:03:31 +0200 Subject: [PATCH 1/2] bugfix & version bump & changelog --- CHANGELOG.md | 3 +++ Project.toml | 2 +- src/data/reconstructing_datatypes.jl | 13 ++++++++----- test/Artifacts.toml | 6 +++--- test/test_files.jl | 21 ++++++++++++++++++++- 5 files changed, 35 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6cddef6e..ff172ae9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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`. diff --git a/Project.toml b/Project.toml index e6595265..571a98d9 100644 --- a/Project.toml +++ b/Project.toml @@ -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" diff --git a/src/data/reconstructing_datatypes.jl b/src/data/reconstructing_datatypes.jl index 861d00a8..1f2c58ed 100644 --- a/src/data/reconstructing_datatypes.jl +++ b/src/data/reconstructing_datatypes.jl @@ -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 @@ -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 diff --git a/test/Artifacts.toml b/test/Artifacts.toml index 15e3e862..f96e1a19 100644 --- a/test/Artifacts.toml +++ b/test/Artifacts.toml @@ -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" diff --git a/test/test_files.jl b/test/test_files.jl index dd0802e7..27ebc152 100644 --- a/test/test_files.jl +++ b/test/test_files.jl @@ -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 @@ -269,4 +269,23 @@ 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") + @test_warn "type Main.MissingStruct does not exist in workspace; reconstructing" ms = load(fn, "ms") + @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 \ No newline at end of file From e20716758dbba0d3aeb2028c18d592ad65d6d26d Mon Sep 17 00:00:00 2001 From: Jonas Isensee Date: Sun, 8 Sep 2024 20:21:58 +0200 Subject: [PATCH 2/2] @test_warn behaves differently on julia <1.7 --- test/test_files.jl | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/test/test_files.jl b/test/test_files.jl index 27ebc152..6c40eefb 100644 --- a/test/test_files.jl +++ b/test/test_files.jl @@ -273,7 +273,11 @@ end @testset "Reconstruct struct with singleton fields" begin fn = joinpath(testfiles,"singleton_struct_fields.jld2") - @test_warn "type Main.MissingStruct does not exist in workspace; reconstructing" ms = load(fn, "ms") + 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