qemu-devel
[Top][All Lists]
Advanced

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

[Qemu-devel] Re: [PATCH 5/7] add qdev property type "cpu"


From: Markus Armbruster
Subject: [Qemu-devel] Re: [PATCH 5/7] add qdev property type "cpu"
Date: Tue, 29 Jun 2010 13:42:17 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux)

Paolo Bonzini <address@hidden> writes:

>> Hmm.  Parse method doesn't accept output of the print method.  Not so
>> nice.  Is the "CPU #" decoration essential?
>
> I noticed the same in parse/print string:
>
> static int parse_string(DeviceState *dev, Property *prop, const char *str)
> {
>     char **ptr = qdev_get_prop_ptr(dev, prop);
>
>     if (*ptr)
>         qemu_free(*ptr);
>     *ptr = qemu_strdup(str);
>     return 0;
> }
>
> static int print_string(DeviceState *dev, Property *prop, char *dest,
> size_t len)
> {
>     char **ptr = qdev_get_prop_ptr(dev, prop);
>     if (!*ptr)
>         return snprintf(dest, len, "<null>");
>     return snprintf(dest, len, "\"%s\"", *ptr);
> }
>
> It looks like printing representation is chosen "for the user", not
> for parsing.

Yes, but does that mean we *should* add such decorations?

For me, the print method should be reasonably close to what the parse
method accepts.  A bit like Lisp's princ, whose ouput is close, but not
identical to what the reader accepts (for output acceptable to the
reader, use prin1).

As to "for the user":

    dev-prop: cpu_env = CPU #0
    dev-prop: cpu_env = 0

Both are equally intelligible, in my opinion: obvious if you know what
the property is about, gibberish if you don't.  The latter is slightly
easier to parse with simple tools like AWK.

By the way, print_string() should escape double-quote and funny
characters.



reply via email to

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