--- a/test/mpool_tests.c Tue Feb 21 01:13:17 2012 +0100 +++ b/test/mpool_tests.c Fri Feb 24 15:53:50 2012 +0100 @@ -2,6 +2,8 @@ * */ +#include <inttypes.h> + #include "mpool_tests.h" UCX_TEST_BEGIN(test_ucx_mempool_new) { @@ -70,7 +72,7 @@ } void test_setdestr(void* elem) { - int *cb = (int*) ((int*) elem)[1]; + intptr_t *cb = (intptr_t*) ((intptr_t*) elem)[1]; *cb = 42; } @@ -79,20 +81,19 @@ UcxMempool *pool = ucx_mempool_new(2); ucx_mempool_malloc(pool, sizeof(int)); - int *test = (int*) ucx_mempool_calloc(pool, 2, sizeof(int)); + intptr_t *test = (intptr_t*) ucx_mempool_calloc(pool, 2, sizeof(intptr_t)); - int *cb = (int*) malloc(sizeof(int)); + int *cb = (intptr_t*) malloc(sizeof(intptr_t)); UCX_TEST_ASSERT(cb != NULL && test != NULL, "no memory for test data") - test[0] = 5; test[1] = (int) cb; + test[0] = 5; test[1] = (intptr_t) cb; *cb = 13; ucx_mempool_set_destr(test, test_setdestr); - UCX_TEST_ASSERT( *(ucx_destructor*)(pool->data[1]) == test_setdestr, "failed") UCX_TEST_ASSERT( - test[0] == 5 && test[1] == (int) cb, "setdestr destroyed data") + test[0] == 5 && test[1] == (intptr_t) cb, "setdestr destroyed data") ucx_mempool_free(pool); @@ -108,22 +109,23 @@ UcxMempool *pool = ucx_mempool_new(1); - int *test = (int*) ucx_mempool_calloc(pool, 2, sizeof(int)); + intptr_t *test = (intptr_t*) calloc(2, sizeof(intptr_t)); - int *cb = (int*) malloc(sizeof(int)); + intptr_t *cb = (intptr_t*) malloc(sizeof(intptr_t)); UCX_TEST_ASSERT(cb != NULL && test != NULL, "no memory for test data") - test[0] = 5; test[1] = (int) cb; + test[0] = 5; test[1] = (intptr_t) cb; *cb = 13; ucx_mempool_reg_destr(pool, test, test_setdestr); ucx_destructor *pooladdr = (ucx_destructor*) - ((char*)pool->data[1] + sizeof(ucx_destructor)); + ((char*)pool->data[0] + sizeof(ucx_destructor)); UCX_TEST_ASSERT(*pooladdr == test_setdestr, "failed") ucx_mempool_free(pool); + free(test); UCX_TEST_ASSERT(*cb == 42, "destructor not called") @@ -137,12 +139,12 @@ UcxMempool *pool = ucx_mempool_new(2); ucx_mempool_malloc(pool, sizeof(int)); - int *test = (int*) ucx_mempool_calloc(pool, 2, sizeof(int)); + intptr_t *test = (intptr_t*) ucx_mempool_calloc(pool, 2, sizeof(intptr_t)); - int *cb = (int*) malloc(sizeof(int)); + intptr_t *cb = (intptr_t*) malloc(sizeof(intptr_t)); UCX_TEST_ASSERT(cb != NULL && test != NULL, "no memory for test data") - test[0] = 5; test[1] = (int) cb; + test[0] = 5; test[1] = (intptr_t) cb; *cb = 13; ucx_mempool_set_destr(test, test_setdestr); @@ -151,14 +153,14 @@ do { n *= 2; UCX_TEST_ASSERT(n < 65536, "test corrupt - no movement for realloc") - rtest = ucx_mempool_realloc(pool, test, n*sizeof(int)); + rtest = ucx_mempool_realloc(pool, test, n*sizeof(intptr_t)); } while (rtest == test); test = rtest; UCX_TEST_ASSERT(*(ucx_destructor*)(pool->data[1]) == test_setdestr, "realloc killed destructor") UCX_TEST_ASSERT( - test[0] == 5 && test[1] == (int) cb, "realloc destroyed data") + test[0] == 5 && test[1] == (intptr_t) cb, "realloc destroyed data") ucx_mempool_free(pool);