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:
parent
d751141e74
commit
c491cd034c
|
@ -80,31 +80,19 @@
|
||||||
} \
|
} \
|
||||||
} while (0)
|
} 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) \
|
#define p_delete(mem_p) \
|
||||||
do { \
|
do { \
|
||||||
void *__ptr = (mem_p); \
|
void **__ptr = (void **) (mem_p); \
|
||||||
free(*__ptr); \
|
free(*__ptr); \
|
||||||
*(void **)__ptr = NULL; \
|
*(void **)__ptr = NULL; \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
|
#ifdef __GNUC__
|
||||||
|
#define likely(expr) __builtin_expect(!!(expr), 1)
|
||||||
|
#define unlikely(expr) __builtin_expect((expr), 0)
|
||||||
|
#else
|
||||||
#define likely(expr) expr
|
#define likely(expr) expr
|
||||||
#define unlikely(expr) expr
|
#define unlikely(expr) expr
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static inline void * __attribute__ ((malloc)) xmalloc(ssize_t size)
|
static inline void * __attribute__ ((malloc)) xmalloc(ssize_t size)
|
||||||
|
|
Loading…
Reference in New Issue