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
This commit is contained in:
vsc 2008-06-17 13:37:51 +00:00
parent e90f744e5e
commit 39c4a2e67f
8 changed files with 39 additions and 27 deletions

View File

@ -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);

View File

@ -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

View File

@ -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;
}

View File

@ -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

View File

@ -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));

View File

@ -17,6 +17,8 @@
<h2>Yap-5.1.3:</h2>
<ul>
<li> FIXED: try,retry,trust_logical should handle 0 arguments correctly.</li>
<li> FIXED: RecoverSlots should check if there are slots to recover.</li>
<li> FIXED: syntax errors should know they are in an included file.</li>
<li> FIXED: ungetc should not mess with streams.</li>
<li> FIXED: LogTalk has its own distribution (Paulo Moura).</li>

View File

@ -14150,10 +14150,10 @@ Return the address of slot @var{slot}: please use with care.
@findex YAP_PutInSlot (C-Interface function)
Set the contents of slot @var{slot} to @var{t}.
@item void YAP_RecoverSlots(int @var{HowMany})
@item int YAP_RecoverSlots(int @var{HowMany})
@findex YAP_RecoverSlots (C-Interface function)
Recover the space for @var{HowMany} slots: these will include the
current default slot.
current default slot. Fails if no such slots exist.
@end table
The following functions complement @var{YAP_RunGoal}:

View File

@ -381,7 +381,7 @@ extern X_API YAP_Term *PROTO(YAP_AddressFromSlot,(long int));
extern X_API void PROTO(YAP_PutInSlot,(long int, YAP_Term));
/* void YAP_RecoverSlots() */
extern X_API void PROTO(YAP_RecoverSlots,(int));
extern X_API int PROTO(YAP_RecoverSlots,(int));
/* void YAP_Throw() */
extern X_API void PROTO(YAP_Throw,(YAP_Term));