[Python-Dev] Highlighting reference-stealing APIs [was Re: cpython: Fix email post-commit review comments.]
Gregory P. Smith
greg at krypto.org
Thu Apr 19 03:04:07 CEST 2012
On Wed, Apr 18, 2012 at 5:01 PM, David Malcolm <dmalcolm at redhat.com> wrote:
> On Thu, 2012-04-19 at 10:48 +1200, Greg Ewing wrote:
> > Antoine Pitrou wrote:
> > > (and here we see why reference-stealing APIs are a nuisance: because
> > > you never know in advance whether a function will steal a reference or
> > > not, and you have to read the docs for each and every C API call you
> > > make)
> > Fortunately, they're very rare, so you don't encounter
> > them often.
> > Unfortunately, they're very rare, so you're all the more
> > likely to forget about them and get bitten.
> > Functions with ref-stealing APIs really ought to have
> > a naming convention that makes them stand out and remind
> > you to consult the documentation.
> FWIW my refcount static analyzer adds various new compile-time
> attributes to gcc:
> so you can write declarations like these:
> extern void bar(int i, PyObject *obj, int j, PyObject *other)
> There's a similar attribute for functions that return borrowed
> PyObject *foo(void)
> Perhaps we should add such attributes to the headers for Python 3.3?
> (perhaps with a different naming convention?)
+1 Adding these annotations and setting up a buildbot that builds using
cpychecker would be a great.
> Hope this is helpful
> Python-Dev mailing list
> Python-Dev at python.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-Dev