Skip to content

Add error checks in the compiler #122595

@serhiy-storchaka

Description

@serhiy-storchaka

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    interpreter-core(Objects, Python, Grammar, and Parser dirs)

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions