[PATCH 04/10] string-list API: mark "struct_string_list" to "for_each_string_list" const
- From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
- Date
- Oct 26, 2022, 15:35 UTC
- Message-ID
- <patch-04.10-40b3cc9b8d4-20221026T151328Z-avarab@gmail.com>
- In-Reply-To
- <cover-00.10-00000000000-20221026T151328Z-avarab@gmail.com>
Add a "const" to the "struct string_list *" passed to for_each_string_list().
This is arguably abuse of the type system, as the "string_list_each_func_t fn" take a "struct string_list_item *", i.e. not one with a "const", and those functions *can* modify those items.
But as we'll see in a subsequent commit we have other such iteration functions that could benefit from a "const", i.e. to declare that we're not altering the list itself, even though we might be calling functions that alter its values.
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> --- string-list.c | 2 +- string-list.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/string-list.c b/string-list.c index 549fc416d68..d8957466d25 100644 --- a/string-list.c +++ b/string-list.c @@ -129,7 +129,7 @@ void string_list_remove_duplicates(struct string_list *list, int free_util) } } -int for_each_string_list(struct string_list *list, +int for_each_string_list(const struct string_list *list, string_list_each_func_t fn, void *cb_data) { int i, ret = 0; diff --git a/string-list.h b/string-list.h index c7b0d5d0008..7153cb79154 100644 --- a/string-list.h +++ b/string-list.h @@ -138,7 +138,7 @@ void string_list_clear_func(struct string_list *list, string_list_clear_func_t c * Apply `func` to each item. If `func` returns nonzero, the * iteration aborts and the return value is propagated. */ -int for_each_string_list(struct string_list *list, +int for_each_string_list(const struct string_list *list, string_list_each_func_t func, void *cb_data); /**
-- 2.38.0.1251.g3eefdfb5e7a