Merged silc_1_1_branch to trunk.
[silc.git] / apps / irssi / src / core / modules-load.c
index e7e780915815e7d24ad20024a4e2010f32020b88..42703fc653a14da643087cf8552b48657598111c 100644 (file)
@@ -64,13 +64,16 @@ static char *module_get_root(const char *name, char **prefixes)
        int len;
 
        /* skip any of the prefixes.. */
-       while (*prefixes != NULL) {
-                len = strlen(*prefixes);
-               if (strncmp(name, *prefixes, len) == 0 && name[len] == '_') {
-                       name += len+1;
-                        break;
+       if (prefixes != NULL) {
+               while (*prefixes != NULL) {
+                       len = strlen(*prefixes);
+                       if (strncmp(name, *prefixes, len) == 0 &&
+                           name[len] == '_') {
+                               name += len+1;
+                               break;
+                       }
+                       prefixes++;
                }
-               prefixes++;
        }
 
        /* skip the _core part */
@@ -94,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);
 
@@ -160,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;
 
@@ -175,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);
@@ -364,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;
@@ -374,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);
@@ -399,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