[MLton] cvs commit: Improved FFI.
Wesley W. Terpstra
wesley@terpstra.ca
Sun, 24 Jul 2005 15:40:20 +0200
On Sat, Jul 23, 2005 at 04:55:44AM -0700, Matthew Fluet wrote:
> Incorporated Wesley's patch for improved FFI. After the discussion on
> the list regarding C pointers, I went ahead and eliminated _address
> infavor of _symbol, which provides the address, getter, and setter.
> So, the FFI system now looks like:
>
> _symbol "symbol" [define] : ptrTy, cbTy; ==> ptrTy * (unit -> cbTy) * (cbTy -> unit)
> _symbol * : ptrTy, cbTy; ==> (ptrTy -> cbTy) * (ptrTy * cbTy -> unit)
I think this was a mistake.
There is now no way to take the address of a function.
Which means you can't pass a MLton function to a C method that takes
a function pointer. I'm sorry I didn't object earlier; I had no net
access...
I realize that you could lie:
val () = _export "foo": int -> int; (fn x => x)
val ptr = #1 _symbol "foo": MLton.Pointer.t, int;
However, I think this is worse than not having a type with address
in the first place. I added it so we could encourage people to
provide the extra information against future problems. The new API
encourages people to provide wrong information...
--
Wesley W. Terpstra