diff options
author | Jacques Lucke <jacques@blender.org> | 2021-12-17 17:38:15 +0300 |
---|---|---|
committer | Jacques Lucke <jacques@blender.org> | 2021-12-17 17:42:28 +0300 |
commit | a3ad5abf2fe85d623f9e78fefc34e27bdc14632e (patch) | |
tree | 6d03a62169251af084ff2e02bd0f567d92f3b826 /intern/opensubdiv/internal | |
parent | c0d96ca9a5dbf168348b6a6bdee2f635c0c1685c (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/opensubdiv/internal')
-rw-r--r-- | intern/opensubdiv/internal/evaluator/evaluator_capi.cc | 4 | ||||
-rw-r--r-- | intern/opensubdiv/internal/topology/topology_refiner_capi.cc | 4 |
2 files changed, 4 insertions, 4 deletions
diff --git a/intern/opensubdiv/internal/evaluator/evaluator_capi.cc b/intern/opensubdiv/internal/evaluator/evaluator_capi.cc index 4b12206e103..5f8d6cddfd5 100644 --- a/intern/opensubdiv/internal/evaluator/evaluator_capi.cc +++ b/intern/opensubdiv/internal/evaluator/evaluator_capi.cc @@ -156,7 +156,7 @@ void assignFunctionPointers(OpenSubdiv_Evaluator *evaluator) OpenSubdiv_Evaluator *openSubdiv_createEvaluatorFromTopologyRefiner( OpenSubdiv_TopologyRefiner *topology_refiner) { - OpenSubdiv_Evaluator *evaluator = OBJECT_GUARDED_NEW(OpenSubdiv_Evaluator); + OpenSubdiv_Evaluator *evaluator = MEM_new<OpenSubdiv_Evaluator>(__func__); assignFunctionPointers(evaluator); evaluator->impl = openSubdiv_createEvaluatorInternal(topology_refiner); return evaluator; @@ -165,5 +165,5 @@ OpenSubdiv_Evaluator *openSubdiv_createEvaluatorFromTopologyRefiner( void openSubdiv_deleteEvaluator(OpenSubdiv_Evaluator *evaluator) { openSubdiv_deleteEvaluatorInternal(evaluator->impl); - OBJECT_GUARDED_DELETE(evaluator, OpenSubdiv_Evaluator); + MEM_delete(evaluator); } diff --git a/intern/opensubdiv/internal/topology/topology_refiner_capi.cc b/intern/opensubdiv/internal/topology/topology_refiner_capi.cc index b30d509be20..547ea190837 100644 --- a/intern/opensubdiv/internal/topology/topology_refiner_capi.cc +++ b/intern/opensubdiv/internal/topology/topology_refiner_capi.cc @@ -225,7 +225,7 @@ void assignFunctionPointers(OpenSubdiv_TopologyRefiner *topology_refiner) OpenSubdiv_TopologyRefiner *allocateTopologyRefiner() { - OpenSubdiv_TopologyRefiner *topology_refiner = OBJECT_GUARDED_NEW(OpenSubdiv_TopologyRefiner); + OpenSubdiv_TopologyRefiner *topology_refiner = MEM_new<OpenSubdiv_TopologyRefiner>(__func__); assignFunctionPointers(topology_refiner); return topology_refiner; } @@ -252,7 +252,7 @@ OpenSubdiv_TopologyRefiner *openSubdiv_createTopologyRefinerFromConverter( void openSubdiv_deleteTopologyRefiner(OpenSubdiv_TopologyRefiner *topology_refiner) { delete topology_refiner->impl; - OBJECT_GUARDED_DELETE(topology_refiner, OpenSubdiv_TopologyRefiner); + MEM_delete(topology_refiner); } bool openSubdiv_topologyRefinerCompareWithConverter( |