From 028c98d6655164bc6d00b5e666a7d4b91cd02dce Mon Sep 17 00:00:00 2001 From: "zik.saleeba" Date: Wed, 11 Mar 2009 10:01:32 +0000 Subject: [PATCH] Now cleaning up more stuff git-svn-id: http://picoc.googlecode.com/svn/trunk@194 21eae674-98b7-11dd-bd71-f92a316d2d60 --- picoc.c | 1 + picoc.h | 1 + variable.c | 22 ++++++++++++++++++++++ 3 files changed, 24 insertions(+) diff --git a/picoc.c b/picoc.c index 18d9cd7..f87d548 100644 --- a/picoc.c +++ b/picoc.c @@ -16,6 +16,7 @@ void Initialise() /* free memory */ void Cleanup() { + VariableCleanup(); TableStrFree(); } diff --git a/picoc.h b/picoc.h index dd9855f..0109e8b 100644 --- a/picoc.h +++ b/picoc.h @@ -295,6 +295,7 @@ void HeapFree(void *Mem); /* variable.c */ void VariableInit(); +void VariableCleanup(); void *VariableAlloc(struct ParseState *Parser, int Size, int OnHeap); void VariableStackPop(struct ParseState *Parser, struct Value *Var); struct Value *VariableAllocValueAndData(struct ParseState *Parser, int DataSize, int IsLValue, struct Value *LValueFrom, int OnHeap); diff --git a/variable.c b/variable.c index c5f0947..102e6a5 100644 --- a/variable.c +++ b/variable.c @@ -15,6 +15,28 @@ void VariableInit() TopStackFrame = NULL; } +/* deallocate the global table */ +void VariableCleanup() +{ + struct TableEntry *Entry; + struct TableEntry *NextEntry; + struct Value *Val; + int Count; + + for (Count = 0; Count < GlobalTable.Size; Count++) + { + for (Entry = GlobalTable.HashTable[Count]; Entry != NULL; Entry = NextEntry) + { + NextEntry = Entry->Next; + Val = Entry->p.v.Val; + if (Val->ValOnHeap) + HeapFree(Val); + + HeapFree(Entry); + } + } +} + /* allocate some memory, either on the heap or the stack and check if we've run out */ void *VariableAlloc(struct ParseState *Parser, int Size, int OnHeap) {