ocamllabs/ocaml-ctypes — pull request #144 by yallop (2014-04-18 10:39:55+00:00)
Title: Stub-generation specific tests

Stub generation makes it possible to bind to functions with types that Foreign doesn't currently support. This pull request adds tests for some of these features.

* Calling variadic functions (e3a2493)

Since functions like [sprintf][sprintf] have dependent types (where the types of later arguments depend on the value of the format string) it's difficult to bind to them in a type safe way from OCaml. Stub generation doesn't solve this in full generality, but it does make it straightforward to bind to particular instantiations of the functions and have the generated calls checked against the function prototypes.

* Passing complex numbers (4e5cf35), unions (9793fa5), structs with union members (929346d), and structs with array members (c128af6) by value.

The [Foreign][foreign] module for binding functions dynamically is implemented using [libffi][libffi], which doesn't currently support passing certain types by value. Stub generation makes it possible to pass values of whatever types the C compiler supports.

[sprintf]: http://linux.die.net/man/3/sprintf
[libffi]: https://github.com/atgreen/libffi
[foreign]: http://ocamllabs.github.io/ocaml-ctypes/Foreign.html