Skip to content

Commit 7cab316

Browse files
fix: bb_test_pop_if_false not setting flag (python#24)
1 parent 12a588a commit 7cab316

File tree

4 files changed

+34
-1
lines changed

4 files changed

+34
-1
lines changed

Python/bytecodes.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1977,6 +1977,7 @@ dummy_func(
19771977
}
19781978
else {
19791979
ERROR_IF(err < 0, error);
1980+
bb_test = BB_TEST(1, 0);
19801981
}
19811982
}
19821983
}
@@ -2018,6 +2019,7 @@ dummy_func(
20182019
}
20192020
else {
20202021
ERROR_IF(err < 0, error);
2022+
bb_test = BB_TEST(1, 0);
20212023
}
20222024
}
20232025
}

Python/generated_cases.c.h

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

Python/tier2.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1131,6 +1131,7 @@ emit_type_guard(_Py_CODEUNIT *write_curr, int guard_opcode, int guard_oparg, int
11311131
fprintf(stderr, "emitted type guard %p %s\n", write_curr,
11321132
_PyOpcode_OpName[guard_opcode]);
11331133
#endif
1134+
assert(guard_oparg <= 0xFF);
11341135
write_curr->op.code = guard_opcode;
11351136
write_curr->op.arg = guard_oparg & 0xFF;
11361137
write_curr++;
@@ -3009,6 +3010,7 @@ _PyTier2_RewriteForwardJump(_Py_CODEUNIT *bb_branch, _Py_CODEUNIT *target)
30093010
}
30103011
else {
30113012
_py_set_opcode(write_curr, NOP);
3013+
write_curr->op.arg = 0;
30123014
write_curr++;
30133015
}
30143016
_py_set_opcode(write_curr,
@@ -3064,6 +3066,7 @@ _PyTier2_RewriteBackwardJump(_Py_CODEUNIT *jump_backward_lazy, _Py_CODEUNIT *tar
30643066
}
30653067
else {
30663068
_py_set_opcode(write_curr, NOP);
3069+
write_curr->op.arg = 0;
30673070
write_curr++;
30683071
}
30693072
_py_set_opcode(write_curr, is_backwards_jump

tier2_test.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,4 +493,30 @@ def f(x,l):
493493

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

496+
######################################################################
497+
# Tests for: Tier 2 BB_TEST_POP_IF_FALSE flag setting #
498+
######################################################################
499+
with TestInfo("tier 2 BB_TEST_POP_IF_FALSE flag setting"):
500+
# See https://github.com/pylbbv/pylbbv/issues/23 for more information.
501+
import sys
502+
503+
class A:
504+
def __init__(self): ...
505+
def __add__(self, _): return "Hewwo!"
506+
507+
def f(a):
508+
b = 1
509+
if a: b = A()
510+
print(b)
511+
return b+b
512+
513+
514+
for _ in range(63): f(0)
515+
516+
assert f(1) == "Hewwo!"
517+
518+
assert f(0) == 2
519+
520+
# As long as it doesn't crash, everything's good.
521+
496522
print("Tests completed ^-^")

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy