Fixed a problem with heap allocation when splitting large blocks from the free list

git-svn-id: http://picoc.googlecode.com/svn/trunk@190 21eae674-98b7-11dd-bd71-f92a316d2d60
This commit is contained in:
zik.saleeba 2009-03-10 23:32:36 +00:00
parent 201019ce2d
commit 8d315824b5
3 changed files with 3 additions and 6 deletions

2
heap.c
View file

@ -135,7 +135,7 @@ void *HeapAlloc(int Size)
#ifdef DEBUG_HEAP
printf("allocating %d(%d) from freelist, split chunk (%d)", Size, AllocSize, (*FreeNode)->Size);
#endif
NewMem = *FreeNode + (*FreeNode)->Size - AllocSize;
NewMem = (void *)*FreeNode + (*FreeNode)->Size - AllocSize;
assert((unsigned long)NewMem >= (unsigned long)&HeapMemory[0] && (unsigned char *)NewMem - &HeapMemory[0] < HEAP_SIZE);
(*FreeNode)->Size -= AllocSize;
NewMem->Size = AllocSize;

View file

@ -114,9 +114,6 @@ char *TableSetIdentifier(struct Table *Tbl, const char *Ident, int IdentLen)
else
{ /* add it to the table - we economise by not allocating the whole structure here */
struct TableEntry *NewEntry = HeapAlloc(sizeof(struct TableEntry *) + IdentLen + 1);
//printf("allocated 0x%lx:%d for '", (unsigned long)NewEntry, sizeof(struct TableEntry *) + IdentLen + 1);
//fwrite(Ident, 1, IdentLen, stdout);
//printf("'\n");
if (NewEntry == NULL)
ProgramFail(NULL, "out of memory");

View file

@ -149,8 +149,8 @@ void VariableStackPop(struct ParseState *Parser, struct Value *Var)
int Success;
#ifdef DEBUG_HEAP
if (Var->ValOnStack)
printf("popping %d at 0x%lx\n", sizeof(struct Value) + VariableSizeValue(Var), (unsigned long)Var);
// if (Var->ValOnStack)
// printf("popping %d at 0x%lx\n", sizeof(struct Value) + VariableSizeValue(Var), (unsigned long)Var);
#endif
if (Var->ValOnHeap)