Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit fb0ab4e

Browse files
committed
Add test and compare oparg too
1 parent 25d3f5b commit fb0ab4e

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

Lib/test/test_capi/test_misc.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2341,6 +2341,17 @@ def long_loop():
23412341
long_loop()
23422342
self.assertEqual(opt.get_count(), 10)
23432343

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+
23442355

23452356
def get_first_executor(func):
23462357
code = func.__code__

Objects/codeobject.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1786,6 +1786,7 @@ code_richcompare(PyObject *self, PyObject *other, int op)
17861786
const int exec_index = co_instr.op.arg;
17871787
_PyExecutorObject *exec = co->co_executors->executors[exec_index];
17881788
co_instr.op.code = exec->vm_data.opcode;
1789+
co_instr.op.arg = exec->vm_data.oparg;
17891790
}
17901791
assert(co_instr.op.code != ENTER_EXECUTOR);
17911792
co_instr.op.code = _PyOpcode_Deopt[co_instr.op.code];
@@ -1794,6 +1795,7 @@ code_richcompare(PyObject *self, PyObject *other, int op)
17941795
const int exec_index = cp_instr.op.arg;
17951796
_PyExecutorObject *exec = cp->co_executors->executors[exec_index];
17961797
cp_instr.op.code = exec->vm_data.opcode;
1798+
cp_instr.op.arg = exec->vm_data.oparg;
17971799
}
17981800
assert(cp_instr.op.code != ENTER_EXECUTOR);
17991801
cp_instr.op.code = _PyOpcode_Deopt[cp_instr.op.code];

0 commit comments

Comments
 (0)