Am 15.09.2016 um 14:45 hat Daniel P. Berrange geschrieben: > Currently the QObjectInputVisitor assumes that all scalar > values are directly represented as their final types. > ie it assumes an 'int' is using QInt, and a 'bool' is > using QBool. > > This adds an alternative constructor for QObjectInputVisitor > that will set it up such that it expects a QString for > all scalar types instead. > > This makes it possible to use QObjectInputVisitor with a > QDict produced from QemuOpts, where everything is in > string format. > > Reviewed-by: Marc-André Lureau <marcandre.lur...@redhat.com> > Signed-off-by: Daniel P. Berrange <berra...@redhat.com>
> @@ -314,6 +370,7 @@ static void qobject_input_type_str(Visitor *v, const char > *name, char **obj, > static void qobject_input_type_number(Visitor *v, const char *name, double > *obj, > Error **errp) > { > + > QObjectInputVisitor *qiv = to_qiv(v); > QObject *qobj = qobject_input_get_object(qiv, name, true); > QInt *qint; This doesn't look intentional. > @@ -335,6 +392,30 @@ static void qobject_input_type_number(Visitor *v, const > char *name, double *obj, > "number"); > } > > +static void qobject_input_type_number_str(Visitor *v, const char *name, > + double *obj, Error **errp) > +{ > + QObjectInputVisitor *qiv = to_qiv(v); > + QString *qstr = qobject_to_qstring(qobject_input_get_object(qiv, name, > + true)); > + char *endp; > + > + if (!qstr || !qstr->string) { > + error_setg(errp, QERR_INVALID_PARAMETER_TYPE, name ? name : "null", > + "string"); > + return; > + } > + > + errno = 0; > + *obj = strtod(qstr->string, &endp); > + if (errno == 0 && endp != qstr->string && *endp == '\0') { > + return; > + } > + > + error_setg(errp, QERR_INVALID_PARAMETER_TYPE, name ? name : "null", > + "string"); This error message is misleading. It complains that it didn't get a string, while in fact it got a string that just didn't parse as a number. > +} > + > static void qobject_input_type_any(Visitor *v, const char *name, QObject > **obj, > Error **errp) > { The rest looks good to me. Kevin