chaeacters mostly

This commit is contained in:
Vitor Santos Costa 2017-10-18 01:02:52 +01:00
parent af38546a0d
commit 7dab812d64
10 changed files with 1185 additions and 1188 deletions

View File

@ -27,6 +27,7 @@ static char SccsId[] = "%W% %G%";
#include "Yap.h" #include "Yap.h"
#include "Yatom.h" #include "Yatom.h"
#include "clause.h" #include "clause.h"
#include "alloc.h"
#include "yapio.h" #include "yapio.h"
#include <stdio.h> #include <stdio.h>
#include <wchar.h> #include <wchar.h>
@ -183,12 +184,17 @@ LookupAtom(const unsigned char *atom) { /* lookup atom in atom table */
} }
#endif #endif
/* add new atom to start of chain */ /* add new atom to start of chain */
size_t asz = strlen((const char *)atom); sz = strlen((const char *)atom);
ae = (AtomEntry *)Yap_AllocAtomSpace((sizeof *ae) + asz+1); size_t asz = (sizeof *ae) + ( sz+1);
ae = malloc(asz);
if (ae == NULL) { if (ae == NULL) {
WRITE_UNLOCK(HashChain[hash].AERWLock); WRITE_UNLOCK(HashChain[hash].AERWLock);
return NIL; return NIL;
} }
// enable fast hashing by making sure that
// the last cell is fully initialized.
CELL *aec = (CELL*)ae;
aec[asz/(YAP_ALIGN+1)-1] = 0;
NOfAtoms++; NOfAtoms++;
na = AbsAtom(ae); na = AbsAtom(ae);
ae->PropsOfAE = NIL; ae->PropsOfAE = NIL;

View File

