From d00341af384665d259af475b14c96bb8414df415 Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Tue, 1 Dec 2015 22:20:51 -0700 Subject: 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 Message-Id: <1449033659-25497-8-git-send-email-eblake@redhat.com> Signed-off-by: Markus Armbruster --- qapi/qapi-visit-core.c | 4 ++-- qapi/qmp-input-visitor.c | 5 ++++- 2 files changed, 6 insertions(+), 3 deletions(-) (limited to 'qapi') diff --git a/qapi/qapi-visit-core.c b/qapi/qapi-visit-core.c index 850ca034cb..cee76bc649 100644 --- a/qapi/qapi-visit-core.c +++ b/qapi/qapi-visit-core.c @@ -81,11 +81,11 @@ void visit_optional(Visitor *v, bool *present, const char *name, } } -void visit_get_next_type(Visitor *v, QType *type, +void visit_get_next_type(Visitor *v, QType *type, bool promote_int, const char *name, Error **errp) { if (v->get_next_type) { - v->get_next_type(v, type, name, errp); + v->get_next_type(v, type, promote_int, name, errp); } } diff --git a/qapi/qmp-input-visitor.c b/qapi/qmp-input-visitor.c index d398de743d..26b7414178 100644 --- a/qapi/qmp-input-visitor.c +++ b/qapi/qmp-input-visitor.c @@ -208,7 +208,7 @@ static void qmp_input_end_list(Visitor *v, Error **errp) qmp_input_pop(qiv, errp); } -static void qmp_input_get_next_type(Visitor *v, QType *type, +static void qmp_input_get_next_type(Visitor *v, QType *type, bool promote_int, const char *name, Error **errp) { QmpInputVisitor *qiv = to_qiv(v); @@ -219,6 +219,9 @@ static void qmp_input_get_next_type(Visitor *v, QType *type, return; } *type = qobject_type(qobj); + if (promote_int && *type == QTYPE_QINT) { + *type = QTYPE_QFLOAT; + } } static void qmp_input_type_int(Visitor *v, int64_t *obj, const char *name, -- cgit v1.2.3-55-g7522