diff --git a/doc/libcfu.texi b/doc/libcfu.texi index 3b1a38d..89f7854 100644 --- a/doc/libcfu.texi +++ b/doc/libcfu.texi @@ -490,7 +490,12 @@ cfulist_map(). The return value is used to build a new list. @deftypefun {cfulist_t *} cfulist_new (); - Returns a new list. + Creates a new list. +@end deftypefun + +@deftypefun {cfulist_t *} cfulist_new_with_free_fn (cfulist_free_fn_t @var{ff}) + + Same as cfulist_new() except automatically calls cfulist_set_free_fn(). @end deftypefun @deftypefun {size_t} cfulist_num_entries (cfulist_t *@var{list}) diff --git a/src/cfulist.c b/src/cfulist.c index 052d515..b58846e 100644 --- a/src/cfulist.c +++ b/src/cfulist.c @@ -84,10 +84,16 @@ cfulist_new(void) { cfulist_t * cfulist_new_with_free_fn(cfulist_free_fn_t free_fn) { cfulist_t *list = cfulist_new(); - list->free_fn = free_fn; + cfulist_set_free_function (list, free_fn); return list; } +int +cfulist_set_free_function(cfulist_t *list, cfulist_free_fn_t ff) { + if (ff) list->free_fn = ff; + return 0; +} + size_t cfulist_num_entries(cfulist_t *list) { return list->num_entries; diff --git a/src/cfulist.h b/src/cfulist.h index 52e92ec..e7cea4f 100644 --- a/src/cfulist.h +++ b/src/cfulist.h @@ -65,9 +65,7 @@ typedef void (*cfulist_free_fn_t)(void *data); /* Returns a new list. */ cfulist_t * cfulist_new(void); -/* Same as cfulist_new(), but set a function to be called on each - * element when the list is destroyed. - */ +/* Same as cfulist_new() except automatically calls cfulist_set_free_fn(). */ cfulist_t * cfulist_new_with_free_fn(cfulist_free_fn_t free_fn); /* Returns the number of entries in the list. */