[MLton-user] calling MLton from MLton via FFI
Christopher Cramer
tsuyoshi at yumegakanau.org
Wed Mar 9 09:36:09 PST 2011
Hi
I need to call some C functions with a pointer to the middle of an array.
The way I have been doing this is to create a function in ML, and export
it, so that I can convert the array to a pointer and then add the offset.
Here is the code I'm using:
val () = let
val gzread = _import "gzread": gzFile * MLton.Pointer.t * word -> int;
in
_export "gzreadoffset" private:
(gzFile * MLton.Pointer.t * word * word -> int) -> unit;
(fn (file, pointer, offset, length) =>
gzread (file, MLton.Pointer.add (pointer, offset), length)
)
end
val gzread = _import "gzreadoffset" private:
gzFile * CharArray.array * word * word -> int;
Is this safe? It previously worked fine, but I am getting a segfault
now and (unless there is a bug in the compiler) this seems to be the only
possible cause. If it's not safe then I will do it in C instead.
Thanks
More information about the MLton-user
mailing list