From 344312314eec327c3bf47f86950a5ad6c616e031 Mon Sep 17 00:00:00 2001 From: Pierre Habouzit Date: Thu, 2 Nov 2006 00:20:25 +0100 Subject: [PATCH] macros to create usual functions : new/delete and init/wipe. we will use __attribute__ so add the define so that it compiles on other compilers well Signed-off-by: Pierre Habouzit --- lib-lib/macros.h | 4 ++++ lib-lib/mem.h | 22 ++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/lib-lib/macros.h b/lib-lib/macros.h index 1867d7b..75c734a 100644 --- a/lib-lib/macros.h +++ b/lib-lib/macros.h @@ -20,6 +20,10 @@ #ifndef MUTT_LIB_LIB_MACROS_H #define MUTT_LIB_LIB_MACROS_H +#ifndef __GNUC__ +# define __attribute__(a) +#endif + /* * config.h must be included by source file! */ diff --git a/lib-lib/mem.h b/lib-lib/mem.h index a405e30..db5ef49 100644 --- a/lib-lib/mem.h +++ b/lib-lib/mem.h @@ -86,4 +86,26 @@ static inline void *xmemdupstr(const void *src, ssize_t len) { return res; } + +#define DO_INIT(type, prefix) \ + static inline type * prefix##_init(type *var) { \ + p_clear(var, 1); \ + return var; \ + } +#define DO_WIPE(type, prefix) \ + static inline void prefix##_wipe(type *var __attribute__((unused))) { } + +#define DO_NEW(type, prefix) \ + static inline type * prefix##_new(void) { \ + return prefix##_init(p_new(type, 1)); \ + } +#define DO_DELETE(type, prefix) \ + static inline void __attribute__((nonnull)) \ + prefix##_delete(type **var) { \ + if (*var) { \ + prefix##_wipe(*var); \ + p_delete(var); \ + } \ + } + #endif /* MUTT_LIB_LIB_MEM_H */ -- 2.20.1