Add g_clear_pointer()

Also reimplement g_clear_object() using g_clear_pointer()

https://bugzilla.gnome.org/show_bug.cgi?id=674634
This commit is contained in:
Xavier Claessens
2012-04-23 17:57:56 +02:00
parent 3f816dc5d1
commit 00285b7517
6 changed files with 61 additions and 25 deletions

View File

@@ -561,19 +561,7 @@ G_STMT_START { \
G_OBJECT_WARN_INVALID_PSPEC ((object), "property", (property_id), (pspec))
void g_clear_object (volatile GObject **object_ptr);
#define g_clear_object(object_ptr) \
G_STMT_START { \
/* Only one access, please */ \
gpointer *_p = (gpointer) (object_ptr); \
gpointer _o; \
\
do \
_o = g_atomic_pointer_get (_p); \
while G_UNLIKELY (!g_atomic_pointer_compare_and_exchange (_p, _o, NULL));\
\
if (_o) \
g_object_unref (_o); \
} G_STMT_END
#define g_clear_object(object_ptr) g_clear_pointer ((object_ptr), g_object_unref)
typedef struct {
/*<private>*/