From 22c5632a53a4fc8c1283a8c979e7a4dad354fe44 Mon Sep 17 00:00:00 2001 From: vsc Date: Sun, 28 Oct 2007 11:23:41 +0000 Subject: [PATCH] fix overflow git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@1969 b08c6af1-5177-4d33-ba66-4b1c6b8b522a --- C/absmi.c | 15 ++++- C/corout.c | 70 ++++++++++++++------ C/index.c | 10 ++- CLPBN/clpbn/examples/School/evidence_128.yap | 1 - changes-5.1.html | 4 ++ 5 files changed, 75 insertions(+), 25 deletions(-) diff --git a/C/absmi.c b/C/absmi.c index 48b83db55..499801bf2 100644 --- a/C/absmi.c +++ b/C/absmi.c @@ -10,8 +10,13 @@ * * * File: absmi.c * * comments: Portable abstract machine interpreter * -* Last rev: $Date: 2007-10-28 00:54:09 $,$Author: vsc $ * +* Last rev: $Date: 2007-10-28 11:23:39 $,$Author: vsc $ * * $Log: not supported by cvs2svn $ +* Revision 1.226 2007/10/28 00:54:09 vsc +* new version of viterbi implementation +* fix all:atvars reporting bad info +* fix bad S info in x86_64 +* * Revision 1.225 2007/10/17 09:18:26 vsc * growtrail assumed SREG meant ASP? * @@ -2655,8 +2660,14 @@ Yap_absmi(int inp) BOp(call, sla); #ifdef LOW_LEVEL_TRACER - if (Yap_do_low_level_trace) + if (Yap_do_low_level_trace) { + extern long long int vsc_count; + + if (vsc_count == 165491LL) { + fprintf(stderr,"%p:%p\n",PREG,PREG->u.sla.sla_u.p); + } low_level_trace(enter_pred,PREG->u.sla.sla_u.p,XREGS+1); + } #endif /* LOW_LEVEL_TRACER */ CACHE_Y_AS_ENV(YREG); { diff --git a/C/corout.c b/C/corout.c index 75c4ada3b..33ab4e1a3 100644 --- a/C/corout.c +++ b/C/corout.c @@ -374,6 +374,9 @@ static int non_ground_complex(register CELL *pt0, goto var_found; } if (IsPairTerm(d0)) { + if (to_visit + 1024 >= (CELL **)AuxSp) { + goto aux_overflow; + } #ifdef RATIONAL_TREES to_visit[0] = pt0; to_visit[1] = pt0_end; @@ -402,6 +405,9 @@ static int non_ground_complex(register CELL *pt0, if (IsExtensionFunctor(f)) { continue; } + if (to_visit + 1024 >= (CELL **)AuxSp) { + goto aux_overflow; + } #ifdef RATIONAL_TREES to_visit[0] = pt0; to_visit[1] = pt0_end; @@ -440,7 +446,7 @@ static int non_ground_complex(register CELL *pt0, /* the term is ground */ Yap_ReleasePreAllocCodeSpace((ADDR)to_visit); - return(FALSE); + return FALSE; var_found: /* the term is non-ground */ @@ -454,31 +460,57 @@ static int non_ground_complex(register CELL *pt0, } #endif /* the system will take care of TR for me, no need to worry here! */ - return(TRUE); + return TRUE; + + aux_overflow: + /* unwind stack */ + Yap_ReleasePreAllocCodeSpace((ADDR)to_visit); +#ifdef RATIONAL_TREES + while (to_visit > (CELL **)to_visit_base) { + to_visit -= 3; + pt0 = to_visit[0]; + *pt0 = (CELL)to_visit[2]; + } +#endif + return -1; } static int non_ground(Term t, Term *Var) { - t = Deref(t); - if (IsVarTerm(t)) { - /* we found a variable */ - *Var = t; - return(TRUE); - } - if (IsPrimitiveTerm(t)) { - return(FALSE); - } else if (IsPairTerm(t)) { - return(non_ground_complex(RepPair(t)-1, RepPair(t)+1, Var)); - } else { - Functor f = FunctorOfTerm(t); - if (IsExtensionFunctor(f)) { - return(FALSE); + int out = -1; + while (out < 0) { + t = Deref(t); + if (IsVarTerm(t)) { + /* we found a variable */ + *Var = t; + return TRUE; } - return(non_ground_complex(RepAppl(t), - RepAppl(t)+ArityOfFunctor(FunctorOfTerm(t)), - Var)); + if (IsPrimitiveTerm(t)) { + return FALSE; + } else if (IsPairTerm(t)) { + out = non_ground_complex(RepPair(t)-1, RepPair(t)+1, Var); + if (out >= 0) + return out; + } else { + Functor f = FunctorOfTerm(t); + if (IsExtensionFunctor(f)) { + return FALSE; + } + out = non_ground_complex(RepAppl(t), + RepAppl(t)+ArityOfFunctor(FunctorOfTerm(t)), + Var); + if (out >= 0) + return out; + } + extern int Yap_do_low_level_trace; + Yap_do_low_level_trace=1; + if (!Yap_ExpandPreAllocCodeSpace(0, NULL)) { + Yap_Error(OUT_OF_AUXSPACE_ERROR, ARG1, "overflow in ground"); + return FALSE; + } } + return FALSE; } #endif diff --git a/C/index.c b/C/index.c index e01363ef8..ff8be69f1 100644 --- a/C/index.c +++ b/C/index.c @@ -11,8 +11,11 @@ * File: index.c * * comments: Indexing a Prolog predicate * * * -* Last rev: $Date: 2007-09-22 08:38:05 $,$Author: vsc $ * +* Last rev: $Date: 2007-10-28 11:23:40 $,$Author: vsc $ * * $Log: not supported by cvs2svn $ +* Revision 1.187 2007/09/22 08:38:05 vsc +* nb_ extra stuff plus an indexing overflow fix. +* * Revision 1.186 2007/06/20 13:48:45 vsc * fix bug in index emulator * @@ -6494,8 +6497,9 @@ static_clause(yamop *ipc, PredEntry *ap) ipc = PREVOP(ipc, ld); p = (CELL *)ipc; while ((c = ClauseCodeToStaticClause(p))) { - UInt fls = c->ClFlags & ~HasBlobsMask; - if ((fls & StaticMask) == StaticMask) { + UInt fls = c->ClFlags; + if ((fls & StaticMask) == StaticMask && + !(fls & (MegaMask|SwitchRootMask|SwitchTableMask|DynamicMask|IndexMask|DBClMask|LogUpdMask|LogUpdRuleMask|DirtyMask))) { if (ap->PredFlags & SourcePredFlag) { if ((char *)c->usc.ClSource < (char *)c+c->ClSize && valid_instructions(ipc, c->ClCode)) diff --git a/CLPBN/clpbn/examples/School/evidence_128.yap b/CLPBN/clpbn/examples/School/evidence_128.yap index 888319780..d3d72799f 100644 --- a/CLPBN/clpbn/examples/School/evidence_128.yap +++ b/CLPBN/clpbn/examples/School/evidence_128.yap @@ -7,7 +7,6 @@ professor_popularity(p5,l) :- {}. professor_popularity(p45,h) :- {}. professor_popularity(p15,m) :- {}. -:- start_low_level_trace. course_rating(c0, h) :- {}. course_rating(c1, m) :- {}. course_rating(c2, l) :- {}. diff --git a/changes-5.1.html b/changes-5.1.html index fec07757b..460de87d3 100644 --- a/changes-5.1.html +++ b/changes-5.1.html @@ -17,6 +17,10 @@

Yap-5.1.3: