MantisBT - OCaml
View Issue Details
0007342OCamlplatform support (windows, cross-compilation, etc)public2016-08-31 17:592016-12-16 03:49
protz 
protz 
normalminoralways
resolvedfixed 
4.05.0 +dev/beta1/beta2/beta3/rc1 
4.05.0 +dev/beta1/beta2/beta3/rc14.05.0 +dev/beta1/beta2/beta3/rc1 
0007342: Unix.read exhibits two different behaviors on Windows vs Linux
Reading Didier and Xavier's excellent "Unix programming in OCaml" course, I performed a `Unix.read` on a descriptor, expecting to read 0 when the descriptor had nothing left in it.

Sadly, I was developing on Windows. It turns out that `Unix.read` throws `EPIPE` there instead (see https://github.com/ocsigen/lwt/issues/20 [^] for another project that performed a workaround there).
See the attached file.

# #use "Test.ml";;
- : unit = ()

# run "ls" [||];;
Exception: Unix.Unix_error (Unix.EPIPE, "read", "").

The workaround is to remove the "when false" clause in Test.ml.
I can submit a pull request that wraps otherlibs/win32unix/unix.ml:read with that exact try-catch block, or I can submit a documentation request that documents this caveat. Any preference?
No tags attached.
? Test.ml (807) 2016-08-31 17:59
https://caml.inria.fr/mantis/file_download.php?file_id=1638&type=bug
Issue History
2016-08-31 17:59protzNew Issue
2016-08-31 17:59protzFile Added: Test.ml
2016-08-31 18:24gascheNote Added: 0016254
2016-08-31 19:03xleroyNote Added: 0016255
2016-09-07 16:47shinwellTarget Version => 4.05.0 +dev/beta1/beta2/beta3/rc1
2016-09-07 20:27protzNote Added: 0016271
2016-11-08 11:56doligezStatusnew => acknowledged
2016-12-16 03:49gascheNote Added: 0017014
2016-12-16 03:49gascheStatusacknowledged => resolved
2016-12-16 03:49gascheFixed in Version => 4.05.0 +dev/beta1/beta2/beta3/rc1
2016-12-16 03:49gascheResolutionopen => fixed
2016-12-16 03:49gascheAssigned To => protz
2017-02-23 16:46doligezCategoryOCaml windows => platform support (windows, etc)
2017-02-23 17:16doligezCategoryplatform support (windows, etc) => platform support (windows, cross-compilation, etc)

Notes
(0016254)
gasche   
2016-08-31 18:24   
As a mostly-unix programmer I would have a preference for the documented behavior (also in `man 3 read` on the C side) to work reliably on Windows -- I'm sure I would have been confused by the issue if people tried my software on Windows.
(0016255)
xleroy   
2016-08-31 19:03   
Another Win32/Unix gratuitous difference, wonderful.

My preferred fix would be to change win32unix/read.c so that a GetLastError() code ERROR_BROKEN_PIPE is turned into a return of 0.
(0016271)
protz   
2016-09-07 20:27   
https://github.com/ocaml/ocaml/pull/797 [^]
(0017014)
gasche   
2016-12-16 03:49   
Fixed by merging GPR#797.