From e8667421ed4a72ceec9c73b4599e4f7f9b06b346 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 20 Nov 2012 03:29:12 +0000 Subject: bmesh operator api edits, add macros and NULL the buffer if BMO_slot_buffer_alloc()'s len is zero. --- source/blender/python/bmesh/bmesh_py_ops.c | 23 ++++++++++++----------- source/blender/python/bmesh/bmesh_py_types.c | 1 + 2 files changed, 13 insertions(+), 11 deletions(-) (limited to 'source/blender/python/bmesh') diff --git a/source/blender/python/bmesh/bmesh_py_ops.c b/source/blender/python/bmesh/bmesh_py_ops.c index a00e09b00ad..3446209e660 100644 --- a/source/blender/python/bmesh/bmesh_py_ops.c +++ b/source/blender/python/bmesh/bmesh_py_ops.c @@ -147,7 +147,7 @@ static PyObject *pyrna_op_call(BPy_BMeshOpFunc *self, PyObject *args, PyObject * return NULL; } else { - slot->data.i = param; + BMO_SLOT_AS_BOOL(slot) = param; } break; @@ -170,7 +170,7 @@ static PyObject *pyrna_op_call(BPy_BMeshOpFunc *self, PyObject *args, PyObject * return NULL; } else { - slot->data.i = (int)param; + BMO_SLOT_AS_INT(slot) = (int)param; } break; } @@ -184,7 +184,7 @@ static PyObject *pyrna_op_call(BPy_BMeshOpFunc *self, PyObject *args, PyObject * return NULL; } else { - slot->data.f = param; + BMO_SLOT_AS_FLOAT(slot) = param; } break; } @@ -217,7 +217,7 @@ static PyObject *pyrna_op_call(BPy_BMeshOpFunc *self, PyObject *args, PyObject * case BMO_OP_SLOT_VEC: { /* passing slot name here is a bit non-descriptive */ - if (mathutils_array_parse(slot->data.vec, 3, 3, value, slot_name) == -1) { + if (mathutils_array_parse(BMO_SLOT_AS_VECTOR(slot), 3, 3, value, slot_name) == -1) { return NULL; } break; @@ -271,7 +271,7 @@ static PyObject *pyrna_op_call(BPy_BMeshOpFunc *self, PyObject *args, PyObject * i = 0; BM_ITER_BPY_BM_SEQ (ele, &iter, ((BPy_BMElemSeq *)value)) { - ((void **)slot->data.buf)[i] = (void *)ele; + slot->data.buf[i] = ele; i++; } } @@ -339,28 +339,29 @@ static PyObject *pyrna_op_call(BPy_BMeshOpFunc *self, PyObject *args, PyObject * /* keep switch in same order as above */ switch (slot->slot_type) { case BMO_OP_SLOT_BOOL: - item = PyBool_FromLong(slot->data.i); + item = PyBool_FromLong((BMO_SLOT_AS_BOOL(slot))); break; case BMO_OP_SLOT_INT: - item = PyLong_FromSsize_t((Py_ssize_t)slot->data.i); + item = PyLong_FromSsize_t(BMO_SLOT_AS_INT(slot)); break; case BMO_OP_SLOT_FLT: - item = PyFloat_FromDouble((double)slot->data.f); + item = PyFloat_FromDouble((double)BMO_SLOT_AS_FLOAT(slot)); break; case BMO_OP_SLOT_MAT: - item = Matrix_CreatePyObject(slot->data.p, 4, 4, Py_NEW, NULL); + item = Matrix_CreatePyObject((float *)BMO_SLOT_AS_MATRIX(slot), 4, 4, Py_NEW, NULL); break; case BMO_OP_SLOT_VEC: - item = Vector_CreatePyObject(slot->data.vec, slot->len, Py_NEW, NULL); + item = Vector_CreatePyObject(BMO_SLOT_AS_VECTOR(slot), slot->len, Py_NEW, NULL); break; case BMO_OP_SLOT_ELEMENT_BUF: { const int size = slot->len; + void **buffer = BMO_SLOT_AS_BUFFER(slot); int j; item = PyList_New(size); for (j = 0; j < size; j++) { - BMHeader *ele = ((BMHeader **)slot->data.buf)[i]; + BMHeader *ele = buffer[i]; PyList_SET_ITEM(item, j, ele ? BPy_BMElem_CreatePyObject(bm, ele) : (Py_INCREF(Py_None), Py_None)); } break; diff --git a/source/blender/python/bmesh/bmesh_py_types.c b/source/blender/python/bmesh/bmesh_py_types.c index bc62e63cf2f..f98e7c71ec0 100644 --- a/source/blender/python/bmesh/bmesh_py_types.c +++ b/source/blender/python/bmesh/bmesh_py_types.c @@ -3306,6 +3306,7 @@ PyObject *BPy_BMElem_CreatePyObject(BMesh *bm, BMHeader *ele) case BM_LOOP: return BPy_BMLoop_CreatePyObject(bm, (BMLoop *)ele); default: + BLI_assert(0); PyErr_SetString(PyExc_SystemError, "internal error"); return NULL; } -- cgit v1.2.3