From a68263845d80e0b604118e15a0d6849a3c287292 Mon Sep 17 00:00:00 2001 From: vsc Date: Thu, 22 Apr 2004 03:24:17 +0000 Subject: [PATCH] trust_logical should protect the last clause, otherwise it cannot jump there. git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@1045 b08c6af1-5177-4d33-ba66-4b1c6b8b522a --- C/absmi.c | 30 ++++++++++++++++++++++++++---- C/heapgc.c | 15 ++++----------- C/index.c | 40 ++++++++++++++++++++-------------------- 3 files changed, 50 insertions(+), 35 deletions(-) diff --git a/C/absmi.c b/C/absmi.c index 64484dae4..9dd486d9d 100644 --- a/C/absmi.c +++ b/C/absmi.c @@ -10,8 +10,11 @@ * * * File: absmi.c * * comments: Portable abstract machine interpreter * -* Last rev: $Date: 2004-04-16 19:27:30 $,$Author: vsc $ * +* Last rev: $Date: 2004-04-22 03:24:17 $,$Author: vsc $ * * $Log: not supported by cvs2svn $ +* Revision 1.129 2004/04/16 19:27:30 vsc +* more bug fixes +* * Revision 1.128 2004/04/14 19:10:22 vsc * expand_clauses: keep a list of clauses to expand * fix new trail scheme for multi-assignment variables @@ -1210,10 +1213,20 @@ Yap_absmi(int inp) TR = --(B->cp_tr); /* actually get rid of the code */ if (cl->ClRefCount == 0 && cl->ClFlags & ErasedMask) { + yamop *next = PREG->u.ld.d; UNLOCK(cl->ClLock); - /* I am the last one using this clause, hence I don't need a lock - to dispose of it - */ + if (next != FAILCODE) { + LogUpdClause *lcl = ClauseCodeToLogUpdClause(next); + /* I am the last one using this clause, hence I don't need a lock + to dispose of it + */ + LOCK(lcl->ClLock); + /* make sure the clause isn't destroyed */ + /* always add an extra reference */ + INC_CLREF_COUNT(lcl); + TRAIL_CLREF(lcl); + UNLOCK(cl->ClLock); + } Yap_ErLogUpdIndex(cl); } else { UNLOCK(cl->ClLock); @@ -1225,6 +1238,15 @@ Yap_absmi(int inp) TR = --B->cp_tr; /* next, recover space for the indexing code if it was erased */ if (cl->ClFlags & ErasedMask) { + yamop *next = PREG->u.ld.d; + if (next != FAILCODE) { + LogUpdClause *lcl = ClauseCodeToLogUpdClause(next); + /* make sure we don't erase the clause we are jumping too */ + if (!(lcl->ClFlags & InUseMask)) { + lcl->ClFlags |= InUseMask; + TRAIL_CLREF(lcl); + } + } Yap_ErLogUpdIndex(cl); } } diff --git a/C/heapgc.c b/C/heapgc.c index 8fca5d4b0..ab1c325b1 100644 --- a/C/heapgc.c +++ b/C/heapgc.c @@ -1403,7 +1403,6 @@ mark_choicepoints(register choiceptr gc_B, tr_fr_ptr saved_TR, int very_verbose) yamop *rtp = gc_B->cp_ap; mark_db_fixed((CELL *)rtp); - mark_db_fixed((CELL *)(gc_B->cp_ap)); mark_db_fixed((CELL *)(gc_B->cp_cp)); #ifdef EASY_SHUNTING current_B = gc_B; @@ -1914,11 +1913,8 @@ sweep_trail(choiceptr gc_B, tr_fr_ptr old_TR) int erase; DEC_CLREF_COUNT(indx); indx->ClFlags &= ~InUseMask; - erase = (indx->ClFlags & ErasedMask) -#if defined(YAPOR) || defined(THREADS) - && (indx->ClRefCount == 0) -#endif - ; + erase = (indx->ClFlags & ErasedMask + && !indx->ClRefCount); if (erase) { /* at this point, no one is accessing the clause */ @@ -1927,13 +1923,10 @@ sweep_trail(choiceptr gc_B, tr_fr_ptr old_TR) } else { LogUpdClause *cl = ClauseFlagsToLogUpdClause(pt0); int erase; + DEC_CLREF_COUNT(cl); cl->ClFlags &= ~InUseMask; - erase = (cl->ClFlags & ErasedMask) -#if defined(YAPOR) || defined(THREADS) - && (cl->ClRefCount == 0) -#endif - ; + erase = ((cl->ClFlags & ErasedMask) && !cl->ClRefCount); if (erase) { /* at this point, no one is accessing the clause */ diff --git a/C/index.c b/C/index.c index 61c89ae82..6c5698f03 100644 --- a/C/index.c +++ b/C/index.c @@ -11,8 +11,11 @@ * File: index.c * * comments: Indexing a Prolog predicate * * * -* Last rev: $Date: 2004-04-21 04:01:53 $,$Author: vsc $ * +* Last rev: $Date: 2004-04-22 03:24:17 $,$Author: vsc $ * * $Log: not supported by cvs2svn $ +* Revision 1.87 2004/04/21 04:01:53 vsc +* fix bad ordering when inserting second clause +* * Revision 1.86 2004/04/20 22:08:23 vsc * fixes for corourining * @@ -87,7 +90,6 @@ UInt STATIC_PROTO(do_index, (ClauseDef *,ClauseDef *,struct intermediates *,UInt UInt STATIC_PROTO(do_compound_index, (ClauseDef *,ClauseDef *,Term *t,struct intermediates *,UInt,UInt,UInt,UInt,int,int,int,CELL *,int)); UInt STATIC_PROTO(do_dbref_index, (ClauseDef *,ClauseDef *,Term,struct intermediates *,UInt,UInt,int,int,CELL *)); UInt STATIC_PROTO(do_blob_index, (ClauseDef *,ClauseDef *,Term,struct intermediates *,UInt,UInt,int,int,CELL *)); -/*path_stack_entry *STATIC_PROTO(kill_unsafe_block, (path_stack_entry *,op_numbers,PredEntry *,int,int,ClauseDef *));*/ static UInt labelno; @@ -5558,7 +5560,7 @@ static_clause(yamop *ipc) } /* this code should be called when we jumped to clauses */ -path_stack_entry * +static path_stack_entry * kill_unsafe_block(path_stack_entry *sp, op_numbers op, PredEntry *ap, int first, int remove, ClauseDef *cls) { yamop *ipc; @@ -5643,27 +5645,25 @@ static void nullify_expand_clause(yamop *ipc, path_stack_entry *sp, ClauseDef *cls) { yamop **st = (yamop **)NEXTOP(ipc,sp); - if (ipc->u.sp.s2 == 2) { - yamop *cl; + yamop **max = st+ipc->u.sp.s1; + /* make sure we get rid of the reference */ + while (st < max) { + if (*st && *st == cls->Code) { + *st = NULL; + ipc->u.sp.s2--; + break; + } + st++; + } + /* if the block has a single element */ + if (ipc->u.sp.s2 == 1) { + yamop **st = (yamop **)NEXTOP(ipc,sp); while ((--sp)->flag != block_entry); while (TRUE) { if (*st && *st != cls->Code) { - cl = *st; - break; - } - st++; - } - if (sp->u.cle.entry_code) { - *sp->u.cle.entry_code = cl; - } - recover_ecls_block(ipc); - } else { - yamop **max = st+ipc->u.sp.s1; - ipc->u.sp.s2--; - while (st < max) { - if (*st && *st == cls->Code) { - *st = NULL; + *sp->u.cle.entry_code = *st; + recover_ecls_block(ipc); return; } st++;