From 3d48d99647b59a6f0461baa4456660917f1bbda6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Fri, 7 Aug 2020 12:41:06 +0200 Subject: [PATCH] Cleanup: Python, Clang-Tidy else-after-return fixes This addresses warnings from Clang-Tidy's `readability-else-after-return` rule in the `source/blender/python` module. No functional changes. --- source/blender/python/bmesh/bmesh_py_ops.c | 8 +- .../blender/python/bmesh/bmesh_py_ops_call.c | 24 +- source/blender/python/bmesh/bmesh_py_types.c | 722 +++++++-------- .../python/bmesh/bmesh_py_types_customdata.c | 108 +-- .../python/bmesh/bmesh_py_types_meshdata.c | 111 +-- .../python/bmesh/bmesh_py_types_select.c | 76 +- source/blender/python/bmesh/bmesh_py_utils.c | 63 +- source/blender/python/generic/bgl.c | 59 +- source/blender/python/generic/idprop_py_api.c | 128 ++- source/blender/python/generic/imbuf_py_api.c | 14 +- source/blender/python/generic/py_capi_utils.c | 83 +- source/blender/python/gpu/gpu_py_batch.c | 2 +- .../blender/python/intern/bpy_app_handlers.c | 18 +- source/blender/python/intern/bpy_driver.c | 16 +- .../blender/python/intern/bpy_library_load.c | 108 ++- source/blender/python/intern/bpy_props.c | 58 +- source/blender/python/intern/bpy_rna.c | 855 +++++++++--------- source/blender/python/intern/bpy_rna_anim.c | 212 +++-- source/blender/python/intern/bpy_rna_array.c | 149 ++- .../blender/python/intern/bpy_rna_callback.c | 76 +- source/blender/python/intern/bpy_rna_gizmo.c | 8 +- source/blender/python/mathutils/mathutils.c | 111 ++- .../python/mathutils/mathutils_Color.c | 34 +- .../python/mathutils/mathutils_Euler.c | 34 +- .../python/mathutils/mathutils_Matrix.c | 249 +++-- .../python/mathutils/mathutils_Quaternion.c | 47 +- .../python/mathutils/mathutils_Vector.c | 109 +-- .../python/mathutils/mathutils_bvhtree.c | 88 +- .../python/mathutils/mathutils_geometry.c | 280 +++--- 29 files changed, 1799 insertions(+), 2051 deletions(-) diff --git a/source/blender/python/bmesh/bmesh_py_ops.c b/source/blender/python/bmesh/bmesh_py_ops.c index 1eccfe06d15..cdbd4832159 100644 --- a/source/blender/python/bmesh/bmesh_py_ops.c +++ b/source/blender/python/bmesh/bmesh_py_ops.c @@ -250,11 +250,9 @@ static PyObject *bpy_bmesh_ops_fakemod_getattro(PyObject *UNUSED(self), PyObject if (BMO_opcode_from_opname(opname) != -1) { return bpy_bmesh_op_CreatePyObject(opname); } - else { - PyErr_Format( - PyExc_AttributeError, "BMeshOpsModule: operator \"%.200s\" doesn't exist", opname); - return NULL; - } + + PyErr_Format(PyExc_AttributeError, "BMeshOpsModule: operator \"%.200s\" doesn't exist", opname); + return NULL; } static PyObject *bpy_bmesh_ops_fakemod_dir(PyObject *UNUSED(self)) diff --git a/source/blender/python/bmesh/bmesh_py_ops_call.c b/source/blender/python/bmesh/bmesh_py_ops_call.c index b1e5c1c761b..a387ba31c84 100644 --- a/source/blender/python/bmesh/bmesh_py_ops_call.c +++ b/source/blender/python/bmesh/bmesh_py_ops_call.c @@ -82,7 +82,7 @@ static int bpy_slot_from_py_elem_check(BPy_BMElem *value, Py_TYPE(value)->tp_name); return -1; } - else if (value->bm == NULL) { + if (value->bm == NULL) { PyErr_Format(PyExc_TypeError, "%.200s: keyword \"%.200s\" %.200s invalidated element", opname, @@ -90,7 +90,7 @@ static int bpy_slot_from_py_elem_check(BPy_BMElem *value, descr); return -1; } - else if (value->bm != bm) { /* we may want to make this check optional by setting 'bm' to NULL */ + if (value->bm != bm) { /* we may want to make this check optional by setting 'bm' to NULL */ PyErr_Format(PyExc_TypeError, "%.200s: keyword \"%.200s\" %.200s invalidated element", opname, @@ -127,7 +127,7 @@ static int bpy_slot_from_py_elemseq_check(BPy_BMGeneric *value, descr); return -1; } - else if (value->bm != bm) { /* we may want to make this check optional by setting 'bm' to NULL */ + if (value->bm != bm) { /* we may want to make this check optional by setting 'bm' to NULL */ PyErr_Format(PyExc_TypeError, "%.200s: keyword \"%.200s\" %.200s, invalidated sequence", opname, @@ -135,7 +135,7 @@ static int bpy_slot_from_py_elemseq_check(BPy_BMGeneric *value, descr); return -1; } - else if ((htype_py & htype_bmo) == 0) { + if ((htype_py & htype_bmo) == 0) { char str_bmo[32]; char str_py[32]; PyErr_Format(PyExc_TypeError, @@ -175,9 +175,8 @@ static int bpy_slot_from_py(BMesh *bm, Py_TYPE(value)->tp_name); return -1; } - else { - BMO_SLOT_AS_BOOL(slot) = param; - } + + BMO_SLOT_AS_BOOL(slot) = param; break; } @@ -223,9 +222,8 @@ static int bpy_slot_from_py(BMesh *bm, Py_TYPE(value)->tp_name); return -1; } - else { - BMO_SLOT_AS_INT(slot) = param; - } + + BMO_SLOT_AS_INT(slot) = param; } break; } @@ -239,9 +237,9 @@ static int bpy_slot_from_py(BMesh *bm, Py_TYPE(value)->tp_name); return -1; } - else { - BMO_SLOT_AS_FLOAT(slot) = param; - } + + BMO_SLOT_AS_FLOAT(slot) = param; + break; } case BMO_OP_SLOT_MAT: { diff --git a/source/blender/python/bmesh/bmesh_py_types.c b/source/blender/python/bmesh/bmesh_py_types.c index fccdfe7fbdc..e39b5faf3c4 100644 --- a/source/blender/python/bmesh/bmesh_py_types.c +++ b/source/blender/python/bmesh/bmesh_py_types.c @@ -292,14 +292,13 @@ static int bpy_bmesh_select_mode_set(BPy_BMesh *self, PyObject *value) -1) { return -1; } - else if (flag == 0) { + if (flag == 0) { PyErr_SetString(PyExc_TypeError, "bm.select_mode: cant assignt an empty value"); return -1; } - else { - self->bm->selectmode = flag; - return 0; - } + + self->bm->selectmode = flag; + return 0; } PyDoc_STRVAR(bpy_bmesh_select_history_doc, @@ -338,9 +337,8 @@ static int bpy_bmvert_co_set(BPy_BMVert *self, PyObject *value) if (mathutils_array_parse(self->v->co, 3, 3, value, "BMVert.co") != -1) { return 0; } - else { - return -1; - } + + return -1; } PyDoc_STRVAR( @@ -359,9 +357,8 @@ static int bpy_bmvert_normal_set(BPy_BMVert *self, PyObject *value) if (mathutils_array_parse(self->v->no, 3, 3, value, "BMVert.normal") != -1) { return 0; } - else { - return -1; - } + + return -1; } PyDoc_STRVAR(bpy_bmvert_is_manifold_doc, @@ -453,9 +450,8 @@ static int bpy_bmface_normal_set(BPy_BMFace *self, PyObject *value) if (mathutils_array_parse(self->f->no, 3, 3, value, "BMFace.normal") != -1) { return 0; } - else { - return -1; - } + + return -1; } PyDoc_STRVAR(bpy_bmface_material_index_doc, "The face's material index.\n\n:type: int"); @@ -481,10 +477,9 @@ static int bpy_bmface_material_index_set(BPy_BMFace *self, PyObject *value) PyErr_SetString(PyExc_ValueError, "material index outside of usable range (0 - 32766)"); return -1; } - else { - self->f->mat_nr = (short)param; - return 0; - } + + self->f->mat_nr = (short)param; + return 0; } /* Loop @@ -586,9 +581,8 @@ static PyObject *bpy_bmfaceseq_active_get(BPy_BMElemSeq *self, void *UNUSED(clos if (bm->act_face) { return BPy_BMElem_CreatePyObject(bm, (BMHeader *)bm->act_face); } - else { - Py_RETURN_NONE; - } + + Py_RETURN_NONE; } static int bpy_bmfaceseq_active_set(BPy_BMElem *self, PyObject *value, void *UNUSED(closure)) @@ -598,18 +592,17 @@ static int bpy_bmfaceseq_active_set(BPy_BMElem *self, PyObject *value, void *UNU bm->act_face = NULL; return 0; } - else if (BPy_BMFace_Check(value)) { + if (BPy_BMFace_Check(value)) { BPY_BM_CHECK_SOURCE_INT(bm, "faces.active = f", value); bm->act_face = ((BPy_BMFace *)value)->f; return 0; } - else { - PyErr_Format(PyExc_TypeError, - "faces.active = f: expected BMFace or None, not %.200s", - Py_TYPE(value)->tp_name); - return -1; - } + + PyErr_Format(PyExc_TypeError, + "faces.active = f: expected BMFace or None, not %.200s", + Py_TYPE(value)->tp_name); + return -1; } static PyGetSetDef bpy_bmesh_getseters[] = { @@ -971,10 +964,9 @@ static PyObject *bpy_bmesh_copy(BPy_BMesh *self) if (bm_copy) { return BPy_BMesh_CreatePyObject(bm_copy, BPY_BMFLAG_NOP); } - else { - PyErr_SetString(PyExc_SystemError, "Unable to copy BMesh, internal error"); - return NULL; - } + + PyErr_SetString(PyExc_SystemError, "Unable to copy BMesh, internal error"); + return NULL; } PyDoc_STRVAR(bpy_bmesh_clear_doc, @@ -1141,9 +1133,8 @@ static PyObject *bpy_bmesh_from_object(BPy_BMesh *self, PyObject *args, PyObject "evaluation mode is RENDER"); return NULL; } - else { - me_eval = mesh_create_eval_final_render(depsgraph, scene_eval, ob_eval, &data_masks); - } + + me_eval = mesh_create_eval_final_render(depsgraph, scene_eval, ob_eval, &data_masks); } else { if (use_cage) { @@ -1161,7 +1152,7 @@ static PyObject *bpy_bmesh_from_object(BPy_BMesh *self, PyObject *args, PyObject "from_object(...): cage arg is unsupported when deform=False"); return NULL; } - else if (use_render) { + if (use_render) { me_eval = mesh_create_eval_no_deform_render(depsgraph, scene_eval, ob, &data_masks); } else { @@ -1329,40 +1320,38 @@ static PyObject *bpy_bmesh_transform(BPy_BMElem *self, PyObject *args, PyObject &filter)) { return NULL; } + + BMVert *eve; + BMIter iter; + void *mat_ptr; + + if (BaseMath_ReadCallback(mat) == -1) { + return NULL; + } + if (mat->num_col != 4 || mat->num_row != 4) { + PyErr_SetString(PyExc_ValueError, "expected a 4x4 matrix"); + return NULL; + } + + if (filter != NULL && PyC_FlagSet_ToBitfield( + bpy_bm_hflag_all_flags, filter, &filter_flags, "bm.transform") == -1) { + return NULL; + } + + mat_ptr = mat->matrix; + + if (!filter_flags) { + BM_ITER_MESH (eve, &iter, self->bm, BM_VERTS_OF_MESH) { + mul_m4_v3((float(*)[4])mat_ptr, eve->co); + } + } else { - BMVert *eve; - BMIter iter; - void *mat_ptr; - - if (BaseMath_ReadCallback(mat) == -1) { - return NULL; - } - else if (mat->num_col != 4 || mat->num_row != 4) { - PyErr_SetString(PyExc_ValueError, "expected a 4x4 matrix"); - return NULL; - } - - if (filter != NULL && - PyC_FlagSet_ToBitfield(bpy_bm_hflag_all_flags, filter, &filter_flags, "bm.transform") == - -1) { - return NULL; - } - - mat_ptr = mat->matrix; - - if (!filter_flags) { - BM_ITER_MESH (eve, &iter, self->bm, BM_VERTS_OF_MESH) { + char filter_flags_ch = (char)filter_flags; + BM_ITER_MESH (eve, &iter, self->bm, BM_VERTS_OF_MESH) { + if (BM_elem_flag_test(eve, filter_flags_ch)) { mul_m4_v3((float(*)[4])mat_ptr, eve->co); } } - else { - char filter_flags_ch = (char)filter_flags; - BM_ITER_MESH (eve, &iter, self->bm, BM_VERTS_OF_MESH) { - if (BM_elem_flag_test(eve, filter_flags_ch)) { - mul_m4_v3((float(*)[4])mat_ptr, eve->co); - } - } - } } Py_RETURN_NONE; @@ -1388,9 +1377,8 @@ static PyObject *bpy_bmesh_calc_volume(BPy_BMElem *self, PyObject *args, PyObjec args, kw, "|O!:calc_volume", (char **)kwlist, &PyBool_Type, &is_signed)) { return NULL; } - else { - return PyFloat_FromDouble(BM_mesh_calc_volume(self->bm, is_signed != Py_False)); - } + + return PyFloat_FromDouble(BM_mesh_calc_volume(self->bm, is_signed != Py_False)); } PyDoc_STRVAR(bpy_bmesh_calc_loop_triangles_doc, @@ -1531,30 +1519,29 @@ static PyObject *bpy_bmvert_copy_from_vert_interp(BPy_BMVert *self, PyObject *ar if (!PyArg_ParseTuple(args, "Of:BMVert.copy_from_vert_interp", &vert_seq, &fac)) { return NULL; } - else { - BMesh *bm = self->bm; - BMVert **vert_array = NULL; - Py_ssize_t vert_seq_len; /* always 2 */ - vert_array = BPy_BMElem_PySeq_As_Array(&bm, - vert_seq, - 2, - 2, - &vert_seq_len, - BM_VERT, - true, - true, - "BMVert.copy_from_vert_interp(...)"); + BMesh *bm = self->bm; + BMVert **vert_array = NULL; + Py_ssize_t vert_seq_len; /* always 2 */ - if (vert_array == NULL) { - return NULL; - } + vert_array = BPy_BMElem_PySeq_As_Array(&bm, + vert_seq, + 2, + 2, + &vert_seq_len, + BM_VERT, + true, + true, + "BMVert.copy_from_vert_interp(...)"); - BM_data_interp_from_verts(bm, vert_array[0], vert_array[1], self->v, clamp_f(fac, 0.0f, 1.0f)); - - PyMem_FREE(vert_array); - Py_RETURN_NONE; + if (vert_array == NULL) { + return NULL; } + + BM_data_interp_from_verts(bm, vert_array[0], vert_array[1], self->v, clamp_f(fac, 0.0f, 1.0f)); + + PyMem_FREE(vert_array); + Py_RETURN_NONE; } PyDoc_STRVAR(bpy_bmvert_copy_from_face_interp_doc, @@ -1574,15 +1561,14 @@ static PyObject *bpy_bmvert_copy_from_face_interp(BPy_BMVert *self, PyObject *ar if (!PyArg_ParseTuple(args, "O!:BMVert.copy_from_face_interp", &BPy_BMFace_Type, &py_face)) { return NULL; } - else { - BMesh *bm = self->bm; - BPY_BM_CHECK_SOURCE_OBJ(bm, "copy_from_face_interp()", py_face); + BMesh *bm = self->bm; - BM_vert_interp_from_face(bm, self->v, py_face->f); + BPY_BM_CHECK_SOURCE_OBJ(bm, "copy_from_face_interp()", py_face); - Py_RETURN_NONE; - } + BM_vert_interp_from_face(bm, self->v, py_face->f); + + Py_RETURN_NONE; } PyDoc_STRVAR(bpy_bmvert_calc_edge_angle_doc, @@ -1615,12 +1601,11 @@ static PyObject *bpy_bmvert_calc_edge_angle(BPy_BMVert *self, PyObject *args) Py_INCREF(fallback); return fallback; } - else { - PyErr_SetString(PyExc_ValueError, - "BMVert.calc_edge_angle(): " - "vert must connect to exactly 2 edges"); - return NULL; - } + + PyErr_SetString(PyExc_ValueError, + "BMVert.calc_edge_angle(): " + "vert must connect to exactly 2 edges"); + return NULL; } return PyFloat_FromDouble(angle); @@ -1697,12 +1682,11 @@ static PyObject *bpy_bmedge_calc_face_angle(BPy_BMEdge *self, PyObject *args) Py_INCREF(fallback); return fallback; } - else { - PyErr_SetString(PyExc_ValueError, - "BMEdge.calc_face_angle(): " - "edge doesn't use 2 faces"); - return NULL; - } + + PyErr_SetString(PyExc_ValueError, + "BMEdge.calc_face_angle(): " + "edge doesn't use 2 faces"); + return NULL; } return PyFloat_FromDouble(angle); @@ -1737,12 +1721,11 @@ static PyObject *bpy_bmedge_calc_face_angle_signed(BPy_BMEdge *self, PyObject *a Py_INCREF(fallback); return fallback; } - else { - PyErr_SetString(PyExc_ValueError, - "BMEdge.calc_face_angle_signed(): " - "edge doesn't use 2 faces"); - return NULL; - } + + PyErr_SetString(PyExc_ValueError, + "BMEdge.calc_face_angle_signed(): " + "edge doesn't use 2 faces"); + return NULL; } return PyFloat_FromDouble(angle); @@ -1767,13 +1750,12 @@ static PyObject *bpy_bmedge_calc_tangent(BPy_BMEdge *self, PyObject *args) if (!PyArg_ParseTuple(args, "O!:BMEdge.calc_face_tangent", &BPy_BMLoop_Type, &py_loop)) { return NULL; } - else { - float vec[3]; - BPY_BM_CHECK_OBJ(py_loop); - /* no need to check if they are from the same mesh or even connected */ - BM_edge_calc_face_tangent(self->e, py_loop->l, vec); - return Vector_CreatePyObject(vec, 3, NULL); - } + + float vec[3]; + BPY_BM_CHECK_OBJ(py_loop); + /* no need to check if they are from the same mesh or even connected */ + BM_edge_calc_face_tangent(self->e, py_loop->l, vec); + return Vector_CreatePyObject(vec, 3, NULL); } PyDoc_STRVAR( @@ -1805,10 +1787,9 @@ static PyObject *bpy_bmedge_other_vert(BPy_BMEdge *self, BPy_BMVert *value) if (other) { return BPy_BMVert_CreatePyObject(self->bm, other); } - else { - /* could raise an exception here */ - Py_RETURN_NONE; - } + + /* could raise an exception here */ + Py_RETURN_NONE; } PyDoc_STRVAR(bpy_bmedge_normal_update_doc, @@ -1852,15 +1833,14 @@ static PyObject *bpy_bmface_copy_from_face_interp(BPy_BMFace *self, PyObject *ar &do_vertex)) { return NULL; } - else { - BMesh *bm = self->bm; - BPY_BM_CHECK_SOURCE_OBJ(bm, "BMFace.copy_from_face_interp(face)", py_face); + BMesh *bm = self->bm; - BM_face_interp_from_face(bm, self->f, py_face->f, do_vertex); + BPY_BM_CHECK_SOURCE_OBJ(bm, "BMFace.copy_from_face_interp(face)", py_face); - Py_RETURN_NONE; - } + BM_face_interp_from_face(bm, self->f, py_face->f, do_vertex); + + Py_RETURN_NONE; } PyDoc_STRVAR(bpy_bmface_copy_doc, @@ -1901,11 +1881,9 @@ static PyObject *bpy_bmface_copy(BPy_BMFace *self, PyObject *args, PyObject *kw) if (f_cpy) { return BPy_BMFace_CreatePyObject(bm, f_cpy); } - else { - PyErr_SetString(PyExc_ValueError, - "BMFace.copy(): couldn't create the new face, internal error"); - return NULL; - } + + PyErr_SetString(PyExc_ValueError, "BMFace.copy(): couldn't create the new face, internal error"); + return NULL; } PyDoc_STRVAR(bpy_bmface_calc_area_doc, @@ -2109,15 +2087,14 @@ static PyObject *bpy_bmloop_copy_from_face_interp(BPy_BMLoop *self, PyObject *ar &do_multires)) { return NULL; } - else { - BMesh *bm = self->bm; - BPY_BM_CHECK_SOURCE_OBJ(bm, "BMLoop.copy_from_face_interp(face)", py_face); + BMesh *bm = self->bm; - BM_loop_interp_from_face(bm, self->l, py_face->f, do_vertex, do_multires); + BPY_BM_CHECK_SOURCE_OBJ(bm, "BMLoop.copy_from_face_interp(face)", py_face); - Py_RETURN_NONE; - } + BM_loop_interp_from_face(bm, self->l, py_face->f, do_vertex, do_multires); + + Py_RETURN_NONE; } PyDoc_STRVAR(bpy_bmloop_calc_angle_doc, @@ -2190,33 +2167,32 @@ static PyObject *bpy_bmvertseq_new(BPy_BMElemSeq *self, PyObject *args) if (!PyArg_ParseTuple(args, "|OO!:verts.new", &py_co, &BPy_BMVert_Type, &py_vert_example)) { return NULL; } - else { - BMesh *bm = self->bm; - BMVert *v; - float co[3] = {0.0f, 0.0f, 0.0f}; - if (py_vert_example) { - BPY_BM_CHECK_OBJ(py_vert_example); - } + BMesh *bm = self->bm; + BMVert *v; + float co[3] = {0.0f, 0.0f, 0.0f}; - if (py_co && mathutils_array_parse(co, 3, 3, py_co, "verts.new(co)") == -1) { - return NULL; - } - - v = BM_vert_create(bm, co, NULL, BM_CREATE_NOP); - - if (v == NULL) { - PyErr_SetString(PyExc_ValueError, - "faces.new(verts): couldn't create the new face, internal error"); - return NULL; - } - - if (py_vert_example) { - BM_elem_attrs_copy(py_vert_example->bm, bm, py_vert_example->v, v); - } - - return BPy_BMVert_CreatePyObject(bm, v); + if (py_vert_example) { + BPY_BM_CHECK_OBJ(py_vert_example); } + + if (py_co && mathutils_array_parse(co, 3, 3, py_co, "verts.new(co)") == -1) { + return NULL; + } + + v = BM_vert_create(bm, co, NULL, BM_CREATE_NOP); + + if (v == NULL) { + PyErr_SetString(PyExc_ValueError, + "faces.new(verts): couldn't create the new face, internal error"); + return NULL; + } + + if (py_vert_example) { + BM_elem_attrs_copy(py_vert_example->bm, bm, py_vert_example->v, v); + } + + return BPy_BMVert_CreatePyObject(bm, v); } /* Edge Seq @@ -2242,49 +2218,48 @@ static PyObject *bpy_bmedgeseq_new(BPy_BMElemSeq *self, PyObject *args) if (!PyArg_ParseTuple(args, "O|O!:edges.new", &vert_seq, &BPy_BMEdge_Type, &py_edge_example)) { return NULL; } - else { - BMesh *bm = self->bm; - BMEdge *e; - BMVert **vert_array = NULL; - Py_ssize_t vert_seq_len; /* always 2 */ - PyObject *ret = NULL; - if (py_edge_example) { - BPY_BM_CHECK_OBJ(py_edge_example); - } + BMesh *bm = self->bm; + BMEdge *e; + BMVert **vert_array = NULL; + Py_ssize_t vert_seq_len; /* always 2 */ + PyObject *ret = NULL; - vert_array = BPy_BMElem_PySeq_As_Array( - &bm, vert_seq, 2, 2, &vert_seq_len, BM_VERT, true, true, "edges.new(...)"); - - if (vert_array == NULL) { - return NULL; - } - - if (BM_edge_exists(vert_array[0], vert_array[1])) { - PyErr_SetString(PyExc_ValueError, "edges.new(): this edge exists"); - goto cleanup; - } - - e = BM_edge_create(bm, vert_array[0], vert_array[1], NULL, BM_CREATE_NOP); - - if (e == NULL) { - PyErr_SetString(PyExc_ValueError, - "faces.new(verts): couldn't create the new face, internal error"); - goto cleanup; - } - - if (py_edge_example) { - BM_elem_attrs_copy(py_edge_example->bm, bm, py_edge_example->e, e); - } - - ret = BPy_BMEdge_CreatePyObject(bm, e); - - cleanup: - if (vert_array) { - PyMem_FREE(vert_array); - } - return ret; + if (py_edge_example) { + BPY_BM_CHECK_OBJ(py_edge_example); } + + vert_array = BPy_BMElem_PySeq_As_Array( + &bm, vert_seq, 2, 2, &vert_seq_len, BM_VERT, true, true, "edges.new(...)"); + + if (vert_array == NULL) { + return NULL; + } + + if (BM_edge_exists(vert_array[0], vert_array[1])) { + PyErr_SetString(PyExc_ValueError, "edges.new(): this edge exists"); + goto cleanup; + } + + e = BM_edge_create(bm, vert_array[0], vert_array[1], NULL, BM_CREATE_NOP); + + if (e == NULL) { + PyErr_SetString(PyExc_ValueError, + "faces.new(verts): couldn't create the new face, internal error"); + goto cleanup; + } + + if (py_edge_example) { + BM_elem_attrs_copy(py_edge_example->bm, bm, py_edge_example->e, e); + } + + ret = BPy_BMEdge_CreatePyObject(bm, e); + +cleanup: + if (vert_array) { + PyMem_FREE(vert_array); + } + return ret; } /* Face Seq @@ -2310,58 +2285,57 @@ static PyObject *bpy_bmfaceseq_new(BPy_BMElemSeq *self, PyObject *args) if (!PyArg_ParseTuple(args, "O|O!:faces.new", &vert_seq, &BPy_BMFace_Type, &py_face_example)) { return NULL; } - else { - BMesh *bm = self->bm; - Py_ssize_t vert_seq_len; - BMVert **vert_array = NULL; + BMesh *bm = self->bm; + Py_ssize_t vert_seq_len; - PyObject *ret = NULL; + BMVert **vert_array = NULL; - BMFace *f_new; + PyObject *ret = NULL; - if (py_face_example) { - BPY_BM_CHECK_OBJ(py_face_example); - } + BMFace *f_new; - vert_array = BPy_BMElem_PySeq_As_Array( - &bm, vert_seq, 3, PY_SSIZE_T_MAX, &vert_seq_len, BM_VERT, true, true, "faces.new(...)"); - - if (vert_array == NULL) { - return NULL; - } - - /* check if the face exists */ - if (BM_face_exists(vert_array, vert_seq_len) != NULL) { - PyErr_SetString(PyExc_ValueError, "faces.new(verts): face already exists"); - goto cleanup; - } - - /* Go ahead and make the face! - * --------------------------- */ - - f_new = BM_face_create_verts(bm, - vert_array, - vert_seq_len, - py_face_example ? py_face_example->f : NULL, - BM_CREATE_NOP, - true); - - if (UNLIKELY(f_new == NULL)) { - PyErr_SetString(PyExc_ValueError, - "faces.new(verts): couldn't create the new face, internal error"); - goto cleanup; - } - - ret = BPy_BMFace_CreatePyObject(bm, f_new); - - /* pass through */ - cleanup: - if (vert_array) { - PyMem_FREE(vert_array); - } - return ret; + if (py_face_example) { + BPY_BM_CHECK_OBJ(py_face_example); } + + vert_array = BPy_BMElem_PySeq_As_Array( + &bm, vert_seq, 3, PY_SSIZE_T_MAX, &vert_seq_len, BM_VERT, true, true, "faces.new(...)"); + + if (vert_array == NULL) { + return NULL; + } + + /* check if the face exists */ + if (BM_face_exists(vert_array, vert_seq_len) != NULL) { + PyErr_SetString(PyExc_ValueError, "faces.new(verts): face already exists"); + goto cleanup; + } + + /* Go ahead and make the face! + * --------------------------- */ + + f_new = BM_face_create_verts(bm, + vert_array, + vert_seq_len, + py_face_example ? py_face_example->f : NULL, + BM_CREATE_NOP, + true); + + if (UNLIKELY(f_new == NULL)) { + PyErr_SetString(PyExc_ValueError, + "faces.new(verts): couldn't create the new face, internal error"); + goto cleanup; + } + + ret = BPy_BMFace_CreatePyObject(bm, f_new); + + /* pass through */ +cleanup: + if (vert_array) { + PyMem_FREE(vert_array); + } + return ret; } /* Elem Seq @@ -2378,16 +2352,15 @@ static PyObject *bpy_bmvertseq_remove(BPy_BMElemSeq *self, BPy_BMVert *value) if (!BPy_BMVert_Check(value)) { return NULL; } - else { - BMesh *bm = self->bm; - BPY_BM_CHECK_SOURCE_OBJ(bm, "verts.remove(vert)", value); + BMesh *bm = self->bm; - BM_vert_kill(bm, value->v); - bpy_bm_generic_invalidate((BPy_BMGeneric *)value); + BPY_BM_CHECK_SOURCE_OBJ(bm, "verts.remove(vert)", value); - Py_RETURN_NONE; - } + BM_vert_kill(bm, value->v); + bpy_bm_generic_invalidate((BPy_BMGeneric *)value); + + Py_RETURN_NONE; } PyDoc_STRVAR(bpy_bmedgeseq_remove_doc, @@ -2401,16 +2374,15 @@ static PyObject *bpy_bmedgeseq_remove(BPy_BMElemSeq *self, BPy_BMEdge *value) if (!BPy_BMEdge_Check(value)) { return NULL; } - else { - BMesh *bm = self->bm; - BPY_BM_CHECK_SOURCE_OBJ(bm, "edges.remove(edges)", value); + BMesh *bm = self->bm; - BM_edge_kill(bm, value->e); - bpy_bm_generic_invalidate((BPy_BMGeneric *)value); + BPY_BM_CHECK_SOURCE_OBJ(bm, "edges.remove(edges)", value); - Py_RETURN_NONE; - } + BM_edge_kill(bm, value->e); + bpy_bm_generic_invalidate((BPy_BMGeneric *)value); + + Py_RETURN_NONE; } PyDoc_STRVAR(bpy_bmfaceseq_remove_doc, @@ -2424,16 +2396,15 @@ static PyObject *bpy_bmfaceseq_remove(BPy_BMElemSeq *self, BPy_BMFace *value) if (!BPy_BMFace_Check(value)) { return NULL; } - else { - BMesh *bm = self->bm; - BPY_BM_CHECK_SOURCE_OBJ(bm, "faces.remove(face)", value); + BMesh *bm = self->bm; - BM_face_kill(bm, value->f); - bpy_bm_generic_invalidate((BPy_BMGeneric *)value); + BPY_BM_CHECK_SOURCE_OBJ(bm, "faces.remove(face)", value); - Py_RETURN_NONE; - } + BM_face_kill(bm, value->f); + bpy_bm_generic_invalidate((BPy_BMGeneric *)value); + + Py_RETURN_NONE; } PyDoc_STRVAR(bpy_bmedgeseq_get__method_doc, @@ -2456,31 +2427,30 @@ static PyObject *bpy_bmedgeseq_get__method(BPy_BMElemSeq *self, PyObject *args) if (!PyArg_ParseTuple(args, "O|O:edges.get", &vert_seq, &fallback)) { return NULL; } - else { - BMesh *bm = self->bm; - BMEdge *e; - BMVert **vert_array = NULL; - Py_ssize_t vert_seq_len; /* always 2 */ - PyObject *ret = NULL; - vert_array = BPy_BMElem_PySeq_As_Array( - &bm, vert_seq, 2, 2, &vert_seq_len, BM_VERT, true, true, "edges.get(...)"); + BMesh *bm = self->bm; + BMEdge *e; + BMVert **vert_array = NULL; + Py_ssize_t vert_seq_len; /* always 2 */ + PyObject *ret = NULL; - if (vert_array == NULL) { - return NULL; - } + vert_array = BPy_BMElem_PySeq_As_Array( + &bm, vert_seq, 2, 2, &vert_seq_len, BM_VERT, true, true, "edges.get(...)"); - if ((e = BM_edge_exists(vert_array[0], vert_array[1]))) { - ret = BPy_BMEdge_CreatePyObject(bm, e); - } - else { - ret = fallback; - Py_INCREF(ret); - } - - PyMem_FREE(vert_array); - return ret; + if (vert_array == NULL) { + return NULL; } + + if ((e = BM_edge_exists(vert_array[0], vert_array[1]))) { + ret = BPy_BMEdge_CreatePyObject(bm, e); + } + else { + ret = fallback; + Py_INCREF(ret); + } + + PyMem_FREE(vert_array); + return ret; } PyDoc_STRVAR(bpy_bmfaceseq_get__method_doc, @@ -2503,32 +2473,31 @@ static PyObject *bpy_bmfaceseq_get__method(BPy_BMElemSeq *self, PyObject *args) if (!PyArg_ParseTuple(args, "O|O:faces.get", &vert_seq, &fallback)) { return NULL; } - else { - BMesh *bm = self->bm; - BMFace *f = NULL; - BMVert **vert_array = NULL; - Py_ssize_t vert_seq_len; - PyObject *ret = NULL; - vert_array = BPy_BMElem_PySeq_As_Array( - &bm, vert_seq, 1, PY_SSIZE_T_MAX, &vert_seq_len, BM_VERT, true, true, "faces.get(...)"); + BMesh *bm = self->bm; + BMFace *f = NULL; + BMVert **vert_array = NULL; + Py_ssize_t vert_seq_len; + PyObject *ret = NULL; - if (vert_array == NULL) { - return NULL; - } + vert_array = BPy_BMElem_PySeq_As_Array( + &bm, vert_seq, 1, PY_SSIZE_T_MAX, &vert_seq_len, BM_VERT, true, true, "faces.get(...)"); - f = BM_face_exists(vert_array, vert_seq_len); - if (f != NULL) { - ret = BPy_BMFace_CreatePyObject(bm, f); - } - else { - ret = fallback; - Py_INCREF(ret); - } - - PyMem_FREE(vert_array); - return ret; + if (vert_array == NULL) { + return NULL; } + + f = BM_face_exists(vert_array, vert_seq_len); + if (f != NULL) { + ret = BPy_BMFace_CreatePyObject(bm, f); + } + else { + ret = fallback; + Py_INCREF(ret); + } + + PyMem_FREE(vert_array); + return ret; } PyDoc_STRVAR( @@ -2651,12 +2620,11 @@ static int bpy_bmelemseq_sort_cmp_by_keys_ascending(const void *index1_v, if (keys[*index1] < keys[*index2]) { return -1; } - else if (keys[*index1] > keys[*index2]) { + if (keys[*index1] > keys[*index2]) { return 1; } - else { - return 0; - } + + return 0; } static int bpy_bmelemseq_sort_cmp_by_keys_descending(const void *index1_v, @@ -3260,54 +3228,51 @@ static PyObject *bpy_bmelemseq_subscript(BPy_BMElemSeq *self, PyObject *key) } return bpy_bmelemseq_subscript_int(self, i); } - else if (PySlice_Check(key)) { + if (PySlice_Check(key)) { PySliceObject *key_slice = (PySliceObject *)key; Py_ssize_t step = 1; if (key_slice->step != Py_None && !_PyEval_SliceIndex(key, &step)) { return NULL; } - else if (step != 1) { + if (step != 1) { PyErr_SetString(PyExc_TypeError, "BMElemSeq[slice]: slice steps not supported"); return NULL; } - else if (key_slice->start == Py_None && key_slice->stop == Py_None) { + if (key_slice->start == Py_None && key_slice->stop == Py_None) { return bpy_bmelemseq_subscript_slice(self, 0, PY_SSIZE_T_MAX); } - else { - Py_ssize_t start = 0, stop = PY_SSIZE_T_MAX; - /* avoid PySlice_GetIndicesEx because it needs to know the length ahead of time. */ - if (key_slice->start != Py_None && !_PyEval_SliceIndex(key_slice->start, &start)) { - return NULL; - } - if (key_slice->stop != Py_None && !_PyEval_SliceIndex(key_slice->stop, &stop)) { - return NULL; - } + Py_ssize_t start = 0, stop = PY_SSIZE_T_MAX; - if (start < 0 || stop < 0) { - /* only get the length for negative values */ - Py_ssize_t len = bpy_bmelemseq_length(self); - if (start < 0) { - start += len; - } - if (stop < 0) { - stop += len; - } - } + /* avoid PySlice_GetIndicesEx because it needs to know the length ahead of time. */ + if (key_slice->start != Py_None && !_PyEval_SliceIndex(key_slice->start, &start)) { + return NULL; + } + if (key_slice->stop != Py_None && !_PyEval_SliceIndex(key_slice->stop, &stop)) { + return NULL; + } - if (stop - start <= 0) { - return PyList_New(0); + if (start < 0 || stop < 0) { + /* only get the length for negative values */ + Py_ssize_t len = bpy_bmelemseq_length(self); + if (start < 0) { + start += len; } - else { - return bpy_bmelemseq_subscript_slice(self, start, stop); + if (stop < 0) { + stop += len; } } + + if (stop - start <= 0) { + return PyList_New(0); + } + + return bpy_bmelemseq_subscript_slice(self, start, stop); } - else { - PyErr_SetString(PyExc_AttributeError, "BMElemSeq[key]: invalid key, key must be an int"); - return NULL; - } + + PyErr_SetString(PyExc_AttributeError, "BMElemSeq[key]: invalid key, key must be an int"); + return NULL; } static int bpy_bmelemseq_contains(BPy_BMElemSeq *self, PyObject *value) @@ -3395,9 +3360,8 @@ static PyObject *bpy_bmiter_next(BPy_BMIter *self) PyErr_SetNone(PyExc_StopIteration); return NULL; } - else { - return (PyObject *)BPy_BMElem_CreatePyObject(self->bm, ele); - } + + return (PyObject *)BPy_BMElem_CreatePyObject(self->bm, ele); } /* Dealloc Functions @@ -3532,9 +3496,8 @@ static PyObject *bpy_bmesh_repr(BPy_BMesh *self) bm->totface, bm->totloop); } - else { - return PyUnicode_FromFormat("", self); - } + + return PyUnicode_FromFormat("", self); } static PyObject *bpy_bmvert_repr(BPy_BMVert *self) @@ -3545,9 +3508,8 @@ static PyObject *bpy_bmvert_repr(BPy_BMVert *self) BMVert *v = self->v; return PyUnicode_FromFormat("", v, BM_elem_index_get(v)); } - else { - return PyUnicode_FromFormat("", self); - } + + return PyUnicode_FromFormat("", self); } static PyObject *bpy_bmedge_repr(BPy_BMEdge *self) @@ -3564,9 +3526,8 @@ static PyObject *bpy_bmedge_repr(BPy_BMEdge *self) e->v2, BM_elem_index_get(e->v2)); } - else { - return PyUnicode_FromFormat("", self); - } + + return PyUnicode_FromFormat("", self); } static PyObject *bpy_bmface_repr(BPy_BMFace *self) @@ -3578,9 +3539,8 @@ static PyObject *bpy_bmface_repr(BPy_BMFace *self) return PyUnicode_FromFormat( "", f, BM_elem_index_get(f), f->len); } - else { - return PyUnicode_FromFormat("", self); - } + + return PyUnicode_FromFormat("", self); } static PyObject *bpy_bmloop_repr(BPy_BMLoop *self) @@ -3599,9 +3559,8 @@ static PyObject *bpy_bmloop_repr(BPy_BMLoop *self) l->f, BM_elem_index_get(l->f)); } - else { - return PyUnicode_FromFormat("", self); - } + + return PyUnicode_FromFormat("", self); } /* Types @@ -4054,12 +4013,10 @@ int bpy_bm_generic_valid_check(BPy_BMGeneric *self) return 0; } - else { - PyErr_Format(PyExc_ReferenceError, - "BMesh data of type %.200s has been removed", - Py_TYPE(self)->tp_name); - return -1; - } + + PyErr_Format( + PyExc_ReferenceError, "BMesh data of type %.200s has been removed", Py_TYPE(self)->tp_name); + return -1; } int bpy_bm_generic_valid_check_source(BMesh *bm_source, @@ -4079,16 +4036,15 @@ int bpy_bm_generic_valid_check_source(BMesh *bm_source, 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; - } + + 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; } } } diff --git a/source/blender/python/bmesh/bmesh_py_types_customdata.c b/source/blender/python/bmesh/bmesh_py_types_customdata.c index 8615da653ae..51616030d30 100644 --- a/source/blender/python/bmesh/bmesh_py_types_customdata.c +++ b/source/blender/python/bmesh/bmesh_py_types_customdata.c @@ -67,10 +67,9 @@ static CustomDataLayer *bpy_bmlayeritem_get(BPy_BMLayerItem *self) if (index_absolute != -1) { return &data->layers[index_absolute]; } - else { - PyErr_SetString(PyExc_RuntimeError, "layer has become invalid"); - return NULL; - } + + PyErr_SetString(PyExc_RuntimeError, "layer has become invalid"); + return NULL; } /* py-type definitions @@ -142,9 +141,8 @@ static PyObject *bpy_bmlayercollection_active_get(BPy_BMLayerItem *self, void *U if (index != -1) { return BPy_BMLayerItem_CreatePyObject(self->bm, self->htype, self->type, index); } - else { - Py_RETURN_NONE; - } + + Py_RETURN_NONE; } PyDoc_STRVAR( @@ -169,9 +167,8 @@ static PyObject *bpy_bmlayeritem_name_get(BPy_BMLayerItem *self, void *UNUSED(fl if (layer) { return PyUnicode_FromString(layer->name); } - else { - return NULL; - } + + return NULL; } static PyGetSetDef bpy_bmlayeraccess_vert_getseters[] = { @@ -617,16 +614,15 @@ static PyObject *bpy_bmlayercollection_get(BPy_BMLayerCollection *self, PyObject if (!PyArg_ParseTuple(args, "s|O:get", &key, &def)) { return NULL; } - else { - CustomData *data; - int index; - data = bpy_bm_customdata_get(self->bm, self->htype); - index = CustomData_get_named_layer(data, self->type, key); /* type relative */ + CustomData *data; + int index; - if (index != -1) { - return BPy_BMLayerItem_CreatePyObject(self->bm, self->htype, self->type, index); - } + data = bpy_bm_customdata_get(self->bm, self->htype); + index = CustomData_get_named_layer(data, self->type, key); /* type relative */ + + if (index != -1) { + return BPy_BMLayerItem_CreatePyObject(self->bm, self->htype, self->type, index); } return Py_INCREF_RET(def); @@ -689,10 +685,9 @@ static PyObject *bpy_bmlayercollection_subscript_str(BPy_BMLayerCollection *self if (index != -1) { return BPy_BMLayerItem_CreatePyObject(self->bm, self->htype, self->type, index); } - else { - PyErr_Format(PyExc_KeyError, "BMLayerCollection[key]: key \"%.200s\" not found", keyname); - return NULL; - } + + PyErr_Format(PyExc_KeyError, "BMLayerCollection[key]: key \"%.200s\" not found", keyname); + return NULL; } static PyObject *bpy_bmlayercollection_subscript_int(BPy_BMLayerCollection *self, int keynum) @@ -750,62 +745,58 @@ static PyObject *bpy_bmlayercollection_subscript(BPy_BMLayerCollection *self, Py if (PyUnicode_Check(key)) { return bpy_bmlayercollection_subscript_str(self, _PyUnicode_AsString(key)); } - else if (PyIndex_Check(key)) { + if (PyIndex_Check(key)) { Py_ssize_t i = PyNumber_AsSsize_t(key, PyExc_IndexError); if (i == -1 && PyErr_Occurred()) { return NULL; } return bpy_bmlayercollection_subscript_int(self, i); } - else if (PySlice_Check(key)) { + if (PySlice_Check(key)) { PySliceObject *key_slice = (PySliceObject *)key; Py_ssize_t step = 1; if (key_slice->step != Py_None && !_PyEval_SliceIndex(key, &step)) { return NULL; } - else if (step != 1) { + if (step != 1) { PyErr_SetString(PyExc_TypeError, "BMLayerCollection[slice]: slice steps not supported"); return NULL; } - else if (key_slice->start == Py_None && key_slice->stop == Py_None) { + if (key_slice->start == Py_None && key_slice->stop == Py_None) { return bpy_bmlayercollection_subscript_slice(self, 0, PY_SSIZE_T_MAX); } - else { - Py_ssize_t start = 0, stop = PY_SSIZE_T_MAX; - /* avoid PySlice_GetIndicesEx because it needs to know the length ahead of time. */ - if (key_slice->start != Py_None && !_PyEval_SliceIndex(key_slice->start, &start)) { - return NULL; - } - if (key_slice->stop != Py_None && !_PyEval_SliceIndex(key_slice->stop, &stop)) { - return NULL; - } + Py_ssize_t start = 0, stop = PY_SSIZE_T_MAX; - if (start < 0 || stop < 0) { - /* only get the length for negative values */ - Py_ssize_t len = bpy_bmlayercollection_length(self); - if (start < 0) { - start += len; - } - if (stop < 0) { - stop += len; - } - } + /* avoid PySlice_GetIndicesEx because it needs to know the length ahead of time. */ + if (key_slice->start != Py_None && !_PyEval_SliceIndex(key_slice->start, &start)) { + return NULL; + } + if (key_slice->stop != Py_None && !_PyEval_SliceIndex(key_slice->stop, &stop)) { + return NULL; + } - if (stop - start <= 0) { - return PyTuple_New(0); + if (start < 0 || stop < 0) { + /* only get the length for negative values */ + Py_ssize_t len = bpy_bmlayercollection_length(self); + if (start < 0) { + start += len; } - else { - return bpy_bmlayercollection_subscript_slice(self, start, stop); + if (stop < 0) { + stop += len; } } + + if (stop - start <= 0) { + return PyTuple_New(0); + } + + return bpy_bmlayercollection_subscript_slice(self, start, stop); } - else { - PyErr_SetString(PyExc_AttributeError, - "BMLayerCollection[key]: invalid key, key must be an int"); - return NULL; - } + + PyErr_SetString(PyExc_AttributeError, "BMLayerCollection[key]: invalid key, key must be an int"); + return NULL; } static int bpy_bmlayercollection_contains(BPy_BMLayerCollection *self, PyObject *value) @@ -1024,11 +1015,11 @@ static void *bpy_bmlayeritem_ptr_get(BPy_BMElem *py_ele, BPy_BMLayerItem *py_lay PyErr_SetString(PyExc_AttributeError, "BMElem[key]: invalid key, must be a BMLayerItem"); return NULL; } - else if (UNLIKELY(py_ele->bm != py_layer->bm)) { + if (UNLIKELY(py_ele->bm != py_layer->bm)) { PyErr_SetString(PyExc_ValueError, "BMElem[layer]: layer is from another mesh"); return NULL; } - else if (UNLIKELY(ele->head.htype != py_layer->htype)) { + if (UNLIKELY(ele->head.htype != py_layer->htype)) { char namestr_1[32], namestr_2[32]; PyErr_Format(PyExc_ValueError, "Layer/Element type mismatch, expected %.200s got layer type %.200s", @@ -1046,9 +1037,8 @@ static void *bpy_bmlayeritem_ptr_get(BPy_BMElem *py_ele, BPy_BMLayerItem *py_lay PyErr_SetString(PyExc_KeyError, "BMElem[key]: layer not found"); return NULL; } - else { - return value; - } + + return value; } /** diff --git a/source/blender/python/bmesh/bmesh_py_types_meshdata.c b/source/blender/python/bmesh/bmesh_py_types_meshdata.c index 82b6cf5c3d5..f42348975c9 100644 --- a/source/blender/python/bmesh/bmesh_py_types_meshdata.c +++ b/source/blender/python/bmesh/bmesh_py_types_meshdata.c @@ -65,9 +65,8 @@ static int bpy_bmloopuv_uv_set(BPy_BMLoopUV *self, PyObject *value, void *UNUSED copy_v2_v2(self->data->uv, tvec); return 0; } - else { - return -1; - } + + return -1; } PyDoc_STRVAR(bpy_bmloopuv_flag__pin_uv_doc, "UV pin state.\n\n:type: boolean"); @@ -136,10 +135,9 @@ int BPy_BMLoopUV_AssignPyObject(struct MLoopUV *mloopuv, PyObject *value) PyErr_Format(PyExc_TypeError, "expected BMLoopUV, not a %.200s", Py_TYPE(value)->tp_name); return -1; } - else { - *((MLoopUV *)mloopuv) = *(((BPy_BMLoopUV *)value)->data); - return 0; - } + + *((MLoopUV *)mloopuv) = *(((BPy_BMLoopUV *)value)->data); + return 0; } PyObject *BPy_BMLoopUV_CreatePyObject(struct MLoopUV *mloopuv) @@ -174,9 +172,8 @@ static int bpy_bmvertskin_radius_set(BPy_BMVertSkin *self, PyObject *value, void copy_v2_v2(self->data->radius, tvec); return 0; } - else { - return -1; - } + + return -1; } PyDoc_STRVAR(bpy_bmvertskin_flag__use_root_doc, @@ -251,10 +248,9 @@ int BPy_BMVertSkin_AssignPyObject(struct MVertSkin *mvertskin, PyObject *value) PyErr_Format(PyExc_TypeError, "expected BMVertSkin, not a %.200s", Py_TYPE(value)->tp_name); return -1; } - else { - *((MVertSkin *)mvertskin) = *(((BPy_BMVertSkin *)value)->data); - return 0; - } + + *((MVertSkin *)mvertskin) = *(((BPy_BMVertSkin *)value)->data); + return 0; } PyObject *BPy_BMVertSkin_CreatePyObject(struct MVertSkin *mvertskin) @@ -351,9 +347,8 @@ int BPy_BMLoopColor_AssignPyObject(struct MLoopCol *mloopcol, PyObject *value) mloopcol_from_float(mloopcol, tvec); return 0; } - else { - return -1; - } + + return -1; } PyObject *BPy_BMLoopColor_CreatePyObject(struct MLoopCol *data) @@ -416,25 +411,22 @@ static PyObject *bpy_bmdeformvert_subscript(BPy_BMDeformVert *self, PyObject *ke if (i == -1 && PyErr_Occurred()) { return NULL; } - else { - MDeformWeight *dw = BKE_defvert_find_index(self->data, i); - if (dw == NULL) { - PyErr_SetString(PyExc_KeyError, - "BMDeformVert[key] = x: " - "key not found"); - return NULL; - } - else { - return PyFloat_FromDouble(dw->weight); - } + MDeformWeight *dw = BKE_defvert_find_index(self->data, i); + + if (dw == NULL) { + PyErr_SetString(PyExc_KeyError, + "BMDeformVert[key] = x: " + "key not found"); + return NULL; } + + return PyFloat_FromDouble(dw->weight); } - else { - PyErr_Format( - PyExc_TypeError, "BMDeformVert keys must be integers, not %.200s", Py_TYPE(key)->tp_name); - return NULL; - } + + PyErr_Format( + PyExc_TypeError, "BMDeformVert keys must be integers, not %.200s", Py_TYPE(key)->tp_name); + return NULL; } static int bpy_bmdeformvert_ass_subscript(BPy_BMDeformVert *self, PyObject *key, PyObject *value) @@ -455,18 +447,17 @@ static int bpy_bmdeformvert_ass_subscript(BPy_BMDeformVert *self, PyObject *key, "weight keys can't be negative"); return -1; } - else { - MDeformWeight *dw = BKE_defvert_ensure_index(self->data, i); - const float f = PyFloat_AsDouble(value); - if (f == -1 && PyErr_Occurred()) { // parsed key not a number - PyErr_SetString(PyExc_TypeError, - "BMDeformVert[key] = x: " - "assigned value not a number"); - return -1; - } - dw->weight = clamp_f(f, 0.0f, 1.0f); + MDeformWeight *dw = BKE_defvert_ensure_index(self->data, i); + const float f = PyFloat_AsDouble(value); + if (f == -1 && PyErr_Occurred()) { // parsed key not a number + PyErr_SetString(PyExc_TypeError, + "BMDeformVert[key] = x: " + "assigned value not a number"); + return -1; } + + dw->weight = clamp_f(f, 0.0f, 1.0f); } else { /* del dvert[group_index] */ @@ -482,11 +473,10 @@ static int bpy_bmdeformvert_ass_subscript(BPy_BMDeformVert *self, PyObject *key, return 0; } - else { - PyErr_Format( - PyExc_TypeError, "BMDeformVert keys must be integers, not %.200s", Py_TYPE(key)->tp_name); - return -1; - } + + PyErr_Format( + PyExc_TypeError, "BMDeformVert keys must be integers, not %.200s", Py_TYPE(key)->tp_name); + return -1; } static int bpy_bmdeformvert_contains(BPy_BMDeformVert *self, PyObject *value) @@ -616,16 +606,14 @@ static PyObject *bpy_bmdeformvert_get(BPy_BMDeformVert *self, PyObject *args) if (!PyArg_ParseTuple(args, "i|O:get", &key, &def)) { return NULL; } - else { - MDeformWeight *dw = BKE_defvert_find_index(self->data, key); - if (dw) { - return PyFloat_FromDouble(dw->weight); - } - else { - return Py_INCREF_RET(def); - } + MDeformWeight *dw = BKE_defvert_find_index(self->data, key); + + if (dw) { + return PyFloat_FromDouble(dw->weight); } + + return Py_INCREF_RET(def); } PyDoc_STRVAR(bpy_bmdeformvert_clear_doc, @@ -675,13 +663,12 @@ int BPy_BMDeformVert_AssignPyObject(struct MDeformVert *dvert, PyObject *value) PyErr_Format(PyExc_TypeError, "expected BMDeformVert, not a %.200s", Py_TYPE(value)->tp_name); return -1; } - else { - MDeformVert *dvert_src = ((BPy_BMDeformVert *)value)->data; - if (LIKELY(dvert != dvert_src)) { - BKE_defvert_copy(dvert, dvert_src); - } - return 0; + + MDeformVert *dvert_src = ((BPy_BMDeformVert *)value)->data; + if (LIKELY(dvert != dvert_src)) { + BKE_defvert_copy(dvert, dvert_src); } + return 0; } PyObject *BPy_BMDeformVert_CreatePyObject(struct MDeformVert *dvert) diff --git a/source/blender/python/bmesh/bmesh_py_types_select.c b/source/blender/python/bmesh/bmesh_py_types_select.c index 5e064453a04..d69668341ff 100644 --- a/source/blender/python/bmesh/bmesh_py_types_select.c +++ b/source/blender/python/bmesh/bmesh_py_types_select.c @@ -51,9 +51,8 @@ static PyObject *bpy_bmeditselseq_active_get(BPy_BMEditSelSeq *self, void *UNUSE if ((ese = self->bm->selected.last)) { return BPy_BMElem_CreatePyObject(self->bm, &ese->ele->head); } - else { - Py_RETURN_NONE; - } + + Py_RETURN_NONE; } static PyGetSetDef bpy_bmeditselseq_getseters[] = { @@ -196,10 +195,9 @@ static PyObject *bpy_bmeditselseq_subscript_int(BPy_BMEditSelSeq *self, int keyn if (ese) { return BPy_BMElem_CreatePyObject(self->bm, &ese->ele->head); } - else { - PyErr_Format(PyExc_IndexError, "BMElemSeq[index]: index %d out of range", keynum); - return NULL; - } + + PyErr_Format(PyExc_IndexError, "BMElemSeq[index]: index %d out of range", keynum); + return NULL; } static PyObject *bpy_bmeditselseq_subscript_slice(BPy_BMEditSelSeq *self, @@ -254,54 +252,51 @@ static PyObject *bpy_bmeditselseq_subscript(BPy_BMEditSelSeq *self, PyObject *ke } return bpy_bmeditselseq_subscript_int(self, i); } - else if (PySlice_Check(key)) { + if (PySlice_Check(key)) { PySliceObject *key_slice = (PySliceObject *)key; Py_ssize_t step = 1; if (key_slice->step != Py_None && !_PyEval_SliceIndex(key, &step)) { return NULL; } - else if (step != 1) { + if (step != 1) { PyErr_SetString(PyExc_TypeError, "BMElemSeq[slice]: slice steps not supported"); return NULL; } - else if (key_slice->start == Py_None && key_slice->stop == Py_None) { + if (key_slice->start == Py_None && key_slice->stop == Py_None) { return bpy_bmeditselseq_subscript_slice(self, 0, PY_SSIZE_T_MAX); } - else { - Py_ssize_t start = 0, stop = PY_SSIZE_T_MAX; - /* avoid PySlice_GetIndicesEx because it needs to know the length ahead of time. */ - if (key_slice->start != Py_None && !_PyEval_SliceIndex(key_slice->start, &start)) { - return NULL; - } - if (key_slice->stop != Py_None && !_PyEval_SliceIndex(key_slice->stop, &stop)) { - return NULL; - } + Py_ssize_t start = 0, stop = PY_SSIZE_T_MAX; - if (start < 0 || stop < 0) { - /* only get the length for negative values */ - Py_ssize_t len = bpy_bmeditselseq_length(self); - if (start < 0) { - start += len; - } - if (stop < 0) { - stop += len; - } - } + /* avoid PySlice_GetIndicesEx because it needs to know the length ahead of time. */ + if (key_slice->start != Py_None && !_PyEval_SliceIndex(key_slice->start, &start)) { + return NULL; + } + if (key_slice->stop != Py_None && !_PyEval_SliceIndex(key_slice->stop, &stop)) { + return NULL; + } - if (stop - start <= 0) { - return PyList_New(0); + if (start < 0 || stop < 0) { + /* only get the length for negative values */ + Py_ssize_t len = bpy_bmeditselseq_length(self); + if (start < 0) { + start += len; } - else { - return bpy_bmeditselseq_subscript_slice(self, start, stop); + if (stop < 0) { + stop += len; } } + + if (stop - start <= 0) { + return PyList_New(0); + } + + return bpy_bmeditselseq_subscript_slice(self, start, stop); } - else { - PyErr_SetString(PyExc_AttributeError, "BMElemSeq[key]: invalid key, key must be an int"); - return NULL; - } + + PyErr_SetString(PyExc_AttributeError, "BMElemSeq[key]: invalid key, key must be an int"); + return NULL; } static int bpy_bmeditselseq_contains(BPy_BMEditSelSeq *self, PyObject *value) @@ -358,10 +353,9 @@ static PyObject *bpy_bmeditseliter_next(BPy_BMEditSelIter *self) PyErr_SetNone(PyExc_StopIteration); return NULL; } - else { - self->ese = ese->next; - return (PyObject *)BPy_BMElem_CreatePyObject(self->bm, &ese->ele->head); - } + + self->ese = ese->next; + return (PyObject *)BPy_BMElem_CreatePyObject(self->bm, &ese->ele->head); } PyTypeObject BPy_BMEditSelSeq_Type; diff --git a/source/blender/python/bmesh/bmesh_py_utils.c b/source/blender/python/bmesh/bmesh_py_utils.c index 9b207693e37..eab9ab226e4 100644 --- a/source/blender/python/bmesh/bmesh_py_utils.c +++ b/source/blender/python/bmesh/bmesh_py_utils.c @@ -91,11 +91,10 @@ static PyObject *bpy_bm_utils_vert_collapse_edge(PyObject *UNUSED(self), PyObjec if (e_new) { return BPy_BMEdge_CreatePyObject(bm, e_new); } - else { - PyErr_SetString(PyExc_ValueError, - "vert_collapse_edge(vert, edge): no new edge created, internal error"); - return NULL; - } + + PyErr_SetString(PyExc_ValueError, + "vert_collapse_edge(vert, edge): no new edge created, internal error"); + return NULL; } PyDoc_STRVAR(bpy_bm_utils_vert_collapse_faces_doc, @@ -158,11 +157,10 @@ static PyObject *bpy_bm_utils_vert_collapse_faces(PyObject *UNUSED(self), PyObje if (e_new) { return BPy_BMEdge_CreatePyObject(bm, e_new); } - else { - PyErr_SetString(PyExc_ValueError, - "vert_collapse_faces(vert, edge): no new edge created, internal error"); - return NULL; - } + + PyErr_SetString(PyExc_ValueError, + "vert_collapse_faces(vert, edge): no new edge created, internal error"); + return NULL; } PyDoc_STRVAR(bpy_bm_utils_vert_dissolve_doc, @@ -360,11 +358,10 @@ static PyObject *bpy_bm_utils_edge_split(PyObject *UNUSED(self), PyObject *args) ret, BPy_BMEdge_CreatePyObject(bm, e_new), BPy_BMVert_CreatePyObject(bm, v_new)); return ret; } - else { - PyErr_SetString(PyExc_ValueError, - "edge_split(edge, vert): couldn't split the edge, internal error"); - return NULL; - } + + PyErr_SetString(PyExc_ValueError, + "edge_split(edge, vert): couldn't split the edge, internal error"); + return NULL; } PyDoc_STRVAR(bpy_bm_utils_edge_rotate_doc, @@ -401,9 +398,8 @@ static PyObject *bpy_bm_utils_edge_rotate(PyObject *UNUSED(self), PyObject *args if (e_new) { return BPy_BMEdge_CreatePyObject(bm, e_new); } - else { - Py_RETURN_NONE; - } + + Py_RETURN_NONE; } PyDoc_STRVAR( @@ -534,10 +530,9 @@ static PyObject *bpy_bm_utils_face_split(PyObject *UNUSED(self), PyObject *args, ret, BPy_BMFace_CreatePyObject(bm, f_new), BPy_BMLoop_CreatePyObject(bm, l_new)); return ret; } - else { - PyErr_SetString(PyExc_ValueError, "face_split(...): couldn't split the face, internal error"); - return NULL; - } + + PyErr_SetString(PyExc_ValueError, "face_split(...): couldn't split the face, internal error"); + return NULL; } PyDoc_STRVAR(bpy_bm_utils_face_split_edgenet_doc, @@ -617,11 +612,10 @@ static PyObject *bpy_bm_utils_face_split_edgenet(PyObject *UNUSED(self), } return ret; } - else { - PyErr_SetString(PyExc_ValueError, - "face_split_edgenet(...): couldn't split the face, internal error"); - return NULL; - } + + PyErr_SetString(PyExc_ValueError, + "face_split_edgenet(...): couldn't split the face, internal error"); + return NULL; } PyDoc_STRVAR(bpy_bm_utils_face_join_doc, @@ -664,9 +658,8 @@ static PyObject *bpy_bm_utils_face_join(PyObject *UNUSED(self), PyObject *args) if (f_new) { return BPy_BMFace_CreatePyObject(bm, f_new); } - else { - Py_RETURN_NONE; - } + + Py_RETURN_NONE; } PyDoc_STRVAR( @@ -721,9 +714,8 @@ static PyObject *bpy_bm_utils_face_vert_separate(PyObject *UNUSED(self), PyObjec if (v_new != v_old) { return BPy_BMVert_CreatePyObject(bm, v_new); } - else { - Py_RETURN_NONE; - } + + Py_RETURN_NONE; } PyDoc_STRVAR(bpy_bm_utils_face_flip_doc, @@ -782,9 +774,8 @@ static PyObject *bpy_bm_utils_loop_separate(PyObject *UNUSED(self), BPy_BMLoop * if (v_new != v_old) { return BPy_BMVert_CreatePyObject(bm, v_new); } - else { - Py_RETURN_NONE; - } + + Py_RETURN_NONE; } static struct PyMethodDef BPy_BM_utils_methods[] = { diff --git a/source/blender/python/generic/bgl.c b/source/blender/python/generic/bgl.c index 2ad2794c76f..32c788d0793 100644 --- a/source/blender/python/generic/bgl.c +++ b/source/blender/python/generic/bgl.c @@ -415,10 +415,9 @@ typedef struct BufferOrOffset { if (ret_str) { \ return PyUnicode_FromString((const char *)ret_str); \ } \ - else { \ - PyErr_SetString(PyExc_AttributeError, "could not get opengl string"); \ - return NULL; \ - } +\ + PyErr_SetString(PyExc_AttributeError, "could not get opengl string"); \ + return NULL; /** \} */ @@ -705,7 +704,7 @@ static int BGL_BufferOrOffsetConverter(PyObject *object, BufferOrOffset *buffer) buffer->offset = NULL; return 1; } - else if (PyNumber_Check(object)) { + if (PyNumber_Check(object)) { Py_ssize_t offset = PyNumber_AsSsize_t(object, PyExc_IndexError); if (offset == -1 && PyErr_Occurred()) { return 0; @@ -715,15 +714,14 @@ static int BGL_BufferOrOffsetConverter(PyObject *object, BufferOrOffset *buffer) buffer->offset = (void *)offset; return 1; } - else if (PyObject_TypeCheck(object, &BGL_bufferType)) { + if (PyObject_TypeCheck(object, &BGL_bufferType)) { buffer->buffer = (Buffer *)object; buffer->offset = NULL; return 1; } - else { - PyErr_SetString(PyExc_TypeError, "expected a bgl.Buffer or None"); - return 0; - } + + PyErr_SetString(PyExc_TypeError, "expected a bgl.Buffer or None"); + return 0; } #define MAX_DIMENSIONS 256 @@ -766,7 +764,7 @@ static PyObject *Buffer_new(PyTypeObject *UNUSED(type), PyObject *args, PyObject "too many dimensions, max is " STRINGIFY(MAX_DIMENSIONS)); return NULL; } - else if (ndimensions < 1) { + if (ndimensions < 1) { PyErr_SetString(PyExc_AttributeError, "sequence must have at least one dimension"); return NULL; } @@ -913,9 +911,8 @@ static int Buffer_ass_item(Buffer *self, int i, PyObject *v) Py_DECREF(row); return ret; } - else { - return -1; - } + + return -1; } switch (self->type) { @@ -996,7 +993,7 @@ static PyObject *Buffer_subscript(Buffer *self, PyObject *item) } return Buffer_item(self, i); } - else if (PySlice_Check(item)) { + if (PySlice_Check(item)) { Py_ssize_t start, stop, step, slicelength; if (PySlice_GetIndicesEx(item, self->dimensions[0], &start, &stop, &step, &slicelength) < 0) { @@ -1006,19 +1003,17 @@ static PyObject *Buffer_subscript(Buffer *self, PyObject *item) if (slicelength <= 0) { return PyTuple_New(0); } - else if (step == 1) { + if (step == 1) { return Buffer_slice(self, start, stop); } - else { - PyErr_SetString(PyExc_IndexError, "slice steps not supported with vectors"); - return NULL; - } - } - else { - PyErr_Format( - PyExc_TypeError, "buffer indices must be integers, not %.200s", Py_TYPE(item)->tp_name); + + PyErr_SetString(PyExc_IndexError, "slice steps not supported with vectors"); return NULL; } + + PyErr_Format( + PyExc_TypeError, "buffer indices must be integers, not %.200s", Py_TYPE(item)->tp_name); + return NULL; } static int Buffer_ass_subscript(Buffer *self, PyObject *item, PyObject *value) @@ -1033,7 +1028,7 @@ static int Buffer_ass_subscript(Buffer *self, PyObject *item, PyObject *value) } return Buffer_ass_item(self, i, value); } - else if (PySlice_Check(item)) { + if (PySlice_Check(item)) { Py_ssize_t start, stop, step, slicelength; if (PySlice_GetIndicesEx(item, self->dimensions[0], &start, &stop, &step, &slicelength) < 0) { @@ -1043,16 +1038,14 @@ static int Buffer_ass_subscript(Buffer *self, PyObject *item, PyObject *value) if (step == 1) { return Buffer_ass_slice(self, start, stop, value); } - else { - PyErr_SetString(PyExc_IndexError, "slice steps not supported with vectors"); - return -1; - } - } - else { - PyErr_Format( - PyExc_TypeError, "buffer indices must be integers, not %.200s", Py_TYPE(item)->tp_name); + + PyErr_SetString(PyExc_IndexError, "slice steps not supported with vectors"); return -1; } + + PyErr_Format( + PyExc_TypeError, "buffer indices must be integers, not %.200s", Py_TYPE(item)->tp_name); + return -1; } static void Buffer_dealloc(Buffer *self) diff --git a/source/blender/python/generic/idprop_py_api.c b/source/blender/python/generic/idprop_py_api.c index cabeeba18b9..615ce514a3e 100644 --- a/source/blender/python/generic/idprop_py_api.c +++ b/source/blender/python/generic/idprop_py_api.c @@ -51,13 +51,12 @@ static PyObject *idprop_py_from_idp_string(const IDProperty *prop) if (prop->subtype == IDP_STRING_SUB_BYTE) { return PyBytes_FromStringAndSize(IDP_String(prop), prop->len); } - else { + #ifdef USE_STRING_COERCE - return PyC_UnicodeFromByteAndSize(IDP_Array(prop), prop->len - 1); + return PyC_UnicodeFromByteAndSize(IDP_Array(prop), prop->len - 1); #else - return PyUnicode_FromStringAndSize(IDP_String(prop), prop->len - 1); + return PyUnicode_FromStringAndSize(IDP_String(prop), prop->len - 1); #endif - } } static PyObject *idprop_py_from_idp_int(const IDProperty *prop) @@ -479,10 +478,10 @@ static IDProperty *idp_from_PySequence_Buffer(const char *name, Py_buffer *buffe /* should never happen as the type has been checked before */ return NULL; } - else { - val.array.type = id_type; - val.array.len = buffer->len / buffer->itemsize; - } + + val.array.type = id_type; + val.array.len = buffer->len / buffer->itemsize; + prop = IDP_New(IDP_ARRAY, &val, name); memcpy(IDP_Array(prop), buffer->buf, buffer->len); return prop; @@ -576,17 +575,15 @@ static IDProperty *idp_from_PySequence(const char *name, PyObject *ob) PyBuffer_Release(&buffer); return prop; } - else { - PyObject *ob_seq_fast = PySequence_Fast(ob, "py -> idprop"); - if (ob_seq_fast != NULL) { - IDProperty *prop = idp_from_PySequence_Fast(name, ob_seq_fast); - Py_DECREF(ob_seq_fast); - return prop; - } - else { - return NULL; - } + + PyObject *ob_seq_fast = PySequence_Fast(ob, "py -> idprop"); + if (ob_seq_fast != NULL) { + IDProperty *prop = idp_from_PySequence_Fast(name, ob_seq_fast); + Py_DECREF(ob_seq_fast); + return prop; } + + return NULL; } static IDProperty *idp_from_PyMapping(const char *name, PyObject *ob) @@ -641,29 +638,28 @@ static IDProperty *idp_from_PyObject(PyObject *name_obj, PyObject *ob) if (PyFloat_Check(ob)) { return idp_from_PyFloat(name, ob); } - else if (PyLong_Check(ob)) { + if (PyLong_Check(ob)) { return idp_from_PyLong(name, ob); } - else if (PyUnicode_Check(ob)) { + if (PyUnicode_Check(ob)) { return idp_from_PyUnicode(name, ob); } - else if (PyBytes_Check(ob)) { + if (PyBytes_Check(ob)) { return idp_from_PyBytes(name, ob); } - else if (PySequence_Check(ob)) { + if (PySequence_Check(ob)) { return idp_from_PySequence(name, ob); } - else if (ob == Py_None || pyrna_id_CheckPyObject(ob)) { + if (ob == Py_None || pyrna_id_CheckPyObject(ob)) { return idp_from_DatablockPointer(name, ob); } - else if (PyMapping_Check(ob)) { + if (PyMapping_Check(ob)) { return idp_from_PyMapping(name, ob); } - else { - PyErr_Format( - PyExc_TypeError, "invalid id-property type %.200s not supported", Py_TYPE(ob)->tp_name); - return NULL; - } + + PyErr_Format( + PyExc_TypeError, "invalid id-property type %.200s not supported", Py_TYPE(ob)->tp_name); + return NULL; } /** \} */ @@ -736,21 +732,19 @@ int BPy_Wrap_SetMapItem(IDProperty *prop, PyObject *key, PyObject *val) IDP_FreeFromGroup(prop, pkey); return 0; } - else { - PyErr_SetString(PyExc_KeyError, "property not found in group"); - return -1; - } - } - else { - bool ok; - ok = BPy_IDProperty_Map_ValidateAndCreate(key, prop, val); - if (ok == false) { - return -1; - } - - return 0; + PyErr_SetString(PyExc_KeyError, "property not found in group"); + return -1; } + + bool ok; + + ok = BPy_IDProperty_Map_ValidateAndCreate(key, prop, val); + if (ok == false) { + return -1; + } + + return 0; } static int BPy_IDGroup_Map_SetItem(BPy_IDProperty *self, PyObject *key, PyObject *val) @@ -1485,7 +1479,7 @@ static PyObject *BPy_IDArray_subscript(BPy_IDArray *self, PyObject *item) } return BPy_IDArray_GetItem(self, i); } - else if (PySlice_Check(item)) { + if (PySlice_Check(item)) { Py_ssize_t start, stop, step, slicelength; if (PySlice_GetIndicesEx(item, self->prop->len, &start, &stop, &step, &slicelength) < 0) { @@ -1495,21 +1489,19 @@ static PyObject *BPy_IDArray_subscript(BPy_IDArray *self, PyObject *item) if (slicelength <= 0) { return PyTuple_New(0); } - else if (step == 1) { + if (step == 1) { return BPy_IDArray_slice(self, start, stop); } - else { - PyErr_SetString(PyExc_TypeError, "slice steps not supported with vectors"); - return NULL; - } - } - else { - PyErr_Format(PyExc_TypeError, - "vector indices must be integers, not %.200s", - __func__, - Py_TYPE(item)->tp_name); + + PyErr_SetString(PyExc_TypeError, "slice steps not supported with vectors"); return NULL; } + + PyErr_Format(PyExc_TypeError, + "vector indices must be integers, not %.200s", + __func__, + Py_TYPE(item)->tp_name); + return NULL; } static int BPy_IDArray_ass_subscript(BPy_IDArray *self, PyObject *item, PyObject *value) @@ -1524,7 +1516,7 @@ static int BPy_IDArray_ass_subscript(BPy_IDArray *self, PyObject *item, PyObject } return BPy_IDArray_SetItem(self, i, value); } - else if (PySlice_Check(item)) { + if (PySlice_Check(item)) { Py_ssize_t start, stop, step, slicelength; if (PySlice_GetIndicesEx(item, self->prop->len, &start, &stop, &step, &slicelength) < 0) { @@ -1534,16 +1526,14 @@ static int BPy_IDArray_ass_subscript(BPy_IDArray *self, PyObject *item, PyObject if (step == 1) { return BPy_IDArray_ass_slice(self, start, stop, value); } - else { - PyErr_SetString(PyExc_TypeError, "slice steps not supported with vectors"); - return -1; - } - } - else { - PyErr_Format( - PyExc_TypeError, "vector indices must be integers, not %.200s", Py_TYPE(item)->tp_name); + + PyErr_SetString(PyExc_TypeError, "slice steps not supported with vectors"); return -1; } + + PyErr_Format( + PyExc_TypeError, "vector indices must be integers, not %.200s", Py_TYPE(item)->tp_name); + return -1; } static PyMappingMethods BPy_IDArray_AsMapping = { @@ -1709,14 +1699,12 @@ static PyObject *BPy_Group_Iter_Next(BPy_IDGroup_Iter *self) BPy_IDGroup_WrapData(self->group->id, cur, self->group->prop)); return ret; } - else { - return PyUnicode_FromString(cur->name); - } - } - else { - PyErr_SetNone(PyExc_StopIteration); - return NULL; + + return PyUnicode_FromString(cur->name); } + + PyErr_SetNone(PyExc_StopIteration); + return NULL; } PyTypeObject BPy_IDGroup_Iter_Type = { diff --git a/source/blender/python/generic/imbuf_py_api.c b/source/blender/python/generic/imbuf_py_api.c index 8a02638786d..3536236754e 100644 --- a/source/blender/python/generic/imbuf_py_api.c +++ b/source/blender/python/generic/imbuf_py_api.c @@ -57,11 +57,10 @@ static int py_imbuf_valid_check(Py_ImBuf *self) if (LIKELY(self->ibuf)) { return 0; } - else { - PyErr_Format( - PyExc_ReferenceError, "ImBuf data of type %.200s has been freed", Py_TYPE(self)->tp_name); - return -1; - } + + PyErr_Format( + PyExc_ReferenceError, "ImBuf data of type %.200s has been freed", Py_TYPE(self)->tp_name); + return -1; } #define PY_IMBUF_CHECK_OBJ(obj) \ @@ -324,9 +323,8 @@ static PyObject *py_imbuf_repr(Py_ImBuf *self) return PyUnicode_FromFormat( "", ibuf, ibuf->name, ibuf->x, ibuf->y); } - else { - return PyUnicode_FromString(""); - } + + return PyUnicode_FromString(""); } static Py_hash_t py_imbuf_hash(Py_ImBuf *self) diff --git a/source/blender/python/generic/py_capi_utils.c b/source/blender/python/generic/py_capi_utils.c index 543cd3b4214..caae5c4e122 100644 --- a/source/blender/python/generic/py_capi_utils.c +++ b/source/blender/python/generic/py_capi_utils.c @@ -375,12 +375,11 @@ void PyC_StackSpit(void) fprintf(stderr, "python line lookup failed, interpreter inactive\n"); return; } - else { - /* lame but handy */ - PyGILState_STATE gilstate = PyGILState_Ensure(); - PyRun_SimpleString("__import__('traceback').print_stack()"); - PyGILState_Release(gilstate); - } + + /* lame but handy */ + PyGILState_STATE gilstate = PyGILState_Ensure(); + PyRun_SimpleString("__import__('traceback').print_stack()"); + PyGILState_Release(gilstate); } void PyC_StackPrint(/* FILE */ void *fp) @@ -760,22 +759,20 @@ const char *PyC_UnicodeAsByteAndSize(PyObject *py_str, Py_ssize_t *size, PyObjec * chars since blender doesn't limit this */ return result; } - else { - PyErr_Clear(); - if (PyBytes_Check(py_str)) { - *size = PyBytes_GET_SIZE(py_str); - return PyBytes_AS_STRING(py_str); - } - else if ((*coerce = PyUnicode_EncodeFSDefault(py_str))) { - *size = PyBytes_GET_SIZE(*coerce); - return PyBytes_AS_STRING(*coerce); - } - else { - /* leave error raised from EncodeFS */ - return NULL; - } + PyErr_Clear(); + + if (PyBytes_Check(py_str)) { + *size = PyBytes_GET_SIZE(py_str); + return PyBytes_AS_STRING(py_str); } + if ((*coerce = PyUnicode_EncodeFSDefault(py_str))) { + *size = PyBytes_GET_SIZE(*coerce); + return PyBytes_AS_STRING(*coerce); + } + + /* leave error raised from EncodeFS */ + return NULL; } const char *PyC_UnicodeAsByte(PyObject *py_str, PyObject **coerce) @@ -789,20 +786,18 @@ const char *PyC_UnicodeAsByte(PyObject *py_str, PyObject **coerce) * chars since blender doesn't limit this. */ return result; } - else { - PyErr_Clear(); - if (PyBytes_Check(py_str)) { - return PyBytes_AS_STRING(py_str); - } - else if ((*coerce = PyUnicode_EncodeFSDefault(py_str))) { - return PyBytes_AS_STRING(*coerce); - } - else { - /* leave error raised from EncodeFS */ - return NULL; - } + PyErr_Clear(); + + if (PyBytes_Check(py_str)) { + return PyBytes_AS_STRING(py_str); } + if ((*coerce = PyUnicode_EncodeFSDefault(py_str))) { + return PyBytes_AS_STRING(*coerce); + } + + /* leave error raised from EncodeFS */ + return NULL; } PyObject *PyC_UnicodeFromByteAndSize(const char *str, Py_ssize_t size) @@ -813,12 +808,11 @@ PyObject *PyC_UnicodeFromByteAndSize(const char *str, Py_ssize_t size) * chars since blender doesn't limit this */ return result; } - else { - PyErr_Clear(); - /* this means paths will always be accessible once converted, on all OS's */ - result = PyUnicode_DecodeFSDefaultAndSize(str, size); - return result; - } + + PyErr_Clear(); + /* this means paths will always be accessible once converted, on all OS's */ + result = PyUnicode_DecodeFSDefaultAndSize(str, size); + return result; } PyObject *PyC_UnicodeFromByte(const char *str) @@ -1136,13 +1130,12 @@ void *PyC_RNA_AsPointer(PyObject *value, const char *type_name) return result; } - else { - PyErr_Format(PyExc_TypeError, - "expected '%.200s' type found '%.200s' instead", - type_name, - Py_TYPE(value)->tp_name); - return NULL; - } + + PyErr_Format(PyExc_TypeError, + "expected '%.200s' type found '%.200s' instead", + type_name, + Py_TYPE(value)->tp_name); + return NULL; } /** \} */ diff --git a/source/blender/python/gpu/gpu_py_batch.c b/source/blender/python/gpu/gpu_py_batch.c index f9fe1654db0..01bccc57c7a 100644 --- a/source/blender/python/gpu/gpu_py_batch.c +++ b/source/blender/python/gpu/gpu_py_batch.c @@ -222,7 +222,7 @@ static PyObject *bpygpu_Batch_draw(BPyGPUBatch *self, PyObject *args) if (!PyArg_ParseTuple(args, "|O!:GPUBatch.draw", &BPyGPUShader_Type, &py_program)) { return NULL; } - else if (py_program == NULL) { + if (py_program == NULL) { if (!bpygpu_batch_is_program_or_error(self)) { return NULL; } diff --git a/source/blender/python/intern/bpy_app_handlers.c b/source/blender/python/intern/bpy_app_handlers.c index dde1d13477f..cdbd3bc0b9c 100644 --- a/source/blender/python/intern/bpy_app_handlers.c +++ b/source/blender/python/intern/bpy_app_handlers.c @@ -118,22 +118,20 @@ static PyObject *bpy_app_handlers_persistent_new(PyTypeObject *UNUSED(type), "get the dictionary from the function passed"); return NULL; } - else { - /* set id */ - if (*dict_ptr == NULL) { - *dict_ptr = PyDict_New(); - } - PyDict_SetItemString(*dict_ptr, PERMINENT_CB_ID, Py_None); + /* set id */ + if (*dict_ptr == NULL) { + *dict_ptr = PyDict_New(); } + PyDict_SetItemString(*dict_ptr, PERMINENT_CB_ID, Py_None); + Py_INCREF(value); return value; } - else { - PyErr_SetString(PyExc_ValueError, "bpy.app.handlers.persistent expected a function"); - return NULL; - } + + PyErr_SetString(PyExc_ValueError, "bpy.app.handlers.persistent expected a function"); + return NULL; } /* dummy type because decorators can't be PyCFunctions */ diff --git a/source/blender/python/intern/bpy_driver.c b/source/blender/python/intern/bpy_driver.c index d48ad2b197c..7fb4b0c469c 100644 --- a/source/blender/python/intern/bpy_driver.c +++ b/source/blender/python/intern/bpy_driver.c @@ -83,9 +83,8 @@ int bpy_pydriver_create_dict(void) if (d == NULL) { return -1; } - else { - bpy_pydriver_Dict = d; - } + + bpy_pydriver_Dict = d; /* import some modules: builtins, bpy, math, (Blender.noise)*/ PyDict_SetItemString(d, "__builtins__", PyEval_GetBuiltins()); @@ -680,11 +679,8 @@ float BPY_driver_exec(struct PathResolvedRNA *anim_rna, if (isfinite(result)) { return (float)result; } - else { - fprintf(stderr, - "\tBPY_driver_eval() - driver '%s' evaluates to '%f'\n", - driver->expression, - result); - return 0.0f; - } + + fprintf( + stderr, "\tBPY_driver_eval() - driver '%s' evaluates to '%f'\n", driver->expression, result); + return 0.0f; } diff --git a/source/blender/python/intern/bpy_library_load.c b/source/blender/python/intern/bpy_library_load.c index 05cbc9af601..bcf13b1d88f 100644 --- a/source/blender/python/intern/bpy_library_load.c +++ b/source/blender/python/intern/bpy_library_load.c @@ -244,21 +244,20 @@ static PyObject *bpy_lib_enter(BPy_Library *self) } return NULL; } - else { - int i = 0, code; - while ((code = BKE_idtype_idcode_iter_step(&i))) { - if (BKE_idtype_idcode_is_linkable(code)) { - const char *name_plural = BKE_idtype_idcode_to_name_plural(code); - PyObject *str = PyUnicode_FromString(name_plural); - PyObject *item; - PyDict_SetItem(self->dict, str, item = PyList_New(0)); - Py_DECREF(item); - PyDict_SetItem(from_dict, str, item = _bpy_names(self, code)); - Py_DECREF(item); + int i = 0, code; + while ((code = BKE_idtype_idcode_iter_step(&i))) { + if (BKE_idtype_idcode_is_linkable(code)) { + const char *name_plural = BKE_idtype_idcode_to_name_plural(code); + PyObject *str = PyUnicode_FromString(name_plural); + PyObject *item; - Py_DECREF(str); - } + PyDict_SetItem(self->dict, str, item = PyList_New(0)); + Py_DECREF(item); + PyDict_SetItem(from_dict, str, item = _bpy_names(self, code)); + Py_DECREF(item); + + Py_DECREF(str); } } @@ -393,65 +392,64 @@ static PyObject *bpy_lib_exit(BPy_Library *self, PyObject *UNUSED(args)) BKE_main_id_tag_all(bmain, LIB_TAG_PRE_EXISTING, false); return NULL; } - else { - Library *lib = mainl->curlib; /* newly added lib, assign before append end */ - BLO_library_link_end(mainl, &(self->blo_handle), self->flag, NULL, NULL, NULL, NULL); - BLO_blendhandle_close(self->blo_handle); - self->blo_handle = NULL; - GHash *old_to_new_ids = BLI_ghash_ptr_new(__func__); + Library *lib = mainl->curlib; /* newly added lib, assign before append end */ + BLO_library_link_end(mainl, &(self->blo_handle), self->flag, NULL, NULL, NULL, NULL); + BLO_blendhandle_close(self->blo_handle); + self->blo_handle = NULL; - /* copied from wm_operator.c */ - { - /* mark all library linked objects to be updated */ - BKE_main_lib_objects_recalc_all(bmain); + GHash *old_to_new_ids = BLI_ghash_ptr_new(__func__); - /* append, rather than linking */ - if (do_append) { - BKE_library_make_local(bmain, lib, old_to_new_ids, true, false); - } + /* copied from wm_operator.c */ + { + /* mark all library linked objects to be updated */ + BKE_main_lib_objects_recalc_all(bmain); + + /* append, rather than linking */ + if (do_append) { + BKE_library_make_local(bmain, lib, old_to_new_ids, true, false); } + } - BKE_main_id_tag_all(bmain, LIB_TAG_PRE_EXISTING, false); + BKE_main_id_tag_all(bmain, LIB_TAG_PRE_EXISTING, false); - /* finally swap the capsules for real bpy objects - * important since BLO_library_append_end initializes NodeTree types used by srna->refine */ + /* finally swap the capsules for real bpy objects + * important since BLO_library_append_end initializes NodeTree types used by srna->refine */ #ifdef USE_RNA_DATABLOCKS - { - int idcode_step = 0, idcode; - while ((idcode = BKE_idtype_idcode_iter_step(&idcode_step))) { - if (BKE_idtype_idcode_is_linkable(idcode) && (idcode != ID_WS || do_append)) { - const char *name_plural = BKE_idtype_idcode_to_name_plural(idcode); - PyObject *ls = PyDict_GetItemString(self->dict, name_plural); - if (ls && PyList_Check(ls)) { - Py_ssize_t size = PyList_GET_SIZE(ls); - Py_ssize_t i; - PyObject *item; + { + int idcode_step = 0, idcode; + while ((idcode = BKE_idtype_idcode_iter_step(&idcode_step))) { + if (BKE_idtype_idcode_is_linkable(idcode) && (idcode != ID_WS || do_append)) { + const char *name_plural = BKE_idtype_idcode_to_name_plural(idcode); + PyObject *ls = PyDict_GetItemString(self->dict, name_plural); + if (ls && PyList_Check(ls)) { + Py_ssize_t size = PyList_GET_SIZE(ls); + Py_ssize_t i; + PyObject *item; - for (i = 0; i < size; i++) { - item = PyList_GET_ITEM(ls, i); - if (PyCapsule_CheckExact(item)) { - PointerRNA id_ptr; - ID *id; + for (i = 0; i < size; i++) { + item = PyList_GET_ITEM(ls, i); + if (PyCapsule_CheckExact(item)) { + PointerRNA id_ptr; + ID *id; - id = PyCapsule_GetPointer(item, NULL); - id = BLI_ghash_lookup_default(old_to_new_ids, id, id); - Py_DECREF(item); + id = PyCapsule_GetPointer(item, NULL); + id = BLI_ghash_lookup_default(old_to_new_ids, id, id); + Py_DECREF(item); - RNA_id_pointer_create(id, &id_ptr); - item = pyrna_struct_CreatePyObject(&id_ptr); - PyList_SET_ITEM(ls, i, item); - } + RNA_id_pointer_create(id, &id_ptr); + item = pyrna_struct_CreatePyObject(&id_ptr); + PyList_SET_ITEM(ls, i, item); } } } } } + } #endif /* USE_RNA_DATABLOCKS */ - BLI_ghash_free(old_to_new_ids, NULL, NULL); - Py_RETURN_NONE; - } + BLI_ghash_free(old_to_new_ids, NULL, NULL); + Py_RETURN_NONE; } static PyObject *bpy_lib_dir(BPy_Library *self) diff --git a/source/blender/python/intern/bpy_props.c b/source/blender/python/intern/bpy_props.c index 830acd987d9..66c67ca061c 100644 --- a/source/blender/python/intern/bpy_props.c +++ b/source/blender/python/intern/bpy_props.c @@ -1408,9 +1408,8 @@ static bool py_long_as_int(PyObject *py_long, int *r_int) *r_int = (int)PyLong_AS_LONG(py_long); return true; } - else { - return false; - } + + return false; } #if 0 @@ -1716,16 +1715,15 @@ static int bpy_prop_callback_check(PyObject *py_func, const char *keyword, int a Py_TYPE(py_func)->tp_name); return -1; } - else { - PyCodeObject *f_code = (PyCodeObject *)PyFunction_GET_CODE(py_func); - if (f_code->co_argcount != argcount) { - PyErr_Format(PyExc_TypeError, - "%s keyword: expected a function taking %d arguments, not %d", - keyword, - argcount, - f_code->co_argcount); - return -1; - } + + PyCodeObject *f_code = (PyCodeObject *)PyFunction_GET_CODE(py_func); + if (f_code->co_argcount != argcount) { + PyErr_Format(PyExc_TypeError, + "%s keyword: expected a function taking %d arguments, not %d", + keyword, + argcount, + f_code->co_argcount); + return -1; } } @@ -1981,7 +1979,7 @@ static void bpy_prop_callback_assign_enum(struct PropertyRNA *prop, Py_DECREF(args); \ return ret; \ } \ - else if (PyTuple_GET_SIZE(args) > 1) { \ + if (PyTuple_GET_SIZE(args) > 1) { \ PyErr_SetString(PyExc_ValueError, "all args must be keywords"); \ return NULL; \ } \ @@ -3537,7 +3535,7 @@ static PyObject *BPy_RemoveProperty(PyObject *self, PyObject *args, PyObject *kw Py_DECREF(args); return ret; } - else if (PyTuple_GET_SIZE(args) > 1) { + if (PyTuple_GET_SIZE(args) > 1) { PyErr_SetString(PyExc_ValueError, "expected one positional arg, one keyword arg"); return NULL; } @@ -3546,27 +3544,27 @@ static PyObject *BPy_RemoveProperty(PyObject *self, PyObject *args, PyObject *kw if (srna == NULL && PyErr_Occurred()) { return NULL; /* self's type was compatible but error getting the srna */ } - else if (srna == NULL) { + if (srna == NULL) { PyErr_SetString(PyExc_TypeError, "RemoveProperty(): struct rna not available for this type"); return NULL; } - else { - const char *id = NULL; - static const char *_keywords[] = { - "attr", - NULL, - }; - static _PyArg_Parser _parser = {"s:RemoveProperty", _keywords, 0}; - if (!_PyArg_ParseTupleAndKeywordsFast(args, kw, &_parser, &id)) { - return NULL; - } + const char *id = NULL; - if (RNA_def_property_free_identifier(srna, id) != 1) { - PyErr_Format(PyExc_TypeError, "RemoveProperty(): '%s' not a defined dynamic property", id); - return NULL; - } + static const char *_keywords[] = { + "attr", + NULL, + }; + static _PyArg_Parser _parser = {"s:RemoveProperty", _keywords, 0}; + if (!_PyArg_ParseTupleAndKeywordsFast(args, kw, &_parser, &id)) { + return NULL; } + + if (RNA_def_property_free_identifier(srna, id) != 1) { + PyErr_Format(PyExc_TypeError, "RemoveProperty(): '%s' not a defined dynamic property", id); + return NULL; + } + Py_RETURN_NONE; } diff --git a/source/blender/python/intern/bpy_rna.c b/source/blender/python/intern/bpy_rna.c index 893832b61b6..955a24bc880 100644 --- a/source/blender/python/intern/bpy_rna.c +++ b/source/blender/python/intern/bpy_rna.c @@ -987,24 +987,23 @@ static PyObject *pyrna_prop_str(BPy_PropertyRNA *self) PyErr_SetString(PyExc_RuntimeError, "could not use property type, internal error"); return NULL; } - else { - /* This should never fail. */ - int len = -1; - char *c = type_fmt; - while ((*c++ = tolower(*type_id++))) { - } + /* This should never fail. */ + int len = -1; + char *c = type_fmt; - if (type == PROP_COLLECTION) { - len = pyrna_prop_collection_length(self); - } - else if (RNA_property_array_check(self->prop)) { - len = pyrna_prop_array_length((BPy_PropertyArrayRNA *)self); - } + while ((*c++ = tolower(*type_id++))) { + } - if (len != -1) { - sprintf(--c, "[%d]", len); - } + if (type == PROP_COLLECTION) { + len = pyrna_prop_collection_length(self); + } + else if (RNA_property_array_check(self->prop)) { + len = pyrna_prop_array_length((BPy_PropertyArrayRNA *)self); + } + + if (len != -1) { + sprintf(--c, "[%d]", len); } /* If a pointer, try to print name of pointer target too. */ @@ -1246,17 +1245,16 @@ static int pyrna_string_to_enum( Py_TYPE(item)->tp_name); return -1; } - else { - if (!RNA_property_enum_value(BPy_GetContext(), ptr, prop, param, r_value)) { - const char *enum_str = pyrna_enum_as_string(ptr, prop); - PyErr_Format(PyExc_TypeError, - "%.200s enum \"%.200s\" not found in (%s)", - error_prefix, - param, - enum_str); - MEM_freeN((void *)enum_str); - return -1; - } + + if (!RNA_property_enum_value(BPy_GetContext(), ptr, prop, param, r_value)) { + const char *enum_str = pyrna_enum_as_string(ptr, prop); + PyErr_Format(PyExc_TypeError, + "%.200s enum \"%.200s\" not found in (%s)", + error_prefix, + param, + enum_str); + MEM_freeN((void *)enum_str); + return -1; } return 0; @@ -1715,14 +1713,14 @@ static int pyrna_py_to_prop( Py_TYPE(value)->tp_name); return -1; } - else { - if (data) { - *((bool *)data) = param; - } - else { - RNA_property_boolean_set(ptr, prop, param); - } + + if (data) { + *((bool *)data) = param; } + else { + RNA_property_boolean_set(ptr, prop, param); + } + break; } case PROP_INT: { @@ -1737,7 +1735,7 @@ static int pyrna_py_to_prop( RNA_property_identifier(prop)); return -1; } - else if (param == -1 && PyErr_Occurred()) { + if (param == -1 && PyErr_Occurred()) { PyErr_Format(PyExc_TypeError, "%.200s %.200s.%.200s expected an int type, not %.200s", error_prefix, @@ -1746,16 +1744,16 @@ static int pyrna_py_to_prop( Py_TYPE(value)->tp_name); return -1; } - else { - int param_i = (int)param; - if (data) { - RNA_property_int_clamp(ptr, prop, ¶m_i); - *((int *)data) = param_i; - } - else { - RNA_property_int_set(ptr, prop, param_i); - } + + int param_i = (int)param; + if (data) { + RNA_property_int_clamp(ptr, prop, ¶m_i); + *((int *)data) = param_i; } + else { + RNA_property_int_set(ptr, prop, param_i); + } + break; } case PROP_FLOAT: { @@ -1769,15 +1767,15 @@ static int pyrna_py_to_prop( Py_TYPE(value)->tp_name); return -1; } - else { - if (data) { - RNA_property_float_clamp(ptr, prop, (float *)¶m); - *((float *)data) = param; - } - else { - RNA_property_float_set(ptr, prop, param); - } + + if (data) { + RNA_property_float_clamp(ptr, prop, (float *)¶m); + *((float *)data) = param; } + else { + RNA_property_float_set(ptr, prop, param); + } + break; } case PROP_STRING: { @@ -1835,19 +1833,18 @@ static int pyrna_py_to_prop( return -1; } - else { - if (data) { - if (RNA_property_flag(prop) & PROP_THICK_WRAP) { - BLI_strncpy((char *)data, (char *)param, RNA_property_string_maxlength(prop)); - } - else { - *((char **)data) = (char *)param; - } + + if (data) { + if (RNA_property_flag(prop) & PROP_THICK_WRAP) { + BLI_strncpy((char *)data, (char *)param, RNA_property_string_maxlength(prop)); } else { - RNA_property_string_set_bytes(ptr, prop, param, PyBytes_Size(value)); + *((char **)data) = (char *)param; } } + else { + RNA_property_string_set_bytes(ptr, prop, param, PyBytes_Size(value)); + } } else { /* Unicode String. */ @@ -1886,22 +1883,22 @@ static int pyrna_py_to_prop( return -1; } - else { - /* Same as bytes. */ - /* XXX, this is suspect, but needed for function calls, - * need to see if there's a better way. */ - if (data) { - if (RNA_property_flag(prop) & PROP_THICK_WRAP) { - BLI_strncpy((char *)data, (char *)param, RNA_property_string_maxlength(prop)); - } - else { - *((char **)data) = (char *)param; - } + + /* Same as bytes. */ + /* XXX, this is suspect, but needed for function calls, + * need to see if there's a better way. */ + if (data) { + if (RNA_property_flag(prop) & PROP_THICK_WRAP) { + BLI_strncpy((char *)data, (char *)param, RNA_property_string_maxlength(prop)); } else { - RNA_property_string_set(ptr, prop, param); + *((char **)data) = (char *)param; } } + else { + RNA_property_string_set(ptr, prop, param); + } + #ifdef USE_STRING_COERCE Py_XDECREF(value_coerce); #endif /* USE_STRING_COERCE */ @@ -1971,7 +1968,7 @@ static int pyrna_py_to_prop( PointerRNA opptr = RNA_property_pointer_get(ptr, prop); return pyrna_pydict_to_props(&opptr, value, false, error_prefix); } - else if (base_type == &RNA_GizmoProperties) { + if (base_type == &RNA_GizmoProperties) { PointerRNA opptr = RNA_property_pointer_get(ptr, prop); return pyrna_pydict_to_props(&opptr, value, false, error_prefix); } @@ -2008,7 +2005,7 @@ static int pyrna_py_to_prop( Py_XDECREF(value_new); return -1; } - else if ((flag & PROP_NEVER_NULL) && value == Py_None) { + if ((flag & PROP_NEVER_NULL) && value == Py_None) { PyErr_Format(PyExc_TypeError, "%.200s %.200s.%.200s does not support a 'None' assignment %.200s type", error_prefix, @@ -2018,8 +2015,8 @@ static int pyrna_py_to_prop( Py_XDECREF(value_new); return -1; } - else if ((value != Py_None) && ((flag & PROP_ID_SELF_CHECK) && - ptr->owner_id == ((BPy_StructRNA *)value)->ptr.owner_id)) { + if ((value != Py_None) && ((flag & PROP_ID_SELF_CHECK) && + ptr->owner_id == ((BPy_StructRNA *)value)->ptr.owner_id)) { PyErr_Format(PyExc_TypeError, "%.200s %.200s.%.200s ID type does not support assignment to itself", error_prefix, @@ -2028,85 +2025,84 @@ static int pyrna_py_to_prop( Py_XDECREF(value_new); return -1; } - else { - BPy_StructRNA *param = (BPy_StructRNA *)value; - bool raise_error = false; - if (data) { - if (flag_parameter & PARM_RNAPTR) { - if (flag & PROP_THICK_WRAP) { - if (value == Py_None) { - memset(data, 0, sizeof(PointerRNA)); - } - else if (RNA_struct_is_a(param->ptr.type, ptr_type)) { - *((PointerRNA *)data) = param->ptr; - } - else { - raise_error = true; - } + BPy_StructRNA *param = (BPy_StructRNA *)value; + bool raise_error = false; + if (data) { + + if (flag_parameter & PARM_RNAPTR) { + if (flag & PROP_THICK_WRAP) { + if (value == Py_None) { + memset(data, 0, sizeof(PointerRNA)); + } + else if (RNA_struct_is_a(param->ptr.type, ptr_type)) { + *((PointerRNA *)data) = param->ptr; } else { - /* For function calls, we sometimes want to pass the 'ptr' directly, - * but watch out that it remains valid! - * We could possibly support this later if needed. */ - BLI_assert(value_new == NULL); - if (value == Py_None) { - *((void **)data) = NULL; - } - else if (RNA_struct_is_a(param->ptr.type, ptr_type)) { - *((PointerRNA **)data) = ¶m->ptr; - } - else { - raise_error = true; - } + raise_error = true; } } - else if (value == Py_None) { - *((void **)data) = NULL; - } - else if (RNA_struct_is_a(param->ptr.type, ptr_type)) { - *((void **)data) = param->ptr.data; - } else { - raise_error = true; + /* For function calls, we sometimes want to pass the 'ptr' directly, + * but watch out that it remains valid! + * We could possibly support this later if needed. */ + BLI_assert(value_new == NULL); + if (value == Py_None) { + *((void **)data) = NULL; + } + else if (RNA_struct_is_a(param->ptr.type, ptr_type)) { + *((PointerRNA **)data) = ¶m->ptr; + } + else { + raise_error = true; + } + } + } + else if (value == Py_None) { + *((void **)data) = NULL; + } + else if (RNA_struct_is_a(param->ptr.type, ptr_type)) { + *((void **)data) = param->ptr.data; + } + else { + raise_error = true; + } + } + else { + /* Data == NULL, assign to RNA. */ + if (value == Py_None || RNA_struct_is_a(param->ptr.type, ptr_type)) { + ReportList reports; + BKE_reports_init(&reports, RPT_STORE); + RNA_property_pointer_set( + ptr, prop, value == Py_None ? PointerRNA_NULL : param->ptr, &reports); + int err = (BPy_reports_to_error(&reports, PyExc_RuntimeError, true)); + if (err == -1) { + Py_XDECREF(value_new); + return -1; } } else { - /* Data == NULL, assign to RNA. */ - if (value == Py_None || RNA_struct_is_a(param->ptr.type, ptr_type)) { - ReportList reports; - BKE_reports_init(&reports, RPT_STORE); - RNA_property_pointer_set( - ptr, prop, value == Py_None ? PointerRNA_NULL : param->ptr, &reports); - int err = (BPy_reports_to_error(&reports, PyExc_RuntimeError, true)); - if (err == -1) { - Py_XDECREF(value_new); - return -1; - } - } - else { - raise_error = true; - } + raise_error = true; } + } - if (raise_error) { - if (pyrna_struct_validity_check(param) == -1) { - /* Error set. */ - } - else { - PointerRNA tmp; - RNA_pointer_create(NULL, ptr_type, NULL, &tmp); - PyErr_Format(PyExc_TypeError, - "%.200s %.200s.%.200s expected a %.200s type, not %.200s", - error_prefix, - RNA_struct_identifier(ptr->type), - RNA_property_identifier(prop), - RNA_struct_identifier(tmp.type), - RNA_struct_identifier(param->ptr.type)); - } - Py_XDECREF(value_new); - return -1; + if (raise_error) { + if (pyrna_struct_validity_check(param) == -1) { + /* Error set. */ } + else { + PointerRNA tmp; + RNA_pointer_create(NULL, ptr_type, NULL, &tmp); + PyErr_Format(PyExc_TypeError, + "%.200s %.200s.%.200s expected a %.200s type, not %.200s", + error_prefix, + RNA_struct_identifier(ptr->type), + RNA_property_identifier(prop), + RNA_struct_identifier(tmp.type), + RNA_struct_identifier(param->ptr.type)); + } + Py_XDECREF(value_new); + return -1; } Py_XDECREF(value_new); @@ -2295,9 +2291,8 @@ static Py_ssize_t pyrna_prop_array_length(BPy_PropertyArrayRNA *self) if (RNA_property_array_dimension(&self->ptr, self->prop, NULL) > 1) { return RNA_property_multi_array_length(&self->ptr, self->prop, self->arraydim); } - else { - return RNA_property_array_length(&self->ptr, self->prop); - } + + return RNA_property_array_length(&self->ptr, self->prop); } static Py_ssize_t pyrna_prop_collection_length(BPy_PropertyRNA *self) @@ -2356,25 +2351,24 @@ static PyObject *pyrna_prop_collection_subscript_int(BPy_PropertyRNA *self, Py_s if (RNA_property_collection_lookup_int(&self->ptr, self->prop, keynum_abs, &newptr)) { return pyrna_struct_CreatePyObject(&newptr); } - else { - const int len = RNA_property_collection_length(&self->ptr, self->prop); - if (keynum_abs >= len) { - PyErr_Format(PyExc_IndexError, - "bpy_prop_collection[index]: " - "index %d out of range, size %d", - keynum, - len); - } - else { - PyErr_Format(PyExc_RuntimeError, - "bpy_prop_collection[index]: internal error, " - "valid index %d given in %d sized collection, but value not found", - keynum_abs, - len); - } - return NULL; + const int len = RNA_property_collection_length(&self->ptr, self->prop); + if (keynum_abs >= len) { + PyErr_Format(PyExc_IndexError, + "bpy_prop_collection[index]: " + "index %d out of range, size %d", + keynum, + len); } + else { + PyErr_Format(PyExc_RuntimeError, + "bpy_prop_collection[index]: internal error, " + "valid index %d given in %d sized collection, but value not found", + keynum_abs, + len); + } + + return NULL; } /* Values type must have been already checked. */ @@ -2473,79 +2467,76 @@ static int pyrna_prop_collection_subscript_str_lib_pair_ptr(BPy_PropertyRNA *sel PyTuple_GET_SIZE(key)); return -1; } - else if (self->ptr.type != &RNA_BlendData) { + if (self->ptr.type != &RNA_BlendData) { PyErr_Format(PyExc_KeyError, "%s: is only valid for bpy.data collections, not %.200s", err_prefix, RNA_struct_identifier(self->ptr.type)); return -1; } - else if ((keyname = _PyUnicode_AsString(PyTuple_GET_ITEM(key, 0))) == NULL) { + if ((keyname = _PyUnicode_AsString(PyTuple_GET_ITEM(key, 0))) == NULL) { PyErr_Format(PyExc_KeyError, "%s: id must be a string, not %.200s", err_prefix, Py_TYPE(PyTuple_GET_ITEM(key, 0))->tp_name); return -1; } - else { - PyObject *keylib = PyTuple_GET_ITEM(key, 1); - Library *lib; - bool found = false; - if (keylib == Py_None) { - lib = NULL; - } - else if (PyUnicode_Check(keylib)) { - Main *bmain = self->ptr.data; - const char *keylib_str = _PyUnicode_AsString(keylib); - lib = BLI_findstring(&bmain->libraries, keylib_str, offsetof(Library, filepath)); - if (lib == NULL) { - if (err_not_found) { - PyErr_Format(PyExc_KeyError, - "%s: lib name '%.240s' " - "does not reference a valid library", - err_prefix, - keylib_str); - return -1; - } - else { - return 0; - } + PyObject *keylib = PyTuple_GET_ITEM(key, 1); + Library *lib; + bool found = false; + + if (keylib == Py_None) { + lib = NULL; + } + else if (PyUnicode_Check(keylib)) { + Main *bmain = self->ptr.data; + const char *keylib_str = _PyUnicode_AsString(keylib); + lib = BLI_findstring(&bmain->libraries, keylib_str, offsetof(Library, filepath)); + if (lib == NULL) { + if (err_not_found) { + PyErr_Format(PyExc_KeyError, + "%s: lib name '%.240s' " + "does not reference a valid library", + err_prefix, + keylib_str); + return -1; } - } - else { - PyErr_Format(PyExc_KeyError, - "%s: lib must be a string or None, not %.200s", - err_prefix, - Py_TYPE(keylib)->tp_name); - return -1; - } - /* lib is either a valid pointer or NULL, - * either way can do direct comparison with id.lib */ - - RNA_PROP_BEGIN (&self->ptr, itemptr, self->prop) { - ID *id = itemptr.data; /* Always an ID. */ - if (id->lib == lib && (STREQLEN(keyname, id->name + 2, sizeof(id->name) - 2))) { - found = true; - if (r_ptr) { - *r_ptr = itemptr; - } - break; - } - } - RNA_PROP_END; - - /* We may want to fail silently as with collection.get(). */ - if ((found == false) && err_not_found) { - /* Only runs for getitem access so use fixed string. */ - PyErr_SetString(PyExc_KeyError, "bpy_prop_collection[key, lib]: not found"); - return -1; - } - else { - return found; /* 1 / 0, no exception. */ + return 0; } } + else { + PyErr_Format(PyExc_KeyError, + "%s: lib must be a string or None, not %.200s", + err_prefix, + Py_TYPE(keylib)->tp_name); + return -1; + } + + /* lib is either a valid pointer or NULL, + * either way can do direct comparison with id.lib */ + + RNA_PROP_BEGIN (&self->ptr, itemptr, self->prop) { + ID *id = itemptr.data; /* Always an ID. */ + if (id->lib == lib && (STREQLEN(keyname, id->name + 2, sizeof(id->name) - 2))) { + found = true; + if (r_ptr) { + *r_ptr = itemptr; + } + break; + } + } + RNA_PROP_END; + + /* We may want to fail silently as with collection.get(). */ + if ((found == false) && err_not_found) { + /* Only runs for getitem access so use fixed string. */ + PyErr_SetString(PyExc_KeyError, "bpy_prop_collection[key, lib]: not found"); + return -1; + } + + return found; /* 1 / 0, no exception. */ } static PyObject *pyrna_prop_collection_subscript_str_lib_pair(BPy_PropertyRNA *self, @@ -2560,9 +2551,8 @@ static PyObject *pyrna_prop_collection_subscript_str_lib_pair(BPy_PropertyRNA *s if (contains == 1) { return pyrna_struct_CreatePyObject(&ptr); } - else { - return NULL; - } + + return NULL; } static PyObject *pyrna_prop_collection_subscript_slice(BPy_PropertyRNA *self, @@ -2707,7 +2697,7 @@ static PyObject *pyrna_prop_collection_subscript(BPy_PropertyRNA *self, PyObject if (PyUnicode_Check(key)) { return pyrna_prop_collection_subscript_str(self, _PyUnicode_AsString(key)); } - else if (PyIndex_Check(key)) { + if (PyIndex_Check(key)) { Py_ssize_t i = PyNumber_AsSsize_t(key, PyExc_IndexError); if (i == -1 && PyErr_Occurred()) { return NULL; @@ -2715,62 +2705,59 @@ static PyObject *pyrna_prop_collection_subscript(BPy_PropertyRNA *self, PyObject return pyrna_prop_collection_subscript_int(self, i); } - else if (PySlice_Check(key)) { + if (PySlice_Check(key)) { PySliceObject *key_slice = (PySliceObject *)key; Py_ssize_t step = 1; if (key_slice->step != Py_None && !_PyEval_SliceIndex(key, &step)) { return NULL; } - else if (step != 1) { + if (step != 1) { PyErr_SetString(PyExc_TypeError, "bpy_prop_collection[slice]: slice steps not supported"); return NULL; } - else if (key_slice->start == Py_None && key_slice->stop == Py_None) { + if (key_slice->start == Py_None && key_slice->stop == Py_None) { return pyrna_prop_collection_subscript_slice(self, 0, PY_SSIZE_T_MAX); } - else { - Py_ssize_t start = 0, stop = PY_SSIZE_T_MAX; - /* Avoid PySlice_GetIndicesEx because it needs to know the length ahead of time. */ - if (key_slice->start != Py_None && !_PyEval_SliceIndex(key_slice->start, &start)) { - return NULL; - } - if (key_slice->stop != Py_None && !_PyEval_SliceIndex(key_slice->stop, &stop)) { - return NULL; - } + Py_ssize_t start = 0, stop = PY_SSIZE_T_MAX; - if (start < 0 || stop < 0) { - /* Only get the length for negative values. */ - Py_ssize_t len = (Py_ssize_t)RNA_property_collection_length(&self->ptr, self->prop); - if (start < 0) { - start += len; - } - if (stop < 0) { - stop += len; - } - } + /* Avoid PySlice_GetIndicesEx because it needs to know the length ahead of time. */ + if (key_slice->start != Py_None && !_PyEval_SliceIndex(key_slice->start, &start)) { + return NULL; + } + if (key_slice->stop != Py_None && !_PyEval_SliceIndex(key_slice->stop, &stop)) { + return NULL; + } - if (stop - start <= 0) { - return PyList_New(0); + if (start < 0 || stop < 0) { + /* Only get the length for negative values. */ + Py_ssize_t len = (Py_ssize_t)RNA_property_collection_length(&self->ptr, self->prop); + if (start < 0) { + start += len; } - else { - return pyrna_prop_collection_subscript_slice(self, start, stop); + if (stop < 0) { + stop += len; } } + + if (stop - start <= 0) { + return PyList_New(0); + } + + return pyrna_prop_collection_subscript_slice(self, start, stop); } - else if (PyTuple_Check(key)) { + if (PyTuple_Check(key)) { /* Special case, for ID datablocks we. */ return pyrna_prop_collection_subscript_str_lib_pair( self, key, "bpy_prop_collection[id, lib]", true); } - else { - PyErr_Format(PyExc_TypeError, - "bpy_prop_collection[key]: invalid key, " - "must be a string or an int, not %.200s", - Py_TYPE(key)->tp_name); - return NULL; - } + + PyErr_Format(PyExc_TypeError, + "bpy_prop_collection[key]: invalid key, " + "must be a string or an int, not %.200s", + Py_TYPE(key)->tp_name); + return NULL; } /* generic check to see if a PyObject is compatible with a collection @@ -2786,18 +2773,17 @@ static int pyrna_prop_collection_type_check(BPy_PropertyRNA *self, PyObject *val "this collection doesn't support None assignment"); return -1; } - else { - return 0; /* None is OK. */ - } + + return 0; /* None is OK. */ } - else if (BPy_StructRNA_Check(value) == 0) { + if (BPy_StructRNA_Check(value) == 0) { PyErr_Format(PyExc_TypeError, "bpy_prop_collection[key] = value: invalid, " "expected a StructRNA type or None, not a %.200s", Py_TYPE(value)->tp_name); return -1; } - else if ((prop_srna = RNA_property_pointer_type(&self->ptr, self->prop))) { + if ((prop_srna = RNA_property_pointer_type(&self->ptr, self->prop))) { StructRNA *value_srna = ((BPy_StructRNA *)value)->ptr.type; if (RNA_struct_is_a(value_srna, prop_srna) == 0) { PyErr_Format(PyExc_TypeError, @@ -2807,9 +2793,8 @@ static int pyrna_prop_collection_type_check(BPy_PropertyRNA *self, PyObject *val RNA_struct_identifier(value_srna)); return -1; } - else { - return 0; /* OK, this is the correct type! */ - } + + return 0; /* OK, this is the correct type! */ } PyErr_Format(PyExc_TypeError, @@ -2831,7 +2816,7 @@ static int pyrna_prop_collection_ass_subscript(BPy_PropertyRNA *self, PyErr_SetString(PyExc_TypeError, "del bpy_prop_collection[key]: not supported"); return -1; } - else if (pyrna_prop_collection_type_check(self, value) == -1) { + if (pyrna_prop_collection_type_check(self, value) == -1) { return -1; /* Exception is set. */ } @@ -2895,13 +2880,12 @@ static int pyrna_prop_collection_ass_subscript(BPy_PropertyRNA *self, } } #endif - else { - PyErr_Format(PyExc_TypeError, - "bpy_prop_collection[key]: invalid key, " - "must be a string or an int, not %.200s", - Py_TYPE(key)->tp_name); - return -1; - } + + PyErr_Format(PyExc_TypeError, + "bpy_prop_collection[key]: invalid key, " + "must be a string or an int, not %.200s", + Py_TYPE(key)->tp_name); + return -1; } static PyObject *pyrna_prop_array_subscript(BPy_PropertyArrayRNA *self, PyObject *key) @@ -2921,43 +2905,40 @@ static PyObject *pyrna_prop_array_subscript(BPy_PropertyArrayRNA *self, PyObject } return pyrna_prop_array_subscript_int(self, i); } - else if (PySlice_Check(key)) { + if (PySlice_Check(key)) { Py_ssize_t step = 1; PySliceObject *key_slice = (PySliceObject *)key; if (key_slice->step != Py_None && !_PyEval_SliceIndex(key, &step)) { return NULL; } - else if (step != 1) { + if (step != 1) { PyErr_SetString(PyExc_TypeError, "bpy_prop_array[slice]: slice steps not supported"); return NULL; } - else if (key_slice->start == Py_None && key_slice->stop == Py_None) { + if (key_slice->start == Py_None && key_slice->stop == Py_None) { /* Note: no significant advantage with optimizing [:] slice as with collections, * but include here for consistency with collection slice func */ Py_ssize_t len = (Py_ssize_t)pyrna_prop_array_length(self); return pyrna_prop_array_subscript_slice(self, &self->ptr, self->prop, 0, len, len); } - else { - int len = pyrna_prop_array_length(self); - Py_ssize_t start, stop, slicelength; - if (PySlice_GetIndicesEx(key, len, &start, &stop, &step, &slicelength) < 0) { - return NULL; - } + int len = pyrna_prop_array_length(self); + Py_ssize_t start, stop, slicelength; - if (slicelength <= 0) { - return PyTuple_New(0); - } - else { - return pyrna_prop_array_subscript_slice(self, &self->ptr, self->prop, start, stop, len); - } + if (PySlice_GetIndicesEx(key, len, &start, &stop, &step, &slicelength) < 0) { + return NULL; } + + if (slicelength <= 0) { + return PyTuple_New(0); + } + + return pyrna_prop_array_subscript_slice(self, &self->ptr, self->prop, start, stop, len); } - else { - PyErr_SetString(PyExc_AttributeError, "bpy_prop_array[key]: invalid key, key must be an int"); - return NULL; - } + + PyErr_SetString(PyExc_AttributeError, "bpy_prop_array[key]: invalid key, key must be an int"); + return NULL; } /** @@ -2972,7 +2953,7 @@ static PyObject *prop_subscript_ass_array_slice__as_seq_fast(PyObject *value, in "element in assignment is not a sequence type"))) { return NULL; } - else if (PySequence_Fast_GET_SIZE(value_fast) != length) { + if (PySequence_Fast_GET_SIZE(value_fast) != length) { Py_DECREF(value_fast); PyErr_SetString(PyExc_ValueError, "bpy_prop_array[slice] = value: " @@ -2980,9 +2961,8 @@ static PyObject *prop_subscript_ass_array_slice__as_seq_fast(PyObject *value, in return NULL; } - else { - return value_fast; - } + + return value_fast; } static int prop_subscript_ass_array_slice__float_recursive( @@ -3005,17 +2985,16 @@ static int prop_subscript_ass_array_slice__float_recursive( } return index; } - else { - BLI_assert(totdim == 1); - const float min = range[0], max = range[1]; - int i; - for (i = 0; i != length; i++) { - float v = PyFloat_AsDouble(value_items[i]); - CLAMP(v, min, max); - value[i] = v; - } - return i; + + BLI_assert(totdim == 1); + const float min = range[0], max = range[1]; + int i; + for (i = 0; i != length; i++) { + float v = PyFloat_AsDouble(value_items[i]); + CLAMP(v, min, max); + value[i] = v; } + return i; } static int prop_subscript_ass_array_slice__int_recursive( @@ -3038,17 +3017,16 @@ static int prop_subscript_ass_array_slice__int_recursive( } return index; } - else { - BLI_assert(totdim == 1); - const int min = range[0], max = range[1]; - int i; - for (i = 0; i != length; i++) { - int v = PyLong_AsLong(value_items[i]); - CLAMP(v, min, max); - value[i] = v; - } - return i; + + BLI_assert(totdim == 1); + const int min = range[0], max = range[1]; + int i; + for (i = 0; i != length; i++) { + int v = PyLong_AsLong(value_items[i]); + CLAMP(v, min, max); + value[i] = v; } + return i; } static int prop_subscript_ass_array_slice__bool_recursive(PyObject **value_items, @@ -3073,15 +3051,14 @@ static int prop_subscript_ass_array_slice__bool_recursive(PyObject **value_items } return index; } - else { - BLI_assert(totdim == 1); - int i; - for (i = 0; i != length; i++) { - int v = PyLong_AsLong(value_items[i]); - value[i] = v; - } - return i; + + BLI_assert(totdim == 1); + int i; + for (i = 0; i != length; i++) { + int v = PyLong_AsLong(value_items[i]); + value[i] = v; } + return i; } /* Could call `pyrna_py_to_prop_array_index(self, i, value)` in a loop, but it is slow. */ @@ -3364,23 +3341,21 @@ static int pyrna_prop_collection_contains(BPy_PropertyRNA *self, PyObject *key) return pyrna_prop_collection_subscript_str_lib_pair_ptr( self, key, "(id, lib) in bpy_prop_collection", false, NULL); } - else { - /* Key in dict style check. */ - const char *keyname = _PyUnicode_AsString(key); + /* Key in dict style check. */ + const char *keyname = _PyUnicode_AsString(key); - if (keyname == NULL) { - PyErr_SetString(PyExc_TypeError, - "bpy_prop_collection.__contains__: expected a string or a tuple of strings"); - return -1; - } - - if (RNA_property_collection_lookup_string(&self->ptr, self->prop, keyname, &newptr)) { - return 1; - } - - return 0; + if (keyname == NULL) { + PyErr_SetString(PyExc_TypeError, + "bpy_prop_collection.__contains__: expected a string or a tuple of strings"); + return -1; } + + if (RNA_property_collection_lookup_string(&self->ptr, self->prop, keyname, &newptr)) { + return 1; + } + + return 0; } static int pyrna_struct_contains(BPy_StructRNA *self, PyObject *value) @@ -3821,30 +3796,25 @@ static PyObject *pyrna_struct_path_resolve(BPy_StructRNA *self, PyObject *args) path); return NULL; } - else { - return pyrna_array_index(&r_ptr, r_prop, index); - } + + return pyrna_array_index(&r_ptr, r_prop, index); } - else { - if (coerce == Py_False) { - return pyrna_prop_CreatePyObject(&r_ptr, r_prop); - } - else { - return pyrna_prop_to_py(&r_ptr, r_prop); - } + + if (coerce == Py_False) { + return pyrna_prop_CreatePyObject(&r_ptr, r_prop); } + + return pyrna_prop_to_py(&r_ptr, r_prop); } - else { - return pyrna_struct_CreatePyObject(&r_ptr); - } - } - else { - PyErr_Format(PyExc_ValueError, - "%.200s.path_resolve(\"%.200s\") could not be resolved", - RNA_struct_identifier(self->ptr.type), - path); - return NULL; + + return pyrna_struct_CreatePyObject(&r_ptr); } + + PyErr_Format(PyExc_ValueError, + "%.200s.path_resolve(\"%.200s\") could not be resolved", + RNA_struct_identifier(self->ptr.type), + path); + return NULL; } PyDoc_STRVAR(pyrna_struct_path_from_id_doc, @@ -3954,22 +3924,21 @@ static PyObject *pyrna_prop_as_bytes(BPy_PropertyRNA *self) RNA_property_identifier(self->prop)); return NULL; } - else { - PyObject *ret; - char buf_fixed[256], *buf; - int buf_len; - buf = RNA_property_string_get_alloc( - &self->ptr, self->prop, buf_fixed, sizeof(buf_fixed), &buf_len); + PyObject *ret; + char buf_fixed[256], *buf; + int buf_len; - ret = PyBytes_FromStringAndSize(buf, buf_len); + buf = RNA_property_string_get_alloc( + &self->ptr, self->prop, buf_fixed, sizeof(buf_fixed), &buf_len); - if (buf_fixed != buf) { - MEM_freeN(buf); - } + ret = PyBytes_FromStringAndSize(buf, buf_len); - return ret; + if (buf_fixed != buf) { + MEM_freeN(buf); } + + return ret; } PyDoc_STRVAR(pyrna_prop_update_doc, @@ -4478,7 +4447,7 @@ static int pyrna_struct_setattro(BPy_StructRNA *self, PyObject *pyname, PyObject PyErr_SetString(PyExc_AttributeError, "bpy_struct: __setattr__ must be a string"); return -1; } - else if (name[0] != '_' && (prop = RNA_struct_find_property(&self->ptr, name))) { + if (name[0] != '_' && (prop = RNA_struct_find_property(&self->ptr, name))) { if (!RNA_property_editable_flag(&self->ptr, prop)) { PyErr_Format(PyExc_AttributeError, "bpy_struct: attribute \"%.200s\" from \"%.200s\" is read-only", @@ -4497,22 +4466,21 @@ static int pyrna_struct_setattro(BPy_StructRNA *self, PyObject *pyname, PyObject name); return -1; } - else { - PointerRNA newptr; - ListBase newlb; - short newtype; - int done = CTX_data_get(C, name, &newptr, &newlb, &newtype); + PointerRNA newptr; + ListBase newlb; + short newtype; - if (done == 1) { - PyErr_Format( - PyExc_AttributeError, "bpy_struct: Context property \"%.200s\" is read-only", name); - BLI_freelistN(&newlb); - return -1; - } + int done = CTX_data_get(C, name, &newptr, &newlb, &newtype); + if (done == 1) { + PyErr_Format( + PyExc_AttributeError, "bpy_struct: Context property \"%.200s\" is read-only", name); BLI_freelistN(&newlb); + return -1; } + + BLI_freelistN(&newlb); } /* pyrna_py_to_prop sets its own exceptions */ @@ -4523,9 +4491,8 @@ static int pyrna_struct_setattro(BPy_StructRNA *self, PyObject *pyname, PyObject } return pyrna_py_to_prop(&self->ptr, prop, NULL, value, "bpy_struct: item.attr = val:"); } - else { - return PyObject_GenericSetAttr((PyObject *)self, pyname, value); - } + + return PyObject_GenericSetAttr((PyObject *)self, pyname, value); } static PyObject *pyrna_prop_dir(BPy_PropertyRNA *self) @@ -4563,7 +4530,7 @@ static PyObject *pyrna_prop_collection_getattro(BPy_PropertyRNA *self, PyObject PyErr_SetString(PyExc_AttributeError, "bpy_prop_collection: __getattr__ must be a string"); return NULL; } - else if (name[0] != '_') { + if (name[0] != '_') { PyObject *ret; PropertyRNA *prop; FunctionRNA *func; @@ -4575,7 +4542,7 @@ static PyObject *pyrna_prop_collection_getattro(BPy_PropertyRNA *self, PyObject return ret; } - else if ((func = RNA_struct_find_function(r_ptr.type, name))) { + if ((func = RNA_struct_find_function(r_ptr.type, name))) { PyObject *self_collection = pyrna_struct_CreatePyObject(&r_ptr); ret = pyrna_func_to_py(&((BPy_DummyPointerRNA *)self_collection)->ptr, func); Py_DECREF(self_collection); @@ -4639,11 +4606,11 @@ static int pyrna_prop_collection_setattro(BPy_PropertyRNA *self, PyObject *pynam PyErr_SetString(PyExc_AttributeError, "bpy_prop: __setattr__ must be a string"); return -1; } - else if (value == NULL) { + if (value == NULL) { PyErr_SetString(PyExc_AttributeError, "bpy_prop: del not supported"); return -1; } - else if (RNA_property_collection_type_get(&self->ptr, self->prop, &r_ptr)) { + if (RNA_property_collection_type_get(&self->ptr, self->prop, &r_ptr)) { if ((prop = RNA_struct_find_property(&r_ptr, name))) { /* pyrna_py_to_prop sets its own exceptions. */ return pyrna_py_to_prop(&r_ptr, prop, NULL, value, "BPy_PropertyRNA - Attribute (setattr):"); @@ -4673,9 +4640,8 @@ static PyObject *pyrna_prop_collection_idprop_add(BPy_PropertyRNA *self) "bpy_prop_collection.add(): not supported for this collection"); return NULL; } - else { - return pyrna_struct_CreatePyObject(&r_ptr); - } + + return pyrna_struct_CreatePyObject(&r_ptr); } static PyObject *pyrna_prop_collection_idprop_remove(BPy_PropertyRNA *self, PyObject *value) @@ -5798,7 +5764,7 @@ static PyObject *pyrna_struct_new(PyTypeObject *type, PyObject *args, PyObject * Py_INCREF(base); return (PyObject *)base; } - else if (PyType_IsSubtype(Py_TYPE(base), &pyrna_struct_Type)) { + if (PyType_IsSubtype(Py_TYPE(base), &pyrna_struct_Type)) { /* this almost never runs, only when using user defined subclasses of built-in object. * this isn't common since it's NOT related to registerable subclasses. eg: * @@ -5826,10 +5792,9 @@ static PyObject *pyrna_struct_new(PyTypeObject *type, PyObject *args, PyObject * type->tp_name); return NULL; } - else { - PyErr_Format(PyExc_TypeError, "bpy_struct.__new__(type): expected a single argument"); - return NULL; - } + + PyErr_Format(PyExc_TypeError, "bpy_struct.__new__(type): expected a single argument"); + return NULL; } /* only needed for subtyping, so a new class gets a valid BPy_StructRNA @@ -5845,18 +5810,17 @@ static PyObject *pyrna_prop_new(PyTypeObject *type, PyObject *args, PyObject *UN if (type == Py_TYPE(base)) { return Py_INCREF_RET((PyObject *)base); } - else if (PyType_IsSubtype(type, &pyrna_prop_Type)) { + if (PyType_IsSubtype(type, &pyrna_prop_Type)) { BPy_PropertyRNA *ret = (BPy_PropertyRNA *)type->tp_alloc(type, 0); ret->ptr = base->ptr; ret->prop = base->prop; return (PyObject *)ret; } - else { - PyErr_Format(PyExc_TypeError, - "bpy_prop.__new__(type): type '%.200s' is not a subtype of bpy_prop", - type->tp_name); - return NULL; - } + + PyErr_Format(PyExc_TypeError, + "bpy_prop.__new__(type): type '%.200s' is not a subtype of bpy_prop", + type->tp_name); + return NULL; } static PyObject *pyrna_param_to_py(PointerRNA *ptr, PropertyRNA *prop, void *data) @@ -6192,9 +6156,8 @@ static PyObject *pyrna_func_call(BPy_FunctionRNA *self, PyObject *args, PyObject err = -1; break; } - else { /* PyDict_GetItemString wont raise an error. */ - continue; - } + /* PyDict_GetItemString wont raise an error. */ + continue; } #ifdef DEBUG_STRING_FREE @@ -7131,25 +7094,24 @@ static PyObject *pyrna_prop_collection_iter_next(BPy_PropertyCollectionIterRNA * PyErr_SetNone(PyExc_StopIteration); return NULL; } - else { - BPy_StructRNA *pyrna = (BPy_StructRNA *)pyrna_struct_CreatePyObject(&self->iter.ptr); + + BPy_StructRNA *pyrna = (BPy_StructRNA *)pyrna_struct_CreatePyObject(&self->iter.ptr); # ifdef USE_PYRNA_STRUCT_REFERENCE - if (pyrna) { /* Unlikely, but may fail. */ - if ((PyObject *)pyrna != Py_None) { - /* hold a reference to the iterator since it may have - * allocated memory 'pyrna' needs. eg: introspecting dynamic enum's */ - /* TODO, we could have an api call to know if this is - * needed since most collections don't */ - pyrna_struct_reference_set(pyrna, (PyObject *)self); - } + if (pyrna) { /* Unlikely, but may fail. */ + if ((PyObject *)pyrna != Py_None) { + /* hold a reference to the iterator since it may have + * allocated memory 'pyrna' needs. eg: introspecting dynamic enum's */ + /* TODO, we could have an api call to know if this is + * needed since most collections don't */ + pyrna_struct_reference_set(pyrna, (PyObject *)self); } + } # endif /* !USE_PYRNA_STRUCT_REFERENCE */ - RNA_property_collection_next(&self->iter); + RNA_property_collection_next(&self->iter); - return (PyObject *)pyrna; - } + return (PyObject *)pyrna; } static void pyrna_prop_collection_iter_dealloc(BPy_PropertyCollectionIterRNA *self) @@ -7413,9 +7375,8 @@ static StructRNA *srna_from_ptr(PointerRNA *ptr) if (ptr->type == &RNA_Struct) { return ptr->data; } - else { - return ptr->type; - } + + return ptr->type; } /* Always returns a new ref, be sure to decref when done. */ @@ -7445,15 +7406,14 @@ PyObject *pyrna_struct_CreatePyObject(PointerRNA *ptr) Py_INCREF(pyrna); return (PyObject *)pyrna; } - else { - /* Existing users will need to use 'type_recast' method. */ - Py_DECREF(pyrna); - *instance = NULL; - /* Continue as if no instance was made. */ + + /* Existing users will need to use 'type_recast' method. */ + Py_DECREF(pyrna); + *instance = NULL; + /* Continue as if no instance was made. */ #if 0 /* No need to assign, will be written to next... */ pyrna = NULL; #endif - } } { @@ -7560,9 +7520,8 @@ PyObject *pyrna_id_CreatePyObject(ID *id) RNA_id_pointer_create(id, &ptr); return pyrna_struct_CreatePyObject(&ptr); } - else { - Py_RETURN_NONE; - } + + Py_RETURN_NONE; } bool pyrna_id_FromPyObject(PyObject *obj, ID **id) @@ -7571,10 +7530,9 @@ bool pyrna_id_FromPyObject(PyObject *obj, ID **id) *id = ((BPy_StructRNA *)obj)->ptr.owner_id; return true; } - else { - *id = NULL; - return false; - } + + *id = NULL; + return false; } bool pyrna_id_CheckPyObject(PyObject *obj) @@ -7869,30 +7827,29 @@ StructRNA *srna_from_self(PyObject *self, const char *error_prefix) if (self == NULL) { return NULL; } - else if (PyCapsule_CheckExact(self)) { + if (PyCapsule_CheckExact(self)) { return PyCapsule_GetPointer(self, NULL); } - else if (PyType_Check(self) == 0) { + if (PyType_Check(self) == 0) { return NULL; } - else { - /* These cases above not errors, they just mean the type was not compatible - * After this any errors will be raised in the script */ - PyObject *error_type, *error_value, *error_traceback; - StructRNA *srna; + /* These cases above not errors, they just mean the type was not compatible + * After this any errors will be raised in the script */ - PyErr_Fetch(&error_type, &error_value, &error_traceback); - PyErr_Clear(); + PyObject *error_type, *error_value, *error_traceback; + StructRNA *srna; - srna = pyrna_struct_as_srna(self, false, error_prefix); + PyErr_Fetch(&error_type, &error_value, &error_traceback); + PyErr_Clear(); - if (!PyErr_Occurred()) { - PyErr_Restore(error_type, error_value, error_traceback); - } + srna = pyrna_struct_as_srna(self, false, error_prefix); - return srna; + if (!PyErr_Occurred()) { + PyErr_Restore(error_type, error_value, error_traceback); } + + return srna; } static int deferred_register_prop(StructRNA *srna, PyObject *key, PyObject *item) diff --git a/source/blender/python/intern/bpy_rna_anim.c b/source/blender/python/intern/bpy_rna_anim.c index 8aba2ae8598..ae19f89c348 100644 --- a/source/blender/python/intern/bpy_rna_anim.c +++ b/source/blender/python/intern/bpy_rna_anim.c @@ -181,24 +181,24 @@ static int pyrna_struct_anim_args_parse_no_resolve(PointerRNA *ptr, *r_path_full = path; return 0; } - else { - char *path_prefix = RNA_path_from_ID_to_struct(ptr); - if (path_prefix == NULL) { - PyErr_Format(PyExc_TypeError, - "%.200s could not make path for type %s", - error_prefix, - RNA_struct_identifier(ptr->type)); - return -1; - } - if (*path == '[') { - *r_path_full = BLI_string_joinN(path_prefix, path); - } - else { - *r_path_full = BLI_string_join_by_sep_charN('.', path_prefix, path); - } - MEM_freeN(path_prefix); + char *path_prefix = RNA_path_from_ID_to_struct(ptr); + if (path_prefix == NULL) { + PyErr_Format(PyExc_TypeError, + "%.200s could not make path for type %s", + error_prefix, + RNA_struct_identifier(ptr->type)); + return -1; } + + if (*path == '[') { + *r_path_full = BLI_string_joinN(path_prefix, path); + } + else { + *r_path_full = BLI_string_join_by_sep_charN('.', path_prefix, path); + } + MEM_freeN(path_prefix); + return 0; } @@ -383,33 +383,32 @@ PyObject *pyrna_struct_keyframe_insert(BPy_StructRNA *self, PyObject *args, PyOb return PyBool_FromLong(result); } - else { - ID *id = self->ptr.owner_id; - ReportList reports; - bool result; - BKE_reports_init(&reports, RPT_STORE); + ID *id = self->ptr.owner_id; + ReportList reports; + bool result; - BLI_assert(BKE_id_is_in_global_main(id)); - result = (insert_keyframe(G_MAIN, - &reports, - id, - NULL, - group_name, - path_full, - index, - &anim_eval_context, - keytype, - NULL, - options) != 0); - MEM_freeN((void *)path_full); + BKE_reports_init(&reports, RPT_STORE); - if (BPy_reports_to_error(&reports, PyExc_RuntimeError, true) == -1) { - return NULL; - } + BLI_assert(BKE_id_is_in_global_main(id)); + result = (insert_keyframe(G_MAIN, + &reports, + id, + NULL, + group_name, + path_full, + index, + &anim_eval_context, + keytype, + NULL, + options) != 0); + MEM_freeN((void *)path_full); - return PyBool_FromLong(result); + if (BPy_reports_to_error(&reports, PyExc_RuntimeError, true) == -1) { + return NULL; } + + return PyBool_FromLong(result); } char pyrna_struct_keyframe_delete_doc[] = @@ -453,7 +452,7 @@ PyObject *pyrna_struct_keyframe_delete(BPy_StructRNA *self, PyObject *args, PyOb NULL) == -1) { return NULL; } - else if (self->ptr.type == &RNA_NlaStrip) { + if (self->ptr.type == &RNA_NlaStrip) { /* Handle special properties for NLA Strips, whose F-Curves are stored on the * strips themselves. These are stored separately or else the properties will * not have any effect. @@ -518,22 +517,21 @@ PyObject *pyrna_struct_keyframe_delete(BPy_StructRNA *self, PyObject *args, PyOb return PyBool_FromLong(result); } - else { - bool result; - ReportList reports; - BKE_reports_init(&reports, RPT_STORE); + bool result; + ReportList reports; - result = (delete_keyframe( - G.main, &reports, self->ptr.owner_id, NULL, path_full, index, cfra) != 0); - MEM_freeN((void *)path_full); + BKE_reports_init(&reports, RPT_STORE); - if (BPy_reports_to_error(&reports, PyExc_RuntimeError, true) == -1) { - return NULL; - } + result = (delete_keyframe(G.main, &reports, self->ptr.owner_id, NULL, path_full, index, cfra) != + 0); + MEM_freeN((void *)path_full); - return PyBool_FromLong(result); + if (BPy_reports_to_error(&reports, PyExc_RuntimeError, true) == -1) { + return NULL; } + + return PyBool_FromLong(result); } char pyrna_struct_driver_add_doc[] = @@ -563,60 +561,59 @@ PyObject *pyrna_struct_driver_add(BPy_StructRNA *self, PyObject *args) &self->ptr, "bpy_struct.driver_add():", path, &path_full, &index) == -1) { return NULL; } - else { - PyObject *ret = NULL; - ReportList reports; - int result; - BKE_reports_init(&reports, RPT_STORE); + PyObject *ret = NULL; + ReportList reports; + int result; - result = ANIM_add_driver(&reports, - (ID *)self->ptr.owner_id, - path_full, - index, - CREATEDRIVER_WITH_FMODIFIER, - DRIVER_TYPE_PYTHON); + BKE_reports_init(&reports, RPT_STORE); - if (BPy_reports_to_error(&reports, PyExc_RuntimeError, true) == -1) { - return NULL; - } + result = ANIM_add_driver(&reports, + (ID *)self->ptr.owner_id, + path_full, + index, + CREATEDRIVER_WITH_FMODIFIER, + DRIVER_TYPE_PYTHON); - if (result) { - ID *id = self->ptr.owner_id; - AnimData *adt = BKE_animdata_from_id(id); - FCurve *fcu; + if (BPy_reports_to_error(&reports, PyExc_RuntimeError, true) == -1) { + return NULL; + } - PointerRNA tptr; + if (result) { + ID *id = self->ptr.owner_id; + AnimData *adt = BKE_animdata_from_id(id); + FCurve *fcu; - if (index == -1) { /* all, use a list */ - int i = 0; - ret = PyList_New(0); - while ((fcu = BKE_fcurve_find(&adt->drivers, path_full, i++))) { - RNA_pointer_create(id, &RNA_FCurve, fcu, &tptr); - PyList_APPEND(ret, pyrna_struct_CreatePyObject(&tptr)); - } - } - else { - fcu = BKE_fcurve_find(&adt->drivers, path_full, index); + PointerRNA tptr; + + if (index == -1) { /* all, use a list */ + int i = 0; + ret = PyList_New(0); + while ((fcu = BKE_fcurve_find(&adt->drivers, path_full, i++))) { RNA_pointer_create(id, &RNA_FCurve, fcu, &tptr); - ret = pyrna_struct_CreatePyObject(&tptr); + PyList_APPEND(ret, pyrna_struct_CreatePyObject(&tptr)); } - - bContext *context = BPy_GetContext(); - WM_event_add_notifier(BPy_GetContext(), NC_ANIMATION | ND_FCURVES_ORDER, NULL); - DEG_relations_tag_update(CTX_data_main(context)); } else { - /* XXX, should be handled by reports, */ - PyErr_SetString(PyExc_TypeError, - "bpy_struct.driver_add(): failed because of an internal error"); - return NULL; + fcu = BKE_fcurve_find(&adt->drivers, path_full, index); + RNA_pointer_create(id, &RNA_FCurve, fcu, &tptr); + ret = pyrna_struct_CreatePyObject(&tptr); } - MEM_freeN((void *)path_full); - - return ret; + bContext *context = BPy_GetContext(); + WM_event_add_notifier(BPy_GetContext(), NC_ANIMATION | ND_FCURVES_ORDER, NULL); + DEG_relations_tag_update(CTX_data_main(context)); } + else { + /* XXX, should be handled by reports, */ + PyErr_SetString(PyExc_TypeError, + "bpy_struct.driver_add(): failed because of an internal error"); + return NULL; + } + + MEM_freeN((void *)path_full); + + return ret; } char pyrna_struct_driver_remove_doc[] = @@ -646,26 +643,25 @@ PyObject *pyrna_struct_driver_remove(BPy_StructRNA *self, PyObject *args) &self->ptr, "bpy_struct.driver_remove():", path, &path_full, &index) == -1) { return NULL; } - else { - short result; - ReportList reports; - BKE_reports_init(&reports, RPT_STORE); + short result; + ReportList reports; - result = ANIM_remove_driver(&reports, (ID *)self->ptr.owner_id, path_full, index, 0); + BKE_reports_init(&reports, RPT_STORE); - if (path != path_full) { - MEM_freeN((void *)path_full); - } + result = ANIM_remove_driver(&reports, (ID *)self->ptr.owner_id, path_full, index, 0); - if (BPy_reports_to_error(&reports, PyExc_RuntimeError, true) == -1) { - return NULL; - } - - bContext *context = BPy_GetContext(); - WM_event_add_notifier(context, NC_ANIMATION | ND_FCURVES_ORDER, NULL); - DEG_relations_tag_update(CTX_data_main(context)); - - return PyBool_FromLong(result); + if (path != path_full) { + MEM_freeN((void *)path_full); } + + if (BPy_reports_to_error(&reports, PyExc_RuntimeError, true) == -1) { + return NULL; + } + + bContext *context = BPy_GetContext(); + WM_event_add_notifier(context, NC_ANIMATION | ND_FCURVES_ORDER, NULL); + DEG_relations_tag_update(CTX_data_main(context)); + + return PyBool_FromLong(result); } diff --git a/source/blender/python/intern/bpy_rna_array.c b/source/blender/python/intern/bpy_rna_array.c index 1e5b53b819e..66e07d556a6 100644 --- a/source/blender/python/intern/bpy_rna_array.c +++ b/source/blender/python/intern/bpy_rna_array.c @@ -180,7 +180,7 @@ static int validate_array_type(PyObject *seq, Py_TYPE(seq)->tp_name); return -1; } - else if ((seq_size != dimsize[dim]) && (is_dynamic == false)) { + if ((seq_size != dimsize[dim]) && (is_dynamic == false)) { PyErr_Format(PyExc_ValueError, "%s sequences of dimension %d should contain %d items, not %d", error_prefix, @@ -201,7 +201,7 @@ static int validate_array_type(PyObject *seq, i); return -1; } - else if (!check_item_type(item)) { + if (!check_item_type(item)) { Py_DECREF(item); #if 0 @@ -279,7 +279,7 @@ static int validate_array_length(PyObject *rvalue, RNA_property_identifier(prop)); return -1; } - else if ((RNA_property_flag(prop) & PROP_DYNAMIC) && lvalue_dim == 0) { + if ((RNA_property_flag(prop) & PROP_DYNAMIC) && lvalue_dim == 0) { if (RNA_property_array_length(ptr, prop) != tot) { #if 0 /* length is flexible */ @@ -382,7 +382,7 @@ static int validate_array(PyObject *rvalue, RNA_property_identifier(prop)); return -1; } - else if (totdim != 2) { + if (totdim != 2) { PyErr_Format(PyExc_ValueError, "%s %.200s.%.200s, matrix assign array with %d dimensions", error_prefix, @@ -391,7 +391,7 @@ static int validate_array(PyObject *rvalue, totdim); return -1; } - else if (pymat->num_col != dimsize[0] || pymat->num_row != dimsize[1]) { + if (pymat->num_col != dimsize[0] || pymat->num_row != dimsize[1]) { PyErr_Format(PyExc_ValueError, "%s %.200s.%.200s, matrix assign dimension size mismatch, " "is %dx%d, expected be %dx%d", @@ -404,10 +404,9 @@ static int validate_array(PyObject *rvalue, dimsize[1]); return -1; } - else { - *r_totitem = dimsize[0] * dimsize[1]; - return 0; - } + + *r_totitem = dimsize[0] * dimsize[1]; + return 0; } } #endif /* USE_MATHUTILS */ @@ -1017,31 +1016,31 @@ int pyrna_array_contains_py(PointerRNA *ptr, PropertyRNA *prop, PyObject *value) PyErr_Clear(); return 0; } - else { - float tmp[32]; - float *tmp_arr; - if (len * sizeof(float) > sizeof(tmp)) { - tmp_arr = PyMem_MALLOC(len * sizeof(float)); - } - else { - tmp_arr = tmp; - } + float tmp[32]; + float *tmp_arr; - RNA_property_float_get_array(ptr, prop, tmp_arr); - - for (i = 0; i < len; i++) { - if (tmp_arr[i] == value_f) { - break; - } - } - - if (tmp_arr != tmp) { - PyMem_FREE(tmp_arr); - } - - return i < len ? 1 : 0; + if (len * sizeof(float) > sizeof(tmp)) { + tmp_arr = PyMem_MALLOC(len * sizeof(float)); } + else { + tmp_arr = tmp; + } + + RNA_property_float_get_array(ptr, prop, tmp_arr); + + for (i = 0; i < len; i++) { + if (tmp_arr[i] == value_f) { + break; + } + } + + if (tmp_arr != tmp) { + PyMem_FREE(tmp_arr); + } + + return i < len ? 1 : 0; + break; } case PROP_INT: { @@ -1050,31 +1049,31 @@ int pyrna_array_contains_py(PointerRNA *ptr, PropertyRNA *prop, PyObject *value) PyErr_Clear(); return 0; } - else { - int tmp[32]; - int *tmp_arr; - if (len * sizeof(int) > sizeof(tmp)) { - tmp_arr = PyMem_MALLOC(len * sizeof(int)); - } - else { - tmp_arr = tmp; - } + int tmp[32]; + int *tmp_arr; - RNA_property_int_get_array(ptr, prop, tmp_arr); - - for (i = 0; i < len; i++) { - if (tmp_arr[i] == value_i) { - break; - } - } - - if (tmp_arr != tmp) { - PyMem_FREE(tmp_arr); - } - - return i < len ? 1 : 0; + if (len * sizeof(int) > sizeof(tmp)) { + tmp_arr = PyMem_MALLOC(len * sizeof(int)); } + else { + tmp_arr = tmp; + } + + RNA_property_int_get_array(ptr, prop, tmp_arr); + + for (i = 0; i < len; i++) { + if (tmp_arr[i] == value_i) { + break; + } + } + + if (tmp_arr != tmp) { + PyMem_FREE(tmp_arr); + } + + return i < len ? 1 : 0; + break; } case PROP_BOOLEAN: { @@ -1083,31 +1082,31 @@ int pyrna_array_contains_py(PointerRNA *ptr, PropertyRNA *prop, PyObject *value) PyErr_Clear(); return 0; } - else { - bool tmp[32]; - bool *tmp_arr; - if (len * sizeof(bool) > sizeof(tmp)) { - tmp_arr = PyMem_MALLOC(len * sizeof(bool)); - } - else { - tmp_arr = tmp; - } + bool tmp[32]; + bool *tmp_arr; - RNA_property_boolean_get_array(ptr, prop, tmp_arr); - - for (i = 0; i < len; i++) { - if (tmp_arr[i] == value_i) { - break; - } - } - - if (tmp_arr != tmp) { - PyMem_FREE(tmp_arr); - } - - return i < len ? 1 : 0; + if (len * sizeof(bool) > sizeof(tmp)) { + tmp_arr = PyMem_MALLOC(len * sizeof(bool)); } + else { + tmp_arr = tmp; + } + + RNA_property_boolean_get_array(ptr, prop, tmp_arr); + + for (i = 0; i < len; i++) { + if (tmp_arr[i] == value_i) { + break; + } + } + + if (tmp_arr != tmp) { + PyMem_FREE(tmp_arr); + } + + return i < len ? 1 : 0; + break; } } diff --git a/source/blender/python/intern/bpy_rna_callback.c b/source/blender/python/intern/bpy_rna_callback.c index f9bcb8943f4..976b8a65ac7 100644 --- a/source/blender/python/intern/bpy_rna_callback.c +++ b/source/blender/python/intern/bpy_rna_callback.c @@ -317,10 +317,10 @@ PyObject *pyrna_callback_classmethod_add(PyObject *UNUSED(self), PyObject *args) error_prefix) == -1) { return NULL; } - else if (params.region_type_str && pyrna_enum_value_from_id(rna_enum_region_type_items, - params.region_type_str, - ¶ms.region_type, - error_prefix) == -1) { + if (params.region_type_str && pyrna_enum_value_from_id(rna_enum_region_type_items, + params.region_type_str, + ¶ms.region_type, + error_prefix) == -1) { return NULL; } @@ -352,29 +352,26 @@ PyObject *pyrna_callback_classmethod_add(PyObject *UNUSED(self), PyObject *args) region_draw_mode_items, params.event_str, ¶ms.event, error_prefix) == -1) { return NULL; } - else if (pyrna_enum_value_from_id(rna_enum_region_type_items, - params.region_type_str, - ¶ms.region_type, - error_prefix) == -1) { + if (pyrna_enum_value_from_id(rna_enum_region_type_items, + params.region_type_str, + ¶ms.region_type, + error_prefix) == -1) { return NULL; } - else { - const eSpace_Type spaceid = rna_Space_refine_reverse(srna); - if (spaceid == SPACE_EMPTY) { - PyErr_Format(PyExc_TypeError, "unknown space type '%.200s'", RNA_struct_identifier(srna)); - return NULL; - } - else { - SpaceType *st = BKE_spacetype_from_id(spaceid); - ARegionType *art = BKE_regiontype_from_id(st, params.region_type); - if (art == NULL) { - PyErr_Format( - PyExc_TypeError, "region type '%.200s' not in space", params.region_type_str); - return NULL; - } - handle = ED_region_draw_cb_activate(art, cb_region_draw, (void *)args, params.event); - } + + const eSpace_Type spaceid = rna_Space_refine_reverse(srna); + if (spaceid == SPACE_EMPTY) { + PyErr_Format(PyExc_TypeError, "unknown space type '%.200s'", RNA_struct_identifier(srna)); + return NULL; } + + SpaceType *st = BKE_spacetype_from_id(spaceid); + ARegionType *art = BKE_regiontype_from_id(st, params.region_type); + if (art == NULL) { + PyErr_Format(PyExc_TypeError, "region type '%.200s' not in space", params.region_type_str); + return NULL; + } + handle = ED_region_draw_cb_activate(art, cb_region_draw, (void *)args, params.event); } else { PyErr_SetString(PyExc_TypeError, "callback_add(): type does not support callbacks"); @@ -448,24 +445,21 @@ PyObject *pyrna_callback_classmethod_remove(PyObject *UNUSED(self), PyObject *ar error_prefix) == -1) { return NULL; } - else { - const eSpace_Type spaceid = rna_Space_refine_reverse(srna); - if (spaceid == SPACE_EMPTY) { - PyErr_Format(PyExc_TypeError, "unknown space type '%.200s'", RNA_struct_identifier(srna)); - return NULL; - } - else { - SpaceType *st = BKE_spacetype_from_id(spaceid); - ARegionType *art = BKE_regiontype_from_id(st, params.region_type); - if (art == NULL) { - PyErr_Format( - PyExc_TypeError, "region type '%.200s' not in space", params.region_type_str); - return NULL; - } - ED_region_draw_cb_exit(art, handle); - capsule_clear = true; - } + + const eSpace_Type spaceid = rna_Space_refine_reverse(srna); + if (spaceid == SPACE_EMPTY) { + PyErr_Format(PyExc_TypeError, "unknown space type '%.200s'", RNA_struct_identifier(srna)); + return NULL; } + + SpaceType *st = BKE_spacetype_from_id(spaceid); + ARegionType *art = BKE_regiontype_from_id(st, params.region_type); + if (art == NULL) { + PyErr_Format(PyExc_TypeError, "region type '%.200s' not in space", params.region_type_str); + return NULL; + } + ED_region_draw_cb_exit(art, handle); + capsule_clear = true; } else { PyErr_SetString(PyExc_TypeError, "callback_remove(): type does not support callbacks"); diff --git a/source/blender/python/intern/bpy_rna_gizmo.c b/source/blender/python/intern/bpy_rna_gizmo.c index aff81c68358..4ef718ef023 100644 --- a/source/blender/python/intern/bpy_rna_gizmo.c +++ b/source/blender/python/intern/bpy_rna_gizmo.c @@ -367,10 +367,10 @@ static PyObject *bpy_gizmo_target_get_value(PyObject *UNUSED(self), PyObject *ar WM_gizmo_target_property_float_get_array(gz, gz_prop, value); return PyC_Tuple_PackArray_F32(value, array_len); } - else { - float value = WM_gizmo_target_property_float_get(gz, gz_prop); - return PyFloat_FromDouble(value); - } + + float value = WM_gizmo_target_property_float_get(gz, gz_prop); + return PyFloat_FromDouble(value); + break; } default: { diff --git a/source/blender/python/mathutils/mathutils.c b/source/blender/python/mathutils/mathutils.c index 5764db4e70c..308d2ef9618 100644 --- a/source/blender/python/mathutils/mathutils.c +++ b/source/blender/python/mathutils/mathutils.c @@ -249,42 +249,41 @@ int mathutils_array_parse_alloc(float **array, memcpy(*array, ((BaseMathObject *)value)->data, size * sizeof(float)); return size; } - else + #endif - { - PyObject *value_fast = NULL; - // *array = NULL; - int ret; - /* non list/tuple cases */ - if (!(value_fast = PySequence_Fast(value, error_prefix))) { - /* PySequence_Fast sets the error */ - return -1; - } + PyObject *value_fast = NULL; + // *array = NULL; + int ret; - size = PySequence_Fast_GET_SIZE(value_fast); - - if (size < array_min) { - Py_DECREF(value_fast); - PyErr_Format(PyExc_ValueError, - "%.200s: sequence size is %d, expected > %d", - error_prefix, - size, - array_min); - return -1; - } - - *array = PyMem_Malloc(size * sizeof(float)); - - ret = mathutils_array_parse_fast(*array, size, value_fast, error_prefix); - Py_DECREF(value_fast); - - if (ret == -1) { - PyMem_Free(*array); - } - - return ret; + /* non list/tuple cases */ + if (!(value_fast = PySequence_Fast(value, error_prefix))) { + /* PySequence_Fast sets the error */ + return -1; } + + size = PySequence_Fast_GET_SIZE(value_fast); + + if (size < array_min) { + Py_DECREF(value_fast); + PyErr_Format(PyExc_ValueError, + "%.200s: sequence size is %d, expected > %d", + error_prefix, + size, + array_min); + return -1; + } + + *array = PyMem_Malloc(size * sizeof(float)); + + ret = mathutils_array_parse_fast(*array, size, value_fast, error_prefix); + Py_DECREF(value_fast); + + if (ret == -1) { + PyMem_Free(*array); + } + + return ret; } /* parse an array of vectors */ @@ -482,45 +481,41 @@ int mathutils_any_to_rotmat(float rmat[3][3], PyObject *value, const char *error if (BaseMath_ReadCallback((BaseMathObject *)value) == -1) { return -1; } - else { - eulO_to_mat3(rmat, ((EulerObject *)value)->eul, ((EulerObject *)value)->order); - return 0; - } + + eulO_to_mat3(rmat, ((EulerObject *)value)->eul, ((EulerObject *)value)->order); + return 0; } - else if (QuaternionObject_Check(value)) { + if (QuaternionObject_Check(value)) { if (BaseMath_ReadCallback((BaseMathObject *)value) == -1) { return -1; } - else { - float tquat[4]; - normalize_qt_qt(tquat, ((QuaternionObject *)value)->quat); - quat_to_mat3(rmat, tquat); - return 0; - } + + float tquat[4]; + normalize_qt_qt(tquat, ((QuaternionObject *)value)->quat); + quat_to_mat3(rmat, tquat); + return 0; } - else if (MatrixObject_Check(value)) { + if (MatrixObject_Check(value)) { if (BaseMath_ReadCallback((BaseMathObject *)value) == -1) { return -1; } - else if (((MatrixObject *)value)->num_row < 3 || ((MatrixObject *)value)->num_col < 3) { + if (((MatrixObject *)value)->num_row < 3 || ((MatrixObject *)value)->num_col < 3) { PyErr_Format( PyExc_ValueError, "%.200s: matrix must have minimum 3x3 dimensions", error_prefix); return -1; } - else { - matrix_as_3x3(rmat, (MatrixObject *)value); - normalize_m3(rmat); - return 0; - } - } - else { - PyErr_Format(PyExc_TypeError, - "%.200s: expected a Euler, Quaternion or Matrix type, " - "found %.200s", - error_prefix, - Py_TYPE(value)->tp_name); - return -1; + + matrix_as_3x3(rmat, (MatrixObject *)value); + normalize_m3(rmat); + return 0; } + + PyErr_Format(PyExc_TypeError, + "%.200s: expected a Euler, Quaternion or Matrix type, " + "found %.200s", + error_prefix, + Py_TYPE(value)->tp_name); + return -1; } /* ----------------------------------MATRIX FUNCTIONS-------------------- */ diff --git a/source/blender/python/mathutils/mathutils_Color.c b/source/blender/python/mathutils/mathutils_Color.c index 08dede8ff78..6bffff467cd 100644 --- a/source/blender/python/mathutils/mathutils_Color.c +++ b/source/blender/python/mathutils/mathutils_Color.c @@ -347,7 +347,7 @@ static PyObject *Color_subscript(ColorObject *self, PyObject *item) } return Color_item(self, i); } - else if (PySlice_Check(item)) { + if (PySlice_Check(item)) { Py_ssize_t start, stop, step, slicelength; if (PySlice_GetIndicesEx(item, COLOR_SIZE, &start, &stop, &step, &slicelength) < 0) { @@ -357,19 +357,17 @@ static PyObject *Color_subscript(ColorObject *self, PyObject *item) if (slicelength <= 0) { return PyTuple_New(0); } - else if (step == 1) { + if (step == 1) { return Color_slice(self, start, stop); } - else { - PyErr_SetString(PyExc_IndexError, "slice steps not supported with color"); - return NULL; - } - } - else { - PyErr_Format( - PyExc_TypeError, "color indices must be integers, not %.200s", Py_TYPE(item)->tp_name); + + PyErr_SetString(PyExc_IndexError, "slice steps not supported with color"); return NULL; } + + PyErr_Format( + PyExc_TypeError, "color indices must be integers, not %.200s", Py_TYPE(item)->tp_name); + return NULL; } static int Color_ass_subscript(ColorObject *self, PyObject *item, PyObject *value) @@ -384,7 +382,7 @@ static int Color_ass_subscript(ColorObject *self, PyObject *item, PyObject *valu } return Color_ass_item(self, i, value); } - else if (PySlice_Check(item)) { + if (PySlice_Check(item)) { Py_ssize_t start, stop, step, slicelength; if (PySlice_GetIndicesEx(item, COLOR_SIZE, &start, &stop, &step, &slicelength) < 0) { @@ -394,16 +392,14 @@ static int Color_ass_subscript(ColorObject *self, PyObject *item, PyObject *valu if (step == 1) { return Color_ass_slice(self, start, stop, value); } - else { - PyErr_SetString(PyExc_IndexError, "slice steps not supported with color"); - return -1; - } - } - else { - PyErr_Format( - PyExc_TypeError, "color indices must be integers, not %.200s", Py_TYPE(item)->tp_name); + + PyErr_SetString(PyExc_IndexError, "slice steps not supported with color"); return -1; } + + PyErr_Format( + PyExc_TypeError, "color indices must be integers, not %.200s", Py_TYPE(item)->tp_name); + return -1; } /* -----------------PROTCOL DECLARATIONS-------------------------- */ diff --git a/source/blender/python/mathutils/mathutils_Euler.c b/source/blender/python/mathutils/mathutils_Euler.c index 7ece587e38f..ebc71706bef 100644 --- a/source/blender/python/mathutils/mathutils_Euler.c +++ b/source/blender/python/mathutils/mathutils_Euler.c @@ -558,7 +558,7 @@ static PyObject *Euler_subscript(EulerObject *self, PyObject *item) } return Euler_item(self, i); } - else if (PySlice_Check(item)) { + if (PySlice_Check(item)) { Py_ssize_t start, stop, step, slicelength; if (PySlice_GetIndicesEx(item, EULER_SIZE, &start, &stop, &step, &slicelength) < 0) { @@ -568,19 +568,17 @@ static PyObject *Euler_subscript(EulerObject *self, PyObject *item) if (slicelength <= 0) { return PyTuple_New(0); } - else if (step == 1) { + if (step == 1) { return Euler_slice(self, start, stop); } - else { - PyErr_SetString(PyExc_IndexError, "slice steps not supported with eulers"); - return NULL; - } - } - else { - PyErr_Format( - PyExc_TypeError, "euler indices must be integers, not %.200s", Py_TYPE(item)->tp_name); + + PyErr_SetString(PyExc_IndexError, "slice steps not supported with eulers"); return NULL; } + + PyErr_Format( + PyExc_TypeError, "euler indices must be integers, not %.200s", Py_TYPE(item)->tp_name); + return NULL; } static int Euler_ass_subscript(EulerObject *self, PyObject *item, PyObject *value) @@ -595,7 +593,7 @@ static int Euler_ass_subscript(EulerObject *self, PyObject *item, PyObject *valu } return Euler_ass_item(self, i, value); } - else if (PySlice_Check(item)) { + if (PySlice_Check(item)) { Py_ssize_t start, stop, step, slicelength; if (PySlice_GetIndicesEx(item, EULER_SIZE, &start, &stop, &step, &slicelength) < 0) { @@ -605,16 +603,14 @@ static int Euler_ass_subscript(EulerObject *self, PyObject *item, PyObject *valu if (step == 1) { return Euler_ass_slice(self, start, stop, value); } - else { - PyErr_SetString(PyExc_IndexError, "slice steps not supported with euler"); - return -1; - } - } - else { - PyErr_Format( - PyExc_TypeError, "euler indices must be integers, not %.200s", Py_TYPE(item)->tp_name); + + PyErr_SetString(PyExc_IndexError, "slice steps not supported with euler"); return -1; } + + PyErr_Format( + PyExc_TypeError, "euler indices must be integers, not %.200s", Py_TYPE(item)->tp_name); + return -1; } /* -----------------PROTCOL DECLARATIONS-------------------------- */ diff --git a/source/blender/python/mathutils/mathutils_Matrix.c b/source/blender/python/mathutils/mathutils_Matrix.c index 3e30c81c8c6..236bb1de29d 100644 --- a/source/blender/python/mathutils/mathutils_Matrix.c +++ b/source/blender/python/mathutils/mathutils_Matrix.c @@ -54,9 +54,8 @@ static int matrix_row_vector_check(MatrixObject *mat, VectorObject *vec, int row "owner matrix has been resized since this row vector was created"); return 0; } - else { - return 1; - } + + return 1; } static int matrix_col_vector_check(MatrixObject *mat, VectorObject *vec, int col) @@ -67,9 +66,8 @@ static int matrix_col_vector_check(MatrixObject *mat, VectorObject *vec, int col "owner matrix has been resized since this column vector was created"); return 0; } - else { - return 1; - } + + return 1; } /* ---------------------------------------------------------------------------- @@ -380,9 +378,8 @@ static PyObject *Matrix_new(PyTypeObject *type, PyObject *args, PyObject *kwds) if (Matrix_ass_slice((MatrixObject *)matrix, 0, INT_MAX, arg) == 0) { return matrix; } - else { /* matrix ok, slice assignment not */ - Py_DECREF(matrix); - } + /* matrix ok, slice assignment not */ + Py_DECREF(matrix); } } break; @@ -406,15 +403,13 @@ static PyObject *matrix__apply_to_copy(PyObject *(*matrix_func)(MatrixObject *), Py_DECREF(ret_dummy); return ret; } - else { /* error */ - Py_DECREF(ret); - return NULL; - } - } - else { - /* copy may fail if the read callback errors out */ + /* error */ + Py_DECREF(ret); return NULL; } + + /* copy may fail if the read callback errors out */ + return NULL; } /* when a matrix is 4x4 size but initialized as a 3x3, re-assign values for 4x4 */ @@ -512,10 +507,9 @@ static PyObject *C_Matrix_Rotation(PyObject *cls, PyObject *args) "or a string in 'X', 'Y', 'Z'"); return NULL; } - else { - /* use the string */ - vec = NULL; - } + + /* use the string */ + vec = NULL; } angle = angle_wrap_rad(angle); @@ -1023,7 +1017,7 @@ static float matrix_determinant_internal(const MatrixObject *self) MATRIX_ITEM(self, 1, 0), MATRIX_ITEM(self, 1, 1)); } - else if (self->num_col == 3) { + if (self->num_col == 3) { return determinant_m3(MATRIX_ITEM(self, 0, 0), MATRIX_ITEM(self, 0, 1), MATRIX_ITEM(self, 0, 2), @@ -1034,9 +1028,8 @@ static float matrix_determinant_internal(const MatrixObject *self) MATRIX_ITEM(self, 2, 1), MATRIX_ITEM(self, 2, 2)); } - else { - return determinant_m4((float(*)[4])self->matrix); - } + + return determinant_m4((float(*)[4])self->matrix); } static void adjoint_matrix_n(float *mat_dst, const float *mat_src, const ushort dim) @@ -1094,9 +1087,8 @@ static bool matrix_invert_internal(const MatrixObject *self, float *r_mat) matrix_invert_with_det_n_internal(r_mat, self->matrix, det, self->num_col); return true; } - else { - return false; - } + + return false; } /** @@ -1475,9 +1467,8 @@ static bool matrix_invert_is_compat(const MatrixObject *self) "only square matrices are supported"); return false; } - else { - return true; - } + + return true; } static bool matrix_invert_args_check(const MatrixObject *self, PyObject *args, bool check_type) @@ -1605,10 +1596,9 @@ static PyObject *Matrix_inverted(MatrixObject *self, PyObject *args) Py_INCREF(fallback); return fallback; } - else { - matrix_invert_raise_degenerate(); - return NULL; - } + + matrix_invert_raise_degenerate(); + return NULL; } return Matrix_copy_notest(self, mat); @@ -2386,48 +2376,47 @@ static int Matrix_ass_slice(MatrixObject *self, int begin, int end, PyObject *va /* PySequence_Fast sets the error */ return -1; } - else { - PyObject **value_fast_items = PySequence_Fast_ITEMS(value_fast); - const int size = end - begin; - int row, col; - float mat[MATRIX_MAX_DIM * MATRIX_MAX_DIM]; - float vec[4]; - if (PySequence_Fast_GET_SIZE(value_fast) != size) { + PyObject **value_fast_items = PySequence_Fast_ITEMS(value_fast); + const int size = end - begin; + int row, col; + float mat[MATRIX_MAX_DIM * MATRIX_MAX_DIM]; + float vec[4]; + + if (PySequence_Fast_GET_SIZE(value_fast) != size) { + Py_DECREF(value_fast); + PyErr_SetString(PyExc_ValueError, + "matrix[begin:end] = []: " + "size mismatch in slice assignment"); + return -1; + } + + memcpy(mat, self->matrix, self->num_col * self->num_row * sizeof(float)); + + /* parse sub items */ + for (row = begin; row < end; row++) { + /* parse each sub sequence */ + PyObject *item = value_fast_items[row - begin]; + + if (mathutils_array_parse( + vec, self->num_col, self->num_col, item, "matrix[begin:end] = value assignment") == + -1) { Py_DECREF(value_fast); - PyErr_SetString(PyExc_ValueError, - "matrix[begin:end] = []: " - "size mismatch in slice assignment"); return -1; } - memcpy(mat, self->matrix, self->num_col * self->num_row * sizeof(float)); - - /* parse sub items */ - for (row = begin; row < end; row++) { - /* parse each sub sequence */ - PyObject *item = value_fast_items[row - begin]; - - if (mathutils_array_parse( - vec, self->num_col, self->num_col, item, "matrix[begin:end] = value assignment") == - -1) { - Py_DECREF(value_fast); - return -1; - } - - for (col = 0; col < self->num_col; col++) { - mat[col * self->num_row + row] = vec[col]; - } + for (col = 0; col < self->num_col; col++) { + mat[col * self->num_row + row] = vec[col]; } - - Py_DECREF(value_fast); - - /*parsed well - now set in matrix*/ - memcpy(self->matrix, mat, self->num_col * self->num_row * sizeof(float)); - - (void)BaseMath_WriteCallback(self); - return 0; } + + Py_DECREF(value_fast); + + /*parsed well - now set in matrix*/ + memcpy(self->matrix, mat, self->num_col * self->num_row * sizeof(float)); + + (void)BaseMath_WriteCallback(self); + return 0; } /*------------------------NUMERIC PROTOCOLS---------------------- *------------------------obj + obj------------------------------*/ @@ -2540,7 +2529,7 @@ static PyObject *Matrix_mul(PyObject *m1, PyObject *m2) return Matrix_CreatePyObject(mat, mat2->num_col, mat1->num_row, Py_TYPE(mat1)); } - else if (mat2) { + if (mat2) { /*FLOAT/INT * MATRIX */ if (((scalar = PyFloat_AsDouble(m1)) == -1.0f && PyErr_Occurred()) == 0) { return matrix_mul_float(mat2, scalar); @@ -2655,7 +2644,7 @@ static PyObject *Matrix_matmul(PyObject *m1, PyObject *m2) return Matrix_CreatePyObject(mat, mat2->num_col, mat1->num_row, Py_TYPE(mat1)); } - else if (mat1) { + if (mat1) { /* MATRIX @ VECTOR */ if (VectorObject_Check(m2)) { VectorObject *vec2 = (VectorObject *)m2; @@ -2772,7 +2761,7 @@ static PyObject *Matrix_subscript(MatrixObject *self, PyObject *item) } return Matrix_item_row(self, i); } - else if (PySlice_Check(item)) { + if (PySlice_Check(item)) { Py_ssize_t start, stop, step, slicelength; if (PySlice_GetIndicesEx(item, self->num_row, &start, &stop, &step, &slicelength) < 0) { @@ -2782,19 +2771,17 @@ static PyObject *Matrix_subscript(MatrixObject *self, PyObject *item) if (slicelength <= 0) { return PyTuple_New(0); } - else if (step == 1) { + if (step == 1) { return Matrix_slice(self, start, stop); } - else { - PyErr_SetString(PyExc_IndexError, "slice steps not supported with matrices"); - return NULL; - } - } - else { - PyErr_Format( - PyExc_TypeError, "matrix indices must be integers, not %.200s", Py_TYPE(item)->tp_name); + + PyErr_SetString(PyExc_IndexError, "slice steps not supported with matrices"); return NULL; } + + PyErr_Format( + PyExc_TypeError, "matrix indices must be integers, not %.200s", Py_TYPE(item)->tp_name); + return NULL; } static int Matrix_ass_subscript(MatrixObject *self, PyObject *item, PyObject *value) @@ -2809,7 +2796,7 @@ static int Matrix_ass_subscript(MatrixObject *self, PyObject *item, PyObject *va } return Matrix_ass_item_row(self, i, value); } - else if (PySlice_Check(item)) { + if (PySlice_Check(item)) { Py_ssize_t start, stop, step, slicelength; if (PySlice_GetIndicesEx(item, self->num_row, &start, &stop, &step, &slicelength) < 0) { @@ -2819,16 +2806,14 @@ static int Matrix_ass_subscript(MatrixObject *self, PyObject *item, PyObject *va if (step == 1) { return Matrix_ass_slice(self, start, stop, value); } - else { - PyErr_SetString(PyExc_IndexError, "slice steps not supported with matrices"); - return -1; - } - } - else { - PyErr_Format( - PyExc_TypeError, "matrix indices must be integers, not %.200s", Py_TYPE(item)->tp_name); + + PyErr_SetString(PyExc_IndexError, "slice steps not supported with matrices"); return -1; } + + PyErr_Format( + PyExc_TypeError, "matrix indices must be integers, not %.200s", Py_TYPE(item)->tp_name); + return -1; } static PyMappingMethods Matrix_AsMapping = { @@ -2977,15 +2962,14 @@ static PyObject *Matrix_is_negative_get(MatrixObject *self, void *UNUSED(closure if (self->num_row == 4 && self->num_col == 4) { return PyBool_FromLong(is_negative_m4((float(*)[4])self->matrix)); } - else if (self->num_row == 3 && self->num_col == 3) { + if (self->num_row == 3 && self->num_col == 3) { return PyBool_FromLong(is_negative_m3((float(*)[3])self->matrix)); } - else { - PyErr_SetString(PyExc_AttributeError, - "Matrix.is_negative: " - "inappropriate matrix size - expects 3x3 or 4x4 matrix"); - return NULL; - } + + PyErr_SetString(PyExc_AttributeError, + "Matrix.is_negative: " + "inappropriate matrix size - expects 3x3 or 4x4 matrix"); + return NULL; } PyDoc_STRVAR(Matrix_is_orthogonal_doc, @@ -3000,15 +2984,14 @@ static PyObject *Matrix_is_orthogonal_get(MatrixObject *self, void *UNUSED(closu if (self->num_row == 4 && self->num_col == 4) { return PyBool_FromLong(is_orthonormal_m4((float(*)[4])self->matrix)); } - else if (self->num_row == 3 && self->num_col == 3) { + if (self->num_row == 3 && self->num_col == 3) { return PyBool_FromLong(is_orthonormal_m3((float(*)[3])self->matrix)); } - else { - PyErr_SetString(PyExc_AttributeError, - "Matrix.is_orthogonal: " - "inappropriate matrix size - expects 3x3 or 4x4 matrix"); - return NULL; - } + + PyErr_SetString(PyExc_AttributeError, + "Matrix.is_orthogonal: " + "inappropriate matrix size - expects 3x3 or 4x4 matrix"); + return NULL; } PyDoc_STRVAR(Matrix_is_orthogonal_axis_vectors_doc, @@ -3024,15 +3007,14 @@ static PyObject *Matrix_is_orthogonal_axis_vectors_get(MatrixObject *self, void if (self->num_row == 4 && self->num_col == 4) { return PyBool_FromLong(is_orthogonal_m4((float(*)[4])self->matrix)); } - else if (self->num_row == 3 && self->num_col == 3) { + if (self->num_row == 3 && self->num_col == 3) { return PyBool_FromLong(is_orthogonal_m3((float(*)[3])self->matrix)); } - else { - PyErr_SetString(PyExc_AttributeError, - "Matrix.is_orthogonal_axis_vectors: " - "inappropriate matrix size - expects 3x3 or 4x4 matrix"); - return NULL; - } + + PyErr_SetString(PyExc_AttributeError, + "Matrix.is_orthogonal_axis_vectors: " + "inappropriate matrix size - expects 3x3 or 4x4 matrix"); + return NULL; } /*****************************************************************************/ @@ -3478,14 +3460,13 @@ static PyObject *MatrixAccess_subscript(MatrixAccessObject *self, PyObject *item } return Matrix_item_row(matrix_user, i); } - else { /* MAT_ACCESS_ROW */ - if (i < 0) { - i += matrix_user->num_col; - } - return Matrix_item_col(matrix_user, i); + /* MAT_ACCESS_ROW */ + if (i < 0) { + i += matrix_user->num_col; } + return Matrix_item_col(matrix_user, i); } - else if (PySlice_Check(item)) { + if (PySlice_Check(item)) { Py_ssize_t start, stop, step, slicelength; if (PySlice_GetIndicesEx(item, MatrixAccess_len(self), &start, &stop, &step, &slicelength) < @@ -3496,19 +3477,17 @@ static PyObject *MatrixAccess_subscript(MatrixAccessObject *self, PyObject *item if (slicelength <= 0) { return PyTuple_New(0); } - else if (step == 1) { + if (step == 1) { return MatrixAccess_slice(self, start, stop); } - else { - PyErr_SetString(PyExc_IndexError, "slice steps not supported with matrix accessors"); - return NULL; - } - } - else { - PyErr_Format( - PyExc_TypeError, "matrix indices must be integers, not %.200s", Py_TYPE(item)->tp_name); + + PyErr_SetString(PyExc_IndexError, "slice steps not supported with matrix accessors"); return NULL; } + + PyErr_Format( + PyExc_TypeError, "matrix indices must be integers, not %.200s", Py_TYPE(item)->tp_name); + return NULL; } static int MatrixAccess_ass_subscript(MatrixAccessObject *self, PyObject *item, PyObject *value) @@ -3527,19 +3506,17 @@ static int MatrixAccess_ass_subscript(MatrixAccessObject *self, PyObject *item, } return Matrix_ass_item_row(matrix_user, i, value); } - else { /* MAT_ACCESS_ROW */ - if (i < 0) { - i += matrix_user->num_col; - } - return Matrix_ass_item_col(matrix_user, i, value); + /* MAT_ACCESS_ROW */ + if (i < 0) { + i += matrix_user->num_col; } + return Matrix_ass_item_col(matrix_user, i, value); } /* TODO, slice */ - else { - PyErr_Format( - PyExc_TypeError, "matrix indices must be integers, not %.200s", Py_TYPE(item)->tp_name); - return -1; - } + + PyErr_Format( + PyExc_TypeError, "matrix indices must be integers, not %.200s", Py_TYPE(item)->tp_name); + return -1; } static PyObject *MatrixAccess_iter(MatrixAccessObject *self) diff --git a/source/blender/python/mathutils/mathutils_Quaternion.c b/source/blender/python/mathutils/mathutils_Quaternion.c index 2b7761b7678..b0e6b330968 100644 --- a/source/blender/python/mathutils/mathutils_Quaternion.c +++ b/source/blender/python/mathutils/mathutils_Quaternion.c @@ -815,7 +815,7 @@ static PyObject *Quaternion_subscript(QuaternionObject *self, PyObject *item) } return Quaternion_item(self, i); } - else if (PySlice_Check(item)) { + if (PySlice_Check(item)) { Py_ssize_t start, stop, step, slicelength; if (PySlice_GetIndicesEx(item, QUAT_SIZE, &start, &stop, &step, &slicelength) < 0) { @@ -825,20 +825,17 @@ static PyObject *Quaternion_subscript(QuaternionObject *self, PyObject *item) if (slicelength <= 0) { return PyTuple_New(0); } - else if (step == 1) { + if (step == 1) { return Quaternion_slice(self, start, stop); } - else { - PyErr_SetString(PyExc_IndexError, "slice steps not supported with quaternions"); - return NULL; - } - } - else { - PyErr_Format(PyExc_TypeError, - "quaternion indices must be integers, not %.200s", - Py_TYPE(item)->tp_name); + + PyErr_SetString(PyExc_IndexError, "slice steps not supported with quaternions"); return NULL; } + + PyErr_Format( + PyExc_TypeError, "quaternion indices must be integers, not %.200s", Py_TYPE(item)->tp_name); + return NULL; } static int Quaternion_ass_subscript(QuaternionObject *self, PyObject *item, PyObject *value) @@ -853,7 +850,7 @@ static int Quaternion_ass_subscript(QuaternionObject *self, PyObject *item, PyOb } return Quaternion_ass_item(self, i, value); } - else if (PySlice_Check(item)) { + if (PySlice_Check(item)) { Py_ssize_t start, stop, step, slicelength; if (PySlice_GetIndicesEx(item, QUAT_SIZE, &start, &stop, &step, &slicelength) < 0) { @@ -863,17 +860,14 @@ static int Quaternion_ass_subscript(QuaternionObject *self, PyObject *item, PyOb if (step == 1) { return Quaternion_ass_slice(self, start, stop, value); } - else { - PyErr_SetString(PyExc_IndexError, "slice steps not supported with quaternion"); - return -1; - } - } - else { - PyErr_Format(PyExc_TypeError, - "quaternion indices must be integers, not %.200s", - Py_TYPE(item)->tp_name); + + PyErr_SetString(PyExc_IndexError, "slice steps not supported with quaternion"); return -1; } + + PyErr_Format( + PyExc_TypeError, "quaternion indices must be integers, not %.200s", Py_TYPE(item)->tp_name); + return -1; } /* ------------------------NUMERIC PROTOCOLS---------------------- */ @@ -967,7 +961,7 @@ static PyObject *Quaternion_mul(PyObject *q1, PyObject *q2) return Quaternion_CreatePyObject(quat, Py_TYPE(q1)); } /* the only case this can happen (for a supported type is "FLOAT * QUAT") */ - else if (quat2) { /* FLOAT * QUAT */ + if (quat2) { /* FLOAT * QUAT */ if (((scalar = PyFloat_AsDouble(q1)) == -1.0f && PyErr_Occurred()) == 0) { return quat_mul_float(quat2, scalar); } @@ -1049,7 +1043,7 @@ static PyObject *Quaternion_matmul(PyObject *q1, PyObject *q2) mul_qt_qtqt(quat, quat1->quat, quat2->quat); return Quaternion_CreatePyObject(quat, Py_TYPE(q1)); } - else if (quat1) { + if (quat1) { /* QUAT @ VEC */ if (VectorObject_Check(q2)) { VectorObject *vec2 = (VectorObject *)q2; @@ -1384,10 +1378,9 @@ static PyObject *quat__apply_to_copy(PyObject *(*quat_func)(QuaternionObject *), Py_DECREF(ret_dummy); return ret; } - else { /* error */ - Py_DECREF(ret); - return NULL; - } + /* error */ + Py_DECREF(ret); + return NULL; } /* axis vector suffers from precision errors, use this function to ensure */ diff --git a/source/blender/python/mathutils/mathutils_Vector.c b/source/blender/python/mathutils/mathutils_Vector.c index 4b47440a530..b30aafbf875 100644 --- a/source/blender/python/mathutils/mathutils_Vector.c +++ b/source/blender/python/mathutils/mathutils_Vector.c @@ -104,10 +104,9 @@ static PyObject *vec__apply_to_copy(PyObject *(*vec_func)(VectorObject *), Vecto Py_DECREF(ret_dummy); return (PyObject *)ret; } - else { /* error */ - Py_DECREF(ret); - return NULL; - } + /* error */ + Py_DECREF(ret); + return NULL; } /*-----------------------CLASS-METHODS----------------------------*/ @@ -1004,12 +1003,11 @@ static PyObject *Vector_angle(VectorObject *self, PyObject *args) Py_INCREF(fallback); return fallback; } - else { - PyErr_SetString(PyExc_ValueError, - "Vector.angle(other): " - "zero length vectors have no valid angle"); - return NULL; - } + + PyErr_SetString(PyExc_ValueError, + "Vector.angle(other): " + "zero length vectors have no valid angle"); + return NULL; } return PyFloat_FromDouble(saacos(dot / (sqrt(dot_self) * sqrt(dot_other)))); @@ -1059,12 +1057,11 @@ static PyObject *Vector_angle_signed(VectorObject *self, PyObject *args) Py_INCREF(fallback); return fallback; } - else { - PyErr_SetString(PyExc_ValueError, - "Vector.angle_signed(other): " - "zero length vectors have no valid angle"); - return NULL; - } + + PyErr_SetString(PyExc_ValueError, + "Vector.angle_signed(other): " + "zero length vectors have no valid angle"); + return NULL; } return PyFloat_FromDouble(angle_signed_v2v2(self->vec, tvec)); @@ -1238,12 +1235,11 @@ static PyObject *Vector_slerp(VectorObject *self, PyObject *args) Py_INCREF(fallback); return fallback; } - else { - PyErr_SetString(PyExc_ValueError, - "Vector.slerp(): " - "zero length vectors unsupported"); - return NULL; - } + + PyErr_SetString(PyExc_ValueError, + "Vector.slerp(): " + "zero length vectors unsupported"); + return NULL; } /* We have sane state, execute slerp */ @@ -1256,12 +1252,11 @@ static PyObject *Vector_slerp(VectorObject *self, PyObject *args) Py_INCREF(fallback); return fallback; } - else { - PyErr_SetString(PyExc_ValueError, - "Vector.slerp(): " - "opposite vectors unsupported"); - return NULL; - } + + PyErr_SetString(PyExc_ValueError, + "Vector.slerp(): " + "opposite vectors unsupported"); + return NULL; } interp_dot_slerp(fac, cosom, w); @@ -1785,7 +1780,7 @@ static PyObject *Vector_mul(PyObject *v1, PyObject *v2) /* element-wise product */ return vector_mul_vec(vec1, vec2); } - else if (vec1) { + if (vec1) { if (((scalar = PyFloat_AsDouble(v2)) == -1.0f && PyErr_Occurred()) == 0) { /* VEC * FLOAT */ return vector_mul_float(vec1, scalar); } @@ -1890,7 +1885,7 @@ static PyObject *Vector_matmul(PyObject *v1, PyObject *v2) /*dot product*/ return PyFloat_FromDouble(dot_vn_vn(vec1->vec, vec2->vec, vec1->size)); } - else if (vec1) { + if (vec1) { if (MatrixObject_Check(v2)) { /* VEC @ MATRIX */ float tvec[MAX_DIMENSIONS]; @@ -2039,9 +2034,8 @@ static PyObject *Vector_richcmpr(PyObject *objectA, PyObject *objectB, int compa if (comparison_type == Py_NE) { Py_RETURN_TRUE; } - else { - Py_RETURN_FALSE; - } + + Py_RETURN_FALSE; } vecA = (VectorObject *)objectA; vecB = (VectorObject *)objectB; @@ -2054,9 +2048,8 @@ static PyObject *Vector_richcmpr(PyObject *objectA, PyObject *objectB, int compa if (comparison_type == Py_NE) { Py_RETURN_TRUE; } - else { - Py_RETURN_FALSE; - } + + Py_RETURN_FALSE; } switch (comparison_type) { @@ -2107,9 +2100,8 @@ static PyObject *Vector_richcmpr(PyObject *objectA, PyObject *objectB, int compa if (result == 1) { Py_RETURN_TRUE; } - else { - Py_RETURN_FALSE; - } + + Py_RETURN_FALSE; } static Py_hash_t Vector_hash(VectorObject *self) @@ -2152,7 +2144,7 @@ static PyObject *Vector_subscript(VectorObject *self, PyObject *item) } return Vector_item(self, i); } - else if (PySlice_Check(item)) { + if (PySlice_Check(item)) { Py_ssize_t start, stop, step, slicelength; if (PySlice_GetIndicesEx(item, self->size, &start, &stop, &step, &slicelength) < 0) { @@ -2162,19 +2154,17 @@ static PyObject *Vector_subscript(VectorObject *self, PyObject *item) if (slicelength <= 0) { return PyTuple_New(0); } - else if (step == 1) { + if (step == 1) { return Vector_slice(self, start, stop); } - else { - PyErr_SetString(PyExc_IndexError, "slice steps not supported with vectors"); - return NULL; - } - } - else { - PyErr_Format( - PyExc_TypeError, "vector indices must be integers, not %.200s", Py_TYPE(item)->tp_name); + + PyErr_SetString(PyExc_IndexError, "slice steps not supported with vectors"); return NULL; } + + PyErr_Format( + PyExc_TypeError, "vector indices must be integers, not %.200s", Py_TYPE(item)->tp_name); + return NULL; } static int Vector_ass_subscript(VectorObject *self, PyObject *item, PyObject *value) @@ -2189,7 +2179,7 @@ static int Vector_ass_subscript(VectorObject *self, PyObject *item, PyObject *va } return Vector_ass_item(self, i, value); } - else if (PySlice_Check(item)) { + if (PySlice_Check(item)) { Py_ssize_t start, stop, step, slicelength; if (PySlice_GetIndicesEx(item, self->size, &start, &stop, &step, &slicelength) < 0) { @@ -2199,16 +2189,14 @@ static int Vector_ass_subscript(VectorObject *self, PyObject *item, PyObject *va if (step == 1) { return Vector_ass_slice(self, start, stop, value); } - else { - PyErr_SetString(PyExc_IndexError, "slice steps not supported with vectors"); - return -1; - } - } - else { - PyErr_Format( - PyExc_TypeError, "vector indices must be integers, not %.200s", Py_TYPE(item)->tp_name); + + PyErr_SetString(PyExc_IndexError, "slice steps not supported with vectors"); return -1; } + + PyErr_Format( + PyExc_TypeError, "vector indices must be integers, not %.200s", Py_TYPE(item)->tp_name); + return -1; } static PyMappingMethods Vector_AsMapping = { @@ -2523,9 +2511,8 @@ static int Vector_swizzle_set(VectorObject *self, PyObject *value, void *closure if (BaseMath_WriteCallback(self) == -1) { return -1; } - else { - return 0; - } + + return 0; } #define _SWIZZLE1(a) ((a) | SWIZZLE_VALID_AXIS) diff --git a/source/blender/python/mathutils/mathutils_bvhtree.c b/source/blender/python/mathutils/mathutils_bvhtree.c index 5a0dc7d6a5e..80a72696d77 100644 --- a/source/blender/python/mathutils/mathutils_bvhtree.c +++ b/source/blender/python/mathutils/mathutils_bvhtree.c @@ -914,16 +914,15 @@ static PyObject *C_BVHTree_FromPolygons(PyObject *UNUSED(cls), PyObject *args, P return bvhtree_CreatePyObject( tree, epsilon, coords, coords_len, tris, tris_len, orig_index, orig_normal); } - else { - if (coords) { - MEM_freeN(coords); - } - if (tris) { - MEM_freeN(tris); - } - return NULL; + if (coords) { + MEM_freeN(coords); } + if (tris) { + MEM_freeN(tris); + } + + return NULL; } #ifndef MATH_STANDALONE @@ -1053,55 +1052,48 @@ static Mesh *bvh_get_mesh(const char *funcname, funcname); return NULL; } - else { - *r_free_mesh = true; - return mesh_create_eval_final_render(depsgraph, scene, ob, &data_masks); - } + + *r_free_mesh = true; + return mesh_create_eval_final_render(depsgraph, scene, ob, &data_masks); } - else if (ob_eval != NULL) { + if (ob_eval != NULL) { if (use_cage) { return mesh_get_eval_deform(depsgraph, scene, ob_eval, &data_masks); } - else { - return mesh_get_eval_final(depsgraph, scene, ob_eval, &data_masks); - } + + return mesh_get_eval_final(depsgraph, scene, ob_eval, &data_masks); } - else { - PyErr_Format(PyExc_ValueError, - "%s(...): Cannot get evaluated data from given dependency graph / object pair", - funcname); + + PyErr_Format(PyExc_ValueError, + "%s(...): Cannot get evaluated data from given dependency graph / object pair", + funcname); + return NULL; + } + + /* !use_deform */ + if (use_render) { + if (use_cage) { + PyErr_Format( + PyExc_ValueError, + "%s(...): cage arg is unsupported when dependency graph evaluation mode is RENDER", + funcname); return NULL; } + + *r_free_mesh = true; + return mesh_create_eval_no_deform_render(depsgraph, scene, ob, &data_masks); } - else { - /* !use_deform */ - if (use_render) { - if (use_cage) { - PyErr_Format( - PyExc_ValueError, - "%s(...): cage arg is unsupported when dependency graph evaluation mode is RENDER", - funcname); - return NULL; - } - else { - *r_free_mesh = true; - return mesh_create_eval_no_deform_render(depsgraph, scene, ob, &data_masks); - } - } - else { - if (use_cage) { - PyErr_Format(PyExc_ValueError, - "%s(...): cage arg is unsupported when deform=False and dependency graph " - "evaluation mode is not RENDER", - funcname); - return NULL; - } - else { - *r_free_mesh = true; - return mesh_create_eval_no_deform(depsgraph, scene, ob, &data_masks); - } - } + + if (use_cage) { + PyErr_Format(PyExc_ValueError, + "%s(...): cage arg is unsupported when deform=False and dependency graph " + "evaluation mode is not RENDER", + funcname); + return NULL; } + + *r_free_mesh = true; + return mesh_create_eval_no_deform(depsgraph, scene, ob, &data_masks); } PyDoc_STRVAR(C_BVHTree_FromObject_doc, diff --git a/source/blender/python/mathutils/mathutils_geometry.c b/source/blender/python/mathutils/mathutils_geometry.c index 93dbac32c19..37997e9f912 100644 --- a/source/blender/python/mathutils/mathutils_geometry.c +++ b/source/blender/python/mathutils/mathutils_geometry.c @@ -204,12 +204,11 @@ static PyObject *M_Geometry_intersect_line_line(PyObject *UNUSED(self), PyObject /* collinear */ Py_RETURN_NONE; } - else { - tuple = PyTuple_New(2); - PyTuple_SET_ITEMS( - tuple, Vector_CreatePyObject(i1, len, NULL), Vector_CreatePyObject(i2, len, NULL)); - return tuple; - } + + tuple = PyTuple_New(2); + PyTuple_SET_ITEMS( + tuple, Vector_CreatePyObject(i1, len, NULL), Vector_CreatePyObject(i2, len, NULL)); + return tuple; } /* Line-Line intersection using algorithm from mathworld.wolfram.com */ @@ -466,9 +465,8 @@ static PyObject *M_Geometry_intersect_line_line_2d(PyObject *UNUSED(self), PyObj if (isect_seg_seg_v2_point(UNPACK4(lines), vi) == 1) { return Vector_CreatePyObject(vi, 2, NULL); } - else { - Py_RETURN_NONE; - } + + Py_RETURN_NONE; } PyDoc_STRVAR( @@ -519,9 +517,8 @@ static PyObject *M_Geometry_intersect_line_plane(PyObject *UNUSED(self), PyObjec if (isect_line_plane_v3(isect, line_a, line_b, plane_co, plane_no) == 1) { return Vector_CreatePyObject(isect, 3, NULL); } - else { - Py_RETURN_NONE; - } + + Py_RETURN_NONE; } PyDoc_STRVAR( @@ -637,43 +634,42 @@ static PyObject *M_Geometry_intersect_line_sphere(PyObject *UNUSED(self), PyObje -1)) == 0) { return NULL; } - else { - bool use_a = true; - bool use_b = true; - float lambda; - PyObject *ret = PyTuple_New(2); + bool use_a = true; + bool use_b = true; + float lambda; - switch (isect_line_sphere_v3(line_a, line_b, sphere_co, sphere_radius, isect_a, isect_b)) { - case 1: - if (!(!clip || (((lambda = line_point_factor_v3(isect_a, line_a, line_b)) >= 0.0f) && - (lambda <= 1.0f)))) { - use_a = false; - } - use_b = false; - break; - case 2: - if (!(!clip || (((lambda = line_point_factor_v3(isect_a, line_a, line_b)) >= 0.0f) && - (lambda <= 1.0f)))) { - use_a = false; - } - if (!(!clip || (((lambda = line_point_factor_v3(isect_b, line_a, line_b)) >= 0.0f) && - (lambda <= 1.0f)))) { - use_b = false; - } - break; - default: + PyObject *ret = PyTuple_New(2); + + switch (isect_line_sphere_v3(line_a, line_b, sphere_co, sphere_radius, isect_a, isect_b)) { + case 1: + if (!(!clip || (((lambda = line_point_factor_v3(isect_a, line_a, line_b)) >= 0.0f) && + (lambda <= 1.0f)))) { use_a = false; + } + use_b = false; + break; + case 2: + if (!(!clip || (((lambda = line_point_factor_v3(isect_a, line_a, line_b)) >= 0.0f) && + (lambda <= 1.0f)))) { + use_a = false; + } + if (!(!clip || (((lambda = line_point_factor_v3(isect_b, line_a, line_b)) >= 0.0f) && + (lambda <= 1.0f)))) { use_b = false; - break; - } - - PyTuple_SET_ITEMS(ret, - use_a ? Vector_CreatePyObject(isect_a, 3, NULL) : Py_INCREF_RET(Py_None), - use_b ? Vector_CreatePyObject(isect_b, 3, NULL) : Py_INCREF_RET(Py_None)); - - return ret; + } + break; + default: + use_a = false; + use_b = false; + break; } + + PyTuple_SET_ITEMS(ret, + use_a ? Vector_CreatePyObject(isect_a, 3, NULL) : Py_INCREF_RET(Py_None), + use_b ? Vector_CreatePyObject(isect_b, 3, NULL) : Py_INCREF_RET(Py_None)); + + return ret; } /* keep in sync with M_Geometry_intersect_line_sphere */ @@ -723,43 +719,42 @@ static PyObject *M_Geometry_intersect_line_sphere_2d(PyObject *UNUSED(self), PyO -1)) == 0) { return NULL; } - else { - bool use_a = true; - bool use_b = true; - float lambda; - PyObject *ret = PyTuple_New(2); + bool use_a = true; + bool use_b = true; + float lambda; - switch (isect_line_sphere_v2(line_a, line_b, sphere_co, sphere_radius, isect_a, isect_b)) { - case 1: - if (!(!clip || (((lambda = line_point_factor_v2(isect_a, line_a, line_b)) >= 0.0f) && - (lambda <= 1.0f)))) { - use_a = false; - } - use_b = false; - break; - case 2: - if (!(!clip || (((lambda = line_point_factor_v2(isect_a, line_a, line_b)) >= 0.0f) && - (lambda <= 1.0f)))) { - use_a = false; - } - if (!(!clip || (((lambda = line_point_factor_v2(isect_b, line_a, line_b)) >= 0.0f) && - (lambda <= 1.0f)))) { - use_b = false; - } - break; - default: + PyObject *ret = PyTuple_New(2); + + switch (isect_line_sphere_v2(line_a, line_b, sphere_co, sphere_radius, isect_a, isect_b)) { + case 1: + if (!(!clip || (((lambda = line_point_factor_v2(isect_a, line_a, line_b)) >= 0.0f) && + (lambda <= 1.0f)))) { use_a = false; + } + use_b = false; + break; + case 2: + if (!(!clip || (((lambda = line_point_factor_v2(isect_a, line_a, line_b)) >= 0.0f) && + (lambda <= 1.0f)))) { + use_a = false; + } + if (!(!clip || (((lambda = line_point_factor_v2(isect_b, line_a, line_b)) >= 0.0f) && + (lambda <= 1.0f)))) { use_b = false; - break; - } - - PyTuple_SET_ITEMS(ret, - use_a ? Vector_CreatePyObject(isect_a, 2, NULL) : Py_INCREF_RET(Py_None), - use_b ? Vector_CreatePyObject(isect_b, 2, NULL) : Py_INCREF_RET(Py_None)); - - return ret; + } + break; + default: + use_a = false; + use_b = false; + break; } + + PyTuple_SET_ITEMS(ret, + use_a ? Vector_CreatePyObject(isect_a, 2, NULL) : Py_INCREF_RET(Py_None), + use_b ? Vector_CreatePyObject(isect_b, 2, NULL) : Py_INCREF_RET(Py_None)); + + return ret; } PyDoc_STRVAR( @@ -849,9 +844,8 @@ static PyObject *M_Geometry_intersect_point_tri(PyObject *UNUSED(self), PyObject if (isect_point_tri_v3(pt, UNPACK3(tri), vi)) { return Vector_CreatePyObject(vi, 3, NULL); } - else { - Py_RETURN_NONE; - } + + Py_RETURN_NONE; } PyDoc_STRVAR(M_Geometry_closest_point_on_tri_doc, @@ -1094,65 +1088,61 @@ static PyObject *M_Geometry_points_in_planes(PyObject *UNUSED(self), PyObject *a (float **)&planes, 4, py_planes, "points_in_planes")) == -1) { return NULL; } - else { - /* note, this could be refactored into plain C easy - py bits are noted */ - const float eps = 0.0001f; - const uint len = (uint)planes_len; - uint i, j, k, l; - float n1n2[3], n2n3[3], n3n1[3]; - float potentialVertex[3]; - char *planes_used = PyMem_Malloc(sizeof(char) * len); + /* note, this could be refactored into plain C easy - py bits are noted */ + const float eps = 0.0001f; + const uint len = (uint)planes_len; + uint i, j, k, l; - /* python */ - PyObject *py_verts = PyList_New(0); - PyObject *py_plane_index = PyList_New(0); + float n1n2[3], n2n3[3], n3n1[3]; + float potentialVertex[3]; + char *planes_used = PyMem_Malloc(sizeof(char) * len); - memset(planes_used, 0, sizeof(char) * len); + /* python */ + PyObject *py_verts = PyList_New(0); + PyObject *py_plane_index = PyList_New(0); - for (i = 0; i < len; i++) { - const float *N1 = planes[i]; - for (j = i + 1; j < len; j++) { - const float *N2 = planes[j]; - cross_v3_v3v3(n1n2, N1, N2); - if (len_squared_v3(n1n2) > eps) { - for (k = j + 1; k < len; k++) { - const float *N3 = planes[k]; - cross_v3_v3v3(n2n3, N2, N3); - if (len_squared_v3(n2n3) > eps) { - cross_v3_v3v3(n3n1, N3, N1); - if (len_squared_v3(n3n1) > eps) { - const float quotient = dot_v3v3(N1, n2n3); - if (fabsf(quotient) > eps) { - /** - *
-                   * potentialVertex = (
-                   *     (n2n3 * N1[3] + n3n1 * N2[3] + n1n2 * N3[3]) *
-                   *     (-1.0 / quotient));
-                   * 
- */ - const float quotient_ninv = -1.0f / quotient; - potentialVertex[0] = ((n2n3[0] * N1[3]) + (n3n1[0] * N2[3]) + - (n1n2[0] * N3[3])) * - quotient_ninv; - potentialVertex[1] = ((n2n3[1] * N1[3]) + (n3n1[1] * N2[3]) + - (n1n2[1] * N3[3])) * - quotient_ninv; - potentialVertex[2] = ((n2n3[2] * N1[3]) + (n3n1[2] * N2[3]) + - (n1n2[2] * N3[3])) * - quotient_ninv; - for (l = 0; l < len; l++) { - const float *NP = planes[l]; - if ((dot_v3v3(NP, potentialVertex) + NP[3]) > 0.000001f) { - break; - } + memset(planes_used, 0, sizeof(char) * len); + + for (i = 0; i < len; i++) { + const float *N1 = planes[i]; + for (j = i + 1; j < len; j++) { + const float *N2 = planes[j]; + cross_v3_v3v3(n1n2, N1, N2); + if (len_squared_v3(n1n2) > eps) { + for (k = j + 1; k < len; k++) { + const float *N3 = planes[k]; + cross_v3_v3v3(n2n3, N2, N3); + if (len_squared_v3(n2n3) > eps) { + cross_v3_v3v3(n3n1, N3, N1); + if (len_squared_v3(n3n1) > eps) { + const float quotient = dot_v3v3(N1, n2n3); + if (fabsf(quotient) > eps) { + /** + *
+                 * potentialVertex = (
+                 *     (n2n3 * N1[3] + n3n1 * N2[3] + n1n2 * N3[3]) *
+                 *     (-1.0 / quotient));
+                 * 
+ */ + const float quotient_ninv = -1.0f / quotient; + potentialVertex[0] = ((n2n3[0] * N1[3]) + (n3n1[0] * N2[3]) + (n1n2[0] * N3[3])) * + quotient_ninv; + potentialVertex[1] = ((n2n3[1] * N1[3]) + (n3n1[1] * N2[3]) + (n1n2[1] * N3[3])) * + quotient_ninv; + potentialVertex[2] = ((n2n3[2] * N1[3]) + (n3n1[2] * N2[3]) + (n1n2[2] * N3[3])) * + quotient_ninv; + for (l = 0; l < len; l++) { + const float *NP = planes[l]; + if ((dot_v3v3(NP, potentialVertex) + NP[3]) > 0.000001f) { + break; } + } - if (l == len) { /* ok */ - /* python */ - PyList_APPEND(py_verts, Vector_CreatePyObject(potentialVertex, 3, NULL)); - planes_used[i] = planes_used[j] = planes_used[k] = true; - } + if (l == len) { /* ok */ + /* python */ + PyList_APPEND(py_verts, Vector_CreatePyObject(potentialVertex, 3, NULL)); + planes_used[i] = planes_used[j] = planes_used[k] = true; } } } @@ -1160,22 +1150,22 @@ static PyObject *M_Geometry_points_in_planes(PyObject *UNUSED(self), PyObject *a } } } + } - PyMem_Free(planes); + PyMem_Free(planes); - /* now make a list of used planes */ - for (i = 0; i < len; i++) { - if (planes_used[i]) { - PyList_APPEND(py_plane_index, PyLong_FromLong(i)); - } + /* now make a list of used planes */ + for (i = 0; i < len; i++) { + if (planes_used[i]) { + PyList_APPEND(py_plane_index, PyLong_FromLong(i)); } - PyMem_Free(planes_used); + } + PyMem_Free(planes_used); - { - PyObject *ret = PyTuple_New(2); - PyTuple_SET_ITEMS(ret, py_verts, py_plane_index); - return ret; - } + { + PyObject *ret = PyTuple_New(2); + PyTuple_SET_ITEMS(ret, py_verts, py_plane_index); + return ret; } } @@ -1321,7 +1311,7 @@ static PyObject *M_Geometry_tessellate_polygon(PyObject *UNUSED(self), PyObject BKE_displist_free(&dispbase); /* possible some dl was allocated */ return NULL; } - else if (totpoints) { + if (totpoints) { /* now make the list to return */ BKE_displist_fill(&dispbase, &dispbase, is_2d ? ((const float[3]){0, 0, -1}) : NULL, false);