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
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel