mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-12-27 07:56:14 +01:00
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
This commit is contained in:
parent
343c76431a
commit
fef2a7b8dd
@ -193,13 +193,6 @@ 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);
|
||||
result = TRUE;
|
||||
}
|
||||
@ -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:
|
||||
|
@ -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;
|
||||
|
13
gitypelib.c
13
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,
|
||||
|
Loading…
Reference in New Issue
Block a user