[MLton] A few patches we had to apply to port from version 20030716 to 20051202 and for the MinGW port

Matthew Fluet fluet at tti-c.org
Thu Mar 29 12:19:27 PST 2007


Hi Nicolas,

Let me second Wesley's "Thank you!".  I know a number of people are
interested in better MinGW support, and perhaps this will spur some more
development on the MinGW port.

> You'll find enclosed an archive containing a list of .patch files we had to
> apply. Those patches were initially applied to the version 20051202. I have
> adapted them (actually the ones which still make sense) in order to apply
> them to the sources from the amd64 SVN branch (checkout done on the 23rd of
> march).

For those patches being applied at this time, I'm applying them to SVN
trunk, and then merging into the x86_64 branch.

> 1. O.S. version dependent patches  
> 
> - bug-fix-cygwin-1_3_17.patch : 

Not yet applied.

> We want our product to run on old versions of Cygwin. As a consequence, we
> use a cross-compiler which produces code for Cygwin 1.3.17. The current
> version of MLton is not compatible with it for several reasons and this is
> why we had to patch it.
> 
> The patch consists in :
> 
> - providing 2 header files which are required by MLton but are not provided
> with Cygwin 1.3.17 (inttypes.h and stdint.h)

Like Wesley, I'm a little wary of packaging entire header files with the
MLton distribution.  We could consider writing minimal inttypes.h and
stdint.h files that provide just enough functionality.

> - implementing the function nanosleep (same implementation than the one used
> for the MinGW target) which is not available on Cygwin 1.3.17
> 
> - disabling the use of the function "fpclassify" which is broken on Cygwin
> 1.3.17 and causes the expression "real(~1)" to be evaluated as "nan"

I see that these are particularly problematic for the cross-compile
situation.  In particular, the host machine might have these functions,
but they remain as unlinked symbols in the executables, to be
dynamically linked at execution time.  When the executable is moved to
an older Cygwin environment, these functions don't exist (or don't work
correctly).

> - handling the fact that the Cygwin 1.3.17 headers contain some definitions
> related to IPv6 (sockaddr_in6 .) but does not define others
> (sockaddr_storage)
> 
> - defining MSG_CTRUNC and MSG_TRUNC which are not defined in the Cygwin
> 1.3.17 headers

These constants aren't actually used in the Basis Library; they were
included just to match the networking functions documentation.

> - bug-fix-solaris7.patch
> 
> This patch is needed to build the MLton runtime when the gcc compiler is
> designed to produce code for Solaris 7 because the headers do not provide
> the definition for MAP_ANON IPv6. 

Applied.

I'll trust that the value for MAP_ANON actually works on Solaris 7. 
Though, if the value 0x100 is appropriate on Solaris 7, perhaps we 
should be including the proper header.

I also went back and regularized our treatment of missing IPv6 
functionality on the different platforms.

> 2. Unix bug fixes
> 
> - bug-fix-spawn-with-fork.patch
> 
> This patch consists in adding a call to "exit" when the "exec" call fails
> after a successful "fork" in the "spawn" implementation. If we don't do so,
> the current process will be duplicated in case the "exec" fails.

Applied, although I note that the different code paths have different 
behaviors under errors.  That is, on Windows, the parent program will 
get a SysError if the spawn{e,p} fails, while on Unix, the parent 
program will get the pid of the created process (although, the created 
process will immediately terminate).

> 3. Windows (Cygwin and MinGW) bug fixes
> 
> - bug-fix-fullpath-windows.patch
> 
> This patch consists in providing an implementation of fullPath() which works
> on Windows (Cygwin and MinGW). The original implementation only works on
> Unix because it does not handle the volume part of a path.

Partially applied.  I left off the "isLink/NFS" changes, since they 
appeared to be explicitly not related to MinGW.  It would be helpful to 
hear more about the isLink/NFS comment to better understand what is 
going on.

> 4. MinGW bug fixes
> 
> - bug-fix-nethostdb-mingw.patch

Applied.

> - bug-fix-rename-mingw.patch
> 
> This patch fixes the rename() function whose behavior is not the same on
> MinGW than Unix (with MinGW, rename fails when the destination file exists
> whereas the Unix specification is to replace the existing file).

Applied with minor revisions.  This doesn't change the functionality,
but makes it clear that should the unlink fail, we return it's error value.

> - bug-fix-times-mingw.patch
> 
> This patch is designed to avoid raising an exception during the
> initialization of the basis library on MinGW when the code contains calls to
> the "times" function which are not detected as dead code during compilation.
> Then, if the "times" function is called, the exception will be raised from
> the location of the call which is easier to understand from a user's point
> of view.

Applied with minor revisions.

> - bug-fix-closesocket-mingw.patch
> 
> This patch fixes the Socket.close() function on MinGW. On Windows, a socket
> should be closed using the "closesocket" function rather than the "close"
> function.

Applied.

> 5. MinGW evolutions
> 
> - evol-getpid-mingw.patch
> 
> This patch enables the getpid() function which exists on Windows

Not yet applied.  I second Wesley's concerns about mixing pids.  But, I 
will also note that in r4522 
(http://www.mlton.org/pipermail/mlton-commit/2006-May/000522.html), 
Wesley remarked that getpid exists in mingw.

> - evol-poll-mingw.patch
> 
> This patch implements the poll() function on MinGW using the select() call
> (based on code adapted from SML/NJ sources by Mathew Fluet). Then, the SML
> functions poll() and select() will work at least for sockets which is better
> than nothing. There is no miracle, they will still fail when we use them on
> pipe handles.

Not yet applied.  It would perhaps be cleaner to move the implementation 
of poll in terms of select to runtime/platform/mingw.c.

I think the best solution would be to directly implement Socket.select 
in terms of the select system call.

> - evol-stub-mingw-error-message.patch
> 
> This patch updates the error message we get when a non-implemented function
> is executed in order to include the name of the function. It makes it easier
> to port to MinGW.

Applied, with minor changes.

> - evol-waitpid-mingw.patch
> 
> This patch provides a partial implementation of the waitpid() function. It
> makes it easier to port an existing application to MinGW. I would say the
> implementation is not very clean. It uses a linked list which is allocated
> using "malloc" and could be replaced with something else. It also does not
> provide support for waiting on any child which seems to be possible using
> the Windows function WaitForMultipleObjects. Anyway, it remains useful.

Not yet applied.

> 6. Misc
> 
> - evol-dash-in-pathes-cygwin.patch
> 
> This patch is designed to use '/' as the path separator when building a path
> on Cygwin. The idea behind the patch is to use '/' when the path is relative
> or uses the Unix format and to use '\\' when the path is an absolute Windows
> like path.

Not yet applied.  Like Wesley, I'm not sure I understand what the 
desired behavior is.

> - evol-new-bitarray-functions.patch
> 
> We have added a few extensions to the BitArray structure in smlnj-lib.
> Implementing what we needed outside the compiler using the existing public
> signature was not efficient enough. You may want to consider this as a
> PolySpace specific need anyway.

Not applied.  We include the SML/NJ libraries as a convenience to users,
so I don't think it is wise to fork our code from that of SML/NJ.  I
would suggest sending your patch to the SML/NJ developers, and we'll
pick it up if it gets merged into the 'official' SML/NJ library.






More information about the MLton mailing list