mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-07-28 21:03:54 -06:00
qapi: Fix alternates that accept 'number' but not 'int'
The QMP input visitor allows integral values to be assigned by promotion to a QTYPE_QFLOAT. However, when parsing an alternate, we did not take this into account, such that an alternate that accepts 'number' and some other type, but not 'int', would reject integral values. With this patch, we now have the following desirable table: alternate has case selected for 'int' 'number' QTYPE_QINT QTYPE_QFLOAT no no error error no yes 'number' 'number' yes no 'int' error yes yes 'int' 'number' While it is unlikely that we will ever use 'number' in an alternate other than in the testsuite, it never hurts to be more precise in what we allow. Signed-off-by: Eric Blake <eblake@redhat.com> Message-Id: <1449033659-25497-8-git-send-email-eblake@redhat.com> Signed-off-by: Markus Armbruster <armbru@redhat.com>
This commit is contained in:
parent
9d3f3494c5
commit
d00341af38
6 changed files with 22 additions and 19 deletions
|
@ -184,6 +184,11 @@ void visit_type_%(c_name)s(Visitor *v, %(c_name)s *obj, const char *name, Error
|
|||
|
||||
|
||||
def gen_visit_alternate(name, variants):
|
||||
promote_int = 'true'
|
||||
for var in variants.variants:
|
||||
if var.type.alternate_qtype() == 'QTYPE_QINT':
|
||||
promote_int = 'false'
|
||||
|
||||
ret = mcgen('''
|
||||
|
||||
void visit_type_%(c_name)s(Visitor *v, %(c_name)s **obj, const char *name, Error **errp)
|
||||
|
@ -194,16 +199,14 @@ void visit_type_%(c_name)s(Visitor *v, %(c_name)s **obj, const char *name, Error
|
|||
if (err) {
|
||||
goto out;
|
||||
}
|
||||
visit_get_next_type(v, &(*obj)->type, name, &err);
|
||||
visit_get_next_type(v, &(*obj)->type, %(promote_int)s, name, &err);
|
||||
if (err) {
|
||||
goto out_obj;
|
||||
}
|
||||
switch ((*obj)->type) {
|
||||
''',
|
||||
c_name=c_name(name))
|
||||
c_name=c_name(name), promote_int=promote_int)
|
||||
|
||||
# FIXME: When 'number' but not 'int' is present in the alternate, we
|
||||
# should allow QTYPE_INT to promote to QTYPE_FLOAT.
|
||||
for var in variants.variants:
|
||||
ret += mcgen('''
|
||||
case %(case)s:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue