Mu_list_replace and mu_list_remove actually reclaim the memory associated with the item.
* include/mailutils/iterator.h (mu_itrctl_delete_nd) (mu_itrctl_replace_nd): New mu_itrctl_req constants. * include/mailutils/list.h (mu_list_remove_nd) (mu_list_replace_nd): New prototypes. (mu_list_destroy_item_t): New typedef. (mu_list_set_destroy_item): Return mu_list_destroy_item_t. * mailbox/list.c (DESTROY_ITEM): New macro. (mu_list_destroy): Use DESTROY_ITEM. (mu_list_remove, mu_list_replace): Actually destroy the item being removed. (mu_list_remove_nd, mu_list_replace_nd): New functions. (mu_list_set_destroy_item): Return previous value of destroy_item. (list_itrctl): Handle mu_itrctl_delete_nd and mu_itrctl_replace_nd. * mailbox/observer.c (mu_observable_create): Register destroy_item function. (mu_observable_destroy): Remove explicit loop. Rely on destroy_item instead. (mu_observable_detach): Use mu_iterator_ctl to actually remove the event. * mh/mh_alias.y (_insert_list): Remove. (alias_expand_list): Use mu_iterator_ctl to insert replacement list and remove the current item. * mh/sortm.c (addop): Register destroy_item function. (remop): Remove call to free. * movemail/movemail.c (main): <uidl loop>: Use mu_itrctl_delete to remove items. * libmu_sieve/util.c: Minor change. * mail/util.c (util_slist_compare): New static function. (util_slist_add): Register destroy_item and comparison functions for the new list. (util_slist_remove,util_slist_destroy): Rewrite. * imap4d/authenticate.c (auth_add): Use mu_list_free_item as destroy_item function. * imap4d/util.c (util_register_event): Likewise. * include/mailutils/cpp/list.h (List)<set_destroy_item>: Change return value. * libmu_cpp/list.cc (List::set_destroy_item): Reflect changes to mu_list_set_destroy_item. * libmu_argp/common.c: Include stdlib.h
Showing
14 changed files
with
109 additions
and
118 deletions
... | @@ -47,6 +47,7 @@ auth_add (char *name, imap4d_auth_handler_fp handler) | ... | @@ -47,6 +47,7 @@ auth_add (char *name, imap4d_auth_handler_fp handler) |
47 | { | 47 | { |
48 | mu_list_create (&imap_auth_list); | 48 | mu_list_create (&imap_auth_list); |
49 | mu_list_set_comparator (imap_auth_list, comp); | 49 | mu_list_set_comparator (imap_auth_list, comp); |
50 | mu_list_set_destroy_item (imap_auth_list, mu_list_free_item); | ||
50 | } | 51 | } |
51 | mu_list_append (imap_auth_list, (void*)p); | 52 | mu_list_append (imap_auth_list, (void*)p); |
52 | } | 53 | } | ... | ... |
... | @@ -951,7 +951,10 @@ util_register_event (int old_state, int new_state, | ... | @@ -951,7 +951,10 @@ util_register_event (int old_state, int new_state, |
951 | evp->action = action; | 951 | evp->action = action; |
952 | evp->data = data; | 952 | evp->data = data; |
953 | if (!event_list) | 953 | if (!event_list) |
954 | mu_list_create (&event_list); | 954 | { |
955 | mu_list_create (&event_list); | ||
956 | mu_list_set_destroy_item (event_list, mu_list_free_item); | ||
957 | } | ||
955 | mu_list_append (event_list, (void*)evp); | 958 | mu_list_append (event_list, (void*)evp); |
956 | } | 959 | } |
957 | 960 | ... | ... |
... | @@ -69,7 +69,7 @@ class List | ... | @@ -69,7 +69,7 @@ class List |
69 | 69 | ||
70 | void apply (mu_list_action_t* action, void* cbdata); | 70 | void apply (mu_list_action_t* action, void* cbdata); |
71 | mu_list_comparator_t set_comparator (mu_list_comparator_t comp); | 71 | mu_list_comparator_t set_comparator (mu_list_comparator_t comp); |
72 | void set_destroy_item (void (*mu_destoy_item) (void *item)); | 72 | mu_list_destroy_item_t set_destroy_item (mu_list_destroy_item_t mu_destroy_item); |
73 | 73 | ||
74 | bool is_empty (); | 74 | bool is_empty (); |
75 | size_t count (); | 75 | size_t count (); | ... | ... |
... | @@ -28,10 +28,12 @@ extern "C" { | ... | @@ -28,10 +28,12 @@ extern "C" { |
28 | 28 | ||
29 | enum mu_itrctl_req | 29 | enum mu_itrctl_req |
30 | { | 30 | { |
31 | mu_itrctl_tell, /* Return current position in the object */ | 31 | mu_itrctl_tell, /* Return current position in the object */ |
32 | mu_itrctl_delete, /* Delete current element */ | 32 | mu_itrctl_delete, /* Delete current element */ |
33 | mu_itrctl_replace,/* Replace current element */ | 33 | mu_itrctl_delete_nd, /* Delete current element, non-destructive */ |
34 | mu_itrctl_insert, /* Insert new element in the current position */ | 34 | mu_itrctl_replace, /* Replace current element */ |
35 | mu_itrctl_replace_nd, /* Replace current element, non-destructive */ | ||
36 | mu_itrctl_insert, /* Insert new element in the current position */ | ||
35 | mu_itrctl_insert_list, /* Insert a list of elements */ | 37 | mu_itrctl_insert_list, /* Insert a list of elements */ |
36 | }; | 38 | }; |
37 | 39 | ... | ... |
... | @@ -35,7 +35,9 @@ extern int mu_list_insert (mu_list_t list, void *item, void *new_item, | ... | @@ -35,7 +35,9 @@ extern int mu_list_insert (mu_list_t list, void *item, void *new_item, |
35 | extern int mu_list_is_empty (mu_list_t); | 35 | extern int mu_list_is_empty (mu_list_t); |
36 | extern int mu_list_count (mu_list_t, size_t *pcount); | 36 | extern int mu_list_count (mu_list_t, size_t *pcount); |
37 | extern int mu_list_remove (mu_list_t, void *item); | 37 | extern int mu_list_remove (mu_list_t, void *item); |
38 | extern int mu_list_remove_nd (mu_list_t, void *item); | ||
38 | extern int mu_list_replace (mu_list_t list, void *old_item, void *new_item); | 39 | extern int mu_list_replace (mu_list_t list, void *old_item, void *new_item); |
40 | extern int mu_list_replace_nd (mu_list_t list, void *old_item, void *new_item); | ||
39 | extern int mu_list_get (mu_list_t, size_t _index, void **pitem); | 41 | extern int mu_list_get (mu_list_t, size_t _index, void **pitem); |
40 | extern int mu_list_to_array (mu_list_t list, void **array, size_t count, size_t *pcount); | 42 | extern int mu_list_to_array (mu_list_t list, void **array, size_t count, size_t *pcount); |
41 | extern int mu_list_locate (mu_list_t list, void *item, void **ret_item); | 43 | extern int mu_list_locate (mu_list_t list, void *item, void **ret_item); |
... | @@ -54,9 +56,11 @@ extern mu_list_comparator_t mu_list_set_comparator (mu_list_t, | ... | @@ -54,9 +56,11 @@ extern mu_list_comparator_t mu_list_set_comparator (mu_list_t, |
54 | extern int mu_list_get_comparator (mu_list_t, mu_list_comparator_t *); | 56 | extern int mu_list_get_comparator (mu_list_t, mu_list_comparator_t *); |
55 | 57 | ||
56 | extern void mu_list_free_item (void *item); | 58 | extern void mu_list_free_item (void *item); |
59 | |||
60 | typedef void (*mu_list_destroy_item_t) (void *); | ||
57 | 61 | ||
58 | extern int mu_list_set_destroy_item (mu_list_t list, | 62 | extern mu_list_destroy_item_t mu_list_set_destroy_item |
59 | void (*destroy_item) (void *)); | 63 | (mu_list_t list, mu_list_destroy_item_t destroy_item); |
60 | 64 | ||
61 | 65 | ||
62 | extern int mu_list_intersect_dup (mu_list_t *, mu_list_t, mu_list_t, | 66 | extern int mu_list_intersect_dup (mu_list_t *, mu_list_t, mu_list_t, | ... | ... |
... | @@ -21,6 +21,7 @@ | ... | @@ -21,6 +21,7 @@ |
21 | #endif | 21 | #endif |
22 | #include "cmdline.h" | 22 | #include "cmdline.h" |
23 | #include <unistd.h> | 23 | #include <unistd.h> |
24 | #include <stdlib.h> | ||
24 | #include <string.h> | 25 | #include <string.h> |
25 | #include <mailutils/syslog.h> | 26 | #include <mailutils/syslog.h> |
26 | #include <mailutils/mailbox.h> | 27 | #include <mailutils/mailbox.h> | ... | ... |
... | @@ -215,12 +215,10 @@ List :: set_comparator (mu_list_comparator_t comp) | ... | @@ -215,12 +215,10 @@ List :: set_comparator (mu_list_comparator_t comp) |
215 | return mu_list_set_comparator (mu_list, comp); | 215 | return mu_list_set_comparator (mu_list, comp); |
216 | } | 216 | } |
217 | 217 | ||
218 | void | 218 | mu_list_destroy_item_t |
219 | List :: set_destroy_item (void (*mu_destroy_item) (void *item)) | 219 | List :: set_destroy_item (mu_list_destroy_item_t mu_destroy_item) |
220 | { | 220 | { |
221 | int status = mu_list_set_destroy_item (mu_list, mu_destroy_item); | 221 | return mu_list_set_destroy_item (mu_list, mu_destroy_item); |
222 | if (status) | ||
223 | throw Exception ("List::set_destroy_item", status); | ||
224 | } | 222 | } |
225 | 223 | ||
226 | std::list<void*> | 224 | std::list<void*> | ... | ... |
... | @@ -96,7 +96,6 @@ mu_sieve_prealloc (mu_list_t *pool, void *ptr, size_t size) | ... | @@ -96,7 +96,6 @@ mu_sieve_prealloc (mu_list_t *pool, void *ptr, size_t size) |
96 | void | 96 | void |
97 | mu_sieve_pfree (mu_list_t *pool, void *ptr) | 97 | mu_sieve_pfree (mu_list_t *pool, void *ptr) |
98 | { | 98 | { |
99 | |||
100 | if (*pool) | 99 | if (*pool) |
101 | mu_list_remove (*pool, ptr); | 100 | mu_list_remove (*pool, ptr); |
102 | free (ptr); | 101 | free (ptr); | ... | ... |
... | @@ -587,55 +587,39 @@ util_slist_lookup (mu_list_t list, const char *str) | ... | @@ -587,55 +587,39 @@ util_slist_lookup (mu_list_t list, const char *str) |
587 | return rc; | 587 | return rc; |
588 | } | 588 | } |
589 | 589 | ||
590 | void | 590 | static int |
591 | util_slist_add (mu_list_t *list, char *value) | 591 | util_slist_compare (const void *a, const void *b) |
592 | { | 592 | { |
593 | char *p; | 593 | return mu_c_strcasecmp (a, b); |
594 | } | ||
594 | 595 | ||
595 | if (!*list && mu_list_create (list)) | 596 | void |
596 | return; | 597 | util_slist_add (mu_list_t *plist, char *value) |
598 | { | ||
599 | mu_list_t list; | ||
597 | 600 | ||
598 | if ((p = strdup(value)) == NULL) | 601 | if (!*plist) |
599 | { | 602 | { |
600 | util_error(_("Not enough memory")); | 603 | if (mu_list_create (&list)) |
601 | return; | 604 | return; |
605 | mu_list_set_destroy_item (list, mu_list_free_item); | ||
606 | mu_list_set_comparator (list, util_slist_compare); | ||
607 | *plist = list; | ||
602 | } | 608 | } |
603 | mu_list_append (*list, p); | 609 | else |
604 | } | 610 | list = *plist; |
605 | 611 | mu_list_append (list, xstrdup (value)); | |
606 | static int | ||
607 | comp (const void *item, const void *data) | ||
608 | { | ||
609 | return strcmp ((char*)item, (char*)data); | ||
610 | } | 612 | } |
611 | 613 | ||
612 | void | 614 | void |
613 | util_slist_remove (mu_list_t *list, char *value) | 615 | util_slist_remove (mu_list_t *list, char *value) |
614 | { | 616 | { |
615 | mu_list_comparator_t cp; | ||
616 | |||
617 | if (!*list) | ||
618 | return; | ||
619 | cp = mu_list_set_comparator (*list, comp); | ||
620 | mu_list_remove (*list, value); | 617 | mu_list_remove (*list, value); |
621 | mu_list_set_comparator (*list, cp); | ||
622 | } | 618 | } |
623 | 619 | ||
624 | void | 620 | void |
625 | util_slist_destroy (mu_list_t *list) | 621 | util_slist_destroy (mu_list_t *list) |
626 | { | 622 | { |
627 | mu_iterator_t itr; | ||
628 | char *name; | ||
629 | |||
630 | if (!*list || mu_list_get_iterator (*list, &itr)) | ||
631 | return; | ||
632 | |||
633 | for (mu_iterator_first (itr); !mu_iterator_is_done (itr); mu_iterator_next (itr)) | ||
634 | { | ||
635 | mu_iterator_current (itr, (void **)&name); | ||
636 | free (name); | ||
637 | } | ||
638 | mu_iterator_destroy (&itr); | ||
639 | mu_list_destroy (list); | 623 | mu_list_destroy (list); |
640 | } | 624 | } |
641 | 625 | ||
... | @@ -649,12 +633,13 @@ util_slist_to_string (mu_list_t list, const char *delim) | ... | @@ -649,12 +633,13 @@ util_slist_to_string (mu_list_t list, const char *delim) |
649 | if (!list || mu_list_get_iterator (list, &itr)) | 633 | if (!list || mu_list_get_iterator (list, &itr)) |
650 | return NULL; | 634 | return NULL; |
651 | 635 | ||
652 | for (mu_iterator_first (itr); !mu_iterator_is_done (itr); mu_iterator_next (itr)) | 636 | for (mu_iterator_first (itr); !mu_iterator_is_done (itr); |
637 | mu_iterator_next (itr)) | ||
653 | { | 638 | { |
654 | mu_iterator_current (itr, (void **)&name); | 639 | mu_iterator_current (itr, (void **)&name); |
655 | if (str && delim) | 640 | if (str && delim) |
656 | util_strcat(&str, delim); | 641 | util_strcat (&str, delim); |
657 | util_strcat(&str, name); | 642 | util_strcat (&str, name); |
658 | } | 643 | } |
659 | mu_iterator_destroy (&itr); | 644 | mu_iterator_destroy (&itr); |
660 | return str; | 645 | return str; | ... | ... |
... | @@ -29,6 +29,14 @@ | ... | @@ -29,6 +29,14 @@ |
29 | #include <iterator0.h> | 29 | #include <iterator0.h> |
30 | #include <mailutils/errno.h> | 30 | #include <mailutils/errno.h> |
31 | 31 | ||
32 | #define DESTROY_ITEM(list, elt) \ | ||
33 | do \ | ||
34 | { \ | ||
35 | if ((list)->destroy_item) \ | ||
36 | (list)->destroy_item ((elt)->item); \ | ||
37 | } \ | ||
38 | while (0) | ||
39 | |||
32 | int | 40 | int |
33 | mu_list_create (mu_list_t *plist) | 41 | mu_list_create (mu_list_t *plist) |
34 | { | 42 | { |
... | @@ -66,8 +74,7 @@ mu_list_destroy (mu_list_t *plist) | ... | @@ -66,8 +74,7 @@ mu_list_destroy (mu_list_t *plist) |
66 | { | 74 | { |
67 | previous = current; | 75 | previous = current; |
68 | current = current->next; | 76 | current = current->next; |
69 | if (list->destroy_item) | 77 | DESTROY_ITEM (list, previous); |
70 | list->destroy_item (previous->item); | ||
71 | free (previous); | 78 | free (previous); |
72 | } | 79 | } |
73 | mu_monitor_unlock (list->monitor); | 80 | mu_monitor_unlock (list->monitor); |
... | @@ -263,7 +270,7 @@ mu_list_remove (mu_list_t list, void *item) | ... | @@ -263,7 +270,7 @@ mu_list_remove (mu_list_t list, void *item) |
263 | mu_iterator_advance (list->itr, current); | 270 | mu_iterator_advance (list->itr, current); |
264 | previous->next = current->next; | 271 | previous->next = current->next; |
265 | current->next->prev = previous; | 272 | current->next->prev = previous; |
266 | /* FIXME: Call destroy_item */ | 273 | DESTROY_ITEM (list, current); |
267 | free (current); | 274 | free (current); |
268 | list->count--; | 275 | list->count--; |
269 | status = 0; | 276 | status = 0; |
... | @@ -275,6 +282,15 @@ mu_list_remove (mu_list_t list, void *item) | ... | @@ -275,6 +282,15 @@ mu_list_remove (mu_list_t list, void *item) |
275 | } | 282 | } |
276 | 283 | ||
277 | int | 284 | int |
285 | mu_list_remove_nd (mu_list_t list, void *item) | ||
286 | { | ||
287 | mu_list_destroy_item_t dptr = mu_list_set_destroy_item (list, NULL); | ||
288 | int rc = mu_list_remove (list, item); | ||
289 | mu_list_set_destroy_item (list, dptr); | ||
290 | return rc; | ||
291 | } | ||
292 | |||
293 | int | ||
278 | mu_list_replace (mu_list_t list, void *old_item, void *new_item) | 294 | mu_list_replace (mu_list_t list, void *old_item, void *new_item) |
279 | { | 295 | { |
280 | struct list_data *current, *previous; | 296 | struct list_data *current, *previous; |
... | @@ -290,7 +306,7 @@ mu_list_replace (mu_list_t list, void *old_item, void *new_item) | ... | @@ -290,7 +306,7 @@ mu_list_replace (mu_list_t list, void *old_item, void *new_item) |
290 | { | 306 | { |
291 | if (comp (current->item, old_item) == 0) | 307 | if (comp (current->item, old_item) == 0) |
292 | { | 308 | { |
293 | /* FIXME: Call destroy_item. Perhaps optionally? */ | 309 | DESTROY_ITEM (list, current); |
294 | current->item = new_item; | 310 | current->item = new_item; |
295 | status = 0; | 311 | status = 0; |
296 | break; | 312 | break; |
... | @@ -301,6 +317,15 @@ mu_list_replace (mu_list_t list, void *old_item, void *new_item) | ... | @@ -301,6 +317,15 @@ mu_list_replace (mu_list_t list, void *old_item, void *new_item) |
301 | } | 317 | } |
302 | 318 | ||
303 | int | 319 | int |
320 | mu_list_replace_nd (mu_list_t list, void *item, void *new_item) | ||
321 | { | ||
322 | mu_list_destroy_item_t dptr = mu_list_set_destroy_item (list, NULL); | ||
323 | int rc = mu_list_replace (list, item, new_item); | ||
324 | mu_list_set_destroy_item (list, dptr); | ||
325 | return rc; | ||
326 | } | ||
327 | |||
328 | int | ||
304 | mu_list_get (mu_list_t list, size_t indx, void **pitem) | 329 | mu_list_get (mu_list_t list, size_t indx, void **pitem) |
305 | { | 330 | { |
306 | struct list_data *current; | 331 | struct list_data *current; |
... | @@ -349,13 +374,12 @@ mu_list_do (mu_list_t list, mu_list_action_t *action, void *cbdata) | ... | @@ -349,13 +374,12 @@ mu_list_do (mu_list_t list, mu_list_action_t *action, void *cbdata) |
349 | return status; | 374 | return status; |
350 | } | 375 | } |
351 | 376 | ||
352 | int | 377 | mu_list_destroy_item_t |
353 | mu_list_set_destroy_item (mu_list_t list, void (*destroy_item)(void *item)) | 378 | mu_list_set_destroy_item (mu_list_t list, void (*destroy_item)(void *item)) |
354 | { | 379 | { |
355 | if (list == NULL) | 380 | mu_list_destroy_item_t ret = list->destroy_item; |
356 | return EINVAL; | ||
357 | list->destroy_item = destroy_item; | 381 | list->destroy_item = destroy_item; |
358 | return 0; | 382 | return ret; |
359 | } | 383 | } |
360 | 384 | ||
361 | int | 385 | int |
... | @@ -545,6 +569,7 @@ list_itrctl (void *owner, enum mu_itrctl_req req, void *arg) | ... | @@ -545,6 +569,7 @@ list_itrctl (void *owner, enum mu_itrctl_req req, void *arg) |
545 | } | 569 | } |
546 | 570 | ||
547 | case mu_itrctl_delete: | 571 | case mu_itrctl_delete: |
572 | case mu_itrctl_delete_nd: | ||
548 | /* Delete current element */ | 573 | /* Delete current element */ |
549 | { | 574 | { |
550 | struct list_data *prev; | 575 | struct list_data *prev; |
... | @@ -555,17 +580,20 @@ list_itrctl (void *owner, enum mu_itrctl_req req, void *arg) | ... | @@ -555,17 +580,20 @@ list_itrctl (void *owner, enum mu_itrctl_req req, void *arg) |
555 | mu_iterator_advance (list->itr, ptr); | 580 | mu_iterator_advance (list->itr, ptr); |
556 | prev->next = ptr->next; | 581 | prev->next = ptr->next; |
557 | ptr->next->prev = prev; | 582 | ptr->next->prev = prev; |
558 | /* FIXME: Call destroy_item */ | 583 | if (req == mu_itrctl_delete) |
584 | DESTROY_ITEM (list, ptr); | ||
559 | free (ptr); | 585 | free (ptr); |
560 | list->count--; | 586 | list->count--; |
561 | } | 587 | } |
562 | break; | 588 | break; |
563 | 589 | ||
564 | case mu_itrctl_replace: | 590 | case mu_itrctl_replace: |
591 | case mu_itrctl_replace_nd: | ||
565 | /* Replace current element */ | 592 | /* Replace current element */ |
566 | if (!arg) | 593 | if (!arg) |
567 | return EINVAL; | 594 | return EINVAL; |
568 | /* FIXME: Call destroy_item. Perhaps optionally? */ | 595 | if (req == mu_itrctl_replace) |
596 | DESTROY_ITEM (list, ptr); | ||
569 | ptr = itr->cur; | 597 | ptr = itr->cur; |
570 | ptr->item = arg; | 598 | ptr->item = arg; |
571 | break; | 599 | break; | ... | ... |
... | @@ -119,6 +119,14 @@ mu_observer_set_flags (mu_observer_t observer, int flags) | ... | @@ -119,6 +119,14 @@ mu_observer_set_flags (mu_observer_t observer, int flags) |
119 | return 0; | 119 | return 0; |
120 | } | 120 | } |
121 | 121 | ||
122 | static void | ||
123 | _free_event (void *ptr) | ||
124 | { | ||
125 | event_t event = ptr; | ||
126 | mu_observer_destroy (&event->observer, NULL); | ||
127 | free (event); | ||
128 | } | ||
129 | |||
122 | int | 130 | int |
123 | mu_observable_create (mu_observable_t *pobservable, void *owner) | 131 | mu_observable_create (mu_observable_t *pobservable, void *owner) |
124 | { | 132 | { |
... | @@ -129,12 +137,13 @@ mu_observable_create (mu_observable_t *pobservable, void *owner) | ... | @@ -129,12 +137,13 @@ mu_observable_create (mu_observable_t *pobservable, void *owner) |
129 | observable = calloc (sizeof (*observable), 1); | 137 | observable = calloc (sizeof (*observable), 1); |
130 | if (observable == NULL) | 138 | if (observable == NULL) |
131 | return ENOMEM; | 139 | return ENOMEM; |
132 | status = mu_list_create (&(observable->list)); | 140 | status = mu_list_create (&observable->list); |
133 | if (status != 0 ) | 141 | if (status != 0 ) |
134 | { | 142 | { |
135 | free (observable); | 143 | free (observable); |
136 | return status; | 144 | return status; |
137 | } | 145 | } |
146 | mu_list_set_destroy_item (observable->list, _free_event); | ||
138 | observable->owner = owner; | 147 | observable->owner = owner; |
139 | *pobservable = observable; | 148 | *pobservable = observable; |
140 | return 0; | 149 | return 0; |
... | @@ -143,31 +152,13 @@ mu_observable_create (mu_observable_t *pobservable, void *owner) | ... | @@ -143,31 +152,13 @@ mu_observable_create (mu_observable_t *pobservable, void *owner) |
143 | void | 152 | void |
144 | mu_observable_destroy (mu_observable_t *pobservable, void *owner) | 153 | mu_observable_destroy (mu_observable_t *pobservable, void *owner) |
145 | { | 154 | { |
146 | mu_iterator_t iterator; | ||
147 | if (pobservable && *pobservable) | 155 | if (pobservable && *pobservable) |
148 | { | 156 | { |
149 | mu_observable_t observable = *pobservable; | 157 | mu_observable_t observable = *pobservable; |
150 | if (observable->owner == owner) | 158 | if (observable->owner == owner) |
151 | { | 159 | { |
152 | int status = mu_list_get_iterator (observable->list, &iterator); | 160 | mu_list_destroy (&observable->list); |
153 | if (status == 0) | 161 | free (observable); |
154 | { | ||
155 | event_t event = NULL; | ||
156 | for (mu_iterator_first (iterator); !mu_iterator_is_done (iterator); | ||
157 | mu_iterator_next (iterator)) | ||
158 | { | ||
159 | event = NULL; | ||
160 | mu_iterator_current (iterator, (void **)&event); | ||
161 | if (event != NULL) | ||
162 | { | ||
163 | mu_observer_destroy (&(event->observer), NULL); | ||
164 | free (event); | ||
165 | } | ||
166 | } | ||
167 | mu_iterator_destroy (&iterator); | ||
168 | } | ||
169 | mu_list_destroy (&((*pobservable)->list)); | ||
170 | free (*pobservable); | ||
171 | } | 162 | } |
172 | *pobservable = NULL; | 163 | *pobservable = NULL; |
173 | } | 164 | } |
... | @@ -198,13 +189,14 @@ mu_observable_detach (mu_observable_t observable, mu_observer_t observer) | ... | @@ -198,13 +189,14 @@ mu_observable_detach (mu_observable_t observable, mu_observer_t observer) |
198 | { | 189 | { |
199 | mu_iterator_t iterator; | 190 | mu_iterator_t iterator; |
200 | int status; | 191 | int status; |
201 | int found = 0; | ||
202 | event_t event = NULL; | 192 | event_t event = NULL; |
193 | |||
203 | if (observable == NULL || observer == NULL) | 194 | if (observable == NULL || observer == NULL) |
204 | return EINVAL; | 195 | return EINVAL; |
205 | status = mu_list_get_iterator (observable->list, &iterator); | 196 | status = mu_list_get_iterator (observable->list, &iterator); |
206 | if (status != 0) | 197 | if (status != 0) |
207 | return status; | 198 | return status; |
199 | status = MU_ERR_NOENT; | ||
208 | for (mu_iterator_first (iterator); !mu_iterator_is_done (iterator); | 200 | for (mu_iterator_first (iterator); !mu_iterator_is_done (iterator); |
209 | mu_iterator_next (iterator)) | 201 | mu_iterator_next (iterator)) |
210 | { | 202 | { |
... | @@ -212,18 +204,12 @@ mu_observable_detach (mu_observable_t observable, mu_observer_t observer) | ... | @@ -212,18 +204,12 @@ mu_observable_detach (mu_observable_t observable, mu_observer_t observer) |
212 | mu_iterator_current (iterator, (void **)&event); | 204 | mu_iterator_current (iterator, (void **)&event); |
213 | if (event && event->observer == observer) | 205 | if (event && event->observer == observer) |
214 | { | 206 | { |
215 | found = 1; | 207 | mu_iterator_ctl (iterator, mu_itrctl_delete, NULL); |
208 | status = 0; | ||
216 | break; | 209 | break; |
217 | } | 210 | } |
218 | } | 211 | } |
219 | mu_iterator_destroy (&iterator); | 212 | mu_iterator_destroy (&iterator); |
220 | if (found) | ||
221 | { | ||
222 | status = mu_list_remove (observable->list, event); | ||
223 | free (event); | ||
224 | } | ||
225 | else | ||
226 | status = MU_ERR_NOENT; | ||
227 | return status; | 213 | return status; |
228 | } | 214 | } |
229 | 215 | ... | ... |
... | @@ -262,26 +262,6 @@ aliascmp (const char *pattern, const char *name) | ... | @@ -262,26 +262,6 @@ aliascmp (const char *pattern, const char *name) |
262 | return strcmp (pattern, name); | 262 | return strcmp (pattern, name); |
263 | } | 263 | } |
264 | 264 | ||
265 | |||
266 | int | ||
267 | _insert_list (mu_list_t list, void *prev, mu_list_t new_list) | ||
268 | { | ||
269 | mu_iterator_t itr; | ||
270 | |||
271 | if (mu_list_get_iterator (new_list, &itr)) | ||
272 | return 1; | ||
273 | for (mu_iterator_first (itr); !mu_iterator_is_done (itr); mu_iterator_next (itr)) | ||
274 | { | ||
275 | void *item; | ||
276 | |||
277 | mu_iterator_current (itr, &item); | ||
278 | mu_list_insert (list, prev, item, 0); | ||
279 | prev = item; | ||
280 | } | ||
281 | mu_iterator_destroy (&itr); | ||
282 | return 0; | ||
283 | } | ||
284 | |||
285 | static int mh_alias_get_internal (const char *name, mu_iterator_t start, | 265 | static int mh_alias_get_internal (const char *name, mu_iterator_t start, |
286 | mu_list_t *return_list, int *inclusive); | 266 | mu_list_t *return_list, int *inclusive); |
287 | 267 | ||
... | @@ -300,9 +280,11 @@ alias_expand_list (mu_list_t name_list, mu_iterator_t orig_itr, int *inclusive) | ... | @@ -300,9 +280,11 @@ alias_expand_list (mu_list_t name_list, mu_iterator_t orig_itr, int *inclusive) |
300 | mu_iterator_current (itr, (void **)&name); | 280 | mu_iterator_current (itr, (void **)&name); |
301 | if (mh_alias_get_internal (name, orig_itr, &exlist, inclusive) == 0) | 281 | if (mh_alias_get_internal (name, orig_itr, &exlist, inclusive) == 0) |
302 | { | 282 | { |
303 | _insert_list (name_list, name, exlist); | 283 | /* Insert exlist after name */ |
304 | mu_list_remove (name_list, name); | 284 | mu_iterator_ctl (itr, mu_itrctl_insert_list, exlist); |
305 | mu_list_destroy (&exlist); | 285 | mu_list_destroy (&exlist); |
286 | /* Remove name */ | ||
287 | mu_iterator_ctl (itr, mu_itrctl_delete, NULL); | ||
306 | } | 288 | } |
307 | } | 289 | } |
308 | mu_iterator_destroy (&itr); | 290 | mu_iterator_destroy (&itr); | ... | ... |
... | @@ -215,10 +215,14 @@ addop (char *field, compfun comp) | ... | @@ -215,10 +215,14 @@ addop (char *field, compfun comp) |
215 | { | 215 | { |
216 | struct comp_op *op = xmalloc (sizeof (*op)); | 216 | struct comp_op *op = xmalloc (sizeof (*op)); |
217 | 217 | ||
218 | if (!oplist && mu_list_create (&oplist)) | 218 | if (!oplist) |
219 | { | 219 | { |
220 | mu_error (_("can't create operation list")); | 220 | if (mu_list_create (&oplist)) |
221 | exit (1); | 221 | { |
222 | mu_error (_("can't create operation list")); | ||
223 | exit (1); | ||
224 | } | ||
225 | mu_list_set_destroy_item (oplist, mu_list_free_item); | ||
222 | } | 226 | } |
223 | op->field = field; | 227 | op->field = field; |
224 | op->comp = comp; | 228 | op->comp = comp; |
... | @@ -248,7 +252,6 @@ remop (compfun comp) | ... | @@ -248,7 +252,6 @@ remop (compfun comp) |
248 | d.op = NULL; | 252 | d.op = NULL; |
249 | mu_list_do (oplist, rem_action, &d); | 253 | mu_list_do (oplist, rem_action, &d); |
250 | mu_list_remove (oplist, d.op); | 254 | mu_list_remove (oplist, d.op); |
251 | free (d.op); | ||
252 | } | 255 | } |
253 | 256 | ||
254 | struct comp_data { | 257 | struct comp_data { | ... | ... |
... | @@ -731,7 +731,6 @@ main (int argc, char **argv) | ... | @@ -731,7 +731,6 @@ main (int argc, char **argv) |
731 | if (rc) | 731 | if (rc) |
732 | die (dest, _("cannot get UIDLs"), rc); | 732 | die (dest, _("cannot get UIDLs"), rc); |
733 | 733 | ||
734 | mu_list_set_comparator (src_uidl_list, NULL); | ||
735 | mu_list_set_comparator (dst_uidl_list, _compare_uidls); | 734 | mu_list_set_comparator (dst_uidl_list, _compare_uidls); |
736 | 735 | ||
737 | mu_list_get_iterator (src_uidl_list, &itr); | 736 | mu_list_get_iterator (src_uidl_list, &itr); |
... | @@ -742,7 +741,7 @@ main (int argc, char **argv) | ... | @@ -742,7 +741,7 @@ main (int argc, char **argv) |
742 | 741 | ||
743 | mu_iterator_current (itr, (void **)&uidl); | 742 | mu_iterator_current (itr, (void **)&uidl); |
744 | if (mu_list_locate (dst_uidl_list, uidl, NULL) == 0) | 743 | if (mu_list_locate (dst_uidl_list, uidl, NULL) == 0) |
745 | mu_list_remove (src_uidl_list, uidl); | 744 | mu_iterator_ctl (itr, mu_itrctl_delete, NULL); |
746 | } | 745 | } |
747 | mu_iterator_destroy (&itr); | 746 | mu_iterator_destroy (&itr); |
748 | mu_list_destroy (&dst_uidl_list); | 747 | mu_list_destroy (&dst_uidl_list); | ... | ... |
-
Please register or sign in to post a comment