From 19e831ed3da2aba75d56e46c57967bcc60442d57 Mon Sep 17 00:00:00 2001 From: Ian Fan Date: Sat, 8 Dec 2018 22:52:29 +0000 Subject: list.c: Remove list_foreach Most occurrences have been replaced by `free_flat_list` which has been moved from stringop.c to list.c. The rest have been replaced by for loops. --- include/list.h | 7 ++++++- include/stringop.h | 1 - 2 files changed, 6 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/list.h b/include/list.h index 03851a82..70af49f6 100644 --- a/include/list.h +++ b/include/list.h @@ -9,7 +9,6 @@ typedef struct { list_t *create_list(void); void list_free(list_t *list); -void list_foreach(list_t *list, void (*callback)(void* item)); void list_add(list_t *list, void *item); void list_insert(list_t *list, int index, void *item); void list_del(list_t *list, int index); @@ -27,4 +26,10 @@ void list_stable_sort(list_t *list, int compare(const void *a, const void *b)); void list_swap(list_t *list, int src, int dest); // move item to end of list void list_move_to_end(list_t *list, void *item); + +/* Calls `free` for each item in the list, then frees the list. + * Do not use this to free lists of primitives or items that require more + * complicated deallocation code. + */ +void free_flat_list(list_t *list); #endif diff --git a/include/stringop.h b/include/stringop.h index 919e605c..215f7916 100644 --- a/include/stringop.h +++ b/include/stringop.h @@ -19,7 +19,6 @@ int lenient_strcmp(char *a, char *b); // Simply split a string with delims, free with `free_flat_list` list_t *split_string(const char *str, const char *delims); -void free_flat_list(list_t *list); // Splits an argument string, keeping quotes intact char **split_args(const char *str, int *argc); -- cgit v1.2.3 From 98c1e19466c0d83c8e1ca86eda5b273eda7eff3c Mon Sep 17 00:00:00 2001 From: Ian Fan Date: Sun, 9 Dec 2018 01:15:23 +0000 Subject: list.c: rename free_flat_list to list_free_items_and_destroy --- include/list.h | 2 +- include/stringop.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/list.h b/include/list.h index 70af49f6..895f6cc0 100644 --- a/include/list.h +++ b/include/list.h @@ -31,5 +31,5 @@ void list_move_to_end(list_t *list, void *item); * Do not use this to free lists of primitives or items that require more * complicated deallocation code. */ -void free_flat_list(list_t *list); +void list_free_items_and_destroy(list_t *list); #endif diff --git a/include/stringop.h b/include/stringop.h index 215f7916..d1bfa29d 100644 --- a/include/stringop.h +++ b/include/stringop.h @@ -17,7 +17,7 @@ char *lenient_strncat(char *dest, const char *src, size_t len); // strcmp that also handles null pointers. int lenient_strcmp(char *a, char *b); -// Simply split a string with delims, free with `free_flat_list` +// Simply split a string with delims, free with `list_free_items_and_destroy` list_t *split_string(const char *str, const char *delims); // Splits an argument string, keeping quotes intact -- cgit v1.2.3