[pypy-dev] offtopic, ontopic, ...
fijall at gmail.com
Tue Feb 14 19:46:28 CET 2012
On Tue, Feb 14, 2012 at 8:13 PM, Stefan Behnel <stefan_ml at behnel.de> wrote:
> Maciej Fijalkowski, 14.02.2012 19:00:
>> On Tue, Feb 14, 2012 at 7:56 PM, Stefan Behnel wrote:
>>> Amaury Forgeot d'Arc, 14.02.2012 18:45:
>>>> 2012/2/14 Stefan Behnel
>>>>> if PyPy can't come up with a fast way to
>>>>> interface with C code, it's bound to die.
>>>> But it certainly can! For example PyPy implements the _ssl and pyexpat
>>>> which are interfaces to the openssl and expat libraries.
>>>> And it does that by generating C code that calls the corresponding
>>>> See for example the code for SSLObject.write():
>>>> it calls the C function SSL_write(), which is declared like this:
>>>> This kind of code is not difficult to write (in this case, it's a simple
>>>> translation of
>>>> CPython modules) and is close enough to C when you really need it.
>>>> For example, it's possible to use macros when they look like function calls,
>>>> or embed C snippets.
>>> Ok, then I take it that this would be the preferred Python+FFI approach for
>>> interfacing, right? ctypes is out of the loop?
>> Ideally it would be a better FFI than ctypes in my opinion.
> Erm, what do you mean by "ideally"? Would you not consider rffi usable or
> ready enough for being used for this? Do you mean there should be yet
> another FFI?
> Simple questions:
> Is rffi usable in this context or is it not? Does it require RPython code
> to be generated or does it also work with Python code? How do callbacks
> work in rffi? Does rffi provide access to PyPy objects? And how so?
> I don't know all that much about RPython. Would it work to generate RPython
> from Cython? Is there a transformation to map regular Python code down to
> RPython? (e.g. by renaming variables, templating, specialising, etc.)
> pypy-dev mailing list
> pypy-dev at python.org
Rffi is an internal RPython detail, it works before compilation but
only as a testing layer. People should not use it (at least right
now). Maybe it's actually reusable as an API, but needs to be
extracted a bit from pypy in order to work on top of python (it
imports something like 3/4 of pypy source tree). It also only works by
a very hackish layer on top of ctypes and it's surely not efficient.
I imagine something slightly better that does roughly the same but
does not have to be RPython.
More information about the pypy-dev