Skip to content
Snippets Groups Projects
Select Git revision
  • 9303a5ac30c3fd4f04881d432b10be894959cfbd
  • main default protected
  • 3.10
  • 3.11
  • revert-15688-bpo-38031-_io-FileIO-opener-crash
  • 3.8
  • 3.9
  • 3.7
  • enum-fix_auto
  • branch-v3.11.0
  • backport-c3648f4-3.11
  • gh-93963/remove-importlib-resources-abcs
  • refactor-wait_for
  • shared-testcase
  • v3.12.0a2
  • v3.12.0a1
  • v3.11.0
  • v3.8.15
  • v3.9.15
  • v3.10.8
  • v3.7.15
  • v3.11.0rc2
  • v3.8.14
  • v3.9.14
  • v3.7.14
  • v3.10.7
  • v3.11.0rc1
  • v3.10.6
  • v3.11.0b5
  • v3.11.0b4
  • v3.10.5
  • v3.11.0b3
  • v3.11.0b2
  • v3.9.13
34 results

pyport.h

Blame
  • 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.