From ea68ec234ad31b0a1d92adbf0c911a5dd541b647 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torsten=20Sch=C3=B6nfeld?= Date: Sat, 10 Sep 2011 16:52:51 +0200 Subject: scanner: correctly handle structs with arrays of anon unions This applies mainly to GValue, which is defined as: struct _GValue { /*< private >*/ GType g_type; /* public for GTypeValueTable methods */ union { gint v_int; guint v_uint; glong v_long; gulong v_ulong; gint64 v_int64; guint64 v_uint64; gfloat v_float; gdouble v_double; gpointer v_pointer; } data[2]; }; Previously, the scanner did not understand the array of unions. This resulted in g_struct_info_get_size returning an incorrect size for GValue (at least on 32bit systems). Fix this by making up a separate union declaration for the GIR that can be referenced by the array. https://bugzilla.gnome.org/show_bug.cgi?id=657040 --- tests/repository/Makefile.am | 2 +- tests/repository/gitypelibtest.c | 26 +++++++++++++++++++++++ tests/scanner/Regress-1.0-expected.gir | 39 ++++++++++++++++++++++++++++++++++ tests/scanner/regress.h | 17 +++++++++++++++ 4 files changed, 83 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/repository/Makefile.am b/tests/repository/Makefile.am index ffc635fe..6331cd30 100644 --- a/tests/repository/Makefile.am +++ b/tests/repository/Makefile.am @@ -17,5 +17,5 @@ gitypelibtest_CPPFLAGS = $(GIREPO_CFLAGS) -I$(top_srcdir)/girepository gitypelibtest_LDADD = $(top_builddir)/libgirepository-1.0.la $(GIREPO_LIBS) TESTS = gitestrepo gitestthrows gitypelibtest -TESTS_ENVIRONMENT=env GI_TYPELIB_PATH=$(top_builddir):$(top_builddir)/tests \ +TESTS_ENVIRONMENT=env GI_TYPELIB_PATH=$(top_builddir):$(top_builddir)/tests:$(top_builddir)/tests/scanner \ XDG_DATA_DIRS="$(top_srcdir)/gir:$(XDG_DATA_DIRS)" $(DEBUG) diff --git a/tests/repository/gitypelibtest.c b/tests/repository/gitypelibtest.c index 2896846a..6e69b096 100644 --- a/tests/repository/gitypelibtest.c +++ b/tests/repository/gitypelibtest.c @@ -106,6 +106,31 @@ test_enum_and_flags_static_methods(GIRepository *repo) g_base_info_unref (enum_info); } +static void +test_size_of_struct_with_array_of_anon_unions(GIRepository *repo) +{ + GITypelib *ret; + GError *error = NULL; + GIBaseInfo *struct_info; + + ret = g_irepository_require (repo, "Regress", NULL, 0, &error); + if (!ret) + g_error ("%s", error->message); + + struct_info = g_irepository_find_by_name (repo, "Regress", "TestStructE"); + if (!struct_info) + g_error ("Could not find Regress.TestStructE"); + g_assert (g_struct_info_get_size (struct_info) + == sizeof (GType) + 2*sizeof (gint64)); + g_base_info_unref (struct_info); + + struct_info = g_irepository_find_by_name (repo, "GObject", "Value"); + if (!struct_info) + g_error ("Could not find GObject.Value"); + g_assert (g_struct_info_get_size (struct_info) == sizeof (GValue)); + g_base_info_unref (struct_info); +} + int main(int argc, char **argv) { @@ -118,6 +143,7 @@ main(int argc, char **argv) /* do tests */ test_enum_and_flags_cidentifier (repo); test_enum_and_flags_static_methods (repo); + test_size_of_struct_with_array_of_anon_unions (repo); exit(0); } diff --git a/tests/scanner/Regress-1.0-expected.gir b/tests/scanner/Regress-1.0-expected.gir index 2f4b5c21..79ca1d31 100644 --- a/tests/scanner/Regress-1.0-expected.gir +++ b/tests/scanner/Regress-1.0-expected.gir @@ -1162,6 +1162,45 @@ TpAccount::status-changed + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/scanner/regress.h b/tests/scanner/regress.h index f30fcd78..4afb9b06 100644 --- a/tests/scanner/regress.h +++ b/tests/scanner/regress.h @@ -243,6 +243,23 @@ struct _RegressTestStructD GPtrArray *garray; }; +/* This one has an array of anonymous unions, inspired by GValue */ +struct RegressTestStructE +{ + GType some_type; + union { + gint v_int; + guint v_uint; + glong v_long; + gulong v_ulong; + gint64 v_int64; + guint64 v_uint64; + gfloat v_float; + gdouble v_double; + gpointer v_pointer; + } some_union[2]; +}; + /* plain-old-data boxed types */ typedef struct _RegressTestSimpleBoxedA RegressTestSimpleBoxedA; typedef struct _RegressTestSimpleBoxedB RegressTestSimpleBoxedB; -- cgit v1.2.1