[Python-checkins] CVS: python/dist/src/Include Python.h,2.23,2.24 pyport.h,2.3,2.4
Tim Peters
python-dev@python.org
Sun, 23 Jul 2000 12:28:37 -0700
Update of /cvsroot/python/python/dist/src/Include
In directory slayer.i.sourceforge.net:/tmp/cvs-serv8641/python/dist/src/Include
Modified Files:
Python.h pyport.h
Log Message:
Included assert.h in Python.h -- it's absurd that this basic tool of
good C practice hasn't been available to everything all along.
Added Py_SAFE_DOWNCAST(VALUE, WIDE, NARROW) macro to pyport.h; this
just casts VALUE from type WIDE to type NARROW, but assert-fails if
Py_DEBUG is defined and info is lost due to casting.
Replaced a line in Fredrik's fix to marshal.c to use the new macro.
Index: Python.h
===================================================================
RCS file: /cvsroot/python/python/dist/src/Include/Python.h,v
retrieving revision 2.23
retrieving revision 2.24
diff -C2 -r2.23 -r2.24
*** Python.h 2000/07/12 17:26:09 2.23
--- Python.h 2000/07/23 19:28:34 2.24
***************
*** 32,36 ****
#include "patchlevel.h"
#include "config.h"
- #include "pyport.h"
/* config.h may or may not define DL_IMPORT */
--- 32,35 ----
***************
*** 52,55 ****
--- 51,57 ----
#include <stdlib.h>
#endif
+ #include <assert.h>
+
+ #include "pyport.h"
#include "myproto.h"
Index: pyport.h
===================================================================
RCS file: /cvsroot/python/python/dist/src/Include/pyport.h,v
retrieving revision 2.3
retrieving revision 2.4
diff -C2 -r2.3 -r2.4
*** pyport.h 2000/07/23 18:10:16 2.3
--- pyport.h 2000/07/23 19:28:34 2.4
***************
*** 28,31 ****
--- 28,35 ----
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,77 ****
--- 78,94 ----
#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