Skip to content

Commit 3ab6147

Browse files
zwaregpshead
authored andcommitted
Enhance Py_UNREACHABLE macro (GH-16032)
1 parent 224b8aa commit 3ab6147

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

Include/pymacro.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,32 @@
100100
# define Py_UNUSED(name) _unused_ ## name
101101
#endif
102102

103+
#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)
118+
#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)
127+
#else
103128
#define Py_UNREACHABLE() abort()
129+
#endif
104130

105131
#endif /* Py_PYMACRO_H */

0 commit comments

Comments
 (0)