Skip to content

Commit 65ef689

Browse files
KristofferCKristofferC
andauthored
retain size for zero length multidimensional arrays in mmap (#59719)
Fixes #44679 Co-authored-by: KristofferC <[email protected]>
1 parent 3af9170 commit 65ef689

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

stdlib/Mmap/src/Mmap.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ function mmap(io::IO,
199199
overflow && throw(ArgumentError("requested size prod($((len, dims...))) too large, would overflow typeof(size(T)) == $(typeof(len))"))
200200
end
201201
len >= 0 || throw(ArgumentError("requested size must be ≥ 0, got $len"))
202-
len == 0 && return Array{T}(undef, ntuple(x->0,Val(N)))
202+
len == 0 && return Array{T}(undef, dims)
203203
len < typemax(Int) - PAGESIZE || throw(ArgumentError("requested size must be < $(typemax(Int)-PAGESIZE), got $len"))
204204

205205
offset >= 0 || throw(ArgumentError("requested offset must be ≥ 0, got $offset"))

stdlib/Mmap/test/runtests.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,13 @@ GC.gc(); GC.gc()
1111
GC.gc(); GC.gc()
1212
@test mmap(file, Array{UInt8,3}, (1,1,11)) == reshape(t,(1,1,11))
1313
GC.gc(); GC.gc()
14-
@test mmap(file, Array{UInt8,3}, (11,0,1)) == Array{UInt8}(undef, (0,0,0))
14+
@test size(mmap(file, Array{UInt8,3}, (11,0,1))) == (11,0,1)
1515
@test mmap(file, Vector{UInt8}, (11,)) == t
1616
GC.gc(); GC.gc()
1717
@test mmap(file, Array{UInt8,2}, (1,11)) == t'
1818
GC.gc(); GC.gc()
19-
@test mmap(file, Array{UInt8,2}, (0,12)) == Array{UInt8}(undef, (0,0))
19+
@test size(mmap(file, Array{UInt8,2}, (0,12))) == (0,12)
20+
@test size(mmap(file, Matrix{Float32}, (10,0))) == (10,0)
2021
m = mmap(file, Array{UInt8,3}, (1,2,1))
2122
@test m == reshape(b"He",(1,2,1))
2223
finalize(m); m=nothing; GC.gc()

0 commit comments

Comments
 (0)