]> granicus.if.org Git - postgresql/commitdiff
Add compiler hints to PLy_elog()
authorPeter Eisentraut <peter_e@gmx.net>
Wed, 23 Aug 2017 00:05:49 +0000 (20:05 -0400)
committerPeter Eisentraut <peter_e@gmx.net>
Wed, 29 Nov 2017 14:56:49 +0000 (09:56 -0500)
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>
src/pl/plpython/plpy_elog.c
src/pl/plpython/plpy_elog.h

index bb864899f618aade745cd031e94233ce8a083356..e244104fed7009bd978964be3f4b60d9f3a6e07e 100644 (file)
@@ -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;
index e73177d130c501ff95182af067e932f380d9c6ed..e4b30c3cca1637edf532264d9503f4880f9eee14 100644 (file)
@@ -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);