qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Kevin Wolf <kwolf@redhat.com>
To: "Daniel P. Berrange" <berrange@redhat.com>
Cc: qemu-devel@nongnu.org, "Markus Armbruster" <armbru@redhat.com>,
	"Max Reitz" <mreitz@redhat.com>,
	"Marc-André Lureau" <marcandre.lureau@gmail.com>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"Andreas Färber" <afaerber@suse.de>
Subject: Re: [Qemu-devel] [PATCH v12 5/6] qapi: add a QObjectInputVisitor that does string conversion
Date: Thu, 15 Sep 2016 16:08:56 +0200	[thread overview]
Message-ID: <20160915140856.GM4726@noname.redhat.com> (raw)
In-Reply-To: <1473943523-20270-6-git-send-email-berrange@redhat.com>

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.lureau@redhat.com>
> Signed-off-by: Daniel P. Berrange <berrange@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

  reply	other threads:[~2016-09-15 14:09 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-09-15 12:45 [Qemu-devel] [PATCH v12 0/6] QAPI/QOM work for non-scalar object properties Daniel P. Berrange
2016-09-15 12:45 ` [Qemu-devel] [PATCH v12 1/6] qdict: implement a qdict_crumple method for un-flattening a dict Daniel P. Berrange
2016-09-15 13:53   ` Kevin Wolf
2016-09-15 12:45 ` [Qemu-devel] [PATCH v12 2/6] option: make parse_option_bool/number non-static Daniel P. Berrange
2016-09-15 12:45 ` [Qemu-devel] [PATCH v12 3/6] qapi: rename QmpInputVisitor to QObjectInputVisitor Daniel P. Berrange
2016-09-15 13:56   ` Kevin Wolf
2016-09-15 12:45 ` [Qemu-devel] [PATCH v12 4/6] qapi: rename QmpOutputVisitor to QObjectOutputVisitor Daniel P. Berrange
2016-09-15 13:56   ` Kevin Wolf
2016-09-15 12:45 ` [Qemu-devel] [PATCH v12 5/6] qapi: add a QObjectInputVisitor that does string conversion Daniel P. Berrange
2016-09-15 14:08   ` Kevin Wolf [this message]
2016-09-15 12:45 ` [Qemu-devel] [PATCH v12 6/6] qom: support arbitrary non-scalar properties with -object Daniel P. Berrange

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20160915140856.GM4726@noname.redhat.com \
    --to=kwolf@redhat.com \
    --cc=afaerber@suse.de \
    --cc=armbru@redhat.com \
    --cc=berrange@redhat.com \
    --cc=marcandre.lureau@gmail.com \
    --cc=mreitz@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).