diff options
author | Campbell Barton <ideasman42@gmail.com> | 2015-01-06 08:42:22 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2015-01-06 11:09:11 +0300 |
commit | 9fd569a654ded46901c7f20c5fe080972cbb10d2 (patch) | |
tree | 933b893aeaa0a8bffe230933523512340dfa016d /source/blender/python/generic/py_capi_utils.c | |
parent | ee58d449455df9470c4a0a902056b8c2001128bf (diff) |
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.
Diffstat (limited to 'source/blender/python/generic/py_capi_utils.c')
-rw-r--r-- | source/blender/python/generic/py_capi_utils.c | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/source/blender/python/generic/py_capi_utils.c b/source/blender/python/generic/py_capi_utils.c index 26deaf8d033..92ac82508e5 100644 --- a/source/blender/python/generic/py_capi_utils.c +++ b/source/blender/python/generic/py_capi_utils.c @@ -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; } |