[pypy-dev] Python FFI
Stefan Behnel
stefan_ml at behnel.de
Tue May 15 17:16:52 CEST 2012
Armin Rigo, 15.05.2012 16:23:
> Fijal and me would like to raise interest among various groups of
> people about building a better ctypes replacement for Python.
> [...]
> The working alternatives nowadays are Cython and ctypes. For Cython
> you have to learn a whole new language; we can argue infinitely about
> preferences, but from my point of view it's mostly just a nicer way to
> write CPython C extensions using --- instead of C --- a custom
> language.
Well, it's basically Python with optional static types, which are mostly
provided in C(-like) notation. I find it surprisingly similar to LuaJIT's
FFI, since you mentioned that anyway.
> Also, because it would parse strings, we can also add support for
> parsing strings in the format of Cython declarations. This would
> still lower the entry barrier, and have the nice effect that the user
> can sometimes copy-and-paste Cython declarations, instead of
> copy-and-pasting carefully chosen pieces of a potentially messy .h
> file full of custom macros (see for example /usr/include/zlib.h). The
> benefit would be that, unlike Cython, he gets to call the declared
> functions directly from his regular Python code.
I assume you are aware of Cython's pure Python mode? It doesn't currently
support calling into C, but that's a matter of doing it, not so much of
researching how it could be done.
Personally, I've always been thinking of Cython as the best FFI that Python
could ever have. Why reinvent the wheel? Do you really think you could come
up with something as powerful as Cython, but substantially simpler?
Stefan
More information about the pypy-dev
mailing list