diff options
| author | Michael Biebl <biebl@debian.org> | 2016-10-01 00:33:49 +0200 |
|---|---|---|
| committer | Michael Biebl <biebl@debian.org> | 2016-10-01 00:33:49 +0200 |
| commit | 270c4830551c9810ad4e83f9a1db2b1cb946208c (patch) | |
| tree | 5df09188f7e43b70896efb7b6e942e0b130d75d3 /shared/nm-utils/nm-macros-internal.h | |
| parent | 7514efc2f38c9ace4557d4e69d68e7d380389030 (diff) | |
New upstream version 1.4.2 upstream/1.4.2
Diffstat (limited to 'shared/nm-utils/nm-macros-internal.h')
| -rw-r--r-- | shared/nm-utils/nm-macros-internal.h | 192 |
1 files changed, 114 insertions, 78 deletions
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(). */ |