Re: [Caml-list] How to handle system decencies in Ocaml (like O_ASYNC not implemented in cygwin)

34 views
Skip to first unread message

Yaron Minsky

unread,
May 6, 2016, 10:33:53 AM5/6/16
to Soegtrop, Michael, caml...@inria.fr, ocaml...@googlegroups.com
Looping in the Core mailing list, since this seems like a core-specific issue.

y

On Fri, May 6, 2016 at 4:48 AM, Soegtrop, Michael
<michael....@intel.com> wrote:
> Dear Ocaml users,
>
>
>
> I am working on compiling core with opam on cygwin. My plan is to integrate
> this with the work of whitequark (MinGW cross opam for Linux) to have a
> MinGW cross opam on cygwin.
>
>
>
> I already have a convenient script to setup cygwin with all modules and to
> compile opam and it works fine. Just when compiling core, there are two Unix
> features not implemented in cygwin. One is O_ASYNC. It is easy to patch it
> away and also easy to make this system dependent in the C file
> (unix_stubs.c), but I wonder how I could handle this in a portable way in
> the OCaml wrapper. It looks like this:
>
>
>
> module Open_flags = struct
>
> external append : unit -> Int63.t = "unix_O_APPEND"
>
> external async : unit -> Int63.t = "unix_O_ASYNC"
>
> external cloexec : unit -> Int63.t = "unix_O_CLOEXEC"
>
>
>
> Is there some way to have async on normal Linux and not have it on cygwin?
>
>
>
> Btw.: Opam, batteries and 34 out of the 35 modules of core compile fine on
> cygwin and the remaining module just has two errors, so I think it is
> worthwhile to fix this.
>
> Best regards,
>
> Michael
>
>
>
> Intel Deutschland GmbH
> Registered Address: Am Campeon 10-12, 85579 Neubiberg, Germany
> Tel: +49 89 99 8853-0, www.intel.de
> Managing Directors: Christin Eisenschmid, Christian Lamprechter
> Chairperson of the Supervisory Board: Nicole Lau
> Registered Office: Munich
> Commercial Register: Amtsgericht Muenchen HRB 186928

Jérôme Benoit

unread,
May 7, 2016, 12:29:56 PM5/7/16
to Yaron Minsky, Soegtrop, Michael, caml...@inria.fr, ocaml...@googlegroups.com
On Fri, 6 May 2016 10:33:32 -0400 in
<CACLX4jRYhcZ4XZCDKGODYd1PPBcqCcfGUU2aVU=VJski...@mail.gmail.com>,
Yaron Minsky <ymi...@janestreet.com> wrote:

> Looping in the Core mailing list, since this seems like a
> core-specific issue.

> > I already have a convenient script to setup cygwin with all modules
> > and to compile opam and it works fine. Just when compiling core,
> > there are two Unix features not implemented in cygwin. One is
> > O_ASYNC. It is easy to patch it away and also easy to make this
> > system dependent in the C file (unix_stubs.c), but I wonder how I
> > could handle this in a portable way in the OCaml wrapper. It looks
> > like this:
> >

Most people that need to make portable code handle flag dependencies on
open() - or other flags on standard functions - in the buildsystem
with a little piece of C code that open() a file created by the
buildsystem with different flags and catch the return code :

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
...
int retasync = open(/path/to/test/file, O_ASYNC);
...

then define a boolean inside the buildsystem to make conditional
compilation based on the boolean.

Cheers.

--
Jérôme Benoit aka fraggle
Piment Noir - http://piment-noir.org
OpenPGP Key ID : 9FE9161D
Key fingerprint : 9CA4 0249 AF57 A35B 34B3 AC15 FAA0 CB50 9FE9 161D

Jérôme Benoit

unread,
May 7, 2016, 12:29:56 PM5/7/16
to Soegtrop, Michael, Yaron Minsky, caml...@inria.fr, ocaml...@googlegroups.com
On Sat, 7 May 2016 08:37:22 +0000 in
<0F7D3B1B3C4B894D824F...@IRSMSX102.ger.corp.intel.com>,
"Soegtrop, Michael" <michael....@intel.com> wrote:

> Dear Jérôme,
>
> it is easy to detect with preprocessor defines if O_ASYNC is
> supported or not on the C level. I wondered what would be the most
> appropriate way to inform OCaml of the situation. I guess I should
> just call caml_failwith("O_ASYNC not supported by Cygwin") in the
> async function on cygwin?

So you want to catch the system call specificities at runtime inside
OCaml ?

Not sure it's a good idea to maintain a list of supported features, std
functions flags, etc. linked to uname -o output inside OCaml.

Most FOSS software simply compile out code not supported by system X
and rely on error handling in the underlying layer and propagate the
error number, message in the upper layer.


> Maybe a "not supported" standard exception
> would be a nice thing to handle system dependencies.


Maybe I fail to understand what you want to achieve, Cygwin do not
report an error that OCaml propagate if you use an unsupported flag
with open() ?

Regards,

Soegtrop, Michael

unread,
May 7, 2016, 12:29:57 PM5/7/16
to Jérôme Benoit, Yaron Minsky, caml...@inria.fr, ocaml...@googlegroups.com
Dear Jérôme,

it is easy to detect with preprocessor defines if O_ASYNC is supported or not on the C level. I wondered what would be the most appropriate way to inform OCaml of the situation. I guess I should just call caml_failwith("O_ASYNC not supported by Cygwin") in the async function on cygwin? Maybe a "not supported" standard exception would be a nice thing to handle system dependencies.

Soegtrop, Michael

unread,
May 9, 2016, 7:41:57 AM5/9/16
to Jérôme Benoit, Yaron Minsky, caml...@inria.fr, ocaml...@googlegroups.com
Dear Jérôme,

> Maybe I fail to understand what you want to achieve, Cygwin do not report
> an error that OCaml propagate if you use an unsupported flag with open() ?

the issue is that the O_ASYNC flag isn't even defined in the Cygwin headers, so I can't simply pass an unsupported flag and wait for open to flag it. I could invent a value for the flag, but I am not sure if this is a good idea. So I thought the cleanest way is to raise an exception in the function which returns the value of the flag.
Reply all
Reply to author
Forward
0 new messages