[MLton-user] Feature request: cleaner C pointer support

Matthew Fluet matthew.fluet at gmail.com
Wed Jan 6 07:00:45 PST 2010


On Wed, Dec 30, 2009 at 3:45 PM, John Reppy <jhr at cs.uchicago.edu> wrote:
> I think that the existing support for C pointers (MLton.Pointer) and foreign-interface programming
> could be improved by the addition of a module
>
>        structure C_PtrDiff : INT
>
> to complement the already existing (but undocumented) C_Size WORD structure.

A C_Ptrdiff : INT structure exists, but isn't currently exported by
c-types.mlb.  Would be easy to do so.

> Then, the MLTON_POINTER signature should have the following revisions:
>
>  1) change the type of add to
>
>        val add : t * C_PtrDiff.int -> t
>
>  2) change the type of diff to
>
>        val diff : t * t -> C_PtrDiff.int
>
>  3) remove sub (since it is now redundant)
>
>  4) change the type of sizeofPointer to
>
>        val sizeofPointer : C_Size.word
>
>  5) add the functions
>
>        val toWord : t -> C_Size.word
>        val fromWord : C_Size.word -> t
>
>     (I know that these can be synthesized by add/diff and null pointers, but they are quite useful
>     for FI programming).

No surprise that internally, all of the pointer operations are in
terms of the native pointer size.  We just wrap things in terms of
Basis Library types.

Rather than extending and changing the MLton.Pointer interface (which,
probably shouldn't depend on the c-types.mlb exports), perhaps it
would make sense to duplicate the interface in c-types.mlb as a C_Ptr
structure, which could naturally depend on the other C_* types.



More information about the MLton-user mailing list