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:
vsc 2001-12-15 04:47:41 +00:00
parent 47b1ef2b63
commit c79f7e0f35

View File

@ -709,29 +709,35 @@ assertz_dynam_clause(PredEntry *p, CODEADDR cp)
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 */
ConsultCapacity += InitialConsultCapacity;
/* I assume it always works ;-) */
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");
return;
}
new_cs = new_cl + ConsultCapacity;
new_cb = ConsultBase + (new_cl - ConsultLow);
new_cb = new_cl + (ConsultSp-ConsultBase);
new_cs = new_cl + (InitialConsultCapacity+1);
/* start copying */
while (pp > ConsultSp)
*--new_cs = *--pp;
memcpy((void *)(new_cs), (void *)(ConsultSp), (ConsultCapacity-(InitialConsultCapacity+1))*sizeof(consult_obj));
/* copying done, release old space */
FreeCodeSpace((char *)ConsultLow);
/* next, set up pointers correctly */
diff = (char *)new_cb-(char *)ConsultBase;
ConsultSp = new_cs;
ConsultBase = new_cb;
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 */