8000 Fix panic and add test for it · python/cpython@88e2e59 · GitHub
[go: up one dir, main page]

Skip to content

Commit 88e2e59

Browse files
Fix panic and add test for it
1 parent 53ab262 commit 88e2e59

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

Lib/test/test_capi/test_opt.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1430,6 +1430,27 @@ class Foo:
14301430
Foo.attr = 0
14311431
self.assertFalse(ex.is_valid())
14321432

1433+
def test_type_version_doesnt_segfault(self):
1434+
"""
1435+
Tests that setting a type version doesn't cause a segfault when later looking at the stack.
1436+
"""
1437+
1438+
# Minimized from mdp.py benchmark
1439+
1440+
class A:
1441+
def __init__(self):
1442+
self.attr = {}
1443+
1444+
def method(self, arg):
1445+
self.attr[arg] = None
1446+
1447+
def fn(a):
1448+
for _ in range(100):
1449+
(_ for _ in [])
1450+
(_ for _ in [a.method(None)])
1451+
1452+
fn(A())
1453+
14331454

14341455
if __name__ == "__main__":
14351456
unittest.main()

Python/optimizer_bytecodes.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -588,7 +588,7 @@ dummy_func(void) {
588588
// Can determine statically, so we interleave the new locals
589589
// and make the current stack the new locals.
590590
// This also sets up for true call inlining.
591-
if (sym_is_null(self_or_null) || sym_is_not_null(self_or_null)) {
591+
if (sym_is_null(self_or_null)) {
592592
localsplus_start = args;
593593
n_locals_already_filled = argcount;
594594
}

Python/optimizer_cases.c.h

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)
0