Skip to content

Commit

Permalink
compat: no MmapIO for windows 7 (#509)
Browse files Browse the repository at this point in the history
* Ensure win7 can be precompiled

* format code

* update precompile

* change the default value for iotype (everywhere)

* update MmapIO

---------

Co-authored-by: 余宏彬 <[email protected]>
  • Loading branch information
HongBinYu-hub and 余宏彬 authored Dec 19, 2023
1 parent a0d0730 commit 037a9d3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
12 changes: 10 additions & 2 deletions src/JLD2.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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) :
Expand Down
2 changes: 1 addition & 1 deletion src/loadsave.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 037a9d3

Please sign in to comment.