[Python-Dev] CFFI released

Stefan Behnel stefan_ml at behnel.de
Tue Jun 19 08:28:37 CEST 2012


Armin Rigo, 18.06.2012 23:29:
> On Mon, Jun 18, 2012 at 9:10 PM, Maciej Fijalkowski wrote:
>>> Make cffi less buggy (check the tracker for new test cases ;-), faster
>>> (closer to swig type wrappers), and easier to use than ctypes, and I am sure
>>> there will be interest.
>>
>> I would say it's already fulfilling those three, but I suppose you should
>> try for yourself.
> 
> I don't think the first is fulfilled so far, as we found various
> issues on various Linux and non-Linux platforms (and fixed them, so I
> suppose that release 0.1.1 is coming soon).  But I agree with Fijal
> about speed and ease of use.  Like SWIG it generates wrappers in the
> form of a CPython C extension with built-in functions, so I suppose
> the performance is similar to SWIG and not ctypes.  Well, SWIG
> wrappers typically have custom logic written in C, whereas in cffi
> this logic is typically written as Python code, so I suppose it ends
> up being slower

Any reason you didn't write the C parts in Cython? Skipping through the
code, it seems like it could benefit, both in terms of code overhead and
performance. For something that heavily relies on Python calls, reducing
the call overhead some more should be quite interesting.

It would also be cool to have Cython integration in the sense that cffi
could generate a .pxd file from the parsed C declarations (and eventually
pass the declarations directly into the compiler), which Cython could use
for its one-the-fly code compilation (similar to what cffi does in the
background, as I understand it) or even in its pure Python mode to allow
for C code interaction (which currently requires Cython syntax).

Both could then support the same interface for C declarations. That would
allow users to start with cffi and then compile the performance critical
parts of their code (e.g. a couple of functions in a Python module) through
Cython without major changes - in some cases, applying the "cython.compile"
decorator could be enough already. Sounds great to me.

Stefan



More information about the Python-Dev mailing list