--- stack/stack.c 2002/03/17 11:26:35 1.115 +++ stack/stack.c 2002/03/17 12:49:27 1.116 @@ -1,3 +1,4 @@ +/* -*- coding: utf-8; -*- */ /* stack - an interactive interpreter for a stack-based language Copyright (C) 2002 Mats Alritzson and Teddy Hogeborn @@ -165,7 +166,6 @@ extern void gc_init(environment *env) { stackitem *new_head= NULL, *titem; - pair *iterator; symbol *tsymb; int i; @@ -195,8 +195,21 @@ if(!(env->gc_ref->item->gc.no_gc)){ /* neither mark nor protect */ - if(env->gc_ref->item->type==string) /* Remove content */ + /* Remove content */ + switch(env->gc_ref->item->type){ + case string: free(env->gc_ref->item->content.ptr); + break; + case tcons: + free(env->gc_ref->item->content.c); + break; + case empty: + case integer: + case tfloat: + case func: + case symb: + /* Symbol strings are freed when walking the hash table */ + } free(env->gc_ref->item); /* Remove from gc_ref */ titem= env->gc_ref->next; @@ -287,6 +300,7 @@ new_value->content.c= malloc(sizeof(pair)); assert(new_value->content.c!=NULL); + env->gc_count += sizeof(pair); new_value->type= tcons; CAR(new_value)= val; CDR(new_value)= env->head; @@ -720,7 +734,10 @@ unprotect(temp_val); return; - default: + case empty: + case integer: + case tfloat: + case string: return; } } @@ -1049,7 +1066,7 @@ } if(myenv.interactive) { - printf("Stack version $Revision: 1.115 $\n\ + printf("Stack version $Revision: 1.116 $\n\ Copyright (C) 2002 Mats Alritzson and Teddy Hogeborn\n\ Stack comes with ABSOLUTELY NO WARRANTY; for details type 'warranty;'.\n\ This is free software, and you are welcome to redistribute it\n\ @@ -1324,6 +1341,7 @@ case integer: case func: case symb: + case empty: new_value->content= old_value->content; break; case string: @@ -1334,6 +1352,7 @@ new_value->content.c= malloc(sizeof(pair)); assert(new_value->content.c!=NULL); + env->gc_count += sizeof(pair); CAR(new_value)= copy_val(env, CAR(old_value)); /* recurse */ CDR(new_value)= copy_val(env, CDR(old_value)); /* recurse */ @@ -1691,7 +1710,7 @@ int count= -1; float ftemp; static int depth= 0; - char *match, *ctemp; + char *match; size_t inlength; if(env->in_string==NULL) { @@ -2367,6 +2386,8 @@ val=new_val(env); val->content.c= malloc(sizeof(pair)); assert(val->content.c!=NULL); + + env->gc_count += sizeof(pair); val->type=tcons; CAR(val)= CAR(CDR(env->head));