diff --git a/Makefile.am b/Makefile.am index 61b89bd9f8..3242157116 100644 --- a/Makefile.am +++ b/Makefile.am @@ -4654,7 +4654,6 @@ EXTRA_DIST += \ shared/nm-dispatcher-api.h \ shared/nm-test-libnm-utils.h \ shared/nm-test-utils-impl.c \ - shared/nm-utils/c-list.h \ shared/nm-utils/c-list-util.c \ shared/nm-utils/c-list-util.h \ shared/nm-utils/gsystem-local-alloc.h \ diff --git a/libnm/nm-manager.c b/libnm/nm-manager.c index 52b2e13510..2b9e0d9695 100644 --- a/libnm/nm-manager.c +++ b/libnm/nm-manager.c @@ -35,7 +35,7 @@ #include "nm-active-connection.h" #include "nm-vpn-connection.h" #include "nm-dbus-helpers.h" -#include "nm-utils/c-list.h" +#include "c-list/src/c-list.h" #include "introspection/org.freedesktop.NetworkManager.h" diff --git a/libnm/nm-object.c b/libnm/nm-object.c index fc7a82af98..605da4927e 100644 --- a/libnm/nm-object.c +++ b/libnm/nm-object.c @@ -33,7 +33,7 @@ #include "nm-dbus-helpers.h" #include "nm-client.h" #include "nm-core-internal.h" -#include "nm-utils/c-list.h" +#include "c-list/src/c-list.h" static gboolean debug = FALSE; #define dbgmsg(f,...) if (G_UNLIKELY (debug)) { g_message (f, ## __VA_ARGS__ ); } diff --git a/shared/nm-utils/c-list-util.h b/shared/nm-utils/c-list-util.h index 199583cffc..e87f1c1989 100644 --- a/shared/nm-utils/c-list-util.h +++ b/shared/nm-utils/c-list-util.h @@ -22,7 +22,7 @@ #ifndef __C_LIST_UTIL_H__ #define __C_LIST_UTIL_H__ -#include "c-list.h" +#include "c-list/src/c-list.h" /*****************************************************************************/ diff --git a/shared/nm-utils/c-list.h b/shared/nm-utils/c-list.h deleted file mode 100644 index a3c4053b66..0000000000 --- a/shared/nm-utils/c-list.h +++ /dev/null @@ -1,397 +0,0 @@ -#pragma once - -/* - * Circular Double Linked List Implementation in Standard ISO-C11 - * - * This implements a generic circular double linked list. List entries must - * embed the CList object, which provides pointers to the next and previous - * element. Insertion and removal can be done in O(1) due to the double links. - * Furthermore, the list is circular, thus allows access to front/tail in O(1) - * as well, even if you only have a single head pointer (which is not how the - * list is usually operated, though). - * - * Note that you are free to use the list implementation without a head - * pointer. However, usual operation uses a single CList object as head, which - * is itself linked in the list and as such must be identified as list head. - * This allows very simply list operations and avoids a lot of special cases. - * Most importantly, you can unlink entries without requiring a head pointer. - */ - -#ifdef __cplusplus -extern "C" { -#endif - -#include - -typedef struct CList CList; - -/** - * struct CList - Entry of a circular double linked list - * @next: next entry - * @prev: previous entry - * - * Each entry in a list must embed a CList object. This object contains - * pointers to its next and previous elements, which can be freely accessed by - * the API user at any time. Note that the list is circular, and the list head - * is linked in the list as well. - * - * The list head must be initialized via C_LIST_INIT before use. There is no - * reason to initialize entry objects before linking them. However, if you need - * a boolean state that tells you whether the entry is linked or not, you should - * initialize the entry via C_LIST_INIT as well. - */ -struct CList { - CList *next; - CList *prev; -}; - -#define C_LIST_INIT(_var) { .next = &(_var), .prev = &(_var) } - -/** - * c_list_init() - initialize list entry - * @what: list entry to initialize - */ -static inline void c_list_init(CList *what) { - *what = (CList)C_LIST_INIT(*what); -} - -/** - * c_list_entry() - get parent container of list entry - * @_what: list entry, or NULL - * @_t: type of parent container - * @_m: member name of list entry in @_t - * - * If the list entry @_what is embedded into a surrounding structure, this will - * turn the list entry pointer @_what into a pointer to the parent container - * (using offsetof(3), or sometimes called container_of(3)). - * - * If @_what is NULL, this will also return NULL. - * - * Return: Pointer to parent container, or NULL. - */ -#define c_list_entry(_what, _t, _m) \ - ((_t *)(void *)(((unsigned long)(void *)(_what) ?: \ - offsetof(_t, _m)) - offsetof(_t, _m))) - -/** - * c_list_is_linked() - check whether an entry is linked - * @what: entry to check, or NULL - * - * Return: True if @what is linked in a list, false if not. - */ -static inline _Bool c_list_is_linked(const CList *what) { - return what && what->next != what; -} - -/** - * c_list_is_empty() - check whether a list is empty - * @list: list to check, or NULL - * - * Return: True if @list is empty, false if not. - */ -static inline _Bool c_list_is_empty(const CList *list) { - return !list || !c_list_is_linked(list); -} - -/** - * c_list_link_before() - link entry into list - * @where: linked list entry used as anchor - * @what: entry to link - * - * This links @what directly in front of @where. @where can either be a list - * head or any entry in the list. - * - * If @where points to the list head, this effectively links @what as new tail - * element. Hence, the macro c_list_link_tail() is an alias to this. - * - * @what is not inspected prior to being linked. Hence, it better not be linked - * into another list, or the other list will be corrupted. - */ -static inline void c_list_link_before(CList *where, CList *what) { - CList *prev = where->prev, *next = where; - - next->prev = what; - what->next = next; - what->prev = prev; - prev->next = what; -} -#define c_list_link_tail(_list, _what) c_list_link_before((_list), (_what)) - -/** - * c_list_link_after() - link entry into list - * @where: linked list entry used as anchor - * @what: entry to link - * - * This links @what directly after @where. @where can either be a list head or - * any entry in the list. - * - * If @where points to the list head, this effectively links @what as new front - * element. Hence, the macro c_list_link_front() is an alias to this. - * - * @what is not inspected prior to being linked. Hence, it better not be linked - * into another list, or the other list will be corrupted. - */ -static inline void c_list_link_after(CList *where, CList *what) { - CList *prev = where, *next = where->next; - - next->prev = what; - what->next = next; - what->prev = prev; - prev->next = what; -} -#define c_list_link_front(_list, _what) c_list_link_after((_list), (_what)) - -/** - * c_list_unlink_stale() - unlink element from list - * @what: element to unlink - * - * This unlinks @what. If @what was initialized via C_LIST_INIT(), it has no - * effect. If @what was never linked, nor initialized, behavior is undefined. - * - * Note that this does not modify @what. It just modifies the previous and next - * elements in the list to no longer reference @what. If you want to make sure - * @what is re-initialized after removal, use c_list_unlink(). - */ -static inline void c_list_unlink_stale(CList *what) { - CList *prev = what->prev, *next = what->next; - - next->prev = prev; - prev->next = next; -} - -/** - * c_list_unlink() - unlink element from list and re-initialize - * @what: element to unlink - * - * This is like c_list_unlink_stale() but re-initializes @what after removal. - */ -static inline void c_list_unlink(CList *what) { - /* condition is not needed, but avoids STOREs in fast-path */ - if (c_list_is_linked(what)) { - c_list_unlink_stale(what); - *what = (CList)C_LIST_INIT(*what); - } -} - -/** - * c_list_swap() - exchange the contents of two lists - * @list1: the list to operate on - * @list2: the list to operate on - * - * This replaces the contents of the list @list1 with the contents - * of @list2, and vice versa. - */ -static inline void c_list_swap(CList *list1, CList *list2) { - CList t; - - /* make neighbors of list1 point to list2, and vice versa */ - t = *list1; - t.next->prev = list2; - t.prev->next = list2; - t = *list2; - t.next->prev = list1; - t.prev->next = list1; - - /* swap list1 and list2 now that their neighbors were fixed up */ - t = *list1; - *list1 = *list2; - *list2 = t; -} - -/** - * c_list_splice() - splice one list into another - * @target: the list to splice into - * @source: the list to splice - * - * This removes all the entries from @source and splice them into @target. - * The order of the two lists is preserved and the source is appended - * to the end of target. - * - * On return, the source list will be empty. - */ -static inline void c_list_splice(CList *target, CList *source) { - if (!c_list_is_empty(source)) { - /* attach the front of @source to the tail of @target */ - source->next->prev = target->prev; - target->prev->next = source->next; - - /* attach the tail of @source to the front of @target */ - source->prev->next = target; - target->prev = source->prev; - - /* clear source */ - *source = (CList)C_LIST_INIT(*source); - } -} - -/** - * c_list_for_each() - loop over all list entries - * @_iter: iterator to use - * @_list: list to loop over - * - * This is a macro to use as for-loop to iterate an entire list. It is meant as - * convenience macro. Feel free to code your own loop iterator. - */ -#define c_list_for_each(_iter, _list) \ - for (_iter = (_list)->next; \ - (_iter) != (_list); \ - _iter = (_iter)->next) - - -/** - * c_list_for_each_safe() - loop over all list entries, safe for removal - * @_iter: iterator to use - * @_safe: used to store pointer to next element - * @_list: list to loop over - * - * This is a macro to use as for-loop to iterate an entire list, safe against - * removal of the current element. It is meant as convenience macro. Feel free - * to code your own loop iterator. - * - * Note that this fetches the next element prior to executing the loop body. - * This makes it safe against removal of the current entry, but it will go - * havoc if you remove other list entries. You better not modify anything but - * the current list entry. - */ -#define c_list_for_each_safe(_iter, _safe, _list) \ - for (_iter = (_list)->next, _safe = (_iter)->next; \ - (_iter) != (_list); \ - _iter = (_safe), _safe = (_safe)->next) - -/** - * c_list_for_each_entry() - loop over all list entries - * @_iter: iterator to use - * @_list: list to loop over - * @_m: member name of CList object in list type - * - * This combines c_list_for_each() with c_list_entry(), making it easy to - * iterate over a list of a specific type. - */ -#define c_list_for_each_entry(_iter, _list, _m) \ - for (_iter = c_list_entry((_list)->next, __typeof__(*_iter), _m); \ - &(_iter)->_m != (_list); \ - _iter = c_list_entry((_iter)->_m.next, __typeof__(*_iter), _m)) - -/** - * c_list_for_each_entry_safe() - loop over all list entries, safe for removal - * @_iter: iterator to use - * @_safe: used to store pointer to next element - * @_list: list to loop over - * @_m: member name of CList object in list type - * - * This combines c_list_for_each_safe() with c_list_entry(), making it easy to - * iterate over a list of a specific type. - */ -#define c_list_for_each_entry_safe(_iter, _safe, _list, _m) \ - for (_iter = c_list_entry((_list)->next, __typeof__(*_iter), _m), \ - _safe = c_list_entry((_iter)->_m.next, __typeof__(*_iter), _m); \ - &(_iter)->_m != (_list); \ - _iter = (_safe), \ - _safe = c_list_entry((_safe)->_m.next, __typeof__(*_iter), _m)) \ - -/** - * c_list_first() - return pointer to first element, or NULL if empty - * @list: list to operate on, or NULL - * - * This returns a pointer to the first element, or NULL if empty. This never - * returns a pointer to the list head. - * - * Return: Pointer to first list element, or NULL if empty. - */ -static inline CList *c_list_first(CList *list) { - return c_list_is_empty(list) ? NULL : list->next; -} - -/** - * c_list_last() - return pointer to last element, or NULL if empty - * @list: list to operate on, or NULL - * - * This returns a pointer to the last element, or NULL if empty. This never - * returns a pointer to the list head. - * - * Return: Pointer to last list element, or NULL if empty. - */ -static inline CList *c_list_last(CList *list) { - return c_list_is_empty(list) ? NULL : list->prev; -} - -/** - * c_list_first_entry() - return pointer to first entry, or NULL if empty - * @_list: list to operate on, or NULL - * @_t: type of list entries - * @_m: name of CList member in @_t - * - * This is like c_list_first(), but also applies c_list_entry() on the result. - * - * Return: Pointer to first list entry, or NULL if empty. - */ -#define c_list_first_entry(_list, _t, _m) \ - c_list_entry(c_list_first(_list), _t, _m) - -/** - * c_list_last_entry() - return pointer to last entry, or NULL if empty - * @_list: list to operate on, or NULL - * @_t: type of list entries - * @_m: name of CList member in @_t - * - * This is like c_list_last(), but also applies c_list_entry() on the result. - * - * Return: Pointer to last list entry, or NULL if empty. - */ -#define c_list_last_entry(_list, _t, _m) \ - c_list_entry(c_list_last(_list), _t, _m) - -/** - * c_list_length() - return number of linked entries, excluding the head - * @list: list to operate on - * - * Returns the number of entries in the list, excluding the list head @list. - * That is, for a list that is empty according to c_list_is_empty(), the - * returned length is 0. This requires to iterate the list and has thus O(n) - * runtime. - * - * Note that this function is meant for debugging purposes only. If you need - * the list size during normal operation, you should maintain a counter - * separately. - * - * Return: Number of items in @list. - */ -static inline unsigned long c_list_length(const CList *list) { - unsigned long n = 0; - const CList *iter; - - c_list_for_each(iter, list) - ++n; - - return n; -} - -/** - * c_list_contains() - check whether an entry is linked in a certain list - * @list: list to operate on - * @what: entry to look for - * - * This checks whether @what is linked into @list. This requires a linear - * search through the list, as such runs in O(n). Note that the list-head is - * considered part of the list, and hence this returns true if @what equals - * @list. - * - * Note that this function is meant for debugging purposes, and consistency - * checks. You should always be aware whether your objects are linked in a - * specific list. - * - * Return: True if @what is in @list, false otherwise. - */ -static inline _Bool c_list_contains(const CList *list, const CList *what) { - const CList *iter; - - c_list_for_each(iter, list) - if (what == iter) - return 1; - - return what == list; -} - -#ifdef __cplusplus -} -#endif diff --git a/shared/nm-utils/nm-c-list.h b/shared/nm-utils/nm-c-list.h index 5e0bf102cc..b43d144197 100644 --- a/shared/nm-utils/nm-c-list.h +++ b/shared/nm-utils/nm-c-list.h @@ -22,7 +22,7 @@ #ifndef __NM_C_LIST_H__ #define __NM_C_LIST_H__ -#include "c-list.h" +#include "c-list/src/c-list.h" /*****************************************************************************/ diff --git a/src/devices/bluetooth/nm-bluez5-manager.c b/src/devices/bluetooth/nm-bluez5-manager.c index de3f407275..5d3bd23a9e 100644 --- a/src/devices/bluetooth/nm-bluez5-manager.c +++ b/src/devices/bluetooth/nm-bluez5-manager.c @@ -30,7 +30,7 @@ #include "nm-core-internal.h" -#include "nm-utils/c-list.h" +#include "c-list/src/c-list.h" #include "nm-bluez-device.h" #include "nm-bluez-common.h" #include "devices/nm-device-bridge.h" diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index 13443ebb5f..b3541a648b 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -66,7 +66,7 @@ #include "nm-netns.h" #include "nm-dispatcher.h" #include "nm-config.h" -#include "nm-utils/c-list.h" +#include "c-list/src/c-list.h" #include "dns/nm-dns-manager.h" #include "nm-core-internal.h" #include "systemd/nm-sd.h" diff --git a/src/nm-act-request.c b/src/nm-act-request.c index e069fb3a30..0ac20b852f 100644 --- a/src/nm-act-request.c +++ b/src/nm-act-request.c @@ -28,7 +28,7 @@ #include #include -#include "nm-utils/c-list.h" +#include "c-list/src/c-list.h" #include "nm-setting-wireless-security.h" #include "nm-setting-8021x.h" diff --git a/src/nm-active-connection.h b/src/nm-active-connection.h index 45a5ac427a..c3d08b6479 100644 --- a/src/nm-active-connection.h +++ b/src/nm-active-connection.h @@ -21,7 +21,7 @@ #ifndef __NETWORKMANAGER_ACTIVE_CONNECTION_H__ #define __NETWORKMANAGER_ACTIVE_CONNECTION_H__ -#include "nm-utils/c-list.h" +#include "c-list/src/c-list.h" #include "nm-connection.h" #include "nm-dbus-object.h" diff --git a/src/nm-auth-manager.c b/src/nm-auth-manager.c index 411f92263b..ca1a2f18f5 100644 --- a/src/nm-auth-manager.c +++ b/src/nm-auth-manager.c @@ -22,7 +22,7 @@ #include "nm-auth-manager.h" -#include "nm-utils/c-list.h" +#include "c-list/src/c-list.h" #include "nm-errors.h" #include "nm-core-internal.h" #include "NetworkManagerUtils.h" diff --git a/src/nm-checkpoint-manager.c b/src/nm-checkpoint-manager.c index e55d632b91..8ba19db9f1 100644 --- a/src/nm-checkpoint-manager.c +++ b/src/nm-checkpoint-manager.c @@ -28,7 +28,7 @@ #include "devices/nm-device.h" #include "nm-manager.h" #include "nm-utils.h" -#include "nm-utils/c-list.h" +#include "c-list/src/c-list.h" /*****************************************************************************/ diff --git a/src/nm-connectivity.c b/src/nm-connectivity.c index d46b7d2859..389e72ad7c 100644 --- a/src/nm-connectivity.c +++ b/src/nm-connectivity.c @@ -30,7 +30,7 @@ #include #endif -#include "nm-utils/c-list.h" +#include "c-list/src/c-list.h" #include "nm-config.h" #include "NetworkManagerUtils.h" diff --git a/src/nm-dbus-manager.c b/src/nm-dbus-manager.c index 522383dba7..3e3691296f 100644 --- a/src/nm-dbus-manager.c +++ b/src/nm-dbus-manager.c @@ -29,7 +29,7 @@ #include #include -#include "nm-utils/c-list.h" +#include "c-list/src/c-list.h" #include "nm-dbus-interface.h" #include "nm-core-internal.h" #include "nm-dbus-compat.h" diff --git a/src/nm-dbus-object.h b/src/nm-dbus-object.h index 947ea6c7dd..43613630bb 100644 --- a/src/nm-dbus-object.h +++ b/src/nm-dbus-object.h @@ -23,7 +23,7 @@ /*****************************************************************************/ -#include "nm-utils/c-list.h" +#include "c-list/src/c-list.h" #include "nm-dbus-utils.h" /*****************************************************************************/ diff --git a/src/nm-firewall-manager.c b/src/nm-firewall-manager.c index 216d5fc81c..134a46f7ec 100644 --- a/src/nm-firewall-manager.c +++ b/src/nm-firewall-manager.c @@ -25,7 +25,7 @@ #include #include "NetworkManagerUtils.h" -#include "nm-utils/c-list.h" +#include "c-list/src/c-list.h" /*****************************************************************************/ diff --git a/src/nm-manager.h b/src/nm-manager.h index 9e94e97064..5444453203 100644 --- a/src/nm-manager.h +++ b/src/nm-manager.h @@ -23,7 +23,7 @@ #define __NETWORKMANAGER_MANAGER_H__ #include "settings/nm-settings-connection.h" -#include "nm-utils/c-list.h" +#include "c-list/src/c-list.h" #include "nm-dbus-manager.h" #define NM_TYPE_MANAGER (nm_manager_get_type ()) diff --git a/src/nm-pacrunner-manager.c b/src/nm-pacrunner-manager.c index 393b429ca1..caae8b203f 100644 --- a/src/nm-pacrunner-manager.c +++ b/src/nm-pacrunner-manager.c @@ -27,7 +27,7 @@ #include "nm-proxy-config.h" #include "nm-ip4-config.h" #include "nm-ip6-config.h" -#include "nm-utils/c-list.h" +#include "c-list/src/c-list.h" #define PACRUNNER_DBUS_SERVICE "org.pacrunner" #define PACRUNNER_DBUS_INTERFACE "org.pacrunner.Manager" diff --git a/src/settings/nm-agent-manager.c b/src/settings/nm-agent-manager.c index 00aa3a0865..453136e4e7 100644 --- a/src/settings/nm-agent-manager.c +++ b/src/settings/nm-agent-manager.c @@ -36,7 +36,7 @@ #include "nm-simple-connection.h" #include "NetworkManagerUtils.h" #include "nm-core-internal.h" -#include "nm-utils/c-list.h" +#include "c-list/src/c-list.h" /*****************************************************************************/ diff --git a/src/settings/nm-secret-agent.c b/src/settings/nm-secret-agent.c index 1f6f15a905..af6d7017bd 100644 --- a/src/settings/nm-secret-agent.c +++ b/src/settings/nm-secret-agent.c @@ -31,7 +31,7 @@ #include "nm-auth-subject.h" #include "nm-simple-connection.h" #include "NetworkManagerUtils.h" -#include "nm-utils/c-list.h" +#include "c-list/src/c-list.h" /*****************************************************************************/ diff --git a/src/settings/nm-settings-connection.c b/src/settings/nm-settings-connection.c index a71de91531..0b998372d7 100644 --- a/src/settings/nm-settings-connection.c +++ b/src/settings/nm-settings-connection.c @@ -25,7 +25,7 @@ #include -#include "nm-utils/c-list.h" +#include "c-list/src/c-list.h" #include "nm-common-macros.h" #include "nm-config.h" diff --git a/src/settings/plugins/ifcfg-rh/shvar.c b/src/settings/plugins/ifcfg-rh/shvar.c index c0dad6ab27..9120b870eb 100644 --- a/src/settings/plugins/ifcfg-rh/shvar.c +++ b/src/settings/plugins/ifcfg-rh/shvar.c @@ -39,7 +39,7 @@ #include "nm-core-internal.h" #include "nm-core-utils.h" #include "nm-utils/nm-enum-utils.h" -#include "nm-utils/c-list.h" +#include "c-list/src/c-list.h" /*****************************************************************************/