[Python-checkins] gh-91719: Reload opcode on unknown error so that C can optimize the dispatching in ceval.c (#94364)

gvanrossum webhook-mailer at python.org
Thu Jun 30 11:38:50 EDT 2022


https://github.com/python/cpython/commit/ea39b77de9fa25b447d0b4148f75f351076e890a
commit: ea39b77de9fa25b447d0b4148f75f351076e890a
branch: main
author: neonene <53406459+neonene at users.noreply.github.com>
committer: gvanrossum <gvanrossum at gmail.com>
date: 2022-06-30T08:38:29-07:00
summary:

gh-91719: Reload opcode on unknown error so that C can optimize the dispatching in ceval.c (#94364)

files:
A Misc/NEWS.d/next/Core and Builtins/2022-06-29-22-18-36.gh-issue-91719.3APYYI.rst
M Python/ceval.c

diff --git a/Misc/NEWS.d/next/Core and Builtins/2022-06-29-22-18-36.gh-issue-91719.3APYYI.rst b/Misc/NEWS.d/next/Core and Builtins/2022-06-29-22-18-36.gh-issue-91719.3APYYI.rst
new file mode 100644
index 0000000000000..0d085e8877837
--- /dev/null
+++ b/Misc/NEWS.d/next/Core and Builtins/2022-06-29-22-18-36.gh-issue-91719.3APYYI.rst	
@@ -0,0 +1,2 @@
+Reload ``opcode`` when raising ``unknown opcode error`` in the interpreter main loop,
+for C compilers to generate dispatching code independently.
diff --git a/Python/ceval.c b/Python/ceval.c
index 946e997fc832d..4fcdf9b41dea9 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -5706,6 +5706,9 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
 #else
         EXTRA_CASES  // From opcode.h, a 'case' for each unused opcode
 #endif
+            /* Tell C compilers not to hold the opcode variable in the loop.
+               next_instr points the current instruction without TARGET(). */
+            opcode = _Py_OPCODE(*next_instr);
             fprintf(stderr, "XXX lineno: %d, opcode: %d\n",
                     _PyInterpreterFrame_GetLine(frame),  opcode);
             _PyErr_SetString(tstate, PyExc_SystemError, "unknown opcode");



More information about the Python-checkins mailing list