]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-105481: the ENABLE_SPECIALIZATION flag does not need to be generated by the build...
authorIrit Katriel <1055913+iritkatriel@users.noreply.github.com>
Tue, 1 Aug 2023 17:05:00 +0000 (18:05 +0100)
committerGitHub <noreply@github.com>
Tue, 1 Aug 2023 17:05:00 +0000 (17:05 +0000)
Doc/whatsnew/3.13.rst
Include/internal/pycore_code.h
Include/opcode.h
Lib/opcode.py
Lib/test/support/__init__.py
Misc/NEWS.d/next/Library/2023-08-01-15-17-20.gh-issue-105481.vMbmj_.rst [new file with mode: 0644]
Modules/_opcode.c
Tools/build/generate_opcode_h.py

index 8fb4e6cfdf14c7fb1ef24c709460ccd95788c4ad..22c1e03470f5dc2b868c1f9c60db594cc034b662 100644 (file)
@@ -117,6 +117,13 @@ and only logged in :ref:`Python Development Mode <devmode>` or on :ref:`Python
 built on debug mode <debug-build>`.
 (Contributed by Victor Stinner in :gh:`62948`.)
 
+opcode
+------
+
+* Move ``opcode.ENABLE_SPECIALIZATION`` to ``_opcode.ENABLE_SPECIALIZATION``.
+  This field was added in 3.12, it was never documented and is not intended for
+  external usage. (Contributed by Irit Katriel in :gh:`105481`.)
+
 pathlib
 -------
 
index bcdf8645c8557c3089bbf69011e3c596219dc0f5..ee1b85187cbab64db2f7862da9d509e775374bbb 100644 (file)
@@ -229,6 +229,8 @@ extern void _PyLineTable_InitAddressRange(
 extern int _PyLineTable_NextAddressRange(PyCodeAddressRange *range);
 extern int _PyLineTable_PreviousAddressRange(PyCodeAddressRange *range);
 
+#define ENABLE_SPECIALIZATION 1
+
 /* Specialization functions */
 
 extern void _Py_Specialize_LoadSuperAttr(PyObject *global_super, PyObject *cls,
index 697520937d90557a633ca33707b680ad3779c463..eb4bb85e5b667df54bdf9963c3afdb3fdf3dc37e 100644 (file)
@@ -256,8 +256,6 @@ extern "C" {
 #define NB_INPLACE_TRUE_DIVIDE                  24
 #define NB_INPLACE_XOR                          25
 
-/* Defined in Lib/opcode.py */
-#define ENABLE_SPECIALIZATION 1
 
 #ifdef __cplusplus
 }
index bed922399821a63bc2115eef362272be87c3431c..51432ab1fab3f15e55b5b04177122afcb3e6b359 100644 (file)
@@ -19,9 +19,6 @@ if sys.version_info[:2] >= (3, 13):
 
 cmp_op = ('<', '<=', '==', '!=', '>', '>=')
 
-
-ENABLE_SPECIALIZATION = True
-
 def is_pseudo(op):
     return op >= MIN_PSEUDO_OPCODE and op <= MAX_PSEUDO_OPCODE
 
index 3b332f49951f0c86ab1afe602ba2f7debf0bce1b..2a59911e54d6b9ad419043718d645949e0a0f5ca 100644 (file)
@@ -6,7 +6,7 @@ if __name__ != 'test.support':
 import contextlib
 import functools
 import getpass
-import opcode
+import _opcode
 import os
 import re
 import stat
@@ -1092,7 +1092,7 @@ def requires_limited_api(test):
 
 def requires_specialization(test):
     return unittest.skipUnless(
-        opcode.ENABLE_SPECIALIZATION, "requires specialization")(test)
+        _opcode.ENABLE_SPECIALIZATION, "requires specialization")(test)
 
 def _filter_suite(suite, pred):
     """Recursively filter test cases in a suite based on a predicate."""
diff --git a/Misc/NEWS.d/next/Library/2023-08-01-15-17-20.gh-issue-105481.vMbmj_.rst b/Misc/NEWS.d/next/Library/2023-08-01-15-17-20.gh-issue-105481.vMbmj_.rst
new file mode 100644 (file)
index 0000000..153c18a
--- /dev/null
@@ -0,0 +1 @@
+:data:`opcode.ENABLE_SPECIALIZATION` (which was added in 3.12 but never documented or intended for external usage) is moved to :data:`_opcode.ENABLE_SPECIALIZATION` where tests can access it.
index b8d95a048ec2c6cacf8f5bc55b9e5f994235e9ad..ad0fa736f8276786773c2984455aaf05fd3aa0d5 100644 (file)
@@ -292,7 +292,16 @@ opcode_functions[] =  {
     {NULL, NULL, 0, NULL}
 };
 
+int
+_opcode_exec(PyObject *m) {
+    if (PyModule_AddIntMacro(m, ENABLE_SPECIALIZATION) < 0) {
+        return -1;
+    }
+    return 0;
+}
+
 static PyModuleDef_Slot module_slots[] = {
+    {Py_mod_exec, _opcode_exec},
     {Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
     {0, NULL}
 };
index 19e5eab822a235d1e3bec3bb27e611d24b581a33..2259dad77869f8f1b8d90254346cccdb26aee5b1 100644 (file)
@@ -73,7 +73,6 @@ def main(opcode_py,
     opname = opcode['opname']
     is_pseudo = opcode['is_pseudo']
 
-    ENABLE_SPECIALIZATION = opcode["ENABLE_SPECIALIZATION"]
     MIN_PSEUDO_OPCODE = opcode["MIN_PSEUDO_OPCODE"]
     MAX_PSEUDO_OPCODE = opcode["MAX_PSEUDO_OPCODE"]
     MIN_INSTRUMENTED_OPCODE = opcode["MIN_INSTRUMENTED_OPCODE"]
@@ -141,10 +140,6 @@ def main(opcode_py,
         for i, (op, _) in enumerate(opcode["_nb_ops"]):
             fobj.write(DEFINE.format(op, i))
 
-        fobj.write("\n")
-        fobj.write("/* Defined in Lib/opcode.py */\n")
-        fobj.write(f"#define ENABLE_SPECIALIZATION {int(ENABLE_SPECIALIZATION)}")
-
         iobj.write("\n")
         iobj.write(f"\nextern const char *const _PyOpcode_OpName[{NUM_OPCODES}];\n")
         iobj.write("\n#ifdef NEED_OPCODE_TABLES\n")