Skip to content

Commit f4399e8

Browse files
fix: reloading of modules (multiply calling LIB("file.so")) is ignored
add: dynl_check_opened newly introduced
1 parent c1e7a64 commit f4399e8

3 files changed

Lines changed: 46 additions & 8 deletions

File tree

Singular/iplib.cc

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1078,6 +1078,10 @@ BOOLEAN load_modules(char *newlib, char *fullname, BOOLEAN autoexport)
10781078
goto load_modules_end;
10791079
}
10801080
}
1081+
if (dynl_check_opened(FullName)) {
1082+
if (BVERBOSE(V_LOAD_LIB)) Warn( "%s already loaded", fullname);
1083+
return FALSE;
1084+
}
10811085
if((IDPACKAGE(pl)->handle=dynl_open(FullName))==(void *)NULL)
10821086
{
10831087
Werror("dynl_open failed:%s", dynl_error());
@@ -1124,13 +1128,18 @@ BOOLEAN load_builtin(char *newlib, BOOLEAN autoexport, SModulFunc_t init)
11241128
int token;
11251129

11261130
pl = IDROOT->get(plib,0);
1127-
if (pl==NULL)
1131+
if (pl!=NULL)
11281132
{
1129-
pl = enterid( plib,0, PACKAGE_CMD, &IDROOT,
1130-
TRUE );
1131-
IDPACKAGE(pl)->language = LANG_C;
1132-
IDPACKAGE(pl)->libname=omStrDup(newlib);
1133+
if (BVERBOSE(V_LOAD_LIB)) Warn( "(builtin) %s already loaded", newlib);
1134+
omFree(plib);
1135+
return FALSE;
11331136
}
1137+
1138+
pl = enterid( plib,0, PACKAGE_CMD, &IDROOT,
1139+
TRUE );
1140+
IDPACKAGE(pl)->language = LANG_C;
1141+
IDPACKAGE(pl)->libname=omStrDup(newlib);
1142+
11341143
IDPACKAGE(pl)->handle=(void *)NULL;
11351144
SModulFunctions sModulFunctions;
11361145

libpolys/polys/mod_raw.cc

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
/*
55
* ABSTRACT: machine depend code for dynamic modules
66
*
7-
* Provides: dynl_open()
7+
* Provides: dynl_check_opened()
8+
* dynl_open()
89
* dynl_sym()
910
* dynl_error()
1011
* dynl_close()
@@ -240,6 +241,13 @@ extern "C" {
240241
#define DL_IMPLEMENTED
241242

242243
static void* kernel_handle = NULL;
244+
int dynl_check_opened(
245+
char *filename /* I: filename to check */
246+
)
247+
{
248+
return dlopen(filename,RTLD_NOW|RTLD_NOLOAD) != NULL;
249+
}
250+
243251
void *dynl_open(
244252
char *filename /* I: filename to load */
245253
)
@@ -285,6 +293,18 @@ const char *dynl_error()
285293

286294
typedef char *((*func_ptr) ());
287295

296+
int dynl_check_opened( /* NOTE: untested */
297+
char *filename /* I: filename to check */
298+
)
299+
{
300+
struct shl_descriptor *desc;
301+
for (int idx = 0; shl_get(idx, &desc) != -1; ++idx)
302+
{
303+
if (strcmp(filename, desc->filename) == 0) return TRUE;
304+
}
305+
return FALSE;
306+
}
307+
288308
void *dynl_open(char *filename)
289309
{
290310
shl_t handle = shl_load(filename, BIND_DEFERRED, 0);
@@ -328,6 +348,11 @@ const char *dynl_error()
328348
*****************************************************************************/
329349
#ifndef DL_IMPLEMENTED
330350

351+
int dynl_check_opened(char *filename)
352+
{
353+
return FALSE;
354+
}
355+
331356
void *dynl_open(char *filename)
332357
{
333358
return(NULL);

libpolys/polys/mod_raw.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
#ifndef MOD_RAW_H
23
#define MOD_RAW_H
34
/****************************************
@@ -6,7 +7,8 @@
67
/*
78
* ABSTRACT: machine depend code for dynamic modules
89
*
9-
* Provides: dynl_open()
10+
* Provides: dynl_check_opened()
11+
* dynl_open()
1012
* dynl_sym()
1113
* dynl_error()
1214
* dunl_close()
@@ -25,6 +27,7 @@ void* dynl_sym_warn(void* handle, const char* proc, const char* msg = NULL );
2527
#ifdef __cplusplus
2628
extern "C" {
2729
#endif
30+
int dynl_check_opened(char* filename);
2831
void * dynl_open(char *filename);
2932
// if handle == DYNL_KERNEL_HANDLE, then symbol is searched for
3033
// in kernel of program
@@ -46,7 +49,8 @@ const char * dynl_error();
4649
#define SI_BUILTIN_PYOBJECT(add)
4750
#endif
4851

49-
/// Use @c add(name) to add built-in library to macro
52+
/// Data for @c type_of_LIB to determine built-in modules,
53+
/// use @c add(name) to add built-in library to macro
5054
#define SI_FOREACH_BUILTIN(add)\
5155
add(huhu)\
5256
SI_BUILTIN_PYOBJECT(add)

0 commit comments

Comments
 (0)