$NetBSD: patch-am,v 1.3 2010/02/19 11:44:56 roy Exp $

We should only check the module itself for g_module_check_init and
g_module_unload functions.

This also makes loading a module a lot faster if these functions do
not exist and the module as a lot of dependencies.

--- gmodule/gmodule.c	2010-02-18 19:59:34.000000000 +0000
+++ gmodule/gmodule.c	2010-02-18 20:18:06.000000000 +0000
@@ -474,25 +474,33 @@
       module->cp_file_name = g_locale_from_utf8 (file_name, -1,
 						 NULL, NULL, NULL);
 #endif
-      module->handle = handle;
+      /* we set RTLD_NEXT so we only load private functions from
+       * the module and not any dependencies */
+      module->handle = RTLD_NEXT;
       module->ref_count = 1;
       module->is_resident = FALSE;
       module->unload = NULL;
       module->next = modules;
       modules = module;
+     
+      /* load private functions */
+      g_module_symbol (module, "g_module_check_init", (gpointer) &check_init);
+      g_module_symbol (module, "g_module_unload", (gpointer) &module->unload);
+
+      /* now set the real handle */
+      module->handle = handle;
       
       /* check initialization */
-      if (g_module_symbol (module, "g_module_check_init", (gpointer) &check_init) && check_init != NULL)
-	check_failed = check_init (module);
-      
-      /* we don't call unload() if the initialization check failed. */
-      if (!check_failed)
-	g_module_symbol (module, "g_module_unload", (gpointer) &module->unload);
-      
-      if (check_failed)
+      if (check_init != NULL)
+        check_failed = check_init(module);
+
+      if (check_failed != NULL)
 	{
 	  gchar *error;
 
+          /* we don't call unload() if the initialization check failed. */
+	  module->unload = NULL;
+
 	  error = g_strconcat ("GModule (", 
                                file_name ? file_name : "NULL", 
                                ") initialization check failed: ", 
