From 170d63190a3cfb0c12ee9ddfe07b21f20825bd6f Mon Sep 17 00:00:00 2001 From: Aaron Griffin Date: Wed, 24 Jan 2007 08:51:50 +0000 Subject: * Shuffled some of the alpm_list free funtions - still not perfect, but better * Added alpm_list_remove_node for single list node removal * Proper error checking/output for failed db_read/db_write (missing files) * Invalid packages (missing files) are now removed from the package cache * -Qs and -Ss output now look the same * config.rpath causes errors on one machine I had, so I added it to CVS * Fixed a "clobbered memory" issue when installing groups - only the outer list should be free'd, not the contained data --- lib/libalpm/alpm_list.c | 55 +++++++++++++++++++++++++++++++++++++------------ 1 file changed, 42 insertions(+), 13 deletions(-) (limited to 'lib/libalpm/alpm_list.c') diff --git a/lib/libalpm/alpm_list.c b/lib/libalpm/alpm_list.c index 26fcb3dc..edb2e8e5 100644 --- a/lib/libalpm/alpm_list.c +++ b/lib/libalpm/alpm_list.c @@ -49,33 +49,37 @@ alpm_list_t *alpm_list_new() return(list); } -/** Free a list structure and possibly the internal data as well +/** Free a list, but not the contained data * @param list the list to free - * @param fn a free function for the internal data, or NULL for none */ -void alpm_list_free(alpm_list_t *list, alpm_list_fn_free fn) +void alpm_list_free(alpm_list_t *list) { alpm_list_t *it = list; while(it) { - alpm_list_t *ptr = it->next; - if(fn && it->data) { - fn(it->data); - } - FREE(it); - it = ptr; + alpm_list_t *tmp = it->next; + free(it); + it = tmp; } } -/** Free the outer list, but not the contained data - * A minor simplification of alpm_list_free +/** Free the internal data of a list structure * @param list the list to free + * @param fn a free function for the internal data */ -void alpm_list_free_outer(alpm_list_t *list) +void alpm_list_free_inner(alpm_list_t *list, alpm_list_fn_free fn) { - alpm_list_free(list, NULL); + alpm_list_t *it = list; + + while(it) { + if(fn && it->data) { + fn(it->data); + } + it = it->next; + } } + /* Mutators */ /** Add a new item to the list @@ -271,6 +275,31 @@ alpm_list_t *alpm_list_remove(alpm_list_t *haystack, void *needle, alpm_list_fn_ return(haystack); } +/** Remove the passed in node from the list that it is a part of + * @note this DOES NOT free the node + * @param node the list node we're removing + * @return the node which took the place of this one + */ +alpm_list_t *alpm_list_remove_node(alpm_list_t *node) +{ + if(!node) return(NULL); + + alpm_list_t *ret = NULL; + + if(node->prev) { + node->prev->next = node->next; + ret = node->prev; + node->prev = NULL; + } + if(node->next) { + node->next->prev = node->prev; + ret = node->next; + node->next = NULL; + } + + return(ret); +} + /** Create a new list without any duplicates * @note DOES NOT copy data members * @param list the list to copy -- cgit v1.2.3-54-g00ecf