Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacques Lucke <jacques@blender.org>2021-12-17 17:38:15 +0300
committerJacques Lucke <jacques@blender.org>2021-12-17 17:42:28 +0300
commita3ad5abf2fe85d623f9e78fefc34e27bdc14632e (patch)
tree6d03a62169251af084ff2e02bd0f567d92f3b826 /intern/libmv
parentc0d96ca9a5dbf168348b6a6bdee2f635c0c1685c (diff)
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
Diffstat (limited to 'intern/libmv')
-rw-r--r--intern/libmv/intern/utildefines.h18
1 files changed, 15 insertions, 3 deletions
diff --git a/intern/libmv/intern/utildefines.h b/intern/libmv/intern/utildefines.h
index 052052a1d76..8b37253698d 100644
--- a/intern/libmv/intern/utildefines.h
+++ b/intern/libmv/intern/utildefines.h
@@ -27,9 +27,21 @@
#ifdef WITH_LIBMV_GUARDED_ALLOC
# include "MEM_guardedalloc.h"
-# define LIBMV_OBJECT_NEW OBJECT_GUARDED_NEW
-# define LIBMV_OBJECT_DELETE OBJECT_GUARDED_DELETE
-# define LIBMV_OBJECT_DELETE OBJECT_GUARDED_DELETE
+# if defined __GNUC__
+# define LIBMV_OBJECT_NEW(type, args...) \
+ new (MEM_mallocN(sizeof(type), __func__)) type(args)
+# else
+# define LIBMV_OBJECT_NEW(type, ...) \
+ new (MEM_mallocN(sizeof(type), __FUNCTION__)) type(__VA_ARGS__)
+# endif
+# define LIBMV_OBJECT_DELETE(what, type) \
+ { \
+ if (what) { \
+ ((type*)what)->~type(); \
+ MEM_freeN(what); \
+ } \
+ } \
+ (void)0
# define LIBMV_STRUCT_NEW(type, count) \
(type*)MEM_mallocN(sizeof(type) * count, __func__)
# define LIBMV_STRUCT_DELETE(what) MEM_freeN(what)