[pypy-dev] offtopic, ontopic, ...
Amaury Forgeot d'Arc
amauryfa at gmail.com
Tue Feb 14 18:45:01 CET 2012
2012/2/14 Stefan Behnel <stefan_ml at behnel.de>
> 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
modules,
which are interfaces to the openssl and expat libraries.
And it does that by generating C code that calls the corresponding
functions.
See for example the code for SSLObject.write():
https://bitbucket.org/pypy/pypy/src/default/pypy/module/_ssl/interp_ssl.py#cl-157
it calls the C function SSL_write(), which is declared like this:
https://bitbucket.org/pypy/pypy/src/default/pypy/rlib/ropenssl.py#cl-255
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.
A C API is not the only way to interface with C libraries.
--
Amaury Forgeot d'Arc
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/pypy-dev/attachments/20120214/c7f2cad7/attachment.html>
More information about the pypy-dev
mailing list