#elif defined(__MINGW32__) && defined(_M_ARM64)
tid = __getReg(18);
#elif defined(__i386__)
- __asm__("movl %%gs:0, %0" : "=r" (tid)); // 32-bit always uses GS
+ __asm__("{movl %%gs:0, %0|mov %0, dword ptr gs:[0]}" : "=r" (tid)); // 32-bit always uses GS
#elif defined(__MACH__) && defined(__x86_64__)
- __asm__("movq %%gs:0, %0" : "=r" (tid)); // x86_64 macOSX uses GS
+ __asm__("{movq %%gs:0, %0|mov %0, qword ptr gs:[0]}" : "=r" (tid)); // x86_64 macOSX uses GS
#elif defined(__x86_64__)
- __asm__("movq %%fs:0, %0" : "=r" (tid)); // x86_64 Linux, BSD uses FS
+ __asm__("{movq %%fs:0, %0|mov %0, qword ptr fs:[0]}" : "=r" (tid)); // x86_64 Linux, BSD uses FS
#elif defined(__arm__) && __ARM_ARCH >= 7
__asm__ ("mrc p15, 0, %0, c13, c0, 3\nbic %0, %0, #3" : "=r" (tid));
#elif defined(__aarch64__) && defined(__APPLE__)
# gh-91321: Build a basic C++ test extension to check that the Python C API is
# compatible with C++ and does not emit C++ compiler warnings.
import os.path
+import platform
import shlex
import shutil
import subprocess
class BaseTests:
TEST_INTERNAL_C_API = False
- def check_build(self, extension_name, std=None, limited=False):
+ def check_build(self, extension_name, std=None, limited=False,
+ extra_cflags=None):
venv_dir = 'env'
with support.setup_venv_with_pip_setuptools(venv_dir) as python_exe:
self._check_build(extension_name, python_exe,
- std=std, limited=limited)
+ std=std, limited=limited,
+ extra_cflags=extra_cflags)
- def _check_build(self, extension_name, python_exe, std, limited):
+ def _check_build(self, extension_name, python_exe, std, limited,
+ extra_cflags=None):
pkg_dir = 'pkg'
os.mkdir(pkg_dir)
shutil.copy(SETUP, os.path.join(pkg_dir, os.path.basename(SETUP)))
env['CPYTHON_TEST_LIMITED'] = '1'
env['CPYTHON_TEST_EXT_NAME'] = extension_name
env['TEST_INTERNAL_C_API'] = str(int(self.TEST_INTERNAL_C_API))
+ if extra_cflags:
+ env['CPYTHON_TEST_EXTRA_CFLAGS'] = extra_cflags
if support.verbose:
print('Run:', ' '.join(map(shlex.quote, cmd)))
subprocess.run(cmd, check=True, env=env)
def test_build_cpp14(self):
self.check_build('_testcpp14ext', std='c++14')
+ # Test that headers compile with Intel asm syntax, which may conflict
+ # with inline assembly in free-threading headers that use AT&T syntax.
+ @unittest.skipIf(support.MS_WINDOWS, "MSVC doesn't support -masm=intel")
+ @unittest.skipUnless(platform.machine() in ('x86_64', 'i686', 'AMD64'),
+ "x86-specific flag")
+ def test_build_intel_asm(self):
+ self.check_build('_testcppext_asm', extra_cflags='-masm=intel')
+
class TestInteralCAPI(BaseTests, unittest.TestCase):
TEST_INTERNAL_C_API = True