[MLton] Representation of strings in the FFI

Jens Axel Søgaard jensaxel@soegaard.net
Fri, 29 Apr 2005 00:25:10 +0200


Stephen Weeks wrote:

> Yes, you can use either of these.  Although you could use the same
> trick I just mentioned too, with the drawback that only monomorphic
> values may be exported
> 
> val _ = _export "intArrayLength": int array -> int;
>         Array.length

This approach would be the cleanest. I am a bit worried due to the
GC comment though.

Suppose the C level calls an exported function which returns
an ML array. To get the length the C level calls the export
intArrayLength function. At this point the C level knows the
length - but now it doesn't know whether the array in question
has been moved (or even removed)? Since exported functions
can't return tuples nor pairs, the obvious solution of letting
intArrayLength return a pair of the length and the array won't
work.

Is the location of globals fixed? If so one could use a global
reference cell to keep track of the where abouts of the array.

Copying the array at the C level before calling intArrayLength
is also possible, but is, well, not an optimal solution.

-- 
Jens Axel Søgaard