There was an error while loading. Please reload this page.
1 parent 04f7875 commit 4fdf3fdCopy full SHA for 4fdf3fd
2 files changed
Lib/test/test_capi/test_misc.py
@@ -2341,6 +2341,17 @@ def long_loop():
2341
long_loop()
2342
self.assertEqual(opt.get_count(), 10)
2343
2344
+ def test_code_richcompare(self):
2345
+ def testfunc(x):
2346
+ i = 0
2347
+ while i < x:
2348
+ i += 1
2349
+
2350
+ opt = _testinternalcapi.get_counter_optimizer()
2351
+ with temporary_optimizer(opt):
2352
+ testfunc(1000)
2353
+ self.assertEqual(testfunc.__code__, testfunc.__code__.replace())
2354
2355
2356
def get_first_executor(func):
2357
code = func.__code__
Objects/codeobject.c
@@ -1781,8 +1781,25 @@ code_richcompare(PyObject *self, PyObject *other, int op)
1781
for (int i = 0; i < Py_SIZE(co); i++) {
1782
_Py_CODEUNIT co_instr = _PyCode_CODE(co)[i];
1783
_Py_CODEUNIT cp_instr = _PyCode_CODE(cp)[i];
1784
1785
+ if (co_instr.op.code == ENTER_EXECUTOR) {
1786
+ const int exec_index = co_instr.op.arg;
1787
+ _PyExecutorObject *exec = co->co_executors->executors[exec_index];
1788
+ co_instr.op.code = exec->vm_data.opcode;
1789
+ co_instr.op.arg = exec->vm_data.oparg;
1790
+ }
1791
+ assert(co_instr.op.code != ENTER_EXECUTOR);
1792
co_instr.op.code = _PyOpcode_Deopt[co_instr.op.code];
1793
1794
+ if (cp_instr.op.code == ENTER_EXECUTOR) {
1795
+ const int exec_index = cp_instr.op.arg;
1796
+ _PyExecutorObject *exec = cp->co_executors->executors[exec_index];
1797
+ cp_instr.op.code = exec->vm_data.opcode;
1798
+ cp_instr.op.arg = exec->vm_data.oparg;
1799
1800
+ assert(cp_instr.op.code != ENTER_EXECUTOR);
1801
cp_instr.op.code = _PyOpcode_Deopt[cp_instr.op.code];
1802
1803
eq = co_instr.cache == cp_instr.cache;
1804
if (!eq) {
1805
goto unequal;
0 commit comments