summaryrefslogtreecommitdiff
path: root/src/pl/plpython
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2023-12-26 16:16:29 -0500
committerTom Lane <tgl@sss.pgh.pa.us>2023-12-26 16:16:37 -0500
commit58c3151bbc045e8f575027f53c79e328381e7e61 (patch)
treecdd43e3a147ae571246b477a1edf51f544eae05a /src/pl/plpython
parentc4fe2e8220462a9688dba4380bda0ccb2ecaabb7 (diff)
Hide warnings from Python headers when using gcc-compatible compiler.
Like commit 388e80132, use "#pragma GCC system_header" to silence warnings appearing within the Python headers, since newer Python versions no longer worry about some restrictions we still use like -Wdeclaration-after-statement. This patch improves on 388e80132 by inventing a separate wrapper header file, allowing the pragma to be tightly scoped to just the Python headers and not other stuff we have laying about in plpython.h. I applied the same technique to plperl for the same reason: the original patch suppressed warnings for a good deal of our own code, not only the Perl headers. Like the previous commit, back-patch to supported branches. Peter Eisentraut and Tom Lane Discussion: https://postgr.es/m/ae523163-6d2a-4b81-a875-832e48dec502@eisentraut.org
Diffstat (limited to 'src/pl/plpython')
-rw-r--r--src/pl/plpython/Makefile3
-rw-r--r--src/pl/plpython/meson.build1
-rw-r--r--src/pl/plpython/plpython.h23
-rw-r--r--src/pl/plpython/plpython_system.h53
4 files changed, 59 insertions, 21 deletions
diff --git a/src/pl/plpython/Makefile b/src/pl/plpython/Makefile
index ef0a5905aed..f959083a0bd 100644
--- a/src/pl/plpython/Makefile
+++ b/src/pl/plpython/Makefile
@@ -39,6 +39,7 @@ DATA = $(NAME)u.control $(NAME)u--1.0.sql
# header files to install - it's not clear which of these might be needed
# so install them all.
INCS = plpython.h \
+ plpython_system.h \
plpy_cursorobject.h \
plpy_elog.h \
plpy_exec.h \
@@ -120,7 +121,7 @@ install-data: installdirs
uninstall-data:
rm -f $(addprefix '$(DESTDIR)$(datadir)/extension'/, $(notdir $(DATA)))
- rm -f $(addprefix '$(DESTDIR)$(includedir_server)'/, plpython.h plpy_util.h)
+ rm -f $(addprefix '$(DESTDIR)$(includedir_server)'/, $(INCS))
.PHONY: install-data uninstall-data
diff --git a/src/pl/plpython/meson.build b/src/pl/plpython/meson.build
index 9f4603a8b5e..0071817e44a 100644
--- a/src/pl/plpython/meson.build
+++ b/src/pl/plpython/meson.build
@@ -67,6 +67,7 @@ install_headers(
'plpy_typeio.h',
'plpy_util.h',
'plpython.h',
+ 'plpython_server.h',
install_dir: dir_include_server,
)
diff --git a/src/pl/plpython/plpython.h b/src/pl/plpython/plpython.h
index 91f6f8d8607..f33f7b59207 100644
--- a/src/pl/plpython/plpython.h
+++ b/src/pl/plpython/plpython.h
@@ -20,27 +20,10 @@
#endif
/*
- * Python versions <= 3.8 otherwise define a replacement, causing macro
- * redefinition warnings.
+ * Pull in Python headers via a wrapper header, to control the scope of
+ * the system_header pragma therein.
*/
-#define HAVE_SNPRINTF 1
-
-#if defined(_MSC_VER) && defined(_DEBUG)
-/* Python uses #pragma to bring in a non-default libpython on VC++ if
- * _DEBUG is defined */
-#undef _DEBUG
-/* Also hide away errcode, since we load Python.h before postgres.h */
-#define errcode __msvc_errcode
-#include <Python.h>
-#undef errcode
-#define _DEBUG
-#elif defined (_MSC_VER)
-#define errcode __msvc_errcode
-#include <Python.h>
-#undef errcode
-#else
-#include <Python.h>
-#endif
+#include "plpython_system.h"
/* define our text domain for translations */
#undef TEXTDOMAIN
diff --git a/src/pl/plpython/plpython_system.h b/src/pl/plpython/plpython_system.h
new file mode 100644
index 00000000000..9532789ae2f
--- /dev/null
+++ b/src/pl/plpython/plpython_system.h
@@ -0,0 +1,53 @@
+/*-------------------------------------------------------------------------
+ *
+ * plpython_system.h - pull in Python's system header files
+ *
+ * We break this out as a separate header file to precisely control
+ * the scope of the "system_header" pragma. No Postgres-specific
+ * declarations should be put here. However, we do include some stuff
+ * that is meant to prevent conflicts between our code and Python.
+ *
+ * Portions Copyright (c) 1996-2023, PostgreSQL Global Development Group
+ * Portions Copyright (c) 1994, Regents of the University of California
+ *
+ * src/pl/plpython/plpython_system.h
+ *
+ *-------------------------------------------------------------------------
+ */
+#ifndef PLPYTHON_SYSTEM_H
+#define PLPYTHON_SYSTEM_H
+
+/*
+ * Newer versions of the Python headers trigger a lot of warnings with our
+ * preferred compiler flags (at least -Wdeclaration-after-statement is known
+ * to be problematic). The system_header pragma hides warnings from within
+ * the rest of this file, if supported.
+ */
+#ifdef HAVE_PRAGMA_GCC_SYSTEM_HEADER
+#pragma GCC system_header
+#endif
+
+/*
+ * Python versions <= 3.8 otherwise define a replacement, causing macro
+ * redefinition warnings.
+ */
+#define HAVE_SNPRINTF 1
+
+#if defined(_MSC_VER) && defined(_DEBUG)
+/* Python uses #pragma to bring in a non-default libpython on VC++ if
+ * _DEBUG is defined */
+#undef _DEBUG
+/* Also hide away errcode, since we load Python.h before postgres.h */
+#define errcode __msvc_errcode
+#include <Python.h>
+#undef errcode
+#define _DEBUG
+#elif defined (_MSC_VER)
+#define errcode __msvc_errcode
+#include <Python.h>
+#undef errcode
+#else
+#include <Python.h>
+#endif
+
+#endif /* PLPYTHON_SYSTEM_H */