Py_INCREF / DECREF not needed in simple C functions?

Fredrik Lundh fredrik at pythonware.com
Fri Mar 2 02:58:01 EST 2001


Owen F. Ransen wrote:
> Thanks for the tip, so I should do this:
>
> static PyObject* Py_ReallyWildFunc (PyObject *self, PyObject *args)
> {
>     double x,y,z ;
>     if (!PyArg_ParseTuple(args, "ddd",&x,&y,&z)) {
>         return (NULL) ;
>     }
>
>     ...do some really wild stuff with x,y,z...
>
>     Py_INCREF (Py_None) ;
>     return (Py_None) ;
> }

correct.

(at least if you need to call your function more than
sys.getrefcount(None) times ;-)

your function "borrows" argument references, but are expected
to return new references.  see:

    http://www.python.org/doc/current/ext/ownershipRules.html

Cheers /F

<!-- (the eff-bot guide to) the standard python library:
http://www.pythonware.com/people/fredrik/librarybook.htm
-->





More information about the Python-list mailing list