diff --git a/C/dbase.c b/C/dbase.c index 27483b1ab..82521d27c 100644 --- a/C/dbase.c +++ b/C/dbase.c @@ -3684,10 +3684,18 @@ p_instance(void) { Term TermDB; Term t1 = Deref(ARG1); + DBRef dbr; if (IsVarTerm(t1) || !IsDBRefTerm(t1)) return (FALSE); - while ((TermDB = GetDBTerm(DBRefOfTerm(t1))) == (CELL)0) { + dbr = DBRefOfTerm(t1); + if (dbr->Flags & ErasedMask) { + /* instance/2 of erased terms should fail under log update + semantics */ + if (dbr->Parent != NULL && dbr->Parent->KindOfPE & LogUpdDBBit) + return(FALSE); + } + while ((TermDB = GetDBTerm(dbr)) == (CELL)0) { /* oops, we are in trouble, not enough stack space */ gc(2, ENV, P); t1 = Deref(ARG1); diff --git a/C/heapgc.c b/C/heapgc.c index 1e30d8077..3f1188aee 100644 --- a/C/heapgc.c +++ b/C/heapgc.c @@ -583,7 +583,7 @@ init_dbtable(tr_fr_ptr trail_ptr) { flags = Flags((CELL)pt0); /* for the moment, if all references to the term in the stacks are only pointers, reset the flag */ - if (FlagOn(DBClMask, flags) && !FlagOn(LogUpdMask, flags)) { + if (FlagOn(DBClMask, flags)) { if (FlagOn(DBNoVars, flags)) { CODEADDR entry = ((CODEADDR)pt0 - (CELL) &(((DBRef) NIL)->Flags)); store_ref_in_dbtable((DBRef)entry); @@ -879,7 +879,14 @@ mark_variable(CELL_PTR current) if ((Functor)cnext == FunctorDBRef) { DBRef tref = DBRefOfTerm(ccur); /* make sure the reference is marked as in use */ - tref->Flags |= GcFoundMask; + if ((tref->Flags & ErasedMask) && + tref->Parent != NULL && + tref->Parent->KindOfPE & LogUpdDBBit) { + *current = MkDBRefTerm(DBErasedMarker); + MARK(current); + } else { + tref->Flags |= GcFoundMask; + } } else { mark_db_fixed(next); } @@ -930,6 +937,7 @@ mark_variable(CELL_PTR current) POP_CONTINUATION(); } } + if (next < H0) POP_CONTINUATION(); #ifdef INSTRUMENT_GC inc_vars_of_type(next,gc_func); #endif @@ -982,7 +990,14 @@ mark_external_reference(CELL *ptr) { if ((Functor)(*next) == FunctorDBRef) { DBRef tref = DBRefOfTerm(reg); /* make sure the reference is marked as in use */ - tref->Flags |= GcFoundMask; + if ((tref->Flags & ErasedMask) && + tref->Parent != NULL && + tref->Parent->KindOfPE & LogUpdDBBit) { + *ptr = MkDBRefTerm(DBErasedMarker); + MARK(ptr); + } else { + tref->Flags |= GcFoundMask; + } } else { mark_db_fixed(next); } @@ -1852,8 +1867,8 @@ sweep_trail(choiceptr gc_B, tr_fr_ptr old_TR) } #endif - if (!FlagOn(GcFoundMask, flags)) { - if (FlagOn(DBClMask, flags) && !FlagOn(LogUpdMask, flags)) { + if (!FlagOn(GcFoundMask, flags) && !FlagOn(LogUpdMask, flags)) { + if (FlagOn(DBClMask, flags)) { Flags((CELL)pt0) = ResetFlag(InUseMask, flags); if (FlagOn(ErasedMask, flags)) { ErDBE((DBRef) ((CELL)pt0 - (CELL) &(((DBRef) NIL)->Flags))); @@ -3076,7 +3091,7 @@ static Int p_gc(void) { #ifndef FIXED_STACKS - do_gc(0, ENV, CP); + do_gc(0, ENV, P); #endif /* FIXED_STACKS */ return(TRUE); } diff --git a/C/init.c b/C/init.c index 389e62669..fee727eff 100644 --- a/C/init.c +++ b/C/init.c @@ -1070,8 +1070,16 @@ InitCodes(void) heap_regs->getworkcode.u.ld.p = (CODEADDR)RepPredProp(PredPropByAtom(LookupAtom("$getwork"), 0)); heap_regs->getworkcode_seq.u.ld.p = (CODEADDR)RepPredProp(PredPropByAtom(LookupAtom("$getwork_seq"), 0)); #endif + heap_regs->db_erased_marker = + (DBRef)AllocCodeSpace(sizeof(DBStruct)); + heap_regs->db_erased_marker->id = FunctorDBRef; + heap_regs->db_erased_marker->Flags = ErasedMask; + heap_regs->db_erased_marker->Code = NULL; + INIT_LOCK(heap_regs->db_erased_marker->lock); + INIT_DBREF_COUNT(heap_regs->db_erased_marker); } + static void InitVersion(void) { diff --git a/C/save.c b/C/save.c index dbdc53cdd..1f9eaea46 100644 --- a/C/save.c +++ b/C/save.c @@ -1158,6 +1158,8 @@ restore_codes(void) #endif if (heap_regs->last_wtime != NULL) heap_regs->last_wtime = (void *)PtoHeapCellAdjust((CELL *)(heap_regs->last_wtime)); + heap_regs->db_erased_marker = + DBRefAdjust(heap_regs->db_erased_marker); } /* restore some heap registers */ diff --git a/H/Heap.h b/H/Heap.h index 7d3382a08..e2ec0e2ff 100644 --- a/H/Heap.h +++ b/H/Heap.h @@ -10,7 +10,7 @@ * File: Heap.h * * mods: * * comments: Heap Init Structure * -* version: $Id: Heap.h,v 1.26 2002-05-23 03:52:34 vsc Exp $ * +* version: $Id: Heap.h,v 1.27 2002-06-04 00:46:32 vsc Exp $ * *************************************************************************/ /* information that can be stored in Code Space */ @@ -282,6 +282,7 @@ typedef struct various_codes { PredEntry *pred_throw; PredEntry *pred_handle_throw; struct array_entry *dyn_array_list; + struct DB_STRUCT *db_erased_marker; UInt n_of_file_aliases; UInt sz_of_file_aliases; struct AliasDescS * file_aliases; @@ -474,6 +475,7 @@ typedef struct various_codes { #define PredThrow heap_regs->pred_throw #define PredHandleThrow heap_regs->pred_handle_throw #define DynArrayList heap_regs->dyn_array_list +#define DBErasedMarker heap_regs->db_erased_marker #define NOfFileAliases heap_regs->n_of_file_aliases #define SzOfFileAliases heap_regs->sz_of_file_aliases #define FileAliases heap_regs->file_aliases diff --git a/Makefile.in b/Makefile.in index bcd385253..bf6845875 100644 --- a/Makefile.in +++ b/Makefile.in @@ -90,7 +90,7 @@ TEXI2PDF=texi2pdf #4.1VPATH=@srcdir@:@srcdir@/OPTYap CWD=$(PWD) # -VERSION=Yap-4.3.21 +VERSION=Yap-4.3.22 # TAG_HEADERS= Tags_32bits.h Tags_32Ops.h Tags_32LowTag.h\ diff --git a/changes4.3.html b/changes4.3.html index ad88f5d0f..08cc54e50 100644 --- a/changes4.3.html +++ b/changes4.3.html @@ -16,6 +16,14 @@