[issue26824] Make some macros use Py_TYPE

STINNER Victor report at bugs.python.org
Fri Apr 22 04:17:45 EDT 2016


STINNER Victor added the comment:

It is possible to implement type checking in C macros.

Example found on the Internet:

/* inline type checking - can mix in with other macros more easily using the comma operator,
 * C11 gives best results here */
#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)
#  define CHECK_TYPE_INLINE(val, type) \
    (void)((void)(((type)0) != (0 ? (val) : ((type)0))), \
           _Generic((val), type: 0, const type: 0))
#else
#  define CHECK_TYPE_INLINE(val, type) \
    ((void)(((type)0) != (0 ? (val) : ((type)0))))
#endif

http://stackoverflow.com/questions/11449632/checking-types-of-macro-parameters-at-compile-time

See also Include/pymacro.h which contains some macros implementing checks tested at the compilation.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue26824>
_______________________________________


More information about the Python-bugs-list mailing list