Skip to content

Commit b154258

Browse files
authored
bpo-38205: Py_UNREACHABLE() calls Py_FatalError() (GH-16290)
1 parent bc2256e commit b154258

File tree

2 files changed

+19
-23
lines changed

2 files changed

+19
-23
lines changed

Include/pymacro.h

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -101,31 +101,26 @@
101101
#endif
102102

103103
#if defined(RANDALL_WAS_HERE)
104-
#define Py_UNREACHABLE() do { \
105-
fputs( \
106-
"ERROR:\n\n" \
107-
"If you're seeing this, the code is in what I thought was\n" \
108-
"an unreachable state.\n\n" \
109-
"I could give you advice for what to do, but honestly, why\n" \
110-
"should you trust me? I clearly screwed this up. I'm writing\n" \
111-
"a message that should never appear, yet I know it will\n" \
112-
"probably appear someday.\n\n" \
113-
"On a deep level, I know I'm not up to this task.\n" \
114-
"I'm so sorry.\n\n" \
115-
"https://xkcd.com/2200\n", stderr); \
116-
abort(); \
117-
} while(0)
104+
#define Py_UNREACHABLE() \
105+
Py_FatalError( \
106+
"If you're seeing this, the code is in what I thought was\n" \
107+
"an unreachable state.\n\n" \
108+
"I could give you advice for what to do, but honestly, why\n" \
109+
"should you trust me? I clearly screwed this up. I'm writing\n" \
110+
"a message that should never appear, yet I know it will\n" \
111+
"probably appear someday.\n\n" \
112+
"On a deep level, I know I'm not up to this task.\n" \
113+
"I'm so sorry.\n" \
114+
"https://xkcd.com/2200")
118115
#elif defined(Py_DEBUG)
119-
#define Py_UNREACHABLE() do { \
120-
fputs( \
121-
"ERROR:\n\n" \
122-
"We've reached an unreachable state. Anything is possible.\n" \
123-
"The limits were in our heads all along. Follow your dreams.\n\n" \
124-
"https://xkcd.com/2200\n", stderr); \
125-
abort(); \
126-
} while(0)
116+
#define Py_UNREACHABLE() \
117+
Py_FatalError( \
118+
"We've reached an unreachable state. Anything is possible.\n" \
119+
"The limits were in our heads all along. Follow your dreams.\n" \
120+
"https://xkcd.com/2200")
127121
#else
128-
#define Py_UNREACHABLE() abort()
122+
#define Py_UNREACHABLE() \
123+
Py_FatalError("Unreachable C code path reached")
129124
#endif
130125

131126
#endif /* Py_PYMACRO_H */
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
The :c:func:`Py_UNREACHABLE` macro now calls :c:func:`Py_FatalError`.

0 commit comments

Comments
 (0)