Sarvi Shanmugham, 16.09.2012 02:16:
> Some one on this alias suggested cffi as a better option to create python
> wrappers to C libraries.
>
> I have been trying it and it is awesome. So far the best approach, by far,
> to generating a python wrapper around a C shared library.
Well, it's not really all that different from Cython code, just slower (in
CPython) and without support for C++. All that it really gives you is
in-place declarations for external C APIs and C function signatures that
you can copy over from C header files directly. In Cython, you'll have to
adapt some of them to Cython syntax first.
> But I still like Cython performance for optimizing/compiling much of my
> python code where needed.
>
> Hence the question, Does Cython play well with CFFI??
Yes, in the sense that both don't interfere.
> Can Cython compile the CFFI and CFFI wrapper code, and Can Compiled Cython
> code invoke the CFFI wrapper directly??
Short answer: if you implement that, then yes. There isn't a technical
problem, it just has to be done. Look at the discussions on the core
developer mailing list regarding fast function dispatch and also CEP 1000.
http://wiki.cython.org/enhancements/cep1000
You may want to ask on the cython-dev list regarding its current status.
Stefan
On Monday 17 Sep 2012 12:51:48 Robert Bradshaw wrote:
> Looks like cffi uses http://code.google.com/p/pycparser/ . I really
> don't think it'd be that hard to write something that translates
> (most) C headers into pxd headers, and C++ provided a suitable parsing
> library. I haven't had time to do it myself, so I guess I shouldn't be
> surprised no one else has either...
There is Enthought's cwrap utility: https://github.com/enthought/cwrap/
It looks a little neglected, esp. wrt. docs, but I'm sure it was made just for this. The setup.py's description:-
"Automatical generate Cython wrappers from C header files"
KR,
Alex