当我从PyObject *
获得PyArg_ParseTuple
时,在从函数返回之前,是否需要确保Py_DECREF
?
示例:
static PyObject * modulefunc(PyObject * self, PyObject * args) {
PyObject * obj;
if (!PyArg_ParseTuple(args, "O", &obj)) {
return NULL;
}
if (!PyObject_TypeCheck(obj, expected_type_ptr)) {
// Do I need to Py_DECREF(obj) here?
PyErr_SetString(PyExc_TypeError, "First argument is not expected type.");
return NULL;
}
// ... rest of function implementation.
}