qapi: Add QAPI_LIST_PREPEND() macro
commit9812e7125b83ba6e4645237150ca5f61bf66197f
authorEric Blake <eblake@redhat.com>
Tue, 27 Oct 2020 05:05:47 +0000 (27 00:05 -0500)
committerEric Blake <eblake@redhat.com>
Fri, 30 Oct 2020 20:10:14 +0000 (30 15:10 -0500)
treefc381c3afbee4152574578ba08e157310c8fb613
parent159f8442382cff6ef6d858dbf02f03f0cc95b4a7
qapi: Add QAPI_LIST_PREPEND() macro

block.c has a useful macro QAPI_LIST_ADD() for inserting at the front
of any QAPI-generated list; move it from block.c to qapi/util.h so
more places can use it, including one earlier place in block.c, and
rename it to something more obvious (since we also have a lot of
places that append, rather than prepend, to a list).

There are many more places in the codebase that can benefit from using
the macro, but converting them will be left to later patches.

In theory, all QAPI list types are child classes of GenericList; but
in practice, that relationship is not explicitly spelled out in the C
type declarations (rather, it is something that happens implicitly due
to C compatible layouts), and the macro does not actually depend on
the GenericList type.  We considered moving GenericList from visitor.h
into util.h to group related code; however, such a move would be
awkward if we do not also move GenericAlternate.  Unfortunately,
moving GenericAlternate would introduce its own problems of
declaration circularity (qapi-builtin-types.h needs a complete
definition of QEnumLookup from util.h, but GenericAlternate needs a
complete definition of QType from qapi-builtin-types.h).

Suggested-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Message-Id: <20201027050556.269064-3-eblake@redhat.com>
[eblake: s/ADD/PREPEND/ per suggestion by Markus]
block.c
include/qapi/util.h