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

Skip to content

Add error checks in the compiler #122595

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

Closed
serhiy-storchaka opened this issue Aug 2, 2024 · 0 comments
Closed

Add error checks in the compiler #122595

serhiy-storchaka opened this issue Aug 2, 2024 · 0 comments
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs)

Comments

@serhiy-storchaka
Copy link
Member

serhiy-storchaka commented Aug 2, 2024

Historically the compiler (Python/compile.c and Python/symtable.c) contained a lot of code that did not check for errors after the C API calls. For example, it did not check that PyLong_AS_LONG(), PySequence_Contains(), PySet_Contains(), etc can fail, it used PyDict_GetItem() that silence errors. There were so much such cases that the code cleanup often stopped before the compiler. Finally many of such cases were gradually fixed. What's left is unchecked PyLong_AS_LONG() and some PyDict_GetItemWithItem().

The following PR adds many error checks. Some internal functions now return -1 to signal error. In most cases such checks are redundant, we know that values in the dicts are Python integers which can be converted to C long because they were created here. But it is safer to always check for errors than omit checks in "safe" case and be wrong.

Linked PRs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs)
Projects
None yet
Development

No branches or pull requests

1 participant