From 193a7be520502f24e995b71768dd89c37b3776eb Mon Sep 17 00:00:00 2001 From: Laurent Bercot Date: Tue, 13 Jun 2023 22:19:05 +0000 Subject: Fix iter_func type; add tain_earliest Signed-off-by: Laurent Bercot --- src/libdatastruct/genset_deepfree.c | 4 ++-- src/libdatastruct/genset_iter_nocancel.c | 2 ++ src/libdatastruct/genset_iter_withcancel.c | 1 + src/libdatastruct/gensetdyn_deepfree.c | 4 ++-- src/libdatastruct/gensetdyn_iter.c | 27 ------------------------- src/libdatastruct/gensetdyn_iter_nocancel.c | 29 +++++++++++++++++++++++++++ src/libdatastruct/gensetdyn_iter_withcancel.c | 1 + 7 files changed, 37 insertions(+), 31 deletions(-) delete mode 100644 src/libdatastruct/gensetdyn_iter.c create mode 100644 src/libdatastruct/gensetdyn_iter_nocancel.c (limited to 'src/libdatastruct') diff --git a/src/libdatastruct/genset_deepfree.c b/src/libdatastruct/genset_deepfree.c index c58a5f9..7b4a728 100644 --- a/src/libdatastruct/genset_deepfree.c +++ b/src/libdatastruct/genset_deepfree.c @@ -3,10 +3,10 @@ #include #include -static int freeiter (char *s, void *aux) +static int freeiter (void *s, void *aux) { free_func_ref f = aux ; - (*f)((void *)s) ; + (*f)(s) ; return 1 ; } diff --git a/src/libdatastruct/genset_iter_nocancel.c b/src/libdatastruct/genset_iter_nocancel.c index 339f4b6..28da323 100644 --- a/src/libdatastruct/genset_iter_nocancel.c +++ b/src/libdatastruct/genset_iter_nocancel.c @@ -1,5 +1,7 @@ /* ISC license. */ +#include + #include #include diff --git a/src/libdatastruct/genset_iter_withcancel.c b/src/libdatastruct/genset_iter_withcancel.c index 1220dbc..6b70c68 100644 --- a/src/libdatastruct/genset_iter_withcancel.c +++ b/src/libdatastruct/genset_iter_withcancel.c @@ -2,6 +2,7 @@ #include #include + #include int genset_iter_withcancel (genset *g, iter_func_ref f, iter_func_ref cancelf, void *stuff) diff --git a/src/libdatastruct/gensetdyn_deepfree.c b/src/libdatastruct/gensetdyn_deepfree.c index 2b0c87c..623120f 100644 --- a/src/libdatastruct/gensetdyn_deepfree.c +++ b/src/libdatastruct/gensetdyn_deepfree.c @@ -3,10 +3,10 @@ #include #include -static int freeiter (char *s, void *aux) +static int freeiter (void *s, void *aux) { free_func_ref f = aux ; - (*f)((void *)s) ; + (*f)(s) ; return 1 ; } diff --git a/src/libdatastruct/gensetdyn_iter.c b/src/libdatastruct/gensetdyn_iter.c deleted file mode 100644 index 8470adf..0000000 --- a/src/libdatastruct/gensetdyn_iter.c +++ /dev/null @@ -1,27 +0,0 @@ -/* ISC license. */ - -#include -#include -#include - -uint32_t gensetdyn_iter_nocancel (gensetdyn *g, uint32_t n, iter_func_ref f, void *stuff) -{ - /* - XXX: we may be called by a freeing function, so we cannot alloc - - XXX: so pray that the bitarray fits in the stack. - */ - unsigned char bits[bitarray_div8(g->storage.len) ? bitarray_div8(g->storage.len) : 1] ; - size_t i = 0 ; - uint32_t j = 0 ; - uint32_t *fl = genalloc_s(uint32_t, &g->freelist) ; - size_t sp = genalloc_len(uint32_t, &g->freelist) ; - bitarray_setn(bits, 0, g->storage.len) ; - - for (; i < sp ; i++) if (fl[i] < g->storage.len) bitarray_clear(bits, fl[i]) ; - for (i = 0 ; (i < g->storage.len) && (j < n) ; i++) if (bitarray_peek(bits, i)) - { - j++ ; - if (!(*f)(gensetdyn_p(g, i), stuff)) break ; - } - return j ; -} diff --git a/src/libdatastruct/gensetdyn_iter_nocancel.c b/src/libdatastruct/gensetdyn_iter_nocancel.c new file mode 100644 index 0000000..a06b6b5 --- /dev/null +++ b/src/libdatastruct/gensetdyn_iter_nocancel.c @@ -0,0 +1,29 @@ +/* ISC license. */ + +#include +#include + +#include +#include + +uint32_t gensetdyn_iter_nocancel (gensetdyn *g, uint32_t n, iter_func_ref f, void *stuff) +{ + /* + XXX: we may be called by a freeing function, so we cannot alloc - + XXX: so pray that the bitarray fits in the stack. + */ + unsigned char bits[bitarray_div8(g->storage.len) ? bitarray_div8(g->storage.len) : 1] ; + size_t i = 0 ; + uint32_t j = 0 ; + uint32_t *fl = genalloc_s(uint32_t, &g->freelist) ; + size_t sp = genalloc_len(uint32_t, &g->freelist) ; + bitarray_setn(bits, 0, g->storage.len) ; + + for (; i < sp ; i++) if (fl[i] < g->storage.len) bitarray_clear(bits, fl[i]) ; + for (i = 0 ; (i < g->storage.len) && (j < n) ; i++) if (bitarray_peek(bits, i)) + { + j++ ; + if (!(*f)(gensetdyn_p(g, i), stuff)) break ; + } + return j ; +} diff --git a/src/libdatastruct/gensetdyn_iter_withcancel.c b/src/libdatastruct/gensetdyn_iter_withcancel.c index 0a250ce..b883e58 100644 --- a/src/libdatastruct/gensetdyn_iter_withcancel.c +++ b/src/libdatastruct/gensetdyn_iter_withcancel.c @@ -2,6 +2,7 @@ #include #include + #include int gensetdyn_iter_withcancel (gensetdyn *g, iter_func_ref f, iter_func_ref cancelf, void *stuff) -- cgit 1.4.1