Skip to content

Commit

Permalink
gh-91325: Skip Stable ABI checks with Py_TRACE_REFS special build (GH…
Browse files Browse the repository at this point in the history
…-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.
  • Loading branch information
encukou authored Jan 29, 2024
1 parent c87233f commit 15fe8ce
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 20 deletions.
36 changes: 25 additions & 11 deletions Lib/test/test_stable_abi_ctypes.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Misc/stable_abi.toml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@
[feature_macro.Py_REF_DEBUG]
doc = 'when Python is compiled in debug mode (with Py_REF_DEBUG)'
windows = 'maybe'
[feature_macro.Py_TRACE_REFS]
# nb. This mode is not compatible with Stable ABI/Limited API.
doc = 'when Python is compiled with Py_TRACE_REFS'
windows = 'maybe'


# Mentioned in PEP 384:
Expand Down
9 changes: 9 additions & 0 deletions Modules/_testcapi_feature_macros.inc
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@ if (res) {
Py_DECREF(result); return NULL;
}

#ifdef Py_TRACE_REFS
res = PyDict_SetItemString(result, "Py_TRACE_REFS", Py_True);
#else
res = PyDict_SetItemString(result, "Py_TRACE_REFS", Py_False);
#endif
if (res) {
Py_DECREF(result); return NULL;
}

#ifdef USE_STACKCHECK
res = PyDict_SetItemString(result, "USE_STACKCHECK", Py_True);
#else
Expand Down
19 changes: 10 additions & 9 deletions Tools/build/stable_abi.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,13 @@ def gen_ctypes_test(manifest, args, outfile):
from _testcapi import get_feature_macros
feature_macros = get_feature_macros()
# Stable ABI is incompatible with Py_TRACE_REFS builds due to PyObject
# layout differences.
# See https://github.com/python/cpython/issues/88299#issuecomment-1113366226
if feature_macros['Py_TRACE_REFS']:
raise unittest.SkipTest("incompatible with Py_TRACE_REFS.")
ctypes_test = import_module('ctypes')
class TestStableABIAvailability(unittest.TestCase):
Expand Down Expand Up @@ -308,16 +315,11 @@ def test_windows_feature_macros(self):
{'function', 'data'},
include_abi_only=True,
)
optional_items = {}
feature_macros = list(manifest.select({'feature_macro'}))
optional_items = {m.name: [] for m in feature_macros}
for item in items:
if item.name in (
# Some symbols aren't exported on all platforms.
# This is a bug: https://bugs.python.org/issue44133
'PyModule_Create2', 'PyModule_FromDefAndSpec2',
):
continue
if item.ifdef:
optional_items.setdefault(item.ifdef, []).append(item.name)
optional_items[item.ifdef].append(item.name)
else:
write(f' "{item.name}",')
write(")")
Expand All @@ -328,7 +330,6 @@ def test_windows_feature_macros(self):
write(f" {name!r},")
write(" )")
write("")
feature_macros = list(manifest.select({'feature_macro'}))
feature_names = sorted(m.name for m in feature_macros)
write(f"EXPECTED_FEATURE_MACROS = set({pprint.pformat(feature_names)})")

Expand Down

0 comments on commit 15fe8ce

Please sign in to comment.