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

@@ -37,6 +37,8 @@
#include "py_capi_utils.h"
#include "../generic/python_utildefines.h"
/* only for BLI_strncpy_wchar_from_utf8, should replace with py funcs but too late in release now */
#include "BLI_string_utf8.h"
@@ -178,6 +180,17 @@ void PyC_Tuple_Fill(PyObject *tuple, PyObject *value)
}
}
void PyC_List_Fill(PyObject *list, PyObject *value)
{
unsigned int tot = PyList_GET_SIZE(list);
unsigned int i;
for (i = 0; i < tot; i++) {
PyList_SET_ITEM(list, i, value);
Py_INCREF(value);
}
}
/* for debugging */
void PyC_ObSpit(const char *name, PyObject *var)
{
@@ -664,8 +677,7 @@ void PyC_RunQuicky(const char *filepath, int n, ...)
PyErr_Print();
PyErr_Clear();
PyList_SET_ITEM(values, i, Py_None); /* hold user */
Py_INCREF(Py_None);
PyList_SET_ITEM(values, i, Py_INCREF_RET(Py_None)); /* hold user */
sizes[i] = 0;
}