[dovecot-cvs] dovecot/src/lib data-stack.c,1.14,1.15 mempool-alloconly.c,1.14,1.15 mempool-datastack.c,1.3,1.4 mempool-system.c,1.6,1.7 mempool.h,1.6,1.7

cras at procontrol.fi cras at procontrol.fi
Fri Dec 27 16:01:44 EET 2002


Update of /home/cvs/dovecot/src/lib
In directory danu:/tmp/cvs-serv32737

Modified Files:
	data-stack.c mempool-alloconly.c mempool-datastack.c 
	mempool-system.c mempool.h 
Log Message:
Removed pool->realloc_min() which nothing used. A few small fixes to
alloc-only pool.



Index: data-stack.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib/data-stack.c,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -d -r1.14 -r1.15
--- data-stack.c	22 Dec 2002 07:28:43 -0000	1.14
+++ data-stack.c	27 Dec 2002 14:01:42 -0000	1.15
@@ -36,11 +36,6 @@
 
 #ifndef DISABLE_DATA_STACK
 
-/* Max. number of bytes to even try to allocate. This is done just to avoid
-   allocating less memory than was actually requested because of integer
-   overflows. */
-#define MAX_ALLOC_SIZE SSIZE_T_MAX
-
 /* Initial stack size - this should be kept in a size that doesn't exceed
    in a normal use to avoid extra malloc()ing. */
 #ifdef DEBUG

Index: mempool-alloconly.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib/mempool-alloconly.c,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -d -r1.14 -r1.15
--- mempool-alloconly.c	22 Dec 2002 07:06:16 -0000	1.14
+++ mempool-alloconly.c	27 Dec 2002 14:01:42 -0000	1.15
@@ -40,7 +40,6 @@
 	int refcount;
 
 	PoolBlock *block;
-	size_t last_alloc_size;
 
 	char name[MEM_ALIGN_SIZE]; /* variable size */
 } AlloconlyPool;
@@ -51,6 +50,7 @@
 
 	size_t size;
 	size_t left;
+	size_t last_alloc_size;
 
 	/* unsigned char data[]; */
 };
@@ -73,7 +73,6 @@
 static void *pool_alloconly_malloc(Pool pool, size_t size);
 static void pool_alloconly_free(Pool pool, void *mem);
 static void *pool_alloconly_realloc(Pool pool, void *mem, size_t size);
-static void *pool_alloconly_realloc_min(Pool pool, void *mem, size_t size);
 static void pool_alloconly_clear(Pool pool);
 
 static void block_alloc(AlloconlyPool *pool, size_t size);
@@ -86,7 +85,6 @@
 	pool_alloconly_free,
 
 	pool_alloconly_realloc,
-	pool_alloconly_realloc_min,
 
 	pool_alloconly_clear
 };
@@ -139,12 +137,10 @@
 	PoolBlock *block;
 
 	/* each block is at least twice the size of the previous one */
-	if (apool->block != NULL)
+	if (apool->block != NULL && size <= apool->block->size)
 		size += apool->block->size;
 
-	if (size <= SIZEOF_POOLBLOCK)
-		size += SIZEOF_POOLBLOCK;
-	size = nearest_power(size);
+	size = nearest_power(size + SIZEOF_POOLBLOCK);
 
 #ifdef DEBUG
 	if (apool->block != NULL) {
@@ -183,7 +179,7 @@
 	alloc->size.size = size;
 
 	apool->block->left -= size + SIZEOF_POOLALLOC;
-	apool->last_alloc_size = size;
+	apool->block->last_alloc_size = size;
 	return alloc->data;
 }
 
@@ -193,24 +189,18 @@
 	/* ignore */
 }
 
