Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: gap root path unification #5941

Draft
wants to merge 12 commits into
base: master
Choose a base branch
from
26 changes: 13 additions & 13 deletions lib/package.gi
Original file line number Diff line number Diff line change
Expand Up @@ -1862,19 +1862,19 @@
#F ExtendRootDirectories( <paths> )
##
InstallGlobalFunction( ExtendRootDirectories, function( rootpaths )
local i;

rootpaths:= Filtered( rootpaths, path -> not path in GAPInfo.RootPaths );
if not IsEmpty( rootpaths ) then
# 'DirectoriesLibrary' concatenates root paths with directory names.
for i in [ 1 .. Length( rootpaths ) ] do
if not EndsWith( rootpaths[i], "/" ) then
rootpaths[i]:= Concatenation( rootpaths[i], "/" );
fi;
od;
# Append the new root paths.
GAPInfo.RootPaths:= Immutable( Concatenation( GAPInfo.RootPaths,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've replaced this now with a loop that uses Add to add each path separately. Various reasons

  • the "skip paths already in the list" is more powerful if we do it after ensuring the trailing slash is there
  • for HPC-GAP compatibility we may have to switch GAPInfo.RootPaths from a plist to an atomic list, where Add is supported but not Append

Anyway this is of course also a natural place to turn relative paths in absolute ones, call realpath, etc. -- but that goes beyond the scope of this PR

rootpaths ) );
local path, changed;

changed:= false;

Check warning on line 1867 in lib/package.gi

View check run for this annotation

Codecov / codecov/patch

lib/package.gi#L1867

Added line #L1867 was not covered by tests
for path in rootpaths do
if not EndsWith( path, "/" ) then
path:= Concatenation( path, "/" );
fi;
if not path in GAPInfo.RootPaths then
Add( GAPInfo.RootPaths, path );
changed:= true;
fi;
od;

Check warning on line 1876 in lib/package.gi

View check run for this annotation

Codecov / codecov/patch

lib/package.gi#L1869-L1876

Added lines #L1869 - L1876 were not covered by tests
if changed then
# Clear the cache.
GAPInfo.DirectoriesLibrary:= AtomicRecord( rec() );
# Reread the package information.
Expand Down
17 changes: 9 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 @@ -1335,6 +1335,8 @@ static Int InitKernel (
InitGlobalBag( &WindowCmdString, "src/gap.c:WindowCmdString" );
InitGlobalBag( &KernelArgs, "src/gap.c:KernelArgs" );

InitGlobalBag( &SyGapRootPaths, "src/gap.c:SyGapRootPaths" ); // FIXME

// init filters and functions
InitHdlrFuncsFromTable( GVarFuncs );

Expand Down Expand Up @@ -1452,21 +1454,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 +1477,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 @@
{
UsingLibGap = TRUE;

InitializeGap(&argc, (const char **)argv, handleSignals);
InitializeGap(&argc, argc, (const char **)argv, handleSignals);

Check warning on line 62 in src/libgap-api.c

View check run for this annotation

Codecov / codecov/patch

src/libgap-api.c#L62

Added line #L62 was not covered by tests
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;

Check warning on line 98 in src/listfunc.c

View check run for this annotation

Codecov / codecov/patch

src/listfunc.c#L98

Added line #L98 was not covered by tests
}

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#L106-L108

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

Check warning on line 112 in src/listfunc.c

View check run for this annotation

Codecov / codecov/patch

src/listfunc.c#L111-L112

Added lines #L111 - L112 were not covered by tests

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
9 changes: 2 additions & 7 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ extern int realmain(int argc, const char * argv[]);

static void SetupInitialGapRoot(const char * argv0)
{
SySetGapRootPath(SYS_DEFAULT_PATHS);
gap_strlcpy(SyDefaultRootPath, SYS_DEFAULT_PATHS, sizeof(SyDefaultRootPath));
}

#else
Expand Down Expand Up @@ -165,19 +165,14 @@ static void SySetInitialGapRootPaths(const char * GAPExecLocation)
strxcat(initgbuf, "lib/init.g", sizeof(initgbuf));

if (SyIsReadableFile(initgbuf) == 0) {
SySetGapRootPath(pathbuf);
gap_strlcpy(SyDefaultRootPath, pathbuf, sizeof(SyDefaultRootPath));
// escape from loop
return;
}
// try up a directory level
strxcat(pathbuf, "../", sizeof(pathbuf));
}
}

// Set GAP root path to current directory, if we have no other
// idea, and for backwards compatibility.
// Note that GAPExecLocation must always end with a slash.
SySetGapRootPath("./");
}

static void SetupInitialGapRoot(const char * argv0)
Expand Down
10 changes: 4 additions & 6 deletions src/streams.c
Original file line number Diff line number Diff line change
Expand Up @@ -358,10 +358,8 @@ Obj READ_AS_FUNC(TypInputFile * input)
*/
Int READ_GAP_ROOT ( const Char * filename )
{
char path[GAP_PATH_MAX];

// try to find the GAP file
SyFindGapRootFile(filename, path, sizeof(path));
Obj path = SyFindGapRootFile(filename);

// try to find compiled version of the GAP file
if (SyUseModule) {
Expand All @@ -378,7 +376,7 @@ Int READ_GAP_ROOT ( const Char * filename )
if (info) {
// found a matching statically linked module; if there is also
// a GAP file, compare their CRC
if (*path && info->crc != SyGAPCRC(path)) {
if (path && info->crc != SyGAPCRC(CSTR_STRING(path))) {
Pr("#W Static module %s has CRC mismatch, ignoring\n",
(Int)filename, 0);
}
Expand All @@ -395,7 +393,7 @@ Int READ_GAP_ROOT ( const Char * filename )
}

// not found?
if (*path == 0)
if (path == 0)
return 0;

#ifdef GAP_ENABLE_SAVELOAD
Expand All @@ -415,7 +413,7 @@ Int READ_GAP_ROOT ( const Char * filename )
}

TypInputFile input;
if (!OpenInput(&input, path))
if (!OpenInput(&input, CSTR_STRING(path)))
return 0;

GAP_TRY
Expand Down
Loading
Loading