diff options
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/python/bmesh/bmesh_py_types.c | 50 | ||||
-rw-r--r-- | source/blender/python/bmesh/bmesh_py_types.h | 18 | ||||
-rw-r--r-- | source/blender/python/bmesh/bmesh_py_types_customdata.c | 2 | ||||
-rw-r--r-- | source/blender/python/bmesh/bmesh_py_types_select.c | 4 | ||||
-rw-r--r-- | source/blender/python/bmesh/bmesh_py_utils.c | 2 |
5 files changed, 50 insertions, 26 deletions
diff --git a/source/blender/python/bmesh/bmesh_py_types.c b/source/blender/python/bmesh/bmesh_py_types.c index c2fa0c00cfc..a31345cd7f5 100644 --- a/source/blender/python/bmesh/bmesh_py_types.c +++ b/source/blender/python/bmesh/bmesh_py_types.c @@ -645,7 +645,7 @@ static int bpy_bmfaceseq_active_set(BPy_BMElem *self, PyObject *value, void *UNU return 0; } else if (BPy_BMFace_Check(value)) { - BPY_BM_CHECK_SOURCE_INT(value, bm, "faces.active = f"); + BPY_BM_CHECK_SOURCE_INT(bm, "faces.active = f", value); bm->act_face = ((BPy_BMFace *)value)->f; return 0; @@ -1411,7 +1411,7 @@ static PyObject *bpy_bmvert_copy_from_face_interp(BPy_BMVert *self, PyObject *ar else { BMesh *bm = self->bm; - BPY_BM_CHECK_SOURCE_OBJ(py_face, bm, "copy_from_face_interp()"); + BPY_BM_CHECK_SOURCE_OBJ(bm, "copy_from_face_interp()", py_face); BM_vert_interp_from_face(bm, self->v, py_face->f); @@ -1557,7 +1557,7 @@ static PyObject *bpy_bmedge_other_vert(BPy_BMEdge *self, BPy_BMVert *value) return NULL; } - BPY_BM_CHECK_SOURCE_OBJ(value, self->bm, "BMEdge.other_vert(vert)"); + BPY_BM_CHECK_SOURCE_OBJ(self->bm, "BMEdge.other_vert(vert)", value); other = BM_edge_other_vert(self->e, value->v); @@ -1614,7 +1614,7 @@ static PyObject *bpy_bmface_copy_from_face_interp(BPy_BMFace *self, PyObject *ar else { BMesh *bm = self->bm; - BPY_BM_CHECK_SOURCE_OBJ(py_face, bm, "BMFace.copy_from_face_interp(face)"); + BPY_BM_CHECK_SOURCE_OBJ(bm, "BMFace.copy_from_face_interp(face)", py_face); BM_face_interp_from_face(bm, self->f, py_face->f, do_vertex); @@ -1811,7 +1811,7 @@ static PyObject *bpy_bmloop_copy_from_face_interp(BPy_BMLoop *self, PyObject *ar else { BMesh *bm = self->bm; - BPY_BM_CHECK_SOURCE_OBJ(py_face, bm, "BMLoop.copy_from_face_interp(face)"); + BPY_BM_CHECK_SOURCE_OBJ(bm, "BMLoop.copy_from_face_interp(face)", py_face); BM_loop_interp_from_face(bm, self->l, py_face->f, do_vertex, do_multires); @@ -2094,7 +2094,7 @@ static PyObject *bpy_bmvertseq_remove(BPy_BMElemSeq *self, BPy_BMVert *value) else { BMesh *bm = self->bm; - BPY_BM_CHECK_SOURCE_OBJ(value, bm, "verts.remove(vert)"); + BPY_BM_CHECK_SOURCE_OBJ(bm, "verts.remove(vert)", value); BM_vert_kill(bm, value->v); bpy_bm_generic_invalidate((BPy_BMGeneric *)value); @@ -2118,7 +2118,7 @@ static PyObject *bpy_bmedgeseq_remove(BPy_BMElemSeq *self, BPy_BMEdge *value) else { BMesh *bm = self->bm; - BPY_BM_CHECK_SOURCE_OBJ(value, bm, "edges.remove(edges)"); + BPY_BM_CHECK_SOURCE_OBJ(bm, "edges.remove(edges)", value); BM_edge_kill(bm, value->e); bpy_bm_generic_invalidate((BPy_BMGeneric *)value); @@ -2142,7 +2142,7 @@ static PyObject *bpy_bmfaceseq_remove(BPy_BMElemSeq *self, BPy_BMFace *value) else { BMesh *bm = self->bm; - BPY_BM_CHECK_SOURCE_OBJ(value, bm, "faces.remove(face)"); + BPY_BM_CHECK_SOURCE_OBJ(bm, "faces.remove(face)", value); BM_face_kill(bm, value->f); bpy_bm_generic_invalidate((BPy_BMGeneric *)value); @@ -3584,18 +3584,34 @@ int bpy_bm_generic_valid_check(BPy_BMGeneric *self) } } -int bpy_bm_generic_valid_check_source(BPy_BMGeneric *self, BMesh *bm_source, const char *error_prefix) +int bpy_bm_generic_valid_check_source(BMesh *bm_source, const char *error_prefix, void **args, unsigned int args_tot) { - int ret = bpy_bm_generic_valid_check(self); - if (LIKELY(ret == 0)) { - if (UNLIKELY(self->bm != bm_source)) { - /* could give more info here */ - PyErr_Format(PyExc_ValueError, - "%.200s: BMesh data of type %.200s is from another mesh", - error_prefix, Py_TYPE(self)->tp_name); - ret = -1; + int ret = 0; + + while (args_tot--) { + BPy_BMGeneric *py_bm_elem = args[args_tot]; + if (py_bm_elem) { + + BLI_assert(BPy_BMesh_Check(py_bm_elem) || + BPy_BMElem_Check(py_bm_elem)); + + ret = bpy_bm_generic_valid_check(py_bm_elem); + if (UNLIKELY(ret == -1)) { + break; + } + else { + if (UNLIKELY(py_bm_elem->bm != bm_source)) { + /* could give more info here */ + PyErr_Format(PyExc_ValueError, + "%.200s: BMesh data of type %.200s is from another mesh", + error_prefix, Py_TYPE(py_bm_elem)->tp_name); + ret = -1; + break; + } + } } } + return ret; } diff --git a/source/blender/python/bmesh/bmesh_py_types.h b/source/blender/python/bmesh/bmesh_py_types.h index 86fa61d5f7e..a2c2c312e71 100644 --- a/source/blender/python/bmesh/bmesh_py_types.h +++ b/source/blender/python/bmesh/bmesh_py_types.h @@ -175,7 +175,7 @@ char *BPy_BMElem_StringFromHType(const char htype); // void bpy_bm_generic_invalidate(BPy_BMGeneric *self); int bpy_bm_generic_valid_check(BPy_BMGeneric *self); -int bpy_bm_generic_valid_check_source(BPy_BMGeneric *self, BMesh *bm_source, const char *error_prefix); +int bpy_bm_generic_valid_check_source(BMesh *bm_source, const char *error_prefix, void **args, unsigned int args_n) ATTR_NONNULL(1, 2); #define BPY_BM_CHECK_OBJ(obj) \ if (UNLIKELY(bpy_bm_generic_valid_check((BPy_BMGeneric *)obj) == -1)) { return NULL; } (void)0 @@ -183,10 +183,18 @@ int bpy_bm_generic_valid_check_source(BPy_BMGeneric *self, BMesh *bm_source, co if (UNLIKELY(bpy_bm_generic_valid_check((BPy_BMGeneric *)obj) == -1)) { return -1; } (void)0 /* macros like BPY_BM_CHECK_OBJ/BPY_BM_CHECK_INT that ensure we're from the right BMesh */ -#define BPY_BM_CHECK_SOURCE_OBJ(obj, bm, errmsg) \ - if (UNLIKELY(bpy_bm_generic_valid_check_source((BPy_BMGeneric *)obj, bm, errmsg) == -1)) { return NULL; } (void)0 -#define BPY_BM_CHECK_SOURCE_INT(obj, bm, errmsg) \ - if (UNLIKELY(bpy_bm_generic_valid_check_source((BPy_BMGeneric *)obj, bm, errmsg) == -1)) { return -1; } (void)0 +#define BPY_BM_CHECK_SOURCE_OBJ(bm, errmsg, ...) { \ + void *_args[] = {__VA_ARGS__}; \ + if (UNLIKELY(bpy_bm_generic_valid_check_source(bm, errmsg, _args, ARRAY_SIZE(_args)) == -1)) { \ + return NULL; \ + } \ +} (void)0 +#define BPY_BM_CHECK_SOURCE_INT(bm, errmsg, ...) { \ + void *_args[] = {__VA_ARGS__}; \ + if (UNLIKELY(bpy_bm_generic_valid_check_source(bm, errmsg, _args, ARRAY_SIZE(_args)) == -1)) { \ + return -1; \ + } \ +} (void)0 #define BPY_BM_IS_VALID(obj) (LIKELY((obj)->bm != NULL)) diff --git a/source/blender/python/bmesh/bmesh_py_types_customdata.c b/source/blender/python/bmesh/bmesh_py_types_customdata.c index dfb3ae75df4..6ecb01a8528 100644 --- a/source/blender/python/bmesh/bmesh_py_types_customdata.c +++ b/source/blender/python/bmesh/bmesh_py_types_customdata.c @@ -281,7 +281,7 @@ static PyObject *bpy_bmlayeritem_copy_from(BPy_BMLayerItem *self, BPy_BMLayerIte } BPY_BM_CHECK_OBJ(self); - BPY_BM_CHECK_SOURCE_OBJ(value, self->bm, "layer.copy_from()"); + BPY_BM_CHECK_SOURCE_OBJ(self->bm, "layer.copy_from()", value); if ((self->htype != value->htype) || (self->type != value->type)) diff --git a/source/blender/python/bmesh/bmesh_py_types_select.c b/source/blender/python/bmesh/bmesh_py_types_select.c index b8e04a0cab8..3c72112e7ce 100644 --- a/source/blender/python/bmesh/bmesh_py_types_select.c +++ b/source/blender/python/bmesh/bmesh_py_types_select.c @@ -112,7 +112,7 @@ static PyObject *bpy_bmeditselseq_add(BPy_BMEditSelSeq *self, BPy_BMElem *value) return NULL; } - BPY_BM_CHECK_SOURCE_OBJ(value, self->bm, "select_history.add()"); + BPY_BM_CHECK_SOURCE_OBJ(self->bm, "select_history.add()", value); BM_select_history_store(self->bm, value->ele); @@ -137,7 +137,7 @@ static PyObject *bpy_bmeditselseq_remove(BPy_BMEditSelSeq *self, BPy_BMElem *val return NULL; } - BPY_BM_CHECK_SOURCE_OBJ(value, self->bm, "select_history.remove()"); + BPY_BM_CHECK_SOURCE_OBJ(self->bm, "select_history.remove()", value); if (BM_select_history_remove(self->bm, value->ele) == false) { PyErr_SetString(PyExc_ValueError, diff --git a/source/blender/python/bmesh/bmesh_py_utils.c b/source/blender/python/bmesh/bmesh_py_utils.c index a1e11d197d5..56a6dafc4f1 100644 --- a/source/blender/python/bmesh/bmesh_py_utils.c +++ b/source/blender/python/bmesh/bmesh_py_utils.c @@ -630,7 +630,7 @@ static PyObject *bpy_bm_utils_face_vert_separate(PyObject *UNUSED(self), PyObjec bm = py_face->bm; BPY_BM_CHECK_OBJ(py_face); - BPY_BM_CHECK_SOURCE_OBJ(py_vert, bm, "face_vert_separate()"); + BPY_BM_CHECK_SOURCE_OBJ(bm, "face_vert_separate()", py_vert); l = BM_face_vert_share_loop(py_face->f, py_vert->v); |