From fef2a7b8dd313dcf107d1cbb5791e150d700fd4d Mon Sep 17 00:00:00 2001 From: Giovanni Campagna Date: Sun, 5 Jun 2011 20:57:01 +0200 Subject: [PATCH] Fix accessing structure fields that are arrays We need to distinguish inline arrays inside structures, and arrays that are pointers and annotations, and we can do it with g_type_info_is_pointer(), setting it to FALSE for fixed size arrays. As a side effect, (array fixed-size=N) on a pointer type has no longer the expected result. https://bugzilla.gnome.org/show_bug.cgi?id=646635 --- gifieldinfo.c | 16 +++++++--------- girnode.c | 4 +++- gitypelib.c | 13 ------------- 3 files changed, 10 insertions(+), 23 deletions(-) diff --git a/gifieldinfo.c b/gifieldinfo.c index 106fc1ce9..17491a80a 100644 --- a/gifieldinfo.c +++ b/gifieldinfo.c @@ -193,14 +193,7 @@ g_field_info_get_field (GIFieldInfo *field_info, if (g_type_info_is_pointer (type_info)) { - if (g_type_info_get_array_type (type_info) == GI_ARRAY_TYPE_C && - g_type_info_get_array_fixed_size (type_info) >= 0) - { - /* Consider fixed-size arrays as embedded inside the struct */ - value->v_pointer = G_STRUCT_MEMBER_P ((mem), (offset)); - } - else - value->v_pointer = G_STRUCT_MEMBER (gpointer, mem, offset); + value->v_pointer = G_STRUCT_MEMBER (gpointer, mem, offset); result = TRUE; } else @@ -248,9 +241,14 @@ g_field_info_get_field (GIFieldInfo *field_info, value->v_double = G_STRUCT_MEMBER (gdouble, mem, offset); result = TRUE; break; + case GI_TYPE_TAG_ARRAY: + /* We don't check the array type and that it is fixed-size, + we trust g-ir-compiler to do the right thing */ + value->v_pointer = G_STRUCT_MEMBER_P (mem, offset); + result = TRUE; + break; case GI_TYPE_TAG_UTF8: case GI_TYPE_TAG_FILENAME: - case GI_TYPE_TAG_ARRAY: case GI_TYPE_TAG_GLIST: case GI_TYPE_TAG_GSLIST: case GI_TYPE_TAG_GHASH: diff --git a/girnode.c b/girnode.c index 9998d8e5b..a56471e52 100644 --- a/girnode.c +++ b/girnode.c @@ -1242,6 +1242,8 @@ serialize_type (GIrTypelibBuild *build, node->has_length ? "," : ""); g_string_append (str, "]"); + if (node->is_pointer) + g_string_append (str, "*"); } else if (node->array_type == GI_ARRAY_TYPE_BYTE_ARRAY) { @@ -1476,7 +1478,7 @@ _g_ir_node_build_typelib (GIrNode *node, ArrayTypeBlob *array = (ArrayTypeBlob *)&data[*offset2]; guint32 pos; - array->pointer = 1; + array->pointer = type->is_pointer; array->reserved = 0; array->tag = type->tag; array->zero_terminated = type->zero_terminated; diff --git a/gitypelib.c b/gitypelib.c index 3ecfb16b6..6d1333ba0 100644 --- a/gitypelib.c +++ b/gitypelib.c @@ -523,19 +523,6 @@ validate_array_type_blob (GITypelib *typelib, gboolean return_type, GError **error) { - ArrayTypeBlob *blob; - - blob = (ArrayTypeBlob*)&typelib->data[offset]; - - if (!blob->pointer) - { - g_set_error (error, - G_TYPELIB_ERROR, - G_TYPELIB_ERROR_INVALID_BLOB, - "Pointer type exected for tag %d", blob->tag); - return FALSE; - } - /* FIXME validate length */ if (!validate_type_blob (typelib,