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:
Campbell Barton
2015-01-06 16:42:22 +11:00
parent ee58d44945
commit 9fd569a654
27 changed files with 253 additions and 118 deletions

View File

@@ -32,6 +32,8 @@
#include "BLI_math.h"
#include "BLI_utildefines.h"
#include "../generic/python_utildefines.h"
#ifndef MATH_STANDALONE
# include "BLI_string.h"
# include "BLI_dynstr.h"
@@ -1653,10 +1655,10 @@ static PyObject *Matrix_decompose(MatrixObject *self)
mat3_to_quat(quat, rot);
ret = PyTuple_New(3);
PyTuple_SET_ITEM(ret, 0, Vector_CreatePyObject(loc, 3, NULL));
PyTuple_SET_ITEM(ret, 1, Quaternion_CreatePyObject(quat, NULL));
PyTuple_SET_ITEM(ret, 2, Vector_CreatePyObject(size, 3, NULL));
PyTuple_SET_ITEMS(ret,
Vector_CreatePyObject(loc, 3, NULL),
Quaternion_CreatePyObject(quat, NULL),
Vector_CreatePyObject(size, 3, NULL));
return ret;
}
@@ -2032,7 +2034,7 @@ static PyObject *Matrix_richcmpr(PyObject *a, PyObject *b, int op)
return NULL;
}
return Py_INCREF(res), res;
return Py_INCREF_RET(res);
}
/*---------------------SEQUENCE PROTOCOLS------------------------