]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-91325: Skip Stable ABI checks with Py_TRACE_REFS special build (GH-92046)
authorPetr Viktorin <encukou@gmail.com>
Mon, 29 Jan 2024 15:45:31 +0000 (16:45 +0100)
committerGitHub <noreply@github.com>
Mon, 29 Jan 2024 15:45:31 +0000 (16:45 +0100)
Skip Stable ABI checks with Py_TRACE_REFS special build

This build is not compatible with Py_LIMITED_API nor with
the stable ABI.

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

index 4976ac3642bbe4664dc408f2c6c820cf0f512ccd..90d4527283842088caafe9a3ab99477a0f761a9a 100644 (file)
@@ -9,6 +9,13 @@ from test.support.import_helper import import_module
 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 @@ SYMBOL_NAMES = (
     "PyModule_AddObjectRef",
     "PyModule_AddStringConstant",
     "PyModule_AddType",
+    "PyModule_Create2",
     "PyModule_ExecDef",
+    "PyModule_FromDefAndSpec2",
     "PyModule_GetDef",
     "PyModule_GetDict",
     "PyModule_GetFilename",
@@ -911,6 +920,13 @@ SYMBOL_NAMES = (
     "_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 @@ if feature_macros['MS_WINDOWS']:
         '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 @@ if feature_macros['Py_REF_DEBUG']:
         '_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'}
index 22b25dd0ec141fdc60b6d905a974fbe2e55756e8..2e6b0fff9cd7704c3817c6132c33ef96af447b6a 100644 (file)
 [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:
index a076e7149800743a48a4c502b0d103df8d695838..f5f3524f2c0177fdf6204ffae1c0a71da35f3cea 100644 (file)
@@ -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
index 85c437d521a15ad293b97a64c7d1f6d66335ccf2..83146622c74f941b1cb825b5f743ab36c3c0fb53 100644 (file)
@@ -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 gen_ctypes_test(manifest, args, outfile):
         {'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 gen_ctypes_test(manifest, args, outfile):
             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)})")