--- a/src/server/ucx/mempool.c Thu Jun 20 14:07:46 2013 +0200 +++ b/src/server/ucx/mempool.c Fri Jun 21 12:10:44 2013 +0200 @@ -1,11 +1,38 @@ /* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * + * Copyright 2013 Olaf Wintermann. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. */ #include <stdlib.h> #include <string.h> #include <stdio.h> -#include <errno.h> +#ifdef __cplusplus +#define __STDC_FORMAT_MACROS +#endif +#include <inttypes.h> #include "mempool.h" @@ -28,7 +55,7 @@ UcxMempool *pool = (UcxMempool*)malloc(sizeof(UcxMempool)); if (pool == NULL) return NULL; - pool->data = malloc(n * sizeof(void*)); + pool->data = (void**) malloc(n * sizeof(void*)); if (pool->data == NULL) { free(pool); return NULL; @@ -40,9 +67,9 @@ } int ucx_mempool_chcap(UcxMempool *pool, size_t newcap) { - void **data = realloc(pool->data, newcap*sizeof(void*)); + void **data = (void**) realloc(pool->data, newcap*sizeof(void*)); if (data == NULL) { - return ENOMEM; + return 1; } else { pool->data = data; pool->size = newcap; @@ -79,13 +106,14 @@ char *newm = (char*) realloc(mem, n + sizeof(ucx_destructor)); if (newm == NULL) return NULL; if (mem != newm) { - for(int i=0;i<pool->ndata;i++) { + for(size_t i=0 ; i < pool->ndata ; i++) { if(pool->data[i] == mem) { pool->data[i] = newm; return newm + sizeof(ucx_destructor); } } - fprintf(stderr, "FATAL: %8x not in mpool %8x\n", ptr, pool); + fprintf(stderr, "FATAL: 0x%08" PRIxPTR" not in mpool 0x%08" PRIxPTR"\n", + (intptr_t)ptr, (intptr_t)pool); exit(1); } else { return newm + sizeof(ucx_destructor); @@ -94,7 +122,7 @@ void ucx_mempool_free(UcxMempool *pool) { ucx_memchunk *chunk; - for(int i=0;i<pool->ndata;i++) { + for(size_t i=0 ; i<pool->ndata ; i++) { chunk = (ucx_memchunk*) pool->data[i]; if(chunk->destructor != NULL) { chunk->destructor(&chunk->c);