From 7aaf37dd376f24c3be41cbd921c99ed438656607 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Sun, 17 Oct 2021 21:06:21 +0200 Subject: [PATCH 1/9] kernel: get rid of SYS_IS_DARWIN No package needs it: float defines its own version (but doesn't use it), CaratInterface has a faux reference, no other distributed package reference it As part of this, replace `task_self` by `mach_task_self`, the name used on macOS. The old name presumably was for use on NeXTStep, which is ancient history. --- GNUmakefile.in | 1 - configure.ac | 6 ------ src/gaptime.c | 8 ++++---- src/sysmem.c | 12 ++++-------- src/system.c | 4 ++-- 5 files changed, 10 insertions(+), 21 deletions(-) diff --git a/GNUmakefile.in b/GNUmakefile.in index fc2f839ee6..7afcbebb58 100644 --- a/GNUmakefile.in +++ b/GNUmakefile.in @@ -12,7 +12,6 @@ # # GAP specific -SYS_IS_DARWIN = @SYS_IS_DARWIN@ SYS_IS_CYGWIN32 = @SYS_IS_CYGWIN32@ ABI = @ABI@ ABI_CFLAGS = @ABI_CFLAGS@ diff --git a/configure.ac b/configure.ac index cbabd6334e..1446b2c3bc 100644 --- a/configure.ac +++ b/configure.ac @@ -896,15 +896,9 @@ case "$host_os" in AC_CONFIG_FILES([bin/gapcmd.bat:cnf/cygwin/gapcmd.bat.in], [chmod +x bin/gapcmd.bat]) ]) ;; - *darwin*) - AC_DEFINE([SYS_IS_DARWIN], [1], [define if this is the Darwin port]) - DARWIN=yes - ;; esac AC_SUBST([SYS_IS_CYGWIN32], [$CYGWIN]) -SYS_IS_DARWIN=$DARWIN -AC_SUBST([SYS_IS_DARWIN]) dnl diff --git a/src/gaptime.c b/src/gaptime.c index 34527add7a..0f647102f8 100644 --- a/src/gaptime.c +++ b/src/gaptime.c @@ -34,7 +34,7 @@ #include #endif -#ifdef SYS_IS_DARWIN +#ifdef __MACH__ // macOS #include #endif @@ -86,7 +86,7 @@ Int8 SyNanosecondsSinceEpoch(void) { Int8 res; -#if defined(SYS_IS_DARWIN) +#if defined(__MACH__) static mach_timebase_info_data_t timeinfo; if (timeinfo.denom == 0) { (void)mach_timebase_info(&timeinfo); @@ -146,7 +146,7 @@ static Int8 SyNanosecondsSinceEpochResolution(void) { Int8 res; -#if defined(SYS_IS_DARWIN) +#if defined(__MACH__) static mach_timebase_info_data_t timeinfo; if (timeinfo.denom == 0) { (void)mach_timebase_info(&timeinfo); @@ -254,7 +254,7 @@ static Obj FuncNanosecondsSinceEpochInfo(Obj self) const char * method = "unsupported"; Int monotonic = 0; -#if defined(SYS_IS_DARWIN) +#if defined(__MACH__) method = "mach_absolute_time"; monotonic = 1; #elif defined(HAVE_CLOCK_GETTIME) && defined(CLOCK_MONOTONIC) diff --git a/src/sysmem.c b/src/sysmem.c index ec84e2e35b..b96adb97da 100644 --- a/src/sysmem.c +++ b/src/sysmem.c @@ -340,7 +340,7 @@ void SyMAdviseFree(void) * Maybe we do want to do this until it breaks to avoid questions * by users... */ -#if !defined(NO_DIRTY_OSX_MMAP_TRICK) && defined(SYS_IS_DARWIN) +#if !defined(NO_DIRTY_OSX_MMAP_TRICK) && defined(__APPLE__) if (mmap(from, size, PROT_NONE, MAP_PRIVATE|MAP_ANONYMOUS|MAP_FIXED, -1, 0) != from) { Panic("OS X trick to free pages did not work!"); @@ -585,10 +585,6 @@ static UInt *** SyFreeBags_(UInt size) */ #ifdef HAVE_VM_ALLOCATE -#if (defined(SYS_IS_DARWIN) && SYS_IS_DARWIN) || defined(__gnu_hurd__) -#define task_self mach_task_self -#endif - static vm_address_t syBase; static UInt *** SyAllocBags_(UInt size) @@ -604,7 +600,7 @@ static UInt *** SyAllocBags_(UInt size) /* allocate memory anywhere on first call */ else if ( 0 < size && syBase == 0 ) { GAP_ASSERT(syWorksize == 0); - if ( vm_allocate(task_self(),&syBase,size*1024,TRUE) == KERN_SUCCESS ) { + if ( vm_allocate(mach_task_self(),&syBase,size*1024,TRUE) == KERN_SUCCESS ) { ret = (UInt***) syBase; } } @@ -613,7 +609,7 @@ static UInt *** SyAllocBags_(UInt size) else { vm_address_t adr; adr = (vm_address_t)( (char*) syBase + syWorksize*1024 ); - if ( vm_allocate(task_self(),&adr,size*1024,FALSE) == KERN_SUCCESS ) { + if ( vm_allocate(mach_task_self(),&adr,size*1024,FALSE) == KERN_SUCCESS ) { ret = (UInt***) ( (char*) syBase + syWorksize*1024 ); } } @@ -645,7 +641,7 @@ static UInt *** SyFreeBags_(UInt size) else if (syWorksize >= size && syWorksize - size >= SyStorMin) { vm_address_t adr; adr = (vm_address_t)( (char*) syBase + (syWorksize-size)*1024 ); - if ( vm_deallocate(task_self(),adr,size*1024) == KERN_SUCCESS ) { + if ( vm_deallocate(mach_task_self(),adr,size*1024) == KERN_SUCCESS ) { ret = (UInt***)( (char*) syBase + syWorksize*1024 ); syWorksize -= size; diff --git a/src/system.c b/src/system.c index 0a0ef7910e..cda01305b8 100644 --- a/src/system.c +++ b/src/system.c @@ -48,7 +48,7 @@ #include -#ifdef SYS_IS_DARWIN +#ifdef __MACH__ // Workaround: TRUE / FALSE are also defined by the OS X Mach-O headers #define ENUM_DYLD_BOOL #include @@ -338,7 +338,7 @@ static void SetupGAPLocation(const char * argv0) char locBuf[GAP_PATH_MAX] = ""; Int4 length = 0; -#ifdef SYS_IS_DARWIN +#if defined(__APPLE__) && defined(__MACH__) uint32_t len = sizeof(locBuf); if (_NSGetExecutablePath(locBuf, &len) != 0) { *locBuf = 0; // reset buffer after error From 56ede2ce6ba4992456dc0920107531ade02832c8 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Sun, 17 Oct 2021 22:08:18 +0200 Subject: [PATCH 2/9] kernel: move some #defines from .h to .c files --- src/debug.h | 2 -- src/integer.c | 4 +++- src/opers.cc | 3 +++ 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/debug.h b/src/debug.h index b3b4a35b63..6ce58276d7 100644 --- a/src/debug.h +++ b/src/debug.h @@ -23,8 +23,6 @@ // Enable various GAP debugging features #define COUNT_BAGS -#define COUNT_OPERS -#define DEBUG_GMP 1 #else #define GAP_ASSERT(x) #endif diff --git a/src/integer.c b/src/integer.c index c14245f29e..eb07a6ce79 100644 --- a/src/integer.c +++ b/src/integer.c @@ -103,7 +103,9 @@ static Obj ObjInt_UIntInv( UInt i ); /* debugging */ -#ifndef DEBUG_GMP +#ifdef GAP_KERNEL_DEBUG +#define DEBUG_GMP 1 +#else #define DEBUG_GMP 0 #endif diff --git a/src/opers.cc b/src/opers.cc index e40f266d77..50703277e6 100644 --- a/src/opers.cc +++ b/src/opers.cc @@ -50,6 +50,9 @@ extern "C" { } // extern "C" +#ifdef GAP_KERNEL_DEBUG +#define COUNT_OPERS +#endif #ifndef __has_cpp_attribute // For backwards compatibility #define __has_cpp_attribute(x) 0 From cadc2053a3db5498070247fb6e717b3da950e230 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Sun, 17 Oct 2021 22:16:13 +0200 Subject: [PATCH 3/9] kernel: define SIZEOF_VOID_P in header, not via autoconf --- src/common.h | 14 ++++++++++++++ src/intobj.h | 5 +++-- src/system.h | 8 -------- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/src/common.h b/src/common.h index 438f2c09c8..197e64d5ba 100644 --- a/src/common.h +++ b/src/common.h @@ -18,6 +18,20 @@ #include "debug.h" +// check if we are on a 64 or 32 bit machine; in the former +// case, define SYS_IS_64_BIT. +// also define SIZEOF_VOID_P for backwards compatibility with some +// GAP packages that expect it +#if INTPTR_MAX == INT64_MAX +#define SYS_IS_64_BIT 1 +#define SIZEOF_VOID_P 8 +#elif INTPTR_MAX == INT32_MAX +#undef SYS_IS_64_BIT +#define SIZEOF_VOID_P 4 +#else +#error Unknown pointer size or missing size macros! +#endif + // check that the pointer size detected by configure matches that of the // current compiler; this helps prevent kernel extensions from being // compiled with the wrong ABI diff --git a/src/intobj.h b/src/intobj.h index 09967f6e39..149afc8c8d 100644 --- a/src/intobj.h +++ b/src/intobj.h @@ -227,9 +227,9 @@ EXPORT_INLINE Obj prod_intobjs(Int l, Int r) #else #ifdef SYS_IS_64_BIT -typedef Int4 HalfInt; +#define HalfInt Int4 #else -typedef Int2 HalfInt; +#define HalfInt Int2 #endif EXPORT_INLINE Obj prod_intobjs(Int l, Int r) @@ -256,6 +256,7 @@ EXPORT_INLINE Obj prod_intobjs(Int l, Int r) return (Obj)0; } +#undef HalfInt #endif #define PROD_INTOBJS(o, l, r) ((o) = prod_intobjs((Int)(l), (Int)(r))) diff --git a/src/system.h b/src/system.h index 44904d6ab8..afc21015f9 100644 --- a/src/system.h +++ b/src/system.h @@ -17,14 +17,6 @@ #include "common.h" -/* check if we are on a 64 bit machine */ -#if SIZEOF_VOID_P == 8 -# define SYS_IS_64_BIT 1 -#elif !defined(SIZEOF_VOID_P) -# error Something is wrong with this GAP installation: SIZEOF_VOID_P not defined -#endif - - /**************************************************************************** ** *S GAP_PATH_MAX . . . . . . . . . . . . size for buffers storing file paths From 5d66d61acc5ce406a8c3673aba693889c4bc14c2 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Sun, 17 Oct 2021 22:41:51 +0200 Subject: [PATCH 4/9] kernel: define SYS_IS_CYGWIN32 in header, not via autoconf --- configure.ac | 1 - src/common.h | 7 +++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 1446b2c3bc..8c9a636673 100644 --- a/configure.ac +++ b/configure.ac @@ -881,7 +881,6 @@ esac case "$host_os" in *cygwin*) - AC_DEFINE([SYS_IS_CYGWIN32], [1], [define if this is the Cygwin32 port]) CYGWIN=yes AS_IF([test "x$enable_compat_mode" = xyes],[ diff --git a/src/common.h b/src/common.h index 197e64d5ba..079925d79e 100644 --- a/src/common.h +++ b/src/common.h @@ -38,6 +38,13 @@ GAP_STATIC_ASSERT(sizeof(void *) == SIZEOF_VOID_P, "sizeof(void *) is wrong"); +// check for cygwin +#if defined(__CYGWIN__) || defined(__CYGWIN32__) +// for historical reasons, the macro we define is called SYS_IS_CYGWIN32 +#define SYS_IS_CYGWIN32 1 +#endif + + #ifdef USE_GASMAN #define GAP_ENABLE_SAVELOAD #endif From 4b0a8f39287e33c8e44b736a85fe13f00fa35c53 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Mon, 18 Oct 2021 00:25:50 +0200 Subject: [PATCH 5/9] kernel: define gap_strlcpy & gap_strlcat unconditionally ... instead of only defining our own version of strlcat / strlcpy on systems where they are unavailable. This gets rid of a dependency on config.h in our header files. --- configure.ac | 3 --- src/error.c | 22 +++++++++++----------- src/gap.c | 8 ++++---- src/gvars.c | 6 +++--- src/io.c | 6 +++--- src/opers.cc | 8 ++++---- src/profile.c | 4 ++-- src/read.c | 2 +- src/scanner.c | 4 ++-- src/streams.c | 2 +- src/sysfiles.c | 12 ++++++------ src/sysroots.c | 6 +++--- src/sysstr.c | 18 ++++-------------- src/sysstr.h | 12 ++++-------- src/system.c | 12 ++++++------ 15 files changed, 54 insertions(+), 71 deletions(-) diff --git a/configure.ac b/configure.ac index 8c9a636673..3c9fa5d2f4 100644 --- a/configure.ac +++ b/configure.ac @@ -962,9 +962,6 @@ AC_CHECK_FUNCS([setitimer]) dnl check for functions dealing with virtual memory AC_CHECK_FUNCS([vm_allocate sbrk madvise sysconf]) -dnl check for functions dealing with strings and integers -AC_CHECK_FUNCS([strlcpy strlcmp strlcat]) - dnl check for large-file support (for accessing files whose sizes or inodes require 64bits) AC_SYS_LARGEFILE diff --git a/src/error.c b/src/error.c index c4f4536f1d..083576fadb 100644 --- a/src/error.c +++ b/src/error.c @@ -522,24 +522,24 @@ void RequireArgumentEx(const char * funcname, Int arg1 = 0; if (funcname) { - strlcat(msgbuf, funcname, sizeof(msgbuf)); - strlcat(msgbuf, ": ", sizeof(msgbuf)); + gap_strlcat(msgbuf, funcname, sizeof(msgbuf)); + gap_strlcat(msgbuf, ": ", sizeof(msgbuf)); } if (argname) { - strlcat(msgbuf, argname, sizeof(msgbuf)); - strlcat(msgbuf, " ", sizeof(msgbuf)); + gap_strlcat(msgbuf, argname, sizeof(msgbuf)); + gap_strlcat(msgbuf, " ", sizeof(msgbuf)); } - strlcat(msgbuf, msg, sizeof(msgbuf)); + gap_strlcat(msgbuf, msg, sizeof(msgbuf)); if (IS_INTOBJ(op)) { - strlcat(msgbuf, " (not the integer %d)", sizeof(msgbuf)); + gap_strlcat(msgbuf, " (not the integer %d)", sizeof(msgbuf)); arg1 = INT_INTOBJ(op); } else if (op == True) - strlcat(msgbuf, " (not the value 'true')", sizeof(msgbuf)); + gap_strlcat(msgbuf, " (not the value 'true')", sizeof(msgbuf)); else if (op == False) - strlcat(msgbuf, " (not the value 'false')", sizeof(msgbuf)); + gap_strlcat(msgbuf, " (not the value 'false')", sizeof(msgbuf)); else if (op == Fail) - strlcat(msgbuf, " (not the value 'fail')", sizeof(msgbuf)); + gap_strlcat(msgbuf, " (not the value 'fail')", sizeof(msgbuf)); else { const char * tnam = TNAM_OBJ(op); // heuristic to choose between 'a' and 'an': use 'an' before a vowel @@ -547,9 +547,9 @@ void RequireArgumentEx(const char * funcname, // "an FFE", so we add a special case for that as well if (TNUM_OBJ(op) == T_FFE || tnam[0] == 'a' || tnam[0] == 'e' || tnam[0] == 'i' || tnam[0] == 'o' || tnam[0] == 'u') - strlcat(msgbuf, " (not an %s)", sizeof(msgbuf)); + gap_strlcat(msgbuf, " (not an %s)", sizeof(msgbuf)); else - strlcat(msgbuf, " (not a %s)", sizeof(msgbuf)); + gap_strlcat(msgbuf, " (not a %s)", sizeof(msgbuf)); arg1 = (Int)tnam; } diff --git a/src/gap.c b/src/gap.c index ca282fb89f..d74832de84 100644 --- a/src/gap.c +++ b/src/gap.c @@ -375,7 +375,7 @@ static Obj FuncSHELL(Obj self, if (GET_LEN_STRING(prompt) > 80) ErrorMayQuit("SHELL: must be a string of length at most 80", 0, 0); promptBuffer[0] = '\0'; - strlcat(promptBuffer, CONST_CSTR_STRING(prompt), sizeof(promptBuffer)); + gap_strlcat(promptBuffer, CONST_CSTR_STRING(prompt), sizeof(promptBuffer)); if (preCommandHook == False) preCommandHook = 0; @@ -744,7 +744,7 @@ static Obj FuncGASMAN(Obj self, Obj args) if ( TNAM_TNUM(k) != 0 ) { Char buf[41]; buf[0] = '\0'; - strlcat( buf, TNAM_TNUM(k), sizeof(buf) ); + gap_strlcat( buf, TNAM_TNUM(k), sizeof(buf) ); Pr("%40s ", (Int)buf, 0); Pr("%8d %8d ", (Int)InfoBags[k].nrLive, (Int)(InfoBags[k].sizeLive/1024)); @@ -769,7 +769,7 @@ static Obj FuncGASMAN(Obj self, Obj args) InfoBags[k].sizeAll != 0) ) { Char buf[41]; buf[0] = '\0'; - strlcat( buf, TNAM_TNUM(k), sizeof(buf) ); + gap_strlcat( buf, TNAM_TNUM(k), sizeof(buf) ); Pr("%40s ", (Int)buf, 0); Pr("%8d %8d ", (Int)InfoBags[k].nrLive, (Int)(InfoBags[k].sizeLive/1024)); @@ -1502,7 +1502,7 @@ void InitializeGap ( char buf[41]; buf[0] = '\0'; - strlcat( buf, TNAM_TNUM(i), sizeof(buf) ); + gap_strlcat( buf, TNAM_TNUM(i), sizeof(buf) ); Pr("#W %36s ", (Int)buf, 0); Pr("%8d %8d ", (Int)InfoBags[i].nrLive, (Int)(InfoBags[i].sizeLive/1024)); diff --git a/src/gvars.c b/src/gvars.c index 5ce9fdf7ac..0b9f955301 100644 --- a/src/gvars.c +++ b/src/gvars.c @@ -677,8 +677,8 @@ UInt GVarName ( if (*cns) { /* only if a namespace is set */ len = strlen(name); if (name[len-1] == NSCHAR) { - strlcpy(gvarbuf, name, 512); - strlcat(gvarbuf, cns, sizeof(gvarbuf)); + gap_strlcpy(gvarbuf, name, 512); + gap_strlcat(gvarbuf, cns, sizeof(gvarbuf)); name = gvarbuf; } } @@ -721,7 +721,7 @@ UInt GVarName ( gvar = INTOBJ_INT(numGVars); SET_ELM_PLIST( TableGVars, pos, gvar ); if (name != gvarbuf) - strlcpy(gvarbuf, name, sizeof(gvarbuf)); + gap_strlcpy(gvarbuf, name, sizeof(gvarbuf)); string = MakeImmString(gvarbuf); #ifdef USE_GVAR_BUCKETS diff --git a/src/io.c b/src/io.c index e130c7b7e3..1c0dfc91e8 100644 --- a/src/io.c +++ b/src/io.c @@ -387,7 +387,7 @@ UInt OpenInput(TypInputFile * input, const Char * filename) else input->echo = FALSE; - strlcpy(input->name, filename, sizeof(input->name)); + gap_strlcpy(input->name, filename, sizeof(input->name)); input->gapnameid = 0; // start with an empty line @@ -427,7 +427,7 @@ UInt OpenInputStream(TypInputFile * input, Obj stream, BOOL echo) input->sline = 0; } input->echo = echo; - strlcpy(input->name, "stream", sizeof(input->name)); + gap_strlcpy(input->name, "stream", sizeof(input->name)); input->gapnameid = 0; // start with an empty line @@ -951,7 +951,7 @@ void SetPrompt(const char * prompt) { if (SyQuiet) prompt = ""; - strlcpy(STATE(Prompt), prompt, sizeof(STATE(Prompt))); + gap_strlcpy(STATE(Prompt), prompt, sizeof(STATE(Prompt))); } diff --git a/src/opers.cc b/src/opers.cc index 50703277e6..29cc99ed4f 100644 --- a/src/opers.cc +++ b/src/opers.cc @@ -1188,10 +1188,10 @@ Obj NewAndFilter ( s = CSTR_STRING(str); s[0] = '('; s[1] = 0; - strlcat(s, CONST_CSTR_STRING(NAME_FUNC(oper1)), str_len); - strlcat(s, " and ", str_len); - strlcat(s, CONST_CSTR_STRING(NAME_FUNC(oper2)), str_len); - strlcat(s, ")", str_len); + gap_strlcat(s, CONST_CSTR_STRING(NAME_FUNC(oper1)), str_len); + gap_strlcat(s, " and ", str_len); + gap_strlcat(s, CONST_CSTR_STRING(NAME_FUNC(oper2)), str_len); + gap_strlcat(s, ")", str_len); SET_LEN_STRING(str, str_len - 1); getter = NewFunctionT( T_FUNCTION, sizeof(OperBag), str, 1, diff --git a/src/profile.c b/src/profile.c index 2e44dee2ba..7a06415127 100644 --- a/src/profile.c +++ b/src/profile.c @@ -620,7 +620,7 @@ enableAtStartup(char * filename, Int repeats, TickMethod tickMethod) Panic("Failed to open '%s' for profiling output.\n", filename); } - strlcpy(profileState.filename, filename, GAP_PATH_MAX); + gap_strlcpy(profileState.filename, filename, GAP_PATH_MAX); ActivateHooks(&profileHooks); @@ -744,7 +744,7 @@ static Obj FuncACTIVATE_PROFILING(Obj self, fopenMaybeCompressed(CONST_CSTR_STRING(filename), &profileState); - strlcpy(profileState.filename, CONST_CSTR_STRING(filename), GAP_PATH_MAX); + gap_strlcpy(profileState.filename, CONST_CSTR_STRING(filename), GAP_PATH_MAX); if(profileState.Stream == 0) { HashUnlock(&profileState); diff --git a/src/read.c b/src/read.c index 62daff9f07..09a99bea2f 100644 --- a/src/read.c +++ b/src/read.c @@ -743,7 +743,7 @@ static LHSRef ReadVar(ReaderState * rs, TypSymbolSet follow) ref.type = R_GVAR; // we do not want to call GVarName on this value until after we // have checked if this is the argument to a lambda function - strlcpy(varname, rs->s.Value, sizeof(varname)); + gap_strlcpy(varname, rs->s.Value, sizeof(varname)); } // match away the identifier, now that we know the variable diff --git a/src/scanner.c b/src/scanner.c index ab70e0ca09..0440bc1755 100644 --- a/src/scanner.c +++ b/src/scanner.c @@ -221,8 +221,8 @@ void Match(ScannerState * s, /* else generate an error message and skip to a symbol in */ else { - strlcpy( errmsg, msg, sizeof(errmsg) ); - strlcat( errmsg, " expected", sizeof(errmsg) ); + gap_strlcpy( errmsg, msg, sizeof(errmsg) ); + gap_strlcat( errmsg, " expected", sizeof(errmsg) ); SyntaxError(s, errmsg); while (!IS_IN(s->Symbol, skipto)) s->Symbol = NextSymbol(s); diff --git a/src/streams.c b/src/streams.c index f468e348ea..ec30f26495 100644 --- a/src/streams.c +++ b/src/streams.c @@ -968,7 +968,7 @@ static Obj FuncREAD_GAP_ROOT(Obj self, Obj filename) RequireStringRep(SELF_NAME, filename); /* Copy to avoid garbage collection moving string */ - strlcpy(filenamecpy, CONST_CSTR_STRING(filename), GAP_PATH_MAX); + gap_strlcpy(filenamecpy, CONST_CSTR_STRING(filename), GAP_PATH_MAX); /* try to open the file */ return READ_GAP_ROOT(filenamecpy) ? True : False; } diff --git a/src/sysfiles.c b/src/sysfiles.c index bdb9a47ca0..be1e215886 100644 --- a/src/sysfiles.c +++ b/src/sysfiles.c @@ -675,8 +675,8 @@ Int SyFopen(const Char * name, const Char * mode, BOOL transparent_compress) } // set up - strlcpy(namegz, name, sizeof(namegz)); - if (strlcat(namegz, ".gz", sizeof(namegz)) >= sizeof(namegz)) { + gap_strlcpy(namegz, name, sizeof(namegz)); + if (gap_strlcat(namegz, ".gz", sizeof(namegz)) >= sizeof(namegz)) { // buffer was not big enough, give up namegz[0] = '\0'; } @@ -2100,11 +2100,11 @@ static Char * readlineFgets(Char * line, UInt length, Int fid, UInt block) } /* maybe add to history, we use key 0 for this function */ GAP_rl_func(0, 0); - strlcpy(line, rlres, length); + gap_strlcpy(line, rlres, length); // FIXME: handle the case where rlres contains more than length // characters better? free(rlres); - strlcat(line, "\n", length); + gap_strlcat(line, "\n", length); /* send the whole line (unclipped) to the window handler */ syWinPut( fid, (*line != '\0' ? "@r" : "@x"), line ); @@ -3061,8 +3061,8 @@ Int SyIsReadableFile ( const Char * name ) /* we might be able to read the file via zlib */ /* beware of buffer overflows */ - if ( strlcpy(xname, name, sizeof(xname)) < sizeof(xname) && - strlcat(xname, ".gz", sizeof(xname)) < sizeof(xname) ) { + if ( gap_strlcpy(xname, name, sizeof(xname)) < sizeof(xname) && + gap_strlcat(xname, ".gz", sizeof(xname)) < sizeof(xname) ) { res = access(xname, R_OK); } diff --git a/src/sysroots.c b/src/sysroots.c index ce441c2c8b..ebdbdb5967 100644 --- a/src/sysroots.c +++ b/src/sysroots.c @@ -54,9 +54,9 @@ Char * SyFindGapRootFile(const Char * filename, Char * buf, size_t size) { for (int k = 0; k < ARRAY_SIZE(SyGapRootPaths); k++) { if (SyGapRootPaths[k][0]) { - if (strlcpy(buf, SyGapRootPaths[k], size) >= size) + if (gap_strlcpy(buf, SyGapRootPaths[k], size) >= size) continue; - if (strlcat(buf, filename, size) >= size) + if (gap_strlcat(buf, filename, size) >= size) continue; if (SyIsReadableFile(buf) == 0) { return buf; @@ -181,7 +181,7 @@ void SySetGapRootPath(const Char * string) #ifdef HPCGAP // for each root to be added, we first add as a root if (n < MAX_GAP_DIRS) { - strlcpy(SyGapRootPaths[n], SyGapRootPaths[n - 1], + gap_strlcpy(SyGapRootPaths[n], SyGapRootPaths[n - 1], sizeof(SyGapRootPaths[n])); } strxcat(SyGapRootPaths[n - 1], "hpcgap/", diff --git a/src/sysstr.c b/src/sysstr.c index 067fb439cb..7159792612 100644 --- a/src/sysstr.c +++ b/src/sysstr.c @@ -13,10 +13,7 @@ #include "sysstr.h" - -#ifndef HAVE_STRLCPY - -size_t strlcpy(char * dst, const char * src, size_t len) +size_t gap_strlcpy(char * dst, const char * src, size_t len) { /* Keep a copy of the original src. */ const char * const orig_src = src; @@ -48,12 +45,7 @@ size_t strlcpy(char * dst, const char * src, size_t len) return src - orig_src - 1; } -#endif /* !HAVE_STRLCPY */ - - -#ifndef HAVE_STRLCAT - -size_t strlcat(char * dst, const char * src, size_t len) +size_t gap_strlcat(char * dst, const char * src, size_t len) { /* Keep a copy of the original dst. */ const char * const orig_dst = dst; @@ -85,18 +77,16 @@ size_t strlcat(char * dst, const char * src, size_t len) return (dst - orig_dst) + strlen(src); } -#endif /* !HAVE_STRLCAT */ - size_t strxcpy(char * dst, const char * src, size_t len) { - size_t res = strlcpy(dst, src, len); + size_t res = gap_strlcpy(dst, src, len); assert(res < len); return res; } size_t strxcat(char * dst, const char * src, size_t len) { - size_t res = strlcat(dst, src, len); + size_t res = gap_strlcat(dst, src, len); assert(res < len); return res; } diff --git a/src/sysstr.h b/src/sysstr.h index ba5ebc1956..1430f670eb 100644 --- a/src/sysstr.h +++ b/src/sysstr.h @@ -68,7 +68,7 @@ EXPORT_INLINE BOOL streq(const char * s1, const char * s2) /**************************************************************************** ** -*F strlcpy( , , ) +*F gap_strlcpy( , , ) ** ** Copy to buffer of size . At most -1 characters will ** be copied. Afterwards, is always 'NUL' terminated @@ -81,13 +81,11 @@ EXPORT_INLINE BOOL streq(const char * s1, const char * s2) ** but not by all, so we provide a fallback implementation for those ** systems that lack it. */ -#ifndef HAVE_STRLCPY -size_t strlcpy(char * dst, const char * src, size_t len); -#endif +size_t gap_strlcpy(char * dst, const char * src, size_t len); /**************************************************************************** ** -*F strlcat( , , ) +*F gap_strlcat( , , ) ** ** Appends to buffer of size (unlike 'strncat', is ** the full size of , not space left). @@ -101,9 +99,7 @@ size_t strlcpy(char * dst, const char * src, size_t len); ** but not by all, so we provide a fallback implementation for those ** systems that lack it. */ -#ifndef HAVE_STRLCAT -size_t strlcat(char * dst, const char * src, size_t len); -#endif +size_t gap_strlcat(char * dst, const char * src, size_t len); /**************************************************************************** ** diff --git a/src/system.c b/src/system.c index cda01305b8..b3bddcc6fe 100644 --- a/src/system.c +++ b/src/system.c @@ -304,8 +304,8 @@ find_yourself(const char * argv0, char * result, size_t resultsize) else if (strchr(argv0, '/')) { if (!getcwd(tmpbuf, sizeof(tmpbuf))) return; - strlcat(tmpbuf, "/", sizeof(tmpbuf)); - strlcat(tmpbuf, argv0, sizeof(tmpbuf)); + gap_strlcat(tmpbuf, "/", sizeof(tmpbuf)); + gap_strlcat(tmpbuf, argv0, sizeof(tmpbuf)); if (realpath(tmpbuf, result) && !access(result, F_OK)) { return; // success } @@ -313,12 +313,12 @@ find_yourself(const char * argv0, char * result, size_t resultsize) // executable name, like 'gap' else { char pathenv[GAP_PATH_MAX], *saveptr, *pathitem; - strlcpy(pathenv, getenv("PATH"), sizeof(pathenv)); + gap_strlcpy(pathenv, getenv("PATH"), sizeof(pathenv)); pathitem = strtok_r(pathenv, ":", &saveptr); for (; pathitem; pathitem = strtok_r(NULL, ":", &saveptr)) { - strlcpy(tmpbuf, pathitem, sizeof(tmpbuf)); - strlcat(tmpbuf, "/", sizeof(tmpbuf)); - strlcat(tmpbuf, argv0, sizeof(tmpbuf)); + gap_strlcpy(tmpbuf, pathitem, sizeof(tmpbuf)); + gap_strlcat(tmpbuf, "/", sizeof(tmpbuf)); + gap_strlcat(tmpbuf, argv0, sizeof(tmpbuf)); if (realpath(tmpbuf, result) && !access(result, F_OK)) { return; // success } From 0324ead7dc8e993878bc78a95874b1245031f075 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Mon, 18 Oct 2021 00:25:50 +0200 Subject: [PATCH 6/9] kernel: add comment to compiled.h about gap_all.h --- src/compiled.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/compiled.h b/src/compiled.h index d7ae692e71..7d0520af8a 100644 --- a/src/compiled.h +++ b/src/compiled.h @@ -19,12 +19,16 @@ // updated to not need it. #include +// HACK: most (all?) GAP packages with a kernel extension include compiled.h +// to get all GAP headers. They should ultimately all switch to including +// gap_all.h; however that header has only been available since GAP 4.11.0, so +// it will take some time for packages to make the switch. +#include "gap_all.h" + #ifdef __cplusplus extern "C" { #endif -#include "gap_all.h" - extern Obj InfoDecision; From e563856be4598762078ddfef37a310928af15fc0 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Mon, 18 Oct 2021 15:43:10 +0200 Subject: [PATCH 7/9] buildsys/kernel: move USE_GMP from configure.ac to common.h --- configure.ac | 5 ----- src/common.h | 5 +++++ 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/configure.ac b/configure.ac index 3c9fa5d2f4..aa073bf284 100644 --- a/configure.ac +++ b/configure.ac @@ -574,11 +574,6 @@ AC_SUBST([GMP_CPPFLAGS]) AC_SUBST([GMP_LDFLAGS]) AC_SUBST([GMP_LIBS]) -dnl Some packages check the USE_GMP flag; retain it for now to -dnl allow these packages to work correctly for now. We should -dnl remove this eventually. -AC_DEFINE([USE_GMP], [1], [for backwards compatibility]) - dnl Find zlib AC_ARG_WITH([zlib], diff --git a/src/common.h b/src/common.h index 079925d79e..9c015c23e5 100644 --- a/src/common.h +++ b/src/common.h @@ -45,6 +45,11 @@ GAP_STATIC_ASSERT(sizeof(void *) == SIZEOF_VOID_P, "sizeof(void *) is wrong"); #endif +// Some packages check the USE_GMP flag; retain it for now to allow these +// packages to work correctly for now. We should remove this eventually. +#define USE_GMP 1 + + #ifdef USE_GASMAN #define GAP_ENABLE_SAVELOAD #endif From 10e9de52f3817b3705072d723c0d03792dbf9ec5 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Mon, 18 Oct 2021 22:52:18 +0200 Subject: [PATCH 8/9] buildsys: restrict ALLOW_PURE_PTHREAD_GETSPECIFIC Now we only #define it when building HPC-GAP --- configure.ac | 2 ++ 1 file changed, 2 insertions(+) diff --git a/configure.ac b/configure.ac index aa073bf284..f7c477180e 100644 --- a/configure.ac +++ b/configure.ac @@ -393,6 +393,7 @@ dnl dnl Test if pthread_getspecific() can be overridden as dnl __attribute__((pure)). dnl +AS_IF([test "x$enable_hpcgap" = xyes],[ AC_MSG_CHECKING([[whether pthread_getspecific() can be made pure]]) AC_COMPILE_IFELSE( [AC_LANG_SOURCE([[ @@ -406,6 +407,7 @@ void * pthread_getspecific(pthread_key_t key); ], [ AC_MSG_RESULT(no) ]) +]) dnl dnl User setting: Debug mode (off by default) From da1a4fecb90e8e903d022aedb6f2cd6c05162df5 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Tue, 19 Oct 2021 16:14:14 +0200 Subject: [PATCH 9/9] kernel: replace some uses of gap_strlcat --- src/opers.cc | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/opers.cc b/src/opers.cc index 29cc99ed4f..f773d4d101 100644 --- a/src/opers.cc +++ b/src/opers.cc @@ -1169,7 +1169,6 @@ Obj NewAndFilter ( Int str_len; Obj str; - char* s; RequireFilter(0, oper1, ""); RequireFilter(0, oper2, ""); @@ -1185,14 +1184,12 @@ Obj NewAndFilter ( str_len = GET_LEN_STRING(NAME_FUNC(oper1)) + GET_LEN_STRING(NAME_FUNC(oper2)) + 8; str = NEW_STRING(str_len); - s = CSTR_STRING(str); - s[0] = '('; - s[1] = 0; - gap_strlcat(s, CONST_CSTR_STRING(NAME_FUNC(oper1)), str_len); - gap_strlcat(s, " and ", str_len); - gap_strlcat(s, CONST_CSTR_STRING(NAME_FUNC(oper2)), str_len); - gap_strlcat(s, ")", str_len); - SET_LEN_STRING(str, str_len - 1); + SET_LEN_STRING(str, 0); + AppendCStr(str, "(", 1); + AppendString(str, NAME_FUNC(oper1)); + AppendCStr(str, " and ", 5); + AppendString(str, NAME_FUNC(oper2)); + AppendCStr(str, ")", 1); getter = NewFunctionT( T_FUNCTION, sizeof(OperBag), str, 1, ArglistObj, (ObjFunc)DoAndFilter );