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 static DBusMemPool *list_pool;
39 _DBUS_DEFINE_GLOBAL_LOCK (list);
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)
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;
149 #ifdef DBUS_ENABLE_STATS
151 _dbus_list_get_stats (dbus_uint32_t *in_use_p,
152 dbus_uint32_t *in_free_list_p,
153 dbus_uint32_t *allocated_p)
156 _dbus_mem_pool_get_stats (list_pool, in_use_p, in_free_list_p, allocated_p);
164 * @addtogroup DBusList
171 * A node in a linked list.
173 * DBusList is a circular list; that is, the tail of the list
174 * points back to the head of the list. The empty list is
175 * represented by a #NULL pointer.
179 * @def _dbus_list_get_next_link
181 * Gets the next link in the list, or #NULL if
182 * there are no more links. Used for iteration.
186 * link = _dbus_list_get_first_link (&list);
187 * while (link != NULL)
189 * printf ("value is %p\n", link->data);
190 * link = _dbus_list_get_next_link (&link);
194 * @param list address of the list head.
195 * @param link current link.
196 * @returns the next link, or %NULL if none.
201 * @def _dbus_list_get_prev_link
203 * Gets the previous link in the list, or #NULL if
204 * there are no more links. Used for iteration.
208 * link = _dbus_list_get_last_link (&list);
209 * while (link != NULL)
211 * printf ("value is %p\n", link->data);
212 * link = _dbus_list_get_prev_link (&link);
216 * @param list address of the list head.
217 * @param link current link.
218 * @returns the previous link, or %NULL if none.
223 * Allocates a linked list node. Useful for preallocating
224 * nodes and using _dbus_list_append_link() to avoid
227 * @param data the value to store in the link.
228 * @returns a newly allocated link.
231 _dbus_list_alloc_link (void *data)
233 return alloc_link (data);
237 * Frees a linked list node allocated with _dbus_list_alloc_link.
238 * Does not free the data in the node.
240 * @param link the list node
243 _dbus_list_free_link (DBusList *link)
250 * Appends a value to the list. May return #FALSE
251 * if insufficient memory exists to add a list link.
252 * This is a constant-time operation.
254 * @param list address of the list head.
255 * @param data the value to append.
256 * @returns #TRUE on success.
259 _dbus_list_append (DBusList **list,
262 if (!_dbus_list_prepend (list, data))
265 /* Now cycle the list forward one so the prepended node is the tail */
266 *list = (*list)->next;
272 * Prepends a value to the list. May return #FALSE
273 * if insufficient memory exists to add a list link.
274 * This is a constant-time operation.
276 * @param list address of the list head.
277 * @param data the value to prepend.
278 * @returns #TRUE on success.
281 _dbus_list_prepend (DBusList **list,
286 link = alloc_link (data);
290 link_before (list, *list, link);
296 * Appends a link to the list.
297 * Cannot fail due to out of memory.
298 * This is a constant-time operation.
300 * @param list address of the list head.
301 * @param link the link to append.
304 _dbus_list_append_link (DBusList **list,
307 _dbus_list_prepend_link (list, link);
309 /* Now cycle the list forward one so the prepended node is the tail */
310 *list = (*list)->next;
314 * Prepends a link to the list.
315 * Cannot fail due to out of memory.
316 * This is a constant-time operation.
318 * @param list address of the list head.
319 * @param link the link to prepend.
322 _dbus_list_prepend_link (DBusList **list,
325 link_before (list, *list, link);
329 * Inserts data into the list after the given existing link.
331 * @param list the list to modify
332 * @param after_this_link existing link to insert after, or #NULL to prepend
333 * @param data the value to insert
334 * @returns #TRUE on success, #FALSE if memory allocation fails
337 _dbus_list_insert_after (DBusList **list,
338 DBusList *after_this_link,
343 if (after_this_link == NULL)
344 return _dbus_list_prepend (list, data);
347 link = alloc_link (data);
351 link_after (list, after_this_link, link);
358 * Inserts a link into the list before the given existing link.
360 * @param list the list to modify
361 * @param before_this_link existing link to insert before, or #NULL to append
362 * @param link the link to insert
365 _dbus_list_insert_before_link (DBusList **list,
366 DBusList *before_this_link,
369 if (before_this_link == NULL)
370 _dbus_list_append_link (list, link);
372 link_before (list, before_this_link, link);
376 * Inserts a link into the list after the given existing link.
378 * @param list the list to modify
379 * @param after_this_link existing link to insert after, or #NULL to prepend
380 * @param link the link to insert
383 _dbus_list_insert_after_link (DBusList **list,
384 DBusList *after_this_link,
387 if (after_this_link == NULL)
388 _dbus_list_prepend_link (list, link);
390 link_after (list, after_this_link, link);
394 * Removes a value from the list. Only removes the
395 * first value equal to the given data pointer,
396 * even if multiple values exist which match.
397 * This is a linear-time operation.
399 * @param list address of the list head.
400 * @param data the value to remove.
401 * @returns #TRUE if a value was found to remove.
404 _dbus_list_remove (DBusList **list,
412 if (link->data == data)
414 _dbus_list_remove_link (list, link);
418 link = _dbus_list_get_next_link (list, link);
425 * Removes a value from the list. Only removes the
426 * last value equal to the given data pointer,
427 * even if multiple values exist which match.
428 * This is a linear-time operation.
430 * @param list address of the list head.
431 * @param data the value to remove.
432 * @returns #TRUE if a value was found to remove.
435 _dbus_list_remove_last (DBusList **list,
440 link = _dbus_list_find_last (list, data);
443 _dbus_list_remove_link (list, link);
451 * Finds a value in the list. Returns the last link
452 * with value equal to the given data pointer.
453 * This is a linear-time operation.
454 * Returns #NULL if no value found that matches.
456 * @param list address of the list head.
457 * @param data the value to find.
458 * @returns the link if found
461 _dbus_list_find_last (DBusList **list,
466 link = _dbus_list_get_last_link (list);
470 if (link->data == data)
473 link = _dbus_list_get_prev_link (list, link);
480 * Removes the given link from the list, but doesn't
481 * free it. _dbus_list_remove_link() both removes the
482 * link and also frees it.
484 * @param list the list
485 * @param link the link in the list
488 _dbus_list_unlink (DBusList **list,
491 if (link->next == link)
493 /* one-element list */
498 link->prev->next = link->next;
499 link->next->prev = link->prev;
510 * Removes a link from the list. This is a constant-time operation.
512 * @param list address of the list head.
513 * @param link the list link to remove.
516 _dbus_list_remove_link (DBusList **list,
519 _dbus_list_unlink (list, link);
524 * Frees all links in the list and sets the list head to #NULL. Does
525 * not free the data in each link, for obvious reasons. This is a
526 * linear-time operation.
528 * @param list address of the list head.
531 _dbus_list_clear (DBusList **list)
538 DBusList *next = _dbus_list_get_next_link (list, link);
549 * Gets the first link in the list.
550 * This is a constant-time operation.
552 * @param list address of the list head.
553 * @returns the first link, or #NULL for an empty list.
556 _dbus_list_get_first_link (DBusList **list)
562 * Gets the last link in the list.
563 * This is a constant-time operation.
565 * @param list address of the list head.
566 * @returns the last link, or #NULL for an empty list.
569 _dbus_list_get_last_link (DBusList **list)
574 return (*list)->prev;
578 * Gets the last data in the list.
579 * This is a constant-time operation.
581 * @param list address of the list head.
582 * @returns the last data in the list, or #NULL for an empty list.
585 _dbus_list_get_last (DBusList **list)
590 return (*list)->prev->data;
594 * Gets the first data in the list.
595 * This is a constant-time operation.
597 * @param list address of the list head.
598 * @returns the first data in the list, or #NULL for an empty list.
601 _dbus_list_get_first (DBusList **list)
606 return (*list)->data;
610 * Removes the first link in the list and returns it. This is a
611 * constant-time operation.
613 * @param list address of the list head.
614 * @returns the first link in the list, or #NULL for an empty list.
617 _dbus_list_pop_first_link (DBusList **list)
621 link = _dbus_list_get_first_link (list);
625 _dbus_list_unlink (list, link);
631 * Removes the first value in the list and returns it. This is a
632 * constant-time operation.
634 * @param list address of the list head.
635 * @returns the first data in the list, or #NULL for an empty list.
638 _dbus_list_pop_first (DBusList **list)
643 link = _dbus_list_get_first_link (list);
648 _dbus_list_remove_link (list, link);
654 * Removes the last value in the list and returns it. This is a
655 * constant-time operation.
657 * @param list address of the list head.
658 * @returns the last data in the list, or #NULL for an empty list.
661 _dbus_list_pop_last (DBusList **list)
666 link = _dbus_list_get_last_link (list);
671 _dbus_list_remove_link (list, link);
677 * Copies a list. This is a linear-time operation. If there isn't
678 * enough memory to copy the entire list, the destination list will be
681 * @param list address of the head of the list to copy.
682 * @param dest address where the copied list should be placed.
683 * @returns #TRUE on success, #FALSE if not enough memory.
686 _dbus_list_copy (DBusList **list,
691 _dbus_assert (list != dest);
698 if (!_dbus_list_append (dest, link->data))
700 /* free what we have so far */
701 _dbus_list_clear (dest);
705 link = _dbus_list_get_next_link (list, link);
712 * Gets the length of a list. This is a linear-time
715 * @param list address of the head of the list
716 * @returns number of elements in the list.
719 _dbus_list_get_length (DBusList **list)
731 link = _dbus_list_get_next_link (list, link);
738 * Calls the given function for each element in the list. The
739 * function is passed the list element as its first argument, and the
740 * given data as its second argument.
742 * @param list address of the head of the list.
743 * @param function function to call for each element.
744 * @param data extra data for the function.
748 _dbus_list_foreach (DBusList **list,
749 DBusForeachFunction function,
757 DBusList *next = _dbus_list_get_next_link (list, link);
759 (* function) (link->data, data);
766 * Check whether length is exactly one.
768 * @param list the list
769 * @returns #TRUE if length is exactly one
772 _dbus_list_length_is_one (DBusList **list)
774 return (*list != NULL &&
775 (*list)->next == *list);
780 #ifdef DBUS_BUILD_TESTS
781 #include "dbus-test.h"
785 verify_list (DBusList **list)
795 if (link->next == link)
797 _dbus_assert (link->prev == link);
798 _dbus_assert (*list == link);
806 _dbus_assert (link->prev->next == link);
807 _dbus_assert (link->next->prev == link);
810 while (link != *list);
812 _dbus_assert (length == _dbus_list_get_length (list));
815 _dbus_assert (_dbus_list_length_is_one (list));
817 _dbus_assert (!_dbus_list_length_is_one (list));
821 is_ascending_sequence (DBusList **list)
826 prev = _DBUS_INT_MIN;
828 link = _dbus_list_get_first_link (list);
831 int v = _DBUS_POINTER_TO_INT (link->data);
838 link = _dbus_list_get_next_link (list, link);
845 is_descending_sequence (DBusList **list)
850 prev = _DBUS_INT_MAX;
852 link = _dbus_list_get_first_link (list);
855 int v = _DBUS_POINTER_TO_INT (link->data);
862 link = _dbus_list_get_next_link (list, link);
869 all_even_values (DBusList **list)
873 link = _dbus_list_get_first_link (list);
876 int v = _DBUS_POINTER_TO_INT (link->data);
881 link = _dbus_list_get_next_link (list, link);
888 all_odd_values (DBusList **list)
892 link = _dbus_list_get_first_link (list);
895 int v = _DBUS_POINTER_TO_INT (link->data);
900 link = _dbus_list_get_next_link (list, link);
907 lists_equal (DBusList **list1,
913 link1 = _dbus_list_get_first_link (list1);
914 link2 = _dbus_list_get_first_link (list2);
915 while (link1 && link2)
917 if (link1->data != link2->data)
920 link1 = _dbus_list_get_next_link (list1, link1);
921 link2 = _dbus_list_get_next_link (list2, link2);
931 * @ingroup DBusListInternals
932 * Unit test for DBusList
933 * @returns #TRUE on success.
936 _dbus_list_test (void)
949 /* Test append and prepend */
954 if (!_dbus_list_append (&list1, _DBUS_INT_TO_POINTER (i)))
955 _dbus_assert_not_reached ("could not allocate for append");
957 if (!_dbus_list_prepend (&list2, _DBUS_INT_TO_POINTER (i)))
958 _dbus_assert_not_reached ("count not allocate for prepend");
961 verify_list (&list1);
962 verify_list (&list2);
964 _dbus_assert (_dbus_list_get_length (&list1) == i);
965 _dbus_assert (_dbus_list_get_length (&list2) == i);
968 _dbus_assert (is_ascending_sequence (&list1));
969 _dbus_assert (is_descending_sequence (&list2));
971 /* Test list clear */
972 _dbus_list_clear (&list1);
973 _dbus_list_clear (&list2);
975 verify_list (&list1);
976 verify_list (&list2);
978 /* Test get_first, get_last, pop_first, pop_last */
983 _dbus_list_append (&list1, _DBUS_INT_TO_POINTER (i));
984 _dbus_list_prepend (&list2, _DBUS_INT_TO_POINTER (i));
997 got_data1 = _dbus_list_get_last (&list1);
998 got_data2 = _dbus_list_get_first (&list2);
1000 data1 = _dbus_list_pop_last (&list1);
1001 data2 = _dbus_list_pop_first (&list2);
1003 _dbus_assert (got_data1 == data1);
1004 _dbus_assert (got_data2 == data2);
1006 _dbus_assert (_DBUS_POINTER_TO_INT (data1) == i);
1007 _dbus_assert (_DBUS_POINTER_TO_INT (data2) == i);
1009 verify_list (&list1);
1010 verify_list (&list2);
1012 _dbus_assert (is_ascending_sequence (&list1));
1013 _dbus_assert (is_descending_sequence (&list2));
1018 _dbus_assert (list1 == NULL);
1019 _dbus_assert (list2 == NULL);
1021 /* Test get_first_link, get_last_link, pop_first_link, pop_last_link */
1026 _dbus_list_append (&list1, _DBUS_INT_TO_POINTER (i));
1027 _dbus_list_prepend (&list2, _DBUS_INT_TO_POINTER (i));
1034 DBusList *got_link1;
1035 DBusList *got_link2;
1039 void *data1_indirect;
1043 got_link1 = _dbus_list_get_last_link (&list1);
1044 got_link2 = _dbus_list_get_first_link (&list2);
1046 link2 = _dbus_list_pop_first_link (&list2);
1048 _dbus_assert (got_link2 == link2);
1050 data1_indirect = got_link1->data;
1051 /* this call makes got_link1 invalid */
1052 data1 = _dbus_list_pop_last (&list1);
1053 _dbus_assert (data1 == data1_indirect);
1054 data2 = link2->data;
1056 _dbus_list_free_link (link2);
1058 _dbus_assert (_DBUS_POINTER_TO_INT (data1) == i);
1059 _dbus_assert (_DBUS_POINTER_TO_INT (data2) == i);
1061 verify_list (&list1);
1062 verify_list (&list2);
1064 _dbus_assert (is_ascending_sequence (&list1));
1065 _dbus_assert (is_descending_sequence (&list2));
1070 _dbus_assert (list1 == NULL);
1071 _dbus_assert (list2 == NULL);
1073 /* Test iteration */
1078 _dbus_list_append (&list1, _DBUS_INT_TO_POINTER (i));
1079 _dbus_list_prepend (&list2, _DBUS_INT_TO_POINTER (i));
1082 verify_list (&list1);
1083 verify_list (&list2);
1085 _dbus_assert (_dbus_list_get_length (&list1) == i);
1086 _dbus_assert (_dbus_list_get_length (&list2) == i);
1089 _dbus_assert (is_ascending_sequence (&list1));
1090 _dbus_assert (is_descending_sequence (&list2));
1093 link2 = _dbus_list_get_first_link (&list2);
1094 while (link2 != NULL)
1096 verify_list (&link2); /* pretend this link is the head */
1098 _dbus_assert (_DBUS_POINTER_TO_INT (link2->data) == i);
1100 link2 = _dbus_list_get_next_link (&list2, link2);
1105 link1 = _dbus_list_get_first_link (&list1);
1106 while (link1 != NULL)
1108 verify_list (&link1); /* pretend this link is the head */
1110 _dbus_assert (_DBUS_POINTER_TO_INT (link1->data) == i);
1112 link1 = _dbus_list_get_next_link (&list1, link1);
1117 link1 = _dbus_list_get_last_link (&list1);
1118 while (link1 != NULL)
1120 verify_list (&link1); /* pretend this link is the head */
1122 _dbus_assert (_DBUS_POINTER_TO_INT (link1->data) == i);
1124 link1 = _dbus_list_get_prev_link (&list1, link1);
1128 _dbus_list_clear (&list1);
1129 _dbus_list_clear (&list2);
1136 _dbus_list_append (&list1, _DBUS_INT_TO_POINTER (i));
1137 _dbus_list_prepend (&list2, _DBUS_INT_TO_POINTER (i));
1146 if (!_dbus_list_remove (&list1, _DBUS_INT_TO_POINTER (i)))
1147 _dbus_assert_not_reached ("element should have been in list");
1148 if (!_dbus_list_remove (&list2, _DBUS_INT_TO_POINTER (i)))
1149 _dbus_assert_not_reached ("element should have been in list");
1151 verify_list (&list1);
1152 verify_list (&list2);
1157 _dbus_assert (all_odd_values (&list1));
1158 _dbus_assert (all_odd_values (&list2));
1160 _dbus_list_clear (&list1);
1161 _dbus_list_clear (&list2);
1163 /* test removing the other half of the elements */
1168 _dbus_list_append (&list1, _DBUS_INT_TO_POINTER (i));
1169 _dbus_list_prepend (&list2, _DBUS_INT_TO_POINTER (i));
1178 if (!_dbus_list_remove (&list1, _DBUS_INT_TO_POINTER (i)))
1179 _dbus_assert_not_reached ("element should have been in list");
1180 if (!_dbus_list_remove (&list2, _DBUS_INT_TO_POINTER (i)))
1181 _dbus_assert_not_reached ("element should have been in list");
1183 verify_list (&list1);
1184 verify_list (&list2);
1189 _dbus_assert (all_even_values (&list1));
1190 _dbus_assert (all_even_values (&list2));
1192 /* clear list using remove_link */
1193 while (list1 != NULL)
1195 _dbus_list_remove_link (&list1, list1);
1196 verify_list (&list1);
1198 while (list2 != NULL)
1200 _dbus_list_remove_link (&list2, list2);
1201 verify_list (&list2);
1204 /* Test remove link more generally */
1208 _dbus_list_append (&list1, _DBUS_INT_TO_POINTER (i));
1209 _dbus_list_prepend (&list2, _DBUS_INT_TO_POINTER (i));
1214 link2 = _dbus_list_get_first_link (&list2);
1215 while (link2 != NULL)
1217 DBusList *next = _dbus_list_get_next_link (&list2, link2);
1219 _dbus_assert (_DBUS_POINTER_TO_INT (link2->data) == i);
1222 _dbus_list_remove_link (&list2, link2);
1224 verify_list (&list2);
1230 _dbus_assert (all_odd_values (&list2));
1231 _dbus_list_clear (&list2);
1234 link1 = _dbus_list_get_first_link (&list1);
1235 while (link1 != NULL)
1237 DBusList *next = _dbus_list_get_next_link (&list1, link1);
1239 _dbus_assert (_DBUS_POINTER_TO_INT (link1->data) == i);
1242 _dbus_list_remove_link (&list1, link1);
1244 verify_list (&list1);
1250 _dbus_assert (all_even_values (&list1));
1251 _dbus_list_clear (&list1);
1253 /* Test copying a list */
1257 _dbus_list_append (&list1, _DBUS_INT_TO_POINTER (i));
1258 _dbus_list_prepend (&list2, _DBUS_INT_TO_POINTER (i));
1262 /* bad pointers, because they are allowed in the copy dest */
1263 copy1 = _DBUS_INT_TO_POINTER (0x342234);
1264 copy2 = _DBUS_INT_TO_POINTER (23);
1266 _dbus_list_copy (&list1, ©1);
1267 verify_list (&list1);
1268 verify_list (©1);
1269 _dbus_assert (lists_equal (&list1, ©1));
1271 _dbus_list_copy (&list2, ©2);
1272 verify_list (&list2);
1273 verify_list (©2);
1274 _dbus_assert (lists_equal (&list2, ©2));
1276 /* Now test copying empty lists */
1277 _dbus_list_clear (&list1);
1278 _dbus_list_clear (&list2);
1279 _dbus_list_clear (©1);
1280 _dbus_list_clear (©2);
1282 /* bad pointers, because they are allowed in the copy dest */
1283 copy1 = _DBUS_INT_TO_POINTER (0x342234);
1284 copy2 = _DBUS_INT_TO_POINTER (23);
1286 _dbus_list_copy (&list1, ©1);
1287 verify_list (&list1);
1288 verify_list (©1);
1289 _dbus_assert (lists_equal (&list1, ©1));
1291 _dbus_list_copy (&list2, ©2);
1292 verify_list (&list2);
1293 verify_list (©2);
1294 _dbus_assert (lists_equal (&list2, ©2));
1296 _dbus_list_clear (&list1);
1297 _dbus_list_clear (&list2);
1299 /* insert_after on empty list */
1300 _dbus_list_insert_after (&list1, NULL,
1301 _DBUS_INT_TO_POINTER (0));
1302 verify_list (&list1);
1304 /* inserting after first element */
1305 _dbus_list_insert_after (&list1, list1,
1306 _DBUS_INT_TO_POINTER (1));
1307 verify_list (&list1);
1308 _dbus_assert (is_ascending_sequence (&list1));
1310 /* inserting at the end */
1311 _dbus_list_insert_after (&list1, list1->next,
1312 _DBUS_INT_TO_POINTER (2));
1313 verify_list (&list1);
1314 _dbus_assert (is_ascending_sequence (&list1));
1316 /* using insert_after to prepend */
1317 _dbus_list_insert_after (&list1, NULL,
1318 _DBUS_INT_TO_POINTER (-1));
1319 verify_list (&list1);
1320 _dbus_assert (is_ascending_sequence (&list1));
1322 _dbus_list_clear (&list1);
1324 /* using remove_last */
1325 _dbus_list_append (&list1, _DBUS_INT_TO_POINTER (2));
1326 _dbus_list_append (&list1, _DBUS_INT_TO_POINTER (1));
1327 _dbus_list_append (&list1, _DBUS_INT_TO_POINTER (3));
1329 _dbus_list_remove_last (&list1, _DBUS_INT_TO_POINTER (2));
1331 verify_list (&list1);
1332 _dbus_assert (is_ascending_sequence (&list1));
1334 _dbus_list_clear (&list1);