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
1818SRC_DIR = os .path .normpath (os .path .join (os .path .dirname (__file__ ), '..' ))
1919
2020# Windows uses MSVC compiler
2121MSVC = (os .name == "nt" )
2222
23- # C compiler flags for GCC and clang
2423COMMON_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
5054def 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' ],
0 commit comments