more fixes
This commit is contained in:
parent
7bfe8aedbe
commit
4b1efa59b4
@ -699,13 +699,11 @@ restart_aux:
|
||||
t1 = Deref(ARG1);
|
||||
if (IsNumTerm(t1)) {
|
||||
Term t2 = Deref(ARG2);
|
||||
if (IsVarTerm(t2)) {
|
||||
t1 = Yap_NumberToListOfAtoms(t1 PASS_REGS);
|
||||
}
|
||||
if (t1) {
|
||||
Term t12 = Yap_NumberToListOfAtoms(t1 PASS_REGS);
|
||||
if (t12) {
|
||||
{
|
||||
pop_text_stack(l);
|
||||
return Yap_unify(t1, t2);
|
||||
return Yap_unify(t12, t2);
|
||||
}
|
||||
}
|
||||
} else if (IsVarTerm(t1)) {
|
||||
|
59
C/errors.c
59
C/errors.c
@ -300,7 +300,10 @@ void Yap_InitError__(const char *file, const char *function, int lineno,
|
||||
return;
|
||||
va_end(ap);
|
||||
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->errorFile = NULL;
|
||||
@ -401,6 +404,8 @@ bool Yap_HandleError__(const char *file, const char *function, int lineno,
|
||||
|
||||
if (LOCAL_PrologMode == UserMode)
|
||||
Yap_Error__(false, file, function, lineno, err, TermNil, serr);
|
||||
else
|
||||
LOCAL_PrologMode &= ~InErrorMode;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -492,6 +497,7 @@ static char tmpbuf[YAP_BUF_SIZE];
|
||||
#undef BEGIN_ERRORS
|
||||
#undef E0
|
||||
#undef E
|
||||
#undef E1
|
||||
#undef E2
|
||||
#undef END_ERRORS
|
||||
|
||||
@ -531,6 +537,16 @@ static char tmpbuf[YAP_BUF_SIZE];
|
||||
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) \
|
||||
case A: { \
|
||||
Term ft[2], nt[3]; \
|
||||
@ -864,6 +880,7 @@ static Int close_error(USES_REGS1) {
|
||||
#undef BEGIN_ERRORS
|
||||
#undef E0
|
||||
#undef E
|
||||
#undef E1
|
||||
#undef E2
|
||||
#undef END_ERRORS
|
||||
|
||||
@ -878,6 +895,7 @@ static Int close_error(USES_REGS1) {
|
||||
#define BEGIN_ERRORS()
|
||||
#define E0(X, Y)
|
||||
#define E(X, Y, Z)
|
||||
#define E1(X, Y, Z)
|
||||
#define E2(X, Y, Z, W)
|
||||
#define END_ERRORS()
|
||||
|
||||
@ -889,6 +907,7 @@ static Int close_error(USES_REGS1) {
|
||||
#undef BEGIN_ERRORS
|
||||
#undef E0
|
||||
#undef E
|
||||
#undef E1
|
||||
#undef E2
|
||||
#undef END_ERRORS
|
||||
|
||||
@ -908,6 +927,7 @@ typedef struct c_error_info {
|
||||
#define BEGIN_ERRORS() static struct c_error_info c_error_list[] = {
|
||||
#define E0(X, Y) {Y##__, ""},
|
||||
#define E(X, Y, Z) {Y##__, Z},
|
||||
#define E1(X, Y, Z) {Y##__, Z},
|
||||
#define E2(X, Y, Z, W) {Y##__, Z " " W},
|
||||
#define END_ERRORS() \
|
||||
{ YAPC_NO_ERROR, "" } \
|
||||
@ -1028,10 +1048,7 @@ static Int get_exception(USES_REGS1) {
|
||||
} else {
|
||||
t = mkerrort(i->errorNo, TermNil, MkSysError(i));
|
||||
}
|
||||
while (B && B->cp_b && ! Yap_unify(t, B->cp_a2)) {
|
||||
Yap_JumpToEnv();
|
||||
}
|
||||
return true;
|
||||
return Yap_unify(ARG1,t);
|
||||
}
|
||||
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->culprit = NULL;
|
||||
} else {
|
||||
char ename[65];
|
||||
Term t1, t2;
|
||||
t1 = ArgOfTerm(1, t);
|
||||
t2 = ArgOfTerm(2, t);
|
||||
// LOCAL_Error_TYPE = ERROR_EVENT;
|
||||
i->errorNo = ERROR_EVENT;
|
||||
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;
|
||||
wellformed = wellformed && ( i->errorAsText != NULL );
|
||||
if (wellformed) {
|
||||
int j;
|
||||
for (j = 0; j < sizeof(c_error_list) / sizeof(struct c_error_info); j++) {
|
||||
if (!strcmp(c_error_list[j].name, i->errorAsText) &&
|
||||
(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)) {
|
||||
const char *err = RepAtom(AtomOfTerm(t1))->StrOfAE;
|
||||
if (!strcmp(err, "instantiation_error")) {
|
||||
|
3
C/exec.c
3
C/exec.c
@ -1397,7 +1397,7 @@ static bool exec_absmi(bool top, yap_reset_t reset_mode USES_REGS) {
|
||||
sigjmp_buf signew, *sighold = LOCAL_RestartEnv;
|
||||
LOCAL_RestartEnv = &signew;
|
||||
|
||||
if (top && (lval = sigsetjmp(signew, 1)) != 0) {
|
||||
if /* top &&*/( (lval = sigsetjmp(signew, 1)) != 0) {
|
||||
switch (lval) {
|
||||
case 1: { /* restart */
|
||||
/* 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;
|
||||
}
|
||||
P = FAILCODE;
|
||||
|
||||
}
|
||||
}
|
||||
YENV = ASP;
|
||||
|
5
C/text.c
5
C/text.c
@ -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,
|
||||
bool error_on USES_REGS) {
|
||||
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);
|
||||
pop_text_stack(i);
|
||||
Yap_popErrorContext(new_rec , true);
|
||||
return t;
|
||||
}
|
||||
|
||||
|
@ -27,15 +27,14 @@ inline static Term sub_int(Int i, Int j USES_REGS) {
|
||||
#if defined(__clang__ ) || defined(__GNUC__)
|
||||
Int 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);
|
||||
#elif defined(__GNUC__)
|
||||
Int w;
|
||||
if (!__builtin_sub_overflow_p(i,j,w))
|
||||
RINT(w);
|
||||
return Yap_gmp_add_ints(i, j);
|
||||
return Yap_gmp_sub_ints(i, j);
|
||||
#else
|
||||
Int x = i - j;
|
||||
|
||||
|
@ -19,6 +19,7 @@
|
||||
|
||||
#define E0(A, B) A,
|
||||
#define E(A, B, C) A,
|
||||
#define E1(A, B, C) A,
|
||||
#define E2(A, B, C, D) A,
|
||||
|
||||
#define BEGIN_ERRORS() typedef enum {
|
||||
|
@ -140,7 +140,7 @@ E(RESOURCE_ERROR_HEAP, RESOURCE_ERROR, "database_space")
|
||||
E(RESOURCE_ERROR_TRAIL, RESOURCE_ERROR, "trail_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_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_EVALUABLE, TYPE_ERROR, "evaluable")
|
||||
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_INTEGER, TYPE_ERROR, "integer")
|
||||
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_UCHAR, TYPE_ERROR, "uchar")
|
||||
|
||||
E0(UNINSTANTIATION_ERROR, UNINSTANTIATION_ERROR_CLASS)
|
||||
E1(UNINSTANTIATION_ERROR, UNINSTANTIATION_ERROR_CLASS, "uninstantiation_error")
|
||||
|
||||
END_ERRORS();
|
||||
|
23
os/charsio.c
23
os/charsio.c
@ -471,16 +471,22 @@ static Int get0_line_codes(USES_REGS1) { /* '$get0'(Stream,-N) */
|
||||
|
||||
/** @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
|
||||
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) */
|
||||
int sno = Yap_CheckBinaryStream(ARG1, Input_Stream_f, "get_byte/2");
|
||||
Term out;
|
||||
static Int get_byte(USES_REGS) { /* '$get_byte'(Stream,-N) */
|
||||
Term out = Deref(ARG2);
|
||||
|
||||
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)
|
||||
return (FALSE);
|
||||
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) */
|
||||
int sno = LOCAL_c_input_stream;
|
||||
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);
|
||||
status = GLOBAL_Stream[sno].status;
|
||||
if (!(status & Binary_Stream_f)
|
||||
|
@ -82,6 +82,8 @@ Term Yap_StringToNumberTerm(const char *s, encoding_t *encp, bool error_on) {
|
||||
CACHE_REGS
|
||||
int sno;
|
||||
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);
|
||||
if (sno < 0)
|
||||
@ -90,6 +92,7 @@ Term Yap_StringToNumberTerm(const char *s, encoding_t *encp, bool error_on) {
|
||||
GLOBAL_Stream[sno].encoding = *encp;
|
||||
else
|
||||
GLOBAL_Stream[sno].encoding = LOCAL_encoding;
|
||||
bool new_rec = Yap_pushErrorContext(error_on,&new_error);
|
||||
#ifdef __ANDROID__
|
||||
while (*s && isblank(*s) && Yap_wide_chtype(*s) == BS)
|
||||
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);
|
||||
Yap_CloseStream(sno);
|
||||
UNLOCK(GLOBAL_Stream[sno].streamlock);
|
||||
pop_text_stack(i);
|
||||
Yap_popErrorContext(new_rec , error_on);
|
||||
return t;
|
||||
}
|
||||
|
||||
|
@ -964,9 +964,8 @@ catch(G, C, A) :-
|
||||
true
|
||||
).
|
||||
'$catch'(_,C,A) :-
|
||||
'$get_exception'(C),
|
||||
%( C = C0 -> '$execute'(A) ; throw(A0) ).
|
||||
'$run_catch'(C,A).
|
||||
'$get_exception'(C0),
|
||||
( C = C0 -> '$execute'(A) ; throw(C0) ).
|
||||
|
||||
% variable throws are user-handled.
|
||||
'$run_catch'(G,E) :-
|
||||
|
Reference in New Issue
Block a user