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



commit 64adba6e3e44551a99dfae9e9198f7645c7bec35
Author: Matthias Clasen <mclasen redhat com>
Date:   Tue Feb 8 18:02:48 2011 -0500

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

 gtk/gtkmain.c    |   27 +++++++++++++++++++--------
 gtk/gtkmain.h    |    3 +++
 gtk/gtkmodules.c |   20 +++++++++++++++++---
 3 files changed, 39 insertions(+), 11 deletions(-)
---
diff --git a/gtk/gtkmain.c b/gtk/gtkmain.c
index a49c849..17a8b21 100644
--- a/gtk/gtkmain.c
+++ b/gtk/gtkmain.c
@@ -628,20 +628,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_widget_device_is_shadowed", &func))
-    {
-      g_error ("GTK+ 3 symbols detected. Using GTK+ 2.x and GTK+ 3 in the same process is not supported");
-    }
+    result = TRUE;
+  else
+    result = FALSE;
 
-  g_module_close (module);
+  if (!module_to_check)
+    g_module_close (module);
+
+  return result;
 }
 
 static void
@@ -662,7 +672,8 @@ 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);
diff --git a/gtk/gtkmain.h b/gtk/gtkmain.h
index 4e378b6..bbea9cd 100644
--- a/gtk/gtkmain.h
+++ b/gtk/gtkmain.h
@@ -225,6 +225,9 @@ 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_H__ */
diff --git a/gtk/gtkmodules.c b/gtk/gtkmodules.c
index a6b40d8..04e2b04 100644
--- a/gtk/gtkmodules.c
+++ b/gtk/gtkmodules.c
@@ -237,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;
 }
@@ -354,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]