[MLton] cvs commit: Loading dynamic libraries works on Darwin

Stephen Weeks sweeks@mlton.org
Tue, 28 Sep 2004 12:46:43 -0700


sweeks      04/09/28 12:46:42

  Modified:    doc/examples/ffi iimport.sml
  Log:
  MAIL Loading dynamic libraries works on Darwin
  
  It works because Darwin has a "dlcompat" compatibility layer built on
  top of their native dyld stuff.  For the iimport.sml test, I needed to
  change the filename of the library.  Also, Darwin doesn't like it if
  you call dlclose on a dynamic library -- it reports the error message
  "dynamic libraries cannot be closed".  So, I disabled dlclose on
  Darwin.
  
  I wonder if we should make the iimport.sml DynLink stuff available in
  the MLton structure.

Revision  Changes    Path
1.3       +14 -6     mlton/doc/examples/ffi/iimport.sml

Index: iimport.sml
===================================================================
RCS file: /cvsroot/mlton/mlton/doc/examples/ffi/iimport.sml,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- iimport.sml	23 Sep 2004 19:36:13 -0000	1.2
+++ iimport.sml	28 Sep 2004 19:46:41 -0000	1.3
@@ -74,15 +74,22 @@
 	 end
 
       val dlclose = fn hndl =>
-	 let
-	    val res = dlclose hndl
-	 in
-	    if res = 0
-	       then ()
+	 if MLton.Platform.OS = MLton.Platform.Darwin
+	    then ()  (* Darwin reports the following error message if you
+		      * try to close a dynamic library.
+		      *   "dynamic libraries cannot be closed"
+		      * So, we disable dlclose on Darwin.
+		      *)
+	 else
+	    let
+	       val res = dlclose hndl
+	    in
+	       if res = 0
+		  then ()
 	       else raise Fail (case dlerror () of
 				   NONE => "???"
 				 | SOME s => s)
-	 end
+	    end
    end
 
 val dll =
@@ -91,6 +98,7 @@
    in
       case host of
 	 Cygwin => "cygwin1.dll"
+       | Darwin => "libm.dylib"
        | _ => "libm.so"
    end