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

map_file fails to map to empty bigarray #5463

Closed
vicuna opened this issue Jan 4, 2012 · 4 comments

Comments

Projects
None yet
1 participant
@vicuna
Copy link

commented Jan 4, 2012

Original bug ID: 5463
Reporter: @mjambon
Status: closed (set by @xavierleroy on 2013-08-31T10:49:00Z)
Resolution: fixed
Priority: normal
Severity: minor
OS: Linux
OS Version: 2.6.34
Version: 3.12.1
Fixed in version: 4.00.0+dev
Category: ~DO NOT USE (was: OCaml general)
Monitored by: mehdi @dbuenzli

Bug description

Bigarray.Array1.map_file fails if the array to be created is empty. This is a slight annoyance because it is not documented in the manual. I don't know where the various implementations of mmap stand, but a warning note would be welcome if a fix is not possible.

On Linux, "man mmap" says in the ERRORS section:

   EINVAL (since Linux 2.6.12) length was 0.

Steps to reproduce

$ cat > mapfile.ml
(* ocamlopt -o mapfile unix.cmxa bigarray.cmxa mapfile.ml *)
let empty = Filename.temp_file "empty" ".dat";;
let fd = Unix.openfile empty [Unix.O_RDONLY] 0;;
Bigarray.Array1.map_file fd Bigarray.char Bigarray.c_layout false 0

$ ocamlopt -o mapfile unix.cmxa bigarray.cmxa mapfile.ml
$ ./mapfile
Fatal error: exception Sys_error("Invalid argument")

@vicuna

This comment has been minimized.

Copy link
Author

commented Jan 4, 2012

Comment author: @dbuenzli

On

uname -v
Darwin Kernel Version 10.8.0: Tue Jun 7 16:33:36 PDT 2011; root:xnu-1504.15.3~1/RELEASE_I386

the man says :

[...]

COMPATIBILITY
mmap() now returns with errno set to EINVAL in places that historically
succeeded. The rules have changed as follows:

 o   The flags parameter must specify either MAP_PRIVATE or MAP_SHARED.

 o   The size parameter must not be 0.

 o   The off parameter must be a multiple of pagesize, as returned by
     sysconf().
@vicuna

This comment has been minimized.

Copy link
Author

commented Jan 4, 2012

Comment author: gerd

@dbuenzli: map_file allows it to map files at offsets that are not a multiple of the pagesize. This is done by rounding down to the next multiple, and hiding the intitial part of the mapping from the user. What I want to say is that it does not necessarily matter what mmap allows when there is a way to emulate more general behavior.

I think an emulation for size=0 is very easy - just return the empty array instead (don't call mmap at all).

@vicuna

This comment has been minimized.

Copy link
Author

commented Jan 17, 2012

Comment author: @xavierleroy

Thanks for the analysis. The proposed fix looks good to me. To be implemented some day.

@vicuna

This comment has been minimized.

Copy link
Author

commented Apr 9, 2012

Comment author: @xavierleroy

Gerd's solution implemented in commit 12326 in version/4.00, 12327 in trunk.

@vicuna vicuna closed this Aug 31, 2013

@vicuna vicuna added the bug label Mar 20, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.