From a3ad5abf2fe85d623f9e78fefc34e27bdc14632e Mon Sep 17 00:00:00 2001 From: Jacques Lucke Date: Fri, 17 Dec 2021 15:38:15 +0100 Subject: Allocator: simplify using guarded allocator in C++ code Using the `MEM_*` API from C++ code was a bit annoying: * When converting C to C++ code, one often has to add a type cast on returned `void *`. That leads to having the same type name three times in the same line. This patch reduces the amount to two and removes the `sizeof(...)` from the line. * The existing alternative of using `OBJECT_GUARDED_NEW` looks a out of place compared to other allocation methods. Sometimes `MEM_CXX_CLASS_ALLOC_FUNCS` can be used when structs are defined in C++ code. It doesn't look great but it's definitely better. The downside is that it makes the name of the allocation less useful. That's because the same name is used for all allocations of a type, independend of where it is allocated. This patch introduces three new functions: `MEM_new`, `MEM_cnew` and `MEM_delete`. These cover the majority of use cases (array allocation is not covered). The `OBJECT_GUARDED_*` macros are removed because they are not needed anymore. Differential Revision: https://developer.blender.org/D13502 --- source/blender/editors/space_file/asset_catalog_tree_view.cc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'source/blender/editors/space_file') diff --git a/source/blender/editors/space_file/asset_catalog_tree_view.cc b/source/blender/editors/space_file/asset_catalog_tree_view.cc index 86c4b78dea4..f6c449a0584 100644 --- a/source/blender/editors/space_file/asset_catalog_tree_view.cc +++ b/source/blender/editors/space_file/asset_catalog_tree_view.cc @@ -679,7 +679,7 @@ using namespace blender::ed::asset_browser; FileAssetCatalogFilterSettingsHandle *file_create_asset_catalog_filter_settings() { - AssetCatalogFilterSettings *filter_settings = OBJECT_GUARDED_NEW(AssetCatalogFilterSettings); + AssetCatalogFilterSettings *filter_settings = MEM_new(__func__); return reinterpret_cast(filter_settings); } @@ -688,7 +688,8 @@ void file_delete_asset_catalog_filter_settings( { AssetCatalogFilterSettings **filter_settings = reinterpret_cast( filter_settings_handle); - OBJECT_GUARDED_SAFE_DELETE(*filter_settings, AssetCatalogFilterSettings); + MEM_delete(*filter_settings); + *filter_settings = nullptr; } bool file_set_asset_catalog_filter_settings( -- cgit v1.2.3