1 /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
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 2.1
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
25 #include "dbus-internals.h"
26 #include "dbus-list.h"
27 #include "dbus-mempool.h"
28 #include "dbus-threads-internal.h"
31 * @defgroup DBusList Linked list
32 * @ingroup DBusInternals
33 * @brief DBusList data structure
35 * Types and functions related to DBusList.
38 /* Protected by _DBUS_LOCK (list) */
39 static DBusMemPool *list_pool;
42 * @defgroup DBusListInternals Linked list implementation details
43 * @ingroup DBusInternals
44 * @brief DBusList implementation details
46 * The guts of DBusList.
51 /* the mem pool is probably a speed hit, with the thread
52 * lock, though it does still save memory - unknown.
55 alloc_link (void *data)
59 if (!_DBUS_LOCK (list))
62 if (list_pool == NULL)
64 list_pool = _dbus_mem_pool_new (sizeof (DBusList), TRUE);
66 if (list_pool == NULL)
72 link = _dbus_mem_pool_alloc (list_pool);
75 _dbus_mem_pool_free (list_pool);
83 link = _dbus_mem_pool_alloc (list_pool);
95 free_link (DBusList *link)
97 if (!_DBUS_LOCK (list))
98 _dbus_assert_not_reached ("we should have initialized global locks "
99 "before we allocated a linked-list link");
101 if (_dbus_mem_pool_dealloc (list_pool, link))
103 _dbus_mem_pool_free (list_pool);
111 link_before (DBusList **list,
112 DBusList *before_this_link,
123 link->next = before_this_link;
124 link->prev = before_this_link->prev;
125 before_this_link->prev = link;
126 link->prev->next = link;
128 if (before_this_link == *list)
134 link_after (DBusList **list,
135 DBusList *after_this_link,
146 link->prev = after_this_link;
147 link->next = after_this_link->next;
148 after_this_link->next = link;
149 link->next->prev = link;
153 #ifdef DBUS_ENABLE_STATS
155 _dbus_list_get_stats (dbus_uint32_t *in_use_p,
156 dbus_uint32_t *in_free_list_p,
157 dbus_uint32_t *allocated_p)
159 if (!_DBUS_LOCK (list))
167 _dbus_mem_pool_get_stats (list_pool, in_use_p, in_free_list_p, allocated_p);
175 * @addtogroup DBusList
182 * A node in a linked list.
184 * DBusList is a circular list; that is, the tail of the list
185 * points back to the head of the list. The empty list is
186 * represented by a #NULL pointer.
190 * @def _dbus_list_get_next_link
192 * Gets the next link in the list, or #NULL if
193 * there are no more links. Used for iteration.
197 * link = _dbus_list_get_first_link (&list);
198 * while (link != NULL)
200 * printf ("value is %p\n", link->data);
201 * link = _dbus_list_get_next_link (&link);
205 * @param list address of the list head.
206 * @param link current link.
207 * @returns the next link, or %NULL if none.
212 * @def _dbus_list_get_prev_link
214 * Gets the previous link in the list, or #NULL if
215 * there are no more links. Used for iteration.
219 * link = _dbus_list_get_last_link (&list);
220 * while (link != NULL)
222 * printf ("value is %p\n", link->data);
223 * link = _dbus_list_get_prev_link (&link);
227 * @param list address of the list head.
228 * @param link current link.
229 * @returns the previous link, or %NULL if none.
234 * Allocates a linked list node. Useful for preallocating
235 * nodes and using _dbus_list_append_link() to avoid
238 * @param data the value to store in the link.
239 * @returns a newly allocated link.
242 _dbus_list_alloc_link (void *data)
244 return alloc_link (data);
248 * Frees a linked list node allocated with _dbus_list_alloc_link.
249 * Does not free the data in the node.
251 * @param link the list node
254 _dbus_list_free_link (DBusList *link)
261 * Appends a value to the list. May return #FALSE
262 * if insufficient memory exists to add a list link.
263 * This is a constant-time operation.
265 * @param list address of the list head.
266 * @param data the value to append.
267 * @returns #TRUE on success.
270 _dbus_list_append (DBusList **list,
273 if (!_dbus_list_prepend (list, data))
276 /* Now cycle the list forward one so the prepended node is the tail */
277 *list = (*list)->next;
283 * Prepends a value to the list. May return #FALSE
284 * if insufficient memory exists to add a list link.
285 * This is a constant-time operation.
287 * @param list address of the list head.
288 * @param data the value to prepend.
289 * @returns #TRUE on success.
292 _dbus_list_prepend (DBusList **list,
297 link = alloc_link (data);
301 link_before (list, *list, link);
307 * Appends a link to the list.
308 * Cannot fail due to out of memory.
309 * This is a constant-time operation.
311 * @param list address of the list head.
312 * @param link the link to append.
315 _dbus_list_append_link (DBusList **list,
318 _dbus_list_prepend_link (list, link);
320 /* Now cycle the list forward one so the prepended node is the tail */
321 *list = (*list)->next;
325 * Prepends a link to the list.
326 * Cannot fail due to out of memory.
327 * This is a constant-time operation.
329 * @param list address of the list head.
330 * @param link the link to prepend.
333 _dbus_list_prepend_link (DBusList **list,
336 link_before (list, *list, link);
340 * Inserts data into the list after the given existing link.
342 * @param list the list to modify
343 * @param after_this_link existing link to insert after, or #NULL to prepend
344 * @param data the value to insert
345 * @returns #TRUE on success, #FALSE if memory allocation fails
348 _dbus_list_insert_after (DBusList **list,
349 DBusList *after_this_link,
354 if (after_this_link == NULL)
355 return _dbus_list_prepend (list, data);
358 link = alloc_link (data);
362 link_after (list, after_this_link, link);
369 * Inserts a link into the list before the given existing link.
371 * @param list the list to modify
372 * @param before_this_link existing link to insert before, or #NULL to append
373 * @param link the link to insert
376 _dbus_list_insert_before_link (DBusList **list,
377 DBusList *before_this_link,
380 if (before_this_link == NULL)
381 _dbus_list_append_link (list, link);
383 link_before (list, before_this_link, link);
387 * Inserts a link into the list after the given existing link.
389 * @param list the list to modify
390 * @param after_this_link existing link to insert after, or #NULL to prepend
391 * @param link the link to insert
394 _dbus_list_insert_after_link (DBusList **list,
395 DBusList *after_this_link,
398 if (after_this_link == NULL)
399 _dbus_list_prepend_link (list, link);
401 link_after (list, after_this_link, link);
405 * Removes a value from the list. Only removes the
406 * first value equal to the given data pointer,
407 * even if multiple values exist which match.
408 * This is a linear-time operation.
410 * @param list address of the list head.
411 * @param data the value to remove.
412 * @returns #TRUE if a value was found to remove.
415 _dbus_list_remove (DBusList **list,
423 if (link->data == data)
425 _dbus_list_remove_link (list, link);
429 link = _dbus_list_get_next_link (list, link);
436 * Removes a value from the list. Only removes the
437 * last value equal to the given data pointer,
438 * even if multiple values exist which match.
439 * This is a linear-time operation.
441 * @param list address of the list head.
442 * @param data the value to remove.
443 * @returns #TRUE if a value was found to remove.
446 _dbus_list_remove_last (DBusList **list,
451 link = _dbus_list_find_last (list, data);
454 _dbus_list_remove_link (list, link);
462 * Finds a value in the list. Returns the last link
463 * with value equal to the given data pointer.
464 * This is a linear-time operation.
465 * Returns #NULL if no value found that matches.
467 * @param list address of the list head.
468 * @param data the value to find.
469 * @returns the link if found
472 _dbus_list_find_last (DBusList **list,
477 link = _dbus_list_get_last_link (list);
481 if (link->data == data)
484 link = _dbus_list_get_prev_link (list, link);
491 * Removes the given link from the list, but doesn't
492 * free it. _dbus_list_remove_link() both removes the
493 * link and also frees it.
495 * @param list the list
496 * @param link the link in the list
499 _dbus_list_unlink (DBusList **list,
502 if (link->next == link)
504 /* one-element list */
509 link->prev->next = link->next;
510 link->next->prev = link->prev;
521 * Removes a link from the list. This is a constant-time operation.
523 * @param list address of the list head.
524 * @param link the list link to remove.
527 _dbus_list_remove_link (DBusList **list,
530 _dbus_list_unlink (list, link);
535 * Frees all links in the list and sets the list head to #NULL. Does
536 * not free the data in each link, for obvious reasons. This is a
537 * linear-time operation.
539 * @param list address of the list head.
542 _dbus_list_clear (DBusList **list)
549 DBusList *next = _dbus_list_get_next_link (list, link);
560 * Gets the first link in the list.
561 * This is a constant-time operation.
563 * @param list address of the list head.
564 * @returns the first link, or #NULL for an empty list.
567 _dbus_list_get_first_link (DBusList **list)
573 * Gets the last link in the list.
574 * This is a constant-time operation.
576 * @param list address of the list head.
577 * @returns the last link, or #NULL for an empty list.
580 _dbus_list_get_last_link (DBusList **list)
585 return (*list)->prev;
589 * Gets the last data in the list.
590 * This is a constant-time operation.
592 * @param list address of the list head.
593 * @returns the last data in the list, or #NULL for an empty list.
596 _dbus_list_get_last (DBusList **list)
601 return (*list)->prev->data;
605 * Gets the first data in the list.
606 * This is a constant-time operation.
608 * @param list address of the list head.
609 * @returns the first data in the list, or #NULL for an empty list.
612 _dbus_list_get_first (DBusList **list)
617 return (*list)->data;
621 * Removes the first link in the list and returns it. This is a
622 * constant-time operation.
624 * @param list address of the list head.
625 * @returns the first link in the list, or #NULL for an empty list.
628 _dbus_list_pop_first_link (DBusList **list)
632 link = _dbus_list_get_first_link (list);
636 _dbus_list_unlink (list, link);
642 * Removes the first value in the list and returns it. This is a
643 * constant-time operation.
645 * @param list address of the list head.
646 * @returns the first data in the list, or #NULL for an empty list.
649 _dbus_list_pop_first (DBusList **list)
654 link = _dbus_list_get_first_link (list);
659 _dbus_list_remove_link (list, link);
665 * Removes the last value in the list and returns it. This is a
666 * constant-time operation.
668 * @param list address of the list head.
669 * @returns the last data in the list, or #NULL for an empty list.
672 _dbus_list_pop_last (DBusList **list)
677 link = _dbus_list_get_last_link (list);
682 _dbus_list_remove_link (list, link);
688 * Copies a list. This is a linear-time operation. If there isn't
689 * enough memory to copy the entire list, the destination list will be
692 * @param list address of the head of the list to copy.
693 * @param dest address where the copied list should be placed.
694 * @returns #TRUE on success, #FALSE if not enough memory.
697 _dbus_list_copy (DBusList **list,
702 _dbus_assert (list != dest);
709 if (!_dbus_list_append (dest, link->data))
711 /* free what we have so far */
712 _dbus_list_clear (dest);
716 link = _dbus_list_get_next_link (list, link);
723 * Gets the length of a list. This is a linear-time
726 * @param list address of the head of the list
727 * @returns number of elements in the list.
730 _dbus_list_get_length (DBusList **list)
742 link = _dbus_list_get_next_link (list, link);
749 * Calls the given function for each element in the list. The
750 * function is passed the list element as its first argument, and the
751 * given data as its second argument.
753 * @param list address of the head of the list.
754 * @param function function to call for each element.
755 * @param data extra data for the function.
759 _dbus_list_foreach (DBusList **list,
760 DBusForeachFunction function,
768 DBusList *next = _dbus_list_get_next_link (list, link);
770 (* function) (link->data, data);
777 * Check whether length is exactly one.
779 * @param list the list
780 * @returns #TRUE if length is exactly one
783 _dbus_list_length_is_one (DBusList **list)
785 return (*list != NULL &&
786 (*list)->next == *list);
791 #ifdef DBUS_ENABLE_EMBEDDED_TESTS
792 #include "dbus-test.h"
796 verify_list (DBusList **list)
806 if (link->next == link)
808 _dbus_assert (link->prev == link);
809 _dbus_assert (*list == link);
817 _dbus_assert (link->prev->next == link);
818 _dbus_assert (link->next->prev == link);
821 while (link != *list);
823 _dbus_assert (length == _dbus_list_get_length (list));
826 _dbus_assert (_dbus_list_length_is_one (list));
828 _dbus_assert (!_dbus_list_length_is_one (list));
832 is_ascending_sequence (DBusList **list)
837 prev = _DBUS_INT_MIN;
839 link = _dbus_list_get_first_link (list);
842 int v = _DBUS_POINTER_TO_INT (link->data);
849 link = _dbus_list_get_next_link (list, link);
856 is_descending_sequence (DBusList **list)
861 prev = _DBUS_INT_MAX;
863 link = _dbus_list_get_first_link (list);
866 int v = _DBUS_POINTER_TO_INT (link->data);
873 link = _dbus_list_get_next_link (list, link);
880 all_even_values (DBusList **list)
884 link = _dbus_list_get_first_link (list);
887 int v = _DBUS_POINTER_TO_INT (link->data);
892 link = _dbus_list_get_next_link (list, link);
899 all_odd_values (DBusList **list)
903 link = _dbus_list_get_first_link (list);
906 int v = _DBUS_POINTER_TO_INT (link->data);
911 link = _dbus_list_get_next_link (list, link);
918 lists_equal (DBusList **list1,
924 link1 = _dbus_list_get_first_link (list1);
925 link2 = _dbus_list_get_first_link (list2);
926 while (link1 && link2)
928 if (link1->data != link2->data)
931 link1 = _dbus_list_get_next_link (list1, link1);
932 link2 = _dbus_list_get_next_link (list2, link2);
942 * @ingroup DBusListInternals
943 * Unit test for DBusList
944 * @returns #TRUE on success.
947 _dbus_list_test (void)
960 /* Test append and prepend */
965 if (!_dbus_list_append (&list1, _DBUS_INT_TO_POINTER (i)))
966 _dbus_assert_not_reached ("could not allocate for append");
968 if (!_dbus_list_prepend (&list2, _DBUS_INT_TO_POINTER (i)))
969 _dbus_assert_not_reached ("count not allocate for prepend");
972 verify_list (&list1);
973 verify_list (&list2);
975 _dbus_assert (_dbus_list_get_length (&list1) == i);
976 _dbus_assert (_dbus_list_get_length (&list2) == i);
979 _dbus_assert (is_ascending_sequence (&list1));
980 _dbus_assert (is_descending_sequence (&list2));
982 /* Test list clear */
983 _dbus_list_clear (&list1);
984 _dbus_list_clear (&list2);
986 verify_list (&list1);
987 verify_list (&list2);
989 /* Test get_first, get_last, pop_first, pop_last */
994 _dbus_list_append (&list1, _DBUS_INT_TO_POINTER (i));
995 _dbus_list_prepend (&list2, _DBUS_INT_TO_POINTER (i));
1008 got_data1 = _dbus_list_get_last (&list1);
1009 got_data2 = _dbus_list_get_first (&list2);
1011 data1 = _dbus_list_pop_last (&list1);
1012 data2 = _dbus_list_pop_first (&list2);
1014 _dbus_assert (got_data1 == data1);
1015 _dbus_assert (got_data2 == data2);
1017 _dbus_assert (_DBUS_POINTER_TO_INT (data1) == i);
1018 _dbus_assert (_DBUS_POINTER_TO_INT (data2) == i);
1020 verify_list (&list1);
1021 verify_list (&list2);
1023 _dbus_assert (is_ascending_sequence (&list1));
1024 _dbus_assert (is_descending_sequence (&list2));
1029 _dbus_assert (list1 == NULL);
1030 _dbus_assert (list2 == NULL);
1032 /* Test get_first_link, get_last_link, pop_first_link, pop_last_link */
1037 _dbus_list_append (&list1, _DBUS_INT_TO_POINTER (i));
1038 _dbus_list_prepend (&list2, _DBUS_INT_TO_POINTER (i));
1045 DBusList *got_link1;
1046 DBusList *got_link2;
1050 void *data1_indirect;
1054 got_link1 = _dbus_list_get_last_link (&list1);
1055 got_link2 = _dbus_list_get_first_link (&list2);
1057 link2 = _dbus_list_pop_first_link (&list2);
1059 _dbus_assert (got_link2 == link2);
1061 data1_indirect = got_link1->data;
1062 /* this call makes got_link1 invalid */
1063 data1 = _dbus_list_pop_last (&list1);
1064 _dbus_assert (data1 == data1_indirect);
1065 data2 = link2->data;
1067 _dbus_list_free_link (link2);
1069 _dbus_assert (_DBUS_POINTER_TO_INT (data1) == i);
1070 _dbus_assert (_DBUS_POINTER_TO_INT (data2) == i);
1072 verify_list (&list1);
1073 verify_list (&list2);
1075 _dbus_assert (is_ascending_sequence (&list1));
1076 _dbus_assert (is_descending_sequence (&list2));
1081 _dbus_assert (list1 == NULL);
1082 _dbus_assert (list2 == NULL);
1084 /* Test iteration */
1089 _dbus_list_append (&list1, _DBUS_INT_TO_POINTER (i));
1090 _dbus_list_prepend (&list2, _DBUS_INT_TO_POINTER (i));
1093 verify_list (&list1);
1094 verify_list (&list2);
1096 _dbus_assert (_dbus_list_get_length (&list1) == i);
1097 _dbus_assert (_dbus_list_get_length (&list2) == i);
1100 _dbus_assert (is_ascending_sequence (&list1));
1101 _dbus_assert (is_descending_sequence (&list2));
1104 link2 = _dbus_list_get_first_link (&list2);
1105 while (link2 != NULL)
1107 verify_list (&link2); /* pretend this link is the head */
1109 _dbus_assert (_DBUS_POINTER_TO_INT (link2->data) == i);
1111 link2 = _dbus_list_get_next_link (&list2, link2);
1116 link1 = _dbus_list_get_first_link (&list1);
1117 while (link1 != NULL)
1119 verify_list (&link1); /* pretend this link is the head */
1121 _dbus_assert (_DBUS_POINTER_TO_INT (link1->data) == i);
1123 link1 = _dbus_list_get_next_link (&list1, link1);
1128 link1 = _dbus_list_get_last_link (&list1);
1129 while (link1 != NULL)
1131 verify_list (&link1); /* pretend this link is the head */
1133 _dbus_assert (_DBUS_POINTER_TO_INT (link1->data) == i);
1135 link1 = _dbus_list_get_prev_link (&list1, link1);
1139 _dbus_list_clear (&list1);
1140 _dbus_list_clear (&list2);
1147 _dbus_list_append (&list1, _DBUS_INT_TO_POINTER (i));
1148 _dbus_list_prepend (&list2, _DBUS_INT_TO_POINTER (i));
1157 if (!_dbus_list_remove (&list1, _DBUS_INT_TO_POINTER (i)))
1158 _dbus_assert_not_reached ("element should have been in list");
1159 if (!_dbus_list_remove (&list2, _DBUS_INT_TO_POINTER (i)))
1160 _dbus_assert_not_reached ("element should have been in list");
1162 verify_list (&list1);
1163 verify_list (&list2);
1168 _dbus_assert (all_odd_values (&list1));
1169 _dbus_assert (all_odd_values (&list2));
1171 _dbus_list_clear (&list1);
1172 _dbus_list_clear (&list2);
1174 /* test removing the other half of the elements */
1179 _dbus_list_append (&list1, _DBUS_INT_TO_POINTER (i));
1180 _dbus_list_prepend (&list2, _DBUS_INT_TO_POINTER (i));
1189 if (!_dbus_list_remove (&list1, _DBUS_INT_TO_POINTER (i)))
1190 _dbus_assert_not_reached ("element should have been in list");
1191 if (!_dbus_list_remove (&list2, _DBUS_INT_TO_POINTER (i)))
1192 _dbus_assert_not_reached ("element should have been in list");
1194 verify_list (&list1);
1195 verify_list (&list2);
1200 _dbus_assert (all_even_values (&list1));
1201 _dbus_assert (all_even_values (&list2));
1203 /* clear list using remove_link */
1204 while (list1 != NULL)
1206 _dbus_list_remove_link (&list1, list1);
1207 verify_list (&list1);
1209 while (list2 != NULL)
1211 _dbus_list_remove_link (&list2, list2);
1212 verify_list (&list2);
1215 /* Test remove link more generally */
1219 _dbus_list_append (&list1, _DBUS_INT_TO_POINTER (i));
1220 _dbus_list_prepend (&list2, _DBUS_INT_TO_POINTER (i));
1225 link2 = _dbus_list_get_first_link (&list2);
1226 while (link2 != NULL)
1228 DBusList *next = _dbus_list_get_next_link (&list2, link2);
1230 _dbus_assert (_DBUS_POINTER_TO_INT (link2->data) == i);
1233 _dbus_list_remove_link (&list2, link2);
1235 verify_list (&list2);
1241 _dbus_assert (all_odd_values (&list2));
1242 _dbus_list_clear (&list2);
1245 link1 = _dbus_list_get_first_link (&list1);
1246 while (link1 != NULL)
1248 DBusList *next = _dbus_list_get_next_link (&list1, link1);
1250 _dbus_assert (_DBUS_POINTER_TO_INT (link1->data) == i);
1253 _dbus_list_remove_link (&list1, link1);
1255 verify_list (&list1);
1261 _dbus_assert (all_even_values (&list1));
1262 _dbus_list_clear (&list1);
1264 /* Test copying a list */
1268 _dbus_list_append (&list1, _DBUS_INT_TO_POINTER (i));
1269 _dbus_list_prepend (&list2, _DBUS_INT_TO_POINTER (i));
1273 /* bad pointers, because they are allowed in the copy dest */
1274 copy1 = _DBUS_INT_TO_POINTER (0x342234);
1275 copy2 = _DBUS_INT_TO_POINTER (23);
1277 _dbus_list_copy (&list1, ©1);
1278 verify_list (&list1);
1279 verify_list (©1);
1280 _dbus_assert (lists_equal (&list1, ©1));
1282 _dbus_list_copy (&list2, ©2);
1283 verify_list (&list2);
1284 verify_list (©2);
1285 _dbus_assert (lists_equal (&list2, ©2));
1287 /* Now test copying empty lists */
1288 _dbus_list_clear (&list1);
1289 _dbus_list_clear (&list2);
1290 _dbus_list_clear (©1);
1291 _dbus_list_clear (©2);
1293 /* bad pointers, because they are allowed in the copy dest */
1294 copy1 = _DBUS_INT_TO_POINTER (0x342234);
1295 copy2 = _DBUS_INT_TO_POINTER (23);
1297 _dbus_list_copy (&list1, ©1);
1298 verify_list (&list1);
1299 verify_list (©1);
1300 _dbus_assert (lists_equal (&list1, ©1));
1302 _dbus_list_copy (&list2, ©2);
1303 verify_list (&list2);
1304 verify_list (©2);
1305 _dbus_assert (lists_equal (&list2, ©2));
1307 _dbus_list_clear (&list1);
1308 _dbus_list_clear (&list2);
1310 /* insert_after on empty list */
1311 _dbus_list_insert_after (&list1, NULL,
1312 _DBUS_INT_TO_POINTER (0));
1313 verify_list (&list1);
1315 /* inserting after first element */
1316 _dbus_list_insert_after (&list1, list1,
1317 _DBUS_INT_TO_POINTER (1));
1318 verify_list (&list1);
1319 _dbus_assert (is_ascending_sequence (&list1));
1321 /* inserting at the end */
1322 _dbus_list_insert_after (&list1, list1->next,
1323 _DBUS_INT_TO_POINTER (2));
1324 verify_list (&list1);
1325 _dbus_assert (is_ascending_sequence (&list1));
1327 /* using insert_after to prepend */
1328 _dbus_list_insert_after (&list1, NULL,
1329 _DBUS_INT_TO_POINTER (-1));
1330 verify_list (&list1);
1331 _dbus_assert (is_ascending_sequence (&list1));
1333 _dbus_list_clear (&list1);
1335 /* using remove_last */
1336 _dbus_list_append (&list1, _DBUS_INT_TO_POINTER (2));
1337 _dbus_list_append (&list1, _DBUS_INT_TO_POINTER (1));
1338 _dbus_list_append (&list1, _DBUS_INT_TO_POINTER (3));
1340 _dbus_list_remove_last (&list1, _DBUS_INT_TO_POINTER (2));
1342 verify_list (&list1);
1343 _dbus_assert (is_ascending_sequence (&list1));
1345 _dbus_list_clear (&list1);