[libpeas] Fix interface sorting in GJS and Seed



commit 1f7785e5e6ab2bbaf4b8905c728f3ad77b62aa80
Author: Garrett Regier <garrettregier gmail com>
Date:   Tue Jul 17 08:43:21 2012 -0700

    Fix interface sorting in GJS and Seed

 loaders/gjs/peas-plugin-loader-gjs.c   |   29 ++++++++++++++++++++++-------
 loaders/seed/peas-plugin-loader-seed.c |   29 ++++++++++++++++++++++-------
 2 files changed, 44 insertions(+), 14 deletions(-)
---
diff --git a/loaders/gjs/peas-plugin-loader-gjs.c b/loaders/gjs/peas-plugin-loader-gjs.c
index 264d8a1..56a511c 100644
--- a/loaders/gjs/peas-plugin-loader-gjs.c
+++ b/loaders/gjs/peas-plugin-loader-gjs.c
@@ -144,14 +144,29 @@ peas_plugin_loader_gjs_provides_extension  (PeasPluginLoader *loader,
          JSVAL_IS_OBJECT (extension) && !JSVAL_IS_NULL (extension);
 }
 
-static gint
-prerequisites_sort (GType *a,
-                    GType *b)
+static void
+sort_interfaces (GArray *interfaces)
 {
-  if (g_type_is_a (*b, *a))
-    return -1;
+  gint i;
+
+  for (i = 0; i < interfaces->len; ++i)
+    {
+      gint j;
+      GType *a = &g_array_index (interfaces, GType, i);
+
+      for (j = i + 1; j < interfaces->len; ++j)
+        {
+          GType *b = &g_array_index (interfaces, GType, j);
+
+          if (g_type_is_a (*a, *b))
+            {
+              GType temp = *a;
 
-  return 1;
+              *a = *b;
+              *b = temp;
+            }
+        }
+    }
 }
 
 static PeasExtension *
@@ -292,7 +307,7 @@ peas_plugin_loader_gjs_create_extension (PeasPluginLoader *loader,
       g_free (prop_name);
     }
 
-  g_array_sort (interfaces, (GCompareFunc) prerequisites_sort);
+  sort_interfaces (interfaces);
 
   return peas_extension_gjs_new (exten_type,
                                  (GType *) g_array_free (interfaces, FALSE),
diff --git a/loaders/seed/peas-plugin-loader-seed.c b/loaders/seed/peas-plugin-loader-seed.c
index 524db9e..2256494 100644
--- a/loaders/seed/peas-plugin-loader-seed.c
+++ b/loaders/seed/peas-plugin-loader-seed.c
@@ -140,14 +140,29 @@ peas_plugin_loader_seed_provides_extension  (PeasPluginLoader *loader,
   return extension && seed_value_is_object (sinfo->context, extension);
 }
 
-static gint
-prerequisites_sort (GType *a,
-                    GType *b)
+static void
+sort_interfaces (GArray *interfaces)
 {
-  if (g_type_is_a (*b, *a))
-    return -1;
+  gint i;
+
+  for (i = 0; i < interfaces->len; ++i)
+    {
+      gint j;
+      GType *a = &g_array_index (interfaces, GType, i);
+
+      for (j = i + 1; j < interfaces->len; ++j)
+        {
+          GType *b = &g_array_index (interfaces, GType, j);
+
+          if (g_type_is_a (*a, *b))
+            {
+              GType temp = *a;
 
-  return 1;
+              *a = *b;
+              *b = temp;
+            }
+        }
+    }
 }
 
 static PeasExtension *
@@ -296,7 +311,7 @@ peas_plugin_loader_seed_create_extension (PeasPluginLoader *loader,
         }
     }
 
-  g_array_sort (interfaces, (GCompareFunc) prerequisites_sort);
+  sort_interfaces (interfaces);
 
   g_strfreev (property_names);
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]