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:
parent
201019ce2d
commit
8d315824b5
2
heap.c
2
heap.c
|
@ -135,7 +135,7 @@ void *HeapAlloc(int Size)
|
||||||
#ifdef DEBUG_HEAP
|
#ifdef DEBUG_HEAP
|
||||||
printf("allocating %d(%d) from freelist, split chunk (%d)", Size, AllocSize, (*FreeNode)->Size);
|
printf("allocating %d(%d) from freelist, split chunk (%d)", Size, AllocSize, (*FreeNode)->Size);
|
||||||
#endif
|
#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);
|
assert((unsigned long)NewMem >= (unsigned long)&HeapMemory[0] && (unsigned char *)NewMem - &HeapMemory[0] < HEAP_SIZE);
|
||||||
(*FreeNode)->Size -= AllocSize;
|
(*FreeNode)->Size -= AllocSize;
|
||||||
NewMem->Size = AllocSize;
|
NewMem->Size = AllocSize;
|
||||||
|
|
3
table.c
3
table.c
|
@ -114,9 +114,6 @@ char *TableSetIdentifier(struct Table *Tbl, const char *Ident, int IdentLen)
|
||||||
else
|
else
|
||||||
{ /* add it to the table - we economise by not allocating the whole structure here */
|
{ /* add it to the table - we economise by not allocating the whole structure here */
|
||||||
struct TableEntry *NewEntry = HeapAlloc(sizeof(struct TableEntry *) + IdentLen + 1);
|
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)
|
if (NewEntry == NULL)
|
||||||
ProgramFail(NULL, "out of memory");
|
ProgramFail(NULL, "out of memory");
|
||||||
|
|
||||||
|
|
|
@ -149,8 +149,8 @@ void VariableStackPop(struct ParseState *Parser, struct Value *Var)
|
||||||
int Success;
|
int Success;
|
||||||
|
|
||||||
#ifdef DEBUG_HEAP
|
#ifdef DEBUG_HEAP
|
||||||
if (Var->ValOnStack)
|
// if (Var->ValOnStack)
|
||||||
printf("popping %d at 0x%lx\n", sizeof(struct Value) + VariableSizeValue(Var), (unsigned long)Var);
|
// printf("popping %d at 0x%lx\n", sizeof(struct Value) + VariableSizeValue(Var), (unsigned long)Var);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (Var->ValOnHeap)
|
if (Var->ValOnHeap)
|
||||||
|
|
Loading…
Reference in a new issue