qemu-devel
[Top][All Lists]
Advanced

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

Re: [PATCH v7 02/11] error: auto propagated local_err


From: Eric Blake
Subject: Re: [PATCH v7 02/11] error: auto propagated local_err
Date: Fri, 21 Feb 2020 08:29:49 -0600
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.4.1

On 2/21/20 3:42 AM, Vladimir Sementsov-Ogievskiy wrote:

+#define ERRP_AUTO_PROPAGATE()                                  \
+    g_auto(ErrorPropagator) _auto_errp_prop = {.errp = errp};  \
+    errp = ((errp == NULL || *errp == error_fatal)             \
+            ? &_auto_errp_prop.local_err : errp)
+
  /*
   * Special error destination to abort on error.
   * See error_setg() and error_propagate() for details.

*errp == error_fatal tests *errp == NULL, which is not what you want.
You need to test errp == &error_fatal, just like error_handle_fatal().

Oops, great bug) And nobody noticed before) Of course, you are right.

Sorry I missed it in my earlier looks.



Superfluous parenthesis around the first operand of ?:.

Wouldn't

    #define ERRP_AUTO_PROPAGATE()                                  \
        g_auto(ErrorPropagator) _auto_errp_prop = {.errp = errp};  \
        if (!errp || errp == &error_fatal) {                       \
            errp = &_auto_errp_prop.local_err;                     \
        }

be clearer?


Hmm, notation with "if" will allow omitting ';' after macro invocation, which seems not good..

Then wrap it:

g_auto(ErrorPropagator) _auto_errp_prop = {.errp = errp}; \
do { \
  if (!errp || errp == &error_fata) {
    errp = &_auto_errp_prop.local_err; \
  } \
while (0)


And if I'm not wrong we've already discussed it somewhere in previous versions.

The original use of ?: stems from my suggestion on an earlier revision when we were still trying to pack everything into two consecutive declaration lines, rather than a declaration and a statement (as ?: is necessary for conditionals in declarations). But since then, we decided to go with a statement (we require a C99 compiler, so declaration after statement is supported by our compiler, even if our coding style currently avoids it where possible), so as long as we support statements, we might as well go with a legible statement instead of insisting on the compact ?: form.

--
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]