qemu-devel
[Top][All Lists]
Advanced

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

Re: [PATCH] qapi: enable use of g_autoptr with QAPI types


From: Daniel P . Berrangé
Subject: Re: [PATCH] qapi: enable use of g_autoptr with QAPI types
Date: Thu, 23 Jul 2020 12:56:19 +0100
User-agent: Mutt/1.14.5 (2020-06-23)

On Thu, Jul 23, 2020 at 06:49:44AM -0500, Eric Blake wrote:
> On 7/23/20 6:12 AM, Daniel P. Berrangé wrote:
> > Currently QAPI generates a type and function for free'ing it:
> > 
> >    typedef struct QCryptoBlockCreateOptions QCryptoBlockCreateOptions;
> >    void qapi_free_QCryptoBlockCreateOptions(QCryptoBlockCreateOptions *obj);
> > 
> 
> > The above code example now becomes
> > 
> >    g_autoptr(QCryptoBlockCreateOptions) opts = NULL;
> > 
> >    opts = g_new0(QCryptoBlockCreateOptions, 1);
> > 
> >    ....do stuff with opts...
> > 
> > Note, if the local pointer needs to live beyond the scope holding the
> > variable, then g_steal_pointer can be used. This is useful to return the
> > pointer to the caller in the success codepath, while letting it be freed
> > in all error codepaths.
> > 
> >    return g_steal_pointer(&opts);
> > 
> 
> Yep, the idea makes sense!
> 
> > Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> > ---
> >   include/crypto/block.h | 2 --
> >   scripts/qapi/types.py  | 1 +
> >   2 files changed, 1 insertion(+), 2 deletions(-)
> 
> Missing a counterpart change to docs/devel/qapi-code-gen.txt.  And it might
> be nice to make this a series with at least one followup patch using the new
> capability, or at least so 'make check' coverage.  But otherwise on the
> right track.

The crypto/block.c already makes use of this capability, which is why
I had to remove the line from block.h to avoid declaring the same thing
twice !

Regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|




reply via email to

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