summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBeniamino Galvani <bgalvani@redhat.com>2020-11-04 17:26:50 +0100
committerBeniamino Galvani <bgalvani@redhat.com>2020-11-16 16:43:39 +0100
commitdfd2fcde0f90316d1a4013d456639994b4fe3438 (patch)
tree1a352897709be0fc85a3359cc878bb161b40e401
parent5b7ce438d9333b6add7b7924f9e2902d91dee335 (diff)
downloadNetworkManager-dfd2fcde0f90316d1a4013d456639994b4fe3438.tar.gz
shared: add c-list macros to iterate backwards
-rw-r--r--.clang-format4
-rw-r--r--libnm/nm-client.c2
-rw-r--r--shared/nm-glib-aux/nm-c-list.h5
-rw-r--r--shared/nm-std-aux/c-list-util.h11
4 files changed, 15 insertions, 7 deletions
diff --git a/.clang-format b/.clang-format
index f0331adefc..b0233c0d09 100644
--- a/.clang-format
+++ b/.clang-format
@@ -66,9 +66,12 @@ SpacesInContainerLiterals: false
SpacesInParentheses: false
ForEachMacros: ['c_list_for_each',
+ 'c_list_for_each_prev',
+ 'c_list_for_each_prev_safe',
'c_list_for_each_continue',
'c_list_for_each_entry',
'c_list_for_each_entry_continue',
+ 'c_list_for_each_entry_prev',
'c_list_for_each_entry_safe',
'c_list_for_each_entry_safe_continue',
'c_list_for_each_entry_safe_unlink',
@@ -93,7 +96,6 @@ ForEachMacros: ['c_list_for_each',
'ndp_msg_opt_rdnss_for_each_addr',
'nla_for_each_attr',
'nla_for_each_nested',
- 'nm_c_list_for_each_entry_prev',
'nm_dedup_multi_iter_for_each',
'nm_ip_config_iter_ip4_address_for_each',
'nm_ip_config_iter_ip4_route_for_each',
diff --git a/libnm/nm-client.c b/libnm/nm-client.c
index e2052204cd..8eb1e3031c 100644
--- a/libnm/nm-client.c
+++ b/libnm/nm-client.c
@@ -1166,7 +1166,7 @@ nml_dbus_object_iface_data_get(NMLDBusObject *dbobj,
count++;
}
} else {
- nm_c_list_for_each_entry_prev (db_iface_data, &dbobj->iface_lst_head, iface_lst) {
+ c_list_for_each_entry_prev (db_iface_data, &dbobj->iface_lst_head, iface_lst) {
if (db_iface_data->dbus_iface_is_wellknown)
break;
if (db_iface_data->iface_removed)
diff --git a/shared/nm-glib-aux/nm-c-list.h b/shared/nm-glib-aux/nm-c-list.h
index e19774dd91..173861c63c 100644
--- a/shared/nm-glib-aux/nm-c-list.h
+++ b/shared/nm-glib-aux/nm-c-list.h
@@ -17,11 +17,6 @@
_what &&c_list_contains(list, &_what->member); \
})
-/* iterate over the list backwards. */
-#define nm_c_list_for_each_entry_prev(_iter, _list, _m) \
- for (_iter = c_list_entry((_list)->prev, __typeof__(*_iter), _m); &(_iter)->_m != (_list); \
- _iter = c_list_entry((_iter)->_m.prev, __typeof__(*_iter), _m))
-
/*****************************************************************************/
typedef struct {
diff --git a/shared/nm-std-aux/c-list-util.h b/shared/nm-std-aux/c-list-util.h
index 828481e114..8f40d32133 100644
--- a/shared/nm-std-aux/c-list-util.h
+++ b/shared/nm-std-aux/c-list-util.h
@@ -42,4 +42,15 @@ c_list_length_is(const CList *list, unsigned long check_len)
return n == check_len;
}
+#define c_list_for_each_prev(_iter, _list) \
+ for (_iter = (_list)->prev; (_iter) != (_list); _iter = (_iter)->prev)
+
+#define c_list_for_each_prev_safe(_iter, _safe, _list) \
+ for (_iter = (_list)->prev, _safe = (_iter)->prev; (_iter) != (_list); \
+ _iter = (_safe), _safe = (_safe)->prev)
+
+#define c_list_for_each_entry_prev(_iter, _list, _m) \
+ for (_iter = c_list_entry((_list)->prev, __typeof__(*_iter), _m); &(_iter)->_m != (_list); \
+ _iter = c_list_entry((_iter)->_m.prev, __typeof__(*_iter), _m))
+
#endif /* __C_LIST_UTIL_H__ */