Skip to content

Commit 9afe052

Browse files
committed
Fix cases_generator bug
Macros should be treated as terminators when searching for the assignment target of an expression involving PyStackRef_FromPyObjectNew
1 parent 96be738 commit 9afe052

File tree

5 files changed

+40
-9
lines changed

5 files changed

+40
-9
lines changed

Lib/test/test_generated_cases.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1639,6 +1639,41 @@ def test_escaping_call_next_to_cmacro(self):
16391639
"""
16401640
self.run_cases_test(input, output)
16411641

1642+
def test_pystackref_frompyobject_new_next_to_cmacro(self):
1643+
input = """
1644+
inst(OP, (-- out1, out2)) {
1645+
PyObject *obj = SPAM();
1646+
#ifdef Py_GIL_DISABLED
1647+
out1 = PyStackRef_FromPyObjectNew(obj);
1648+
#else
1649+
out1 = PyStackRef_FromPyObjectNew(obj);
1650+
#endif
1651+
out2 = PyStackRef_FromPyObjectNew(obj);
1652+
}
1653+
"""
1654+
output = """
1655+
TARGET(OP) {
1656+
frame->instr_ptr = next_instr;
1657+
next_instr += 1;
1658+
INSTRUCTION_STATS(OP);
1659+
_PyStackRef out1;
1660+
_PyStackRef out2;
1661+
PyObject *obj = SPAM();
1662+
#ifdef Py_GIL_DISABLED
1663+
out1 = PyStackRef_FromPyObjectNew(obj);
1664+
#else
1665+
out1 = PyStackRef_FromPyObjectNew(obj);
1666+
#endif
1667+
out2 = PyStackRef_FromPyObjectNew(obj);
1668+
stack_pointer[0] = out1;
1669+
stack_pointer[1] = out2;
1670+
stack_pointer += 2;
1671+
assert(WITHIN_STACK_BOUNDS());
1672+
DISPATCH();
1673+
}
1674+
"""
1675+
self.run_cases_test(input, output)
1676+
16421677
def test_pop_dead_inputs_all_live(self):
16431678
input = """
16441679
inst(OP, (a, b --)) {

Python/bytecodes.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2149,8 +2149,7 @@ dummy_func(
21492149
DEOPT_IF(true);
21502150
}
21512151
#else
2152-
Py_INCREF(attr_o);
2153-
attr = PyStackRef_FromPyObjectSteal(attr_o);
2152+
attr = PyStackRef_FromPyObjectNew(attr_o);
21542153
#endif
21552154
STAT_INC(LOAD_ATTR, hit);
21562155
null = PyStackRef_NULL;

Python/executor_cases.c.h

Lines changed: 2 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Python/generated_cases.c.h

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

Tools/cases_generator/analyzer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ def find_assignment_target(node: parser.InstDef, idx: int) -> list[lexer.Token]:
384384
"""Find the tokens that make up the left-hand side of an assignment"""
385385
offset = 0
386386
for tkn in reversed(node.block.tokens[: idx]):
387-
if tkn.kind in {"SEMI", "LBRACE", "RBRACE"}:
387+
if tkn.kind in {"SEMI", "LBRACE", "RBRACE", "CMACRO"}:
388388
return node.block.tokens[idx - offset : idx]
389389
offset += 1
390390
return []

0 commit comments

Comments
 (0)