Skip to content

Commit

Permalink
Remove crc argument to Load{Dynamic,Static}Module
Browse files Browse the repository at this point in the history
No caller used it, and using it correctly would have been both non-trivial,
and generally of limited use (as only the arbitrary hardcoded "crc" value in
the module's `StructInitInfo` instance is checked)
  • Loading branch information
fingolfin committed May 18, 2021
1 parent 1dc1f81 commit 2e22e9a
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 91 deletions.
15 changes: 2 additions & 13 deletions doc/ref/gappkg.xml
Original file line number Diff line number Diff line change
Expand Up @@ -148,25 +148,14 @@ with <Ref Func="LoadDynamicModule"/>.
</Subsection>

<ManSection>
<Func Name="LoadDynamicModule" Arg='filename[, crc]'/>
<Func Name="LoadDynamicModule" Arg='filename'/>

<Description>
To load a compiled file, the command <Ref Func="LoadDynamicModule"/> is used.
This command loads <A>filename</A> as module. If given, the CRC checksum
<A>crc</A> must match the value of the module (see <Ref Sect="CrcFile"/>).
This command loads <A>filename</A> as module.
<P/>
<Log><![CDATA[
gap> LoadDynamicModule("./test.so");
gap> CrcFile("test.so");
2906458206
gap> LoadDynamicModule("./test.so",1);
Error, <crc> mismatch (or no support for dynamic loading) called from
<function>( <arguments> ) called from read-eval-loop
Entering break read-eval-print loop ...
you can 'quit;' to quit to outer loop, or
you can 'return;' to continue
brk> quit;
gap> LoadDynamicModule("./test.so",2906458206);
]]></Log>
<P/>
On some operating systems, once you have loaded a dynamic module with
Expand Down
47 changes: 13 additions & 34 deletions lib/files.gd
Original file line number Diff line number Diff line change
Expand Up @@ -564,63 +564,42 @@ end );

#############################################################################
##
#F LoadDynamicModule( <filename> [, <crc> ] ) . . . . . . . . load a module
#F LoadDynamicModule( <filename> ) . . . . . . . . . . . . . . try to load a dynamic module
##
## <ManSection>
## <Func Name="LoadDynamicModule" Arg='filename [, crc ]'/>
## <Func Name="LoadDynamicModule" Arg='filename'/>
##
## <Description>
## </Description>
## </ManSection>
##
BIND_GLOBAL( "LoadDynamicModule", function( arg )
BIND_GLOBAL( "LoadDynamicModule", function( filename )

if Length(arg) = 1 then
if not LOAD_DYN( arg[1], false ) then
Error( "no support for dynamic loading" );
fi;
elif Length(arg) = 2 then
if not LOAD_DYN( arg[1], arg[2] ) then
Error( "<crc> mismatch (or no support for dynamic loading)" );
fi;
else
Error( "usage: LoadDynamicModule( <filename> [, <crc> ] )" );
if not LOAD_DYN( filename ) then
Error( "no support for dynamic loading" );
fi;

end );

#############################################################################
##
#F LoadStaticModule( <filename> [, <crc> ] ) . . . . . . . . load a module
#F LoadStaticModule( <filename> ) . . . . . . . . . . . . . . try to load a static module
##
## <ManSection>
## <Func Name="LoadStaticModule" Arg='filename [, crc ]'/>
## <Func Name="LoadStaticModule" Arg='filename'/>
##
## <Description>
## </Description>
## </ManSection>
##
BIND_GLOBAL( "LoadStaticModule", function( arg )

if Length(arg) = 1 then
if not arg[1] in SHOW_STAT() then
Error( "unknown static module ", arg[1] );
fi;
BIND_GLOBAL( "LoadStaticModule", function( filename )

if not LOAD_STAT( arg[1], false ) then
Error( "loading static module ", arg[1], " failed" );
fi;
elif Length(arg) = 2 then
if not arg[1] in SHOW_STAT() then
Error( "unknown static module ", arg[1] );
fi;
if not filename in SHOW_STAT() then
Error( "unknown static module ", filename );
fi;

if not LOAD_STAT( arg[1], arg[2] ) then
Error( "loading static module ", arg[1],
" failed, possible crc mismatch" );
fi;
else
Error( "usage: LoadStaticModule( <filename> [, <crc> ] )" );
if not LOAD_STAT( filename ) then
Error( "loading static module ", filename, " failed" );
fi;

end );
Expand Down
40 changes: 6 additions & 34 deletions src/modules.c
Original file line number Diff line number Diff line change
Expand Up @@ -232,14 +232,11 @@ static Int SyLoadModule(const Char * name, InitInfoFunc * func)

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

#if !defined(HAVE_DLOPEN)
/* no dynamic library support */
Expand Down Expand Up @@ -279,17 +276,6 @@ 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;
}
}

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