@ -38,7 +38,7 @@ bool Yap_Warning(const char *s, ...) {
PredEntry *pred; PredEntry *pred;
bool rc; bool rc;
Term ts[2]; Term ts[2];
const char *format; const char *fmt;
char tmpbuf[MAXPATHLEN]; char tmpbuf[MAXPATHLEN];
LOCAL_DoingUndefp = true; LOCAL_DoingUndefp = true;
@ -46,12 +46,12 @@ bool Yap_Warning(const char *s, ...) {
pred = RepPredProp(PredPropByFunc(FunctorPrintMessage, pred = RepPredProp(PredPropByFunc(FunctorPrintMessage,
PROLOG_MODULE)); // PROCEDURE_print_message2 PROLOG_MODULE)); // PROCEDURE_print_message2
va_start(ap, s); va_start(ap, s);
format = va_arg(ap, char *); fmt = va_arg(ap, char *);
if (format != NULL) { if (fmt != NULL) {
#if HAVE_VSNPRINTF #if HAVE_VSNPRINTF
vsnprintf(tmpbuf, MAXPATHLEN - 1, format, ap); vsnprintf(tmpbuf, MAXPATHLEN - 1, fmt, ap);
#else #else
(void)vsprintf(tmpbuf, format, ap); (void)vsprintf(tmpbuf, fmt, ap);
#endif #endif
} else } else
return false; return false;
@ -321,12 +321,12 @@ void Yap_ThrowError__(const char *file, const char *function, int lineno,
char tmpbuf[MAXPATHLEN]; char tmpbuf[MAXPATHLEN];
va_start(ap, where); va_start(ap, where);
char *format = va_arg(ap, char *); char *fmt = va_arg(ap, char *);
if (format != NULL) { if (fmt != NULL) {
#if HAVE_VSNPRINTF #if HAVE_VSNPRINTF
(void)vsnprintf(tmpbuf, MAXPATHLEN - 1, format, ap); (void)vsnprintf(tmpbuf, MAXPATHLEN - 1, fmt, ap);
#else #else
(void)vsprintf(tnpbuf, format, ap); (void)vsprintf(tnpbuf, fmt, ap);
#endif #endif
// fprintf(stderr, "warning: "); // fprintf(stderr, "warning: ");
Yap_Error__(file, function, lineno, type, where, tmpbuf); Yap_Error__(file, function, lineno, type, where, tmpbuf);
@ -377,7 +377,7 @@ yamop *Yap_Error__(const char *file, const char *function, int lineno,
Functor fun; Functor fun;
Term error_t; Term error_t;
Term comment; Term comment;
char *format; char *fmt;
char s[MAXPATHLEN]; char s[MAXPATHLEN];
/* disallow recursive error handling */ /* disallow recursive error handling */
@ -406,10 +406,10 @@ yamop *Yap_Error__(const char *file, const char *function, int lineno,
#if DEBUG_STRICT #if DEBUG_STRICT
if (Yap_heap_regs && !(LOCAL_PrologMode & BootMode)) if (Yap_heap_regs && !(LOCAL_PrologMode & BootMode))
fprintf(stderr, "***** Processing Error %d (%lx,%x) %s***\n", type, fprintf(stderr, "***** Processing Error %d (%lx,%x) %s***\n", type,
(unsigned long int)LOCAL_Signals, LOCAL_PrologMode, format); (unsigned long int)LOCAL_Signals, LOCAL_PrologMode, fmt);
else else
fprintf(stderr, "***** Processing Error %d (%x) %s***\n", type, fprintf(stderr, "***** Processing Error %d (%x) %s***\n", type,
LOCAL_PrologMode, format); LOCAL_PrologMode, fmt);
#endif #endif
if (type == INTERRUPT_EVENT) { if (type == INTERRUPT_EVENT) {
fprintf(stderr, "%% YAP exiting: cannot handle signal %d\n", fprintf(stderr, "%% YAP exiting: cannot handle signal %d\n",
@ -425,12 +425,12 @@ yamop *Yap_Error__(const char *file, const char *function, int lineno,
Yap_exit(1); Yap_exit(1);
} }
va_start(ap, where); va_start(ap, where);
format = va_arg(ap, char *); fmt = va_arg(ap, char *);
if (format != NULL) { if (fmt != NULL) {
#if HAVE_VSNPRINTF #if HAVE_VSNPRINTF
(void)vsnprintf(s, MAXPATHLEN - 1, format, ap); (void)vsnprintf(s, MAXPATHLEN - 1, fmt, ap);
#else #else
(void)vsprintf(s, format, ap); (void)vsprintf(s, fmt, ap);
#endif #endif
// fprintf(stderr, "warning: "); // fprintf(stderr, "warning: ");
comment = MkAtomTerm(Yap_LookupAtom(s)); comment = MkAtomTerm(Yap_LookupAtom(s));

View File

@ -268,7 +268,7 @@ static void *codes2buf(Term t0, void *b0, bool *get_codes USES_REGS) {
} }
} }
st0 = st = malloc(length + 1); st0 = st = Malloc(length + 1);
t = t0; t = t0;
if (codes) { if (codes) {
while (IsPairTerm(t)) { while (IsPairTerm(t)) {
@ -339,7 +339,7 @@ static void *codes2buf(Term t0, void *b0, bool *get_codes USES_REGS) {
seq_tv_t *inp USES_REGS) { seq_tv_t *inp USES_REGS) {
bool codes; bool codes;
unsigned char *nbuf = codes2buf(t, buf, &codes PASS_REGS); unsigned char *nbuf = codes2buf(t, buf, &codes PASS_REGS);
if (!codes) if (codes)
return NULL; return NULL;
return nbuf; return nbuf;
} }
@ -645,7 +645,7 @@ static void *codes2buf(Term t0, void *b0, bool *get_codes USES_REGS) {
out->val.uc = BaseMalloc(leng + 1); out->val.uc = BaseMalloc(leng + 1);
strcpy(out->val.c, (char *)s0); strcpy(out->val.c, (char *)s0);
} else if (out->val.uc != s0) { } else if (out->val.uc != s0) {
out->val.c = Realloc(out->val.c, leng + 1); out->val.c = BaseMalloc(leng + 1);
strcpy(out->val.c, (char *)s0); strcpy(out->val.c, (char *)s0);
} }
} else if (out->enc == ENC_ISO_LATIN1) { } else if (out->enc == ENC_ISO_LATIN1) {
@ -954,7 +954,7 @@ bool write_Text(unsigned char *inp, seq_tv_t *out USES_REGS) {
bufv[j++] = nbuf; bufv[j++] = nbuf;
} }
if (j == 0) { if (j == 0) {
buf = malloc(8); buf = Malloc(8);
memset(buf, 0, 4); memset(buf, 0, 4);
} else if (j == 1) { } else if (j == 1) {
buf = bufv[0]; buf = bufv[0];

View File

@ -525,7 +525,7 @@ SET(CMAKE_SKIP_BUILD_RPATH FALSE)
# when building, don't use the install RPATH already # when building, don't use the install RPATH already
# (but later on when installing) # (but later on when installing)
SET(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE) SET(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
SET(CMAKE_INSTALL_RPATH "${libdir}") SET(CMAKE_INSTALL_RPATH "${libdir}")

View File

@ -114,3 +114,4 @@ typedef unsigned long int YAP_ULONG_LONG;
#define Unsigned(V) ((CELL)(V)) #define Unsigned(V) ((CELL)(V))
#define Signed(V) ((Int)(V)) #define Signed(V) ((Int)(V))

View File

@ -188,11 +188,7 @@ INLINE_ONLY inline EXTERN utf8proc_ssize_t get_utf8(const utf8proc_uint8_t *ptr,
utf8proc_int32_t *valp) { utf8proc_int32_t *valp) {
utf8proc_ssize_t rc = utf8proc_iterate(ptr, n, valp); utf8proc_ssize_t rc = utf8proc_iterate(ptr, n, valp);
if (rc < 0) { if (rc < 0) {
if (rc == UTF8PROC_ERROR_INVALIDUTF8) LOCAL_ActiveError->errorNo = REPRESENTATION_ERROR_IN_CHARACTER_CODE;
Yap_Warning("get_utf8 found bad UTF-8 char %s, skipping...", ptr);
else
Yap_Warning("UTF-8 error %d, skipping...", *ptr);
rc = 1;
} }
return rc; return rc;
} }
@ -203,8 +199,9 @@ INLINE_ONLY inline EXTERN utf8proc_ssize_t put_utf8(utf8proc_uint8_t *ptr,
INLINE_ONLY inline EXTERN utf8proc_ssize_t put_utf8(utf8proc_uint8_t *ptr, INLINE_ONLY inline EXTERN utf8proc_ssize_t put_utf8(utf8proc_uint8_t *ptr,
utf8proc_int32_t val) { utf8proc_int32_t val) {
utf8proc_ssize_t rc = utf8proc_encode_char(val, ptr); utf8proc_ssize_t rc = utf8proc_encode_char(val, ptr);
if (rc == 0) if (rc < 0) {
Yap_Warning("UTF-8 error at %s", ptr); LOCAL_ActiveError->errorNo = REPRESENTATION_ERROR_CHARACTER_CODE;
}
return rc; return rc;
} }
@ -217,15 +214,11 @@ inline static const utf8proc_uint8_t *skip_utf8(const utf8proc_uint8_t *pt,
if (b == 0) if (b == 0)
return pt; return pt;
if (l < 0) { if (l < 0) {
if (l == UTF8PROC_ERROR_INVALIDUTF8) LOCAL_ActiveError->errorNo = REPRESENTATION_ERROR_CHARACTER_CODE;
Yap_Warning("skip_utf8: found bad UTF-8 in char %s[%d], skipping...", } else {
pt, i);
else
Yap_Warning("UTF-8 error %d at %s[%d], skipping...", l, pt, i);
l = 1;
}
pt += l; pt += l;
} }
}
return pt; return pt;
} }
@ -240,14 +233,11 @@ inline static utf8proc_ssize_t strlen_utf8(const utf8proc_uint8_t *pt) {
utf8proc_ssize_t l = utf8proc_iterate(pt, -1, &b); utf8proc_ssize_t l = utf8proc_iterate(pt, -1, &b);
if (b == 0) if (b == 0)
return rc; return rc;
else if (b > 0) { else if (l > 0) {
pt += l; pt += l;
rc++; rc++;
} else { } else {
if (l == UTF8PROC_ERROR_INVALIDUTF8) LOCAL_ActiveError->errorNo = REPRESENTATION_ERROR_CHARACTER_CODE;
Yap_Warning("found bad UTF-8 char %d, skipping %s...", *pt, pt);
else
Yap_Warning("UTF-8 error %d, skipping...", l);
pt++; pt++;
} }
} }
@ -259,6 +249,9 @@ inline static utf8proc_ssize_t strlen_latin_utf8(const unsigned char *pt) {
utf8proc_uint8_t b; utf8proc_uint8_t b;
while (true) { while (true) {
utf8proc_ssize_t l = utf8proc_encode_char(*pt, &b); utf8proc_ssize_t l = utf8proc_encode_char(*pt, &b);
if (l<0) {
pt++;
}
if (b == 0) if (b == 0)
return rc; return rc;
pt++; pt++;
@ -276,6 +269,7 @@ inline static utf8proc_ssize_t strnlen_latin_utf8(const unsigned char *pt,
if (b == 0) if (b == 0)
return rc; return rc;
pt++; pt++;
if (l > 0)
rc += l; rc += l;
if (--max == 0) if (--max == 0)
return rc; return rc;
@ -290,6 +284,8 @@ inline static utf8proc_ssize_t strlen_ucs2_utf8(const wchar_t *pt) {
utf8proc_ssize_t l = utf8proc_encode_char(*pt, &b); utf8proc_ssize_t l = utf8proc_encode_char(*pt, &b);
if (b == 0) if (b == 0)
return rc; return rc;
if (l < 0)
continue;
pt++; pt++;
rc += l; rc += l;
} }
@ -947,7 +943,6 @@ static inline Atom Yap_ListOfAtomsToAtom(Term t0 USES_REGS) {
out.type = YAP_STRING_ATOM; out.type = YAP_STRING_ATOM;
out.val.uc = NULL; out.val.uc = NULL;
out.enc = ENC_ISO_UTF8; out.enc = ENC_ISO_UTF8;
out.enc = ENC_ISO_UTF8;
if (!Yap_CVT_Text(&inp, &out PASS_REGS)) if (!Yap_CVT_Text(&inp, &out PASS_REGS))
return (Atom)NULL; return (Atom)NULL;
return out.val.a; return out.val.a;

View File

@ -20,8 +20,6 @@ check_include_files( "stdio.h;cudd/cudd.h" HAVE_CUDD_CUDD_H )
check_include_files( "stdio.h;cudd/cuddInt.h" HAVE_CUDD_CUDDINT_H ) check_include_files( "stdio.h;cudd/cuddInt.h" HAVE_CUDD_CUDDINT_H )
configure_file (cmake/cudd_config.h.cmake configure_file (cmake/cudd_config.h.cmake
"${CMAKE_CURRENT_BINARY_DIR}/cudd_config.h" ) "${CMAKE_CURRENT_BINARY_DIR}/cudd_config.h" )
configure_file (cmake/cudd_config.h.cmake
"${CMAKE_BINARY_DIR}/packages/cplint/config,config.h" )
endif (CUDD_FOUND) endif (CUDD_FOUND)

View File

@ -5,7 +5,6 @@ package:
requirements: requirements:
build: build:
- cmake - cmake
- clang
- swig - swig
- readline - readline
- gmp - gmp

View File

@ -97,7 +97,7 @@ Int Yap_peek(int sno) {
CACHE_REGS CACHE_REGS
Int ocharcount, olinecount, olinepos; Int ocharcount, olinecount, olinepos;
StreamDesc *s; StreamDesc *s;
uint32_t ch; int32_t ch;
s = GLOBAL_Stream + sno; s = GLOBAL_Stream + sno;
#if USE_READLINE #if USE_READLINE
@ -1039,11 +1039,11 @@ code with _C_, while leaving the current stream position unaltered.
*/ */
static Int peek_byte(USES_REGS1) { /* at_end_of_stream */ static Int peek_byte(USES_REGS1) { /* at_end_of_stream */
/* the next character is a EOF */ /* the next character is a EOF */
int sno = Yap_CheckStream(ARG1, Input_Stream_f, "peek_byte/2"); int sno = Yap_CheckBinaryStream(ARG1, Input_Stream_f, "peek_byte/2");
Int ch; Int ch;
if (sno < 0) if (sno < 0)
return (FALSE); return false;
if (!(GLOBAL_Stream[sno].status & Binary_Stream_f)) { if (!(GLOBAL_Stream[sno].status & Binary_Stream_f)) {
UNLOCK(GLOBAL_Stream[sno].streamlock); UNLOCK(GLOBAL_Stream[sno].streamlock);
Yap_Error(PERMISSION_ERROR_INPUT_BINARY_STREAM, ARG1, "peek_byte/2"); Yap_Error(PERMISSION_ERROR_INPUT_BINARY_STREAM, ARG1, "peek_byte/2");
@ -1099,22 +1099,20 @@ atom with _C_, while leaving the stream position unaltered.
static Int peek_char(USES_REGS1) { static Int peek_char(USES_REGS1) {
/* the next character is a EOF */ /* the next character is a EOF */
int sno = Yap_CheckTextStream(ARG1, Input_Stream_f, "peek/2"); int sno = Yap_CheckTextStream(ARG1, Input_Stream_f, "peek/2");
unsigned char sinp[10]; unsigned char sinp[16];
Int ch; Int ch;
if (sno < 0) if (sno < 0)
return false; return false;
if ((GLOBAL_Stream[sno].status & Binary_Stream_f)) {
UNLOCK(GLOBAL_Stream[sno].streamlock);
Yap_Error(PERMISSION_ERROR_INPUT_TEXT_STREAM, ARG1, "peek_byte/2");
return (FALSE);
}
if ((ch = Yap_peek(sno)) < 0) { if ((ch = Yap_peek(sno)) < 0) {
UNLOCK(GLOBAL_Stream[sno].streamlock); UNLOCK(GLOBAL_Stream[sno].streamlock);
return Yap_unify_constant(ARG2, MkAtomTerm(AtomEof)); return Yap_unify_constant(ARG2, MkAtomTerm(AtomEof));
} }
UNLOCK(GLOBAL_Stream[sno].streamlock); UNLOCK(GLOBAL_Stream[sno].streamlock);
int off = put_utf8(sinp, ch); int off = put_utf8(sinp, ch);
if (off < 0) {
return false;
}
sinp[off] = '\0'; sinp[off] = '\0';
return Yap_unify_constant(ARG2, MkAtomTerm(Yap_ULookupAtom(sinp))); return Yap_unify_constant(ARG2, MkAtomTerm(Yap_ULookupAtom(sinp)));
} }