Module: Mesa Branch: main Commit: b269cadf5680e688286660a507fd64d4f3145710 URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=b269cadf5680e688286660a507fd64d4f3145710
Author: Caio Oliveira <[email protected]> Date: Mon Sep 18 01:15:42 2023 -0700 util: Make DECLARE_LINEAR_ALLOC_* macros assume no destructors Linear allocator doesn't support calling custom destructors to its child allocations nor freeing individual child allocations. So the destructor callback and the delete operator don't apply to objects using linear allocator. Reviewed-by: Marek Olšák <[email protected]> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/25280> --- src/util/ralloc.h | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/util/ralloc.h b/src/util/ralloc.h index 47a0f40182b..1759692aa39 100644 --- a/src/util/ralloc.h +++ b/src/util/ralloc.h @@ -517,7 +517,7 @@ void gc_sweep_end(gc_ctx *ctx); * * which is more idiomatic in C++ than calling ralloc. */ -#define DECLARE_ALLOC_CXX_OPERATORS_TEMPLATE(TYPE, ALLOC_FUNC) \ +#define DECLARE_RALLOC_CXX_OPERATORS_TEMPLATE(TYPE, ALLOC_FUNC) \ private: \ static void _ralloc_destructor(void *p) \ { \ @@ -545,16 +545,27 @@ public: \ } #define DECLARE_RALLOC_CXX_OPERATORS(type) \ - DECLARE_ALLOC_CXX_OPERATORS_TEMPLATE(type, ralloc_size) + DECLARE_RALLOC_CXX_OPERATORS_TEMPLATE(type, ralloc_size) #define DECLARE_RZALLOC_CXX_OPERATORS(type) \ - DECLARE_ALLOC_CXX_OPERATORS_TEMPLATE(type, rzalloc_size) + DECLARE_RALLOC_CXX_OPERATORS_TEMPLATE(type, rzalloc_size) + + +#define DECLARE_LINEAR_ALLOC_CXX_OPERATORS_TEMPLATE(TYPE, ALLOC_FUNC) \ +public: \ + static void* operator new(size_t size, void *mem_ctx) \ + { \ + void *p = ALLOC_FUNC(mem_ctx, size); \ + assert(p != NULL); \ + static_assert(HAS_TRIVIAL_DESTRUCTOR(TYPE)); \ + return p; \ + } #define DECLARE_LINEAR_ALLOC_CXX_OPERATORS(type) \ - DECLARE_ALLOC_CXX_OPERATORS_TEMPLATE(type, linear_alloc_child) + DECLARE_LINEAR_ALLOC_CXX_OPERATORS_TEMPLATE(type, linear_alloc_child) #define DECLARE_LINEAR_ZALLOC_CXX_OPERATORS(type) \ - DECLARE_ALLOC_CXX_OPERATORS_TEMPLATE(type, linear_zalloc_child) + DECLARE_LINEAR_ALLOC_CXX_OPERATORS_TEMPLATE(type, linear_zalloc_child) /** * Do a fast allocation from the linear buffer, also known as the child node
