[libpeas] Keep plugins order in PeasExtensionSet
- From: Garrett Regier <gregier src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libpeas] Keep plugins order in PeasExtensionSet
- Date: Wed, 16 Dec 2015 01:06:18 +0000 (UTC)
commit e07d2844b6ab78ceefd4e2f746967b85c0da3236
Author: Garrett Regier <garrettregier gmail com>
Date: Wed Nov 18 00:38:11 2015 -0800
Keep plugins order in PeasExtensionSet
The PeasEngine orders the plugin-list based
on dependencies and it should be maintained.
https://bugzilla.gnome.org/show_bug.cgi?id=758446
libpeas/peas-extension-set.c | 30 +++++++++++++------------
tests/libpeas/extension-set.c | 48 +++++++++++++++++++++++++++++++++++++++++
2 files changed, 64 insertions(+), 14 deletions(-)
---
diff --git a/libpeas/peas-extension-set.c b/libpeas/peas-extension-set.c
index 302c149..cb3f9cc 100644
--- a/libpeas/peas-extension-set.c
+++ b/libpeas/peas-extension-set.c
@@ -94,7 +94,7 @@ struct _PeasExtensionSetPrivate {
guint n_parameters;
GParameter *parameters;
- GList *extensions;
+ GQueue extensions;
};
typedef struct {
@@ -219,11 +219,11 @@ add_extension (PeasExtensionSet *set,
priv->n_parameters,
priv->parameters);
- item = (ExtensionItem *) g_slice_new (ExtensionItem);
+ item = g_slice_new (ExtensionItem);
item->info = info;
item->exten = exten;
- priv->extensions = g_list_prepend (priv->extensions, item);
+ g_queue_push_tail (&priv->extensions, item);
g_signal_emit (set, signals[EXTENSION_ADDED], 0, info, exten);
}
@@ -244,16 +244,16 @@ remove_extension (PeasExtensionSet *set,
{
PeasExtensionSetPrivate *priv = GET_PRIV (set);
GList *l;
- ExtensionItem *item;
- for (l = priv->extensions; l; l = l->next)
+ for (l = priv->extensions.head; l != NULL; l = l->next)
{
- item = (ExtensionItem *) l->data;
+ ExtensionItem *item = l->data;
+
if (item->info != info)
continue;
remove_extension_item (set, item);
- priv->extensions = g_list_delete_link (priv->extensions, l);
+ g_queue_delete_link (&priv->extensions, l);
return;
}
}
@@ -261,6 +261,9 @@ remove_extension (PeasExtensionSet *set,
static void
peas_extension_set_init (PeasExtensionSet *set)
{
+ PeasExtensionSetPrivate *priv = GET_PRIV (set);
+
+ g_queue_init (&priv->extensions);
}
static void
@@ -296,13 +299,12 @@ peas_extension_set_dispose (GObject *object)
PeasExtensionSetPrivate *priv = GET_PRIV (set);
GList *l;
- if (priv->extensions != NULL)
+ if (priv->extensions.length > 0)
{
- for (l = priv->extensions; l != NULL; l = l->next)
+ for (l = priv->extensions.tail; l != NULL; l = l->prev)
remove_extension_item (set, (ExtensionItem *) l->data);
- g_list_free (priv->extensions);
- priv->extensions = NULL;
+ g_queue_clear (&priv->extensions);
}
if (priv->parameters != NULL)
@@ -329,7 +331,7 @@ peas_extension_set_call_real (PeasExtensionSet *set,
GList *l;
GIArgument dummy;
- for (l = priv->extensions; l; l = l->next)
+ for (l = priv->extensions.head; l != NULL; l = l->next)
{
ExtensionItem *item = (ExtensionItem *) l->data;
ret = peas_extension_callv (item->exten, method_name, args, &dummy) && ret;
@@ -455,7 +457,7 @@ peas_extension_set_get_extension (PeasExtensionSet *set,
g_return_val_if_fail (PEAS_IS_EXTENSION_SET (set), NULL);
g_return_val_if_fail (info != NULL, NULL);
- for (l = priv->extensions; l != NULL; l = l->next)
+ for (l = priv->extensions.head; l != NULL; l = l->next)
{
ExtensionItem *item = l->data;
@@ -594,7 +596,7 @@ peas_extension_set_foreach (PeasExtensionSet *set,
g_return_if_fail (PEAS_IS_EXTENSION_SET (set));
g_return_if_fail (func != NULL);
- for (l = priv->extensions; l; l = l->next)
+ for (l = priv->extensions.head; l != NULL; l = l->next)
{
ExtensionItem *item = (ExtensionItem *) l->data;
diff --git a/tests/libpeas/extension-set.c b/tests/libpeas/extension-set.c
index 93d6339..c4d4d3c 100644
--- a/tests/libpeas/extension-set.c
+++ b/tests/libpeas/extension-set.c
@@ -286,6 +286,52 @@ test_extension_set_foreach (PeasEngine *engine)
g_object_unref (extension_set);
}
+static void
+ordering_cb (PeasExtensionSet *set,
+ PeasPluginInfo *info,
+ PeasExtension *extension,
+ GList **order)
+{
+ const gchar *order_module_name = (const gchar *) (*order)->data;
+
+ g_assert_cmpstr (order_module_name, ==,
+ peas_plugin_info_get_module_name (info));
+ *order = g_list_delete_link (*order, *order);
+}
+
+static void
+test_extension_set_ordering (PeasEngine *engine)
+{
+ guint i;
+ GList *foreach_order = NULL;
+ GList *dispose_order = NULL;
+ PeasExtensionSet *extension_set;
+
+ for (i = 0; i < G_N_ELEMENTS (loadable_plugins); ++i)
+ {
+ /* Use descriptive names to make an assert more informative */
+ foreach_order = g_list_append (foreach_order,
+ (gpointer) loadable_plugins[i]);
+ dispose_order = g_list_prepend (dispose_order,
+ (gpointer) loadable_plugins[i]);
+ }
+
+ extension_set = testing_extension_set_new (engine, NULL);
+
+ peas_extension_set_foreach (extension_set,
+ (PeasExtensionSetForeachFunc) ordering_cb,
+ &foreach_order);
+ g_assert (foreach_order == NULL);
+
+
+ g_signal_connect (extension_set,
+ "extension-removed",
+ G_CALLBACK (ordering_cb),
+ &dispose_order);
+ g_object_unref (extension_set);
+ g_assert (dispose_order == NULL);
+}
+
int
main (int argc,
char **argv)
@@ -310,6 +356,8 @@ main (int argc,
TEST ("foreach", foreach);
+ TEST ("ordering", ordering);
+
#undef TEST
return testing_run_tests ();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]