[capi-sig] Does PyObject_SetAttrString am PyArg_Parse steal an object reference?

Robert Steckroth robertsteckroth at gmail.com
Wed Dec 5 20:14:43 CET 2012

In the below example, is there an extra reference to the align object when
the Py_RETURN_NONE IS hit? Also, why do I have to Py_INCREF(s_obj)? If I do
not, I end up with crashes. Is this a bug?

PyObject *s_obj=NULL, *align=NULL;
if ( ! PyArg_ParseTupleAndKeywords(args, kwds, "|OO", kwlist, &s_obj,
&align) )
    return NULL;

if ( s_obj ) Py_XINCREF(s_obj);

if ( align ) { Py_XINCREF(align);
                PyObject_SetAttrString(s_obj, "align", align); }

Bust0ut, Surgemcgee: Systems Engineer ---

More information about the capi-sig mailing list