Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 3eecdeb

Browse filesBrowse files
committed
Fix INSTRUMENT_FOR_ITER for list/tuple
1 parent f49a07b commit 3eecdeb
Copy full SHA for 3eecdeb

File tree

Expand file treeCollapse file tree

3 files changed

+18
-3
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+18
-3
lines changed

‎Lib/test/test_monitoring.py

Copy file name to clipboardExpand all lines: Lib/test/test_monitoring.py
+15Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2157,6 +2157,21 @@ def callback(code, instruction_offset):
21572157
sys.monitoring.restart_events()
21582158
sys.monitoring.set_events(0, 0)
21592159

2160+
def test_134879(self):
2161+
# gh-134789
2162+
# Specialized FOR_ITER not incrementing index
2163+
def foo():
2164+
t = 0
2165+
for i in [1,2,3,4]:
2166+
t += i
2167+
self.assertEqual(t, 10)
2168+
2169+
sys.monitoring.use_tool_id(0, "test")
2170+
self.addCleanup(sys.monitoring.free_tool_id, 0)
2171+
sys.monitoring.set_local_events(0, foo.__code__, E.BRANCH_LEFT | E.BRANCH_RIGHT)
2172+
foo()
2173+
sys.monitoring.set_local_events(0, foo.__code__, 0)
2174+
21602175

21612176
class TestOptimizer(MonitoringTestBase, unittest.TestCase):
21622177

‎Python/bytecodes.c

Copy file name to clipboardExpand all lines: Python/bytecodes.c
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3130,7 +3130,6 @@ dummy_func(
31303130
if (PyStackRef_IsTaggedInt(null_or_index)) {
31313131
next = _PyForIter_NextWithIndex(iter_o, null_or_index);
31323132
if (PyStackRef_IsNull(next)) {
3133-
null_or_index = PyStackRef_TagInt(-1);
31343133
JUMPBY(oparg + 1);
31353134
DISPATCH();
31363135
}
@@ -3191,6 +3190,7 @@ dummy_func(
31913190
JUMPBY(oparg + 1);
31923191
DISPATCH();
31933192
}
3193+
null_or_index = PyStackRef_IncrementTaggedIntNoOverflow(null_or_index);
31943194
INSTRUMENTED_JUMP(this_instr, next_instr, PY_MONITORING_EVENT_BRANCH_LEFT);
31953195
}
31963196
else {

‎Python/generated_cases.c.h

Copy file name to clipboardExpand all lines: Python/generated_cases.c.h
+2-2Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.