summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilip Chimento <philip.chimento@gmail.com>2019-06-20 00:18:13 -0700
committerPhilip Chimento <philip.chimento@gmail.com>2019-06-20 11:54:10 -0700
commite49cfb8d3462d624cad8b76c6560bd76996ed544 (patch)
treeb296172edc26b41f14a005e3008b13a7512f1f61
parent5fdc6c8f714bc8c8af8b1ecaa05663923b0a83ba (diff)
downloadgobject-introspection-e49cfb8d3462d624cad8b76c6560bd76996ed544.tar.gz
girepository: Return pointer array for interface cache
In g_irepository_get_object_gtype_interfaces(), returning the address of the first GIBaseInfo* does not work reliably, because the GIBaseInfos are not necessarily stored contiguously. So the second and subsequent ones might be garbage. Instead, return the address of the array of GIBaseInfo pointers. Add a test that verifies the functionality, as well. This is unfortunately an API and ABI break.
-rw-r--r--girepository/girepository.c6
-rw-r--r--girepository/girepository.h2
-rw-r--r--tests/repository/gitestrepo.c24
3 files changed, 28 insertions, 4 deletions
diff --git a/girepository/girepository.c b/girepository/girepository.c
index ca5dc2b9..08149da8 100644
--- a/girepository/girepository.c
+++ b/girepository/girepository.c
@@ -984,13 +984,13 @@ g_irepository_find_by_error_domain (GIRepository *repository,
* returning a concrete class of #GLocalFile, which is a #GType we
* see at runtime, but not statically.
*
- * Since: 1.60
+ * Since: 1.62
*/
void
g_irepository_get_object_gtype_interfaces (GIRepository *repository,
GType gtype,
guint *n_interfaces_out,
- GIInterfaceInfo **interfaces_out)
+ GIInterfaceInfo ***interfaces_out)
{
GTypeInterfaceCache *cache;
@@ -1039,7 +1039,7 @@ g_irepository_get_object_gtype_interfaces (GIRepository *repository,
}
*n_interfaces_out = cache->n_interfaces;
- *interfaces_out = *((GIInterfaceInfo**)&(cache->interfaces[0]));
+ *interfaces_out = (GIInterfaceInfo**)&cache->interfaces[0];
}
static void
diff --git a/girepository/girepository.h b/girepository/girepository.h
index 8dfcca2c..073985b6 100644
--- a/girepository/girepository.h
+++ b/girepository/girepository.h
@@ -163,7 +163,7 @@ GI_AVAILABLE_IN_1_60
void g_irepository_get_object_gtype_interfaces (GIRepository *repository,
GType gtype,
guint *n_interfaces_out,
- GIInterfaceInfo **interfaces_out);
+ GIInterfaceInfo ***interfaces_out);
GI_AVAILABLE_IN_ALL
gint g_irepository_get_n_infos (GIRepository *repository,
diff --git a/tests/repository/gitestrepo.c b/tests/repository/gitestrepo.c
index 6c10b076..abe30d98 100644
--- a/tests/repository/gitestrepo.c
+++ b/tests/repository/gitestrepo.c
@@ -57,6 +57,29 @@ test_type_info_get_name (GIRepository *repo)
g_base_info_unref ((GIBaseInfo*)typeinfo);
}
+static void
+test_get_gtype_interfaces (GIRepository *repo)
+{
+ GIInterfaceInfo **interfaces;
+ guint n_interfaces, ix;
+ gboolean found_initable = FALSE, found_async_initable = FALSE;
+
+ g_irepository_get_object_gtype_interfaces (repo, G_TYPE_DBUS_CONNECTION, &n_interfaces, &interfaces);
+
+ g_assert_cmpuint (n_interfaces, ==, 2);
+
+ for (ix = 0; ix < n_interfaces; ix++)
+ {
+ const gchar *name = g_base_info_get_name(*(interfaces + ix));
+ if (strcmp (name, "Initable") == 0)
+ found_initable = TRUE;
+ else if (strcmp (name, "AsyncInitable") == 0)
+ found_async_initable = TRUE;
+ }
+
+ g_assert_true (found_initable);
+ g_assert_true (found_async_initable);
+}
int
main(int argc, char **argv)
@@ -161,6 +184,7 @@ main(int argc, char **argv)
}
test_type_info_get_name (repo);
+ test_get_gtype_interfaces (repo);
/* Error quark tests */
errorinfo = g_irepository_find_by_error_domain (repo, G_RESOLVER_ERROR);