Skip to content

Commit cdddd5d

Browse files
committed
Add compiler hints to PLy_elog()
Decorate PLy_elog() in a similar way as elog(), to give compilers and static analyzers hints in which cases it does not return. Reviewed-by: John Naylor <jcnaylor@gmail.com>
1 parent eaedf0d commit cdddd5d

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

src/pl/plpython/plpy_elog.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ static bool set_string_attr(PyObject *obj, char *attrname, char *str);
4444
* in the context.
4545
*/
4646
void
47-
PLy_elog(int elevel, const char *fmt,...)
47+
PLy_elog_impl(int elevel, const char *fmt,...)
4848
{
4949
char *xmsg;
5050
char *tbmsg;

src/pl/plpython/plpy_elog.h

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,33 @@ extern PyObject *PLy_exc_error;
1010
extern PyObject *PLy_exc_fatal;
1111
extern PyObject *PLy_exc_spi_error;
1212

13-
extern void PLy_elog(int elevel, const char *fmt,...) pg_attribute_printf(2, 3);
13+
/*
14+
* PLy_elog()
15+
*
16+
* See comments at elog() about the compiler hinting.
17+
*/
18+
#ifdef HAVE__VA_ARGS
19+
#ifdef HAVE__BUILTIN_CONSTANT_P
20+
#define PLy_elog(elevel, ...) \
21+
do { \
22+
PLy_elog_impl(elevel, __VA_ARGS__); \
23+
if (__builtin_constant_p(elevel) && (elevel) >= ERROR) \
24+
pg_unreachable(); \
25+
} while(0)
26+
#else /* !HAVE__BUILTIN_CONSTANT_P */
27+
#define PLy_elog(elevel, ...) \
28+
do { \
29+
const int elevel_ = (elevel); \
30+
PLy_elog_impl(elevel_, __VA_ARGS__); \
31+
if (elevel_ >= ERROR) \
32+
pg_unreachable(); \
33+
} while(0)
34+
#endif /* HAVE__BUILTIN_CONSTANT_P */
35+
#else /* !HAVE__VA_ARGS */
36+
#define PLy_elog PLy_elog_impl
37+
#endif /* HAVE__VA_ARGS */
38+
39+
extern void PLy_elog_impl(int elevel, const char *fmt,...) pg_attribute_printf(2, 3);
1440

1541
extern void PLy_exception_set(PyObject *exc, const char *fmt,...) pg_attribute_printf(2, 3);
1642

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy