Py_INCREF / DECREF not needed in simple C functions?

Alex Martelli aleaxit at yahoo.com
Thu Mar 1 10:17:04 EST 2001


"Owen F. Ransen" <ransen_spam_me_not at nemo.it> wrote in message
news:3a9e5301.1251797 at news.newsguy.com...
> Trundling along here and reading the docs I've come
> to the conclusion that if I pass simple values to
> my C extensions to Python I do not need to worry
> about Py_INCREF and Py_DECREF.
>
> Am I right? For example if I only pass, say, 3
> double values to a C extension function, the values
> of which I extract using PyArgs_ParseTuple, then
> I do not need to worry about reference counts?
    [snip]
>     return (Py_None) ;

Actually, you _should_ incref None if you want to
return it -- or, use
    return Py_BuildValue("");
to return None, and then you can keep not worrying:-).


Alex






More information about the Python-list mailing list