Strategies for using cffi with C++ code?

Stefan Behnel stefan_ml at behnel.de
Fri May 22 23:58:10 EDT 2015


Skip Montanaro schrieb am 22.05.2015 um 19:15:
> 2015-05-22 12:05 GMT-05:00 Lele Gaifax:
>> Maybe http://docs.cython.org/src/userguide/wrapping_CPlusPlus.html?
> 
> Thanks for the reference, Lele. I was thinking in terms of cffi, but
> this might work as well. (Shouldn't cffi interfaces be the thinnest?)

Thin in what sense? cffi is a generic library (at least on CPython), so the
interface can never be as thin as what a dedicated compiler can generate
for a specific piece of interface code. PyPy's cffi can mitigate this by
applying runtime optimisations, but you can't do that in CPython without
running some kind of native code generator, be it a JIT compiler or a
static compiler. cffi can apply the latter (run a C compiler) to a certain
extent, but then you end up with a dependency on a C compiler at *runtime*.
The term "thin" really doesn't apply to that dependency. And even if you
accept to go down that route, you'd still get better results from runtime
compilation with Cython, as it will additionally optimise your interface
code (and thus make it "thinner").

Being a Cython core developer, I'm certainly a somewhat biased expert, but
using Cython to generate a statically compiled and optimised C++ wrapper is
really your best choice. IMHO, it provides the best results/tradeoffs in
terms of developer effort, runtime performance and overall end user experience.

Stefan





More information about the Python-list mailing list