|
From: Vitor S. C. <vs...@us...> - 2008-06-17 13:38:13
|
Update of /cvsroot/yap/C In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv22579/C Modified Files: absmi.c adtdefs.c c_interface.c heapgc.c Log Message: 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. Index: absmi.c =================================================================== RCS file: /cvsroot/yap/C/absmi.c,v retrieving revision 1.241 retrieving revision 1.242 diff -u -r1.241 -r1.242 --- absmi.c 4 Jun 2008 14:47:18 -0000 1.241 +++ absmi.c 17 Jun 2008 13:37:48 -0000 1.242 @@ -12,6 +12,11 @@ * comments: Portable abstract machine interpreter * * Last rev: $Date$,$Author$ * * $Log$ +* Revision 1.242 2008/06/17 13:37:48 vsc +* 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. +* * Revision 1.241 2008/06/04 14:47:18 vsc * make sure we do trim_trail whenever we mess with B! * @@ -835,7 +840,7 @@ ASP = (CELL *) PROTECT_FROZEN_B(B); } else { - ASP = YREG; + ASP = YREG+E_CB; } saveregs(); #if PUSH_REGS @@ -852,7 +857,7 @@ ASP = (CELL *) PROTECT_FROZEN_B(B); } else { - ASP = YREG; + ASP = YREG+E_CB; } saveregs(); #if PUSH_REGS @@ -861,7 +866,7 @@ #if BP_FREE P1REG = PCBACKUP; #endif - return (0); + return 0; ENDBOp(); /***************************************************************** @@ -1045,7 +1050,7 @@ 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); @@ -1142,7 +1147,7 @@ #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 @@ -1153,7 +1158,7 @@ #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); @@ -1338,7 +1343,7 @@ 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(); @@ -1462,7 +1467,7 @@ #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 @@ -1473,7 +1478,7 @@ #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); @@ -1557,7 +1562,7 @@ 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) { @@ -2680,7 +2685,7 @@ if (ActiveSignals & YAP_CREEP_SIGNAL) { GONext(); } - ASP = YREG; + ASP = YREG+E_CB; /* cut_e */ if (SREG <= ASP) { ASP = SREG-EnvSizeInCells; @@ -8174,7 +8179,7 @@ /* 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; @@ -8307,7 +8312,7 @@ #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 @@ -8318,7 +8323,7 @@ #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); Index: adtdefs.c =================================================================== RCS file: /cvsroot/yap/C/adtdefs.c,v retrieving revision 1.58 retrieving revision 1.59 diff -u -r1.58 -r1.59 --- adtdefs.c 27 Mar 2008 00:41:31 -0000 1.58 +++ adtdefs.c 17 Jun 2008 13:37:48 -0000 1.59 @@ -1165,12 +1165,16 @@ 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 Index: c_interface.c =================================================================== RCS file: /cvsroot/yap/C/c_interface.c,v retrieving revision 1.118 retrieving revision 1.119 diff -u -r1.118 -r1.119 --- c_interface.c 4 Jun 2008 14:47:18 -0000 1.118 +++ c_interface.c 17 Jun 2008 13:37:48 -0000 1.119 @@ -12,6 +12,11 @@ * * * Last rev: $Date$,$Author$ * * $Log$ +* Revision 1.119 2008/06/17 13:37:48 vsc +* 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. +* * Revision 1.118 2008/06/04 14:47:18 vsc * make sure we do trim_trail whenever we mess with B! * @@ -441,7 +446,7 @@ 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)); @@ -1005,10 +1010,10 @@ return Yap_InitSlot(t); } -X_API void +X_API int YAP_RecoverSlots(int n) { - Yap_RecoverSlots(n); + return Yap_RecoverSlots(n); } X_API Term @@ -1443,7 +1448,7 @@ CP = old_CP; Yap_AllowRestart = TRUE; } else { - ASP = B->cp_env; + ENV = B->cp_env; B = B->cp_b; Yap_AllowRestart = FALSE; } Index: heapgc.c =================================================================== RCS file: /cvsroot/yap/C/heapgc.c,v retrieving revision 1.211 retrieving revision 1.212 diff -u -r1.211 -r1.212 --- heapgc.c 8 Jun 2008 08:05:11 -0000 1.211 +++ heapgc.c 17 Jun 2008 13:37:49 -0000 1.212 @@ -1566,7 +1566,7 @@ 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 |