Starting with Python 3.9, the Python headers contain inline functions that fall afoul of our -Wdeclaration-after-statement coding style. In order to silence those warnings, I've added some GCC-specific contortions to disable that warning for Python.h only. Clang doesn't appear to warn about this at all; maybe it recognizes that this is an external header file. We could also write a configure check for this if we want to be more flexible.

(Attempts to convince upstream to change the coding style were unsuccessful (https://bugs.python.org/issue39615).)

--
Peter Eisentraut              http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
From e63a5935b7059d70418b63bd4e4b7ccb487e2075 Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <pe...@eisentraut.org>
Date: Mon, 2 Mar 2020 09:11:05 +0100
Subject: [PATCH] Silence compiler warnings with Python 3.9

Starting with Python 3.9, the Python headers contain inline functions that
fall afoul of our -Wdeclaration-after-statement coding style, so add
some contortions to disable that warning for Python.h only.

Attempts to convince upstream to change the coding style were
unsuccessful (https://bugs.python.org/issue39615).
---
 src/pl/plpython/plpython.h | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/src/pl/plpython/plpython.h b/src/pl/plpython/plpython.h
index 6d981a0a06..7f2256e9e2 100644
--- a/src/pl/plpython/plpython.h
+++ b/src/pl/plpython/plpython.h
@@ -42,6 +42,21 @@
 #undef vprintf
 #undef printf
 
+/*
+ * Starting with Python 3.9, the Python headers contain inline functions that
+ * fall afoul of our -Wdeclaration-after-statement coding style, so we need to
+ * do a little dance here to disable that warning momentarily.
+ */
+
+#ifdef __GNUC__
+#define GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + 
__GNUC_PATCHLEVEL__)
+#endif
+
+#if defined(__GNUC__) && GCC_VERSION >= 40600
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wdeclaration-after-statement"
+#endif
+
 #if defined(_MSC_VER) && defined(_DEBUG)
 /* Python uses #pragma to bring in a non-default libpython on VC++ if
  * _DEBUG is defined */
@@ -59,6 +74,10 @@
 #include <Python.h>
 #endif
 
+#if defined(__GNUC__) && GCC_VERSION >= 40600
+#pragma GCC diagnostic pop
+#endif
+
 /*
  * Python 2/3 strings/unicode/bytes handling.  Python 2 has strings
  * and unicode, Python 3 has strings, which are unicode on the C
-- 
2.25.0

Reply via email to