Skip to content

Commit 15fe8ce

Browse files
authored
gh-91325: Skip Stable ABI checks with Py_TRACE_REFS special build (GH-92046)
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 c87233f commit 15fe8ce

File tree

4 files changed

+48
-20
lines changed

4 files changed

+48
-20
lines changed

Lib/test/test_stable_abi_ctypes.py

+25-11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Misc/stable_abi.toml

+4
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@
7878
[feature_macro.Py_REF_DEBUG]
7979
doc = 'when Python is compiled in debug mode (with Py_REF_DEBUG)'
8080
windows = 'maybe'
81+
[feature_macro.Py_TRACE_REFS]
82+
# nb. This mode is not compatible with Stable ABI/Limited API.
83+
doc = 'when Python is compiled with Py_TRACE_REFS'
84+
windows = 'maybe'
8185

8286

8387
# Mentioned in PEP 384:

Modules/_testcapi_feature_macros.inc

+9
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/build/stable_abi.py

+10-9
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,13 @@ def gen_ctypes_test(manifest, args, outfile):
278278
from _testcapi import get_feature_macros
279279
280280
feature_macros = get_feature_macros()
281+
282+
# Stable ABI is incompatible with Py_TRACE_REFS builds due to PyObject
283+
# layout differences.
284+
# See https://github.com/python/cpython/issues/88299#issuecomment-1113366226
285+
if feature_macros['Py_TRACE_REFS']:
286+
raise unittest.SkipTest("incompatible with Py_TRACE_REFS.")
287+
281288
ctypes_test = import_module('ctypes')
282289
283290
class TestStableABIAvailability(unittest.TestCase):
@@ -308,16 +315,11 @@ def test_windows_feature_macros(self):
308315
{'function', 'data'},
309316
include_abi_only=True,
310317
)
311-
optional_items = {}
318+
feature_macros = list(manifest.select({'feature_macro'}))
319+
optional_items = {m.name: [] for m in feature_macros}
312320
for item in items:
313-
if item.name in (
314-
# Some symbols aren't exported on all platforms.
315-
# This is a bug: https://bugs.python.org/issue44133
316-
'PyModule_Create2', 'PyModule_FromDefAndSpec2',
317-
):
318-
continue
319321
if item.ifdef:
320-
optional_items.setdefault(item.ifdef, []).append(item.name)
322+
optional_items[item.ifdef].append(item.name)
321323
else:
322324
write(f' "{item.name}",')
323325
write(")")
@@ -328,7 +330,6 @@ def test_windows_feature_macros(self):
328330
write(f" {name!r},")
329331
write(" )")
330332
write("")
331-
feature_macros = list(manifest.select({'feature_macro'}))
332333
feature_names = sorted(m.name for m in feature_macros)
333334
write(f"EXPECTED_FEATURE_MACROS = set({pprint.pformat(feature_names)})")
334335

0 commit comments

Comments
 (0)