1
0
mirror of https://github.com/postgres/postgres.git synced 2025-04-24 10:47:04 +03:00

Teach compiler that ereport(>=ERROR) does not return

When elevel >= ERROR, we add an abort() call to the ereport() macro to
give the compiler a hint that the ereport() expansion will not return,
but the abort() isn't actually reached because the longjmp happens in
errfinish().

Because the effect of ereport() varies with the elevel, we cannot use
standard compiler attributes such as noreturn for this.
This commit is contained in:
Peter Eisentraut 2012-08-21 00:03:32 -04:00
parent ffdd5a0ee3
commit 71450d7fd6

View File

@ -100,11 +100,16 @@
* and have errstart insert the default text domain. Modules can either use * and have errstart insert the default text domain. Modules can either use
* ereport_domain() directly, or preferably they can override the TEXTDOMAIN * ereport_domain() directly, or preferably they can override the TEXTDOMAIN
* macro. * macro.
*
* When elevel >= ERROR, we add an abort() call to give the compiler a hint
* that the ereport() expansion will not return, but the abort() isn't actually
* reached because the longjmp happens in errfinish().
*---------- *----------
*/ */
#define ereport_domain(elevel, domain, rest) \ #define ereport_domain(elevel, domain, rest) \
(errstart(elevel, __FILE__, __LINE__, PG_FUNCNAME_MACRO, domain) ? \ (errstart(elevel, __FILE__, __LINE__, PG_FUNCNAME_MACRO, domain) ? \
(errfinish rest) : (void) 0) (errfinish rest) : (void) 0), \
((elevel) >= ERROR ? abort() : (void) 0)
#define ereport(elevel, rest) \ #define ereport(elevel, rest) \
ereport_domain(elevel, TEXTDOMAIN, rest) ereport_domain(elevel, TEXTDOMAIN, rest)