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

View File

@ -486,6 +486,7 @@ Yap_InitCPred(char *Name, unsigned long int Arity, CPredicate code, int flags)
PredEntry *pe = NULL;
yamop *p_code;
StaticClause *cl = NULL;
Functor f = NULL;
while (atom == NIL) {
atom = Yap_FullLookupAtom(Name);
@ -494,9 +495,18 @@ Yap_InitCPred(char *Name, unsigned long int Arity, CPredicate code, int flags)
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) {
if (Arity)
pe = RepPredProp(PredPropByFunc(Yap_MkFunctor(atom, Arity),CurrentModule));
pe = RepPredProp(PredPropByFunc(f,CurrentModule));
else
pe = RepPredProp(PredPropByAtom(atom,CurrentModule));
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;
yamop *p_code = NULL;
StaticClause *cl = NULL;
Functor f = NULL;
while (atom == NIL) {
atom = Yap_FullLookupAtom(Name);
@ -583,9 +594,18 @@ Yap_InitCmpPred(char *Name, unsigned long int Arity, CmpPredicate cmp_code, int
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) {
if (Arity)
pe = RepPredProp(PredPropByFunc(Yap_MkFunctor(atom, Arity),CurrentModule));
pe = RepPredProp(PredPropByFunc(f,CurrentModule));
else
pe = RepPredProp(PredPropByAtom(atom,CurrentModule));
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;
PredEntry *pe = NULL;
Functor f = NULL;
while (atom == NIL) {
atom = Yap_FullLookupAtom(Name);
@ -647,9 +668,18 @@ Yap_InitAsmPred(char *Name, unsigned long int Arity, int code, CPredicate def,
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) {
if (Arity)
pe = RepPredProp(PredPropByFunc(Yap_MkFunctor(atom, Arity),CurrentModule));
pe = RepPredProp(PredPropByFunc(f,CurrentModule));
else
pe = RepPredProp(PredPropByAtom(atom,CurrentModule));
if (!pe && !Yap_growheap(FALSE, sizeof(PredEntry), NULL)) {
@ -772,6 +802,7 @@ Yap_InitCPredBack(char *Name, unsigned long int Arity,
{
PredEntry *pe = NULL;
Atom atom = NIL;
Functor f = NULL;
while (atom == NIL) {
atom = Yap_FullLookupAtom(Name);
@ -780,9 +811,18 @@ Yap_InitCPredBack(char *Name, unsigned long int Arity,
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) {
if (Arity)
pe = RepPredProp(PredPropByFunc(Yap_MkFunctor(atom, Arity),CurrentModule));
pe = RepPredProp(PredPropByFunc(f,CurrentModule));
else
pe = RepPredProp(PredPropByAtom(atom,CurrentModule));
if (!pe && !Yap_growheap(FALSE, sizeof(PredEntry), NULL)) {