Select Git revision
pyport.h 24.97 KiB
#ifndef Py_PYPORT_H
#define Py_PYPORT_H
#include "pyconfig.h" /* include for defines */
#include <inttypes.h>
#include <limits.h>
#ifndef UCHAR_MAX
# error "limits.h must define UCHAR_MAX"
#endif
#if UCHAR_MAX != 255
# error "Python's source code assumes C's unsigned char is an 8-bit type"
#endif
// Macro to use C++ static_cast<>, reinterpret_cast<> and const_cast<>
// in the Python C API.
//
// In C++, _Py_CAST(type, expr) converts a constant expression to a
// non constant type using const_cast<type>. For example,
// _Py_CAST(PyObject*, op) can convert a "const PyObject*" to
// "PyObject*".
//
// The type argument must not be a constant type.
#ifdef __cplusplus
# define _Py_STATIC_CAST(type, expr) static_cast<type>(expr)
extern "C++" {
namespace {
template <typename type, typename expr_type>
inline type _Py_CAST_impl(expr_type *expr) {
return reinterpret_cast<type>(expr);
}
template <typename type, typename expr_type>
inline type _Py_CAST_impl(expr_type const *expr) {
return reinterpret_cast<type>(const_cast<expr_type *>(expr));
}
template <typename type, typename expr_type>
inline type _Py_CAST_impl(expr_type &expr) {
return static_cast<type>(expr);
}
template <typename type, typename expr_type>
inline type _Py_CAST_impl(expr_type const &expr) {
return static_cast<type>(const_cast<expr_type &>(expr));
}
}
}
# define _Py_CAST(type, expr) _Py_CAST_impl<type>(expr)
#else
# define _Py_STATIC_CAST(type, expr) ((type)(expr))
# define _Py_CAST(type, expr) ((type)(expr))
#endif
// Static inline functions should use _Py_NULL rather than using directly NULL
// to prevent C++ compiler warnings. In C++, _Py_NULL uses nullptr.
#ifdef __cplusplus
# define _Py_NULL nullptr
#else
# define _Py_NULL NULL
#endif
/* Defines to build Python and its standard library:
*
* - Py_BUILD_CORE: Build Python core. Give access to Python internals, but
* should not be used by third-party modules.