From 39c4a2e67f889ed8c464100d8eaf7586b393b933 Mon Sep 17 00:00:00 2001 From: vsc Date: Tue, 17 Jun 2008 13:37:51 +0000 Subject: [PATCH] fix c_interface not to crash when people try to recover slots that are not there. fix try_logical and friends to handle case where predicate has arity 0. git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@2278 b08c6af1-5177-4d33-ba66-4b1c6b8b522a --- C/absmi.c | 33 ++++++++++++++++++--------------- C/adtdefs.c | 6 +++++- C/c_interface.c | 13 ++++++++----- C/heapgc.c | 2 +- H/Yapproto.h | 4 ++-- changes-5.1.html | 2 ++ docs/yap.tex | 4 ++-- include/YapInterface.h | 2 +- 8 files changed, 39 insertions(+), 27 deletions(-) diff --git a/C/absmi.c b/C/absmi.c index 1cddc7e99..7df45a5ef 100644 --- a/C/absmi.c +++ b/C/absmi.c @@ -10,8 +10,11 @@ * * * File: absmi.c * * comments: Portable abstract machine interpreter * -* Last rev: $Date: 2008-06-04 14:47:18 $,$Author: vsc $ * +* Last rev: $Date: 2008-06-17 13:37:48 $,$Author: vsc $ * * $Log: not supported by cvs2svn $ +* Revision 1.241 2008/06/04 14:47:18 vsc +* make sure we do trim_trail whenever we mess with B! +* * Revision 1.240 2008/04/04 16:11:40 vsc * yapor had gotten broken with recent thread changes * @@ -832,7 +835,7 @@ Yap_absmi(int inp) ASP = (CELL *) PROTECT_FROZEN_B(B); } else { - ASP = YREG; + ASP = YREG+E_CB; } saveregs(); #if PUSH_REGS @@ -849,7 +852,7 @@ Yap_absmi(int inp) ASP = (CELL *) PROTECT_FROZEN_B(B); } else { - ASP = YREG; + ASP = YREG+E_CB; } saveregs(); #if PUSH_REGS @@ -858,7 +861,7 @@ Yap_absmi(int inp) #if BP_FREE P1REG = PCBACKUP; #endif - return (0); + return 0; ENDBOp(); /***************************************************************** @@ -1042,7 +1045,7 @@ Yap_absmi(int inp) JMPNext(); } restore_yaam_regs(PREG->u.lld.n); - restore_at_least_one_arg(PREG->u.lld.t.s); + restore_args(PREG->u.lld.t.s); LOCK(PREG->u.lld.d->ClPred->StatisticsForPred.lock); PREG->u.lld.d->ClPred->StatisticsForPred.NOfRetries++; UNLOCK(PREG->u.lld.d->ClPred->StatisticsForPred.lock); @@ -1139,7 +1142,7 @@ Yap_absmi(int inp) #ifdef YAPOR if (SCH_top_shared_cp(B)) { SCH_last_alternative(PREG, B_YREG); - restore_at_least_one_arg(ap->ArityOfPE); + restore_args(ap->ArityOfPE); #ifdef FROZEN_STACKS S_YREG = (CELL *) PROTECT_FROZEN_B(B_YREG); #else @@ -1150,7 +1153,7 @@ Yap_absmi(int inp) #endif /* YAPOR */ { pop_yaam_regs(); - pop_at_least_one_arg(ap->ArityOfPE); + pop_args(ap->ArityOfPE); S_YREG--; #ifdef FROZEN_STACKS S_YREG = (CELL *) PROTECT_FROZEN_B(B_YREG); @@ -1335,7 +1338,7 @@ Yap_absmi(int inp) JMPNext(); } restore_yaam_regs(PREG->u.lld.n); - restore_at_least_one_arg(PREG->u.lld.t.s); + restore_args(PREG->u.lld.t.s); RetriesCounter--; if (RetriesCounter == 0) { saveregs(); @@ -1459,7 +1462,7 @@ Yap_absmi(int inp) #ifdef YAPOR if (SCH_top_shared_cp(B)) { SCH_last_alternative(PREG, B_YREG); - restore_at_least_one_arg(ap->ArityOfPE); + restore_args(ap->ArityOfPE); #ifdef FROZEN_STACKS S_YREG = (CELL *) PROTECT_FROZEN_B(B_YREG); #else @@ -1470,7 +1473,7 @@ Yap_absmi(int inp) #endif /* YAPOR */ { pop_yaam_regs(); - pop_at_least_one_arg(ap->ArityOfPE); + pop_args(ap->ArityOfPE); S_YREG--; #ifdef FROZEN_STACKS S_YREG = (CELL *) PROTECT_FROZEN_B(B_YREG); @@ -1554,7 +1557,7 @@ Yap_absmi(int inp) LogUpdClause *cl = ClauseCodeToLogUpdClause(PREG); Term t; - ASP = YREG; + ASP = YREG+E_CB; saveregs(); while ((t = Yap_FetchTermFromDB(cl->ClSource)) == 0L) { if (Yap_Error_TYPE == OUT_OF_ATTVARS_ERROR) { @@ -2677,7 +2680,7 @@ Yap_absmi(int inp) if (ActiveSignals & YAP_CREEP_SIGNAL) { GONext(); } - ASP = YREG; + ASP = YREG+E_CB; /* cut_e */ if (SREG <= ASP) { ASP = SREG-EnvSizeInCells; @@ -8171,7 +8174,7 @@ Yap_absmi(int inp) /* fprintf(stderr,"+ %p/%p %d %d %d--%u\n",PREG,PREG->u.lld.d->ClPred,timestamp,PREG->u.lld.d->ClPred->TimeStampOfPred,PREG->u.lld.d->ClTimeStart,PREG->u.lld.d->ClTimeEnd);*/ /* Point AP to the code that follows this instruction */ /* always do this, even if we are not going to use it */ - store_at_least_one_arg(PREG->u.lld.t.s); + store_args(PREG->u.lld.t.s); store_yaam_regs(PREG->u.lld.n, 0); set_cut(S_YREG, B); B = B_YREG; @@ -8304,7 +8307,7 @@ Yap_absmi(int inp) #ifdef YAPOR if (SCH_top_shared_cp(B)) { SCH_last_alternative(PREG, B_YREG); - restore_at_least_one_arg(ap->ArityOfPE); + restore_args(ap->ArityOfPE); #ifdef FROZEN_STACKS S_YREG = (CELL *) PROTECT_FROZEN_B(B_YREG); #else @@ -8315,7 +8318,7 @@ Yap_absmi(int inp) #endif /* YAPOR */ { pop_yaam_regs(); - pop_at_least_one_arg(ap->ArityOfPE); + pop_args(ap->ArityOfPE); S_YREG--; #ifdef FROZEN_STACKS S_YREG = (CELL *) PROTECT_FROZEN_B(B_YREG); diff --git a/C/adtdefs.c b/C/adtdefs.c index 056afb5c3..d642889d0 100644 --- a/C/adtdefs.c +++ b/C/adtdefs.c @@ -1165,12 +1165,16 @@ Yap_InitSlot(Term t) return((ASP+1)-LCL0); } -void +int Yap_RecoverSlots(int n) { Int old_slots = IntOfTerm(ASP[0]); + if (old_slots - n < 0) { + return FALSE; + } ASP += n; ASP[0] = MkIntTerm(old_slots-n); + return TRUE; } Term diff --git a/C/c_interface.c b/C/c_interface.c index de8035ad2..08e15ae8b 100644 --- a/C/c_interface.c +++ b/C/c_interface.c @@ -10,8 +10,11 @@ * File: c_interface.c * * comments: c_interface primitives definition * * * -* Last rev: $Date: 2008-06-04 14:47:18 $,$Author: vsc $ * +* Last rev: $Date: 2008-06-17 13:37:48 $,$Author: vsc $ * * $Log: not supported by cvs2svn $ +* Revision 1.118 2008/06/04 14:47:18 vsc +* make sure we do trim_trail whenever we mess with B! +* * Revision 1.117 2008/06/04 13:58:36 vsc * more fixes to C-interface * @@ -438,7 +441,7 @@ X_API long STD_PROTO(YAP_InitSlot,(Term)); X_API Term STD_PROTO(YAP_GetFromSlot,(long)); X_API Term *STD_PROTO(YAP_AddressFromSlot,(long)); X_API void STD_PROTO(YAP_PutInSlot,(long, Term)); -X_API void STD_PROTO(YAP_RecoverSlots,(int)); +X_API int STD_PROTO(YAP_RecoverSlots,(int)); X_API void STD_PROTO(YAP_Throw,(Term)); X_API void STD_PROTO(YAP_Halt,(int)); X_API Term *STD_PROTO(YAP_TopOfLocalStack,(void)); @@ -1002,10 +1005,10 @@ YAP_InitSlot(Term t) return Yap_InitSlot(t); } -X_API void +X_API int YAP_RecoverSlots(int n) { - Yap_RecoverSlots(n); + return Yap_RecoverSlots(n); } X_API Term @@ -1440,7 +1443,7 @@ YAP_RunGoal(Term t) CP = old_CP; Yap_AllowRestart = TRUE; } else { - ASP = B->cp_env; + ENV = B->cp_env; B = B->cp_b; Yap_AllowRestart = FALSE; } diff --git a/C/heapgc.c b/C/heapgc.c index 21cc58573..29510ed85 100644 --- a/C/heapgc.c +++ b/C/heapgc.c @@ -1566,7 +1566,7 @@ mark_environments(CELL_PTR gc_ENV, OPREG size, CELL *pvbmap) if (MARKED_PTR(gc_ENV+E_CB)) return; MARK(gc_ENV+E_CB); - + size = EnvSize((CELL_PTR) (gc_ENV[E_CP])); /* size = EnvSize(CP) */ pvbmap = EnvBMap((CELL_PTR) (gc_ENV[E_CP])); #if 0 diff --git a/H/Yapproto.h b/H/Yapproto.h index 9c0cbc4bf..eb57b73ec 100644 --- a/H/Yapproto.h +++ b/H/Yapproto.h @@ -10,7 +10,7 @@ * File: Yap.proto * * mods: * * comments: Function declarations for YAP * -* version: $Id: Yapproto.h,v 1.86 2008-06-04 14:47:18 vsc Exp $ * +* version: $Id: Yapproto.h,v 1.87 2008-06-17 13:37:49 vsc Exp $ * *************************************************************************/ /* prototype file for Yap */ @@ -52,7 +52,7 @@ int STD_PROTO(Yap_AtomReleaseHold,(Atom)); long STD_PROTO(Yap_InitSlot,(Term)); long STD_PROTO(Yap_NewSlots,(int)); Term STD_PROTO(Yap_GetFromSlot,(long)); -void STD_PROTO(Yap_RecoverSlots,(int)); +int STD_PROTO(Yap_RecoverSlots,(int)); Term STD_PROTO(Yap_GetFromSlot,(long)); Term *STD_PROTO(Yap_AddressFromSlot,(long)); void STD_PROTO(Yap_PutInSlot,(long, Term)); diff --git a/changes-5.1.html b/changes-5.1.html index 4eacf5e2b..ad347ed17 100644 --- a/changes-5.1.html +++ b/changes-5.1.html @@ -17,6 +17,8 @@

Yap-5.1.3: