Commit d92736ab authored by Xavier Claessens's avatar Xavier Claessens
Browse files

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
parent 9e4b2805
......@@ -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));\
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment