<br><div class="gmail_quote">On Tue, Aug 30, 2011 at 10:05 AM, Guido van Rossum <span dir="ltr"><<a href="mailto:guido@python.org">guido@python.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div class="im">On Tue, Aug 30, 2011 at 9:49 AM, "Martin v. Löwis" <<a href="mailto:martin@v.loewis.de">martin@v.loewis.de</a>> wrote:<br>
</div>
The problem lies with the PyPy backend -- there it generates ctypes<br>
code, which means that the signature you declare to Cython/Pyrex must<br>
match the *linker* level API, not the C compiler level API. Thus, if<br>
in a system header a certain function is really a macro that invokes<br>
another function with a permuted or augmented argument list, you'd<br>
have to know what that macro does. I also don't see how this would<br>
work for #defined constants: where does Cython/Pyrex get their value?<br>
ctypes doesn't have their values.<br>
<br>
So, for PyPy, a solution based on Cython/Pyrex has many of the same<br>
downsides as one based on ctypes where it comes to complying with an<br>
API defined by a .h file.<br></blockquote><div><br>It's certainly a harder problem.<br><br>For most simple constants, Cython/Pyrex might be able to generate a series of tiny C programs with which to find CPP symbol values:<br>
<br>#include "file1.h"<br>...<br>#include "filen.h" <br><br>main()<br>{<br>printf("%d", POSSIBLE_CPP_SYMBOL1);<br>}<br><br>...and again with %f, %s, etc. The typing is quite a mess, and code fragments would probably be impractical. But since the C Preprocessor is supposedly turing complete, maybe there's a pleasant surprise waiting there.<br>
<br>But hopefully clang has something that'd make this easier.<br><br>SIP's approach of using something close to, but not identical to, the .h's sounds like it might be pretty productive - especially if the derivative of the .h's could be automatically derived using a python script, with minor tweaks to the inputs on .h upgrades. But sip itself is apparently C++-only.<br>
<br><br></div></div>