8000 Support jump<0 in stack_effect() · python/cpython@977e639 · GitHub
[go: up one dir, main page]

Skip to content

Commit 977e639

Browse files
committed
Support jump<0 in stack_effect()
1 parent a271ebc commit 977e639

File tree

1 file changed

+26
-3
lines changed

1 file changed

+26
-3
lines changed

Python/compile.c

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1075,12 +1075,35 @@ static int
10751075
stack_effect(int opcode, int oparg, int jump)
10761076
{
10771077
if (0 <= opcode && opcode < 256) {
1078-
int popped = _PyOpcode_num_popped(opcode, oparg, jump);
1079-
int pushed = _PyOpcode_num_pushed(opcode, oparg, jump);
1078+
int popped, pushed;
1079+
if (jump > 0) {
1080+
popped = _PyOpcode_num_popped(opcode, oparg, true);
1081+
pushed = _PyOpcode_num_pushed(opcode, oparg, true);
1082+
}
1083+
else {
1084+
popped = _PyOpcode_num_popped(opcode, oparg, false);
1085+
pushed = _PyOpcode_num_pushed(opcode, oparg, false);
1086+
}
10801087
if (popped < 0 || pushed < 0) {
10811088
return PY_INVALID_STACK_EFFECT;
10821089
}
1083-
return pushed - popped;
1090+
if (jump >= 0) {
1091+
return pushed - popped;
1092+
}
1093+
if (jump < 0) {
1094+
// Compute max(pushed - popped, alt_pushed - alt_popped)
1095+
int alt_popped = _PyOpcode_num_popped(opcode, oparg, true);
1096+
int alt_pushed = _PyOpcode_num_pushed(opcode, oparg, true);
1097+
if (alt_popped < 0 || alt_pushed < 0) {
1098+
return PY_INVALID_STACK_EFFECT;
1099+
}
1100+
int diff = pushed - popped;
1101+
int alt_diff = alt_pushed - alt_popped;
1102+
if (alt_diff > diff) {
1103+
return alt_diff;
1104+
}
1105+
return diff;
1106+
}
10841107
}
10851108

10861109
// Pseudo ops

0 commit comments

Comments
 (0)
0