qapi: Implement deprecated-input={reject,crash} for enum values

This copies the code implementing the policy from qapi/qmp-dispatch.c
to qapi/qobject-input-visitor.c.  Tolerable, but if we acquire more
copies, we should look into factoring them out.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Tested-by: Peter Krempa <pkrempa@redhat.com>
Acked-by: Peter Krempa <pkrempa@redhat.com>
Message-Id: <20211025042405.3762351-5-armbru@redhat.com>
This commit is contained in:
Markus Armbruster 2021-10-25 06:24:04 +02:00
parent ed29bb28f8
commit aa2370444b
4 changed files with 38 additions and 6 deletions

View file

@ -38,6 +38,8 @@ objects_seen = set()
def gen_enum_lookup(name: str,
members: List[QAPISchemaEnumMember],
prefix: Optional[str] = None) -> str:
max_index = c_enum_const(name, '_MAX', prefix)
flags = ''
ret = mcgen('''
const QEnumLookup %(c_name)s_lookup = {
@ -52,13 +54,26 @@ const QEnumLookup %(c_name)s_lookup = {
''',
index=index, name=memb.name)
ret += memb.ifcond.gen_endif()
if 'deprecated' in (f.name for f in memb.features):
flags += mcgen('''
[%(index)s] = QAPI_ENUM_DEPRECATED,
''',
index=index)
if flags:
ret += mcgen('''
},
.flags = (const unsigned char[%(max_index)s]) {
''',
max_index=max_index)
ret += flags
ret += mcgen('''
},
.size = %(max_index)s
};
''',
max_index=c_enum_const(name, '_MAX', prefix))
max_index=max_index)
return ret