Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit ab9d6ed

Browse filesBrowse files
committed
bpo-40555: Check for p->error_indicator in loop rules after the main loop is done
1 parent b7a78ca commit ab9d6ed
Copy full SHA for ab9d6ed

File tree

3 files changed

+37
-28
lines changed
Filter options

3 files changed

+37
-28
lines changed

‎Lib/test/test_eof.py

Copy file name to clipboardExpand all lines: Lib/test/test_eof.py
+9Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,15 @@ def test_EOFS(self):
2626
else:
2727
raise support.TestFailed
2828

29+
def test_eof_with_line_continuation(self):
30+
expect = "unexpected EOF while parsing (<string>, line 1)"
31+
try:
32+
compile('"\\xhh" \\', '<string>', 'exec', dont_inherit=True)
33+
except SyntaxError as msg:
34+
self.assertEqual(str(msg), expect)
35+
else:
36+
raise support.TestFailed
37+
2938
def test_line_continuation_EOF(self):
3039
"""A continuation at the end of input must be an error; bpo2180."""
3140
expect = 'unexpected EOF while parsing (<string>, line 1)'

‎Parser/pegen/parse.c

Copy file name to clipboardExpand all lines: Parser/pegen/parse.c
+27-27Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -11437,7 +11437,7 @@ _loop1_11_rule(Parser *p)
1143711437
}
1143811438
p->mark = mark;
1143911439
}
11440-
if (n == 0) {
11440+
if (n == 0 || p->error_indicator) {
1144111441
PyMem_Free(children);
1144211442
return NULL;
1144311443
}
@@ -11876,7 +11876,7 @@ _loop1_22_rule(Parser *p)
1187611876
}
1187711877
p->mark = mark;
1187811878
}
11879-
if (n == 0) {
11879+
if (n == 0 || p->error_indicator) {
1188011880
PyMem_Free(children);
1188111881
return NULL;
1188211882
}
@@ -12252,7 +12252,7 @@ _loop1_31_rule(Parser *p)
1225212252
}
1225312253
p->mark = mark;
1225412254
}
12255-
if (n == 0) {
12255+
if (n == 0 || p->error_indicator) {
1225612256
PyMem_Free(children);
1225712257
return NULL;
1225812258
}
@@ -12911,7 +12911,7 @@ _loop1_47_rule(Parser *p)
1291112911
}
1291212912
p->mark = mark;
1291312913
}
12914-
if (n == 0) {
12914+
if (n == 0 || p->error_indicator) {
1291512915
PyMem_Free(children);
1291612916
return NULL;
1291712917
}
@@ -13267,7 +13267,7 @@ _loop1_56_rule(Parser *p)
1326713267
}
1326813268
p->mark = mark;
1326913269
}
13270-
if (n == 0) {
13270+
if (n == 0 || p->error_indicator) {
1327113271
PyMem_Free(children);
1327213272
return NULL;
1327313273
}
@@ -13369,7 +13369,7 @@ _loop1_58_rule(Parser *p)
1336913369
}
1337013370
p->mark = mark;
1337113371
}
13372-
if (n == 0) {
13372+
if (n == 0 || p->error_indicator) {
1337313373
PyMem_Free(children);
1337413374
return NULL;
1337513375
}
@@ -13422,7 +13422,7 @@ _loop1_59_rule(Parser *p)
1342213422
}
1342313423
p->mark = mark;
1342413424
}
13425-
if (n == 0) {
13425+
if (n == 0 || p->error_indicator) {
1342613426
PyMem_Free(children);
1342713427
return NULL;
1342813428
}
@@ -13475,7 +13475,7 @@ _loop1_60_rule(Parser *p)
1347513475
}
1347613476
p->mark = mark;
1347713477
}
13478-
if (n == 0) {
13478+
if (n == 0 || p->error_indicator) {
1347913479
PyMem_Free(children);
1348013480
return NULL;
1348113481
}
@@ -13577,7 +13577,7 @@ _loop1_62_rule(Parser *p)
1357713577
}
1357813578
p->mark = mark;
1357913579
}
13580-
if (n == 0) {
13580+
if (n == 0 || p->error_indicator) {
1358113581
PyMem_Free(children);
1358213582
return NULL;
1358313583
}
@@ -13679,7 +13679,7 @@ _loop1_64_rule(Parser *p)
1367913679
}
1368013680
p->mark = mark;
1368113681
}
13682-
if (n == 0) {
13682+
if (n == 0 || p->error_indicator) {
1368313683
PyMem_Free(children);
1368413684
return NULL;
1368513685
}
@@ -13781,7 +13781,7 @@ _loop1_66_rule(Parser *p)
1378113781
}
1378213782
p->mark = mark;
1378313783
}
13784-
if (n == 0) {
13784+
if (n == 0 || p->error_indicator) {
1378513785
PyMem_Free(children);
1378613786
return NULL;
1378713787
}
@@ -13834,7 +13834,7 @@ _loop1_67_rule(Parser *p)
1383413834
}
1383513835
p->mark = mark;
1383613836
}
13837-
if (n == 0) {
13837+
if (n == 0 || p->error_indicator) {
1383813838
PyMem_Free(children);
1383913839
return NULL;
1384013840
}
@@ -14007,7 +14007,7 @@ _loop1_71_rule(Parser *p)
1400714007
}
1400814008
p->mark = mark;
1400914009
}
14010-
if (n == 0) {
14010+
if (n == 0 || p->error_indicator) {
1401114011
PyMem_Free(children);
1401214012
return NULL;
1401314013
}
@@ -14145,7 +14145,7 @@ _loop1_74_rule(Parser *p)
1414514145
}
1414614146
p->mark = mark;
1414714147
}
14148-
if (n == 0) {
14148+
if (n == 0 || p->error_indicator) {
1414914149
PyMem_Free(children);
1415014150
return NULL;
1415114151
}
@@ -14345,7 +14345,7 @@ _loop1_78_rule(Parser *p)
1434514345
}
1434614346
p->mark = mark;
1434714347
}
14348-
if (n == 0) {
14348+
if (n == 0 || p->error_indicator) {
1434914349
PyMem_Free(children);
1435014350
return NULL;
1435114351
}
@@ -14447,7 +14447,7 @@ _loop1_80_rule(Parser *p)
1444714447
}
1444814448
p->mark = mark;
1444914449
}
14450-
if (n == 0) {
14450+
if (n == 0 || p->error_indicator) {
1445114451
PyMem_Free(children);
1445214452
return NULL;
1445314453
}
@@ -14500,7 +14500,7 @@ _loop1_81_rule(Parser *p)
1450014500
}
1450114501
p->mark = mark;
1450214502
}
14503-
if (n == 0) {
14503+
if (n == 0 || p->error_indicator) {
1450414504
PyMem_Free(children);
1450514505
return NULL;
1450614506
}
@@ -14553,7 +14553,7 @@ _loop1_82_rule(Parser *p)
1455314553
}
1455414554
p->mark = mark;
1455514555
}
14556-
if (n == 0) {
14556+
if (n == 0 || p->error_indicator) {
1455714557
PyMem_Free(children);
1455814558
return NULL;
1455914559
}
@@ -14655,7 +14655,7 @@ _loop1_84_rule(Parser *p)
1465514655
}
1465614656
p->mark = mark;
1465714657
}
14658-
if (n == 0) {
14658+
if (n == 0 || p->error_indicator) {
1465914659
PyMem_Free(children);
1466014660
return NULL;
1466114661
}
@@ -14757,7 +14757,7 @@ _loop1_86_rule(Parser *p)
1475714757
}
1475814758
p->mark = mark;
1475914759
}
14760-
if (n == 0) {
14760+
if (n == 0 || p->error_indicator) {
1476114761
PyMem_Free(children);
1476214762
return NULL;
1476314763
}
@@ -14859,7 +14859,7 @@ _loop1_88_rule(Parser *p)
1485914859
}
1486014860
p->mark = mark;
1486114861
}
14862-
if (n == 0) {
14862+
if (n == 0 || p->error_indicator) {
1486314863
PyMem_Free(children);
1486414864
return NULL;
1486514865
}
@@ -14912,7 +14912,7 @@ _loop1_89_rule(Parser *p)
1491214912
}
1491314913
p->mark = mark;
1491414914
}
14915-
if (n == 0) {
14915+
if (n == 0 || p->error_indicator) {
1491614916
PyMem_Free(children);
1491714917
return NULL;
1491814918
}
@@ -14965,7 +14965,7 @@ _loop1_90_rule(Parser *p)
1496514965
}
1496614966
p->mark = mark;
1496714967
}
14968-
if (n == 0) {
14968+
if (n == 0 || p->error_indicator) {
1496914969
PyMem_Free(children);
1497014970
return NULL;
1497114971
}
@@ -15018,7 +15018,7 @@ _loop1_91_rule(Parser *p)
1501815018
}
1501915019
p->mark = mark;
1502015020
}
15021-
if (n == 0) {
15021+
if (n == 0 || p->error_indicator) {
1502215022
PyMem_Free(children);
1502315023
return NULL;
1502415024
}
@@ -15358,7 +15358,7 @@ _loop1_99_rule(Parser *p)
1535815358
}
1535915359
p->mark = mark;
1536015360
}
15361-
if (n == 0) {
15361+
if (n == 0 || p->error_indicator) {
1536215362
PyMem_Free(children);
1536315363
return NULL;
1536415364
}
@@ -15567,7 +15567,7 @@ _loop1_104_rule(Parser *p)
1556715567
}
1556815568
p->mark = mark;
1556915569
}
15570-
if (n == 0) {
15570+
if (n == 0 || p->error_indicator) {
1557115571
PyMem_Free(children);
1557215572
return NULL;
1557315573
}
@@ -17165,7 +17165,7 @@ _loop1_145_rule(Parser *p)
1716517165
}
1716617166
p->mark = mark;
1716717167
}
17168-
if (n == 0) {
17168+
if (n == 0 || p->error_indicator) {
1716917169
PyMem_Free(children);
1717017170
return NULL;
1717117171
}

‎Tools/peg_generator/pegen/c_generator.py

Copy file name to clipboardExpand all lines: Tools/peg_generator/pegen/c_generator.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,7 @@ def _handle_loop_rule_body(self, node: Rule, rhs: Rhs) -> None:
525525
rulename=node.name if memoize else None,
526526
)
527527
if is_repeat1:
528-
self.print("if (n == 0) {")
528+
self.print("if (n == 0 || p->error_indicator) {")
529529
with self.indent():
530530
self.print("PyMem_Free(children);")
531531
self.print("return NULL;")

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.