[pypy-dev] Python FFI

Maciej Fijalkowski fijall at gmail.com
Tue May 15 17:39:54 CEST 2012


On Tue, May 15, 2012 at 5:16 PM, Stefan Behnel <stefan_ml at behnel.de> wrote:

> 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


Hi Stefan.

Cython's pure-python mode requires quite a bit of work to be able to work
and design I think, although feel free to prove me wrong. Most importantly,
it's not only about calls - cython deals with it just fine. I want to be
able to manipulate the resulting data structures and arguments from pure
python and do all of that without compiling anything. This is part one,
however part two is that you need some extra step - you need at the very
least preprocessing that would remove stuff from files that's incorrect
python, if I understood you correctly. This is quite different from what I
have in mind where you don't have to have an extra compile/preprocess step
anywhere.

Cheers,
fijal
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/pypy-dev/attachments/20120515/258d1320/attachment.html>


More information about the pypy-dev mailing list