summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorBrandt Bucher <brandtbucher@microsoft.com>2022-07-22 18:04:20 (GMT)
committerGitHub <noreply@github.com>2022-07-22 18:04:20 (GMT)
commite402b26b7fb953a2f0c17a0044bb6d6cbd726e54 (patch)
treeb0b4dc8fd76d64028e0018066de86900949364e4 /Python
parent79d2f549adcbbefd4f2c0a0c9dd572bbbf252c62 (diff)
downloadcpython-e402b26b7fb953a2f0c17a0044bb6d6cbd726e54.zip
cpython-e402b26b7fb953a2f0c17a0044bb6d6cbd726e54.tar.gz
cpython-e402b26b7fb953a2f0c17a0044bb6d6cbd726e54.tar.bz2
GH-95113: Don't use EXTENDED_ARG_QUICK in unquickened code (GH-95121)
Diffstat (limited to 'Python')
-rw-r--r--Python/ceval.c8
-rw-r--r--Python/compile.c6
-rw-r--r--Python/specialize.c3
3 files changed, 14 insertions, 3 deletions
diff --git a/Python/ceval.c b/Python/ceval.c
index 88d13c8..3a9b0e5 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -5631,8 +5631,16 @@ handle_eval_breaker:
assert(oparg);
oparg <<= 8;
oparg |= _Py_OPARG(*next_instr);
+ // We might be tracing. To avoid breaking tracing guarantees in
+ // quickened instructions, always deoptimize the next opcode:
opcode = _PyOpcode_Deopt[_Py_OPCODE(*next_instr)];
PRE_DISPATCH_GOTO();
+ // CPython hasn't traced the following instruction historically
+ // (DO_TRACING would clobber our extended oparg anyways), so just
+ // skip our usual cframe.use_tracing check before dispatch. Also,
+ // make sure the next instruction isn't a RESUME, since that needs
+ // to trace properly (and shouldn't have an extended arg anyways):
+ assert(opcode != RESUME);
DISPATCH_GOTO();
}
diff --git a/Python/compile.c b/Python/compile.c
index 52b7d92..9db61fb 100644
--- a/Python/compile.c
+++ b/Python/compile.c
@@ -211,13 +211,13 @@ write_instr(_Py_CODEUNIT *codestr, struct instr *instruction, int ilen)
int caches = _PyOpcode_Caches[opcode];
switch (ilen - caches) {
case 4:
- *codestr++ = _Py_MAKECODEUNIT(EXTENDED_ARG_QUICK, (oparg >> 24) & 0xFF);
+ *codestr++ = _Py_MAKECODEUNIT(EXTENDED_ARG, (oparg >> 24) & 0xFF);
/* fall through */
case 3:
- *codestr++ = _Py_MAKECODEUNIT(EXTENDED_ARG_QUICK, (oparg >> 16) & 0xFF);
+ *codestr++ = _Py_MAKECODEUNIT(EXTENDED_ARG, (oparg >> 16) & 0xFF);
/* fall through */
case 2:
- *codestr++ = _Py_MAKECODEUNIT(EXTENDED_ARG_QUICK, (oparg >> 8) & 0xFF);
+ *codestr++ = _Py_MAKECODEUNIT(EXTENDED_ARG, (oparg >> 8) & 0xFF);
/* fall through */
case 1:
*codestr++ = _Py_MAKECODEUNIT(opcode, oparg & 0xFF);
diff --git a/Python/specialize.c b/Python/specialize.c
index 6f1f3cb..53b2ae8 100644
--- a/Python/specialize.c
+++ b/Python/specialize.c
@@ -295,6 +295,9 @@ _PyCode_Quicken(PyCodeObject *code)
else {
assert(!_PyOpcode_Caches[opcode]);
switch (opcode) {
+ case EXTENDED_ARG:
+ _Py_SET_OPCODE(instructions[i], EXTENDED_ARG_QUICK);
+ break;
case JUMP_BACKWARD:
_Py_SET_OPCODE(instructions[i], JUMP_BACKWARD_QUICK);
break;