PyAPI: add utilities PyTuple_SET_ITEMS, Py_INCREF_RET

Setting all values of a tuple is such a common operation that it deserves its own macro.
Also added Py_INCREF_RET to avoid confusing use of comma operator.
This commit is contained in:
2015-01-06 16:42:22 +11:00
parent ee58d44945
commit 9fd569a654
27 changed files with 253 additions and 118 deletions

View File

@@ -35,6 +35,7 @@
#include "BLI_kdtree.h"
#include "../generic/py_capi_utils.h"
#include "../generic/python_utildefines.h"
#include "mathutils.h"
#include "mathutils_kdtree.h" /* own include */
@@ -58,9 +59,10 @@ static void kdtree_nearest_to_py_tuple(const KDTreeNearest *nearest, PyObject *p
BLI_assert(nearest->index >= 0);
BLI_assert(PyTuple_GET_SIZE(py_retval) == 3);
PyTuple_SET_ITEM(py_retval, 0, Vector_CreatePyObject((float *)nearest->co, 3, NULL));
PyTuple_SET_ITEM(py_retval, 1, PyLong_FromLong(nearest->index));
PyTuple_SET_ITEM(py_retval, 2, PyFloat_FromDouble(nearest->dist));
PyTuple_SET_ITEMS(py_retval,
Vector_CreatePyObject((float *)nearest->co, 3, NULL),
PyLong_FromLong(nearest->index),
PyFloat_FromDouble(nearest->dist));
}
static PyObject *kdtree_nearest_to_py(const KDTreeNearest *nearest)