[gobject-introspection] Fix accessing structure fields that are arrays
- From: Giovanni Campagna <gcampagna src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gobject-introspection] Fix accessing structure fields that are arrays
- Date: Wed, 8 Jun 2011 16:07:04 +0000 (UTC)
commit aea1a55dff7f5cf7f3d87bbe515d94b66057b852
Author: Giovanni Campagna <gcampagna src gnome org>
Date: Sun Jun 5 20:57:01 2011 +0200
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
girepository/gifieldinfo.c | 16 +++++++---------
girepository/girnode.c | 4 +++-
girepository/gitypelib.c | 13 -------------
tests/scanner/Regress-1.0-expected.gir | 9 +--------
tests/scanner/regress.h | 6 ++----
5 files changed, 13 insertions(+), 35 deletions(-)
---
diff --git a/girepository/gifieldinfo.c b/girepository/gifieldinfo.c
index 106fc1c..17491a8 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 9998d8e..a56471e 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 3ecfb16..6d1333b 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 6c5fdec..e2f2f93 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 3721354..7df66a5 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;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]