1
0
mirror of https://github.com/irssi/irssi.git synced 2024-08-18 03:54:16 -04:00

Module loading fixes.

git-svn-id: http://svn.irssi.org/repos/irssi/trunk@1762 dbcabf3a-b0e7-0310-adc4-f8d773084564
This commit is contained in:
Timo Sirainen 2001-08-17 13:52:14 +00:00 committed by cras
parent 422ef7759d
commit 2d37f461ac

View File

@ -131,10 +131,24 @@ static GModule *module_open(const char *name)
return module; return module;
} }
static char *module_get_func(const char *rootmodule, const char *submodule,
const char *function)
{
if (strcmp(submodule, "core") == 0)
return g_strconcat(rootmodule, "_core_", function, NULL);
if (strcmp(rootmodule, submodule) == 0)
return g_strconcat(rootmodule, "_", function, NULL);
return g_strconcat(submodule, "_", rootmodule, "_", function, NULL);
}
#define module_error(error, text, rootmodule, submodule) \ #define module_error(error, text, rootmodule, submodule) \
signal_emit("module error", 4, GINT_TO_POINTER(error), text, \ signal_emit("module error", 4, GINT_TO_POINTER(error), text, \
rootmodule, submodule) rootmodule, submodule)
/* Returns 1 if ok, 0 if error in module and
-1 if module wasn't found */
static int module_load_name(const char *path, const char *rootmodule, static int module_load_name(const char *path, const char *rootmodule,
const char *submodule, int silent) const char *submodule, int silent)
{ {
@ -150,16 +164,11 @@ static int module_load_name(const char *path, const char *rootmodule,
module_error(MODULE_ERROR_LOAD, g_module_error(), module_error(MODULE_ERROR_LOAD, g_module_error(),
rootmodule, submodule); rootmodule, submodule);
} }
return FALSE; return -1;
} }
/* get the module's init() function */ /* get the module's init() function */
if (strcmp(submodule, "core") == 0) initfunc = module_get_func(rootmodule, submodule, "init");
initfunc = g_strconcat(rootmodule, "_core_init", NULL);
else {
initfunc = g_strconcat(submodule, "_",
rootmodule, "_init", NULL);
}
if (!g_module_symbol(gmodule, initfunc, (gpointer *) &module_init)) { if (!g_module_symbol(gmodule, initfunc, (gpointer *) &module_init)) {
if (!silent) if (!silent)
@ -167,7 +176,7 @@ static int module_load_name(const char *path, const char *rootmodule,
rootmodule, submodule); rootmodule, submodule);
g_module_close(gmodule); g_module_close(gmodule);
g_free(initfunc); g_free(initfunc);
return FALSE; return 0;
} }
g_free(initfunc); g_free(initfunc);
@ -176,7 +185,10 @@ static int module_load_name(const char *path, const char *rootmodule,
module_init(); module_init();
module = module_find(rootmodule); module = module_find(rootmodule);
rec = module == NULL ? NULL : module_file_find(module, submodule); rec = module == NULL ? NULL :
strcmp(rootmodule, submodule) == 0 ?
module_file_find(module, "core") :
module_file_find(module, submodule);
if (rec == NULL) { if (rec == NULL) {
rec = module_register_full(rootmodule, submodule, NULL); rec = module_register_full(rootmodule, submodule, NULL);
rec->gmodule = gmodule; rec->gmodule = gmodule;
@ -184,7 +196,7 @@ static int module_load_name(const char *path, const char *rootmodule,
module_error(MODULE_ERROR_INVALID, NULL, module_error(MODULE_ERROR_INVALID, NULL,
rootmodule, submodule); rootmodule, submodule);
return FALSE; return 0;
} }
rec->gmodule = gmodule; rec->gmodule = gmodule;
@ -193,21 +205,21 @@ static int module_load_name(const char *path, const char *rootmodule,
settings_check_module(rec->defined_module_name); settings_check_module(rec->defined_module_name);
signal_emit("module loaded", 2, rec->root, rec); signal_emit("module loaded", 2, rec->root, rec);
return TRUE; return 1;
} }
static int module_load_prefixes(const char *path, const char *module, static int module_load_prefixes(const char *path, const char *module,
int start, int end, char **prefixes) int start, int end, char **prefixes)
{ {
GString *realpath; GString *realpath;
int ok; int status;
/* load module_core */ /* load module_core */
realpath = g_string_new(path); realpath = g_string_new(path);
g_string_insert(realpath, end, "_core"); g_string_insert(realpath, end, "_core");
ok = module_load_name(realpath->str, module, "core", FALSE); status = module_load_name(realpath->str, module, "core", FALSE);
if (ok && prefixes != NULL) { if (status > 0 && prefixes != NULL) {
/* load all the "prefix modules", like the fe-common, irc, /* load all the "prefix modules", like the fe-common, irc,
etc. part of the module */ etc. part of the module */
while (*prefixes != NULL) { while (*prefixes != NULL) {
@ -223,7 +235,7 @@ static int module_load_prefixes(const char *path, const char *module,
} }
g_string_free(realpath, TRUE); g_string_free(realpath, TRUE);
return ok; return status;
} }
static int module_load_full(const char *path, const char *rootmodule, static int module_load_full(const char *path, const char *rootmodule,
@ -231,7 +243,7 @@ static int module_load_full(const char *path, const char *rootmodule,
char **prefixes) char **prefixes)
{ {
MODULE_REC *module; MODULE_REC *module;
int ok, try_prefixes; int status, try_prefixes;
if (!g_module_supported()) if (!g_module_supported())
return FALSE; return FALSE;
@ -247,15 +259,15 @@ static int module_load_full(const char *path, const char *rootmodule,
/* check if the given module exists.. */ /* check if the given module exists.. */
try_prefixes = strcmp(rootmodule, submodule) == 0; try_prefixes = strcmp(rootmodule, submodule) == 0;
ok = module_load_name(path, rootmodule, submodule, try_prefixes); status = module_load_name(path, rootmodule, submodule, try_prefixes);
if (!ok && try_prefixes) { if (status == -1 && try_prefixes) {
/* nope, try loading the module_core, /* nope, try loading the module_core,
fe_module, etc. */ fe_module, etc. */
ok = module_load_prefixes(path, rootmodule, status = module_load_prefixes(path, rootmodule,
start, end, prefixes); start, end, prefixes);
} }
return ok; return status > 0;
} }
/* Load module - automatically tries to load also the related non-core /* Load module - automatically tries to load also the related non-core
@ -316,14 +328,7 @@ static void module_file_deinit_gmodule(MODULE_FILE_REC *file)
char *deinitfunc; char *deinitfunc;
/* call the module's deinit() function */ /* call the module's deinit() function */
if (strcmp(file->name, "core") == 0) { deinitfunc = module_get_func(file->root->name, file->name, "deinit");
deinitfunc = g_strconcat(file->root->name,
"_core_deinit", NULL);
} else {
deinitfunc = g_strconcat(file->name, "_",
file->root->name, "_deinit", NULL);
}
if (g_module_symbol(file->gmodule, deinitfunc, if (g_module_symbol(file->gmodule, deinitfunc,
(gpointer *) &module_deinit)) (gpointer *) &module_deinit))
module_deinit(); module_deinit();