summaryrefslogtreecommitdiffstats
path: root/Include/pymacro.h
diff options
context:
space:
mode:
authorZachary Ware <zachary.ware@gmail.com>2019-09-12 12:35:48 (GMT)
committerGregory P. Smith <greg@krypto.org>2019-09-12 12:35:48 (GMT)
commit3ab61473ba7f3dca32d779ec2766a4faa0657923 (patch)
tree2657ab3fa643b71c0d3fad6bd071e474bbe982a7 /Include/pymacro.h
parent224b8aaa7e8f67f748e8b7b6a4a77a25f6554651 (diff)
downloadcpython-3ab61473ba7f3dca32d779ec2766a4faa0657923.zip
cpython-3ab61473ba7f3dca32d779ec2766a4faa0657923.tar.gz
cpython-3ab61473ba7f3dca32d779ec2766a4faa0657923.tar.bz2
Enhance Py_UNREACHABLE macro (GH-16032)
Diffstat (limited to 'Include/pymacro.h')
-rw-r--r--Include/pymacro.h26
1 files changed, 26 insertions, 0 deletions
diff --git a/Include/pymacro.h b/Include/pymacro.h
index 1890619..ae09063 100644
--- a/Include/pymacro.h
+++ b/Include/pymacro.h
@@ -100,6 +100,32 @@
# define Py_UNUSED(name) _unused_ ## name
#endif
+#if defined(RANDALL_WAS_HERE)
+#define Py_UNREACHABLE() do { \
+ fputs( \
+ "ERROR:\n\n" \
+ "If you're seeing this, the code is in what I thought was\n" \
+ "an unreachable state.\n\n" \
+ "I could give you advice for what to do, but honestly, why\n" \
+ "should you trust me? I clearly screwed this up. I'm writing\n" \
+ "a message that should never appear, yet I know it will\n" \
+ "probably appear someday.\n\n" \
+ "On a deep level, I know I'm not up to this task.\n" \
+ "I'm so sorry.\n\n" \
+ "https://xkcd.com/2200\n", stderr); \
+ abort(); \
+ } while(0)
+#elif defined(Py_DEBUG)
+#define Py_UNREACHABLE() do { \
+ fputs( \
+ "ERROR:\n\n" \
+ "We've reached an unreachable state. Anything is possible.\n" \
+ "The limits were in our heads all along. Follow your dreams.\n\n" \
+ "https://xkcd.com/2200\n", stderr); \
+ abort(); \
+ } while(0)
+#else
#define Py_UNREACHABLE() abort()
+#endif
#endif /* Py_PYMACRO_H */