Replies: 3 comments
-
I'd just like to make a note here regarding using CIL for this purpose: I have found that using CIL to parse a pre-processed header file on OSX fails due to the OSX standard library containing functions using block pointers. I have been trying to auto-generate the Ctypes binding code for enums but ran into the above issue. I could generate a header file which has been preprocessed using:
this then does not include the function prototypes using block pointers but the resulting file will not contain types (e.g. bool or size_t) from the standard library and CIL will again complain that it can't parse the processed file: I can't see an option to get CIL to ignore this and just give me the parse tree. I have hacked around this by adding typedefs containing bool, size_t, unint64_t to the processed header file by hand, which CIL can then parse, but this is a not a nice way of solving the problem. |
Beta Was this translation helpful? Give feedback.
-
It may be that using clang (via clang-ocaml?) is a better option than CIL. |
Beta Was this translation helpful? Give feedback.
-
There's a start on a CIL-based bindings generator here. |
Beta Was this translation helpful? Give feedback.
-
Just keeping this issue to remind myself that I started working on a simple CIL -> Ctypes transformer that got this far in 10 minutes:
which outputs from the C header file:
A bit more work and that could turn into a Ctypes call, and we could have a camlp4 extension that lets you write "#include <ncurses.h>" and automatically import in type-safe OCaml calls. A ppx equivalent should also be straightforward with an extension_point.
Beta Was this translation helpful? Give feedback.
All reactions