# HG changeset patch # User Matti Hamalainen # Date 1423265960 -7200 # Node ID 79e904905dbf5fda35c7bcdd5452e9c44989d66b # Parent e96c900ca6f15c98a72d914b9590f342765acba7# Parent 23a79bd6c9d6c77592fefe85d6e4d175aa6a767f Merged. diff -r 23a79bd6c9d6 -r 79e904905dbf th_util.c --- a/th_util.c Sat Feb 07 00:33:41 2015 +0200 +++ b/th_util.c Sat Feb 07 01:39:20 2015 +0200 @@ -240,6 +240,19 @@ } +void th_llist_free_func_node(th_llist_t *list, void (*freefunc)(th_llist_t *)) +{ + th_llist_t *curr = list; + + while (curr != NULL) + { + th_llist_t *next = curr->next; + freefunc(curr); + curr = next; + } +} + + void th_llist_free_func(th_llist_t *list, void (*freefunc)(void *data)) { th_llist_t *curr = list; @@ -247,7 +260,7 @@ while (curr != NULL) { th_llist_t *next = curr->next; - if (freefunc != NULL && curr->data != NULL) + if (curr->data != NULL) freefunc(curr->data); th_free(curr); curr = next; @@ -257,7 +270,14 @@ void th_llist_free(th_llist_t *list) { - th_llist_free_func(list, NULL); + th_llist_t *curr = list; + + while (curr != NULL) + { + th_llist_t *next = curr->next; + th_free(curr); + curr = next; + } } @@ -523,9 +543,9 @@ /* * Ringbuffers */ -qringbuf_t * th_ringbuf_new(const size_t size, void (*mdeallocator)(void *data)) +th_ringbuf_t * th_ringbuf_new(const size_t size, void (*mdeallocator)(void *data)) { - qringbuf_t *res = th_malloc0(sizeof(qringbuf_t)); + th_ringbuf_t *res = th_malloc0(sizeof(th_ringbuf_t)); res->data = (char **) th_calloc(size, sizeof(char *)); res->size = size; @@ -536,7 +556,7 @@ } -BOOL th_ringbuf_grow(qringbuf_t *buf, const size_t n) +BOOL th_ringbuf_grow(th_ringbuf_t *buf, const size_t n) { buf->data = (char **) th_realloc(buf->data, (buf->size + n) * sizeof(char *)); if (buf->data != NULL) @@ -549,7 +569,7 @@ } -void th_ringbuf_free(qringbuf_t *buf) +void th_ringbuf_free(th_ringbuf_t *buf) { int i; @@ -564,7 +584,7 @@ } -void th_ringbuf_add(qringbuf_t *buf, void *ptr) +void th_ringbuf_add(th_ringbuf_t *buf, void *ptr) { if (buf->n < buf->size) buf->n++; diff -r 23a79bd6c9d6 -r 79e904905dbf th_util.h --- a/th_util.h Sat Feb 07 00:33:41 2015 +0200 +++ b/th_util.h Sat Feb 07 01:39:20 2015 +0200 @@ -155,6 +155,7 @@ th_llist_t * th_llist_new(void *data); void th_llist_free(th_llist_t *list); void th_llist_free_func(th_llist_t *list, void (*freefunc)(void *data)); +void th_llist_free_func_node(th_llist_t *list, void (*freefunc)(th_llist_t *node)); void th_llist_append_node(th_llist_t **list, th_llist_t *node); th_llist_t * th_llist_append(th_llist_t **list, void *data); @@ -182,12 +183,12 @@ char **data; int n, size; void (*deallocator)(void *); -} qringbuf_t; +} th_ringbuf_t; -qringbuf_t * th_ringbuf_new(const size_t size, void (*mdeallocator)(void *)); -BOOL th_ringbuf_grow(qringbuf_t *buf, const size_t n); -void th_ringbuf_free(qringbuf_t *buf); -void th_ringbuf_add(qringbuf_t *buf, void *ptr); +th_ringbuf_t * th_ringbuf_new(const size_t size, void (*mdeallocator)(void *)); +BOOL th_ringbuf_grow(th_ringbuf_t *buf, const size_t n); +void th_ringbuf_free(th_ringbuf_t *buf); +void th_ringbuf_add(th_ringbuf_t *buf, void *ptr); /* Growing buffers