From 037a9d30a0249033e12c6fa47773d743edfbcba8 Mon Sep 17 00:00:00 2001 From: Madison Yu <65697599+HongBinYu-hub@users.noreply.github.com> Date: Tue, 19 Dec 2023 17:14:05 +0800 Subject: [PATCH] compat: no MmapIO for windows 7 (#509) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Ensure win7 can be precompiled * format code * update precompile * change the default value for iotype (everywhere) * update MmapIO --------- Co-authored-by: 余宏彬 --- src/JLD2.jl | 12 ++++++++++-- src/loadsave.jl | 2 +- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/JLD2.jl b/src/JLD2.jl index e1dca33c..4c4f7ae5 100644 --- a/src/JLD2.jl +++ b/src/JLD2.jl @@ -56,6 +56,14 @@ include("bufferedio.jl") include("misc.jl") include("superblock.jl") +is_win7() = Sys.iswindows() && Sys.windows_version().major <= 6 && Sys.windows_version().minor <= 1 +# Windows 7 doesn't support mmap, falls back to IOStream +const DEFAULT_IOTYPE = if is_win7() + IOStream +else + MmapIO +end + """ RelOffset @@ -300,7 +308,7 @@ read_bytestring(io::IOStream) = String(readuntil(io, 0x00)) const OPEN_FILES = Dict{String,WeakRef}() const OPEN_FILES_LOCK = ReentrantLock() -function jldopen(fname::AbstractString, wr::Bool, create::Bool, truncate::Bool, iotype::T=MmapIO; +function jldopen(fname::AbstractString, wr::Bool, create::Bool, truncate::Bool, iotype::T=DEFAULT_IOTYPE; fallback::Union{Type, Nothing} = FallbackType(iotype), compress=false, mmaparrays::Bool=false, @@ -437,7 +445,7 @@ Opens a JLD2 file at path `fname`. `"a"`/`"a+"`: Open for reading and writing, creating a new file if none exists, but preserving the existing file if one is present """ -function jldopen(fname::AbstractString, mode::AbstractString="r"; iotype=MmapIO, kwargs...) +function jldopen(fname::AbstractString, mode::AbstractString="r"; iotype=DEFAULT_IOTYPE, kwargs...) (wr, create, truncate) = mode == "r" ? (false, false, false) : mode == "r+" ? (true, false, false) : mode == "a" || mode == "a+" ? (true, true, false) : diff --git a/src/loadsave.jl b/src/loadsave.jl index 63b84a57..14d9acd6 100644 --- a/src/loadsave.jl +++ b/src/loadsave.jl @@ -237,7 +237,7 @@ is equivalent to To choose the io type `IOStream` instead of the default `MmapIO` use `jldsave(fn, IOStream; kwargs...)`. """ -function jldsave(filename::AbstractString, compress=false, iotype::T=MmapIO; +function jldsave(filename::AbstractString, compress=false, iotype::T=DEFAULT_IOTYPE; kwargs... ) where T<:Union{Type{IOStream},Type{MmapIO}} jldopen(filename, "w"; compress=compress, iotype=iotype) do f