Skip to content

Commit ec07618

Browse files
authored
Treat warnings as errors on Windows (MSVC) (#117)
* Replace "CPP" with "CXX". * Test also C++14 on Windows. * GitHub Actions: upgrade Windows latest Python to 3.13.
1 parent 6d8c17a commit ec07618

File tree

4 files changed

+59
-45
lines changed

4 files changed

+59
-45
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ jobs:
5353
- os: windows-latest
5454
python: 3.6
5555
- os: windows-latest
56-
python: 3.12
56+
python: 3.13
5757

5858
# macOS: test only new Python
5959
- os: macos-latest

tests/setup.py

Lines changed: 39 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -13,38 +13,42 @@
1313

1414

1515
# C++ is only supported on Python 3.6 and newer
16-
TEST_CPP = (sys.version_info >= (3, 6))
16+
TEST_CXX = (sys.version_info >= (3, 6))
1717

1818
SRC_DIR = os.path.normpath(os.path.join(os.path.dirname(__file__), '..'))
1919

2020
# Windows uses MSVC compiler
2121
MSVC = (os.name == "nt")
2222

23-
# C compiler flags for GCC and clang
2423
COMMON_FLAGS = [
25-
# Treat warnings as error
26-
'-Werror',
27-
# Enable all warnings
28-
'-Wall', '-Wextra',
29-
# Extra warnings
30-
'-Wconversion',
31-
# /usr/lib64/pypy3.7/include/pyport.h:68:20: error: redefinition of typedef
32-
# 'Py_hash_t' is a C11 feature
33-
"-Wno-typedef-redefinition",
24+
'-I' + SRC_DIR,
3425
]
35-
CFLAGS = COMMON_FLAGS + [
36-
# Use C99 for pythoncapi_compat.c which initializes PyModuleDef with a
37-
# mixture of designated and non-designated initializers
38-
'-std=c99',
39-
]
40-
CPPFLAGS = list(COMMON_FLAGS)
41-
# FIXME: _Py_CAST() emits C++ compilers on Python 3.12.
42-
# See: https://github.com/python/cpython/issues/94731
43-
if 0:
44-
CPPFLAGS.extend((
45-
'-Wold-style-cast',
46-
'-Wzero-as-null-pointer-constant',
26+
if not MSVC:
27+
# C compiler flags for GCC and clang
28+
COMMON_FLAGS.extend((
29+
# Treat warnings as error
30+
'-Werror',
31+
# Enable all warnings
32+
'-Wall', '-Wextra',
33+
# Extra warnings
34+
'-Wconversion',
35+
# /usr/lib64/pypy3.7/include/pyport.h:68:20: error: redefinition of typedef
36+
# 'Py_hash_t' is a C11 feature
37+
"-Wno-typedef-redefinition",
38+
))
39+
CFLAGS = COMMON_FLAGS + [
40+
# Use C99 for pythoncapi_compat.c which initializes PyModuleDef with a
41+
# mixture of designated and non-designated initializers
42+
'-std=c99',
43+
]
44+
else:
45+
# C compiler flags for MSVC
46+
COMMON_FLAGS.extend((
47+
# Treat all compiler warnings as compiler errors
48+
'/WX',
4749
))
50+
CFLAGS = list(COMMON_FLAGS)
51+
CXXFLAGS = list(COMMON_FLAGS)
4852

4953

5054
def main():
@@ -66,34 +70,31 @@ def main():
6670
# CC env var overrides sysconfig CC variable in setuptools
6771
os.environ['CC'] = cmd
6872

69-
cflags = ['-I' + SRC_DIR]
70-
cppflags = list(cflags)
71-
if not MSVC:
72-
cflags.extend(CFLAGS)
73-
cppflags.extend(CPPFLAGS)
74-
7573
# C extension
7674
c_ext = Extension(
7775
'test_pythoncapi_compat_cext',
7876
sources=['test_pythoncapi_compat_cext.c'],
79-
extra_compile_args=cflags)
77+
extra_compile_args=CFLAGS)
8078
extensions = [c_ext]
8179

82-
if TEST_CPP:
80+
if TEST_CXX:
8381
# C++ extension
8482

8583
# MSVC has /std flag but doesn't support /std:c++11
8684
if not MSVC:
8785
versions = [
88-
('test_pythoncapi_compat_cpp03ext', '-std=c++03'),
89-
('test_pythoncapi_compat_cpp11ext', '-std=c++11'),
86+
('test_pythoncapi_compat_cpp03ext', ['-std=c++03']),
87+
('test_pythoncapi_compat_cpp11ext', ['-std=c++11']),
9088
]
9189
else:
92-
versions = [('test_pythoncapi_compat_cppext', None)]
93-
for name, flag in versions:
94-
flags = list(cppflags)
95-
if flag is not None:
96-
flags.append(flag)
90+
versions = [
91+
('test_pythoncapi_compat_cppext', None),
92+
('test_pythoncapi_compat_cpp14ext', ['/std:c++14', '/Zc:__cplusplus']),
93+
]
94+
for name, std_flags in versions:
95+
flags = list(CXXFLAGS)
96+
if std_flags is not None:
97+
flags.extend(std_flags)
9798
cpp_ext = Extension(
9899
name,
99100
sources=['test_pythoncapi_compat_cppext.cpp'],

tests/test_pythoncapi_compat.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,23 @@
2424
from utils import run_command, command_stdout
2525

2626

27+
# Windows uses MSVC compiler
28+
MSVC = (os.name == "nt")
29+
2730
TESTS = [
2831
("test_pythoncapi_compat_cext", "C"),
29-
("test_pythoncapi_compat_cppext", "C++"),
30-
("test_pythoncapi_compat_cpp03ext", "C++03"),
31-
("test_pythoncapi_compat_cpp11ext", "C++11"),
3232
]
33+
if not MSVC:
34+
TESTS.extend((
35+
("test_pythoncapi_compat_cpp03ext", "C++03"),
36+
("test_pythoncapi_compat_cpp11ext", "C++11"),
37+
))
38+
else:
39+
TESTS.extend((
40+
("test_pythoncapi_compat_cppext", "C++"),
41+
("test_pythoncapi_compat_cpp14ext", "C++14"),
42+
))
43+
3344

3445
VERBOSE = False
3546

tests/test_pythoncapi_compat_cext.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,14 @@
1515
# define PYTHON3 1
1616
#endif
1717

18-
#if defined(_MSC_VER) && defined(__cplusplus)
19-
# define MODULE_NAME test_pythoncapi_compat_cppext
18+
#if defined(__cplusplus) && __cplusplus >= 201402
19+
# define MODULE_NAME test_pythoncapi_compat_cpp14ext
2020
#elif defined(__cplusplus) && __cplusplus >= 201103
2121
# define MODULE_NAME test_pythoncapi_compat_cpp11ext
22-
#elif defined(__cplusplus)
22+
#elif defined(__cplusplus) && !defined(_MSC_VER)
2323
# define MODULE_NAME test_pythoncapi_compat_cpp03ext
24+
#elif defined(__cplusplus)
25+
# define MODULE_NAME test_pythoncapi_compat_cppext
2426
#else
2527
# define MODULE_NAME test_pythoncapi_compat_cext
2628
#endif

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy