skalibs

Mirror/fork of https://skarnet.org/software/skalibs/
git clone https://ccx.te2000.cz/git/skalibs
Log | Files | Refs | README | LICENSE

commit 57459439db1f48dbbace1ab059117798fa26d203
parent 564c6ba2f899a4b530d58f6ac123e31d6b797fe2
Author: Laurent Bercot <ska-skaware@skarnet.org>
Date:   Fri, 13 Apr 2018 02:19:08 +0000

 Add genset[dyn]_deepfree

Diffstat:
Mpackage/deps.mak | 2++
Msrc/include/skalibs/genset.h | 2++
Msrc/include/skalibs/gensetdyn.h | 1+
Asrc/libdatastruct/genset_deepfree.c | 16++++++++++++++++
Asrc/libdatastruct/gensetdyn_deepfree.c | 17+++++++++++++++++
5 files changed, 38 insertions(+), 0 deletions(-)

diff --git a/package/deps.mak b/package/deps.mak @@ -127,8 +127,10 @@ src/libdatastruct/genqdyn_push.o src/libdatastruct/genqdyn_push.lo: src/libdatas src/libdatastruct/genqdyn_unpush.o src/libdatastruct/genqdyn_unpush.lo: src/libdatastruct/genqdyn_unpush.c src/include/skalibs/genqdyn.h src/include/skalibs/stralloc.h src/libdatastruct/genqdyn_zero.o src/libdatastruct/genqdyn_zero.lo: src/libdatastruct/genqdyn_zero.c src/include/skalibs/genqdyn.h src/libdatastruct/genset.o src/libdatastruct/genset.lo: src/libdatastruct/genset.c src/include/skalibs/genset.h +src/libdatastruct/genset_deepfree.o src/libdatastruct/genset_deepfree.lo: src/libdatastruct/genset_deepfree.c src/include/skalibs/functypes.h src/include/skalibs/genset.h src/libdatastruct/genset_iter_nocancel.o src/libdatastruct/genset_iter_nocancel.lo: src/libdatastruct/genset_iter_nocancel.c src/include/skalibs/bitarray.h src/include/skalibs/genset.h src/libdatastruct/genset_iter_withcancel.o src/libdatastruct/genset_iter_withcancel.lo: src/libdatastruct/genset_iter_withcancel.c src/include/skalibs/genset.h +src/libdatastruct/gensetdyn_deepfree.o src/libdatastruct/gensetdyn_deepfree.lo: src/libdatastruct/gensetdyn_deepfree.c src/include/skalibs/functypes.h src/include/skalibs/gensetdyn.h src/libdatastruct/gensetdyn_delete.o src/libdatastruct/gensetdyn_delete.lo: src/libdatastruct/gensetdyn_delete.c src/include/skalibs/genalloc.h src/include/skalibs/gensetdyn.h src/libdatastruct/gensetdyn_free.o src/libdatastruct/gensetdyn_free.lo: src/libdatastruct/gensetdyn_free.c src/include/skalibs/genalloc.h src/include/skalibs/gensetdyn.h src/include/skalibs/stralloc.h src/libdatastruct/gensetdyn_init.o src/libdatastruct/gensetdyn_init.lo: src/libdatastruct/gensetdyn_init.c src/include/skalibs/genalloc.h src/include/skalibs/gensetdyn.h src/include/skalibs/stralloc.h diff --git a/src/include/skalibs/genset.h b/src/include/skalibs/genset.h @@ -27,6 +27,7 @@ extern int genset_delete (genset *, uint32_t) ; extern uint32_t genset_iter_nocancel (genset *, uint32_t, iterfunc_t_ref, void *) ; #define genset_iter(g, f, stuff) genset_iter_nocancel(g, (g)->max, f, stuff) extern int genset_iter_withcancel (genset *, iterfunc_t_ref, iterfunc_t_ref, void *) ; +extern void genset_deepfree (genset *, freefunc_t_ref) ; #define GENSETB_TYPE(type, size) struct { type storage[size] ; uint32_t freelist[size] ; genset info ; } #define GENSETB_init(type, g, size) GENSET_init(&(g)->info, type, (g)->storage, (g)->freelist, size) @@ -35,5 +36,6 @@ extern int genset_iter_withcancel (genset *, iterfunc_t_ref, iterfunc_t_ref, voi #define gensetb_delete(g, i) genset_delete(&(g)->info, i) #define gensetb_n(g) genset_n(&(g)->info) #define gensetb_iter(g, f, p) genset_iter(&(g)->info, f, p) +#define gensetb_deepfree(g, f) genset_deepfree(&(g)->info, f) #endif diff --git a/src/include/skalibs/gensetdyn.h b/src/include/skalibs/gensetdyn.h @@ -29,6 +29,7 @@ extern void gensetdyn_init (gensetdyn *, uint32_t, uint32_t, uint32_t, uint32_t) extern int gensetdyn_ready (gensetdyn *, uint32_t) ; #define gensetdyn_readyplus(x, n) gensetdyn_ready(x, gensetdyn_n(x) + (n)) extern void gensetdyn_free (gensetdyn *) ; +extern void gensetdyn_deepfree (gensetdyn *, freefunc_t_ref) ; extern int gensetdyn_new (gensetdyn *, uint32_t *) ; extern int gensetdyn_delete (gensetdyn *, uint32_t) ; diff --git a/src/libdatastruct/genset_deepfree.c b/src/libdatastruct/genset_deepfree.c @@ -0,0 +1,16 @@ +/* ISC license. */ + +#include <skalibs/functypes.h> +#include <skalibs/genset.h> + +static int freeiter (char *s, void *aux) +{ + freefunc_t_ref f = aux ; + (*f)((void *)s) ; + return 1 ; +} + +void genset_deepfree (genset *g, freefunc_t_ref f) +{ + genset_iter(g, &freeiter, f) ; +} diff --git a/src/libdatastruct/gensetdyn_deepfree.c b/src/libdatastruct/gensetdyn_deepfree.c @@ -0,0 +1,17 @@ +/* ISC license. */ + +#include <skalibs/functypes.h> +#include <skalibs/gensetdyn.h> + +static int freeiter (char *s, void *aux) +{ + freefunc_t_ref f = aux ; + (*f)((void *)s) ; + return 1 ; +} + +void gensetdyn_deepfree (gensetdyn *g, freefunc_t_ref f) +{ + gensetdyn_iter(g, &freeiter, f) ; + gensetdyn_free(g) ; +}