[ocaml-ctypes] Finalising data

Jeremy Yallop yallop at gmail.com
Mon May 19 15:52:29 BST 2014


Dear Florian,

On 19/05/2014, Florian Pichlmeier <florian.pichlmeier at mytum.de> wrote:
> But now i have encountered a new problem.
> Zeromq uses incomplete types for many data types,
> like the frame type
> typedef struct _zframe_t zframe_t;
>
> On the OCaml side i use void pointer to represent
> these data types, and thats where the problem arose.
>
> The frame destroy function call for example is that
>     zframe_destroy (zframe_t **self_p);
> with the corresponding ocaml function
>
> let destroy (msg : t) =
> let stub = foreign "zframe_destroy" (ptr void @-> returning int) in
> stub (msg +@ 0)
>
> The problem is the msg +@ 0 part.

The ctypes equivalent of zeromq's incomplete struct declaration is a
call to the 'structure' function without a corresponding call to
'seal'.  For example, you can represent zframe_t as follows:

    (* struct _zframe_t *)
    let zframe_t = structure "_zframe_t"

This allows you to give a more precise type to the zframe_destroy binding:

    let zframe_destroy = foreign "zframe_destroy"
        (ptr (ptr zframe_t) @-> returning int)

Although 'zframe_t' is incomplete, 'ptr zframe_t' (i.e. zframe_t*) is
complete, so pointer arithmetic (with +@ etc.) should work as you
expect.

I hope that helps,

Jeremy.


More information about the Ctypes mailing list