fix reading predicates with prolog and other module.
This commit is contained in:
parent
d38d54b67a
commit
5dd62b6354
11
C/qlyr.c
11
C/qlyr.c
@ -785,7 +785,6 @@ ReadHash(IOSTREAM *stream)
|
||||
static void
|
||||
read_clauses(IOSTREAM *stream, PredEntry *pp, UInt nclauses, UInt flags) {
|
||||
if (pp->PredFlags & LogUpdatePredFlag) {
|
||||
|
||||
pp->TimeStampOfPred = 0L;
|
||||
/* first, clean up whatever was there */
|
||||
if (pp->cs.p_code.NOfClauses) {
|
||||
@ -887,7 +886,7 @@ read_pred(IOSTREAM *stream, Term mod) {
|
||||
if (mod == IDB_MODULE) {
|
||||
if (flags & AtomDBPredFlag) {
|
||||
Atom a = LookupAtom((Atom)read_uint(stream));
|
||||
if ((ap = RepPredProp(PredPropByAtom(a,mod))) == NULL) {
|
||||
if ((ap = RepPredProp(PredPropByAtomAndMod(a,mod))) == NULL) {
|
||||
ERROR(OUT_OF_CODE_SPACE);
|
||||
}
|
||||
} else if (flags & NumberDBPredFlag) {
|
||||
@ -897,23 +896,25 @@ read_pred(IOSTREAM *stream, Term mod) {
|
||||
}
|
||||
} else {
|
||||
Functor f = LookupFunctor((Functor)read_uint(stream));
|
||||
if ((ap = RepPredProp(PredPropByFunc(f,mod))) == NULL) {
|
||||
if ((ap = RepPredProp(PredPropByFuncAndMod(f,mod))) == NULL) {
|
||||
ERROR(OUT_OF_CODE_SPACE);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (mod == TermProlog)
|
||||
mod = PROLOG_MODULE;
|
||||
if (arity) {
|
||||
Functor f;
|
||||
|
||||
f = LookupFunctor((Functor)read_uint(stream));
|
||||
if ((ap = RepPredProp(PredPropByFunc(f,mod))) == NULL) {
|
||||
if ((ap = RepPredProp(PredPropByFuncAndMod(f,mod))) == NULL) {
|
||||
ERROR(OUT_OF_CODE_SPACE);
|
||||
}
|
||||
} else {
|
||||
Atom a;
|
||||
|
||||
a = LookupAtom((Atom)read_uint(stream));
|
||||
if ((ap = RepPredProp(PredPropByAtom(a,mod))) == NULL) {
|
||||
if ((ap = RepPredProp(PredPropByAtomAndMod(a,mod))) == NULL) {
|
||||
ERROR(OUT_OF_CODE_SPACE);
|
||||
}
|
||||
}
|
||||
|
89
H/Yatom.h
89
H/Yatom.h
@ -1564,6 +1564,64 @@ PredPropByFunc (Functor fe, Term cur_mod)
|
||||
return Yap_NewPredPropByFunctor (fe, cur_mod);
|
||||
}
|
||||
|
||||
EXTERN inline Prop
|
||||
GetPredPropByFuncAndModHavingLock (FunctorEntry *fe, Term cur_mod)
|
||||
{
|
||||
PredEntry *p;
|
||||
|
||||
if (!(p = RepPredProp(fe->PropsOfFE))) {
|
||||
return NIL;
|
||||
}
|
||||
if (p->ModuleOfPred == cur_mod) {
|
||||
#ifdef THREADS
|
||||
/* Thread Local Predicates */
|
||||
if (p->PredFlags & ThreadLocalPredFlag) {
|
||||
return AbsPredProp (Yap_GetThreadPred (p INIT_REGS));
|
||||
}
|
||||
#endif
|
||||
return AbsPredProp(p);
|
||||
}
|
||||
if (p->NextOfPE) {
|
||||
UInt hash = PRED_HASH(fe,cur_mod,PredHashTableSize);
|
||||
READ_LOCK(PredHashRWLock);
|
||||
p = PredHash[hash];
|
||||
|
||||
while (p) {
|
||||
if (p->FunctorOfPred == fe &&
|
||||
p->ModuleOfPred == cur_mod)
|
||||
{
|
||||
#ifdef THREADS
|
||||
/* Thread Local Predicates */
|
||||
if (p->PredFlags & ThreadLocalPredFlag) {
|
||||
READ_UNLOCK(PredHashRWLock);
|
||||
return AbsPredProp (Yap_GetThreadPred (p INIT_REGS));
|
||||
}
|
||||
#endif
|
||||
READ_UNLOCK(PredHashRWLock);
|
||||
return AbsPredProp(p);
|
||||
}
|
||||
p = RepPredProp(p->NextOfPE);
|
||||
}
|
||||
READ_UNLOCK(PredHashRWLock);
|
||||
}
|
||||
return NIL;
|
||||
}
|
||||
|
||||
EXTERN inline Prop
|
||||
PredPropByFuncAndMod (Functor fe, Term cur_mod)
|
||||
/* get predicate entry for ap/arity; create it if neccessary. */
|
||||
{
|
||||
Prop p0;
|
||||
|
||||
WRITE_LOCK (fe->FRWLock);
|
||||
p0 = GetPredPropByFuncAndModHavingLock(fe, cur_mod);
|
||||
if (p0) {
|
||||
WRITE_UNLOCK (fe->FRWLock);
|
||||
return p0;
|
||||
}
|
||||
return Yap_NewPredPropByFunctor (fe, cur_mod);
|
||||
}
|
||||
|
||||
EXTERN inline Prop
|
||||
PredPropByAtom (Atom at, Term cur_mod)
|
||||
/* get predicate entry for ap/arity; create it if neccessary. */
|
||||
@ -1595,6 +1653,37 @@ PredPropByAtom (Atom at, Term cur_mod)
|
||||
return Yap_NewPredPropByAtom (ae, cur_mod);
|
||||
}
|
||||
|
||||
EXTERN inline Prop
|
||||
PredPropByAtomAndMod (Atom at, Term cur_mod)
|
||||
/* get predicate entry for ap/arity; create it if neccessary. */
|
||||
{
|
||||
Prop p0;
|
||||
AtomEntry *ae = RepAtom (at);
|
||||
|
||||
WRITE_LOCK (ae->ARWLock);
|
||||
p0 = ae->PropsOfAE;
|
||||
while (p0)
|
||||
{
|
||||
PredEntry *pe = RepPredProp (p0);
|
||||
if (pe->KindOfPE == PEProp &&
|
||||
(pe->ModuleOfPred == cur_mod))
|
||||
{
|
||||
#ifdef THREADS
|
||||
/* Thread Local Predicates */
|
||||
if (pe->PredFlags & ThreadLocalPredFlag)
|
||||
{
|
||||
WRITE_UNLOCK (ae->ARWLock);
|
||||
return AbsPredProp (Yap_GetThreadPred (pe INIT_REGS));
|
||||
}
|
||||
#endif
|
||||
WRITE_UNLOCK (ae->ARWLock);
|
||||
return (p0);
|
||||
}
|
||||
p0 = pe->NextOfPE;
|
||||
}
|
||||
return Yap_NewPredPropByAtom (ae, cur_mod);
|
||||
}
|
||||
|
||||
#if DEBUG_PELOCKING
|
||||
#define PELOCK(I,Z) \
|
||||
{ LOCK((Z)->PELock); (Z)->StatisticsForPred.NOfEntries=(I);(Z)->StatisticsForPred.NOfHeadSuccesses=pthread_self(); }
|
||||
|
Reference in New Issue
Block a user