Py_INCREF / DECREF not needed in simple C functions?

Owen F. Ransen ransen_spam_me_not at nemo.it
Thu Mar 1 10:03:58 EST 2001


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?

Concrete example:

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...

    return (Py_None) ;
}

(I know that in the future I may do more complex things,
 but at the moment I'm concentraing on this simple stuff)
--
Owen F. Ransen
http://www.ransen.com/
Home of Gliftic & Repligator Image Generators



More information about the Python-list mailing list