All of lore.kernel.org
 help / color / mirror / Atom feed
From: Eric Blake <eblake@redhat.com>
To: "Dr. David Alan Gilbert" <dgilbert@redhat.com>,
	Fam Zheng <famz@redhat.com>
Cc: peter.maydell@linaro.org, quintela@redhat.com, cohuck@redhat.com,
	qemu-devel@nongnu.org, peterx@redhat.com, rth@twiddle.net
Subject: Re: [Qemu-devel] [PATCH 5/5] migration: Route more error paths
Date: Wed, 20 Sep 2017 10:32:26 -0500	[thread overview]
Message-ID: <80ea7936-97b1-7d82-1373-149d33a811f7@redhat.com> (raw)
In-Reply-To: <20170920142040.GE2449@work-vm>

[-- Attachment #1: Type: text/plain, Size: 1371 bytes --]

On 09/20/2017 09:20 AM, Dr. David Alan Gilbert wrote:

>>>      /* Save file with vmstate */
>>> -    vmstate_save_state(f, desc, obj, NULL);
>>> +    g_assert(!vmstate_save_state(f, desc, obj, NULL));
>>
>> Though this is test code, isn't putting anything with a side effect into an
>> assert expression a very bad pattern in general?
> 
> Hmm; ok I've changed this but I'm not really convinced; the whole point
> of an asser in a test is to actually run it, and I think the g_assert
> prints the text that failed, so it gives you a much better error inline.

glib doesn't make life any easier by having two different flavors of
assertions.

g_assert() can be disabled at compile-time (side effects are lost).  It
is roughly akin to assert(); and the output when an assertion fails
isn't that much more useful than what you get with plain assert().

g_assert_cmpint() cannot be disabled at compile-time, but can have a
runtime switch on whether it abort()s or continues on.  Here, the output
when something fails is MUCH more pleasant to read.

But the fact that there are two separate families of g_assert* behaviors
just makes it easier to live by the mantra that side-effects don't
belong inside assertions.

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


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

  reply	other threads:[~2017-09-20 15:32 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-09-19 18:00 [Qemu-devel] [PATCH 0/5] migration: let pre_save fail Dr. David Alan Gilbert (git)
2017-09-19 18:00 ` [Qemu-devel] [PATCH 1/5] migration: pre_save return int Dr. David Alan Gilbert (git)
2017-09-20 13:57   ` Cornelia Huck
2017-09-20 14:32     ` Dr. David Alan Gilbert
2017-09-19 18:00 ` [Qemu-devel] [PATCH 2/5] migration: check pre_save return in vmstate_save_state Dr. David Alan Gilbert (git)
2017-09-19 18:00 ` [Qemu-devel] [PATCH 3/5] migration: wire vmstate_save_state errors up to vmstate_subsection_save Dr. David Alan Gilbert (git)
2017-09-19 18:00 ` [Qemu-devel] [PATCH 4/5] migration: Route errors up through vmstate_save Dr. David Alan Gilbert (git)
2017-09-19 18:00 ` [Qemu-devel] [PATCH 5/5] migration: Route more error paths Dr. David Alan Gilbert (git)
2017-09-20  3:31   ` Peter Xu
2017-09-20 15:45     ` Dr. David Alan Gilbert
2017-09-20  3:55   ` Fam Zheng
2017-09-20 13:26     ` Eric Blake
2017-09-20 14:20     ` Dr. David Alan Gilbert
2017-09-20 15:32       ` Eric Blake [this message]
2017-09-20 14:30   ` Cornelia Huck
2017-09-20 15:57     ` Dr. David Alan Gilbert
2017-09-20 16:00       ` Cornelia Huck

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=80ea7936-97b1-7d82-1373-149d33a811f7@redhat.com \
    --to=eblake@redhat.com \
    --cc=cohuck@redhat.com \
    --cc=dgilbert@redhat.com \
    --cc=famz@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=peterx@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=quintela@redhat.com \
    --cc=rth@twiddle.net \
    /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.