diff --git a/gistructinfo.c b/gistructinfo.c index 0fbaec842..bd7774637 100644 --- a/gistructinfo.c +++ b/gistructinfo.c @@ -22,6 +22,8 @@ #include "config.h" +#include + #include #include @@ -114,6 +116,47 @@ g_struct_info_get_field (GIStructInfo *info, g_struct_get_field_offset (info, n)); } +/** + * g_struct_info_find_field: + * @info: a #GIStructInfo + * @name: a field name + * + * Obtain the type information for field named @name. + * + * Returns: (transfer full): the #GIFieldInfo or %NULL if not found, + * free it with g_base_info_unref() when done. + */ +GIFieldInfo * +g_struct_info_find_field (GIStructInfo *info, + const gchar *name) +{ + GIRealInfo *rinfo = (GIRealInfo *)info; + StructBlob *blob = (StructBlob *)&rinfo->typelib->data[rinfo->offset]; + Header *header = (Header *)rinfo->typelib->data; + guint32 offset = rinfo->offset + header->struct_blob_size; + gint i; + + for (i = 0; i < blob->n_fields; i++) + { + FieldBlob *field_blob = (FieldBlob *)&rinfo->typelib->data[offset]; + const gchar *fname = (const gchar *)&rinfo->typelib->data[field_blob->name]; + + if (strcmp (name, fname) == 0) + { + return (GIFieldInfo *) g_info_new (GI_INFO_TYPE_FIELD, + (GIBaseInfo* )info, + rinfo->typelib, + offset); + } + + offset += header->field_blob_size; + if (field_blob->has_embedded_type) + offset += header->callback_blob_size; + } + + return NULL; +} + /** * g_struct_info_get_n_methods: * @info: a #GIStructInfo diff --git a/gistructinfo.h b/gistructinfo.h index 2651311d3..4a60d5bb2 100644 --- a/gistructinfo.h +++ b/gistructinfo.h @@ -48,6 +48,10 @@ GI_AVAILABLE_IN_ALL GIFieldInfo * g_struct_info_get_field (GIStructInfo *info, gint n); +GI_AVAILABLE_IN_ALL +GIFieldInfo * g_struct_info_find_field (GIStructInfo *info, + const gchar *name); + GI_AVAILABLE_IN_ALL gint g_struct_info_get_n_methods (GIStructInfo *info);