PyAPI: add PyList_APPEND

This appends while giving ownership to the list, avoiding temp assignment.
This matches PyList_SET_ITEM which bypasses refcount's

Note, this also reduce code-size, Py_DECREF is a rather heavy macro.
This commit is contained in:
2015-01-06 17:39:47 +11:00
parent 9fd569a654
commit bf0c8e116d
7 changed files with 30 additions and 64 deletions

View File

@@ -44,6 +44,14 @@ extern "C" {
* use sparingly to avoid comma operator or temp var assignment */
BLI_INLINE PyObject *Py_INCREF_RET(PyObject *op) { Py_INCREF(op); return op; }
/* append & transfer ownership to the list, avoids inline Py_DECREF all over (which is quite a large macro) */
BLI_INLINE int PyList_APPEND(PyObject *op, PyObject *v)
{
int ret = PyList_Append(op, v);
Py_DecRef(v);
return ret;
}
#ifdef __cplusplus
}
#endif