> It won't go in cleanly any more: How about the below patch?
Mike Lambert Index: stacks.c =================================================================== RCS file: /cvs/public/parrot/stacks.c,v retrieving revision 1.26 diff -u -r1.26 stacks.c --- stacks.c 29 Mar 2002 20:14:42 -0000 1.26 +++ stacks.c 30 Mar 2002 01:15:31 -0000 @@ -149,7 +149,21 @@ void *thing, Stack_entry_type type, Stack_cleanup_method cleanup) { Stack_chunk *chunk = stack_base->prev; - Stack_entry *entry = &chunk->entry[chunk->used]; + Stack_entry *entry; + + /* Do we need a new chunk? */ + if (chunk->used == STACK_CHUNK_DEPTH) { + /* Need to add a new chunk */ + Stack_chunk *new_chunk = mem_allocate_aligned(sizeof(Stack_chunk)); + new_chunk->used = 0; + new_chunk->next = stack_base; + new_chunk->prev = chunk; + chunk->next = new_chunk; + stack_base->prev = new_chunk; + chunk = new_chunk; + } + + entry = &chunk->entry[chunk->used]; /* Remember the type */ entry->entry_type = type; @@ -184,17 +198,8 @@ "Invalid stack_entry_type!\n"); break; } - - /* Register the new entry */ - if (++chunk->used == STACK_CHUNK_DEPTH) { - /* Need to add a new chunk */ - Stack_chunk *new_chunk = mem_allocate_aligned(sizeof(Stack_chunk)); - new_chunk->used = 0; - new_chunk->next = stack_base; - new_chunk->prev = chunk; - chunk->next = new_chunk; - stack_base->prev = new_chunk; - } + + chunk->used++; } /* Pop off an entry and return a pointer to the contents */ @@ -222,7 +227,10 @@ internal_exception(ERROR_STACK_EMPTY, "No entries on stack!\n"); } - entry = &chunk->entry[chunk->used - 1]; + /* Now decrement the SP */ + chunk->used--; + + entry = &chunk->entry[chunk->used]; /* Types of 0 mean we don't care */ if (type && entry->entry_type != type) { @@ -234,9 +242,6 @@ if (entry->flags & STACK_ENTRY_CLEANUP_FLAG) { (*entry->cleanup)(entry); } - - /* Now decrement the SP */ - chunk->used--; /* Sometimes the caller doesn't care what the value was */ if (where == NULL) {