summary refs log tree commit diff
path: root/include/nm-macros-internal.h
diff options
context:
space:
mode:
authorMichael Biebl <biebl@debian.org>2015-11-24 00:06:32 +0100
committerMichael Biebl <biebl@debian.org>2015-11-24 00:06:32 +0100
commita6ece1a2aa19a6268335c87d4fdef20123dd04a5 (patch)
tree87f1961faacdfafb1c4fee5f2feb6bcb5c06813b /include/nm-macros-internal.h
parent81836c2d44802b4cca833d7775dd627e0797a7e2 (diff)
Imported Upstream version 1.0.8 upstream/1.0.8
Diffstat (limited to 'include/nm-macros-internal.h')
-rw-r--r--include/nm-macros-internal.h41
1 files changed, 33 insertions, 8 deletions
diff --git a/include/nm-macros-internal.h b/include/nm-macros-internal.h
index 170fb46c..a2f2da5a 100644
--- a/include/nm-macros-internal.h
+++ b/include/nm-macros-internal.h
@@ -24,6 +24,7 @@
 
 
 #include <glib.h>
+#include <glib-object.h>
 
 /********************************************************/
 
@@ -83,7 +84,7 @@
  * It's not that bad however, because gcc and clang often have the
  * same name for the same warning. */
 
-#if defined (__GNUC__)
+#if defined (__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6))
 #define NM_PRAGMA_WARNING_DISABLE(warning) \
         _Pragma("GCC diagnostic push"); \
         _Pragma(_NM_PRAGMA_WARNING_DO(warning))
@@ -95,7 +96,7 @@
 #define NM_PRAGMA_WARNING_DISABLE(warning)
 #endif
 
-#if defined (__GNUC__)
+#if defined (__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6))
 #define NM_PRAGMA_WARNING_REENABLE \
     _Pragma("GCC diagnostic pop")
 #elif defined (__clang__)
@@ -256,6 +257,17 @@ nm_clear_g_source (guint *id)
 	return FALSE;
 }
 
+static inline gboolean
+nm_clear_g_signal_handler (gpointer self, guint *id)
+{
+	if (id && *id) {
+		g_signal_handler_disconnect (self, *id);
+		*id = 0;
+		return TRUE;
+	}
+	return FALSE;
+}
+
 /*****************************************************************************/
 
 /* Determine whether @x is a power of two (@x being an integer type).
@@ -265,12 +277,12 @@ nm_clear_g_source (guint *id)
 #define nm_utils_is_power_of_two(x) ({ \
 		const typeof(x) __x = (x); \
 		\
-		((__x & (__x - 1)) == 0) && \
-			/* Check if the value is negative. In that case, return FALSE.
-			 * The first expression is a compile time constant, depending on whether
-			 * the type is signed. The second expression is a clumsy way for (__x >= 0),
-			 * which causes a compiler warning for unsigned types. */ \
-			( ( ((typeof(__x)) -1) > ((typeof(__x)) 0) ) || (__x > 0) || (__x == 0) ); \
+		/* Check if the value is negative. In that case, return FALSE.
+		 * The first expression is a compile time constant, depending on whether
+		 * the type is signed. The second expression is a clumsy way for (__x >= 0),
+		 * which causes a compiler warning for unsigned types. */ \
+		    ( ( ((typeof(__x)) -1) > ((typeof(__x)) 0) ) || (__x > 0) || (__x == 0) ) \
+		 && ((__x & (__x - 1)) == 0); \
 	})
 
 /*****************************************************************************/
@@ -317,4 +329,17 @@ nm_strstrip (char *str)
 
 /*****************************************************************************/
 
+#define nm_sprintf_buf(buf, format, ...) ({ \
+		char * _buf = (buf); \
+		\
+		/* some static assert trying to ensure that the buffer is statically allocated.
+		 * It disallows a buffer size of sizeof(gpointer) to catch that. */ \
+		G_STATIC_ASSERT (G_N_ELEMENTS (buf) == sizeof (buf) && sizeof (buf) != sizeof (char *)); \
+		g_snprintf (_buf, sizeof (buf), \
+		            ""format"", __VA_ARGS__); \
+		_buf; \
+	})
+
+/*****************************************************************************/
+
 #endif /* __NM_MACROS_INTERNAL_H__ */