diff --git a/C/adtdefs.c b/C/adtdefs.c index 3b940fdfc..161f3d717 100644 --- a/C/adtdefs.c +++ b/C/adtdefs.c @@ -712,9 +712,8 @@ Yap_NewPredPropByFunctor(FunctorEntry *fe, Term cur_mod) PredHash[hsh] = p; } WRITE_UNLOCK(PredHashRWLock); - /* make sure that we have something here */ - p->NextOfPE = RepPredProp(fe->PropsOfFE)->NextOfPE; - RepPredProp(fe->PropsOfFE)->NextOfPE = AbsPredProp(p); + /* make sure that we have something here: note that this is not a valid pointer!! */ + RepPredProp(fe->PropsOfFE)->NextOfPE = fe->PropsOfFE; } else { fe->PropsOfFE = AbsPredProp(p); p->NextOfPE = NIL; diff --git a/C/agc.c b/C/agc.c index c0fe027b5..118265f29 100755 --- a/C/agc.c +++ b/C/agc.c @@ -194,6 +194,29 @@ AtomAdjust(Atom a) #include "rheap.h" +static void +RestoreHashPreds(void) +{ + UInt i; + + for (i = 0; i < PredHashTableSize; i++) { + PredEntry *p = PredHash[i]; + + if (p) + p = PredEntryAdjust(p); + while (p) { + Prop nextp; + + if (p->NextOfPE) + p->NextOfPE = PropAdjust(p->NextOfPE); + nextp = p->NextOfPE; + CleanCode(p); + p = RepPredProp(nextp); + } + } +} + + static void init_reg_copies(void) { OldASP = ASP; diff --git a/C/save.c b/C/save.c index f032fabf6..ce01ce615 100755 --- a/C/save.c +++ b/C/save.c @@ -1321,7 +1321,6 @@ static void restore_heap(void) { restore_codes(); - RestoreHashPreds(); RestoreIOStructures(); } diff --git a/H/rheap.h b/H/rheap.h index d2eae0b64..e09e868a9 100755 --- a/H/rheap.h +++ b/H/rheap.h @@ -379,6 +379,7 @@ AdjustSwitchTable(op_numbers op, yamop *table, COUNT i) STATIC_PROTO(void RestoreAtomList, (Atom)); STATIC_PROTO(void RestoreAtom, (AtomEntry *)); +STATIC_PROTO(void RestoreHashPreds, (void)); static void RestoreAtoms(void) @@ -658,7 +659,7 @@ RestorePredHash(void) Yap_Error(FATAL_ERROR,MkIntTerm(0),"restore should find predicate hash table"); } REINIT_RWLOCK(PredHashRWLock); - /* RestoreHashPreds() does most of the work */ + RestoreHashPreds(); /* does most of the work */ } static void