Skip to content

Commit

Permalink
fix: reloading of modules (multiply calling LIB("file.so")) is ignored
Browse files Browse the repository at this point in the history
add: dynl_check_opened newly introduced
  • Loading branch information
alexanderdreyer committed Dec 14, 2012
1 parent c1e7a64 commit f4399e8
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 8 deletions.
19 changes: 14 additions & 5 deletions Singular/iplib.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1078,6 +1078,10 @@ BOOLEAN load_modules(char *newlib, char *fullname, BOOLEAN autoexport)
goto load_modules_end;
}
}
if (dynl_check_opened(FullName)) {
if (BVERBOSE(V_LOAD_LIB)) Warn( "%s already loaded", fullname);
return FALSE;
}
if((IDPACKAGE(pl)->handle=dynl_open(FullName))==(void *)NULL)
{
Werror("dynl_open failed:%s", dynl_error());
Expand Down Expand Up @@ -1124,13 +1128,18 @@ BOOLEAN load_builtin(char *newlib, BOOLEAN autoexport, SModulFunc_t init)
int token;

pl = IDROOT->get(plib,0);
if (pl==NULL)
if (pl!=NULL)
{
pl = enterid( plib,0, PACKAGE_CMD, &IDROOT,
TRUE );
IDPACKAGE(pl)->language = LANG_C;
IDPACKAGE(pl)->libname=omStrDup(newlib);
if (BVERBOSE(V_LOAD_LIB)) Warn( "(builtin) %s already loaded", newlib);
omFree(plib);
return FALSE;
}

pl = enterid( plib,0, PACKAGE_CMD, &IDROOT,
TRUE );
IDPACKAGE(pl)->language = LANG_C;
IDPACKAGE(pl)->libname=omStrDup(newlib);

IDPACKAGE(pl)->handle=(void *)NULL;
SModulFunctions sModulFunctions;

Expand Down
27 changes: 26 additions & 1 deletion libpolys/polys/mod_raw.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
/*
* ABSTRACT: machine depend code for dynamic modules
*
* Provides: dynl_open()
* Provides: dynl_check_opened()
* dynl_open()
* dynl_sym()
* dynl_error()
* dynl_close()
Expand Down Expand Up @@ -240,6 +241,13 @@ extern "C" {
#define DL_IMPLEMENTED

static void* kernel_handle = NULL;
int dynl_check_opened(
char *filename /* I: filename to check */
)
{
return dlopen(filename,RTLD_NOW|RTLD_NOLOAD) != NULL;
}

void *dynl_open(
char *filename /* I: filename to load */
)
Expand Down Expand Up @@ -285,6 +293,18 @@ const char *dynl_error()

typedef char *((*func_ptr) ());

int dynl_check_opened( /* NOTE: untested */
char *filename /* I: filename to check */
)
{
struct shl_descriptor *desc;
for (int idx = 0; shl_get(idx, &desc) != -1; ++idx)
{
if (strcmp(filename, desc->filename) == 0) return TRUE;
}
return FALSE;
}

void *dynl_open(char *filename)
{
shl_t handle = shl_load(filename, BIND_DEFERRED, 0);
Expand Down Expand Up @@ -328,6 +348,11 @@ const char *dynl_error()
*****************************************************************************/
#ifndef DL_IMPLEMENTED

int dynl_check_opened(char *filename)
{
return FALSE;
}

void *dynl_open(char *filename)
{
return(NULL);
Expand Down
8 changes: 6 additions & 2 deletions libpolys/polys/mod_raw.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

#ifndef MOD_RAW_H
#define MOD_RAW_H
/****************************************
Expand All @@ -6,7 +7,8 @@
/*
* ABSTRACT: machine depend code for dynamic modules
*
* Provides: dynl_open()
* Provides: dynl_check_opened()
* dynl_open()
* dynl_sym()
* dynl_error()
* dunl_close()
Expand All @@ -25,6 +27,7 @@ void* dynl_sym_warn(void* handle, const char* proc, const char* msg = NULL );
#ifdef __cplusplus
extern "C" {
#endif
int dynl_check_opened(char* filename);
void * dynl_open(char *filename);
// if handle == DYNL_KERNEL_HANDLE, then symbol is searched for
// in kernel of program
Expand All @@ -46,7 +49,8 @@ const char * dynl_error();
#define SI_BUILTIN_PYOBJECT(add)
#endif

/// Use @c add(name) to add built-in library to macro
/// Data for @c type_of_LIB to determine built-in modules,
/// use @c add(name) to add built-in library to macro
#define SI_FOREACH_BUILTIN(add)\
add(huhu)\
SI_BUILTIN_PYOBJECT(add)
Expand Down

0 comments on commit f4399e8

Please sign in to comment.