diff --git a/C/attvar.c b/C/attvar.c index 9340ce4a5..d9bc03c85 100644 --- a/C/attvar.c +++ b/C/attvar.c @@ -438,12 +438,12 @@ GetAllAtts(attvar_record *attv) { static Term AllAttVars(Term t) { if (t == TermNil) { - return(t); + return t; } else { attvar_record *attv = (attvar_record *)VarOfTerm(t); if (!IsVarTerm(attv->Done) || !IsUnboundVar(&attv->Done)) - return(AllAttVars(attv->NS)); - else return(MkPairTerm(t,AllAttVars(attv->NS))); + return AllAttVars(attv->NS); + else return MkPairTerm(t,AllAttVars(attv->NS)); } } @@ -623,12 +623,12 @@ p_get_all_atts(void) { Yap_Error(TYPE_ERROR_VARIABLE,inp,"get_att/2"); return(FALSE); } - return(Yap_unify(ARG2,GetAllAtts(attv))); + return Yap_unify(ARG2,GetAllAtts(attv)); } - return(TRUE); + return TRUE; } else { Yap_Error(TYPE_ERROR_VARIABLE,inp,"get_att/2"); - return(FALSE); + return FALSE; } } diff --git a/C/cdmgr.c b/C/cdmgr.c index 3342184f5..17c391b08 100644 --- a/C/cdmgr.c +++ b/C/cdmgr.c @@ -11,8 +11,11 @@ * File: cdmgr.c * * comments: Code manager * * * -* Last rev: $Date: 2004-12-08 00:10:48 $,$Author: vsc $ * +* Last rev: $Date: 2004-12-16 05:57:23 $,$Author: vsc $ * * $Log: not supported by cvs2svn $ +* Revision 1.144 2004/12/08 00:10:48 vsc +* more grow fixes +* * Revision 1.143 2004/12/05 05:01:23 vsc * try to reduce overheads when running with goal expansion enabled. * CLPBN fixes @@ -2021,7 +2024,7 @@ p_compile_dynamic(void) old_optimize = optimizer_on; optimizer_on = FALSE; YAPEnterCriticalSection(); - code_adr = Yap_cclause(t, 3, mod, Deref(ARG3)); /* vsc: give the number of arguments to + code_adr = Yap_cclause(t, 5, mod, Deref(ARG3)); /* vsc: give the number of arguments to cclause() in case there is a overflow */ t = Deref(ARG1); /* just in case there was an heap overflow */ if (!Yap_ErrorMessage) { diff --git a/C/compiler.c b/C/compiler.c index dca52bef0..390e465a0 100644 --- a/C/compiler.c +++ b/C/compiler.c @@ -11,8 +11,13 @@ * File: compiler.c * * comments: Clause compiler * * * -* Last rev: $Date: 2004-12-05 05:01:23 $,$Author: vsc $ * +* Last rev: $Date: 2004-12-16 05:57:32 $,$Author: vsc $ * * $Log: not supported by cvs2svn $ +* Revision 1.55 2004/12/05 05:01:23 vsc +* try to reduce overheads when running with goal expansion enabled. +* CLPBN fixes +* Handle overflows when allocating big clauses properly. +* * Revision 1.54 2004/11/19 22:08:41 vsc * replace SYSTEM_ERROR by out OUT_OF_WHATEVER_ERROR whenever appropriate. * @@ -2770,7 +2775,7 @@ Yap_cclause(volatile Term inp_clause, int NOfArgs, int mod, volatile Term src) ARG3 = src; YAPLeaveCriticalSection(); - if (!Yap_gcl(Yap_Error_Size, 3, ENV, P)) { + if (!Yap_gcl(Yap_Error_Size, NOfArgs, ENV, P)) { Yap_Error_TYPE = OUT_OF_STACK_ERROR; Yap_Error_Term = inp_clause; } diff --git a/C/dbase.c b/C/dbase.c index 8b36532bd..437c2812f 100644 --- a/C/dbase.c +++ b/C/dbase.c @@ -2290,14 +2290,16 @@ p_still_variant(void) static int copy_attachments(CELL *ts) { - while (TRUE) { - attvar_record *orig = (attvar_record *)Yap_ReadTimedVar(DelayedVars); + Term orig = Yap_ReadTimedVar(DelayedVars); + Term orig2 = Yap_ReadTimedVar(AttsMutableList); + while (TRUE) { /* store away in case there is an overflow */ if (attas[IntegerOfTerm(ts[2])].term_to_op(ts[1], ts[0]) == FALSE) { /* oops, we did not have enough space to copy the elements */ /* reset queue of woken up goals */ - Yap_UpdateTimedVar(DelayedVars, (CELL)orig); + Yap_UpdateTimedVar(DelayedVars, orig); + Yap_UpdateTimedVar(AttsMutableList, orig2); return FALSE; } if (ts[3] == TermNil) return TRUE; @@ -2423,9 +2425,10 @@ GetDBTerm(DBTerm *DBSP) #ifdef COROUTINING if (DBSP->attachments != 0L) { if (!copy_attachments((CELL *)AdjustIDBPtr(DBSP->attachments,(CELL)HOld-(CELL)(DBSP->Contents)))) { - Yap_Error_TYPE = OUT_OF_ATTVARS_ERROR; - Yap_Error_Size = 0; - return (Term)0; + H = HOld; + Yap_Error_TYPE = OUT_OF_ATTVARS_ERROR; + Yap_Error_Size = 0; + return (Term)0; } } #endif diff --git a/C/utilpreds.c b/C/utilpreds.c index 9a6cbbea8..33e2bc9e1 100644 --- a/C/utilpreds.c +++ b/C/utilpreds.c @@ -310,17 +310,18 @@ CopyTerm(Term inp) { H += 2; if ((res = copy_complex_term(Hi-2, Hi-1, Hi, Hi)) < 0) { ARG3 = t; + H = Hi-1; if (res == -1) { /* handle overflow */ if (!Yap_gc(3, ENV, P)) { Yap_Error(OUT_OF_STACK_ERROR, TermNil, Yap_ErrorMessage); - return(FALSE); + return FALSE; } t = Deref(ARG3); goto restart_attached; } else { /* handle overflow */ if (!Yap_ExpandPreAllocCodeSpace(0,NULL)) { - Yap_Error(OUT_OF_HEAP_ERROR, TermNil, Yap_ErrorMessage); - return(FALSE); + Yap_Error(OUT_OF_AUXSPACE_ERROR, TermNil, Yap_ErrorMessage); + return FALSE; } t = Deref(ARG3); goto restart_attached; @@ -345,18 +346,19 @@ CopyTerm(Term inp) { { int res; if ((res = copy_complex_term(ap-1, ap+1, Hi, Hi)) < 0) { + H = Hi; ARG3 = t; if (res == -1) { /* handle overflow */ if (!Yap_gc(3, ENV, P)) { Yap_Error(OUT_OF_STACK_ERROR, TermNil, Yap_ErrorMessage); - return(FALSE); + return FALSE; } t = Deref(ARG3); goto restart_list; } else { /* handle overflow */ if (!Yap_ExpandPreAllocCodeSpace(0,NULL)) { - Yap_Error(OUT_OF_HEAP_ERROR, TermNil, Yap_ErrorMessage); - return(FALSE); + Yap_Error(OUT_OF_AUXSPACE_ERROR, TermNil, Yap_ErrorMessage); + return FALSE; } t = Deref(ARG3); goto restart_list; @@ -379,19 +381,21 @@ CopyTerm(Term inp) { H += 1+ArityOfFunctor(f); { int res; + if ((res = copy_complex_term(ap, ap+ArityOfFunctor(f), HB0+1, HB0)) < 0) { + H = HB0; ARG3 = t; if (res == -1) { if (!Yap_gc(3, ENV, P)) { Yap_Error(OUT_OF_STACK_ERROR, TermNil, Yap_ErrorMessage); - return(FALSE); + return FALSE; } t = Deref(ARG3); goto restart_appl; } else { /* handle overflow */ if (!Yap_ExpandPreAllocCodeSpace(0,NULL)) { - Yap_Error(OUT_OF_HEAP_ERROR, TermNil, Yap_ErrorMessage); - return(FALSE); + Yap_Error(OUT_OF_AUXSPACE_ERROR, TermNil, Yap_ErrorMessage); + return FALSE; } t = Deref(ARG3); goto restart_appl; @@ -411,6 +415,9 @@ static Int p_copy_term(void) /* copy term t to a new instance */ { Term t = CopyTerm(ARG1); + if (t == 0L) + return FALSE; + /* be careful, there may be a stack shift here */ return Yap_unify(ARG2,t); } @@ -621,6 +628,7 @@ CopyTermNoDelays(Term inp) { H += 2; res = copy_complex_term_no_delays(ap-1, ap+1, H-2, H-2); if (res) { + H = Hi; if (res == -1) { /* handle overflow */ if (!Yap_gc(2, ENV, P)) { Yap_Error(OUT_OF_STACK_ERROR, TermNil, Yap_ErrorMessage); @@ -630,7 +638,7 @@ CopyTermNoDelays(Term inp) { goto restart_list; } else { /* handle overflow */ if (!Yap_ExpandPreAllocCodeSpace(0,NULL)) { - Yap_Error(OUT_OF_HEAP_ERROR, TermNil, Yap_ErrorMessage); + Yap_Error(OUT_OF_AUXSPACE_ERROR, TermNil, Yap_ErrorMessage); return(FALSE); } t = Deref(ARG1); @@ -653,6 +661,7 @@ CopyTermNoDelays(Term inp) { H += 1+ArityOfFunctor(f); res = copy_complex_term_no_delays(ap, ap+ArityOfFunctor(f), HB0+1, HB0); if (res) { + H = HB0; if (res == -1) { if (!Yap_gc(2, ENV, P)) { Yap_Error(OUT_OF_STACK_ERROR, TermNil, Yap_ErrorMessage); @@ -662,7 +671,7 @@ CopyTermNoDelays(Term inp) { goto restart_appl; } else { /* handle overflow */ if (!Yap_ExpandPreAllocCodeSpace(0,NULL)) { - Yap_Error(OUT_OF_HEAP_ERROR, TermNil, Yap_ErrorMessage); + Yap_Error(OUT_OF_AUXSPACE_ERROR, TermNil, Yap_ErrorMessage); return(FALSE); } t = Deref(ARG1); @@ -676,7 +685,11 @@ CopyTermNoDelays(Term inp) { static Int p_copy_term_no_delays(void) /* copy term t to a new instance */ { - return(Yap_unify(ARG2,CopyTermNoDelays(ARG1))); + Term t = CopyTermNoDelays(ARG1); + if (t == 0L) + return FALSE; + /* be careful, there may be a stack shift here */ + return(Yap_unify(ARG2,t)); }