summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorda-woods <dw-git@d-woods.co.uk>2021-08-07 09:08:42 +0100
committerGitHub <noreply@github.com>2021-08-07 10:08:42 +0200
commit563c261155f6ce787be80c68d6a3524393142589 (patch)
tree172cd6f358c4d32ab9bafd87397ed0b54bf3c16b
parent671da4001c8f41739c58ca84c8195d382ead9da9 (diff)
downloadcython-563c261155f6ce787be80c68d6a3524393142589.tar.gz
Suppress warnings about constant expressions on MSVC (GH-4317)
Adds utility code sections to toggle C compiler warnings for the duration of the utility code.
-rw-r--r--Cython/Compiler/Code.py14
-rw-r--r--Cython/Utility/ModuleSetupCode.c17
2 files changed, 31 insertions, 0 deletions
diff --git a/Cython/Compiler/Code.py b/Cython/Compiler/Code.py
index f02bbae27..a2affbe89 100644
--- a/Cython/Compiler/Code.py
+++ b/Cython/Compiler/Code.py
@@ -1143,7 +1143,9 @@ class GlobalState(object):
'cleanup_globals',
'cleanup_module',
'main_method',
+ 'utility_code_pragmas', # silence some irrelevant warnings in utility code
'utility_code_def',
+ 'utility_code_pragmas_end', # clean-up the utility_code_pragmas
'end'
]
@@ -1241,6 +1243,18 @@ class GlobalState(object):
code.put(util.format_code(util.impl))
code.putln("")
+ #
+ # utility code pragmas
+ #
+ code = self.parts['utility_code_pragmas']
+ util = UtilityCode.load_cached("UtilityCodePragmas", "ModuleSetupCode.c")
+ code.putln(util.format_code(util.impl))
+ code.putln("")
+ code = self.parts['utility_code_pragmas_end']
+ util = UtilityCode.load_cached("UtilityCodePragmasEnd", "ModuleSetupCode.c")
+ code.putln(util.format_code(util.impl))
+ code.putln("")
+
def __getitem__(self, key):
return self.parts[key]
diff --git a/Cython/Utility/ModuleSetupCode.c b/Cython/Utility/ModuleSetupCode.c
index 6c2141893..dcd081742 100644
--- a/Cython/Utility/ModuleSetupCode.c
+++ b/Cython/Utility/ModuleSetupCode.c
@@ -1796,3 +1796,20 @@ static void __Pyx_FastGilFuncInit(void) {
}
#endif
+
+///////////////////// UtilityCodePragmas /////////////////////////
+
+#if _MSC_VER
+#pragma warning( push )
+/* Warning 4127: conditional expression is constant
+ * Cython uses constant conditional expressions to allow in inline functions to be optimized at
+ * compile-time, so this warning is not useful
+ */
+#pragma warning( disable : 4127 )
+#endif
+
+///////////////////// UtilityCodePragmasEnd //////////////////////
+
+#if _MSV_VER
+#pragma warning( pop ) /* undo whatever Cython has done to warnings */
+#endif