# HG changeset patch # User Mike Becker # Date 1325367676 -3600 # Node ID 2dc4c688c26249cf7843e9b5d3a430752a75b19e # Parent b78e174b68141c626af85dc2cd5f87ab689cf964 fixed mpool compiler warnings diff -r b78e174b6814 -r 2dc4c688c262 ucx/mpool.c --- a/ucx/mpool.c Sat Dec 31 22:21:45 2011 +0100 +++ b/ucx/mpool.c Sat Dec 31 22:41:16 2011 +0100 @@ -5,6 +5,7 @@ #include #include #include +#include #include "mpool.h" @@ -25,27 +26,37 @@ UcxMempool *ucx_mempool_new(size_t n) { UcxMempool *pool = (UcxMempool*)malloc(sizeof(UcxMempool)); + if (pool == NULL) return NULL; + pool->data = malloc(n * sizeof(void*)); + if (pool->data == NULL) { + free(pool); + return NULL; + } + pool->ndata = 0; pool->size = n; return pool; } -void ucx_mempool_chcap(UcxMempool *pool, size_t newcap) { +int ucx_mempool_chcap(UcxMempool *pool, size_t newcap) { void **data = realloc(pool->data, newcap*sizeof(void*)); - pool->data = data; - pool->size = newcap; + if (data == NULL) { + return ENOMEM; + } else { + pool->data = data; + pool->size = newcap; + return EXIT_SUCCESS; + } } void *ucx_mempool_malloc(UcxMempool *pool, size_t n) { ucx_memchunk *mem = (ucx_memchunk*)malloc(sizeof(ucx_destructor) + n); - if(mem == NULL) { - return NULL; - } + if (mem == NULL) return NULL; if (pool->ndata >= pool->size) { ucx_mempool_chcap(pool, pool->size + 16); - } + } mem->destructor = NULL; pool->data[pool->ndata] = mem; @@ -65,18 +76,19 @@ void *ucx_mempool_realloc(UcxMempool *pool, void *ptr, size_t n) { void *mem = ((char*)ptr) - sizeof(ucx_destructor); - void *newm = realloc(mem, n + sizeof(ucx_destructor)); + char *newm = (char*) realloc(mem, n + sizeof(ucx_destructor)); if (newm == NULL) return NULL; - if(mem != newm) { + if (mem != newm) { for(int i=0;indata;i++) { if(pool->data[i] == mem) { pool->data[i] = newm; break; } } - /* TODO: exit or kill stultus programmer */ + fprintf(stderr, "FATAL: %8x not in mpool %8x\n", mem, pool); + exit(1); } - return newm + sizeof(ucx_destructor); + return ((char*) newm) + sizeof(ucx_destructor); } void ucx_mempool_free(UcxMempool *pool) { diff -r b78e174b6814 -r 2dc4c688c262 ucx/mpool.h --- a/ucx/mpool.h Sat Dec 31 22:21:45 2011 +0100 +++ b/ucx/mpool.h Sat Dec 31 22:41:16 2011 +0100 @@ -19,7 +19,7 @@ #define ucx_mempool_new_default() ucx_mempool_new(16) UcxMempool *ucx_mempool_new(size_t n); -void ucx_mempool_chcap(UcxMempool *pool, size_t newcap); +int ucx_mempool_chcap(UcxMempool *pool, size_t newcap); void *ucx_mempool_malloc(UcxMempool *pool, size_t n); void *ucx_mempool_calloc(UcxMempool *pool, size_t nelem, size_t elsize);