fix expand_consult
git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@232 b08c6af1-5177-4d33-ba66-4b1c6b8b522a
This commit is contained in:
parent
47b1ef2b63
commit
c79f7e0f35
22
C/cdmgr.c
22
C/cdmgr.c
@ -709,29 +709,35 @@ assertz_dynam_clause(PredEntry *p, CODEADDR cp)
|
|||||||
|
|
||||||
static void expand_consult(void)
|
static void expand_consult(void)
|
||||||
{
|
{
|
||||||
register consult_obj *new_cl, *new_cb, *new_cs, *pp;
|
consult_obj *new_cl, *new_cb, *new_cs, *old_top;
|
||||||
|
UInt old_sz = ConsultCapacity-1, i;
|
||||||
|
Int diff;
|
||||||
|
|
||||||
/* fetch the top of the old stacks */
|
|
||||||
pp = ConsultLow + ConsultCapacity;
|
old_top = ConsultBase+ConsultCapacity;
|
||||||
/* now increment consult capacity */
|
/* now increment consult capacity */
|
||||||
ConsultCapacity += InitialConsultCapacity;
|
ConsultCapacity += InitialConsultCapacity;
|
||||||
/* I assume it always works ;-) */
|
/* I assume it always works ;-) */
|
||||||
new_cl = (consult_obj *)AllocCodeSpace(sizeof(consult_obj)*ConsultCapacity);
|
new_cl = (consult_obj *)AllocCodeSpace(sizeof(consult_obj)*ConsultCapacity);
|
||||||
if (new_cl == NIL) {
|
if (new_cl == NULL) {
|
||||||
Error(SYSTEM_ERROR,TermNil,"Could not expand consult space: Heap crashed against Stacks");
|
Error(SYSTEM_ERROR,TermNil,"Could not expand consult space: Heap crashed against Stacks");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
new_cs = new_cl + ConsultCapacity;
|
new_cb = new_cl + (ConsultSp-ConsultBase);
|
||||||
new_cb = ConsultBase + (new_cl - ConsultLow);
|
new_cs = new_cl + (InitialConsultCapacity+1);
|
||||||
/* start copying */
|
/* start copying */
|
||||||
while (pp > ConsultSp)
|
memcpy((void *)(new_cs), (void *)(ConsultSp), (ConsultCapacity-(InitialConsultCapacity+1))*sizeof(consult_obj));
|
||||||
*--new_cs = *--pp;
|
|
||||||
/* copying done, release old space */
|
/* copying done, release old space */
|
||||||
FreeCodeSpace((char *)ConsultLow);
|
FreeCodeSpace((char *)ConsultLow);
|
||||||
/* next, set up pointers correctly */
|
/* next, set up pointers correctly */
|
||||||
|
diff = (char *)new_cb-(char *)ConsultBase;
|
||||||
ConsultSp = new_cs;
|
ConsultSp = new_cs;
|
||||||
ConsultBase = new_cb;
|
ConsultBase = new_cb;
|
||||||
ConsultLow = new_cl;
|
ConsultLow = new_cl;
|
||||||
|
/* adjust consultbase pointers */
|
||||||
|
for (i = 0; i < old_sz; i++) {
|
||||||
|
new_cs->c = (consult_obj *)((void *)(new_cs->c)+diff);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* p was already locked */
|
/* p was already locked */
|
||||||
|
Reference in New Issue
Block a user