From 39d1537211501a8603f93a3196b910dce40e1617 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Sun, 18 Feb 2018 08:50:45 -0500 Subject: [PATCH] Stop loading modules We no longer look at the GTK_MODULES environment variables. With this commit, we stop loading general-purpose modules altogether. --- gtk/gtkmain.c | 28 ---- gtk/gtkmodules.c | 317 ---------------------------------------- gtk/gtkmodulesprivate.h | 4 - 3 files changed, 349 deletions(-) diff --git a/gtk/gtkmain.c b/gtk/gtkmain.c index e8e74238ce..8af6ee4471 100644 --- a/gtk/gtkmain.c +++ b/gtk/gtkmain.c @@ -120,7 +120,6 @@ #include "gtkdndprivate.h" #include "gtkmain.h" #include "gtkmenu.h" -#include "gtkmodules.h" #include "gtkmodulesprivate.h" #include "gtkprivate.h" #include "gtkrecentmanager.h" @@ -383,8 +382,6 @@ gtk_disable_setlocale (void) #undef gtk_init_check #endif -static GString *gtk_modules_string = NULL; - #ifdef G_OS_WIN32 static char *iso639_to_check = NULL; @@ -576,21 +573,6 @@ do_pre_parse_initialization (void) } #endif /* G_ENABLE_DEBUG */ - env_string = g_getenv ("GTK3_MODULES"); - if (env_string) - gtk_modules_string = g_string_new (env_string); - - env_string = g_getenv ("GTK_MODULES"); - if (env_string) - { - if (gtk_modules_string) - g_string_append_c (gtk_modules_string, G_SEARCHPATH_SEPARATOR); - else - gtk_modules_string = g_string_new (NULL); - - g_string_append (gtk_modules_string, env_string); - } - env_string = g_getenv ("GTK_SLOWDOWN"); if (env_string) { @@ -647,16 +629,6 @@ do_post_parse_initialization (void) gtk_initialized = TRUE; - if (gtk_modules_string) - { - _gtk_modules_init (NULL, NULL, gtk_modules_string->str); - g_string_free (gtk_modules_string, TRUE); - } - else - { - _gtk_modules_init (NULL, NULL, NULL); - } - display_manager = gdk_display_manager_get (); if (gdk_display_manager_get_default_display (display_manager) != NULL) _gtk_accessibility_init (); diff --git a/gtk/gtkmodules.c b/gtk/gtkmodules.c index c28d6e38a5..d8e98c848b 100644 --- a/gtk/gtkmodules.c +++ b/gtk/gtkmodules.c @@ -30,25 +30,6 @@ #include -typedef struct _GtkModuleInfo GtkModuleInfo; -struct _GtkModuleInfo -{ - GModule *module; - gint ref_count; - GtkModuleInitFunc init_func; - GtkModuleDisplayInitFunc display_init_func; - GSList *names; -}; - -static GSList *gtk_modules = NULL; - -static gboolean default_display_opened = FALSE; - -/* Saved argc, argv for delayed module initialization - */ -static gint gtk_argc = 0; -static gchar **gtk_argv = NULL; - static gchar ** get_module_path (void) { @@ -207,304 +188,6 @@ _gtk_find_module (const gchar *name, return module_name; } -static GModule * -find_module (const gchar *name) -{ - GModule *module; - gchar *module_name; - - module_name = _gtk_find_module (name, "modules"); - if (!module_name) - { - /* As last resort, try loading without an absolute path (using system - * library path) - */ - module_name = g_module_build_path (NULL, name); - } - - module = g_module_open (module_name, G_MODULE_BIND_LOCAL | G_MODULE_BIND_LAZY); - - 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; -} - -static gint -cmp_module (GtkModuleInfo *info, - GModule *module) -{ - return info->module != module; -} - -static gboolean -module_is_blacklisted (const gchar *name, - gboolean verbose) -{ - if (g_str_equal (name, "gail") || - g_str_equal (name, "atk-bridge")) - { - if (verbose) - g_message ("Not loading module \"%s\": The functionality is provided by GTK natively. Please try to not load it.", name); - - return TRUE; - } - - return FALSE; -} - -static GSList * -load_module (GSList *module_list, - const gchar *name) -{ - GtkModuleInitFunc modinit_func; - gpointer modinit_func_ptr; - GtkModuleInfo *info = NULL; - GModule *module = NULL; - GSList *l; - gboolean success = FALSE; - - if (g_module_supported ()) - { - for (l = gtk_modules; l; l = l->next) - { - info = l->data; - if (g_slist_find_custom (info->names, name, - (GCompareFunc)strcmp)) - { - info->ref_count++; - - success = TRUE; - break; - } - info = NULL; - } - - if (!success) - { - module = find_module (name); - - if (module) - { - /* Do the check this late so we only warn about existing modules, - * not old modules that are still in the modules path. */ - if (module_is_blacklisted (name, TRUE)) - { - modinit_func = NULL; - success = TRUE; - } - else if (g_module_symbol (module, "gtk_module_init", &modinit_func_ptr)) - modinit_func = modinit_func_ptr; - else - modinit_func = NULL; - - if (!modinit_func) - g_module_close (module); - else - { - GSList *temp; - - success = TRUE; - info = NULL; - - temp = g_slist_find_custom (gtk_modules, module, - (GCompareFunc)cmp_module); - if (temp != NULL) - info = temp->data; - - if (!info) - { - info = g_new0 (GtkModuleInfo, 1); - - info->names = g_slist_prepend (info->names, g_strdup (name)); - info->module = module; - info->ref_count = 1; - info->init_func = modinit_func; - g_module_symbol (module, "gtk_module_display_init", - (gpointer *) &info->display_init_func); - - gtk_modules = g_slist_append (gtk_modules, info); - - /* display_init == NULL indicates a non-multihead aware module. - * For these, we delay the call to init_func until first display is - * opened, see default_display_notify_cb(). - * For multihead aware modules, we call init_func immediately, - * and also call display_init_func on all opened displays. - */ - if (default_display_opened || info->display_init_func) - (* info->init_func) (>k_argc, >k_argv); - - if (info->display_init_func) - { - GSList *displays, *iter; - displays = gdk_display_manager_list_displays (gdk_display_manager_get ()); - for (iter = displays; iter; iter = iter->next) - { - GdkDisplay *display = iter->data; - (* info->display_init_func) (display); - } - g_slist_free (displays); - } - } - else - { - GTK_NOTE (MODULES, g_message ("Module already loaded, ignoring: %s", name)); - info->names = g_slist_prepend (info->names, g_strdup (name)); - info->ref_count++; - /* remove new reference count on module, we already have one */ - g_module_close (module); - } - } - } - } - } - - if (success && info) - { - if (!g_slist_find (module_list, info)) - { - module_list = g_slist_prepend (module_list, info); - } - } - else - { - if (!module_is_blacklisted (name, FALSE)) - { - const gchar *error = g_module_error (); - - g_message ("Failed to load module \"%s\"%s%s", - name, error ? ": " : "", error ? error : ""); - } - } - - return module_list; -} - -static GSList * -load_modules (const char *module_str) -{ - gchar **module_names; - GSList *module_list = NULL; - gint i; - - GTK_NOTE (MODULES, g_message ("Loading module list: %s", module_str)); - - module_names = gtk_split_file_list (module_str); - for (i = 0; module_names[i]; i++) - module_list = load_module (module_list, module_names[i]); - - module_list = g_slist_reverse (module_list); - g_strfreev (module_names); - - return module_list; -} - -static void -default_display_notify_cb (GdkDisplayManager *display_manager) -{ - GSList *slist; - - /* Initialize non-multihead-aware modules when the - * default display is first set to a non-NULL value. - */ - - if (!gdk_display_get_default () || default_display_opened) - return; - - default_display_opened = TRUE; - - for (slist = gtk_modules; slist; slist = slist->next) - { - if (slist->data) - { - GtkModuleInfo *info = slist->data; - - if (!info->display_init_func) - (* info->init_func) (>k_argc, >k_argv); - } - } -} - -static void -display_closed_cb (GdkDisplay *display, - gboolean is_error) -{ - GtkSettings *settings; - - settings = gtk_settings_get_for_display (display); - - g_object_set_data_full (G_OBJECT (settings), I_("gtk-modules"), NULL, NULL); -} - -static void -display_opened_cb (GdkDisplayManager *display_manager, - GdkDisplay *display) -{ - GSList *slist; - - for (slist = gtk_modules; slist; slist = slist->next) - { - if (slist->data) - { - GtkModuleInfo *info = slist->data; - - if (info->display_init_func) - (* info->display_init_func) (display); - } - } - - /* Since closing display doesn't actually release the resources yet, - * we have to connect to the ::closed signal. - */ - g_signal_connect (display, "closed", G_CALLBACK (display_closed_cb), NULL); -} - -void -_gtk_modules_init (gint *argc, - gchar ***argv, - const gchar *gtk_modules_args) -{ - GdkDisplayManager *display_manager; - gint i; - - g_assert (gtk_argv == NULL); - - if (argc && argv) - { - /* store argc and argv for later use in mod initialization */ - gtk_argc = *argc; - gtk_argv = g_new (gchar *, *argc + 1); - for (i = 0; i < gtk_argc; i++) - gtk_argv [i] = g_strdup ((*argv) [i]); - gtk_argv [*argc] = NULL; - } - - display_manager = gdk_display_manager_get (); - default_display_opened = gdk_display_get_default () != NULL; - g_signal_connect (display_manager, "notify::default-display", - G_CALLBACK (default_display_notify_cb), - NULL); - g_signal_connect (display_manager, "display-opened", - G_CALLBACK (display_opened_cb), - NULL); - - if (gtk_modules_args) - { - /* Modules specified in the GTK_MODULES environment variable - * or on the command line are always loaded, so we'll just leak - * the refcounts. - */ - g_slist_free (load_modules (gtk_modules_args)); - } -} - /* Return TRUE if module_to_check causes version conflicts. * If module_to_check is NULL, check the main module. */ diff --git a/gtk/gtkmodulesprivate.h b/gtk/gtkmodulesprivate.h index 99987bb077..67da320f80 100644 --- a/gtk/gtkmodulesprivate.h +++ b/gtk/gtkmodulesprivate.h @@ -33,10 +33,6 @@ gchar * _gtk_find_module (const gchar *name, const gchar *type); gchar ** _gtk_get_module_path (const gchar *type); -void _gtk_modules_init (gint *argc, - gchar ***argv, - const gchar *gtk_modules_args); - gboolean _gtk_module_has_mixed_deps (GModule *module); G_END_DECLS