[Mesa-dev] [RFC PATCH 4/5] ralloc: Make the C++ macros arrange for class destructors to be called.
Kenneth Graunke
kenneth at whitecape.org
Wed Sep 18 14:55:42 PDT 2013
Previously, almost all classes didn't actually call their destructors,
which is non-intuitive for C++ code. Setting them up to be called was
somewhat of a pain, since it required defining a helper function.
With the new macros, we can easily encapsulate this complexity, making
destructors just happen automatically.
Signed-off-by: Kenneth Graunke <kenneth at whitecape.org>
---
src/glsl/ralloc.h | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/src/glsl/ralloc.h b/src/glsl/ralloc.h
index 799d3a9..82a3daa 100644
--- a/src/glsl/ralloc.h
+++ b/src/glsl/ralloc.h
@@ -405,15 +405,23 @@ bool ralloc_vasprintf_append(char **str, const char *fmt, va_list args);
#endif
#define _RALLOC_OPS(ALLOC, TYPE) \
+private: \
+ static void _ralloc_##TYPE##_destructor_callback(void *p) \
+ { \
+ reinterpret_cast<TYPE *>(p)->~TYPE(); \
+ } \
+public: \
static void* operator new(size_t size, void *mem_ctx) \
{ \
void *p = ALLOC(mem_ctx, size); \
assert(p != NULL); \
+ ralloc_set_destructor(p, _ralloc_##TYPE##_destructor_callback); \
return p; \
} \
\
static void operator delete(void *p) \
{ \
+ ralloc_set_destructor(p, NULL); \
ralloc_free(p); \
}
--
1.8.3.4
More information about the mesa-dev
mailing list