Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bpo-40555: Check for p->error_indicator in loop rules after the main loop is done #19986

Merged
merged 1 commit into from
May 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions Lib/test/test_eof.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@ def test_EOFS(self):
else:
raise support.TestFailed

def test_eof_with_line_continuation(self):
expect = "unexpected EOF while parsing (<string>, line 1)"
try:
compile('"\\xhh" \\', '<string>', 'exec', dont_inherit=True)
except SyntaxError as msg:
self.assertEqual(str(msg), expect)
else:
raise support.TestFailed

def test_line_continuation_EOF(self):
"""A continuation at the end of input must be an error; bpo2180."""
expect = 'unexpected EOF while parsing (<string>, line 1)'
Expand Down
54 changes: 27 additions & 27 deletions Parser/pegen/parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -11437,7 +11437,7 @@ _loop1_11_rule(Parser *p)
}
p->mark = mark;
}
if (n == 0) {
if (n == 0 || p->error_indicator) {
PyMem_Free(children);
return NULL;
}
Expand Down Expand Up @@ -11876,7 +11876,7 @@ _loop1_22_rule(Parser *p)
}
p->mark = mark;
}
if (n == 0) {
if (n == 0 || p->error_indicator) {
PyMem_Free(children);
return NULL;
}
Expand Down Expand Up @@ -12252,7 +12252,7 @@ _loop1_31_rule(Parser *p)
}
p->mark = mark;
}
if (n == 0) {
if (n == 0 || p->error_indicator) {
PyMem_Free(children);
return NULL;
}
Expand Down Expand Up @@ -12911,7 +12911,7 @@ _loop1_47_rule(Parser *p)
}
p->mark = mark;
}
if (n == 0) {
if (n == 0 || p->error_indicator) {
PyMem_Free(children);
return NULL;
}
Expand Down Expand Up @@ -13267,7 +13267,7 @@ _loop1_56_rule(Parser *p)
}
p->mark = mark;
}
if (n == 0) {
if (n == 0 || p->error_indicator) {
PyMem_Free(children);
return NULL;
}
Expand Down Expand Up @@ -13369,7 +13369,7 @@ _loop1_58_rule(Parser *p)
}
p->mark = mark;
}
if (n == 0) {
if (n == 0 || p->error_indicator) {
PyMem_Free(children);
return NULL;
}
Expand Down Expand Up @@ -13422,7 +13422,7 @@ _loop1_59_rule(Parser *p)
}
p->mark = mark;
}
if (n == 0) {
if (n == 0 || p->error_indicator) {
PyMem_Free(children);
return NULL;
}
Expand Down Expand Up @@ -13475,7 +13475,7 @@ _loop1_60_rule(Parser *p)
}
p->mark = mark;
}
if (n == 0) {
if (n == 0 || p->error_indicator) {
PyMem_Free(children);
return NULL;
}
Expand Down Expand Up @@ -13577,7 +13577,7 @@ _loop1_62_rule(Parser *p)
}
p->mark = mark;
}
if (n == 0) {
if (n == 0 || p->error_indicator) {
PyMem_Free(children);
return NULL;
}
Expand Down Expand Up @@ -13679,7 +13679,7 @@ _loop1_64_rule(Parser *p)
}
p->mark = mark;
}
if (n == 0) {
if (n == 0 || p->error_indicator) {
PyMem_Free(children);
return NULL;
}
Expand Down Expand Up @@ -13781,7 +13781,7 @@ _loop1_66_rule(Parser *p)
}
p->mark = mark;
}
if (n == 0) {
if (n == 0 || p->error_indicator) {
PyMem_Free(children);
return NULL;
}
Expand Down Expand Up @@ -13834,7 +13834,7 @@ _loop1_67_rule(Parser *p)
}
p->mark = mark;
}
if (n == 0) {
if (n == 0 || p->error_indicator) {
PyMem_Free(children);
return NULL;
}
Expand Down Expand Up @@ -14007,7 +14007,7 @@ _loop1_71_rule(Parser *p)
}
p->mark = mark;
}
if (n == 0) {
if (n == 0 || p->error_indicator) {
PyMem_Free(children);
return NULL;
}
Expand Down Expand Up @@ -14145,7 +14145,7 @@ _loop1_74_rule(Parser *p)
}
p->mark = mark;
}
if (n == 0) {
if (n == 0 || p->error_indicator) {
PyMem_Free(children);
return NULL;
}
Expand Down Expand Up @@ -14345,7 +14345,7 @@ _loop1_78_rule(Parser *p)
}
p->mark = mark;
}
if (n == 0) {
if (n == 0 || p->error_indicator) {
PyMem_Free(children);
return NULL;
}
Expand Down Expand Up @@ -14447,7 +14447,7 @@ _loop1_80_rule(Parser *p)
}
p->mark = mark;
}
if (n == 0) {
if (n == 0 || p->error_indicator) {
PyMem_Free(children);
return NULL;
}
Expand Down Expand Up @@ -14500,7 +14500,7 @@ _loop1_81_rule(Parser *p)
}
p->mark = mark;
}
if (n == 0) {
if (n == 0 || p->error_indicator) {
PyMem_Free(children);
return NULL;
}
Expand Down Expand Up @@ -14553,7 +14553,7 @@ _loop1_82_rule(Parser *p)
}
p->mark = mark;
}
if (n == 0) {
if (n == 0 || p->error_indicator) {
PyMem_Free(children);
return NULL;
}
Expand Down Expand Up @@ -14655,7 +14655,7 @@ _loop1_84_rule(Parser *p)
}
p->mark = mark;
}
if (n == 0) {
if (n == 0 || p->error_indicator) {
PyMem_Free(children);
return NULL;
}
Expand Down Expand Up @@ -14757,7 +14757,7 @@ _loop1_86_rule(Parser *p)
}
p->mark = mark;
}
if (n == 0) {
if (n == 0 || p->error_indicator) {
PyMem_Free(children);
return NULL;
}
Expand Down Expand Up @@ -14859,7 +14859,7 @@ _loop1_88_rule(Parser *p)
}
p->mark = mark;
}
if (n == 0) {
if (n == 0 || p->error_indicator) {
PyMem_Free(children);
return NULL;
}
Expand Down Expand Up @@ -14912,7 +14912,7 @@ _loop1_89_rule(Parser *p)
}
p->mark = mark;
}
if (n == 0) {
if (n == 0 || p->error_indicator) {
PyMem_Free(children);
return NULL;
}
Expand Down Expand Up @@ -14965,7 +14965,7 @@ _loop1_90_rule(Parser *p)
}
p->mark = mark;
}
if (n == 0) {
if (n == 0 || p->error_indicator) {
PyMem_Free(children);
return NULL;
}
Expand Down Expand Up @@ -15018,7 +15018,7 @@ _loop1_91_rule(Parser *p)
}
p->mark = mark;
}
if (n == 0) {
if (n == 0 || p->error_indicator) {
PyMem_Free(children);
return NULL;
}
Expand Down Expand Up @@ -15358,7 +15358,7 @@ _loop1_99_rule(Parser *p)
}
p->mark = mark;
}
if (n == 0) {
if (n == 0 || p->error_indicator) {
PyMem_Free(children);
return NULL;
}
Expand Down Expand Up @@ -15567,7 +15567,7 @@ _loop1_104_rule(Parser *p)
}
p->mark = mark;
}
if (n == 0) {
if (n == 0 || p->error_indicator) {
PyMem_Free(children);
return NULL;
}
Expand Down Expand Up @@ -17165,7 +17165,7 @@ _loop1_145_rule(Parser *p)
}
p->mark = mark;
}
if (n == 0) {
if (n == 0 || p->error_indicator) {
PyMem_Free(children);
return NULL;
}
Expand Down
2 changes: 1 addition & 1 deletion Tools/peg_generator/pegen/c_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ def _handle_loop_rule_body(self, node: Rule, rhs: Rhs) -> None:
rulename=node.name if memoize else None,
)
if is_repeat1:
self.print("if (n == 0) {")
self.print("if (n == 0 || p->error_indicator) {")
with self.indent():
self.print("PyMem_Free(children);")
self.print("return NULL;")
Expand Down