GH-100222: Redefine _Py_CODEUNIT as a union to clarify structure of code unit. (GH-100223)

This commit is contained in:
Mark Shannon 2022-12-14 11:12:53 +00:00 committed by GitHub
parent 985a71032b
commit 6997e77bdf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 150 additions and 134 deletions

View file

@ -1520,9 +1520,10 @@ deopt_code(_Py_CODEUNIT *instructions, Py_ssize_t len)
_Py_CODEUNIT instruction = instructions[i];
int opcode = _PyOpcode_Deopt[_Py_OPCODE(instruction)];
int caches = _PyOpcode_Caches[opcode];
instructions[i] = _Py_MAKECODEUNIT(opcode, _Py_OPARG(instruction));
instructions[i].opcode = opcode;
while (caches--) {
instructions[++i] = _Py_MAKECODEUNIT(CACHE, 0);
instructions[++i].opcode = CACHE;
instructions[i].oparg = 0;
}
}
}
@ -1775,9 +1776,9 @@ 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];
_Py_SET_OPCODE(co_instr, _PyOpcode_Deopt[_Py_OPCODE(co_instr)]);
_Py_SET_OPCODE(cp_instr, _PyOpcode_Deopt[_Py_OPCODE(cp_instr)]);
eq = co_instr == cp_instr;
co_instr.opcode = _PyOpcode_Deopt[_Py_OPCODE(co_instr)];
cp_instr.opcode =_PyOpcode_Deopt[_Py_OPCODE(cp_instr)];
eq = co_instr.cache == cp_instr.cache;
if (!eq) {
goto unequal;
}