From: Tim Janik Date: Sun, 9 Aug 1998 11:39:50 +0000 (+0000) Subject: fix cmopiler warnings. check (de)initialization code. X-Git-Url: http://git.openbox.org/?a=commitdiff_plain;h=1718cd8c8da7577b1ef72731e7c3348255effe4b;p=dana%2Fcg-glib.git fix cmopiler warnings. check (de)initialization code. --- diff --git a/gmodule/gmodule.c b/gmodule/gmodule.c index f5ef2d8a..396a3237 100644 --- a/gmodule/gmodule.c +++ b/gmodule/gmodule.c @@ -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); } diff --git a/gmodule/gmodule.h b/gmodule/gmodule.h index f6e21f7f..fd63af30 100644 --- a/gmodule/gmodule.h +++ b/gmodule/gmodule.h @@ -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); diff --git a/gmodule/libgplugin_a.c b/gmodule/libgplugin_a.c index 5f8ff5a5..31299788 100644 --- a/gmodule/libgplugin_a.c +++ b/gmodule/libgplugin_a.c @@ -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); diff --git a/gmodule/libgplugin_b.c b/gmodule/libgplugin_b.c index b31a936a..d9689758 100644 --- a/gmodule/libgplugin_b.c +++ b/gmodule/libgplugin_b.c @@ -18,6 +18,20 @@ */ #include +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) { diff --git a/gmodule/testgmodule.c b/gmodule/testgmodule.c index 3a18f78a..c716c8dd 100644 --- a/gmodule/testgmodule.c +++ b/gmodule/testgmodule.c @@ -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;