diff --git a/C/arrays.c b/C/arrays.c index df533800a..a42aacebd 100644 --- a/C/arrays.c +++ b/C/arrays.c @@ -1534,6 +1534,10 @@ p_assign_static(void) ReleaseTermFromDB(ref); } ptr->ValueOfVE.terms[indx] = StoreTermInDB(3,3); + if (ptr->ValueOfVE.terms[indx]){ + WRITE_UNLOCK(ptr->ArRWLock); + return(FALSE); + } } break; } diff --git a/C/bb.c b/C/bb.c index 61f315558..55fcddc05 100644 --- a/C/bb.c +++ b/C/bb.c @@ -313,9 +313,8 @@ p_bb_update(void) ReleaseTermFromDB(p->Element); p->Element = StoreTermInDB(3,3); - WRITE_UNLOCK(p->BBRWLock); - return(TRUE); + return(p->Element != NULL); } static Int diff --git a/C/dbase.c b/C/dbase.c index 04180bba1..e0640f7e8 100644 --- a/C/dbase.c +++ b/C/dbase.c @@ -3968,6 +3968,8 @@ p_enqueue(void) } else father_key = (db_queue *)DBRefOfTerm(Father); x = StoreTermInDB(2, 2); + if (x == NULL) + return(FALSE); x->Parent = NULL; WRITE_LOCK(father_key->QRWLock); if (father_key->LastInQueue != NULL) diff --git a/C/utilpreds.c b/C/utilpreds.c index c2a6d2321..10010e758 100644 --- a/C/utilpreds.c +++ b/C/utilpreds.c @@ -666,7 +666,6 @@ p_variables_in_term(void) /* variables in term t */ return(unify(ARG3,out)); } - static Term non_singletons_in_complex_term(register CELL *pt0, register CELL *pt0_end) { @@ -910,10 +909,11 @@ p_ground(void) /* ground(+T) */ static Int var_in_complex_term(register CELL *pt0, register CELL *pt0_end, - Term t) + Term v) { register CELL **to_visit = (CELL **)(HeapTop + sizeof(CELL)); + register tr_fr_ptr TR0 = TR; loop: while (pt0 < pt0_end) { @@ -922,8 +922,8 @@ static Int var_in_complex_term(register CELL *pt0, ++ pt0; ptd0 = pt0; d0 = *ptd0; - deref_head(d0, vars_in_term_unk); - vars_in_term_nvar: + deref_head(d0, var_in_term_unk); + var_in_term_nvar: { if (IsPairTerm(d0)) { #ifdef RATIONAL_TREES @@ -974,18 +974,15 @@ static Int var_in_complex_term(register CELL *pt0, } - deref_body(d0, ptd0, vars_in_term_unk, vars_in_term_nvar); - if ((CELL)ptd0 == t) { /* we found it */ -#ifdef RATIONAL_TREES - while (to_visit > (CELL **)(HeapTop + sizeof(CELL))) { - to_visit -= 3; - pt0 = to_visit[0]; - pt0_end = to_visit[1]; - *pt0 = (CELL)to_visit[2]; - } -#endif + deref_body(d0, ptd0, var_in_term_unk, var_in_term_nvar); + if ((CELL)ptd0 == v) { /* we found it */ + clean_tr(TR0); return(TRUE); } + /* do or pt2 are unbound */ + *ptd0 = TermNil; + /* next make sure noone will see this as a variable again */ + TrailTerm(TR++) = (CELL)ptd0; } /* Do we still have compound terms to visit */ if (to_visit > (CELL **)(HeapTop + sizeof(CELL))) { @@ -1001,16 +998,19 @@ static Int var_in_complex_term(register CELL *pt0, #endif goto loop; } + clean_tr(TR0); return(FALSE); } -Int +static Int var_in_term(Term v, Term t) /* variables in term t */ { - if (IsPrimitiveTerm(t)) + if (IsVarTerm(t)) { + return(v == t); + } else if (IsPrimitiveTerm(t)) { return(FALSE); - else if (IsPairTerm(t)) { + } else if (IsPairTerm(t)) { return(var_in_complex_term(RepPair(t)-1, RepPair(t)+1, v)); } @@ -1019,6 +1019,12 @@ var_in_term(Term v, Term t) /* variables in term t */ ArityOfFunctor(FunctorOfTerm(t)),v)); } +static Int +p_var_in_term(void) +{ + return(var_in_term(Deref(ARG2), Deref(ARG1))); +} + /* The code for TermHash was originally contributed by Gertjen Van Noor */ /* This code with max_depth == -1 will loop for infinite trees */ @@ -1550,6 +1556,7 @@ void InitUtilCPreds(void) InitCPred("$copy_term_but_not_constraints", 2, p_copy_term_no_delays, 0); InitCPred("ground", 1, p_ground, SafePredFlag); InitCPred("$variables_in_term", 3, p_variables_in_term, SafePredFlag); + InitCPred("variable_in_term", 2, p_var_in_term, SafePredFlag); InitCPred("$non_singletons_in_term", 3, p_non_singletons_in_term, SafePredFlag); InitCPred("term_hash", 4, GvNTermHash, SafePredFlag); InitCPred("variant", 2, p_variant, SafePredFlag); diff --git a/H/Yapproto.h b/H/Yapproto.h index 42dac4a72..68d87c574 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.13 2002-02-26 15:51:54 vsc Exp $ * +* version: $Id: Yapproto.h,v 1.14 2002-03-07 05:13:21 vsc Exp $ * *************************************************************************/ /* prototype file for Yap */ @@ -279,7 +279,6 @@ void STD_PROTO(InitUserBacks,(void)); /* utilpreds.c */ Term STD_PROTO(CopyTerm,(Term)); -Int STD_PROTO(var_in_term, (Term, Term)); void STD_PROTO(InitUtilCPreds,(void)); /* yap.c */ diff --git a/changes4.3.html b/changes4.3.html index bf9461980..64d5da04a 100644 --- a/changes4.3.html +++ b/changes4.3.html @@ -16,6 +16,25 @@

Yap-4.3.21: