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 <asido4@gmail.com>
Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
Arvydas Sidorenko 2012-07-30 21:06:05 +02:00 committed by Uli Schlachter
parent d751141e74
commit c491cd034c
1 changed files with 9 additions and 21 deletions

View File

@ -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)