qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH 00/16] introduce OptsVisitor, rebase -net/-netde


From: Laszlo Ersek
Subject: Re: [Qemu-devel] [PATCH 00/16] introduce OptsVisitor, rebase -net/-netdev parsing
Date: Sat, 09 Jun 2012 13:21:50 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:10.0.4) Gecko/20120422 Thunderbird/10.0.4

On 06/07/12 17:46, Paolo Bonzini wrote:
> Il 07/06/2012 17:29, Michael Roth ha scritto:
>> For QEMU <-> X serialization/deserialization, such as a visitor which
>> implements a wire encoding (QMP being the only example currently), we need to
>> take care that the wire encoding is compatible with the representation
>> expected by the other end (according to the QAPI schema or whatever other
>> means we use to document it). This holds for QMP/JSON, and we'll need to take
>> care that it holds for anything that's added in the future.
> 
> Actually the string visitor does indeed need an uint64 visitor exactly
> for this reason.  Will be done before 1.2. :)
> 
> Laszlo's option visitor needs the same, but it's not in the tree.

Here's my implementation (will post as part of my v2 series). The common part 
could be extracted to "cutils.c".

Laszlo

static void
opts_type_uint64(Visitor *v, uint64_t *obj, const char *name, Error **errp)
{
    OptsVisitor *ov = DO_UPCAST(OptsVisitor, visitor, v);
    const QemuOpt *opt;
    const char *str;

    opt = lookup_scalar(ov, name, errp);
    if (!opt) {
        return;
    }

    str = opt->str;
    if (str != NULL) {
        while (isspace((unsigned char)*str)) {
            ++str;
        }

        if (*str != '-' && *str != '\0') {
            unsigned long long val;
            char *endptr;

            /* non-empty, non-negative subject sequence */
            errno = 0;
            val = strtoull(str, &endptr, 0);
            if (*endptr == '\0' && errno == 0 && val <= UINT64_MAX) {
                *obj = val;
                processed(ov, name);
                return;
            }
        }
    }
    error_set(errp, QERR_INVALID_PARAMETER_VALUE, opt->name,
              "an uint64 value");
}



reply via email to

[Prev in Thread] Current Thread [Next in Thread]