[dovecot-cvs] dovecot/src/lib data-stack.c,1.19,1.20 mempool-alloconly.c,1.25,1.26 mempool-system.c,1.14,1.15

cras at procontrol.fi cras at procontrol.fi
Sun Sep 21 21:55:38 EEST 2003


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

Modified Files:
	data-stack.c mempool-alloconly.c mempool-system.c 
Log Message:
Added support for Boehm GC. However it seems to be crashing for some reason
with me..



Index: data-stack.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib/data-stack.c,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -d -r1.19 -r1.20
--- data-stack.c	26 Aug 2003 21:18:16 -0000	1.19
+++ data-stack.c	21 Sep 2003 17:55:36 -0000	1.20
@@ -7,6 +7,12 @@
 
 #include <stdlib.h>
 
+#ifdef HAVE_GC_GC_H
+#  include <gc/gc.h>
+#elif defined (HAVE_GC_H)
+#  include <gc.h>
+#endif
+
 /* Use malloc() and free() for all memory allocations. Useful for debugging
    memory corruption. */
 /* #define DISABLE_DATA_STACK */
@@ -21,6 +27,12 @@
 #  define INITIAL_STACK_SIZE (1024*32)
 #endif
 
+#ifdef DEBUG
+#  define CLEAR_CHR 0xde
+#elif defined(USE_GC)
+#  define CLEAR_CHR 0
+#endif
+
 struct stack_block {
 	struct stack_block *next;
 
@@ -75,7 +87,12 @@
 		frame_pos = 0;
 		if (unused_frame_blocks == NULL) {
 			/* allocate new block */
+#ifndef USE_GC
 			frame_block = calloc(sizeof(*frame_block), 1);
+#else
+			frame_block = GC_malloc(sizeof(*frame_block));
+                        memset(frame_block, 0, sizeof(*frame_block));
+#endif
 			if (frame_block == NULL)
 				i_panic("t_push(): Out of memory");
 		} else {
@@ -96,6 +113,7 @@
         return data_stack_frame++;
 }
 
+#ifndef USE_GC
 static void free_blocks(struct stack_block *block)
 {
 	struct stack_block *next;
@@ -115,6 +133,7 @@
 		block = next;
 	}
 }
