Mercurial > hg > nnchat
comparison th_util.c @ 306:21528fe535fb
Don't use void pointers in the ringbuffer implementation.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sat, 11 Jun 2011 05:36:09 +0300 |
parents | dbf07a4eadd7 |
children | a6304a3719ee |
comparison
equal
deleted
inserted
replaced
305:6918c46015d0 | 306:21528fe535fb |
---|---|
401 */ | 401 */ |
402 qringbuf_t * th_ringbuf_new(const size_t size, void (*mdeallocator)(void *data)) | 402 qringbuf_t * th_ringbuf_new(const size_t size, void (*mdeallocator)(void *data)) |
403 { | 403 { |
404 qringbuf_t *res = th_calloc(1, sizeof(qringbuf_t)); | 404 qringbuf_t *res = th_calloc(1, sizeof(qringbuf_t)); |
405 | 405 |
406 res->data = (void **) th_malloc(size * sizeof(void *)); | 406 res->data = (char **) th_calloc(size, sizeof(char *)); |
407 res->size = size; | 407 res->size = size; |
408 res->n = 0; | 408 res->n = 0; |
409 res->deallocator = mdeallocator; | 409 res->deallocator = mdeallocator; |
410 | 410 |
411 return res; | 411 return res; |
412 } | 412 } |
413 | 413 |
414 | 414 |
415 BOOL th_ringbuf_grow(qringbuf_t *buf, const size_t n) | 415 BOOL th_ringbuf_grow(qringbuf_t *buf, const size_t n) |
416 { | 416 { |
417 buf->size += n; | 417 buf->data = (char **) th_realloc(buf->data, (buf->size + n) * sizeof(char *)); |
418 buf->data = (void **) th_realloc(buf->data, buf->size * sizeof(void *)); | 418 if (buf->data != NULL) { |
419 return (buf->data != NULL); | 419 memset(buf->data + buf->size, 0, sizeof(char *) * n); |
420 buf->size += n; | |
421 return TRUE; | |
422 } else | |
423 return FALSE; | |
420 } | 424 } |
421 | 425 |
422 | 426 |
423 void th_ringbuf_free(qringbuf_t *buf) | 427 void th_ringbuf_free(qringbuf_t *buf) |
424 { | 428 { |