diff options
author | Garrett Regier <garrettregier@gmail.com> | 2015-11-21 20:07:03 -0800 |
---|---|---|
committer | Garrett Regier <garrettregier@gmail.com> | 2015-12-15 16:57:46 -0800 |
commit | fd59261b2f7e7ca7330e9891ed76681f1ba498dc (patch) | |
tree | e6768af1a7c0135692919cb8213e479392b50c47 | |
parent | fb7e9a509af15f880f4cb495a834b23d808a193d (diff) | |
download | libpeas-fd59261b2f7e7ca7330e9891ed76681f1ba498dc.tar.gz |
Keep PeasEngine:plugin-list better ordered
This is less confusing that the prior way of ordering.
-rw-r--r-- | libpeas/peas-engine.c | 64 | ||||
-rw-r--r-- | tests/libpeas/engine.c | 6 | ||||
-rw-r--r-- | tests/libpeas/plugins/Makefile.am | 1 | ||||
-rw-r--r-- | tests/libpeas/plugins/two-deps.plugin (renamed from tests/plugins/two-deps.plugin) | 2 | ||||
-rw-r--r-- | tests/plugins/Makefile.am | 5 | ||||
-rw-r--r-- | tests/testing-util/testing-util.c | 10 |
6 files changed, 44 insertions, 44 deletions
diff --git a/libpeas/peas-engine.c b/libpeas/peas-engine.c index b8dbed8..8ab0821 100644 --- a/libpeas/peas-engine.c +++ b/libpeas/peas-engine.c @@ -102,7 +102,7 @@ struct _PeasEnginePrivate { LoaderInfo loaders[PEAS_UTILS_N_LOADERS]; GList *search_paths; - GList *plugin_list; + GQueue plugin_list; guint in_dispose : 1; guint use_nonglobal_loaders : 1; @@ -124,8 +124,8 @@ static void peas_engine_load_plugin_real (PeasEngine *engine, static void peas_engine_unload_plugin_real (PeasEngine *engine, PeasPluginInfo *info); -static GList * -plugin_info_prepend_sorted (GList *plugin_list, +static void +plugin_info_prepend_sorted (GQueue *plugin_list, PeasPluginInfo *info) { guint i; @@ -136,7 +136,7 @@ plugin_info_prepend_sorted (GList *plugin_list, for (i = 0; dependencies[i] != NULL; ++i) { - GList *pos = furthest_dep != NULL ? furthest_dep : plugin_list; + GList *pos = furthest_dep != NULL ? furthest_dep : plugin_list->head; for (; pos != NULL; pos = pos->next) { @@ -149,15 +149,20 @@ plugin_info_prepend_sorted (GList *plugin_list, } } + /* GLib changed only accepts NULL for + * g_queue_insert_after() at version 2.44 + */ if (furthest_dep == NULL) - return g_list_prepend (plugin_list, info); + { + g_queue_push_tail (plugin_list, info); + return; + } g_debug ("Adding '%s' after '%s' due to dependencies", peas_plugin_info_get_module_name (info), peas_plugin_info_get_module_name (furthest_dep->data)); - g_list_insert (furthest_dep, info, 1); - return plugin_list; + g_queue_insert_after (plugin_list, furthest_dep, info); } static gboolean @@ -187,7 +192,7 @@ load_plugin_info (PeasEngine *engine, return FALSE; } - priv->plugin_list = plugin_info_prepend_sorted (priv->plugin_list, info); + plugin_info_prepend_sorted (&priv->plugin_list, info); g_object_notify_by_pspec (G_OBJECT (engine), properties[PROP_PLUGIN_LIST]); @@ -323,7 +328,7 @@ plugin_list_changed (PeasEngine *engine) msg = g_string_new ("Plugins: "); - for (pos = priv->plugin_list; pos != NULL; pos = pos->next) + for (pos = priv->plugin_list.head; pos != NULL; pos = pos->next) { if (pos->prev != NULL) g_string_append (msg, ", "); @@ -489,6 +494,8 @@ peas_engine_init (PeasEngine *engine) priv->in_dispose = FALSE; + g_queue_init (&priv->plugin_list); + /* The C plugin loader is always enabled */ priv->loaders[PEAS_UTILS_C_LOADER_ID].enabled = TRUE; } @@ -583,7 +590,7 @@ peas_engine_dispose (GObject *object) priv->in_dispose = TRUE; /* First unload all the plugins */ - for (item = priv->plugin_list; item; item = item->next) + for (item = priv->plugin_list.tail; item != NULL; item = item->prev) { PeasPluginInfo *info = PEAS_PLUGIN_INFO (item->data); @@ -610,8 +617,12 @@ peas_engine_finalize (GObject *object) GList *item; /* free the infos */ - g_list_free_full (priv->plugin_list, - (GDestroyNotify) _peas_plugin_info_unref); + for (item = priv->plugin_list.head; item != NULL; item = item->next) + { + PeasPluginInfo *info = (PeasPluginInfo *) item->data; + + _peas_plugin_info_unref (info); + } /* free the search path list */ for (item = priv->search_paths; item; item = item->next) @@ -624,6 +635,7 @@ peas_engine_finalize (GObject *object) } g_list_free (priv->search_paths); + g_queue_clear (&priv->plugin_list); G_OBJECT_CLASS (peas_engine_parent_class)->finalize (object); } @@ -1030,14 +1042,7 @@ peas_engine_get_plugin_list (PeasEngine *engine) g_return_val_if_fail (PEAS_IS_ENGINE (engine), NULL); - return priv->plugin_list; -} - -static gint -compare_plugin_info_and_name (PeasPluginInfo *info, - const gchar *module_name) -{ - return strcmp (peas_plugin_info_get_module_name (info), module_name); + return priv->plugin_list.head; } /** @@ -1061,11 +1066,16 @@ peas_engine_get_plugin_info (PeasEngine *engine, g_return_val_if_fail (PEAS_IS_ENGINE (engine), NULL); g_return_val_if_fail (plugin_name != NULL, NULL); - l = g_list_find_custom (priv->plugin_list, - plugin_name, - (GCompareFunc) compare_plugin_info_and_name); + for (l = priv->plugin_list.head; l != NULL; l = l->next) + { + PeasPluginInfo *info = (PeasPluginInfo *) l->data; + const gchar *module_name = peas_plugin_info_get_module_name (info); + + if (strcmp (module_name, plugin_name) == 0) + return info; + } - return l == NULL ? NULL : (PeasPluginInfo *) l->data; + return NULL; } static void @@ -1198,7 +1208,7 @@ peas_engine_unload_plugin_real (PeasEngine *engine, /* First unload all the dependant plugins */ module_name = peas_plugin_info_get_module_name (info); - for (item = priv->plugin_list; item; item = item->next) + for (item = priv->plugin_list.tail; item != NULL; item = item->prev) { PeasPluginInfo *other_info = PEAS_PLUGIN_INFO (item->data); @@ -1452,7 +1462,7 @@ peas_engine_get_loaded_plugins (PeasEngine *engine) array = g_array_new (TRUE, FALSE, sizeof (gchar *)); - for (pl = priv->plugin_list; pl; pl = pl->next) + for (pl = priv->plugin_list.head; pl != NULL; pl = pl->next) { PeasPluginInfo *info = (PeasPluginInfo *) pl->data; gchar *module_name; @@ -1506,7 +1516,7 @@ peas_engine_set_loaded_plugins (PeasEngine *engine, g_return_if_fail (PEAS_IS_ENGINE (engine)); - for (pl = priv->plugin_list; pl; pl = pl->next) + for (pl = priv->plugin_list.head; pl != NULL; pl = pl->next) { PeasPluginInfo *info = (PeasPluginInfo *) pl->data; const gchar *module_name; diff --git a/tests/libpeas/engine.c b/tests/libpeas/engine.c index 8b297b9..26bdc43 100644 --- a/tests/libpeas/engine.c +++ b/tests/libpeas/engine.c @@ -286,9 +286,9 @@ test_engine_plugin_list (PeasEngine *engine) /* Verify that we are finding the furthest dependency in the list */ dependencies = peas_plugin_info_get_dependencies (two_deps_info); - g_assert_cmpint (loadable_index, <, builtin_index); - g_assert_cmpstr (dependencies[0], ==, "loadable"); - g_assert_cmpstr (dependencies[1], ==, "builtin"); + g_assert_cmpint (builtin_index, <, loadable_index); + g_assert_cmpstr (dependencies[0], ==, "builtin"); + g_assert_cmpstr (dependencies[1], ==, "loadable"); /* The two-deps plugin should be ordered after builtin and loadable */ g_assert_cmpint (builtin_index, <, two_deps_index); diff --git a/tests/libpeas/plugins/Makefile.am b/tests/libpeas/plugins/Makefile.am index 5db17a9..cb35f85 100644 --- a/tests/libpeas/plugins/Makefile.am +++ b/tests/libpeas/plugins/Makefile.am @@ -25,6 +25,7 @@ noinst_PLUGIN = \ nonexistent-dep.plugin \ not-loadable.plugin \ os-dependant-help.plugin \ + two-deps.plugin \ unkown-loader.plugin EXTRA_DIST = $(noinst_PLUGIN) diff --git a/tests/plugins/two-deps.plugin b/tests/libpeas/plugins/two-deps.plugin index b463a82..0231c27 100644 --- a/tests/plugins/two-deps.plugin +++ b/tests/libpeas/plugins/two-deps.plugin @@ -1,6 +1,6 @@ [Plugin] Module=two-deps -Depends=loadable;builtin +Depends=builtin;loadable Name=Two Deps Description=This plugin cannot be loaded and has two deps. Authors=Garrett Regier diff --git a/tests/plugins/Makefile.am b/tests/plugins/Makefile.am index cd5b8cd..d0cb6ba 100644 --- a/tests/plugins/Makefile.am +++ b/tests/plugins/Makefile.am @@ -7,9 +7,8 @@ SUBDIRS = \ self-dep noinst_PLUGIN = \ - full-info.plugin \ - min-info.plugin \ - two-deps.plugin \ + full-info.plugin \ + min-info.plugin \ unavailable.plugin EXTRA_DIST = $(noinst_PLUGIN) diff --git a/tests/testing-util/testing-util.c b/tests/testing-util/testing-util.c index 5229945..4763e46 100644 --- a/tests/testing-util/testing-util.c +++ b/tests/testing-util/testing-util.c @@ -249,16 +249,6 @@ testing_util_engine_new_full (gboolean nonglobal_loaders) (GWeakNotify) engine_weak_notify, NULL); - /* The plugins that two-deps depends on must be added - * to the engine before it. This is used to verify that - * the engine will order the plugin list correctly. - */ - peas_engine_add_search_path (engine, - BUILDDIR "/tests/plugins/builtin", - SRCDIR "/tests/plugins/builtin"); - peas_engine_add_search_path (engine, - BUILDDIR "/tests/plugins/loadable", - SRCDIR "/tests/plugins/loadable"); peas_engine_add_search_path (engine, BUILDDIR "/tests/plugins", SRCDIR "/tests/plugins"); |