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

Replace assert(0) with Py_UNREACHABLE in Python/symtable.c #100577

Closed
sobolevn opened this issue Dec 28, 2022 · 0 comments · Fixed by #100579
Closed

Replace assert(0) with Py_UNREACHABLE in Python/symtable.c #100577

sobolevn opened this issue Dec 28, 2022 · 0 comments · Fixed by #100579
Assignees
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error

Comments

@sobolevn
Copy link
Member

sobolevn commented Dec 28, 2022

While looking at #87447 I've noticed that there are three places in cpython where assert(0) is used instead of Py_UNREACHABLE macro:

cpython/Python/symtable.c

Lines 1539 to 1542 in 984894a

/* We should always find either a FunctionBlock, ModuleBlock or ClassBlock
and should never fall to this case
*/
assert(0);

As the docs say:

Use this when you have a code path that cannot be reached by design.
For example, in the default: clause in a switch statement for which
all possible values are covered in case statements. Use this in places
where you might be tempted to put an assert(0) or abort() call.

The intent with Py_UNREACHABLE is clearer and error message is nicer.

Linked PRs

@sobolevn sobolevn added type-bug An unexpected behavior, bug, or error interpreter-core (Objects, Python, Grammar, and Parser dirs) labels Dec 28, 2022
@sobolevn sobolevn self-assigned this Dec 28, 2022
sobolevn added a commit to sobolevn/cpython that referenced this issue Dec 28, 2022
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) type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant