gibaseinfo: Add initialiser macro for GIAttributeIter

Makes it a little easier to use.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
This commit is contained in:
Philip Withnall 2024-01-18 12:27:46 +00:00
parent 57d64b111f
commit 9aea530ac0
4 changed files with 15 additions and 5 deletions

View File

@ -784,7 +784,7 @@ const char *
gi_base_info_get_attribute (GIBaseInfo *info,
const char *name)
{
GIAttributeIter iter = { 0, };
GIAttributeIter iter = GI_ATTRIBUTE_ITER_INIT;
const char *curname, *curvalue;
while (gi_base_info_iterate_attributes (info, &iter, &curname, &curvalue))
{
@ -872,7 +872,7 @@ _attribute_blob_find_first (GIBaseInfo *info,
* void
* print_attributes (GIBaseInfo *info)
* {
* GIAttributeIter iter = { 0, };
* GIAttributeIter iter = GI_ATTRIBUTE_ITER_INIT;
* const char *name;
* const char *value;
* while (gi_base_info_iterate_attributes (info, &iter, &name, &value))

View File

@ -48,6 +48,16 @@ typedef struct {
void *_dummy[4];
} GIAttributeIter;
/**
* GI_ATTRIBUTE_ITER_INIT:
*
* Initialise a stack-allocated [type@GIRepository.AttributeIter] to a value
* suitable for passing to the first call to an iterate function.
*
* Since: 2.80
*/
#define GI_ATTRIBUTE_ITER_INIT { NULL, { NULL, } }
#define GI_TYPE_BASE_INFO (gi_base_info_get_type ())
/**

View File

@ -426,7 +426,7 @@ const char *
gi_callable_info_get_return_attribute (GICallableInfo *info,
const char *name)
{
GIAttributeIter iter = { 0, };
GIAttributeIter iter = GI_ATTRIBUTE_ITER_INIT;
const char *curname, *curvalue;
while (gi_callable_info_iterate_return_attributes (info, &iter, &curname, &curvalue))
{

View File

@ -350,7 +350,7 @@ static void
write_attributes (Xml *file,
GIBaseInfo *info)
{
GIAttributeIter iter = { 0, };
GIAttributeIter iter = GI_ATTRIBUTE_ITER_INIT;
const char *name, *value;
while (gi_base_info_iterate_attributes (info, &iter, &name, &value))
@ -365,7 +365,7 @@ static void
write_return_value_attributes (Xml *file,
GICallableInfo *info)
{
GIAttributeIter iter = { 0, };
GIAttributeIter iter = GI_ATTRIBUTE_ITER_INIT;
const char *name, *value;
while (gi_callable_info_iterate_return_attributes (info, &iter, &name, &value))