<div dir="ltr">Thank you for your reply Daniel.<div><br></div><div>About the structs: perhaps I have a fundamental misconception about how ctypes works. Libuv functions expect that the caller allocate the memory for the struct. My understanding was that adding fields to the struct in ctypes would affect the memory that struct takes up. Therefore, the different platforms would actually need these separate fields**.</div><div><br></div><div>**Some library maintainers get around this by allocating an area for extension of a fixed size. This is not the case with libuv.</div><div><br></div><div>You are correct though that I don't need to expose many (actually probably none) of the Loop's internal fields.</div><div><br></div><div>Thoughts?</div><div><br></div><div>Trevor<br><br>On Friday, October 17, 2014, Daniel Bünzli <<a href="mailto:daniel.buenzli@erratique.ch" target="_blank">daniel.buenzli@erratique.ch</a>> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Le vendredi, 17 octobre 2014 à 13:35, Trevor Smith a écrit :<br>
> Hello,<br>
><br>
> I am working on a ctypes binding to libuv [<a href="https://github.com/joyent/libuv" target="_blank">https://github.com/joyent/libuv</a>], and I have two questions:<br>
><br>
> 1) Is the recommended way to interact with C-defines the way described in this thread? <a href="http://lists.ocaml.org/pipermail/ctypes/2014-February/000064.html" target="_blank">http://lists.ocaml.org/pipermail/ctypes/2014-February/000064.html</a><br>
I think so. If you want to pattern match you can have a look here:<br>
<br>
<a href="https://github.com/dbuenzli/tsdl/tree/master/support" target="_blank">https://github.com/dbuenzli/tsdl/tree/master/support</a><br>
<a href="https://github.com/dbuenzli/tsdl/blob/master/myocamlbuild.ml#L39" target="_blank">https://github.com/dbuenzli/tsdl/blob/master/myocamlbuild.ml#L39</a><br>
<br>
> 2) What is the recommended way to deal with struct fields that vary depending upon platform?<br>
><br>
> Libuv is a cross platform library, and has platform-specific fields for its structs. For example see the struct uv_loop_s.<br>
I'm not familiar with the API but having a look at:<br>
<br>
<a href="https://github.com/joyent/libuv/blob/v1.0.0-rc1/include/uv.h#L1381" target="_blank">https://github.com/joyent/libuv/blob/v1.0.0-rc1/include/uv.h#L1381</a><br>
<br>
Then I wouldn't bother at all about the private fields, just describe the constant part of the struct (and do you even need to ? It seems only stop_flag is interesting here, you could aswell treat the struct as an abstract data type). Now if really needed I would define C accessors for each private field and raise if the field is not available for the platform and ctypes-bind to these accessors.<br>
<br>
Best,<br>
<br>
Daniel<br>
<br>
<br>
</blockquote></div>
</div>