Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mmap_array fails for empty file (0-length array) #10516

Closed
stevengj opened this issue Mar 13, 2015 · 4 comments
Closed

mmap_array fails for empty file (0-length array) #10516

stevengj opened this issue Mar 13, 2015 · 4 comments
Labels
io Involving the I/O subsystem: libuv, read, write, etc.

Comments

@stevengj
Copy link
Member

mmap_array(Int, (0,), open("foo", "r")) on an empty file "foo" gives:

ERROR: SystemError: memory mapping failed: Invalid argument
 in systemerror at /Users/stevenj/Code/julia/usr/lib/julia/sys.dylib
 in mmap at mmap.jl:35
 in mmap_array at mmap.jl:108
 in mmap_array at mmap.jl:4

(See also JuliaIO/JSON.jl#98.)

@ihnorton ihnorton added the io Involving the I/O subsystem: libuv, read, write, etc. label Mar 24, 2015
@quinnj
Copy link
Member

quinnj commented Oct 14, 2015

The current behavior is an explicit check that the file size is > 0 or an ArgumentError is thrown. I guess I can see the argument that we should return a 0-length array. Do people think that would generally be a better behavior?

@stevengj
Copy link
Member Author

Since 0-length arrays are valid, I think it would be better to support any length >= 0 here. 0 length will come up as a corner case in a lot of algorithms, and it's better not to force the caller to check for that.

@kcajf
Copy link
Contributor

kcajf commented Jul 5, 2021

Sorry to raise an old issue. I just encountered the following:

julia> using Mmap

julia> x = Mmap.mmap(open("test.dat", "w+"), Array{Float64,2}, (1, 10))
1×10 Matrix{Float64}:
 0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0
 
julia> x = Mmap.mmap(open("test.dat", "w+"), Array{Float64,2}, (0, 10))
0×0 Matrix{Float64}

I would expect the second call to return a 0x10 Matrix{Float64} instead of 0x0. I traced the cause to the line added in this issue/PR:

len == 0 && return Array{T}(undef, ntuple(x->0,Val(N)))

It looks like this could be an oversight, and that line could just be replaced with:

len == 0 && return Array{T}(undef, dims)

What do you think?

@stevengj
Copy link
Member Author

stevengj commented Jul 5, 2021

Yes, that seems like an oversight in d208f8d, and would make a good PR.

On an unrelated note, it seems like the len >= 0 check in that function should really be all(>=(0), dims)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
io Involving the I/O subsystem: libuv, read, write, etc.
Projects
None yet
Development

No branches or pull requests

4 participants