diff options
author | Timo Sirainen <cras@irssi.org> | 2001-10-21 16:23:43 +0000 |
---|---|---|
committer | cras <cras@dbcabf3a-b0e7-0310-adc4-f8d773084564> | 2001-10-21 16:23:43 +0000 |
commit | 388d2e1f443a2f75d7324f069837fbec6cd5435b (patch) | |
tree | b818ba8b9a1b60af0bb24141f4eee991a2b38af3 /src/core/modules-load.c | |
parent | 373fad3cedf5d38ec287be96000561a95a855b9d (diff) | |
download | irssi-388d2e1f443a2f75d7324f069837fbec6cd5435b.zip |
deinit() function is now checked and saved when loading module. Unloading
modules that had module_deinit() function (not module_core_deinit()) wasn't
called before. Also, error message wasn't printed if module didn't have the
_core part and wasn't really irssi module.
git-svn-id: http://svn.irssi.org/repos/irssi/trunk@1882 dbcabf3a-b0e7-0310-adc4-f8d773084564
Diffstat (limited to 'src/core/modules-load.c')
-rw-r--r-- | src/core/modules-load.c | 31 |
1 files changed, 14 insertions, 17 deletions
diff --git a/src/core/modules-load.c b/src/core/modules-load.c index db554ef7..17f50e55 100644 --- a/src/core/modules-load.c +++ b/src/core/modules-load.c @@ -154,10 +154,12 @@ static int module_load_name(const char *path, const char *rootmodule, const char *submodule, int silent) { void (*module_init) (void); + void (*module_deinit) (void); GModule *gmodule; MODULE_REC *module; MODULE_FILE_REC *rec; - char *initfunc; + char *initfunc, *deinitfunc; + int found; gmodule = module_open(path); if (gmodule == NULL) { @@ -168,18 +170,20 @@ static int module_load_name(const char *path, const char *rootmodule, return -1; } - /* get the module's init() function */ + /* get the module's init() and deinit() functions */ initfunc = module_get_func(rootmodule, submodule, "init"); + deinitfunc = module_get_func(rootmodule, submodule, "deinit"); + found = g_module_symbol(gmodule, initfunc, (gpointer *) &module_init) && + g_module_symbol(gmodule, deinitfunc, (gpointer *) &module_deinit); + g_free(initfunc); + g_free(deinitfunc); - if (!g_module_symbol(gmodule, initfunc, (gpointer *) &module_init)) { - if (!silent) - module_error(MODULE_ERROR_INVALID, NULL, - rootmodule, submodule); + if (!found) { + module_error(MODULE_ERROR_INVALID, NULL, + rootmodule, submodule); g_module_close(gmodule); - g_free(initfunc); return 0; } - g_free(initfunc); /* Call the module's init() function - it should register itself with module_register() function, abort if it doesn't. */ @@ -200,6 +204,7 @@ static int module_load_name(const char *path, const char *rootmodule, return 0; } + rec->module_deinit = module_deinit; rec->gmodule = gmodule; rec->initialized = TRUE; @@ -344,16 +349,8 @@ int module_load_sub(const char *path, const char *submodule, char **prefixes) static void module_file_deinit_gmodule(MODULE_FILE_REC *file) { - void (*module_deinit) (void); - char *deinitfunc; - /* call the module's deinit() function */ - deinitfunc = module_get_func(file->root->name, file->name, "deinit"); - if (g_module_symbol(file->gmodule, deinitfunc, - (gpointer *) &module_deinit)) - module_deinit(); - - g_free(deinitfunc); + file->module_deinit(); if (file->defined_module_name != NULL) { settings_remove_module(file->defined_module_name); |