<br><div class="gmail_quote">On Tue, Aug 30, 2011 at 10:05 AM, Guido van Rossum <span dir="ltr">&lt;<a href="mailto:guido@python.org">guido@python.org</a>&gt;</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, &quot;Martin v. Löwis&quot; &lt;<a href="mailto:martin@v.loewis.de">martin@v.loewis.de</a>&gt; 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&#39;d<br>
have to know what that macro does. I also don&#39;t see how this would<br>
work for #defined constants: where does Cython/Pyrex get their value?<br>
ctypes doesn&#39;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&#39;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 &quot;file1.h&quot;<br>...<br>#include &quot;filen.h&quot; <br><br>main()<br>{<br>printf(&quot;%d&quot;, 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&#39;s a pleasant surprise waiting there.<br>
<br>But hopefully clang has something that&#39;d make this easier.<br><br>SIP&#39;s approach of using something close to, but not identical to, the .h&#39;s sounds like it might be pretty productive - especially if the derivative of the .h&#39;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>