From 3d7bb7feaf2ee8bf96ec4dfa2d7c835c4ad0505a Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Thu, 21 Oct 2010 14:59:42 -0400 Subject: [PATCH] Fix regression in g_irepository_get_info Commit f97cc8687469f25752f79275 broke the lookup in g_irepository_get_info; the passed offset is 0-based, then we convert it to 1-based (and then back to 0 later...which needs to be fixed). --- girepository.c | 6 ++++-- girwriter.c | 4 +++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/girepository.c b/girepository.c index 18ecafbe5..7ac407a1a 100644 --- a/girepository.c +++ b/girepository.c @@ -519,11 +519,13 @@ g_irepository_get_n_infos (GIRepository *repository, * g_irepository_get_info: * @repository: (allow-none): A #GIRepository, may be %NULL for the default * @namespace_: Namespace to inspect - * @index: Offset into namespace metadata for entry + * @index: 0-based offset into namespace metadata for entry * * This function returns a particular metadata entry in the * given namespace @namespace_. The namespace must have * already been loaded before calling this function. + * See g_irepository_get_n_infos() to find the maximum number of + * entries. * * Returns: (transfer full): #GIBaseInfo containing metadata */ @@ -543,7 +545,7 @@ g_irepository_get_info (GIRepository *repository, g_return_val_if_fail (typelib != NULL, NULL); - entry = g_typelib_get_dir_entry (typelib, index); + entry = g_typelib_get_dir_entry (typelib, index + 1); if (entry == NULL) return NULL; return _g_info_new_full (entry->blob_type, diff --git a/girwriter.c b/girwriter.c index 48f1a5d21..8c4fa2c35 100644 --- a/girwriter.c +++ b/girwriter.c @@ -1349,6 +1349,7 @@ gir_writer_write (const char *filename, const gchar *c_prefix; const char *ns = namespace; const char *version; + gint n_infos; version = g_irepository_get_version (repository, ns); @@ -1361,7 +1362,8 @@ gir_writer_write (const char *filename, if (c_prefix) xml_printf (xml, " c:prefix=\"%s\"", c_prefix); - for (j = 0; j < g_irepository_get_n_infos (repository, ns); j++) + n_infos = g_irepository_get_n_infos (repository, ns); + for (j = 0; j < n_infos; j++) { GIBaseInfo *info = g_irepository_get_info (repository, ns, j); switch (g_base_info_get_type (info))