<div class="gmail_quote">2012/2/14 Stefan Behnel <span dir="ltr"><<a href="mailto:stefan_ml@behnel.de">stefan_ml@behnel.de</a>></span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div id=":3eo">if PyPy can't come up with a fast way to<br>
interface with C code, it's bound to die.</div></blockquote><div><br></div><div>But it certainly can! For example PyPy implements the _ssl and pyexpat modules,</div><div>which are interfaces to the openssl and expat libraries.</div>
<div>And it does that by generating C code that calls the corresponding functions.</div><div><br></div><div>See for example the code for SSLObject.write():</div><div><a href="https://bitbucket.org/pypy/pypy/src/default/pypy/module/_ssl/interp_ssl.py#cl-157">https://bitbucket.org/pypy/pypy/src/default/pypy/module/_ssl/interp_ssl.py#cl-157</a></div>
<div>it calls the C function SSL_write(), which is declared like this:</div><div><a href="https://bitbucket.org/pypy/pypy/src/default/pypy/rlib/ropenssl.py#cl-255">https://bitbucket.org/pypy/pypy/src/default/pypy/rlib/ropenssl.py#cl-255</a></div>
<div>This kind of code is not difficult to write (in this case, it's a simple translation of</div><div>CPython modules) and is close enough to C when you really need it.</div><div>For example, it's possible to use macros when they look like function calls,</div>
<div>or embed C snippets.</div><div><br></div><div>A C API is not the only way to interface with C libraries.</div><div><br></div></div>-- <br>Amaury Forgeot d'Arc<br>