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

Skip to content

bpo-42218: Correctly handle errors in left-recursive rules #23065

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

Merged
merged 4 commits into from
Oct 31, 2020

Conversation

lysnikolaou
Copy link
Member

@lysnikolaou lysnikolaou commented Oct 31, 2020

Left-recursive rules need to check for errors explicitly, since
even if the rule returns NULL, the parsing might continue and lead
to long-distance failures.

https://bugs.python.org/issue42218

Left-recursive rules need to check for errors explicitly, since
even if the rule returns NULL, the parsing might continue and lead
to long-distance failures.
Copy link
Member

@pablogsal pablogsal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, great catch, @lysnikolaou! 🎣

@pablogsal
Copy link
Member

@lysnikolaou (For a different PR/issue) I was thinking that maybe we should add an assert(!p->error_indicator) to the beginning of each function in the pegen.c file to avoid similar situations in the future. What do you think?

@lysnikolaou
Copy link
Member Author

@lysnikolaou (For a different PR/issue) I was thinking that maybe we should add an assert(!p->error_indicator) to the beginning of each function in the pegen.c file to avoid similar situations in the future. What do you think?

That's a good idea, though every function might be a bit too much. Are we 100% sure that the assertion should apply to every single rule?

@lysnikolaou lysnikolaou merged commit 02cdfc9 into python:master Oct 31, 2020
@miss-islington
Copy link
Contributor

Thanks @lysnikolaou for the PR 🌮🎉.. I'm working now to backport this PR to: 3.9.
🐍🍒⛏🤖

@lysnikolaou lysnikolaou deleted the left-recursive-error-indicator branch October 31, 2020 18:31
@miss-islington
Copy link
Contributor

Sorry, @lysnikolaou, I could not cleanly backport this to 3.9 due to a conflict.
Please backport using cherry_picker on command line.
cherry_picker 02cdfc93f82fecdb7eae97a868d4ee222b9875d9 3.9

lysnikolaou added a commit to lysnikolaou/cpython that referenced this pull request Oct 31, 2020
…honGH-23065)

Left-recursive rules need to check for errors explicitly, since
even if the rule returns NULL, the parsing might continue and lead
to long-distance failures.

Co-authored-by: Pablo Galindo <[email protected]>
(cherry picked from commit 02cdfc9)
@bedevere-bot
Copy link

GH-23066 is a backport of this pull request to the 3.9 branch.

@bedevere-bot bedevere-bot removed the needs backport to 3.9 only security fixes label Oct 31, 2020
@pablogsal
Copy link
Member

That's a good idea, though every function might be a bit too much. Are we 100% sure that the assertion should apply to every single rule?

I am confident it applies to most of the functions if not all. The key here is that non of these functions should be called with the error indicator set, ever. As the assertion is also only on debug mode (and is just a simple check of an integer) I think the cost is not too elevated. The most annoying part is checking what functions don't make sense to include the check.

@lysnikolaou
Copy link
Member Author

The most annoying part is checking what functions don't make sense to include the check.

Right, that's what I wanted to say before as well. Figuring out where might be a bit annoying, but I agree that it's definitely worth it.

@pablogsal
Copy link
Member

Right, that's what I wanted to say before as well. Figuring out where might be a bit annoying, but I agree that it's definitely worth it.

Ok, I will try to make a proposal PR soon :)

@lysnikolaou
Copy link
Member Author

Let me know, in case you don't find the bandwidth. I can take it up, if needed.

miss-islington pushed a commit that referenced this pull request Oct 31, 2020
…23065) (GH-23066)

Left-recursive rules need to check for errors explicitly, since
even if the rule returns NULL, the parsing might continue and lead
to long-distance failures.

Co-authored-by: Pablo Galindo <[email protected]>
(cherry picked from commit 02cdfc9)

Automerge-Triggered-By: GH:lysnikolaou
adorilson pushed a commit to adorilson/cpython that referenced this pull request Mar 13, 2021
…23065)

Left-recursive rules need to check for errors explicitly, since
even if the rule returns NULL, the parsing might continue and lead
to long-distance failures.

Co-authored-by: Pablo Galindo <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants