Skip to content

Commit 0fa4e68

Browse files
committed
Skip Stable ABI checks with Py_TRACE_REFS special build
This build is not compatible with Py_LIMITED_API nor with the stable ABI.
1 parent 83bce8e commit 0fa4e68

4 files changed

Lines changed: 48 additions & 20 deletions

File tree

Lib/test/test_stable_abi_ctypes.py

Lines changed: 25 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Misc/stable_abi.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@
7171
[feature_macro.Py_REF_DEBUG]
7272
doc = 'when Python is compiled in debug mode (with Py_REF_DEBUG)'
7373
windows = 'maybe'
74+
[feature_macro.Py_TRACE_REFS]
75+
# nb. This mode is not compatible with Stable ABI/Limited API.
76+
doc = 'when Python is compiled with Py_TRACE_REFS'
77+
windows = 'maybe'
7478

7579

7680
# Mentioned in PEP 384:

Modules/_testcapi_feature_macros.inc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,15 @@ if (res) {
3838
Py_DECREF(result); return NULL;
3939
}
4040

41+
#ifdef Py_TRACE_REFS
42+
res = PyDict_SetItemString(result, "Py_TRACE_REFS", Py_True);
43+
#else
44+
res = PyDict_SetItemString(result, "Py_TRACE_REFS", Py_False);
45+
#endif
46+
if (res) {
47+
Py_DECREF(result); return NULL;
48+
}
49+
4150
#ifdef USE_STACKCHECK
4251
res = PyDict_SetItemString(result, "USE_STACKCHECK", Py_True);
4352
#else

Tools/scripts/stable_abi.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,13 @@ def gen_ctypes_test(manifest, args, outfile):
277277
from _testcapi import get_feature_macros
278278
279279
feature_macros = get_feature_macros()
280+
281+
# Stable ABI is incompatible with Py_TRACE_REFS builds due to PyObject
282+
# layout differences.
283+
# See https://github.com/python/cpython/issues/88299#issuecomment-1113366226
284+
if feature_macros['Py_TRACE_REFS']:
285+
raise unittest.SkipTest("incompatible with Py_TRACE_REFS.")
286+
280287
ctypes_test = import_module('ctypes')
281288
282289
class TestStableABIAvailability(unittest.TestCase):
@@ -307,16 +314,11 @@ def test_windows_feature_macros(self):
307314
{'function', 'data'},
308315
include_abi_only=True,
309316
)
310-
optional_items = {}
317+
feature_macros = list(manifest.select({'feature_macro'}))
318+
optional_items = {m.name: [] for m in feature_macros}
311319
for item in items:
312-
if item.name in (
313-
# Some symbols aren't exported on all platforms.
314-
# This is a bug: https://bugs.python.org/issue44133
315-
'PyModule_Create2', 'PyModule_FromDefAndSpec2',
316-
):
317-
continue
318320
if item.ifdef:
319-
optional_items.setdefault(item.ifdef, []).append(item.name)
321+
optional_items[item.ifdef].append(item.name)
320322
else:
321323
write(f' "{item.name}",')
322324
write(")")
@@ -327,7 +329,6 @@ def test_windows_feature_macros(self):
327329
write(f" {name!r},")
328330
write(" )")
329331
write("")
330-
feature_macros = list(manifest.select({'feature_macro'}))
331332
feature_names = sorted(m.name for m in feature_macros)
332333
write(f"EXPECTED_FEATURE_MACROS = set({pprint.pformat(feature_names)})")
333334

0 commit comments

Comments
 (0)