From 6d2326dabf769298fc7523e3491f68fbd67f6aae Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Mon, 31 Jul 2023 19:57:28 +1000 Subject: [PATCH] Cleanup: use function style casts --- .../opensubdiv/internal/evaluator/patch_map.cc | 2 +- source/blender/blenfont/intern/blf_glyph.cc | 2 +- .../intern/gpencil_modifier_legacy.cc | 2 +- .../bmesh/intern/bmesh_polygon_edgenet.cc | 4 ++-- .../blender/bmesh/operators/bmo_primitive.cc | 6 +++--- .../blender/bmesh/tools/bmesh_region_match.cc | 2 +- .../draw/engines/eevee/eevee_lightcache.cc | 4 ++-- source/blender/draw/intern/draw_common.cc | 2 +- .../gpencil_legacy/editaction_gpencil.cc | 2 +- .../intern/grease_pencil_frames.cc | 2 +- source/blender/gpu/intern/gpu_select_pick.cc | 2 +- source/blender/makesrna/intern/rna_rna.cc | 2 +- source/blender/python/generic/bgl.cc | 8 ++++---- source/blender/python/generic/idprop_py_api.cc | 6 +++--- source/blender/python/intern/bpy_rna.cc | 18 +++++++++--------- .../python/mathutils/mathutils_Vector.cc | 4 ++-- .../simulation/intern/implicit_blender.cc | 6 +++--- .../windowmanager/gizmo/intern/wm_gizmo_map.cc | 2 +- source/blender/windowmanager/intern/wm_draw.cc | 2 +- .../windowmanager/intern/wm_playanim.cc | 2 +- .../windowmanager/xr/intern/wm_xr_action.cc | 2 +- 21 files changed, 41 insertions(+), 41 deletions(-) diff --git a/intern/opensubdiv/internal/evaluator/patch_map.cc b/intern/opensubdiv/internal/evaluator/patch_map.cc index 9f3647586e4..6d5166dd0f6 100644 --- a/intern/opensubdiv/internal/evaluator/patch_map.cc +++ b/intern/opensubdiv/internal/evaluator/patch_map.cc @@ -133,7 +133,7 @@ void PatchMap::initializeQuadtree(PatchTable const &patchTable) // int nPatchFaces = (_maxPatchFace - _minPatchFace) + 1; - int nHandles = (int)_handles.size(); + int nHandles = int(_handles.size()); _quadtree.reserve(nPatchFaces + nHandles); _quadtree.resize(nPatchFaces); diff --git a/source/blender/blenfont/intern/blf_glyph.cc b/source/blender/blenfont/intern/blf_glyph.cc index 8bc4e241cdd..e936dacfdb0 100644 --- a/source/blender/blenfont/intern/blf_glyph.cc +++ b/source/blender/blenfont/intern/blf_glyph.cc @@ -203,7 +203,7 @@ static GlyphBLF *blf_glyph_cache_find_glyph(const GlyphCacheBLF *gc, uint charco */ static uchar blf_glyph_gamma(uchar c) { - /* The following is `(char)(powf(c / 256.0f, 1.0f / 1.43f) * 256.0f)`. */ + /* The following is `char(powf(c / 256.0f, 1.0f / 1.43f) * 256.0f)`. */ static const uchar gamma[256] = { 0, 5, 9, 11, 14, 16, 19, 21, 23, 25, 26, 28, 30, 32, 34, 35, 37, 38, 40, 41, 43, 44, 46, 47, 49, 50, 52, 53, 54, 56, 57, 58, 60, 61, 62, 64, diff --git a/source/blender/blenkernel/intern/gpencil_modifier_legacy.cc b/source/blender/blenkernel/intern/gpencil_modifier_legacy.cc index 5a6cd20bfcd..b149e118f42 100644 --- a/source/blender/blenkernel/intern/gpencil_modifier_legacy.cc +++ b/source/blender/blenkernel/intern/gpencil_modifier_legacy.cc @@ -481,7 +481,7 @@ void BKE_gpencil_modifier_copydata_generic(const GpencilModifierData *md_src, const size_t data_size = sizeof(GpencilModifierData); const char *md_src_data = ((const char *)md_src) + data_size; char *md_dst_data = ((char *)md_dst) + data_size; - BLI_assert(data_size <= (size_t)mti->struct_size); + BLI_assert(data_size <= size_t(mti->struct_size)); memcpy(md_dst_data, md_src_data, size_t(mti->struct_size) - data_size); } diff --git a/source/blender/bmesh/intern/bmesh_polygon_edgenet.cc b/source/blender/bmesh/intern/bmesh_polygon_edgenet.cc index 01e84f11584..c78dca15e5f 100644 --- a/source/blender/bmesh/intern/bmesh_polygon_edgenet.cc +++ b/source/blender/bmesh/intern/bmesh_polygon_edgenet.cc @@ -1563,7 +1563,7 @@ bool BM_face_split_edgenet_connect_islands(BMesh *bm, BMVert *v_origin = g->vert_span.min; /* Index of BMVert for the edge group connection with `v_origin`. */ const int index_other = bm_face_split_edgenet_find_connection(&args, v_origin, false); - // BLI_assert(index_other >= 0 && index_other < (int)vert_arr_len); + // BLI_assert(index_other >= 0 && index_other < int(vert_arr_len)); /* only for degenerate geometry */ if (index_other != -1) { @@ -1590,7 +1590,7 @@ bool BM_face_split_edgenet_connect_islands(BMesh *bm, BMVert *v_origin = g->vert_span.max; /* Index of BMVert for the edge group connection with `v_origin`. */ const int index_other = bm_face_split_edgenet_find_connection(&args, v_origin, true); - // BLI_assert(index_other >= 0 && index_other < (int)vert_arr_len); + // BLI_assert(index_other >= 0 && index_other < int(vert_arr_len)); /* only for degenerate geometry */ if (index_other != -1) { diff --git a/source/blender/bmesh/operators/bmo_primitive.cc b/source/blender/bmesh/operators/bmo_primitive.cc index b5d3c252ecb..e25d6bf7b88 100644 --- a/source/blender/bmesh/operators/bmo_primitive.cc +++ b/source/blender/bmesh/operators/bmo_primitive.cc @@ -852,7 +852,7 @@ void bmo_create_uvsphere_exec(BMesh *bm, BMOperator *op) BMO_slot_mat4_get(op->slots_in, "matrix", mat); const float phid = float(M_PI) / tot; - /* phi = 0.25f * (float)M_PI; */ /* UNUSED */ + // const float phi = 0.25f * float(M_PI); /* UNUSED. */ /* one segment first */ for (a = 0; a <= tot; a++) { @@ -970,8 +970,8 @@ void bmo_create_icosphere_exec(BMesh *bm, BMOperator *op) BMO_slot_mat4_get(op->slots_in, "matrix", mat); - /* phid = 2.0f * (float)M_PI / subdiv; */ /* UNUSED */ - /* phi = 0.25f * (float)M_PI; */ /* UNUSED */ + // phid = 2.0f * float(M_PI) / subdiv; /* UNUSED. */ + // phi = 0.25f * float(M_PI); /* UNUSED. */ for (a = 0; a < 12; a++) { vec[0] = rad_div * icovert[a][0]; diff --git a/source/blender/bmesh/tools/bmesh_region_match.cc b/source/blender/bmesh/tools/bmesh_region_match.cc index d4aa605a33d..6dd31308eb0 100644 --- a/source/blender/bmesh/tools/bmesh_region_match.cc +++ b/source/blender/bmesh/tools/bmesh_region_match.cc @@ -472,7 +472,7 @@ static void bm_uuidwalk_pass_add(UUIDWalk *uuidwalk, UUIDFaceStep *fstep; - BLI_assert(faces_pass_len == (uint)BLI_linklist_count(faces_pass)); + BLI_assert(faces_pass_len == uint(BLI_linklist_count(faces_pass))); /* rehash faces now all their verts have been added */ bm_uuidwalk_rehash_facelinks(uuidwalk, faces_pass, faces_pass_len, true); diff --git a/source/blender/draw/engines/eevee/eevee_lightcache.cc b/source/blender/draw/engines/eevee/eevee_lightcache.cc index c539c966948..86040151e75 100644 --- a/source/blender/draw/engines/eevee/eevee_lightcache.cc +++ b/source/blender/draw/engines/eevee/eevee_lightcache.cc @@ -1097,8 +1097,8 @@ static void compute_cell_id(EEVEE_LightGrid *egrid, probe->grid_resolution_z; /* Add one for level 0 */ - int max_lvl = (int)floorf(log2f( - float(MAX3(probe->grid_resolution_x, probe->grid_resolution_y, probe->grid_resolution_z)))); + int max_lvl = int(floorf(log2f( + float(MAX3(probe->grid_resolution_x, probe->grid_resolution_y, probe->grid_resolution_z))))); int visited_cells = 0; *r_stride = 0; diff --git a/source/blender/draw/intern/draw_common.cc b/source/blender/draw/intern/draw_common.cc index 013b0ef737e..81ad869b9b0 100644 --- a/source/blender/draw/intern/draw_common.cc +++ b/source/blender/draw/intern/draw_common.cc @@ -22,7 +22,7 @@ #if 0 # define UI_COLOR_RGB_FROM_U8(r, g, b, v4) \ - ARRAY_SET_ITEMS(v4, (float)r / 255.0f, (float)g / 255.0f, (float)b / 255.0f, 1.0) + ARRAY_SET_ITEMS(v4, float(r) / 255.0f, float(g) / 255.0f, float(b) / 255.0f, 1.0) #endif #define UI_COLOR_RGBA_FROM_U8(r, g, b, a, v4) \ ARRAY_SET_ITEMS(v4, float(r) / 255.0f, float(g) / 255.0f, float(b) / 255.0f, float(a) / 255.0f) diff --git a/source/blender/editors/gpencil_legacy/editaction_gpencil.cc b/source/blender/editors/gpencil_legacy/editaction_gpencil.cc index 655e9e5f258..a3ae6662691 100644 --- a/source/blender/editors/gpencil_legacy/editaction_gpencil.cc +++ b/source/blender/editors/gpencil_legacy/editaction_gpencil.cc @@ -505,7 +505,7 @@ static bool gpencil_frame_snap_nearest(bGPDframe * /*gpf*/, Scene * /*scene*/) { #if 0 /* NOTE: gpf->framenum is already an int! */ if (gpf->flag & GP_FRAME_SELECT) { - gpf->framenum = (int)(floor(gpf->framenum + 0.5)); + gpf->framenum = int(floor(gpf->framenum + 0.5)); } #endif return false; diff --git a/source/blender/editors/grease_pencil/intern/grease_pencil_frames.cc b/source/blender/editors/grease_pencil/intern/grease_pencil_frames.cc index 5275fd5d081..ddb98c5df99 100644 --- a/source/blender/editors/grease_pencil/intern/grease_pencil_frames.cc +++ b/source/blender/editors/grease_pencil/intern/grease_pencil_frames.cc @@ -71,7 +71,7 @@ bool layer_has_any_frame_selected(const bke::greasepencil::Layer *layer) return false; } -void select_frames_region(struct KeyframeEditData *ked, +void select_frames_region( KeyframeEditData *ked, bke::greasepencil::Layer *layer, const short tool, const short select_mode) diff --git a/source/blender/gpu/intern/gpu_select_pick.cc b/source/blender/gpu/intern/gpu_select_pick.cc index 0d82f3c5136..ab2f3f8a44f 100644 --- a/source/blender/gpu/intern/gpu_select_pick.cc +++ b/source/blender/gpu/intern/gpu_select_pick.cc @@ -304,7 +304,7 @@ void gpu_select_pick_begin(GPUSelectResult *buffer, #ifdef DEBUG_PRINT printf("%s: mode=%d, use_cache=%d, is_cache=%d\n", __func__, - (int)mode, + int(mode), ps->use_cache, ps->is_cached); #endif diff --git a/source/blender/makesrna/intern/rna_rna.cc b/source/blender/makesrna/intern/rna_rna.cc index 35ef5e4c653..a6e16a139d5 100644 --- a/source/blender/makesrna/intern/rna_rna.cc +++ b/source/blender/makesrna/intern/rna_rna.cc @@ -1587,7 +1587,7 @@ static void rna_property_override_diff_propptr(Main *bmain, index > 0 && item_index_buff_len < sizeof(item_index_buff); index /= 10) { - item_index_buff[item_index_buff_len++] = '0' + (char)(index % 10); + item_index_buff[item_index_buff_len++] = '0' + char(index % 10); } BLI_assert(index == 0); } diff --git a/source/blender/python/generic/bgl.cc b/source/blender/python/generic/bgl.cc index 6b163bc883f..a73e6a882a3 100644 --- a/source/blender/python/generic/bgl.cc +++ b/source/blender/python/generic/bgl.cc @@ -426,7 +426,7 @@ struct BufferOrOffset { #define ret_def_GLuint uint ret_uint #define ret_set_GLuint ret_uint = #define ret_default_GLuint 0 -#define ret_ret_GLuint return PyLong_FromLong((long)ret_uint) +#define ret_ret_GLuint return PyLong_FromLong(long(ret_uint)) #if 0 # define ret_def_GLsizei size_t ret_size_t @@ -437,18 +437,18 @@ struct BufferOrOffset { #if 0 # define ret_def_GLsync uint ret_sync # define ret_set_GLsync ret_sync = -# define ret_ret_GLsync return PyLong_FromLong((long)ret_sync) +# define ret_ret_GLsync return PyLong_FromLong(long(ret_sync)) #endif #define ret_def_GLenum uint ret_uint #define ret_set_GLenum ret_uint = #define ret_default_GLenum 0 -#define ret_ret_GLenum return PyLong_FromLong((long)ret_uint) +#define ret_ret_GLenum return PyLong_FromLong(long(ret_uint)) #define ret_def_GLboolean uchar ret_bool #define ret_set_GLboolean ret_bool = #define ret_default_GLboolean GL_FALSE -#define ret_ret_GLboolean return PyLong_FromLong((long)ret_bool) +#define ret_ret_GLboolean return PyLong_FromLong(long(ret_bool)) #define ret_def_GLstring \ const char *default_GLstring = ""; \ diff --git a/source/blender/python/generic/idprop_py_api.cc b/source/blender/python/generic/idprop_py_api.cc index 9f98d12cc16..151c39f06b8 100644 --- a/source/blender/python/generic/idprop_py_api.cc +++ b/source/blender/python/generic/idprop_py_api.cc @@ -222,7 +222,7 @@ static int BPy_IDGroup_SetData(BPy_IDProperty *self, IDProperty *prop, PyObject break; } case IDP_FLOAT: { - float fvalue = (float)PyFloat_AsDouble(value); + float fvalue = float(PyFloat_AsDouble(value)); if (fvalue == -1 && PyErr_Occurred()) { PyErr_SetString(PyExc_TypeError, "expected a float"); return -1; @@ -1807,9 +1807,9 @@ static PyObject *BPy_IDArray_GetItem(BPy_IDArray *self, Py_ssize_t index) case IDP_DOUBLE: return PyFloat_FromDouble(((double *)IDP_Array(self->prop))[index]); case IDP_INT: - return PyLong_FromLong((long)((int *)IDP_Array(self->prop))[index]); + return PyLong_FromLong(long(((int *)IDP_Array(self->prop))[index])); case IDP_BOOLEAN: - return PyBool_FromLong((long)((int8_t *)IDP_Array(self->prop))[index]); + return PyBool_FromLong(long(((int8_t *)IDP_Array(self->prop))[index])); } PyErr_Format( diff --git a/source/blender/python/intern/bpy_rna.cc b/source/blender/python/intern/bpy_rna.cc index 4fc9e20c3a0..f1fac60d8af 100644 --- a/source/blender/python/intern/bpy_rna.cc +++ b/source/blender/python/intern/bpy_rna.cc @@ -5530,22 +5530,22 @@ static PyObject *foreach_getset(BPy_PropertyRNA *self, PyObject *args, int set) switch (raw_type) { case PROP_RAW_CHAR: - item = PyLong_FromLong((long)((char *)array)[i]); + item = PyLong_FromLong(long(((char *)array)[i])); break; case PROP_RAW_SHORT: - item = PyLong_FromLong((long)((short *)array)[i]); + item = PyLong_FromLong(long(((short *)array)[i])); break; case PROP_RAW_INT: - item = PyLong_FromLong((long)((int *)array)[i]); + item = PyLong_FromLong(long(((int *)array)[i])); break; case PROP_RAW_FLOAT: - item = PyFloat_FromDouble((double)((float *)array)[i]); + item = PyFloat_FromDouble(double(((float *)array)[i])); break; case PROP_RAW_DOUBLE: - item = PyFloat_FromDouble((double)((double *)array)[i]); + item = PyFloat_FromDouble(double(((double *)array)[i])); break; case PROP_RAW_BOOLEAN: - item = PyBool_FromLong((long)((bool *)array)[i]); + item = PyBool_FromLong(long(((bool *)array)[i])); break; default: /* PROP_RAW_UNSET */ /* Should never happen. */ @@ -5658,7 +5658,7 @@ static PyObject *pyprop_array_foreach_getset(BPy_PropertyArrayRNA *self, RNA_property_int_get_array(&self->ptr, self->prop, static_cast(array)); for (i = 0; i < size; i++) { - item = PyLong_FromLong((long)((int *)array)[i]); + item = PyLong_FromLong(long(((int *)array)[i])); PySequence_SetItem(seq, i, item); Py_DECREF(item); } @@ -5680,7 +5680,7 @@ static PyObject *pyprop_array_foreach_getset(BPy_PropertyArrayRNA *self, RNA_property_float_get_array(&self->ptr, self->prop, static_cast(array)); for (i = 0; i < size; i++) { - item = PyFloat_FromDouble((double)((float *)array)[i]); + item = PyFloat_FromDouble(double(((float *)array)[i])); PySequence_SetItem(seq, i, item); Py_DECREF(item); } @@ -6588,7 +6588,7 @@ static PyObject *pyrna_func_call(BPy_FunctionRNA *self, PyObject *args, PyObject #ifdef DEBUG_STRING_FREE # if 0 if (PyList_GET_SIZE(string_free_ls)) { -printf("%.200s.%.200s(): has %d strings\n", RNA_struct_identifier(self_ptr->type), RNA_function_identifier(self_func), (int)PyList_GET_SIZE(string_free_ls)); +printf("%.200s.%.200s(): has %d strings\n", RNA_struct_identifier(self_ptr->type), RNA_function_identifier(self_func), int(PyList_GET_SIZE(string_free_ls))); } # endif Py_DECREF(string_free_ls); diff --git a/source/blender/python/mathutils/mathutils_Vector.cc b/source/blender/python/mathutils/mathutils_Vector.cc index f579a96949d..097f0ac7114 100644 --- a/source/blender/python/mathutils/mathutils_Vector.cc +++ b/source/blender/python/mathutils/mathutils_Vector.cc @@ -2693,8 +2693,8 @@ 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 */ - (size_from = (size_t)mathutils_array_parse( - vec_assign, 2, 4, value, "Vector.**** = swizzle assignment")) == size_t(-1)) + (size_from = size_t(mathutils_array_parse( + vec_assign, 2, 4, value, "Vector.**** = swizzle assignment"))) == size_t(-1)) { return -1; } diff --git a/source/blender/simulation/intern/implicit_blender.cc b/source/blender/simulation/intern/implicit_blender.cc index 1d7468bc96d..fc192fdc9e9 100644 --- a/source/blender/simulation/intern/implicit_blender.cc +++ b/source/blender/simulation/intern/implicit_blender.cc @@ -992,7 +992,7 @@ static int cg_filtered_pre(lfVector *dv, # ifdef DEBUG_TIME double end = PIL_check_seconds_timer(); - printf("cg_filtered_pre time: %f\n", (float)(end - start)); + printf("cg_filtered_pre time: %f\n", float(end - start)); # endif del_lfvector(h); @@ -1103,7 +1103,7 @@ static int cg_filtered_pre(lfVector *dv, # ifdef DEBUG_TIME double end = PIL_check_seconds_timer(); - printf("cg_filtered_pre time: %f\n", (float)(end - start)); + printf("cg_filtered_pre time: %f\n", float(end - start)); # endif del_lfvector(btemp); @@ -1145,7 +1145,7 @@ bool SIM_mass_spring_solve_velocities(Implicit_Data *data, float dt, ImplicitSol # ifdef DEBUG_TIME double end = PIL_check_seconds_timer(); - printf("cg_filtered calc time: %f\n", (float)(end - start)); + printf("cg_filtered calc time: %f\n", float(end - start)); # endif /* advance velocities */ diff --git a/source/blender/windowmanager/gizmo/intern/wm_gizmo_map.cc b/source/blender/windowmanager/gizmo/intern/wm_gizmo_map.cc index 9b9b08c947c..0781b59ecc2 100644 --- a/source/blender/windowmanager/gizmo/intern/wm_gizmo_map.cc +++ b/source/blender/windowmanager/gizmo/intern/wm_gizmo_map.cc @@ -302,7 +302,7 @@ eWM_GizmoFlagMapDrawStep WM_gizmomap_drawstep_from_gizmo_group(const wmGizmoGrou void WM_gizmomap_tag_refresh_drawstep(wmGizmoMap *gzmap, const eWM_GizmoFlagMapDrawStep drawstep) { - BLI_assert((uint)drawstep < WM_GIZMOMAP_DRAWSTEP_MAX); + BLI_assert(uint(drawstep) < WM_GIZMOMAP_DRAWSTEP_MAX); if (gzmap) { gzmap->update_flag[drawstep] |= (GIZMOMAP_IS_PREPARE_DRAW | GIZMOMAP_IS_REFRESH_CALLBACK); } diff --git a/source/blender/windowmanager/intern/wm_draw.cc b/source/blender/windowmanager/intern/wm_draw.cc index ccf7601563d..79b58963c84 100644 --- a/source/blender/windowmanager/intern/wm_draw.cc +++ b/source/blender/windowmanager/intern/wm_draw.cc @@ -1340,7 +1340,7 @@ bool WM_window_pixels_read_sample_from_offscreen(bContext *C, zero_v3(r_col); /* While this shouldn't happen, return in the case it does. */ - BLI_assert((uint)pos[0] < (uint)size[0] && (uint)pos[1] < (uint)size[1]); + BLI_assert(uint(pos[0]) < uint(size[0]) && uint(pos[1]) < uint(size[1])); if (!(uint(pos[0]) < uint(size[0]) && uint(pos[1]) < uint(size[1]))) { return false; } diff --git a/source/blender/windowmanager/intern/wm_playanim.cc b/source/blender/windowmanager/intern/wm_playanim.cc index 680cb7075ae..f7e1d747722 100644 --- a/source/blender/windowmanager/intern/wm_playanim.cc +++ b/source/blender/windowmanager/intern/wm_playanim.cc @@ -252,7 +252,7 @@ struct PlayState { static void print_ps(PlayState *ps) { printf("ps:\n"); - printf(" direction=%d,\n", (int)ps->direction); + printf(" direction=%d,\n", int(ps->direction)); printf(" once=%d,\n", ps->once); printf(" pingpong=%d,\n", ps->pingpong); printf(" noskip=%d,\n", ps->noskip); diff --git a/source/blender/windowmanager/xr/intern/wm_xr_action.cc b/source/blender/windowmanager/xr/intern/wm_xr_action.cc index a2f820021b3..5c9390daeef 100644 --- a/source/blender/windowmanager/xr/intern/wm_xr_action.cc +++ b/source/blender/windowmanager/xr/intern/wm_xr_action.cc @@ -336,7 +336,7 @@ bool WM_xr_action_binding_create(wmXrData *xr, const wmXrPose *poses) { const uint count = uint(BLI_listbase_count(user_paths)); - BLI_assert(count == (uint)BLI_listbase_count(component_paths)); + BLI_assert(count == uint(BLI_listbase_count(component_paths))); GHOST_XrActionBindingInfo *binding_infos = static_cast( MEM_calloc_arrayN(count, sizeof(*binding_infos), "XrActionBinding_Infos"));