Skip to content

Commit 16901c0

Browse files
authored
bpo-44133: Skip PyThread_get_thread_native_id() if not available (GH-30636)
test_capi.test_export_symbols() doesn't check if Python exports the "PyThread_get_thread_native_id" symbol if the _thread.get_native_id() function is not available (if the PY_HAVE_THREAD_NATIVE_ID macro is not defined).
1 parent ad6e640 commit 16901c0

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

Lib/test/test_capi.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# these are all functions _testcapi exports whose name begins with 'test_'.
33

44
from collections import OrderedDict
5+
import _thread
56
import importlib.machinery
67
import importlib.util
78
import os
@@ -648,7 +649,11 @@ def test_export_symbols(self):
648649
# "PyThread_get_thread_native_id" symbols are exported by the Python
649650
# (directly by the binary, or via by the Python dynamic library).
650651
ctypes = import_helper.import_module('ctypes')
651-
names = ['PyThread_get_thread_native_id']
652+
names = []
653+
654+
# Test if the PY_HAVE_THREAD_NATIVE_ID macro is defined
655+
if hasattr(_thread, 'get_native_id'):
656+
names.append('PyThread_get_thread_native_id')
652657

653658
# Python/frozenmain.c fails to build on Windows when the symbols are
654659
# missing:
@@ -657,6 +662,7 @@ def test_export_symbols(self):
657662
# - PyInitFrozenExtensions
658663
if os.name != 'nt':
659664
names.append('Py_FrozenMain')
665+
660666
for name in names:
661667
with self.subTest(name=name):
662668
self.assertTrue(hasattr(ctypes.pythonapi, name))

0 commit comments

Comments
 (0)