Merged silc_1_1_branch to trunk.
[silc.git] / apps / irssi / src / core / modules-load.c
index 69bdecdf07c61780b4f93eeb3dc401c1b2812b20..42703fc653a14da643087cf8552b48657598111c 100644 (file)
@@ -97,7 +97,7 @@ static char *module_get_sub(const char *name, const char *root)
            strcmp(name+rootlen, "_core") == 0)
                 return g_strdup("core");
 
-       if (namelen+1 > rootlen && name[namelen-rootlen-1] == '_' &&
+       if (namelen > rootlen && name[namelen-rootlen-1] == '_' &&
            strcmp(name+namelen-rootlen, root) == 0)
                 return g_strndup(name, namelen-rootlen-1);
 
@@ -163,6 +163,7 @@ static int module_load_name(const char *path, const char *rootmodule,
        GModule *gmodule;
         MODULE_REC *module;
        MODULE_FILE_REC *rec;
+       gpointer value1, value2;
        char *initfunc, *deinitfunc;
         int found;
 
@@ -178,11 +179,14 @@ static int module_load_name(const char *path, const char *rootmodule,
        /* 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);
+       found = g_module_symbol(gmodule, initfunc, &value1) &&
+               g_module_symbol(gmodule, deinitfunc, &value2);
        g_free(initfunc);
        g_free(deinitfunc);
 
+       module_init = value1;
+       module_deinit = value2;
+
        if (!found) {
                module_error(MODULE_ERROR_INVALID, NULL,
                             rootmodule, submodule);
@@ -367,6 +371,15 @@ static void module_file_deinit_gmodule(MODULE_FILE_REC *file)
        g_module_close(file->gmodule);
 }
 
+#else /* !HAVE_GMODULE - modules are not supported */
+
+int module_load(const char *path, char **prefixes)
+{
+        return FALSE;
+}
+
+#endif
+
 void module_file_unload(MODULE_FILE_REC *file)
 {
        MODULE_REC *root;
@@ -377,8 +390,10 @@ void module_file_unload(MODULE_FILE_REC *file)
         if (file->initialized)
                signal_emit("module unloaded", 2, file->root, file);
 
+#ifdef HAVE_GMODULE
        if (file->gmodule != NULL)
                 module_file_deinit_gmodule(file);
+#endif
 
        g_free(file->name);
        g_free(file->defined_module_name);
@@ -402,16 +417,3 @@ void module_unload(MODULE_REC *module)
         g_free(module->name);
        g_free(module);
 }
-
-#else /* !HAVE_GMODULE - modules are not supported */
-
-int module_load(const char *path, char **prefixes)
-{
-        return FALSE;
-}
-
-void module_unload(MODULE_REC *module)
-{
-}
-
-#endif