# HG changeset patch # User Timo Sirainen # Date 1030560383 -10800 # Node ID c081870db35ce8feec92ab4836488c08bcd270c5 # Parent 12746cf2e4478b0152e4b59c293b4cae97b6b407 Still memaligns diff -r 12746cf2e447 -r c081870db35c src/lib/mempool-alloconly.c --- a/src/lib/mempool-alloconly.c Wed Aug 28 21:38:04 2002 +0300 +++ b/src/lib/mempool-alloconly.c Wed Aug 28 21:46:23 2002 +0300 @@ -50,9 +50,12 @@ unsigned int size; unsigned int left; - unsigned char data[MEM_ALIGN_SIZE]; /* variable size */ + /* unsigned char data[]; */ }; -#define SIZEOF_POOLBLOCK (sizeof(PoolBlock)-MEM_ALIGN_SIZE) +#define SIZEOF_POOLBLOCK (MEM_ALIGN(sizeof(PoolBlock))) + +#define POOL_BLOCK_DATA(block) \ + ((char *) (block) + SIZEOF_POOLBLOCK) typedef struct { union { @@ -120,8 +123,8 @@ if (apool->block != NULL) size += apool->block->size; - if (size <= sizeof(PoolBlock)) - size += sizeof(PoolBlock); + if (size <= SIZEOF_POOLBLOCK) + size += SIZEOF_POOLBLOCK; size = nearest_power(size); block = calloc(size, 1); @@ -144,7 +147,7 @@ block_alloc(apool, size); } - alloc = (PoolAlloc *) (apool->block->data + + alloc = (PoolAlloc *) (POOL_BLOCK_DATA(apool->block) + apool->block->size - apool->block->left); alloc->size.size = size; @@ -169,9 +172,9 @@ static int pool_try_grow(AlloconlyPool *apool, void *mem, unsigned int size) { /* see if we want to grow the memory we allocated last */ - if (apool->block->data + (apool->block->size - - apool->block->left - - apool->last_alloc_size) == mem) { + if (POOL_BLOCK_DATA(apool->block) + (apool->block->size - + apool->block->left - + apool->last_alloc_size) == mem) { /* yeah, see if we can grow */ if (apool->block->left >= size-apool->last_alloc_size) { /* just shrink the available size */ @@ -233,7 +236,8 @@ } /* clear the last block */ - memset(apool->block->data, 0, apool->block->size - apool->block->left); + memset(POOL_BLOCK_DATA(apool->block), 0, + apool->block->size - apool->block->left); apool->block->left = apool->block->size; apool->last_alloc_size = 0; diff -r 12746cf2e447 -r c081870db35c src/lib/temp-mempool.c --- a/src/lib/temp-mempool.c Wed Aug 28 21:38:04 2002 +0300 +++ b/src/lib/temp-mempool.c Wed Aug 28 21:46:23 2002 +0300 @@ -51,6 +51,11 @@ /* unsigned char data[]; */ }; +#define SIZEOF_MEMBLOCK MEM_ALIGN(sizeof(MemBlock)) + +#define MEM_BLOCK_DATA(block) \ + ((char *) (block) + SIZEOF_MEMBLOCK) + /* current_stack contains last t_push()ed blocks. After that new MemBlockStack is created and it's ->prev is set to current_stack. */ #define MEM_LIST_BLOCK_COUNT 16 @@ -159,11 +164,11 @@ prev_size = current_block == NULL ? 0 : current_block->size; alloc_size = nearest_power(prev_size + min_size); - block = malloc(MEM_ALIGN(sizeof(MemBlock)) + alloc_size); + block = malloc(SIZEOF_MEMBLOCK + alloc_size); if (block == NULL) { i_panic("mem_block_alloc(): " "Out of memory when allocating %u bytes", - sizeof(MemBlock)-1 + alloc_size); + SIZEOF_MEMBLOCK + alloc_size); } block->size = alloc_size; block->next = NULL; @@ -196,7 +201,7 @@ if (current_block->left >= size) { /* enough space in current block, use it */ - ret = (char *) current_block + MEM_ALIGN(sizeof(MemBlock)) + + ret = MEM_BLOCK_DATA(current_block) + (current_block->size - current_block->left); if (permanent) current_block->left -= size; @@ -219,7 +224,7 @@ current_block->next = block; current_block = block; - return (char *) current_block + MEM_ALIGN(sizeof(MemBlock)); + return MEM_BLOCK_DATA(current_block); } void *t_malloc(unsigned int size) @@ -239,7 +244,7 @@ int t_try_grow(void *mem, unsigned int size) { /* see if we want to grow the memory we allocated last */ - if ((char *) current_block + MEM_ALIGN(sizeof(MemBlock)) + + if (MEM_BLOCK_DATA(current_block) + (current_block->size - current_block->left - last_alloc_size) == mem) { /* yeah, see if we can grow */