[MLton-user] FFI questions
Matthew Fluet
fluet@cs.cornell.edu
Mon, 25 Jul 2005 11:24:33 -0400 (EDT)
> Are there MLton types matching long and size_t? Currently, it seems
> that MLton is 32-bit only, but this might change in the future. So
> using Int32 and Word32 seems unwise.
Using Int<N> and Word<N> is currently your best (and only) option. The
number of bits used to represent a C long and a C size_t is platform
dependent, so you'll need to determine the right number of bits for your
platform and using the corresponding Int/Word structure.
In the future, I think the right design will be to introduce a new ML
Basis System library for FFI related structures. I believe that we will
be able to set up this library so that it provides something like:
signature CTYPES =
struct
SChar : INTEGER
UChar : WORD
SInt : INTEGER
UInt : WORD
SLong : INTEGER
ULong : WORD
SLongLong : INTEGER
ULongLong : WORD
SizeT : WORD
...
end
and these would be bound to appropriate Int<N>/Word<N> structures
depending upon the target platform.
> I'm interfacing a library which stores pointers to char arrays, and
> it's the task of the application to ensure that the arrays are not
> freed while the library is still using them. Is there an easy way to
> prevent MLton from freeing a string? Or should I use malloc and
> memcpy, and manage memory by hand?
There is currently no way to pin ML objects with the current version of
MLton; so your only immediate option will be to manage the memory by hand.
On the MLton development list, there has been a recent discussion on how
to provide this functionality:
http://mlton.org/pipermail/mlton/2005-July/027461.html
However, nothing has been implemented yet.