[ocaml-ctypes] Abstract 'a typ

Daniel Bünzli daniel.buenzli at erratique.ch
Mon Mar 9 21:37:20 GMT 2015



Le lundi, 9 mars 2015 à 22:14, Thomas Braibant a écrit :

> I do not know what's the preferred way to handle this situation in
> ctypes. I would really like to use `abstract`, but in that particular
> case, I should really not be able to provide the size nor the
> alignement of the struct. I could use void pointers to implement foo
> pointers, but this seem a bit error prone (minor variation: use magic
> to expose `unit ptr typ` as `foo ptr typ` with `foo` a fresh type).

If your bindings are thin you should just use an OCaml abstract type that denotes pointers to void pointers. The only place where you need to be careful is in the bindings themselves but that should be trivial.

For example in tsdl:

https://github.com/dbuenzli/tsdl/blob/bc18d14b1a28af99ebc30b61e303ee5304055d31/src/tsdl.mli#L727
https://github.com/dbuenzli/tsdl/blob/bc18d14b1a28af99ebc30b61e303ee5304055d31/src/tsdl.ml#L1093-L1095

Best,

Daniel




More information about the Ctypes mailing list