Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

bpo-31338#3374

Merged
warsaw merged 8 commits into
python:masterpython/cpython:masterfrom
warsaw:bpo-31338warsaw/cpython:bpo-31338Copy head branch name to clipboard
Sep 15, 2017
Merged

bpo-31338#3374
warsaw merged 8 commits into
python:masterpython/cpython:masterfrom
warsaw:bpo-31338warsaw/cpython:bpo-31338Copy head branch name to clipboard

Conversation

@warsaw

@warsaw warsaw commented Sep 6, 2017

Copy link
Copy Markdown
Member

Over in http://bugs.python.org/issue31338 the idea to implement a macro called Py_UNREACHABLE() was proposed. This would be used in cases where you'd be tempted to use an assert(0) or abort(), i.e. for code paths you do not expect will ever be reached.

Using Py_UNREACHABLE() has a few advantages:

  • Consistency; it's easy to search for such code paths;
  • The intent is clear;
  • Being a macro, we adjust this on a per-compiler basis in case we need to make it more friendly (although the default implementation makes gcc, clang, and MSVC happy).
  • We can define it differently for other use cases, such as adding a common debugging entry point, or printing __FILE__ and __LINE__, etc.

I've changed the examples described in bpo-31338, but may not have gotten them all.

For now, this is defined strictly as abort() which is the simplest thing that make the common compilers happy.

I've also added some documentation about Py_UNREACHABLE() and a few other macros in pymacros.h.

https://bugs.python.org/issue31338

@vstinner vstinner left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM.

@warsaw

warsaw commented Sep 15, 2017

Copy link
Copy Markdown
Member Author

Thanks @Haypo !

@warsaw warsaw merged commit b2e5794 into python:master Sep 15, 2017
@warsaw warsaw deleted the bpo-31338 branch September 15, 2017 01:13
@encukou

encukou commented Nov 8, 2017

Copy link
Copy Markdown
Member

The Py_UNREACHABLE() doc entry is missing versionadded, see #4337

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.