Skip to content

Commit

Permalink
fix: bb_test_pop_if_false not setting flag (python#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
Fidget-Spinner authored Jun 8, 2023
1 parent 12a588a commit 7cab316
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 1 deletion.
2 changes: 2 additions & 0 deletions Python/bytecodes.c
Original file line number Diff line number Diff line change
Expand Up @@ -1977,6 +1977,7 @@ dummy_func(
}
else {
ERROR_IF(err < 0, error);
bb_test = BB_TEST(1, 0);
}
}
}
Expand Down Expand Up @@ -2018,6 +2019,7 @@ dummy_func(
}
else {
ERROR_IF(err < 0, error);
bb_test = BB_TEST(1, 0);
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion Python/generated_cases.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Python/tier2.c
Original file line number Diff line number Diff line change
Expand Up @@ -1131,6 +1131,7 @@ emit_type_guard(_Py_CODEUNIT *write_curr, int guard_opcode, int guard_oparg, int
fprintf(stderr, "emitted type guard %p %s\n", write_curr,
_PyOpcode_OpName[guard_opcode]);
#endif
assert(guard_oparg <= 0xFF);
write_curr->op.code = guard_opcode;
write_curr->op.arg = guard_oparg & 0xFF;
write_curr++;
Expand Down Expand Up @@ -3009,6 +3010,7 @@ _PyTier2_RewriteForwardJump(_Py_CODEUNIT *bb_branch, _Py_CODEUNIT *target)
}
else {
_py_set_opcode(write_curr, NOP);
write_curr->op.arg = 0;
write_curr++;
}
_py_set_opcode(write_curr,
Expand Down Expand Up @@ -3064,6 +3066,7 @@ _PyTier2_RewriteBackwardJump(_Py_CODEUNIT *jump_backward_lazy, _Py_CODEUNIT *tar
}
else {
_py_set_opcode(write_curr, NOP);
write_curr->op.arg = 0;
write_curr++;
}
_py_set_opcode(write_curr, is_backwards_jump
Expand Down
26 changes: 26 additions & 0 deletions tier2_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -493,4 +493,30 @@ def f(x,l):

# As long as it doesn't crash, everything's good.

######################################################################
# Tests for: Tier 2 BB_TEST_POP_IF_FALSE flag setting #
######################################################################
with TestInfo("tier 2 BB_TEST_POP_IF_FALSE flag setting"):
# See https://github.com/pylbbv/pylbbv/issues/23 for more information.
import sys

class A:
def __init__(self): ...
def __add__(self, _): return "Hewwo!"

def f(a):
b = 1
if a: b = A()
print(b)
return b+b


for _ in range(63): f(0)

assert f(1) == "Hewwo!"

assert f(0) == 2

# As long as it doesn't crash, everything's good.

print("Tests completed ^-^")

0 comments on commit 7cab316

Please sign in to comment.