more fixes

This commit is contained in:
Vitor Santos Costa 2018-04-17 17:47:40 +01:00
parent 7bfe8aedbe
commit 4b1efa59b4
10 changed files with 58 additions and 61 deletions

View File

@ -699,13 +699,11 @@ restart_aux:
t1 = Deref(ARG1); t1 = Deref(ARG1);
if (IsNumTerm(t1)) { if (IsNumTerm(t1)) {
Term t2 = Deref(ARG2); Term t2 = Deref(ARG2);
if (IsVarTerm(t2)) { Term t12 = Yap_NumberToListOfAtoms(t1 PASS_REGS);
t1 = Yap_NumberToListOfAtoms(t1 PASS_REGS); if (t12) {
}
if (t1) {
{ {
pop_text_stack(l); pop_text_stack(l);
return Yap_unify(t1, t2); return Yap_unify(t12, t2);
} }
} }
} else if (IsVarTerm(t1)) { } else if (IsVarTerm(t1)) {

View File

@ -300,7 +300,10 @@ void Yap_InitError__(const char *file, const char *function, int lineno,
return; return;
va_end(ap); va_end(ap);
if (LOCAL_ActiveError->errorNo != YAP_NO_ERROR) { if (LOCAL_ActiveError->errorNo != YAP_NO_ERROR) {
Yap_exit(1); yap_error_number err = LOCAL_ActiveError->errorNo;
fprintf(stderr, "%% Warning %s WITHIN ERROR %s %s\n", Yap_errorName(e),
Yap_errorClassName(Yap_errorClass(err)), Yap_errorName(err));
return;
} }
LOCAL_ActiveError->errorNo = e; LOCAL_ActiveError->errorNo = e;
LOCAL_ActiveError->errorFile = NULL; LOCAL_ActiveError->errorFile = NULL;
@ -401,6 +404,8 @@ bool Yap_HandleError__(const char *file, const char *function, int lineno,
if (LOCAL_PrologMode == UserMode) if (LOCAL_PrologMode == UserMode)
Yap_Error__(false, file, function, lineno, err, TermNil, serr); Yap_Error__(false, file, function, lineno, err, TermNil, serr);
else
LOCAL_PrologMode &= ~InErrorMode;
return false; return false;
} }
} }
@ -492,6 +497,7 @@ static char tmpbuf[YAP_BUF_SIZE];
#undef BEGIN_ERRORS #undef BEGIN_ERRORS
#undef E0 #undef E0
#undef E #undef E
#undef E1
#undef E2 #undef E2
#undef END_ERRORS #undef END_ERRORS
@ -531,6 +537,16 @@ static char tmpbuf[YAP_BUF_SIZE];
return Yap_MkApplTerm(FunctorError, 2, ft); \ return Yap_MkApplTerm(FunctorError, 2, ft); \
} }
#define E1(A, B, C) \
case A: { \
Term ft[2], nt[1]; \
nt[0] = MkVarTerm(); \
Yap_unify(nt[0], culprit); \
ft[0] = Yap_MkApplTerm(Yap_MkFunctor(Yap_LookupAtom(C), 1),1 , nt); \
ft[1] = info; \
return Yap_MkApplTerm(FunctorError, 2, ft); \
}
#define E2(A, B, C, D) \ #define E2(A, B, C, D) \
case A: { \ case A: { \
Term ft[2], nt[3]; \ Term ft[2], nt[3]; \
@ -864,6 +880,7 @@ static Int close_error(USES_REGS1) {
#undef BEGIN_ERRORS #undef BEGIN_ERRORS
#undef E0 #undef E0
#undef E #undef E
#undef E1
#undef E2 #undef E2
#undef END_ERRORS #undef END_ERRORS
@ -878,6 +895,7 @@ static Int close_error(USES_REGS1) {
#define BEGIN_ERRORS() #define BEGIN_ERRORS()
#define E0(X, Y) #define E0(X, Y)
#define E(X, Y, Z) #define E(X, Y, Z)
#define E1(X, Y, Z)
#define E2(X, Y, Z, W) #define E2(X, Y, Z, W)
#define END_ERRORS() #define END_ERRORS()
@ -889,6 +907,7 @@ static Int close_error(USES_REGS1) {
#undef BEGIN_ERRORS #undef BEGIN_ERRORS
#undef E0 #undef E0
#undef E #undef E
#undef E1
#undef E2 #undef E2
#undef END_ERRORS #undef END_ERRORS
@ -908,6 +927,7 @@ typedef struct c_error_info {
#define BEGIN_ERRORS() static struct c_error_info c_error_list[] = { #define BEGIN_ERRORS() static struct c_error_info c_error_list[] = {
#define E0(X, Y) {Y##__, ""}, #define E0(X, Y) {Y##__, ""},
#define E(X, Y, Z) {Y##__, Z}, #define E(X, Y, Z) {Y##__, Z},
#define E1(X, Y, Z) {Y##__, Z},
#define E2(X, Y, Z, W) {Y##__, Z " " W}, #define E2(X, Y, Z, W) {Y##__, Z " " W},
#define END_ERRORS() \ #define END_ERRORS() \
{ YAPC_NO_ERROR, "" } \ { YAPC_NO_ERROR, "" } \
@ -1028,10 +1048,7 @@ static Int get_exception(USES_REGS1) {
} else { } else {
t = mkerrort(i->errorNo, TermNil, MkSysError(i)); t = mkerrort(i->errorNo, TermNil, MkSysError(i));
} }
while (B && B->cp_b && ! Yap_unify(t, B->cp_a2)) { return Yap_unify(ARG1,t);
Yap_JumpToEnv();
}
return true;
} }
return false; return false;
} }
@ -1055,40 +1072,13 @@ yap_error_descriptor_t *Yap_UserError(Term t, yap_error_descriptor_t *i) {
LOCAL_ActiveError->errorRawTerm = Yap_SaveTerm(t); LOCAL_ActiveError->errorRawTerm = Yap_SaveTerm(t);
LOCAL_ActiveError->culprit = NULL; LOCAL_ActiveError->culprit = NULL;
} else { } else {
char ename[65];
Term t1, t2; Term t1, t2;
t1 = ArgOfTerm(1, t); t1 = ArgOfTerm(1, t);
t2 = ArgOfTerm(2, t); t2 = ArgOfTerm(2, t);
// LOCAL_Error_TYPE = ERROR_EVENT; // LOCAL_Error_TYPE = ERROR_EVENT;
i->errorNo = ERROR_EVENT; wellformed = wellformed && ( i->errorAsText != NULL );
i->errorClass = EVENT;
if (IsApplTerm(t1)) {
Functor f1 = FunctorOfTerm(t1);
arity_t a1 = ArityOfFunctor(f1);
i->errorAsText = ename;
i->classAsText = RepAtom(NameOfFunctor(f1))->StrOfAE;
if (a1 == 1) {
wellformed = false;
} else {
Term ti;
if (!IsAtomTerm((ti = ArgOfTerm(1, t1)))) {
wellformed = false;
}
strncpy(ename, RepAtom(AtomOfTerm(ti))->StrOfAE, 64);
}
if (a1 == 3) {
Term ti;
if (!IsAtomTerm((ti = ArgOfTerm(2, t1))))
wellformed = false;
strncat(ename, " ", 64);
strncat(ename, RepAtom(AtomOfTerm(ti))->StrOfAE, 64);
} else if (a1 > 3) {
wellformed = false;
}
i->culprit =
Yap_TermToBuffer(ArgOfTerm(a1, t1), ENC_ISO_UTF8, Quote_illegal_f | Ignore_ops_f | Unfold_cyclics_f);
int j;
if (wellformed) { if (wellformed) {
int j;
for (j = 0; j < sizeof(c_error_list) / sizeof(struct c_error_info); j++) { for (j = 0; j < sizeof(c_error_list) / sizeof(struct c_error_info); j++) {
if (!strcmp(c_error_list[j].name, i->errorAsText) && if (!strcmp(c_error_list[j].name, i->errorAsText) &&
(c_error_list[j].class == 0 || (c_error_list[j].class == 0 ||
@ -1106,7 +1096,6 @@ yap_error_descriptor_t *Yap_UserError(Term t, yap_error_descriptor_t *i) {
} }
} }
} }
}
} else if (IsAtomTerm(t1)) { } else if (IsAtomTerm(t1)) {
const char *err = RepAtom(AtomOfTerm(t1))->StrOfAE; const char *err = RepAtom(AtomOfTerm(t1))->StrOfAE;
if (!strcmp(err, "instantiation_error")) { if (!strcmp(err, "instantiation_error")) {

View File

@ -1397,7 +1397,7 @@ static bool exec_absmi(bool top, yap_reset_t reset_mode USES_REGS) {
sigjmp_buf signew, *sighold = LOCAL_RestartEnv; sigjmp_buf signew, *sighold = LOCAL_RestartEnv;
LOCAL_RestartEnv = &signew; LOCAL_RestartEnv = &signew;
if (top && (lval = sigsetjmp(signew, 1)) != 0) { if /* top &&*/( (lval = sigsetjmp(signew, 1)) != 0) {
switch (lval) { switch (lval) {
case 1: { /* restart */ case 1: { /* restart */
/* otherwise, SetDBForThrow will fail entering critical mode */ /* otherwise, SetDBForThrow will fail entering critical mode */
@ -1469,7 +1469,6 @@ static bool exec_absmi(bool top, yap_reset_t reset_mode USES_REGS) {
return false; return false;
} }
P = FAILCODE; P = FAILCODE;
} }
} }
YENV = ASP; YENV = ASP;

View File

@ -735,12 +735,7 @@ static size_t write_length(const unsigned char *s0, seq_tv_t *out USES_REGS) {
static Term write_number(unsigned char *s, seq_tv_t *out, static Term write_number(unsigned char *s, seq_tv_t *out,
bool error_on USES_REGS) { bool error_on USES_REGS) {
Term t; Term t;
yap_error_descriptor_t new_error;
int i = push_text_stack();
bool new_rec = Yap_pushErrorContext(true,&new_error);
t = Yap_StringToNumberTerm((char *)s, &out->enc,true); t = Yap_StringToNumberTerm((char *)s, &out->enc,true);
pop_text_stack(i);
Yap_popErrorContext(new_rec , true);
return t; return t;
} }

View File

@ -27,15 +27,14 @@ inline static Term sub_int(Int i, Int j USES_REGS) {
#if defined(__clang__ ) || defined(__GNUC__) #if defined(__clang__ ) || defined(__GNUC__)
Int k; Int k;
if (__builtin_sub_overflow(i,j,&k)) { if (__builtin_sub_overflow(i,j,&k)) {
return Yap_gmp_add_ints(i, j); return Yap_gmp_sub_ints(i, j);
} }
printf("%ld %ld %ld\n", i, j , k);
RINT(k); RINT(k);
#elif defined(__GNUC__) #elif defined(__GNUC__)
Int w; Int w;
if (!__builtin_sub_overflow_p(i,j,w)) if (!__builtin_sub_overflow_p(i,j,w))
RINT(w); RINT(w);
return Yap_gmp_add_ints(i, j); return Yap_gmp_sub_ints(i, j);
#else #else
Int x = i - j; Int x = i - j;

View File

@ -19,6 +19,7 @@
#define E0(A, B) A, #define E0(A, B) A,
#define E(A, B, C) A, #define E(A, B, C) A,
#define E1(A, B, C) A,
#define E2(A, B, C, D) A, #define E2(A, B, C, D) A,
#define BEGIN_ERRORS() typedef enum { #define BEGIN_ERRORS() typedef enum {

View File

@ -140,7 +140,7 @@ E(RESOURCE_ERROR_HEAP, RESOURCE_ERROR, "database_space")
E(RESOURCE_ERROR_TRAIL, RESOURCE_ERROR, "trail_space") E(RESOURCE_ERROR_TRAIL, RESOURCE_ERROR, "trail_space")
E(RESOURCE_ERROR_STACK, RESOURCE_ERROR, "stack_space") E(RESOURCE_ERROR_STACK, RESOURCE_ERROR, "stack_space")
E(SYNTAX_ERROR, SYNTAX_ERROR_CLASS, "syntax_error") E1(SYNTAX_ERROR, SYNTAX_ERROR_CLASS, "syntax_error")
E(SYSTEM_ERROR_INTERNAL, SYSTEM_ERROR_CLASS, "internal") E(SYSTEM_ERROR_INTERNAL, SYSTEM_ERROR_CLASS, "internal")
E(SYSTEM_ERROR_COMPILER, SYSTEM_ERROR_CLASS, "compiler") E(SYSTEM_ERROR_COMPILER, SYSTEM_ERROR_CLASS, "compiler")
@ -172,6 +172,7 @@ E(TYPE_ERROR_DBREF, TYPE_ERROR, "dbref")
E(TYPE_ERROR_DBTERM, TYPE_ERROR, "dbterm") E(TYPE_ERROR_DBTERM, TYPE_ERROR, "dbterm")
E(TYPE_ERROR_EVALUABLE, TYPE_ERROR, "evaluable") E(TYPE_ERROR_EVALUABLE, TYPE_ERROR, "evaluable")
E(TYPE_ERROR_FLOAT, TYPE_ERROR, "float") E(TYPE_ERROR_FLOAT, TYPE_ERROR, "float")
E(TYPE_ERROR_IN_BYTE, TYPE_ERROR, "in_byte")
E(TYPE_ERROR_IN_CHARACTER, TYPE_ERROR, "in_character") E(TYPE_ERROR_IN_CHARACTER, TYPE_ERROR, "in_character")
E(TYPE_ERROR_INTEGER, TYPE_ERROR, "integer") E(TYPE_ERROR_INTEGER, TYPE_ERROR, "integer")
E(TYPE_ERROR_KEY, TYPE_ERROR, "key") E(TYPE_ERROR_KEY, TYPE_ERROR, "key")
@ -186,6 +187,6 @@ E(TYPE_ERROR_TEXT, TYPE_ERROR, "text")
E(TYPE_ERROR_UBYTE, TYPE_ERROR, "ubyte") E(TYPE_ERROR_UBYTE, TYPE_ERROR, "ubyte")
E(TYPE_ERROR_UCHAR, TYPE_ERROR, "uchar") E(TYPE_ERROR_UCHAR, TYPE_ERROR, "uchar")
E0(UNINSTANTIATION_ERROR, UNINSTANTIATION_ERROR_CLASS) E1(UNINSTANTIATION_ERROR, UNINSTANTIATION_ERROR_CLASS, "uninstantiation_error")
END_ERRORS(); END_ERRORS();

View File

@ -471,16 +471,22 @@ static Int get0_line_codes(USES_REGS1) { /* '$get0'(Stream,-N) */
/** @pred get_byte(+ _S_,- _C_) is iso /** @pred get_byte(+ _S_,- _C_) is iso
If _C_ is unbound, or is a character code, and the stream _S_ is a If _C_ is unbound, or is a byte, and the stream _S_ is a
binary stream, read the next byte from that stream and unify its binary stream, read the next byte from that stream and unify its
code with _C_. code with _C_. A byte is represented as either a number between 1 and 255, or as -1 for EOF.
*/ */
static Int get_byte(USES_REGS1) { /* '$get_byte'(Stream,-N) */ static Int get_byte(USES_REGS) { /* '$get_byte'(Stream,-N) */
int sno = Yap_CheckBinaryStream(ARG1, Input_Stream_f, "get_byte/2"); Term out = Deref(ARG2);
Term out;
if (!IsVarTerm(out)) {
if (!IsIntegerTerm(out)) Yap_ThrowError(TYPE_ERROR_IN_BYTE, ARG1, " bad type");
Int ch = IntegerOfTerm(out);
if (ch < -1 || ch > 255) Yap_ThrowError(TYPE_ERROR_IN_BYTE, ARG1, " bad type");
}
int sno = Yap_CheckBinaryStream(ARG1, Input_Stream_f, "get_byte/2");
if (sno < 0) if (sno < 0)
return (FALSE); return (FALSE);
out = MkIntTerm(GLOBAL_Stream[sno].stream_getc(sno)); out = MkIntTerm(GLOBAL_Stream[sno].stream_getc(sno));
@ -500,8 +506,13 @@ code with _C_.
static Int get_byte_1(USES_REGS1) { /* '$get_byte'(Stream,-N) */ static Int get_byte_1(USES_REGS1) { /* '$get_byte'(Stream,-N) */
int sno = LOCAL_c_input_stream; int sno = LOCAL_c_input_stream;
Int status; Int status;
Term out; Term out = Deref(ARG1);
if (!IsVarTerm(out)) {
if (!IsIntegerTerm(out)) Yap_ThrowError(TYPE_ERROR_IN_BYTE, ARG2, " bad type");
Int ch = IntegerOfTerm(out);
if (ch < -1 || ch > 255) Yap_ThrowError(TYPE_ERROR_IN_BYTE, ARG2, " bad type");
}
LOCK(GLOBAL_Stream[sno].streamlock); LOCK(GLOBAL_Stream[sno].streamlock);
status = GLOBAL_Stream[sno].status; status = GLOBAL_Stream[sno].status;
if (!(status & Binary_Stream_f) if (!(status & Binary_Stream_f)

View File

@ -82,6 +82,8 @@ Term Yap_StringToNumberTerm(const char *s, encoding_t *encp, bool error_on) {
CACHE_REGS CACHE_REGS
int sno; int sno;
Term t; Term t;
yap_error_descriptor_t new_error;
int i = push_text_stack();
sno = Yap_open_buf_read_stream(s, strlen(s), encp, MEM_BUF_USER); sno = Yap_open_buf_read_stream(s, strlen(s), encp, MEM_BUF_USER);
if (sno < 0) if (sno < 0)
@ -90,6 +92,7 @@ Term Yap_StringToNumberTerm(const char *s, encoding_t *encp, bool error_on) {
GLOBAL_Stream[sno].encoding = *encp; GLOBAL_Stream[sno].encoding = *encp;
else else
GLOBAL_Stream[sno].encoding = LOCAL_encoding; GLOBAL_Stream[sno].encoding = LOCAL_encoding;
bool new_rec = Yap_pushErrorContext(error_on,&new_error);
#ifdef __ANDROID__ #ifdef __ANDROID__
while (*s && isblank(*s) && Yap_wide_chtype(*s) == BS) while (*s && isblank(*s) && Yap_wide_chtype(*s) == BS)
s++; s++;
@ -97,6 +100,8 @@ Term Yap_StringToNumberTerm(const char *s, encoding_t *encp, bool error_on) {
t = Yap_scan_num(GLOBAL_Stream + sno, error_on); t = Yap_scan_num(GLOBAL_Stream + sno, error_on);
Yap_CloseStream(sno); Yap_CloseStream(sno);
UNLOCK(GLOBAL_Stream[sno].streamlock); UNLOCK(GLOBAL_Stream[sno].streamlock);
pop_text_stack(i);
Yap_popErrorContext(new_rec , error_on);
return t; return t;
} }

View File

@ -964,9 +964,8 @@ catch(G, C, A) :-
true true
). ).
'$catch'(_,C,A) :- '$catch'(_,C,A) :-
'$get_exception'(C), '$get_exception'(C0),
%( C = C0 -> '$execute'(A) ; throw(A0) ). ( C = C0 -> '$execute'(A) ; throw(C0) ).
'$run_catch'(C,A).
% variable throws are user-handled. % variable throws are user-handled.
'$run_catch'(G,E) :- '$run_catch'(G,E) :-