[glib/glib-2-32] Fix g_clear_object macro with C++ compilers
- From: Xavier Claessens <xclaesse src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib/glib-2-32] Fix g_clear_object macro with C++ compilers
- Date: Mon, 30 Apr 2012 14:53:32 +0000 (UTC)
commit d92736ab032bb650b1d115042e2a0ff965175940
Author: Xavier Claessens <xavier claessens collabora co uk>
Date: Wed Apr 25 15:02:25 2012 +0200
Fix g_clear_object macro with C++ compilers
In C++ it is invalid to cast a void* to void**.
Also add a static check to ensure
sizeof(*object_ptr) == sizeof (gpointer).
This avoid common mistake of missing '&'
in g_clear_object(&obj);
https://bugzilla.gnome.org/show_bug.cgi?id=674634
gobject/gobject.h | 4 +++-
1 files changed, 3 insertions(+), 1 deletions(-)
---
diff --git a/gobject/gobject.h b/gobject/gobject.h
index 3572736..8c9e42a 100644
--- a/gobject/gobject.h
+++ b/gobject/gobject.h
@@ -563,10 +563,12 @@ G_STMT_START { \
void g_clear_object (volatile GObject **object_ptr);
#define g_clear_object(object_ptr) \
G_STMT_START { \
+ G_STATIC_ASSERT (sizeof *(object_ptr) == sizeof (gpointer)); \
/* Only one access, please */ \
- gpointer *_p = (gpointer) (object_ptr); \
+ gpointer *_p = (gpointer *) (object_ptr); \
gpointer _o; \
\
+ (void) (0 ? (gpointer) *(object_ptr) : 0); \
do \
_o = g_atomic_pointer_get (_p); \
while G_UNLIKELY (!g_atomic_pointer_compare_and_exchange (_p, _o, NULL));\
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]