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

Unix.read exhibits two different behaviors on Windows vs Linux #7342

Closed
vicuna opened this issue Aug 31, 2016 · 4 comments
Closed

Unix.read exhibits two different behaviors on Windows vs Linux #7342

vicuna opened this issue Aug 31, 2016 · 4 comments

Comments

@vicuna
Copy link

vicuna commented Aug 31, 2016

Original bug ID: 7342
Reporter: @protz
Assigned to: @protz
Status: resolved (set by @gasche on 2016-12-16T02:49:50Z)
Resolution: fixed
Priority: normal
Severity: minor
Version: 4.05.0 +dev/beta1/beta2/beta3/rc1
Target version: 4.05.0 +dev/beta1/beta2/beta3/rc1
Fixed in version: 4.05.0 +dev/beta1/beta2/beta3/rc1
Category: platform support (windows, cross-compilation, etc)
Monitored by: dsheets @gasche @hcarty

Bug description

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 ocsigen/lwt#20 for another project that performed a workaround there).

Steps to reproduce

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.

Additional information

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?

File attachments

@vicuna
Copy link
Author

vicuna commented Aug 31, 2016

Comment author: @gasche

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.

@vicuna
Copy link
Author

vicuna commented Aug 31, 2016

Comment author: @xavierleroy

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.

@vicuna
Copy link
Author

vicuna commented Sep 7, 2016

Comment author: @protz

#797

@vicuna
Copy link
Author

vicuna commented Dec 16, 2016

Comment author: @gasche

Fixed by merging #797.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant