Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions src/gap.c
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ int realmain(int argc, const char * argv[])
Int4 crc; // crc of file to compile

// initialize everything and read init.g which runs the GAP session
InitializeGap(&argc, argv, 1);
InitializeGap(&argc, argc, argv, 1);
if (!STATE(UserHasQUIT)) { /* maybe the user QUIT from the initial
read of init.g somehow*/
// maybe compile in which case init.g got skipped
Expand Down Expand Up @@ -1452,21 +1452,18 @@ StructInitInfo * InitInfoGap ( void )
** function. We use the resulting pointer as a hint to the garbage collector
** as to where the execution stack (might) start.
*/
void InitializeGap(int * pargc, const char * argv[], BOOL handleSignals)
void InitializeGap(void * stackBottom, int argc, const char * argv[], BOOL handleSignals)
{
const int argc = *pargc;

// initialize the basic system and gasman
InitSystem(argc, argv, handleSignals);

// Initialise memory -- have to do this here to make sure we are at top of C stack
InitBags(
Bag * alignedStackBottom = (Bag *)(((UInt)stackBottom / C_STACK_ALIGN) * C_STACK_ALIGN);
#if defined(USE_GASMAN)
SyStorMin,
InitBags(SyStorMin, alignedStackBottom);
#else
0,
InitBags(0, alignedStackBottom);
#endif
(Bag *)(((UInt)pargc / C_STACK_ALIGN) * C_STACK_ALIGN));

STATE(UserHasQUIT) = FALSE;
STATE(UserHasQuit) = FALSE;
Expand All @@ -1478,6 +1475,8 @@ void InitializeGap(int * pargc, const char * argv[], BOOL handleSignals)
// call kernel initialisation
ModulesInitKernel();

InitRootPaths(argc, argv);

#ifdef HPCGAP
InitMainThread();
#endif
Expand Down
4 changes: 2 additions & 2 deletions src/gap.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ BOOL IsUsingLibGap(void);

/****************************************************************************
**
*F InitializeGap( <argc>, <argv>, <handleSignals> ) . . . . . . . init GAP
*F InitializeGap() . . . . . . . . . . . . . . . . . . . . . initialize GAP
*/
void InitializeGap(int * pargc, const char * argv[], BOOL handleSignals);
void InitializeGap(void * stackBottom, int argc, const char * argv[], BOOL handleSignals);


/****************************************************************************
Expand Down
2 changes: 1 addition & 1 deletion src/libgap-api.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ void GAP_Initialize(int argc,
{
UsingLibGap = TRUE;

InitializeGap(&argc, (const char **)argv, handleSignals);
InitializeGap(&argc, argc, (const char **)argv, handleSignals);
SetExtraMarkFuncBags(markBagsCallback);
STATE(JumpToCatchCallback) = errorCallback;

Expand Down
111 changes: 56 additions & 55 deletions src/listfunc.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,95 +44,96 @@
*/
static void AddList3(Obj list, Obj obj, Int pos)
{
Int len;
Int i;
Int len;
Int i;
len = LEN_LIST(list);
if (pos == (Int) -1)
pos = len + 1;
for (i = len +1; i > pos; i--)
ASS_LIST(list, i, ELM_LIST(list, i-1));
ASS_LIST( list, pos, obj );
if (pos == (Int)-1)
pos = len + 1;
for (i = len + 1; i > pos; i--)
ASS_LIST(list, i, ELM_LIST(list, i - 1));

Check warning on line 53 in src/listfunc.c

View check run for this annotation

Codecov / codecov/patch

src/listfunc.c#L53

Added line #L53 was not covered by tests
ASS_LIST(list, pos, obj);
}

void AddList (
Obj list,
Obj obj)
void AddList(Obj list, Obj obj)
{
AddList3(list, obj, -1);
AddList3(list, obj, -1);
}


static void AddPlist3(Obj list, Obj obj, Int pos)
void AddPlist3(Obj list, Obj obj, Int pos)
{
UInt len;
UInt len;

if ( ! IS_PLIST_MUTABLE(list) ) {
if (!IS_PLIST_MUTABLE(list)) {
ErrorMayQuit("List Assignment: <list> must be a mutable list", 0, 0);
}
// in order to be optimistic when building list call assignment
len = LEN_PLIST( list );
len = LEN_PLIST(list);
if (pos == (Int)-1)
pos = len + 1;
if ( len == 0) {
AssPlistEmpty( list, pos, obj );
pos = len + 1;
if (len == 0) {
AssPlistEmpty(list, pos, obj);
return;
}
if (pos <= len) {
GROW_PLIST(list, len+1);
SET_LEN_PLIST(list, len+1);
Obj * ptr = ADDR_OBJ(list) + pos;
SyMemmove(ptr + 1, ptr, sizeof(Obj) * (len - pos + 1));
GROW_PLIST(list, len + 1);
SET_LEN_PLIST(list, len + 1);
Obj * ptr = ADDR_OBJ(list) + pos;
SyMemmove(ptr + 1, ptr, sizeof(Obj) * (len - pos + 1));
}
ASS_LIST(list, pos, obj);
}

void AddPlist (
Obj list,
Obj obj)
void AddPlist(Obj list, Obj obj)

Check warning on line 87 in src/listfunc.c

View check run for this annotation

Codecov / codecov/patch

src/listfunc.c#L87

Added line #L87 was not covered by tests
{

AddPlist3(list, obj, -1);
AddPlist3(list, obj, -1);

Check warning on line 89 in src/listfunc.c

View check run for this annotation

Codecov / codecov/patch

src/listfunc.c#L89

Added line #L89 was not covered by tests
}

static Obj AddListOper;

static Obj FuncADD_LIST3(Obj self, Obj list, Obj obj, Obj pos)
{
// dispatch
Int ipos;
if (pos == (Obj)0)
ipos = -1;
else if (IS_POS_INTOBJ(pos))
ipos = INT_INTOBJ(pos);
else {
DoOperation3Args( self, list, obj, pos);
return (Obj) 0;
}
UInt tnum = TNUM_OBJ(list);
if ( IS_PLIST( list ) ) {
AddPlist3( list, obj, ipos );
} else if ( FIRST_LIST_TNUM <= tnum && tnum <= LAST_LIST_TNUM ) {
AddList3( list, obj, ipos );
#ifdef HPCGAP
// Only support adding to end of atomic lists
} else if ( tnum == T_ALIST && pos == (Obj)0 ) {
AddAList( list, obj );
#endif
} else {
if (pos == 0)
DoOperation2Args( self, list, obj );
else
DoOperation3Args( self, list, obj, pos);
}
if (!IS_POS_INTOBJ(pos)) {
DoOperation3Args(self, list, obj, pos);
return 0;
}

UInt tnum = TNUM_OBJ(list);
if (FIRST_PLIST_TNUM <= tnum && tnum <= LAST_PLIST_TNUM) {
AddPlist3(list, obj, INT_INTOBJ(pos));
return 0;
}
else if (FIRST_LIST_TNUM <= tnum && tnum <= LAST_LIST_TNUM) {
AddList3(list, obj, INT_INTOBJ(pos));
return 0;

Check warning on line 108 in src/listfunc.c

View check run for this annotation

Codecov / codecov/patch

src/listfunc.c#L107-L108

Added lines #L107 - L108 were not covered by tests
}
else {
DoOperation3Args(self, list, obj, pos);
}

return 0;
}


static Obj FuncADD_LIST(Obj self, Obj list, Obj obj)
{
FuncADD_LIST3(self, list, obj, (Obj)0);
return (Obj) 0;
UInt tnum = TNUM_OBJ(list);
if (FIRST_PLIST_TNUM <= tnum && tnum <= LAST_PLIST_TNUM) {
AddPlist3(list, obj, -1);
}
else if (FIRST_LIST_TNUM <= tnum && tnum <= LAST_LIST_TNUM) {
AddList3(list, obj, -1);
}
#ifdef HPCGAP
else if (tnum == T_ALIST) {
AddAList(list, obj);
}
#endif
else {
DoOperation2Args(self, list, obj);
}

return 0;
}


Expand Down
1 change: 1 addition & 0 deletions src/listfunc.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ void AddList(Obj list, Obj obj);

void AddPlist(Obj list, Obj obj);

void AddPlist3(Obj list, Obj obj, Int pos);

/****************************************************************************
**
Expand Down
84 changes: 47 additions & 37 deletions src/system.c
Original file line number Diff line number Diff line change
Expand Up @@ -360,11 +360,12 @@ static void usage(void)
}

struct optInfo {
Char shortkey;
Char longkey[50];
int (*handler)(const char * argv[], void *);
void *otherArg;
UInt minargs;
int phase;
char shortkey;
char longkey[50];
int (*handler)(const char * argv[], void *);
void *otherArg;
UInt minargs;
};


Expand Down Expand Up @@ -486,48 +487,48 @@ static int printVersion(const char * argv[], void * dummy)
// These options must be kept in sync with those in system.g, so the help
// output is correct
static const struct optInfo options[] = {
{ 'C', "", processCompilerArgs, 0, 4}, // must handle in kernel
{ 'D', "debug-loading", toggle, &SyDebugLoading, 0}, // must handle in kernel
{ 0, 'C', "", processCompilerArgs, 0, 4}, // must handle in kernel
{ 0, 'D', "debug-loading", toggle, &SyDebugLoading, 0}, // must handle in kernel
#if defined(USE_GASMAN) || defined(USE_BOEHM_GC)
{ 'K', "maximal-workspace", storeMemory2, &SyStorKill, 1}, // could handle from library with new interface
{ 0, 'K', "maximal-workspace", storeMemory2, &SyStorKill, 1}, // could handle from library with new interface
#endif
#ifdef GAP_ENABLE_SAVELOAD
{ 'L', "", storeString, &SyRestoring, 1}, // must be handled in kernel
{ 'R', "", unsetString, &SyRestoring, 0}, // kernel
{ 0, 'L', "", storeString, &SyRestoring, 1}, // must be handled in kernel
{ 0, 'R', "", unsetString, &SyRestoring, 0}, // kernel
#endif
{ 'M', "", toggle, &SyUseModule, 0}, // must be handled in kernel
{ 'e', "", toggle, &SyCTRD, 0 }, // kernel
{ 'f', "", forceLineEditing, (void *)2, 0 }, // probably library now
{ 'E', "", toggle, &SyUseReadline, 0 }, // kernel
{ 'l', "roots", setGapRootPath, 0, 1}, // kernel
{ 0, 'M', "", toggle, &SyUseModule, 0}, // must be handled in kernel
{ 0, 'e', "", toggle, &SyCTRD, 0 }, // kernel
{ 0, 'f', "", forceLineEditing, (void *)2, 0 }, // probably library now
{ 0, 'E', "", toggle, &SyUseReadline, 0 }, // kernel
{ 1, 'l', "roots", setGapRootPath, 0, 1}, // kernel
#ifdef USE_GASMAN
{ 'm', "", storeMemory2, &SyStorMin, 1 }, // kernel
{ 0, 'm', "", storeMemory2, &SyStorMin, 1 }, // kernel
#endif
{ 'r', "", toggle, &IgnoreGapRC, 0 }, // kernel
{ 0, 'r', "", toggle, &IgnoreGapRC, 0 }, // kernel
#ifdef USE_GASMAN
{ 's', "", storeMemory, &SyAllocPool, 1 }, // kernel
{ 0, 's', "", storeMemory, &SyAllocPool, 1 }, // kernel
#endif
{ 'n', "", forceLineEditing, 0, 0}, // prob library
{ 0, 'n', "", forceLineEditing, 0, 0}, // prob library
#ifdef USE_GASMAN
{ 'o', "", storeMemory2, &SyStorMax, 1 }, // library with new interface
{ 0, 'o', "", storeMemory2, &SyStorMax, 1 }, // library with new interface
#endif
{ 'p', "", toggle, &SyWindow, 0 }, // ??
{ 'q', "quiet", toggle, &SyQuiet, 0 }, // ??
{ 0, 'p', "", toggle, &SyWindow, 0 }, // ??
{ 0, 'q', "quiet", toggle, &SyQuiet, 0 }, // ??
#ifdef HPCGAP
{ 'S', "", toggle, &ThreadUI, 0 }, // Thread UI
{ 'Z', "", toggle, &DeadlockCheck, 0 }, // Deadlock prevention
{ 'P', "", storePosInteger, &SyNumProcessors, 1 }, // number of CPUs
{ 'G', "", storePosInteger, &SyNumGCThreads, 1 }, // number of GC threads
{ 0 , "single-thread", toggle, &SingleThreadStartup, 0 }, // startup with one thread only
{ 0, 'S', "", toggle, &ThreadUI, 0 }, // Thread UI
{ 0, 'Z', "", toggle, &DeadlockCheck, 0 }, // Deadlock prevention
{ 0, 'P', "", storePosInteger, &SyNumProcessors, 1 }, // number of CPUs
{ 0, 'G', "", storePosInteger, &SyNumGCThreads, 1 }, // number of GC threads
{ 0, 0 , "single-thread", toggle, &SingleThreadStartup, 0 }, // startup with one thread only
#endif
// The following options must be handled in the kernel so they are set up before loading the library
{ 0 , "prof", enableProfilingAtStartup, 0, 1}, // enable profiling at startup
{ 0 , "memprof", enableMemoryProfilingAtStartup, 0, 1 }, // enable memory profiling at startup
{ 0 , "cover", enableCodeCoverageAtStartup, 0, 1}, // enable code coverage at startup
{ 0 , "quitonbreak", toggle, &SyQuitOnBreak, 0}, // Quit GAP if we enter the break loop
{ 0 , "enableMemCheck", enableMemCheck, 0, 0 },
{ 0 , "version", printVersion, 0, 0 },
{ 0, "", 0, 0, 0}};
{ 0, 0 , "prof", enableProfilingAtStartup, 0, 1}, // enable profiling at startup
{ 0, 0 , "memprof", enableMemoryProfilingAtStartup, 0, 1 }, // enable memory profiling at startup
{ 0, 0 , "cover", enableCodeCoverageAtStartup, 0, 1}, // enable code coverage at startup
{ 0, 0 , "quitonbreak", toggle, &SyQuitOnBreak, 0}, // Quit GAP if we enter the break loop
{ 0, 0 , "enableMemCheck", enableMemCheck, 0, 0 },
{ 0, 0 , "version", printVersion, 0, 0 },
{ 0, 0, "", 0, 0, 0}};


static void InitSysOpts(void)
Expand Down Expand Up @@ -579,7 +580,7 @@ static void InitSysOpts(void)
SyWindow = 0;
}

static void ParseCommandLineOptions(int argc, const char * argv[])
static void ParseCommandLineOptions(int argc, const char * argv[], int phase)
{
// scan the command line for options that we have to process in the kernel
// we just scan the whole command line looking for the keys for the
Expand Down Expand Up @@ -637,7 +638,8 @@ static void ParseCommandLineOptions(int argc, const char * argv[])
usage();
}

(*options[i].handler)(argv + 1, options[i].otherArg);
if (options[i].phase == phase)
(*options[i].handler)(argv + 1, options[i].otherArg);

argv += options[i].minargs;
argc -= options[i].minargs;
Expand Down Expand Up @@ -687,7 +689,9 @@ void InitSystem(int argc, const char * argv[], BOOL handleSignals)

InitSysFiles();

ParseCommandLineOptions(argc, argv);
// first stage of command line options parsing: handle everything except
// for root paths
ParseCommandLineOptions(argc, argv, 0);

#ifdef HAVE_LIBREADLINE
InitReadline();
Expand All @@ -702,6 +706,12 @@ void InitSystem(int argc, const char * argv[], BOOL handleSignals)
SyRedirectStderrToStdOut();
syWinPut(0, "@p", "1.");
}
}

void InitRootPaths(int argc, const char * argv[])
{
// second stage of command line options parsing: handle root paths
ParseCommandLineOptions(argc, argv, 1);

InitDotGapPath();
}
4 changes: 4 additions & 0 deletions src/system.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,4 +136,8 @@ void Panic_(const char * file, int line, const char * fmt, ...) NORETURN
*/
void InitSystem(int argc, const char * argv[], BOOL handleSignals);


void InitRootPaths(int argc, const char * argv[]);


#endif // GAP_SYSTEM_H
Loading