Arvydas Sidorenko | 30 Jul 2012 21:06
Picon
Gravatar

[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 <asido4 <at> gmail.com>
---
 common/util.h |   24 ++++++------------------
 1 files changed, 6 insertions(+), 18 deletions(-)

diff --git a/common/util.h b/common/util.h
index a2f9e49..cf4500f 100644
--- a/common/util.h
+++ b/common/util.h
 <at>  <at>  -80,31 +80,19  <at>  <at> 
         }                                            \
     } while (0)

+#define p_delete(mem_p)                              \
+    do {                                             \
+        void **__ptr = (void **) (mem_p);            \
+        free(*__ptr);                                \
+        *(void **)__ptr = NULL;                      \
+    } while (0)

 #ifdef __GNUC__
(Continue reading)

Uli Schlachter | 31 Jul 2012 16:36
Picon
Gravatar

Re: [PATCH] common/util.h: dodgy non-__GNUC__ p_delete

On 30.07.2012 21:06, Arvydas Sidorenko wrote:
> 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 <at> gmail.com>
[...]
> -#define p_delete(mem_p)                            \
> -    do {                                           \
> -        void *__ptr = (mem_p);                     \
> -        free(*__ptr);                              \
> -        *(void **)__ptr = NULL;                    \
> -    } while (0)

Wow, that looks quite wrong.

Pushed, thanks!

Uli
--

-- 
"Every once in a while, declare peace. It confuses the hell out of your enemies"
 - 79th Rule of Acquisition


Gmane