From f57377a23a422f3917a2a0bea2b6035403b8568a Mon Sep 17 00:00:00 2001 From: Vitor Santos Costa Date: Sat, 29 Sep 2018 14:43:27 -0500 Subject: [PATCH] maintain compatibility with olde linuxen. --- C/cdmgr.c | 2 ++ CMakeLists.txt | 7 ++++++- CXX/yapi.hh | 11 ++++++++++- H/TermExt.h | 26 +++++--------------------- H/YapEval.h | 4 ++-- H/arith2.h | 6 +++--- os/fmem.c | 5 ++++- os/iopreds.c | 14 ++++++++------ os/iopreds.h | 2 +- os/mem.c | 2 +- os/readline.c | 2 +- os/streams.c | 26 ++++++++++++-------------- os/yapio.h | 2 +- pl/protect.yap | 2 +- 14 files changed, 57 insertions(+), 54 deletions(-) mode change 100644 => 100755 C/cdmgr.c mode change 100644 => 100755 CMakeLists.txt mode change 100644 => 100755 CXX/yapi.hh mode change 100644 => 100755 H/YapEval.h mode change 100644 => 100755 os/fmem.c mode change 100644 => 100755 os/iopreds.c mode change 100644 => 100755 os/iopreds.h mode change 100644 => 100755 os/mem.c mode change 100644 => 100755 os/readline.c mode change 100644 => 100755 os/streams.c mode change 100644 => 100755 os/yapio.h diff --git a/C/cdmgr.c b/C/cdmgr.c old mode 100644 new mode 100755 index 037f4e0b3..5dadfc886 --- a/C/cdmgr.c +++ b/C/cdmgr.c @@ -3082,6 +3082,7 @@ static Int p_clean_up_dead_clauses(USES_REGS1) { void Yap_HidePred(PredEntry *pe) { pe->PredFlags |= (HiddenPredFlag | NoSpyPredFlag | NoTracePredFlag); + /* char newMod[1024]; strncpy(newMod, "$$$--hidden-module--",1023); Term cmod = pe->ModuleOfPred; @@ -3090,6 +3091,7 @@ void Yap_HidePred(PredEntry *pe) { else strncat(newMod, RepAtom(AtomOfTerm(cmod))->StrOfAE, 1023-strlen(newMod)); pe->ModuleOfPred = MkAtomTerm(Yap_LookupAtom(newMod)); + */ } static Int /* $system_predicate(P) */ diff --git a/CMakeLists.txt b/CMakeLists.txt old mode 100644 new mode 100755 index d33175a60..1510e2282 --- 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 old mode 100644 new mode 100755 index 25770e00a..21d120734 --- a/os/iopreds.c +++ b/os/iopreds.c @@ -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); @@ -1160,12 +1160,14 @@ bool Yap_initStream(int sno, FILE *fd, const char *name, const char *io_mode, } else { st->encoding = encoding; } - - name = Yap_guessFileName(fd, sno, YAP_FILENAME_MAX); if (!name) + name = Yap_guessFileName(fd, sno); + if (!name) { Yap_Error(SYSTEM_ERROR_INTERNAL, file_name, - "Yap_guessFileName failed: opening a file without a name"); - st->name = Yap_LookupAtom(name); + "Yap_guessFileName failed: opening a file without a name"); + return false; + } + st->name = name; st->user_name = file_name; st->file = fd; st->linepos = 0; @@ -1314,7 +1316,7 @@ 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, + Yap_initStream(sno, st->file, Yap_LookupAtom(fname), io_mode, user_name, LOCAL_encoding, st->status, vfsp); return true; } 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 old mode 100644 new mode 100755 index c51459aec..d813c76a2 --- a/os/streams.c +++ b/os/streams.c @@ -315,35 +315,35 @@ bool Yap_SetCurInpPos( return true; } -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); +char *Yap_guessFileName(FILE *file, int sno) { + size_t maxs = YAP_FILENAME_MAX-1; + char *nameb = malloc(maxs + 1); if (!file) { strncpy(nameb, "memory buffer", maxs); - return pop_output_text_stack(i,nameb); + return nameb; } int f = fileno(file); if (f < 0) { strcpy(nameb, "???"); - return pop_output_text_stack(i,nameb); + return nameb; } #if __linux__ - char *path = Malloc(1024); + char *path = malloc(1024); if (snprintf(path, 1023, "/proc/self/fd/%d", f) && readlink(path, nameb, maxs)) { - return pop_output_text_stack(i,nameb); + free(path); + return nameb; } #elif __APPLE__ if (fcntl(f, F_GETPATH, nameb) != -1) { - return pop_output_text_stack(i,nameb); + return nameb; } #else - TCHAR *path = Malloc(MAX_PATH + 1); + TCHAR *path = malloc(MAX_PATH + 1); if (!GetFullPathName(path, MAX_PATH, path, NULL)) { - pop_text_stack(i); + return NULL; } else { int i; @@ -351,14 +351,12 @@ char *Yap_guessFileName(FILE *file, int sno, size_t max) { for (i = 0; i < strlen(path); i++) ptr += put_utf8(ptr, path[i]); *ptr = '\0'; - return pop_output_text_stack(i,nameb); + return nameb; } #endif if (!StreamName(sno)) { - pop_text_stack(i); return NULL; } - pop_text_stack(i); return RepAtom(AtomOfTerm(StreamName(sno)))->StrOfAE; } diff --git a/os/yapio.h b/os/yapio.h old mode 100644 new mode 100755 index 5ef858027..fc2d87b02 --- a/os/yapio.h +++ b/os/yapio.h @@ -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, size_t max); +extern char *Yap_guessFileName(FILE *f, int sno); extern void Yap_plwrite(Term t, struct stream_desc *mywrite, int max_depth, int flags, int priority); diff --git a/pl/protect.yap b/pl/protect.yap index 7d9bc46dd..ff3b2753a 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),