qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Daniel P. Berrangé" <berrange@redhat.com>
To: Eric Blake <eblake@redhat.com>
Cc: Michael Roth <mdroth@linux.vnet.ibm.com>,
	qemu-devel@nongnu.org, Markus Armbruster <armbru@redhat.com>
Subject: Re: [PATCH] qapi: enable use of g_autoptr with QAPI types
Date: Thu, 23 Jul 2020 12:56:19 +0100	[thread overview]
Message-ID: <20200723115619.GG2615312@redhat.com> (raw)
In-Reply-To: <781b8043-bce5-9f64-bc5f-4f2f740c6a6d@redhat.com>

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	other threads:[~2020-07-23 11:57 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-23 11:12 [PATCH] qapi: enable use of g_autoptr with QAPI types Daniel P. Berrangé
2020-07-23 11:49 ` Eric Blake
2020-07-23 11:56   ` Daniel P. Berrangé [this message]
2020-07-23 12:50     ` Markus Armbruster
2020-07-23 12:52       ` Daniel P. Berrangé

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200723115619.GG2615312@redhat.com \
    --to=berrange@redhat.com \
    --cc=armbru@redhat.com \
    --cc=eblake@redhat.com \
    --cc=mdroth@linux.vnet.ibm.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).