shared: add c-list macros to iterate backwards

This commit is contained in:
Beniamino Galvani 2020-11-04 17:26:50 +01:00
parent 5b7ce438d9
commit dfd2fcde0f
4 changed files with 15 additions and 7 deletions

View File

@ -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',

View File

@ -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)

View File

@ -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 {

View File

@ -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__ */