Re: Out-of-memory error reports in libpq
Ranier Vilela <ranier.vf@gmail.com>
From: Ranier Vilela <ranier.vf@gmail.com>
To: Peter Smith <smithpb2250@gmail.com>
Cc: Tom Lane <tgl@sss.pgh.pa.us>, Andres Freund <andres@anarazel.de>, PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>,
Michael Paquier <michael@paquier.xyz>, Alvaro Herrera <alvherre@alvh.no-ip.org>, Peter Geoghegan <pg@bowt.ie>
Date: 2021-07-29T11:23:17Z
Lists: pgsql-hackers
Em qui., 29 de jul. de 2021 às 04:02, Peter Smith <smithpb2250@gmail.com>
escreveu:
> (This is not a code review - this is just to satisfy my curiosity)
>
> I've seen lots of code like this where I may have been tempted to use
> a ternary operator for readability, so I was wondering is there a PG
> convention to avoid such ternary operator assignments, or is it simply
> a personal taste thing, or is there some other reason?
>
> For example:
>
> if (msg)
> res->errMsg = msg;
> else
> res->errMsg = libpq_gettext("out of memory\n");
>
The C compiler will expand:
res->errMsg = msg ? msg : libpq_gettext("out of memory\n");
to
if (msg)
res->errMsg = msg;
else
res->errMsg = libpq_gettext("out of memory\n");
What IMHO is much more readable.
regards,
Ranier Vilela
Commits
-
Improve libpq's handling of OOM during error message construction.
- 514b4c11d247 15.0 landed
- 43f1d2ab361c 14.0 landed
-
In libpq, always append new error messages to conn->errorMessage.
- ffa2e4670123 14.0 cited