+#endif
 
 unsigned int t_pop(void)
 {
@@ -127,14 +146,16 @@
 	/* update the current block */
 	current_block = current_frame_block->block[frame_pos];
 	current_block->left = current_frame_block->block_space_used[frame_pos];
-#ifdef DEBUG
+#ifdef CLEAR_CHR
 	memset(STACK_BLOCK_DATA(current_block) +
-	       (current_block->size - current_block->left), 0xde,
+	       (current_block->size - current_block->left), CLEAR_CHR,
 	       current_block->left);
 #endif
 	if (current_block->next != NULL) {
 		/* free unused blocks */
+#ifndef USE_GC
 		free_blocks(current_block->next);
+#endif
 		current_block->next = NULL;
 	}
 
@@ -163,7 +184,11 @@
 	prev_size = current_block == NULL ? 0 : current_block->size;
 	alloc_size = nearest_power(prev_size + min_size);
 
+#ifndef USE_GC
 	block = malloc(SIZEOF_MEMBLOCK + alloc_size);
+#else
+	block = GC_malloc_atomic(SIZEOF_MEMBLOCK + alloc_size);
+#endif
 	if (block == NULL) {
 		i_panic("mem_block_alloc(): "
 			"Out of memory when allocating %"PRIuSIZE_T" bytes",
@@ -342,18 +367,27 @@
 	if (frame_pos != BLOCK_FRAME_COUNT-1)
 		i_panic("Missing t_pop() call");
 
+#ifndef USE_GC
 	while (unused_frame_blocks != NULL) {
                 struct stack_frame_block *frame_block = unused_frame_blocks;
 		unused_frame_blocks = unused_frame_blocks->prev;
 
-                free(frame_block);
+		free(frame_block);
 	}
 
 	free(current_block);
 	free(unused_block);
+#endif
+	unused_frame_blocks = NULL;
+	current_block = NULL;
+	unused_block = NULL;
 }
 
 #else
+
+#ifdef USE_GC
+#  error No GC with disabled data stack
+#endif
 
 struct stack_frame {
 	struct stack_frame *next;

Index: mempool-alloconly.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib/mempool-alloconly.c,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -d -r1.25 -r1.26
--- mempool-alloconly.c	21 Sep 2003 16:21:37 -0000	1.25
+++ mempool-alloconly.c	21 Sep 2003 17:55:36 -0000	1.26
@@ -7,6 +7,12 @@
 
 #include <stdlib.h>
 
+#ifdef HAVE_GC_GC_H
+#  include <gc/gc.h>
+#elif defined (HAVE_GC_H)
+#  include <gc.h>
+#endif
+
 #define MAX_ALLOC_SIZE SSIZE_T_MAX
 
 struct alloconly_pool {
@@ -64,16 +70,21 @@
 pool_t pool_alloconly_create(const char *name, size_t size)
 {
 	struct alloconly_pool *apool;
-	int len;
+	size_t len;
 
-	len = strlen(name);
+	len = strlen(name)+1;
 
-	apool = calloc(SIZEOF_ALLOCONLYPOOL + len+1, 1);
+#ifndef USE_GC
+	apool = calloc(SIZEOF_ALLOCONLYPOOL + len, 1);
+#else
+	apool = GC_malloc(SIZEOF_ALLOCONLYPOOL + len);
+	memset(apool, 0, SIZEOF_ALLOCONLYPOOL + len);
+#endif
 	if (apool == NULL)
 		i_panic("pool_alloconly_create(): Out of memory");
 	apool->pool = static_alloconly_pool;
 	apool->refcount = 1;
-	memcpy(apool->name, name, len+1);
+	memcpy(apool->name, name, len);
 
 	block_alloc(apool, size);
 	return (struct pool *) apool;
@@ -88,8 +99,14 @@
 #ifdef DEBUG
 	memset(apool->block, 0xde, SIZEOF_POOLBLOCK + apool->block->size);
 #endif
+
+#ifndef USE_GC
 	free(apool->block);
 	free(apool);
+#else
+	apool->block = NULL;
+	apool = NULL;
+#endif
 }
 
 static const char *pool_alloconly_get_name(pool_t pool)
@@ -131,7 +148,12 @@
 	}
 #endif
 
+#ifndef USE_GC
 	block = calloc(size, 1);
+#else
+	block = GC_malloc(size);
+	memset(block, 0, size);
+#endif
 	if (block == NULL)
 		i_panic("block_alloc(): Out of memory");
 	block->prev = apool->block;
@@ -230,7 +252,9 @@
 #ifdef DEBUG
 		memset(block, 0xde, SIZEOF_POOLBLOCK + block->size);
 #endif
+#ifndef USE_GC
 		free(block);
+#endif
 	}
 
 	/* clear the block */

Index: mempool-system.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib/mempool-system.c,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -d -r1.14 -r1.15
--- mempool-system.c	21 Sep 2003 16:21:37 -0000	1.14
+++ mempool-system.c	21 Sep 2003 17:55:36 -0000	1.15
@@ -7,6 +7,12 @@
 
 #include <stdlib.h>
 
+#ifdef HAVE_GC_GC_H
+#  include <gc/gc.h>
+#elif defined (HAVE_GC_H)
+#  include <gc.h>
+#endif
+
 static const char *pool_system_get_name(pool_t pool);
 static void pool_system_ref(pool_t pool);
 static void pool_system_unref(pool_t pool);
@@ -55,17 +61,25 @@
 	if (size == 0 || size > SSIZE_T_MAX)
 		i_panic("Trying to allocate %"PRIuSIZE_T" bytes", size);
 
+#ifndef USE_GC
 	mem = calloc(size, 1);
+#else
+	mem = GC_malloc(size);
+	memset(mem, 0, size);
+#endif
 	if (mem == NULL)
 		i_panic("pool_system_malloc(): Out of memory");
 
 	return mem;
 }
 
-static void pool_system_free(pool_t pool __attr_unused__, void *mem)
+static void pool_system_free(pool_t pool __attr_unused__,
+			     void *mem __attr_unused__)
 {
+#ifndef USE_GC
 	if (mem != NULL)
 		free(mem);
+#endif
 }
 
 static void *pool_system_realloc(pool_t pool __attr_unused__, void *mem,
@@ -74,7 +88,11 @@
 	if (new_size == 0 || new_size > SSIZE_T_MAX)
 		i_panic("Trying to allocate %"PRIuSIZE_T" bytes", new_size);
 
+#ifndef USE_GC
 	mem = realloc(mem, new_size);
+#else
+	mem = GC_realloc(mem, new_size);
+#endif
 	if (mem == NULL)
 		i_panic("pool_system_realloc(): Out of memory");
 



More information about the dovecot-cvs mailing list