Skip to content

Commit

Permalink
kernel: move GASMAN and GNU readline specific code out of InitSystem (
Browse files Browse the repository at this point in the history
#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.
  • Loading branch information
fingolfin authored Jan 6, 2025
1 parent d2dab76 commit 773b924
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 33 deletions.
11 changes: 11 additions & 0 deletions src/gasman.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions src/saveload.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
#include "sysstr.h"
#include "version.h"

#include "config.h"

#include <stdio.h>
#include <unistd.h>

Expand Down Expand Up @@ -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;
}

Expand Down
10 changes: 10 additions & 0 deletions src/sysfiles.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
42 changes: 9 additions & 33 deletions src/system.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}


Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -656,40 +659,13 @@ 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();

// now that the user has had a chance to give -x and -y,
// 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();
Expand Down

0 comments on commit 773b924

Please sign in to comment.