1 /* -*- mode: C; c-file-style: "gnu" -*- */
2 /* dbus-list.c Generic linked list utility (internal to D-BUS implementation)
4 * Copyright (C) 2002 Red Hat, Inc.
6 * Licensed under the Academic Free License version 1.2
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #include "dbus-internals.h"
25 #include "dbus-list.h"
26 #include "dbus-mempool.h"
27 #include "dbus-threads.h"
30 * @defgroup DBusList Linked list
31 * @ingroup DBusInternals
32 * @brief DBusList data structure
34 * Types and functions related to DBusList.
37 static DBusMemPool *list_pool;
38 _DBUS_DEFINE_GLOBAL_LOCK (list);
41 * @defgroup DBusListInternals Linked list implementation details
42 * @ingroup DBusInternals
43 * @brief DBusList implementation details
45 * The guts of DBusList.
50 /* the mem pool is probably a speed hit, with the thread
51 * lock, though it does still save memory - unknown.
54 alloc_link (void *data)
58 if (!_DBUS_LOCK (list))
61 if (list_pool == NULL)
63 list_pool = _dbus_mem_pool_new (sizeof (DBusList), TRUE);
65 if (list_pool == NULL)
71 link = _dbus_mem_pool_alloc (list_pool);
74 _dbus_mem_pool_free (list_pool);
82 link = _dbus_mem_pool_alloc (list_pool);
94 free_link (DBusList *link)
97 if (_dbus_mem_pool_dealloc (list_pool, link))
99 _dbus_mem_pool_free (list_pool);
107 link_before (DBusList **list,
108 DBusList *before_this_link,
119 link->next = before_this_link;
120 link->prev = before_this_link->prev;
121 before_this_link->prev = link;
122 link->prev->next = link;
124 if (before_this_link == *list)
130 link_after (DBusList **list,
131 DBusList *after_this_link,
142 link->prev = after_this_link;
143 link->next = after_this_link->next;
144 after_this_link->next = link;
145 link->next->prev = link;
152 * @addtogroup DBusList
159 * A node in a linked list.
161 * DBusList is a circular list; that is, the tail of the list
162 * points back to the head of the list. The empty list is
163 * represented by a #NULL pointer.
167 * @def _dbus_list_get_next_link
169 * Gets the next link in the list, or #NULL if
170 * there are no more links. Used for iteration.
174 * link = _dbus_list_get_first_link (&list);
175 * while (link != NULL)
177 * printf ("value is %p\n", link->data);
178 * link = _dbus_list_get_next_link (&link);
182 * @param list address of the list head.
183 * @param link current link.
184 * @returns the next link, or %NULL if none.
189 * @def _dbus_list_get_prev_link
191 * Gets the previous link in the list, or #NULL if
192 * there are no more links. Used for iteration.
196 * link = _dbus_list_get_last_link (&list);
197 * while (link != NULL)
199 * printf ("value is %p\n", link->data);
200 * link = _dbus_list_get_prev_link (&link);
204 * @param list address of the list head.
205 * @param link current link.
206 * @returns the previous link, or %NULL if none.
211 * Allocates a linked list node. Useful for preallocating
212 * nodes and using _dbus_list_append_link() to avoid
215 * @param data the value to store in the link.
216 * @returns a newly allocated link.
219 _dbus_list_alloc_link (void *data)
221 return alloc_link (data);
225 * Frees a linked list node allocated with _dbus_list_alloc_link.
226 * Does not free the data in the node.
228 * @param link the list node
231 _dbus_list_free_link (DBusList *link)
238 * Appends a value to the list. May return #FALSE
239 * if insufficient memory exists to add a list link.
240 * This is a constant-time operation.
242 * @param list address of the list head.
243 * @param data the value to append.
244 * @returns #TRUE on success.
247 _dbus_list_append (DBusList **list,
250 if (!_dbus_list_prepend (list, data))
253 /* Now cycle the list forward one so the prepended node is the tail */
254 *list = (*list)->next;
260 * Prepends a value to the list. May return #FALSE
261 * if insufficient memory exists to add a list link.
262 * This is a constant-time operation.
264 * @param list address of the list head.
265 * @param data the value to prepend.
266 * @returns #TRUE on success.
269 _dbus_list_prepend (DBusList **list,
274 link = alloc_link (data);
278 link_before (list, *list, link);
284 * Appends a link to the list.
285 * Cannot fail due to out of memory.
286 * This is a constant-time operation.
288 * @param list address of the list head.
289 * @param link the link to append.
292 _dbus_list_append_link (DBusList **list,
295 _dbus_list_prepend_link (list, link);
297 /* Now cycle the list forward one so the prepended node is the tail */
298 *list = (*list)->next;
302 * Prepends a link to the list.
303 * Cannot fail due to out of memory.
304 * This is a constant-time operation.
306 * @param list address of the list head.
307 * @param link the link to prepend.
310 _dbus_list_prepend_link (DBusList **list,
313 link_before (list, *list, link);
317 * Inserts data into the list before the given existing link.
319 * @param list the list to modify
320 * @param before_this_link existing link to insert before, or #NULL to append
321 * @param data the value to insert
322 * @returns #TRUE on success, #FALSE if memory allocation fails
325 _dbus_list_insert_before (DBusList **list,
326 DBusList *before_this_link,
331 if (before_this_link == NULL)
332 return _dbus_list_append (list, data);
335 link = alloc_link (data);
339 link_before (list, before_this_link, link);
346 * Inserts data into the list after the given existing link.
348 * @param list the list to modify
349 * @param after_this_link existing link to insert after, or #NULL to prepend
350 * @param data the value to insert
351 * @returns #TRUE on success, #FALSE if memory allocation fails
354 _dbus_list_insert_after (DBusList **list,
355 DBusList *after_this_link,
360 if (after_this_link == NULL)
361 return _dbus_list_prepend (list, data);
364 link = alloc_link (data);
368 link_after (list, after_this_link, link);
375 * Inserts a link into the list before the given existing link.
377 * @param list the list to modify
378 * @param before_this_link existing link to insert before, or #NULL to append
379 * @param link the link to insert
382 _dbus_list_insert_before_link (DBusList **list,
383 DBusList *before_this_link,
386 if (before_this_link == NULL)
387 _dbus_list_append_link (list, link);
389 link_before (list, before_this_link, link);
393 * Inserts a link into the list after the given existing link.
395 * @param list the list to modify
396 * @param after_this_link existing link to insert after, or #NULL to prepend
397 * @param link the link to insert
400 _dbus_list_insert_after_link (DBusList **list,
401 DBusList *after_this_link,
404 if (after_this_link == NULL)
405 _dbus_list_prepend_link (list, link);
407 link_after (list, after_this_link, link);
411 * Removes a value from the list. Only removes the
412 * first value equal to the given data pointer,
413 * even if multiple values exist which match.
414 * This is a linear-time operation.
416 * @param list address of the list head.
417 * @param data the value to remove.
418 * @returns #TRUE if a value was found to remove.
421 _dbus_list_remove (DBusList **list,
429 if (link->data == data)
431 _dbus_list_remove_link (list, link);
435 link = _dbus_list_get_next_link (list, link);
442 * Removes a value from the list. Only removes the
443 * last value equal to the given data pointer,
444 * even if multiple values exist which match.
445 * This is a linear-time operation.
447 * @param list address of the list head.
448 * @param data the value to remove.
449 * @returns #TRUE if a value was found to remove.
452 _dbus_list_remove_last (DBusList **list,
457 link = _dbus_list_get_last_link (list);
461 if (link->data == data)
463 _dbus_list_remove_link (list, link);
467 link = _dbus_list_get_prev_link (list, link);
474 _dbus_list_unlink (DBusList **list,
477 if (link->next == link)
479 /* one-element list */
484 link->prev->next = link->next;
485 link->next->prev = link->prev;
493 * Removes a link from the list. This is a constant-time operation.
495 * @param list address of the list head.
496 * @param link the list link to remove.
499 _dbus_list_remove_link (DBusList **list,
502 _dbus_list_unlink (list, link);
507 * Frees all links in the list and sets the list head to #NULL. Does
508 * not free the data in each link, for obvious reasons. This is a
509 * linear-time operation.
511 * @param list address of the list head.
514 _dbus_list_clear (DBusList **list)
521 DBusList *next = _dbus_list_get_next_link (list, link);
532 * Gets the first link in the list.
533 * This is a constant-time operation.
535 * @param list address of the list head.
536 * @returns the first link, or #NULL for an empty list.
539 _dbus_list_get_first_link (DBusList **list)
545 * Gets the last link in the list.
546 * This is a constant-time operation.
548 * @param list address of the list head.
549 * @returns the last link, or #NULL for an empty list.
552 _dbus_list_get_last_link (DBusList **list)
557 return (*list)->prev;
561 * Gets the last data in the list.
562 * This is a constant-time operation.
564 * @param list address of the list head.
565 * @returns the last data in the list, or #NULL for an empty list.
568 _dbus_list_get_last (DBusList **list)
573 return (*list)->prev->data;
577 * Gets the first data in the list.
578 * This is a constant-time operation.
580 * @param list address of the list head.
581 * @returns the first data in the list, or #NULL for an empty list.
584 _dbus_list_get_first (DBusList **list)
589 return (*list)->data;
593 * Removes the first link in the list and returns it. This is a
594 * constant-time operation.
596 * @param list address of the list head.
597 * @returns the first link in the list, or #NULL for an empty list.
600 _dbus_list_pop_first_link (DBusList **list)
604 link = _dbus_list_get_first_link (list);
608 _dbus_list_unlink (list, link);
614 * Removes the first value in the list and returns it. This is a
615 * constant-time operation.
617 * @param list address of the list head.
618 * @returns the first data in the list, or #NULL for an empty list.
621 _dbus_list_pop_first (DBusList **list)
626 link = _dbus_list_get_first_link (list);
631 _dbus_list_remove_link (list, link);
637 * Removes the last value in the list and returns it. This is a
638 * constant-time operation.
640 * @param list address of the list head.
641 * @returns the last data in the list, or #NULL for an empty list.
644 _dbus_list_pop_last (DBusList **list)
649 link = _dbus_list_get_last_link (list);
654 _dbus_list_remove_link (list, link);
660 * Removes the last link in the list and returns it. This is a
661 * constant-time operation.
663 * @param list address of the list head.
664 * @returns the last link in the list, or #NULL for an empty list.
667 _dbus_list_pop_last_link (DBusList **list)
671 link = _dbus_list_get_last_link (list);
675 _dbus_list_unlink (list, link);
681 * Copies a list. This is a linear-time operation. If there isn't
682 * enough memory to copy the entire list, the destination list will be
685 * @param list address of the head of the list to copy.
686 * @param dest address where the copied list should be placed.
687 * @returns #TRUE on success, #FALSE if not enough memory.
690 _dbus_list_copy (DBusList **list,
695 _dbus_assert (list != dest);
702 if (!_dbus_list_append (dest, link->data))
704 /* free what we have so far */
705 _dbus_list_clear (dest);
709 link = _dbus_list_get_next_link (list, link);
716 * Gets the length of a list. This is a linear-time
719 * @param list address of the head of the list
720 * @returns number of elements in the list.
723 _dbus_list_get_length (DBusList **list)
735 link = _dbus_list_get_next_link (list, link);
742 * Calls the given function for each element in the list. The
743 * function is passed the list element as its first argument, and the
744 * given data as its second argument.
746 * @param list address of the head of the list.
747 * @param function function to call for each element.
748 * @param data extra data for the function.
752 _dbus_list_foreach (DBusList **list,
753 DBusForeachFunction function,
761 DBusList *next = _dbus_list_get_next_link (list, link);
763 (* function) (link->data, data);
770 * Check whether length is exactly one.
772 * @param list the list
773 * @returns #TRUE if length is exactly one
776 _dbus_list_length_is_one (DBusList **list)
778 return (*list != NULL &&
779 (*list)->next == *list);
784 #ifdef DBUS_BUILD_TESTS
785 #include "dbus-test.h"
789 verify_list (DBusList **list)
799 if (link->next == link)
801 _dbus_assert (link->prev == link);
802 _dbus_assert (*list == link);
810 _dbus_assert (link->prev->next == link);
811 _dbus_assert (link->next->prev == link);
814 while (link != *list);
816 _dbus_assert (length == _dbus_list_get_length (list));
819 _dbus_assert (_dbus_list_length_is_one (list));
821 _dbus_assert (!_dbus_list_length_is_one (list));
825 is_ascending_sequence (DBusList **list)
830 prev = _DBUS_INT_MIN;
832 link = _dbus_list_get_first_link (list);
835 int v = _DBUS_POINTER_TO_INT (link->data);
842 link = _dbus_list_get_next_link (list, link);
849 is_descending_sequence (DBusList **list)
854 prev = _DBUS_INT_MAX;
856 link = _dbus_list_get_first_link (list);
859 int v = _DBUS_POINTER_TO_INT (link->data);
866 link = _dbus_list_get_next_link (list, link);
873 all_even_values (DBusList **list)
877 link = _dbus_list_get_first_link (list);
880 int v = _DBUS_POINTER_TO_INT (link->data);
885 link = _dbus_list_get_next_link (list, link);
892 all_odd_values (DBusList **list)
896 link = _dbus_list_get_first_link (list);
899 int v = _DBUS_POINTER_TO_INT (link->data);
904 link = _dbus_list_get_next_link (list, link);
911 lists_equal (DBusList **list1,
917 link1 = _dbus_list_get_first_link (list1);
918 link2 = _dbus_list_get_first_link (list2);
919 while (link1 && link2)
921 if (link1->data != link2->data)
924 link1 = _dbus_list_get_next_link (list1, link1);
925 link2 = _dbus_list_get_next_link (list2, link2);
935 * @ingroup DBusListInternals
936 * Unit test for DBusList
937 * @returns #TRUE on success.
940 _dbus_list_test (void)
953 /* Test append and prepend */
958 if (!_dbus_list_append (&list1, _DBUS_INT_TO_POINTER (i)))
959 _dbus_assert_not_reached ("could not allocate for append");
961 if (!_dbus_list_prepend (&list2, _DBUS_INT_TO_POINTER (i)))
962 _dbus_assert_not_reached ("count not allocate for prepend");
965 verify_list (&list1);
966 verify_list (&list2);
968 _dbus_assert (_dbus_list_get_length (&list1) == i);
969 _dbus_assert (_dbus_list_get_length (&list2) == i);
972 _dbus_assert (is_ascending_sequence (&list1));
973 _dbus_assert (is_descending_sequence (&list2));
975 /* Test list clear */
976 _dbus_list_clear (&list1);
977 _dbus_list_clear (&list2);
979 verify_list (&list1);
980 verify_list (&list2);
982 /* Test get_first, get_last, pop_first, pop_last */
987 _dbus_list_append (&list1, _DBUS_INT_TO_POINTER (i));
988 _dbus_list_prepend (&list2, _DBUS_INT_TO_POINTER (i));
1001 got_data1 = _dbus_list_get_last (&list1);
1002 got_data2 = _dbus_list_get_first (&list2);
1004 data1 = _dbus_list_pop_last (&list1);
1005 data2 = _dbus_list_pop_first (&list2);
1007 _dbus_assert (got_data1 == data1);
1008 _dbus_assert (got_data2 == data2);
1010 _dbus_assert (_DBUS_POINTER_TO_INT (data1) == i);
1011 _dbus_assert (_DBUS_POINTER_TO_INT (data2) == i);
1013 verify_list (&list1);
1014 verify_list (&list2);
1016 _dbus_assert (is_ascending_sequence (&list1));
1017 _dbus_assert (is_descending_sequence (&list2));
1022 _dbus_assert (list1 == NULL);
1023 _dbus_assert (list2 == NULL);
1025 /* Test get_first_link, get_last_link, pop_first_link, pop_last_link */
1030 _dbus_list_append (&list1, _DBUS_INT_TO_POINTER (i));
1031 _dbus_list_prepend (&list2, _DBUS_INT_TO_POINTER (i));
1038 DBusList *got_link1;
1039 DBusList *got_link2;
1047 got_link1 = _dbus_list_get_last_link (&list1);
1048 got_link2 = _dbus_list_get_first_link (&list2);
1050 link1 = _dbus_list_pop_last_link (&list1);
1051 link2 = _dbus_list_pop_first_link (&list2);
1053 _dbus_assert (got_link1 == link1);
1054 _dbus_assert (got_link2 == link2);
1056 data1 = link1->data;
1057 data2 = link2->data;
1059 _dbus_list_free_link (link1);
1060 _dbus_list_free_link (link2);
1062 _dbus_assert (_DBUS_POINTER_TO_INT (data1) == i);
1063 _dbus_assert (_DBUS_POINTER_TO_INT (data2) == i);
1065 verify_list (&list1);
1066 verify_list (&list2);
1068 _dbus_assert (is_ascending_sequence (&list1));
1069 _dbus_assert (is_descending_sequence (&list2));
1074 _dbus_assert (list1 == NULL);
1075 _dbus_assert (list2 == NULL);
1077 /* Test iteration */
1082 _dbus_list_append (&list1, _DBUS_INT_TO_POINTER (i));
1083 _dbus_list_prepend (&list2, _DBUS_INT_TO_POINTER (i));
1086 verify_list (&list1);
1087 verify_list (&list2);
1089 _dbus_assert (_dbus_list_get_length (&list1) == i);
1090 _dbus_assert (_dbus_list_get_length (&list2) == i);
1093 _dbus_assert (is_ascending_sequence (&list1));
1094 _dbus_assert (is_descending_sequence (&list2));
1097 link2 = _dbus_list_get_first_link (&list2);
1098 while (link2 != NULL)
1100 verify_list (&link2); /* pretend this link is the head */
1102 _dbus_assert (_DBUS_POINTER_TO_INT (link2->data) == i);
1104 link2 = _dbus_list_get_next_link (&list2, link2);
1109 link1 = _dbus_list_get_first_link (&list1);
1110 while (link1 != NULL)
1112 verify_list (&link1); /* pretend this link is the head */
1114 _dbus_assert (_DBUS_POINTER_TO_INT (link1->data) == i);
1116 link1 = _dbus_list_get_next_link (&list1, link1);
1121 link1 = _dbus_list_get_last_link (&list1);
1122 while (link1 != NULL)
1124 verify_list (&link1); /* pretend this link is the head */
1126 _dbus_assert (_DBUS_POINTER_TO_INT (link1->data) == i);
1128 link1 = _dbus_list_get_prev_link (&list1, link1);
1132 _dbus_list_clear (&list1);
1133 _dbus_list_clear (&list2);
1140 _dbus_list_append (&list1, _DBUS_INT_TO_POINTER (i));
1141 _dbus_list_prepend (&list2, _DBUS_INT_TO_POINTER (i));
1150 if (!_dbus_list_remove (&list1, _DBUS_INT_TO_POINTER (i)))
1151 _dbus_assert_not_reached ("element should have been in list");
1152 if (!_dbus_list_remove (&list2, _DBUS_INT_TO_POINTER (i)))
1153 _dbus_assert_not_reached ("element should have been in list");
1155 verify_list (&list1);
1156 verify_list (&list2);
1161 _dbus_assert (all_odd_values (&list1));
1162 _dbus_assert (all_odd_values (&list2));
1164 _dbus_list_clear (&list1);
1165 _dbus_list_clear (&list2);
1167 /* test removing the other half of the elements */
1172 _dbus_list_append (&list1, _DBUS_INT_TO_POINTER (i));
1173 _dbus_list_prepend (&list2, _DBUS_INT_TO_POINTER (i));
1182 if (!_dbus_list_remove (&list1, _DBUS_INT_TO_POINTER (i)))
1183 _dbus_assert_not_reached ("element should have been in list");
1184 if (!_dbus_list_remove (&list2, _DBUS_INT_TO_POINTER (i)))
1185 _dbus_assert_not_reached ("element should have been in list");
1187 verify_list (&list1);
1188 verify_list (&list2);
1193 _dbus_assert (all_even_values (&list1));
1194 _dbus_assert (all_even_values (&list2));
1196 /* clear list using remove_link */
1197 while (list1 != NULL)
1199 _dbus_list_remove_link (&list1, list1);
1200 verify_list (&list1);
1202 while (list2 != NULL)
1204 _dbus_list_remove_link (&list2, list2);
1205 verify_list (&list2);
1208 /* Test remove link more generally */
1212 _dbus_list_append (&list1, _DBUS_INT_TO_POINTER (i));
1213 _dbus_list_prepend (&list2, _DBUS_INT_TO_POINTER (i));
1218 link2 = _dbus_list_get_first_link (&list2);
1219 while (link2 != NULL)
1221 DBusList *next = _dbus_list_get_next_link (&list2, link2);
1223 _dbus_assert (_DBUS_POINTER_TO_INT (link2->data) == i);
1226 _dbus_list_remove_link (&list2, link2);
1228 verify_list (&list2);
1234 _dbus_assert (all_odd_values (&list2));
1235 _dbus_list_clear (&list2);
1238 link1 = _dbus_list_get_first_link (&list1);
1239 while (link1 != NULL)
1241 DBusList *next = _dbus_list_get_next_link (&list1, link1);
1243 _dbus_assert (_DBUS_POINTER_TO_INT (link1->data) == i);
1246 _dbus_list_remove_link (&list1, link1);
1248 verify_list (&list1);
1254 _dbus_assert (all_even_values (&list1));
1255 _dbus_list_clear (&list1);
1257 /* Test copying a list */
1261 _dbus_list_append (&list1, _DBUS_INT_TO_POINTER (i));
1262 _dbus_list_prepend (&list2, _DBUS_INT_TO_POINTER (i));
1266 /* bad pointers, because they are allowed in the copy dest */
1267 copy1 = _DBUS_INT_TO_POINTER (0x342234);
1268 copy2 = _DBUS_INT_TO_POINTER (23);
1270 _dbus_list_copy (&list1, ©1);
1271 verify_list (&list1);
1272 verify_list (©1);
1273 _dbus_assert (lists_equal (&list1, ©1));
1275 _dbus_list_copy (&list2, ©2);
1276 verify_list (&list2);
1277 verify_list (©2);
1278 _dbus_assert (lists_equal (&list2, ©2));
1280 /* Now test copying empty lists */
1281 _dbus_list_clear (&list1);
1282 _dbus_list_clear (&list2);
1283 _dbus_list_clear (©1);
1284 _dbus_list_clear (©2);
1286 /* bad pointers, because they are allowed in the copy dest */
1287 copy1 = _DBUS_INT_TO_POINTER (0x342234);
1288 copy2 = _DBUS_INT_TO_POINTER (23);
1290 _dbus_list_copy (&list1, ©1);
1291 verify_list (&list1);
1292 verify_list (©1);
1293 _dbus_assert (lists_equal (&list1, ©1));
1295 _dbus_list_copy (&list2, ©2);
1296 verify_list (&list2);
1297 verify_list (©2);
1298 _dbus_assert (lists_equal (&list2, ©2));
1300 _dbus_list_clear (&list1);
1301 _dbus_list_clear (&list2);
1303 /* insert_before on empty list */
1304 _dbus_list_insert_before (&list1, NULL,
1305 _DBUS_INT_TO_POINTER (0));
1306 verify_list (&list1);
1308 /* inserting before first element */
1309 _dbus_list_insert_before (&list1, list1,
1310 _DBUS_INT_TO_POINTER (2));
1311 verify_list (&list1);
1312 _dbus_assert (is_descending_sequence (&list1));
1314 /* inserting in the middle */
1315 _dbus_list_insert_before (&list1, list1->next,
1316 _DBUS_INT_TO_POINTER (1));
1317 verify_list (&list1);
1318 _dbus_assert (is_descending_sequence (&list1));
1320 /* using insert_before to append */
1321 _dbus_list_insert_before (&list1, NULL,
1322 _DBUS_INT_TO_POINTER (-1));
1323 verify_list (&list1);
1324 _dbus_assert (is_descending_sequence (&list1));
1326 _dbus_list_clear (&list1);
1328 /* insert_after on empty list */
1329 _dbus_list_insert_after (&list1, NULL,
1330 _DBUS_INT_TO_POINTER (0));
1331 verify_list (&list1);
1333 /* inserting after first element */
1334 _dbus_list_insert_after (&list1, list1,
1335 _DBUS_INT_TO_POINTER (1));
1336 verify_list (&list1);
1337 _dbus_assert (is_ascending_sequence (&list1));
1339 /* inserting at the end */
1340 _dbus_list_insert_after (&list1, list1->next,
1341 _DBUS_INT_TO_POINTER (2));
1342 verify_list (&list1);
1343 _dbus_assert (is_ascending_sequence (&list1));
1345 /* using insert_after to prepend */
1346 _dbus_list_insert_after (&list1, NULL,
1347 _DBUS_INT_TO_POINTER (-1));
1348 verify_list (&list1);
1349 _dbus_assert (is_ascending_sequence (&list1));
1351 _dbus_list_clear (&list1);
1353 /* using remove_last */
1354 _dbus_list_append (&list1, _DBUS_INT_TO_POINTER (2));
1355 _dbus_list_append (&list1, _DBUS_INT_TO_POINTER (1));
1356 _dbus_list_append (&list1, _DBUS_INT_TO_POINTER (3));
1358 _dbus_list_remove_last (&list1, _DBUS_INT_TO_POINTER (2));
1360 verify_list (&list1);
1361 _dbus_assert (is_ascending_sequence (&list1));
1363 _dbus_list_clear (&list1);