From: Eric Bollengier Date: Tue, 16 Mar 2021 12:43:32 +0000 (+0100) Subject: Enhance bdelete_and_free() macro X-Git-Tag: Release-11.0.2~14 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b500346f960eda5fc26fae12c23caf33da44499a;p=thirdparty%2Fbacula.git Enhance bdelete_and_free() macro --- diff --git a/bacula/src/baconfig.h b/bacula/src/baconfig.h index b7f7c29d3..b3b797d29 100644 --- a/bacula/src/baconfig.h +++ b/bacula/src/baconfig.h @@ -603,8 +603,18 @@ void t_msg(const char *file, int line, int64_t level, const char *fmt,...); #endif /** Macro to simplify free/reset pointers */ -#define bfree_and_null(a) do{if(a){bfree(a); (a)=NULL;}} while(0) -#define bdelete_and_null(a) do{if(a){delete a; (a)=NULL;}} while(0) +#define bfree_and_null(a) do{if(a){void *b__=(void*)a; (a)=NULL; bfree(b__);}} while(0) + +/* If changed, please run the tests in tools/test-cpp.c */ +#if __cplusplus >= 201103L +# define bdelete_and_null(a) do{if(a){auto b__ = a; (a)=NULL; delete b__;}} while(0) +#else +# ifdef HAVE_TYPEOF +# define bdelete_and_null(a) do{if(a){typeof(a) b__ = a; (a)=NULL; delete b__;}} while(0) +# else +# define bdelete_and_null(a) do{if(a){delete a; (a)=NULL;}} while(0) +# endif +#endif /** * Replace codes needed in both file routines and non-file routines