[MLton-user] SVN r6941 MLton/MinGW32 and FFI

Dan DuVarney duvarney at reactive-systems.com
Tue Nov 11 06:41:43 PST 2008


Thanks for the pointer to the LibrarySupport documenation page. It was
quite useful. I discovered the problem with the distributed ffi
examples. They are  missing symbol scopes which cause link-time errors
on MinGW32. It looks like the default scope is "external." When I added
"public" scopes to import.sml (see below), I was able to get "import" to
compile and run. Someone might want to check to see if this is a problem
on other OSes, as I don't have access to a linux machine. If I can get
SVN access, I'd be happy to check-in the updated example code (although
I'm unsure of the effect of changing the scope to "public" on other OSes).

One question occurs to me. Is there a compiler option to change the
default scope of foreign functions and data? That could also be used to
get this example to work.

-Dan

--------------------------------- import.sml
-----------------------------------------
(* main.sml *)

(* Declare ffi to be implemented by calling the C function ffi. *)
val ffi = _import "ffi" public: real array * int ref * char ref * int ->
char;
open Array

val size = 10
val a = tabulate (size, fn i => real i)
val ri = ref 0
val rc = ref #"0"
val n = 17

(* Call the C function *)
val c = ffi (a, ri, rc, n)

val (nGet, nSet) = _symbol "FFI_INT" public: (unit -> int) * (int -> unit);

val _ = print (concat [Int.toString (nGet ()), "\n"])

val _ =
   print (if c = #"c" andalso !ri = 45 andalso !rc = c
             then "success\n"
          else "fail\n")


-- 
Dan DuVarney
Senior Software Engineer         Reactive Systems Inc.
duvarney at reactive-systems.com    +1 (919) 324-3507 ext. 103
OpenPGP (GnuPG) public key file:
http://www.reactive-systems.com/~duvarney/pgp_public_key.txt




More information about the MLton-user mailing list