<br><br><div class="gmail_quote">On Wed, Apr 18, 2012 at 5:01 PM, David Malcolm <span dir="ltr">&lt;<a href="mailto:dmalcolm@redhat.com">dmalcolm@redhat.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

On Thu, 2012-04-19 at 10:48 +1200, Greg Ewing wrote:<br>
&gt; Antoine Pitrou wrote:<br>
&gt;<br>
&gt; &gt; (and here we see why reference-stealing APIs are a nuisance: because<br>
&gt; &gt; you never know in advance whether a function will steal a reference or<br>
&gt; &gt; not, and you have to read the docs for each and every C API call you<br>
&gt; &gt; make)<br>
&gt;<br>
&gt; Fortunately, they&#39;re very rare, so you don&#39;t encounter<br>
&gt; them often.<br>
&gt;<br>
&gt; Unfortunately, they&#39;re very rare, so you&#39;re all the more<br>
&gt; likely to forget about them and get bitten.<br>
&gt;<br>
&gt; Functions with ref-stealing APIs really ought to have<br>
&gt; a naming convention that makes them stand out and remind<br>
&gt; you to consult the documentation.<br>
FWIW my refcount static analyzer adds various new compile-time<br>
attributes to gcc:<br>
<a href="http://gcc-python-plugin.readthedocs.org/en/latest/cpychecker.html#marking-functions-that-steal-references-to-their-arguments" target="_blank">http://gcc-python-plugin.readthedocs.org/en/latest/cpychecker.html#marking-functions-that-steal-references-to-their-arguments</a><br>


so you can write declarations like these:<br>
<br>
extern void bar(int i, PyObject *obj, int j, PyObject *other)<br>
  CPYCHECKER_STEALS_REFERENCE_TO_ARG(2)<br>
  CPYCHECKER_STEALS_REFERENCE_TO_ARG(4);<br>
<br>
There&#39;s a similar attribute for functions that return borrowed<br>
references:<br>
<br>
  PyObject *foo(void)<br>
    CPYCHECKER_RETURNS_BORROWED_REF;<br>
<br>
Perhaps we should add such attributes to the headers for Python 3.3?<br>
(perhaps with a different naming convention?)<br></blockquote><div><br></div><div>+1  Adding these annotations and setting up a buildbot that builds using cpychecker would be a great.</div><div><br></div><div>-gps</div><div>

 </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
Hope this is helpful<br>
Dave<br>
<br>
_______________________________________________<br>
Python-Dev mailing list<br>
<a href="mailto:Python-Dev@python.org">Python-Dev@python.org</a><br>
<a href="http://mail.python.org/mailman/listinfo/python-dev" target="_blank">http://mail.python.org/mailman/listinfo/python-dev</a><br>
Unsubscribe: <a href="http://mail.python.org/mailman/options/python-dev/greg%40krypto.org" target="_blank">http://mail.python.org/mailman/options/python-dev/greg%40krypto.org</a><br>
</blockquote></div><br>