Fixed a bug where function prototypes were not being deallocated

correctly when they were overridden by the actual function.



git-svn-id: http://picoc.googlecode.com/svn/trunk@529 21eae674-98b7-11dd-bd71-f92a316d2d60
This commit is contained in:
zik.saleeba 2011-02-15 01:21:27 +00:00
parent e17f6f955f
commit de95adb36a
3 changed files with 37 additions and 11 deletions

View file

@ -160,7 +160,10 @@ struct Value *ParseFunctionDefinition(struct ParseState *Parser, struct ValueTyp
if (TableGet(&GlobalTable, Identifier, &OldFuncValue, NULL, NULL))
{
if (OldFuncValue->Val->FuncDef.Body.Pos == NULL)
TableDelete(&GlobalTable, Identifier); /* override an old function prototype */
{
/* override an old function prototype */
VariableFree(TableDelete(&GlobalTable, Identifier));
}
else
ProgramFail(Parser, "'%s' is already defined", Identifier);
}

View file

@ -106,8 +106,11 @@ struct Value *TableDelete(struct Table *Tbl, const char *Key)
{
if ((*EntryPtr)->p.v.Key == Key)
{
struct Value *Val = (*EntryPtr)->p.v.Val;
*EntryPtr = (*EntryPtr)->Next;
struct TableEntry *DeleteEntry = *EntryPtr;
struct Value *Val = DeleteEntry->p.v.Val;
*EntryPtr = DeleteEntry->Next;
HeapFreeMem(DeleteEntry);
return Val;
}
}

View file

@ -26,8 +26,11 @@ Recreations & Essays, W.W. Rouse Ball, MacMillan, NewYork, 11th Ed. 1967,
*
*/
#include<stdio.h>
#include<stdlib.h>
#include <stdio.h>
#include <stdlib.h>
#define TRUE 1
#define FALSE 0
#define N 4 /* This is the number of "disks" on tower A initially. */
/* Taken to be 64 in the legend. The number of moves
@ -67,16 +70,33 @@ PrintAll()
int Move(int *source, int *dest)
{
int i=0,j=0;
int i,j;
int done = FALSE;
while((*(source + i)==0)&&(i<N))i++;
while((*(dest + j)==0)&&(j<N))j++;
for (i=0; i<N && !done; )
{
if (source[i] != 0)
done = TRUE;
else
i++;
}
done = FALSE;
for (j=0; j<N && !done; )
{
if (dest[j] != 0)
done = TRUE;
else
j++;
}
//while (source[i]==0 && i<N) i++;
//while(dest[j]==0 && j<N) j++;
*(dest+j-1) = *(source+i);
*(source + i) = 0;
dest[j-1] = source[i];
source[i] = 0;
PrintAll(); /* Print configuration after each move. */
return *(dest+j-1);
return dest[j-1];
}