Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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