diff options
author | Peter Eisentraut <peter_e@gmx.net> | 2017-08-22 20:05:49 -0400 |
---|---|---|
committer | Peter Eisentraut <peter_e@gmx.net> | 2017-11-29 09:56:49 -0500 |
commit | cdddd5d40b8a8b37db18adda3912e029756d1e36 (patch) | |
tree | eebbf34e9c5c2e96453bca2dbf81739f3cd9a53c /src | |
parent | eaedf0df7197b21182f6c341a44e4fdaa3cd6ea6 (diff) | |
download | postgresql-cdddd5d40b8a8b37db18adda3912e029756d1e36.tar.gz postgresql-cdddd5d40b8a8b37db18adda3912e029756d1e36.zip |
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>
Diffstat (limited to 'src')
-rw-r--r-- | src/pl/plpython/plpy_elog.c | 2 | ||||
-rw-r--r-- | src/pl/plpython/plpy_elog.h | 28 |
2 files changed, 28 insertions, 2 deletions
diff --git a/src/pl/plpython/plpy_elog.c b/src/pl/plpython/plpy_elog.c index bb864899f61..e244104fed7 100644 --- a/src/pl/plpython/plpy_elog.c +++ b/src/pl/plpython/plpy_elog.c @@ -44,7 +44,7 @@ static bool set_string_attr(PyObject *obj, char *attrname, char *str); * in the context. */ void -PLy_elog(int elevel, const char *fmt,...) +PLy_elog_impl(int elevel, const char *fmt,...) { char *xmsg; char *tbmsg; diff --git a/src/pl/plpython/plpy_elog.h b/src/pl/plpython/plpy_elog.h index e73177d130c..e4b30c3cca1 100644 --- a/src/pl/plpython/plpy_elog.h +++ b/src/pl/plpython/plpy_elog.h @@ -10,7 +10,33 @@ extern PyObject *PLy_exc_error; extern PyObject *PLy_exc_fatal; extern PyObject *PLy_exc_spi_error; -extern void PLy_elog(int elevel, const char *fmt,...) pg_attribute_printf(2, 3); +/* + * PLy_elog() + * + * See comments at elog() about the compiler hinting. + */ +#ifdef HAVE__VA_ARGS +#ifdef HAVE__BUILTIN_CONSTANT_P +#define PLy_elog(elevel, ...) \ + do { \ + PLy_elog_impl(elevel, __VA_ARGS__); \ + if (__builtin_constant_p(elevel) && (elevel) >= ERROR) \ + pg_unreachable(); \ + } while(0) +#else /* !HAVE__BUILTIN_CONSTANT_P */ +#define PLy_elog(elevel, ...) \ + do { \ + const int elevel_ = (elevel); \ + PLy_elog_impl(elevel_, __VA_ARGS__); \ + if (elevel_ >= ERROR) \ + pg_unreachable(); \ + } while(0) +#endif /* HAVE__BUILTIN_CONSTANT_P */ +#else /* !HAVE__VA_ARGS */ +#define PLy_elog PLy_elog_impl +#endif /* HAVE__VA_ARGS */ + +extern void PLy_elog_impl(int elevel, const char *fmt,...) pg_attribute_printf(2, 3); extern void PLy_exception_set(PyObject *exc, const char *fmt,...) pg_attribute_printf(2, 3); |