[network-manager-applet] build: define g_clear_pointer() in the compatibility header nm-glib-compat.h



commit 3e3bd1ee8bf7de93460fd5fa1e897b295f2899f8
Author: Jiří Klimeš <jklimes redhat com>
Date:   Tue Nov 11 09:41:15 2014 +0100

    build: define g_clear_pointer() in the compatibility header nm-glib-compat.h
    
    It is needed to be able to compile with glib 2.32 that does not contain the
    function.

 src/connection-editor/page-general.c |    1 +
 src/connection-editor/page-ip4.c     |    1 +
 src/connection-editor/page-ip6.c     |    1 +
 src/connection-editor/page-ppp.c     |    1 +
 src/connection-editor/page-vpn.c     |    1 +
 src/utils/nm-glib-compat.h           |   28 ++++++++++++++++++++++++++++
 6 files changed, 33 insertions(+), 0 deletions(-)
---
diff --git a/src/connection-editor/page-general.c b/src/connection-editor/page-general.c
index 5cece09..37fb8c2 100644
--- a/src/connection-editor/page-general.c
+++ b/src/connection-editor/page-general.c
@@ -26,6 +26,7 @@
 #include <nm-setting-connection.h>
 
 #include "page-general.h"
+#include "nm-glib-compat.h"
 
 G_DEFINE_TYPE (CEPageGeneral, ce_page_general, CE_TYPE_PAGE)
 
diff --git a/src/connection-editor/page-ip4.c b/src/connection-editor/page-ip4.c
index 2dbfaa3..5559e66 100644
--- a/src/connection-editor/page-ip4.c
+++ b/src/connection-editor/page-ip4.c
@@ -46,6 +46,7 @@
 #include "page-ip4.h"
 #include "ip4-routes-dialog.h"
 #include "connection-helpers.h"
+#include "nm-glib-compat.h"
 
 G_DEFINE_TYPE (CEPageIP4, ce_page_ip4, CE_TYPE_PAGE)
 
diff --git a/src/connection-editor/page-ip6.c b/src/connection-editor/page-ip6.c
index c5d96bc..6aa55cc 100644
--- a/src/connection-editor/page-ip6.c
+++ b/src/connection-editor/page-ip6.c
@@ -45,6 +45,7 @@
 
 #include "page-ip6.h"
 #include "ip6-routes-dialog.h"
+#include "nm-glib-compat.h"
 
 G_DEFINE_TYPE (CEPageIP6, ce_page_ip6, CE_TYPE_PAGE)
 
diff --git a/src/connection-editor/page-ppp.c b/src/connection-editor/page-ppp.c
index 7e7c1aa..472b075 100644
--- a/src/connection-editor/page-ppp.c
+++ b/src/connection-editor/page-ppp.c
@@ -33,6 +33,7 @@
 #include "page-ppp.h"
 #include "ppp-auth-methods-dialog.h"
 #include "nm-connection-editor.h"
+#include "nm-glib-compat.h"
 
 G_DEFINE_TYPE (CEPagePpp, ce_page_ppp, CE_TYPE_PAGE)
 
diff --git a/src/connection-editor/page-vpn.c b/src/connection-editor/page-vpn.c
index 957f35d..004a260 100644
--- a/src/connection-editor/page-vpn.c
+++ b/src/connection-editor/page-vpn.c
@@ -38,6 +38,7 @@
 #include "connection-helpers.h"
 #include "nm-connection-editor.h"
 #include "vpn-helpers.h"
+#include "nm-glib-compat.h"
 
 G_DEFINE_TYPE (CEPageVpn, ce_page_vpn, CE_TYPE_PAGE)
 
diff --git a/src/utils/nm-glib-compat.h b/src/utils/nm-glib-compat.h
index d88d0ff..18454c7 100644
--- a/src/utils/nm-glib-compat.h
+++ b/src/utils/nm-glib-compat.h
@@ -122,6 +122,34 @@
     G_GNUC_END_IGNORE_DEPRECATIONS \
   })
 
+
+/*************************************************************
+ * Define g_clear_pointer() if it doesn't exist (glib < 2.34)
+ *************************************************************/
+
+#if !GLIB_CHECK_VERSION(2,34,0)
+
+#define g_clear_pointer(pp, destroy)     \
+       G_STMT_START { \
+               G_STATIC_ASSERT (sizeof *(pp) == sizeof (gpointer)); \
+               /* Only one access, please */ \
+               gpointer *_pp = (gpointer *) (pp); \
+               gpointer _p; \
+               /* This assignment is needed to avoid a gcc warning */ \
+               GDestroyNotify _destroy = (GDestroyNotify) (destroy); \
+         \
+               (void) (0 ? (gpointer) *(pp) : 0); \
+               do \
+                       _p = g_atomic_pointer_get (_pp); \
+               while G_UNLIKELY (!g_atomic_pointer_compare_and_exchange (_pp, _p, NULL)); \
+         \
+               if (_p) \
+                       _destroy (_p); \
+       } G_STMT_END
+
+#endif
+
+
 /*************************************************************/
 
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]