Skip to content

Commit

Permalink
Merge ea7194d into 653dfd1
Browse files Browse the repository at this point in the history
  • Loading branch information
fingolfin committed Jan 27, 2021
2 parents 653dfd1 + ea7194d commit 89e4961
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 17 deletions.
55 changes: 55 additions & 0 deletions lib/files.gd
Expand Up @@ -626,6 +626,61 @@ BIND_GLOBAL( "LoadStaticModule", function( arg )
end );


#############################################################################
##
#F IsPackageKernelExtensionAvailable( <pkgname> [, <modname> ] )
##
BIND_GLOBAL( "IsPackageKernelExtensionAvailable", function( pkgname, modname... )
local fname;

if Length(modname) = 0 then
modname := pkgname;
elif Length(modname) = 1 then
modname := modname[1];
else
Error( "usage: IsPackageKernelExtensionAvailable( <pkgname> [, <modname> ] )" );
fi;

if modname in SHOW_STAT() then
return true;
fi;
fname := Filename(DirectoriesPackagePrograms(pkgname), Concatenation(modname, ".so"));
if fname <> fail then
# TODO: better error handling?
return LOAD_DYN(fname, true);
fi;
return false;
end );


#############################################################################
##
#F LoadPackageKernelExtension( <pkgname> [, <modname> ] )
##
BIND_GLOBAL( "LoadPackageKernelExtension", function( pkgname, modname... )
local fname;

if Length(modname) = 0 then
modname := pkgname;
elif Length(modname) = 1 then
modname := modname[1];
else
Error( "usage: LoadPackageKernelExtension( <pkgname> [, <modname> ] )" );
fi;

if modname in SHOW_STAT() then
LoadStaticModule(modname);
return true;
fi;
fname := Filename(DirectoriesPackagePrograms(pkgname), Concatenation(modname, ".so"));
if fname <> fail then
LoadDynamicModule(fname);
return true;
fi;
return false;
end );


#############################################################################
##
#F Edit( <filename> ) . . . . . . . . . . . . . . . . . edit and read file
Expand Down
12 changes: 12 additions & 0 deletions lib/package.gi
Expand Up @@ -1210,6 +1210,18 @@ InstallGlobalFunction( DirectoriesPackagePrograms, function( name )
# This package is not known.
return [];
fi;
# FIXME: inject another secondary path??? to allow "out of tree builds"
# for packages, and/or allow GAP itself to store binaries for the package
# so that the precise combination of GAP and package are matched...
# That is, take the precise GAP version (possibly including the git commit
# it was compiled from), plus the package version (and possibly also the locations of both?)
# and combine them into a unique ID (e.g. via a hash), then use that to
# store .so binaries


# also add a new mechanism to integrate kernel extensions into a package:
# let the package declare in its PackageInfo.g that it has a kernel extension;
# how to build it; what's its name; then GAP can take care of that dynamically
return [ Directory( Concatenation( installationpath, "/bin/",
GAPInfo.Architecture, "/" ) ) ];
end );
Expand Down
22 changes: 5 additions & 17 deletions src/modules.c
Expand Up @@ -229,17 +229,14 @@ static Int SyLoadModule(const Char * name, InitInfoFunc * func)
#endif



/****************************************************************************
**
*F FuncLOAD_DYN( <self>, <name>, <crc> ) . . . try to load a dynamic module
*/
static Obj FuncLOAD_DYN(Obj self, Obj filename, Obj crc)
static Obj FuncLOAD_DYN(Obj self, Obj filename, Obj justTestAvailability)
{
RequireStringRep(SELF_NAME, filename);
if (!IS_INTOBJ(crc) && crc != False) {
RequireArgument(SELF_NAME, crc, "must be a small integer or 'false'");
}
RequireTrueOrFalse(SELF_NAME, justTestAvailability);

#if !defined(HAVE_DLOPEN)
/* no dynamic library support */
Expand Down Expand Up @@ -279,20 +276,11 @@ static Obj FuncLOAD_DYN(Obj self, Obj filename, Obj crc)
if (info->type % 10 > 2)
ErrorMayQuit("LOAD_DYN: Invalid kernel module", 0, 0);

/* check the crc value */
if (crc != False) {
if (INT_INTOBJ(crc) != info->crc) {
if (SyDebugLoading) {
Pr("#I LOAD_DYN: crc values do not match, gap %d, dyn %d\n",
INT_INTOBJ(crc), info->crc);
}
return False;
}
if (justTestAvailability != True) {
ActivateModule(info);
RecordLoadedModule(info, 0, CONST_CSTR_STRING(filename));
}

ActivateModule(info);
RecordLoadedModule(info, 0, CONST_CSTR_STRING(filename));

return True;
#endif
}
Expand Down

0 comments on commit 89e4961

Please sign in to comment.