fix bad handling of trail overflow.

This commit is contained in:
Vitor Santos Costa 2009-05-04 21:26:47 -05:00
parent 10c38f8164
commit 780b629bff

View File

@ -360,7 +360,7 @@ trail_overflow:
{ {
tr_fr_ptr oTR = TR; tr_fr_ptr oTR = TR;
reset_trail(TR0); reset_trail(TR0);
if (!Yap_growtrail((oTR-TR0)*sizeof(tr_fr_ptr *), FALSE)) { if (!Yap_growtrail((oTR-TR0)*sizeof(tr_fr_ptr *), TRUE)) {
return -4; return -4;
} }
return -2; return -2;
@ -388,7 +388,7 @@ trail_overflow:
static Term static Term
handle_cp_overflow(int res, UInt arity, Term t) handle_cp_overflow(int res, tr_fr_ptr TR0, UInt arity, Term t)
{ {
XREGS[arity+1] = t; XREGS[arity+1] = t;
switch(res) { switch(res) {
@ -412,6 +412,12 @@ handle_cp_overflow(int res, UInt arity, Term t)
} }
} }
return Deref(XREGS[arity+1]); return Deref(XREGS[arity+1]);
case -4:
if (!Yap_growtrail((TR-TR0)*sizeof(tr_fr_ptr *), FALSE)) {
Yap_Error(OUT_OF_TRAIL_ERROR, TermNil, Yap_ErrorMessage);
return 0L;
}
return Deref(XREGS[arity+1]);
default: default:
return 0L; return 0L;
} }
@ -420,6 +426,7 @@ handle_cp_overflow(int res, UInt arity, Term t)
static Term static Term
CopyTerm(Term inp, UInt arity, int share, int newattvs) { CopyTerm(Term inp, UInt arity, int share, int newattvs) {
Term t = Deref(inp); Term t = Deref(inp);
tr_fr_ptr TR0 = TR;
if (IsVarTerm(t)) { if (IsVarTerm(t)) {
#if COROUTINING #if COROUTINING
@ -433,7 +440,7 @@ CopyTerm(Term inp, UInt arity, int share, int newattvs) {
H += 2; H += 2;
if ((res = copy_complex_term(Hi-2, Hi-1, share, newattvs, Hi, Hi)) < 0) { if ((res = copy_complex_term(Hi-2, Hi-1, share, newattvs, Hi, Hi)) < 0) {
H = Hi-1; H = Hi-1;
if ((t = handle_cp_overflow(res,arity,t))== 0L) if ((t = handle_cp_overflow(res, TR0, arity, t))== 0L)
return FALSE; return FALSE;
goto restart_attached; goto restart_attached;
} }
@ -457,7 +464,7 @@ CopyTerm(Term inp, UInt arity, int share, int newattvs) {
int res; int res;
if ((res = copy_complex_term(ap-1, ap+1, share, newattvs, Hi, Hi)) < 0) { if ((res = copy_complex_term(ap-1, ap+1, share, newattvs, Hi, Hi)) < 0) {
H = Hi; H = Hi;
if ((t = handle_cp_overflow(res,arity,t))== 0L) if ((t = handle_cp_overflow(res, TR0, arity, t))== 0L)
return FALSE; return FALSE;
goto restart_list; goto restart_list;
} else if (res && share && FunctorOfTerm(t) != FunctorMutable) { } else if (res && share && FunctorOfTerm(t) != FunctorMutable) {
@ -481,7 +488,7 @@ CopyTerm(Term inp, UInt arity, int share, int newattvs) {
H += 1+ArityOfFunctor(f); H += 1+ArityOfFunctor(f);
if (H > ASP-128) { if (H > ASP-128) {
H = HB0; H = HB0;
if ((t = handle_cp_overflow(-1,arity,t))== 0L) if ((t = handle_cp_overflow(-1, TR0, arity, t))== 0L)
return FALSE; return FALSE;
goto restart_appl; goto restart_appl;
} else { } else {
@ -489,7 +496,7 @@ CopyTerm(Term inp, UInt arity, int share, int newattvs) {
if ((res = copy_complex_term(ap, ap+ArityOfFunctor(f), share, newattvs, HB0+1, HB0)) < 0) { if ((res = copy_complex_term(ap, ap+ArityOfFunctor(f), share, newattvs, HB0+1, HB0)) < 0) {
H = HB0; H = HB0;
if ((t = handle_cp_overflow(res,arity,t))== 0L) if ((t = handle_cp_overflow(res, TR0, arity, t))== 0L)
return FALSE; return FALSE;
goto restart_appl; goto restart_appl;
} else if (res && share) { } else if (res && share) {