From: Tim Janik Date: Sun, 9 Aug 1998 13:13:12 +0000 (+0000) Subject: hm, fixup call sequences for check_init() and de_init(). X-Git-Tag: GLIB_1_1_3~9 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=af0977e8e7c384c0fff179a3222ba257695e3a8f;p=platform%2Fupstream%2Fglib.git hm, fixup call sequences for check_init() and de_init(). we need to have internal structures in a sane state before we call external functions. --- diff --git a/gmodule/gmodule.c b/gmodule/gmodule.c index a4f31c1..a883ace 100644 --- a/gmodule/gmodule.c +++ b/gmodule/gmodule.c @@ -66,6 +66,9 @@ g_module_find_by_handle (gpointer handle) { GModule *module; + if (main_module && main_module->handle == handle) + return main_module; + for (module = modules; module; module = module->next) if (handle == module->handle) return module; @@ -180,22 +183,19 @@ g_module_open (const gchar *file_name, module = g_new (GModule, 1); module->file_name = g_strdup (file_name); module->handle = handle; - module->ref_count = 0; + module->ref_count = 1; module->de_init = NULL; - module->next = NULL; + module->next = modules; + modules = module; /* 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? */ + /* we don't call de_init() if the initialization check failed. */ if (!check_failed) g_module_symbol (module, "g_module_de_init", &module->de_init); - module->ref_count += 1; - module->next = modules; - modules = module; - if (check_failed) { g_module_close (module); @@ -214,13 +214,15 @@ gboolean g_module_close (GModule *module) { CHECK_ERROR (FALSE); - + g_return_val_if_fail (module != NULL, FALSE); g_return_val_if_fail (module->ref_count > 0, FALSE); - + if (module != main_module) module->ref_count--; - + + if (!module->ref_count && module->de_init) + module->de_init (module); if (!module->ref_count) { GModule *last; @@ -243,9 +245,6 @@ g_module_close (GModule *module) } module->next = NULL; - if (module->de_init) - module->de_init (module); - _g_module_close (&module->handle, FALSE); g_free (module->file_name); diff --git a/gmodule/libgplugin_a.c b/gmodule/libgplugin_a.c index 3129978..1ed32b3 100644 --- a/gmodule/libgplugin_a.c +++ b/gmodule/libgplugin_a.c @@ -42,7 +42,7 @@ gplugin_say_boo_func (void) g_print ("GPluginA: BOOH!\n"); } -void +G_MODULE_EXPORT void gplugin_a_module_func (GModule *module) { void(*f)(void) = NULL;