qemu-devel
[Top][All Lists]
Advanced

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

Re: [Qemu-devel] [PATCH 07/18] qom: add link properties


From: Avi Kivity
Subject: Re: [Qemu-devel] [PATCH 07/18] qom: add link properties
Date: Thu, 01 Dec 2011 14:34:21 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:8.0) Gecko/20111115 Thunderbird/8.0

On 12/01/2011 01:35 PM, Stefan Hajnoczi wrote:
> >>
> >> +static void qdev_get_link_property(DeviceState *dev, Visitor *v, void 
> >> *opaque,
> >> +                                   const char *name, Error **errp)
> >> +{
> >> +    DeviceState **child = opaque;
> >> +    gchar *path;
> >> +
> >> +    if (*child) {
> >> +        path = qdev_get_canonical_path(*child);
> >> +        visit_type_str(v, &path, name, errp);
> >> +        g_free(path);
> >> +    } else {
> >> +        path = (gchar *)"";
> >
> > If gchar != char, this is wrong.  Also, you're converting a const
> > pointer into a non-const pointer, discarding type safety.
>
> This looked weird to me too but the cast has to do with the fact that
> the visitor function works both for input and output visitors.  The
> output visitor needs to write to gchar** while the input visitor does
> not.

So you need to pass a non-const pointer to an array of const char, or
const gchar **.  You don't modify the string in place, you allocate a
new string and free the old one.


> When this function is called with the correct visitor type we are
> guaranteed that path will not be modified.

What if it's called with the output visitor? (warning: confusing
convention).

-- 
error compiling committee.c: too many arguments to function




reply via email to

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