Skip to content

Commit

Permalink
Fix code_richcompare not to change code object.
Browse files Browse the repository at this point in the history
  • Loading branch information
corona10 committed Aug 21, 2023
1 parent 9697196 commit 2197675
Showing 1 changed file with 18 additions and 15 deletions.
33 changes: 18 additions & 15 deletions Objects/codeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -1781,30 +1781,33 @@ code_richcompare(PyObject *self, PyObject *other, int op)
for (int i = 0; i < Py_SIZE(co); i++) {
_Py_CODEUNIT co_instr = _PyCode_CODE(co)[i];
_Py_CODEUNIT cp_instr = _PyCode_CODE(cp)[i];
uint8_t co_code = co_instr.op.code;
uint8_t co_arg = co_instr.op.arg;
uint8_t cp_code = cp_instr.op.code;
uint8_t cp_arg = cp_instr.op.arg;

if (co_instr.op.code == ENTER_EXECUTOR) {
const int exec_index = co_instr.op.arg;
if (co_code == ENTER_EXECUTOR) {
const int exec_index = co_arg;
_PyExecutorObject *exec = co->co_executors->executors[exec_index];
co_instr.op.code = exec->vm_data.opcode;
co_instr.op.arg = exec->vm_data.oparg;
co_code = exec->vm_data.opcode;
co_arg = exec->vm_data.oparg;
}
assert(co_instr.op.code != ENTER_EXECUTOR);
co_instr.op.code = _PyOpcode_Deopt[co_instr.op.code];
assert(co_code != ENTER_EXECUTOR);
co_code = _PyOpcode_Deopt[co_code];

if (cp_instr.op.code == ENTER_EXECUTOR) {
const int exec_index = cp_instr.op.arg;
if (cp_code == ENTER_EXECUTOR) {
const int exec_index = cp_arg;
_PyExecutorObject *exec = cp->co_executors->executors[exec_index];
cp_instr.op.code = exec->vm_data.opcode;
cp_instr.op.arg = exec->vm_data.oparg;
cp_code = exec->vm_data.opcode;
cp_arg = exec->vm_data.oparg;
}
assert(cp_instr.op.code != ENTER_EXECUTOR);
cp_instr.op.code = _PyOpcode_Deopt[cp_instr.op.code];
assert(cp_code != ENTER_EXECUTOR);
cp_code = _PyOpcode_Deopt[cp_code];

eq = co_instr.cache == cp_instr.cache;
if (!eq) {
if (co_code != cp_code || co_arg != cp_arg) {
goto unequal;
}
i += _PyOpcode_Caches[co_instr.op.code];
i += _PyOpcode_Caches[co_code];
}

/* compare constants */
Expand Down

0 comments on commit 2197675

Please sign in to comment.