From fb2ba20b67a1d5152da898039af7402292af31f2 Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Tue, 22 Apr 2025 11:22:18 +0200 Subject: [PATCH] Refactor: Use more typed MEM_calloc<> and MEM_malloc<> Pull Request: https://projects.blender.org/blender/blender/pulls/137822 --- source/blender/blenkernel/intern/curve.cc | 2 +- source/blender/blenkernel/intern/key.cc | 2 +- .../blender/blenkernel/intern/mesh_convert.cc | 2 +- .../blender/blenkernel/intern/pointcache.cc | 4 +- source/blender/blenlib/BLI_strict_flags.h | 1 - .../blender/blenlib/intern/filereader_zstd.cc | 4 +- source/blender/blenlib/intern/kdtree_impl.h | 3 +- source/blender/blenloader/intern/undofile.cc | 2 +- source/blender/blenloader/intern/writefile.cc | 2 +- .../blender/bmesh/intern/bmesh_construct.cc | 9 +-- source/blender/bmesh/intern/bmesh_core.cc | 2 +- source/blender/bmesh/intern/bmesh_edgeloop.cc | 14 ++--- .../blender/bmesh/intern/bmesh_iterators.cc | 4 +- source/blender/bmesh/intern/bmesh_log.cc | 4 +- source/blender/bmesh/intern/bmesh_mesh.cc | 35 ++++------- .../bmesh/intern/bmesh_mesh_convert.cc | 5 +- .../bmesh/intern/bmesh_mesh_normals.cc | 4 +- .../blender/bmesh/intern/bmesh_operators.cc | 2 +- .../bmesh/intern/bmesh_polygon_edgenet.cc | 3 +- source/blender/bmesh/intern/bmesh_query.cc | 8 +-- .../blender/bmesh/operators/bmo_beautify.cc | 4 +- .../bmesh/operators/bmo_connect_pair.cc | 4 +- source/blender/bmesh/operators/bmo_create.cc | 2 +- source/blender/bmesh/operators/bmo_dupe.cc | 2 +- .../bmesh/operators/bmo_fill_edgeloop.cc | 4 +- .../blender/bmesh/operators/bmo_fill_grid.cc | 8 +-- source/blender/bmesh/operators/bmo_hull.cc | 2 +- source/blender/bmesh/operators/bmo_inset.cc | 5 +- .../bmesh/operators/bmo_join_triangles.cc | 3 +- source/blender/bmesh/operators/bmo_normals.cc | 3 +- .../bmesh/operators/bmo_offset_edgeloops.cc | 2 +- .../blender/bmesh/operators/bmo_primitive.cc | 2 +- .../bmesh/operators/bmo_removedoubles.cc | 2 +- .../bmesh/operators/bmo_subdivide_edgering.cc | 2 +- .../bmesh/operators/bmo_triangulate.cc | 2 +- source/blender/bmesh/tools/bmesh_beautify.cc | 3 +- source/blender/bmesh/tools/bmesh_bevel.cc | 7 +-- .../bmesh/tools/bmesh_decimate_collapse.cc | 7 +-- .../bmesh/tools/bmesh_decimate_dissolve.cc | 4 +- .../bmesh/tools/bmesh_decimate_unsubdivide.cc | 6 +- source/blender/bmesh/tools/bmesh_edgenet.cc | 3 +- source/blender/bmesh/tools/bmesh_intersect.cc | 3 +- source/blender/bmesh/tools/bmesh_path.cc | 12 ++-- .../blender/bmesh/tools/bmesh_path_region.cc | 5 +- .../bmesh/tools/bmesh_path_region_uv.cc | 5 +- source/blender/bmesh/tools/bmesh_path_uv.cc | 12 ++-- .../blender/bmesh/tools/bmesh_region_match.cc | 6 +- source/blender/bmesh/tools/bmesh_separate.cc | 3 +- source/blender/bmesh/tools/bmesh_wireframe.cc | 11 ++-- .../engines/eevee/eevee_lightprobe_volume.cc | 2 +- .../draw/engines/overlay/overlay_mesh.hh | 2 +- .../draw/intern/draw_cache_impl_particles.cc | 24 +++---- .../intern/draw_cache_impl_subdivision.cc | 23 ++++--- source/blender/draw/intern/draw_context.cc | 2 +- source/blender/draw/intern/draw_fluid.cc | 3 +- .../blender/draw/intern/draw_select_buffer.cc | 2 +- .../extract_mesh_vbo_mesh_analysis.cc | 2 +- .../blender/editors/animation/anim_filter.cc | 4 +- .../blender/editors/animation/anim_markers.cc | 7 +-- source/blender/editors/animation/drivers.cc | 3 +- .../blender/editors/animation/fmodifier_ui.cc | 12 ++-- .../editors/animation/keyframes_general.cc | 5 +- .../animation/keyframes_general_test.cc | 2 +- .../animation/keyframes_keylist_test.cc | 3 +- .../blender/editors/animation/keyingsets.cc | 3 +- .../blender/editors/armature/armature_add.cc | 8 +-- .../editors/armature/armature_skinning.cc | 4 +- .../editors/armature/armature_utils.cc | 4 +- .../editors/armature/editarmature_undo.cc | 3 +- .../blender/editors/armature/meshlaplacian.cc | 6 +- .../editors/armature/pose_transform.cc | 3 +- source/blender/editors/curve/editcurve.cc | 63 ++++++++----------- source/blender/editors/curve/editcurve_add.cc | 16 ++--- .../blender/editors/curve/editcurve_paint.cc | 13 ++-- source/blender/editors/curve/editcurve_pen.cc | 22 +++---- .../blender/editors/curve/editcurve_select.cc | 2 +- .../blender/editors/curve/editcurve_undo.cc | 3 +- source/blender/editors/curve/editfont.cc | 27 ++++---- .../editors/curves/intern/curves_data.cc | 4 +- .../editors/curves/intern/curves_draw.cc | 7 +-- .../editors/curves/intern/curves_ops.cc | 8 +-- .../gizmo_types/button2d_gizmo.cc | 2 +- .../editors/gpencil_legacy/annotate_paint.cc | 11 ++-- .../gpencil_legacy/editaction_gpencil.cc | 3 +- .../editors/interface/interface_align.cc | 3 +- .../editors/interface/interface_handlers.cc | 11 ++-- .../editors/interface/interface_icons.cc | 4 +- .../editors/interface/interface_panel.cc | 3 +- .../templates/interface_template_list.cc | 11 ++-- .../editors/lattice/editlattice_select.cc | 2 +- .../editors/lattice/editlattice_undo.cc | 9 +-- .../blender/editors/mesh/editmesh_bisect.cc | 2 +- .../mesh/editmesh_extrude_spin_gizmo.cc | 6 +- source/blender/editors/mesh/editmesh_inset.cc | 3 +- source/blender/editors/mesh/editmesh_rip.cc | 3 +- .../blender/editors/mesh/editmesh_select.cc | 34 ++++------ source/blender/editors/mesh/editmesh_tools.cc | 25 ++++---- source/blender/editors/mesh/editmesh_undo.cc | 5 +- source/blender/editors/mesh/editmesh_utils.cc | 27 +++----- source/blender/editors/mesh/meshtools.cc | 19 +++--- .../editors/metaball/editmball_undo.cc | 3 +- source/blender/editors/object/object_bake.cc | 3 +- .../blender/editors/object/object_bake_api.cc | 9 +-- source/blender/editors/object/object_hook.cc | 7 +-- .../blender/editors/object/object_modifier.cc | 14 ++--- .../blender/editors/object/object_remesh.cc | 5 +- .../blender/editors/object/object_vgroup.cc | 22 +++---- .../editors/physics/dynamicpaint_ops.cc | 3 +- .../blender/editors/physics/particle_edit.cc | 48 ++++++-------- .../editors/physics/particle_object.cc | 5 +- .../blender/editors/physics/physics_fluid.cc | 6 +- .../editors/physics/physics_pointcache.cc | 3 +- .../blender/editors/render/render_internal.cc | 2 +- .../blender/editors/render/render_preview.cc | 3 +- .../blender/editors/render/render_shading.cc | 4 +- source/blender/editors/screen/area.cc | 14 ++--- source/blender/editors/screen/screen_edit.cc | 4 +- .../blender/editors/screen/screen_geometry.cc | 4 +- source/blender/editors/screen/screendump.cc | 3 +- .../sculpt_paint/grease_pencil_trace_util.cc | 5 +- .../editors/sculpt_paint/paint_cursor.cc | 6 +- .../editors/sculpt_paint/paint_curve.cc | 10 ++- .../editors/sculpt_paint/paint_image.cc | 6 +- .../editors/sculpt_paint/paint_image_2d.cc | 8 +-- .../sculpt_paint/paint_image_2d_curve_mask.cc | 3 +- .../editors/sculpt_paint/paint_image_proj.cc | 9 +-- .../blender/editors/sculpt_paint/paint_ops.cc | 2 +- .../sculpt_paint/paint_vertex_weight_ops.cc | 3 +- .../editors/sculpt_paint/paint_weight.cc | 6 +- .../editors/sculpt_paint/sculpt_trim.cc | 3 +- .../blender/editors/sculpt_paint/sculpt_uv.cc | 7 +-- .../editors/space_buttons/space_buttons.cc | 5 +- .../editors/space_console/console_draw.cc | 2 +- .../editors/space_console/console_ops.cc | 8 +-- .../editors/space_console/space_console.cc | 2 +- .../blender/editors/space_file/file_draw.cc | 2 +- .../editors/space_file/file_indexer.cc | 3 +- source/blender/editors/space_file/filelist.cc | 3 +- source/blender/editors/space_file/filesel.cc | 3 +- source/blender/editors/space_file/fsmenu.cc | 2 +- .../blender/editors/space_file/space_file.cc | 2 +- .../blender/editors/space_graph/graph_draw.cc | 3 +- .../editors/space_graph/graph_slider_ops.cc | 16 ++--- .../blender/editors/space_graph/graph_view.cc | 3 +- .../editors/space_graph/space_graph.cc | 6 +- .../blender/editors/space_image/image_ops.cc | 2 +- .../editors/space_image/image_sequence.cc | 4 +- .../blender/editors/space_image/image_undo.cc | 6 +- .../editors/space_image/space_image.cc | 2 +- .../blender/editors/space_info/info_stats.cc | 2 +- .../blender/editors/space_info/space_info.cc | 2 +- source/blender/editors/space_info/textview.cc | 6 +- .../blender/editors/space_node/node_gizmo.cc | 8 +-- .../blender/editors/space_node/node_group.cc | 4 +- .../editors/space_node/node_relationships.cc | 2 +- .../editors/space_outliner/outliner_tree.cc | 6 +- .../space_outliner/tree/tree_element_rna.cc | 2 +- .../editors/space_script/space_script.cc | 2 +- .../space_sequencer/sequencer_drag_drop.cc | 3 +- .../space_statusbar/space_statusbar.cc | 4 +- .../blender/editors/space_text/space_text.cc | 2 +- .../blender/editors/space_text/text_format.cc | 8 +-- source/blender/editors/space_text/text_ops.cc | 4 +- .../editors/space_topbar/space_topbar.cc | 2 +- .../editors/space_userpref/space_userpref.cc | 2 +- .../editors/space_userpref/userpref_ops.cc | 3 +- .../editors/space_view3d/view3d_buttons.cc | 3 +- .../editors/space_view3d/view3d_draw.cc | 2 +- .../editors/space_view3d/view3d_edit.cc | 2 +- .../space_view3d/view3d_gizmo_camera.cc | 3 +- .../space_view3d/view3d_gizmo_empty.cc | 3 +- .../space_view3d/view3d_gizmo_forcefield.cc | 3 +- .../space_view3d/view3d_gizmo_light.cc | 12 ++-- .../space_view3d/view3d_gizmo_navigate.cc | 3 +- .../space_view3d/view3d_gizmo_ruler.cc | 2 +- .../space_view3d/view3d_gizmo_tool_generic.cc | 3 +- .../view3d_navigate_smoothview.cc | 3 +- .../editors/space_view3d/view3d_utils.cc | 2 +- .../editors/space_view3d/view3d_view.cc | 5 +- .../editors/transform/transform_convert.cc | 6 +- .../transform/transform_convert_armature.cc | 7 +-- .../transform/transform_convert_mesh.cc | 15 ++--- .../transform/transform_convert_mesh_skin.cc | 4 +- .../transform/transform_convert_mesh_uv.cc | 3 +- .../transform_convert_mesh_vert_cdata.cc | 4 +- .../transform/transform_convert_object.cc | 2 +- .../transform/transform_gizmo_3d_cage.cc | 3 +- .../transform/transform_gizmo_3d_shear.cc | 3 +- .../editors/transform/transform_mode_bend.cc | 2 +- .../transform/transform_mode_edge_slide.cc | 6 +- .../transform/transform_mode_tosphere.cc | 2 +- .../transform/transform_mode_vert_slide.cc | 2 +- .../transform/transform_orientations.cc | 3 +- source/blender/editors/util/ed_transverts.cc | 3 +- .../blender/editors/uvedit/uvedit_islands.cc | 7 +-- .../blender/editors/uvedit/uvedit_select.cc | 16 +++-- .../editors/uvedit/uvedit_smart_stitch.cc | 26 +++----- .../editors/uvedit/uvedit_unwrap_ops.cc | 13 ++-- .../geometry/intern/uv_parametrizer.cc | 2 +- .../blender/gpu/dummy/dummy_vertex_buffer.hh | 2 +- source/blender/gpu/intern/gpu_batch_utils.cc | 2 +- source/blender/gpu/intern/gpu_index_buffer.cc | 3 +- source/blender/gpu/intern/gpu_material.cc | 6 +- source/blender/gpu/intern/gpu_select_pick.cc | 3 +- source/blender/gpu/intern/gpu_viewport.cc | 3 +- source/blender/gpu/metal/mtl_vertex_buffer.mm | 2 +- .../blender/gpu/opengl/gl_shader_interface.cc | 4 +- source/blender/gpu/opengl/gl_vertex_buffer.cc | 2 +- source/blender/gpu/tests/texture_test.cc | 8 +-- .../blender/gpu/vulkan/vk_shader_interface.cc | 3 +- source/blender/gpu/vulkan/vk_vertex_buffer.cc | 2 +- .../blender/imbuf/movie/intern/movie_read.cc | 4 +- source/blender/makesrna/intern/rna_curve.cc | 5 +- .../nodes/node_geo_string_to_curves.cc | 2 +- source/blender/render/intern/bake.cc | 3 +- .../windowmanager/intern/wm_playanim.cc | 2 +- 216 files changed, 545 insertions(+), 773 deletions(-) diff --git a/source/blender/blenkernel/intern/curve.cc b/source/blender/blenkernel/intern/curve.cc index 9b948cfe7c0..8e3e86055c1 100644 --- a/source/blender/blenkernel/intern/curve.cc +++ b/source/blender/blenkernel/intern/curve.cc @@ -1185,7 +1185,7 @@ static void makeknots(Nurb *nu, short uv) void BKE_nurb_knot_alloc_u(Nurb *nu) { - nu->knotsu = static_cast(MEM_calloc_arrayN(KNOTSU(nu) + 1, sizeof(float), __func__)); + nu->knotsu = MEM_calloc_arrayN(KNOTSU(nu) + 1, __func__); } void BKE_nurb_knot_calc_u(Nurb *nu) diff --git a/source/blender/blenkernel/intern/key.cc b/source/blender/blenkernel/intern/key.cc index f8d0dba8489..c5347c5f536 100644 --- a/source/blender/blenkernel/intern/key.cc +++ b/source/blender/blenkernel/intern/key.cc @@ -1551,7 +1551,7 @@ float *BKE_key_evaluate_object_ex( /* allocate array */ if (arr == nullptr) { - out = static_cast(MEM_callocN(size, "BKE_key_evaluate_object out")); + out = MEM_calloc_arrayN(size, "BKE_key_evaluate_object out"); } else { if (arr_size != size) { diff --git a/source/blender/blenkernel/intern/mesh_convert.cc b/source/blender/blenkernel/intern/mesh_convert.cc index 89b456a6a63..81ebf6615c4 100644 --- a/source/blender/blenkernel/intern/mesh_convert.cc +++ b/source/blender/blenkernel/intern/mesh_convert.cc @@ -1035,7 +1035,7 @@ static void move_shapekey_layers_to_keyblocks(const Mesh &mesh, MEM_SAFE_FREE(kb->data); kb->totelem = mesh.verts_num; - kb->data = MEM_malloc_arrayN(size_t(kb->totelem), sizeof(float3), __func__); + kb->data = MEM_malloc_arrayN(size_t(kb->totelem), __func__); MutableSpan kb_coords(static_cast(kb->data), kb->totelem); if (kb->uid == actshape_uid) { mesh.attributes().lookup("position").varray.materialize(kb_coords); diff --git a/source/blender/blenkernel/intern/pointcache.cc b/source/blender/blenkernel/intern/pointcache.cc index eb9f37cd0db..5524d4ebede 100644 --- a/source/blender/blenkernel/intern/pointcache.cc +++ b/source/blender/blenkernel/intern/pointcache.cc @@ -1512,7 +1512,7 @@ static int ptcache_file_compressed_read(PTCacheFile *pf, uchar *result, uint len size_t out_len = len; #endif uchar *in; - uchar *props = static_cast(MEM_callocN(sizeof(char[16]), "tmp")); + uchar *props = MEM_calloc_arrayN(16, "tmp"); ptcache_file_read(pf, &compressed, 1, sizeof(uchar)); if (compressed) { @@ -1557,7 +1557,7 @@ static int ptcache_file_compressed_write( int r = 0; uchar compressed = 0; size_t out_len = 0; - uchar *props = static_cast(MEM_callocN(sizeof(char[16]), "tmp")); + uchar *props = MEM_calloc_arrayN(16, "tmp"); size_t sizeOfIt = 5; (void)mode; /* unused when building w/o compression */ diff --git a/source/blender/blenlib/BLI_strict_flags.h b/source/blender/blenlib/BLI_strict_flags.h index f07e67a6e64..7320f0e3f34 100644 --- a/source/blender/blenlib/BLI_strict_flags.h +++ b/source/blender/blenlib/BLI_strict_flags.h @@ -17,7 +17,6 @@ #ifdef __GNUC__ /* NOTE(@ideasman42): CLANG behaves slightly differently to GCC, * these can be enabled but do so carefully as they can introduce build-errors. */ -# pragma GCC diagnostic error "-Wsign-conversion" # if !defined(__clang__) # pragma GCC diagnostic error "-Wsign-compare" # pragma GCC diagnostic error "-Wconversion" diff --git a/source/blender/blenlib/intern/filereader_zstd.cc b/source/blender/blenlib/intern/filereader_zstd.cc index ee72cf1d639..44544fa1a9b 100644 --- a/source/blender/blenlib/intern/filereader_zstd.cc +++ b/source/blender/blenlib/intern/filereader_zstd.cc @@ -173,8 +173,8 @@ static const char *zstd_ensure_cache(ZstdReader *zstd, int frame) size_t uncompressed_size = zstd->seek.uncompressed_ofs[frame + 1] - zstd->seek.uncompressed_ofs[frame]; - char *uncompressed_data = static_cast(MEM_mallocN(uncompressed_size, __func__)); - char *compressed_data = static_cast(MEM_mallocN(compressed_size, __func__)); + char *uncompressed_data = MEM_malloc_arrayN(uncompressed_size, __func__); + char *compressed_data = MEM_malloc_arrayN(compressed_size, __func__); if (zstd->base->seek(zstd->base, zstd->seek.compressed_ofs[frame], SEEK_SET) < 0 || zstd->base->read(zstd->base, compressed_data, compressed_size) < compressed_size) { diff --git a/source/blender/blenlib/intern/kdtree_impl.h b/source/blender/blenlib/intern/kdtree_impl.h index a8a6fe23f63..3bab78ec3c6 100644 --- a/source/blender/blenlib/intern/kdtree_impl.h +++ b/source/blender/blenlib/intern/kdtree_impl.h @@ -99,8 +99,7 @@ KDTree *BLI_kdtree_nd_(new)(uint nodes_len_capacity) * four (1D to 4D), differing by their `float co[KD_DIMS]` member. It seems like the code * generating the templates does not distinguish these cases, and create a single code for all * four cases, leading to invalid allocation sizes. */ - tree->nodes = static_cast( - MEM_mallocN(sizeof(KDTreeNode) * nodes_len_capacity, "KDTreeNode")); + tree->nodes = MEM_malloc_arrayN(nodes_len_capacity, "KDTreeNode"); tree->nodes_len = 0; tree->root = KD_NODE_ROOT_IS_INIT; tree->max_node_index = -1; diff --git a/source/blender/blenloader/intern/undofile.cc b/source/blender/blenloader/intern/undofile.cc index 9ec986553fa..1caf49658ea 100644 --- a/source/blender/blenloader/intern/undofile.cc +++ b/source/blender/blenloader/intern/undofile.cc @@ -157,7 +157,7 @@ void BLO_memfile_chunk_add(MemFileWriteData *mem_data, const char *buf, size_t s /* not equal... */ if (curchunk->buf == nullptr) { - char *buf_new = static_cast(MEM_mallocN(size, "Chunk buffer")); + char *buf_new = MEM_malloc_arrayN(size, "Chunk buffer"); memcpy(buf_new, buf, size); curchunk->buf = buf_new; memfile->size += size; diff --git a/source/blender/blenloader/intern/writefile.cc b/source/blender/blenloader/intern/writefile.cc index 3fa340694bf..8fbf9091542 100644 --- a/source/blender/blenloader/intern/writefile.cc +++ b/source/blender/blenloader/intern/writefile.cc @@ -484,7 +484,7 @@ static WriteData *writedata_new(WriteWrap *ww) wd->buffer.max_size = ZSTD_BUFFER_SIZE; wd->buffer.chunk_size = ZSTD_CHUNK_SIZE; } - wd->buffer.buf = static_cast(MEM_mallocN(wd->buffer.max_size, "wd->buffer.buf")); + wd->buffer.buf = MEM_malloc_arrayN(wd->buffer.max_size, "wd->buffer.buf"); } return wd; diff --git a/source/blender/bmesh/intern/bmesh_construct.cc b/source/blender/bmesh/intern/bmesh_construct.cc index 7728021f37e..9b8eb2d6bbe 100644 --- a/source/blender/bmesh/intern/bmesh_construct.cc +++ b/source/blender/bmesh/intern/bmesh_construct.cc @@ -572,12 +572,9 @@ BMesh *BM_mesh_copy(BMesh *bm_old) const BMCustomDataCopyMap loop_map = CustomData_bmesh_copy_map_calc(bm_old->ldata, bm_new->ldata); - vtable = static_cast( - MEM_mallocN(sizeof(BMVert *) * bm_old->totvert, "BM_mesh_copy vtable")); - etable = static_cast( - MEM_mallocN(sizeof(BMEdge *) * bm_old->totedge, "BM_mesh_copy etable")); - ftable = static_cast( - MEM_mallocN(sizeof(BMFace *) * bm_old->totface, "BM_mesh_copy ftable")); + vtable = MEM_malloc_arrayN(bm_old->totvert, "BM_mesh_copy vtable"); + etable = MEM_malloc_arrayN(bm_old->totedge, "BM_mesh_copy etable"); + ftable = MEM_malloc_arrayN(bm_old->totface, "BM_mesh_copy ftable"); BM_ITER_MESH_INDEX (v, &iter, bm_old, BM_VERTS_OF_MESH, i) { /* copy between meshes so can't use 'example' argument */ diff --git a/source/blender/bmesh/intern/bmesh_core.cc b/source/blender/bmesh/intern/bmesh_core.cc index fbf38b8a2af..9027f6c7e98 100644 --- a/source/blender/bmesh/intern/bmesh_core.cc +++ b/source/blender/bmesh/intern/bmesh_core.cc @@ -2245,7 +2245,7 @@ void bmesh_kernel_vert_separate( if (r_vout != nullptr) { BMVert **verts; - verts = static_cast(MEM_mallocN(sizeof(BMVert *) * verts_num, __func__)); + verts = MEM_malloc_arrayN(verts_num, __func__); *r_vout = verts; verts[0] = v; diff --git a/source/blender/bmesh/intern/bmesh_edgeloop.cc b/source/blender/bmesh/intern/bmesh_edgeloop.cc index e1bd74bacbd..7ad987bf28d 100644 --- a/source/blender/bmesh/intern/bmesh_edgeloop.cc +++ b/source/blender/bmesh/intern/bmesh_edgeloop.cc @@ -74,7 +74,7 @@ static bool bm_loop_build(BMEdgeLoopStore *el_store, BMVert *v_prev, BMVert *v, } while (v) { - LinkData *node = static_cast(MEM_callocN(sizeof(*node), __func__)); + LinkData *node = MEM_callocN(__func__); int count; node->data = v; add_fn(&el_store->verts, node); @@ -136,7 +136,7 @@ int BM_mesh_edgeloops_find(BMesh *bm, } const uint edges_len = BLI_stack_count(edge_stack); - BMEdge **edges = static_cast(MEM_mallocN(sizeof(*edges) * edges_len, __func__)); + BMEdge **edges = MEM_malloc_arrayN(edges_len, __func__); BLI_stack_pop_n_reverse(edge_stack, edges, BLI_stack_count(edge_stack)); BLI_stack_free(edge_stack); @@ -298,14 +298,14 @@ bool BM_mesh_edgeloops_find_path(BMesh *bm, } } edges_len = BLI_stack_count(edge_stack); - edges = static_cast(MEM_mallocN(sizeof(*edges) * edges_len, __func__)); + edges = MEM_malloc_arrayN(edges_len, __func__); BLI_stack_pop_n_reverse(edge_stack, edges, BLI_stack_count(edge_stack)); BLI_stack_free(edge_stack); } else { int i = 0; edges_len = bm->totedge; - edges = static_cast(MEM_mallocN(sizeof(*edges) * edges_len, __func__)); + edges = MEM_malloc_arrayN(edges_len, __func__); BM_ITER_MESH_INDEX (e, &iter, bm, BM_EDGES_OF_MESH, i) { BM_elem_flag_enable(e, BM_ELEM_INTERNAL_TAG); @@ -345,7 +345,7 @@ bool BM_mesh_edgeloops_find_path(BMesh *bm, /* build loop from edge pointers */ v = v_match[0]; while (true) { - LinkData *node = static_cast(MEM_callocN(sizeof(*node), __func__)); + LinkData *node = MEM_callocN(__func__); node->data = v; BLI_addhead(&el_store->verts, node); el_store->len++; @@ -357,7 +357,7 @@ bool BM_mesh_edgeloops_find_path(BMesh *bm, v = v_match[1]; while (true) { - LinkData *node = static_cast(MEM_callocN(sizeof(*node), __func__)); + LinkData *node = MEM_callocN(__func__); node->data = v; BLI_addtail(&el_store->verts, node); el_store->len++; @@ -502,7 +502,7 @@ BMEdgeLoopStore *BM_edgeloop_from_verts(BMVert **v_arr, const int v_arr_tot, boo MEM_callocN(sizeof(*el_store), __func__)); int i; for (i = 0; i < v_arr_tot; i++) { - LinkData *node = static_cast(MEM_callocN(sizeof(*node), __func__)); + LinkData *node = MEM_callocN(__func__); node->data = v_arr[i]; BLI_addtail(&el_store->verts, node); } diff --git a/source/blender/bmesh/intern/bmesh_iterators.cc b/source/blender/bmesh/intern/bmesh_iterators.cc index 35cf1d29c8e..261c7eef59e 100644 --- a/source/blender/bmesh/intern/bmesh_iterators.cc +++ b/source/blender/bmesh/intern/bmesh_iterators.cc @@ -154,7 +154,7 @@ void *BM_iter_as_arrayN(BMesh *bm, if (BM_iter_init(&iter, bm, itype, data) && iter.count > 0) { BMElem *ele; BMElem **array = iter.count > stack_array_size ? - static_cast(MEM_mallocN(sizeof(ele) * iter.count, __func__)) : + MEM_malloc_arrayN(iter.count, __func__) : reinterpret_cast(stack_array); int i = 0; @@ -188,7 +188,7 @@ void *BMO_iter_as_arrayN(BMOpSlot slot_args[BMO_OP_MAX_SLOTS], slot_len > 0) { BMElem **array = slot_len > stack_array_size ? - static_cast(MEM_mallocN(sizeof(ele) * slot_len, __func__)) : + MEM_malloc_arrayN(slot_len, __func__) : reinterpret_cast(stack_array); int i = 0; diff --git a/source/blender/bmesh/intern/bmesh_log.cc b/source/blender/bmesh/intern/bmesh_log.cc index 18c7d1567a8..ef931100fee 100644 --- a/source/blender/bmesh/intern/bmesh_log.cc +++ b/source/blender/bmesh/intern/bmesh_log.cc @@ -544,14 +544,14 @@ void BM_log_mesh_elems_reorder(BMesh *bm, BMLog *log) BMVert *v; /* Put all vertex IDs into an array */ - uint *varr = static_cast(MEM_mallocN(sizeof(int) * size_t(bm->totvert), __func__)); + uint *varr = MEM_malloc_arrayN(size_t(bm->totvert), __func__); BM_ITER_MESH_INDEX (v, &bm_iter, bm, BM_VERTS_OF_MESH, i) { varr[i] = bm_log_vert_id_get(log, v); } BMFace *f; /* Put all face IDs into an array */ - uint *farr = static_cast(MEM_mallocN(sizeof(int) * size_t(bm->totface), __func__)); + uint *farr = MEM_malloc_arrayN(size_t(bm->totface), __func__); BM_ITER_MESH_INDEX (f, &bm_iter, bm, BM_FACES_OF_MESH, i) { farr[i] = bm_log_face_id_get(log, f); } diff --git a/source/blender/bmesh/intern/bmesh_mesh.cc b/source/blender/bmesh/intern/bmesh_mesh.cc index 29d0e7872df..a1561923f41 100644 --- a/source/blender/bmesh/intern/bmesh_mesh.cc +++ b/source/blender/bmesh/intern/bmesh_mesh.cc @@ -132,7 +132,7 @@ void BM_mesh_elem_toolflags_clear(BMesh *bm) BMesh *BM_mesh_create(const BMAllocTemplate *allocsize, const BMeshCreateParams *params) { /* allocate the structure */ - BMesh *bm = static_cast(MEM_callocN(sizeof(BMesh), __func__)); + BMesh *bm = MEM_callocN(__func__); /* allocate the memory pools for the mesh elements */ bm_mempool_init(bm, allocsize, params->use_toolflags); @@ -768,11 +768,8 @@ void BM_mesh_remap(BMesh *bm, const uint *vert_idx, const uint *edge_idx, const /* Make a copy of all vertices. */ verts_pool = bm->vtable; - verts_copy = static_cast( - MEM_mallocN(sizeof(BMVert) * totvert, "BM_mesh_remap verts copy")); - void **pyptrs = (cd_vert_pyptr != -1) ? - static_cast(MEM_mallocN(sizeof(void *) * totvert, __func__)) : - nullptr; + verts_copy = MEM_malloc_arrayN(totvert, "BM_mesh_remap verts copy"); + void **pyptrs = (cd_vert_pyptr != -1) ? MEM_malloc_arrayN(totvert, __func__) : nullptr; for (i = totvert, ve = verts_copy + totvert - 1, vep = verts_pool + totvert - 1; i--; ve--, vep--) { @@ -825,11 +822,8 @@ void BM_mesh_remap(BMesh *bm, const uint *vert_idx, const uint *edge_idx, const /* Make a copy of all vertices. */ edges_pool = bm->etable; - edges_copy = static_cast( - MEM_mallocN(sizeof(BMEdge) * totedge, "BM_mesh_remap edges copy")); - void **pyptrs = (cd_edge_pyptr != -1) ? - static_cast(MEM_mallocN(sizeof(void *) * totedge, __func__)) : - nullptr; + edges_copy = MEM_malloc_arrayN(totedge, "BM_mesh_remap edges copy"); + void **pyptrs = (cd_edge_pyptr != -1) ? MEM_malloc_arrayN(totedge, __func__) : nullptr; for (i = totedge, ed = edges_copy + totedge - 1, edp = edges_pool + totedge - 1; i--; ed--, edp--) { @@ -881,11 +875,8 @@ void BM_mesh_remap(BMesh *bm, const uint *vert_idx, const uint *edge_idx, const /* Make a copy of all vertices. */ faces_pool = bm->ftable; - faces_copy = static_cast( - MEM_mallocN(sizeof(BMFace) * totface, "BM_mesh_remap faces copy")); - void **pyptrs = (cd_poly_pyptr != -1) ? - static_cast(MEM_mallocN(sizeof(void *) * totface, __func__)) : - nullptr; + faces_copy = MEM_malloc_arrayN(totface, "BM_mesh_remap faces copy"); + void **pyptrs = (cd_poly_pyptr != -1) ? MEM_malloc_arrayN(totface, __func__) : nullptr; for (i = totface, fa = faces_copy + totface - 1, fap = faces_pool + totface - 1; i--; fa--, fap--) { @@ -1053,17 +1044,13 @@ void BM_mesh_rebuild(BMesh *bm, const char remap = (vpool_dst ? BM_VERT : 0) | (epool_dst ? BM_EDGE : 0) | (lpool_dst ? BM_LOOP : 0) | (fpool_dst ? BM_FACE : 0); - BMVert **vtable_dst = (remap & BM_VERT) ? static_cast(MEM_mallocN( - sizeof(BMVert *) * bm->totvert, __func__)) : + BMVert **vtable_dst = (remap & BM_VERT) ? MEM_malloc_arrayN(bm->totvert, __func__) : nullptr; - BMEdge **etable_dst = (remap & BM_EDGE) ? static_cast(MEM_mallocN( - sizeof(BMEdge *) * bm->totedge, __func__)) : + BMEdge **etable_dst = (remap & BM_EDGE) ? MEM_malloc_arrayN(bm->totedge, __func__) : nullptr; - BMLoop **ltable_dst = (remap & BM_LOOP) ? static_cast(MEM_mallocN( - sizeof(BMLoop *) * bm->totloop, __func__)) : + BMLoop **ltable_dst = (remap & BM_LOOP) ? MEM_malloc_arrayN(bm->totloop, __func__) : nullptr; - BMFace **ftable_dst = (remap & BM_FACE) ? static_cast(MEM_mallocN( - sizeof(BMFace *) * bm->totface, __func__)) : + BMFace **ftable_dst = (remap & BM_FACE) ? MEM_malloc_arrayN(bm->totface, __func__) : nullptr; const bool use_toolflags = params->use_toolflags; diff --git a/source/blender/bmesh/intern/bmesh_mesh_convert.cc b/source/blender/bmesh/intern/bmesh_mesh_convert.cc index f2c8f178baa..481939662a2 100644 --- a/source/blender/bmesh/intern/bmesh_mesh_convert.cc +++ b/source/blender/bmesh/intern/bmesh_mesh_convert.cc @@ -616,7 +616,7 @@ static BMVert **bm_to_mesh_vertex_map(BMesh *bm, const int old_verts_num) /* Caller needs to ensure this. */ BLI_assert(old_verts_num > 0); - vertMap = static_cast(MEM_callocN(sizeof(*vertMap) * old_verts_num, "vertMap")); + vertMap = MEM_calloc_arrayN(old_verts_num, "vertMap"); if (cd_shape_keyindex_offset != -1) { BM_ITER_MESH_INDEX (eve, &iter, bm, BM_VERTS_OF_MESH, i) { const int keyi = BM_ELEM_CD_GET_INT(eve, cd_shape_keyindex_offset); @@ -1575,8 +1575,7 @@ void BM_mesh_bm_to_me(Main *bmain, BMesh *bm, Mesh *mesh, const BMeshToMeshParam MEM_SAFE_FREE(mesh->mselect); if (mesh->totselect != 0) { - mesh->mselect = static_cast( - MEM_mallocN(sizeof(MSelect) * mesh->totselect, "Mesh selection history")); + mesh->mselect = MEM_malloc_arrayN(mesh->totselect, "Mesh selection history"); } int i; LISTBASE_FOREACH_INDEX (BMEditSelection *, selected, &bm->selected, i) { diff --git a/source/blender/bmesh/intern/bmesh_mesh_normals.cc b/source/blender/bmesh/intern/bmesh_mesh_normals.cc index 484d6a217aa..d786d39ce1a 100644 --- a/source/blender/bmesh/intern/bmesh_mesh_normals.cc +++ b/source/blender/bmesh/intern/bmesh_mesh_normals.cc @@ -2153,8 +2153,8 @@ BMLoopNorEditDataArray *BM_loop_normal_editdata_array_init(BMesh *bm, totloopsel = bm_loop_normal_mark_indiv(bm, loops, do_all_loops_of_vert); if (totloopsel) { - BMLoopNorEditData *lnor_ed = lnors_ed_arr->lnor_editdata = static_cast( - MEM_mallocN(sizeof(*lnor_ed) * totloopsel, __func__)); + BMLoopNorEditData *lnor_ed = lnors_ed_arr->lnor_editdata = + MEM_malloc_arrayN(totloopsel, __func__); BM_ITER_MESH (v, &viter, bm, BM_VERTS_OF_MESH) { BM_ITER_ELEM (l, &liter, v, BM_LOOPS_OF_VERT) { diff --git a/source/blender/bmesh/intern/bmesh_operators.cc b/source/blender/bmesh/intern/bmesh_operators.cc index 588d9559849..d56a9b80f5a 100644 --- a/source/blender/bmesh/intern/bmesh_operators.cc +++ b/source/blender/bmesh/intern/bmesh_operators.cc @@ -465,7 +465,7 @@ void *BMO_slot_as_arrayN(BMOpSlot slot_args[BMO_OP_MAX_SLOTS], const char *slot_ /* could add support for mapping type */ BLI_assert(slot->slot_type == BMO_OP_SLOT_ELEMENT_BUF); - ret = static_cast(MEM_mallocN(sizeof(void *) * slot->len, __func__)); + ret = MEM_malloc_arrayN(slot->len, __func__); memcpy(ret, slot->data.buf, sizeof(void *) * slot->len); *len = slot->len; return ret; diff --git a/source/blender/bmesh/intern/bmesh_polygon_edgenet.cc b/source/blender/bmesh/intern/bmesh_polygon_edgenet.cc index 82d567b6861..8c9e2e28688 100644 --- a/source/blender/bmesh/intern/bmesh_polygon_edgenet.cc +++ b/source/blender/bmesh/intern/bmesh_polygon_edgenet.cc @@ -474,8 +474,7 @@ bool BM_face_split_edgenet(BMesh *bm, * large for single faces with complex edge-nets, see: #65980. */ /* over-alloc (probably 2-4 is only used in most cases), for the biggest-fan */ - edge_order = static_cast( - MEM_mallocN(sizeof(*edge_order) * edge_order_len, __func__)); + edge_order = MEM_malloc_arrayN(edge_order_len, __func__); /* use later */ face_verts = static_cast( diff --git a/source/blender/bmesh/intern/bmesh_query.cc b/source/blender/bmesh/intern/bmesh_query.cc index a71cfcf548d..156d40eb42a 100644 --- a/source/blender/bmesh/intern/bmesh_query.cc +++ b/source/blender/bmesh/intern/bmesh_query.cc @@ -2158,7 +2158,7 @@ int BM_mesh_calc_face_groups(BMesh *bm, bm->elem_index_dirty &= ~BM_FACE; /* detect groups */ - stack = static_cast(MEM_mallocN(sizeof(*stack) * tot_faces, __func__)); + stack = MEM_malloc_arrayN(tot_faces, __func__); f_next = static_cast(BM_iter_new(&iter, bm, BM_FACES_OF_MESH, nullptr)); @@ -2310,7 +2310,7 @@ int BM_mesh_calc_edge_groups(BMesh *bm, bm->elem_index_dirty &= ~BM_EDGE; /* detect groups */ - stack = static_cast(MEM_mallocN(sizeof(*stack) * tot_edges, __func__)); + stack = MEM_malloc_arrayN(tot_edges, __func__); e_next = static_cast(BM_iter_new(&iter, bm, BM_EDGES_OF_MESH, nullptr)); @@ -2388,14 +2388,14 @@ int BM_mesh_calc_edge_groups(BMesh *bm, int BM_mesh_calc_edge_groups_as_arrays( BMesh *bm, BMVert **verts, BMEdge **edges, BMFace **faces, int (**r_groups)[3]) { - int(*groups)[3] = static_cast(MEM_mallocN(sizeof(*groups) * bm->totvert, __func__)); + int(*groups)[3] = MEM_malloc_arrayN(bm->totvert, __func__); STACK_DECLARE(groups); STACK_INIT(groups, bm->totvert); /* Clear all selected vertices */ BM_mesh_elem_hflag_disable_all(bm, BM_VERT | BM_EDGE | BM_FACE, BM_ELEM_TAG, false); - BMVert **stack = static_cast(MEM_mallocN(sizeof(*stack) * bm->totvert, __func__)); + BMVert **stack = MEM_malloc_arrayN(bm->totvert, __func__); STACK_DECLARE(stack); STACK_INIT(stack, bm->totvert); diff --git a/source/blender/bmesh/operators/bmo_beautify.cc b/source/blender/bmesh/operators/bmo_beautify.cc index 8808be4fe4d..b0bdfc06d7a 100644 --- a/source/blender/bmesh/operators/bmo_beautify.cc +++ b/source/blender/bmesh/operators/bmo_beautify.cc @@ -44,8 +44,8 @@ void bmo_beautify_fill_exec(BMesh *bm, BMOperator *op) } /* will over alloc if some edges can't be rotated */ - edge_array = static_cast(MEM_mallocN( - sizeof(*edge_array) * size_t(BMO_slot_buffer_len(op->slots_in, "edges")), __func__)); + edge_array = MEM_malloc_arrayN(size_t(BMO_slot_buffer_len(op->slots_in, "edges")), + __func__); BMO_ITER (e, &siter, op->slots_in, "edges", BM_EDGE) { diff --git a/source/blender/bmesh/operators/bmo_connect_pair.cc b/source/blender/bmesh/operators/bmo_connect_pair.cc index 9a7de247d93..8d0e3d1cddb 100644 --- a/source/blender/bmesh/operators/bmo_connect_pair.cc +++ b/source/blender/bmesh/operators/bmo_connect_pair.cc @@ -290,7 +290,7 @@ static void state_link_add(PathContext *pc, PathLinkState *state, BMElem *ele, B static PathLinkState *state_dupe_add(PathLinkState *state, const PathLinkState *state_orig) { - state = static_cast(MEM_mallocN(sizeof(*state), __func__)); + state = MEM_mallocN(__func__); *state = *state_orig; return state; } @@ -630,7 +630,7 @@ void bmo_connect_vert_pair_exec(BMesh *bm, BMOperator *op) /* add first vertex */ { PathLinkState *state; - state = static_cast(MEM_callocN(sizeof(*state), __func__)); + state = MEM_callocN(__func__); state_link_add(&pc, state, (BMElem *)pc.v_pair[0], nullptr); BLI_heapsimple_insert(pc.states, state->dist, state); } diff --git a/source/blender/bmesh/operators/bmo_create.cc b/source/blender/bmesh/operators/bmo_create.cc index 607e4af98d2..086a249a9f8 100644 --- a/source/blender/bmesh/operators/bmo_create.cc +++ b/source/blender/bmesh/operators/bmo_create.cc @@ -268,7 +268,7 @@ void bmo_contextual_create_exec(BMesh *bm, BMOperator *op) * this connectivity could be used rather than treating * them as a bunch of isolated verts. */ - BMVert **vert_arr = static_cast(MEM_mallocN(sizeof(BMVert *) * totv, __func__)); + BMVert **vert_arr = MEM_malloc_arrayN(totv, __func__); BMFace *f; totv = BMO_iter_as_array(op->slots_in, "geom", BM_VERT, (void **)vert_arr, totv); diff --git a/source/blender/bmesh/operators/bmo_dupe.cc b/source/blender/bmesh/operators/bmo_dupe.cc index f5adc1da149..cd2662d20e8 100644 --- a/source/blender/bmesh/operators/bmo_dupe.cc +++ b/source/blender/bmesh/operators/bmo_dupe.cc @@ -549,7 +549,7 @@ void bmo_spin_exec(BMesh *bm, BMOperator *op) BMVert **vtable = nullptr; if (use_merge) { - vtable = static_cast(MEM_mallocN(sizeof(BMVert *) * bm->totvert, __func__)); + vtable = MEM_malloc_arrayN(bm->totvert, __func__); int i = 0; BMIter iter; BMVert *v; diff --git a/source/blender/bmesh/operators/bmo_fill_edgeloop.cc b/source/blender/bmesh/operators/bmo_fill_edgeloop.cc index 6c1913f8634..e761ef3c670 100644 --- a/source/blender/bmesh/operators/bmo_fill_edgeloop.cc +++ b/source/blender/bmesh/operators/bmo_fill_edgeloop.cc @@ -23,7 +23,7 @@ void bmo_edgeloop_fill_exec(BMesh *bm, BMOperator *op) /* first collect an array of unique from the edges */ const int tote = BMO_slot_buffer_len(op->slots_in, "edges"); const int totv = tote; /* these should be the same */ - BMVert **verts = static_cast(MEM_mallocN(sizeof(*verts) * totv, __func__)); + BMVert **verts = MEM_malloc_arrayN(totv, __func__); BMVert *v; BMEdge *e; @@ -72,7 +72,7 @@ void bmo_edgeloop_fill_exec(BMesh *bm, BMOperator *op) if (ok) { /* NOTE: in the case of multiple loops, this over-allocates (which is fine). */ - BMVert **f_verts = static_cast(MEM_mallocN(sizeof(*verts) * totv, __func__)); + BMVert **f_verts = MEM_malloc_arrayN(totv, __func__); BMIter eiter; /* build array of connected verts and edges */ diff --git a/source/blender/bmesh/operators/bmo_fill_grid.cc b/source/blender/bmesh/operators/bmo_fill_grid.cc index f1bc84bbabd..f52bb1f0e7b 100644 --- a/source/blender/bmesh/operators/bmo_fill_grid.cc +++ b/source/blender/bmesh/operators/bmo_fill_grid.cc @@ -245,11 +245,11 @@ static void bm_grid_fill_array(BMesh *bm, /* Store loops */ if (use_loop_interp) { /* x2 because each edge connects 2 loops */ - larr_x_a = static_cast(MEM_mallocN(sizeof(*larr_x_a) * (xtot - 1), __func__)); - larr_x_b = static_cast(MEM_mallocN(sizeof(*larr_x_b) * (xtot - 1), __func__)); + larr_x_a = MEM_malloc_arrayN((xtot - 1), __func__); + larr_x_b = MEM_malloc_arrayN((xtot - 1), __func__); - larr_y_a = static_cast(MEM_mallocN(sizeof(*larr_y_a) * (ytot - 1), __func__)); - larr_y_b = static_cast(MEM_mallocN(sizeof(*larr_y_b) * (ytot - 1), __func__)); + larr_y_a = MEM_malloc_arrayN((ytot - 1), __func__); + larr_y_b = MEM_malloc_arrayN((ytot - 1), __func__); /* fill in the loops */ for (x = 0; x < xtot - 1; x++) { diff --git a/source/blender/bmesh/operators/bmo_hull.cc b/source/blender/bmesh/operators/bmo_hull.cc index 3f5c0f942cb..85f11089b12 100644 --- a/source/blender/bmesh/operators/bmo_hull.cc +++ b/source/blender/bmesh/operators/bmo_hull.cc @@ -445,7 +445,7 @@ static BMVert **hull_verts_from_bullet(plConvexHull hull, const int num_input_verts) { const int num_verts = plConvexHullNumVertices(hull); - BMVert **hull_verts = static_cast(MEM_mallocN(sizeof(*hull_verts) * num_verts, AT)); + BMVert **hull_verts = MEM_malloc_arrayN(num_verts, AT); int i; for (i = 0; i < num_verts; i++) { diff --git a/source/blender/bmesh/operators/bmo_inset.cc b/source/blender/bmesh/operators/bmo_inset.cc index dcc991127be..06a97f2785c 100644 --- a/source/blender/bmesh/operators/bmo_inset.cc +++ b/source/blender/bmesh/operators/bmo_inset.cc @@ -752,8 +752,7 @@ void bmo_inset_region_exec(BMesh *bm, BMOperator *op) } bm->elem_index_dirty |= BM_EDGE; - edge_info = static_cast( - MEM_mallocN(edge_info_len * sizeof(SplitEdgeInfo), __func__)); + edge_info = MEM_malloc_arrayN(edge_info_len, __func__); /* fill in array and initialize tagging */ es = edge_info; @@ -1355,7 +1354,7 @@ void bmo_inset_region_exec(BMesh *bm, BMOperator *op) * which BM_vert_calc_shell_factor uses. */ /* over allocate */ - varr_co = static_cast(MEM_callocN(sizeof(*varr_co) * bm->totvert, __func__)); + varr_co = MEM_calloc_arrayN(bm->totvert, __func__); void *vert_lengths_p = nullptr; BM_ITER_MESH_INDEX (v, &iter, bm, BM_VERTS_OF_MESH, i) { diff --git a/source/blender/bmesh/operators/bmo_join_triangles.cc b/source/blender/bmesh/operators/bmo_join_triangles.cc index b683fb948fe..ebba7fe601d 100644 --- a/source/blender/bmesh/operators/bmo_join_triangles.cc +++ b/source/blender/bmesh/operators/bmo_join_triangles.cc @@ -980,8 +980,7 @@ void bmo_join_triangles_exec(BMesh *bm, BMOperator *op) s.edge_queue = BLI_heap_new(); s.select_tris_only = BMO_slot_bool_get(op->slots_in, "deselect_joined"); if (s.use_topo_influence) { - s.edge_queue_nodes = static_cast( - MEM_malloc_arrayN(bm->totedge, sizeof(HeapNode *), __func__)); + s.edge_queue_nodes = MEM_malloc_arrayN(bm->totedge, __func__); } #ifdef USE_JOIN_TRIANGLE_INTERACTIVE_TESTING diff --git a/source/blender/bmesh/operators/bmo_normals.cc b/source/blender/bmesh/operators/bmo_normals.cc index ca0b41668de..a5d09ca05aa 100644 --- a/source/blender/bmesh/operators/bmo_normals.cc +++ b/source/blender/bmesh/operators/bmo_normals.cc @@ -255,8 +255,7 @@ static void bmo_recalc_face_normals_array(BMesh *bm, void bmo_recalc_face_normals_exec(BMesh *bm, BMOperator *op) { - int *groups_array = static_cast( - MEM_mallocN(sizeof(*groups_array) * bm->totface, __func__)); + int *groups_array = MEM_malloc_arrayN(bm->totface, __func__); BMFace **faces_grp = static_cast( MEM_mallocN(sizeof(*faces_grp) * bm->totface, __func__)); diff --git a/source/blender/bmesh/operators/bmo_offset_edgeloops.cc b/source/blender/bmesh/operators/bmo_offset_edgeloops.cc index 2f9a31d597f..cf96ba84cc0 100644 --- a/source/blender/bmesh/operators/bmo_offset_edgeloops.cc +++ b/source/blender/bmesh/operators/bmo_offset_edgeloops.cc @@ -82,7 +82,7 @@ void bmo_offset_edgeloops_exec(BMesh *bm, BMOperator *op) BM_mesh_elem_hflag_disable_all(bm, BM_VERT | BM_EDGE | BM_FACE, BM_ELEM_TAG, false); /* over alloc */ - verts = static_cast(MEM_mallocN(sizeof(*verts) * (edges_num * 2), __func__)); + verts = MEM_malloc_arrayN((edges_num * 2), __func__); STACK_INIT(verts, (edges_num * 2)); diff --git a/source/blender/bmesh/operators/bmo_primitive.cc b/source/blender/bmesh/operators/bmo_primitive.cc index ffed8df281b..9dc5aae9200 100644 --- a/source/blender/bmesh/operators/bmo_primitive.cc +++ b/source/blender/bmesh/operators/bmo_primitive.cc @@ -1156,7 +1156,7 @@ void BM_mesh_calc_uvs_sphere(BMesh *bm, const short oflag, const int cd_loop_uv_ void bmo_create_monkey_exec(BMesh *bm, BMOperator *op) { - BMVert **tv = static_cast(MEM_mallocN(sizeof(*tv) * monkeynv * 2, "tv")); + BMVert **tv = MEM_malloc_arrayN(monkeynv * 2, "tv"); float mat[4][4]; int i; diff --git a/source/blender/bmesh/operators/bmo_removedoubles.cc b/source/blender/bmesh/operators/bmo_removedoubles.cc index e71295bab48..e228fe2f83d 100644 --- a/source/blender/bmesh/operators/bmo_removedoubles.cc +++ b/source/blender/bmesh/operators/bmo_removedoubles.cc @@ -642,7 +642,7 @@ static void bmesh_find_doubles_common(BMesh *bm, BMO_slot_buffer_flag_enable(bm, op->slots_in, "keep_verts", BM_VERT, VERT_KEEP); } - int *duplicates = static_cast(MEM_mallocN(sizeof(int) * verts_len, __func__)); + int *duplicates = MEM_malloc_arrayN(verts_len, __func__); { KDTree_3d *tree = BLI_kdtree_3d_new(verts_len); for (int i = 0; i < verts_len; i++) { diff --git a/source/blender/bmesh/operators/bmo_subdivide_edgering.cc b/source/blender/bmesh/operators/bmo_subdivide_edgering.cc index 12c9e35f4ff..21943fcb218 100644 --- a/source/blender/bmesh/operators/bmo_subdivide_edgering.cc +++ b/source/blender/bmesh/operators/bmo_subdivide_edgering.cc @@ -446,7 +446,7 @@ static LoopPairStore *bm_edgering_pair_store_create(BMesh *bm, BMEdgeLoopStore *el_store_b, const int interp_mode) { - LoopPairStore *lpair = static_cast(MEM_mallocN(sizeof(*lpair), __func__)); + LoopPairStore *lpair = MEM_mallocN(__func__); if (interp_mode == SUBD_RING_INTERP_SURF) { const uint len_a = BM_edgeloop_length_get(el_store_a); diff --git a/source/blender/bmesh/operators/bmo_triangulate.cc b/source/blender/bmesh/operators/bmo_triangulate.cc index 209e2924031..0c620c8067c 100644 --- a/source/blender/bmesh/operators/bmo_triangulate.cc +++ b/source/blender/bmesh/operators/bmo_triangulate.cc @@ -101,7 +101,7 @@ void bmo_triangle_fill_exec(BMesh *bm, BMOperator *op) uint i; bool is_degenerate = true; - nors = static_cast(MEM_mallocN(sizeof(*nors) * nors_tot, __func__)); + nors = MEM_malloc_arrayN(nors_tot, __func__); for (sf_vert = static_cast(sf_ctx.fillvertbase.first), i = 0; sf_vert; sf_vert = sf_vert->next, i++) diff --git a/source/blender/bmesh/tools/bmesh_beautify.cc b/source/blender/bmesh/tools/bmesh_beautify.cc index 7aba7e30cf0..7bd73fa018d 100644 --- a/source/blender/bmesh/tools/bmesh_beautify.cc +++ b/source/blender/bmesh/tools/bmesh_beautify.cc @@ -315,8 +315,7 @@ void BM_mesh_beautify_fill(BMesh *bm, #endif eheap = BLI_heap_new_ex(uint(edge_array_len)); - eheap_table = static_cast( - MEM_mallocN(sizeof(HeapNode *) * size_t(edge_array_len), __func__)); + eheap_table = MEM_malloc_arrayN(size_t(edge_array_len), __func__); /* build heap */ for (i = 0; i < edge_array_len; i++) { diff --git a/source/blender/bmesh/tools/bmesh_bevel.cc b/source/blender/bmesh/tools/bmesh_bevel.cc index 82afb4be78b..695f24eb7c7 100644 --- a/source/blender/bmesh/tools/bmesh_bevel.cc +++ b/source/blender/bmesh/tools/bmesh_bevel.cc @@ -844,8 +844,8 @@ static void math_layer_info_init(BevelParams *bp, BMesh *bm) /* Use an array as a stack. Stack size can't exceed total faces if keep track of what is in * stack. */ - BMFace **stack = static_cast(MEM_malloc_arrayN(totface, sizeof(BMFace *), __func__)); - bool *in_stack = static_cast(MEM_malloc_arrayN(totface, sizeof(bool), __func__)); + BMFace **stack = MEM_malloc_arrayN(totface, __func__); + bool *in_stack = MEM_malloc_arrayN(totface, __func__); /* Set all component ids by DFS from faces with unassigned components. */ for (f = 0; f < totface; f++) { @@ -5013,8 +5013,7 @@ static VMesh *square_out_adj_vmesh(BevelParams *bp, BevVert *bv) float ns2inv = 1.0f / float(ns2); VMesh *vm = new_adj_vmesh(bp->mem_arena, n_bndv, ns, bv->vmesh->boundstart); int clstride = 3 * (ns2 + 1); - float *centerline = static_cast( - MEM_mallocN(sizeof(float) * clstride * n_bndv, "bevel")); + float *centerline = MEM_malloc_arrayN(clstride * n_bndv, "bevel"); bool *cset = MEM_calloc_arrayN(n_bndv, "bevel"); /* Find on_edge, place on bndv[i]'s elast where offset line would meet, diff --git a/source/blender/bmesh/tools/bmesh_decimate_collapse.cc b/source/blender/bmesh/tools/bmesh_decimate_collapse.cc index 1577701cdbd..124d4e229e6 100644 --- a/source/blender/bmesh/tools/bmesh_decimate_collapse.cc +++ b/source/blender/bmesh/tools/bmesh_decimate_collapse.cc @@ -409,9 +409,8 @@ static int *bm_edge_symmetry_map(BMesh *bm, uint symmetry_axis, float limit) tree = BLI_kdtree_3d_new(bm->totedge); - etable = static_cast(MEM_mallocN(sizeof(*etable) * bm->totedge, __func__)); - edge_symmetry_map = static_cast( - MEM_mallocN(sizeof(*edge_symmetry_map) * bm->totedge, __func__)); + etable = MEM_malloc_arrayN(bm->totedge, __func__); + edge_symmetry_map = MEM_malloc_arrayN(bm->totedge, __func__); BM_ITER_MESH_INDEX (e, &iter, bm, BM_EDGES_OF_MESH, i) { float co[3]; @@ -1316,7 +1315,7 @@ void BM_mesh_decimate_collapse(BMesh *bm, vquadrics = MEM_calloc_arrayN(bm->totvert, __func__); /* Since some edges may be degenerate, we might be over allocating a little here. */ eheap = BLI_heap_new_ex(bm->totedge); - eheap_table = static_cast(MEM_mallocN(sizeof(HeapNode *) * bm->totedge, __func__)); + eheap_table = MEM_malloc_arrayN(bm->totedge, __func__); tot_edge_orig = bm->totedge; /* build initial edge collapse cost data */ diff --git a/source/blender/bmesh/tools/bmesh_decimate_dissolve.cc b/source/blender/bmesh/tools/bmesh_decimate_dissolve.cc index 3f3dfd23e54..a7e32a657fc 100644 --- a/source/blender/bmesh/tools/bmesh_decimate_dissolve.cc +++ b/source/blender/bmesh/tools/bmesh_decimate_dissolve.cc @@ -384,7 +384,7 @@ void BM_mesh_decimate_dissolve_ex(BMesh *bm, /* prepare for cleanup */ BM_mesh_elem_index_ensure(bm, BM_VERT); - vert_reverse_lookup = static_cast(MEM_mallocN(sizeof(int) * bm->totvert, __func__)); + vert_reverse_lookup = MEM_malloc_arrayN(bm->totvert, __func__); copy_vn_i(vert_reverse_lookup, bm->totvert, -1); for (i = 0; i < vinput_len; i++) { BMVert *v = vinput_arr[i]; @@ -392,7 +392,7 @@ void BM_mesh_decimate_dissolve_ex(BMesh *bm, } /* --- cleanup --- */ - earray = static_cast(MEM_mallocN(sizeof(BMEdge *) * bm->totedge, __func__)); + earray = MEM_malloc_arrayN(bm->totedge, __func__); BM_ITER_MESH_INDEX (e_iter, &iter, bm, BM_EDGES_OF_MESH, i) { earray[i] = e_iter; } diff --git a/source/blender/bmesh/tools/bmesh_decimate_unsubdivide.cc b/source/blender/bmesh/tools/bmesh_decimate_unsubdivide.cc index ed94a7dea93..91a178f64ed 100644 --- a/source/blender/bmesh/tools/bmesh_decimate_unsubdivide.cc +++ b/source/blender/bmesh/tools/bmesh_decimate_unsubdivide.cc @@ -202,10 +202,8 @@ void BM_mesh_decimate_unsubdivide_ex(BMesh *bm, const int iterations, const bool { /* NOTE: while #BMWalker seems like a logical choice, it results in uneven geometry. */ - BMVert **verts_collapse = static_cast( - MEM_mallocN(sizeof(BMVert *) * bm->totvert, __func__)); - BMVert **verts_ignore = static_cast( - MEM_mallocN(sizeof(BMVert *) * bm->totvert, __func__)); + BMVert **verts_collapse = MEM_malloc_arrayN(bm->totvert, __func__); + BMVert **verts_ignore = MEM_malloc_arrayN(bm->totvert, __func__); uint verts_collapse_num = 0; uint verts_ignore_num = 0; diff --git a/source/blender/bmesh/tools/bmesh_edgenet.cc b/source/blender/bmesh/tools/bmesh_edgenet.cc index 2721728c494..f38aaa9bb3b 100644 --- a/source/blender/bmesh/tools/bmesh_edgenet.cc +++ b/source/blender/bmesh/tools/bmesh_edgenet.cc @@ -414,8 +414,7 @@ static LinkNode *bm_edgenet_path_calc_best(BMEdge *e, void BM_mesh_edgenet(BMesh *bm, const bool use_edge_tag, const bool use_new_face_tag) { - VertNetInfo *vnet_info = static_cast( - MEM_callocN(sizeof(*vnet_info) * size_t(bm->totvert), __func__)); + VertNetInfo *vnet_info = MEM_calloc_arrayN(size_t(bm->totvert), __func__); BLI_mempool *edge_queue_pool = BLI_mempool_create(sizeof(LinkNode), 0, 512, BLI_MEMPOOL_NOP); BLI_mempool *path_pool = BLI_mempool_create(sizeof(LinkNode), 0, 512, BLI_MEMPOOL_NOP); LinkNode *edge_queue = nullptr; diff --git a/source/blender/bmesh/tools/bmesh_intersect.cc b/source/blender/bmesh/tools/bmesh_intersect.cc index 2f5ead780c1..d3036f55d82 100644 --- a/source/blender/bmesh/tools/bmesh_intersect.cc +++ b/source/blender/bmesh/tools/bmesh_intersect.cc @@ -1527,8 +1527,7 @@ bool BM_mesh_intersect(BMesh *bm, user_data_wrap.test_fn = test_fn; user_data_wrap.user_data = user_data; - groups_array = static_cast( - MEM_mallocN(sizeof(*groups_array) * size_t(bm->totface), __func__)); + groups_array = MEM_malloc_arrayN(size_t(bm->totface), __func__); group_tot = BM_mesh_calc_face_groups( bm, groups_array, &group_index, bm_loop_filter_fn, nullptr, &user_data_wrap, 0, BM_EDGE); diff --git a/source/blender/bmesh/tools/bmesh_path.cc b/source/blender/bmesh/tools/bmesh_path.cc index 0732f9d2384..d4c42c5daf5 100644 --- a/source/blender/bmesh/tools/bmesh_path.cc +++ b/source/blender/bmesh/tools/bmesh_path.cc @@ -142,8 +142,8 @@ LinkNode *BM_mesh_calc_path_vert(BMesh *bm, /* Allocate. */ totvert = bm->totvert; - verts_prev = static_cast(MEM_callocN(sizeof(*verts_prev) * totvert, __func__)); - cost = static_cast(MEM_mallocN(sizeof(*cost) * totvert, __func__)); + verts_prev = MEM_calloc_arrayN(totvert, __func__); + cost = MEM_malloc_arrayN(totvert, __func__); copy_vn_fl(cost, totvert, COST_INIT_MAX); @@ -322,8 +322,8 @@ LinkNode *BM_mesh_calc_path_edge(BMesh *bm, /* Allocate. */ totedge = bm->totedge; - edges_prev = static_cast(MEM_callocN(sizeof(*edges_prev) * totedge, __func__)); - cost = static_cast(MEM_mallocN(sizeof(*cost) * totedge, __func__)); + edges_prev = MEM_calloc_arrayN(totedge, __func__); + cost = MEM_malloc_arrayN(totedge, __func__); copy_vn_fl(cost, totedge, COST_INIT_MAX); @@ -523,8 +523,8 @@ LinkNode *BM_mesh_calc_path_face(BMesh *bm, /* Allocate. */ totface = bm->totface; - faces_prev = static_cast(MEM_callocN(sizeof(*faces_prev) * totface, __func__)); - cost = static_cast(MEM_mallocN(sizeof(*cost) * totface, __func__)); + faces_prev = MEM_calloc_arrayN(totface, __func__); + cost = MEM_malloc_arrayN(totface, __func__); copy_vn_fl(cost, totface, COST_INIT_MAX); diff --git a/source/blender/bmesh/tools/bmesh_path_region.cc b/source/blender/bmesh/tools/bmesh_path_region.cc index 4b2f64ec4ac..b8b137bd41e 100644 --- a/source/blender/bmesh/tools/bmesh_path_region.cc +++ b/source/blender/bmesh/tools/bmesh_path_region.cc @@ -156,9 +156,8 @@ static LinkNode *mesh_calc_path_region_elem(BMesh *bm, int *depths[2] = {nullptr}; int pass = 0; - BMVert **stack = static_cast(MEM_mallocN(sizeof(*stack) * bm->totvert, __func__)); - BMVert **stack_other = static_cast( - MEM_mallocN(sizeof(*stack_other) * bm->totvert, __func__)); + BMVert **stack = MEM_malloc_arrayN(bm->totvert, __func__); + BMVert **stack_other = MEM_malloc_arrayN(bm->totvert, __func__); STACK_DECLARE(stack); STACK_INIT(stack, bm->totvert); diff --git a/source/blender/bmesh/tools/bmesh_path_region_uv.cc b/source/blender/bmesh/tools/bmesh_path_region_uv.cc index 2b54a504c1f..4dcb27b5195 100644 --- a/source/blender/bmesh/tools/bmesh_path_region_uv.cc +++ b/source/blender/bmesh/tools/bmesh_path_region_uv.cc @@ -160,9 +160,8 @@ static LinkNode *mesh_calc_path_region_elem(BMesh *bm, int *depths[2] = {nullptr}; int pass = 0; - BMLoop **stack = static_cast(MEM_mallocN(sizeof(*stack) * bm->totloop, __func__)); - BMLoop **stack_other = static_cast( - MEM_mallocN(sizeof(*stack_other) * bm->totloop, __func__)); + BMLoop **stack = MEM_malloc_arrayN(bm->totloop, __func__); + BMLoop **stack_other = MEM_malloc_arrayN(bm->totloop, __func__); STACK_DECLARE(stack); STACK_INIT(stack, bm->totloop); diff --git a/source/blender/bmesh/tools/bmesh_path_uv.cc b/source/blender/bmesh/tools/bmesh_path_uv.cc index 0557b8c29df..b2924579fc9 100644 --- a/source/blender/bmesh/tools/bmesh_path_uv.cc +++ b/source/blender/bmesh/tools/bmesh_path_uv.cc @@ -140,8 +140,8 @@ LinkNode *BM_mesh_calc_path_uv_vert(BMesh *bm, /* Allocate. */ totloop = bm->totloop; - loops_prev = static_cast(MEM_callocN(sizeof(*loops_prev) * totloop, __func__)); - cost = static_cast(MEM_mallocN(sizeof(*cost) * totloop, __func__)); + loops_prev = MEM_calloc_arrayN(totloop, __func__); + cost = MEM_malloc_arrayN(totloop, __func__); copy_vn_fl(cost, totloop, COST_INIT_MAX); @@ -344,8 +344,8 @@ LinkNode *BM_mesh_calc_path_uv_edge(BMesh *bm, bm->elem_index_dirty &= ~BM_LOOP; totloop = bm->totloop; - loops_prev = static_cast(MEM_callocN(sizeof(*loops_prev) * totloop, __func__)); - cost = static_cast(MEM_mallocN(sizeof(*cost) * totloop, __func__)); + loops_prev = MEM_calloc_arrayN(totloop, __func__); + cost = MEM_malloc_arrayN(totloop, __func__); copy_vn_fl(cost, totloop, COST_INIT_MAX); @@ -572,8 +572,8 @@ LinkNode *BM_mesh_calc_path_uv_face(BMesh *bm, /* Allocate. */ totface = bm->totface; - faces_prev = static_cast(MEM_callocN(sizeof(*faces_prev) * totface, __func__)); - cost = static_cast(MEM_mallocN(sizeof(*cost) * totface, __func__)); + faces_prev = MEM_calloc_arrayN(totface, __func__); + cost = MEM_malloc_arrayN(totface, __func__); copy_vn_fl(cost, totface, COST_INIT_MAX); diff --git a/source/blender/bmesh/tools/bmesh_region_match.cc b/source/blender/bmesh/tools/bmesh_region_match.cc index 9da13db47f5..fc448684751 100644 --- a/source/blender/bmesh/tools/bmesh_region_match.cc +++ b/source/blender/bmesh/tools/bmesh_region_match.cc @@ -1265,10 +1265,8 @@ static UIDFashMatch *bm_vert_fasthash_create(BMesh *bm, const uint depth) BMVert *v; BMIter iter; - id_prev = static_cast( - MEM_mallocN(sizeof(*id_prev) * uint(bm->totvert), __func__)); - id_curr = static_cast( - MEM_mallocN(sizeof(*id_curr) * uint(bm->totvert), __func__)); + id_prev = MEM_malloc_arrayN(uint(bm->totvert), __func__); + id_curr = MEM_malloc_arrayN(uint(bm->totvert), __func__); BM_ITER_MESH_INDEX (v, &iter, bm, BM_VERTS_OF_MESH, i) { id_prev[i] = bm_vert_fasthash_single(v); diff --git a/source/blender/bmesh/tools/bmesh_separate.cc b/source/blender/bmesh/tools/bmesh_separate.cc index 2bb92ee2c36..77883078342 100644 --- a/source/blender/bmesh/tools/bmesh_separate.cc +++ b/source/blender/bmesh/tools/bmesh_separate.cc @@ -20,8 +20,7 @@ void BM_mesh_separate_faces(BMesh *bm, BMFaceFilterFunc filter_fn, void *user_data) { - BMFace **faces_array_all = static_cast( - MEM_mallocN(bm->totface * sizeof(BMFace *), __func__)); + BMFace **faces_array_all = MEM_malloc_arrayN(bm->totface, __func__); /* * - Create an array of faces based on 'filter_fn'. * First part of array for match, for non-match. diff --git a/source/blender/bmesh/tools/bmesh_wireframe.cc b/source/blender/bmesh/tools/bmesh_wireframe.cc index 8edfb203f57..feb5aa29e48 100644 --- a/source/blender/bmesh/tools/bmesh_wireframe.cc +++ b/source/blender/bmesh/tools/bmesh_wireframe.cc @@ -176,12 +176,9 @@ void BM_mesh_wireframe(BMesh *bm, BMIter itersub; /* filled only with boundary verts */ - BMVert **verts_src = static_cast( - MEM_mallocN(sizeof(BMVert *) * totvert_orig, __func__)); - BMVert **verts_neg = static_cast( - MEM_mallocN(sizeof(BMVert *) * totvert_orig, __func__)); - BMVert **verts_pos = static_cast( - MEM_mallocN(sizeof(BMVert *) * totvert_orig, __func__)); + BMVert **verts_src = MEM_malloc_arrayN(totvert_orig, __func__); + BMVert **verts_neg = MEM_malloc_arrayN(totvert_orig, __func__); + BMVert **verts_pos = MEM_malloc_arrayN(totvert_orig, __func__); /* Will over-allocate, but makes for easy lookups by index to keep aligned. */ BMVert **verts_boundary = static_cast( @@ -306,7 +303,7 @@ void BM_mesh_wireframe(BMesh *bm, BM_mesh_elem_hflag_disable_all(bm, BM_VERT, BM_ELEM_TAG, false); } - verts_loop = static_cast(MEM_mallocN(sizeof(BMVert *) * verts_loop_tot, __func__)); + verts_loop = MEM_malloc_arrayN(verts_loop_tot, __func__); verts_loop_tot = 0; /* count up again */ BM_ITER_MESH (f_src, &iter, bm, BM_FACES_OF_MESH) { diff --git a/source/blender/draw/engines/eevee/eevee_lightprobe_volume.cc b/source/blender/draw/engines/eevee/eevee_lightprobe_volume.cc index 4bad092072f..c021f220289 100644 --- a/source/blender/draw/engines/eevee/eevee_lightprobe_volume.cc +++ b/source/blender/draw/engines/eevee/eevee_lightprobe_volume.cc @@ -1257,7 +1257,7 @@ void IrradianceBake::read_surfels(LightProbeGridCacheFrame *cache_frame) surfels_buf_.read(); cache_frame->surfels_len = capture_info_buf_.surfel_len; - cache_frame->surfels = MEM_malloc_arrayN(cache_frame->surfels_len, sizeof(Surfel), __func__); + cache_frame->surfels = MEM_malloc_arrayN(cache_frame->surfels_len, __func__); MutableSpan surfels_dst((Surfel *)cache_frame->surfels, cache_frame->surfels_len); Span surfels_src(surfels_buf_.data(), cache_frame->surfels_len); diff --git a/source/blender/draw/engines/overlay/overlay_mesh.hh b/source/blender/draw/engines/overlay/overlay_mesh.hh index 0ee764fe9d0..d06f5ce5426 100644 --- a/source/blender/draw/engines/overlay/overlay_mesh.hh +++ b/source/blender/draw/engines/overlay/overlay_mesh.hh @@ -1051,7 +1051,7 @@ class MeshUVs : Overlay { { const int width = resolution.x; const int height = floor(float(resolution.y) * (aspect.y / aspect.x)); - float *buffer = static_cast(MEM_mallocN(sizeof(float) * height * width, __func__)); + float *buffer = MEM_malloc_arrayN(height * width, __func__); MaskRasterHandle *handle = BKE_maskrasterize_handle_new(); BKE_maskrasterize_handle_init(handle, mask, width, height, true, true, true); diff --git a/source/blender/draw/intern/draw_cache_impl_particles.cc b/source/blender/draw/intern/draw_cache_impl_particles.cc index 64b0d8cbc3a..a8e4c56f31b 100644 --- a/source/blender/draw/intern/draw_cache_impl_particles.cc +++ b/source/blender/draw/intern/draw_cache_impl_particles.cc @@ -428,12 +428,11 @@ static void particle_calculate_uvs(ParticleSystem *psys, *r_uv = r_parent_uvs[parent_index]; } else { - *r_uv = static_cast( - MEM_callocN(sizeof(**r_uv) * num_uv_layers, "Particle UVs")); + *r_uv = MEM_calloc_arrayN(num_uv_layers, "Particle UVs"); } } else { - *r_uv = static_cast(MEM_callocN(sizeof(**r_uv) * num_uv_layers, "Particle UVs")); + *r_uv = MEM_calloc_arrayN(num_uv_layers, "Particle UVs"); } if (child_index == -1) { /* Calculate UVs for parent particles. */ @@ -472,12 +471,11 @@ static void particle_calculate_mcol(ParticleSystem *psys, *r_mcol = r_parent_mcol[parent_index]; } else { - *r_mcol = static_cast( - MEM_callocN(sizeof(**r_mcol) * num_col_layers, "Particle MCol")); + *r_mcol = MEM_calloc_arrayN(num_col_layers, "Particle MCol"); } } else { - *r_mcol = static_cast(MEM_callocN(sizeof(**r_mcol) * num_col_layers, "Particle MCol")); + *r_mcol = MEM_calloc_arrayN(num_col_layers, "Particle MCol"); } if (child_index == -1) { /* Calculate MCols for parent particles. */ @@ -937,12 +935,10 @@ static void particle_batch_cache_ensure_procedural_strand_data(PTCacheEdit *edit MEM_SAFE_FREE(cache->col_tex); MEM_SAFE_FREE(cache->col_layer_names); - cache->proc_col_buf = static_cast( - MEM_calloc_arrayN(cache->num_col_layers, sizeof(void *), "proc_col_buf")); - cache->col_tex = static_cast( - MEM_calloc_arrayN(cache->num_col_layers, sizeof(void *), "col_tex")); - cache->col_layer_names = static_cast(MEM_calloc_arrayN( - cache->num_col_layers, sizeof(*cache->col_layer_names), "col_layer_names")); + cache->proc_col_buf = MEM_calloc_arrayN(cache->num_col_layers, "proc_col_buf"); + cache->col_tex = MEM_calloc_arrayN(cache->num_col_layers, "col_tex"); + cache->col_layer_names = MEM_calloc_arrayN(cache->num_col_layers, + "col_layer_names"); /* Vertex colors */ for (int i = 0; i < cache->num_col_layers; i++) { @@ -1218,8 +1214,8 @@ static void particle_batch_cache_ensure_pos_and_seg(PTCacheEdit *edit, attr_id.ind = GPU_vertformat_attr_add(&format, "ind", GPU_COMP_I32, 1, GPU_FETCH_INT); if (psmd) { - uv_id = static_cast(MEM_mallocN(sizeof(*uv_id) * num_uv_layers, "UV attr format")); - col_id = static_cast(MEM_mallocN(sizeof(*col_id) * num_col_layers, "Col attr format")); + uv_id = MEM_malloc_arrayN(num_uv_layers, "UV attr format"); + col_id = MEM_malloc_arrayN(num_col_layers, "Col attr format"); for (int i = 0; i < num_uv_layers; i++) { diff --git a/source/blender/draw/intern/draw_cache_impl_subdivision.cc b/source/blender/draw/intern/draw_cache_impl_subdivision.cc index 0084f179510..3e7d2bfc5da 100644 --- a/source/blender/draw/intern/draw_cache_impl_subdivision.cc +++ b/source/blender/draw/intern/draw_cache_impl_subdivision.cc @@ -539,14 +539,14 @@ static bool draw_subdiv_topology_info_cb(const bke::subdiv::ForeachContext *fore *cache->edges_draw_flag, get_origindex_format(), GPU_USAGE_DYNAMIC); GPU_vertbuf_data_alloc(*cache->edges_draw_flag, cache->num_subdiv_loops); - cache->subdiv_loop_subdiv_vert_index = static_cast( - MEM_mallocN(cache->num_subdiv_loops * sizeof(int), "subdiv_loop_subdiv_vert_index")); + cache->subdiv_loop_subdiv_vert_index = MEM_malloc_arrayN(cache->num_subdiv_loops, + "subdiv_loop_subdiv_vert_index"); - cache->subdiv_loop_subdiv_edge_index = static_cast( - MEM_mallocN(cache->num_subdiv_loops * sizeof(int), "subdiv_loop_subdiv_edge_index")); + cache->subdiv_loop_subdiv_edge_index = MEM_malloc_arrayN(cache->num_subdiv_loops, + "subdiv_loop_subdiv_edge_index"); - cache->subdiv_loop_face_index = static_cast( - MEM_mallocN(cache->num_subdiv_loops * sizeof(int), "subdiv_loop_face_index")); + cache->subdiv_loop_face_index = MEM_malloc_arrayN(cache->num_subdiv_loops, + "subdiv_loop_face_index"); /* Initialize context pointers and temporary buffers. */ ctx->patch_coords = cache->patch_coords->data().data(); @@ -564,16 +564,16 @@ static bool draw_subdiv_topology_info_cb(const bke::subdiv::ForeachContext *fore CustomData_get_layer(&ctx->coarse_mesh->edge_data, CD_ORIGINDEX)); if (cache->num_subdiv_verts) { - ctx->vert_origindex_map = static_cast( - MEM_mallocN(cache->num_subdiv_verts * sizeof(int), "subdiv_vert_origindex_map")); + ctx->vert_origindex_map = MEM_malloc_arrayN(cache->num_subdiv_verts, + "subdiv_vert_origindex_map"); for (int i = 0; i < num_verts; i++) { ctx->vert_origindex_map[i] = -1; } } if (cache->num_subdiv_edges) { - ctx->edge_origindex_map = static_cast( - MEM_mallocN(cache->num_subdiv_edges * sizeof(int), "subdiv_edge_origindex_map")); + ctx->edge_origindex_map = MEM_malloc_arrayN(cache->num_subdiv_edges, + "subdiv_edge_origindex_map"); for (int i = 0; i < num_edges; i++) { ctx->edge_origindex_map[i] = -1; } @@ -1550,8 +1550,7 @@ static void draw_subdiv_cache_ensure_mat_offsets(DRWSubdivCache &cache, /* Compute per face offsets. */ int *mat_end = static_cast(MEM_dupallocN(mat_start)); - int *per_face_mat_offset = static_cast( - MEM_mallocN(sizeof(int) * mesh_eval->faces_num, "per_face_mat_offset")); + int *per_face_mat_offset = MEM_malloc_arrayN(mesh_eval->faces_num, "per_face_mat_offset"); for (int i = 0; i < mesh_eval->faces_num; i++) { const int mat_index = material_indices[i]; diff --git a/source/blender/draw/intern/draw_context.cc b/source/blender/draw/intern/draw_context.cc index c284d50e872..53cd7b92de0 100644 --- a/source/blender/draw/intern/draw_context.cc +++ b/source/blender/draw/intern/draw_context.cc @@ -390,7 +390,7 @@ template<> Mesh &DRW_object_get_data_for_drawing(const Object &object) DRWData *DRW_viewport_data_create() { - DRWData *drw_data = static_cast(MEM_callocN(sizeof(DRWData), "DRWData")); + DRWData *drw_data = MEM_callocN("DRWData"); drw_data->default_view = new blender::draw::View("DrawDefaultView"); diff --git a/source/blender/draw/intern/draw_fluid.cc b/source/blender/draw/intern/draw_fluid.cc index 98fb45b9de5..fc81a2afb92 100644 --- a/source/blender/draw/intern/draw_fluid.cc +++ b/source/blender/draw/intern/draw_fluid.cc @@ -51,8 +51,7 @@ static void create_flame_spectrum_texture(float *data) # define MAX_FIRE_ALPHA 0.06f # define FULL_ON_FIRE 100 - float *spec_pixels = (float *)MEM_mallocN(TFUNC_WIDTH * 4 * 16 * 16 * sizeof(float), - "spec_pixels"); + float *spec_pixels = MEM_malloc_arrayN(TFUNC_WIDTH * 4 * 16 * 16, "spec_pixels"); IMB_colormanagement_blackbody_temperature_to_rgb_table(data, TFUNC_WIDTH, 1500, 3000); diff --git a/source/blender/draw/intern/draw_select_buffer.cc b/source/blender/draw/intern/draw_select_buffer.cc index 889b1875a8c..ca93d1c0ab5 100644 --- a/source/blender/draw/intern/draw_select_buffer.cc +++ b/source/blender/draw/intern/draw_select_buffer.cc @@ -97,7 +97,7 @@ uint *DRW_select_buffer_read( /* Read the UI32 pixels. */ buf_len = BLI_rcti_size_x(rect) * BLI_rcti_size_y(rect); - r_buf = static_cast(MEM_mallocN(buf_len * sizeof(*r_buf), __func__)); + r_buf = MEM_malloc_arrayN(buf_len, __func__); GPUFrameBuffer *select_id_fb = DRW_engine_select_framebuffer_get(); GPU_framebuffer_bind(select_id_fb); diff --git a/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_mesh_analysis.cc b/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_mesh_analysis.cc index 9481866e187..b39e4d3906f 100644 --- a/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_mesh_analysis.cc +++ b/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_mesh_analysis.cc @@ -486,7 +486,7 @@ static void statvis_calc_sharp(const MeshRenderData &mr, MutableSpan r_sh const float minmax_irange = 1.0f / (max - min); /* Can we avoid this extra allocation? */ - float *vert_angles = (float *)MEM_mallocN(sizeof(float) * mr.verts_num, __func__); + float *vert_angles = MEM_malloc_arrayN(mr.verts_num, __func__); copy_vn_fl(vert_angles, mr.verts_num, -M_PI); if (mr.extract_type == MeshExtractType::BMesh) { diff --git a/source/blender/editors/animation/anim_filter.cc b/source/blender/editors/animation/anim_filter.cc index c65c0fa4a30..4c83ca428e5 100644 --- a/source/blender/editors/animation/anim_filter.cc +++ b/source/blender/editors/animation/anim_filter.cc @@ -243,7 +243,7 @@ static bool graphedit_get_context(bAnimContext *ac, SpaceGraph *sipo) { /* init dopesheet data if non-existent (i.e. for old files) */ if (sipo->ads == nullptr) { - sipo->ads = static_cast(MEM_callocN(sizeof(bDopeSheet), "GraphEdit DopeSheet")); + sipo->ads = MEM_callocN("GraphEdit DopeSheet"); sipo->ads->source = reinterpret_cast(ac->scene); } ac->ads = sipo->ads; @@ -291,7 +291,7 @@ static bool nlaedit_get_context(bAnimContext *ac, SpaceNla *snla) { /* init dopesheet data if non-existent (i.e. for old files) */ if (snla->ads == nullptr) { - snla->ads = static_cast(MEM_callocN(sizeof(bDopeSheet), "NlaEdit DopeSheet")); + snla->ads = MEM_callocN("NlaEdit DopeSheet"); } ac->ads = snla->ads; diff --git a/source/blender/editors/animation/anim_markers.cc b/source/blender/editors/animation/anim_markers.cc index 830df1726b2..b464b837f16 100644 --- a/source/blender/editors/animation/anim_markers.cc +++ b/source/blender/editors/animation/anim_markers.cc @@ -779,7 +779,7 @@ static wmOperatorStatus ed_marker_add_exec(bContext *C, wmOperator * /*op*/) marker->flag &= ~SELECT; } - marker = static_cast(MEM_callocN(sizeof(TimeMarker), "TimeMarker")); + marker = MEM_callocN("TimeMarker"); marker->flag = SELECT; marker->frame = frame; SNPRINTF(marker->name, "F_%02d", frame); @@ -1215,8 +1215,7 @@ static void ed_marker_duplicate_apply(bContext *C) marker->flag &= ~SELECT; /* create and set up new marker */ - TimeMarker *newmarker = static_cast( - MEM_callocN(sizeof(TimeMarker), "TimeMarker")); + TimeMarker *newmarker = MEM_callocN("TimeMarker"); newmarker->flag = SELECT; newmarker->frame = marker->frame; STRNCPY(newmarker->name, marker->name); @@ -1924,7 +1923,7 @@ static wmOperatorStatus ed_marker_camera_bind_exec(bContext *C, wmOperator *op) marker = ED_markers_find_nearest_marker(markers, scene->r.cfra); if ((marker == nullptr) || (marker->frame != scene->r.cfra)) { - marker = static_cast(MEM_callocN(sizeof(TimeMarker), "Camera TimeMarker")); + marker = MEM_callocN("Camera TimeMarker"); /* This marker's name is only displayed in the viewport statistics, animation editors use the * camera's name when bound to a marker. */ SNPRINTF(marker->name, "F_%02d", scene->r.cfra); diff --git a/source/blender/editors/animation/drivers.cc b/source/blender/editors/animation/drivers.cc index 953a1a58a4a..0da5529a95d 100644 --- a/source/blender/editors/animation/drivers.cc +++ b/source/blender/editors/animation/drivers.cc @@ -106,8 +106,7 @@ FCurve *alloc_driver_fcurve(const char rna_path[], if (!ELEM(creation_mode, DRIVER_FCURVE_LOOKUP_ONLY, DRIVER_FCURVE_EMPTY)) { /* add some new driver data */ - fcu->driver = static_cast( - MEM_callocN(sizeof(ChannelDriver), "ChannelDriver")); + fcu->driver = MEM_callocN("ChannelDriver"); /* F-Modifier or Keyframes? */ if (creation_mode == DRIVER_FCURVE_GENERATOR) { diff --git a/source/blender/editors/animation/fmodifier_ui.cc b/source/blender/editors/animation/fmodifier_ui.cc index fe1fa75c21f..a9bcbfa5e4b 100644 --- a/source/blender/editors/animation/fmodifier_ui.cc +++ b/source/blender/editors/animation/fmodifier_ui.cc @@ -337,8 +337,7 @@ static void fmodifier_panel_header(const bContext *C, Panel *panel) 0.0, 0.0, TIP_("Delete Modifier")); - FModifierDeleteContext *ctx = static_cast( - MEM_mallocN(sizeof(FModifierDeleteContext), __func__)); + FModifierDeleteContext *ctx = MEM_mallocN(__func__); ctx->owner_id = owner_id; ctx->modifiers = fmodifier_list_space_specific(C); BLI_assert(ctx->modifiers != nullptr); @@ -603,8 +602,7 @@ static void fmod_envelope_addpoint_cb(bContext *C, void *fcm_dv, void * /*arg*/) } /* add new */ - fedn = static_cast( - MEM_callocN((env->totvert + 1) * sizeof(FCM_EnvelopeData), "FCM_EnvelopeData")); + fedn = MEM_calloc_arrayN((env->totvert + 1), "FCM_EnvelopeData"); /* add the points that should occur before the point to be pasted */ if (i > 0) { @@ -626,8 +624,7 @@ static void fmod_envelope_addpoint_cb(bContext *C, void *fcm_dv, void * /*arg*/) env->totvert++; } else { - env->data = static_cast( - MEM_callocN(sizeof(FCM_EnvelopeData), "FCM_EnvelopeData")); + env->data = MEM_callocN("FCM_EnvelopeData"); *(env->data) = fed; env->totvert = 1; @@ -645,8 +642,7 @@ static void fmod_envelope_deletepoint_cb(bContext * /*C*/, void *fcm_dv, void *i /* check that no data exists for the current frame... */ if (env->totvert > 1) { /* allocate a new smaller array */ - fedn = static_cast( - MEM_callocN(sizeof(FCM_EnvelopeData) * (env->totvert - 1), "FCM_EnvelopeData")); + fedn = MEM_calloc_arrayN((env->totvert - 1), "FCM_EnvelopeData"); memcpy(fedn, env->data, sizeof(FCM_EnvelopeData) * (index)); memcpy(fedn + index, diff --git a/source/blender/editors/animation/keyframes_general.cc b/source/blender/editors/animation/keyframes_general.cc index af661ba4450..7b255d0132e 100644 --- a/source/blender/editors/animation/keyframes_general.cc +++ b/source/blender/editors/animation/keyframes_general.cc @@ -70,8 +70,7 @@ bool duplicate_fcurve_keys(FCurve *fcu) /* If a key is selected */ if (fcu->bezt[i].f2 & SELECT) { /* Expand the list */ - BezTriple *newbezt = static_cast( - MEM_callocN(sizeof(BezTriple) * (fcu->totvert + 1), "beztriple")); + BezTriple *newbezt = MEM_calloc_arrayN((fcu->totvert + 1), "beztriple"); memcpy(newbezt, fcu->bezt, sizeof(BezTriple) * (i + 1)); memcpy(newbezt + i + 1, fcu->bezt + i, sizeof(BezTriple)); @@ -294,7 +293,7 @@ ListBase find_fcurve_segments(FCurve *fcu) while (find_fcurve_segment(fcu, current_index, &segment_start_idx, &segment_len)) { FCurveSegment *segment; - segment = static_cast(MEM_callocN(sizeof(*segment), "FCurveSegment")); + segment = MEM_callocN("FCurveSegment"); segment->start_index = segment_start_idx; segment->length = segment_len; BLI_addtail(&segments, segment); diff --git a/source/blender/editors/animation/keyframes_general_test.cc b/source/blender/editors/animation/keyframes_general_test.cc index f05179fc5e1..1bb31b12633 100644 --- a/source/blender/editors/animation/keyframes_general_test.cc +++ b/source/blender/editors/animation/keyframes_general_test.cc @@ -521,7 +521,7 @@ TEST_F(keyframes_paste, pastebuf_match_path_property) bArmature *armature = BKE_armature_add(bmain, "Armature"); for (const auto &bone_name : {"hand.L", "hand.R", "middle"}) { - Bone *bone = static_cast(MEM_callocN(sizeof(Bone), __func__)); + Bone *bone = MEM_callocN(__func__); STRNCPY(bone->name, bone_name); BLI_addtail(&armature->bonebase, bone); } diff --git a/source/blender/editors/animation/keyframes_keylist_test.cc b/source/blender/editors/animation/keyframes_keylist_test.cc index 5876615f4f6..05921d3408b 100644 --- a/source/blender/editors/animation/keyframes_keylist_test.cc +++ b/source/blender/editors/animation/keyframes_keylist_test.cc @@ -42,8 +42,7 @@ const float FRAME_STEP = 0.005; static void build_fcurve(FCurve &fcurve) { fcurve.totvert = 3; - fcurve.bezt = static_cast( - MEM_callocN(sizeof(BezTriple) * fcurve.totvert, "BezTriples")); + fcurve.bezt = MEM_calloc_arrayN(fcurve.totvert, "BezTriples"); fcurve.bezt[0].vec[1][0] = 10.0f; fcurve.bezt[0].vec[1][1] = 1.0f; fcurve.bezt[1].vec[1][0] = 20.0f; diff --git a/source/blender/editors/animation/keyingsets.cc b/source/blender/editors/animation/keyingsets.cc index c9473f051b5..0d2c174eca0 100644 --- a/source/blender/editors/animation/keyingsets.cc +++ b/source/blender/editors/animation/keyingsets.cc @@ -186,8 +186,7 @@ static wmOperatorStatus add_empty_ks_path_exec(bContext *C, wmOperator *op) BLI_findlink(&scene->keyingsets, scene->active_keyingset - 1)); /* Don't use the API method for this, since that checks on values... */ - KS_Path *keyingset_path = static_cast( - MEM_callocN(sizeof(KS_Path), "KeyingSetPath Empty")); + KS_Path *keyingset_path = MEM_callocN("KeyingSetPath Empty"); BLI_addtail(&keyingset->paths, keyingset_path); keyingset->active_path = BLI_listbase_count(&keyingset->paths); diff --git a/source/blender/editors/armature/armature_add.cc b/source/blender/editors/armature/armature_add.cc index ea8afea9c88..ce48ce603b7 100644 --- a/source/blender/editors/armature/armature_add.cc +++ b/source/blender/editors/armature/armature_add.cc @@ -61,7 +61,7 @@ using blender::Vector; EditBone *ED_armature_ebone_add(bArmature *arm, const char *name) { - EditBone *bone = static_cast(MEM_callocN(sizeof(EditBone), "eBone")); + EditBone *bone = MEM_callocN("eBone"); STRNCPY(bone->name, name); ED_armature_ebone_unique_name(arm->edbo, bone->name, nullptr); @@ -1076,7 +1076,7 @@ void ED_armature_ebone_copy(EditBone *dest, const EditBone *source) EditBone *duplicateEditBoneObjects( EditBone *cur_bone, const char *name, ListBase *editbones, Object *src_ob, Object *dst_ob) { - EditBone *e_bone = static_cast(MEM_mallocN(sizeof(EditBone), "addup_editbone")); + EditBone *e_bone = MEM_mallocN("addup_editbone"); /* Copy data from old bone to new bone */ ED_armature_ebone_copy(e_bone, cur_bone); @@ -1630,7 +1630,7 @@ static wmOperatorStatus armature_extrude_exec(bContext *C, wmOperator *op) } totbone++; - newbone = static_cast(MEM_callocN(sizeof(EditBone), "extrudebone")); + newbone = MEM_callocN("extrudebone"); if (do_extrude == TIP_EXTRUDE) { copy_v3_v3(newbone->head, ebone->tail); @@ -1874,7 +1874,7 @@ static wmOperatorStatus armature_subdivide_exec(bContext *C, wmOperator *op) float val2[3]; float val3[3]; - newbone = static_cast(MEM_mallocN(sizeof(EditBone), "ebone subdiv")); + newbone = MEM_mallocN("ebone subdiv"); *newbone = *ebone; BLI_addtail(arm->edbo, newbone); diff --git a/source/blender/editors/armature/armature_skinning.cc b/source/blender/editors/armature/armature_skinning.cc index 918bcd8c7b5..be5f6e059f4 100644 --- a/source/blender/editors/armature/armature_skinning.cc +++ b/source/blender/editors/armature/armature_skinning.cc @@ -334,8 +334,8 @@ static void add_verts_to_dgroups(ReportList *reports, /* create an array of root and tip positions transformed into * global coords */ - root = static_cast(MEM_callocN(sizeof(float[3]) * numbones, "root")); - tip = static_cast(MEM_callocN(sizeof(float[3]) * numbones, "tip")); + root = MEM_calloc_arrayN(numbones, "root"); + tip = MEM_calloc_arrayN(numbones, "tip"); selected = MEM_calloc_arrayN(numbones, "selected"); for (int j = 0; j < numbones; j++) { diff --git a/source/blender/editors/armature/armature_utils.cc b/source/blender/editors/armature/armature_utils.cc index 77e99791af5..7ad22cfa1d6 100644 --- a/source/blender/editors/armature/armature_utils.cc +++ b/source/blender/editors/armature/armature_utils.cc @@ -446,7 +446,7 @@ static EditBone *make_boneList_recursive(ListBase *edbo, EditBone *eBoneTest = nullptr; LISTBASE_FOREACH (Bone *, curBone, bones) { - eBone = static_cast(MEM_callocN(sizeof(EditBone), "make_editbone")); + eBone = MEM_callocN("make_editbone"); eBone->temp.bone = curBone; /* Copy relevant data from bone to eBone @@ -677,7 +677,7 @@ void ED_armature_from_edit(Main *bmain, bArmature *arm) /* Copy the bones from the edit-data into the armature. */ LISTBASE_FOREACH (EditBone *, eBone, arm->edbo) { - newBone = static_cast(MEM_callocN(sizeof(Bone), "bone")); + newBone = MEM_callocN("bone"); eBone->temp.bone = newBone; /* Associate the real Bones with the EditBones */ STRNCPY(newBone->name, eBone->name); diff --git a/source/blender/editors/armature/editarmature_undo.cc b/source/blender/editors/armature/editarmature_undo.cc index a0a7c9fbbf8..73819f26891 100644 --- a/source/blender/editors/armature/editarmature_undo.cc +++ b/source/blender/editors/armature/editarmature_undo.cc @@ -223,8 +223,7 @@ static bool armature_undosys_step_encode(bContext *C, Main *bmain, UndoStep *us_ blender::Vector objects = ED_undo_editmode_objects_from_view_layer(scene, view_layer); us->scene_ref.ptr = scene; - us->elems = static_cast( - MEM_callocN(sizeof(*us->elems) * objects.size(), __func__)); + us->elems = MEM_calloc_arrayN(objects.size(), __func__); us->elems_len = objects.size(); for (uint i = 0; i < objects.size(); i++) { diff --git a/source/blender/editors/armature/meshlaplacian.cc b/source/blender/editors/armature/meshlaplacian.cc index 99a4f322c1b..ae37cd0d93f 100644 --- a/source/blender/editors/armature/meshlaplacian.cc +++ b/source/blender/editors/armature/meshlaplacian.cc @@ -1697,10 +1697,8 @@ static void harmonic_coordinates_bind(MeshDeformModifierData *mmd, MeshDeformBin } /* convert MDefBindInfluences to smaller MDefInfluences */ - mmd->dyngrid = static_cast( - MEM_callocN(sizeof(MDefCell) * mdb->size3, "MDefDynGrid")); - mmd->dyninfluences = static_cast( - MEM_callocN(sizeof(MDefInfluence) * mmd->influences_num, "MDefInfluence")); + mmd->dyngrid = MEM_calloc_arrayN(mdb->size3, "MDefDynGrid"); + mmd->dyninfluences = MEM_calloc_arrayN(mmd->influences_num, "MDefInfluence"); offset = 0; for (a = 0; a < mdb->size3; a++) { cell = &mmd->dyngrid[a]; diff --git a/source/blender/editors/armature/pose_transform.cc b/source/blender/editors/armature/pose_transform.cc index eacb8ac53aa..e4405e795a0 100644 --- a/source/blender/editors/armature/pose_transform.cc +++ b/source/blender/editors/armature/pose_transform.cc @@ -530,8 +530,7 @@ static wmOperatorStatus pose_visual_transform_apply_exec(bContext *C, wmOperator struct XFormArray { float matrix[4][4]; bool is_set; - } *pchan_xform_array = static_cast( - MEM_mallocN(sizeof(*pchan_xform_array) * chanbase_len, __func__)); + } *pchan_xform_array = MEM_malloc_arrayN(chanbase_len, __func__); bool changed = false; int i; diff --git a/source/blender/editors/curve/editcurve.cc b/source/blender/editors/curve/editcurve.cc index f203fdbc7e6..7ef9a1f084d 100644 --- a/source/blender/editors/curve/editcurve.cc +++ b/source/blender/editors/curve/editcurve.cc @@ -205,7 +205,7 @@ static void init_editNurb_keyIndex(EditNurb *editnurb, ListBase *origBase) * it might be replaced and freed while editcurve remain in use * (in viewport render case e.g.). Note that we could use a pool to avoid * lots of malloc's here, but... not really a problem for now. */ - BPoint *origbp_cpy = static_cast(MEM_mallocN(sizeof(*origbp_cpy), __func__)); + BPoint *origbp_cpy = MEM_mallocN(__func__); *origbp_cpy = *origbp; keyIndex = init_cvKeyIndex(origbp_cpy, key_index, nu_index, pt_index, vertex_index); BLI_ghash_insert(gh, bp, keyIndex); @@ -552,8 +552,7 @@ GHash *ED_curve_keyindex_hash_duplicate(GHash *keyindex) GHASH_ITER (gh_iter, keyindex) { void *cv = BLI_ghashIterator_getKey(&gh_iter); CVKeyIndex *index = static_cast(BLI_ghashIterator_getValue(&gh_iter)); - CVKeyIndex *newIndex = static_cast( - MEM_mallocN(sizeof(CVKeyIndex), "dupli_keyIndexHash index")); + CVKeyIndex *newIndex = MEM_mallocN("dupli_keyIndexHash index"); memcpy(newIndex, index, sizeof(CVKeyIndex)); newIndex->orig_cv = MEM_dupallocN(index->orig_cv); @@ -688,7 +687,7 @@ static void calc_shapeKeys(Object *obedit, ListBase *newnurbs) } } - ofs = static_cast(MEM_callocN(sizeof(float[3]) * totvec, "currkey->data")); + ofs = MEM_calloc_arrayN(totvec, "currkey->data"); i = 0; LISTBASE_FOREACH (Nurb *, nu, &editnurb->nurbs) { if (nu->bezt) { @@ -1168,8 +1167,7 @@ static int *init_index_map(Object *obedit, int *r_old_totvert) } } - old_to_new_map = static_cast( - MEM_mallocN(old_totvert * sizeof(int), "curve old to new index map")); + old_to_new_map = MEM_malloc_arrayN(old_totvert, "curve old to new index map"); for (int i = 0; i < old_totvert; i++) { old_to_new_map[i] = -1; } @@ -1350,7 +1348,7 @@ void ED_curve_editnurb_make(Object *obedit) BKE_curve_editNurb_keyIndex_free(&editnurb->keyindex); } else { - editnurb = static_cast(MEM_callocN(sizeof(EditNurb), "editnurb")); + editnurb = MEM_callocN("editnurb"); cu->editnurb = editnurb; } @@ -1777,7 +1775,7 @@ static void ed_surf_delete_selected(Object *obedit) if (newv != nu->pntsv) { /* delete */ bp = nu->bp; - bpn = newbp = (BPoint *)MEM_mallocN(newv * nu->pntsu * sizeof(BPoint), "deleteNurb"); + bpn = newbp = MEM_malloc_arrayN(newv * nu->pntsu, "deleteNurb"); for (b = 0; b < nu->pntsv; b++) { if ((bp->f1 & SELECT) == 0) { memcpy(bpn, bp, nu->pntsu * sizeof(BPoint)); @@ -1803,7 +1801,7 @@ static void ed_surf_delete_selected(Object *obedit) if (newu != nu->pntsu) { /* delete */ bp = nu->bp; - bpn = newbp = (BPoint *)MEM_mallocN(newu * nu->pntsv * sizeof(BPoint), "deleteNurb"); + bpn = newbp = MEM_malloc_arrayN(newu * nu->pntsv, "deleteNurb"); for (b = 0; b < nu->pntsv; b++) { for (a = 0; a < nu->pntsu; a++, bp++) { if ((bp->f1 & SELECT) == 0) { @@ -1928,7 +1926,7 @@ static void ed_curve_delete_selected(Object *obedit, View3D *v3d) } } if (type) { - bezt1 = (BezTriple *)MEM_mallocN((nu->pntsu) * sizeof(BezTriple), "delNurb"); + bezt1 = MEM_malloc_arrayN((nu->pntsu), "delNurb"); memcpy(bezt1, nu->bezt, (nu->pntsu) * sizeof(BezTriple)); keyIndex_updateBezt(editnurb, nu->bezt, bezt1, nu->pntsu); MEM_freeN(nu->bezt); @@ -1953,7 +1951,7 @@ static void ed_curve_delete_selected(Object *obedit, View3D *v3d) } } if (type) { - bp1 = (BPoint *)MEM_mallocN(nu->pntsu * sizeof(BPoint), "delNurb2"); + bp1 = MEM_malloc_arrayN(nu->pntsu, "delNurb2"); memcpy(bp1, nu->bp, (nu->pntsu) * sizeof(BPoint)); keyIndex_updateBP(editnurb, nu->bp, bp1, nu->pntsu); MEM_freeN(nu->bp); @@ -2089,10 +2087,8 @@ bool ed_editnurb_extrude_flag(EditNurb *editnurb, const uint8_t flag) const NurbDim max = editnurb_find_max_points_num(editnurb); /* One point induces at most one interval. Except single point case, it can give + 1. * Another +1 is for first element of the first interval. */ - int *const intvls_u = static_cast( - MEM_malloc_arrayN(max.pntsu + 2, sizeof(int), "extrudeNurb0")); - int *const intvls_v = static_cast( - MEM_malloc_arrayN(max.pntsv + 2, sizeof(int), "extrudeNurb1")); + int *const intvls_u = MEM_malloc_arrayN(max.pntsu + 2, "extrudeNurb0"); + int *const intvls_v = MEM_malloc_arrayN(max.pntsv + 2, "extrudeNurb1"); bool ok = false; LISTBASE_FOREACH (Nurb *, nu, &editnurb->nurbs) { @@ -2130,8 +2126,7 @@ bool ed_editnurb_extrude_flag(EditNurb *editnurb, const uint8_t flag) const int new_pntsu = nu->pntsu + intvl_cnt_u - 1; const int new_pntsv = nu->pntsv + intvl_cnt_v - 1; - BPoint *const new_bp = (BPoint *)MEM_malloc_arrayN( - new_pntsu * new_pntsv, sizeof(BPoint), "extrudeNurb2"); + BPoint *const new_bp = MEM_malloc_arrayN(new_pntsu * new_pntsv, "extrudeNurb2"); BPoint *new_bp_v = new_bp; bool selected_v = is_first_sel_v; @@ -2350,7 +2345,7 @@ static void adduplicateflagNurb( if (ED_curve_nurb_select_check(v3d, nu)) { /* A rectangular area in nurb has to be selected and if splitting * must be in U or V direction. */ - usel = static_cast(MEM_callocN(nu->pntsu, "adduplicateN3")); + usel = MEM_calloc_arrayN(nu->pntsu, "adduplicateN3"); bp = nu->bp; for (a = 0; a < nu->pntsv; a++) { for (b = 0; b < nu->pntsu; b++, bp++) { @@ -3509,7 +3504,7 @@ static void subdividenurb(Object *obedit, View3D *v3d, int number_cuts) if (amount) { /* insert */ - beztnew = (BezTriple *)MEM_mallocN((amount + nu->pntsu) * sizeof(BezTriple), "subdivNurb"); + beztnew = MEM_malloc_arrayN((amount + nu->pntsu), "subdivNurb"); beztn = beztnew; a = nu->pntsu; bezt = nu->bezt; @@ -3599,7 +3594,7 @@ static void subdividenurb(Object *obedit, View3D *v3d, int number_cuts) if (amount) { /* insert */ - bpnew = (BPoint *)MEM_mallocN((amount + nu->pntsu) * sizeof(BPoint), "subdivNurb2"); + bpnew = MEM_malloc_arrayN((amount + nu->pntsu), "subdivNurb2"); bpn = bpnew; a = nu->pntsu; @@ -3709,7 +3704,7 @@ static void subdividenurb(Object *obedit, View3D *v3d, int number_cuts) int tot = ((number_cuts + 1) * nu->pntsu - number_cuts) * ((number_cuts + 1) * nu->pntsv - number_cuts); - bpn = bpnew = static_cast(MEM_mallocN(tot * sizeof(BPoint), "subdivideNurb4")); + bpn = bpnew = MEM_malloc_arrayN(tot, "subdivideNurb4"); bp = nu->bp; /* first subdivide rows */ for (a = 0; a < nu->pntsv; a++) { @@ -3769,8 +3764,7 @@ static void subdividenurb(Object *obedit, View3D *v3d, int number_cuts) } if (sel) { /* V direction. */ - bpn = bpnew = static_cast( - MEM_mallocN((sel + nu->pntsv) * nu->pntsu * sizeof(BPoint), "subdivideNurb4")); + bpn = bpnew = MEM_malloc_arrayN((sel + nu->pntsv) * nu->pntsu, "subdivideNurb4"); bp = nu->bp; for (a = 0; a < nu->pntsv; a++) { for (b = 0; b < nu->pntsu; b++) { @@ -3819,8 +3813,8 @@ static void subdividenurb(Object *obedit, View3D *v3d, int number_cuts) if (sel) { /* U direction. */ /* Inserting U points is sort of 'default' Flat curves only get * U points inserted in them. */ - bpn = bpnew = static_cast( - MEM_mallocN((sel + nu->pntsu) * nu->pntsv * sizeof(BPoint), "subdivideNurb4")); + bpn = bpnew = MEM_malloc_arrayN((sel + nu->pntsu) * nu->pntsv, + "subdivideNurb4"); bp = nu->bp; for (a = 0; a < nu->pntsv; a++) { for (b = 0; b < nu->pntsu; b++) { @@ -4157,7 +4151,7 @@ static void switchdirection_knots(float *base, int tot) /* and make in increasing order again */ a = tot - 1; fp1 = base; - fp2 = tempf = static_cast(MEM_mallocN(sizeof(float) * tot, "switchdirect")); + fp2 = tempf = MEM_malloc_arrayN(tot, "switchdirect"); while (a--) { fp2[0] = fabsf(fp1[1] - fp1[0]); fp1++; @@ -4411,8 +4405,7 @@ static bool merge_2_nurb(Curve *cu, ListBase *editnurb, Nurb *nu1, Nurb *nu2) nu1->orderv++; } temp = nu1->bp; - nu1->bp = static_cast( - MEM_mallocN(nu1->pntsu * nu1->pntsv * sizeof(BPoint), "mergeBP")); + nu1->bp = MEM_malloc_arrayN(nu1->pntsu * nu1->pntsv, "mergeBP"); bp = nu1->bp; bp1 = temp; @@ -4688,8 +4681,7 @@ static wmOperatorStatus make_segment_exec(bContext *C, wmOperator *op) if ((nu1 && nu2) && (nu1 != nu2)) { if (nu1->type == nu2->type) { if (nu1->type == CU_BEZIER) { - BezTriple *bezt = (BezTriple *)MEM_mallocN((nu1->pntsu + nu2->pntsu) * sizeof(BezTriple), - "addsegmentN"); + BezTriple *bezt = MEM_malloc_arrayN((nu1->pntsu + nu2->pntsu), "addsegmentN"); ED_curve_beztcpy(cu->editnurb, bezt, nu2->bezt, nu2->pntsu); ED_curve_beztcpy(cu->editnurb, bezt + nu2->pntsu, nu1->bezt, nu1->pntsu); @@ -4703,7 +4695,7 @@ static wmOperatorStatus make_segment_exec(bContext *C, wmOperator *op) BKE_nurb_handles_calc(nu1); } else { - bp = (BPoint *)MEM_mallocN((nu1->pntsu + nu2->pntsu) * sizeof(BPoint), "addsegmentN2"); + bp = MEM_malloc_arrayN((nu1->pntsu + nu2->pntsu), "addsegmentN2"); ED_curve_bpcpy(cu->editnurb, bp, nu2->bp, nu2->pntsu); ED_curve_bpcpy(cu->editnurb, bp + nu2->pntsu, nu1->bp, nu1->pntsu); MEM_freeN(nu1->bp); @@ -5318,7 +5310,7 @@ static bool ed_editcurve_extrude(Curve *cu, EditNurb *editnurb, View3D *v3d) const int new_len = pnt_len + new_points; bezt_src = nu->bezt; - bezt_dst = static_cast(MEM_mallocN(new_len * sizeof(BezTriple), __func__)); + bezt_dst = MEM_malloc_arrayN(new_len, __func__); bezt_src_iter = &bezt_src[0]; bezt_dst_iter = &bezt_dst[0]; i = 0; @@ -5418,7 +5410,7 @@ static bool ed_editcurve_extrude(Curve *cu, EditNurb *editnurb, View3D *v3d) bp_prev = nullptr; } bp_src = nu->bp; - bp_dst = static_cast(MEM_mallocN(new_len * sizeof(BPoint), __func__)); + bp_dst = MEM_malloc_arrayN(new_len, __func__); bp_src_iter = &bp_src[0]; bp_dst_iter = &bp_dst[0]; i = 0; @@ -5564,8 +5556,7 @@ int ed_editcurve_addvert(Curve *cu, EditNurb *editnurb, View3D *v3d, const float Nurb *nurb_new; if (!nu) { /* Bezier as default. */ - nurb_new = static_cast( - MEM_callocN(sizeof(Nurb), "BLI_editcurve_addvert new_bezt_nurb 2")); + nurb_new = MEM_callocN("BLI_editcurve_addvert new_bezt_nurb 2"); nurb_new->type = CU_BEZIER; nurb_new->resolu = cu->resolu; nurb_new->orderu = 4; @@ -6643,7 +6634,7 @@ void ed_dissolve_bez_segment(BezTriple *bezt_prev, const int dims = 3; const int points_len = ((cu->resolu - 1) * i_span_edge_len) + 1; - float *points = static_cast(MEM_mallocN(points_len * dims * sizeof(float), __func__)); + float *points = MEM_malloc_arrayN(points_len * dims, __func__); float *points_stride = points; const int points_stride_len = (cu->resolu - 1); diff --git a/source/blender/editors/curve/editcurve_add.cc b/source/blender/editors/curve/editcurve_add.cc index bd010bf7943..48ebc19bf6b 100644 --- a/source/blender/editors/curve/editcurve_add.cc +++ b/source/blender/editors/curve/editcurve_add.cc @@ -131,7 +131,7 @@ Nurb *ED_curve_add_nurbs_primitive( /* these types call this function to return a Nurb */ if (!ELEM(stype, CU_PRIM_TUBE, CU_PRIM_DONUT)) { - nu = (Nurb *)MEM_callocN(sizeof(Nurb), "addNurbprim"); + nu = MEM_callocN("addNurbprim"); nu->type = cutype; nu->resolu = cu->resolu; nu->resolv = cu->resolv; @@ -142,7 +142,7 @@ Nurb *ED_curve_add_nurbs_primitive( nu->resolu = cu->resolu; if (cutype == CU_BEZIER) { nu->pntsu = 2; - nu->bezt = (BezTriple *)MEM_callocN(sizeof(BezTriple) * nu->pntsu, "addNurbprim1"); + nu->bezt = MEM_calloc_arrayN(nu->pntsu, "addNurbprim1"); bezt = nu->bezt; bezt->h1 = bezt->h2 = HD_ALIGN; bezt->f1 = bezt->f2 = bezt->f3 = SELECT; @@ -179,7 +179,7 @@ Nurb *ED_curve_add_nurbs_primitive( nu->pntsu = 4; nu->pntsv = 1; nu->orderu = 4; - nu->bp = (BPoint *)MEM_callocN(sizeof(BPoint) * nu->pntsu, "addNurbprim3"); + nu->bp = MEM_calloc_arrayN(nu->pntsu, "addNurbprim3"); bp = nu->bp; for (a = 0; a < 4; a++, bp++) { @@ -216,7 +216,7 @@ Nurb *ED_curve_add_nurbs_primitive( nu->orderu = 5; nu->flagu = CU_NURB_ENDPOINT; /* endpoint */ nu->resolu = cu->resolu; - nu->bp = (BPoint *)MEM_callocN(sizeof(BPoint) * nu->pntsu, "addNurbprim3"); + nu->bp = MEM_calloc_arrayN(nu->pntsu, "addNurbprim3"); bp = nu->bp; for (a = 0; a < 5; a++, bp++) { @@ -251,7 +251,7 @@ Nurb *ED_curve_add_nurbs_primitive( if (cutype == CU_BEZIER) { nu->pntsu = 4; - nu->bezt = (BezTriple *)MEM_callocN(sizeof(BezTriple) * nu->pntsu, "addNurbprim1"); + nu->bezt = MEM_calloc_arrayN(nu->pntsu, "addNurbprim1"); nu->flagu = CU_NURB_CYCLIC; bezt = nu->bezt; @@ -296,7 +296,7 @@ Nurb *ED_curve_add_nurbs_primitive( nu->pntsu = 8; nu->pntsv = 1; nu->orderu = 3; - nu->bp = (BPoint *)MEM_callocN(sizeof(BPoint) * nu->pntsu, "addNurbprim6"); + nu->bp = MEM_calloc_arrayN(nu->pntsu, "addNurbprim6"); nu->flagu = CU_NURB_CYCLIC | CU_NURB_BEZIER | CU_NURB_ENDPOINT; bp = nu->bp; @@ -333,7 +333,7 @@ Nurb *ED_curve_add_nurbs_primitive( nu->orderu = 4; nu->orderv = 4; nu->flag = CU_SMOOTH; - nu->bp = (BPoint *)MEM_callocN(sizeof(BPoint) * (4 * 4), "addNurbprim6"); + nu->bp = MEM_calloc_arrayN((4 * 4), "addNurbprim6"); nu->flagu = 0; nu->flagv = 0; bp = nu->bp; @@ -395,7 +395,7 @@ Nurb *ED_curve_add_nurbs_primitive( nu->resolu = cu->resolu; nu->resolv = cu->resolv; nu->flag = CU_SMOOTH; - nu->bp = (BPoint *)MEM_callocN(sizeof(BPoint) * nu->pntsu, "addNurbprim6"); + nu->bp = MEM_calloc_arrayN(nu->pntsu, "addNurbprim6"); nu->flagu = 0; bp = nu->bp; diff --git a/source/blender/editors/curve/editcurve_paint.cc b/source/blender/editors/curve/editcurve_paint.cc index 190bb2103a3..137a1d1fbb9 100644 --- a/source/blender/editors/curve/editcurve_paint.cc +++ b/source/blender/editors/curve/editcurve_paint.cc @@ -577,7 +577,7 @@ static bool curve_draw_init(bContext *C, wmOperator *op, bool is_invoke) { BLI_assert(op->customdata == nullptr); - CurveDrawData *cdd = static_cast(MEM_callocN(sizeof(*cdd), __func__)); + CurveDrawData *cdd = MEM_callocN(__func__); Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); if (is_invoke) { @@ -722,7 +722,7 @@ static void curve_draw_exec_precalc(wmOperator *op) BLI_mempool_iter iter; StrokeElem *selem, *selem_prev; - float *lengths = static_cast(MEM_mallocN(sizeof(float) * stroke_len, __func__)); + float *lengths = MEM_malloc_arrayN(stroke_len, __func__); StrokeElem **selem_array = static_cast( MEM_mallocN(sizeof(*selem_array) * stroke_len, __func__)); lengths[0] = 0.0f; @@ -798,7 +798,7 @@ static wmOperatorStatus curve_draw_exec(bContext *C, wmOperator *op) const float radius_max = cps->radius_max; const float radius_range = cps->radius_max - cps->radius_min; - Nurb *nu = static_cast(MEM_callocN(sizeof(Nurb), __func__)); + Nurb *nu = MEM_callocN(__func__); nu->pntsv = 0; nu->resolu = cu->resolu; nu->resolv = cu->resolv; @@ -820,8 +820,7 @@ static wmOperatorStatus curve_draw_exec(bContext *C, wmOperator *op) } coords_indices; coords_indices.radius = use_pressure_radius ? dims++ : -1; - float *coords = static_cast( - MEM_mallocN(sizeof(*coords) * stroke_len * dims, __func__)); + float *coords = MEM_malloc_arrayN(stroke_len * dims, __func__); float *cubic_spline = nullptr; uint cubic_spline_len = 0; @@ -920,7 +919,7 @@ static wmOperatorStatus curve_draw_exec(bContext *C, wmOperator *op) if (result == 0) { nu->pntsu = cubic_spline_len; - nu->bezt = static_cast(MEM_callocN(sizeof(BezTriple) * nu->pntsu, __func__)); + nu->bezt = MEM_calloc_arrayN(nu->pntsu, __func__); float *co = cubic_spline; BezTriple *bezt = nu->bezt; @@ -1016,7 +1015,7 @@ static wmOperatorStatus curve_draw_exec(bContext *C, wmOperator *op) nu->pntsu = stroke_len; nu->pntsv = 1; nu->type = CU_POLY; - nu->bp = static_cast(MEM_callocN(nu->pntsu * sizeof(BPoint), __func__)); + nu->bp = MEM_calloc_arrayN(nu->pntsu, __func__); /* Misc settings. */ nu->resolu = cu->resolu; diff --git a/source/blender/editors/curve/editcurve_pen.cc b/source/blender/editors/curve/editcurve_pen.cc index 1113da9350d..dfb783e76c5 100644 --- a/source/blender/editors/curve/editcurve_pen.cc +++ b/source/blender/editors/curve/editcurve_pen.cc @@ -601,8 +601,7 @@ static void insert_bezt_to_nurb(Nurb *nu, const CutData *data, Curve *cu) { EditNurb *editnurb = cu->editnurb; - BezTriple *new_bezt_array = (BezTriple *)MEM_mallocN((nu->pntsu + 1) * sizeof(BezTriple), - __func__); + BezTriple *new_bezt_array = MEM_malloc_arrayN((nu->pntsu + 1), __func__); const int index = data->bezt_index + 1; /* Copy all control points before the cut to the new memory. */ ED_curve_beztcpy(editnurb, new_bezt_array, nu->bezt, index); @@ -657,7 +656,7 @@ static void insert_bp_to_nurb(Nurb *nu, const CutData *data, Curve *cu) { EditNurb *editnurb = cu->editnurb; - BPoint *new_bp_array = (BPoint *)MEM_mallocN((nu->pntsu + 1) * sizeof(BPoint), __func__); + BPoint *new_bp_array = MEM_malloc_arrayN((nu->pntsu + 1), __func__); const int index = data->bp_index + 1; /* Copy all control points before the cut to the new memory. */ ED_curve_bpcpy(editnurb, new_bp_array, nu->bp, index); @@ -756,7 +755,7 @@ static void update_cut_data_for_nurb( if (nu->type == CU_BEZIER) { for (int i = 0; i < end; i++) { - float *points = static_cast(MEM_mallocN(sizeof(float[3]) * (resolu + 1), __func__)); + float *points = MEM_malloc_arrayN(3 * (resolu + 1), __func__); const BezTriple *bezt1 = nu->bezt + i; const BezTriple *bezt2 = nu->bezt + (i + 1) % nu->pntsu; @@ -945,8 +944,7 @@ static void extrude_vertices_from_selected_endpoints(EditNurb *editnurb, const bool last_sel = BEZT_ISSEL_ANY(last_bezt) && nu1->pntsu > 1; if (first_sel) { if (last_sel) { - BezTriple *new_bezt = (BezTriple *)MEM_mallocN((nu1->pntsu + 2) * sizeof(BezTriple), - __func__); + BezTriple *new_bezt = MEM_malloc_arrayN((nu1->pntsu + 2), __func__); ED_curve_beztcpy(editnurb, new_bezt, nu1->bezt, 1); ED_curve_beztcpy(editnurb, new_bezt + nu1->pntsu + 1, last_bezt, 1); BEZT_DESEL_ALL(nu1->bezt); @@ -967,8 +965,7 @@ static void extrude_vertices_from_selected_endpoints(EditNurb *editnurb, BEZT_SEL_IDX(new_bezt + (nu1->pntsu - 1), 2); } else { - BezTriple *new_bezt = (BezTriple *)MEM_mallocN((nu1->pntsu + 1) * sizeof(BezTriple), - __func__); + BezTriple *new_bezt = MEM_malloc_arrayN((nu1->pntsu + 1), __func__); ED_curve_beztcpy(editnurb, new_bezt, nu1->bezt, 1); BEZT_DESEL_ALL(nu1->bezt); ED_curve_beztcpy(editnurb, new_bezt + 1, nu1->bezt, nu1->pntsu); @@ -985,8 +982,7 @@ static void extrude_vertices_from_selected_endpoints(EditNurb *editnurb, cu->actvert = 0; } else if (last_sel) { - BezTriple *new_bezt = (BezTriple *)MEM_mallocN((nu1->pntsu + 1) * sizeof(BezTriple), - __func__); + BezTriple *new_bezt = MEM_malloc_arrayN((nu1->pntsu + 1), __func__); ED_curve_beztcpy(editnurb, new_bezt + nu1->pntsu, last_bezt, 1); BEZT_DESEL_ALL(last_bezt); ED_curve_beztcpy(editnurb, new_bezt, nu1->bezt, nu1->pntsu); @@ -1008,7 +1004,7 @@ static void extrude_vertices_from_selected_endpoints(EditNurb *editnurb, const bool last_sel = last_bp->f1 & SELECT && nu1->pntsu > 1; if (first_sel) { if (last_sel) { - BPoint *new_bp = (BPoint *)MEM_mallocN((nu1->pntsu + 2) * sizeof(BPoint), __func__); + BPoint *new_bp = MEM_malloc_arrayN((nu1->pntsu + 2), __func__); ED_curve_bpcpy(editnurb, new_bp, nu1->bp, 1); ED_curve_bpcpy(editnurb, new_bp + nu1->pntsu + 1, last_bp, 1); nu1->bp->f1 &= ~SELECT; @@ -1021,7 +1017,7 @@ static void extrude_vertices_from_selected_endpoints(EditNurb *editnurb, nu1->pntsu += 2; } else { - BPoint *new_bp = (BPoint *)MEM_mallocN((nu1->pntsu + 1) * sizeof(BPoint), __func__); + BPoint *new_bp = MEM_malloc_arrayN((nu1->pntsu + 1), __func__); ED_curve_bpcpy(editnurb, new_bp, nu1->bp, 1); nu1->bp->f1 &= ~SELECT; ED_curve_bpcpy(editnurb, new_bp + 1, nu1->bp, nu1->pntsu); @@ -1035,7 +1031,7 @@ static void extrude_vertices_from_selected_endpoints(EditNurb *editnurb, cu->actvert = 0; } else if (last_sel) { - BPoint *new_bp = (BPoint *)MEM_mallocN((nu1->pntsu + 1) * sizeof(BPoint), __func__); + BPoint *new_bp = MEM_malloc_arrayN((nu1->pntsu + 1), __func__); ED_curve_bpcpy(editnurb, new_bp, nu1->bp, nu1->pntsu); ED_curve_bpcpy(editnurb, new_bp + nu1->pntsu, last_bp, 1); last_bp->f1 &= ~SELECT; diff --git a/source/blender/editors/curve/editcurve_select.cc b/source/blender/editors/curve/editcurve_select.cc index 8a102bc0397..5e78d8a735e 100644 --- a/source/blender/editors/curve/editcurve_select.cc +++ b/source/blender/editors/curve/editcurve_select.cc @@ -1932,7 +1932,7 @@ static void curve_select_shortest_path_surf(Nurb *nu, int vert_src, int vert_dst } *data; /* init connectivity data */ - data = static_cast(MEM_mallocN(sizeof(*data) * vert_num, __func__)); + data = MEM_malloc_arrayN(vert_num, __func__); for (int i = 0; i < vert_num; i++) { data[i].vert = i; data[i].vert_prev = -1; diff --git a/source/blender/editors/curve/editcurve_undo.cc b/source/blender/editors/curve/editcurve_undo.cc index f1446a47284..107d2455b91 100644 --- a/source/blender/editors/curve/editcurve_undo.cc +++ b/source/blender/editors/curve/editcurve_undo.cc @@ -217,8 +217,7 @@ static bool curve_undosys_step_encode(bContext *C, Main *bmain, UndoStep *us_p) blender::Vector objects = ED_undo_editmode_objects_from_view_layer(scene, view_layer); us->scene_ref.ptr = scene; - us->elems = static_cast( - MEM_callocN(sizeof(*us->elems) * objects.size(), __func__)); + us->elems = MEM_calloc_arrayN(objects.size(), __func__); us->elems_len = objects.size(); for (uint i = 0; i < objects.size(); i++) { diff --git a/source/blender/editors/curve/editfont.cc b/source/blender/editors/curve/editfont.cc index 29b2f40079f..90e017016e7 100644 --- a/source/blender/editors/curve/editfont.cc +++ b/source/blender/editors/curve/editfont.cc @@ -535,7 +535,7 @@ static bool font_paste_utf8(bContext *C, const char *str, const size_t str_len) int tmplen; - char32_t *mem = static_cast(MEM_mallocN((sizeof(*mem) * (str_len + 1)), __func__)); + char32_t *mem = MEM_malloc_arrayN(str_len + 1, __func__); tmplen = BLI_str_utf8_as_utf32(mem, str, str_len + 1); @@ -564,7 +564,7 @@ static char *font_select_to_buffer(Object *obedit) const size_t text_buf_len = selend - selstart; const size_t len_utf8 = BLI_str_utf32_as_utf8_len_ex(text_buf, text_buf_len + 1); - char *buf = static_cast(MEM_mallocN(len_utf8 + 1, __func__)); + char *buf = MEM_malloc_arrayN(len_utf8 + 1, __func__); BLI_str_utf32_as_utf8(buf, text_buf, len_utf8); return buf; } @@ -771,7 +771,7 @@ static wmOperatorStatus text_insert_unicode_invoke(bContext *C, wmOperator * /*op*/, const wmEvent * /*event*/) { - char *edit_string = static_cast(MEM_mallocN(24, __func__)); + char *edit_string = MEM_malloc_arrayN(24, __func__); edit_string[0] = 0; UI_popup_block_invoke_ex(C, wm_block_insert_unicode_create, edit_string, MEM_freeN, false); return OPERATOR_FINISHED; @@ -845,8 +845,8 @@ static void txt_add_object(bContext *C, MEM_freeN(cu->strinfo); } - cu->str = static_cast(MEM_mallocN(nbytes + 4, "str")); - cu->strinfo = static_cast(MEM_callocN((nchars + 4) * sizeof(CharInfo), "strinfo")); + cu->str = MEM_malloc_arrayN(nbytes + 4, "str"); + cu->strinfo = MEM_calloc_arrayN((nchars + 4), "strinfo"); cu->len = 0; cu->len_char32 = nchars - 1; @@ -1095,7 +1095,7 @@ static void copy_selection(Object *obedit) BKE_vfont_clipboard_get(&text_buf, nullptr, &len_utf8, nullptr); /* system clipboard */ - buf = static_cast(MEM_mallocN(len_utf8 + 1, __func__)); + buf = MEM_malloc_arrayN(len_utf8 + 1, __func__); if (buf) { BLI_str_utf32_as_utf8(buf, text_buf, len_utf8 + 1); WM_clipboard_text_set(buf, false); @@ -1211,7 +1211,7 @@ static wmOperatorStatus paste_text_exec(bContext *C, wmOperator *op) BKE_vfont_clipboard_get(&text_buf, nullptr, &len_utf8, nullptr); if (text_buf) { - clipboard_vfont.buf = static_cast(MEM_mallocN(len_utf8 + 1, __func__)); + clipboard_vfont.buf = MEM_malloc_arrayN(len_utf8 + 1, __func__); if (clipboard_vfont.buf == nullptr) { MEM_freeN(clipboard_system.buf); @@ -1879,8 +1879,7 @@ static wmOperatorStatus insert_text_exec(bContext *C, wmOperator *op) inserted_utf8 = RNA_string_get_alloc(op->ptr, "text", nullptr, 0, nullptr); len = BLI_strlen_utf8(inserted_utf8); - inserted_text = static_cast( - MEM_callocN(sizeof(char32_t) * (len + 1), "FONT_insert_text")); + inserted_text = MEM_calloc_arrayN((len + 1), "FONT_insert_text"); len = BLI_str_utf8_as_utf32(inserted_text, inserted_utf8, MAXTEXT); for (a = 0; a < len; a++) { @@ -2254,12 +2253,11 @@ void ED_curve_editfont_make(Object *obedit) int len_char32; if (ef == nullptr) { - ef = cu->editfont = static_cast(MEM_callocN(sizeof(EditFont), "editfont")); + ef = cu->editfont = MEM_callocN("editfont"); ef->textbuf = static_cast( MEM_callocN((MAXTEXT + 4) * sizeof(*ef->textbuf), "texteditbuf")); - ef->textbufinfo = static_cast( - MEM_callocN((MAXTEXT + 4) * sizeof(CharInfo), "texteditbufinfo")); + ef->textbufinfo = MEM_calloc_arrayN((MAXTEXT + 4), "texteditbufinfo"); } /* Convert the original text to chat32_t. */ @@ -2299,7 +2297,7 @@ void ED_curve_editfont_load(Object *obedit) cu->len = BLI_str_utf32_as_utf8_len(ef->textbuf); /* Alloc memory for UTF-8 variable char length string */ - cu->str = static_cast(MEM_mallocN(cu->len + sizeof(char32_t), "str")); + cu->str = MEM_malloc_arrayN(cu->len + sizeof(char32_t), "str"); /* Copy the wchar to UTF-8 */ BLI_str_utf32_as_utf8(cu->str, ef->textbuf, cu->len + 1); @@ -2307,8 +2305,7 @@ void ED_curve_editfont_load(Object *obedit) if (cu->strinfo) { MEM_freeN(cu->strinfo); } - cu->strinfo = static_cast( - MEM_callocN((cu->len_char32 + 4) * sizeof(CharInfo), "texteditinfo")); + cu->strinfo = MEM_calloc_arrayN((cu->len_char32 + 4), "texteditinfo"); memcpy(cu->strinfo, ef->textbufinfo, cu->len_char32 * sizeof(CharInfo)); /* Other vars */ diff --git a/source/blender/editors/curves/intern/curves_data.cc b/source/blender/editors/curves/intern/curves_data.cc index 830fff4ca03..643e2b25dda 100644 --- a/source/blender/editors/curves/intern/curves_data.cc +++ b/source/blender/editors/curves/intern/curves_data.cc @@ -56,7 +56,7 @@ void transverts_from_curves_positions_create(bke::CurvesGeometry &curves, return; } - tvs->transverts = static_cast(MEM_calloc_arrayN(size, sizeof(TransVert), __func__)); + tvs->transverts = MEM_calloc_arrayN(size, __func__); tvs->transverts_tot = size; int offset = 0; @@ -78,7 +78,7 @@ float (*point_normals_array_create(const Curves *curves_id))[3] using namespace blender; const bke::CurvesGeometry &curves = curves_id->geometry.wrap(); const int size = curves.points_num(); - float3 *data = static_cast(MEM_malloc_arrayN(size, sizeof(float3), __func__)); + float3 *data = MEM_malloc_arrayN(size, __func__); bke::curves_normals_point_domain_calc(curves, {data, size}); return reinterpret_cast(data); } diff --git a/source/blender/editors/curves/intern/curves_draw.cc b/source/blender/editors/curves/intern/curves_draw.cc index 1d78702246d..72faa22e4f3 100644 --- a/source/blender/editors/curves/intern/curves_draw.cc +++ b/source/blender/editors/curves/intern/curves_draw.cc @@ -582,7 +582,7 @@ static bool curve_draw_init(bContext *C, wmOperator *op, bool is_invoke) { BLI_assert(op->customdata == nullptr); - CurveDrawData *cdd = static_cast(MEM_callocN(sizeof(*cdd), __func__)); + CurveDrawData *cdd = MEM_callocN(__func__); Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C); @@ -785,8 +785,7 @@ static wmOperatorStatus curves_draw_exec(bContext *C, wmOperator *op) int dims = 3; const int radius_index = use_pressure_radius ? dims++ : -1; - float *coords = static_cast( - MEM_mallocN(sizeof(*coords) * stroke_len * dims, __func__)); + float *coords = MEM_malloc_arrayN(stroke_len * dims, __func__); float *cubic_spline = nullptr; uint cubic_spline_len = 0; @@ -1228,7 +1227,7 @@ static void curve_draw_exec_precalc(wmOperator *op) BLI_mempool_iter iter; StrokeElem *selem, *selem_prev; - float *lengths = static_cast(MEM_mallocN(sizeof(float) * stroke_len, __func__)); + float *lengths = MEM_malloc_arrayN(stroke_len, __func__); StrokeElem **selem_array = static_cast( MEM_mallocN(sizeof(*selem_array) * stroke_len, __func__)); lengths[0] = 0.0f; diff --git a/source/blender/editors/curves/intern/curves_ops.cc b/source/blender/editors/curves/intern/curves_ops.cc index 2d8d5d7fcde..713c16627ec 100644 --- a/source/blender/editors/curves/intern/curves_ops.cc +++ b/source/blender/editors/curves/intern/curves_ops.cc @@ -311,9 +311,8 @@ static void try_convert_single_object(Object &curves_ob, settings.totpart = 0; psys_changed_type(&surface_ob, particle_system); - MutableSpan particles{ - static_cast(MEM_calloc_arrayN(hair_num, sizeof(ParticleData), __func__)), - hair_num}; + MutableSpan particles{MEM_calloc_arrayN(hair_num, __func__), + hair_num}; /* The old hair system still uses #MFace, so make sure those are available on the mesh. */ BKE_mesh_tessface_calc(&surface_me); @@ -357,8 +356,7 @@ static void try_convert_single_object(Object &curves_ob, ParticleData &particle = particles[new_hair_i]; const int num_keys = points.size(); - MutableSpan hair_keys{ - static_cast(MEM_calloc_arrayN(num_keys, sizeof(HairKey), __func__)), num_keys}; + MutableSpan hair_keys{MEM_calloc_arrayN(num_keys, __func__), num_keys}; particle.hair = hair_keys.data(); particle.totkey = hair_keys.size(); diff --git a/source/blender/editors/gizmo_library/gizmo_types/button2d_gizmo.cc b/source/blender/editors/gizmo_library/gizmo_types/button2d_gizmo.cc index ca2d80d0d20..dd4890fef56 100644 --- a/source/blender/editors/gizmo_library/gizmo_types/button2d_gizmo.cc +++ b/source/blender/editors/gizmo_library/gizmo_types/button2d_gizmo.cc @@ -152,7 +152,7 @@ static void button2d_draw_intern(const bContext *C, else if (RNA_property_is_set(gz->ptr, shape_prop)) { const uint polys_len = RNA_property_string_length(gz->ptr, shape_prop); /* We shouldn't need the +1, but a null char is set. */ - char *polys = static_cast(MEM_mallocN(polys_len + 1, __func__)); + char *polys = MEM_malloc_arrayN(polys_len + 1, __func__); RNA_property_string_get(gz->ptr, shape_prop, polys); button->shape_batch[0] = GPU_batch_tris_from_poly_2d_encoded( (uchar *)polys, polys_len, nullptr); diff --git a/source/blender/editors/gpencil_legacy/annotate_paint.cc b/source/blender/editors/gpencil_legacy/annotate_paint.cc index fa31190369b..88bd05e623f 100644 --- a/source/blender/editors/gpencil_legacy/annotate_paint.cc +++ b/source/blender/editors/gpencil_legacy/annotate_paint.cc @@ -712,8 +712,7 @@ static void annotation_stroke_arrow_allocate(bGPDstroke *gps, const int totpoint /* Copy appropriate settings for stroke. */ gps->totpoints = totpoints; /* Allocate enough memory for a continuous array for storage points. */ - gps->points = static_cast( - MEM_callocN(sizeof(bGPDspoint) * gps->totpoints, "annotation_stroke_points")); + gps->points = MEM_calloc_arrayN(gps->totpoints, "annotation_stroke_points"); } static void annotation_arrow_create_open(tGPsdata *p, @@ -843,7 +842,7 @@ static void annotation_stroke_newfrombuffer(tGPsdata *p) } /* allocate memory for a new stroke */ - gps = static_cast(MEM_callocN(sizeof(bGPDstroke), "annotation_stroke")); + gps = MEM_callocN("annotation_stroke"); /* copy appropriate settings for stroke */ gps->totpoints = totelem; @@ -857,8 +856,7 @@ static void annotation_stroke_newfrombuffer(tGPsdata *p) gps->tot_triangles = 0; /* allocate enough memory for a continuous array for storage points */ - gps->points = static_cast( - MEM_callocN(sizeof(bGPDspoint) * gps->totpoints, "annotation_stroke_points")); + gps->points = MEM_calloc_arrayN(gps->totpoints, "annotation_stroke_points"); gps->tot_triangles = 0; /* set pointer to first non-initialized point */ @@ -966,8 +964,7 @@ static void annotation_stroke_newfrombuffer(tGPsdata *p) int interp_depth = 0; int found_depth = 0; - depth_arr = static_cast( - MEM_mallocN(sizeof(float) * gpd->runtime.sbuffer_used, "depth_points")); + depth_arr = MEM_malloc_arrayN(gpd->runtime.sbuffer_used, "depth_points"); const ViewDepths *depths = p->depths; for (i = 0, ptc = static_cast(gpd->runtime.sbuffer); diff --git a/source/blender/editors/gpencil_legacy/editaction_gpencil.cc b/source/blender/editors/gpencil_legacy/editaction_gpencil.cc index a9202dfe7b0..0321461dd4f 100644 --- a/source/blender/editors/gpencil_legacy/editaction_gpencil.cc +++ b/source/blender/editors/gpencil_legacy/editaction_gpencil.cc @@ -354,8 +354,7 @@ bool ED_gpencil_anim_copybuf_copy(bAnimContext *ac) /* create a new layer in buffer if there were keyframes here */ if (BLI_listbase_is_empty(&copied_frames) == false) { - bGPDlayer *new_layer = static_cast( - MEM_callocN(sizeof(bGPDlayer), "GPCopyPasteLayer")); + bGPDlayer *new_layer = MEM_callocN("GPCopyPasteLayer"); BLI_addtail(&gpencil_anim_copybuf, new_layer); /* move over copied frames */ diff --git a/source/blender/editors/interface/interface_align.cc b/source/blender/editors/interface/interface_align.cc index d221efeb901..6bfa2fd2093 100644 --- a/source/blender/editors/interface/interface_align.cc +++ b/source/blender/editors/interface/interface_align.cc @@ -404,8 +404,7 @@ void ui_block_align_calc(uiBlock *block, const ARegion *region) butal_array = butal_array_buf; } else { - butal_array = static_cast( - MEM_mallocN(sizeof(*butal_array) * num_buttons, __func__)); + butal_array = MEM_malloc_arrayN(num_buttons, __func__); } memset(butal_array, 0, sizeof(*butal_array) * size_t(num_buttons)); diff --git a/source/blender/editors/interface/interface_handlers.cc b/source/blender/editors/interface/interface_handlers.cc index 4e6454a5624..d9d5c604777 100644 --- a/source/blender/editors/interface/interface_handlers.cc +++ b/source/blender/editors/interface/interface_handlers.cc @@ -3077,7 +3077,7 @@ void ui_but_active_string_clear_and_exit(bContext *C, uiBut *but) /* most likely nullptr, but let's check, and give it temp zero string */ if (!but->active->text_edit.edit_string) { - but->active->text_edit.edit_string = static_cast(MEM_callocN(1, "temp str")); + but->active->text_edit.edit_string = MEM_calloc_arrayN(1, "temp str"); } but->active->text_edit.edit_string[0] = 0; @@ -3419,8 +3419,7 @@ static bool ui_textedit_copypaste(uiBut *but, uiTextEdit &text_edit, const int m else if (ELEM(mode, UI_TEXTEDIT_COPY, UI_TEXTEDIT_CUT)) { /* copy the contents to the copypaste buffer */ const int sellen = but->selend - but->selsta; - char *buf = static_cast( - MEM_mallocN(sizeof(char) * (sellen + 1), "ui_textedit_copypaste")); + char *buf = MEM_malloc_arrayN((sellen + 1), "ui_textedit_copypaste"); memcpy(buf, text_edit.edit_string + but->selsta, sellen); buf[sellen] = '\0'; @@ -10048,8 +10047,7 @@ static int ui_handle_list_event(bContext *C, const wmEvent *event, ARegion *regi if (dyn_data->items_filter_neworder || dyn_data->items_filter_flags) { /* If we have a display order different from * collection order, we have some work! */ - int *org_order = static_cast( - MEM_mallocN(dyn_data->items_shown * sizeof(int), __func__)); + int *org_order = MEM_malloc_arrayN(dyn_data->items_shown, __func__); const int *new_order = dyn_data->items_filter_neworder; int org_idx = -1, len = dyn_data->items_len; int current_idx = -1; @@ -12523,8 +12521,7 @@ static uiBlockInteraction_Handle *ui_block_interaction_begin(bContext *C, } } - int *unique_retval_ids = static_cast( - MEM_mallocN(sizeof(*unique_retval_ids) * unique_retval_ids_len, __func__)); + int *unique_retval_ids = MEM_malloc_arrayN(unique_retval_ids_len, __func__); unique_retval_ids_len = 0; for (const std::unique_ptr &but : block->buttons) { if (but->active || (but->flag & UI_BUT_DRAG_MULTI)) { diff --git a/source/blender/editors/interface/interface_icons.cc b/source/blender/editors/interface/interface_icons.cc index 6351330ebcb..0b3b63d399b 100644 --- a/source/blender/editors/interface/interface_icons.cc +++ b/source/blender/editors/interface/interface_icons.cc @@ -155,7 +155,7 @@ static DrawInfo *def_internal_icon( if (bbuf) { int y, imgsize; - iimg->rect = static_cast(MEM_mallocN(size * size * sizeof(uint), __func__)); + iimg->rect = MEM_malloc_arrayN(size * size * sizeof(uint), __func__); /* Here we store the rect in the icon - same as before */ if (size == bbuf->x && size == bbuf->y && xofs == 0 && yofs == 0) { @@ -1262,7 +1262,7 @@ void ui_icon_ensure_deferred(const bContext *C, const int icon_id, const bool bi img->w = STUDIOLIGHT_ICON_SIZE; img->h = STUDIOLIGHT_ICON_SIZE; const size_t size = STUDIOLIGHT_ICON_SIZE * STUDIOLIGHT_ICON_SIZE * sizeof(uint); - img->rect = static_cast(MEM_mallocN(size, __func__)); + img->rect = MEM_malloc_arrayN(size, __func__); memset(img->rect, 0, size); di->data.buffer.image = img; diff --git a/source/blender/editors/interface/interface_panel.cc b/source/blender/editors/interface/interface_panel.cc index 03c3e7f7927..4575929f3cb 100644 --- a/source/blender/editors/interface/interface_panel.cc +++ b/source/blender/editors/interface/interface_panel.cc @@ -1723,8 +1723,7 @@ static bool uiAlignPanelStep(ARegion *region, const float factor, const bool dra } /* Sort panels. */ - PanelSort *panel_sort = static_cast( - MEM_mallocN(sizeof(PanelSort) * active_panels_len, __func__)); + PanelSort *panel_sort = MEM_malloc_arrayN(active_panels_len, __func__); { PanelSort *ps = panel_sort; LISTBASE_FOREACH (Panel *, panel, ®ion->panels) { diff --git a/source/blender/editors/interface/templates/interface_template_list.cc b/source/blender/editors/interface/templates/interface_template_list.cc index b2359ed5992..57e7492a47e 100644 --- a/source/blender/editors/interface/templates/interface_template_list.cc +++ b/source/blender/editors/interface/templates/interface_template_list.cc @@ -163,8 +163,7 @@ uiListNameFilter::uiListNameFilter(uiList &list) filter_ = storage_.filter_buff; } else { - filter_ = storage_.filter_dyn = static_cast( - MEM_mallocN((slen + 3) * sizeof(char), "filter_dyn")); + filter_ = storage_.filter_dyn = MEM_malloc_arrayN((slen + 3), "filter_dyn"); } BLI_strncpy_ensure_pad(filter_, filter_raw, '*', slen + 3); } @@ -294,8 +293,7 @@ void UI_list_filter_and_sort_items(uiList *ui_list, */ qsort(names, order_idx, sizeof(StringCmp), cmpstringp); - dyn_data->items_filter_neworder = static_cast( - MEM_mallocN(sizeof(int) * order_idx, "items_filter_neworder")); + dyn_data->items_filter_neworder = MEM_malloc_arrayN(order_idx, "items_filter_neworder"); for (new_idx = 0; new_idx < order_idx; new_idx++) { dyn_data->items_filter_neworder[names[new_idx].org_idx] = new_idx; } @@ -674,7 +672,7 @@ static uiList *ui_list_ensure(const bContext *C, BLI_findstring(®ion->ui_lists, full_list_id, offsetof(uiList, list_id))); if (!ui_list) { - ui_list = static_cast(MEM_callocN(sizeof(uiList), "uiList")); + ui_list = MEM_callocN("uiList"); STRNCPY(ui_list->list_id, full_list_id); BLI_addtail(®ion->ui_lists, ui_list); ui_list->list_grip = -UI_LIST_AUTO_SIZE_THRESHOLD; /* Force auto size by default. */ @@ -687,8 +685,7 @@ static uiList *ui_list_ensure(const bContext *C, } if (!ui_list->dyn_data) { - ui_list->dyn_data = static_cast( - MEM_callocN(sizeof(uiListDyn), "uiList.dyn_data")); + ui_list->dyn_data = MEM_callocN("uiList.dyn_data"); } uiListDyn *dyn_data = ui_list->dyn_data; /* Note that this isn't a `uiListType` callback, it's stored in the runtime list data. Otherwise diff --git a/source/blender/editors/lattice/editlattice_select.cc b/source/blender/editors/lattice/editlattice_select.cc index 8a5e443c6ac..03897d11baf 100644 --- a/source/blender/editors/lattice/editlattice_select.cc +++ b/source/blender/editors/lattice/editlattice_select.cc @@ -111,7 +111,7 @@ static wmOperatorStatus lattice_select_random_exec(bContext *C, wmOperator *op) int a = lt->pntsu * lt->pntsv * lt->pntsw; int elem_map_len = 0; - BPoint **elem_map = static_cast(MEM_mallocN(sizeof(*elem_map) * a, __func__)); + BPoint **elem_map = MEM_malloc_arrayN(a, __func__); BPoint *bp = lt->def; while (a--) { diff --git a/source/blender/editors/lattice/editlattice_undo.cc b/source/blender/editors/lattice/editlattice_undo.cc index 2718ca36d2d..0f2c889a0cb 100644 --- a/source/blender/editors/lattice/editlattice_undo.cc +++ b/source/blender/editors/lattice/editlattice_undo.cc @@ -72,8 +72,7 @@ static void undolatt_to_editlatt(UndoLattice *ult, EditLatt *editlatt) * relations to #MDeformWeight might have changed. */ if (editlatt->latt->dvert && ult->dvert) { BKE_defvert_array_free(editlatt->latt->dvert, len_dst); - editlatt->latt->dvert = static_cast( - MEM_mallocN(sizeof(MDeformVert) * len_src, "Lattice MDeformVert")); + editlatt->latt->dvert = MEM_malloc_arrayN(len_src, "Lattice MDeformVert"); BKE_defvert_array_copy(editlatt->latt->dvert, ult->dvert, len_src); } @@ -117,8 +116,7 @@ static void *undolatt_from_editlatt(UndoLattice *ult, EditLatt *editlatt) if (editlatt->latt->dvert) { const int tot = ult->pntsu * ult->pntsv * ult->pntsw; - ult->dvert = static_cast( - MEM_mallocN(sizeof(MDeformVert) * tot, "Undo Lattice MDeformVert")); + ult->dvert = MEM_malloc_arrayN(tot, "Undo Lattice MDeformVert"); BKE_defvert_array_copy(ult->dvert, editlatt->latt->dvert, tot); ult->undo_size += sizeof(*ult->dvert) * tot; } @@ -203,8 +201,7 @@ static bool lattice_undosys_step_encode(bContext *C, Main *bmain, UndoStep *us_p blender::Vector objects = ED_undo_editmode_objects_from_view_layer(scene, view_layer); us->scene_ref.ptr = scene; - us->elems = static_cast( - MEM_callocN(sizeof(*us->elems) * objects.size(), __func__)); + us->elems = MEM_calloc_arrayN(objects.size(), __func__); us->elems_len = objects.size(); for (uint i = 0; i < objects.size(); i++) { diff --git a/source/blender/editors/mesh/editmesh_bisect.cc b/source/blender/editors/mesh/editmesh_bisect.cc index 94cf8c63eae..e2e279b8e6c 100644 --- a/source/blender/editors/mesh/editmesh_bisect.cc +++ b/source/blender/editors/mesh/editmesh_bisect.cc @@ -151,7 +151,7 @@ static wmOperatorStatus mesh_bisect_invoke(bContext *C, wmOperator *op, const wm wmGesture *gesture = static_cast(op->customdata); BisectData *opdata; - opdata = static_cast(MEM_mallocN(sizeof(BisectData), "inset_operator_data")); + opdata = MEM_mallocN("inset_operator_data"); gesture->user_data.data = opdata; opdata->backup_len = objects.size(); diff --git a/source/blender/editors/mesh/editmesh_extrude_spin_gizmo.cc b/source/blender/editors/mesh/editmesh_extrude_spin_gizmo.cc index 0a91cf31017..562048ca0f3 100644 --- a/source/blender/editors/mesh/editmesh_extrude_spin_gizmo.cc +++ b/source/blender/editors/mesh/editmesh_extrude_spin_gizmo.cc @@ -107,8 +107,7 @@ static void gizmo_mesh_spin_init_setup(const bContext * /*C*/, wmGizmoGroup *gzg const float scale_base = INIT_SCALE_BASE; const float scale_button = INIT_SCALE_BUTTON; - GizmoGroupData_SpinInit *ggd = static_cast( - MEM_callocN(sizeof(*ggd), __func__)); + GizmoGroupData_SpinInit *ggd = MEM_callocN(__func__); gzgroup->customdata = ggd; const wmGizmoType *gzt_dial = WM_gizmotype_find("GIZMO_GT_dial_3d", true); const wmGizmoType *gzt_button = WM_gizmotype_find("GIZMO_GT_button_2d", true); @@ -814,8 +813,7 @@ static void gizmo_mesh_spin_redo_setup(const bContext *C, wmGizmoGroup *gzgroup) return; } - GizmoGroupData_SpinRedo *ggd = static_cast( - MEM_callocN(sizeof(*ggd), __func__)); + GizmoGroupData_SpinRedo *ggd = MEM_callocN(__func__); gzgroup->customdata = ggd; const wmGizmoType *gzt_arrow = WM_gizmotype_find("GIZMO_GT_arrow_3d", true); diff --git a/source/blender/editors/mesh/editmesh_inset.cc b/source/blender/editors/mesh/editmesh_inset.cc index bf9a0f48b87..b9633825314 100644 --- a/source/blender/editors/mesh/editmesh_inset.cc +++ b/source/blender/editors/mesh/editmesh_inset.cc @@ -122,8 +122,7 @@ static bool edbm_inset_init(bContext *C, wmOperator *op, const bool is_modal) RNA_float_set(op->ptr, "depth", 0.0f); } - op->customdata = opdata = static_cast( - MEM_mallocN(sizeof(InsetData), "inset_operator_data")); + op->customdata = opdata = MEM_mallocN("inset_operator_data"); uint objects_used_len = 0; diff --git a/source/blender/editors/mesh/editmesh_rip.cc b/source/blender/editors/mesh/editmesh_rip.cc index efbdf8e2af2..b8bcfb982a0 100644 --- a/source/blender/editors/mesh/editmesh_rip.cc +++ b/source/blender/editors/mesh/editmesh_rip.cc @@ -418,8 +418,7 @@ static UnorderedLoopPair *edbm_tagged_loop_pairs_to_fill(BMesh *bm) } if (total_tag) { - UnorderedLoopPair *uloop_pairs = static_cast( - MEM_mallocN(total_tag * sizeof(UnorderedLoopPair), __func__)); + UnorderedLoopPair *uloop_pairs = MEM_malloc_arrayN(total_tag, __func__); UnorderedLoopPair *ulp = uloop_pairs; BM_ITER_MESH (e, &iter, bm, BM_EDGES_OF_MESH) { diff --git a/source/blender/editors/mesh/editmesh_select.cc b/source/blender/editors/mesh/editmesh_select.cc index e2567cb85cb..ca68a83ca3d 100644 --- a/source/blender/editors/mesh/editmesh_select.cc +++ b/source/blender/editors/mesh/editmesh_select.cc @@ -1371,8 +1371,7 @@ static wmOperatorStatus edbm_select_similar_region_exec(bContext *C, wmOperator return OPERATOR_CANCELLED; } - int *groups_array = static_cast( - MEM_mallocN(sizeof(*groups_array) * bm->totfacesel, __func__)); + int *groups_array = MEM_malloc_arrayN(bm->totfacesel, __func__); group_tot = BM_mesh_calc_face_groups( bm, groups_array, &group_index, nullptr, nullptr, nullptr, BM_ELEM_SELECT, BM_VERT); @@ -1385,7 +1384,7 @@ static wmOperatorStatus edbm_select_similar_region_exec(bContext *C, wmOperator const int fg_sta = group_index[i][0]; const int fg_len = group_index[i][1]; int j; - BMFace **fg = static_cast(MEM_mallocN(sizeof(*fg) * fg_len, __func__)); + BMFace **fg = MEM_malloc_arrayN(fg_len, __func__); for (j = 0; j < fg_len; j++) { fg[j] = BM_face_at_index(bm, groups_array[fg_sta + j]); @@ -1646,8 +1645,7 @@ static wmOperatorStatus edbm_loop_multiselect_exec(bContext *C, wmOperator *op) } } - BMEdge **edarray = static_cast( - MEM_mallocN(sizeof(BMEdge *) * totedgesel, "edge array")); + BMEdge **edarray = MEM_malloc_arrayN(totedgesel, "edge array"); edindex = 0; BM_ITER_MESH (eed, &iter, em->bm, BM_EDGES_OF_MESH) { @@ -2981,8 +2979,7 @@ bool EDBM_select_interior_faces(BMEditMesh *em) BMIter iter; bool changed = false; - float *edge_lengths = static_cast( - MEM_mallocN(sizeof(*edge_lengths) * bm->totedge, __func__)); + float *edge_lengths = MEM_malloc_arrayN(bm->totedge, __func__); { bool has_nonmanifold = false; @@ -3014,13 +3011,11 @@ bool EDBM_select_interior_faces(BMEditMesh *em) int(*fgroup_index)[2]; int fgroup_len; - int *fgroup_array = static_cast( - MEM_mallocN(sizeof(*fgroup_array) * bm->totface, __func__)); + int *fgroup_array = MEM_malloc_arrayN(bm->totface, __func__); fgroup_len = BM_mesh_calc_face_groups( bm, fgroup_array, &fgroup_index, bm_interior_loop_filter_fn, nullptr, nullptr, 0, BM_EDGE); - int *fgroup_recalc_stack = static_cast( - MEM_mallocN(sizeof(*fgroup_recalc_stack) * fgroup_len, __func__)); + int *fgroup_recalc_stack = MEM_malloc_arrayN(fgroup_len, __func__); STACK_DECLARE(fgroup_recalc_stack); STACK_INIT(fgroup_recalc_stack, fgroup_len); @@ -3034,10 +3029,8 @@ bool EDBM_select_interior_faces(BMEditMesh *em) } bm->elem_index_dirty |= BM_FACE; - ListBase *fgroup_listbase = static_cast( - MEM_callocN(sizeof(*fgroup_listbase) * fgroup_len, __func__)); - BMFaceLink *f_link_array = static_cast( - MEM_callocN(sizeof(*f_link_array) * bm->totface, __func__)); + ListBase *fgroup_listbase = MEM_calloc_arrayN(fgroup_len, __func__); + BMFaceLink *f_link_array = MEM_calloc_arrayN(bm->totface, __func__); for (int i = 0; i < fgroup_len; i++) { const int fg_sta = fgroup_index[i][0]; @@ -3058,10 +3051,8 @@ bool EDBM_select_interior_faces(BMEditMesh *em) MEM_freeN(fgroup_index); Heap *fgroup_heap = BLI_heap_new_ex(fgroup_len); - HeapNode **fgroup_table = static_cast( - MEM_mallocN(sizeof(*fgroup_table) * fgroup_len, __func__)); - bool *fgroup_dirty = static_cast( - MEM_callocN(sizeof(*fgroup_dirty) * fgroup_len, __func__)); + HeapNode **fgroup_table = MEM_malloc_arrayN(fgroup_len, __func__); + bool *fgroup_dirty = MEM_calloc_arrayN(fgroup_len, __func__); for (int i = 0; i < fgroup_len; i++) { const float cost = bm_interior_face_group_calc_cost(&fgroup_listbase[i], edge_lengths); @@ -5363,8 +5354,7 @@ static int loop_find_region(BMLoop *l, int flag, GSet *visit_face_set, BMFace ** } } - BMFace **region_alloc = static_cast( - MEM_malloc_arrayN(region.size(), sizeof(BMFace *), __func__)); + BMFace **region_alloc = MEM_malloc_arrayN(region.size(), __func__); memcpy(region_alloc, region.data(), region.as_span().size_in_bytes()); *region_out = region_alloc; return region.size(); @@ -5402,7 +5392,7 @@ static int loop_find_regions(BMEditMesh *em, const bool selbigger) int count = 0, i; visit_face_set = BLI_gset_ptr_new_ex(__func__, edges_len); - BMEdge **edges = static_cast(MEM_mallocN(sizeof(*edges) * edges_len, __func__)); + BMEdge **edges = MEM_malloc_arrayN(edges_len, __func__); i = 0; BM_ITER_MESH (e, &iter, em->bm, BM_EDGES_OF_MESH) { diff --git a/source/blender/editors/mesh/editmesh_tools.cc b/source/blender/editors/mesh/editmesh_tools.cc index 73759ab82c6..b0eab8f419a 100644 --- a/source/blender/editors/mesh/editmesh_tools.cc +++ b/source/blender/editors/mesh/editmesh_tools.cc @@ -1196,7 +1196,7 @@ static bool edbm_connect_vert_pair(BMEditMesh *em, Mesh *mesh, wmOperator *op) return false; } - BMVert **verts = static_cast(MEM_mallocN(sizeof(*verts) * verts_len, __func__)); + BMVert **verts = MEM_malloc_arrayN(verts_len, __func__); { BMIter iter; BMVert *v; @@ -4652,7 +4652,7 @@ static bool edbm_fill_grid_prepare(BMesh *bm, int offset, int *span_p, const boo } const int verts_len = BM_edgeloop_length_get(el_store); const int edges_len = verts_len - (BM_edgeloop_is_closed(el_store) ? 0 : 1); - BMEdge **edges = static_cast(MEM_mallocN(sizeof(*edges) * edges_len, __func__)); + BMEdge **edges = MEM_malloc_arrayN(edges_len, __func__); BM_edgeloop_edges_get(el_store, edges); for (int i = 0; i < edges_len; i++) { BM_elem_flag_enable(edges[i], BM_ELEM_TAG); @@ -4715,8 +4715,7 @@ static bool edbm_fill_grid_prepare(BMesh *bm, int offset, int *span_p, const boo * * NOTE: we may have already checked 'edbm_fill_grid_vert_tag_angle()' on each * vert, but advantage of de-duplicating is minimal. */ - SortPtrByFloat *ele_sort = static_cast( - MEM_mallocN(sizeof(*ele_sort) * verts_len, __func__)); + SortPtrByFloat *ele_sort = MEM_malloc_arrayN(verts_len, __func__); LinkData *v_link; for (v_link = static_cast(verts->first), i = 0; v_link; v_link = v_link->next, i++) @@ -5625,7 +5624,7 @@ static wmOperatorStatus edbm_decimate_exec(bContext *C, wmOperator *op) continue; } - float *vweights = static_cast(MEM_mallocN(sizeof(*vweights) * bm->totvert, __func__)); + float *vweights = MEM_malloc_arrayN(bm->totvert, __func__); { const int cd_dvert_offset = CustomData_get_offset(&bm->vdata, CD_MDEFORMVERT); const int defbase_act = BKE_object_defgroup_active_index_get(obedit) - 1; @@ -6642,8 +6641,8 @@ static void sort_bmelem_flag(bContext *C, uint *tbuf[3] = {nullptr, nullptr, nullptr}, *tb; if (totelem[0]) { - tb = tbuf[0] = static_cast(MEM_callocN(sizeof(int) * totelem[0], __func__)); - mp = map[0] = static_cast(MEM_callocN(sizeof(int) * totelem[0], __func__)); + tb = tbuf[0] = MEM_calloc_arrayN(totelem[0], __func__); + mp = map[0] = MEM_calloc_arrayN(totelem[0], __func__); BM_ITER_MESH_INDEX (ve, &iter, em->bm, BM_VERTS_OF_MESH, i) { if (BM_elem_flag_test(ve, flag)) { @@ -6657,8 +6656,8 @@ static void sort_bmelem_flag(bContext *C, } if (totelem[1]) { - tb = tbuf[1] = static_cast(MEM_callocN(sizeof(int) * totelem[1], __func__)); - mp = map[1] = static_cast(MEM_callocN(sizeof(int) * totelem[1], __func__)); + tb = tbuf[1] = MEM_calloc_arrayN(totelem[1], __func__); + mp = map[1] = MEM_calloc_arrayN(totelem[1], __func__); BM_ITER_MESH_INDEX (ed, &iter, em->bm, BM_EDGES_OF_MESH, i) { if (BM_elem_flag_test(ed, flag)) { @@ -6672,8 +6671,8 @@ static void sort_bmelem_flag(bContext *C, } if (totelem[2]) { - tb = tbuf[2] = static_cast(MEM_callocN(sizeof(int) * totelem[2], __func__)); - mp = map[2] = static_cast(MEM_callocN(sizeof(int) * totelem[2], __func__)); + tb = tbuf[2] = MEM_calloc_arrayN(totelem[2], __func__); + mp = map[2] = MEM_calloc_arrayN(totelem[2], __func__); BM_ITER_MESH_INDEX (fa, &iter, em->bm, BM_FACES_OF_MESH, i) { if (BM_elem_flag_test(fa, flag)) { @@ -6859,7 +6858,7 @@ static void sort_bmelem_flag(bContext *C, qsort(sb, aff, sizeof(BMElemSort), bmelemsort_comp); - mp = map[j] = static_cast(MEM_mallocN(sizeof(int) * tot, __func__)); + mp = map[j] = MEM_malloc_arrayN(tot, __func__); p_blk = pb + tot - 1; s_blk = sb + aff - 1; for (i = tot; i--; p_blk--) { @@ -7787,7 +7786,7 @@ static wmOperatorStatus mesh_symmetry_snap_exec(bContext *C, wmOperator *op) totobjects++; /* Only allocate memory after checking whether to skip object. */ - int *index = static_cast(MEM_mallocN(bm->totvert * sizeof(*index), __func__)); + int *index = MEM_malloc_arrayN(bm->totvert, __func__); /* Vertex iter. */ BMIter iter; diff --git a/source/blender/editors/mesh/editmesh_undo.cc b/source/blender/editors/mesh/editmesh_undo.cc index 7c4cc366cc6..109f488beb8 100644 --- a/source/blender/editors/mesh/editmesh_undo.cc +++ b/source/blender/editors/mesh/editmesh_undo.cc @@ -795,7 +795,7 @@ static void *undomesh_from_editmesh(UndoMesh *um, Mesh &mesh, Key *key, UndoMesh um_arraystore.task_pool = BLI_task_pool_create_background(nullptr, TASK_PRIORITY_LOW); } - UMArrayData *um_data = static_cast(MEM_mallocN(sizeof(*um_data), __func__)); + UMArrayData *um_data = MEM_mallocN(__func__); um_data->um = um; um_data->um_ref = um_ref; @@ -957,8 +957,7 @@ static bool mesh_undosys_step_encode(bContext *C, Main *bmain, UndoStep *us_p) blender::Vector objects = ED_undo_editmode_objects_from_view_layer(scene, view_layer); us->scene_ref.ptr = scene; - us->elems = static_cast( - MEM_callocN(sizeof(*us->elems) * objects.size(), __func__)); + us->elems = MEM_calloc_arrayN(objects.size(), __func__); us->elems_len = objects.size(); UndoMesh **um_references = nullptr; diff --git a/source/blender/editors/mesh/editmesh_utils.cc b/source/blender/editors/mesh/editmesh_utils.cc index 67967f2a3e8..7e95917c3f9 100644 --- a/source/blender/editors/mesh/editmesh_utils.cc +++ b/source/blender/editors/mesh/editmesh_utils.cc @@ -489,8 +489,8 @@ UvVertMap *BM_uv_vert_map_create(BMesh *bm, const bool use_select) return nullptr; } - vmap->vert = (UvMapVert **)MEM_callocN(sizeof(*vmap->vert) * totverts, "UvMapVert_pt"); - UvMapVert *buf = vmap->buf = (UvMapVert *)MEM_callocN(sizeof(*vmap->buf) * totuv, "UvMapVert"); + vmap->vert = MEM_calloc_arrayN(totverts, "UvMapVert_pt"); + UvMapVert *buf = vmap->buf = MEM_calloc_arrayN(totuv, "UvMapVert"); if (!vmap->vert || !vmap->buf) { BKE_mesh_uv_vert_map_free(vmap); @@ -759,13 +759,11 @@ static void bm_uv_build_islands(UvElementMap *element_map, int islandbufsize = 0; /* map holds the map from current vmap->buf to the new, sorted map */ - uint *map = static_cast(MEM_mallocN(sizeof(*map) * totuv, __func__)); - BMFace **stack = static_cast(MEM_mallocN(sizeof(*stack) * bm->totface, __func__)); - UvElement *islandbuf = static_cast( - MEM_callocN(sizeof(*islandbuf) * totuv, __func__)); + uint *map = MEM_malloc_arrayN(totuv, __func__); + BMFace **stack = MEM_malloc_arrayN(bm->totface, __func__); + UvElement *islandbuf = MEM_calloc_arrayN(totuv, __func__); /* Island number for BMFaces. */ - int *island_number = static_cast( - MEM_callocN(sizeof(*island_number) * bm->totface, __func__)); + int *island_number = MEM_calloc_arrayN(bm->totface, __func__); copy_vn_i(island_number, bm->totface, INVALID_ISLAND); const BMUVOffsets uv_offsets = BM_uv_map_offsets_get(bm); @@ -839,12 +837,9 @@ static void bm_uv_build_islands(UvElementMap *element_map, } } - element_map->island_indices = static_cast( - MEM_callocN(sizeof(*element_map->island_indices) * nislands, __func__)); - element_map->island_total_uvs = static_cast( - MEM_callocN(sizeof(*element_map->island_total_uvs) * nislands, __func__)); - element_map->island_total_unique_uvs = static_cast( - MEM_callocN(sizeof(*element_map->island_total_unique_uvs) * nislands, __func__)); + element_map->island_indices = MEM_calloc_arrayN(nislands, __func__); + element_map->island_total_uvs = MEM_calloc_arrayN(nislands, __func__); + element_map->island_total_unique_uvs = MEM_calloc_arrayN(nislands, __func__); int j = 0; for (int i = 0; i < totuv; i++) { UvElement *next = element_map->storage[i].next; @@ -1043,9 +1038,7 @@ UvElementMap *BM_uv_element_map_create(BMesh *bm, element_map->storage = (UvElement *)MEM_callocN(sizeof(*element_map->storage) * totuv, "UvElement"); - bool *winding = use_winding ? - static_cast(MEM_callocN(sizeof(*winding) * bm->totface, "winding")) : - nullptr; + bool *winding = use_winding ? MEM_calloc_arrayN(bm->totface, "winding") : nullptr; UvElement *buf = element_map->storage; int j; diff --git a/source/blender/editors/mesh/meshtools.cc b/source/blender/editors/mesh/meshtools.cc index ad11bb0dacc..b4d80a6b972 100644 --- a/source/blender/editors/mesh/meshtools.cc +++ b/source/blender/editors/mesh/meshtools.cc @@ -471,8 +471,7 @@ wmOperatorStatus ED_mesh_join_objects_exec(bContext *C, wmOperator *op) LISTBASE_FOREACH (bDeformGroup *, dg, &mesh->vertex_group_names) { /* See if this group exists in the object (if it doesn't, add it to the end) */ if (!BKE_object_defgroup_find_name(ob, dg->name)) { - bDeformGroup *odg = static_cast( - MEM_mallocN(sizeof(bDeformGroup), __func__)); + bDeformGroup *odg = MEM_mallocN(__func__); memcpy(odg, dg, sizeof(bDeformGroup)); BLI_addtail(&mesh_active->vertex_group_names, odg); } @@ -490,10 +489,8 @@ wmOperatorStatus ED_mesh_join_objects_exec(bContext *C, wmOperator *op) * check if destination mesh already has matching entries too. */ if (mesh->key && key) { /* for remapping KeyBlock.relative */ - int *index_map = static_cast( - MEM_mallocN(sizeof(int) * mesh->key->totkey, __func__)); - KeyBlock **kb_map = static_cast( - MEM_mallocN(sizeof(KeyBlock *) * mesh->key->totkey, __func__)); + int *index_map = MEM_malloc_arrayN(mesh->key->totkey, __func__); + KeyBlock **kb_map = MEM_malloc_arrayN(mesh->key->totkey, __func__); LISTBASE_FOREACH_INDEX (KeyBlock *, kb, &mesh->key->block, i) { BLI_assert(i < mesh->key->totkey); @@ -548,7 +545,7 @@ wmOperatorStatus ED_mesh_join_objects_exec(bContext *C, wmOperator *op) &ldata, CD_PROP_INT32, CD_CONSTRUCT, totloop, ".corner_vert"); int *corner_edges = (int *)CustomData_add_layer_named( &ldata, CD_PROP_INT32, CD_CONSTRUCT, totloop, ".corner_edge"); - int *face_offsets = static_cast(MEM_malloc_arrayN(faces_num + 1, sizeof(int), __func__)); + int *face_offsets = MEM_malloc_arrayN(faces_num + 1, __func__); face_offsets[faces_num] = totloop; vertofs = 0; @@ -678,10 +675,10 @@ wmOperatorStatus ED_mesh_join_objects_exec(bContext *C, wmOperator *op) const int totcol = matar.size(); if (totcol) { - mesh->mat = static_cast(MEM_callocN(sizeof(*mesh->mat) * totcol, __func__)); + mesh->mat = MEM_calloc_arrayN(totcol, __func__); std::copy_n(matar.data(), totcol, mesh->mat); - ob->mat = static_cast(MEM_callocN(sizeof(*ob->mat) * totcol, __func__)); - ob->matbits = static_cast(MEM_callocN(sizeof(*ob->matbits) * totcol, __func__)); + ob->mat = MEM_calloc_arrayN(totcol, __func__); + ob->matbits = MEM_calloc_arrayN(totcol, __func__); } ob->totcol = mesh->totcol = totcol; @@ -1081,7 +1078,7 @@ int *mesh_get_x_mirror_faces(Object *ob, BMEditMesh *em, Mesh *mesh_eval) int a; mirrorverts = MEM_calloc_arrayN(totvert, "MirrorVerts"); - mirrorfaces = static_cast(MEM_callocN(sizeof(int[2]) * totface, "MirrorFaces")); + mirrorfaces = MEM_calloc_arrayN(2 * totface, "MirrorFaces"); const Span vert_positions = mesh_eval ? mesh_eval->vert_positions() : mesh->vert_positions(); diff --git a/source/blender/editors/metaball/editmball_undo.cc b/source/blender/editors/metaball/editmball_undo.cc index faaa029b2cb..28930d1caa4 100644 --- a/source/blender/editors/metaball/editmball_undo.cc +++ b/source/blender/editors/metaball/editmball_undo.cc @@ -160,8 +160,7 @@ static bool mball_undosys_step_encode(bContext *C, Main *bmain, UndoStep *us_p) blender::Vector objects = ED_undo_editmode_objects_from_view_layer(scene, view_layer); us->scene_ref.ptr = scene; - us->elems = static_cast( - MEM_callocN(sizeof(*us->elems) * objects.size(), __func__)); + us->elems = MEM_calloc_arrayN(objects.size(), __func__); us->elems_len = objects.size(); for (uint i = 0; i < objects.size(); i++) { diff --git a/source/blender/editors/object/object_bake.cc b/source/blender/editors/object/object_bake.cc index 1638f88e009..271bda3519d 100644 --- a/source/blender/editors/object/object_bake.cc +++ b/source/blender/editors/object/object_bake.cc @@ -54,8 +54,7 @@ static Image *bake_object_image_get(Object *ob, int mat_nr) static Image **bake_object_image_get_array(Object *ob) { - Image **image_array = static_cast( - MEM_mallocN(sizeof(Material *) * ob->totcol, __func__)); + Image **image_array = MEM_malloc_arrayN(ob->totcol, __func__); for (int i = 0; i < ob->totcol; i++) { image_array[i] = bake_object_image_get(ob, i); } diff --git a/source/blender/editors/object/object_bake_api.cc b/source/blender/editors/object/object_bake_api.cc index a1900aa7aa8..ed3b379d269 100644 --- a/source/blender/editors/object/object_bake_api.cc +++ b/source/blender/editors/object/object_bake_api.cc @@ -1081,8 +1081,7 @@ static void bake_targets_populate_pixels_color_attributes(BakeTargets *targets, /* Populate through adjacent triangles, first triangle wins. */ const int corner_tris_num = poly_to_tri_count(mesh_eval->faces_num, mesh_eval->corners_num); - int3 *corner_tris = static_cast( - MEM_mallocN(sizeof(*corner_tris) * corner_tris_num, __func__)); + int3 *corner_tris = MEM_malloc_arrayN(corner_tris_num, __func__); const Span corner_verts = mesh_eval->corner_verts(); bke::mesh::corner_tris_calc(mesh_eval->vert_positions(), @@ -1514,8 +1513,7 @@ static wmOperatorStatus bake(const BakeAPIRender *bkr, /* Populate the pixel array with the face data. Except if we use a cage, then * it is populated later with the cage mesh (smoothed version of the mesh). */ - pixel_array_low = static_cast( - MEM_mallocN(sizeof(BakePixel) * targets.pixels_num, "bake pixels low poly")); + pixel_array_low = MEM_malloc_arrayN(targets.pixels_num, "bake pixels low poly"); if ((bkr->is_selected_to_active && (ob_cage == nullptr) && bkr->is_cage) == false) { if (!CustomData_has_layer(&me_low_eval->corner_data, CD_PROP_FLOAT2)) { BKE_reportf(reports, @@ -1653,8 +1651,7 @@ static wmOperatorStatus bake(const BakeAPIRender *bkr, ob_low_eval->base_flag &= ~(BASE_ENABLED_AND_MAYBE_VISIBLE_IN_VIEWPORT | BASE_ENABLED_RENDER); /* populate the pixel arrays with the corresponding face data for each high poly object */ - pixel_array_high = static_cast( - MEM_mallocN(sizeof(BakePixel) * targets.pixels_num, "bake pixels high poly")); + pixel_array_high = MEM_malloc_arrayN(targets.pixels_num, "bake pixels high poly"); if (!RE_bake_pixels_populate_from_objects( me_low_eval, diff --git a/source/blender/editors/object/object_hook.cc b/source/blender/editors/object/object_hook.cc index 82e44e4a366..4a13a45adc7 100644 --- a/source/blender/editors/object/object_hook.cc +++ b/source/blender/editors/object/object_hook.cc @@ -74,7 +74,7 @@ static int return_editmesh_indexar(BMEditMesh *em, return 0; } - *r_indexar = index = static_cast(MEM_mallocN(4 * indexar_num, "hook indexar")); + *r_indexar = index = MEM_malloc_arrayN(indexar_num, "hook indexar"); *r_indexar_num = indexar_num; nr = 0; zero_v3(r_cent); @@ -179,7 +179,7 @@ static int return_editlattice_indexar(Lattice *editlatt, return 0; } - *r_indexar = index = static_cast(MEM_mallocN(4 * indexar_num, "hook indexar")); + *r_indexar = index = MEM_malloc_arrayN(indexar_num, "hook indexar"); *r_indexar_num = indexar_num; nr = 0; zero_v3(r_cent); @@ -267,8 +267,7 @@ static int return_editcurve_indexar(Object *obedit, return 0; } - *r_indexar = index = static_cast( - MEM_mallocN(sizeof(*index) * indexar_num, "hook indexar")); + *r_indexar = index = MEM_malloc_arrayN(indexar_num, "hook indexar"); *r_indexar_num = indexar_num; nr = 0; zero_v3(r_cent); diff --git a/source/blender/editors/object/object_modifier.cc b/source/blender/editors/object/object_modifier.cc index d3aef59747e..5ac0e16c897 100644 --- a/source/blender/editors/object/object_modifier.cc +++ b/source/blender/editors/object/object_modifier.cc @@ -765,10 +765,10 @@ static void add_shapekey_layers(Mesh &mesh_dest, const Mesh &mesh_src) mesh_src.verts_num, kb->name, kb->totelem); - array = MEM_calloc_arrayN(mesh_src.verts_num, sizeof(float[3]), __func__); + array = MEM_calloc_arrayN(mesh_src.verts_num, __func__); } else { - array = MEM_malloc_arrayN(size_t(mesh_src.verts_num), sizeof(float[3]), __func__); + array = MEM_malloc_arrayN(size_t(mesh_src.verts_num), __func__); memcpy(array, kb->data, sizeof(float[3]) * size_t(mesh_src.verts_num)); } @@ -3249,7 +3249,7 @@ static wmOperatorStatus ocean_bake_exec(bContext *C, wmOperator *op) omd->foam_fade, omd->resolution); - och->time = static_cast(MEM_mallocN(och->duration * sizeof(float), "foam bake time")); + och->time = MEM_malloc_arrayN(och->duration, "foam bake time"); int cfra = scene->r.cfra; @@ -3619,8 +3619,8 @@ static wmOperatorStatus dash_modifier_segment_add_exec(bContext *C, wmOperator * return OPERATOR_CANCELLED; } - GreasePencilDashModifierSegment *new_segments = static_cast( - MEM_malloc_arrayN(dmd->segments_num + 1, sizeof(GreasePencilDashModifierSegment), __func__)); + GreasePencilDashModifierSegment *new_segments = + MEM_malloc_arrayN(dmd->segments_num + 1, __func__); const int new_active_index = std::clamp(dmd->segment_active_index + 1, 0, dmd->segments_num); if (dmd->segments_num != 0) { @@ -3855,8 +3855,8 @@ static wmOperatorStatus time_modifier_segment_add_exec(bContext *C, wmOperator * return OPERATOR_CANCELLED; } - GreasePencilTimeModifierSegment *new_segments = static_cast( - MEM_malloc_arrayN(tmd->segments_num + 1, sizeof(GreasePencilTimeModifierSegment), __func__)); + GreasePencilTimeModifierSegment *new_segments = + MEM_malloc_arrayN(tmd->segments_num + 1, __func__); const int new_active_index = std::clamp(tmd->segment_active_index + 1, 0, tmd->segments_num); if (tmd->segments_num != 0) { diff --git a/source/blender/editors/object/object_remesh.cc b/source/blender/editors/object/object_remesh.cc index d29f934fdc6..dad446ac456 100644 --- a/source/blender/editors/object/object_remesh.cc +++ b/source/blender/editors/object/object_remesh.cc @@ -685,8 +685,7 @@ static bool mesh_is_manifold_consistent(Mesh *mesh) bool is_manifold_consistent = true; char *edge_faces = MEM_calloc_arrayN(mesh->edges_num, "remesh_manifold_check"); - int *edge_vert = (int *)MEM_malloc_arrayN( - mesh->edges_num, sizeof(uint), "remesh_consistent_check"); + int *edge_vert = MEM_malloc_arrayN(mesh->edges_num, "remesh_consistent_check"); for (uint i = 0; i < mesh->edges_num; i++) { edge_vert[i] = -1; @@ -951,7 +950,7 @@ static void quadriflow_end_job(void *customdata) static wmOperatorStatus quadriflow_remesh_exec(bContext *C, wmOperator *op) { - QuadriFlowJob *job = (QuadriFlowJob *)MEM_mallocN(sizeof(QuadriFlowJob), "QuadriFlowJob"); + QuadriFlowJob *job = MEM_mallocN("QuadriFlowJob"); job->op = op; job->owner = CTX_data_active_object(C); diff --git a/source/blender/editors/object/object_vgroup.cc b/source/blender/editors/object/object_vgroup.cc index 95a450dca8e..c3bc18eb459 100644 --- a/source/blender/editors/object/object_vgroup.cc +++ b/source/blender/editors/object/object_vgroup.cc @@ -172,7 +172,7 @@ bool vgroup_parray_alloc(ID *id, MDeformVert ***dvert_arr, int *dvert_tot, const i = em->bm->totvert; - *dvert_arr = static_cast(MEM_mallocN(sizeof(void *) * i, __func__)); + *dvert_arr = MEM_malloc_arrayN(i, __func__); *dvert_tot = i; i = 0; @@ -199,8 +199,7 @@ bool vgroup_parray_alloc(ID *id, MDeformVert ***dvert_arr, int *dvert_tot, const MutableSpan dverts = mesh->deform_verts_for_write(); *dvert_tot = mesh->verts_num; - *dvert_arr = static_cast( - MEM_mallocN(sizeof(void *) * mesh->verts_num, __func__)); + *dvert_arr = MEM_malloc_arrayN(mesh->verts_num, __func__); if (use_vert_sel) { const bke::AttributeAccessor attributes = mesh->attributes(); @@ -228,8 +227,7 @@ bool vgroup_parray_alloc(ID *id, MDeformVert ***dvert_arr, int *dvert_tot, const if (lt->dvert) { BPoint *def = lt->def; *dvert_tot = lt->pntsu * lt->pntsv * lt->pntsw; - *dvert_arr = static_cast( - MEM_mallocN(sizeof(void *) * (*dvert_tot), __func__)); + *dvert_arr = MEM_malloc_arrayN((*dvert_tot), __func__); if (use_vert_sel) { for (int i = 0; i < *dvert_tot; i++) { @@ -1664,12 +1662,10 @@ static void vgroup_smooth_subset(Object *ob, mesh->edges(), mesh->verts_num, vert_to_edge_offsets, vert_to_edge_indices); } - weight_accum_prev = static_cast( - MEM_mallocN(sizeof(*weight_accum_prev) * dvert_tot, __func__)); - weight_accum_curr = static_cast( - MEM_mallocN(sizeof(*weight_accum_curr) * dvert_tot, __func__)); + weight_accum_prev = MEM_malloc_arrayN(dvert_tot, __func__); + weight_accum_curr = MEM_malloc_arrayN(dvert_tot, __func__); - verts_used = static_cast(MEM_mallocN(sizeof(*verts_used) * dvert_tot, __func__)); + verts_used = MEM_malloc_arrayN(dvert_tot, __func__); STACK_INIT(verts_used, dvert_tot); #define IS_BM_VERT_READ(v) (use_hide ? (BM_elem_flag_test(v, BM_ELEM_HIDDEN) == 0) : true) @@ -1896,8 +1892,7 @@ static int vgroup_limit_total_subset(Object *ob, if (num_to_drop > 0) { /* re-pack dw array so that non-bone weights are first, bone-weighted verts at end * sort the tail, then copy only the truncated array back to dv->dw */ - dw_temp = static_cast( - MEM_mallocN(sizeof(MDeformWeight) * dv->totweight, __func__)); + dw_temp = MEM_malloc_arrayN(dv->totweight, __func__); bone_count = 0; non_bone_count = 0; for (j = 0; j < dv->totweight; j++) { @@ -3783,8 +3778,7 @@ static wmOperatorStatus vgroup_do_remap(Object *ob, const char *name_array, wmOp int defbase_tot = BLI_listbase_count(defbase); /* Needs a dummy index at the start. */ - int *sort_map_update = static_cast( - MEM_mallocN(sizeof(int) * (defbase_tot + 1), __func__)); + int *sort_map_update = MEM_malloc_arrayN((defbase_tot + 1), __func__); int *sort_map = sort_map_update + 1; const char *name; diff --git a/source/blender/editors/physics/dynamicpaint_ops.cc b/source/blender/editors/physics/dynamicpaint_ops.cc index 1f7403ac416..fd39b64e170 100644 --- a/source/blender/editors/physics/dynamicpaint_ops.cc +++ b/source/blender/editors/physics/dynamicpaint_ops.cc @@ -487,8 +487,7 @@ static wmOperatorStatus dynamicpaint_bake_exec(bContext *C, wmOperator *op) canvas->error[0] = '\0'; canvas->flags |= MOD_DPAINT_BAKING; - DynamicPaintBakeJob *job = static_cast( - MEM_mallocN(sizeof(DynamicPaintBakeJob), "DynamicPaintBakeJob")); + DynamicPaintBakeJob *job = MEM_mallocN("DynamicPaintBakeJob"); job->bmain = CTX_data_main(C); job->scene = scene_eval; job->depsgraph = depsgraph; diff --git a/source/blender/editors/physics/particle_edit.cc b/source/blender/editors/physics/particle_edit.cc index cb3e3077058..e584b9f18d9 100644 --- a/source/blender/editors/physics/particle_edit.cc +++ b/source/blender/editors/physics/particle_edit.cc @@ -2357,7 +2357,7 @@ static void pe_select_cache_free_generic_userdata(void *data) static void pe_select_cache_init_with_generic_userdata(bContext *C, wmGenericUserData *wm_userdata) { - PEData *data = static_cast(MEM_callocN(sizeof(*data), __func__)); + PEData *data = MEM_callocN(__func__); wm_userdata->data = data; wm_userdata->free_fn = pe_select_cache_free_generic_userdata; wm_userdata->use_free = true; @@ -2778,8 +2778,7 @@ static void rekey_particle(PEData *data, int pa_index) pa->flag |= PARS_REKEY; - key = new_keys = static_cast( - MEM_callocN(data->totrekey * sizeof(HairKey), "Hair re-key keys")); + key = new_keys = MEM_calloc_arrayN(data->totrekey, "Hair re-key keys"); okey = pa->hair; /* root and tip stay the same */ @@ -2944,10 +2943,9 @@ static int remove_tagged_particles(Object *ob, ParticleSystem *psys, int mirror) if (new_totpart != psys->totpart) { if (new_totpart) { - npa = new_pars = static_cast( - MEM_callocN(new_totpart * sizeof(ParticleData), "ParticleData array")); - npoint = new_points = static_cast( - MEM_callocN(new_totpart * sizeof(PTCacheEditPoint), "PTCacheEditKey array")); + npa = new_pars = MEM_calloc_arrayN(new_totpart, "ParticleData array"); + npoint = new_points = MEM_calloc_arrayN(new_totpart, + "PTCacheEditKey array"); if (ELEM(nullptr, new_pars, new_points)) { /* allocation error! */ @@ -3049,10 +3047,8 @@ static void remove_tagged_keys(Depsgraph *depsgraph, Object *ob, ParticleSystem } if (new_totkey != pa->totkey) { - nhkey = new_hkeys = static_cast( - MEM_callocN(new_totkey * sizeof(HairKey), "HairKeys")); - nkey = new_keys = static_cast( - MEM_callocN(new_totkey * sizeof(PTCacheEditKey), "particle edit keys")); + nhkey = new_hkeys = MEM_calloc_arrayN(new_totkey, "HairKeys"); + nkey = new_keys = MEM_calloc_arrayN(new_totkey, "particle edit keys"); hkey = pa->hair; LOOP_KEYS { @@ -3138,10 +3134,9 @@ static void subdivide_particle(PEData *data, int pa_index) pa->flag |= PARS_REKEY; - nkey = new_keys = static_cast( - MEM_callocN((pa->totkey + totnewkey) * sizeof(HairKey), "Hair subdivide keys")); - nekey = new_ekeys = static_cast( - MEM_callocN((pa->totkey + totnewkey) * sizeof(PTCacheEditKey), "Hair subdivide edit keys")); + nkey = new_keys = MEM_calloc_arrayN((pa->totkey + totnewkey), "Hair subdivide keys"); + nekey = new_ekeys = MEM_calloc_arrayN((pa->totkey + totnewkey), + "Hair subdivide edit keys"); key = pa->hair; endtime = key[pa->totkey - 1].time; @@ -3593,10 +3588,8 @@ static void PE_mirror_x(Depsgraph *depsgraph, Scene *scene, Object *ob, int tagg CD_MFACE); /* allocate new arrays and copy existing */ - new_pars = static_cast( - MEM_callocN(newtotpart * sizeof(ParticleData), "ParticleData new")); - new_points = static_cast( - MEM_callocN(newtotpart * sizeof(PTCacheEditPoint), "PTCacheEditPoint new")); + new_pars = MEM_calloc_arrayN(newtotpart, "ParticleData new"); + new_points = MEM_calloc_arrayN(newtotpart, "PTCacheEditPoint new"); if (psys->particles) { memcpy(new_pars, psys->particles, totpart * sizeof(ParticleData)); @@ -4442,8 +4435,7 @@ static int brush_add(const bContext *C, PEData *data, short number) return 0; } - add_pars = static_cast( - MEM_callocN(number * sizeof(ParticleData), "ParticleData add")); + add_pars = MEM_calloc_arrayN(number, "ParticleData add"); rng = BLI_rng_new_srandom(psys->seed + data->mval[0] + data->mval[1]); @@ -4510,11 +4502,9 @@ static int brush_add(const bContext *C, PEData *data, short number) int newtotpart = totpart + n; float hairmat[4][4], cur_co[3]; KDTree_3d *tree = nullptr; - ParticleData *pa, *new_pars = static_cast( - MEM_callocN(newtotpart * sizeof(ParticleData), "ParticleData new")); - PTCacheEditPoint *point, - *new_points = static_cast( - MEM_callocN(newtotpart * sizeof(PTCacheEditPoint), "PTCacheEditPoint array new")); + ParticleData *pa, *new_pars = MEM_calloc_arrayN(newtotpart, "ParticleData new"); + PTCacheEditPoint *point, *new_points = MEM_calloc_arrayN( + newtotpart, "PTCacheEditPoint array new"); PTCacheEditKey *key; HairKey *hkey; @@ -4565,10 +4555,8 @@ static int brush_add(const bContext *C, PEData *data, short number) for (i = totpart; i < newtotpart; i++, pa++, point++) { memcpy(pa, add_pars + i - totpart, sizeof(ParticleData)); - pa->hair = static_cast( - MEM_callocN(pset->totaddkey * sizeof(HairKey), "BakeKey key add")); - key = point->keys = static_cast( - MEM_callocN(pset->totaddkey * sizeof(PTCacheEditKey), "PTCacheEditKey add")); + pa->hair = MEM_calloc_arrayN(pset->totaddkey, "BakeKey key add"); + key = point->keys = MEM_calloc_arrayN(pset->totaddkey, "PTCacheEditKey add"); point->totkey = pa->totkey = pset->totaddkey; for (k = 0, hkey = pa->hair; k < pa->totkey; k++, hkey++, key++) { diff --git a/source/blender/editors/physics/particle_object.cc b/source/blender/editors/physics/particle_object.cc index c33c03cba06..f4e700a7047 100644 --- a/source/blender/editors/physics/particle_object.cc +++ b/source/blender/editors/physics/particle_object.cc @@ -230,7 +230,7 @@ static wmOperatorStatus new_particle_target_exec(bContext *C, wmOperator * /*op* pt->flag &= ~PTARGET_CURRENT; } - pt = static_cast(MEM_callocN(sizeof(ParticleTarget), "keyed particle target")); + pt = MEM_callocN("keyed particle target"); pt->flag |= PTARGET_CURRENT; pt->psys = 1; @@ -1115,8 +1115,7 @@ static bool copy_particle_systems_to_object(const bContext *C, #define PSYS_FROM_NEXT(cur) (single_psys_from ? nullptr : (cur)->next) totpsys = single_psys_from ? 1 : BLI_listbase_count(&ob_from->particlesystem); - tmp_psys = static_cast( - MEM_mallocN(sizeof(ParticleSystem *) * totpsys, "temporary particle system array")); + tmp_psys = MEM_malloc_arrayN(totpsys, "temporary particle system array"); for (psys_from = PSYS_FROM_FIRST, i = 0; psys_from; psys_from = PSYS_FROM_NEXT(psys_from), i++) { psys = BKE_object_copy_particlesystem(psys_from, 0); diff --git a/source/blender/editors/physics/physics_fluid.cc b/source/blender/editors/physics/physics_fluid.cc index 2cf4147033d..929fc24e9dc 100644 --- a/source/blender/editors/physics/physics_fluid.cc +++ b/source/blender/editors/physics/physics_fluid.cc @@ -510,7 +510,7 @@ static void fluid_free_startjob(void *customdata, wmJobWorkerStatus *worker_stat static wmOperatorStatus fluid_bake_exec(bContext *C, wmOperator *op) { - FluidJob *job = static_cast(MEM_mallocN(sizeof(FluidJob), "FluidJob")); + FluidJob *job = MEM_mallocN("FluidJob"); char error_msg[256] = "\0"; if (!fluid_initjob(C, job, op, error_msg, sizeof(error_msg))) { @@ -537,7 +537,7 @@ static wmOperatorStatus fluid_bake_exec(bContext *C, wmOperator *op) static wmOperatorStatus fluid_bake_invoke(bContext *C, wmOperator *op, const wmEvent * /*_event*/) { Scene *scene = CTX_data_scene(C); - FluidJob *job = static_cast(MEM_mallocN(sizeof(FluidJob), "FluidJob")); + FluidJob *job = MEM_mallocN("FluidJob"); char error_msg[256] = "\0"; if (!fluid_initjob(C, job, op, error_msg, sizeof(error_msg))) { @@ -621,7 +621,7 @@ static wmOperatorStatus fluid_free_exec(bContext *C, wmOperator *op) return OPERATOR_CANCELLED; } - FluidJob *job = static_cast(MEM_mallocN(sizeof(FluidJob), "FluidJob")); + FluidJob *job = MEM_mallocN("FluidJob"); job->bmain = CTX_data_main(C); job->scene = scene; job->depsgraph = CTX_data_depsgraph_pointer(C); diff --git a/source/blender/editors/physics/physics_pointcache.cc b/source/blender/editors/physics/physics_pointcache.cc index 8d7e3f2ffd0..fd6e5d0315f 100644 --- a/source/blender/editors/physics/physics_pointcache.cc +++ b/source/blender/editors/physics/physics_pointcache.cc @@ -213,8 +213,7 @@ static wmOperatorStatus ptcache_bake_invoke(bContext *C, wmOperator *op, const w { bool all = STREQ(op->type->idname, "PTCACHE_OT_bake_all"); - PointCacheJob *job = static_cast( - MEM_mallocN(sizeof(PointCacheJob), "PointCacheJob")); + PointCacheJob *job = MEM_mallocN("PointCacheJob"); job->wm = CTX_wm_manager(C); job->baker = ptcache_baker_create(C, op, all); job->baker->bake_job = job; diff --git a/source/blender/editors/render/render_internal.cc b/source/blender/editors/render/render_internal.cc index 447b11fe4e3..dd55e59502d 100644 --- a/source/blender/editors/render/render_internal.cc +++ b/source/blender/editors/render/render_internal.cc @@ -525,7 +525,7 @@ static void image_renderinfo_cb(void *rjv, RenderStats *rs) if (rr) { /* malloc OK here, stats_draw is not in tile threads */ if (rr->text == nullptr) { - rr->text = static_cast(MEM_callocN(IMA_MAX_RENDER_TEXT_SIZE, "rendertext")); + rr->text = MEM_calloc_arrayN(IMA_MAX_RENDER_TEXT_SIZE, "rendertext"); } make_renderinfo_string(rs, rj->scene, rj->v3d_override, rr->error, rr->text); diff --git a/source/blender/editors/render/render_preview.cc b/source/blender/editors/render/render_preview.cc index 1ba4e4ea7c4..77bc699803c 100644 --- a/source/blender/editors/render/render_preview.cc +++ b/source/blender/editors/render/render_preview.cc @@ -1106,8 +1106,7 @@ static void shader_preview_texture(ShaderPreview *sp, Tex *tex, Scene *sce, Rend RenderView *rv = (RenderView *)rr->views.first; ImBuf *rv_ibuf = RE_RenderViewEnsureImBuf(rr, rv); IMB_assign_float_buffer(rv_ibuf, - static_cast(MEM_callocN(sizeof(float[4]) * width * height, - "texture render result")), + MEM_calloc_arrayN(4 * width * height, "texture render result"), IB_TAKE_OWNERSHIP); RE_ReleaseResult(re); diff --git a/source/blender/editors/render/render_shading.cc b/source/blender/editors/render/render_shading.cc index 2ab415ebf38..d1109a304b6 100644 --- a/source/blender/editors/render/render_shading.cc +++ b/source/blender/editors/render/render_shading.cc @@ -622,7 +622,7 @@ static wmOperatorStatus material_slot_move_exec(bContext *C, wmOperator *op) return OPERATOR_CANCELLED; } - slot_remap = static_cast(MEM_mallocN(sizeof(uint) * ob->totcol, __func__)); + slot_remap = MEM_malloc_arrayN(ob->totcol, __func__); range_vn_u(slot_remap, ob->totcol, 0); @@ -2947,7 +2947,7 @@ static void paste_mtex_copybuf(ID *id) if (mtex) { if (*mtex == nullptr) { - *mtex = static_cast(MEM_callocN(sizeof(MTex), "mtex copy")); + *mtex = MEM_callocN("mtex copy"); } else if ((*mtex)->tex) { id_us_min(&(*mtex)->tex->id); diff --git a/source/blender/editors/screen/area.cc b/source/blender/editors/screen/area.cc index c70fcdba0a5..0f2101f5909 100644 --- a/source/blender/editors/screen/area.cc +++ b/source/blender/editors/screen/area.cc @@ -829,7 +829,7 @@ void ED_area_status_text(ScrArea *area, const char *str) if (ar) { if (str) { if (ar->runtime->headerstr == nullptr) { - ar->runtime->headerstr = static_cast(MEM_mallocN(UI_MAX_DRAW_STR, "headerprint")); + ar->runtime->headerstr = MEM_malloc_arrayN(UI_MAX_DRAW_STR, "headerprint"); } BLI_strncpy(ar->runtime->headerstr, str, UI_MAX_DRAW_STR); BLI_str_rstrip(ar->runtime->headerstr); @@ -1047,7 +1047,7 @@ static void area_azone_init(const wmWindow *win, const bScreen *screen, ScrArea #endif /* set area action zones */ - AZone *az = (AZone *)MEM_callocN(sizeof(AZone), "actionzone"); + AZone *az = MEM_callocN("actionzone"); BLI_addtail(&(area->actionzones), az); az->type = AZONE_AREA; az->x1 = coords[i][0]; @@ -1064,7 +1064,7 @@ static void fullscreen_azone_init(ScrArea *area, ARegion *region) return; } - AZone *az = (AZone *)MEM_callocN(sizeof(AZone), "fullscreen action zone"); + AZone *az = MEM_callocN("fullscreen action zone"); BLI_addtail(&(area->actionzones), az); az->type = AZONE_FULLSCREEN; az->region = region; @@ -1231,7 +1231,7 @@ static void region_azone_edge_init(ScrArea *area, return; } - AZone *az = (AZone *)MEM_callocN(sizeof(AZone), "actionzone"); + AZone *az = MEM_callocN("actionzone"); BLI_addtail(&(area->actionzones), az); az->type = AZONE_REGION; az->region = region; @@ -1249,7 +1249,7 @@ static void region_azone_scrollbar_init(ScrArea *area, ARegion *region, AZScrollDirection direction) { - AZone *az = static_cast(MEM_callocN(sizeof(*az), __func__)); + AZone *az = MEM_callocN(__func__); BLI_addtail(&area->actionzones, az); az->type = AZONE_REGION_SCROLL; @@ -2164,7 +2164,7 @@ static void area_offscreen_init(ScrArea *area) ScrArea *ED_area_offscreen_create(wmWindow *win, eSpace_Type space_type) { - ScrArea *area = static_cast(MEM_callocN(sizeof(ScrArea), __func__)); + ScrArea *area = MEM_callocN(__func__); area->spacetype = space_type; screen_area_spacelink_add(WM_window_get_active_scene(win), area, space_type); @@ -2589,7 +2589,7 @@ static void region_align_info_to_area( void ED_area_swapspace(bContext *C, ScrArea *sa1, ScrArea *sa2) { - ScrArea *tmp = static_cast(MEM_callocN(sizeof(ScrArea), __func__)); + ScrArea *tmp = MEM_callocN(__func__); wmWindow *win = CTX_wm_window(C); ED_area_exit(C, sa1); diff --git a/source/blender/editors/screen/screen_edit.cc b/source/blender/editors/screen/screen_edit.cc index 0bc697bc80b..84228033e2f 100644 --- a/source/blender/editors/screen/screen_edit.cc +++ b/source/blender/editors/screen/screen_edit.cc @@ -61,7 +61,7 @@ static ScrArea *screen_addarea_ex(ScrAreaMap *area_map, ScrVert *bottom_right, const eSpace_Type space_type) { - ScrArea *area = static_cast(MEM_callocN(sizeof(ScrArea), "addscrarea")); + ScrArea *area = MEM_callocN("addscrarea"); area->v1 = bottom_left; area->v2 = top_left; @@ -1269,7 +1269,7 @@ static void screen_global_area_refresh(wmWindow *win, screen_area_spacelink_add(WM_window_get_active_scene(win), area, space_type); /* Data specific to global areas. */ - area->global = static_cast(MEM_callocN(sizeof(*area->global), __func__)); + area->global = MEM_callocN(__func__); area->global->size_max = height_max; area->global->size_min = height_min; area->global->align = align; diff --git a/source/blender/editors/screen/screen_geometry.cc b/source/blender/editors/screen/screen_geometry.cc index 4ea17295455..98bc51299fa 100644 --- a/source/blender/editors/screen/screen_geometry.cc +++ b/source/blender/editors/screen/screen_geometry.cc @@ -38,7 +38,7 @@ int screen_geom_area_width(const ScrArea *area) ScrVert *screen_geom_vertex_add_ex(ScrAreaMap *area_map, short x, short y) { - ScrVert *sv = static_cast(MEM_callocN(sizeof(ScrVert), "addscrvert")); + ScrVert *sv = MEM_callocN("addscrvert"); sv->vec.x = x; sv->vec.y = y; @@ -52,7 +52,7 @@ ScrVert *screen_geom_vertex_add(bScreen *screen, short x, short y) ScrEdge *screen_geom_edge_add_ex(ScrAreaMap *area_map, ScrVert *v1, ScrVert *v2) { - ScrEdge *se = static_cast(MEM_callocN(sizeof(ScrEdge), "addscredge")); + ScrEdge *se = MEM_callocN("addscredge"); BKE_screen_sort_scrvert(&v1, &v2); se->v1 = v1; diff --git a/source/blender/editors/screen/screendump.cc b/source/blender/editors/screen/screendump.cc index 7581f5d112a..03dbe506b54 100644 --- a/source/blender/editors/screen/screendump.cc +++ b/source/blender/editors/screen/screendump.cc @@ -65,8 +65,7 @@ static int screenshot_data_create(bContext *C, wmOperator *op, ScrArea *area) uint8_t *dumprect = WM_window_pixels_read(C, win, dumprect_size); if (dumprect) { - ScreenshotData *scd = static_cast( - MEM_callocN(sizeof(ScreenshotData), "screenshot")); + ScreenshotData *scd = MEM_callocN("screenshot"); scd->dumpsx = dumprect_size[0]; scd->dumpsy = dumprect_size[1]; diff --git a/source/blender/editors/sculpt_paint/grease_pencil_trace_util.cc b/source/blender/editors/sculpt_paint/grease_pencil_trace_util.cc index 12e36fea4c0..1a77370dda1 100644 --- a/source/blender/editors/sculpt_paint/grease_pencil_trace_util.cc +++ b/source/blender/editors/sculpt_paint/grease_pencil_trace_util.cc @@ -54,15 +54,14 @@ Bitmap *create_bitmap(const int2 &size) /* Number of words per scanline. */ const int32_t dy = (size.x + BM_WORDBITS - 1) / BM_WORDBITS; - potrace_bitmap_t *bm = static_cast( - MEM_mallocN(sizeof(potrace_bitmap_t), __func__)); + potrace_bitmap_t *bm = MEM_mallocN(__func__); if (!bm) { return nullptr; } bm->w = size.x; bm->h = size.y; bm->dy = dy; - bm->map = static_cast(MEM_mallocN(size.y * dy * sizeof(potrace_word), __func__)); + bm->map = MEM_malloc_arrayN(size.y * dy, __func__); return bm; } diff --git a/source/blender/editors/sculpt_paint/paint_cursor.cc b/source/blender/editors/sculpt_paint/paint_cursor.cc index 202cd78bad9..6d3e76beb3d 100644 --- a/source/blender/editors/sculpt_paint/paint_cursor.cc +++ b/source/blender/editors/sculpt_paint/paint_cursor.cc @@ -316,10 +316,10 @@ static int load_tex(Brush *br, ViewContext *vc, float zoom, bool col, bool prima target->old_col = col; } if (col) { - buffer = static_cast(MEM_mallocN(sizeof(uchar) * size * size * 4, "load_tex")); + buffer = MEM_malloc_arrayN(size * size * 4, "load_tex"); } else { - buffer = static_cast(MEM_mallocN(sizeof(uchar) * size * size, "load_tex")); + buffer = MEM_malloc_arrayN(size * size, "load_tex"); } pool = BKE_image_pool_new(); @@ -454,7 +454,7 @@ static int load_tex_cursor(Brush *br, ViewContext *vc, float zoom) cursor_snap.size = size; } - buffer = static_cast(MEM_mallocN(sizeof(uchar) * size * size, "load_tex")); + buffer = MEM_malloc_arrayN(size * size, "load_tex"); BKE_curvemapping_init(br->curve); diff --git a/source/blender/editors/sculpt_paint/paint_curve.cc b/source/blender/editors/sculpt_paint/paint_curve.cc index 5108d946767..c12f12c5a0f 100644 --- a/source/blender/editors/sculpt_paint/paint_curve.cc +++ b/source/blender/editors/sculpt_paint/paint_curve.cc @@ -200,8 +200,8 @@ static void paintcurve_point_add(bContext *C, wmOperator *op, const int loc[2]) ED_paintcurve_undo_push_begin(op->type->name); - PaintCurvePoint *pcp = static_cast( - MEM_mallocN((pc->tot_points + 1) * sizeof(PaintCurvePoint), "PaintCurvePoint")); + PaintCurvePoint *pcp = MEM_malloc_arrayN((pc->tot_points + 1), + "PaintCurvePoint"); int add_index = pc->add_index; if (pc->points) { @@ -330,8 +330,7 @@ static wmOperatorStatus paintcurve_delete_point_exec(bContext *C, wmOperator *op int new_tot = pc->tot_points - tot_del; PaintCurvePoint *points_new = nullptr; if (new_tot > 0) { - points_new = static_cast( - MEM_mallocN(new_tot * sizeof(PaintCurvePoint), "PaintCurvePoint")); + points_new = MEM_malloc_arrayN(new_tot, "PaintCurvePoint"); } for (i = 0, pcp = pc->points; i < pc->tot_points; i++, pcp++) { @@ -586,8 +585,7 @@ static wmOperatorStatus paintcurve_slide_invoke(bContext *C, wmOperator *op, con if (pcp) { ARegion *region = CTX_wm_region(C); wmWindow *window = CTX_wm_window(C); - PointSlideData *psd = static_cast( - MEM_mallocN(sizeof(PointSlideData), "PointSlideData")); + PointSlideData *psd = MEM_mallocN("PointSlideData"); copy_v2_v2_int(psd->initial_loc, event->mval); psd->event = event->type; psd->pcp = pcp; diff --git a/source/blender/editors/sculpt_paint/paint_image.cc b/source/blender/editors/sculpt_paint/paint_image.cc index 0a071e753a9..5692d96e652 100644 --- a/source/blender/editors/sculpt_paint/paint_image.cc +++ b/source/blender/editors/sculpt_paint/paint_image.cc @@ -206,8 +206,7 @@ BlurKernel *paint_new_blur_kernel(Brush *br, bool proj) side = kernel->side = 2; kernel->side_squared = kernel->side * kernel->side; - kernel->wdata = static_cast( - MEM_mallocN(sizeof(float) * kernel->side_squared, "blur kernel data")); + kernel->wdata = MEM_malloc_arrayN(kernel->side_squared, "blur kernel data"); kernel->pixel_len = radius; } else { @@ -219,8 +218,7 @@ BlurKernel *paint_new_blur_kernel(Brush *br, bool proj) side = kernel->side = radius * 2 + 1; kernel->side_squared = kernel->side * kernel->side; - kernel->wdata = static_cast( - MEM_mallocN(sizeof(float) * kernel->side_squared, "blur kernel data")); + kernel->wdata = MEM_malloc_arrayN(kernel->side_squared, "blur kernel data"); kernel->pixel_len = br->blur_kernel_radius; } diff --git a/source/blender/editors/sculpt_paint/paint_image_2d.cc b/source/blender/editors/sculpt_paint/paint_image_2d.cc index fff8378bf87..a34836b6e12 100644 --- a/source/blender/editors/sculpt_paint/paint_image_2d.cc +++ b/source/blender/editors/sculpt_paint/paint_image_2d.cc @@ -217,7 +217,7 @@ static ushort *brush_painter_mask_ibuf_new(BrushPainter *painter, const int size ushort *mask, *m; int x, y, thread = 0; - mask = static_cast(MEM_mallocN(sizeof(ushort) * size * size, __func__)); + mask = MEM_malloc_arrayN(size * size, __func__); m = mask; for (y = 0; y < size; y++) { @@ -302,14 +302,12 @@ static void brush_painter_mask_imbuf_partial_update(BrushPainter *painter, /* create brush image buffer if it didn't exist yet */ if (!cache->tex_mask) { - cache->tex_mask = static_cast( - MEM_mallocN(sizeof(ushort) * diameter * diameter, __func__)); + cache->tex_mask = MEM_malloc_arrayN(diameter * diameter, __func__); } /* create new texture image buffer with coordinates relative to old */ tex_mask_old = cache->tex_mask_old; - cache->tex_mask_old = static_cast( - MEM_mallocN(sizeof(ushort) * diameter * diameter, __func__)); + cache->tex_mask_old = MEM_malloc_arrayN(diameter * diameter, __func__); if (tex_mask_old) { ImBuf maskibuf; diff --git a/source/blender/editors/sculpt_paint/paint_image_2d_curve_mask.cc b/source/blender/editors/sculpt_paint/paint_image_2d_curve_mask.cc index 92230658bc0..78b0045ff6e 100644 --- a/source/blender/editors/sculpt_paint/paint_image_2d_curve_mask.cc +++ b/source/blender/editors/sculpt_paint/paint_image_2d_curve_mask.cc @@ -110,8 +110,7 @@ static void sampled_curve_free(CurveMaskCache *curve_mask_cache) static void update_sampled_curve(CurveMaskCache *curve_mask_cache, const Brush *brush) { if (curve_mask_cache->sampled_curve == nullptr) { - curve_mask_cache->sampled_curve = static_cast( - MEM_mallocN(CurveSamplesLen * sizeof(float), __func__)); + curve_mask_cache->sampled_curve = MEM_malloc_arrayN(CurveSamplesLen, __func__); } for (int i = 0; i < CurveSamplesLen; i++) { diff --git a/source/blender/editors/sculpt_paint/paint_image_proj.cc b/source/blender/editors/sculpt_paint/paint_image_proj.cc index 2aa24f4eabc..6e183ac7272 100644 --- a/source/blender/editors/sculpt_paint/paint_image_proj.cc +++ b/source/blender/editors/sculpt_paint/paint_image_proj.cc @@ -3895,8 +3895,7 @@ static void proj_paint_state_cavity_init(ProjPaintState *ps) int *counter = MEM_calloc_arrayN(ps->totvert_eval, "counter"); float(*edges)[3] = static_cast( MEM_callocN(sizeof(float[3]) * ps->totvert_eval, "edges")); - ps->cavities = static_cast( - MEM_mallocN(sizeof(float) * ps->totvert_eval, "ProjectPaint Cavities")); + ps->cavities = MEM_malloc_arrayN(ps->totvert_eval, "ProjectPaint Cavities"); cavities = ps->cavities; for (const int64_t i : ps->edges_eval.index_range()) { @@ -3932,8 +3931,7 @@ static void proj_paint_state_seam_bleed_init(ProjPaintState *ps) ps->vertFaces = MEM_calloc_arrayN(ps->totvert_eval, "paint-vertFaces"); ps->faceSeamFlags = MEM_calloc_arrayN(ps->corner_tris_eval.size(), __func__); ps->faceWindingFlags = MEM_calloc_arrayN(ps->corner_tris_eval.size(), __func__); - ps->loopSeamData = static_cast( - MEM_mallocN(sizeof(LoopSeamData) * ps->totloop_eval, "paint-loopSeamUVs")); + ps->loopSeamData = MEM_malloc_arrayN(ps->totloop_eval, "paint-loopSeamUVs"); ps->vertSeams = MEM_calloc_arrayN(ps->totvert_eval, "paint-vertSeams"); } } @@ -3957,8 +3955,7 @@ static void proj_paint_state_thread_init(ProjPaintState *ps, const bool reset_th if (ps->is_shared_user == false) { if (ps->thread_tot > 1) { - ps->tile_lock = static_cast( - MEM_mallocN(sizeof(SpinLock), "projpaint_tile_lock")); + ps->tile_lock = MEM_mallocN("projpaint_tile_lock"); BLI_spin_init(ps->tile_lock); } diff --git a/source/blender/editors/sculpt_paint/paint_ops.cc b/source/blender/editors/sculpt_paint/paint_ops.cc index 0a82ee3215d..f106eb83c80 100644 --- a/source/blender/editors/sculpt_paint/paint_ops.cc +++ b/source/blender/editors/sculpt_paint/paint_ops.cc @@ -618,7 +618,7 @@ static wmOperatorStatus stencil_control_invoke(bContext *C, wmOperator *op, cons } } - scd = static_cast(MEM_mallocN(sizeof(StencilControlData), __func__)); + scd = MEM_mallocN(__func__); scd->mask = mask; scd->br = br; diff --git a/source/blender/editors/sculpt_paint/paint_vertex_weight_ops.cc b/source/blender/editors/sculpt_paint/paint_vertex_weight_ops.cc index 128f14b5a46..f6e819855b5 100644 --- a/source/blender/editors/sculpt_paint/paint_vertex_weight_ops.cc +++ b/source/blender/editors/sculpt_paint/paint_vertex_weight_ops.cc @@ -75,8 +75,7 @@ static void wpaint_prev_create(WPaintPrev *wpp, MDeformVert *dverts, int dcount) wpaint_prev_init(wpp); if (dverts && dcount) { - wpp->wpaint_prev = static_cast( - MEM_malloc_arrayN(dcount, sizeof(MDeformVert), __func__)); + wpp->wpaint_prev = MEM_malloc_arrayN(dcount, __func__); wpp->tot = dcount; BKE_defvert_array_copy(wpp->wpaint_prev, dverts, dcount); } diff --git a/source/blender/editors/sculpt_paint/paint_weight.cc b/source/blender/editors/sculpt_paint/paint_weight.cc index 750a4ebbc16..db84d60f588 100644 --- a/source/blender/editors/sculpt_paint/paint_weight.cc +++ b/source/blender/editors/sculpt_paint/paint_weight.cc @@ -958,7 +958,7 @@ static bool wpaint_stroke_test_start(bContext *C, wmOperator *op, const float mo bool *unlocked = (bool *)MEM_dupallocN(wpd->vgroup_validmap); if (wpd->lock_flags) { - bool *locked = (bool *)MEM_mallocN(sizeof(bool) * wpd->defbase_tot, __func__); + bool *locked = MEM_malloc_arrayN(wpd->defbase_tot, __func__); BKE_object_defgroup_split_locked_validmap( wpd->defbase_tot, wpd->lock_flags, wpd->vgroup_validmap, locked, unlocked); wpd->vgroup_locked = locked; @@ -969,7 +969,7 @@ static bool wpaint_stroke_test_start(bContext *C, wmOperator *op, const float mo if (wpd->do_multipaint && ts.auto_normalize) { bool *tmpflags; - tmpflags = (bool *)MEM_mallocN(sizeof(bool) * defbase_tot, __func__); + tmpflags = MEM_malloc_arrayN(defbase_tot, __func__); if (wpd->lock_flags) { BLI_array_binary_or(tmpflags, wpd->defbase_sel, wpd->lock_flags, wpd->defbase_tot); } @@ -1000,7 +1000,7 @@ static bool wpaint_stroke_test_start(bContext *C, wmOperator *op, const float mo /* Brush may have changed after initialization. */ brush = BKE_paint_brush(&vp.paint); if (ELEM(brush->weight_brush_type, WPAINT_BRUSH_TYPE_SMEAR, WPAINT_BRUSH_TYPE_BLUR)) { - wpd->precomputed_weight = (float *)MEM_mallocN(sizeof(float) * mesh.verts_num, __func__); + wpd->precomputed_weight = MEM_malloc_arrayN(mesh.verts_num, __func__); } if (!ob.sculpt->mode.wpaint.dvert_prev.is_empty()) { diff --git a/source/blender/editors/sculpt_paint/sculpt_trim.cc b/source/blender/editors/sculpt_paint/sculpt_trim.cc index 45e4324eee0..f2dfd3fdaa5 100644 --- a/source/blender/editors/sculpt_paint/sculpt_trim.cc +++ b/source/blender/editors/sculpt_paint/sculpt_trim.cc @@ -348,8 +348,7 @@ static void generate_geometry(gesture::GestureData &gesture_data) const int trim_faces_nums = (2 * (screen_points.size() - 2)) + (2 * screen_points.size()); trim_operation->mesh = BKE_mesh_new_nomain( trim_totverts, 0, trim_faces_nums, trim_faces_nums * 3); - trim_operation->true_mesh_co = static_cast( - MEM_malloc_arrayN(trim_totverts, sizeof(float[3]), "mesh orco")); + trim_operation->true_mesh_co = MEM_malloc_arrayN(trim_totverts, "mesh orco"); float shape_origin[3]; float shape_normal[3]; diff --git a/source/blender/editors/sculpt_paint/sculpt_uv.cc b/source/blender/editors/sculpt_paint/sculpt_uv.cc index 236b4df88ea..aca7b318780 100644 --- a/source/blender/editors/sculpt_paint/sculpt_uv.cc +++ b/source/blender/editors/sculpt_paint/sculpt_uv.cc @@ -727,8 +727,7 @@ static UvSculptData *uv_sculpt_stroke_init(bContext *C, wmOperator *op, const wm /* Allocate the unique uv buffers */ data->uv = MEM_calloc_arrayN(unique_uvs, __func__); /* Holds, for each UvElement in elementMap, an index of its unique UV. */ - int *uniqueUv = static_cast( - MEM_mallocN(sizeof(*uniqueUv) * data->elementMap->total_uvs, __func__)); + int *uniqueUv = MEM_malloc_arrayN(data->elementMap->total_uvs, __func__); GHash *edgeHash = BLI_ghash_new(uv_edge_hash, uv_edge_compare, "uv_brush_edge_hash"); /* we have at most totalUVs edges */ UvEdge *edges = MEM_calloc_arrayN(data->elementMap->total_uvs, __func__); @@ -877,8 +876,8 @@ static UvSculptData *uv_sculpt_stroke_init(bContext *C, wmOperator *op, const wm if (!data->initial_stroke) { uv_sculpt_stroke_exit(C, op); } - data->initial_stroke->initialSelection = static_cast(MEM_mallocN( - sizeof(*data->initial_stroke->initialSelection) * data->totalUniqueUvs, __func__)); + data->initial_stroke->initialSelection = MEM_malloc_arrayN( + data->totalUniqueUvs, __func__); if (!data->initial_stroke->initialSelection) { uv_sculpt_stroke_exit(C, op); } diff --git a/source/blender/editors/space_buttons/space_buttons.cc b/source/blender/editors/space_buttons/space_buttons.cc index 2d8dce6fc13..786e7864c12 100644 --- a/source/blender/editors/space_buttons/space_buttons.cc +++ b/source/blender/editors/space_buttons/space_buttons.cc @@ -57,7 +57,7 @@ static SpaceLink *buttons_create(const ScrArea * /*area*/, const Scene * /*scene ARegion *region; SpaceProperties *sbuts; - sbuts = static_cast(MEM_callocN(sizeof(SpaceProperties), "initbuts")); + sbuts = MEM_callocN("initbuts"); sbuts->spacetype = SPACE_PROPERTIES; sbuts->mainb = sbuts->mainbuser = BCONTEXT_OBJECT; sbuts->visible_tabs = uint(-1); /* 0xFFFFFFFF - All tabs visible by default. */ @@ -123,8 +123,7 @@ static void buttons_init(wmWindowManager * /*wm*/, ScrArea *area) SpaceProperties *sbuts = (SpaceProperties *)area->spacedata.first; if (sbuts->runtime == nullptr) { - sbuts->runtime = static_cast( - MEM_mallocN(sizeof(SpaceProperties_Runtime), __func__)); + sbuts->runtime = MEM_mallocN(__func__); sbuts->runtime->search_string[0] = '\0'; sbuts->runtime->tab_search_results = BLI_BITMAP_NEW(BCONTEXT_TOT * 2, __func__); } diff --git a/source/blender/editors/space_console/console_draw.cc b/source/blender/editors/space_console/console_draw.cc index 8dc70daec13..d098ac2e4cb 100644 --- a/source/blender/editors/space_console/console_draw.cc +++ b/source/blender/editors/space_console/console_draw.cc @@ -64,7 +64,7 @@ void console_scrollback_prompt_begin(SpaceConsole *sc, ConsoleLine *cl_dummy) cl_dummy->type = CONSOLE_LINE_INPUT; cl_dummy->len = prompt_len + cl->len; cl_dummy->len_alloc = cl_dummy->len + 1; - cl_dummy->line = static_cast(MEM_mallocN(cl_dummy->len_alloc, "cl_dummy")); + cl_dummy->line = MEM_malloc_arrayN(cl_dummy->len_alloc, "cl_dummy"); memcpy(cl_dummy->line, sc->prompt, prompt_len); memcpy(cl_dummy->line + prompt_len, cl->line, cl->len + 1); BLI_addtail(&sc->scrollback, cl_dummy); diff --git a/source/blender/editors/space_console/console_ops.cc b/source/blender/editors/space_console/console_ops.cc index 488da5945ae..dd2a29c92b0 100644 --- a/source/blender/editors/space_console/console_ops.cc +++ b/source/blender/editors/space_console/console_ops.cc @@ -224,8 +224,7 @@ static void console_history_debug(const bContext *C) static ConsoleLine *console_lb_add__internal(ListBase *lb, ConsoleLine *from) { - ConsoleLine *ci = static_cast( - MEM_callocN(sizeof(ConsoleLine), "ConsoleLine Add")); + ConsoleLine *ci = MEM_callocN("ConsoleLine Add"); if (from) { BLI_assert(strlen(from->line) == from->len); @@ -235,7 +234,7 @@ static ConsoleLine *console_lb_add__internal(ListBase *lb, ConsoleLine *from) ci->type = from->type; } else { - ci->line = static_cast(MEM_callocN(64, "console-in-line")); + ci->line = MEM_calloc_arrayN(64, "console-in-line"); ci->len_alloc = 64; ci->len = 0; } @@ -260,8 +259,7 @@ static ConsoleLine *console_scrollback_add(const bContext *C, ConsoleLine *from) static ConsoleLine *console_lb_add_str__internal(ListBase *lb, char *str, bool own) { - ConsoleLine *ci = static_cast( - MEM_callocN(sizeof(ConsoleLine), "ConsoleLine Add")); + ConsoleLine *ci = MEM_callocN("ConsoleLine Add"); const int str_len = strlen(str); if (own) { ci->line = str; diff --git a/source/blender/editors/space_console/space_console.cc b/source/blender/editors/space_console/space_console.cc index ec19b327767..3792239ba77 100644 --- a/source/blender/editors/space_console/space_console.cc +++ b/source/blender/editors/space_console/space_console.cc @@ -40,7 +40,7 @@ static SpaceLink *console_create(const ScrArea * /*area*/, const Scene * /*scene ARegion *region; SpaceConsole *sconsole; - sconsole = static_cast(MEM_callocN(sizeof(SpaceConsole), "initconsole")); + sconsole = MEM_callocN("initconsole"); sconsole->spacetype = SPACE_CONSOLE; sconsole->lheight = 14; diff --git a/source/blender/editors/space_file/file_draw.cc b/source/blender/editors/space_file/file_draw.cc index 8fcee3a40d9..71b833a6a77 100644 --- a/source/blender/editors/space_file/file_draw.cc +++ b/source/blender/editors/space_file/file_draw.cc @@ -127,7 +127,7 @@ struct FileTooltipData { static FileTooltipData *file_tooltip_data_create(const SpaceFile *sfile, const FileDirEntry *file) { - FileTooltipData *data = (FileTooltipData *)MEM_mallocN(sizeof(FileTooltipData), __func__); + FileTooltipData *data = MEM_mallocN(__func__); data->sfile = sfile; data->file = file; return data; diff --git a/source/blender/editors/space_file/file_indexer.cc b/source/blender/editors/space_file/file_indexer.cc index ce0fd331f67..0b250019c2f 100644 --- a/source/blender/editors/space_file/file_indexer.cc +++ b/source/blender/editors/space_file/file_indexer.cc @@ -41,8 +41,7 @@ constexpr FileIndexerType default_indexer() static FileIndexerEntry *file_indexer_entry_create_from_datablock_info( BLODataBlockInfo *datablock_info, const int idcode) { - FileIndexerEntry *entry = static_cast( - MEM_mallocN(sizeof(FileIndexerEntry), __func__)); + FileIndexerEntry *entry = MEM_mallocN(__func__); entry->idcode = idcode; /* Shallow copy data-block info and mark original as having its asset data ownership stolen. */ entry->datablock_info = *datablock_info; diff --git a/source/blender/editors/space_file/filelist.cc b/source/blender/editors/space_file/filelist.cc index 25ad0018bf1..5e5fbe0bda4 100644 --- a/source/blender/editors/space_file/filelist.cc +++ b/source/blender/editors/space_file/filelist.cc @@ -1741,8 +1741,7 @@ static void filelist_cache_init(FileListEntryCache *cache, size_t cache_size) MEM_mallocN(sizeof(*cache->block_entries) * cache_size, __func__)); cache->misc_entries = BLI_ghash_ptr_new_ex(__func__, cache_size); - cache->misc_entries_indices = static_cast( - MEM_mallocN(sizeof(*cache->misc_entries_indices) * cache_size, __func__)); + cache->misc_entries_indices = MEM_malloc_arrayN(cache_size, __func__); copy_vn_i(cache->misc_entries_indices, cache_size, -1); cache->misc_cursor = 0; diff --git a/source/blender/editors/space_file/filesel.cc b/source/blender/editors/space_file/filesel.cc index d996a3627bf..9b13ca65f15 100644 --- a/source/blender/editors/space_file/filesel.cc +++ b/source/blender/editors/space_file/filesel.cc @@ -149,8 +149,7 @@ static FileSelectParams *fileselect_ensure_updated_file_params(SpaceFile *sfile) /* create new parameters if necessary */ if (!sfile->params) { - sfile->params = static_cast( - MEM_callocN(sizeof(FileSelectParams), "fileselparams")); + sfile->params = MEM_callocN("fileselparams"); /* set path to most recently opened .blend */ BLI_path_split_dir_file(blendfile_path, sfile->params->dir, diff --git a/source/blender/editors/space_file/fsmenu.cc b/source/blender/editors/space_file/fsmenu.cc index 30bce1e8368..fbf46d6368a 100644 --- a/source/blender/editors/space_file/fsmenu.cc +++ b/source/blender/editors/space_file/fsmenu.cc @@ -298,7 +298,7 @@ void fsmenu_insert_entry(FSMenu *fsmenu, } } - fsm_iter = static_cast(MEM_mallocN(sizeof(*fsm_iter), "fsme")); + fsm_iter = MEM_mallocN("fsme"); fsm_iter->path = has_trailing_slash ? BLI_strdup(path) : BLI_string_joinN(path, SEP_STR); fsm_iter->save = (flag & FS_INSERT_SAVE) != 0; diff --git a/source/blender/editors/space_file/space_file.cc b/source/blender/editors/space_file/space_file.cc index e1c4fc4de0a..633741e5739 100644 --- a/source/blender/editors/space_file/space_file.cc +++ b/source/blender/editors/space_file/space_file.cc @@ -56,7 +56,7 @@ static SpaceLink *file_create(const ScrArea * /*area*/, const Scene * /*scene*/) ARegion *region; SpaceFile *sfile; - sfile = static_cast(MEM_callocN(sizeof(SpaceFile), "initfile")); + sfile = MEM_callocN("initfile"); sfile->spacetype = SPACE_FILE; /* header */ diff --git a/source/blender/editors/space_graph/graph_draw.cc b/source/blender/editors/space_graph/graph_draw.cc index b3c1cfc6386..0a2fd921020 100644 --- a/source/blender/editors/space_graph/graph_draw.cc +++ b/source/blender/editors/space_graph/graph_draw.cc @@ -861,8 +861,7 @@ static void add_bezt_vertices(BezTriple *bezt, float prev_key[2], prev_handle[2], bez_handle[2], bez_key[2]; /* Allocation needs +1 on resolution because BKE_curve_forward_diff_bezier uses it to iterate * inclusively. */ - float *bezier_diff_points = static_cast( - MEM_mallocN(sizeof(float) * ((resolution + 1) * 2), "Draw bezt data")); + float *bezier_diff_points = MEM_malloc_arrayN(((resolution + 1) * 2), "Draw bezt data"); prev_key[0] = prevbezt->vec[1][0]; prev_key[1] = prevbezt->vec[1][1]; diff --git a/source/blender/editors/space_graph/graph_slider_ops.cc b/source/blender/editors/space_graph/graph_slider_ops.cc index e031633e15b..b7e55640be9 100644 --- a/source/blender/editors/space_graph/graph_slider_ops.cc +++ b/source/blender/editors/space_graph/graph_slider_ops.cc @@ -22,6 +22,7 @@ #include "DEG_depsgraph.hh" #include "DNA_anim_types.h" +#include "DNA_curve_types.h" #include "DNA_scene_types.h" #include "RNA_access.hh" @@ -161,14 +162,11 @@ static void store_original_bezt_arrays(tGraphSliderOp *gso) continue; } - const int arr_size = sizeof(BezTriple) * fcu->totvert; - - tBeztCopyData *copy = static_cast( - MEM_mallocN(sizeof(tBeztCopyData), "bezts_copy")); - BezTriple *bezts_copy = static_cast(MEM_mallocN(arr_size, "bezts_copy_array")); + tBeztCopyData *copy = MEM_mallocN("bezts_copy"); + BezTriple *bezts_copy = MEM_malloc_arrayN(fcu->totvert, "bezts_copy_array"); copy->tot_vert = fcu->totvert; - memcpy(bezts_copy, fcu->bezt, arr_size); + memcpy(bezts_copy, fcu->bezt, sizeof(BezTriple) * fcu->totvert); copy->bezt = bezts_copy; @@ -211,14 +209,12 @@ static void reset_bezts(tGraphSliderOp *gso) tBeztCopyData *data = static_cast(link_bezt->data); - const int arr_size = sizeof(BezTriple) * data->tot_vert; - MEM_freeN(fcu->bezt); - fcu->bezt = static_cast(MEM_mallocN(arr_size, __func__)); + fcu->bezt = MEM_malloc_arrayN(data->tot_vert, __func__); fcu->totvert = data->tot_vert; - memcpy(fcu->bezt, data->bezt, arr_size); + memcpy(fcu->bezt, data->bezt, sizeof(BezTriple) * data->tot_vert); link_bezt = link_bezt->next; } diff --git a/source/blender/editors/space_graph/graph_view.cc b/source/blender/editors/space_graph/graph_view.cc index a7ae8b20222..431bc2398a1 100644 --- a/source/blender/editors/space_graph/graph_view.cc +++ b/source/blender/editors/space_graph/graph_view.cc @@ -417,8 +417,7 @@ static void create_ghost_curves(bAnimContext *ac, int start, int end) /* Create samples, but store them in a new curve * - we cannot use fcurve_store_samples() as that will only overwrite the original curve. */ - gcu->fpt = fpt = static_cast( - MEM_callocN(sizeof(FPoint) * (end - start + 1), "Ghost FPoint Samples")); + gcu->fpt = fpt = MEM_calloc_arrayN((end - start + 1), "Ghost FPoint Samples"); gcu->totvert = end - start + 1; /* Use the sampling callback at 1-frame intervals from start to end frames. */ diff --git a/source/blender/editors/space_graph/space_graph.cc b/source/blender/editors/space_graph/space_graph.cc index 7542102d44e..4c49e90c6d6 100644 --- a/source/blender/editors/space_graph/space_graph.cc +++ b/source/blender/editors/space_graph/space_graph.cc @@ -61,11 +61,11 @@ static SpaceLink *graph_create(const ScrArea * /*area*/, const Scene *scene) SpaceGraph *sipo; /* Graph Editor - general stuff */ - sipo = static_cast(MEM_callocN(sizeof(SpaceGraph), "init graphedit")); + sipo = MEM_callocN("init graphedit"); sipo->spacetype = SPACE_GRAPH; /* allocate DopeSheet data for Graph Editor */ - sipo->ads = static_cast(MEM_callocN(sizeof(bDopeSheet), "GraphEdit DopeSheet")); + sipo->ads = MEM_callocN("GraphEdit DopeSheet"); sipo->ads->source = (ID *)scene; /* settings for making it easier by default to just see what you're interested in tweaking */ @@ -145,7 +145,7 @@ static void graph_init(wmWindowManager *wm, ScrArea *area) /* Init dope-sheet if non-existent (i.e. for old files). */ if (sipo->ads == nullptr) { wmWindow *win = WM_window_find_by_area(wm, area); - sipo->ads = static_cast(MEM_callocN(sizeof(bDopeSheet), "GraphEdit DopeSheet")); + sipo->ads = MEM_callocN("GraphEdit DopeSheet"); sipo->ads->source = win ? (ID *)WM_window_get_active_scene(win) : nullptr; } diff --git a/source/blender/editors/space_image/image_ops.cc b/source/blender/editors/space_image/image_ops.cc index d1e5f784c18..cee405cbf04 100644 --- a/source/blender/editors/space_image/image_ops.cc +++ b/source/blender/editors/space_image/image_ops.cc @@ -1915,7 +1915,7 @@ static ImageSaveData *image_save_as_init(bContext *C, wmOperator *op) ImageUser *iuser = image_user_from_context(C); Scene *scene = CTX_data_scene(C); - ImageSaveData *isd = static_cast(MEM_callocN(sizeof(*isd), __func__)); + ImageSaveData *isd = MEM_callocN(__func__); isd->image = image; isd->iuser = iuser; diff --git a/source/blender/editors/space_image/image_sequence.cc b/source/blender/editors/space_image/image_sequence.cc index 6f4c4ce5fa3..4fae2f5e212 100644 --- a/source/blender/editors/space_image/image_sequence.cc +++ b/source/blender/editors/space_image/image_sequence.cc @@ -66,7 +66,7 @@ static void image_sequence_get_frame_ranges(wmOperator *op, ListBase *ranges) } else { /* start a new frame range */ - range = static_cast(MEM_callocN(sizeof(*range), __func__)); + range = MEM_callocN(__func__); BLI_path_join(range->filepath, sizeof(range->filepath), dir, filename); BLI_addtail(ranges, range); @@ -164,7 +164,7 @@ ListBase ED_image_filesel_detect_sequences(blender::StringRefNull root_path, } /* Filepath property for drag & drop etc. */ else { - ImageFrameRange *range = static_cast(MEM_callocN(sizeof(*range), __func__)); + ImageFrameRange *range = MEM_callocN(__func__); BLI_addtail(&ranges, range); STRNCPY(range->filepath, filepath); diff --git a/source/blender/editors/space_image/image_undo.cc b/source/blender/editors/space_image/image_undo.cc index 22f8fb49437..2ed9bf8dcb6 100644 --- a/source/blender/editors/space_image/image_undo.cc +++ b/source/blender/editors/space_image/image_undo.cc @@ -242,7 +242,7 @@ void *ED_image_paint_tile_push(PaintTileMap *paint_tile_map, *tmpibuf = imbuf_alloc_temp_tile(); } - PaintTile *ptile = static_cast(MEM_callocN(sizeof(PaintTile), "PaintTile")); + PaintTile *ptile = MEM_callocN("PaintTile"); ptile->image = image; ptile->ibuf = ibuf; @@ -485,7 +485,7 @@ struct UndoImageBuf { static UndoImageBuf *ubuf_from_image_no_tiles(Image *image, const ImBuf *ibuf) { - UndoImageBuf *ubuf = static_cast(MEM_callocN(sizeof(*ubuf), __func__)); + UndoImageBuf *ubuf = MEM_callocN(__func__); ubuf->image_dims[0] = ibuf->x; ubuf->image_dims[1] = ibuf->y; @@ -722,7 +722,7 @@ static UndoImageHandle *uhandle_lookup(ListBase *undo_handles, const Image *imag static UndoImageHandle *uhandle_add(ListBase *undo_handles, Image *image, ImageUser *iuser) { BLI_assert(uhandle_lookup(undo_handles, image, iuser->tile) == nullptr); - UndoImageHandle *uh = static_cast(MEM_callocN(sizeof(*uh), __func__)); + UndoImageHandle *uh = MEM_callocN(__func__); uh->image_ref.ptr = image; uh->iuser = *iuser; uh->iuser.scene = nullptr; diff --git a/source/blender/editors/space_image/space_image.cc b/source/blender/editors/space_image/space_image.cc index a6aca04cc64..180f1263f9f 100644 --- a/source/blender/editors/space_image/space_image.cc +++ b/source/blender/editors/space_image/space_image.cc @@ -96,7 +96,7 @@ static SpaceLink *image_create(const ScrArea * /*area*/, const Scene * /*scene*/ ARegion *region; SpaceImage *simage; - simage = static_cast(MEM_callocN(sizeof(SpaceImage), "initimage")); + simage = MEM_callocN("initimage"); simage->spacetype = SPACE_IMAGE; simage->zoom = 1.0f; simage->lock = true; diff --git a/source/blender/editors/space_info/info_stats.cc b/source/blender/editors/space_info/info_stats.cc index 374f36c1186..c88f0194ad4 100644 --- a/source/blender/editors/space_info/info_stats.cc +++ b/source/blender/editors/space_info/info_stats.cc @@ -505,7 +505,7 @@ static bool format_stats( return false; } Depsgraph *depsgraph = BKE_scene_ensure_depsgraph(bmain, scene, view_layer); - *stats_p = (SceneStats *)MEM_mallocN(sizeof(SceneStats), __func__); + *stats_p = MEM_mallocN(__func__); stats_update(depsgraph, scene, view_layer, v3d_local, *stats_p); } diff --git a/source/blender/editors/space_info/space_info.cc b/source/blender/editors/space_info/space_info.cc index fdf1661fc1e..566c0e84e8b 100644 --- a/source/blender/editors/space_info/space_info.cc +++ b/source/blender/editors/space_info/space_info.cc @@ -38,7 +38,7 @@ static SpaceLink *info_create(const ScrArea * /*area*/, const Scene * /*scene*/) ARegion *region; SpaceInfo *sinfo; - sinfo = static_cast(MEM_callocN(sizeof(SpaceInfo), "initinfo")); + sinfo = MEM_callocN("initinfo"); sinfo->spacetype = SPACE_INFO; sinfo->rpt_mask = INFO_RPT_OP; diff --git a/source/blender/editors/space_info/textview.cc b/source/blender/editors/space_info/textview.cc index 0d293f5f505..eeac61a8c71 100644 --- a/source/blender/editors/space_info/textview.cc +++ b/source/blender/editors/space_info/textview.cc @@ -106,10 +106,8 @@ static int textview_wrap_offsets( *r_lines = 1; - *r_offsets = static_cast(MEM_callocN( - sizeof(**r_offsets) * - (str_len * column_width_max / std::max(1, width - (column_width_max - 1)) + 1), - __func__)); + *r_offsets = MEM_calloc_arrayN( + (str_len * column_width_max / std::max(1, width - (column_width_max - 1)) + 1), __func__); (*r_offsets)[0] = 0; for (i = 0, end = width, j = 0; j < str_len && str[j]; j += BLI_str_utf8_size_safe(str + j)) { diff --git a/source/blender/editors/space_node/node_gizmo.cc b/source/blender/editors/space_node/node_gizmo.cc index 751ac7daeb6..1de782daacb 100644 --- a/source/blender/editors/space_node/node_gizmo.cc +++ b/source/blender/editors/space_node/node_gizmo.cc @@ -116,7 +116,7 @@ static bool WIDGETGROUP_node_transform_poll(const bContext *C, wmGizmoGroupType static void WIDGETGROUP_node_transform_setup(const bContext * /*C*/, wmGizmoGroup *gzgroup) { - wmGizmoWrapper *wwrapper = (wmGizmoWrapper *)MEM_mallocN(sizeof(wmGizmoWrapper), __func__); + wmGizmoWrapper *wwrapper = MEM_mallocN(__func__); wwrapper->gizmo = WM_gizmo_new("GIZMO_GT_cage_2d", gzgroup, nullptr); @@ -674,8 +674,7 @@ static bool WIDGETGROUP_node_sbeam_poll(const bContext *C, wmGizmoGroupType * /* static void WIDGETGROUP_node_sbeam_setup(const bContext * /*C*/, wmGizmoGroup *gzgroup) { - NodeSunBeamsWidgetGroup *sbeam_group = (NodeSunBeamsWidgetGroup *)MEM_mallocN( - sizeof(NodeSunBeamsWidgetGroup), __func__); + NodeSunBeamsWidgetGroup *sbeam_group = MEM_mallocN(__func__); sbeam_group->gizmo = WM_gizmo_new("GIZMO_GT_move_3d", gzgroup, nullptr); wmGizmo *gz = sbeam_group->gizmo; @@ -781,8 +780,7 @@ static bool WIDGETGROUP_node_corner_pin_poll(const bContext *C, wmGizmoGroupType static void WIDGETGROUP_node_corner_pin_setup(const bContext * /*C*/, wmGizmoGroup *gzgroup) { - NodeCornerPinWidgetGroup *cpin_group = (NodeCornerPinWidgetGroup *)MEM_mallocN( - sizeof(NodeCornerPinWidgetGroup), __func__); + NodeCornerPinWidgetGroup *cpin_group = MEM_mallocN(__func__); const wmGizmoType *gzt_move_3d = WM_gizmotype_find("GIZMO_GT_move_3d", false); for (int i = 0; i < 4; i++) { diff --git a/source/blender/editors/space_node/node_group.cc b/source/blender/editors/space_node/node_group.cc index 65b8ec1fc88..e15453d050c 100644 --- a/source/blender/editors/space_node/node_group.cc +++ b/source/blender/editors/space_node/node_group.cc @@ -920,8 +920,8 @@ static void update_nested_node_refs_after_moving_nodes_into_group( ref.path.id_in_node = new_ref.id; } MEM_SAFE_FREE(group.nested_node_refs); - group.nested_node_refs = static_cast( - MEM_malloc_arrayN(new_nested_node_refs.size(), sizeof(bNestedNodeRef), __func__)); + group.nested_node_refs = MEM_malloc_arrayN(new_nested_node_refs.size(), + __func__); uninitialized_copy_n( new_nested_node_refs.data(), new_nested_node_refs.size(), group.nested_node_refs); group.nested_node_refs_num = new_nested_node_refs.size(); diff --git a/source/blender/editors/space_node/node_relationships.cc b/source/blender/editors/space_node/node_relationships.cc index 1d028224702..6d3d7fe2b37 100644 --- a/source/blender/editors/space_node/node_relationships.cc +++ b/source/blender/editors/space_node/node_relationships.cc @@ -1212,7 +1212,7 @@ static void add_dragged_links_to_tree(bContext &C, bNodeLinkDrag &nldrag) /* Before actually adding the link let nodes perform special link insertion handling. */ - bNodeLink *new_link = static_cast(MEM_mallocN(sizeof(bNodeLink), __func__)); + bNodeLink *new_link = MEM_mallocN(__func__); *new_link = link; if (link.fromnode->typeinfo->insert_link) { if (!link.fromnode->typeinfo->insert_link(&ntree, link.fromnode, new_link)) { diff --git a/source/blender/editors/space_outliner/outliner_tree.cc b/source/blender/editors/space_outliner/outliner_tree.cc index af072041da2..6d71d569cec 100644 --- a/source/blender/editors/space_outliner/outliner_tree.cc +++ b/source/blender/editors/space_outliner/outliner_tree.cc @@ -568,8 +568,7 @@ static void outliner_sort(ListBase *lb) int totelem = BLI_listbase_count(lb); if (totelem > 1) { - tTreeSort *tear = static_cast( - MEM_mallocN(totelem * sizeof(tTreeSort), "tree sort array")); + tTreeSort *tear = MEM_malloc_arrayN(totelem, "tree sort array"); tTreeSort *tp = tear; int skip = 0; @@ -635,8 +634,7 @@ static void outliner_collections_children_sort(ListBase *lb) int totelem = BLI_listbase_count(lb); if (totelem > 1) { - tTreeSort *tear = static_cast( - MEM_mallocN(totelem * sizeof(tTreeSort), "tree sort array")); + tTreeSort *tear = MEM_malloc_arrayN(totelem, "tree sort array"); tTreeSort *tp = tear; LISTBASE_FOREACH (TreeElement *, te, lb) { diff --git a/source/blender/editors/space_outliner/tree/tree_element_rna.cc b/source/blender/editors/space_outliner/tree/tree_element_rna.cc index f332b148c54..893ef08d653 100644 --- a/source/blender/editors/space_outliner/tree/tree_element_rna.cc +++ b/source/blender/editors/space_outliner/tree/tree_element_rna.cc @@ -223,7 +223,7 @@ TreeElementRNAArrayElement::TreeElementRNAArrayElement(TreeElement &legacy_te, char c = RNA_property_array_item_char(TreeElementRNAArrayElement::get_property_rna(), index); const size_t name_size = sizeof(char[20]); - legacy_te_.name = static_cast(MEM_callocN(name_size, "OutlinerRNAArrayName")); + legacy_te_.name = MEM_calloc_arrayN(name_size, "OutlinerRNAArrayName"); if (c) { BLI_snprintf((char *)legacy_te_.name, name_size, " %c", c); } diff --git a/source/blender/editors/space_script/space_script.cc b/source/blender/editors/space_script/space_script.cc index 5558e92f5de..db9bb9e22fe 100644 --- a/source/blender/editors/space_script/space_script.cc +++ b/source/blender/editors/space_script/space_script.cc @@ -38,7 +38,7 @@ static SpaceLink *script_create(const ScrArea * /*area*/, const Scene * /*scene* ARegion *region; SpaceScript *sscript; - sscript = static_cast(MEM_callocN(sizeof(SpaceScript), "initscript")); + sscript = MEM_callocN("initscript"); sscript->spacetype = SPACE_SCRIPT; /* header */ diff --git a/source/blender/editors/space_sequencer/sequencer_drag_drop.cc b/source/blender/editors/space_sequencer/sequencer_drag_drop.cc index 74840ca4ca6..699d67e309a 100644 --- a/source/blender/editors/space_sequencer/sequencer_drag_drop.cc +++ b/source/blender/editors/space_sequencer/sequencer_drag_drop.cc @@ -587,8 +587,7 @@ static void start_audio_video_job(bContext *C, wmDrag *drag, bool only_audio) wmJob *wm_job = WM_jobs_get( wm, win, nullptr, "Load Previews", eWM_JobFlag(0), WM_JOB_TYPE_SEQ_DRAG_DROP_PREVIEW); - DropJobData *job_data = (DropJobData *)MEM_mallocN(sizeof(DropJobData), - "SeqDragDropPreviewData"); + DropJobData *job_data = MEM_mallocN("SeqDragDropPreviewData"); get_drag_path(C, drag, job_data->path); job_data->only_audio = only_audio; diff --git a/source/blender/editors/space_statusbar/space_statusbar.cc b/source/blender/editors/space_statusbar/space_statusbar.cc index edc4c638b5e..6cc193bba20 100644 --- a/source/blender/editors/space_statusbar/space_statusbar.cc +++ b/source/blender/editors/space_statusbar/space_statusbar.cc @@ -33,7 +33,7 @@ static SpaceLink *statusbar_create(const ScrArea * /*area*/, const Scene * /*sce ARegion *region; SpaceStatusBar *sstatusbar; - sstatusbar = static_cast(MEM_callocN(sizeof(*sstatusbar), "init statusbar")); + sstatusbar = MEM_callocN("init statusbar"); sstatusbar->spacetype = SPACE_STATUSBAR; /* header region */ @@ -144,7 +144,7 @@ void ED_spacetype_statusbar() st->blend_write = statusbar_space_blend_write; /* regions: header window */ - art = static_cast(MEM_callocN(sizeof(*art), "spacetype statusbar header region")); + art = MEM_callocN("spacetype statusbar header region"); art->regionid = RGN_TYPE_HEADER; art->prefsizey = 0.8f * HEADERY; art->prefsizex = UI_UNIT_X * 5; /* Mainly to avoid glitches */ diff --git a/source/blender/editors/space_text/space_text.cc b/source/blender/editors/space_text/space_text.cc index 5e6a58bb1f9..37b5143c3cf 100644 --- a/source/blender/editors/space_text/space_text.cc +++ b/source/blender/editors/space_text/space_text.cc @@ -45,7 +45,7 @@ static SpaceLink *text_create(const ScrArea * /*area*/, const Scene * /*scene*/) ARegion *region; SpaceText *stext; - stext = static_cast(MEM_callocN(sizeof(SpaceText), "inittext")); + stext = MEM_callocN("inittext"); stext->spacetype = SPACE_TEXT; stext->lheight = 12; diff --git a/source/blender/editors/space_text/text_format.cc b/source/blender/editors/space_text/text_format.cc index f6d965ee6d1..09246a56efb 100644 --- a/source/blender/editors/space_text/text_format.cc +++ b/source/blender/editors/space_text/text_format.cc @@ -34,10 +34,10 @@ static void flatten_string_append(FlattenString *fs, const char *c, int accum, i int *naccum; fs->len *= 2; - nbuf = static_cast(MEM_callocN(sizeof(*fs->buf) * fs->len, "fs->buf")); + nbuf = MEM_calloc_arrayN(fs->len, "fs->buf"); memcpy(nbuf, fs->buf, sizeof(*fs->buf) * fs->pos); - naccum = static_cast(MEM_callocN(sizeof(*fs->accum) * fs->len, "fs->accum")); + naccum = MEM_calloc_arrayN(fs->len, "fs->accum"); memcpy(naccum, fs->accum, sizeof(*fs->accum) * fs->pos); if (fs->buf != fs->fixedbuf) { @@ -112,14 +112,14 @@ int text_check_format_len(TextLine *line, uint len) if (line->format) { if (strlen(line->format) < len) { MEM_freeN(line->format); - line->format = static_cast(MEM_mallocN(len + 2, "SyntaxFormat")); + line->format = MEM_malloc_arrayN(len + 2, "SyntaxFormat"); if (!line->format) { return 0; } } } else { - line->format = static_cast(MEM_mallocN(len + 2, "SyntaxFormat")); + line->format = MEM_malloc_arrayN(len + 2, "SyntaxFormat"); if (!line->format) { return 0; } diff --git a/source/blender/editors/space_text/text_ops.cc b/source/blender/editors/space_text/text_ops.cc index dd2d42a50c2..42d50375b5f 100644 --- a/source/blender/editors/space_text/text_ops.cc +++ b/source/blender/editors/space_text/text_ops.cc @@ -170,7 +170,7 @@ static char *buf_tabs_to_spaces(const char *in_buf, const int tab_size, int *r_o /* Allocate output before with extra space for expanded tabs. */ const int out_size = strlen(in_buf) + num_tabs * (tab_size - 1) + 1; - char *out_buf = static_cast(MEM_mallocN(out_size * sizeof(char), __func__)); + char *out_buf = MEM_malloc_arrayN(out_size, __func__); /* Fill output buffer. */ int spaces_until_tab = 0; @@ -1421,7 +1421,7 @@ static wmOperatorStatus text_convert_whitespace_exec(bContext *C, wmOperator *op } if (type == TO_TABS) { - char *tmp_line = static_cast(MEM_mallocN(sizeof(*tmp_line) * (max_len + 1), __func__)); + char *tmp_line = MEM_malloc_arrayN(max_len + 1, __func__); LISTBASE_FOREACH (TextLine *, tmp, &text->lines) { const char *text_check_line = tmp->line; diff --git a/source/blender/editors/space_topbar/space_topbar.cc b/source/blender/editors/space_topbar/space_topbar.cc index 8462f046c6b..378a210f2c1 100644 --- a/source/blender/editors/space_topbar/space_topbar.cc +++ b/source/blender/editors/space_topbar/space_topbar.cc @@ -42,7 +42,7 @@ static SpaceLink *topbar_create(const ScrArea * /*area*/, const Scene * /*scene* ARegion *region; SpaceTopBar *stopbar; - stopbar = static_cast(MEM_callocN(sizeof(*stopbar), "init topbar")); + stopbar = MEM_callocN("init topbar"); stopbar->spacetype = SPACE_TOPBAR; /* header */ diff --git a/source/blender/editors/space_userpref/space_userpref.cc b/source/blender/editors/space_userpref/space_userpref.cc index 46fbc854cae..5653d0bac86 100644 --- a/source/blender/editors/space_userpref/space_userpref.cc +++ b/source/blender/editors/space_userpref/space_userpref.cc @@ -35,7 +35,7 @@ static SpaceLink *userpref_create(const ScrArea *area, const Scene * /*scene*/) ARegion *region; SpaceUserPref *spref; - spref = static_cast(MEM_callocN(sizeof(SpaceUserPref), "inituserpref")); + spref = MEM_callocN("inituserpref"); spref->spacetype = SPACE_USERPREF; /* header */ diff --git a/source/blender/editors/space_userpref/userpref_ops.cc b/source/blender/editors/space_userpref/userpref_ops.cc index 8c68a5aa46b..e421487635a 100644 --- a/source/blender/editors/space_userpref/userpref_ops.cc +++ b/source/blender/editors/space_userpref/userpref_ops.cc @@ -83,8 +83,7 @@ static void PREFERENCES_OT_reset_default_theme(wmOperatorType *ot) static wmOperatorStatus preferences_autoexec_add_exec(bContext * /*C*/, wmOperator * /*op*/) { - bPathCompare *path_cmp = static_cast( - MEM_callocN(sizeof(bPathCompare), "bPathCompare")); + bPathCompare *path_cmp = MEM_callocN("bPathCompare"); BLI_addtail(&U.autoexec_paths, path_cmp); U.runtime.is_dirty = true; return OPERATOR_FINISHED; diff --git a/source/blender/editors/space_view3d/view3d_buttons.cc b/source/blender/editors/space_view3d/view3d_buttons.cc index ba00d3d0eaf..9b3686c2206 100644 --- a/source/blender/editors/space_view3d/view3d_buttons.cc +++ b/source/blender/editors/space_view3d/view3d_buttons.cc @@ -293,8 +293,7 @@ static void apply_scale_factor_clamp(float *val, static TransformProperties *v3d_transform_props_ensure(View3D *v3d) { if (v3d->runtime.properties_storage == nullptr) { - TransformProperties *tfp = static_cast( - MEM_callocN(sizeof(TransformProperties), "TransformProperties")); + TransformProperties *tfp = MEM_new("TransformProperties"); /* Construct C++ structures in otherwise zero initialized struct. */ new (tfp) TransformProperties(); diff --git a/source/blender/editors/space_view3d/view3d_draw.cc b/source/blender/editors/space_view3d/view3d_draw.cc index 37234b971ef..c01dc0fa2ee 100644 --- a/source/blender/editors/space_view3d/view3d_draw.cc +++ b/source/blender/editors/space_view3d/view3d_draw.cc @@ -2409,7 +2409,7 @@ void view3d_depths_rect_create(ARegion *region, rcti *rect, ViewDepths *r_d) r_d->w = w; r_d->h = h; - r_d->depths = static_cast(MEM_mallocN(sizeof(float) * w * h, "View depths Subset")); + r_d->depths = MEM_malloc_arrayN(w * h, "View depths Subset"); { GPUViewport *viewport = WM_draw_region_get_viewport(region); diff --git a/source/blender/editors/space_view3d/view3d_edit.cc b/source/blender/editors/space_view3d/view3d_edit.cc index 1e581042aff..a0efb777eea 100644 --- a/source/blender/editors/space_view3d/view3d_edit.cc +++ b/source/blender/editors/space_view3d/view3d_edit.cc @@ -782,7 +782,7 @@ static wmOperatorStatus view3d_clipping_exec(bContext *C, wmOperator *op) WM_operator_properties_border_to_rcti(op, &rect); rv3d->rflag |= RV3D_CLIPPING; - rv3d->clipbb = static_cast(MEM_callocN(sizeof(BoundBox), "clipbb")); + rv3d->clipbb = MEM_callocN("clipbb"); /* nullptr object because we don't want it in object space */ ED_view3d_clipping_calc(rv3d->clipbb, rv3d->clip, region, nullptr, &rect); diff --git a/source/blender/editors/space_view3d/view3d_gizmo_camera.cc b/source/blender/editors/space_view3d/view3d_gizmo_camera.cc index a226ba908e2..ac439f22734 100644 --- a/source/blender/editors/space_view3d/view3d_gizmo_camera.cc +++ b/source/blender/editors/space_view3d/view3d_gizmo_camera.cc @@ -411,8 +411,7 @@ static bool WIDGETGROUP_camera_view_poll(const bContext *C, wmGizmoGroupType * / static void WIDGETGROUP_camera_view_setup(const bContext * /*C*/, wmGizmoGroup *gzgroup) { - CameraViewWidgetGroup *viewgroup = static_cast( - MEM_mallocN(sizeof(CameraViewWidgetGroup), __func__)); + CameraViewWidgetGroup *viewgroup = MEM_mallocN(__func__); viewgroup->border = WM_gizmo_new("GIZMO_GT_cage_2d", gzgroup, nullptr); diff --git a/source/blender/editors/space_view3d/view3d_gizmo_empty.cc b/source/blender/editors/space_view3d/view3d_gizmo_empty.cc index 994b915bd5e..df7ce846cd1 100644 --- a/source/blender/editors/space_view3d/view3d_gizmo_empty.cc +++ b/source/blender/editors/space_view3d/view3d_gizmo_empty.cc @@ -120,8 +120,7 @@ static bool WIDGETGROUP_empty_image_poll(const bContext *C, wmGizmoGroupType * / static void WIDGETGROUP_empty_image_setup(const bContext * /*C*/, wmGizmoGroup *gzgroup) { - EmptyImageWidgetGroup *igzgroup = static_cast( - MEM_mallocN(sizeof(EmptyImageWidgetGroup), __func__)); + EmptyImageWidgetGroup *igzgroup = MEM_mallocN(__func__); igzgroup->gizmo = WM_gizmo_new("GIZMO_GT_cage_2d", gzgroup, nullptr); wmGizmo *gz = igzgroup->gizmo; RNA_enum_set(gz->ptr, "transform", ED_GIZMO_CAGE_XFORM_FLAG_SCALE); diff --git a/source/blender/editors/space_view3d/view3d_gizmo_forcefield.cc b/source/blender/editors/space_view3d/view3d_gizmo_forcefield.cc index 8bbd3a3f9b7..95204203b9b 100644 --- a/source/blender/editors/space_view3d/view3d_gizmo_forcefield.cc +++ b/source/blender/editors/space_view3d/view3d_gizmo_forcefield.cc @@ -58,8 +58,7 @@ static bool WIDGETGROUP_forcefield_poll(const bContext *C, wmGizmoGroupType * /* static void WIDGETGROUP_forcefield_setup(const bContext * /*C*/, wmGizmoGroup *gzgroup) { /* only wind effector for now */ - wmGizmoWrapper *wwrapper = static_cast( - MEM_mallocN(sizeof(wmGizmoWrapper), __func__)); + wmGizmoWrapper *wwrapper = MEM_mallocN(__func__); gzgroup->customdata = wwrapper; wwrapper->gizmo = WM_gizmo_new("GIZMO_GT_arrow_3d", gzgroup, nullptr); diff --git a/source/blender/editors/space_view3d/view3d_gizmo_light.cc b/source/blender/editors/space_view3d/view3d_gizmo_light.cc index 0370448c6b6..1f6f9b6364b 100644 --- a/source/blender/editors/space_view3d/view3d_gizmo_light.cc +++ b/source/blender/editors/space_view3d/view3d_gizmo_light.cc @@ -162,8 +162,7 @@ static bool WIDGETGROUP_light_spot_poll(const bContext *C, wmGizmoGroupType * /* static void WIDGETGROUP_light_spot_setup(const bContext *C, wmGizmoGroup *gzgroup) { - LightSpotWidgetGroup *ls_gzgroup = static_cast( - MEM_mallocN(sizeof(LightSpotWidgetGroup), __func__)); + LightSpotWidgetGroup *ls_gzgroup = MEM_mallocN(__func__); gzgroup->customdata = ls_gzgroup; @@ -322,8 +321,7 @@ static bool WIDGETGROUP_light_point_poll(const bContext *C, wmGizmoGroupType * / static void WIDGETGROUP_light_point_setup(const bContext *C, wmGizmoGroup *gzgroup) { - wmGizmoWrapper *wwrapper = static_cast( - MEM_mallocN(sizeof(wmGizmoWrapper), __func__)); + wmGizmoWrapper *wwrapper = MEM_mallocN(__func__); wwrapper->gizmo = WM_gizmo_new("GIZMO_GT_cage_2d", gzgroup, nullptr); /* Point radius gizmo. */ wmGizmo *gz = wwrapper->gizmo; @@ -446,8 +444,7 @@ static bool WIDGETGROUP_light_area_poll(const bContext *C, wmGizmoGroupType * /* static void WIDGETGROUP_light_area_setup(const bContext * /*C*/, wmGizmoGroup *gzgroup) { - wmGizmoWrapper *wwrapper = static_cast( - MEM_mallocN(sizeof(wmGizmoWrapper), __func__)); + wmGizmoWrapper *wwrapper = MEM_mallocN(__func__); wwrapper->gizmo = WM_gizmo_new("GIZMO_GT_cage_2d", gzgroup, nullptr); wmGizmo *gz = wwrapper->gizmo; RNA_enum_set(gz->ptr, "transform", ED_GIZMO_CAGE_XFORM_FLAG_SCALE); @@ -542,8 +539,7 @@ static bool WIDGETGROUP_light_target_poll(const bContext *C, wmGizmoGroupType * static void WIDGETGROUP_light_target_setup(const bContext * /*C*/, wmGizmoGroup *gzgroup) { - wmGizmoWrapper *wwrapper = static_cast( - MEM_mallocN(sizeof(wmGizmoWrapper), __func__)); + wmGizmoWrapper *wwrapper = MEM_mallocN(__func__); wwrapper->gizmo = WM_gizmo_new("GIZMO_GT_move_3d", gzgroup, nullptr); wmGizmo *gz = wwrapper->gizmo; diff --git a/source/blender/editors/space_view3d/view3d_gizmo_navigate.cc b/source/blender/editors/space_view3d/view3d_gizmo_navigate.cc index 33e600d830d..208e142d2ae 100644 --- a/source/blender/editors/space_view3d/view3d_gizmo_navigate.cc +++ b/source/blender/editors/space_view3d/view3d_gizmo_navigate.cc @@ -162,8 +162,7 @@ static bool WIDGETGROUP_navigate_poll(const bContext *C, wmGizmoGroupType * /*gz static void WIDGETGROUP_navigate_setup(const bContext *C, wmGizmoGroup *gzgroup) { - NavigateWidgetGroup *navgroup = static_cast( - MEM_callocN(sizeof(NavigateWidgetGroup), __func__)); + NavigateWidgetGroup *navgroup = MEM_callocN(__func__); wmOperatorType *ot_view_axis = WM_operatortype_find("VIEW3D_OT_view_axis", true); wmOperatorType *ot_view_camera = WM_operatortype_find("VIEW3D_OT_view_camera", true); diff --git a/source/blender/editors/space_view3d/view3d_gizmo_ruler.cc b/source/blender/editors/space_view3d/view3d_gizmo_ruler.cc index 7ba2c5ed5ba..53fc5db505d 100644 --- a/source/blender/editors/space_view3d/view3d_gizmo_ruler.cc +++ b/source/blender/editors/space_view3d/view3d_gizmo_ruler.cc @@ -555,7 +555,7 @@ static bool view3d_ruler_to_gpencil(bContext *C, wmGizmoGroup *gzgroup) int j; /* allocate memory for a new stroke */ - gps = (bGPDstroke *)MEM_callocN(sizeof(bGPDstroke), "gp_stroke"); + gps = MEM_callocN("gp_stroke"); if (ruler_item->flag & RULERITEM_USE_ANGLE) { gps->totpoints = 3; pt = gps->points = (bGPDspoint *)MEM_callocN(sizeof(bGPDspoint) * gps->totpoints, diff --git a/source/blender/editors/space_view3d/view3d_gizmo_tool_generic.cc b/source/blender/editors/space_view3d/view3d_gizmo_tool_generic.cc index 7c9a46557d6..774fd32683e 100644 --- a/source/blender/editors/space_view3d/view3d_gizmo_tool_generic.cc +++ b/source/blender/editors/space_view3d/view3d_gizmo_tool_generic.cc @@ -115,8 +115,7 @@ static wmGizmo *tool_generic_create_gizmo(const bContext *C, wmGizmoGroup *gzgro static void WIDGETGROUP_tool_generic_setup(const bContext *C, wmGizmoGroup *gzgroup) { - wmGizmoWrapper *wwrapper = static_cast( - MEM_mallocN(sizeof(wmGizmoWrapper), __func__)); + wmGizmoWrapper *wwrapper = MEM_mallocN(__func__); wwrapper->gizmo = tool_generic_create_gizmo(C, gzgroup); gzgroup->customdata = wwrapper; diff --git a/source/blender/editors/space_view3d/view3d_navigate_smoothview.cc b/source/blender/editors/space_view3d/view3d_navigate_smoothview.cc index a6998e6cb11..49c7465d4d9 100644 --- a/source/blender/editors/space_view3d/view3d_navigate_smoothview.cc +++ b/source/blender/editors/space_view3d/view3d_navigate_smoothview.cc @@ -344,8 +344,7 @@ void ED_view3d_smooth_view_ex( /* Keep track of running timer! */ if (rv3d->sms == nullptr) { - rv3d->sms = static_cast( - MEM_mallocN(sizeof(SmoothView3DStore), "smoothview v3d")); + rv3d->sms = MEM_mallocN("smoothview v3d"); } *rv3d->sms = sms; if (rv3d->smooth_timer) { diff --git a/source/blender/editors/space_view3d/view3d_utils.cc b/source/blender/editors/space_view3d/view3d_utils.cc index a5a6deaae70..86a981dba50 100644 --- a/source/blender/editors/space_view3d/view3d_utils.cc +++ b/source/blender/editors/space_view3d/view3d_utils.cc @@ -809,7 +809,7 @@ bool ED_view3d_camera_lock_undo_grouped_push(const char *str, static void view3d_boxview_clip(ScrArea *area) { - BoundBox *bb = static_cast(MEM_callocN(sizeof(BoundBox), "clipbb")); + BoundBox *bb = MEM_callocN("clipbb"); float clip[6][4]; float x1 = 0.0f, y1 = 0.0f, z1 = 0.0f, ofs[3] = {0.0f, 0.0f, 0.0f}; diff --git a/source/blender/editors/space_view3d/view3d_view.cc b/source/blender/editors/space_view3d/view3d_view.cc index 529af44857b..c28a5fca080 100644 --- a/source/blender/editors/space_view3d/view3d_view.cc +++ b/source/blender/editors/space_view3d/view3d_view.cc @@ -883,7 +883,7 @@ static bool view3d_localview_init(const Depsgraph *depsgraph, } } - v3d->localvd = static_cast(MEM_mallocN(sizeof(View3D), "localview")); + v3d->localvd = MEM_mallocN("localview"); *v3d->localvd = blender::dna::shallow_copy(*v3d); v3d->local_view_uid = local_view_bit; @@ -896,8 +896,7 @@ static bool view3d_localview_init(const Depsgraph *depsgraph, Object *camera_old = nullptr; float dist_new, ofs_new[3]; - rv3d->localvd = static_cast( - MEM_mallocN(sizeof(RegionView3D), "localview region")); + rv3d->localvd = MEM_mallocN("localview region"); memcpy(rv3d->localvd, rv3d, sizeof(RegionView3D)); if (frame_selected) { diff --git a/source/blender/editors/transform/transform_convert.cc b/source/blender/editors/transform/transform_convert.cc index e7498cc1e20..fd770ba517e 100644 --- a/source/blender/editors/transform/transform_convert.cc +++ b/source/blender/editors/transform/transform_convert.cc @@ -457,8 +457,7 @@ TransDataCurveHandleFlags *initTransDataCurveHandles(TransData *td, BezTriple *b { TransDataCurveHandleFlags *hdata; td->flag |= TD_BEZTRIPLE; - hdata = td->hdata = static_cast( - MEM_mallocN(sizeof(TransDataCurveHandleFlags), "CuHandle Data")); + hdata = td->hdata = MEM_mallocN("CuHandle Data"); hdata->ih1 = bezt->h1; hdata->h1 = &bezt->h1; hdata->ih2 = bezt->h2; /* In case the second is not selected. */ @@ -827,8 +826,7 @@ static void init_TransDataContainers(TransInfo *t, Object *obact, Span objects = local_objects; } - t->data_container = static_cast( - MEM_callocN(sizeof(*t->data_container) * objects.size(), __func__)); + t->data_container = MEM_calloc_arrayN(objects.size(), __func__); t->data_container_len = objects.size(); for (int i = 0; i < objects.size(); i++) { diff --git a/source/blender/editors/transform/transform_convert_armature.cc b/source/blender/editors/transform/transform_convert_armature.cc index c12fbbef1ab..494db56448a 100644 --- a/source/blender/editors/transform/transform_convert_armature.cc +++ b/source/blender/editors/transform/transform_convert_armature.cc @@ -640,8 +640,8 @@ static void createTransPose(bContext * /*C*/, TransInfo *t) } } - PoseInitData_Mirror *pid = static_cast( - MEM_mallocN((total_mirrored + 1) * sizeof(PoseInitData_Mirror), "PoseInitData_Mirror")); + PoseInitData_Mirror *pid = MEM_malloc_arrayN((total_mirrored + 1), + "PoseInitData_Mirror"); /* Trick to terminate iteration. */ pid[total_mirrored].pchan = nullptr; @@ -780,8 +780,7 @@ static void createTransArmatureVerts(bContext * /*C*/, TransInfo *t) } if (mirror) { - BoneInitData *bid = static_cast( - MEM_mallocN((total_mirrored + 1) * sizeof(BoneInitData), "BoneInitData")); + BoneInitData *bid = MEM_malloc_arrayN((total_mirrored + 1), "BoneInitData"); /* Trick to terminate iteration. */ bid[total_mirrored].bone = nullptr; diff --git a/source/blender/editors/transform/transform_convert_mesh.cc b/source/blender/editors/transform/transform_convert_mesh.cc index 4ac04d9839f..3821cc71395 100644 --- a/source/blender/editors/transform/transform_convert_mesh.cc +++ b/source/blender/editors/transform/transform_convert_mesh.cc @@ -354,8 +354,7 @@ static void mesh_customdatacorrect_init_container_merge_group(TransDataContainer * to one of the sliding vertices. */ /* Over allocate, only 'math' layers are indexed. */ - int *customdatalayer_map = static_cast( - MEM_mallocN(sizeof(int) * bm->ldata.totlayer, __func__)); + int *customdatalayer_map = MEM_malloc_arrayN(bm->ldata.totlayer, __func__); int layer_math_map_len = 0; for (int i = 0; i < bm->ldata.totlayer; i++) { if (CustomData_layer_has_math(&bm->ldata, i)) { @@ -770,8 +769,7 @@ void transform_convert_mesh_islands_calc(BMEditMesh *em, if (!has_only_single_islands) { if (em->selectmode & (SCE_SELECT_VERTEX | SCE_SELECT_EDGE)) { - groups_array = static_cast( - MEM_mallocN(sizeof(*groups_array) * bm->totedgesel, __func__)); + groups_array = MEM_malloc_arrayN(bm->totedgesel, __func__); data.island_tot = BM_mesh_calc_edge_groups( bm, groups_array, &group_index, nullptr, nullptr, BM_ELEM_SELECT); @@ -779,8 +777,7 @@ void transform_convert_mesh_islands_calc(BMEditMesh *em, itype = BM_VERTS_OF_EDGE; } else { /* `bm->selectmode & SCE_SELECT_FACE`. */ - groups_array = static_cast( - MEM_mallocN(sizeof(*groups_array) * bm->totfacesel, __func__)); + groups_array = MEM_malloc_arrayN(bm->totfacesel, __func__); data.island_tot = BM_mesh_calc_face_groups( bm, groups_array, &group_index, nullptr, nullptr, nullptr, BM_ELEM_SELECT, BM_VERT); @@ -1203,7 +1200,7 @@ void transform_convert_mesh_mirrordata_calc(BMEditMesh *em, BMIter iter; int i, flag, totvert = bm->totvert; - vert_map = static_cast(MEM_callocN(totvert * sizeof(*vert_map), __func__)); + vert_map = MEM_calloc_arrayN(totvert, __func__); float select_sum[3] = {0}; BM_ITER_MESH_INDEX (eve, &iter, bm, BM_VERTS_OF_MESH, i) { @@ -1567,9 +1564,9 @@ static void createTransEditVerts(bContext * /*C*/, TransInfo *t) int *dists_index = nullptr; float *dists = nullptr; if (prop_mode & T_PROP_CONNECTED) { - dists = static_cast(MEM_mallocN(bm->totvert * sizeof(float), __func__)); + dists = MEM_malloc_arrayN(bm->totvert, __func__); if (is_island_center) { - dists_index = static_cast(MEM_mallocN(bm->totvert * sizeof(int), __func__)); + dists_index = MEM_malloc_arrayN(bm->totvert, __func__); } transform_convert_mesh_connectivity_distance(em->bm, mtx, dists, dists_index); } diff --git a/source/blender/editors/transform/transform_convert_mesh_skin.cc b/source/blender/editors/transform/transform_convert_mesh_skin.cc index f5c92326a02..9f0897a234a 100644 --- a/source/blender/editors/transform/transform_convert_mesh_skin.cc +++ b/source/blender/editors/transform/transform_convert_mesh_skin.cc @@ -139,9 +139,9 @@ static void createTransMeshSkin(bContext * /*C*/, TransInfo *t) int *dists_index = nullptr; float *dists = nullptr; if (prop_mode & T_PROP_CONNECTED) { - dists = static_cast(MEM_mallocN(bm->totvert * sizeof(float), __func__)); + dists = MEM_malloc_arrayN(bm->totvert, __func__); if (is_island_center) { - dists_index = static_cast(MEM_mallocN(bm->totvert * sizeof(int), __func__)); + dists_index = MEM_malloc_arrayN(bm->totvert, __func__); } transform_convert_mesh_connectivity_distance(em->bm, mtx, dists, dists_index); } diff --git a/source/blender/editors/transform/transform_convert_mesh_uv.cc b/source/blender/editors/transform/transform_convert_mesh_uv.cc index 38b42d50851..3d94bb11cc8 100644 --- a/source/blender/editors/transform/transform_convert_mesh_uv.cc +++ b/source/blender/editors/transform/transform_convert_mesh_uv.cc @@ -281,8 +281,7 @@ static void createTransUVs(bContext *C, TransInfo *t) continue; } - island_center = static_cast( - MEM_callocN(sizeof(*island_center) * elementmap->total_islands, __func__)); + island_center = MEM_calloc_arrayN(elementmap->total_islands, __func__); } BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) { diff --git a/source/blender/editors/transform/transform_convert_mesh_vert_cdata.cc b/source/blender/editors/transform/transform_convert_mesh_vert_cdata.cc index 96829cde0c6..817095a53d1 100644 --- a/source/blender/editors/transform/transform_convert_mesh_vert_cdata.cc +++ b/source/blender/editors/transform/transform_convert_mesh_vert_cdata.cc @@ -134,9 +134,9 @@ static void createTransMeshVertCData(bContext * /*C*/, TransInfo *t) int *dists_index = nullptr; float *dists = nullptr; if (prop_mode & T_PROP_CONNECTED) { - dists = static_cast(MEM_mallocN(bm->totvert * sizeof(float), __func__)); + dists = MEM_malloc_arrayN(bm->totvert, __func__); if (is_island_center) { - dists_index = static_cast(MEM_mallocN(bm->totvert * sizeof(int), __func__)); + dists_index = MEM_malloc_arrayN(bm->totvert, __func__); } transform_convert_mesh_connectivity_distance(em->bm, mtx, dists, dists_index); } diff --git a/source/blender/editors/transform/transform_convert_object.cc b/source/blender/editors/transform/transform_convert_object.cc index 39d594ca614..d54bbbbb956 100644 --- a/source/blender/editors/transform/transform_convert_object.cc +++ b/source/blender/editors/transform/transform_convert_object.cc @@ -521,7 +521,7 @@ static void createTransObject(bContext *C, TransInfo *t) td = tc->data = MEM_calloc_arrayN(tc->data_len, "TransOb"); tx = tc->data_ext = MEM_calloc_arrayN(tc->data_len, "TransObExtension"); - TransDataObject *tdo = static_cast(MEM_callocN(sizeof(*tdo), __func__)); + TransDataObject *tdo = MEM_callocN(__func__); t->custom.type.data = tdo; t->custom.type.free_cb = freeTransObjectCustomData; diff --git a/source/blender/editors/transform/transform_gizmo_3d_cage.cc b/source/blender/editors/transform/transform_gizmo_3d_cage.cc index 622a5f842a1..a5d2afb4d4e 100644 --- a/source/blender/editors/transform/transform_gizmo_3d_cage.cc +++ b/source/blender/editors/transform/transform_gizmo_3d_cage.cc @@ -59,8 +59,7 @@ static bool WIDGETGROUP_xform_cage_poll(const bContext *C, wmGizmoGroupType *gzg static void WIDGETGROUP_xform_cage_setup(const bContext * /*C*/, wmGizmoGroup *gzgroup) { - XFormCageWidgetGroup *xgzgroup = static_cast( - MEM_mallocN(sizeof(XFormCageWidgetGroup), __func__)); + XFormCageWidgetGroup *xgzgroup = MEM_mallocN(__func__); const wmGizmoType *gzt_cage = WM_gizmotype_find("GIZMO_GT_cage_3d", true); xgzgroup->gizmo = WM_gizmo_new_ptr(gzt_cage, gzgroup, nullptr); wmGizmo *gz = xgzgroup->gizmo; diff --git a/source/blender/editors/transform/transform_gizmo_3d_shear.cc b/source/blender/editors/transform/transform_gizmo_3d_shear.cc index 6592db38bf2..c2b329625ae 100644 --- a/source/blender/editors/transform/transform_gizmo_3d_shear.cc +++ b/source/blender/editors/transform/transform_gizmo_3d_shear.cc @@ -61,8 +61,7 @@ static bool WIDGETGROUP_xform_shear_poll(const bContext *C, wmGizmoGroupType *gz static void WIDGETGROUP_xform_shear_setup(const bContext * /*C*/, wmGizmoGroup *gzgroup) { - XFormShearWidgetGroup *xgzgroup = static_cast( - MEM_mallocN(sizeof(XFormShearWidgetGroup), __func__)); + XFormShearWidgetGroup *xgzgroup = MEM_mallocN(__func__); const wmGizmoType *gzt_arrow = WM_gizmotype_find("GIZMO_GT_arrow_3d", true); wmOperatorType *ot_shear = WM_operatortype_find("TRANSFORM_OT_shear", true); diff --git a/source/blender/editors/transform/transform_mode_bend.cc b/source/blender/editors/transform/transform_mode_bend.cc index 493ab9aa2e7..f5e50d4304d 100644 --- a/source/blender/editors/transform/transform_mode_bend.cc +++ b/source/blender/editors/transform/transform_mode_bend.cc @@ -296,7 +296,7 @@ static void initBend(TransInfo *t, wmOperator * /*op*/) } calculateCenterLocal(t, t->center_global); - data = static_cast(MEM_callocN(sizeof(*data), __func__)); + data = MEM_callocN(__func__); curs = t->scene->cursor.location; copy_v3_v3(data->warp_sta, curs); diff --git a/source/blender/editors/transform/transform_mode_edge_slide.cc b/source/blender/editors/transform/transform_mode_edge_slide.cc index 6afa0f8e619..ed107f136ee 100644 --- a/source/blender/editors/transform/transform_mode_edge_slide.cc +++ b/source/blender/editors/transform/transform_mode_edge_slide.cc @@ -85,7 +85,7 @@ struct EdgeSlideData { }; struct EdgeSlideParams { - wmOperator *op = nullptr; + wmOperator *op; float perc; /** When un-clamped - use this index: #TransDataEdgeSlideVert.dir_side. */ @@ -278,7 +278,7 @@ static void calcEdgeSlide_mval_range(TransInfo *t, if (use_calc_direction) { loop_dir = MEM_calloc_arrayN(loop_nr, "sv loop_dir"); - loop_maxdist = static_cast(MEM_mallocN(sizeof(float) * loop_nr, "sv loop_maxdist")); + loop_maxdist = MEM_malloc_arrayN(loop_nr, "sv loop_maxdist"); copy_vn_fl(loop_maxdist, loop_nr, FLT_MAX); } @@ -884,7 +884,7 @@ static void initEdgeSlide_ex(TransInfo *t, t->mode = TFM_EDGE_SLIDE; { - EdgeSlideParams *slp = static_cast(MEM_callocN(sizeof(*slp), __func__)); + EdgeSlideParams *slp = MEM_callocN(__func__); slp->op = op; slp->use_even = use_even; slp->flipped = flipped; diff --git a/source/blender/editors/transform/transform_mode_tosphere.cc b/source/blender/editors/transform/transform_mode_tosphere.cc index 6d7d6ac5b9b..f89fdb1e05b 100644 --- a/source/blender/editors/transform/transform_mode_tosphere.cc +++ b/source/blender/editors/transform/transform_mode_tosphere.cc @@ -212,7 +212,7 @@ static void initToSphere(TransInfo *t, wmOperator * /*op*/) t->num.val_flag[0] |= NUM_NULL_ONE | NUM_NO_NEGATIVE; - ToSphereInfo *data = static_cast(MEM_callocN(sizeof(*data), __func__)); + ToSphereInfo *data = MEM_callocN(__func__); t->custom.mode.data = data; t->custom.mode.use_free = true; diff --git a/source/blender/editors/transform/transform_mode_vert_slide.cc b/source/blender/editors/transform/transform_mode_vert_slide.cc index 3f2597151c0..9b3b1b42616 100644 --- a/source/blender/editors/transform/transform_mode_vert_slide.cc +++ b/source/blender/editors/transform/transform_mode_vert_slide.cc @@ -569,7 +569,7 @@ static void initVertSlide_ex(TransInfo *t, bool use_even, bool flipped, bool use t->mode = TFM_VERT_SLIDE; { - VertSlideParams *slp = static_cast(MEM_callocN(sizeof(*slp), __func__)); + VertSlideParams *slp = MEM_callocN(__func__); slp->use_even = use_even; slp->flipped = flipped; slp->perc = 0.0f; diff --git a/source/blender/editors/transform/transform_orientations.cc b/source/blender/editors/transform/transform_orientations.cc index 57c4893354f..d5d6af6c2a1 100644 --- a/source/blender/editors/transform/transform_orientations.cc +++ b/source/blender/editors/transform/transform_orientations.cc @@ -521,8 +521,7 @@ TransformOrientation *addMatrixSpace(bContext *C, /* If not, create a new one. */ if (ts == nullptr) { - ts = static_cast( - MEM_callocN(sizeof(TransformOrientation), "UserTransSpace from matrix")); + ts = MEM_callocN("UserTransSpace from matrix"); BLI_addtail(transform_orientations, ts); STRNCPY(ts->name, name); } diff --git a/source/blender/editors/util/ed_transverts.cc b/source/blender/editors/util/ed_transverts.cc index 560e387f5e1..a995eb08f72 100644 --- a/source/blender/editors/util/ed_transverts.cc +++ b/source/blender/editors/util/ed_transverts.cc @@ -526,8 +526,7 @@ void ED_transverts_create_from_obedit(TransVertStore *tvs, const Object *obedit, memory); MutableSpan positions = pointcloud->positions_for_write(); - tvs->transverts = static_cast( - MEM_calloc_arrayN(selection.size(), sizeof(TransVert), __func__)); + tvs->transverts = MEM_calloc_arrayN(selection.size(), __func__); tvs->transverts_tot = selection.size(); selection.foreach_index(GrainSize(1024), [&](const int64_t i, const int64_t pos) { diff --git a/source/blender/editors/uvedit/uvedit_islands.cc b/source/blender/editors/uvedit/uvedit_islands.cc index 141d4f5ffa7..9cc87b95ab6 100644 --- a/source/blender/editors/uvedit/uvedit_islands.cc +++ b/source/blender/editors/uvedit/uvedit_islands.cc @@ -120,8 +120,7 @@ int bm_mesh_calc_uv_islands(const Scene *scene, int island_added = 0; BM_mesh_elem_table_ensure(bm, BM_FACE); - int *groups_array = static_cast( - MEM_mallocN(sizeof(*groups_array) * size_t(bm->totface), __func__)); + int *groups_array = MEM_malloc_arrayN(bm->totface, __func__); int(*group_index)[2]; @@ -150,13 +149,13 @@ int bm_mesh_calc_uv_islands(const Scene *scene, for (int i = 0; i < group_len; i++) { const int faces_start = group_index[i][0]; const int faces_len = group_index[i][1]; - BMFace **faces = static_cast(MEM_mallocN(sizeof(*faces) * faces_len, __func__)); + BMFace **faces = MEM_malloc_arrayN(faces_len, __func__); for (int j = 0; j < faces_len; j++) { faces[j] = BM_face_at_index(bm, groups_array[faces_start + j]); } - FaceIsland *island = static_cast(MEM_callocN(sizeof(*island), __func__)); + FaceIsland *island = MEM_callocN(__func__); island->faces = faces; island->faces_len = faces_len; island->offsets = uv_offsets; diff --git a/source/blender/editors/uvedit/uvedit_select.cc b/source/blender/editors/uvedit/uvedit_select.cc index bb307c482a3..5534431efd7 100644 --- a/source/blender/editors/uvedit/uvedit_select.cc +++ b/source/blender/editors/uvedit/uvedit_select.cc @@ -1853,8 +1853,8 @@ static void uv_select_linked_multi(Scene *scene, continue; } - stack = static_cast(MEM_mallocN(sizeof(*stack) * (bm->totface + 1), "UvLinkStack")); - flag = static_cast(MEM_callocN(sizeof(*flag) * bm->totface, "UvLinkFlag")); + stack = MEM_malloc_arrayN(bm->totface + 1, "UvLinkStack"); + flag = MEM_calloc_arrayN(bm->totface, "UvLinkFlag"); if (hit == nullptr) { /* Use existing selection */ @@ -4369,8 +4369,7 @@ static wmOperatorStatus uv_select_overlap(bContext *C, const bool extend) } } - UVOverlapData *overlap_data = static_cast( - MEM_mallocN(sizeof(UVOverlapData) * uv_tri_len, "UvOverlapData")); + UVOverlapData *overlap_data = MEM_malloc_arrayN(uv_tri_len, "UvOverlapData"); BVHTree *uv_tree = BLI_bvhtree_new(uv_tri_len, 0.0f, 4, 6); /* Use a global data index when inserting into the BVH. */ @@ -5058,8 +5057,7 @@ static wmOperatorStatus uv_select_similar_island_exec(bContext *C, wmOperator *o Vector objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data_with_uvs( scene, view_layer, nullptr); - ListBase *island_list_ptr = static_cast( - MEM_callocN(sizeof(*island_list_ptr) * objects.size(), __func__)); + ListBase *island_list_ptr = MEM_calloc_arrayN(objects.size(), __func__); int island_list_len = 0; const bool face_selected = !(scene->toolsettings->uv_flag & UV_SYNC_SELECTION); @@ -5286,7 +5284,7 @@ BMFace **ED_uvedit_selected_faces(const Scene *scene, BMesh *bm, int len_max, in CLAMP_MAX(len_max, bm->totface); int faces_len = 0; - BMFace **faces = static_cast(MEM_mallocN(sizeof(*faces) * len_max, __func__)); + BMFace **faces = MEM_malloc_arrayN(len_max, __func__); BMIter iter; BMFace *f; @@ -5316,7 +5314,7 @@ BMLoop **ED_uvedit_selected_edges(const Scene *scene, BMesh *bm, int len_max, in CLAMP_MAX(len_max, bm->totloop); int edges_len = 0; - BMLoop **edges = static_cast(MEM_mallocN(sizeof(*edges) * len_max, __func__)); + BMLoop **edges = MEM_malloc_arrayN(len_max, __func__); BMIter iter; BMFace *f; @@ -5375,7 +5373,7 @@ BMLoop **ED_uvedit_selected_verts(const Scene *scene, BMesh *bm, int len_max, in CLAMP_MAX(len_max, bm->totloop); int verts_len = 0; - BMLoop **verts = static_cast(MEM_mallocN(sizeof(*verts) * len_max, __func__)); + BMLoop **verts = MEM_malloc_arrayN(len_max, __func__); BMIter iter; BMFace *f; diff --git a/source/blender/editors/uvedit/uvedit_smart_stitch.cc b/source/blender/editors/uvedit/uvedit_smart_stitch.cc index 72cb5b536b6..ce0cd7006d1 100644 --- a/source/blender/editors/uvedit/uvedit_smart_stitch.cc +++ b/source/blender/editors/uvedit/uvedit_smart_stitch.cc @@ -240,8 +240,7 @@ static StitchPreviewer *stitch_preview_init() { StitchPreviewer *stitch_preview; - stitch_preview = static_cast( - MEM_mallocN(sizeof(StitchPreviewer), "stitch_previewer")); + stitch_preview = MEM_mallocN("stitch_previewer"); stitch_preview->preview_polys = nullptr; stitch_preview->preview_stitchable = nullptr; stitch_preview->preview_unstitchable = nullptr; @@ -985,8 +984,8 @@ static int stitch_process_data(StitchStateContainer *ssc, preview_position[i].data_position = STITCH_NO_PREVIEW; } - island_stitch_data = static_cast(MEM_callocN( - sizeof(*island_stitch_data) * state->element_map->total_islands, "stitch_island_data")); + island_stitch_data = MEM_calloc_arrayN(state->element_map->total_islands, + "stitch_island_data"); if (!island_stitch_data) { return 0; } @@ -1157,8 +1156,7 @@ static int stitch_process_data(StitchStateContainer *ssc, /* initialize the preview buffers */ preview->preview_polys = static_cast( MEM_mallocN(sizeof(float[2]) * preview->preview_uvs, "tri_uv_stitch_prev")); - preview->uvs_per_polygon = static_cast( - MEM_mallocN(sizeof(*preview->uvs_per_polygon) * preview->num_polys, "tri_uv_stitch_prev")); + preview->uvs_per_polygon = MEM_malloc_arrayN(preview->num_polys, "tri_uv_stitch_prev"); preview->static_tris = static_cast( MEM_mallocN((sizeof(float[6]) * state->tris_per_island[ssc->static_island]), @@ -1882,14 +1880,11 @@ static StitchState *stitch_init(bContext *C, /* internal uvs need no normals but it is hard and slow to keep a map of * normals only for boundary uvs, so allocating for all uvs. * Times 2 because each `float[2]` is stored as `{n[2 * i], n[2*i + 1]}`. */ - state->normals = static_cast( - MEM_callocN(sizeof(*state->normals) * 2 * unique_uvs, "uv_stitch_normals")); - state->map = map = static_cast( - MEM_mallocN(sizeof(*map) * state->element_map->total_uvs, "uv_stitch_unique_map")); + state->normals = MEM_calloc_arrayN(2 * unique_uvs, "uv_stitch_normals"); + state->map = map = MEM_malloc_arrayN(state->element_map->total_uvs, "uv_stitch_unique_map"); /* Allocate the edge stack */ edge_hash = BLI_ghash_new(uv_edge_hash, uv_edge_compare, "stitch_edge_hash"); - all_edges = static_cast( - MEM_mallocN(sizeof(*all_edges) * state->element_map->total_uvs, "ssc_edges")); + all_edges = MEM_malloc_arrayN(state->element_map->total_uvs, "ssc_edges"); BLI_assert(!state->stitch_preview); /* Paranoia. */ if (!state->uvs || !map || !edge_hash || !all_edges) { @@ -1960,8 +1955,7 @@ static StitchState *stitch_init(bContext *C, } total_edges = BLI_ghash_len(edge_hash); - state->edges = edges = static_cast( - MEM_mallocN(sizeof(*edges) * total_edges, "stitch_edges")); + state->edges = edges = MEM_malloc_arrayN(total_edges, "stitch_edges"); /* I assume any system will be able to at least allocate an iterator :p */ if (!edges) { @@ -2124,8 +2118,8 @@ static StitchState *stitch_init(bContext *C, /***** initialize static island preview data *****/ - state->tris_per_island = static_cast(MEM_mallocN( - sizeof(*state->tris_per_island) * state->element_map->total_islands, "stitch island tris")); + state->tris_per_island = MEM_malloc_arrayN(state->element_map->total_islands, + "stitch island tris"); for (i = 0; i < state->element_map->total_islands; i++) { state->tris_per_island[i] = 0; } diff --git a/source/blender/editors/uvedit/uvedit_unwrap_ops.cc b/source/blender/editors/uvedit/uvedit_unwrap_ops.cc index cd0c23f7b87..ece1fdcbd02 100644 --- a/source/blender/editors/uvedit/uvedit_unwrap_ops.cc +++ b/source/blender/editors/uvedit/uvedit_unwrap_ops.cc @@ -902,8 +902,7 @@ static ParamHandle *construct_param_handle_subsurfed(const Scene *scene, const int *origPolyIndices = static_cast( CustomData_get_layer(&subdiv_mesh->face_data, CD_ORIGINDEX)); - faceMap = static_cast( - MEM_mallocN(subdiv_mesh->faces_num * sizeof(BMFace *), "unwrap_edit_face_map")); + faceMap = MEM_malloc_arrayN(subdiv_mesh->faces_num, "unwrap_edit_face_map"); BM_mesh_elem_index_ensure(em->bm, BM_VERT); BM_mesh_elem_table_ensure(em->bm, BM_EDGE | BM_FACE); @@ -913,8 +912,7 @@ static ParamHandle *construct_param_handle_subsurfed(const Scene *scene, faceMap[i] = BM_face_at_index(em->bm, origPolyIndices[i]); } - edgeMap = static_cast( - MEM_mallocN(subdiv_mesh->edges_num * sizeof(BMEdge *), "unwrap_edit_edge_map")); + edgeMap = MEM_malloc_arrayN(subdiv_mesh->edges_num, "unwrap_edit_edge_map"); /* map subsurfed edges to original editEdges */ for (int i = 0; i < subdiv_mesh->edges_num; i++) { @@ -2145,8 +2143,8 @@ void ED_uvedit_live_unwrap_begin(Scene *scene, Object *obedit, wmWindow *win_mod /* Create or increase size of g_live_unwrap.handles array */ if (g_live_unwrap.handles == nullptr) { g_live_unwrap.len_alloc = 32; - g_live_unwrap.handles = static_cast(MEM_mallocN( - sizeof(ParamHandle *) * g_live_unwrap.len_alloc, "uvedit_live_unwrap_liveHandles")); + g_live_unwrap.handles = MEM_malloc_arrayN(g_live_unwrap.len_alloc, + "uvedit_live_unwrap_liveHandles"); g_live_unwrap.len = 0; } if (g_live_unwrap.len >= g_live_unwrap.len_alloc) { @@ -3197,8 +3195,7 @@ static wmOperatorStatus smart_project_exec(bContext *C, wmOperator *op) const BMUVOffsets offsets = BM_uv_map_offsets_get(em->bm); BLI_assert(offsets.uv >= 0); - ThickFace *thick_faces = static_cast( - MEM_mallocN(sizeof(*thick_faces) * em->bm->totface, __func__)); + ThickFace *thick_faces = MEM_malloc_arrayN(em->bm->totface, __func__); uint thick_faces_len = 0; BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) { diff --git a/source/blender/geometry/intern/uv_parametrizer.cc b/source/blender/geometry/intern/uv_parametrizer.cc index af6314d5eac..88646b707d0 100644 --- a/source/blender/geometry/intern/uv_parametrizer.cc +++ b/source/blender/geometry/intern/uv_parametrizer.cc @@ -2367,7 +2367,7 @@ static void p_abf_setup_system(PAbfSystem *sys) sys->lambdaTriangle = MEM_calloc_arrayN(sys->nfaces, "ABFlambdatri"); sys->lambdaPlanar = MEM_calloc_arrayN(sys->ninterior, "ABFlamdaplane"); - sys->lambdaLength = (float *)MEM_mallocN(sizeof(float) * sys->ninterior, "ABFlambdalen"); + sys->lambdaLength = MEM_malloc_arrayN(sys->ninterior, "ABFlambdalen"); sys->J2dt = MEM_malloc_arrayN(size_t(sys->nangles), "ABFj2dt"); sys->bstar = MEM_malloc_arrayN(size_t(sys->nfaces), "ABFbstar"); diff --git a/source/blender/gpu/dummy/dummy_vertex_buffer.hh b/source/blender/gpu/dummy/dummy_vertex_buffer.hh index 4093d1c2250..5068cf92a5e 100644 --- a/source/blender/gpu/dummy/dummy_vertex_buffer.hh +++ b/source/blender/gpu/dummy/dummy_vertex_buffer.hh @@ -28,7 +28,7 @@ class DummyVertexBuffer : public VertBuf { void acquire_data() override { MEM_SAFE_FREE(data_); - data_ = (uchar *)MEM_mallocN(sizeof(uchar) * this->size_alloc_get(), __func__); + data_ = MEM_malloc_arrayN(this->size_alloc_get(), __func__); } void resize_data() override {} void release_data() override diff --git a/source/blender/gpu/intern/gpu_batch_utils.cc b/source/blender/gpu/intern/gpu_batch_utils.cc index 42d038f2339..ad65cdfad94 100644 --- a/source/blender/gpu/intern/gpu_batch_utils.cc +++ b/source/blender/gpu/intern/gpu_batch_utils.cc @@ -122,7 +122,7 @@ blender::gpu::Batch *GPU_batch_wire_from_poly_2d_encoded(const uchar *polys_flat /* Over alloc */ /* Lines are pairs of (x, y) byte locations packed into an int32_t. */ - int32_t *lines = static_cast(MEM_mallocN(sizeof(*lines) * polys_len, __func__)); + int32_t *lines = MEM_malloc_arrayN(polys_len, __func__); int32_t *lines_step = lines; const float range_uchar[2] = { diff --git a/source/blender/gpu/intern/gpu_index_buffer.cc b/source/blender/gpu/intern/gpu_index_buffer.cc index 5532f58a8b5..00aa3ee43b1 100644 --- a/source/blender/gpu/intern/gpu_index_buffer.cc +++ b/source/blender/gpu/intern/gpu_index_buffer.cc @@ -489,8 +489,7 @@ IndexBuf *GPU_indexbuf_build_from_memory(const GPUPrimType prim_type, const uint32_t indices_num = data_len * indices_per_primitive(prim_type); /* TODO: The need for this copy is meant to be temporary. The data should be uploaded directly to * the GPU here rather than copied to an array owned by the IBO first. */ - uint32_t *copy = static_cast( - MEM_malloc_arrayN(indices_num, sizeof(uint32_t), __func__)); + uint32_t *copy = MEM_malloc_arrayN(indices_num, __func__); threading::memory_bandwidth_bound_task(sizeof(uint32_t) * indices_num * 2, [&]() { array_utils::copy(Span(data, indices_num), MutableSpan(copy, indices_num)); }); diff --git a/source/blender/gpu/intern/gpu_material.cc b/source/blender/gpu/intern/gpu_material.cc index 2997e28345e..ad182465f8e 100644 --- a/source/blender/gpu/intern/gpu_material.cc +++ b/source/blender/gpu/intern/gpu_material.cc @@ -155,8 +155,7 @@ GPUTexture **gpu_material_sky_texture_layer_set( UNUSED_VARS_NDEBUG(width, height); if (mat->sky_builder == nullptr) { - mat->sky_builder = static_cast( - MEM_mallocN(sizeof(GPUSkyBuilder), "GPUSkyBuilder")); + mat->sky_builder = MEM_mallocN("GPUSkyBuilder"); mat->sky_builder->current_layer = 0; } @@ -186,8 +185,7 @@ GPUTexture **gpu_material_ramp_texture_row_set(GPUMaterial *mat, UNUSED_VARS_NDEBUG(size); if (mat->coba_builder == nullptr) { - mat->coba_builder = static_cast( - MEM_mallocN(sizeof(GPUColorBandBuilder), "GPUColorBandBuilder")); + mat->coba_builder = MEM_mallocN("GPUColorBandBuilder"); mat->coba_builder->current_layer = 0; } diff --git a/source/blender/gpu/intern/gpu_select_pick.cc b/source/blender/gpu/intern/gpu_select_pick.cc index c4119cf08aa..722a0be930f 100644 --- a/source/blender/gpu/intern/gpu_select_pick.cc +++ b/source/blender/gpu/intern/gpu_select_pick.cc @@ -374,8 +374,7 @@ void gpu_select_pick_begin(GPUSelectBuffer *buffer, const rcti *input, eGPUSelec } else { /* Set to 0xff for #SELECT_ID_NONE. */ - ps->nearest.rect_id = static_cast( - MEM_mallocN(sizeof(uint) * ps->dst.rect_len, __func__)); + ps->nearest.rect_id = MEM_malloc_arrayN(ps->dst.rect_len, __func__); memset(ps->nearest.rect_id, 0xff, sizeof(uint) * ps->dst.rect_len); } } diff --git a/source/blender/gpu/intern/gpu_viewport.cc b/source/blender/gpu/intern/gpu_viewport.cc index d7bf686eebf..0838a21f51c 100644 --- a/source/blender/gpu/intern/gpu_viewport.cc +++ b/source/blender/gpu/intern/gpu_viewport.cc @@ -99,8 +99,7 @@ bool GPU_viewport_do_update(GPUViewport *viewport) GPUViewport *GPU_viewport_create() { - GPUViewport *viewport = static_cast( - MEM_callocN(sizeof(GPUViewport), "GPUViewport")); + GPUViewport *viewport = MEM_callocN("GPUViewport"); viewport->do_color_management = false; viewport->size[0] = viewport->size[1] = -1; viewport->active_view = 0; diff --git a/source/blender/gpu/metal/mtl_vertex_buffer.mm b/source/blender/gpu/metal/mtl_vertex_buffer.mm index 2005c6453a1..eb9fdb1f707 100644 --- a/source/blender/gpu/metal/mtl_vertex_buffer.mm +++ b/source/blender/gpu/metal/mtl_vertex_buffer.mm @@ -26,7 +26,7 @@ void MTLVertBuf::acquire_data() data_ = nullptr; } else { - data_ = (uchar *)MEM_mallocN(sizeof(uchar) * this->size_alloc_get(), __func__); + data_ = MEM_malloc_arrayN(this->size_alloc_get(), __func__); } } diff --git a/source/blender/gpu/opengl/gl_shader_interface.cc b/source/blender/gpu/opengl/gl_shader_interface.cc index 656943cb1c8..fe354f79cdc 100644 --- a/source/blender/gpu/opengl/gl_shader_interface.cc +++ b/source/blender/gpu/opengl/gl_shader_interface.cc @@ -254,7 +254,7 @@ GLShaderInterface::GLShaderInterface(GLuint program) /* Bit set to true if uniform comes from a uniform block. */ BLI_bitmap *uniforms_from_blocks = BLI_BITMAP_NEW(active_uniform_len, __func__); /* Set uniforms from block for exclusion. */ - GLint *ubo_uni_ids = (GLint *)MEM_mallocN(sizeof(GLint) * max_ubo_uni_len, __func__); + GLint *ubo_uni_ids = MEM_malloc_arrayN(max_ubo_uni_len, __func__); for (int i = 0; i < ubo_len; i++) { GLint ubo_uni_len; glGetActiveUniformBlockiv(program, i, GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS, &ubo_uni_len); @@ -266,7 +266,7 @@ GLShaderInterface::GLShaderInterface(GLuint program) MEM_freeN(ubo_uni_ids); int input_tot_len = attr_len + ubo_len + uniform_len + ssbo_len; - inputs_ = (ShaderInput *)MEM_callocN(sizeof(ShaderInput) * input_tot_len, __func__); + inputs_ = MEM_calloc_arrayN(input_tot_len, __func__); const uint32_t name_buffer_len = attr_len * max_attr_name_len + ubo_len * max_ubo_name_len + uniform_len * max_uniform_name_len + diff --git a/source/blender/gpu/opengl/gl_vertex_buffer.cc b/source/blender/gpu/opengl/gl_vertex_buffer.cc index a30b06bcc3c..877951a8cc9 100644 --- a/source/blender/gpu/opengl/gl_vertex_buffer.cc +++ b/source/blender/gpu/opengl/gl_vertex_buffer.cc @@ -22,7 +22,7 @@ void GLVertBuf::acquire_data() /* Discard previous data if any. */ MEM_SAFE_FREE(data_); - data_ = (uchar *)MEM_mallocN(sizeof(uchar) * this->size_alloc_get(), __func__); + data_ = MEM_malloc_arrayN(this->size_alloc_get(), __func__); } void GLVertBuf::resize_data() diff --git a/source/blender/gpu/tests/texture_test.cc b/source/blender/gpu/tests/texture_test.cc index 6361e532d60..8cb8940759e 100644 --- a/source/blender/gpu/tests/texture_test.cc +++ b/source/blender/gpu/tests/texture_test.cc @@ -308,7 +308,7 @@ GPU_TEST(texture_copy) template static DataType *generate_test_data(size_t data_len) { - DataType *data = static_cast(MEM_mallocN(data_len * sizeof(DataType), __func__)); + DataType *data = MEM_malloc_arrayN(data_len, __func__); for (int i : IndexRange(data_len)) { if (std::is_same()) { data[i] = (DataType)(i % 8) / 8.0f; @@ -1046,8 +1046,7 @@ static void test_texture_update_sub_no_unpack_row_length() GPU_texture_clear(texture, GPU_DATA_FLOAT, &clear_color); const float4 texture_color(0.0f, 1.0f, 0.0f, 1.0f); - float4 *texture_data = static_cast( - MEM_mallocN(sub_size.x * sub_size.y * sizeof(float4), __func__)); + float4 *texture_data = MEM_malloc_arrayN(sub_size.x * sub_size.y, __func__); for (int i = 0; i < sub_size.x * sub_size.y; i++) { texture_data[i] = texture_color; } @@ -1102,8 +1101,7 @@ static void test_texture_update_sub_unpack_row_length() const float4 texture_color(0.0f, 1.0f, 0.0f, 1.0f); const float4 texture_color_off(1.0f, 0.0f, 0.0f, 1.0f); - float4 *texture_data = static_cast( - MEM_mallocN(size.x * size.y * sizeof(float4), __func__)); + float4 *texture_data = MEM_malloc_arrayN(size.x * size.y, __func__); for (int x = 0; x < size.x; x++) { for (int y = 0; y < size.y; y++) { int index = x + y * size.x; diff --git a/source/blender/gpu/vulkan/vk_shader_interface.cc b/source/blender/gpu/vulkan/vk_shader_interface.cc index 3b4f1c6b3e3..55780dcd74e 100644 --- a/source/blender/gpu/vulkan/vk_shader_interface.cc +++ b/source/blender/gpu/vulkan/vk_shader_interface.cc @@ -78,8 +78,7 @@ void VKShaderInterface::init(const shader::ShaderCreateInfo &info) names_size += info.subpass_inputs_.size() * SUBPASS_FALLBACK_NAME_LEN; int32_t input_tot_len = attr_len_ + ubo_len_ + uniform_len_ + ssbo_len_ + constant_len_; - inputs_ = static_cast( - MEM_calloc_arrayN(input_tot_len, sizeof(ShaderInput), __func__)); + inputs_ = MEM_calloc_arrayN(input_tot_len, __func__); ShaderInput *input = inputs_; name_buffer_ = (char *)MEM_mallocN(names_size, "name_buffer"); diff --git a/source/blender/gpu/vulkan/vk_vertex_buffer.cc b/source/blender/gpu/vulkan/vk_vertex_buffer.cc index d58b4d61cd9..830b6895887 100644 --- a/source/blender/gpu/vulkan/vk_vertex_buffer.cc +++ b/source/blender/gpu/vulkan/vk_vertex_buffer.cc @@ -109,7 +109,7 @@ void VKVertexBuffer::acquire_data() /* Discard previous data if any. */ /* TODO: Use mapped memory. */ MEM_SAFE_FREE(data_); - data_ = (uchar *)MEM_mallocN(sizeof(uchar) * this->size_alloc_get(), __func__); + data_ = MEM_malloc_arrayN(this->size_alloc_get(), __func__); } void VKVertexBuffer::resize_data() diff --git a/source/blender/imbuf/movie/intern/movie_read.cc b/source/blender/imbuf/movie/intern/movie_read.cc index f737f8e8dcf..ca9eae18d5f 100644 --- a/source/blender/imbuf/movie/intern/movie_read.cc +++ b/source/blender/imbuf/movie/intern/movie_read.cc @@ -445,10 +445,10 @@ static int startffmpeg(MovieReader *anim) av_image_fill_arrays( anim->pFrameDeinterlaced->data, anim->pFrameDeinterlaced->linesize, - static_cast(MEM_callocN( + MEM_calloc_arrayN( av_image_get_buffer_size( anim->pCodecCtx->pix_fmt, anim->pCodecCtx->width, anim->pCodecCtx->height, 1), - "ffmpeg deinterlace")), + "ffmpeg deinterlace"), anim->pCodecCtx->pix_fmt, anim->pCodecCtx->width, anim->pCodecCtx->height, diff --git a/source/blender/makesrna/intern/rna_curve.cc b/source/blender/makesrna/intern/rna_curve.cc index bb5fdc74af6..f4d44b8aeaa 100644 --- a/source/blender/makesrna/intern/rna_curve.cc +++ b/source/blender/makesrna/intern/rna_curve.cc @@ -595,11 +595,10 @@ static void rna_Curve_body_set(PointerRNA *ptr, const char *value) MEM_freeN(cu->strinfo); } - cu->str = static_cast(MEM_mallocN(len_bytes + sizeof(char32_t), "str")); + cu->str = MEM_malloc_arrayN(len_bytes + sizeof(char32_t), "str"); memcpy(cu->str, value, len_bytes + 1); - cu->strinfo = static_cast( - MEM_callocN((len_chars + 4) * sizeof(CharInfo), "strinfo")); + cu->strinfo = MEM_calloc_arrayN((len_chars + 4), "strinfo"); } static void rna_Nurb_update_cyclic_u(Main *bmain, Scene *scene, PointerRNA *ptr) diff --git a/source/blender/nodes/geometry/nodes/node_geo_string_to_curves.cc b/source/blender/nodes/geometry/nodes/node_geo_string_to_curves.cc index f2210d5b1b1..da03324a03d 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_string_to_curves.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_string_to_curves.cc @@ -195,7 +195,7 @@ static std::optional get_text_layout(GeoNodeExecParams ¶ms) cu.len = len_bytes; cu.pos = len_chars; /* The reason for the additional character here is unknown, but reflects other code elsewhere. */ - cu.str = static_cast(MEM_mallocN(len_bytes + sizeof(char32_t), __func__)); + cu.str = MEM_malloc_arrayN(len_bytes + sizeof(char32_t), __func__); memcpy(cu.str, layout.text.c_str(), len_bytes + 1); cu.strinfo = MEM_calloc_arrayN(len_chars + 1, __func__); diff --git a/source/blender/render/intern/bake.cc b/source/blender/render/intern/bake.cc index 8c2bcd8d6e9..efdb7a7812b 100644 --- a/source/blender/render/intern/bake.cc +++ b/source/blender/render/intern/bake.cc @@ -570,8 +570,7 @@ bool RE_bake_pixels_populate_from_objects(Mesh *me_low, tris_high = MEM_calloc_arrayN(highpoly_num, "MVerts Highpoly Mesh Array"); /* Assume all high-poly tessfaces are triangles. */ - me_highpoly = static_cast( - MEM_mallocN(sizeof(Mesh *) * highpoly_num, "Highpoly Derived Meshes")); + me_highpoly = MEM_malloc_arrayN(highpoly_num, "Highpoly Derived Meshes"); Array treeData(highpoly_num); if (!is_cage) { diff --git a/source/blender/windowmanager/intern/wm_playanim.cc b/source/blender/windowmanager/intern/wm_playanim.cc index e48f6fbd889..d0ee0ad480d 100644 --- a/source/blender/windowmanager/intern/wm_playanim.cc +++ b/source/blender/windowmanager/intern/wm_playanim.cc @@ -125,7 +125,7 @@ static bool buffer_from_filepath(const char *filepath, if (UNLIKELY(size == size_t(-1))) { *r_error_message = BLI_sprintfN("failure '%s' to access size", strerror(errno)); } - else if (r_mem && UNLIKELY(!(mem = static_cast(MEM_mallocN(size, __func__))))) { + else if (r_mem && UNLIKELY(!(mem = MEM_malloc_arrayN(size, __func__)))) { *r_error_message = BLI_sprintfN("error allocating buffer %" PRIu64 " size", uint64_t(size)); } else if (r_mem && UNLIKELY((size_read = BLI_read(file, mem, size)) != size)) {