From 27accea53e055576a315388b296071d024bfe26f Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Sun, 26 Jan 2025 20:08:04 +0100 Subject: [PATCH] Cleanup: Various clang-tidy warnings in python Pull Request: https://projects.blender.org/blender/blender/pulls/133734 --- source/blender/python/BPY_extern.hh | 2 +- source/blender/python/BPY_extern_python.hh | 2 +- source/blender/python/bmesh/bmesh_py_types.cc | 2 +- .../python/bmesh/bmesh_py_types_customdata.cc | 14 ++++------ .../python/bmesh/bmesh_py_types_meshdata.cc | 2 +- .../python/bmesh/bmesh_py_types_select.cc | 2 +- source/blender/python/generic/bgl.cc | 26 ++++++----------- .../blender/python/generic/idprop_py_api.cc | 6 ++-- source/blender/python/gpu/gpu_py_batch.cc | 2 +- source/blender/python/gpu/gpu_py_buffer.cc | 28 ++++++------------- source/blender/python/gpu/gpu_py_shader.cc | 1 - .../python/gpu/gpu_py_shader_create_info.cc | 6 ++-- .../blender/python/intern/bpy_app_timers.cc | 6 ++-- .../python/intern/bpy_app_translations.cc | 2 +- source/blender/python/intern/bpy_driver.hh | 2 -- source/blender/python/intern/bpy_operator.cc | 4 +-- .../python/intern/bpy_operator_wrap.cc | 2 +- source/blender/python/intern/bpy_rna.cc | 8 +++--- source/blender/python/intern/bpy_rna_array.cc | 2 +- .../blender/python/intern/bpy_rna_callback.cc | 6 ++-- source/blender/python/intern/bpy_traceback.cc | 2 +- .../blender/python/intern/bpy_utils_units.cc | 2 +- source/blender/python/mathutils/mathutils.hh | 12 ++++---- .../python/mathutils/mathutils_Matrix.cc | 7 ++--- .../python/mathutils/mathutils_Matrix.hh | 2 +- .../python/mathutils/mathutils_Vector.cc | 4 +-- .../python/mathutils/mathutils_bvhtree.cc | 4 +-- .../python/mathutils/mathutils_kdtree.cc | 2 +- .../python/mathutils/mathutils_noise.cc | 4 +-- 29 files changed, 68 insertions(+), 96 deletions(-) diff --git a/source/blender/python/BPY_extern.hh b/source/blender/python/BPY_extern.hh index f82775951c6..0705771c9ea 100644 --- a/source/blender/python/BPY_extern.hh +++ b/source/blender/python/BPY_extern.hh @@ -36,7 +36,7 @@ bool BPY_is_pyconstraint(Text *text); /* global interpreter lock */ -typedef void *BPy_ThreadStatePtr; +using BPy_ThreadStatePtr = void *; /** * Analogue of #PyEval_SaveThread() diff --git a/source/blender/python/BPY_extern_python.hh b/source/blender/python/BPY_extern_python.hh index 0d86916712c..3dc1c67ea46 100644 --- a/source/blender/python/BPY_extern_python.hh +++ b/source/blender/python/BPY_extern_python.hh @@ -13,7 +13,7 @@ struct bContext; /* For 'FILE'. */ -#include +#include /* `bpy_interface.cc` */ diff --git a/source/blender/python/bmesh/bmesh_py_types.cc b/source/blender/python/bmesh/bmesh_py_types.cc index a279cb779af..871cad68273 100644 --- a/source/blender/python/bmesh/bmesh_py_types.cc +++ b/source/blender/python/bmesh/bmesh_py_types.cc @@ -3711,7 +3711,7 @@ static PyObject *bpy_bmiter_next(BPy_BMIter *self) return nullptr; } - return (PyObject *)BPy_BMElem_CreatePyObject(self->bm, ele); + return BPy_BMElem_CreatePyObject(self->bm, ele); } /* Deallocate Functions diff --git a/source/blender/python/bmesh/bmesh_py_types_customdata.cc b/source/blender/python/bmesh/bmesh_py_types_customdata.cc index a05b6bb2541..e962f162332 100644 --- a/source/blender/python/bmesh/bmesh_py_types_customdata.cc +++ b/source/blender/python/bmesh/bmesh_py_types_customdata.cc @@ -11,6 +11,8 @@ #include +#include + #include "BLI_math_vector.h" #include "BLI_utildefines.h" @@ -833,12 +835,8 @@ static PyObject *bpy_bmlayercollection_subscript_slice(BPy_BMLayerCollection *se BPY_BM_CHECK_OBJ(self); - if (start > len) { - start = len; - } - if (stop > len) { - stop = len; - } + start = std::min(start, len); + stop = std::min(stop, len); tuple = PyTuple_New(stop - start); @@ -1286,9 +1284,7 @@ int BPy_BMLayerItem_SetItem(BPy_BMElem *py_ele, BPy_BMLayerItem *py_layer, PyObj ret = -1; } else { - if (tmp_val_len > sizeof(mstring->s)) { - tmp_val_len = sizeof(mstring->s); - } + tmp_val_len = std::min(tmp_val_len, sizeof(mstring->s)); memcpy(mstring->s, tmp_val, tmp_val_len); mstring->s_len = tmp_val_len; } diff --git a/source/blender/python/bmesh/bmesh_py_types_meshdata.cc b/source/blender/python/bmesh/bmesh_py_types_meshdata.cc index 98c6529c73c..99b66b795f6 100644 --- a/source/blender/python/bmesh/bmesh_py_types_meshdata.cc +++ b/source/blender/python/bmesh/bmesh_py_types_meshdata.cc @@ -360,7 +360,7 @@ int BPy_BMVertSkin_AssignPyObject(MVertSkin *mvertskin, PyObject *value) return -1; } - *((MVertSkin *)mvertskin) = *(((BPy_BMVertSkin *)value)->data); + *(mvertskin) = *(((BPy_BMVertSkin *)value)->data); return 0; } diff --git a/source/blender/python/bmesh/bmesh_py_types_select.cc b/source/blender/python/bmesh/bmesh_py_types_select.cc index 3823b1723d2..368db63ba5b 100644 --- a/source/blender/python/bmesh/bmesh_py_types_select.cc +++ b/source/blender/python/bmesh/bmesh_py_types_select.cc @@ -353,7 +353,7 @@ static PyObject *bpy_bmeditseliter_next(BPy_BMEditSelIter *self) } self->ese = ese->next; - return (PyObject *)BPy_BMElem_CreatePyObject(self->bm, &ese->ele->head); + return BPy_BMElem_CreatePyObject(self->bm, &ese->ele->head); } PyTypeObject BPy_BMEditSelSeq_Type; diff --git a/source/blender/python/generic/bgl.cc b/source/blender/python/generic/bgl.cc index 4501e3feafd..bbaec530bbf 100644 --- a/source/blender/python/generic/bgl.cc +++ b/source/blender/python/generic/bgl.cc @@ -24,6 +24,8 @@ #include +#include + #include "CLG_log.h" /* Forward declare API's defines here. */ @@ -908,15 +910,9 @@ static PyObject *Buffer_slice(Buffer *self, Py_ssize_t begin, Py_ssize_t end) { PyObject *list; - if (begin < 0) { - begin = 0; - } - if (end > self->dimensions[0]) { - end = self->dimensions[0]; - } - if (begin > end) { - begin = end; - } + begin = std::max(begin, 0); + end = std::min(end, self->dimensions[0]); + begin = std::min(begin, end); list = PyList_New(end - begin); @@ -967,15 +963,9 @@ static int Buffer_ass_slice(Buffer *self, Py_ssize_t begin, Py_ssize_t end, PyOb int err = 0; Py_ssize_t count; - if (begin < 0) { - begin = 0; - } - if (end > self->dimensions[0]) { - end = self->dimensions[0]; - } - if (begin > end) { - begin = end; - } + begin = std::max(begin, 0); + end = std::min(end, self->dimensions[0]); + begin = std::min(begin, end); if (!PySequence_Check(seq)) { PyErr_Format(PyExc_TypeError, diff --git a/source/blender/python/generic/idprop_py_api.cc b/source/blender/python/generic/idprop_py_api.cc index 498cae7ba13..3d847acbc0f 100644 --- a/source/blender/python/generic/idprop_py_api.cc +++ b/source/blender/python/generic/idprop_py_api.cc @@ -1045,9 +1045,9 @@ static IDProperty *idp_from_PyObject(IDProperty *prop_exist, /** \name Mapping Get/Set (Internal Access) * \{ */ -bool BPy_IDProperty_Map_ValidateAndCreate(PyObject *name_obj, IDProperty *group, PyObject *ob) +bool BPy_IDProperty_Map_ValidateAndCreate(PyObject *key, IDProperty *group, PyObject *ob) { - const char *name = idp_try_read_name(name_obj); + const char *name = idp_try_read_name(key); if (!name) { return false; } @@ -1617,7 +1617,7 @@ static PyObject *BPy_IDGroup_View_reversed(BPy_IDGroup_View *self, PyObject * /* static PyMethodDef BPy_IDGroup_View_methods[] = { {"__reversed__", - (PyCFunction)(void (*)(void))BPy_IDGroup_View_reversed, + (PyCFunction)(void (*)())BPy_IDGroup_View_reversed, METH_NOARGS, BPy_IDGroup_View_reversed_doc}, {nullptr, nullptr}, diff --git a/source/blender/python/gpu/gpu_py_batch.cc b/source/blender/python/gpu/gpu_py_batch.cc index 2d539f53353..546704aae9d 100644 --- a/source/blender/python/gpu/gpu_py_batch.cc +++ b/source/blender/python/gpu/gpu_py_batch.cc @@ -240,7 +240,7 @@ static const char *pygpu_shader_check_compatibility(blender::gpu::Batch *batch) } /* Check batch compatibility with shader. */ - for (auto vert : blender::Span(batch->verts, ARRAY_SIZE(batch->verts))) { + for (auto *vert : blender::Span(batch->verts, ARRAY_SIZE(batch->verts))) { if (!vert) { continue; } diff --git a/source/blender/python/gpu/gpu_py_buffer.cc b/source/blender/python/gpu/gpu_py_buffer.cc index c4551563af8..c0964a8c715 100644 --- a/source/blender/python/gpu/gpu_py_buffer.cc +++ b/source/blender/python/gpu/gpu_py_buffer.cc @@ -13,6 +13,8 @@ #include +#include + #include "BLI_utildefines.h" #include "MEM_guardedalloc.h" @@ -327,15 +329,9 @@ static int pygpu_buffer_ass_slice(BPyGPUBuffer *self, PyObject *item; int count, err = 0; - if (begin < 0) { - begin = 0; - } - if (end > self->shape[0]) { - end = self->shape[0]; - } - if (begin > end) { - begin = end; - } + begin = std::max(begin, 0); + end = std::min(end, self->shape[0]); + begin = std::min(begin, end); if (!PySequence_Check(seq)) { PyErr_Format(PyExc_TypeError, @@ -447,15 +443,9 @@ static PyObject *pygpu_buffer_slice(BPyGPUBuffer *self, Py_ssize_t begin, Py_ssi PyObject *list; Py_ssize_t count; - if (begin < 0) { - begin = 0; - } - if (end > self->shape[0]) { - end = self->shape[0]; - } - if (begin > end) { - begin = end; - } + begin = std::max(begin, 0); + end = std::min(end, self->shape[0]); + begin = std::min(begin, end); list = PyList_New(end - begin); @@ -636,7 +626,7 @@ static int pygpu_buffer__bf_getbuffer(BPyGPUBuffer *self, Py_buffer *view, int f memset(view, 0, sizeof(*view)); view->obj = (PyObject *)self; - view->buf = (void *)self->buf.as_void; + view->buf = self->buf.as_void; view->len = bpygpu_Buffer_size(self); view->readonly = 0; view->itemsize = GPU_texture_dataformat_size(eGPUDataFormat(self->format)); diff --git a/source/blender/python/gpu/gpu_py_shader.cc b/source/blender/python/gpu/gpu_py_shader.cc index d411750c604..9541ff66e24 100644 --- a/source/blender/python/gpu/gpu_py_shader.cc +++ b/source/blender/python/gpu/gpu_py_shader.cc @@ -13,7 +13,6 @@ #include "BLI_utildefines.h" -#include "GPU_capabilities.hh" #include "GPU_shader.hh" #include "GPU_texture.hh" #include "GPU_uniform_buffer.hh" diff --git a/source/blender/python/gpu/gpu_py_shader_create_info.cc b/source/blender/python/gpu/gpu_py_shader_create_info.cc index cb787dab2a5..51ae2c01553 100644 --- a/source/blender/python/gpu/gpu_py_shader_create_info.cc +++ b/source/blender/python/gpu/gpu_py_shader_create_info.cc @@ -233,7 +233,7 @@ static bool pygpu_interface_info_get_args(BPyGPUStageInterfaceInfo *self, } #ifdef USE_GPU_PY_REFERENCES - PyList_Append(self->references, (PyObject *)py_name); + PyList_Append(self->references, py_name); #endif *r_type = (Type)pygpu_type.value_found; @@ -425,7 +425,7 @@ static void pygpu_interface_info__tp_dealloc(PyObject *self) } #endif - Py_TYPE(self)->tp_free((PyObject *)self); + Py_TYPE(self)->tp_free(self); } PyDoc_STRVAR( @@ -1296,7 +1296,7 @@ static void pygpu_shader_info__tp_dealloc(PyObject *self) #endif - Py_TYPE(self)->tp_free((PyObject *)self); + Py_TYPE(self)->tp_free(self); } PyDoc_STRVAR( diff --git a/source/blender/python/intern/bpy_app_timers.cc b/source/blender/python/intern/bpy_app_timers.cc index 656d063381c..95ef356844c 100644 --- a/source/blender/python/intern/bpy_app_timers.cc +++ b/source/blender/python/intern/bpy_app_timers.cc @@ -10,6 +10,8 @@ #include +#include + #include "bpy_app_timers.hh" #include "../generic/python_compat.hh" @@ -35,9 +37,7 @@ static double handle_returned_value(PyObject *function, PyObject *ret) return -1; } - if (value < 0.0) { - value = 0.0; - } + value = std::max(value, 0.0); return value; } diff --git a/source/blender/python/intern/bpy_app_translations.cc b/source/blender/python/intern/bpy_app_translations.cc index d6b4d1ac262..e7a4389251b 100644 --- a/source/blender/python/intern/bpy_app_translations.cc +++ b/source/blender/python/intern/bpy_app_translations.cc @@ -338,7 +338,7 @@ static PyObject *app_translations_py_messages_register(BlenderAppTranslations *s PyExc_ValueError, "bpy.app.translations.register: translations message cache already contains some data for " "addon '%s'", - (const char *)PyUnicode_AsUTF8(module_name)); + PyUnicode_AsUTF8(module_name)); return nullptr; } diff --git a/source/blender/python/intern/bpy_driver.hh b/source/blender/python/intern/bpy_driver.hh index 9c10eceacdd..67c2ba5ef78 100644 --- a/source/blender/python/intern/bpy_driver.hh +++ b/source/blender/python/intern/bpy_driver.hh @@ -10,8 +10,6 @@ #include -#include - /** * For faster execution we keep a special dictionary for py-drivers, with * the needed modules and aliases. diff --git a/source/blender/python/intern/bpy_operator.cc b/source/blender/python/intern/bpy_operator.cc index c86ea252288..4fd80344093 100644 --- a/source/blender/python/intern/bpy_operator.cc +++ b/source/blender/python/intern/bpy_operator.cc @@ -122,7 +122,7 @@ static PyObject *pyop_poll(PyObject * /*self*/, PyObject *args) } /* main purpose of this function */ - ret = WM_operator_poll_context((bContext *)C, ot, context) ? Py_True : Py_False; + ret = WM_operator_poll_context(C, ot, context) ? Py_True : Py_False; return Py_NewRef(ret); } @@ -204,7 +204,7 @@ static PyObject *pyop_call(PyObject * /*self*/, PyObject *args) context = wmOperatorCallContext(context_int); } - if (WM_operator_poll_context((bContext *)C, ot, context) == false) { + if (WM_operator_poll_context(C, ot, context) == false) { bool msg_free = false; const char *msg = CTX_wm_operator_poll_msg_get(C, &msg_free); PyErr_Format(PyExc_RuntimeError, diff --git a/source/blender/python/intern/bpy_operator_wrap.cc b/source/blender/python/intern/bpy_operator_wrap.cc index 87c6854d790..59f5e8b6acf 100644 --- a/source/blender/python/intern/bpy_operator_wrap.cc +++ b/source/blender/python/intern/bpy_operator_wrap.cc @@ -142,7 +142,7 @@ PyObject *PYOP_wrap_macro_define(PyObject * /*self*/, PyObject *args) } /* identifiers */ - srna = pyrna_struct_as_srna((PyObject *)macro, false, "Macro Define:"); + srna = pyrna_struct_as_srna(macro, false, "Macro Define:"); if (srna == nullptr) { return nullptr; } diff --git a/source/blender/python/intern/bpy_rna.cc b/source/blender/python/intern/bpy_rna.cc index 8c8d796c8a6..c3816464f72 100644 --- a/source/blender/python/intern/bpy_rna.cc +++ b/source/blender/python/intern/bpy_rna.cc @@ -4174,7 +4174,7 @@ static void pyrna_dir_members_py(PyObject *list, PyObject *self) PyObject *dict; PyObject **dict_ptr; - dict_ptr = _PyObject_GetDictPtr((PyObject *)self); + dict_ptr = _PyObject_GetDictPtr(self); if (dict_ptr && (dict = *dict_ptr)) { pyrna_dir_members_py__add_keys(list, dict); @@ -5675,7 +5675,7 @@ static PyObject *foreach_getset(BPy_PropertyRNA *self, PyObject *args, int set) ((float *)array)[i] = float(PyFloat_AsDouble(item)); break; case PROP_RAW_DOUBLE: - ((double *)array)[i] = double(PyFloat_AsDouble(item)); + ((double *)array)[i] = PyFloat_AsDouble(item); break; case PROP_RAW_INT64: ((int64_t *)array)[i] = PyC_Long_AsI64(item); @@ -5756,7 +5756,7 @@ static PyObject *foreach_getset(BPy_PropertyRNA *self, PyObject *args, int set) item = PyFloat_FromDouble(double(((float *)array)[i])); break; case PROP_RAW_DOUBLE: - item = PyFloat_FromDouble(double(((double *)array)[i])); + item = PyFloat_FromDouble(((double *)array)[i]); break; case PROP_RAW_BOOLEAN: item = PyBool_FromLong(long(((bool *)array)[i])); @@ -8552,7 +8552,7 @@ static PyObject *bpy_types_module_getattro(PyObject *self, PyObject *pyname) return nullptr; #endif /* The error raised here will be displayed. */ - ret = PyObject_GenericGetAttr((PyObject *)self, pyname); + ret = PyObject_GenericGetAttr(self, pyname); } return ret; diff --git a/source/blender/python/intern/bpy_rna_array.cc b/source/blender/python/intern/bpy_rna_array.cc index 1db325f55e1..26c8928ecb3 100644 --- a/source/blender/python/intern/bpy_rna_array.cc +++ b/source/blender/python/intern/bpy_rna_array.cc @@ -550,7 +550,7 @@ static int py_to_array(PyObject *seq, if (prop_is_param_dyn_alloc) { /* not freeing allocated mem, RNA_parameter_list_free() will do this */ ParameterDynAlloc *param_alloc = (ParameterDynAlloc *)param_data; - param_alloc->array_tot = int(totitem); + param_alloc->array_tot = totitem; /* freeing param list will free */ param_alloc->array = MEM_callocN(item_size * totitem, "py_to_array dyn"); diff --git a/source/blender/python/intern/bpy_rna_callback.cc b/source/blender/python/intern/bpy_rna_callback.cc index f037b4403bf..6f73b511a2e 100644 --- a/source/blender/python/intern/bpy_rna_callback.cc +++ b/source/blender/python/intern/bpy_rna_callback.cc @@ -85,7 +85,7 @@ static void cb_wm_cursor_draw(bContext *C, int x, int y, void *customdata) PyObject *cb_func, *cb_args, *result; PyGILState_STATE gilstate; - bpy_context_set((bContext *)C, &gilstate); + bpy_context_set(C, &gilstate); cb_func = PyTuple_GET_ITEM((PyObject *)customdata, 1); cb_args = PyTuple_GET_ITEM((PyObject *)customdata, 2); @@ -110,7 +110,7 @@ static void cb_wm_cursor_draw(bContext *C, int x, int y, void *customdata) PyErr_Clear(); } - bpy_context_clear((bContext *)C, &gilstate); + bpy_context_clear(C, &gilstate); } #if 0 @@ -354,7 +354,7 @@ PyObject *pyrna_callback_classmethod_add(PyObject * /*self*/, PyObject *args) * This reference is decremented in #BPY_callback_screen_free and #BPY_callback_wm_free. */ Py_INCREF(args); - PyObject *ret = PyCapsule_New((void *)handle, rna_capsual_id, nullptr); + PyObject *ret = PyCapsule_New(handle, rna_capsual_id, nullptr); /* Store 'args' in context as well for simple access. */ PyCapsule_SetDestructor(ret, cb_rna_capsule_destructor); diff --git a/source/blender/python/intern/bpy_traceback.cc b/source/blender/python/intern/bpy_traceback.cc index 0fbbcc718de..a86bafcc0d0 100644 --- a/source/blender/python/intern/bpy_traceback.cc +++ b/source/blender/python/intern/bpy_traceback.cc @@ -209,7 +209,7 @@ bool python_script_error_jump( *r_lineno_end = -1; *r_offset_end = 0; - PyErr_Fetch(&exception, &value, (PyObject **)&tb); + PyErr_Fetch(&exception, &value, &tb); if (exception == nullptr) { /* Equivalent of `!PyErr_Occurred()`. */ return false; } diff --git a/source/blender/python/intern/bpy_utils_units.cc b/source/blender/python/intern/bpy_utils_units.cc index 6258c74a284..b7a8c9a1fec 100644 --- a/source/blender/python/intern/bpy_utils_units.cc +++ b/source/blender/python/intern/bpy_utils_units.cc @@ -318,7 +318,7 @@ static PyObject *bpyunits_to_string(PyObject * /*self*/, PyObject *args, PyObjec PyObject *result; BKE_unit_value_as_string_adaptive( - buf1, sizeof(buf1), value, precision, usys, ucat, bool(split_unit), false); + buf1, sizeof(buf1), value, precision, usys, ucat, split_unit, false); if (compatible_unit) { BKE_unit_name_to_alt(buf2, sizeof(buf2), buf1, usys, ucat); diff --git a/source/blender/python/mathutils/mathutils.hh b/source/blender/python/mathutils/mathutils.hh index a57ff196d4b..0feaacea5d5 100644 --- a/source/blender/python/mathutils/mathutils.hh +++ b/source/blender/python/mathutils/mathutils.hh @@ -89,18 +89,18 @@ PyMODINIT_FUNC PyInit_mathutils(); int EXPP_FloatsAreEqual(float af, float bf, int maxDiff); int EXPP_VectorsAreEqual(const float *vecA, const float *vecB, int size, int floatSteps); -typedef struct Mathutils_Callback Mathutils_Callback; +using Mathutils_Callback = struct Mathutils_Callback; /** Checks the user is still valid. */ -typedef int (*BaseMathCheckFunc)(BaseMathObject *); +using BaseMathCheckFunc = int (*)(BaseMathObject *); /** Gets the vector from the user. */ -typedef int (*BaseMathGetFunc)(BaseMathObject *, int); +using BaseMathGetFunc = int (*)(BaseMathObject *, int); /** Sets the users vector values once its modified. */ -typedef int (*BaseMathSetFunc)(BaseMathObject *, int); +using BaseMathSetFunc = int (*)(BaseMathObject *, int); /** Same as #BaseMathGetFunc but only for an index. */ -typedef int (*BaseMathGetIndexFunc)(BaseMathObject *, int, int); +using BaseMathGetIndexFunc = int (*)(BaseMathObject *, int, int); /** Same as #BaseMathSetFunc but only for an index. */ -typedef int (*BaseMathSetIndexFunc)(BaseMathObject *, int, int); +using BaseMathSetIndexFunc = int (*)(BaseMathObject *, int, int); struct Mathutils_Callback { BaseMathCheckFunc check; diff --git a/source/blender/python/mathutils/mathutils_Matrix.cc b/source/blender/python/mathutils/mathutils_Matrix.cc index 296b6816c03..8de18c89479 100644 --- a/source/blender/python/mathutils/mathutils_Matrix.cc +++ b/source/blender/python/mathutils/mathutils_Matrix.cc @@ -708,7 +708,7 @@ static PyObject *C_Matrix_Rotation(PyObject *cls, PyObject *args) } if (vec && PyUnicode_Check(vec)) { - axis = PyUnicode_AsUTF8((PyObject *)vec); + axis = PyUnicode_AsUTF8(vec); if (axis == nullptr || axis[0] == '\0' || axis[1] != '\0' || axis[0] < 'X' || axis[0] > 'Z') { PyErr_SetString(PyExc_ValueError, "Matrix.Rotation(): " @@ -2254,7 +2254,7 @@ static PyObject *Matrix_identity(MatrixObject *self) /** Copy `Matrix.copy()` */ static PyObject *Matrix_copy_notest(MatrixObject *self, const float *matrix) { - return Matrix_CreatePyObject((const float *)matrix, self->col_num, self->row_num, Py_TYPE(self)); + return Matrix_CreatePyObject(matrix, self->col_num, self->row_num, Py_TYPE(self)); } PyDoc_STRVAR( @@ -3126,8 +3126,7 @@ static PyObject *Matrix_translation_get(MatrixObject *self, void * /*closure*/) return nullptr; } - ret = (PyObject *)Vector_CreatePyObject_cb( - (PyObject *)self, 3, mathutils_matrix_translation_cb_index, 3); + ret = Vector_CreatePyObject_cb((PyObject *)self, 3, mathutils_matrix_translation_cb_index, 3); return ret; } diff --git a/source/blender/python/mathutils/mathutils_Matrix.hh b/source/blender/python/mathutils/mathutils_Matrix.hh index 96f70946bba..17c334d0176 100644 --- a/source/blender/python/mathutils/mathutils_Matrix.hh +++ b/source/blender/python/mathutils/mathutils_Matrix.hh @@ -15,7 +15,7 @@ extern PyTypeObject matrix_Type; extern PyTypeObject matrix_access_Type; -typedef unsigned short ushort; +using ushort = unsigned short; #define MatrixObject_Check(v) PyObject_TypeCheck((v), &matrix_Type) #define MatrixObject_CheckExact(v) (Py_TYPE(v) == &matrix_Type) diff --git a/source/blender/python/mathutils/mathutils_Vector.cc b/source/blender/python/mathutils/mathutils_Vector.cc index 250df7f3caa..4dda45d0168 100644 --- a/source/blender/python/mathutils/mathutils_Vector.cc +++ b/source/blender/python/mathutils/mathutils_Vector.cc @@ -99,7 +99,7 @@ static PyObject *vec__apply_to_copy(PyObject *(*vec_func)(VectorObject *), Vecto PyObject *ret_dummy = vec_func((VectorObject *)ret); if (ret_dummy) { Py_DECREF(ret_dummy); - return (PyObject *)ret; + return ret; } /* error */ Py_DECREF(ret); @@ -2813,7 +2813,7 @@ static int Vector_swizzle_set(VectorObject *self, PyObject *value, void *closure size_from = axis_from; } - else if ((void)PyErr_Clear(), /* run but ignore the result */ + else if (PyErr_Clear(), /* run but ignore the result */ (size_from = size_t(mathutils_array_parse( vec_assign, 2, 4, value, "Vector.**** = swizzle assignment"))) == size_t(-1)) { diff --git a/source/blender/python/mathutils/mathutils_bvhtree.cc b/source/blender/python/mathutils/mathutils_bvhtree.cc index f6b06cd048b..2884e3737ff 100644 --- a/source/blender/python/mathutils/mathutils_bvhtree.cc +++ b/source/blender/python/mathutils/mathutils_bvhtree.cc @@ -47,7 +47,7 @@ # include "../bmesh/bmesh_py_types.hh" #endif /* MATH_STANDALONE */ -#include "BLI_strict_flags.h" /* Keep last. */ +#include "BLI_strict_flags.h" /* IWYU pragma: keep. Keep last. */ /* -------------------------------------------------------------------- */ /** \name Documentation String (snippets) @@ -790,7 +790,7 @@ static PyObject *C_BVHTree_FromPolygons(PyObject * /*cls*/, PyObject *args, PyOb plink = static_cast(BLI_memarena_alloc( poly_arena, sizeof(*plink) + (sizeof(int) * size_t(py_tricoords_len)))); - plink->len = uint(py_tricoords_len); + plink->len = py_tricoords_len; *p_plink_prev = plink; p_plink_prev = &plink->next; diff --git a/source/blender/python/mathutils/mathutils_kdtree.cc b/source/blender/python/mathutils/mathutils_kdtree.cc index 7adb59e07e6..0f0c51ef27c 100644 --- a/source/blender/python/mathutils/mathutils_kdtree.cc +++ b/source/blender/python/mathutils/mathutils_kdtree.cc @@ -22,7 +22,7 @@ #include "mathutils.hh" #include "mathutils_kdtree.hh" /* own include */ -#include "BLI_strict_flags.h" /* Keep last. */ +#include "BLI_strict_flags.h" /* IWYU pragma: keep. Keep last. */ struct PyKDTree { PyObject_HEAD diff --git a/source/blender/python/mathutils/mathutils_noise.cc b/source/blender/python/mathutils/mathutils_noise.cc index b67977ee602..87ee712d1f8 100644 --- a/source/blender/python/mathutils/mathutils_noise.cc +++ b/source/blender/python/mathutils/mathutils_noise.cc @@ -218,7 +218,7 @@ static float turb( float amp, out, t; int i; amp = 1.0f; - out = float(2.0f * BLI_noise_generic_noise(1.0f, x, y, z, false, nb) - 1.0f); + out = (2.0f * BLI_noise_generic_noise(1.0f, x, y, z, false, nb) - 1.0f); if (hard) { out = fabsf(out); } @@ -227,7 +227,7 @@ static float turb( x *= freqscale; y *= freqscale; z *= freqscale; - t = float(amp * (2.0f * BLI_noise_generic_noise(1.0f, x, y, z, false, nb) - 1.0f)); + t = (amp * (2.0f * BLI_noise_generic_noise(1.0f, x, y, z, false, nb) - 1.0f)); if (hard) { t = fabsf(t); }