11# gh-91321: Build a basic C++ test extension to check that the Python C API is
22# compatible with C++ and does not emit C++ compiler warnings.
33import os .path
4+ import platform
45import shlex
56import shutil
67import subprocess
2829class BaseTests :
2930 TEST_INTERNAL_C_API = False
3031
31- def check_build (self , extension_name , std = None , limited = False ):
32+ def check_build (self , extension_name , std = None , limited = False ,
33+ extra_cflags = None ):
3234 venv_dir = 'env'
3335 with support .setup_venv_with_pip_setuptools (venv_dir ) as python_exe :
3436 self ._check_build (extension_name , python_exe ,
35- std = std , limited = limited )
37+ std = std , limited = limited ,
38+ extra_cflags = extra_cflags )
3639
37- def _check_build (self , extension_name , python_exe , std , limited ):
40+ def _check_build (self , extension_name , python_exe , std , limited ,
41+ extra_cflags = None ):
3842 pkg_dir = 'pkg'
3943 os .mkdir (pkg_dir )
4044 shutil .copy (SETUP , os .path .join (pkg_dir , os .path .basename (SETUP )))
@@ -48,6 +52,8 @@ def run_cmd(operation, cmd):
4852 env ['CPYTHON_TEST_LIMITED' ] = '1'
4953 env ['CPYTHON_TEST_EXT_NAME' ] = extension_name
5054 env ['TEST_INTERNAL_C_API' ] = str (int (self .TEST_INTERNAL_C_API ))
55+ if extra_cflags :
56+ env ['CPYTHON_TEST_EXTRA_CFLAGS' ] = extra_cflags
5157 if support .verbose :
5258 print ('Run:' , ' ' .join (map (shlex .quote , cmd )))
5359 subprocess .run (cmd , check = True , env = env )
@@ -116,6 +122,14 @@ def test_build_cpp11(self):
116122 def test_build_cpp14 (self ):
117123 self .check_build ('_testcpp14ext' , std = 'c++14' )
118124
125+ # Test that headers compile with Intel asm syntax, which may conflict
126+ # with inline assembly in free-threading headers that use AT&T syntax.
127+ @unittest .skipIf (support .MS_WINDOWS , "MSVC doesn't support -masm=intel" )
128+ @unittest .skipUnless (platform .machine () in ('x86_64' , 'i686' , 'AMD64' ),
129+ "x86-specific flag" )
130+ def test_build_intel_asm (self ):
131+ self .check_build ('_testcppext_asm' , extra_cflags = '-masm=intel' )
132+
119133
120134class TestInteralCAPI (BaseTests , unittest .TestCase ):
121135 TEST_INTERNAL_C_API = True
0 commit comments