qemu-devel
[Top][All Lists]
Advanced

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

Re: [Qemu-devel] [RFC] error: auto propagated local_err


From: Eric Blake
Subject: Re: [Qemu-devel] [RFC] error: auto propagated local_err
Date: Wed, 18 Sep 2019 13:32:41 -0500
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0

On 9/18/19 1:05 PM, Eric Blake wrote:

>>> #define MAKE_ERRP_SAFE() \
>>> g_auto(ErrorPropagationStruct) (__auto_errp_prop) = {.errp = errp}; \
>>> errp = &__auto_errp_prop.local_err
>>>

I tried to see if this could be done with just a single declaration
line, as in:

typedef struct ErrorPropagator {
    Error **errp;
    Error *local_err;
} ErrorPropagator;

#define MAKE_ERRP_SAFE() \
  g_auto(ErrorPropagator) __auto_errp_prop = { \
    errp, ((errp = &__auto_errp_prop.local_err), NULL) }

But sadly, C17 paragraph 6.7.9P23 states:

"The evaluations of the initialization list expressions are
indeterminately sequenced with respect to one another and thus the order
in which any side effects occur is unspecified."

which does not bode well for the assignment to __auto_errp_prop.errp.
All changes to errp would have to be within the same initializer.  Maybe:

#define MAKE_ERRP_SAFE() \
  g_auto(ErrorPropagator) __auto_errp_prop = { \
    .local_err = (__auto_errp_prop.err = errp, \
        (errp = &__auto_errp_prop.local_err), NULL) }

but by the time you get that complicated, just using a statement is
easier to read.

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



reply via email to

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