Skip to content

Commit 6ef8f8c

Browse files
authored
gh-105481: the ENABLE_SPECIALIZATION flag does not need to be generated by the build script, or exposed in opcode.py (#107534)
1 parent 49f238e commit 6ef8f8c

File tree

8 files changed

+21
-12
lines changed

8 files changed

+21
-12
lines changed

Doc/whatsnew/3.13.rst

+7
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,13 @@ and only logged in :ref:`Python Development Mode <devmode>` or on :ref:`Python
117117
built on debug mode <debug-build>`.
118118
(Contributed by Victor Stinner in :gh:`62948`.)
119119

120+
opcode
121+
------
122+
123+
* Move ``opcode.ENABLE_SPECIALIZATION`` to ``_opcode.ENABLE_SPECIALIZATION``.
124+
This field was added in 3.12, it was never documented and is not intended for
125+
external usage. (Contributed by Irit Katriel in :gh:`105481`.)
126+
120127
pathlib
121128
-------
122129

Include/internal/pycore_code.h

+2
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,8 @@ extern void _PyLineTable_InitAddressRange(
229229
extern int _PyLineTable_NextAddressRange(PyCodeAddressRange *range);
230230
extern int _PyLineTable_PreviousAddressRange(PyCodeAddressRange *range);
231231

232+
#define ENABLE_SPECIALIZATION 1
233+
232234
/* Specialization functions */
233235

234236
extern void _Py_Specialize_LoadSuperAttr(PyObject *global_super, PyObject *cls,

Include/opcode.h

-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Lib/opcode.py

-3
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@
1919

2020
cmp_op = ('<', '<=', '==', '!=', '>', '>=')
2121

22-
23-
ENABLE_SPECIALIZATION = True
24-
2522
def is_pseudo(op):
2623
return op >= MIN_PSEUDO_OPCODE and op <= MAX_PSEUDO_OPCODE
2724

Lib/test/support/__init__.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import contextlib
77
import functools
88
import getpass
9-
import opcode
9+
import _opcode
1010
import os
1111
import re
1212
import stat
@@ -1092,7 +1092,7 @@ def requires_limited_api(test):
10921092

10931093
def requires_specialization(test):
10941094
return unittest.skipUnless(
1095-
opcode.ENABLE_SPECIALIZATION, "requires specialization")(test)
1095+
_opcode.ENABLE_SPECIALIZATION, "requires specialization")(test)
10961096

10971097
def _filter_suite(suite, pred):
10981098
"""Recursively filter test cases in a suite based on a predicate."""
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
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.

Modules/_opcode.c

+9
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,16 @@ opcode_functions[] = {
292292
{NULL, NULL, 0, NULL}
293293
};
294294

295+
int
296+
_opcode_exec(PyObject *m) {
297+
if (PyModule_AddIntMacro(m, ENABLE_SPECIALIZATION) < 0) {
298+
return -1;
299+
}
300+
return 0;
301+
}
302+
295303
static PyModuleDef_Slot module_slots[] = {
304+
{Py_mod_exec, _opcode_exec},
296305
{Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
297306
{0, NULL}
298307
};

Tools/build/generate_opcode_h.py

-5
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ def main(opcode_py,
7373
opname = opcode['opname']
7474
is_pseudo = opcode['is_pseudo']
7575

76-
ENABLE_SPECIALIZATION = opcode["ENABLE_SPECIALIZATION"]
7776
MIN_PSEUDO_OPCODE = opcode["MIN_PSEUDO_OPCODE"]
7877
MAX_PSEUDO_OPCODE = opcode["MAX_PSEUDO_OPCODE"]
7978
MIN_INSTRUMENTED_OPCODE = opcode["MIN_INSTRUMENTED_OPCODE"]
@@ -141,10 +140,6 @@ def main(opcode_py,
141140
for i, (op, _) in enumerate(opcode["_nb_ops"]):
142141
fobj.write(DEFINE.format(op, i))
143142

144-
fobj.write("\n")
145-
fobj.write("/* Defined in Lib/opcode.py */\n")
146-
fobj.write(f"#define ENABLE_SPECIALIZATION {int(ENABLE_SPECIALIZATION)}")
147-
148143
iobj.write("\n")
149144
iobj.write(f"\nextern const char *const _PyOpcode_OpName[{NUM_OPCODES}];\n")
150145
iobj.write("\n#ifdef NEED_OPCODE_TABLES\n")

0 commit comments

Comments
 (0)