Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:06:50

0001 #ifndef Py_PYPORT_H
0002 #define Py_PYPORT_H
0003 
0004 #include "pyconfig.h" /* include for defines */
0005 
0006 #include <inttypes.h>
0007 
0008 #include <limits.h>
0009 #ifndef UCHAR_MAX
0010 #  error "limits.h must define UCHAR_MAX"
0011 #endif
0012 #if UCHAR_MAX != 255
0013 #  error "Python's source code assumes C's unsigned char is an 8-bit type"
0014 #endif
0015 
0016 
0017 // Macro to use C++ static_cast<> in the Python C API.
0018 #ifdef __cplusplus
0019 #  define _Py_STATIC_CAST(type, expr) static_cast<type>(expr)
0020 #else
0021 #  define _Py_STATIC_CAST(type, expr) ((type)(expr))
0022 #endif
0023 // Macro to use the more powerful/dangerous C-style cast even in C++.
0024 #define _Py_CAST(type, expr) ((type)(expr))
0025 
0026 // Static inline functions should use _Py_NULL rather than using directly NULL
0027 // to prevent C++ compiler warnings. On C++11 and newer, _Py_NULL is defined as
0028 // nullptr.
0029 #if defined(__cplusplus) && __cplusplus >= 201103
0030 #  define _Py_NULL nullptr
0031 #else
0032 #  define _Py_NULL NULL
0033 #endif
0034 
0035 
0036 /* Defines to build Python and its standard library:
0037  *
0038  * - Py_BUILD_CORE: Build Python core. Give access to Python internals, but
0039  *   should not be used by third-party modules.
0040  * - Py_BUILD_CORE_BUILTIN: Build a Python stdlib module as a built-in module.
0041  * - Py_BUILD_CORE_MODULE: Build a Python stdlib module as a dynamic library.
0042  *
0043  * Py_BUILD_CORE_BUILTIN and Py_BUILD_CORE_MODULE imply Py_BUILD_CORE.
0044  *
0045  * On Windows, Py_BUILD_CORE_MODULE exports "PyInit_xxx" symbol, whereas
0046  * Py_BUILD_CORE_BUILTIN does not.
0047  */
0048 #if defined(Py_BUILD_CORE_BUILTIN) && !defined(Py_BUILD_CORE)
0049 #  define Py_BUILD_CORE
0050 #endif
0051 #if defined(Py_BUILD_CORE_MODULE) && !defined(Py_BUILD_CORE)
0052 #  define Py_BUILD_CORE
0053 #endif
0054 
0055 
0056 /**************************************************************************
0057 Symbols and macros to supply platform-independent interfaces to basic
0058 C language & library operations whose spellings vary across platforms.
0059 
0060 Please try to make documentation here as clear as possible:  by definition,
0061 the stuff here is trying to illuminate C's darkest corners.
0062 
0063 Config #defines referenced here:
0064 
0065 SIGNED_RIGHT_SHIFT_ZERO_FILLS
0066 Meaning:  To be defined iff i>>j does not extend the sign bit when i is a
0067           signed integral type and i < 0.
0068 Used in:  Py_ARITHMETIC_RIGHT_SHIFT
0069 
0070 Py_DEBUG
0071 Meaning:  Extra checks compiled in for debug mode.
0072 Used in:  Py_SAFE_DOWNCAST
0073 
0074 **************************************************************************/
0075 
0076 /* typedefs for some C9X-defined synonyms for integral types.
0077  *
0078  * The names in Python are exactly the same as the C9X names, except with a
0079  * Py_ prefix.  Until C9X is universally implemented, this is the only way
0080  * to ensure that Python gets reliable names that don't conflict with names
0081  * in non-Python code that are playing their own tricks to define the C9X
0082  * names.
0083  *
0084  * NOTE: don't go nuts here!  Python has no use for *most* of the C9X
0085  * integral synonyms.  Only define the ones we actually need.
0086  */
0087 
0088 /* long long is required. Ensure HAVE_LONG_LONG is defined for compatibility. */
0089 #ifndef HAVE_LONG_LONG
0090 #define HAVE_LONG_LONG 1
0091 #endif
0092 #ifndef PY_LONG_LONG
0093 #define PY_LONG_LONG long long
0094 /* If LLONG_MAX is defined in limits.h, use that. */
0095 #define PY_LLONG_MIN LLONG_MIN
0096 #define PY_LLONG_MAX LLONG_MAX
0097 #define PY_ULLONG_MAX ULLONG_MAX
0098 #endif
0099 
0100 #define PY_UINT32_T uint32_t
0101 #define PY_UINT64_T uint64_t
0102 
0103 /* Signed variants of the above */
0104 #define PY_INT32_T int32_t
0105 #define PY_INT64_T int64_t
0106 
0107 /* PYLONG_BITS_IN_DIGIT describes the number of bits per "digit" (limb) in the
0108  * PyLongObject implementation (longintrepr.h). It's currently either 30 or 15,
0109  * defaulting to 30. The 15-bit digit option may be removed in the future.
0110  */
0111 #ifndef PYLONG_BITS_IN_DIGIT
0112 #define PYLONG_BITS_IN_DIGIT 30
0113 #endif
0114 
0115 /* uintptr_t is the C9X name for an unsigned integral type such that a
0116  * legitimate void* can be cast to uintptr_t and then back to void* again
0117  * without loss of information.  Similarly for intptr_t, wrt a signed
0118  * integral type.
0119  */
0120 typedef uintptr_t       Py_uintptr_t;
0121 typedef intptr_t        Py_intptr_t;
0122 
0123 /* Py_ssize_t is a signed integral type such that sizeof(Py_ssize_t) ==
0124  * sizeof(size_t).  C99 doesn't define such a thing directly (size_t is an
0125  * unsigned integral type).  See PEP 353 for details.
0126  * PY_SSIZE_T_MAX is the largest positive value of type Py_ssize_t.
0127  */
0128 #ifdef HAVE_PY_SSIZE_T
0129 
0130 #elif HAVE_SSIZE_T
0131 typedef ssize_t         Py_ssize_t;
0132 #   define PY_SSIZE_T_MAX SSIZE_MAX
0133 #elif SIZEOF_VOID_P == SIZEOF_SIZE_T
0134 typedef Py_intptr_t     Py_ssize_t;
0135 #   define PY_SSIZE_T_MAX INTPTR_MAX
0136 #else
0137 #   error "Python needs a typedef for Py_ssize_t in pyport.h."
0138 #endif
0139 
0140 /* Smallest negative value of type Py_ssize_t. */
0141 #define PY_SSIZE_T_MIN (-PY_SSIZE_T_MAX-1)
0142 
0143 /* Py_hash_t is the same size as a pointer. */
0144 #define SIZEOF_PY_HASH_T SIZEOF_SIZE_T
0145 typedef Py_ssize_t Py_hash_t;
0146 /* Py_uhash_t is the unsigned equivalent needed to calculate numeric hash. */
0147 #define SIZEOF_PY_UHASH_T SIZEOF_SIZE_T
0148 typedef size_t Py_uhash_t;
0149 
0150 /* Now PY_SSIZE_T_CLEAN is mandatory. This is just for backward compatibility. */
0151 typedef Py_ssize_t Py_ssize_clean_t;
0152 
0153 /* Largest possible value of size_t. */
0154 #define PY_SIZE_MAX SIZE_MAX
0155 
0156 /* Macro kept for backward compatibility: use directly "z" in new code.
0157  *
0158  * PY_FORMAT_SIZE_T is a modifier for use in a printf format to convert an
0159  * argument with the width of a size_t or Py_ssize_t: "z" (C99).
0160  */
0161 #ifndef PY_FORMAT_SIZE_T
0162 #   define PY_FORMAT_SIZE_T "z"
0163 #endif
0164 
0165 /* Py_LOCAL can be used instead of static to get the fastest possible calling
0166  * convention for functions that are local to a given module.
0167  *
0168  * Py_LOCAL_INLINE does the same thing, and also explicitly requests inlining,
0169  * for platforms that support that.
0170  *
0171  * NOTE: You can only use this for functions that are entirely local to a
0172  * module; functions that are exported via method tables, callbacks, etc,
0173  * should keep using static.
0174  */
0175 
0176 #if defined(_MSC_VER)
0177    /* ignore warnings if the compiler decides not to inline a function */
0178 #  pragma warning(disable: 4710)
0179    /* fastest possible local call under MSVC */
0180 #  define Py_LOCAL(type) static type __fastcall
0181 #  define Py_LOCAL_INLINE(type) static __inline type __fastcall
0182 #else
0183 #  define Py_LOCAL(type) static type
0184 #  define Py_LOCAL_INLINE(type) static inline type
0185 #endif
0186 
0187 #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 < 0x030b0000
0188 #  define Py_MEMCPY memcpy
0189 #endif
0190 
0191 #ifdef HAVE_IEEEFP_H
0192 #include <ieeefp.h>  /* needed for 'finite' declaration on some platforms */
0193 #endif
0194 
0195 #include <math.h> /* Moved here from the math section, before extern "C" */
0196 
0197 /********************************************
0198  * WRAPPER FOR <time.h> and/or <sys/time.h> *
0199  ********************************************/
0200 
0201 #ifdef HAVE_SYS_TIME_H
0202 #include <sys/time.h>
0203 #endif
0204 #include <time.h>
0205 
0206 /******************************
0207  * WRAPPER FOR <sys/select.h> *
0208  ******************************/
0209 
0210 /* NB caller must include <sys/types.h> */
0211 
0212 #ifdef HAVE_SYS_SELECT_H
0213 #include <sys/select.h>
0214 #endif /* !HAVE_SYS_SELECT_H */
0215 
0216 /*******************************
0217  * stat() and fstat() fiddling *
0218  *******************************/
0219 
0220 #ifdef HAVE_SYS_STAT_H
0221 #include <sys/stat.h>
0222 #elif defined(HAVE_STAT_H)
0223 #include <stat.h>
0224 #endif
0225 
0226 #ifndef S_IFMT
0227 /* VisualAge C/C++ Failed to Define MountType Field in sys/stat.h */
0228 #define S_IFMT 0170000
0229 #endif
0230 
0231 #ifndef S_IFLNK
0232 /* Windows doesn't define S_IFLNK but posixmodule.c maps
0233  * IO_REPARSE_TAG_SYMLINK to S_IFLNK */
0234 #  define S_IFLNK 0120000
0235 #endif
0236 
0237 #ifndef S_ISREG
0238 #define S_ISREG(x) (((x) & S_IFMT) == S_IFREG)
0239 #endif
0240 
0241 #ifndef S_ISDIR
0242 #define S_ISDIR(x) (((x) & S_IFMT) == S_IFDIR)
0243 #endif
0244 
0245 #ifndef S_ISCHR
0246 #define S_ISCHR(x) (((x) & S_IFMT) == S_IFCHR)
0247 #endif
0248 
0249 #ifndef S_ISLNK
0250 #define S_ISLNK(x) (((x) & S_IFMT) == S_IFLNK)
0251 #endif
0252 
0253 #ifdef __cplusplus
0254 /* Move this down here since some C++ #include's don't like to be included
0255    inside an extern "C" */
0256 extern "C" {
0257 #endif
0258 
0259 
0260 /* Py_ARITHMETIC_RIGHT_SHIFT
0261  * C doesn't define whether a right-shift of a signed integer sign-extends
0262  * or zero-fills.  Here a macro to force sign extension:
0263  * Py_ARITHMETIC_RIGHT_SHIFT(TYPE, I, J)
0264  *    Return I >> J, forcing sign extension.  Arithmetically, return the
0265  *    floor of I/2**J.
0266  * Requirements:
0267  *    I should have signed integer type.  In the terminology of C99, this can
0268  *    be either one of the five standard signed integer types (signed char,
0269  *    short, int, long, long long) or an extended signed integer type.
0270  *    J is an integer >= 0 and strictly less than the number of bits in the
0271  *    type of I (because C doesn't define what happens for J outside that
0272  *    range either).
0273  *    TYPE used to specify the type of I, but is now ignored.  It's been left
0274  *    in for backwards compatibility with versions <= 2.6 or 3.0.
0275  * Caution:
0276  *    I may be evaluated more than once.
0277  */
0278 #ifdef SIGNED_RIGHT_SHIFT_ZERO_FILLS
0279 #define Py_ARITHMETIC_RIGHT_SHIFT(TYPE, I, J) \
0280     ((I) < 0 ? -1-((-1-(I)) >> (J)) : (I) >> (J))
0281 #else
0282 #define Py_ARITHMETIC_RIGHT_SHIFT(TYPE, I, J) ((I) >> (J))
0283 #endif
0284 
0285 /* Py_FORCE_EXPANSION(X)
0286  * "Simply" returns its argument.  However, macro expansions within the
0287  * argument are evaluated.  This unfortunate trickery is needed to get
0288  * token-pasting to work as desired in some cases.
0289  */
0290 #define Py_FORCE_EXPANSION(X) X
0291 
0292 /* Py_SAFE_DOWNCAST(VALUE, WIDE, NARROW)
0293  * Cast VALUE to type NARROW from type WIDE.  In Py_DEBUG mode, this
0294  * assert-fails if any information is lost.
0295  * Caution:
0296  *    VALUE may be evaluated more than once.
0297  */
0298 #ifdef Py_DEBUG
0299 #  define Py_SAFE_DOWNCAST(VALUE, WIDE, NARROW) \
0300        (assert(_Py_STATIC_CAST(WIDE, _Py_STATIC_CAST(NARROW, (VALUE))) == (VALUE)), \
0301         _Py_STATIC_CAST(NARROW, (VALUE)))
0302 #else
0303 #  define Py_SAFE_DOWNCAST(VALUE, WIDE, NARROW) _Py_STATIC_CAST(NARROW, (VALUE))
0304 #endif
0305 
0306 
0307 /* Py_DEPRECATED(version)
0308  * Declare a variable, type, or function deprecated.
0309  * The macro must be placed before the declaration.
0310  * Usage:
0311  *    Py_DEPRECATED(3.3) extern int old_var;
0312  *    Py_DEPRECATED(3.4) typedef int T1;
0313  *    Py_DEPRECATED(3.8) PyAPI_FUNC(int) Py_OldFunction(void);
0314  */
0315 #if defined(__GNUC__) \
0316     && ((__GNUC__ >= 4) || (__GNUC__ == 3) && (__GNUC_MINOR__ >= 1))
0317 #define Py_DEPRECATED(VERSION_UNUSED) __attribute__((__deprecated__))
0318 #elif defined(_MSC_VER)
0319 #define Py_DEPRECATED(VERSION) __declspec(deprecated( \
0320                                           "deprecated in " #VERSION))
0321 #else
0322 #define Py_DEPRECATED(VERSION_UNUSED)
0323 #endif
0324 
0325 // _Py_DEPRECATED_EXTERNALLY(version)
0326 // Deprecated outside CPython core.
0327 #ifdef Py_BUILD_CORE
0328 #define _Py_DEPRECATED_EXTERNALLY(VERSION_UNUSED)
0329 #else
0330 #define _Py_DEPRECATED_EXTERNALLY(version) Py_DEPRECATED(version)
0331 #endif
0332 
0333 
0334 #if defined(__clang__)
0335 #define _Py_COMP_DIAG_PUSH _Pragma("clang diagnostic push")
0336 #define _Py_COMP_DIAG_IGNORE_DEPR_DECLS \
0337     _Pragma("clang diagnostic ignored \"-Wdeprecated-declarations\"")
0338 #define _Py_COMP_DIAG_POP _Pragma("clang diagnostic pop")
0339 #elif defined(__GNUC__) \
0340     && ((__GNUC__ >= 5) || (__GNUC__ == 4) && (__GNUC_MINOR__ >= 6))
0341 #define _Py_COMP_DIAG_PUSH _Pragma("GCC diagnostic push")
0342 #define _Py_COMP_DIAG_IGNORE_DEPR_DECLS \
0343     _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
0344 #define _Py_COMP_DIAG_POP _Pragma("GCC diagnostic pop")
0345 #elif defined(_MSC_VER)
0346 #define _Py_COMP_DIAG_PUSH __pragma(warning(push))
0347 #define _Py_COMP_DIAG_IGNORE_DEPR_DECLS __pragma(warning(disable: 4996))
0348 #define _Py_COMP_DIAG_POP __pragma(warning(pop))
0349 #else
0350 #define _Py_COMP_DIAG_PUSH
0351 #define _Py_COMP_DIAG_IGNORE_DEPR_DECLS
0352 #define _Py_COMP_DIAG_POP
0353 #endif
0354 
0355 /* _Py_HOT_FUNCTION
0356  * The hot attribute on a function is used to inform the compiler that the
0357  * function is a hot spot of the compiled program. The function is optimized
0358  * more aggressively and on many target it is placed into special subsection of
0359  * the text section so all hot functions appears close together improving
0360  * locality.
0361  *
0362  * Usage:
0363  *    int _Py_HOT_FUNCTION x(void) { return 3; }
0364  *
0365  * Issue #28618: This attribute must not be abused, otherwise it can have a
0366  * negative effect on performance. Only the functions were Python spend most of
0367  * its time must use it. Use a profiler when running performance benchmark
0368  * suite to find these functions.
0369  */
0370 #if defined(__GNUC__) \
0371     && ((__GNUC__ >= 5) || (__GNUC__ == 4) && (__GNUC_MINOR__ >= 3))
0372 #define _Py_HOT_FUNCTION __attribute__((hot))
0373 #else
0374 #define _Py_HOT_FUNCTION
0375 #endif
0376 
0377 // Ask the compiler to always inline a static inline function. The compiler can
0378 // ignore it and decides to not inline the function.
0379 //
0380 // It can be used to inline performance critical static inline functions when
0381 // building Python in debug mode with function inlining disabled. For example,
0382 // MSC disables function inlining when building in debug mode.
0383 //
0384 // Marking blindly a static inline function with Py_ALWAYS_INLINE can result in
0385 // worse performances (due to increased code size for example). The compiler is
0386 // usually smarter than the developer for the cost/benefit analysis.
0387 //
0388 // If Python is built in debug mode (if the Py_DEBUG macro is defined), the
0389 // Py_ALWAYS_INLINE macro does nothing.
0390 //
0391 // It must be specified before the function return type. Usage:
0392 //
0393 //     static inline Py_ALWAYS_INLINE int random(void) { return 4; }
0394 #if defined(Py_DEBUG)
0395    // If Python is built in debug mode, usually compiler optimizations are
0396    // disabled. In this case, Py_ALWAYS_INLINE can increase a lot the stack
0397    // memory usage. For example, forcing inlining using gcc -O0 increases the
0398    // stack usage from 6 KB to 15 KB per Python function call.
0399 #  define Py_ALWAYS_INLINE
0400 #elif defined(__GNUC__) || defined(__clang__) || defined(__INTEL_COMPILER)
0401 #  define Py_ALWAYS_INLINE __attribute__((always_inline))
0402 #elif defined(_MSC_VER)
0403 #  define Py_ALWAYS_INLINE __forceinline
0404 #else
0405 #  define Py_ALWAYS_INLINE
0406 #endif
0407 
0408 // Py_NO_INLINE
0409 // Disable inlining on a function. For example, it reduces the C stack
0410 // consumption: useful on LTO+PGO builds which heavily inline code (see
0411 // bpo-33720).
0412 //
0413 // Usage:
0414 //
0415 //    Py_NO_INLINE static int random(void) { return 4; }
0416 #if defined(__GNUC__) || defined(__clang__) || defined(__INTEL_COMPILER)
0417 #  define Py_NO_INLINE __attribute__ ((noinline))
0418 #elif defined(_MSC_VER)
0419 #  define Py_NO_INLINE __declspec(noinline)
0420 #else
0421 #  define Py_NO_INLINE
0422 #endif
0423 
0424 /**************************************************************************
0425 Prototypes that are missing from the standard include files on some systems
0426 (and possibly only some versions of such systems.)
0427 
0428 Please be conservative with adding new ones, document them and enclose them
0429 in platform-specific #ifdefs.
0430 **************************************************************************/
0431 
0432 #ifdef HAVE__GETPTY
0433 #include <sys/types.h>          /* we need to import mode_t */
0434 extern char * _getpty(int *, int, mode_t, int);
0435 #endif
0436 
0437 /* On QNX 6, struct termio must be declared by including sys/termio.h
0438    if TCGETA, TCSETA, TCSETAW, or TCSETAF are used.  sys/termio.h must
0439    be included before termios.h or it will generate an error. */
0440 #if defined(HAVE_SYS_TERMIO_H) && !defined(__hpux)
0441 #include <sys/termio.h>
0442 #endif
0443 
0444 
0445 /* On 4.4BSD-descendants, ctype functions serves the whole range of
0446  * wchar_t character set rather than single byte code points only.
0447  * This characteristic can break some operations of string object
0448  * including str.upper() and str.split() on UTF-8 locales.  This
0449  * workaround was provided by Tim Robbins of FreeBSD project.
0450  */
0451 
0452 #if defined(__APPLE__)
0453 #  define _PY_PORT_CTYPE_UTF8_ISSUE
0454 #endif
0455 
0456 #ifdef _PY_PORT_CTYPE_UTF8_ISSUE
0457 #ifndef __cplusplus
0458    /* The workaround below is unsafe in C++ because
0459     * the <locale> defines these symbols as real functions,
0460     * with a slightly different signature.
0461     * See issue #10910
0462     */
0463 #include <ctype.h>
0464 #include <wctype.h>
0465 #undef isalnum
0466 #define isalnum(c) iswalnum(btowc(c))
0467 #undef isalpha
0468 #define isalpha(c) iswalpha(btowc(c))
0469 #undef islower
0470 #define islower(c) iswlower(btowc(c))
0471 #undef isspace
0472 #define isspace(c) iswspace(btowc(c))
0473 #undef isupper
0474 #define isupper(c) iswupper(btowc(c))
0475 #undef tolower
0476 #define tolower(c) towlower(btowc(c))
0477 #undef toupper
0478 #define toupper(c) towupper(btowc(c))
0479 #endif
0480 #endif
0481 
0482 
0483 /* Declarations for symbol visibility.
0484 
0485   PyAPI_FUNC(type): Declares a public Python API function and return type
0486   PyAPI_DATA(type): Declares public Python data and its type
0487   PyMODINIT_FUNC:   A Python module init function.  If these functions are
0488                     inside the Python core, they are private to the core.
0489                     If in an extension module, it may be declared with
0490                     external linkage depending on the platform.
0491 
0492   As a number of platforms support/require "__declspec(dllimport/dllexport)",
0493   we support a HAVE_DECLSPEC_DLL macro to save duplication.
0494 */
0495 
0496 /*
0497   All windows ports, except cygwin, are handled in PC/pyconfig.h.
0498 
0499   Cygwin is the only other autoconf platform requiring special
0500   linkage handling and it uses __declspec().
0501 */
0502 #if defined(__CYGWIN__)
0503 #       define HAVE_DECLSPEC_DLL
0504 #endif
0505 
0506 #include "exports.h"
0507 
0508 /* only get special linkage if built as shared or platform is Cygwin */
0509 #if defined(Py_ENABLE_SHARED) || defined(__CYGWIN__)
0510 #       if defined(HAVE_DECLSPEC_DLL)
0511 #               if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
0512 #                       define PyAPI_FUNC(RTYPE) Py_EXPORTED_SYMBOL RTYPE
0513 #                       define PyAPI_DATA(RTYPE) extern Py_EXPORTED_SYMBOL RTYPE
0514         /* module init functions inside the core need no external linkage */
0515         /* except for Cygwin to handle embedding */
0516 #                       if defined(__CYGWIN__)
0517 #                               define PyMODINIT_FUNC Py_EXPORTED_SYMBOL PyObject*
0518 #                       else /* __CYGWIN__ */
0519 #                               define PyMODINIT_FUNC PyObject*
0520 #                       endif /* __CYGWIN__ */
0521 #               else /* Py_BUILD_CORE */
0522         /* Building an extension module, or an embedded situation */
0523         /* public Python functions and data are imported */
0524         /* Under Cygwin, auto-import functions to prevent compilation */
0525         /* failures similar to those described at the bottom of 4.1: */
0526         /* http://docs.python.org/extending/windows.html#a-cookbook-approach */
0527 #                       if !defined(__CYGWIN__)
0528 #                               define PyAPI_FUNC(RTYPE) Py_IMPORTED_SYMBOL RTYPE
0529 #                       endif /* !__CYGWIN__ */
0530 #                       define PyAPI_DATA(RTYPE) extern Py_IMPORTED_SYMBOL RTYPE
0531         /* module init functions outside the core must be exported */
0532 #                       if defined(__cplusplus)
0533 #                               define PyMODINIT_FUNC extern "C" Py_EXPORTED_SYMBOL PyObject*
0534 #                       else /* __cplusplus */
0535 #                               define PyMODINIT_FUNC Py_EXPORTED_SYMBOL PyObject*
0536 #                       endif /* __cplusplus */
0537 #               endif /* Py_BUILD_CORE */
0538 #       endif /* HAVE_DECLSPEC_DLL */
0539 #endif /* Py_ENABLE_SHARED */
0540 
0541 /* If no external linkage macros defined by now, create defaults */
0542 #ifndef PyAPI_FUNC
0543 #       define PyAPI_FUNC(RTYPE) Py_EXPORTED_SYMBOL RTYPE
0544 #endif
0545 #ifndef PyAPI_DATA
0546 #       define PyAPI_DATA(RTYPE) extern Py_EXPORTED_SYMBOL RTYPE
0547 #endif
0548 #ifndef PyMODINIT_FUNC
0549 #       if defined(__cplusplus)
0550 #               define PyMODINIT_FUNC extern "C" Py_EXPORTED_SYMBOL PyObject*
0551 #       else /* __cplusplus */
0552 #               define PyMODINIT_FUNC Py_EXPORTED_SYMBOL PyObject*
0553 #       endif /* __cplusplus */
0554 #endif
0555 
0556 /* limits.h constants that may be missing */
0557 
0558 #ifndef INT_MAX
0559 #define INT_MAX 2147483647
0560 #endif
0561 
0562 #ifndef LONG_MAX
0563 #if SIZEOF_LONG == 4
0564 #define LONG_MAX 0X7FFFFFFFL
0565 #elif SIZEOF_LONG == 8
0566 #define LONG_MAX 0X7FFFFFFFFFFFFFFFL
0567 #else
0568 #error "could not set LONG_MAX in pyport.h"
0569 #endif
0570 #endif
0571 
0572 #ifndef LONG_MIN
0573 #define LONG_MIN (-LONG_MAX-1)
0574 #endif
0575 
0576 #ifndef LONG_BIT
0577 #define LONG_BIT (8 * SIZEOF_LONG)
0578 #endif
0579 
0580 #if LONG_BIT != 8 * SIZEOF_LONG
0581 /* 04-Oct-2000 LONG_BIT is apparently (mis)defined as 64 on some recent
0582  * 32-bit platforms using gcc.  We try to catch that here at compile-time
0583  * rather than waiting for integer multiplication to trigger bogus
0584  * overflows.
0585  */
0586 #error "LONG_BIT definition appears wrong for platform (bad gcc/glibc config?)."
0587 #endif
0588 
0589 #ifdef __cplusplus
0590 }
0591 #endif
0592 
0593 /*
0594  * Hide GCC attributes from compilers that don't support them.
0595  */
0596 #if (!defined(__GNUC__) || __GNUC__ < 2 || \
0597      (__GNUC__ == 2 && __GNUC_MINOR__ < 7) )
0598 #define Py_GCC_ATTRIBUTE(x)
0599 #else
0600 #define Py_GCC_ATTRIBUTE(x) __attribute__(x)
0601 #endif
0602 
0603 /*
0604  * Specify alignment on compilers that support it.
0605  */
0606 #if defined(__GNUC__) && __GNUC__ >= 3
0607 #define Py_ALIGNED(x) __attribute__((aligned(x)))
0608 #else
0609 #define Py_ALIGNED(x)
0610 #endif
0611 
0612 /* Eliminate end-of-loop code not reached warnings from SunPro C
0613  * when using do{...}while(0) macros
0614  */
0615 #ifdef __SUNPRO_C
0616 #pragma error_messages (off,E_END_OF_LOOP_CODE_NOT_REACHED)
0617 #endif
0618 
0619 #ifndef Py_LL
0620 #define Py_LL(x) x##LL
0621 #endif
0622 
0623 #ifndef Py_ULL
0624 #define Py_ULL(x) Py_LL(x##U)
0625 #endif
0626 
0627 #define Py_VA_COPY va_copy
0628 
0629 /*
0630  * Convenient macros to deal with endianness of the platform. WORDS_BIGENDIAN is
0631  * detected by configure and defined in pyconfig.h. The code in pyconfig.h
0632  * also takes care of Apple's universal builds.
0633  */
0634 
0635 #ifdef WORDS_BIGENDIAN
0636 #  define PY_BIG_ENDIAN 1
0637 #  define PY_LITTLE_ENDIAN 0
0638 #else
0639 #  define PY_BIG_ENDIAN 0
0640 #  define PY_LITTLE_ENDIAN 1
0641 #endif
0642 
0643 #ifdef __ANDROID__
0644    /* The Android langinfo.h header is not used. */
0645 #  undef HAVE_LANGINFO_H
0646 #  undef CODESET
0647 #endif
0648 
0649 /* Maximum value of the Windows DWORD type */
0650 #define PY_DWORD_MAX 4294967295U
0651 
0652 /* This macro used to tell whether Python was built with multithreading
0653  * enabled.  Now multithreading is always enabled, but keep the macro
0654  * for compatibility.
0655  */
0656 #ifndef WITH_THREAD
0657 #  define WITH_THREAD
0658 #endif
0659 
0660 #ifdef WITH_THREAD
0661 #  ifdef Py_BUILD_CORE
0662 #    ifdef HAVE_THREAD_LOCAL
0663 #      error "HAVE_THREAD_LOCAL is already defined"
0664 #    endif
0665 #    define HAVE_THREAD_LOCAL 1
0666 #    ifdef thread_local
0667 #      define _Py_thread_local thread_local
0668 #    elif __STDC_VERSION__ >= 201112L && !defined(__STDC_NO_THREADS__)
0669 #      define _Py_thread_local _Thread_local
0670 #    elif defined(_MSC_VER)  /* AKA NT_THREADS */
0671 #      define _Py_thread_local __declspec(thread)
0672 #    elif defined(__GNUC__)  /* includes clang */
0673 #      define _Py_thread_local __thread
0674 #    else
0675        // fall back to the PyThread_tss_*() API, or ignore.
0676 #      undef HAVE_THREAD_LOCAL
0677 #    endif
0678 #  endif
0679 #endif
0680 
0681 /* Check that ALT_SOABI is consistent with Py_TRACE_REFS:
0682    ./configure --with-trace-refs should must be used to define Py_TRACE_REFS */
0683 #if defined(ALT_SOABI) && defined(Py_TRACE_REFS)
0684 #  error "Py_TRACE_REFS ABI is not compatible with release and debug ABI"
0685 #endif
0686 
0687 #if defined(__ANDROID__) || defined(__VXWORKS__)
0688    // Use UTF-8 as the locale encoding, ignore the LC_CTYPE locale.
0689    // See _Py_GetLocaleEncoding(), PyUnicode_DecodeLocale()
0690    // and PyUnicode_EncodeLocale().
0691 #  define _Py_FORCE_UTF8_LOCALE
0692 #endif
0693 
0694 #if defined(_Py_FORCE_UTF8_LOCALE) || defined(__APPLE__)
0695    // Use UTF-8 as the filesystem encoding.
0696    // See PyUnicode_DecodeFSDefaultAndSize(), PyUnicode_EncodeFSDefault(),
0697    // Py_DecodeLocale() and Py_EncodeLocale().
0698 #  define _Py_FORCE_UTF8_FS_ENCODING
0699 #endif
0700 
0701 /* Mark a function which cannot return. Example:
0702    PyAPI_FUNC(void) _Py_NO_RETURN PyThread_exit_thread(void);
0703 
0704    XLC support is intentionally omitted due to bpo-40244 */
0705 #ifndef _Py_NO_RETURN
0706 #if defined(__clang__) || \
0707     (defined(__GNUC__) && \
0708      ((__GNUC__ >= 3) || \
0709       (__GNUC__ == 2) && (__GNUC_MINOR__ >= 5)))
0710 #  define _Py_NO_RETURN __attribute__((__noreturn__))
0711 #elif defined(_MSC_VER)
0712 #  define _Py_NO_RETURN __declspec(noreturn)
0713 #else
0714 #  define _Py_NO_RETURN
0715 #endif
0716 #endif
0717 
0718 
0719 // Preprocessor check for a builtin preprocessor function. Always return 0
0720 // if __has_builtin() macro is not defined.
0721 //
0722 // __has_builtin() is available on clang and GCC 10.
0723 #ifdef __has_builtin
0724 #  define _Py__has_builtin(x) __has_builtin(x)
0725 #else
0726 #  define _Py__has_builtin(x) 0
0727 #endif
0728 
0729 // _Py_TYPEOF(expr) gets the type of an expression.
0730 //
0731 // Example: _Py_TYPEOF(x) x_copy = (x);
0732 //
0733 // The macro is only defined if GCC or clang compiler is used.
0734 #if defined(__GNUC__) || defined(__clang__)
0735 #  define _Py_TYPEOF(expr) __typeof__(expr)
0736 #endif
0737 
0738 
0739 /* A convenient way for code to know if sanitizers are enabled. */
0740 #if defined(__has_feature)
0741 #  if __has_feature(memory_sanitizer)
0742 #    if !defined(_Py_MEMORY_SANITIZER)
0743 #      define _Py_MEMORY_SANITIZER
0744 #    endif
0745 #  endif
0746 #  if __has_feature(address_sanitizer)
0747 #    if !defined(_Py_ADDRESS_SANITIZER)
0748 #      define _Py_ADDRESS_SANITIZER
0749 #    endif
0750 #  endif
0751 #  if __has_feature(thread_sanitizer)
0752 #    if !defined(_Py_THREAD_SANITIZER)
0753 #      define _Py_THREAD_SANITIZER
0754 #    endif
0755 #  endif
0756 #elif defined(__GNUC__)
0757 #  if defined(__SANITIZE_ADDRESS__)
0758 #    define _Py_ADDRESS_SANITIZER
0759 #  endif
0760 #  if defined(__SANITIZE_THREAD__)
0761 #    define _Py_THREAD_SANITIZER
0762 #  endif
0763 #endif
0764 
0765 
0766 /* AIX has __bool__ redefined in it's system header file. */
0767 #if defined(_AIX) && defined(__bool__)
0768 #undef __bool__
0769 #endif
0770 
0771 // Make sure we have maximum alignment, even if the current compiler
0772 // does not support max_align_t. Note that:
0773 // - Autoconf reports alignment of unknown types to 0.
0774 // - 'long double' has maximum alignment on *most* platforms,
0775 //   looks like the best we can do for pre-C11 compilers.
0776 // - The value is tested, see test_alignof_max_align_t
0777 #if !defined(ALIGNOF_MAX_ALIGN_T) || ALIGNOF_MAX_ALIGN_T == 0
0778 #   undef ALIGNOF_MAX_ALIGN_T
0779 #   define ALIGNOF_MAX_ALIGN_T _Alignof(long double)
0780 #endif
0781 
0782 #endif /* Py_PYPORT_H */