fix cmopiler warnings. check (de)initialization code.
authorTim Janik <timj@src.gnome.org>
Sun, 9 Aug 1998 11:39:50 +0000 (11:39 +0000)
committerTim Janik <timj@src.gnome.org>
Sun, 9 Aug 1998 11:39:50 +0000 (11:39 +0000)
gmodule/gmodule.c
gmodule/gmodule.h
gmodule/libgplugin_a.c
gmodule/libgplugin_b.c
gmodule/testgmodule.c

index f5ef2d8..396a323 100644 (file)
@@ -36,6 +36,7 @@ struct _GModule
   gchar        *file_name;
   gpointer handle;
   guint ref_count;
+  GModuleDeInit de_init;
   GModule *next;
 };
 
@@ -134,9 +135,10 @@ g_module_open (const gchar    *file_name,
            {
              main_module = g_new (GModule, 1);
              main_module->file_name = NULL;
+             main_module->handle = handle;
              main_module->ref_count = 1;
+             main_module->de_init = NULL;
              main_module->next = NULL;
-             main_module->handle = handle;
            }
        }
 
@@ -156,7 +158,9 @@ g_module_open (const gchar    *file_name,
   handle = _g_module_open (file_name, (flags & G_MODULE_BIND_LAZY) != 0);
   if (handle)
     {
-      GModule *module;
+      gchar *saved_error;
+      GModuleCheckInit check_init;
+      gboolean check_failed = FALSE;
 
       /* search the module list by handle, since file names are not unique */
       module = g_module_find_by_handle (handle);
@@ -169,17 +173,41 @@ g_module_open (const gchar    *file_name,
          return module;
        }
 
+      saved_error = module_error;
+      module_error = NULL;
+      g_module_set_error (NULL);
+
       module = g_new (GModule, 1);
       module->file_name = g_strdup (file_name);
       module->handle = handle;
-      module->ref_count = 1;
+      module->ref_count = 0;
+      module->de_init = NULL;
+      module->next = NULL;
+
+      /* check initialization */
+      if (g_module_symbol (module, "g_module_check_init", &check_init))
+       check_failed = check_init (module);
+
+      /* should call de_init() on failed initializations also? */
+      if (!check_failed)
+       g_module_symbol (module, "g_module_de_init", &module->de_init);
+
+      module->ref_count += 1;
       module->next = modules;
       modules = module;
 
-      return module;
+      if (check_failed)
+       {
+         g_module_close (module);
+         module = NULL;
+         g_module_set_error ("GModule initialization check failed");
+       }
+      else
+       g_module_set_error (saved_error);
+      g_free (saved_error);
     }
 
-  return NULL;
+  return module;
 }
 
 gboolean
@@ -198,9 +226,6 @@ g_module_close (GModule        *module)
       GModule *last;
       GModule *node;
 
-      _g_module_close (&module->handle, FALSE);
-      g_free (module->file_name);
-
       last = NULL;
       node = modules;
       while (node)
@@ -216,6 +241,14 @@ g_module_close (GModule        *module)
          last = node;
          node = last->next;
        }
+      module->next = NULL;
+
+      if (module->de_init)
+       module->de_init (module);
+
+      _g_module_close (&module->handle, FALSE);
+      g_free (module->file_name);
+
       g_free (module);
     }
 
index f6e21f7..fd63af3 100644 (file)
@@ -28,7 +28,9 @@ extern "C" {
 #endif /* __cplusplus */
 
 
-/* exporting and importing functions */
+/* exporting and importing functions,
+ * we need autoconf support here for supporting windows.
+ */
 #define        G_MODULE_EXPORT
 #define        G_MODULE_IMPORT         extern
 
@@ -39,7 +41,9 @@ typedef enum
   G_MODULE_BIND_MASK   = 0x01
 } GModuleFlags;
 
-typedef        struct _GModule GModule;
+typedef        struct  _GModule                GModule;
+typedef gboolean (*GModuleCheckInit)   (GModule        *module);
+typedef void    (*GModuleDeInit)       (GModule        *module);
 
 /* return TRUE if dynamic module loading is supported */
 gboolean       g_module_supported         (void);
