Hi Sarvi,
On Sat, Aug 25, 2012 at 2:22 AM, Sarvi Shanmugham <
sarv...@gmail.com> wrote:
> I read a bit more, took mylibrary.h and put it through the gcc preprocessor
> Didn't Work. Got a traceback
This is basically why it is not the supported approach. At the
beginning, we considered doing this, which would be nice because you'd
only need to write the "#include <foo.h>".
However, there are a number of problems making the approach fragile.
For example, foo.h might use unsupported C extensions (for example
GCC's). This is true even if foo.h doesn't explicitly *use* them but
just inherits them from #include'ing a standard header. For example,
"#include <stdint.h>" might expand to some type declarations, say
"long long long", which were added recently to GCC. So even though
foo.h doesn't actually use "long long long" and compiles fine on old
GCCs, doing the macro-expansion will try to declare a "long long long"
type and crash, depending on whether the installed stdint.h is from a
recent GCC or not. By contrast, the current approach should work more
robustly: on any system where you'd successfully compile a piece of C
code using the header, it should work in CFFI too.
Another issue is what to do with complex macro declarations. For
example there is no way we can just #include <ncurses.h> and be done,
because it has macros like this:
#define getyx(win,y,x) <some code which writes to both x and y>
which need a bit of custom code to be supported.
This is why we took the current approach. Note that some people have
some early success using large libraries with CFFI by writing large
headers into a local .h file and just doing
ffi.cdef(open('local.h').read()). The point is still that this local
header is not exactly the same as the installed one. You need to go
once through the original .h file manually and copy and fix things,
e.g. replacing too-precise declarations with "...", removing parts,
etc.
A bientôt,
Armin.