diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2020-03-24 11:48:33 -0400 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2020-03-24 11:49:00 -0400 |
commit | e3a87b4991cc2d00b7a3082abb54c5f12baedfd1 (patch) | |
tree | 84b3fdf1ebbc4452e357b73f13b50ff911b2c35d /src/backend/utils/error/elog.c | |
parent | cef27ae01ac872355b2bd56c0882aafe5c6f08de (diff) | |
download | postgresql-e3a87b4991cc2d00b7a3082abb54c5f12baedfd1.tar.gz postgresql-e3a87b4991cc2d00b7a3082abb54c5f12baedfd1.zip |
Re-implement the ereport() macro using __VA_ARGS__.
Now that we require C99, we can depend on __VA_ARGS__ to work, and
revising ereport() to use it has several significant benefits:
* The extra parentheses around the auxiliary function calls are now
optional. Aside from being a bit less ugly, this removes a common
gotcha for new contributors, because in some cases the compiler errors
you got from forgetting them were unintelligible.
* The auxiliary function calls are now evaluated as a comma expression
list rather than as extra arguments to errfinish(). This means that
compilers can be expected to warn about no-op expressions in the list,
allowing detection of several other common mistakes such as forgetting
to add errmsg(...) when converting an elog() call to ereport().
* Unlike the situation with extra function arguments, comma expressions
are guaranteed to be evaluated left-to-right, so this removes platform
dependency in the order of the auxiliary function calls. While that
dependency hasn't caused us big problems in the past, this change does
allow dropping some rather shaky assumptions around errcontext() domain
handling.
There's no intention to make wholesale changes of existing ereport
calls, but as proof-of-concept this patch removes the extra parens
from a couple of calls in postgres.c.
While new code can be written either way, code intended to be
back-patched will need to use extra parens for awhile yet. It seems
worth back-patching this change into v12, so as to reduce the window
where we have to be careful about that by one year. Hence, this patch
is careful to preserve ABI compatibility; a followup HEAD-only patch
will make some additional simplifications.
Andres Freund and Tom Lane
Discussion: https://postgr.es/m/CA+fd4k6N8EjNvZpM8nme+y+05mz-SM8Z_BgkixzkA34R+ej0Kw@mail.gmail.com
Diffstat (limited to 'src/backend/utils/error/elog.c')
-rw-r--r-- | src/backend/utils/error/elog.c | 10 |
1 files changed, 0 insertions, 10 deletions
diff --git a/src/backend/utils/error/elog.c b/src/backend/utils/error/elog.c index 62eef7b71f4..de705c86fa1 100644 --- a/src/backend/utils/error/elog.c +++ b/src/backend/utils/error/elog.c @@ -1116,16 +1116,6 @@ errcontext_msg(const char *fmt,...) * translate it. Instead, each errcontext_msg() call should be preceded by * a set_errcontext_domain() call to specify the domain. This is usually * done transparently by the errcontext() macro. - * - * Although errcontext is primarily meant for use at call sites distant from - * the original ereport call, there are a few places that invoke errcontext - * within ereport. The expansion of errcontext as a comma expression calling - * set_errcontext_domain then errcontext_msg is problematic in this case, - * because the intended comma expression becomes two arguments to errfinish, - * which the compiler is at liberty to evaluate in either order. But in - * such a case, the set_errcontext_domain calls must be selecting the same - * TEXTDOMAIN value that the errstart call did, so order does not matter - * so long as errstart initializes context_domain along with domain. */ int set_errcontext_domain(const char *domain) |