summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiovanni Campagna <gcampagna@src.gnome.org>2011-06-05 20:57:01 +0200
committerGiovanni Campagna <gcampagna@src.gnome.org>2011-06-08 17:45:13 +0200
commitaea1a55dff7f5cf7f3d87bbe515d94b66057b852 (patch)
tree62f4cd439fb25ae36a1def9709ea6e5642b62808
parentc8c23d2db2ec6594b5c43bd01cc78db396c709f3 (diff)
downloadgobject-introspection-aea1a55dff7f5cf7f3d87bbe515d94b66057b852.tar.gz
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
-rw-r--r--girepository/gifieldinfo.c16
-rw-r--r--girepository/girnode.c4
-rw-r--r--girepository/gitypelib.c13
-rw-r--r--tests/scanner/Regress-1.0-expected.gir9
-rw-r--r--tests/scanner/regress.h6
5 files changed, 13 insertions, 35 deletions
diff --git a/girepository/gifieldinfo.c b/girepository/gifieldinfo.c
index 106fc1ce..17491a80 100644
--- a/girepository/gifieldinfo.c
+++ b/girepository/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/girepository/girnode.c b/girepository/girnode.c
index 9998d8e5..a56471e5 100644
--- a/girepository/girnode.c
+++ b/girepository/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/girepository/gitypelib.c b/girepository/gitypelib.c
index 3ecfb16b..6d1333ba 100644
--- a/girepository/gitypelib.c
+++ b/girepository/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,
diff --git a/tests/scanner/Regress-1.0-expected.gir b/tests/scanner/Regress-1.0-expected.gir
index 6c5fdec5..e2f2f93e 100644
--- a/tests/scanner/Regress-1.0-expected.gir
+++ b/tests/scanner/Regress-1.0-expected.gir
@@ -1104,14 +1104,7 @@ TpAccount::status-changed</doc>
</array>
</field>
<field name="array2" writable="1">
- <array zero-terminated="0"
- c:type="RegressTestStructB**"
- fixed-size="5">
- <type name="TestStructB" c:type="RegressTestStructB*"/>
- </array>
- </field>
- <field name="array3" writable="1">
- <array zero-terminated="0" c:type="gpointer*">
+ <array c:type="gpointer*">
<type name="TestObj"/>
</array>
</field>
diff --git a/tests/scanner/regress.h b/tests/scanner/regress.h
index 37213548..7df66a57 100644
--- a/tests/scanner/regress.h
+++ b/tests/scanner/regress.h
@@ -223,8 +223,7 @@ struct _RegressTestStructC
/**
* RegressTestStructD:
* @array1: (array zero-terminated=1):
- * @array2: (array fixed-size=5):
- * @array3: (array) (element-type RegressTestObj):
+ * @array2: (array zero-terminated=1) (element-type RegressTestObj):
* @field: (type RegressTestObj):
* @list: (element-type RegressTestObj):
* @garray: (element-type RegressTestObj):
@@ -232,8 +231,7 @@ struct _RegressTestStructC
struct _RegressTestStructD
{
RegressTestStructA **array1;
- RegressTestStructB **array2;
- gpointer *array3;
+ gpointer *array2;
gpointer field;
GList *list;
GPtrArray *garray;