qemu-devel
[Top][All Lists]
Advanced

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

Re: [RFC PATCH 10/12] qapi: Generate QOM config marshalling code


From: Kevin Wolf
Subject: Re: [RFC PATCH 10/12] qapi: Generate QOM config marshalling code
Date: Fri, 10 Dec 2021 17:50:44 +0100

Am 23.11.2021 um 15:16 hat Markus Armbruster geschrieben:
> Kevin Wolf <kwolf@redhat.com> writes:
> 
> > Signed-off-by: Kevin Wolf <kwolf@redhat.com>
> > ---
> >  backends/rng-random.c | 17 ++------
> >  backends/rng.c        | 17 ++------
> >  scripts/qapi/main.py  |  2 +
> >  scripts/qapi/qom.py   | 91 +++++++++++++++++++++++++++++++++++++++++++
> >  qapi/meson.build      |  3 ++
> >  5 files changed, 104 insertions(+), 26 deletions(-)
> >  create mode 100644 scripts/qapi/qom.py
> >
> > diff --git a/backends/rng-random.c b/backends/rng-random.c
> > index b221308091..35738df3c6 100644
> > --- a/backends/rng-random.c
> > +++ b/backends/rng-random.c
> > @@ -14,6 +14,7 @@
> >  #include "sysemu/rng-random.h"
> >  #include "sysemu/rng.h"
> >  #include "qapi/error.h"
> > +#include "qapi/qapi-qom-qom.h"
> >  #include "qapi/visitor.h"
> >  #include "qapi/qmp/qerror.h"
> >  #include "qemu/main-loop.h"
> > @@ -90,7 +91,8 @@ static char *rng_random_get_filename(Object *obj, Error 
> > **errp)
> >      return g_strdup(s->filename);
> >  }
> >  
> > -static bool rng_random_config(Object *obj, const char *filename, Error 
> > **errp)
> > +bool qom_rng_random_config(Object *obj, bool has_filename,
> > +                           const char *filename, Error **errp)
> >  {
> >      RngRandom *s = RNG_RANDOM(obj);
> >  
> > @@ -100,17 +102,6 @@ static bool rng_random_config(Object *obj, const char 
> > *filename, Error **errp)
> >      return true;
> >  }
> >  
> > -static bool rng_random_marshal_config(Object *obj, Visitor *v, Error 
> > **errp)
> > -{
> > -    g_autofree char *filename = NULL;
> > -
> > -    if (!visit_type_str(v, "filename", &filename, errp)) {
> > -        return false;
> > -    }
> > -
> > -    return rng_random_config(obj, filename, errp);
> > -}
> > -
> 
> Generated replacement:
> 
>    bool qom_rng_random_marshal_config(Object *obj, Visitor *v, Error **errp)
>    {
>        q_obj_rng_random_config config = {0};
> 
>        if (!visit_type_q_obj_rng_random_config_members(v, &config, errp)) {
>            return false;
>        }
> 
>        return qom_rng_random_config(obj, config.has_filename, 
> config.filename, errp);
>    }
> 
> where visit_type_q_obj_rng_random_config_members() is
> 
>     bool visit_type_q_obj_rng_random_config_members(Visitor *v, 
> q_obj_rng_random_config *obj, Error **errp)
>     {
>         if (visit_optional(v, "filename", &obj->has_filename)) {
>             if (!visit_type_str(v, "filename", &obj->filename, errp)) {
>                 return false;
>             }
>         }
>         return true;
>     }
> 
> The handwritten version lacks a visit_optional(), I think.

Yes, this looks like a bug in the handwritten version from patch 5.

The generated version seems to have a bug, too: It doesn't free the
members of @config after calling qom_rng_random_config().

Kevin




reply via email to

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