From a0ac0f1bc48afa19611b72382abf8cc5250442bc Mon Sep 17 00:00:00 2001 From: Max Horn Date: Thu, 26 Nov 2020 12:05:34 +0100 Subject: [PATCH] WIP LoadPackageKernelExtension, IsPackageKernelExtensionAvailable --- lib/files.gd | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++ lib/package.gi | 12 +++++++++++ src/modules.c | 15 +++++++------- 3 files changed, 75 insertions(+), 7 deletions(-) diff --git a/lib/files.gd b/lib/files.gd index c13f250e3f7..c58b64bc409 100644 --- a/lib/files.gd +++ b/lib/files.gd @@ -626,6 +626,61 @@ BIND_GLOBAL( "LoadStaticModule", function( arg ) end ); +############################################################################# +## +#F IsPackageKernelExtensionAvailable( [, ] ) +## +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( [, ] )" ); + 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( [, ] ) +## +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( [, ] )" ); + 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( ) . . . . . . . . . . . . . . . . . edit and read file diff --git a/lib/package.gi b/lib/package.gi index 489256f1638..ccfcad050d5 100644 --- a/lib/package.gi +++ b/lib/package.gi @@ -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 ); diff --git a/src/modules.c b/src/modules.c index 4896b3a2a48..1cdab369ea4 100644 --- a/src/modules.c +++ b/src/modules.c @@ -229,17 +229,14 @@ static Int SyLoadModule(const Char * name, InitInfoFunc * func) #endif - /**************************************************************************** ** *F FuncLOAD_DYN( , , ) . . . 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 */ @@ -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) { @@ -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