From 2b07f1ed31bcc6a404d75bad7eb88e698d3eeead Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Steve=20Fr=C3=A9cinaux?= Date: Mon, 16 Aug 2010 22:39:19 +0200 Subject: [PATCH] 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 function. https://bugzilla.gnome.org/show_bug.cgi?id=625983 --- girepository.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/girepository.c b/girepository.c index 17d076d5b..96a23e6fe 100644 --- a/girepository.c +++ b/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; }