13
13
14
14
15
15
# 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 ))
17
17
18
18
SRC_DIR = os .path .normpath (os .path .join (os .path .dirname (__file__ ),'..' ))
19
19
20
20
# Windows uses MSVC compiler
21
21
MSVC = (os .name == "nt" )
22
22
23
- # C compiler flags for GCC and clang
24
- 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" ,
34
- ]
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' ,
47
- ))
23
+ if not MSVC :
24
+ # C compiler flags for GCC and clang
25
+ COMMON_FLAGS = [
26
+ # Treat warnings as error
27
+ '-Werror' ,
28
+ # Enable all warnings
29
+ '-Wall' ,'-Wextra' ,
30
+ # Extra warnings
31
+ '-Wconversion' ,
32
+ # /usr/lib64/pypy3.7/include/pyport.h:68:20: error: redefinition of typedef
33
+ # 'Py_hash_t' is a C11 feature
34
+ "-Wno-typedef-redefinition" ,
35
+ ]
36
+ CFLAGS = COMMON_FLAGS + [
37
+ # Use C99 for pythoncapi_compat.c which initializes PyModuleDef with a
38
+ # mixture of designated and non-designated initializers
39
+ '-std=c99' ,
40
+ ]
41
+ CXXFLAGS = list (COMMON_FLAGS )
42
+ # FIXME: _Py_CAST() emits C++ compilers on Python 3.12.
43
+ # See: https://github.com/python/cpython/issues/94731
44
+ if 0 :
45
+ CXXFLAGS .extend ((
46
+ '-Wold-style-cast' ,
47
+ '-Wzero-as-null-pointer-constant' ,
48
+ ))
49
+ else :
50
+ COMMON_FLAGS = [
51
+ # Treat all compiler warnings as compiler errors
52
+ '/WX' ,
53
+ ]
54
+ if sys .version_info >= (3 ,13 ):
55
+ COMMON_FLAGS .append (
56
+ # Display warnings level 1 to 4
57
+ '/W4'
58
+ )
59
+ CFLAGS = COMMON_FLAGS + [
60
+ '/std:c99'
61
+ ]
62
+ CXXFLAGS = list (COMMON_FLAGS )
48
63
49
64
50
65
def main ():
@@ -68,9 +83,8 @@ def main():
68
83
69
84
cflags = ['-I' + SRC_DIR ]
70
85
cppflags = list (cflags )
71
- if not MSVC :
72
- cflags .extend (CFLAGS )
73
- cppflags .extend (CPPFLAGS )
86
+ cflags .extend (CFLAGS )
87
+ cppflags .extend (CXXFLAGS )
74
88
75
89
# C extension
76
90
c_ext = Extension (
@@ -79,7 +93,7 @@ def main():
79
93
extra_compile_args = cflags )
80
94
extensions = [c_ext ]
81
95
82
- if TEST_CPP :
96
+ if TEST_CXX :
83
97
# C++ extension
84
98
85
99
# MSVC has /std flag but doesn't support /std:c++11
@@ -89,7 +103,10 @@ def main():
89
103
('test_pythoncapi_compat_cpp11ext' ,'-std=c++11' ),
90
104
]
91
105
else :
92
- versions = [('test_pythoncapi_compat_cppext' ,None )]
106
+ versions = [
107
+ ('test_pythoncapi_compat_cpp03ext' ,'/std:c++03' ),
108
+ ('test_pythoncapi_compat_cpp11ext' ,'/std:c++11' ),
109
+ ]
93
110
for name ,flag in versions :
94
111
flags = list (cppflags )
95
112
if flag is not None :