From c491cd034c98987eb73f468dc0b5e4a5d58cc922 Mon Sep 17 00:00:00 2001 From: Arvydas Sidorenko Date: Mon, 30 Jul 2012 21:06:05 +0200 Subject: [PATCH] common/util.h: dodgy non-__GNUC__ p_delete I assume nobody have tried to compile Awesome with GNU uncompatible compiler for ages and thus non-__GNUC__ p_delete version got overlooked for quite some time. First of all, a problem I see is that it assigns void** to a variable of type void* and then dereferences the same void* variable. None of the compilers I am aware of will let you go through this without an error. And second of all, lets have one portable p_delete. Signed-off-by: Arvydas Sidorenko Signed-off-by: Uli Schlachter --- common/util.h | 30 +++++++++--------------------- 1 file changed, 9 insertions(+), 21 deletions(-) diff --git a/common/util.h b/common/util.h index a2f9e497..cf4500f4 100644 --- a/common/util.h +++ b/common/util.h @@ -80,31 +80,19 @@ } \ } while (0) - -#ifdef __GNUC__ - -#define p_delete(mem_pp) \ - do { \ - typeof(**(mem_pp)) **__ptr = (mem_pp); \ - free(*__ptr); \ - *__ptr = NULL; \ - } while(0) - -#define likely(expr) __builtin_expect(!!(expr), 1) -#define unlikely(expr) __builtin_expect((expr), 0) - -#else - -#define p_delete(mem_p) \ - do { \ - void *__ptr = (mem_p); \ - free(*__ptr); \ - *(void **)__ptr = NULL; \ +#define p_delete(mem_p) \ + do { \ + void **__ptr = (void **) (mem_p); \ + free(*__ptr); \ + *(void **)__ptr = NULL; \ } while (0) +#ifdef __GNUC__ +#define likely(expr) __builtin_expect(!!(expr), 1) +#define unlikely(expr) __builtin_expect((expr), 0) +#else #define likely(expr) expr #define unlikely(expr) expr - #endif static inline void * __attribute__ ((malloc)) xmalloc(ssize_t size)