Skip to content

Commit

Permalink
[3.13] gh-127906: Backport test_cext changes from the main branch (#1…
Browse files Browse the repository at this point in the history
  • Loading branch information
vstinner authored Dec 13, 2024
1 parent 78095c9 commit 2996a2b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
2 changes: 2 additions & 0 deletions Lib/test/test_cext/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ def run_cmd(operation, cmd):
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
Expand Down
10 changes: 8 additions & 2 deletions Lib/test/test_cext/extension.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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}
};

Expand Down
13 changes: 11 additions & 2 deletions Lib/test/test_cext/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,16 @@


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(
Expand All @@ -25,8 +29,13 @@
'-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():
Expand Down

0 comments on commit 2996a2b

Please sign in to comment.