From 46beb1adcb3d254b21067a575dc0665035085cab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dag-Erling=20Sm=C3=B8rgrav?= Date: Thu, 30 Oct 2014 12:14:05 +0000 Subject: [PATCH] Various fixes for Linux and gcc portability. --- t/t_malloc.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/t/t_malloc.c b/t/t_malloc.c index d8f9c1f..72ac0ac 100644 --- a/t/t_malloc.c +++ b/t/t_malloc.c @@ -32,6 +32,14 @@ #include #include +#ifndef MAP_NOCORE +#define MAP_NOCORE 0 +#endif + +#ifndef MAP_NOSYNC +#define MAP_NOSYNC 0 +#endif + #ifdef HAVE_UTRACE #include #include @@ -39,6 +47,7 @@ #include #include +#include #include #include #include @@ -216,7 +225,7 @@ t_malloc_bucket(size_t size) void *p; /* select bucket */ - for (shift = BUCKET_MIN_SHIFT; (1 << shift) < size; ++shift) + for (shift = BUCKET_MIN_SHIFT; (1U << shift) < size; ++shift) /* nothing */ ; assert(shift >= BUCKET_MIN_SHIFT && shift <= BUCKET_MAX_SHIFT); b = &buckets[shift]; @@ -243,7 +252,7 @@ t_malloc_bucket(size_t size) /* update the free block pointer */ if (b->free == b->unused) { /* never been used before, increment free pointer */ - b->free = b->unused = b->unused + (1 << shift); + b->free = b->unused = b->unused + (1U << shift); } else { /* previously used, disconnect from free list */ b->free = *(char **)p; @@ -266,7 +275,7 @@ t_malloc(size_t size) /* select and call the right backend */ if (size == 0) return (t_malloc_null()); - else if (size > (1 << BUCKET_MAX_SHIFT)) + else if (size > (1U << BUCKET_MAX_SHIFT)) return (t_malloc_mapped(size)); else return (t_malloc_bucket(size)); @@ -351,8 +360,8 @@ realloc(void *o, size_t size) b = &buckets[shift]; if (o >= b->base && o < b->top) { /* found our bucket */ - assert(PDIFF(o, b->base) % (1 << shift) == 0); - osize = 1 << shift; + assert(PDIFF(o, b->base) % (1U << shift) == 0); + osize = 1U << shift; goto found; } } @@ -422,8 +431,8 @@ free(void *p) b = &buckets[shift]; if (p >= b->base && p < b->top) { /* found our bucket */ - assert(PDIFF(p, b->base) % (1 << shift) == 0); - memset(p, BUCKET_FILL_FREE, 1 << shift); + assert(PDIFF(p, b->base) % (1U << shift) == 0); + memset(p, BUCKET_FILL_FREE, 1U << shift); /* connect the block to the free list */ *(char **)p = b->free; b->free = p;