Expand All @@ -300,16 +286,13 @@ static Obj FuncLOAD_DYN(Obj self, Obj filename, Obj crc)

/****************************************************************************
**
*F FuncLOAD_STAT( <self>, <name>, <crc> ) . . . . try to load static module
*F FuncLOAD_STAT( <self>, <name> ) . . . . . . . try to load a static module
*/
static Obj FuncLOAD_STAT(Obj self, Obj filename, Obj crc)
static Obj FuncLOAD_STAT(Obj self, Obj filename)
{
StructInitInfo * info = 0;

RequireStringRep(SELF_NAME, filename);
if (!IS_INTOBJ(crc) && crc != False) {
RequireArgument(SELF_NAME, crc, "must be a small integer or 'false'");
}

/* try to find the module */
info = LookupStaticModule(CONST_CSTR_STRING(filename));
Expand All @@ -321,17 +304,6 @@ static Obj FuncLOAD_STAT(Obj self, Obj filename, Obj crc)
return False;
}

/* check the crc value */
if (crc != False) {
if (INT_INTOBJ(crc) != info->crc) {
if (SyDebugLoading) {
Pr("#I LOAD_STAT: crc values do not match, gap %d, stat %d\n",
INT_INTOBJ(crc), info->crc);
}
return False;
}
}

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

Expand Down Expand Up @@ -1079,8 +1051,8 @@ void ModulesPostRestore(void)
*/
static StructGVarFunc GVarFuncs[] = {
GVAR_FUNC_1ARGS(GAP_CRC, filename),
GVAR_FUNC_2ARGS(LOAD_DYN, filename, crc),
GVAR_FUNC_2ARGS(LOAD_STAT, filename, crc),
GVAR_FUNC_1ARGS(LOAD_DYN, filename),
GVAR_FUNC_1ARGS(LOAD_STAT, filename),
GVAR_FUNC_0ARGS(SHOW_STAT),
GVAR_FUNC_0ARGS(LoadedModules),
GVAR_FUNC_0ARGS(ExportToKernelFinished),
Expand Down
2 changes: 1 addition & 1 deletion tst/test-compile/run_compiled_static.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ rm -rf .libs "$gfile.comp"*

"$gac" "$gfile" -o "$gfile.comp" 2>&1 >/dev/null

echo "LOAD_STAT(\"$gfile\",false);; runtest();" |
echo "LoadStaticModule(\"$gfile\");; runtest();" |
"./$gfile.comp" -l "$GAPROOT" -r -A -q -b -x 200 2>&1 |
sed "s:${GAPROOT//:/\\:}:GAPROOT:g"

Expand Down
12 changes: 3 additions & 9 deletions tst/testinstall/kernel/gap.tst
Original file line number Diff line number Diff line change
Expand Up @@ -131,19 +131,13 @@ gap> GAP_CRC("foobar");
0

#
gap> LOAD_DYN(fail, fail);
gap> LOAD_DYN(fail);
Error, LOAD_DYN: <filename> must be a string (not the value 'fail')
gap> LOAD_DYN("foobar", fail);
Error, LOAD_DYN: <crc> must be a small integer or 'false' (not the value 'fail\
')

#
gap> LOAD_STAT(fail, fail);
gap> LOAD_STAT(fail);
Error, LOAD_STAT: <filename> must be a string (not the value 'fail')
gap> LOAD_STAT("foobar", fail);
Error, LOAD_STAT: <crc> must be a small integer or 'false' (not the value 'fai\
l')
gap> LOAD_STAT("foobar", false);
gap> LOAD_STAT("foobar");
false

#
Expand Down

0 comments on commit 2e22e9a

Please sign in to comment.