https://github.com/python/cpython/commit/15fe8cea174772060b24c96d335a498aba3b8ed4
commit: 15fe8cea174772060b24c96d335a498aba3b8ed4
branch: main
author: Petr Viktorin <[email protected]>
committer: encukou <[email protected]>
date: 2024-01-29T16:45:31+01:00
summary:

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.

files:
M Lib/test/test_stable_abi_ctypes.py
M Misc/stable_abi.toml
M Modules/_testcapi_feature_macros.inc
M Tools/build/stable_abi.py

diff --git a/Lib/test/test_stable_abi_ctypes.py 
b/Lib/test/test_stable_abi_ctypes.py
index 4976ac3642bbe4..90d45272838420 100644
--- a/Lib/test/test_stable_abi_ctypes.py
+++ b/Lib/test/test_stable_abi_ctypes.py
@@ -9,6 +9,13 @@
 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):
@@ -441,7 +448,9 @@ def test_windows_feature_macros(self):
     "PyModule_AddObjectRef",
     "PyModule_AddStringConstant",
     "PyModule_AddType",
+    "PyModule_Create2",
     "PyModule_ExecDef",
+    "PyModule_FromDefAndSpec2",
     "PyModule_GetDef",
     "PyModule_GetDict",
     "PyModule_GetFilename",
@@ -911,6 +920,13 @@ def test_windows_feature_macros(self):
     "_Py_TrueStruct",
     "_Py_VaBuildValue_SizeT",
 )
+if feature_macros['HAVE_FORK']:
+    SYMBOL_NAMES += (
+        'PyOS_AfterFork',
+        'PyOS_AfterFork_Child',
+        'PyOS_AfterFork_Parent',
+        'PyOS_BeforeFork',
+    )
 if feature_macros['MS_WINDOWS']:
     SYMBOL_NAMES += (
         'PyErr_SetExcFromWindowsErr',
@@ -926,17 +942,6 @@ def test_windows_feature_macros(self):
         'PyUnicode_DecodeMBCSStateful',
         'PyUnicode_EncodeCodePage',
     )
-if feature_macros['HAVE_FORK']:
-    SYMBOL_NAMES += (
-        'PyOS_AfterFork',
-        'PyOS_AfterFork_Child',
-        'PyOS_AfterFork_Parent',
-        'PyOS_BeforeFork',
-    )
-if feature_macros['USE_STACKCHECK']:
-    SYMBOL_NAMES += (
-        'PyOS_CheckStack',
-    )
 if feature_macros['PY_HAVE_THREAD_NATIVE_ID']:
     SYMBOL_NAMES += (
         'PyThread_get_thread_native_id',
@@ -946,14 +951,23 @@ def test_windows_feature_macros(self):
         '_Py_NegativeRefcount',
         '_Py_RefTotal',
     )
+if feature_macros['Py_TRACE_REFS']:
+    SYMBOL_NAMES += (
+    )
+if feature_macros['USE_STACKCHECK']:
+    SYMBOL_NAMES += (
+        'PyOS_CheckStack',
+    )
 
 EXPECTED_FEATURE_MACROS = set(['HAVE_FORK',
  'MS_WINDOWS',
  'PY_HAVE_THREAD_NATIVE_ID',
  'Py_REF_DEBUG',
+ 'Py_TRACE_REFS',
  'USE_STACKCHECK'])
 WINDOWS_FEATURE_MACROS = {'HAVE_FORK': False,
  'MS_WINDOWS': True,
  'PY_HAVE_THREAD_NATIVE_ID': True,
  'Py_REF_DEBUG': 'maybe',
+ 'Py_TRACE_REFS': 'maybe',
  'USE_STACKCHECK': 'maybe'}
diff --git a/Misc/stable_abi.toml b/Misc/stable_abi.toml
index 22b25dd0ec141f..2e6b0fff9cd770 100644
--- a/Misc/stable_abi.toml
+++ b/Misc/stable_abi.toml
@@ -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:
diff --git a/Modules/_testcapi_feature_macros.inc 
b/Modules/_testcapi_feature_macros.inc
index a076e714980074..f5f3524f2c0177 100644
--- a/Modules/_testcapi_feature_macros.inc
+++ b/Modules/_testcapi_feature_macros.inc
@@ -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
diff --git a/Tools/build/stable_abi.py b/Tools/build/stable_abi.py
index 85c437d521a15a..83146622c74f94 100644
--- a/Tools/build/stable_abi.py
+++ b/Tools/build/stable_abi.py
@@ -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):
@@ -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(")")
@@ -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)})")
 

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]

Reply via email to