summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2020-09-24 12:51:05 +0200
committerThomas Haller <thaller@redhat.com>2020-09-30 09:48:26 +0200
commitf37dd5d394fc1a7bd19c6d65129ca76e0a3c3b82 (patch)
tree4c6cff7b54513a9ff2fb5ff810811c077e09327d
parent1c3f7d823e17dbfc26ab11ef8943135b2c6961c5 (diff)
downloadNetworkManager-f37dd5d394fc1a7bd19c6d65129ca76e0a3c3b82.tar.gz
shared: move NM_CMP*() macros to "nm-std-aux.h"
I would need these macros earlier in "nm-glib-aux/nm-shared-utils.h", so it would be sufficient to just move them. However, when I already move them, move them to "nm-std-aux/nm-std-aux.h" because they don't need a glib dependency.
-rw-r--r--shared/nm-glib-aux/nm-shared-utils.h120
-rw-r--r--shared/nm-std-aux/nm-std-aux.h102
2 files changed, 102 insertions, 120 deletions
diff --git a/shared/nm-glib-aux/nm-shared-utils.h b/shared/nm-glib-aux/nm-shared-utils.h
index d3a7194212..c114086cf4 100644
--- a/shared/nm-glib-aux/nm-shared-utils.h
+++ b/shared/nm-glib-aux/nm-shared-utils.h
@@ -248,126 +248,6 @@ gboolean nm_utils_ipaddr_is_normalized(int addr_family, const char *str_addr);
/*****************************************************************************/
-#define NM_CMP_RETURN(c) \
- G_STMT_START \
- { \
- const int _cc = (c); \
- if (_cc) \
- return _cc < 0 ? -1 : 1; \
- } \
- G_STMT_END
-
-#define NM_CMP_RETURN_DIRECT(c) \
- G_STMT_START \
- { \
- const int _cc = (c); \
- if (_cc) \
- return _cc; \
- } \
- G_STMT_END
-
-#define NM_CMP_SELF(a, b) \
- G_STMT_START \
- { \
- typeof(a) _a = (a); \
- typeof(b) _b = (b); \
- \
- if (_a == _b) \
- return 0; \
- if (!_a) \
- return -1; \
- if (!_b) \
- return 1; \
- } \
- G_STMT_END
-
-#define NM_CMP_DIRECT(a, b) \
- G_STMT_START \
- { \
- typeof(a) _a = (a); \
- typeof(b) _b = (b); \
- \
- if (_a != _b) \
- return (_a < _b) ? -1 : 1; \
- } \
- G_STMT_END
-
-#define NM_CMP_DIRECT_UNSAFE(a, b) \
- G_STMT_START \
- { \
- if ((a) != (b)) \
- return ((a) < (b)) ? -1 : 1; \
- } \
- G_STMT_END
-
-/* In the general case, direct pointer comparison is undefined behavior in C.
- * Avoid that by casting pointers to void* and then to uintptr_t. This comparison
- * is not really meaningful, except that it provides some kind of stable sort order
- * between pointers (that can otherwise not be compared). */
-#define NM_CMP_DIRECT_PTR(a, b) NM_CMP_DIRECT((uintptr_t)((void *) (a)), (uintptr_t)((void *) (b)))
-
-#define NM_CMP_DIRECT_MEMCMP(a, b, size) NM_CMP_RETURN(memcmp((a), (b), (size)))
-
-#define NM_CMP_DIRECT_STRCMP(a, b) NM_CMP_RETURN_DIRECT(strcmp((a), (b)))
-
-#define NM_CMP_DIRECT_STRCMP0(a, b) NM_CMP_RETURN_DIRECT(nm_strcmp0((a), (b)))
-
-#define NM_CMP_DIRECT_IN6ADDR(a, b) \
- G_STMT_START \
- { \
- const struct in6_addr *const _a = (a); \
- const struct in6_addr *const _b = (b); \
- NM_CMP_RETURN(memcmp(_a, _b, sizeof(struct in6_addr))); \
- } \
- G_STMT_END
-
-#define NM_CMP_FIELD(a, b, field) NM_CMP_DIRECT(((a)->field), ((b)->field))
-
-#define NM_CMP_FIELD_UNSAFE(a, b, field) \
- G_STMT_START \
- { \
- /* it's unsafe, because it evaluates the arguments more then once.
- * This is necessary for bitfields, for which typeof() doesn't work. */ \
- if (((a)->field) != ((b)->field)) \
- return ((a)->field < ((b)->field)) ? -1 : 1; \
- } \
- G_STMT_END
-
-#define NM_CMP_FIELD_BOOL(a, b, field) NM_CMP_DIRECT(!!((a)->field), !!((b)->field))
-
-#define NM_CMP_FIELD_STR(a, b, field) NM_CMP_RETURN(strcmp(((a)->field), ((b)->field)))
-
-#define NM_CMP_FIELD_STR_INTERNED(a, b, field) \
- G_STMT_START \
- { \
- const char *_a = ((a)->field); \
- const char *_b = ((b)->field); \
- \
- if (_a != _b) { \
- NM_CMP_RETURN_DIRECT(nm_strcmp0(_a, _b)); \
- } \
- } \
- G_STMT_END
-
-#define NM_CMP_FIELD_STR0(a, b, field) NM_CMP_RETURN_DIRECT(nm_strcmp0(((a)->field), ((b)->field)))
-
-#define NM_CMP_FIELD_MEMCMP_LEN(a, b, field, len) \
- NM_CMP_RETURN(memcmp(&((a)->field), &((b)->field), NM_MIN(len, sizeof((a)->field))))
-
-#define NM_CMP_FIELD_MEMCMP(a, b, field) \
- NM_CMP_RETURN(memcmp(&((a)->field), &((b)->field), sizeof((a)->field)))
-
-#define NM_CMP_FIELD_IN6ADDR(a, b, field) \
- G_STMT_START \
- { \
- const struct in6_addr *const _a = &((a)->field); \
- const struct in6_addr *const _b = &((b)->field); \
- NM_CMP_RETURN(memcmp(_a, _b, sizeof(struct in6_addr))); \
- } \
- G_STMT_END
-
-/*****************************************************************************/
-
gboolean nm_utils_memeqzero(gconstpointer data, gsize length);
/*****************************************************************************/
diff --git a/shared/nm-std-aux/nm-std-aux.h b/shared/nm-std-aux/nm-std-aux.h
index 9a5b217238..98ccf53503 100644
--- a/shared/nm-std-aux/nm-std-aux.h
+++ b/shared/nm-std-aux/nm-std-aux.h
@@ -749,6 +749,108 @@ nm_steal_fd(int *p_fd)
/*****************************************************************************/
+#define NM_CMP_RETURN(c) \
+ do { \
+ const int _cc = (c); \
+ if (_cc) \
+ return _cc < 0 ? -1 : 1; \
+ } while (0)
+
+#define NM_CMP_RETURN_DIRECT(c) \
+ do { \
+ const int _cc = (c); \
+ if (_cc) \
+ return _cc; \
+ } while (0)
+
+#define NM_CMP_SELF(a, b) \
+ do { \
+ typeof(a) _a = (a); \
+ typeof(b) _b = (b); \
+ \
+ if (_a == _b) \
+ return 0; \
+ if (!_a) \
+ return -1; \
+ if (!_b) \
+ return 1; \
+ } while (0)
+
+#define NM_CMP_DIRECT(a, b) \
+ do { \
+ typeof(a) _a = (a); \
+ typeof(b) _b = (b); \
+ \
+ if (_a != _b) \
+ return (_a < _b) ? -1 : 1; \
+ } while (0)
+
+#define NM_CMP_DIRECT_UNSAFE(a, b) \
+ do { \
+ if ((a) != (b)) \
+ return ((a) < (b)) ? -1 : 1; \
+ } while (0)
+
+/* In the general case, direct pointer comparison is undefined behavior in C.
+ * Avoid that by casting pointers to void* and then to uintptr_t. This comparison
+ * is not really meaningful, except that it provides some kind of stable sort order
+ * between pointers (that can otherwise not be compared). */
+#define NM_CMP_DIRECT_PTR(a, b) NM_CMP_DIRECT((uintptr_t)((void *) (a)), (uintptr_t)((void *) (b)))
+
+#define NM_CMP_DIRECT_MEMCMP(a, b, size) NM_CMP_RETURN(memcmp((a), (b), (size)))
+
+#define NM_CMP_DIRECT_STRCMP(a, b) NM_CMP_RETURN_DIRECT(strcmp((a), (b)))
+
+#define NM_CMP_DIRECT_STRCMP0(a, b) NM_CMP_RETURN_DIRECT(nm_strcmp0((a), (b)))
+
+#define NM_CMP_DIRECT_IN6ADDR(a, b) \
+ do { \
+ const struct in6_addr *const _a = (a); \
+ const struct in6_addr *const _b = (b); \
+ NM_CMP_RETURN(memcmp(_a, _b, sizeof(struct in6_addr))); \
+ } while (0)
+
+#define NM_CMP_FIELD(a, b, field) NM_CMP_DIRECT(((a)->field), ((b)->field))
+
+#define NM_CMP_FIELD_UNSAFE(a, b, field) \
+ do { \
+ /* it's unsafe, because it evaluates the arguments more then once.
+ * This is necessary for bitfields, for which typeof() doesn't work. */ \
+ if (((a)->field) != ((b)->field)) \
+ return ((a)->field < ((b)->field)) ? -1 : 1; \
+ } while (0)
+
+#define NM_CMP_FIELD_BOOL(a, b, field) NM_CMP_DIRECT(!!((a)->field), !!((b)->field))
+
+#define NM_CMP_FIELD_STR(a, b, field) NM_CMP_RETURN(strcmp(((a)->field), ((b)->field)))
+
+#define NM_CMP_FIELD_STR_INTERNED(a, b, field) \
+ do { \
+ const char *_a = ((a)->field); \
+ const char *_b = ((b)->field); \
+ \
+ if (_a != _b) { \
+ NM_CMP_RETURN_DIRECT(nm_strcmp0(_a, _b)); \
+ } \
+ } while (0)
+
+#define NM_CMP_FIELD_STR0(a, b, field) NM_CMP_RETURN_DIRECT(nm_strcmp0(((a)->field), ((b)->field)))
+
+#define NM_CMP_FIELD_MEMCMP_LEN(a, b, field, len) \
+ NM_CMP_RETURN(memcmp(&((a)->field), &((b)->field), NM_MIN(len, sizeof((a)->field))))
+
+#define NM_CMP_FIELD_MEMCMP(a, b, field) \
+ NM_CMP_RETURN(memcmp(&((a)->field), &((b)->field), sizeof((a)->field)))
+
+#define NM_CMP_FIELD_IN6ADDR(a, b, field) \
+ do { \
+ const struct in6_addr *const _a = &((a)->field); \
+ const struct in6_addr *const _b = &((b)->field); \
+ NM_CMP_RETURN(memcmp(_a, _b, sizeof(struct in6_addr))); \
+ } while (0)
+
+/*****************************************************************************/
+
#define NM_AF_UNSPEC 0 /* AF_UNSPEC */
#define NM_AF_INET 2 /* AF_INET */
#define NM_AF_INET6 10 /* AF_INET6 */