index 5f8ff5a..3129978 100644 (file)
@@ -52,7 +52,7 @@ gplugin_a_module_func (GModule *module)
   g_print ("GPluginA: retrive symbol `%s' from \"%s\"\n",
           string,
           g_basename (g_module_name (module)));
-  if (!g_module_symbol (module, string, &f))
+  if (!g_module_symbol (module, string, (gpointer) &f))
     {
       g_print ("error: %s\n", g_module_error ());
       exit (1);
index b31a936..d968975 100644 (file)
  */
 #include        <gmodule.h>
 
+G_MODULE_EXPORT gboolean
+g_module_check_init (GModule *module)
+{
+  g_print ("GPluginB: check-init\n");
+
+  return 0;
+}
+
+G_MODULE_EXPORT void
+g_module_de_init (GModule *module)
+{
+  g_print ("GPluginB: de-init\n");
+}
+
 G_MODULE_EXPORT void
 gplugin_b_func (void)
 {
index 3a18f78..c716c8d 100644 (file)
@@ -76,14 +76,14 @@ main (int   arg,
    */
   string = "gplugin_a_func";
   g_print ("retrive symbol `%s' from \"%s\"\n", string, g_basename (g_module_name (module_a)));
-  if (!g_module_symbol (module_a, string, &f_a))
+  if (!g_module_symbol (module_a, string, (gpointer) &f_a))
     {
       g_print ("error: %s\n", g_module_error ());
       return 1;
     }
   string = "gplugin_b_func";
   g_print ("retrive symbol `%s' from \"%s\"\n", string, g_basename (g_module_name (module_b)));
-  if (!g_module_symbol (module_b, string, &f_b))
+  if (!g_module_symbol (module_b, string, (gpointer) &f_b))
     {
       g_print ("error: %s\n", g_module_error ());
       return 1;
@@ -97,19 +97,19 @@ main (int   arg,
    */
   string = "g_clash_func";
   g_print ("retrive symbol `%s' from \"%s\"\n", string, g_basename (g_module_name (module_self)));
-  if (!g_module_symbol (module_self, string, &f_self))
+  if (!g_module_symbol (module_self, string, (gpointer) &f_self))
     {
       g_print ("error: %s\n", g_module_error ());
       return 1;
     }
   g_print ("retrive symbol `%s' from \"%s\"\n", string, g_basename (g_module_name (module_a)));
-  if (!g_module_symbol (module_a, string, &f_a))
+  if (!g_module_symbol (module_a, string, (gpointer) &f_a))
     {
       g_print ("error: %s\n", g_module_error ());
       return 1;
     }
   g_print ("retrive symbol `%s' from \"%s\"\n", string, g_basename (g_module_name (module_b)));
-  if (!g_module_symbol (module_b, string, &f_b))
+  if (!g_module_symbol (module_b, string, (gpointer) &f_b))
     {
       g_print ("error: %s\n", g_module_error ());
       return 1;
@@ -125,13 +125,13 @@ main (int   arg,
    */
   string = "gplugin_clash_func";
   g_print ("retrive symbol `%s' from \"%s\"\n", string, g_basename (g_module_name (module_a)));
-  if (!g_module_symbol (module_a, string, &f_a))
+  if (!g_module_symbol (module_a, string, (gpointer) &f_a))
     {
       g_print ("error: %s\n", g_module_error ());
       return 1;
     }
   g_print ("retrive symbol `%s' from \"%s\"\n", string, g_basename (g_module_name (module_b)));
-  if (!g_module_symbol (module_b, string, &f_b))
+  if (!g_module_symbol (module_b, string, (gpointer) &f_b))
     {
       g_print ("error: %s\n", g_module_error ());
       return 1;
@@ -147,7 +147,7 @@ main (int   arg,
    */
   string = "gplugin_a_module_func";
   g_print ("retrive symbol `%s' from \"%s\"\n", string, g_basename (g_module_name (module_a)));
-  if (!g_module_symbol (module_a, string, &gmod_f))
+  if (!g_module_symbol (module_a, string, (gpointer) &gmod_f))
     {
       g_print ("error: %s\n", g_module_error ());
       return 1;