]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.13] gh-127906: Backport test_cext changes from the main branch (#127923)
authorVictor Stinner <vstinner@python.org>
Fri, 13 Dec 2024 15:04:08 +0000 (16:04 +0100)
committerGitHub <noreply@github.com>
Fri, 13 Dec 2024 15:04:08 +0000 (15:04 +0000)
Lib/test/test_cext/__init__.py
Lib/test/test_cext/extension.c
Lib/test/test_cext/setup.py

index ec44b0ce1f8a56f7b8b3964bdf1423fdcf6347ce..54859f9ff7622d13986d3cd86ede568a2b55b3fe 100644 (file)
@@ -86,6 +86,8 @@ class TestExt(unittest.TestCase):
         cmd = [python_exe, '-X', 'dev',
                '-m', 'pip', 'install', '--no-build-isolation',
                os.path.abspath(pkg_dir)]
+        if support.verbose:
+            cmd.append('-v')
         run_cmd('Install', cmd)
 
         # Do a reference run. Until we test that running python
index eb23dbe20353bae467acf2c64cc95df95e6c69cb..b76abe1d74c628584a827f1a1c113b6527d7b773 100644 (file)
@@ -37,7 +37,13 @@ static PyMethodDef _testcext_methods[] = {
 
 
 static int
-_testcext_exec(PyObject *module)
+_testcext_exec(
+#ifdef __STDC_VERSION__
+    PyObject *module
+#else
+    PyObject *Py_UNUSED(module)
+#endif
+    )
 {
 #ifdef __STDC_VERSION__
     if (PyModule_AddIntMacro(module, __STDC_VERSION__) < 0) {
@@ -53,7 +59,7 @@ _testcext_exec(PyObject *module)
 }
 
 static PyModuleDef_Slot _testcext_slots[] = {
-    {Py_mod_exec, _testcext_exec},
+    {Py_mod_exec, (void*)_testcext_exec},
     {0, NULL}
 };
 
index ccad3fa62ad08676c2887aee16f6723c172a3f7d..e97749b45ea6f31d20ec3eec10a112b61eb99d04 100644 (file)
@@ -11,12 +11,16 @@ from setuptools import setup, Extension
 
 
 SOURCE = 'extension.c'
+
 if not support.MS_WINDOWS:
     # C compiler flags for GCC and clang
     CFLAGS = [
         # The purpose of test_cext extension is to check that building a C
         # extension using the Python C API does not emit C compiler warnings.
         '-Werror',
+
+        # gh-120593: Check the 'const' qualifier
+        '-Wcast-qual',
     ]
     if not support.Py_GIL_DISABLED:
         CFLAGS.append(
@@ -25,8 +29,13 @@ if not support.MS_WINDOWS:
             '-Werror=declaration-after-statement',
         )
 else:
-    # Don't pass any compiler flag to MSVC
-    CFLAGS = []
+    # MSVC compiler flags
+    CFLAGS = [
+        # Display warnings level 1 to 4
+        '/W4',
+        # Treat all compiler warnings as compiler errors
+        '/WX',
+    ]
 
 
 def main():