fix overflow bug

This commit is contained in:
Vítor Santos de Costa 2008-10-07 23:52:26 +01:00
parent 2cdcf87044
commit 444fc8fb7f
2 changed files with 67 additions and 4 deletions

View File

@ -713,6 +713,9 @@ Yap_NewThreadPred(PredEntry *ap)
{ {
PredEntry *p = (PredEntry *) Yap_AllocAtomSpace(sizeof(*p)); PredEntry *p = (PredEntry *) Yap_AllocAtomSpace(sizeof(*p));
if (p == NULL) {
return NULL;
}
INIT_LOCK(p->PELock); INIT_LOCK(p->PELock);
p->KindOfPE = PEProp; p->KindOfPE = PEProp;
p->ArityOfPE = ap->ArityOfPE; p->ArityOfPE = ap->ArityOfPE;
@ -923,6 +926,10 @@ Yap_PutValue(Atom a, Term v)
WRITE_UNLOCK(ae->ARWLock); WRITE_UNLOCK(ae->ARWLock);
} else { } else {
p = (ValEntry *) Yap_AllocAtomSpace(sizeof(ValEntry)); p = (ValEntry *) Yap_AllocAtomSpace(sizeof(ValEntry));
if (p == NULL) {
WRITE_UNLOCK(ae->ARWLock);
return;
}
p->NextOfPE = RepAtom(a)->PropsOfAE; p->NextOfPE = RepAtom(a)->PropsOfAE;
RepAtom(a)->PropsOfAE = AbsValProp(p); RepAtom(a)->PropsOfAE = AbsValProp(p);
p->KindOfPE = ValProperty; p->KindOfPE = ValProperty;
@ -951,6 +958,10 @@ Yap_PutValue(Atom a, Term v)
Yap_FreeCodeSpace((char *) (RepAppl(t0))); Yap_FreeCodeSpace((char *) (RepAppl(t0)));
} }
pt = (CELL *) Yap_AllocAtomSpace(sizeof(CELL)*(1 + 2*sizeof(Float)/sizeof(CELL))); pt = (CELL *) Yap_AllocAtomSpace(sizeof(CELL)*(1 + 2*sizeof(Float)/sizeof(CELL)));
if (pt == NULL) {
WRITE_UNLOCK(ae->ARWLock);
return;
}
p->ValueOfVE = AbsAppl(pt); p->ValueOfVE = AbsAppl(pt);
pt[0] = (CELL)FunctorDouble; pt[0] = (CELL)FunctorDouble;
} }
@ -970,6 +981,10 @@ Yap_PutValue(Atom a, Term v)
Yap_FreeCodeSpace((char *) (RepAppl(t0))); Yap_FreeCodeSpace((char *) (RepAppl(t0)));
} }
pt = (CELL *) Yap_AllocAtomSpace(2*sizeof(CELL)); pt = (CELL *) Yap_AllocAtomSpace(2*sizeof(CELL));
if (pt == NULL) {
WRITE_UNLOCK(ae->ARWLock);
return;
}
p->ValueOfVE = AbsAppl(pt); p->ValueOfVE = AbsAppl(pt);
pt[0] = (CELL)FunctorLongInt; pt[0] = (CELL)FunctorLongInt;
} }
@ -981,6 +996,11 @@ Yap_PutValue(Atom a, Term v)
sizeof(MP_INT)+sizeof(CELL)+ sizeof(MP_INT)+sizeof(CELL)+
(((MP_INT *)(ap+1))->_mp_alloc*sizeof(mp_limb_t)); (((MP_INT *)(ap+1))->_mp_alloc*sizeof(mp_limb_t));
CELL *pt = (CELL *) Yap_AllocAtomSpace(sz); CELL *pt = (CELL *) Yap_AllocAtomSpace(sz);
if (pt == NULL) {
WRITE_UNLOCK(ae->ARWLock);
return;
}
if (IsApplTerm(t0)) { if (IsApplTerm(t0)) {
Yap_FreeCodeSpace((char *) RepAppl(t0)); Yap_FreeCodeSpace((char *) RepAppl(t0));
} }
@ -1292,6 +1312,9 @@ HoldEntry *
Yap_InitAtomHold(void) Yap_InitAtomHold(void)
{ {
HoldEntry *x = (HoldEntry *)Yap_AllocAtomSpace(sizeof(struct hold_entry)); HoldEntry *x = (HoldEntry *)Yap_AllocAtomSpace(sizeof(struct hold_entry));
if (x == NULL) {
return NULL;
}
x->KindOfPE = HoldProperty; x->KindOfPE = HoldProperty;
x->NextOfPE = NIL; x->NextOfPE = NIL;
return x; return x;

View File

@ -486,6 +486,7 @@ Yap_InitCPred(char *Name, unsigned long int Arity, CPredicate code, int flags)
PredEntry *pe = NULL; PredEntry *pe = NULL;
yamop *p_code; yamop *p_code;
StaticClause *cl = NULL; StaticClause *cl = NULL;
Functor f = NULL;
while (atom == NIL) { while (atom == NIL) {
atom = Yap_FullLookupAtom(Name); atom = Yap_FullLookupAtom(Name);
@ -494,9 +495,18 @@ Yap_InitCPred(char *Name, unsigned long int Arity, CPredicate code, int flags)
return; return;
} }
} }
if (Arity) {
while (!f) {
f = Yap_MkFunctor(atom,Arity);
if (!f && !Yap_growheap(FALSE, 0L, NULL)) {
Yap_Error(OUT_OF_HEAP_ERROR,TermNil,"while initialising %s", Name);
return;
}
}
}
while (pe == NULL) { while (pe == NULL) {
if (Arity) if (Arity)
pe = RepPredProp(PredPropByFunc(Yap_MkFunctor(atom, Arity),CurrentModule)); pe = RepPredProp(PredPropByFunc(f,CurrentModule));
else else
pe = RepPredProp(PredPropByAtom(atom,CurrentModule)); pe = RepPredProp(PredPropByAtom(atom,CurrentModule));
if (!pe && !Yap_growheap(FALSE, sizeof(PredEntry), NULL)) { if (!pe && !Yap_growheap(FALSE, sizeof(PredEntry), NULL)) {
@ -575,6 +585,7 @@ Yap_InitCmpPred(char *Name, unsigned long int Arity, CmpPredicate cmp_code, int
PredEntry *pe = NULL; PredEntry *pe = NULL;
yamop *p_code = NULL; yamop *p_code = NULL;
StaticClause *cl = NULL; StaticClause *cl = NULL;
Functor f = NULL;
while (atom == NIL) { while (atom == NIL) {
atom = Yap_FullLookupAtom(Name); atom = Yap_FullLookupAtom(Name);
@ -583,9 +594,18 @@ Yap_InitCmpPred(char *Name, unsigned long int Arity, CmpPredicate cmp_code, int
return; return;
} }
} }
if (Arity) {
while (!f) {
f = Yap_MkFunctor(atom,Arity);
if (!f && !Yap_growheap(FALSE, 0L, NULL)) {
Yap_Error(OUT_OF_HEAP_ERROR,TermNil,"while initialising %s", Name);
return;
}
}
}
while (pe == NULL) { while (pe == NULL) {
if (Arity) if (Arity)
pe = RepPredProp(PredPropByFunc(Yap_MkFunctor(atom, Arity),CurrentModule)); pe = RepPredProp(PredPropByFunc(f,CurrentModule));
else else
pe = RepPredProp(PredPropByAtom(atom,CurrentModule)); pe = RepPredProp(PredPropByAtom(atom,CurrentModule));
if (!pe && !Yap_growheap(FALSE, sizeof(PredEntry), NULL)) { if (!pe && !Yap_growheap(FALSE, sizeof(PredEntry), NULL)) {
@ -639,6 +659,7 @@ Yap_InitAsmPred(char *Name, unsigned long int Arity, int code, CPredicate def,
{ {
Atom atom = NIL; Atom atom = NIL;
PredEntry *pe = NULL; PredEntry *pe = NULL;
Functor f = NULL;
while (atom == NIL) { while (atom == NIL) {
atom = Yap_FullLookupAtom(Name); atom = Yap_FullLookupAtom(Name);
@ -647,9 +668,18 @@ Yap_InitAsmPred(char *Name, unsigned long int Arity, int code, CPredicate def,
return; return;
} }
} }
if (Arity) {
while (!f) {
f = Yap_MkFunctor(atom,Arity);
if (!f && !Yap_growheap(FALSE, 0L, NULL)) {
Yap_Error(OUT_OF_HEAP_ERROR,TermNil,"while initialising %s", Name);
return;
}
}
}
while (pe == NULL) { while (pe == NULL) {
if (Arity) if (Arity)
pe = RepPredProp(PredPropByFunc(Yap_MkFunctor(atom, Arity),CurrentModule)); pe = RepPredProp(PredPropByFunc(f,CurrentModule));
else else
pe = RepPredProp(PredPropByAtom(atom,CurrentModule)); pe = RepPredProp(PredPropByAtom(atom,CurrentModule));
if (!pe && !Yap_growheap(FALSE, sizeof(PredEntry), NULL)) { if (!pe && !Yap_growheap(FALSE, sizeof(PredEntry), NULL)) {
@ -772,6 +802,7 @@ Yap_InitCPredBack(char *Name, unsigned long int Arity,
{ {
PredEntry *pe = NULL; PredEntry *pe = NULL;
Atom atom = NIL; Atom atom = NIL;
Functor f = NULL;
while (atom == NIL) { while (atom == NIL) {
atom = Yap_FullLookupAtom(Name); atom = Yap_FullLookupAtom(Name);
@ -780,9 +811,18 @@ Yap_InitCPredBack(char *Name, unsigned long int Arity,
return; return;
} }
} }
if (Arity) {
while (!f) {
f = Yap_MkFunctor(atom,Arity);
if (!f && !Yap_growheap(FALSE, 0L, NULL)) {
Yap_Error(OUT_OF_HEAP_ERROR,TermNil,"while initialising %s", Name);
return;
}
}
}
while (pe == NULL) { while (pe == NULL) {
if (Arity) if (Arity)
pe = RepPredProp(PredPropByFunc(Yap_MkFunctor(atom, Arity),CurrentModule)); pe = RepPredProp(PredPropByFunc(f,CurrentModule));
else else
pe = RepPredProp(PredPropByAtom(atom,CurrentModule)); pe = RepPredProp(PredPropByAtom(atom,CurrentModule));
if (!pe && !Yap_growheap(FALSE, sizeof(PredEntry), NULL)) { if (!pe && !Yap_growheap(FALSE, sizeof(PredEntry), NULL)) {