[gtk+] Extend the mixed-dependency check to modules as well



commit d2bdd50a0b1f754540fe4038862c7c983513875c
Author: Matthias Clasen <mclasen redhat com>
Date:   Tue Feb 8 13:49:16 2011 -0500

    Extend the mixed-dependency check to modules as well
    
    This helps prevent accidents with GTK_PATH.

 gtk/gtkmain.c        |   29 ++++++++++++++++++++---------
 gtk/gtkmainprivate.h |    2 ++
 gtk/gtkmodules.c     |   27 +++++++++++++++++++++------
 3 files changed, 43 insertions(+), 15 deletions(-)
---
diff --git a/gtk/gtkmain.c b/gtk/gtkmain.c
index 515f05b..47af377 100644
--- a/gtk/gtkmain.c
+++ b/gtk/gtkmain.c
@@ -738,20 +738,30 @@ setlocale_initialization (void)
     }
 }
 
-static void
-check_mixed_deps (void)
+/* Return TRUE if module_to_check causes version conflicts.
+ * If module_to_check is NULL, check the main module.
+ */
+gboolean
+_gtk_module_has_mixed_deps (GModule *module_to_check)
 {
   GModule *module;
   gpointer func;
+  gboolean result;
 
-  module = g_module_open (NULL, 0);
+  if (!module_to_check)
+    module = g_module_open (NULL, 0);
+  else
+    module = module_to_check;
 
   if (g_module_symbol (module, "gtk_progress_get_type", &func))
-    {
-      g_error ("GTK+ 2.x symbols detected. Using GTK+ 2.x and GTK+ 3 in the same process is not supported");
-    }
+    result = TRUE;
+  else
+    result = FALSE;
+
+  if (!module_to_check)
+    g_module_close (module);
 
-  g_module_close (module);
+  return result;
 }
 
 static void
@@ -765,11 +775,12 @@ do_pre_parse_initialization (int    *argc,
 
   pre_initialized = TRUE;
 
-  check_mixed_deps ();
+  if (_gtk_module_has_mixed_deps (NULL))
+    g_error ("GTK+ 2.x symbols detected. Using GTK+ 2.x and GTK+ 3 in the same process is not supported");
 
   gdk_pre_parse_libgtk_only ();
   gdk_event_handler_set ((GdkEventFunc)gtk_main_do_event, NULL, NULL);
-  
+
 #ifdef G_ENABLE_DEBUG
   env_string = g_getenv ("GTK_DEBUG");
   if (env_string != NULL)
diff --git a/gtk/gtkmainprivate.h b/gtk/gtkmainprivate.h
index f4605d7..5667938 100644
--- a/gtk/gtkmainprivate.h
+++ b/gtk/gtkmainprivate.h
@@ -30,6 +30,8 @@ gboolean _gtk_boolean_handled_accumulator (GSignalInvocationHint *ihint,
 
 gchar *_gtk_get_lc_ctype (void);
 
+gboolean _gtk_module_has_mixed_deps (GModule *module);
+
 G_END_DECLS
 
 #endif  /* __GTK_MAIN_PRIVATE_H__ */
diff --git a/gtk/gtkmodules.c b/gtk/gtkmodules.c
index bd9ba57..5fa2abf 100644
--- a/gtk/gtkmodules.c
+++ b/gtk/gtkmodules.c
@@ -26,7 +26,8 @@
 #include "gtksettings.h"
 #include "gtkdebug.h"
 #include "gtkprivate.h" /* GTK_LIBDIR */
-#include "gtkintl.h" 
+#include "gtkmainprivate.h"
+#include "gtkintl.h"
 
 #include <gmodule.h>
 
@@ -236,7 +237,16 @@ find_module (const gchar *name)
     }
 
   module = g_module_open (module_name, G_MODULE_BIND_LOCAL | G_MODULE_BIND_LAZY);
-  g_free(module_name);
+
+  if (_gtk_module_has_mixed_deps (module))
+    {
+      g_warning ("GTK+ module %s cannot be loaded.\n"
+                 "GTK+ 2.x symbols detected. Using GTK+ 2.x and GTK+ 3 in the same process is not supported.", module_name);
+      g_module_close (module);
+      module = NULL;
+    }
+
+  g_free (module_name);
 
   return module;
 }
@@ -264,7 +274,7 @@ load_module (GSList      *module_list,
       for (l = gtk_modules; l; l = l->next)
 	{
 	  info = l->data;
-	  if (g_slist_find_custom (info->names, name, 
+	  if (g_slist_find_custom (info->names, name,
 				   (GCompareFunc)strcmp))
 	    {
 	      info->ref_count++;
@@ -273,7 +283,7 @@ load_module (GSList      *module_list,
 	    }
 	}
 
-      if (!success) 
+      if (!success)
 	{
 	  module = find_module (name);
 
@@ -353,8 +363,13 @@ load_module (GSList      *module_list,
 	}
     }
   else
-    g_message ("Failed to load module \"%s\": %s", name, g_module_error ());
-  
+    {
+      const gchar *error = g_module_error ();
+
+      g_message ("Failed to load module \"%s\"%s%s",
+                 name, error ? ": " : "", error ? error : "");
+    }
+
   return module_list;
 }
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]