Skip to content

Commit f4ba837

Browse files
authored
Merge pull request #631 from KristofferC/backports-release-0.4
Backports some fixes to 0.4
2 parents b9fdf3e + 2bf98ff commit f4ba837

7 files changed

+50
-62
lines changed

CHANGELOG.md

+15-11
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.4.54
2+
3+
- **Deprecation**: Do not rely on JLD2 to load a compression library. This feature will be removed in a future release. Instead explicitly add `using` statements into your scripts.
4+
15
## 0.4.53
26
- Experimental: Slicing and inplace updating of array datasets
37
- updated CI workflows
@@ -22,7 +26,7 @@
2226
- fix `Upgrade` for Singleton types
2327

2428
## 0.4.50
25-
- Don't hide exception data during loading and saving (#569)
29+
- Don't hide exception data during loading and saving (#569)
2630

2731
## 0.4.49
2832
- update compat bounds
@@ -32,7 +36,7 @@
3236
- fix behaviour for unnormalized strings
3337
- add missing method for load_attributes
3438
- clean up `using` statements
35-
39+
3640
## 0.4.47
3741
- fix loading structs with more than 256 fields (#558)
3842

@@ -71,7 +75,7 @@
7175
- restrict default Dict encoding to Base implementations
7276

7377
## 0.4.37
74-
- Update Dict encoding for latest julia
78+
- Update Dict encoding for latest julia
7579

7680
## 0.4.36
7781
- compat bound for TranscodingStreams.jl
@@ -93,22 +97,22 @@
9397
## 0.4.31
9498
- fix UInt32 truncation error for absurdly large array sizes
9599
- move test-files to a separate repo
96-
100+
97101
## 0.4.30
98102
- allow loading compressed files during precompilation #446 (@marius311)
99-
103+
100104
## 0.4.29
101105
- added `Upgrade` feature
102-
106+
103107
## 0.4.28
104108
- compatibility to julia v1.9-dev (@eschnett)
105-
109+
106110
## 0.4.26
107111
- fix identity relations with custom serialization
108112

109113
## 0.4.25
110114
- remove leftover debug statement
111-
115+
112116
## 0.4.24
113117
- read-only support for `JLD.jl` files
114118
- read-only support for many HDF5 files. Most test files of HDF5.jl are covered
@@ -119,14 +123,14 @@
119123

120124
## 0.4.23
121125
- Support for `const` fields in mutable structs
122-
126+
123127
## 0.4.22
124128
- Fix reconstruction of partially initialized structs
125129

126130
## 0.4.21
127-
- Add explicit type mapping
131+
- Add explicit type mapping
128132

129-
## 0.4.20
133+
## 0.4.20
130134
- TTFX improvements
131135
- Add a comment on jldsave (@BoundaryValueProblems)
132136
## 0.4.19

Project.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "JLD2"
22
uuid = "033835bb-8acc-5ee8-8aae-3f567f8a3819"
3-
version = "0.4.53"
3+
version = "0.4.54"
44

55
[deps]
66
FileIO = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549"

src/compression.jl

+7-24
Original file line numberDiff line numberDiff line change
@@ -33,35 +33,18 @@ end
3333
# Dynamic Package Loading Logic copied from FileIO
3434
const load_locker = Base.ReentrantLock()
3535

36-
function _findmod(f::Symbol)
37-
for (u,v) in Base.loaded_modules
38-
(Symbol(v) == f) && return u
39-
end
40-
nothing
41-
end
42-
43-
function topimport(modname)
44-
@info "Attempting to dynamically load $modname"
45-
@eval Base.__toplevel__ import $modname
46-
u = _findmod(modname)
47-
@eval $modname = Base.loaded_modules[$u]
48-
end
4936

5037
function checked_import(pkg::Symbol)
5138
lock(load_locker) do
52-
# kludge for test suite
53-
if isdefined(Main, pkg)
54-
m1 = getfield(Main, pkg)
55-
isa(m1, Module) && return false, m1
39+
for m in Base.loaded_modules_array()
40+
(Symbol(m) == pkg) && return false, m
5641
end
57-
if isdefined(JLD2, pkg)
58-
m1 = getfield(JLD2, pkg)
59-
isa(m1, Module) && return false, m1
42+
@info "Attempting to dynamically load $pkg"
43+
@eval Base.__toplevel__ import $pkg
44+
for m in Base.loaded_modules_array()
45+
(Symbol(m) == pkg) && return true, m
6046
end
61-
m = _findmod(pkg)
62-
(m === nothing) || return false, Base.loaded_modules[m]
63-
topimport(pkg)
64-
return true, Base.loaded_modules[_findmod(pkg)]
47+
throw(InternalError("Module $pkg could not be loaded."))
6548
end
6649
end
6750

src/data/reconstructing_datatypes.jl

+17-19
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ end
2020
"""
2121
readas(::Type)::Type
2222
23-
**Experimental feature**:
23+
**Experimental feature**:
2424
`JLD2.readas` can be overloaded to override which type a saved type is read as,
2525
and is used together with custom serialization using [`JLD2.writeas`](@ref).
2626
2727
The typical case is custom serialization of parametric types,
28-
where not all type parameters are available during reading.
28+
where not all type parameters are available during reading.
2929
Consider the following example for an anonymous function `fun` inside a `Foo`
3030
```julia
3131
struct Foo{F<:Function}
@@ -53,7 +53,7 @@ restart julia, include the definitions again, and call
5353
`foo::Foo{UndefinedFunction}` and `foo::FooSerialization`
5454
with and without defining the `JLD2.readas` above, respectively.
5555
"""
56-
readas(::Any) = nothing # default to nothing to do nothing if no overload is specified.
56+
readas(::Any) = nothing # default to nothing to do nothing if no overload is specified.
5757

5858
function _readas(T_custom, T_in)
5959
T_out = readas(T_custom)::Union{Type,Nothing}
@@ -65,7 +65,7 @@ end
6565
function jltype(f::JLDFile, sdt::Union{SharedDatatype,CommittedDatatype})
6666
cdt = get(f.datatype_locations, sdt.header_offset, sdt)
6767
haskey(f.h5jltype, cdt) && return f.h5jltype[cdt]::ReadRepresentation
68-
68+
6969
dt, attrs = read_shared_datatype(f, cdt)
7070

7171
julia_type_attr = nothing
@@ -223,12 +223,12 @@ function constructrr(f::JLDFile, T::DataType, dt::CompoundDatatype,
223223
# The on disk representation of T can only be the same as in memory
224224
# if the offsets are the same, field type on disk (readtype) and in memory (wstype)
225225
# are the same and if no CustomSerialization is involved
226-
samelayout = samelayout &&
227-
offsets[i] == fieldoffset(T, i) &&
228-
types[i] === wstype &&
226+
samelayout = samelayout &&
227+
offsets[i] == fieldoffset(T, i) &&
228+
types[i] === wstype &&
229229
# An OnDiskRepresentation as odr means that something "fixable" went wrong
230230
# for this field
231-
!(odrs[i] isa OnDiskRepresentation) &&
231+
!(odrs[i] isa OnDiskRepresentation) &&
232232
!(odrs[i] <: CustomSerialization)
233233

234234
mapped[dtindex] = true
@@ -285,13 +285,13 @@ function constructrr(f::JLDFile, u::Upgrade, dt::CompoundDatatype,
285285

286286
T2 = NamedTuple{tuple(dt.names...), typeof(rodr).parameters[2]}
287287

288-
return (ReadRepresentation{u.target, CustomSerialization{T2, rodr}}(), false)
288+
return (ReadRepresentation{u.target, CustomSerialization{T2, rodr}}(), false)
289289
end
290290

291-
function constructrr(f::JLDFile, u::Upgrade, dt::BasicDatatype,
291+
function constructrr(f::JLDFile, u::Upgrade, dt::BasicDatatype,
292292
attrs::Vector{ReadAttribute},
293293
hard_failure::Bool=false)
294-
return (ReadRepresentation{u.target, CustomSerialization{NamedTuple{(), Tuple{}},nothing}}(), false)
294+
return (ReadRepresentation{u.target, CustomSerialization{NamedTuple{(), Tuple{}},nothing}}(), false)
295295
end
296296

297297
function constructrr(f::JLDFile, T::UnionAll, dt::CompoundDatatype,
@@ -334,9 +334,7 @@ function _resolve_type(rr::ReadRepresentation{T,DataTypeODR()},
334334
hasparams::Bool,
335335
params) where T
336336
parts = split(mypath, '.')
337-
modules = vcat([Main], collect(keys(Base.module_keys)))
338-
unique!(modules)
339-
for mod in modules
337+
for mod in Base.loaded_modules_array()
340338
resolution_attempt = _resolve_type_singlemodule(rr,
341339
mod,
342340
parts,
@@ -689,9 +687,9 @@ function jlconvert(::ReadRepresentation{T, S}, f::JLDFile, ptr::Ptr, header_offs
689687
offset = offsets[i]
690688
rtype = types[i]
691689
odr = odrs[i]
692-
690+
693691
rr = ReadRepresentation{rtype,odr}()
694-
if !(jlconvert_canbeuninitialized(rr)) || jlconvert_isinitialized(rr, ptr+offset)
692+
if !(jlconvert_canbeuninitialized(rr)) || jlconvert_isinitialized(rr, ptr+offset)
695693
res[i] = jlconvert(rr, f, ptr+offset, NULL_REFERENCE)
696694
end
697695
end
@@ -721,9 +719,9 @@ end
721719
offset = offsets[i]
722720
rtype = types[i]
723721
odr = odrs[i]
724-
722+
725723
rr = ReadRepresentation{rtype,odr}()
726-
724+
727725
fni = QuoteNode(fn[i])
728726
ttype = T.types[i]
729727
if odr === nothing
@@ -745,7 +743,7 @@ end
745743
end
746744
end
747745

748-
push!(args, (:obj))
746+
push!(args, (:obj))
749747
return blk
750748
end
751749
if isbitstype(T)

src/data/specialcased_types.jl

+8-6
Original file line numberDiff line numberDiff line change
@@ -304,13 +304,15 @@ wconvert(::Type{String}, x::Module) = string(x)
304304
function rconvert(::Type{Module}, x::String)
305305
pkg = Symbol(x)
306306
# Try to find the module
307-
# Start with the method used to find compression libraries
308-
m =_findmod(pkg)
309-
isnothing(m) || return Base.loaded_modules[m]
310-
@info "Encountered reference to module $x, but it is not currently loaded."
307+
for m in Base.loaded_modules_array()
308+
(Symbol(m) == pkg) && return m
309+
end
310+
@warn "Encountered reference to module $x, but it is not currently loaded."
311311
return try
312-
topimport(pkg)
313-
Base.loaded_modules[_findmod(pkg)]
312+
@eval Base.__toplevel__ import $pkg
313+
for m in Base.loaded_modules_array()
314+
(Symbol(m) == pkg) && return m
315+
end
314316
catch
315317
@warn "Could not load module $x. Returning a dummy module"
316318
Module(Symbol(x*"_dummy"))

test/modules.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ S = BType(x)
2121
end
2222

2323
@testset "name collisions" begin
24-
mods = collect(keys(Base.module_keys))
24+
mods = Base.loaded_modules_array()
2525
# use whichever module would not be found first in a linear search
2626
M = findfirst(==(A), mods) < findfirst(==(B), mods) ? B : A
2727
x = M.SameNameType(42)

test/runtests.jl

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using JLD2, FileIO
22
using Test
3+
using CodecZlib, CodecBzip2, CodecZstd, CodecLz4
34

45
function better_success(cmd)
56
fn1, _ = mktemp()

0 commit comments

Comments
 (0)