[dovecot-cvs] dovecot/src/lib data-stack.c,1.16,1.17

cras at procontrol.fi cras at procontrol.fi
Mon Jan 27 02:46:31 EET 2003


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

Modified Files:
	data-stack.c 
Log Message:
Allow calling t_push() before data_stack_init().



Index: data-stack.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib/data-stack.c,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -d -r1.16 -r1.17
--- data-stack.c	5 Jan 2003 13:09:51 -0000	1.16
+++ data-stack.c	27 Jan 2003 00:46:29 -0000	1.17
@@ -69,9 +69,9 @@
 	size_t last_alloc_size[BLOCK_FRAME_COUNT];
 };
 
-unsigned int data_stack_frame;
+unsigned int data_stack_frame = 0;
 
-static int frame_pos; /* current frame position current_frame_block */
+static int frame_pos = BLOCK_FRAME_COUNT-1; /* in current_frame_block */
 static struct stack_frame_block *current_frame_block;
 static struct stack_frame_block *unused_frame_blocks;
 
@@ -88,6 +88,13 @@
 	frame_pos++;
 	if (frame_pos == BLOCK_FRAME_COUNT) {
 		/* frame block full */
+		if (data_stack_frame == 0) {
+			/* kludgy, but allow this before initialization */
+			frame_pos = 0;
+			data_stack_init();
+			return t_push();
+		}
+
 		frame_pos = 0;
 		if (unused_frame_blocks == NULL) {
 			/* allocate new block */
@@ -329,20 +336,22 @@
 
 void data_stack_init(void)
 {
-        data_stack_frame = 0;
+	if (data_stack_frame == 0) {
+		data_stack_frame = 1;
 
-	current_block = mem_block_alloc(INITIAL_STACK_SIZE);
-	current_block->left = current_block->size;
-	current_block->next = NULL;
+		current_block = mem_block_alloc(INITIAL_STACK_SIZE);
+		current_block->left = current_block->size;
+		current_block->next = NULL;
 
-	current_frame_block = NULL;
-	unused_frame_blocks = NULL;
-	frame_pos = BLOCK_FRAME_COUNT-1;
+		current_frame_block = NULL;
+		unused_frame_blocks = NULL;
+		frame_pos = BLOCK_FRAME_COUNT-1;
 
-	t_push();
+		last_buffer_block = NULL;
+		last_buffer_size = 0;
+	}
 
-        last_buffer_block = NULL;
-	last_buffer_size = 0;
+	t_push();
 }
 
 void data_stack_deinit(void)
@@ -492,7 +501,7 @@
 
 void data_stack_init(void)
 {
-        data_stack_frame = 0;
+	data_stack_frame = 0;
 	current_frame = NULL;
 	buffer_mem = NULL;
 




More information about the dovecot-cvs mailing list