[MLton] Re: [MLton-commit] r4510

Matthew Fluet fluet@cs.cornell.edu
Wed, 10 May 2006 16:01:13 -0400 (EDT)


>>> Defined all of the SIG and tty constants with #ifndef in the
>>> platform-independent code, so that each platform doesn't have to
>>> define the missing ones.
>>
>> We've now used this technique for the _SC (sysconf) and _PC (pathconf)
>> constants, and the E (errno) constants.  While it is certainly expedient,
>> I'm worried that it masks issues.
>
> Does this mean that application writers must be aware of which
> constants and things from Posix are _really_ there and which ones are
> not actually usable?  This makes writing portable applications hard.

It's no harder (but, unfortunately, no easier) than you have porting 
between any Posix-like system.

On the up side, some of these constants are only there because I found it 
easier to cut-n-paste from the Single UNIX specification.  Not all of them 
are used by the Basis Library (SIGPOLL is such an example).

The _SC and _PC constants are fine -- you need to look up the property by 
giving a string denoting the property.  If the platform provides the 
constant/property, you get back a SOME value; if the platform doesn't, you 
get back a NONE.

My worry is more that someone porting to a new platform won't notice that 
they forgot to add the right include that provides the constants, because 
the runtime will compile (but providing none of the constants).

> I noticed a similar thing with nonblocking socket IO implemented with
> MSG_DONTWAIT.  This flag doesn't exist on Cygwin, MinGW, HP-UX, or
> AIX, it was just #defined to 0 so it was basically ignored.  I though
> it was bad enough so that I fixed it by simulating the flag on
> platforms where it doesn't exist (not committed to svn yet, will be
> included in the AIX patch).  Will there now be dozens of flags which
> may or may not really be available?  Do you think this is a bad thing
> or irrelevant?

I don't think there will be dozens.  It is a bad thing if the flag or 
values are used by the Basis Library to implement higher-level functions, 
like nonblocking socket IO.  It isn't so bad for things like the _SC and 
_PC constants, as we are simply exporting to the user some Posix 
functionality, and not really using it within the Basis Library proper.