[C2hs] c2hs / Language.C feature to discover cdecl / stdcall
Duncan Coutts
duncan.coutts at worc.ox.ac.uk
Thu Apr 2 05:34:00 EDT 2009
It was pointed out to me yesterday that it would be rather useful if
c2hs could automatically work out if the ffi import for a {# call/fun #}
hook should be ccall or stdcall calling convention.
It would be useful because some Windows libs use stdcall. Some,
otherwise portable, libs use ccall on most platforms and stdcall on
Windows. OpenGL is an example of the latter.
In principle this is possible because, in GNU C at least, the calling
convention in indicated in a function __attribute__((__stdcall__)).
So the first job would be for Language.C to keep the __attribute__'s in
the abstract syntax tree. They already get parsed, but at least last
time I looked they were not entered into the AST. The attribute syntax
is pretty uniform so a generic representation in the AST would be fine.
Any code that interpreted the attributes would just have to match on
known string values.
That's the most work. With that done it should be relatively
straightforward for c2hs to inspect the set of attributes to see if it's
got a stdcall attribute and if so generate an appropriate ffi import.
Duncan
More information about the C2hs
mailing list