All of lore.kernel.org
 help / color / mirror / Atom feed
From: Eric Blake <eblake@redhat.com>
To: "Daniel P. Berrangé" <berrange@redhat.com>, qemu-devel@nongnu.org
Cc: "Alex Bennée" <alex.bennee@linaro.org>
Subject: Re: [Qemu-devel] [PATCH 3/4] docs: document use of automatic cleanup functions in glib
Date: Fri, 23 Aug 2019 14:53:41 -0500	[thread overview]
Message-ID: <d95f3cad-1b15-5255-a0c9-fcfa2f25e414@redhat.com> (raw)
In-Reply-To: <20190823163931.7442-4-berrange@redhat.com>


[-- Attachment #1.1: Type: text/plain, Size: 1255 bytes --]

On 8/23/19 11:39 AM, Daniel P. Berrangé wrote:
> Document the use of g_autofree and g_autoptr in glib for automatic
> freeing of memory, or other resource cleanup (eg mutex unlocking).
> 
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> ---
>  CODING_STYLE.md | 101 ++++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 101 insertions(+)


> +The cleanup functions are not restricted to simply free'ing memory. The
> +GMutexLocker class is a variant of GMutex that has automatic locking and
> +unlocking at start and end of the enclosing scope
> +
> +In the following example, the `lock` in `MyObj` will be held for the
> +precise duration of the `somefunc` function
> +
> +    typedef struct {
> +        GMutex lock;
> +    } MyObj;
> +
> +    char *somefunc(MyObj *obj) {
> +        g_autofree GMutexLocker *locker = g_mutex_locker_new(&obj->lock)

Wrong example (you don't want to call g_free, and you missed ';'). This
should be

g_autoptr (GMutexLocker) locker = g_mutex_locker_new(&obj->lock);

With that fixed,

Reviewed-by: Eric Blake <eblake@redhat.com>

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

  reply	other threads:[~2019-08-23 19:56 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-23 16:39 [Qemu-devel] [PATCH 0/4] docs: add docs about use of automatic cleanup functions Daniel P. Berrangé
2019-08-23 16:39 ` [Qemu-devel] [PATCH 1/4] docs: convert CODING_STYLE and HACKING to markdown syntax Daniel P. Berrangé
2019-08-28 12:25   ` Alex Bennée
2019-08-28 13:08     ` Daniel P. Berrangé
2019-08-23 16:39 ` [Qemu-devel] [PATCH 2/4] docs: merge HACKING.md contents into CODING_STYLE.md Daniel P. Berrangé
2019-08-23 19:35   ` Eric Blake
2019-08-28 15:06     ` Alex Bennée
2019-08-28 15:10       ` Daniel P. Berrangé
2019-08-23 16:39 ` [Qemu-devel] [PATCH 3/4] docs: document use of automatic cleanup functions in glib Daniel P. Berrangé
2019-08-23 19:53   ` Eric Blake [this message]
2019-08-28  9:00   ` Stefan Hajnoczi
2019-08-28 15:14   ` Alex Bennée
2019-08-28 15:20     ` Daniel P. Berrangé
2019-08-28 16:04       ` Alex Bennée
2019-08-23 16:39 ` [Qemu-devel] [PATCH 4/4] docs: add table of contents to CODING_STYLE.md Daniel P. Berrangé
2019-08-23 21:48 ` [Qemu-devel] [PATCH 0/4] docs: add docs about use of automatic cleanup functions Marc-André Lureau
2019-08-28 12:30   ` Alex Bennée
2019-08-28 13:07     ` 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=d95f3cad-1b15-5255-a0c9-fcfa2f25e414@redhat.com \
    --to=eblake@redhat.com \
    --cc=alex.bennee@linaro.org \
    --cc=berrange@redhat.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.