diff --git a/gtk/gtkmain.c b/gtk/gtkmain.c index a49c84949..17a8b21e2 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 4e378b696..bbea9cdbd 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 a6b40d88b..04e2b0491 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; }