Files
postgresql/src/pl/plpython/plpy_elog.h
Tom Lane 7640f93123 Fix assorted header files that failed to compile standalone.
We have a longstanding project convention that all .h files should
be includable with no prerequisites other than postgres.h.  This is
tested/relied-on by cpluspluscheck.  However, cpluspluscheck has not
historically been applied to most headers outside the src/include
tree, with the predictable consequence that some of them don't work.
Fix that, usually by adding missing #include dependencies.

The change in printf_hack.h might require some explanation: without
it, my C++ compiler whines that the function is unused.  There's
not so many call sites that "inline" is going to cost much, and
besides all the callers are in test code that we really don't care
about the size of.

There's no actual bugs being fixed here, so I see no need to back-patch.

Discussion: https://postgr.es/m/b517ec3918d645eb950505eac8dd434e@gaz-is.ru
2019-05-31 11:45:33 -04:00

47 lines
1.2 KiB
C

/*
* src/pl/plpython/plpy_elog.h
*/
#ifndef PLPY_ELOG_H
#define PLPY_ELOG_H
#include "plpython.h"
/* global exception classes */
extern PyObject *PLy_exc_error;
extern PyObject *PLy_exc_fatal;
extern PyObject *PLy_exc_spi_error;
/*
* PLy_elog()
*
* See comments at elog() about the compiler hinting.
*/
#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 */
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);
extern void PLy_exception_set_plural(PyObject *exc, const char *fmt_singular, const char *fmt_plural,
unsigned long n,...) pg_attribute_printf(2, 5) pg_attribute_printf(3, 5);
extern void PLy_exception_set_with_details(PyObject *excclass, ErrorData *edata);
#endif /* PLPY_ELOG_H */