error handling
This commit is contained in:
parent
0dd8f62237
commit
7d44e3188b
29
C/adtdefs.c
29
C/adtdefs.c
@ -27,23 +27,23 @@ static char SccsId[] = "%W% %G%";
|
||||
|
||||
#include "Yap.h"
|
||||
#include "Yatom.h"
|
||||
#include "yapio.h"
|
||||
#include "clause.h"
|
||||
#include "yapio.h"
|
||||
#include <stdio.h>
|
||||
#include <wchar.h>
|
||||
#if HAVE_STRING_Hq
|
||||
#include <string.h>
|
||||
#endif
|
||||
|
||||
uint64_t HashFunction(const unsigned char *CHP) {
|
||||
uint64_t HashFunction(const unsigned char *CHP) {
|
||||
/* djb2 */
|
||||
uint64_t hash = 5381;
|
||||
uint64_t c;
|
||||
|
||||
while ((c = (uint64_t)(*CHP++)) != '\0') {
|
||||
while ((c = *CHP++) != '\0') {
|
||||
/* hash = ((hash << 5) + hash) + c; hash * 33 + c */
|
||||
hash = hash * (uint64_t)33 + c;
|
||||
}
|
||||
}
|
||||
return hash;
|
||||
/*
|
||||
UInt OUT=0, i = 1;
|
||||
@ -63,7 +63,6 @@ uint64_t WideHashFunction(wchar_t *CHP) {
|
||||
return hash;
|
||||
}
|
||||
|
||||
|
||||
/* this routine must be run at least having a read lock on ae */
|
||||
static Prop
|
||||
GetFunctorProp(AtomEntry *ae,
|
||||
@ -78,8 +77,7 @@ GetFunctorProp(AtomEntry *ae,
|
||||
}
|
||||
|
||||
/* vsc: We must guarantee that IsVarTerm(functor) returns true! */
|
||||
static inline Functor InlinedUnlockedMkFunctor(AtomEntry *ae,
|
||||
arity_t arity) {
|
||||
static inline Functor InlinedUnlockedMkFunctor(AtomEntry *ae, arity_t arity) {
|
||||
FunctorEntry *p;
|
||||
Prop p0;
|
||||
|
||||
@ -174,7 +172,7 @@ static Atom
|
||||
LookupAtom(const unsigned char *atom) { /* lookup atom in atom table */
|
||||
uint64_t hash;
|
||||
const unsigned char *p;
|
||||
Atom a, na;
|
||||
Atom a, na = NIL;
|
||||
AtomEntry *ae;
|
||||
size_t sz = AtomHashTableSize;
|
||||
|
||||
@ -182,7 +180,7 @@ LookupAtom(const unsigned char *atom) { /* lookup atom in atom table */
|
||||
p = atom;
|
||||
|
||||
hash = HashFunction(p);
|
||||
hash = hash % sz ;
|
||||
hash = hash % sz;
|
||||
|
||||
/* we'll start by holding a read lock in order to avoid contention */
|
||||
READ_LOCK(HashChain[hash].AERWLock);
|
||||
@ -346,7 +344,7 @@ Atom Yap_LookupMaybeWideAtomWithLength(
|
||||
ptr0 = (wchar_t *)Yap_AllocCodeSpace(sizeof(wchar_t) * (len0 + 2));
|
||||
if (!ptr0)
|
||||
return NIL;
|
||||
memcpy(ptr0, atom, (len0+1) * sizeof(wchar_t));
|
||||
memcpy(ptr0, atom, (len0 + 1) * sizeof(wchar_t));
|
||||
ptr0[len0] = '\0';
|
||||
at = LookupWideAtom(ptr0);
|
||||
Yap_FreeCodeSpace((char *)ptr0);
|
||||
@ -566,10 +564,8 @@ Yap_OpPropForModule(Atom a,
|
||||
}
|
||||
|
||||
OpEntry *
|
||||
Yap_GetOpProp(Atom a,
|
||||
op_type type,
|
||||
Term cmod
|
||||
USES_REGS) { /* look property list of atom a for kind */
|
||||
Yap_GetOpProp(Atom a, op_type type,
|
||||
Term cmod USES_REGS) { /* look property list of atom a for kind */
|
||||
AtomEntry *ae = RepAtom(a);
|
||||
PropEntry *pp;
|
||||
OpEntry *oinfo = NULL;
|
||||
@ -801,7 +797,7 @@ Prop Yap_NewPredPropByFunctor(FunctorEntry *fe, Term cur_mod) {
|
||||
p->ModuleOfPred = 0L;
|
||||
} else
|
||||
p->ModuleOfPred = cur_mod;
|
||||
// TRUE_FUNC_WRITE_LOCK(fe);
|
||||
// TRUE_FUNC_WRITE_LOCK(fe);
|
||||
INIT_LOCK(p->PELock);
|
||||
p->KindOfPE = PEProp;
|
||||
p->ArityOfPE = fe->ArityOfFE;
|
||||
@ -888,8 +884,7 @@ Prop Yap_NewThreadPred(PredEntry *ap USES_REGS) {
|
||||
return NIL;
|
||||
}
|
||||
INIT_LOCK(p->PELock);
|
||||
p->StatisticsForPred = NULL:
|
||||
p->KindOfPE = PEProp;
|
||||
p->StatisticsForPred = NULL : p->KindOfPE = PEProp;
|
||||
p->ArityOfPE = ap->ArityOfPE;
|
||||
p->cs.p_code.FirstClause = p->cs.p_code.LastClause = NULL;
|
||||
p->cs.p_code.NOfClauses = 0;
|
||||
|
@ -93,6 +93,10 @@ arrays. Memory mapped arrays are limited by available space in the file
|
||||
system and in the virtual memory space.
|
||||
|
||||
The following predicates manipulate arrays:
|
||||
|
||||
|
||||
|
||||
|
||||
*/
|
||||
|
||||
#include "Yap.h"
|
||||
@ -100,6 +104,11 @@ The following predicates manipulate arrays:
|
||||
#include "clause.h"
|
||||
#include "eval.h"
|
||||
#include "heapgc.h"
|
||||
#if HAVE_ERRNO_H
|
||||
#include <errno.h>
|
||||
#else
|
||||
extern int errno;
|
||||
#endif
|
||||
#if HAVE_STRING_H
|
||||
#include <string.h>
|
||||
#endif
|
||||
|
51
C/dbase.c
51
C/dbase.c
@ -97,10 +97,10 @@ stored in the i.d.b.
|
||||
*/
|
||||
|
||||
#include "Yap.h"
|
||||
#include "clause.h"
|
||||
#include "yapio.h"
|
||||
#include "attvar.h"
|
||||
#include "clause.h"
|
||||
#include "heapgc.h"
|
||||
#include "yapio.h"
|
||||
#if HAVE_STRING_H
|
||||
#include <string.h>
|
||||
#endif
|
||||
@ -712,15 +712,22 @@ loop:
|
||||
f = (Functor)(*ap2);
|
||||
if (IsExtensionFunctor(f)) {
|
||||
switch ((CELL)f) {
|
||||
case (CELL) FunctorDBRef: {
|
||||
case (CELL)FunctorDBRef: {
|
||||
DBRef dbentry;
|
||||
/* store now the correct entry */
|
||||
|
||||
dbentry = DBRefOfTerm(d0);
|
||||
*StoPoint++ = d0;
|
||||
dbg->lr--;
|
||||
if (dbentry->Flags & LogUpdMask) {
|
||||
LogUpdClause *cl = (LogUpdClause *)dbentry;
|
||||
|
||||
/* store now the correct entry */
|
||||
#if DEBUG
|
||||
if (GLOBAL_Option['i' - 'a' + 1]) {
|
||||
Yap_DebugPlWriteln(d0);
|
||||
fprintf(stderr, "+%p@%p %s\n", cl, cl->ClPred,
|
||||
IndicatorOfPred(cl->ClPred));
|
||||
}
|
||||
#endif
|
||||
cl->ClRefCount++;
|
||||
} else {
|
||||
dbentry->NOfRefsTo++;
|
||||
@ -731,14 +738,14 @@ loop:
|
||||
++pt0;
|
||||
continue;
|
||||
}
|
||||
case (CELL) FunctorLongInt:
|
||||
case (CELL)FunctorLongInt:
|
||||
CheckDBOverflow(3);
|
||||
*StoPoint++ = AbsAppl(CodeMax);
|
||||
CodeMax = copy_long_int(CodeMax, ap2);
|
||||
++pt0;
|
||||
continue;
|
||||
#ifdef USE_GMP
|
||||
case (CELL) FunctorBigInt:
|
||||
case (CELL)FunctorBigInt:
|
||||
CheckDBOverflow(3 + Yap_SizeOfBigInt(d0));
|
||||
/* first thing, store a link to the list before we move on */
|
||||
*StoPoint++ = AbsAppl(CodeMax);
|
||||
@ -746,7 +753,7 @@ loop:
|
||||
++pt0;
|
||||
continue;
|
||||
#endif
|
||||
case (CELL) FunctorString: {
|
||||
case (CELL)FunctorString: {
|
||||
CELL *st = CodeMax;
|
||||
|
||||
CheckDBOverflow(3 + ap2[1]);
|
||||
@ -756,7 +763,7 @@ loop:
|
||||
++pt0;
|
||||
continue;
|
||||
}
|
||||
case (CELL) FunctorDouble: {
|
||||
case (CELL)FunctorDouble: {
|
||||
CELL *st = CodeMax;
|
||||
|
||||
CheckDBOverflow(4);
|
||||
@ -1340,7 +1347,7 @@ static DBRef CreateDBRefForAtom(Term Tm, DBProp p, int InFlag,
|
||||
UInt sz = DBLength(NIL);
|
||||
|
||||
flag = DBAtomic;
|
||||
if (InFlag &MkIfNot && (dbg->found_one = check_if_cons(p->First, Tm)))
|
||||
if (InFlag & MkIfNot && (dbg->found_one = check_if_cons(p->First, Tm)))
|
||||
return dbg->found_one;
|
||||
pp = AllocDBSpace(sz);
|
||||
if (pp == NIL) {
|
||||
@ -1368,7 +1375,7 @@ static DBRef CreateDBRefForVar(Term Tm, DBProp p, int InFlag,
|
||||
Register DBRef pp;
|
||||
UInt sz = DBLength(NULL);
|
||||
|
||||
if (InFlag &MkIfNot && (dbg->found_one = check_if_var(p->First)))
|
||||
if (InFlag & MkIfNot && (dbg->found_one = check_if_var(p->First)))
|
||||
return dbg->found_one;
|
||||
pp = AllocDBSpace(sz);
|
||||
if (pp == NULL) {
|
||||
@ -1499,17 +1506,17 @@ static DBRef CreateDBStruct(Term Tm, DBProp p, int InFlag, int *pstat,
|
||||
fun = FunctorOfTerm(Tm);
|
||||
if (IsExtensionFunctor(fun)) {
|
||||
switch ((CELL)fun) {
|
||||
case (CELL) FunctorDouble:
|
||||
case (CELL)FunctorDouble:
|
||||
ntp = copy_double(ntp0, RepAppl(Tm));
|
||||
break;
|
||||
case (CELL) FunctorString:
|
||||
case (CELL)FunctorString:
|
||||
ntp = copy_string(ntp0, RepAppl(Tm));
|
||||
break;
|
||||
case (CELL) FunctorDBRef:
|
||||
case (CELL)FunctorDBRef:
|
||||
Yap_ReleasePreAllocCodeSpace((ADDR)pp0);
|
||||
return CreateDBWithDBRef(Tm, p, dbg);
|
||||
#ifdef USE_GMP
|
||||
case (CELL) FunctorBigInt:
|
||||
case (CELL)FunctorBigInt:
|
||||
ntp = copy_big_int(ntp0, RepAppl(Tm));
|
||||
break;
|
||||
#endif
|
||||
@ -2503,8 +2510,8 @@ static Term GetDBTerm(DBTerm *DBSP, int src USES_REGS) {
|
||||
CalculateStackGap(PASS_REGS1);
|
||||
if (HR + NOf > ASP - EventFlag / sizeof(CELL)) {
|
||||
if (LOCAL_PrologMode & InErrorMode) {
|
||||
LOCAL_PrologMode &= ~InErrorMode;
|
||||
if (HR + NOf > ASP)
|
||||
LOCAL_PrologMode &= ~InErrorMode;
|
||||
if (HR + NOf > ASP)
|
||||
fprintf(stderr,
|
||||
"\n\n [ FATAL ERROR: No Stack for Error Handling ]\n");
|
||||
Yap_exit(1);
|
||||
@ -2714,9 +2721,9 @@ static PredEntry *new_lu_entry(Term t) {
|
||||
pe->PredFlags |= LogUpdatePredFlag;
|
||||
if (IsAtomTerm(t)) {
|
||||
pe->PredFlags |= AtomDBPredFlag;
|
||||
pe->FunctorOfPred = (Functor)AtomOfTerm(t);
|
||||
pe->FunctorOfPred = (Functor)AtomOfTerm(t);
|
||||
} else {
|
||||
pe->FunctorOfPred = FunctorOfTerm(t);
|
||||
pe->FunctorOfPred = FunctorOfTerm(t);
|
||||
}
|
||||
pe->ArityOfPE = 3;
|
||||
pe->OpcodeOfPred = Yap_opcode(_op_fail);
|
||||
@ -2753,7 +2760,7 @@ static DBProp find_entry(Term t) {
|
||||
arity = 2;
|
||||
}
|
||||
DBProp rc = RepDBProp(FindDBProp(RepAtom(at), 0, arity, 0));
|
||||
return rc;
|
||||
return rc;
|
||||
}
|
||||
|
||||
static PredEntry *find_lu_entry(Term t) {
|
||||
@ -3971,7 +3978,7 @@ static void EraseLogUpdCl(LogUpdClause *clau) {
|
||||
}
|
||||
}
|
||||
clau->ClTimeEnd = ap->TimeStampOfPred;
|
||||
Yap_RemoveClauseFromIndex(ap, clau->ClCode);
|
||||
Yap_RemoveClauseFromIndex(ap, clau->ClCode);
|
||||
/* release the extra reference */
|
||||
}
|
||||
clau->ClRefCount--;
|
||||
@ -4266,7 +4273,7 @@ static Int p_current_reference_counter(USES_REGS1) {
|
||||
Yap_Error(INSTANTIATION_ERROR, t1, "increase_reference_counter/1");
|
||||
return FALSE;
|
||||
}
|
||||
if (!IsDBRefTerm(t1)) {
|
||||
if (!IsDBRefTerm(t1)) {
|
||||
Yap_Error(TYPE_ERROR_DBREF, t1, "increase_reference_counter");
|
||||
return FALSE;
|
||||
}
|
||||
|
Reference in New Issue
Block a user