[gobject-introspection] Include the loaded version in g_irepository_enumerate_versions()

commit 3ed944ed5f7a8231ba5c431d59e33f23dca56f87
Author: Steve Frécinaux <code istique net>
Date:   Mon Aug 16 22:39:19 2010 +0200

    Include the loaded version in g_irepository_enumerate_versions()
    Logically speaking, the already loaded version of a namespace is part of
    the currently available versions, and can be forgotten if we only
    consider the versions available in GI_TYPELIB_PATH, as it could have
    been loaded using g_irepository_require_private().
    As a side effect, it meant that bindings relying on enumerate_version()
    (like pygobject) were not able to require private versions through their
    classical requirement scheme.
    This patch fixes it by adding the loaded version to the unsorted list of
    available versions returned by g_irepository_enumerate_versions()
    This patch also uses g_list_prepend() instead of g_list_append() in that

 girepository/girepository.c |   15 +++++++++++++--
 1 files changed, 13 insertions(+), 2 deletions(-)
diff --git a/girepository/girepository.c b/girepository/girepository.c
index 17d076d..96a23e6 100644
--- a/girepository/girepository.c
+++ b/girepository/girepository.c
@@ -1166,7 +1166,8 @@ find_namespace_latest (const gchar  *namespace,
  * @repository: (allow-none): the repository
  * @namespace_: GI namespace, e.g. "Gtk"
- * Obtain a list of versions for @namespace_ in this @repository.
+ * Obtain an unordered list of versions (either currently loaded or
+ * available) for @namespace_ in this @repository.
  * Returns: (element-type utf8) (transfer full): the array of versions.
@@ -1177,6 +1178,7 @@ g_irepository_enumerate_versions (GIRepository *repository,
   GList *ret = NULL;
   GSList *search_path;
   GSList *candidates, *link;
+  const gchar *loaded_version;
   search_path = build_search_path_with_overrides ();
   candidates = enumerate_namespace_versions (namespace_, search_path);
@@ -1185,10 +1187,19 @@ g_irepository_enumerate_versions (GIRepository *repository,
   for (link = candidates; link; link = link->next)
       struct NamespaceVersionCandidadate *candidate = link->data;
-      ret = g_list_append (ret, g_strdup (candidate->version));
+      ret = g_list_prepend (ret, g_strdup (candidate->version));
       free_candidate (candidate);
   g_slist_free (candidates);
+  /* The currently loaded version of a namespace is also part of the
+   * available versions, as it could have been loaded using
+   * require_private().
+   */
+  loaded_version = g_irepository_get_version (NULL, namespace_);
+  if (loaded_version && !g_list_find_custom (ret, loaded_version, g_str_equal))
+    ret = g_list_prepend (ret, g_strdup (loaded_version));
   return ret;

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