]> granicus.if.org Git - python/commitdiff
Enhance Py_UNREACHABLE macro (GH-16032)
authorZachary Ware <zachary.ware@gmail.com>
Thu, 12 Sep 2019 12:35:48 +0000 (13:35 +0100)
committerGregory P. Smith <greg@krypto.org>
Thu, 12 Sep 2019 12:35:48 +0000 (13:35 +0100)
Include/pymacro.h

index 1890619099a35b121ee52844b1f229a8899204f7..ae09063e10d87234cd7fedd44d7fd96189044dd7 100644 (file)
 #  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 */