Skip to content
Snippets Groups Projects
  • Eric Blake's avatar
    9812e712
    qapi: Add QAPI_LIST_PREPEND() macro · 9812e712
    Eric Blake authored
    
    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: default avatarVladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
    Signed-off-by: default avatarEric Blake <eblake@redhat.com>
    Reviewed-by: default avatarVladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
    Reviewed-by: default avatarMarkus Armbruster <armbru@redhat.com>
    Message-Id: <20201027050556.269064-3-eblake@redhat.com>
    [eblake: s/ADD/PREPEND/ per suggestion by Markus]
    9812e712
    History
    qapi: Add QAPI_LIST_PREPEND() macro
    Eric Blake authored
    
    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: default avatarVladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
    Signed-off-by: default avatarEric Blake <eblake@redhat.com>
    Reviewed-by: default avatarVladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
    Reviewed-by: default avatarMarkus Armbruster <armbru@redhat.com>
    Message-Id: <20201027050556.269064-3-eblake@redhat.com>
    [eblake: s/ADD/PREPEND/ per suggestion by Markus]