[MLton-user] bug report, FFI of mlton-20070826

Katsuhiro Ueno katsu at riec.tohoku.ac.jp
Fri Aug 31 07:31:37 PDT 2007


Hello,

I found a problem about FFI of the latest MLton.

Exporting an ML function which returns "char" causes linker error.
For example:

val e = _export "f" : (unit -> char) -> unit;
val _ = e (fn () => #"a")

Compiling this code goes well, but linking will be aborted by
"undefined symbols" error (I am on x86-darwin):

$ mlton -default-ann 'allowFFI true' test.sml
/usr/bin/ld: Undefined symbols:
_MLton_FFI_Int8
collect2: ld returned 1 exit status
call to system failed with exit status 1:
gcc -o a /tmp/filegdbAmA.o /tmp/fileAZL4LJ.o
-L/usr/local/lib/mlton/self -lmlton -lgdtoa -lm -lgmp -L/sw/lib


I think this error is due to that correspondance of FFI types is
different between compiler and basis library.

Here is my ad-hoc fix.

--- mlton/elaborate/elaborate-core.fun	(revision 5976)
+++ mlton/elaborate/elaborate-core.fun	(working copy)
@@ -752,7 +752,9 @@
                      let
                         open CType
                      in
-                        [Word8, Word16, Word32]
+                        (* According to basis-library/mlton/ffi.fun,
+                         * to the C-world, chars are signed integers. *)
+                        [Int8, Int16, Int32]
                      end)
             @ sized (Tycon.int o IntSiz



More information about the MLton-user mailing list