All the mail mirrored from lore.kernel.org
 help / color / mirror / Atom feed
From: Eric Blake <eblake@redhat.com>
To: "Michael S. Tsirkin" <mst@redhat.com>, qemu-devel@nongnu.org
Cc: kwolf@redhat.com, armbru@redhat.com, dgilbert@redhat.com
Subject: Re: [Qemu-devel] [PATCH v2 1/3] error: don't rely on pointer comparisons
Date: Wed, 17 Jun 2015 09:41:19 -0600	[thread overview]
Message-ID: <5581951F.9050802@redhat.com> (raw)
In-Reply-To: <1434525861-21768-2-git-send-email-mst@redhat.com>

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

On 06/17/2015 01:24 AM, Michael S. Tsirkin wrote:
> makes it possible to copy error_abort pointers,
> not just pass them on directly.
> 

> @@ -168,7 +175,7 @@ void error_free(Error *err)
>  
>  void error_propagate(Error **dst_errp, Error *local_err)
>  {
> -    if (local_err && dst_errp == &error_abort) {
> +    if (local_err && error_is_abort(dst_errp)) {
>          error_report_err(local_err);
>          abort();
>      } else if (dst_errp && !*dst_errp) {

As I pointed out on 3/3, this breaks code that does:

if (local_err) {
    error_propagate(errp, local_err);
    ...
}

now that local_err is non-NULL when errp is error_abort.  But what if
you alter the semantics, and have error_propagate return a bool (true if
an error was propagated, false if no error or caller didn't care):

bool error_propagate(Error **dst_errp, Error *local_err)
{
    if (error_is_abort(&local_err)) {
        assert(error_is_abort(dst_errp);
        return false;
    }
    if (local_err && error_is_abort(dst_errp)) {
        error_report_err(local_err);
        abort();
    }
    if (dst_errp && !*dst_errp) {
        *dst_errp = local_err;
        return true;
    }
    if (local_err) {
        error_free(local_err);
    }
    return false;
}

then callers can be modified to this idiom (also has the benefit of
being one line shorter):

if (error_propagate(errp, local_err)) {
    ...
}

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org


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

  parent reply	other threads:[~2015-06-17 15:43 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-17  7:24 [Qemu-devel] [PATCH v2 0/3] error: allow local errors to trigger abort Michael S. Tsirkin
2015-06-17  7:24 ` [Qemu-devel] [PATCH v2 1/3] error: don't rely on pointer comparisons Michael S. Tsirkin
2015-06-17 15:21   ` Eric Blake
2015-06-17 15:41   ` Eric Blake [this message]
2015-06-18 15:36     ` Markus Armbruster
2015-06-18 16:10   ` Markus Armbruster
2015-06-17  7:24 ` [Qemu-devel] [PATCH v2 2/3] error: allow local errors to trigger abort Michael S. Tsirkin
2015-06-17  7:24 ` [Qemu-devel] [PATCH v2 3/3] block/nfs: switch to error_init_local Michael S. Tsirkin
2015-06-17 15:32   ` Eric Blake
2015-06-23  9:03     ` Michael S. Tsirkin
2015-06-18 16:34 ` [Qemu-devel] [PATCH v2 0/3] error: allow local errors to trigger abort Markus Armbruster
2015-06-18 16:49   ` Paolo Bonzini
2015-06-22 11:31     ` Markus Armbruster

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=5581951F.9050802@redhat.com \
    --to=eblake@redhat.com \
    --cc=armbru@redhat.com \
    --cc=dgilbert@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=mst@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.