diff --git a/C/cdmgr.c b/C/cdmgr.c index 8b9fd55cb..68d5130a0 100644 --- a/C/cdmgr.c +++ b/C/cdmgr.c @@ -3097,7 +3097,7 @@ void Yap_HidePred(PredEntry *pe) { if (pe->NextOfPE) { UInt hash = PRED_HASH(pe->FunctorOfPred, CurrentModule, PredHashTableSize); READ_LOCK(PredHashRWLock); - PredEntry *p, **op = PredHash+hash; + PredEntry *p, **op = PredHash + hash; p = *op; while (p) { @@ -3144,7 +3144,7 @@ void Yap_HidePred(PredEntry *pe) { op = &p->NextPredOfModule; p = p->NextPredOfModule; } -pe->NextPredOfModule = NULL; + pe->NextPredOfModule = NULL; } } @@ -3168,16 +3168,15 @@ stash_predicate(USES_REGS1) { /* char ns[1024]; const char *s = (pe->ModuleOfPred == PROLOG_MODULE ? - "__prolog__stash__" : - snprintf(sn,1023,"__%s__".RepAtom(AtomOfTerm( pe->ModuleOfPred )))); - pe->ModuleOfPred = MkAtomTerm(Yap_LookupAtom(s)); + "__prolog__stash__" : + snprintf(sn,1023,"__%s__".RepAtom(AtomOfTerm( + pe->ModuleOfPred )))); pe->ModuleOfPred = MkAtomTerm(Yap_LookupAtom(s)); */ return true; } else return false; } - static Int /* $hidden_predicate(P) */ hidden_predicate(USES_REGS1) { PredEntry *pe = diff --git a/CMakeLists.txt b/CMakeLists.txt old mode 100644 new mode 100755 index 2e62ef230..6b11bf0f0 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -334,9 +334,14 @@ find_package(GMP) list(APPEND YAP_SYSTEM_OPTIONS big_numbers) + if (GMP_FOUND) #config.h needs this (TODO: change in code latter) include_directories(${GMP_INCLUDE_DIRS}) + check_include_file(gmp.h HAVE_GMP_H) + check_include_file_cxx(gmpxx.h HAVE_GMPXX_H) + + endif (GMP_FOUND) option(WITH_READLINE "use readline or libedit" ON) @@ -416,7 +421,7 @@ set(DEF_TRAILSPACE 0) set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS DEPTH_LIMIT=1;COROUTINING=1;RATIONAL_TREES=1) # inform we are compiling YAP -set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS "_YAP_NOT_INSTALLED_=1;HAVE_CONFIG_H=1;_GNU_SOURCE") +set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS "_YAP_NOT_INSTALLED_=1;HAVE_CONFIG_H=1;_GNU_SOURCE=1") # Compilation model # target_compile_definitions(libYap PUBLIC _XOPEN_SOURCE=700 ) diff --git a/CXX/yapi.hh b/CXX/yapi.hh old mode 100644 new mode 100755 index ba6ec0f16..794e5af61 --- a/CXX/yapi.hh +++ b/CXX/yapi.hh @@ -8,11 +8,20 @@ #define YAP_CPP_INTERFACE 1 -#include #include #include #include +extern "C"{ +#include "config.h" +} + +#if HAVE_GMPXX_H +#include +#elif HAVE_GMP_H +#include +#endif + /*! * * @ingroup fli_c_cxx diff --git a/H/TermExt.h b/H/TermExt.h index cd2487948..d6ffa0f79 100755 --- a/H/TermExt.h +++ b/H/TermExt.h @@ -388,26 +388,6 @@ INLINE_ONLY bool IsStringTerm(Term t) { #include -#if !defined(__cplusplus) -#include -#endif - -#else - -typedef UInt mp_limb_t; - -typedef struct { - Int _mp_size, _mp_alloc; - mp_limb_t *_mp_d; -} MP_INT; - -typedef struct { - MP_INT _mp_num; - MP_INT _mp_den; -} MP_RAT; - -#endif - INLINE_ONLY bool IsBigIntTerm(Term); INLINE_ONLY bool IsBigIntTerm(Term t) { @@ -415,7 +395,11 @@ INLINE_ONLY bool IsBigIntTerm(Term t) { FunctorOfTerm(t) == FunctorBigInt; } -#ifdef USE_GMP + +#if !defined(__cplusplus) +#include +#endif + Term Yap_MkBigIntTerm(MP_INT *); MP_INT *Yap_BigIntOfTerm(Term); diff --git a/H/YapEval.h b/H/YapEval.h old mode 100644 new mode 100755 index 7b8cde243..48d24c0ed --- a/H/YapEval.h +++ b/H/YapEval.h @@ -632,13 +632,13 @@ __Yap_Mk64IntegerTerm(YAP_LONG_LONG i USES_REGS) { } inline static Term add_int(Int i, Int j USES_REGS) { -#if defined(__clang__) || defined(__GNUC__) +#if defined(__clang__) || (defined(__GNUC__) && __GNUC__ > 4) Int w; if (!__builtin_add_overflow(i, j, &w)) RINT(w); return Yap_gmp_add_ints(i, j); ; -#elif defined(__GNUC__) +#elif defined(__GNUC__) && __GNUC__ > 4 Int w; if (!__builtin_add_overflow_p(i, j, w)) RINT(w); diff --git a/H/arith2.h b/H/arith2.h index 723db794a..12d78f0c0 100755 --- a/H/arith2.h +++ b/H/arith2.h @@ -24,13 +24,13 @@ inline static int sub_overflow(Int x, Int i, Int j) { } inline static Term sub_int(Int i, Int j USES_REGS) { -#if defined(__clang__ ) || defined(__GNUC__) +#if defined(__clang__ ) || (defined(__GNUC__) && __GNUC__ > 4) Int k; if (__builtin_sub_overflow(i,j,&k)) { return Yap_gmp_sub_ints(i, j); } RINT(k); -#elif defined(__GNUC__) +#elif defined(__GNUC__) && __GNUC__ >4 Int w; if (!__builtin_sub_overflow_p(i,j,w)) RINT(w); @@ -64,7 +64,7 @@ inline static int mul_overflow(Int z, Int i1, Int i2) { return (i2 && z / i2 != i1); } -#if defined(__clang__) || defined(__GNUC__) +#if defined(__clang__) || (defined(__GNUC__) && __GNUC__ > 4) #define DO_MULTI() \ if (__builtin_mul_overflow(i1, i2, &z)) { \ goto overflow; \ diff --git a/os/fmem.c b/os/fmem.c old mode 100644 new mode 100755 index faebfb81e..b50763a5d --- a/os/fmem.c +++ b/os/fmem.c @@ -23,6 +23,9 @@ static char SccsId[] = "%W% %G%"; * */ +#define _GNU_SOURCE + + #include "YapText.h" #include "format.h" #include "sysbits.h" @@ -163,7 +166,7 @@ int Yap_open_buf_read_stream(const char *buf, size_t nchars, f = st->file = fmemopen((void *)buf, nchars, "r"); st->vfs = NULL; flags = Input_Stream_f | InMemory_Stream_f | Seekable_Stream_f; - Yap_initStream(sno, f, RepAtom(fname)->StrOfAE, "r", uname, encoding, flags, NULL); + Yap_initStream(sno, f, fname, "r", uname, encoding, flags, NULL); // like any file stream. Yap_DefaultStreamOps(st); UNLOCK(st->streamlock); diff --git a/os/iopreds.c b/os/iopreds.c index 46473af86..f163624ff 100644 --- a/os/iopreds.c +++ b/os/iopreds.c @@ -342,7 +342,7 @@ void Yap_DefaultStreamOps(StreamDesc *st) { st->stream_putc = 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; + st->stream_wgetc = st->vfs->get_wchar; default_peek(st); return; } else { @@ -1126,7 +1126,7 @@ static void check_bom(int sno, StreamDesc *st) { } } -bool Yap_initStream(int sno, FILE *fd, const char *name, const char *io_mode, +bool Yap_initStream(int sno, FILE *fd, Atom name, const char *io_mode, Term file_name, encoding_t encoding, stream_flags_t flags, void *vfs) { // fprintf(stderr,"+ %s --> %d\n", name, sno); @@ -1228,7 +1228,8 @@ 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; @@ -1273,7 +1274,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 j= push_text_stack(); + int j = push_text_stack(); const char *buf; buf = Yap_TextTermToText(tin PASS_REGS); @@ -1283,11 +1284,10 @@ static bool fill_stream(int sno, StreamDesc *st, Term tin, const char *io_mode, } buf = pop_output_text_stack(j, buf); Atom nat = Yap_LookupAtom(Yap_StrPrefix(buf, 32)); - 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, nat, MkAtomTerm(NameOfFunctor(f))); - pop_text_stack(j); + pop_text_stack(j); return Yap_OpenBufWriteStream(PASS_REGS1); } } else if (!strcmp(RepAtom(NameOfFunctor(f))->StrOfAE, "popen")) { @@ -1313,8 +1313,8 @@ static bool fill_stream(int sno, StreamDesc *st, Term tin, const char *io_mode, if (!strchr(io_mode, 'b') && binary_file(fname)) { st->status |= Binary_Stream_f; } - Yap_initStream(sno, st->file, fname, io_mode, user_name, LOCAL_encoding, - st->status, vfsp); + Yap_initStream(sno, st->file, Yap_LookupAtom(fname), io_mode, user_name, + LOCAL_encoding, st->status, vfsp); return true; } @@ -1670,7 +1670,7 @@ int Yap_OpenStream(Term tin, const char *io_mode, Term user_name, return -1; } -int Yap_FileStream(FILE *fd, char *name, Term file_name, int flags, +int Yap_FileStream(FILE *fd, Atom name, Term file_name, int flags, VFS_t *vfsp) { CACHE_REGS int sno; diff --git a/os/iopreds.h b/os/iopreds.h old mode 100644 new mode 100755 index 3980a2efb..972937ee0 --- a/os/iopreds.h +++ b/os/iopreds.h @@ -31,7 +31,7 @@ INLINE_ONLY bool IsStreamTerm(Term t) { (IsApplTerm(t) && (FunctorOfTerm(t) == FunctorStream))); } -extern bool Yap_initStream(int sno, FILE *fd, const char *name, const char *io_mode, Term file_name, encoding_t encoding, +extern bool Yap_initStream(int sno, FILE *fd, Atom name, const char *io_mode, Term file_name, encoding_t encoding, stream_flags_t flags, void *vfs); #define Yap_CheckStream(arg, kind, msg) \ diff --git a/os/mem.c b/os/mem.c old mode 100644 new mode 100755 index b8623ddc1..a0b321ec0 --- a/os/mem.c +++ b/os/mem.c @@ -225,7 +225,7 @@ int Yap_open_buf_read_stream(const char *buf, size_t nchars, encoding_t *encp, flags = Input_Stream_f | InMemory_Stream_f; st->vfs = NULL; st->name = name; - Yap_initStream(sno, f, "Memory Stream","wa", TermNil, encoding, flags, NULL); + Yap_initStream(sno, f, Yap_LookupAtom("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; diff --git a/os/readline.c b/os/readline.c old mode 100644 new mode 100755 index 01b240eb9..341d737e5 --- a/os/readline.c +++ b/os/readline.c @@ -218,7 +218,7 @@ static char **prolog_completion(const char *text, int start, int end) { } else if (start == 0) { int i = 0; const char *p; - while (isblank(text[i++]) && i <= end) + while (isspace(text[i++]) && i <= end) ; p = text + i; diff --git a/os/streams.c b/os/streams.c index a56838f64..dff198cbe 100644 --- a/os/streams.c +++ b/os/streams.c @@ -363,7 +363,6 @@ Atom Yap_guessFileName(FILE *file, int sno, size_t max) { } #endif if (!StreamName(sno)) { - pop_text_stack(i); return NULL; } pop_text_stack(i); diff --git a/os/yapio.h b/os/yapio.h index 58f4827aa..983522f19 100644 --- a/os/yapio.h +++ b/os/yapio.h @@ -26,8 +26,8 @@ #include #include "YapIOConfig.h" -#include #include +#include #ifndef _PL_WRITE_ @@ -51,7 +51,7 @@ typedef struct AliasDescS { * @return a new VFS that will support /assets */ -extern struct vfs *Yap_InitAssetManager( void ); +extern struct vfs *Yap_InitAssetManager(void); /* routines in parser.c */ extern VarEntry *Yap_LookupVar(const char *); @@ -85,8 +85,9 @@ extern int Yap_PlGetWchar(void); extern int Yap_PlFGetchar(void); extern int Yap_GetCharForSIGINT(void); extern Int Yap_StreamToFileNo(Term); -extern int Yap_OpenStream(Term tin, const char* io_mode, Term user_name, encoding_t enc); -extern int Yap_FileStream(FILE*, char *, Term, int, VFS_t *); +extern int Yap_OpenStream(Term tin, const char *io_mode, Term user_name, + encoding_t enc); +extern int Yap_FileStream(FILE *, Atom, Term, int, VFS_t *); extern char *Yap_TermToBuffer(Term t, int flags); extern char *Yap_HandleToString(yhandle_t l, size_t sz, size_t *length, encoding_t *encoding, int flags); @@ -112,18 +113,19 @@ typedef enum mem_buf_source { extern char *Yap_MemStreamBuf(int sno); -extern char *Yap_StrPrefix( const char *buf, size_t n) ; +extern char *Yap_StrPrefix(const char *buf, size_t n); extern Term Yap_StringToNumberTerm(const char *s, encoding_t *encp, bool error_on); extern int Yap_FormatFloat(Float f, char **s, size_t sz); extern int Yap_open_buf_read_stream(const char *buf, size_t nchars, - encoding_t *encp, memBufSource src, Atom name, - Term uname); + encoding_t *encp, memBufSource src, + Atom name, Term uname); extern int Yap_open_buf_write_stream(encoding_t enc, memBufSource src); -extern Term Yap_BufferToTerm(const char *s, Term opts); -extern X_API Term Yap_BufferToTermWithPrioBindings(const char *s, Term opts, Term bindings, size_t sz, - int prio); +extern Term Yap_BufferToTerm(const char *s, Term opts); +extern X_API Term Yap_BufferToTermWithPrioBindings(const char *s, Term opts, + Term bindings, size_t sz, + int prio); extern FILE *Yap_GetInputStream(Term t, const char *m); extern FILE *Yap_GetOutputStream(Term t, const char *m); extern Atom Yap_guessFileName(FILE *f, int sno, size_t max); @@ -156,36 +158,34 @@ INLINE_ONLY Term MkCharTerm(Int c) { return MkAtomTerm(Yap_ULookupAtom(cs)); } - - extern char *GLOBAL_cwd; +INLINE_ONLY char *Yap_VF(const char *path) { + char *out; -INLINE_ONLY char *Yap_VF(const char *path){ - char *out; - - out = (char *)malloc(YAP_FILENAME_MAX+1); - if ( GLOBAL_cwd == NULL || GLOBAL_cwd[0] == 0 || !Yap_IsAbsolutePath(path, false)) { - return (char *) path; - } - strcpy(out, GLOBAL_cwd); - strcat(out, "/" ); - strcat(out, path); - return out; + out = (char *)malloc(YAP_FILENAME_MAX + 1); + if (GLOBAL_cwd == NULL || GLOBAL_cwd[0] == 0 || + !Yap_IsAbsolutePath(path, false)) { + return (char *)path; + } + strcpy(out, GLOBAL_cwd); + strcat(out, "/"); + strcat(out, path); + return out; } +INLINE_ONLY char *Yap_VFAlloc(const char *path) { + char *out; -INLINE_ONLY char *Yap_VFAlloc(const char *path){ - char *out; - - out = (char *)malloc(YAP_FILENAME_MAX+1); - if ( GLOBAL_cwd == NULL || GLOBAL_cwd[0] == 0 || !Yap_IsAbsolutePath(path, false)) { - return (char *) path; - } - strcpy(out, GLOBAL_cwd); - strcat(out, "/" ); - strcat(out, path); - return out; + out = (char *)malloc(YAP_FILENAME_MAX + 1); + if (GLOBAL_cwd == NULL || GLOBAL_cwd[0] == 0 || + !Yap_IsAbsolutePath(path, false)) { + return (char *)path; + } + strcpy(out, GLOBAL_cwd); + strcat(out, "/"); + strcat(out, path); + return out; } /// UT when yap started @@ -193,6 +193,4 @@ extern uint64_t Yap_StartOfWTimes; extern bool Yap_HandleSIGINT(void); - - #endif diff --git a/pl/protect.yap b/pl/protect.yap index 242d951c5..d7e489c09 100755 --- a/pl/protect.yap +++ b/pl/protect.yap @@ -48,7 +48,7 @@ prolog:'$protect' :- '$new_system_predicate'(Name,Arity,M), sub_atom(Name,0,1,_, '$'), functor(P,Name,Arity), - %'$hide_predicate'(P,M), +% '$hide_predicate'(P,M), fail. prolog:'$protect' :- current_atom(Name),