diff --git a/base/mmap.jl b/base/mmap.jl index 3a331d884bc0f..3aef752cac3bc 100644 --- a/base/mmap.jl +++ b/base/mmap.jl @@ -99,7 +99,8 @@ function mmap{T,N}(io::IO, isbits(T) || throw(ArgumentError("unable to mmap $T; must satisfy isbits(T) == true")) len = prod(dims) * sizeof(T) - len > 0 || throw(ArgumentError("requested size must be > 0, got $len")) + len >= 0 || throw(ArgumentError("requested size must be ≥ 0, got $len")) + len == 0 && return Array(T,ntuple(x->0,N)) len < typemax(Int) - PAGESIZE || throw(ArgumentError("requested size must be < $(typemax(Int)-PAGESIZE), got $len")) offset >= 0 || throw(ArgumentError("requested offset must be ≥ 0, got $offset")) diff --git a/test/mmap.jl b/test/mmap.jl index 2a7b493bd1b68..987f0732a92e8 100644 --- a/test/mmap.jl +++ b/test/mmap.jl @@ -11,12 +11,12 @@ gc(); gc() gc(); gc() @test Mmap.mmap(file, Array{UInt8,3}, (1,1,11)) == reshape(t,(1,1,11)) gc(); gc() -@test_throws ArgumentError Mmap.mmap(file, Array{UInt8,3}, (11,0,1)) # 0-dimension results in len=0 +@test Mmap.mmap(file, Array{UInt8,3}, (11,0,1)) == Array(UInt8,(0,0,0)) @test Mmap.mmap(file, Vector{UInt8}, (11,)) == t gc(); gc() @test Mmap.mmap(file, Array{UInt8,2}, (1,11)) == t' gc(); gc() -@test_throws ArgumentError Mmap.mmap(file, Array{UInt8,2}, (0,12)) +@test Mmap.mmap(file, Array{UInt8,2}, (0,12)) == Array(UInt8,(0,0)) m = Mmap.mmap(file, Array{UInt8,3}, (1,2,1)) @test m == reshape("He".data,(1,2,1)) finalize(m); m=nothing; gc() @@ -48,8 +48,8 @@ close(s) gc(); gc() s = open(f->f,file,"w") -@test_throws ArgumentError Mmap.mmap(file) # requested len=0 on empty file -@test_throws ArgumentError Mmap.mmap(file,Vector{UInt8},0) +@test Mmap.mmap(file) == Array(UInt8, 0) # requested len=0 on empty file +@test Mmap.mmap(file,Vector{UInt8},0) == Array(UInt8, 0) m = Mmap.mmap(file,Vector{UInt8},12) m[:] = "Hello World\n".data Mmap.sync!(m) @@ -284,4 +284,4 @@ n = similar(m, (2,2)) n = similar(m, 12) @test length(n) == 12 @test size(n) == (12,) -finalize(m); m = nothing; gc() \ No newline at end of file +finalize(m); m = nothing; gc()