Mercurial > hg > th-libs
changeset 632:553db886533e
Return a THERR_* error value from th_ringbuf_grow() instead of BOOL. This
breaks the API, but checking against BOOL will result in failure in case of
actual success (THERR_OK == 0) which should be "easy" to detect.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Fri, 17 Jan 2020 20:08:55 +0200 |
parents | d5221299656a |
children | e3c4d8e28695 |
files | th_datastruct.c th_datastruct.h |
diffstat | 2 files changed, 13 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- a/th_datastruct.c Fri Jan 17 20:07:25 2020 +0200 +++ b/th_datastruct.c Fri Jan 17 20:08:55 2020 +0200 @@ -360,17 +360,19 @@ } -BOOL th_ringbuf_grow(th_ringbuf_t *buf, const size_t n) +int th_ringbuf_grow(th_ringbuf_t *buf, const size_t nadd) { - buf->data = (void **) th_realloc(buf->data, (buf->size + n) * sizeof(void *)); - if (buf->data != NULL) - { - memset(buf->data + buf->size, 0, sizeof(void *) * n); - buf->size += n; - return TRUE; - } - else - return FALSE; + if (buf == NULL) + return THERR_NULLPTR; + + buf->data = (void **) th_realloc(buf->data, (buf->size + nadd) * sizeof(void *)); + if (buf->data == NULL) + return THERR_MALLOC; + + memset(buf->data + buf->size, 0, sizeof(void *) * nadd); + buf->size += nadd; + + return THERR_OK; }
--- a/th_datastruct.h Fri Jan 17 20:07:25 2020 +0200 +++ b/th_datastruct.h Fri Jan 17 20:08:55 2020 +0200 @@ -67,7 +67,7 @@ int th_ringbuf_init(th_ringbuf_t *buf, const size_t size, void (*mdeallocator)(void *data)); th_ringbuf_t * th_ringbuf_new(const size_t size, void (*mdeallocator)(void *data)); -BOOL th_ringbuf_grow(th_ringbuf_t *buf, const size_t n); +int 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);