Skip to content

Commit

Permalink
WIP LoadPackageKernelExtension, IsPackageKernelExtensionAvailable
Browse files Browse the repository at this point in the history
  • Loading branch information
fingolfin committed Jan 27, 2021
1 parent b5a4016 commit a0ac0f1
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 7 deletions.
55 changes: 55 additions & 0 deletions lib/files.gd
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
15 changes: 8 additions & 7 deletions src/modules.c
Original file line number Diff line number Diff line change
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,6 +276,7 @@ static Obj FuncLOAD_DYN(Obj self, Obj filename, Obj crc)
if (info->type % 10 > 2)
ErrorMayQuit("LOAD_DYN: Invalid kernel module", 0, 0);

#if 0
/* check the crc value */
if (crc != False) {
if (INT_INTOBJ(crc) != info->crc) {
Expand All @@ -289,9 +287,12 @@ static Obj FuncLOAD_DYN(Obj self, Obj filename, Obj crc)
return False;
}
}
#endif

ActivateModule(info);
RecordLoadedModule(info, 0, CONST_CSTR_STRING(filename));
if (justTestAvailability != True) {
ActivateModule(info);
RecordLoadedModule(info, 0, CONST_CSTR_STRING(filename));
}

return True;
#endif
Expand Down

0 comments on commit a0ac0f1

Please sign in to comment.