-static void *pool_alloconly_realloc(Pool pool, void *mem, size_t size)
-{
-	/* there's no point in shrinking the memory usage,
-	   so just do the same as realloc_min() */
-	return pool_alloconly_realloc_min(pool, mem, size);
-}
-
 static int pool_try_grow(AlloconlyPool *apool, void *mem, size_t size)
 {
 	/* see if we want to grow the memory we allocated last */
-	if (POOL_BLOCK_DATA(apool->block) + (apool->block->size -
-					     apool->block->left -
-					     apool->last_alloc_size) == mem) {
+	if (POOL_BLOCK_DATA(apool->block) +
+	    (apool->block->size - apool->block->left -
+	     apool->block->last_alloc_size) == mem) {
 		/* yeah, see if we can grow */
-		if (apool->block->left >= size-apool->last_alloc_size) {
+		if (apool->block->left >= size-apool->block->last_alloc_size) {
 			/* just shrink the available size */
-			apool->block->left -= size - apool->last_alloc_size;
-			apool->last_alloc_size = size;
+			apool->block->left -=
+				size - apool->block->last_alloc_size;
+			apool->block->last_alloc_size = size;
 			return TRUE;
 		}
 	}
@@ -218,7 +208,7 @@
 	return FALSE;
 }
 
-static void *pool_alloconly_realloc_min(Pool pool, void *mem, size_t size)
+static void *pool_alloconly_realloc(Pool pool, void *mem, size_t size)
 {
 	AlloconlyPool *apool = (AlloconlyPool *) pool;
 	PoolAlloc *alloc;
@@ -228,16 +218,14 @@
 	if (size == 0 || size > SSIZE_T_MAX)
 		i_panic("Trying to allocate %"PRIuSIZE_T" bytes", size);
 
-	if (mem == NULL) {
-		alloc = NULL;
-		old_size = 0;
-	} else {
-		/* get old size */
-                alloc = (PoolAlloc *) ((char *) mem - SIZEOF_POOLALLOC);
-		old_size = alloc->size.size;
-	}
+	if (mem == NULL)
+		return pool_alloconly_malloc(pool, size);
 
-	if (old_size >= size)
+	/* get old size */
+	alloc = (PoolAlloc *) ((char *) mem - SIZEOF_POOLALLOC);
+	old_size = alloc->size.size;
+
+	if (size <= old_size)
 		return mem;
 
 	size = MEM_ALIGN(size);
@@ -275,6 +263,5 @@
 	memset(POOL_BLOCK_DATA(apool->block), 0,
 	       apool->block->size - apool->block->left);
 	apool->block->left = apool->block->size;
-
-	apool->last_alloc_size = 0;
+	apool->block->last_alloc_size = 0;
 }

Index: mempool-datastack.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib/mempool-datastack.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- mempool-datastack.c	22 Dec 2002 07:06:16 -0000	1.3
+++ mempool-datastack.c	27 Dec 2002 14:01:42 -0000	1.4
@@ -41,7 +41,6 @@
 static void *pool_data_stack_malloc(Pool pool, size_t size);
 static void pool_data_stack_free(Pool pool, void *mem);
 static void *pool_data_stack_realloc(Pool pool, void *mem, size_t size);
-static void *pool_data_stack_realloc_min(Pool pool, void *mem, size_t size);
 static void pool_data_stack_clear(Pool pool);
 
 static struct Pool static_data_stack_pool = {
@@ -52,7 +51,6 @@
 	pool_data_stack_free,
 
 	pool_data_stack_realloc,
-	pool_data_stack_realloc_min,
 
 	pool_data_stack_clear
 };
@@ -85,13 +83,8 @@
 {
 }
 
-static void *pool_data_stack_realloc(Pool pool, void *mem, size_t size)
-{
-	return pool_data_stack_realloc_min(pool, mem, size);
-}
-
-static void *pool_data_stack_realloc_min(Pool pool __attr_unused__,
-					 void *mem, size_t size)
+static void *pool_data_stack_realloc(Pool pool __attr_unused__,
+				     void *mem, size_t size)
 {
 	/* @UNSAFE */
 	PoolAlloc *alloc, *new_alloc;

Index: mempool-system.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib/mempool-system.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- mempool-system.c	22 Dec 2002 07:06:16 -0000	1.6
+++ mempool-system.c	27 Dec 2002 14:01:42 -0000	1.7
@@ -43,7 +43,6 @@
 static void *pool_system_malloc(Pool pool, size_t size);
 static void pool_system_free(Pool pool, void *mem);
 static void *pool_system_realloc(Pool pool, void *mem, size_t size);
-static void *pool_system_realloc_min(Pool pool, void *mem, size_t size);
 static void pool_system_clear(Pool pool);
 
 static struct Pool static_system_pool = {
@@ -54,7 +53,6 @@
 	pool_system_free,
 
 	pool_system_realloc,
-	pool_system_realloc_min,
 
 	pool_system_clear
 };
@@ -122,25 +120,6 @@
 	}
 
         return rmem;
-}
-
-static void *pool_system_realloc_min(Pool pool, void *mem, size_t size)
-{
-	PoolAlloc *alloc;
-        size_t old_size;
-
-	if (mem == NULL)
-		old_size = 0;
-	else {
-		/* get old size */
-                alloc = (PoolAlloc *) ((char *) mem - sizeof(PoolAlloc));
-		old_size = alloc->size.size;
-	}
-
-	if (old_size >= size)
-		return mem;
-	else
-                return pool_system_realloc(pool, mem, size);
 }
 
 static void pool_system_clear(Pool pool __attr_unused__)

Index: mempool.h
===================================================================
RCS file: /home/cvs/dovecot/src/lib/mempool.h,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- mempool.h	21 Dec 2002 13:08:49 -0000	1.6
+++ mempool.h	27 Dec 2002 14:01:42 -0000	1.7
@@ -20,8 +20,6 @@
 
 	/* reallocate the `mem' to be exactly `size' */
 	void *(*realloc)(Pool pool, void *mem, size_t size);
-	/* reallocate the `mem' to be at least `size' if it wasn't previously */
-	void *(*realloc_min)(Pool pool, void *mem, size_t size);
 
 	/* Frees all the memory in pool. NOTE: system_pool doesn't support
 	   this and crashes if it's used */
@@ -44,7 +42,6 @@
 
 #define p_malloc(pool, size) (pool)->malloc(pool, size)
 #define p_realloc(pool, mem, size) (pool)->realloc(pool, mem, size)
-#define p_realloc_min(pool, mem, size) (pool)->realloc_min(pool, mem, size)
 #define p_free(pool, mem) (pool)->free(pool, mem)
 
 #define p_clear(pool) (pool)->clear(pool)




More information about the dovecot-cvs mailing list