diff options
Diffstat (limited to 'shared')
| -rw-r--r-- | shared/Makefile.in | 2 | ||||
| -rw-r--r-- | shared/nm-default.h | 61 | ||||
| -rw-r--r-- | shared/nm-utils/nm-macros-internal.h | 192 | ||||
| -rw-r--r-- | shared/nm-version-macros.h | 8 | ||||
| -rw-r--r-- | shared/nm-version-macros.h.in | 6 |
5 files changed, 181 insertions, 88 deletions
diff --git a/shared/Makefile.in b/shared/Makefile.in index 3e98aec6..c98c4994 100644 --- a/shared/Makefile.in +++ b/shared/Makefile.in @@ -92,7 +92,7 @@ ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 am__aclocal_m4_deps = $(top_srcdir)/m4/attributes.m4 \ $(top_srcdir)/m4/ax_lib_readline.m4 \ $(top_srcdir)/m4/compiler_options.m4 \ - $(top_srcdir)/m4/gettext.m4 \ + $(top_srcdir)/m4/gettext.m4 $(top_srcdir)/m4/git-sha-record.m4 \ $(top_srcdir)/m4/gnome-code-coverage.m4 \ $(top_srcdir)/m4/gtk-doc.m4 $(top_srcdir)/m4/iconv.m4 \ $(top_srcdir)/m4/intlmacosx.m4 $(top_srcdir)/m4/intltool.m4 \ diff --git a/shared/nm-default.h b/shared/nm-default.h index e3e3ea44..9e2377cf 100644 --- a/shared/nm-default.h +++ b/shared/nm-default.h @@ -52,15 +52,68 @@ #define NM_VERSION_MAX_ALLOWED NM_VERSION_NEXT_STABLE #define NM_VERSION_MIN_REQUIRED NM_VERSION_0_9_8 +#ifndef NM_MORE_ASSERTS +#define NM_MORE_ASSERTS 0 +#endif + +#if NM_MORE_ASSERTS == 0 +/* The cast macros like NM_TYPE() are implemented via G_TYPE_CHECK_INSTANCE_CAST() + * and _G_TYPE_CIC(). The latter, by default performs runtime checks of the type + * by calling g_type_check_instance_cast(). + * This check has a certain overhead without being helpful. + * + * Example 1: + * static void foo (NMType *obj) + * { + * access_obj_without_check (obj); + * } + * foo ((NMType *) obj); + * // There is no runtime check and passing an invalid pointer + * // leads to a crash. + * + * Example 2: + * static void foo (NMType *obj) + * { + * access_obj_without_check (obj); + * } + * foo (NM_TYPE (obj)); + * // There is a runtime check which prints a g_warning(), but that doesn't + * // avoid the crash as NM_TYPE() cannot do anything then passing on the + * // invalid pointer. + * + * Example 3: + * static void foo (NMType *obj) + * { + * g_return_if_fail (NM_IS_TYPE (obj)); + * access_obj_without_check (obj); + * } + * foo ((NMType *) obj); + * // There is a runtime check which prints a g_critical() which also avoids + * // the crash. That is actually helpful to catch bugs and avoid crashes. + * + * Example 4: + * static void foo (NMType *obj) + * { + * g_return_if_fail (NM_IS_TYPE (obj)); + * access_obj_without_check (obj); + * } + * foo (NM_TYPE (obj)); + * // The runtime check is performed twice, with printing a g_warning() and + * // a g_critical() and avoiding the crash. + * + * Example 3 is how it should be done. Type checks in NM_TYPE() are pointless. + * Disable them for our production builds. + */ +#ifndef G_DISABLE_CAST_CHECKS +#define G_DISABLE_CAST_CHECKS +#endif +#endif + #include <stdlib.h> #include <glib.h> /*****************************************************************************/ -#ifndef NM_MORE_ASSERTS -#define NM_MORE_ASSERTS 0 -#endif - #if NM_MORE_ASSERTS == 0 /* glib assertions (g_return_*(), g_assert*()) contain a textual representation diff --git a/shared/nm-utils/nm-macros-internal.h b/shared/nm-utils/nm-macros-internal.h index 73075c68..9e9f5d8f 100644 --- a/shared/nm-utils/nm-macros-internal.h +++ b/shared/nm-utils/nm-macros-internal.h @@ -175,45 +175,24 @@ NM_G_ERROR_MSG (GError *error) /********************************************************/ -#define _NM_IN_SET_EVAL_1(op, _x, y1) \ - (_x == (y1)) - -#define _NM_IN_SET_EVAL_2(op, _x, y1, y2) \ - ( (_x == (y1)) \ - op (_x == (y2)) \ - ) - -#define _NM_IN_SET_EVAL_3(op, _x, y1, y2, y3) \ - ( (_x == (y1)) \ - op (_x == (y2)) \ - op (_x == (y3)) \ - ) - -#define _NM_IN_SET_EVAL_4(op, _x, y1, y2, y3, y4) \ - ( (_x == (y1)) \ - op (_x == (y2)) \ - op (_x == (y3)) \ - op (_x == (y4)) \ - ) - -#define _NM_IN_SET_EVAL_5(op, _x, y1, y2, y3, y4, y5) \ - ( (_x == (y1)) \ - op (_x == (y2)) \ - op (_x == (y3)) \ - op (_x == (y4)) \ - op (_x == (y5)) \ - ) - -#define _NM_IN_SET_EVAL_6(op, _x, y1, y2, y3, y4, y5, y6) \ - ( (_x == (y1)) \ - op (_x == (y2)) \ - op (_x == (y3)) \ - op (_x == (y4)) \ - op (_x == (y5)) \ - op (_x == (y6)) \ - ) - -#define _NM_IN_SET_EVAL_N2(op, _x, n, ...) _NM_IN_SET_EVAL_##n(op, _x, __VA_ARGS__) +#define _NM_IN_SET_EVAL_1( op, _x, y) (_x == (y)) +#define _NM_IN_SET_EVAL_2( op, _x, y, ...) (_x == (y)) op _NM_IN_SET_EVAL_1 (op, _x, __VA_ARGS__) +#define _NM_IN_SET_EVAL_3( op, _x, y, ...) (_x == (y)) op _NM_IN_SET_EVAL_2 (op, _x, __VA_ARGS__) +#define _NM_IN_SET_EVAL_4( op, _x, y, ...) (_x == (y)) op _NM_IN_SET_EVAL_3 (op, _x, __VA_ARGS__) +#define _NM_IN_SET_EVAL_5( op, _x, y, ...) (_x == (y)) op _NM_IN_SET_EVAL_4 (op, _x, __VA_ARGS__) +#define _NM_IN_SET_EVAL_6( op, _x, y, ...) (_x == (y)) op _NM_IN_SET_EVAL_5 (op, _x, __VA_ARGS__) +#define _NM_IN_SET_EVAL_7( op, _x, y, ...) (_x == (y)) op _NM_IN_SET_EVAL_6 (op, _x, __VA_ARGS__) +#define _NM_IN_SET_EVAL_8( op, _x, y, ...) (_x == (y)) op _NM_IN_SET_EVAL_7 (op, _x, __VA_ARGS__) +#define _NM_IN_SET_EVAL_9( op, _x, y, ...) (_x == (y)) op _NM_IN_SET_EVAL_8 (op, _x, __VA_ARGS__) +#define _NM_IN_SET_EVAL_10(op, _x, y, ...) (_x == (y)) op _NM_IN_SET_EVAL_9 (op, _x, __VA_ARGS__) +#define _NM_IN_SET_EVAL_11(op, _x, y, ...) (_x == (y)) op _NM_IN_SET_EVAL_10 (op, _x, __VA_ARGS__) +#define _NM_IN_SET_EVAL_12(op, _x, y, ...) (_x == (y)) op _NM_IN_SET_EVAL_11 (op, _x, __VA_ARGS__) +#define _NM_IN_SET_EVAL_13(op, _x, y, ...) (_x == (y)) op _NM_IN_SET_EVAL_12 (op, _x, __VA_ARGS__) +#define _NM_IN_SET_EVAL_14(op, _x, y, ...) (_x == (y)) op _NM_IN_SET_EVAL_13 (op, _x, __VA_ARGS__) +#define _NM_IN_SET_EVAL_15(op, _x, y, ...) (_x == (y)) op _NM_IN_SET_EVAL_14 (op, _x, __VA_ARGS__) +#define _NM_IN_SET_EVAL_16(op, _x, y, ...) (_x == (y)) op _NM_IN_SET_EVAL_15 (op, _x, __VA_ARGS__) + +#define _NM_IN_SET_EVAL_N2(op, _x, n, ...) (_NM_IN_SET_EVAL_##n(op, _x, __VA_ARGS__)) #define _NM_IN_SET_EVAL_N(op, x, n, ...) \ ({ \ typeof(x) _x = (x); \ @@ -238,45 +217,24 @@ _NM_IN_STRSET_streq (const char *x, const char *s) return s && strcmp (x, s) == 0; } -#define _NM_IN_STRSET_EVAL_1(op, _x, y1) \ - _NM_IN_STRSET_streq (_x, y1) - -#define _NM_IN_STRSET_EVAL_2(op, _x, y1, y2) \ - ( _NM_IN_STRSET_streq (_x, y1) \ - op _NM_IN_STRSET_streq (_x, y2) \ - ) - -#define _NM_IN_STRSET_EVAL_3(op, _x, y1, y2, y3) \ - ( _NM_IN_STRSET_streq (_x, y1) \ - op _NM_IN_STRSET_streq (_x, y2) \ - op _NM_IN_STRSET_streq (_x, y3) \ - ) - -#define _NM_IN_STRSET_EVAL_4(op, _x, y1, y2, y3, y4) \ - ( _NM_IN_STRSET_streq (_x, y1) \ - op _NM_IN_STRSET_streq (_x, y2) \ - op _NM_IN_STRSET_streq (_x, y3) \ - op _NM_IN_STRSET_streq (_x, y4) \ - ) - -#define _NM_IN_STRSET_EVAL_5(op, _x, y1, y2, y3, y4, y5) \ - ( _NM_IN_STRSET_streq (_x, y1) \ - op _NM_IN_STRSET_streq (_x, y2) \ - op _NM_IN_STRSET_streq (_x, y3) \ - op _NM_IN_STRSET_streq (_x, y4) \ - op _NM_IN_STRSET_streq (_x, y5) \ - ) - -#define _NM_IN_STRSET_EVAL_6(op, _x, y1, y2, y3, y4, y5, y6) \ - ( _NM_IN_STRSET_streq (_x, y1) \ - op _NM_IN_STRSET_streq (_x, y2) \ - op _NM_IN_STRSET_streq (_x, y3) \ - op _NM_IN_STRSET_streq (_x, y4) \ - op _NM_IN_STRSET_streq (_x, y5) \ - op _NM_IN_STRSET_streq (_x, y6) \ - ) - -#define _NM_IN_STRSET_EVAL_N2(op, _x, n, ...) _NM_IN_STRSET_EVAL_##n(op, _x, __VA_ARGS__) +#define _NM_IN_STRSET_EVAL_1( op, _x, y) _NM_IN_STRSET_streq (_x, y) +#define _NM_IN_STRSET_EVAL_2( op, _x, y, ...) _NM_IN_STRSET_streq (_x, y) op _NM_IN_STRSET_EVAL_1 (op, _x, __VA_ARGS__) +#define _NM_IN_STRSET_EVAL_3( op, _x, y, ...) _NM_IN_STRSET_streq (_x, y) op _NM_IN_STRSET_EVAL_2 (op, _x, __VA_ARGS__) +#define _NM_IN_STRSET_EVAL_4( op, _x, y, ...) _NM_IN_STRSET_streq (_x, y) op _NM_IN_STRSET_EVAL_3 (op, _x, __VA_ARGS__) +#define _NM_IN_STRSET_EVAL_5( op, _x, y, ...) _NM_IN_STRSET_streq (_x, y) op _NM_IN_STRSET_EVAL_4 (op, _x, __VA_ARGS__) +#define _NM_IN_STRSET_EVAL_6( op, _x, y, ...) _NM_IN_STRSET_streq (_x, y) op _NM_IN_STRSET_EVAL_5 (op, _x, __VA_ARGS__) +#define _NM_IN_STRSET_EVAL_7( op, _x, y, ...) _NM_IN_STRSET_streq (_x, y) op _NM_IN_STRSET_EVAL_6 (op, _x, __VA_ARGS__) +#define _NM_IN_STRSET_EVAL_8( op, _x, y, ...) _NM_IN_STRSET_streq (_x, y) op _NM_IN_STRSET_EVAL_7 (op, _x, __VA_ARGS__) +#define _NM_IN_STRSET_EVAL_9( op, _x, y, ...) _NM_IN_STRSET_streq (_x, y) op _NM_IN_STRSET_EVAL_8 (op, _x, __VA_ARGS__) +#define _NM_IN_STRSET_EVAL_10(op, _x, y, ...) _NM_IN_STRSET_streq (_x, y) op _NM_IN_STRSET_EVAL_9 (op, _x, __VA_ARGS__) +#define _NM_IN_STRSET_EVAL_11(op, _x, y, ...) _NM_IN_STRSET_streq (_x, y) op _NM_IN_STRSET_EVAL_10 (op, _x, __VA_ARGS__) +#define _NM_IN_STRSET_EVAL_12(op, _x, y, ...) _NM_IN_STRSET_streq (_x, y) op _NM_IN_STRSET_EVAL_11 (op, _x, __VA_ARGS__) +#define _NM_IN_STRSET_EVAL_13(op, _x, y, ...) _NM_IN_STRSET_streq (_x, y) op _NM_IN_STRSET_EVAL_12 (op, _x, __VA_ARGS__) +#define _NM_IN_STRSET_EVAL_14(op, _x, y, ...) _NM_IN_STRSET_streq (_x, y) op _NM_IN_STRSET_EVAL_13 (op, _x, __VA_ARGS__) +#define _NM_IN_STRSET_EVAL_15(op, _x, y, ...) _NM_IN_STRSET_streq (_x, y) op _NM_IN_STRSET_EVAL_14 (op, _x, __VA_ARGS__) +#define _NM_IN_STRSET_EVAL_16(op, _x, y, ...) _NM_IN_STRSET_streq (_x, y) op _NM_IN_STRSET_EVAL_15 (op, _x, __VA_ARGS__) + +#define _NM_IN_STRSET_EVAL_N2(op, _x, n, ...) (_NM_IN_STRSET_EVAL_##n(op, _x, __VA_ARGS__)) #define _NM_IN_STRSET_EVAL_N(op, x, n, ...) \ ({ \ const char *_x = (x); \ @@ -302,6 +260,22 @@ _NM_IN_STRSET_streq (const char *x, const char *s) /*****************************************************************************/ +#define nm_str_not_empty(str) \ + ({ \ + /* implemented as macro to preserve constness */ \ + typeof (str) __str = (str); \ + _nm_unused const char *__str_type_check = __str; \ + ((__str && __str[0]) ? __str : ((char *) NULL)); \ + }) + +static inline char * +nm_strdup_not_empty (const char *str) +{ + return str && str[0] ? g_strdup (str) : NULL; +} + +/*****************************************************************************/ + #define NM_PRINT_FMT_QUOTED(cond, prefix, str, suffix, str_else) \ (cond) ? (prefix) : "", \ (cond) ? (str) : (str_else), \ @@ -356,6 +330,24 @@ _notify (obj_type *obj, _PropertyEnums prop) \ /*****************************************************************************/ +#define __NM_GET_PRIVATE(self, type, is_check, result_cmd) \ + ({ \ + /* preserve the const-ness of self. Unfortunately, that + * way, @self cannot be a void pointer */ \ + typeof (self) _self = (self); \ + \ + /* Get compiler error if variable is of wrong type */ \ + _nm_unused const type *_self2 = (_self); \ + \ + nm_assert (is_check (_self)); \ + ( result_cmd ); \ + }) + +#define _NM_GET_PRIVATE(self, type, is_check) __NM_GET_PRIVATE(self, type, is_check, &_self->_priv) +#define _NM_GET_PRIVATE_PTR(self, type, is_check) __NM_GET_PRIVATE(self, type, is_check, _self->_priv) + +/*****************************************************************************/ + static inline gpointer nm_g_object_ref (gpointer obj) { @@ -526,6 +518,50 @@ nm_strcmp_p_with_data (gconstpointer a, gconstpointer b, gpointer user_data) /*****************************************************************************/ +/* Taken from systemd's UNIQ_T and UNIQ macros. */ + +#define NM_UNIQ_T(x, uniq) G_PASTE(__unique_prefix_, G_PASTE(x, uniq)) +#define NM_UNIQ __COUNTER__ + +/*****************************************************************************/ + +/* glib's MIN()/MAX() macros don't have function-like behavior, in that they evaluate + * the argument possibly twice. + * + * Taken from systemd's MIN()/MAX() macros. */ + +#define NM_MIN(a, b) __NM_MIN(NM_UNIQ, a, NM_UNIQ, b) +#define __NM_MIN(aq, a, bq, b) \ + ({ \ + typeof (a) NM_UNIQ_T(A, aq) = (a); \ + typeof (b) NM_UNIQ_T(B, bq) = (b); \ + ((NM_UNIQ_T(A, aq) < NM_UNIQ_T(B, bq)) ? NM_UNIQ_T(A, aq) : NM_UNIQ_T(B, bq)); \ + }) + +#define NM_MAX(a, b) __NM_MAX(NM_UNIQ, a, NM_UNIQ, b) +#define __NM_MAX(aq, a, bq, b) \ + ({ \ + typeof (a) NM_UNIQ_T(A, aq) = (a); \ + typeof (b) NM_UNIQ_T(B, bq) = (b); \ + ((NM_UNIQ_T(A, aq) > NM_UNIQ_T(B, bq)) ? NM_UNIQ_T(A, aq) : NM_UNIQ_T(B, bq)); \ + }) + +#define NM_CLAMP(x, low, high) __NM_CLAMP(NM_UNIQ, x, NM_UNIQ, low, NM_UNIQ, high) +#define __NM_CLAMP(xq, x, lowq, low, highq, high) \ + ({ \ + typeof(x)NM_UNIQ_T(X,xq) = (x); \ + typeof(low) NM_UNIQ_T(LOW,lowq) = (low); \ + typeof(high) NM_UNIQ_T(HIGH,highq) = (high); \ + \ + ( (NM_UNIQ_T(X,xq) > NM_UNIQ_T(HIGH,highq)) \ + ? NM_UNIQ_T(HIGH,highq) \ + : (NM_UNIQ_T(X,xq) < NM_UNIQ_T(LOW,lowq)) \ + ? NM_UNIQ_T(LOW,lowq) \ + : NM_UNIQ_T(X,xq)); \ + }) + +/*****************************************************************************/ + static inline guint nm_encode_version (guint major, guint minor, guint micro) { /* analog to the preprocessor macro NM_ENCODE_VERSION(). */ diff --git a/shared/nm-version-macros.h b/shared/nm-version-macros.h index 3c3b1732..14109559 100644 --- a/shared/nm-version-macros.h +++ b/shared/nm-version-macros.h @@ -45,7 +45,7 @@ * Evaluates to the micro version number of NetworkManager which this source * compiled against. */ -#define NM_MICRO_VERSION (0) +#define NM_MICRO_VERSION (2) /** * NM_CHECK_VERSION: @@ -69,8 +69,10 @@ #define NM_VERSION_1_0 (NM_ENCODE_VERSION (1, 0, 0)) #define NM_VERSION_1_2 (NM_ENCODE_VERSION (1, 2, 0)) #define NM_VERSION_1_4 (NM_ENCODE_VERSION (1, 4, 0)) +#define NM_VERSION_1_4_2 (NM_ENCODE_VERSION (1, 4, 2)) +#define NM_VERSION_1_4_4 (NM_ENCODE_VERSION (1, 4, 4)) -#define NM_VERSION_CUR_STABLE NM_VERSION_1_2 -#define NM_VERSION_NEXT_STABLE NM_VERSION_1_4 +#define NM_VERSION_CUR_STABLE NM_VERSION_1_4_2 +#define NM_VERSION_NEXT_STABLE NM_VERSION_1_4_4 #endif /* __NM_VERSION_MACROS_H__ */ diff --git a/shared/nm-version-macros.h.in b/shared/nm-version-macros.h.in index d67aab4c..62fc1c6d 100644 --- a/shared/nm-version-macros.h.in +++ b/shared/nm-version-macros.h.in @@ -69,8 +69,10 @@ #define NM_VERSION_1_0 (NM_ENCODE_VERSION (1, 0, 0)) #define NM_VERSION_1_2 (NM_ENCODE_VERSION (1, 2, 0)) #define NM_VERSION_1_4 (NM_ENCODE_VERSION (1, 4, 0)) +#define NM_VERSION_1_4_2 (NM_ENCODE_VERSION (1, 4, 2)) +#define NM_VERSION_1_4_4 (NM_ENCODE_VERSION (1, 4, 4)) -#define NM_VERSION_CUR_STABLE NM_VERSION_1_2 -#define NM_VERSION_NEXT_STABLE NM_VERSION_1_4 +#define NM_VERSION_CUR_STABLE NM_VERSION_1_4_2 +#define NM_VERSION_NEXT_STABLE NM_VERSION_1_4_4 #endif /* __NM_VERSION_MACROS_H__ */ |