From 773b924db57f2b6f8920e9dcaac5594f5f95da75 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Mon, 6 Jan 2025 15:44:41 +0100 Subject: [PATCH] kernel: move GASMAN and GNU readline specific code out of `InitSystem` (#5893) SyUseReadline is always 0 / false if HAVE_LIBREADLINE is undefined. In fact ideally it would not even be defined unless HAVE_LIBREADLINE is defined, but we don't do that for logistical reasons: it would affect the ABI, and would require enforcing that `config.h` is included before `sysopt.h`, which just is not practical at this point. --- src/gasman.c | 11 +++++++++++ src/saveload.c | 4 ++++ src/sysfiles.c | 10 ++++++++++ src/system.c | 42 +++++++++--------------------------------- 4 files changed, 34 insertions(+), 33 deletions(-) diff --git a/src/gasman.c b/src/gasman.c index 6ad5d880c6..c12302dc0f 100644 --- a/src/gasman.c +++ b/src/gasman.c @@ -1270,6 +1270,17 @@ void SetStackBottomBags(void * StackBottom) void InitBags(UInt initial_size, Bag * stack_bottom) { + // fix max if it is lower than min + if (SyStorMax != 0 && SyStorMax < SyStorMin) { + SyStorMax = SyStorMin; + } + + // fix pool size if larger than SyStorKill + if (SyStorKill != 0 && SyAllocPool != 0 && + SyAllocPool > 1024 * SyStorKill) { + SyAllocPool = SyStorKill * 1024; + } + ClearGlobalBags(); // install the allocator and the abort function diff --git a/src/saveload.c b/src/saveload.c index f089fe9be5..a62de1ae6c 100644 --- a/src/saveload.c +++ b/src/saveload.c @@ -32,6 +32,8 @@ #include "sysstr.h" #include "version.h" +#include "config.h" + #include #include @@ -499,9 +501,11 @@ static Char * GetKernelDescription(void) { static Char SyKernelDescription[256]; strcpy(SyKernelDescription, SyKernelVersion); +#ifdef HAVE_LIBREADLINE if (SyUseReadline) { strcat(SyKernelDescription, " with readline"); } +#endif return SyKernelDescription; } diff --git a/src/sysfiles.c b/src/sysfiles.c index 1428e193be..50c221dcf9 100644 --- a/src/sysfiles.c +++ b/src/sysfiles.c @@ -3234,6 +3234,16 @@ void InitSysFiles(void) setbuf(stderr, (char *)0); #ifdef HAVE_LIBREADLINE + // don't use readline if in Window mode (e.g. for XGAP) + if (SyWindow) + SyUseReadline = 0; + + // don't use readline if stdin is not attached to a terminal + // FIXME: disabled this, as it breaks certain workspaces (see also + // issue https://github.com/gap-system/gap/issues/5014) + //else if (!isatty(fileno(stdin))) + // SyUseReadline = 0; + if (SyUseReadline) { rl_readline_name = "GAP"; rl_initialize(); diff --git a/src/system.c b/src/system.c index 52e9832f44..d848486597 100644 --- a/src/system.c +++ b/src/system.c @@ -249,13 +249,12 @@ UInt SyWindow; ** If ret is 0 'SyExit' should signal to a calling process that all is ok. ** If ret is 1 'SyExit' should signal a failure to the calling process. */ -void SyExit ( - UInt ret ) +void SyExit(UInt ret) { #ifdef USE_JULIA_GC jl_atexit_hook(ret); #endif - exit( (int)ret ); + exit((int)ret); } @@ -559,11 +558,15 @@ void InitSystem ( SyCompilePlease = 0; SyDebugLoading = 0; SyLineEdit = 1; -#ifdef HPCGAP +#ifdef HAVE_LIBREADLINE + #ifdef HPCGAP SyUseReadline = 0; - SyNumProcessors = SyCountProcessors(); -#else + #else SyUseReadline = 1; + #endif +#endif +#ifdef HPCGAP + SyNumProcessors = SyCountProcessors(); #endif SyNrCols = 0; SyNrColsLocked = 0; @@ -656,20 +659,6 @@ void InitSystem ( } } -#if !defined(HAVE_LIBREADLINE) - // don't use readline of readline is not available (obviously) - // so that e.g. the GAP banner reports this correctly. - SyUseReadline = 0; -#else - // don't use readline if in Window mode (e.g. for XGAP) - if (SyWindow) - SyUseReadline = 0; - // don't use readline if stdin is not attached to a terminal - // FIXME: disabled this, as it breaks certain workspaces (see also - // issue https://github.com/gap-system/gap/issues/5014) - //else if (!isatty(fileno(stdin))) - // SyUseReadline = 0; -#endif InitSysFiles(); @@ -677,19 +666,6 @@ void InitSystem ( // we determine the size of the screen ourselves getwindowsize(); -#ifdef USE_GASMAN - // fix max if it is lower than min - if ( SyStorMax != 0 && SyStorMax < SyStorMin ) { - SyStorMax = SyStorMin; - } - - // fix pool size if larger than SyStorKill - if ( SyStorKill != 0 && SyAllocPool != 0 && - SyAllocPool > 1024 * SyStorKill ) { - SyAllocPool = SyStorKill * 1024; - } -#endif - // when running in package mode set ctrl-d and line editing if ( SyWindow ) { SyRedirectStderrToStdOut();