[ocaml-ctypes] Defines, and Structs with platform-specific fields

Jeremy Yallop yallop at gmail.com
Mon Oct 20 21:46:26 BST 2014


On 20 October 2014 16:28, Trevor Smith <trevorsummerssmith at gmail.com> wrote:
> Jeremy -- I like the functor idea + first class modules: it is elegant.
> However I agree with Daniel's point about maintainability.

Yes, the need to keep things in sync with a potentially changing
implementation is certainly a drawback.

> If I use the allocate w/ a c function that returns the size of the struct I
> will be good to go. Then have ctypes reference public fields

Careful: giving a partial definition of the struct in ctypes will work
well as long as you're dealing with a prefix -- i.e. when the public
fields are all at the beginning of the struct.  That doesn't appear to
be the case with libuv, where public and private fields are sometimes
interleaved.  The other approaches Daniel suggests -- either defining
accessors in C, or treating the struct types as abstract -- should
work well, though.

This discussion is a useful reminder that ctypes really needs support
for retrieving struct layout details from the declared API.  I'll look
at how to add that support later this week and report back.


More information about the Ctypes mailing list