Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitec07618

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 parent6d8c17a commitec07618

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-
if0:
44-
CPPFLAGS.extend((
45-
'-Wold-style-cast',
46-
'-Wzero-as-null-pointer-constant',
26+
ifnotMSVC:
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
defmain():
@@ -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-
ifnotMSVC:
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-
ifTEST_CPP:
80+
ifTEST_CXX:
8381
# C++ extension
8482

8583
# MSVC has /std flag but doesn't support /std:c++11
8684
ifnotMSVC:
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-
forname,flaginversions:
94-
flags=list(cppflags)
95-
ifflagisnotNone:
96-
flags.append(flag)
90+
versions= [
91+
('test_pythoncapi_compat_cppext',None),
92+
('test_pythoncapi_compat_cpp14ext', ['/std:c++14','/Zc:__cplusplus']),
93+
]
94+
forname,std_flagsinversions:
95+
flags=list(CXXFLAGS)
96+
ifstd_flagsisnotNone:
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
fromutilsimportrun_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+
ifnotMSVC:
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
# definePYTHON3 1
1616
#endif
1717

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

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp