Merge 192.168.1.103:github/yap-6.3

This commit is contained in:
Vitor Santos Costa 2018-10-06 05:39:52 +01:00
commit ba6e0728ae
12 changed files with 53 additions and 65 deletions

View File

@ -85,7 +85,7 @@ static void InitConsultStack(void) {
LOCAL_ConsultCapacity = InitialConsultCapacity; LOCAL_ConsultCapacity = InitialConsultCapacity;
LOCAL_ConsultBase = LOCAL_ConsultSp = LOCAL_ConsultBase = LOCAL_ConsultSp =
LOCAL_ConsultLow + LOCAL_ConsultCapacity; LOCAL_ConsultLow + LOCAL_ConsultCapacity;
} s
void Yap_ResetConsultStack(void) { void Yap_ResetConsultStack(void) {
CACHE_REGS CACHE_REGS

View File

@ -606,7 +606,7 @@ endif ()
if (WIN32) if (WIN32)
target_link_libraries(libYap ${WINDLLS}) target_link_libraries(libYap ${WINDLLS})
if (PYTHON_INCLUDE_DIRS AND PYTHON_LIBRARIES) if (WITH_PYTHON AND PYTHON_INCLUDE_DIRS AND PYTHON_LIBRARIES)
target_link_libraries(libYap ${PYTHON_LIBRARIES}) target_link_libraries(libYap ${PYTHON_LIBRARIES})
endif () endif ()
endif (WIN32) endif (WIN32)
@ -687,7 +687,7 @@ set_target_properties(libYap
# file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/packages/python/swig/yap4py) # file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/packages/python/swig/yap4py)
if (PYTHONLIBS_FOUND AND SWIG_FOUND) if (WITH_PYTHON AND PYTHONLIBS_FOUND AND SWIG_FOUND)
set( ENV{PYTHONPATH} ${CMAKE_BINARY_DIR}/packages/python/swig:${CMAKE_BINARY_DIR}/packages/python/yap_kernel:. ) set( ENV{PYTHONPATH} ${CMAKE_BINARY_DIR}/packages/python/swig:${CMAKE_BINARY_DIR}/packages/python/yap_kernel:. )
add_subdirectory(packages/python/swig) add_subdirectory(packages/python/swig)
@ -927,7 +927,7 @@ if (WIN32)
set(MSVC_RUNTIME "dynamic") set(MSVC_RUNTIME "dynamic")
ENDIF (MSVC) ENDIF (MSVC)
target_link_libraries(libYap wsock32 ws2_32 Shlwapi) target_link_libraries(libYap wsock32 ws2_32 shlwapi)
endif (WIN32) endif (WIN32)

View File

@ -88,6 +88,7 @@ typedef struct vfs {
int (*peek_char)(int sno); /// unget an octet from the stream int (*peek_char)(int sno); /// unget an octet from the stream
int (*peek_wchar)(int sno); /// unget an octet from the stream int (*peek_wchar)(int sno); /// unget an octet from the stream
int (*put_char)(int sno, int ch); /// output an octet to the stream int (*put_char)(int sno, int ch); /// output an octet to the stream
int (*put_wchar)(int sno, int ch); /// output a character to the stream
void (*flush)(int sno); /// flush a stream void (*flush)(int sno); /// flush a stream
int64_t (*seek)(int sno, int64_t offset, int64_t (*seek)(int sno, int64_t offset,
int whence); /// jump around the stream int whence); /// jump around the stream

View File

@ -678,13 +678,13 @@ VFS_t *vfsp;
strcat(bs, "/*"); strcat(bs, "/*");
#endif #endif
if ((hFile = _findfirst(bs, &c_file)) == -1L) { if ((hFile = _findfirst(bs, &c_file)) == -1L) {
return (Yap_Unify(ARD2, tf)); return (Yap_unify(ARG2, tf));
} }
YAP_PutInSlot(sl, YAP_MkPairTerm(YAP_MkAtomTerm(YAP_LookupAtom(c_file.name)), Yap_PutInSlot(sl, MkPairTerm(MkAtomTerm(Yap_LookupAtom(c_file.name)),
YAP_GetFromSlot(sl))); Yap_GetFromSlot(sl)));
while (_findnext(hFile, &c_file) == 0) { while (_findnext(hFile, &c_file) == 0) {
YAP_Term ti = YAP_MkAtomTerm(YAP_LookupAtom(c_file.name)); Term ti = MkAtomTerm(Yap_LookupAtom(c_file.name));
YAP_PutInSlot(sl, YAP_MkPairTerm(ti, YAP_GetFromSlot(sl))); Yap_PutInSlot(sl, MkPairTerm(ti, Yap_GetFromSlot(sl)));
} }
_findclose(hFile); _findclose(hFile);
#elif HAVE_OPENDIR #elif HAVE_OPENDIR

View File

@ -340,7 +340,7 @@ void Yap_DefaultStreamOps(StreamDesc *st) {
st->stream_wgetc = get_wchar; st->stream_wgetc = get_wchar;
if (st->vfs && !st->file) { if (st->vfs && !st->file) {
st->stream_putc = st->vfs->put_char; st->stream_putc = st->vfs->put_char;
st->stream_wputc = st->vfs->put_char; st->stream_wputc = st->vfs->put_wchar;
st->stream_getc = st->vfs->get_char; st->stream_getc = st->vfs->get_char;
st->stream_wgetc = st->vfs->get_char; st->stream_wgetc = st->vfs->get_char;
default_peek(st); default_peek(st);
@ -1161,11 +1161,7 @@ bool Yap_initStream(int sno, FILE *fd, const char *name, const char *io_mode,
st->encoding = encoding; st->encoding = encoding;
} }
if (name == NULL) { name = Yap_guessFileName(fd, sno, YAP_FILENAME_MAX);
char buf[YAP_FILENAME_MAX + 1];
memset(buf, 0, YAP_FILENAME_MAX + 1);
name = Yap_guessFileName(fd, sno, buf, YAP_FILENAME_MAX);
}
if (!name) if (!name)
Yap_Error(SYSTEM_ERROR_INTERNAL, file_name, Yap_Error(SYSTEM_ERROR_INTERNAL, file_name,
"Yap_guessFileName failed: opening a file without a name"); "Yap_guessFileName failed: opening a file without a name");
@ -1233,11 +1229,11 @@ typedef enum open_enum_choices { OPEN_DEFS() } open_choices_t;
static const param_t open_defs[] = {OPEN_DEFS()}; static const param_t open_defs[] = {OPEN_DEFS()};
#undef PAR #undef PAR
static bool fill_stream(int sno, StreamDesc *st, Term tin, const char *io_mode, static bool fill_stream(int sno, StreamDesc *st, Term tin, const char *io_mode, Term user_name, encoding_t enc) {
Term user_name, encoding_t enc) {
struct vfs *vfsp = NULL; struct vfs *vfsp = NULL;
const char *fname; const char *fname;
int i;
if (IsAtomTerm(tin)) if (IsAtomTerm(tin))
fname = RepAtom(AtomOfTerm(tin))->StrOfAE; fname = RepAtom(AtomOfTerm(tin))->StrOfAE;
else if (IsStringTerm(tin)) else if (IsStringTerm(tin))
@ -1279,7 +1275,7 @@ static bool fill_stream(int sno, StreamDesc *st, Term tin, const char *io_mode,
if (strchr(io_mode, 'r')) { if (strchr(io_mode, 'r')) {
return Yap_OpenBufWriteStream(PASS_REGS1); return Yap_OpenBufWriteStream(PASS_REGS1);
} else { } else {
int i = push_text_stack(); i = push_text_stack();
const char *buf; const char *buf;
buf = Yap_TextTermToText(tin PASS_REGS); buf = Yap_TextTermToText(tin PASS_REGS);
@ -1299,7 +1295,6 @@ static bool fill_stream(int sno, StreamDesc *st, Term tin, const char *io_mode,
int i = push_text_stack(); int i = push_text_stack();
buf = Yap_TextTermToText(ArgOfTerm(1, tin) PASS_REGS); buf = Yap_TextTermToText(ArgOfTerm(1, tin) PASS_REGS);
if (buf == NULL) { if (buf == NULL) {
pop_text_stack(i);
return false; return false;
} }
#if _WIN32 #if _WIN32
@ -1312,7 +1307,8 @@ static bool fill_stream(int sno, StreamDesc *st, Term tin, const char *io_mode,
st->status |= Popen_Stream_f; st->status |= Popen_Stream_f;
pop_text_stack(i); pop_text_stack(i);
} else { } else {
Yap_ThrowError(DOMAIN_ERROR_SOURCE_SINK, tin, "open"); pop_text_stack(i);
Yap_ThrowError(DOMAIN_ERROR_SOURCE_SINK, tin, "open");
} }
} }
if (!strchr(io_mode, 'b') && binary_file(fname)) { if (!strchr(io_mode, 'b') && binary_file(fname)) {

View File

@ -48,7 +48,6 @@ int format_synch(int sno, int sno0, format_info *fg) {
GLOBAL_Stream[sno].linecount = 1; GLOBAL_Stream[sno].linecount = 1;
GLOBAL_Stream[sno].linepos = 0; GLOBAL_Stream[sno].linepos = 0;
GLOBAL_Stream[sno].charcount = 0; GLOBAL_Stream[sno].charcount = 0;
GLOBAL_Stream[sno].recbs = NULL;
GLOBAL_Stream[sno].vfs = NULL; GLOBAL_Stream[sno].vfs = NULL;
fg->lstart = 0; fg->lstart = 0;
fg->phys_start = 0; fg->phys_start = 0;
@ -105,7 +104,6 @@ bool fill_pads(int sno, int sno0, int total, format_info *fg USES_REGS) {
GLOBAL_Stream[sno].linecount = 1; GLOBAL_Stream[sno].linecount = 1;
GLOBAL_Stream[sno].linepos += nchars; GLOBAL_Stream[sno].linepos += nchars;
GLOBAL_Stream[sno].charcount = 0; GLOBAL_Stream[sno].charcount = 0;
GLOBAL_Stream[sno].recbs = NULL;
GLOBAL_Stream[sno].vfs = NULL; GLOBAL_Stream[sno].vfs = NULL;
GLOBAL_Stream[sno].file = NULL; GLOBAL_Stream[sno].file = NULL;
fg->phys_start = 0; fg->phys_start = 0;
@ -193,8 +191,7 @@ bool Yap_set_stream_to_buf(StreamDesc *st, const char *buf,
st->file = f = NULL; st->file = f = NULL;
flags = Input_Stream_f | InMemory_Stream_f; flags = Input_Stream_f | InMemory_Stream_f;
st->vfs = NULL; st->vfs = NULL;
Yap_initStream(st - GLOBAL_Stream, f, "r", TermNil, LOCAL_encoding, flags, Yap_initStream(st - GLOBAL_Stream, f, "buffer", "r", TermNil, LOCAL_encoding, flags, NULL);
AtomRead, NULL);
// like any file stream. // like any file stream.
/* currently these streams are not seekable */ /* currently these streams are not seekable */
st->status = Input_Stream_f | InMemory_Stream_f; st->status = Input_Stream_f | InMemory_Stream_f;
@ -207,8 +204,7 @@ bool Yap_set_stream_to_buf(StreamDesc *st, const char *buf,
return true; return true;
} }
int Yap_open_buf_read_stream(const char *buf, size_t nchars, encoding_t *encp, int Yap_open_buf_read_stream(const char *buf, size_t nchars, encoding_t *encp, memBufSource src , Atom name, Term uname) {
memBufSource src) {
CACHE_REGS CACHE_REGS
int sno; int sno;
StreamDesc *st; StreamDesc *st;
@ -228,7 +224,8 @@ int Yap_open_buf_read_stream(const char *buf, size_t nchars, encoding_t *encp,
st->file = f = NULL; st->file = f = NULL;
flags = Input_Stream_f | InMemory_Stream_f; flags = Input_Stream_f | InMemory_Stream_f;
st->vfs = NULL; st->vfs = NULL;
Yap_initStream(sno, f, "wa", TermNil, encoding, flags, AtomRead, NULL); st->name = name;
Yap_initStream(sno, f, "Memory Stream","wa", TermNil, encoding, flags, NULL);
// like any file stream. // like any file stream.
/* currently these streams are not seekable */ /* currently these streams are not seekable */
st->status = Input_Stream_f | InMemory_Stream_f; st->status = Input_Stream_f | InMemory_Stream_f;
@ -257,7 +254,7 @@ open_mem_read_stream(USES_REGS1) /* $open_mem_read_stream(+List,-Stream) */
} }
buf = pop_output_text_stack(i, buf); buf = pop_output_text_stack(i, buf);
sno = Yap_open_buf_read_stream(buf, strlen(buf) + 1, &LOCAL_encoding, sno = Yap_open_buf_read_stream(buf, strlen(buf) + 1, &LOCAL_encoding,
MEM_BUF_MALLOC); MEM_BUF_MALLOC, AtomNil, TermNil);
t = Yap_MkStream(sno); t = Yap_MkStream(sno);
return Yap_unify(ARG2, t); return Yap_unify(ARG2, t);
} }
@ -278,7 +275,6 @@ int Yap_open_buf_write_stream(encoding_t enc, memBufSource src) {
st->charcount = 0; st->charcount = 0;
st->linecount = 1; st->linecount = 1;
st->encoding = enc; st->encoding = enc;
st->recbs = NULL;
st->vfs = NULL; st->vfs = NULL;
st->file = NULL; st->file = NULL;
Yap_DefaultStreamOps(st); Yap_DefaultStreamOps(st);

View File

@ -315,36 +315,35 @@ bool Yap_SetCurInpPos(
return true; return true;
} }
char *Yap_guessFileName(FILE *file, int sno, char *nameb, size_t max) { char *Yap_guessFileName(FILE *file, int sno, size_t max) {
size_t maxs = Yap_Max(1024, max); size_t maxs = Yap_Max(1023, max-1);
if (!nameb) { int i = push_text_stack();
nameb = malloc(maxs + 1); char *nameb = Malloc(maxs + 1);
}
if (!file) { if (!file) {
strncpy(nameb, "memory buffer", maxs); strncpy(nameb, "memory buffer", maxs);
return nameb;
return pop_output_text_stack(i,nameb);
} }
int f = fileno(file); int f = fileno(file);
if (f < 0) { if (f < 0) {
strcpy(nameb, "???"); strcpy(nameb, "???");
return nameb; return pop_output_text_stack(i,nameb);
} }
#if __linux__ #if __linux__
char *path = malloc(1024); char *path = Malloc(1024);
if (snprintf(path, 1023, "/proc/self/fd/%d", f) && if (snprintf(path, 1023, "/proc/self/fd/%d", f) &&
readlink(path, nameb, maxs)) { readlink(path, nameb, maxs)) {
free(path); return pop_output_text_stack(i,nameb);
return nameb;
} }
#elif __APPLE__ #elif __APPLE__
if (fcntl(f, F_GETPATH, nameb) != -1) { if (fcntl(f, F_GETPATH, nameb) != -1) {
return nameb; return pop_output_text_stack(i,nameb);
} }
#else #else
TCHAR path = malloc(MAX_PATH + 1); TCHAR *path = Malloc(MAX_PATH + 1);
if (!GetFullPathName(path, MAX_PATH, path, NULL)) { if (!GetFullPathName(path, MAX_PATH, path, NULL)) {
free(path); pop_text_stack(i);
return NULL; return NULL;
} else { } else {
int i; int i;
@ -352,14 +351,14 @@ char *Yap_guessFileName(FILE *file, int sno, char *nameb, size_t max) {
for (i = 0; i < strlen(path); i++) for (i = 0; i < strlen(path); i++)
ptr += put_utf8(ptr, path[i]); ptr += put_utf8(ptr, path[i]);
*ptr = '\0'; *ptr = '\0';
free(path); return pop_output_text_stack(i,nameb);
return nameb;
} }
free(path);
#endif #endif
if (!StreamName(sno)) { if (!StreamName(sno)) {
pop_text_stack(i);
return NULL; return NULL;
} }
pop_text_stack(i);
return RepAtom(AtomOfTerm(StreamName(sno)))->StrOfAE; return RepAtom(AtomOfTerm(StreamName(sno)))->StrOfAE;
} }

View File

@ -1872,7 +1872,7 @@ static Int p_sleep(USES_REGS1) {
Term ts = ARG1; Term ts = ARG1;
#if defined(__MINGW32__) || _MSC_VER #if defined(__MINGW32__) || _MSC_VER
{ {
unsigned long int secs = 0, usecs = 0, msecs, out; unsigned long int secs = 0, usecs = 0, msecs;
if (IsIntegerTerm(ts)) { if (IsIntegerTerm(ts)) {
secs = IntegerOfTerm(ts); secs = IntegerOfTerm(ts);
} else if (IsFloatTerm(ts)) { } else if (IsFloatTerm(ts)) {
@ -1902,7 +1902,7 @@ static Int p_sleep(USES_REGS1) {
req.tv_sec = IntOfTerm(ts); req.tv_sec = IntOfTerm(ts);
} }
out = nanosleep(&req, NULL); out = nanosleep(&req, NULL);
return true; return out == 0;
} }
#elif HAVE_USLEEP #elif HAVE_USLEEP
{ {

View File

@ -32,7 +32,7 @@
#if _WIN32 || defined(__MINGW32__) #if _WIN32 || defined(__MINGW32__)
#include <winsock2.h> #include <winsock2.h>
/* Windows */ /* Windows */
#include "Shlwapi.h" #include "shlwapi.h"
#include <direct.h> #include <direct.h>
#include <io.h> #include <io.h>
#include <windows.h> #include <windows.h>
@ -40,6 +40,12 @@
#define S_ISDIR(x) (((x)&_S_IFDIR) == _S_IFDIR) #define S_ISDIR(x) (((x)&_S_IFDIR) == _S_IFDIR)
#endif #endif
#endif #endif
#ifndef BUF_SIZE
#ifdef MAX_PATH
#define BUF_SIZE MAX_PATH
#endif
#endif
#ifdef HAVE_UNISTD_H #ifdef HAVE_UNISTD_H
#include <unistd.h> #include <unistd.h>
@ -115,6 +121,10 @@
/* windows.h does not like absmi.h, this /* windows.h does not like absmi.h, this
should fix it for now */ should fix it for now */
#include <math.h> #include <math.h>
#include <math.h>
#if HAVE_TIME_H
#include <time.h>
#endif
#if HAVE_SYS_TIME_H && !_MSC_VER #if HAVE_SYS_TIME_H && !_MSC_VER
#include <sys/time.h> #include <sys/time.h>
#endif #endif

View File

@ -126,7 +126,7 @@ extern X_API Term Yap_BufferToTermWithPrioBindings(const char *s, Term opts, Te
int prio); int prio);
extern FILE *Yap_GetInputStream(Term t, const char *m); extern FILE *Yap_GetInputStream(Term t, const char *m);
extern FILE *Yap_GetOutputStream(Term t, const char *m); extern FILE *Yap_GetOutputStream(Term t, const char *m);
extern char *Yap_guessFileName(FILE *f, int sno, char *nameb, size_t max); extern char *Yap_guessFileName(FILE *f, int sno, size_t max);
extern void Yap_plwrite(Term t, struct stream_desc *mywrite, int max_depth, extern void Yap_plwrite(Term t, struct stream_desc *mywrite, int max_depth,
int flags, int priority); int flags, int priority);

View File

@ -34,7 +34,7 @@ add_definitions(-DSQLITE_ENABLE_FTS5=1 )
SET_PROPERTY(DIRECTORY PROPERTY COMPILE_DEFINITIONS YAP_KERNEL=1 ) SET_PROPERTY(DIRECTORY PROPERTY COMPILE_DEFINITIONS YAP_KERNEL=1 )
if (ANDROID) if (ANDROID OR WIN32)
add_library( YAPsqlite3 OBJECT add_library( YAPsqlite3 OBJECT
${YAPSQLITE3_SOURCES} ) ${YAPSQLITE3_SOURCES} )

View File

@ -3,7 +3,7 @@
* @author VITOR SANTOS COSTA <vsc@VITORs-MBP.lan> * @author VITOR SANTOS COSTA <vsc@VITORs-MBP.lan>
* @date Thu Nov 19 09:54:00 2015 * @date Thu Nov 19 09:54:00 2015
* *
* @addtogroup lists * @addtogroup lists
* @{ * @{
*/ */
@ -77,20 +77,6 @@ lists:append([H|T], L, [H|R]) :-
/** @pred delete(+ _List_, ? _Element_, ? _Residue_) /** @pred delete(+ _List_, ? _Element_, ? _Residue_)
eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee
True when _List_ is a list, in which _Element_ may or may not
occur, and _Residue_ is a copy of _List_ with all elements
identical to _Element_ deleted.
eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee
*/
lists:delete([], _, []).
lists:delete([Head|List], Elem, Residue) :-
Head = Elem,
lists:delete(List, Elem, Residue).
lists:delete([Head|List], Elem, [Head|Residue]) :-
lists:delete(List, Elem, Residue).
:- set_prolog_flag(source, false). % disable source. :- set_prolog_flag(source, false). % disable source.