path: root/st.c
diff options
author卜部昌平 <>2019-08-26 07:06:40 (GMT)
committer卜部昌平 <>2019-08-27 06:52:26 (GMT)
commit6dd60cf114701f1ff3526381c0e742c588af2f91 (patch)
treed3552b145f9b5153c470ad7e3cf560c0dd5c552e /st.c
parente3fc30564e9466d6926f9d25a090dcf787bd5c33 (diff)
st_foreach now free from ANYARGS
After 5e86b005c0f2ef30df2f9906c7e2f3abefe286a2, I now think ANYARGS is dangerous and should be extinct. This commit deletes ANYARGS from st_foreach. I strongly believe that this commit should have had come with b0af0592fdd9e9d4e4b863fde006d67ccefeac21, which added extra parameter to st_foreach callbacks.
Diffstat (limited to 'st.c')
1 files changed, 18 insertions, 5 deletions
diff --git a/st.c b/st.c
index cecc2ac..c32a7ed 100644
--- a/st.c
+++ b/st.c
@@ -1548,7 +1548,7 @@ st_update(st_table *tab, st_data_t key,
different for ST_CHECK and when the current element is removed
during traversing. */
static inline int
-st_general_foreach(st_table *tab, int (*func)(ANYARGS), st_update_callback_func *replace, st_data_t arg,
+st_general_foreach(st_table *tab, st_foreach_check_callback_func *func, st_update_callback_func *replace, st_data_t arg,
int check_p)
st_index_t bin;
@@ -1659,20 +1659,33 @@ st_general_foreach(st_table *tab, int (*func)(ANYARGS), st_update_callback_func
-st_foreach_with_replace(st_table *tab, int (*func)(ANYARGS), st_update_callback_func *replace, st_data_t arg)
+st_foreach_with_replace(st_table *tab, st_foreach_check_callback_func *func, st_update_callback_func *replace, st_data_t arg)
return st_general_foreach(tab, func, replace, arg, TRUE);
+struct functor {
+ st_foreach_callback_func *func;
+ st_data_t arg;
+static int
+apply_functor(st_data_t k, st_data_t v, st_data_t d, int _)
+ const struct functor *f = (void *)d;
+ return f->func(k, v, f->arg);
-st_foreach(st_table *tab, int (*func)(ANYARGS), st_data_t arg)
+st_foreach(st_table *tab, st_foreach_callback_func *func, st_data_t arg)
- return st_general_foreach(tab, func, NULL, arg, FALSE);
+ const struct functor f = { func, arg };
+ return st_general_foreach(tab, apply_functor, NULL, (st_data_t)&f, FALSE);
/* See comments for function st_delete_safe. */
-st_foreach_check(st_table *tab, int (*func)(ANYARGS), st_data_t arg,
+st_foreach_check(st_table *tab, st_foreach_check_callback_func *func, st_data_t arg,
st_data_t never ATTRIBUTE_UNUSED)
return st_general_foreach(tab, func, NULL, arg, TRUE);