Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/JLD2.jl
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,6 @@ function jldopen(fname::AbstractString, wr::Bool, create::Bool, truncate::Bool,
parallel_read::Bool=false,
plain::Bool=false
) where T<:Union{Type{IOStream},Type{MmapIO}}

mmaparrays && @warn "mmaparrays keyword is currently ignored" maxlog = 1
filters = Filters.normalize_filters(compress)

Expand Down
20 changes: 19 additions & 1 deletion src/data/reconstructing_datatypes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,24 @@ function types_from_refs(f::JLDFile, ptr::Ptr)
end
end

if VERSION ≥ v"1.12"
const loaded_modules = OncePerTask{Ref{Tuple{UInt, Vector{Module}}}}() do
Ref{Tuple{UInt, Vector{Module}}}((Base.tls_world_age(), Base.loaded_modules_array()))
end

function get_loaded_modules()
loaded_modules_cache = loaded_modules()
cached_world_age, cached_loaded_modules = loaded_modules_cache[]
if Base.tls_world_age() ≥ cached_world_age
cached_loaded_modules = Base.loaded_modules_array()
loaded_modules_cache[] = (Base.tls_world_age(), cached_loaded_modules)
end
return cached_loaded_modules
end
else
get_loaded_modules() = Base.loaded_modules_array()
end

"""
find_type(typepath::String)

Expand All @@ -324,7 +342,7 @@ If the type is not found, it returns `nothing`.
function find_type(typepath::String)
parts = split(typepath, '.')
# Find a type in the loaded modules by traversing the parts
for mod in Base.loaded_modules_array()
for mod in get_loaded_modules()
for part in parts
sym = Symbol(part)
(!isa(mod, Module) || !isdefined(mod, sym)) && break
Expand Down
4 changes: 2 additions & 2 deletions src/data/specialcased_types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -311,13 +311,13 @@ wconvert(::Type{String}, x::Module) = string(x)
function rconvert(::Type{Module}, x::String)
pkg = Symbol(x)
# Try to find the module
for m in Base.loaded_modules_array()
for m in get_loaded_modules()
(Symbol(m) == pkg) && return m
end
@warn "Encountered reference to module $x, but it is not currently loaded."
return try
@eval Base.__toplevel__ import $pkg
for m in Base.loaded_modules_array()
for m in get_loaded_modules()
(Symbol(m) == pkg) && return m
end
catch
Expand Down
Loading