This patch fixes a bug in the pop_generic_entry's switch statment, changing it from 
switching on type to (*top)->entry_type.  Otherwise when type=0 (i.e., don't care) the 
logic breaks.

The patch also includes a few styalistic changes that make it easier for the compiler 
to optimize (e.g., instead of 'a > b - 1' use 'a >= b').  If you would prefer not to 
receive patches that include these types of changes, just let me know.

David Jacobs

--- parrot-0.0.3/stacks.c Wed Nov  7 12:29:18 2001
+++ parrot/stacks.c Sun Dec  9 16:37:38 2001
@@ -16,12 +16,10 @@
 stack_depth(struct Parrot_Interp *interpreter, struct StackChunk *chunk) {
   INTVAL               depth;
 
-  depth = chunk->used;
-
-  while (chunk->next) {
-    chunk = chunk->next;
-    depth += chunk->used;
+  for (depth = chunk->used; chunk->next; chunk = chunk->next) {
+      depth += chunk->used;
   }
+
   return depth;
 }
 
@@ -31,7 +29,7 @@
       chunk = chunk->next;
     }
 
-    while (depth > chunk->used - 1) {
+    while (depth >= chunk->used) {
       depth -= chunk->used;
       chunk = chunk->prev; /* Expect caller to have checked bounds */
     }
@@ -144,7 +142,7 @@
     }
 
     /* Snag the value */
-    switch(type) {
+    switch((*top)->entry_type) {
     case STACK_ENTRY_INT:
         *(INTVAL *)where = (*top)->entry.int_val;
         break;
@@ -173,7 +171,7 @@
     chunk_base->used--;
     chunk_base->free++;
     /* Can we toss a whole chunk? */
-    if (0 == chunk_base->used && chunk_base->prev) {
+    if (!chunk_base->used && chunk_base->prev) {
         chunk_base = chunk_base->prev;
     } 
     if (chunk_base->used) {

Reply via email to