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/bmesh | |
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/bmesh')
-rw-r--r-- | source/blender/python/bmesh/bmesh_py_ops_call.c | 12 | ||||
-rw-r--r-- | source/blender/python/bmesh/bmesh_py_types_customdata.c | 8 | ||||
-rw-r--r-- | source/blender/python/bmesh/bmesh_py_types_meshdata.c | 11 | ||||
-rw-r--r-- | source/blender/python/bmesh/bmesh_py_utils.c | 12 |
4 files changed, 26 insertions, 17 deletions
diff --git a/source/blender/python/bmesh/bmesh_py_ops_call.c b/source/blender/python/bmesh/bmesh_py_ops_call.c index e8ef4c58895..84c1031a24a 100644 --- a/source/blender/python/bmesh/bmesh_py_ops_call.c +++ b/source/blender/python/bmesh/bmesh_py_ops_call.c @@ -43,6 +43,8 @@ #include "bmesh_py_types.h" +#include "../generic/python_utildefines.h" + static int bpy_bm_op_as_py_error(BMesh *bm) { if (BMO_error_occurred(bm)) { @@ -547,13 +549,13 @@ static PyObject *bpy_slot_to_py(BMesh *bm, BMOpSlot *slot) break; case BMO_OP_SLOT_PTR: BLI_assert(0); /* currently we don't have any pointer return values in use */ - item = (Py_INCREF(Py_None), Py_None); + item = Py_INCREF_RET(Py_None); break; case BMO_OP_SLOT_ELEMENT_BUF: { if (slot->slot_subtype.elem & BMO_OP_SLOT_SUBTYPE_ELEM_IS_SINGLE) { BMHeader *ele = BMO_slot_buffer_get_single(slot); - item = ele ? BPy_BMElem_CreatePyObject(bm, ele) : (Py_INCREF(Py_None), Py_None); + item = ele ? BPy_BMElem_CreatePyObject(bm, ele) : Py_INCREF_RET(Py_None); } else { const int size = slot->len; @@ -664,7 +666,7 @@ static PyObject *bpy_slot_to_py(BMesh *bm, BMOpSlot *slot) } case BMO_OP_SLOT_SUBTYPE_MAP_INTERNAL: /* can't convert from these */ - item = (Py_INCREF(Py_None), Py_None); + item = Py_INCREF_RET(Py_None); break; } break; @@ -743,7 +745,7 @@ PyObject *BPy_BMO_call(BPy_BMeshOpFunc *self, PyObject *args, PyObject *kw) ret = NULL; /* exception raised above */ } else if (bmop.slots_out[0].slot_name == NULL) { - ret = (Py_INCREF(Py_None), Py_None); + ret = Py_INCREF_RET(Py_None); } else { /* build return value */ @@ -759,7 +761,7 @@ PyObject *BPy_BMO_call(BPy_BMeshOpFunc *self, PyObject *args, PyObject *kw) /* this function doesn't throw exceptions */ item = bpy_slot_to_py(bm, slot); if (item == NULL) { - item = (Py_INCREF(Py_None), Py_None); + item = Py_INCREF_RET(Py_None); } #if 1 diff --git a/source/blender/python/bmesh/bmesh_py_types_customdata.c b/source/blender/python/bmesh/bmesh_py_types_customdata.c index 3c1502dc72b..bfcd91ac72d 100644 --- a/source/blender/python/bmesh/bmesh_py_types_customdata.c +++ b/source/blender/python/bmesh/bmesh_py_types_customdata.c @@ -42,6 +42,7 @@ #include "bmesh_py_types_meshdata.h" #include "../mathutils/mathutils.h" +#include "../generic/python_utildefines.h" #include "BKE_customdata.h" @@ -483,8 +484,9 @@ static PyObject *bpy_bmlayercollection_items(BPy_BMLayerCollection *self) for (i = 0; tot-- > 0; index++) { item = PyTuple_New(2); - PyTuple_SET_ITEM(item, 0, PyUnicode_FromString(data->layers[index].name)); - PyTuple_SET_ITEM(item, 1, BPy_BMLayerItem_CreatePyObject(self->bm, self->htype, self->type, index)); + PyTuple_SET_ITEMS(item, + PyUnicode_FromString(data->layers[index].name), + BPy_BMLayerItem_CreatePyObject(self->bm, self->htype, self->type, index)); PyList_SET_ITEM(ret, i++, item); } @@ -559,7 +561,7 @@ static PyObject *bpy_bmlayercollection_get(BPy_BMLayerCollection *self, PyObject } } - return Py_INCREF(def), def; + return Py_INCREF_RET(def); } static struct PyMethodDef bpy_bmlayeritem_methods[] = { diff --git a/source/blender/python/bmesh/bmesh_py_types_meshdata.c b/source/blender/python/bmesh/bmesh_py_types_meshdata.c index df0c39fd3b3..94f38ffdec7 100644 --- a/source/blender/python/bmesh/bmesh_py_types_meshdata.c +++ b/source/blender/python/bmesh/bmesh_py_types_meshdata.c @@ -45,6 +45,8 @@ #include "bmesh_py_types_meshdata.h" +#include "../generic/python_utildefines.h" + /* Mesh BMTexPoly * ************** */ @@ -684,10 +686,9 @@ static PyObject *bpy_bmdeformvert_items(BPy_BMDeformVert *self) ret = PyList_New(self->data->totweight); for (i = 0; i < self->data->totweight; i++, dw++) { item = PyTuple_New(2); - - PyTuple_SET_ITEM(item, 0, PyLong_FromLong(dw->def_nr)); - PyTuple_SET_ITEM(item, 1, PyFloat_FromDouble(dw->weight)); - + PyTuple_SET_ITEMS(item, + PyLong_FromLong(dw->def_nr), + PyFloat_FromDouble(dw->weight)); PyList_SET_ITEM(ret, i, item); } @@ -721,7 +722,7 @@ static PyObject *bpy_bmdeformvert_get(BPy_BMDeformVert *self, PyObject *args) return PyFloat_FromDouble(dw->weight); } else { - return Py_INCREF(def), def; + return Py_INCREF_RET(def); } } } diff --git a/source/blender/python/bmesh/bmesh_py_utils.c b/source/blender/python/bmesh/bmesh_py_utils.c index 7088036245a..0b667ab9029 100644 --- a/source/blender/python/bmesh/bmesh_py_utils.c +++ b/source/blender/python/bmesh/bmesh_py_utils.c @@ -42,6 +42,8 @@ #include "bmesh_py_types.h" #include "bmesh_py_utils.h" /* own include */ +#include "../generic/python_utildefines.h" + PyDoc_STRVAR(bpy_bm_utils_vert_collapse_edge_doc, ".. method:: vert_collapse_edge(vert, edge)\n" @@ -365,8 +367,9 @@ static PyObject *bpy_bm_utils_edge_split(PyObject *UNUSED(self), PyObject *args) if (v_new && e_new) { PyObject *ret = PyTuple_New(2); - PyTuple_SET_ITEM(ret, 0, BPy_BMEdge_CreatePyObject(bm, e_new)); - PyTuple_SET_ITEM(ret, 1, BPy_BMVert_CreatePyObject(bm, v_new)); + PyTuple_SET_ITEMS(ret, + BPy_BMEdge_CreatePyObject(bm, e_new), + BPy_BMVert_CreatePyObject(bm, v_new)); return ret; } else { @@ -524,8 +527,9 @@ static PyObject *bpy_bm_utils_face_split(PyObject *UNUSED(self), PyObject *args, if (f_new && l_new) { PyObject *ret = PyTuple_New(2); - PyTuple_SET_ITEM(ret, 0, BPy_BMFace_CreatePyObject(bm, f_new)); - PyTuple_SET_ITEM(ret, 1, BPy_BMLoop_CreatePyObject(bm, l_new)); + PyTuple_SET_ITEMS(ret, + BPy_BMFace_CreatePyObject(bm, f_new), + BPy_BMLoop_CreatePyObject(bm, l_new)); return ret; } else { |