From 49bc31067163474729755c8a9dbd543ba3744d3f Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Wed, 9 Oct 2013 08:46:02 +0000 Subject: Move guarded objetc allocation to a guardedalloc header Also made libmv-capi use guarded objetc allocation. Run into some suspecious cases when it was not so clear whether memory is being freed or not. Now we'll know for sure whether there're leaks or not :) Having this macros in a guardedalloc header helps using them in other areas (for now it's OCIO and libmv, but in the future it'll be more places). --- intern/guardedalloc/MEM_guardedalloc.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'intern/guardedalloc') diff --git a/intern/guardedalloc/MEM_guardedalloc.h b/intern/guardedalloc/MEM_guardedalloc.h index d5ba2f5bd68..aebde0a6425 100644 --- a/intern/guardedalloc/MEM_guardedalloc.h +++ b/intern/guardedalloc/MEM_guardedalloc.h @@ -244,6 +244,24 @@ public: \ MEM_freeN(mem); \ } \ +#if defined __GNUC__ || defined __sun +# define OBJECT_GUARDED_NEW(type, args ...) \ + new(MEM_mallocN(sizeof(type), __func__)) type(args) +#else +# define OBJECT_GUARDED_NEW(type, ...) \ + new(MEM_mallocN(sizeof(type), __FUNCTION__)) type(__VA_ARGS__) +#endif +#define OBJECT_GUARDED_DELETE(what, type) \ + { if(what) { \ + ((type*)(what))->~type(); \ + MEM_freeN(what); \ + } } (void)0 +#define OBJECT_GUARDED_DELETE_ARRAY(what, type, count) \ + { if(what) { \ + for (int i = 0; i < count; i++) ((type*)(what))[i].~type(); \ + MEM_freeN(what); \ + } } (void)0 + #endif /* __cplusplus */ #ifdef __cplusplus -- cgit v1.2.3