summaryrefslogtreecommitdiffstats
path: root/Include/pyport.h
diff options
context:
space:
mode:
Diffstat (limited to 'Include/pyport.h')
-rw-r--r--Include/pyport.h17
1 files changed, 17 insertions, 0 deletions
diff --git a/Include/pyport.h b/Include/pyport.h
index 4faba7c..ed8a28e 100644
--- a/Include/pyport.h
+++ b/Include/pyport.h
@@ -27,6 +27,10 @@ RETSIGTYPE
Meaning: Expands to void or int, depending on what the platform wants
signal handlers to return. Note that only void is ANSI!
Used in: Py_RETURN_FROM_SIGNAL_HANDLER
+
+Py_DEBUG
+Meaning: Extra checks compiled in for debug mode.
+Used in: Py_SAFE_DOWNCAST
**************************************************************************/
@@ -74,6 +78,19 @@ extern "C" {
#define Py_RETURN_FROM_SIGNAL_HANDLER(VALUE) \
Py_FORCE_EXPANSION(RETSIGTYPE) ## _PySIGRETURN(VALUE)
+/* Py_SAFE_DOWNCAST(VALUE, WIDE, NARROW)
+ * Cast VALUE to type NARROW from type WIDE. In Py_DEBUG mode, this
+ * assert-fails if any information is lost.
+ * Caution:
+ * VALUE may be evaluated more than once.
+ */
+#ifdef Py_DEBUG
+#define Py_SAFE_DOWNCAST(VALUE, WIDE, NARROW) \
+ (assert((WIDE)(NARROW)(VALUE) == (VALUE)), (NARROW)(VALUE))
+#else
+#define Py_SAFE_DOWNCAST(VALUE, WIDE, NARROW) (NARROW)(VALUE)
+#endif
+
#ifdef __cplusplus
}
#endif