Re: Missing errcode() in ereport
Andres Freund <andres@anarazel.de>
From: Andres Freund <andres@anarazel.de>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Amit Kapila <amit.kapila16@gmail.com>, Michael Paquier <michael@paquier.xyz>, Julien Rouhaud <rjuju123@gmail.com>, Masahiko Sawada <masahiko.sawada@2ndquadrant.com>, PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Date: 2020-03-20T02:12:04Z
Lists: pgsql-hackers
Hi, On 2020-03-19 21:03:17 -0400, Tom Lane wrote: > I wrote: > > I think that at least some compilers will complain about side-effect-free > > subexpressions of a comma expression. Could we restructure things so > > that the errcode/errmsg/etc calls form a standalone comma expression > > rather than appearing to be arguments of a varargs function? > > Yeah, the attached quick-hack patch seems to work really well for > this. Heh, you're too fast. I just sent something similar, and a few followup patches. What is your thinking about pain around backpatching it might introduce? We can't easily backpatch support for ereport-without-extra-parens, I think, because it needs __VA_ARGS__? > As a nice side benefit, the backend gets a couple KB smaller from > removal of errfinish's useless dummy argument. I don't think it's the removal of the dummy parameter itself that constitutes most of the savings, but instead it's not having to push the return value of errmsg(), errcode(), et al as vararg arguments. > I think that we could now also change all the helper functions > (errmsg et al) to return void instead of a dummy value, but that > would make the patch a lot longer and probably not move the > goalposts much in terms of error detection. I did include that in my prototype patch. Agree that it's not necessary for the error detection capability, but it seems misleading to leave the return values around if they're not actually needed. > It also looks like we could use the same trick to get plain elog() > to have the behavior of not evaluating its arguments when it's > not going to print anything. I've not poked at that yet either. I've included a patch for that. I think it's now sufficient to #define elog(elevel, ...) \ ereport(elevel, errmsg(__VA_ARGS__)) which imo is quite nice, as it allows us to get rid of a lot of duplication. Greetings, Andres Freund
Commits
-
Go back to returning int from ereport auxiliary functions.
- bda6dedbea59 13.0 landed
-
Improve the internal implementation of ereport().
- 17a28b03645e 13.0 landed
-
Re-implement the ereport() macro using __VA_ARGS__.
- e3a87b4991cc 13.0 landed
- a86715451653 12.3 landed
-
Add missing errcode() in a few ereport calls.
- 6bdfe428d399 9.5.22 landed
- fe27ce1c136d 9.6.18 landed
- 569f9354bb43 10.13 landed
- 18c41cb6b714 11.8 landed
- e37824136f06 12.3 landed
- b4f140869f5d 13.0 landed