Merge 192.168.1.103:github/yap-6.3
This commit is contained in:
commit
ba6e0728ae
@ -85,7 +85,7 @@ static void InitConsultStack(void) {
|
||||
LOCAL_ConsultCapacity = InitialConsultCapacity;
|
||||
LOCAL_ConsultBase = LOCAL_ConsultSp =
|
||||
LOCAL_ConsultLow + LOCAL_ConsultCapacity;
|
||||
}
|
||||
s
|
||||
|
||||
void Yap_ResetConsultStack(void) {
|
||||
CACHE_REGS
|
||||
|
@ -606,7 +606,7 @@ endif ()
|
||||
|
||||
if (WIN32)
|
||||
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})
|
||||
endif ()
|
||||
endif (WIN32)
|
||||
@ -687,7 +687,7 @@ set_target_properties(libYap
|
||||
|
||||
# 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:. )
|
||||
add_subdirectory(packages/python/swig)
|
||||
|
||||
@ -927,7 +927,7 @@ if (WIN32)
|
||||
set(MSVC_RUNTIME "dynamic")
|
||||
ENDIF (MSVC)
|
||||
|
||||
target_link_libraries(libYap wsock32 ws2_32 Shlwapi)
|
||||
target_link_libraries(libYap wsock32 ws2_32 shlwapi)
|
||||
|
||||
endif (WIN32)
|
||||
|
||||
|
@ -88,6 +88,7 @@ typedef struct vfs {
|
||||
int (*peek_char)(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_wchar)(int sno, int ch); /// output a character to the stream
|
||||
void (*flush)(int sno); /// flush a stream
|
||||
int64_t (*seek)(int sno, int64_t offset,
|
||||
int whence); /// jump around the stream
|
||||
|
10
os/files.c
10
os/files.c
@ -678,13 +678,13 @@ VFS_t *vfsp;
|
||||
strcat(bs, "/*");
|
||||
#endif
|
||||
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_GetFromSlot(sl)));
|
||||
Yap_PutInSlot(sl, MkPairTerm(MkAtomTerm(Yap_LookupAtom(c_file.name)),
|
||||
Yap_GetFromSlot(sl)));
|
||||
while (_findnext(hFile, &c_file) == 0) {
|
||||
YAP_Term ti = YAP_MkAtomTerm(YAP_LookupAtom(c_file.name));
|
||||
YAP_PutInSlot(sl, YAP_MkPairTerm(ti, YAP_GetFromSlot(sl)));
|
||||
Term ti = MkAtomTerm(Yap_LookupAtom(c_file.name));
|
||||
Yap_PutInSlot(sl, MkPairTerm(ti, Yap_GetFromSlot(sl)));
|
||||
}
|
||||
_findclose(hFile);
|
||||
#elif HAVE_OPENDIR
|
||||
|
18
os/iopreds.c
18
os/iopreds.c
@ -340,7 +340,7 @@ void Yap_DefaultStreamOps(StreamDesc *st) {
|
||||
st->stream_wgetc = get_wchar;
|
||||
if (st->vfs && !st->file) {
|
||||
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_wgetc = st->vfs->get_char;
|
||||
default_peek(st);
|
||||
@ -1161,11 +1161,7 @@ bool Yap_initStream(int sno, FILE *fd, const char *name, const char *io_mode,
|
||||
st->encoding = encoding;
|
||||
}
|
||||
|
||||
if (name == NULL) {
|
||||
char buf[YAP_FILENAME_MAX + 1];
|
||||
memset(buf, 0, YAP_FILENAME_MAX + 1);
|
||||
name = Yap_guessFileName(fd, sno, buf, YAP_FILENAME_MAX);
|
||||
}
|
||||
name = Yap_guessFileName(fd, sno, YAP_FILENAME_MAX);
|
||||
if (!name)
|
||||
Yap_Error(SYSTEM_ERROR_INTERNAL, file_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()};
|
||||
#undef PAR
|
||||
|
||||
static bool fill_stream(int sno, StreamDesc *st, Term tin, const char *io_mode,
|
||||
Term user_name, encoding_t enc) {
|
||||
static bool fill_stream(int sno, StreamDesc *st, Term tin, const char *io_mode, Term user_name, encoding_t enc) {
|
||||
struct vfs *vfsp = NULL;
|
||||
const char *fname;
|
||||
|
||||
int i;
|
||||
if (IsAtomTerm(tin))
|
||||
fname = RepAtom(AtomOfTerm(tin))->StrOfAE;
|
||||
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')) {
|
||||
return Yap_OpenBufWriteStream(PASS_REGS1);
|
||||
} else {
|
||||
int i = push_text_stack();
|
||||
i = push_text_stack();
|
||||
const char *buf;
|
||||
|
||||
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();
|
||||
buf = Yap_TextTermToText(ArgOfTerm(1, tin) PASS_REGS);
|
||||
if (buf == NULL) {
|
||||
pop_text_stack(i);
|
||||
return false;
|
||||
}
|
||||
#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;
|
||||
pop_text_stack(i);
|
||||
} 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)) {
|
||||
|
14
os/mem.c
14
os/mem.c
@ -48,7 +48,6 @@ int format_synch(int sno, int sno0, format_info *fg) {
|
||||
GLOBAL_Stream[sno].linecount = 1;
|
||||
GLOBAL_Stream[sno].linepos = 0;
|
||||
GLOBAL_Stream[sno].charcount = 0;
|
||||
GLOBAL_Stream[sno].recbs = NULL;
|
||||
GLOBAL_Stream[sno].vfs = NULL;
|
||||
fg->lstart = 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].linepos += nchars;
|
||||
GLOBAL_Stream[sno].charcount = 0;
|
||||
GLOBAL_Stream[sno].recbs = NULL;
|
||||
GLOBAL_Stream[sno].vfs = NULL;
|
||||
GLOBAL_Stream[sno].file = NULL;
|
||||
fg->phys_start = 0;
|
||||
@ -193,8 +191,7 @@ bool Yap_set_stream_to_buf(StreamDesc *st, const char *buf,
|
||||
st->file = f = NULL;
|
||||
flags = Input_Stream_f | InMemory_Stream_f;
|
||||
st->vfs = NULL;
|
||||
Yap_initStream(st - GLOBAL_Stream, f, "r", TermNil, LOCAL_encoding, flags,
|
||||
AtomRead, NULL);
|
||||
Yap_initStream(st - GLOBAL_Stream, f, "buffer", "r", TermNil, LOCAL_encoding, flags, NULL);
|
||||
// like any file stream.
|
||||
/* currently these streams are not seekable */
|
||||
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;
|
||||
}
|
||||
|
||||
int Yap_open_buf_read_stream(const char *buf, size_t nchars, encoding_t *encp,
|
||||
memBufSource src) {
|
||||
int Yap_open_buf_read_stream(const char *buf, size_t nchars, encoding_t *encp, memBufSource src , Atom name, Term uname) {
|
||||
CACHE_REGS
|
||||
int sno;
|
||||
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;
|
||||
flags = Input_Stream_f | InMemory_Stream_f;
|
||||
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.
|
||||
/* currently these streams are not seekable */
|
||||
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);
|
||||
sno = Yap_open_buf_read_stream(buf, strlen(buf) + 1, &LOCAL_encoding,
|
||||
MEM_BUF_MALLOC);
|
||||
MEM_BUF_MALLOC, AtomNil, TermNil);
|
||||
t = Yap_MkStream(sno);
|
||||
return Yap_unify(ARG2, t);
|
||||
}
|
||||
@ -278,7 +275,6 @@ int Yap_open_buf_write_stream(encoding_t enc, memBufSource src) {
|
||||
st->charcount = 0;
|
||||
st->linecount = 1;
|
||||
st->encoding = enc;
|
||||
st->recbs = NULL;
|
||||
st->vfs = NULL;
|
||||
st->file = NULL;
|
||||
Yap_DefaultStreamOps(st);
|
||||
|
31
os/streams.c
31
os/streams.c
@ -315,36 +315,35 @@ bool Yap_SetCurInpPos(
|
||||
return true;
|
||||
}
|
||||
|
||||
char *Yap_guessFileName(FILE *file, int sno, char *nameb, size_t max) {
|
||||
size_t maxs = Yap_Max(1024, max);
|
||||
if (!nameb) {
|
||||
nameb = malloc(maxs + 1);
|
||||
}
|
||||
char *Yap_guessFileName(FILE *file, int sno, size_t max) {
|
||||
size_t maxs = Yap_Max(1023, max-1);
|
||||
int i = push_text_stack();
|
||||
char *nameb = Malloc(maxs + 1);
|
||||
if (!file) {
|
||||
strncpy(nameb, "memory buffer", maxs);
|
||||
return nameb;
|
||||
|
||||
return pop_output_text_stack(i,nameb);
|
||||
}
|
||||
int f = fileno(file);
|
||||
if (f < 0) {
|
||||
strcpy(nameb, "???");
|
||||
return nameb;
|
||||
return pop_output_text_stack(i,nameb);
|
||||
}
|
||||
|
||||
#if __linux__
|
||||
char *path = malloc(1024);
|
||||
char *path = Malloc(1024);
|
||||
if (snprintf(path, 1023, "/proc/self/fd/%d", f) &&
|
||||
readlink(path, nameb, maxs)) {
|
||||
free(path);
|
||||
return nameb;
|
||||
return pop_output_text_stack(i,nameb);
|
||||
}
|
||||
#elif __APPLE__
|
||||
if (fcntl(f, F_GETPATH, nameb) != -1) {
|
||||
return nameb;
|
||||
return pop_output_text_stack(i,nameb);
|
||||
}
|
||||
#else
|
||||
TCHAR path = malloc(MAX_PATH + 1);
|
||||
TCHAR *path = Malloc(MAX_PATH + 1);
|
||||
if (!GetFullPathName(path, MAX_PATH, path, NULL)) {
|
||||
free(path);
|
||||
pop_text_stack(i);
|
||||
return NULL;
|
||||
} else {
|
||||
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++)
|
||||
ptr += put_utf8(ptr, path[i]);
|
||||
*ptr = '\0';
|
||||
free(path);
|
||||
return nameb;
|
||||
return pop_output_text_stack(i,nameb);
|
||||
}
|
||||
free(path);
|
||||
#endif
|
||||
if (!StreamName(sno)) {
|
||||
pop_text_stack(i);
|
||||
return NULL;
|
||||
}
|
||||
pop_text_stack(i);
|
||||
return RepAtom(AtomOfTerm(StreamName(sno)))->StrOfAE;
|
||||
}
|
||||
|
||||
|
@ -1872,7 +1872,7 @@ static Int p_sleep(USES_REGS1) {
|
||||
Term ts = ARG1;
|
||||
#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)) {
|
||||
secs = IntegerOfTerm(ts);
|
||||
} else if (IsFloatTerm(ts)) {
|
||||
@ -1902,7 +1902,7 @@ static Int p_sleep(USES_REGS1) {
|
||||
req.tv_sec = IntOfTerm(ts);
|
||||
}
|
||||
out = nanosleep(&req, NULL);
|
||||
return true;
|
||||
return out == 0;
|
||||
}
|
||||
#elif HAVE_USLEEP
|
||||
{
|
||||
|
12
os/sysbits.h
12
os/sysbits.h
@ -32,7 +32,7 @@
|
||||
#if _WIN32 || defined(__MINGW32__)
|
||||
#include <winsock2.h>
|
||||
/* Windows */
|
||||
#include "Shlwapi.h"
|
||||
#include "shlwapi.h"
|
||||
#include <direct.h>
|
||||
#include <io.h>
|
||||
#include <windows.h>
|
||||
@ -40,6 +40,12 @@
|
||||
#define S_ISDIR(x) (((x)&_S_IFDIR) == _S_IFDIR)
|
||||
#endif
|
||||
#endif
|
||||
#ifndef BUF_SIZE
|
||||
#ifdef MAX_PATH
|
||||
#define BUF_SIZE MAX_PATH
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
@ -115,6 +121,10 @@
|
||||
/* windows.h does not like absmi.h, this
|
||||
should fix it for now */
|
||||
#include <math.h>
|
||||
#include <math.h>
|
||||
#if HAVE_TIME_H
|
||||
#include <time.h>
|
||||
#endif
|
||||
#if HAVE_SYS_TIME_H && !_MSC_VER
|
||||
#include <sys/time.h>
|
||||
#endif
|
||||
|
@ -126,7 +126,7 @@ extern X_API Term Yap_BufferToTermWithPrioBindings(const char *s, Term opts, Te
|
||||
int prio);
|
||||
extern FILE *Yap_GetInputStream(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,
|
||||
int flags, int priority);
|
||||
|
||||
|
@ -34,7 +34,7 @@ add_definitions(-DSQLITE_ENABLE_FTS5=1 )
|
||||
SET_PROPERTY(DIRECTORY PROPERTY COMPILE_DEFINITIONS YAP_KERNEL=1 )
|
||||
|
||||
|
||||
if (ANDROID)
|
||||
if (ANDROID OR WIN32)
|
||||
add_library( YAPsqlite3 OBJECT
|
||||
${YAPSQLITE3_SOURCES} )
|
||||
|
||||
|
@ -77,20 +77,6 @@ lists:append([H|T], L, [H|R]) :-
|
||||
|
||||
/** @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.
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user