GVariantTypeInfo changes

- rename 'type' in MemberInfo to 'type_info'
 - add 'ending_type' field to MemberInfo
 - document how to find the ending
This commit is contained in:
Ryan Lortie 2010-02-02 23:38:20 -05:00
parent 1de58ef708
commit 0ac2277b49
3 changed files with 39 additions and 11 deletions

View File

@ -336,7 +336,7 @@ tuple_info_free (GVariantTypeInfo *info)
tuple_info = (TupleInfo *) info;
for (i = 0; i < tuple_info->n_members; i++)
g_variant_type_info_unref (tuple_info->members[i].type);
g_variant_type_info_unref (tuple_info->members[i].type_info);
g_slice_free1 (sizeof (GVariantMemberInfo) * tuple_info->n_members,
tuple_info->members);
@ -357,8 +357,17 @@ tuple_allocate_members (const GVariantType *type,
item_type = g_variant_type_first (type);
while (item_type)
{
(*members)[i++].type = g_variant_type_info_get (item_type);
GVariantMemberInfo *member = &(*members)[i++];
member->type_info = g_variant_type_info_get (item_type);
item_type = g_variant_type_next (item_type);
if (item_type == NULL)
member->ending_type = G_VARIANT_MEMBER_ENDING_LAST;
else if (member->type_info->fixed_size)
member->ending_type = G_VARIANT_MEMBER_ENDING_FIXED;
else
member->ending_type = G_VARIANT_MEMBER_ENDING_OFFSET;
}
g_assert (i == *n_members);
@ -377,8 +386,8 @@ tuple_get_item (TupleInfo *info,
if (&info->members[info->n_members] == item)
return FALSE;
*d = item->type->alignment;
*e = item->type->fixed_size;
*d = item->type_info->alignment;
*e = item->type_info->fixed_size;
return TRUE;
}
@ -591,7 +600,7 @@ tuple_set_base_info (TupleInfo *info)
/* can find the max of a list of "one less than" powers of two
* by 'or'ing them
*/
base->alignment |= m->type->alignment;
base->alignment |= m->type_info->alignment;
m--; /* take 'm' back to the last item */
@ -599,7 +608,7 @@ tuple_set_base_info (TupleInfo *info)
* offsets are stored and the last item is fixed-sized too (since
* an offset is never stored for the last item).
*/
if (m->i == -1 && m->type->fixed_size)
if (m->i == -1 && m->type_info->fixed_size)
/* in that case, the fixed size can be found by finding the
* start of the last item (in the usual way) and adding its
* fixed size.
@ -609,7 +618,7 @@ tuple_set_base_info (TupleInfo *info)
* easier) so we round up to that here.
*/
base->fixed_size =
tuple_align (((m->a & m->b) | m->c) + m->type->fixed_size,
tuple_align (((m->a & m->b) | m->c) + m->type_info->fixed_size,
base->alignment);
else
/* else, the tuple is not fixed size */

View File

@ -95,16 +95,35 @@ typedef struct _GVariantTypeInfo GVariantTypeInfo;
*
* For details about how 'a', 'b' and 'c' are calculated, see the
* comments at the point of the implementation in gvariantypeinfo.c.
*
* The end address of the item is then determined in one of three ways,
* according to the 'end_type' field.
*
* - FIXED: For fixed sized items, the end address is equal to the
* start address plus the fixed size.
*
* - LAST: For the last variable sized item in the tuple, the end
* address is equal to the end address of the tuple, minus the size
* of the offset array.
*
* - OFFSET: For other variable sized items, the next index past 'i'
* (ie: 'i + 1') must be consulted to find the end of this item.
*/
typedef struct
{
GVariantTypeInfo *type;
GVariantTypeInfo *type_info;
gsize i, a;
gint8 b, c;
guint8 ending_type;
} GVariantMemberInfo;
#define G_VARIANT_MEMBER_ENDING_FIXED 0
#define G_VARIANT_MEMBER_ENDING_LAST 1
#define G_VARIANT_MEMBER_ENDING_OFFSET 2
/* query */
G_GNUC_INTERNAL
const gchar * g_variant_type_info_get_type_string (GVariantTypeInfo *typeinfo);

View File

@ -826,7 +826,7 @@ describe_info (GVariantTypeInfo *info)
sep = ", ";
minfo = g_variant_type_info_member_info (info, i);
subtype = describe_info (minfo->type);
subtype = describe_info (minfo->type_info);
g_string_append (string, subtype);
g_free (subtype);
}
@ -845,8 +845,8 @@ describe_info (GVariantTypeInfo *info)
g_assert_cmpint (g_variant_type_info_n_members (info), ==, 2);
keyinfo = g_variant_type_info_member_info (info, 0);
valueinfo = g_variant_type_info_member_info (info, 1);
key = describe_info (keyinfo->type);
value = describe_info (valueinfo->type);
key = describe_info (keyinfo->type_info);
value = describe_info (valueinfo->type_info);
result = g_strjoin ("", "e of [", key, ", ", value, "]", NULL);
g_free (key);
g_free (value);