On Wed, Apr 18, 2012 at 5:01 PM, David Malcolm <dmalc...@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: > > http://gcc-python-plugin.readthedocs.org/en/latest/cpychecker.html#marking-functions-that-steal-references-to-their-arguments > so you can write declarations like these: > > extern void bar(int i, PyObject *obj, int j, PyObject *other) > CPYCHECKER_STEALS_REFERENCE_TO_ARG(2) > CPYCHECKER_STEALS_REFERENCE_TO_ARG(4); > > There's a similar attribute for functions that return borrowed > references: > > PyObject *foo(void) > CPYCHECKER_RETURNS_BORROWED_REF; > > 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. -gps > > Hope this is helpful > Dave > > _______________________________________________ > Python-Dev mailing list > Python-Dev@python.org > http://mail.python.org/mailman/listinfo/python-dev > Unsubscribe: > http://mail.python.org/mailman/options/python-dev/greg%40krypto.org >
_______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com