changeset 1032:ea309e90c01a HEAD

Allow calling t_push() before data_stack_init().
author Timo Sirainen <tss@iki.fi>
date Mon, 27 Jan 2003 02:46:29 +0200
parents f17e2263f223
children e37e626902c3
files src/lib/data-stack.c
diffstat 1 files changed, 22 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib/data-stack.c	Mon Jan 27 00:50:40 2003 +0200
+++ b/src/lib/data-stack.c	Mon Jan 27 02:46:29 2003 +0200
@@ -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;
+		last_buffer_block = NULL;
+		last_buffer_size = 0;
+	}
 
 	t_push();
-
-        last_buffer_block = NULL;
-	last_buffer_size = 0;
 }
 
 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;