【发布时间】:2012-04-11 04:00:41
【问题描述】:
当我有一个从PyArg_ParseTuple 获得的PyObject * 时,我是否需要在从函数返回之前确保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.
}
【问题讨论】:
标签: python c python-module python-c-api cpython