Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 51abbc7

Browse files
committed
Fix Armin's bug 1333982. He found it, he didn't created it :-)
This code generated a C assertion: assert 1, ([s for s in x] + [s for s in x]) pass assert was completely broken, it needed to use the proper block. compiler_use_block() is now no longer used, so remove it.
1 parent 0e7a0ed commit 51abbc7

2 files changed

Lines changed: 41 additions & 9 deletions

File tree

Lib/test/test_dis.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,43 @@ def bug708901():
4646
bug708901.func_code.co_firstlineno + 2,
4747
bug708901.func_code.co_firstlineno + 3)
4848

49+
50+
def bug1333982(x=[]):
51+
assert 0, ([s for s in x] +
52+
1)
53+
pass
54+
55+
dis_bug1333982 = """\
56+
%-4d 0 LOAD_CONST 1 (0)
57+
3 JUMP_IF_TRUE 47 (to 53)
58+
6 POP_TOP
59+
7 LOAD_GLOBAL 0 (AssertionError)
60+
10 BUILD_LIST 0
61+
13 DUP_TOP
62+
14 LOAD_ATTR 1 (append)
63+
17 STORE_FAST 1 (_[1])
64+
20 LOAD_FAST 0 (x)
65+
23 GET_ITER
66+
>> 24 FOR_ITER 16 (to 43)
67+
27 STORE_FAST 2 (s)
68+
30 LOAD_FAST 1 (_[1])
69+
33 LOAD_FAST 2 (s)
70+
36 CALL_FUNCTION 1
71+
39 POP_TOP
72+
40 JUMP_ABSOLUTE 24
73+
>> 43 DELETE_FAST 1 (_[1])
74+
75+
%-4d 46 LOAD_CONST 2 (1)
76+
49 BINARY_ADD
77+
50 RAISE_VARARGS 2
78+
>> 53 POP_TOP
79+
80+
%-4d 54 LOAD_CONST 0 (None)
81+
57 RETURN_VALUE
82+
"""%(bug1333982.func_code.co_firstlineno + 1,
83+
bug1333982.func_code.co_firstlineno + 2,
84+
bug1333982.func_code.co_firstlineno + 3)
85+
4986
class DisTests(unittest.TestCase):
5087
def do_disassembly_test(self, func, expected):
5188
s = StringIO.StringIO()
@@ -83,6 +120,9 @@ def test_dis(self):
83120
def test_bug_708901(self):
84121
self.do_disassembly_test(bug708901, dis_bug708901)
85122

123+
def test_bug_1333982(self):
124+
self.do_disassembly_test(bug1333982, dis_bug1333982)
125+
86126
def test_main():
87127
run_unittest(DisTests)
88128

Python/compile.c

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,6 @@ static int compiler_addop(struct compiler *, int);
171171
static int compiler_addop_o(struct compiler *, int, PyObject *, PyObject *);
172172
static int compiler_addop_i(struct compiler *, int, int);
173173
static int compiler_addop_j(struct compiler *, int, basicblock *, int);
174-
static void compiler_use_block(struct compiler *, basicblock *);
175174
static basicblock *compiler_use_new_block(struct compiler *);
176175
static int compiler_error(struct compiler *, const char *);
177176
static int compiler_nameop(struct compiler *, identifier, expr_context_ty);
@@ -1178,13 +1177,6 @@ compiler_new_block(struct compiler *c)
11781177
return b;
11791178
}
11801179

1181-
static void
1182-
compiler_use_block(struct compiler *c, basicblock *block)
1183-
{
1184-
assert (block != NULL);
1185-
c->u->u_curblock = block;
1186-
}
1187-
11881180
static basicblock *
11891181
compiler_use_new_block(struct compiler *c)
11901182
{
@@ -2529,7 +2521,7 @@ compiler_assert(struct compiler *c, stmt_ty s)
25292521
else {
25302522
ADDOP_I(c, RAISE_VARARGS, 1);
25312523
}
2532-
compiler_use_block(c, end);
2524+
compiler_use_next_block(c, end);
25332525
ADDOP(c, POP_TOP);
25342526
return 1;
25352527
}

0 commit comments

Comments
 (0)