fix some overflows recorded.

git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@1141 b08c6af1-5177-4d33-ba66-4b1c6b8b522a
This commit is contained in:
vsc 2004-09-17 20:47:35 +00:00
parent 0de365678a
commit bb2cb9e9f8
3 changed files with 106 additions and 23 deletions

View File

@ -10,8 +10,11 @@
* *
* File: absmi.c *
* comments: Portable abstract machine interpreter *
* Last rev: $Date: 2004-09-17 19:34:49 $,$Author: vsc $ *
* Last rev: $Date: 2004-09-17 20:47:35 $,$Author: vsc $ *
* $Log: not supported by cvs2svn $
* Revision 1.144 2004/09/17 19:34:49 vsc
* simplify frozen/2
*
* Revision 1.143 2004/08/16 21:02:04 vsc
* more fixes for !
*
@ -2454,7 +2457,7 @@ Yap_absmi(int inp)
/* This is easier: I know there is an environment so I cannot do allocate */
NoStackCommitY:
/* find something to fool S */
if (ActiveSignals & YAP_CDOVF_SIGNAL) {
if (!ActiveSignals || ActiveSignals & YAP_CDOVF_SIGNAL) {
goto do_commit_b_y;
}
if (ActiveSignals != YAP_CREEP_SIGNAL) {
@ -2469,7 +2472,7 @@ Yap_absmi(int inp)
/* Problem: have I got an environment or not? */
NoStackCommitX:
/* find something to fool S */
if (ActiveSignals & YAP_CDOVF_SIGNAL) {
if (!ActiveSignals || ActiveSignals & YAP_CDOVF_SIGNAL) {
goto do_commit_b_x;
}
if (ActiveSignals != YAP_CREEP_SIGNAL) {

View File

@ -3437,16 +3437,54 @@ p_recorded(void)
if (!Yap_unify(ARG2, cl->ClSource->Entry)) {
return FALSE;
}
} else if (!Yap_unify(ARG2,GetDBTerm(cl->ClSource))) {
return FALSE;
} else {
Term TermDB;
while ((TermDB = GetDBTerm(cl->ClSource)) == (CELL)0) {
/* oops, we are in trouble, not enough stack space */
if (Yap_Error_TYPE == OUT_OF_ATTVARS_ERROR) {
Yap_Error_TYPE = YAP_NO_ERROR;
if (!Yap_growglobal(NULL)) {
Yap_Error(OUT_OF_ATTVARS_ERROR, TermNil, Yap_ErrorMessage);
return FALSE;
}
} else {
Yap_Error_TYPE = YAP_NO_ERROR;
if (!Yap_gcl(Yap_Error_Size, 3, ENV, P)) {
Yap_Error(OUT_OF_STACK_ERROR, TermNil, Yap_ErrorMessage);
return(FALSE);
}
}
}
if (!Yap_unify(ARG2,TermDB)) {
return FALSE;
}
ap = cl->ClPred;
return Yap_unify(GetDBLUKey(ap), ARG1);
}
ap = cl->ClPred;
return Yap_unify(GetDBLUKey(ap), ARG1);
} else if (!Yap_unify(ARG2,GetDBTermFromDBEntry(ref))
|| !UnifyDBKey(ref,0,ARG1)) {
return FALSE;
} else {
return TRUE;
Term TermDB;
while ((TermDB = GetDBTermFromDBEntry(ref)) == (CELL)0) {
/* oops, we are in trouble, not enough stack space */
if (Yap_Error_TYPE == OUT_OF_ATTVARS_ERROR) {
Yap_Error_TYPE = YAP_NO_ERROR;
if (!Yap_growglobal(NULL)) {
Yap_Error(OUT_OF_ATTVARS_ERROR, TermNil, Yap_ErrorMessage);
return FALSE;
}
} else {
Yap_Error_TYPE = YAP_NO_ERROR;
if (!Yap_gcl(Yap_Error_Size, 3, ENV, P)) {
Yap_Error(OUT_OF_STACK_ERROR, TermNil, Yap_ErrorMessage);
return(FALSE);
}
}
}
if (!Yap_unify(ARG2,TermDB)
|| !UnifyDBKey(ref,0,ARG1)) {
return FALSE;
} else {
return TRUE;
}
}
}
if ((pe = find_lu_entry(twork)) != NULL) {

View File

@ -194,7 +194,6 @@ copy_complex_term(register CELL *pt0, register CELL *pt0_end, CELL *ptf, CELL *H
}
continue;
}
derefa_body(d0, ptd0, copy_term_unk, copy_term_nvar);
if (ptd0 >= HLow && ptd0 < H) {
@ -1325,7 +1324,7 @@ static int variant_complex(register CELL *pt0, register CELL *pt0_end, register
register CELL **to_visit = (CELL **)ASP;
/* make sure that unification always forces trailing */
HBREG = H;
loop:
while (pt0 < pt0_end) {
@ -1366,6 +1365,8 @@ static int variant_complex(register CELL *pt0, register CELL *pt0_end, register
/* now link the two structures so that no one else will */
/* come here */
to_visit -= 4;
if ((CELL *)to_visit < H+1024)
goto out_of_stack;
to_visit[0] = pt0;
to_visit[1] = pt0_end;
to_visit[2] = pt1;
@ -1375,6 +1376,8 @@ static int variant_complex(register CELL *pt0, register CELL *pt0_end, register
/* store the terms to visit */
if (pt0 < pt0_end) {
to_visit -= 3;
if ((CELL *)to_visit < H+1024)
goto out_of_stack;
to_visit[0] = pt0;
to_visit[1] = pt0_end;
to_visit[2] = pt1;
@ -1407,6 +1410,8 @@ static int variant_complex(register CELL *pt0, register CELL *pt0_end, register
/* now link the two structures so that no one else will */
/* come here */
to_visit -= 4;
if ((CELL *)to_visit < H+1024)
goto out_of_stack;
to_visit[0] = pt0;
to_visit[1] = pt0_end;
to_visit[2] = pt1;
@ -1416,6 +1421,8 @@ static int variant_complex(register CELL *pt0, register CELL *pt0_end, register
/* store the terms to visit */
if (pt0 < pt0_end) {
to_visit -= 3;
if ((CELL *)to_visit < H+1024)
goto out_of_stack;
to_visit[0] = pt0;
to_visit[1] = pt0_end;
to_visit[2] = pt1;
@ -1454,7 +1461,27 @@ static int variant_complex(register CELL *pt0, register CELL *pt0_end, register
RESET_VARIABLE(pt1);
}
HBREG = B->cp_h;
return(TRUE);
return TRUE;
out_of_stack:
H = HBREG;
/* untrail all bindings made by variant */
#ifdef RATIONAL_TREES
while (to_visit < (CELL **)ASP) {
pt0 = to_visit[0];
pt0_end = to_visit[1];
pt1 = to_visit[2];
*pt0 = (CELL)to_visit[3];
to_visit += 4;
}
#endif
while (TR != (tr_fr_ptr)OLDTR) {
CELL *pt1 = (CELL *) TrailTerm(--TR);
RESET_VARIABLE(pt1);
}
HBREG = B->cp_h;
return -1;
fail:
/* failure */
@ -1474,7 +1501,7 @@ static int variant_complex(register CELL *pt0, register CELL *pt0_end, register
RESET_VARIABLE(pt1);
}
HBREG = B->cp_h;
return(FALSE);
return FALSE;
}
static Int
@ -1482,6 +1509,7 @@ p_variant(void) /* variant terms t1 and t2 */
{
Term t1 = Deref(ARG1);
Term t2 = Deref(ARG2);
int out;
if (t1 == t2)
return (TRUE);
@ -1496,23 +1524,37 @@ p_variant(void) /* variant terms t1 and t2 */
}
if (IsPairTerm(t1)) {
if (IsPairTerm(t2)) {
return(variant_complex(RepPair(t1)-1,
RepPair(t1)+1,
RepPair(t2)-1));
out = variant_complex(RepPair(t1)-1,
RepPair(t1)+1,
RepPair(t2)-1);
if (out < 0) goto error;
}
else return (FALSE);
}
if (!IsApplTerm(t2)) return(FALSE);
{
if (!IsApplTerm(t2)) {
return FALSE;
} else {
Functor f1 = FunctorOfTerm(t1);
if (f1 != FunctorOfTerm(t2)) return(FALSE);
if (IsExtensionFunctor(f1)) {
return(unify_extension(f1, t1, RepAppl(t1), t2));
}
return(variant_complex(RepAppl(t1),
RepAppl(t1)+ArityOfFunctor(f1),
RepAppl(t2)));
out = variant_complex(RepAppl(t1),
RepAppl(t1)+ArityOfFunctor(f1),
RepAppl(t2));
if (out < 0) goto error;
return out;
}
error:
if (out == -1) {
if (!Yap_gc(2, ENV, P)) {
Yap_Error(OUT_OF_STACK_ERROR, TermNil, "in variant");
return FALSE;
}
return p_variant();
}
return FALSE;
}
static int subsumes_complex(register CELL *pt0, register CELL *pt0_end, register