(root)/
Python-3.11.7/
Include/
pyport.h
       1  #ifndef Py_PYPORT_H
       2  #define Py_PYPORT_H
       3  
       4  #include "pyconfig.h" /* include for defines */
       5  
       6  #include <inttypes.h>
       7  
       8  #include <limits.h>
       9  #ifndef UCHAR_MAX
      10  #  error "limits.h must define UCHAR_MAX"
      11  #endif
      12  #if UCHAR_MAX != 255
      13  #  error "Python's source code assumes C's unsigned char is an 8-bit type"
      14  #endif
      15  
      16  
      17  // Macro to use C++ static_cast<> in the Python C API.
      18  #ifdef __cplusplus
      19  #  define _Py_STATIC_CAST(type, expr) static_cast<type>(expr)
      20  #else
      21  #  define _Py_STATIC_CAST(type, expr) ((type)(expr))
      22  #endif
      23  // Macro to use the more powerful/dangerous C-style cast even in C++.
      24  #define _Py_CAST(type, expr) ((type)(expr))
      25  
      26  // Static inline functions should use _Py_NULL rather than using directly NULL
      27  // to prevent C++ compiler warnings. On C++11 and newer, _Py_NULL is defined as
      28  // nullptr.
      29  #if defined(__cplusplus) && __cplusplus >= 201103
      30  #  define _Py_NULL nullptr
      31  #else
      32  #  define _Py_NULL NULL
      33  #endif
      34  
      35  
      36  /* Defines to build Python and its standard library:
      37   *
      38   * - Py_BUILD_CORE: Build Python core. Give access to Python internals, but
      39   *   should not be used by third-party modules.
      40   * - Py_BUILD_CORE_BUILTIN: Build a Python stdlib module as a built-in module.
      41   * - Py_BUILD_CORE_MODULE: Build a Python stdlib module as a dynamic library.
      42   *
      43   * Py_BUILD_CORE_BUILTIN and Py_BUILD_CORE_MODULE imply Py_BUILD_CORE.
      44   *
      45   * On Windows, Py_BUILD_CORE_MODULE exports "PyInit_xxx" symbol, whereas
      46   * Py_BUILD_CORE_BUILTIN does not.
      47   */
      48  #if defined(Py_BUILD_CORE_BUILTIN) && !defined(Py_BUILD_CORE)
      49  #  define Py_BUILD_CORE
      50  #endif
      51  #if defined(Py_BUILD_CORE_MODULE) && !defined(Py_BUILD_CORE)
      52  #  define Py_BUILD_CORE
      53  #endif
      54  
      55  
      56  /**************************************************************************
      57  Symbols and macros to supply platform-independent interfaces to basic
      58  C language & library operations whose spellings vary across platforms.
      59  
      60  Please try to make documentation here as clear as possible:  by definition,
      61  the stuff here is trying to illuminate C's darkest corners.
      62  
      63  Config #defines referenced here:
      64  
      65  SIGNED_RIGHT_SHIFT_ZERO_FILLS
      66  Meaning:  To be defined iff i>>j does not extend the sign bit when i is a
      67            signed integral type and i < 0.
      68  Used in:  Py_ARITHMETIC_RIGHT_SHIFT
      69  
      70  Py_DEBUG
      71  Meaning:  Extra checks compiled in for debug mode.
      72  Used in:  Py_SAFE_DOWNCAST
      73  
      74  **************************************************************************/
      75  
      76  /* typedefs for some C9X-defined synonyms for integral types.
      77   *
      78   * The names in Python are exactly the same as the C9X names, except with a
      79   * Py_ prefix.  Until C9X is universally implemented, this is the only way
      80   * to ensure that Python gets reliable names that don't conflict with names
      81   * in non-Python code that are playing their own tricks to define the C9X
      82   * names.
      83   *
      84   * NOTE: don't go nuts here!  Python has no use for *most* of the C9X
      85   * integral synonyms.  Only define the ones we actually need.
      86   */
      87  
      88  /* long long is required. Ensure HAVE_LONG_LONG is defined for compatibility. */
      89  #ifndef HAVE_LONG_LONG
      90  #define HAVE_LONG_LONG 1
      91  #endif
      92  #ifndef PY_LONG_LONG
      93  #define PY_LONG_LONG long long
      94  /* If LLONG_MAX is defined in limits.h, use that. */
      95  #define PY_LLONG_MIN LLONG_MIN
      96  #define PY_LLONG_MAX LLONG_MAX
      97  #define PY_ULLONG_MAX ULLONG_MAX
      98  #endif
      99  
     100  #define PY_UINT32_T uint32_t
     101  #define PY_UINT64_T uint64_t
     102  
     103  /* Signed variants of the above */
     104  #define PY_INT32_T int32_t
     105  #define PY_INT64_T int64_t
     106  
     107  /* PYLONG_BITS_IN_DIGIT describes the number of bits per "digit" (limb) in the
     108   * PyLongObject implementation (longintrepr.h). It's currently either 30 or 15,
     109   * defaulting to 30. The 15-bit digit option may be removed in the future.
     110   */
     111  #ifndef PYLONG_BITS_IN_DIGIT
     112  #define PYLONG_BITS_IN_DIGIT 30
     113  #endif
     114  
     115  /* uintptr_t is the C9X name for an unsigned integral type such that a
     116   * legitimate void* can be cast to uintptr_t and then back to void* again
     117   * without loss of information.  Similarly for intptr_t, wrt a signed
     118   * integral type.
     119   */
     120  typedef uintptr_t       Py_uintptr_t;
     121  typedef intptr_t        Py_intptr_t;
     122  
     123  /* Py_ssize_t is a signed integral type such that sizeof(Py_ssize_t) ==
     124   * sizeof(size_t).  C99 doesn't define such a thing directly (size_t is an
     125   * unsigned integral type).  See PEP 353 for details.
     126   * PY_SSIZE_T_MAX is the largest positive value of type Py_ssize_t.
     127   */
     128  #ifdef HAVE_PY_SSIZE_T
     129  
     130  #elif HAVE_SSIZE_T
     131  typedef ssize_t         Py_ssize_t;
     132  #   define PY_SSIZE_T_MAX SSIZE_MAX
     133  #elif SIZEOF_VOID_P == SIZEOF_SIZE_T
     134  typedef Py_intptr_t     Py_ssize_t;
     135  #   define PY_SSIZE_T_MAX INTPTR_MAX
     136  #else
     137  #   error "Python needs a typedef for Py_ssize_t in pyport.h."
     138  #endif
     139  
     140  /* Smallest negative value of type Py_ssize_t. */
     141  #define PY_SSIZE_T_MIN (-PY_SSIZE_T_MAX-1)
     142  
     143  /* Py_hash_t is the same size as a pointer. */
     144  #define SIZEOF_PY_HASH_T SIZEOF_SIZE_T
     145  typedef Py_ssize_t Py_hash_t;
     146  /* Py_uhash_t is the unsigned equivalent needed to calculate numeric hash. */
     147  #define SIZEOF_PY_UHASH_T SIZEOF_SIZE_T
     148  typedef size_t Py_uhash_t;
     149  
     150  /* Now PY_SSIZE_T_CLEAN is mandatory. This is just for backward compatibility. */
     151  typedef Py_ssize_t Py_ssize_clean_t;
     152  
     153  /* Largest possible value of size_t. */
     154  #define PY_SIZE_MAX SIZE_MAX
     155  
     156  /* Macro kept for backward compatibility: use "z" in new code.
     157   *
     158   * PY_FORMAT_SIZE_T is a platform-specific modifier for use in a printf
     159   * format to convert an argument with the width of a size_t or Py_ssize_t.
     160   * C99 introduced "z" for this purpose, but old MSVCs had not supported it.
     161   * Since MSVC supports "z" since (at least) 2015, we can just use "z"
     162   * for new code.
     163   *
     164   * These "high level" Python format functions interpret "z" correctly on
     165   * all platforms (Python interprets the format string itself, and does whatever
     166   * the platform C requires to convert a size_t/Py_ssize_t argument):
     167   *
     168   *     PyBytes_FromFormat
     169   *     PyErr_Format
     170   *     PyBytes_FromFormatV
     171   *     PyUnicode_FromFormatV
     172   *
     173   * Lower-level uses require that you interpolate the correct format modifier
     174   * yourself (e.g., calling printf, fprintf, sprintf, PyOS_snprintf); for
     175   * example,
     176   *
     177   *     Py_ssize_t index;
     178   *     fprintf(stderr, "index %" PY_FORMAT_SIZE_T "d sucks\n", index);
     179   *
     180   * That will expand to %zd or to something else correct for a Py_ssize_t on
     181   * the platform.
     182   */
     183  #ifndef PY_FORMAT_SIZE_T
     184  #   define PY_FORMAT_SIZE_T "z"
     185  #endif
     186  
     187  /* Py_LOCAL can be used instead of static to get the fastest possible calling
     188   * convention for functions that are local to a given module.
     189   *
     190   * Py_LOCAL_INLINE does the same thing, and also explicitly requests inlining,
     191   * for platforms that support that.
     192   *
     193   * NOTE: You can only use this for functions that are entirely local to a
     194   * module; functions that are exported via method tables, callbacks, etc,
     195   * should keep using static.
     196   */
     197  
     198  #if defined(_MSC_VER)
     199     /* ignore warnings if the compiler decides not to inline a function */
     200  #  pragma warning(disable: 4710)
     201     /* fastest possible local call under MSVC */
     202  #  define Py_LOCAL(type) static type __fastcall
     203  #  define Py_LOCAL_INLINE(type) static __inline type __fastcall
     204  #else
     205  #  define Py_LOCAL(type) static type
     206  #  define Py_LOCAL_INLINE(type) static inline type
     207  #endif
     208  
     209  // bpo-28126: Py_MEMCPY is kept for backwards compatibility,
     210  #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 < 0x030b0000
     211  #  define Py_MEMCPY memcpy
     212  #endif
     213  
     214  #ifdef HAVE_IEEEFP_H
     215  #include <ieeefp.h>  /* needed for 'finite' declaration on some platforms */
     216  #endif
     217  
     218  #include <math.h> /* Moved here from the math section, before extern "C" */
     219  
     220  /********************************************
     221   * WRAPPER FOR <time.h> and/or <sys/time.h> *
     222   ********************************************/
     223  
     224  #ifdef HAVE_SYS_TIME_H
     225  #include <sys/time.h>
     226  #endif
     227  #include <time.h>
     228  
     229  /******************************
     230   * WRAPPER FOR <sys/select.h> *
     231   ******************************/
     232  
     233  /* NB caller must include <sys/types.h> */
     234  
     235  #ifdef HAVE_SYS_SELECT_H
     236  #include <sys/select.h>
     237  #endif /* !HAVE_SYS_SELECT_H */
     238  
     239  /*******************************
     240   * stat() and fstat() fiddling *
     241   *******************************/
     242  
     243  #ifdef HAVE_SYS_STAT_H
     244  #include <sys/stat.h>
     245  #elif defined(HAVE_STAT_H)
     246  #include <stat.h>
     247  #endif
     248  
     249  #ifndef S_IFMT
     250  /* VisualAge C/C++ Failed to Define MountType Field in sys/stat.h */
     251  #define S_IFMT 0170000
     252  #endif
     253  
     254  #ifndef S_IFLNK
     255  /* Windows doesn't define S_IFLNK but posixmodule.c maps
     256   * IO_REPARSE_TAG_SYMLINK to S_IFLNK */
     257  #  define S_IFLNK 0120000
     258  #endif
     259  
     260  #ifndef S_ISREG
     261  #define S_ISREG(x) (((x) & S_IFMT) == S_IFREG)
     262  #endif
     263  
     264  #ifndef S_ISDIR
     265  #define S_ISDIR(x) (((x) & S_IFMT) == S_IFDIR)
     266  #endif
     267  
     268  #ifndef S_ISCHR
     269  #define S_ISCHR(x) (((x) & S_IFMT) == S_IFCHR)
     270  #endif
     271  
     272  #ifdef __cplusplus
     273  /* Move this down here since some C++ #include's don't like to be included
     274     inside an extern "C" */
     275  extern "C" {
     276  #endif
     277  
     278  
     279  /* Py_ARITHMETIC_RIGHT_SHIFT
     280   * C doesn't define whether a right-shift of a signed integer sign-extends
     281   * or zero-fills.  Here a macro to force sign extension:
     282   * Py_ARITHMETIC_RIGHT_SHIFT(TYPE, I, J)
     283   *    Return I >> J, forcing sign extension.  Arithmetically, return the
     284   *    floor of I/2**J.
     285   * Requirements:
     286   *    I should have signed integer type.  In the terminology of C99, this can
     287   *    be either one of the five standard signed integer types (signed char,
     288   *    short, int, long, long long) or an extended signed integer type.
     289   *    J is an integer >= 0 and strictly less than the number of bits in the
     290   *    type of I (because C doesn't define what happens for J outside that
     291   *    range either).
     292   *    TYPE used to specify the type of I, but is now ignored.  It's been left
     293   *    in for backwards compatibility with versions <= 2.6 or 3.0.
     294   * Caution:
     295   *    I may be evaluated more than once.
     296   */
     297  #ifdef SIGNED_RIGHT_SHIFT_ZERO_FILLS
     298  #define Py_ARITHMETIC_RIGHT_SHIFT(TYPE, I, J) \
     299      ((I) < 0 ? -1-((-1-(I)) >> (J)) : (I) >> (J))
     300  #else
     301  #define Py_ARITHMETIC_RIGHT_SHIFT(TYPE, I, J) ((I) >> (J))
     302  #endif
     303  
     304  /* Py_FORCE_EXPANSION(X)
     305   * "Simply" returns its argument.  However, macro expansions within the
     306   * argument are evaluated.  This unfortunate trickery is needed to get
     307   * token-pasting to work as desired in some cases.
     308   */
     309  #define Py_FORCE_EXPANSION(X) X
     310  
     311  /* Py_SAFE_DOWNCAST(VALUE, WIDE, NARROW)
     312   * Cast VALUE to type NARROW from type WIDE.  In Py_DEBUG mode, this
     313   * assert-fails if any information is lost.
     314   * Caution:
     315   *    VALUE may be evaluated more than once.
     316   */
     317  #ifdef Py_DEBUG
     318  #  define Py_SAFE_DOWNCAST(VALUE, WIDE, NARROW) \
     319         (assert(_Py_STATIC_CAST(WIDE, _Py_STATIC_CAST(NARROW, (VALUE))) == (VALUE)), \
     320          _Py_STATIC_CAST(NARROW, (VALUE)))
     321  #else
     322  #  define Py_SAFE_DOWNCAST(VALUE, WIDE, NARROW) _Py_STATIC_CAST(NARROW, (VALUE))
     323  #endif
     324  
     325  
     326  /* Py_DEPRECATED(version)
     327   * Declare a variable, type, or function deprecated.
     328   * The macro must be placed before the declaration.
     329   * Usage:
     330   *    Py_DEPRECATED(3.3) extern int old_var;
     331   *    Py_DEPRECATED(3.4) typedef int T1;
     332   *    Py_DEPRECATED(3.8) PyAPI_FUNC(int) Py_OldFunction(void);
     333   */
     334  #if defined(__GNUC__) \
     335      && ((__GNUC__ >= 4) || (__GNUC__ == 3) && (__GNUC_MINOR__ >= 1))
     336  #define Py_DEPRECATED(VERSION_UNUSED) __attribute__((__deprecated__))
     337  #elif defined(_MSC_VER)
     338  #define Py_DEPRECATED(VERSION) __declspec(deprecated( \
     339                                            "deprecated in " #VERSION))
     340  #else
     341  #define Py_DEPRECATED(VERSION_UNUSED)
     342  #endif
     343  
     344  #if defined(__clang__)
     345  #define _Py_COMP_DIAG_PUSH _Pragma("clang diagnostic push")
     346  #define _Py_COMP_DIAG_IGNORE_DEPR_DECLS \
     347      _Pragma("clang diagnostic ignored \"-Wdeprecated-declarations\"")
     348  #define _Py_COMP_DIAG_POP _Pragma("clang diagnostic pop")
     349  #elif defined(__GNUC__) \
     350      && ((__GNUC__ >= 5) || (__GNUC__ == 4) && (__GNUC_MINOR__ >= 6))
     351  #define _Py_COMP_DIAG_PUSH _Pragma("GCC diagnostic push")
     352  #define _Py_COMP_DIAG_IGNORE_DEPR_DECLS \
     353      _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
     354  #define _Py_COMP_DIAG_POP _Pragma("GCC diagnostic pop")
     355  #elif defined(_MSC_VER)
     356  #define _Py_COMP_DIAG_PUSH __pragma(warning(push))
     357  #define _Py_COMP_DIAG_IGNORE_DEPR_DECLS __pragma(warning(disable: 4996))
     358  #define _Py_COMP_DIAG_POP __pragma(warning(pop))
     359  #else
     360  #define _Py_COMP_DIAG_PUSH
     361  #define _Py_COMP_DIAG_IGNORE_DEPR_DECLS
     362  #define _Py_COMP_DIAG_POP
     363  #endif
     364  
     365  /* _Py_HOT_FUNCTION
     366   * The hot attribute on a function is used to inform the compiler that the
     367   * function is a hot spot of the compiled program. The function is optimized
     368   * more aggressively and on many target it is placed into special subsection of
     369   * the text section so all hot functions appears close together improving
     370   * locality.
     371   *
     372   * Usage:
     373   *    int _Py_HOT_FUNCTION x(void) { return 3; }
     374   *
     375   * Issue #28618: This attribute must not be abused, otherwise it can have a
     376   * negative effect on performance. Only the functions were Python spend most of
     377   * its time must use it. Use a profiler when running performance benchmark
     378   * suite to find these functions.
     379   */
     380  #if defined(__GNUC__) \
     381      && ((__GNUC__ >= 5) || (__GNUC__ == 4) && (__GNUC_MINOR__ >= 3))
     382  #define _Py_HOT_FUNCTION __attribute__((hot))
     383  #else
     384  #define _Py_HOT_FUNCTION
     385  #endif
     386  
     387  // Ask the compiler to always inline a static inline function. The compiler can
     388  // ignore it and decides to not inline the function.
     389  //
     390  // It can be used to inline performance critical static inline functions when
     391  // building Python in debug mode with function inlining disabled. For example,
     392  // MSC disables function inlining when building in debug mode.
     393  //
     394  // Marking blindly a static inline function with Py_ALWAYS_INLINE can result in
     395  // worse performances (due to increased code size for example). The compiler is
     396  // usually smarter than the developer for the cost/benefit analysis.
     397  //
     398  // If Python is built in debug mode (if the Py_DEBUG macro is defined), the
     399  // Py_ALWAYS_INLINE macro does nothing.
     400  //
     401  // It must be specified before the function return type. Usage:
     402  //
     403  //     static inline Py_ALWAYS_INLINE int random(void) { return 4; }
     404  #if defined(Py_DEBUG)
     405     // If Python is built in debug mode, usually compiler optimizations are
     406     // disabled. In this case, Py_ALWAYS_INLINE can increase a lot the stack
     407     // memory usage. For example, forcing inlining using gcc -O0 increases the
     408     // stack usage from 6 KB to 15 KB per Python function call.
     409  #  define Py_ALWAYS_INLINE
     410  #elif defined(__GNUC__) || defined(__clang__) || defined(__INTEL_COMPILER)
     411  #  define Py_ALWAYS_INLINE __attribute__((always_inline))
     412  #elif defined(_MSC_VER)
     413  #  define Py_ALWAYS_INLINE __forceinline
     414  #else
     415  #  define Py_ALWAYS_INLINE
     416  #endif
     417  
     418  // Py_NO_INLINE
     419  // Disable inlining on a function. For example, it reduces the C stack
     420  // consumption: useful on LTO+PGO builds which heavily inline code (see
     421  // bpo-33720).
     422  //
     423  // Usage:
     424  //
     425  //    Py_NO_INLINE static int random(void) { return 4; }
     426  #if defined(__GNUC__) || defined(__clang__) || defined(__INTEL_COMPILER)
     427  #  define Py_NO_INLINE __attribute__ ((noinline))
     428  #elif defined(_MSC_VER)
     429  #  define Py_NO_INLINE __declspec(noinline)
     430  #else
     431  #  define Py_NO_INLINE
     432  #endif
     433  
     434  /**************************************************************************
     435  Prototypes that are missing from the standard include files on some systems
     436  (and possibly only some versions of such systems.)
     437  
     438  Please be conservative with adding new ones, document them and enclose them
     439  in platform-specific #ifdefs.
     440  **************************************************************************/
     441  
     442  #ifdef HAVE__GETPTY
     443  #include <sys/types.h>          /* we need to import mode_t */
     444  extern char * _getpty(int *, int, mode_t, int);
     445  #endif
     446  
     447  /* On QNX 6, struct termio must be declared by including sys/termio.h
     448     if TCGETA, TCSETA, TCSETAW, or TCSETAF are used.  sys/termio.h must
     449     be included before termios.h or it will generate an error. */
     450  #if defined(HAVE_SYS_TERMIO_H) && !defined(__hpux)
     451  #include <sys/termio.h>
     452  #endif
     453  
     454  
     455  /* On 4.4BSD-descendants, ctype functions serves the whole range of
     456   * wchar_t character set rather than single byte code points only.
     457   * This characteristic can break some operations of string object
     458   * including str.upper() and str.split() on UTF-8 locales.  This
     459   * workaround was provided by Tim Robbins of FreeBSD project.
     460   */
     461  
     462  #if defined(__APPLE__)
     463  #  define _PY_PORT_CTYPE_UTF8_ISSUE
     464  #endif
     465  
     466  #ifdef _PY_PORT_CTYPE_UTF8_ISSUE
     467  #ifndef __cplusplus
     468     /* The workaround below is unsafe in C++ because
     469      * the <locale> defines these symbols as real functions,
     470      * with a slightly different signature.
     471      * See issue #10910
     472      */
     473  #include <ctype.h>
     474  #include <wctype.h>
     475  #undef isalnum
     476  #define isalnum(c) iswalnum(btowc(c))
     477  #undef isalpha
     478  #define isalpha(c) iswalpha(btowc(c))
     479  #undef islower
     480  #define islower(c) iswlower(btowc(c))
     481  #undef isspace
     482  #define isspace(c) iswspace(btowc(c))
     483  #undef isupper
     484  #define isupper(c) iswupper(btowc(c))
     485  #undef tolower
     486  #define tolower(c) towlower(btowc(c))
     487  #undef toupper
     488  #define toupper(c) towupper(btowc(c))
     489  #endif
     490  #endif
     491  
     492  
     493  /* Declarations for symbol visibility.
     494  
     495    PyAPI_FUNC(type): Declares a public Python API function and return type
     496    PyAPI_DATA(type): Declares public Python data and its type
     497    PyMODINIT_FUNC:   A Python module init function.  If these functions are
     498                      inside the Python core, they are private to the core.
     499                      If in an extension module, it may be declared with
     500                      external linkage depending on the platform.
     501  
     502    As a number of platforms support/require "__declspec(dllimport/dllexport)",
     503    we support a HAVE_DECLSPEC_DLL macro to save duplication.
     504  */
     505  
     506  /*
     507    All windows ports, except cygwin, are handled in PC/pyconfig.h.
     508  
     509    Cygwin is the only other autoconf platform requiring special
     510    linkage handling and it uses __declspec().
     511  */
     512  #if defined(__CYGWIN__)
     513  #       define HAVE_DECLSPEC_DLL
     514  #endif
     515  
     516  #include "exports.h"
     517  
     518  /* only get special linkage if built as shared or platform is Cygwin */
     519  #if defined(Py_ENABLE_SHARED) || defined(__CYGWIN__)
     520  #       if defined(HAVE_DECLSPEC_DLL)
     521  #               if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
     522  #                       define PyAPI_FUNC(RTYPE) Py_EXPORTED_SYMBOL RTYPE
     523  #                       define PyAPI_DATA(RTYPE) extern Py_EXPORTED_SYMBOL RTYPE
     524          /* module init functions inside the core need no external linkage */
     525          /* except for Cygwin to handle embedding */
     526  #                       if defined(__CYGWIN__)
     527  #                               define PyMODINIT_FUNC Py_EXPORTED_SYMBOL PyObject*
     528  #                       else /* __CYGWIN__ */
     529  #                               define PyMODINIT_FUNC PyObject*
     530  #                       endif /* __CYGWIN__ */
     531  #               else /* Py_BUILD_CORE */
     532          /* Building an extension module, or an embedded situation */
     533          /* public Python functions and data are imported */
     534          /* Under Cygwin, auto-import functions to prevent compilation */
     535          /* failures similar to those described at the bottom of 4.1: */
     536          /* http://docs.python.org/extending/windows.html#a-cookbook-approach */
     537  #                       if !defined(__CYGWIN__)
     538  #                               define PyAPI_FUNC(RTYPE) Py_IMPORTED_SYMBOL RTYPE
     539  #                       endif /* !__CYGWIN__ */
     540  #                       define PyAPI_DATA(RTYPE) extern Py_IMPORTED_SYMBOL RTYPE
     541          /* module init functions outside the core must be exported */
     542  #                       if defined(__cplusplus)
     543  #                               define PyMODINIT_FUNC extern "C" Py_EXPORTED_SYMBOL PyObject*
     544  #                       else /* __cplusplus */
     545  #                               define PyMODINIT_FUNC Py_EXPORTED_SYMBOL PyObject*
     546  #                       endif /* __cplusplus */
     547  #               endif /* Py_BUILD_CORE */
     548  #       endif /* HAVE_DECLSPEC_DLL */
     549  #endif /* Py_ENABLE_SHARED */
     550  
     551  /* If no external linkage macros defined by now, create defaults */
     552  #ifndef PyAPI_FUNC
     553  #       define PyAPI_FUNC(RTYPE) Py_EXPORTED_SYMBOL RTYPE
     554  #endif
     555  #ifndef PyAPI_DATA
     556  #       define PyAPI_DATA(RTYPE) extern Py_EXPORTED_SYMBOL RTYPE
     557  #endif
     558  #ifndef PyMODINIT_FUNC
     559  #       if defined(__cplusplus)
     560  #               define PyMODINIT_FUNC extern "C" Py_EXPORTED_SYMBOL PyObject*
     561  #       else /* __cplusplus */
     562  #               define PyMODINIT_FUNC Py_EXPORTED_SYMBOL PyObject*
     563  #       endif /* __cplusplus */
     564  #endif
     565  
     566  /* limits.h constants that may be missing */
     567  
     568  #ifndef INT_MAX
     569  #define INT_MAX 2147483647
     570  #endif
     571  
     572  #ifndef LONG_MAX
     573  #if SIZEOF_LONG == 4
     574  #define LONG_MAX 0X7FFFFFFFL
     575  #elif SIZEOF_LONG == 8
     576  #define LONG_MAX 0X7FFFFFFFFFFFFFFFL
     577  #else
     578  #error "could not set LONG_MAX in pyport.h"
     579  #endif
     580  #endif
     581  
     582  #ifndef LONG_MIN
     583  #define LONG_MIN (-LONG_MAX-1)
     584  #endif
     585  
     586  #ifndef LONG_BIT
     587  #define LONG_BIT (8 * SIZEOF_LONG)
     588  #endif
     589  
     590  #if LONG_BIT != 8 * SIZEOF_LONG
     591  /* 04-Oct-2000 LONG_BIT is apparently (mis)defined as 64 on some recent
     592   * 32-bit platforms using gcc.  We try to catch that here at compile-time
     593   * rather than waiting for integer multiplication to trigger bogus
     594   * overflows.
     595   */
     596  #error "LONG_BIT definition appears wrong for platform (bad gcc/glibc config?)."
     597  #endif
     598  
     599  #ifdef __cplusplus
     600  }
     601  #endif
     602  
     603  /*
     604   * Hide GCC attributes from compilers that don't support them.
     605   */
     606  #if (!defined(__GNUC__) || __GNUC__ < 2 || \
     607       (__GNUC__ == 2 && __GNUC_MINOR__ < 7) )
     608  #define Py_GCC_ATTRIBUTE(x)
     609  #else
     610  #define Py_GCC_ATTRIBUTE(x) __attribute__(x)
     611  #endif
     612  
     613  /*
     614   * Specify alignment on compilers that support it.
     615   */
     616  #if defined(__GNUC__) && __GNUC__ >= 3
     617  #define Py_ALIGNED(x) __attribute__((aligned(x)))
     618  #else
     619  #define Py_ALIGNED(x)
     620  #endif
     621  
     622  /* Eliminate end-of-loop code not reached warnings from SunPro C
     623   * when using do{...}while(0) macros
     624   */
     625  #ifdef __SUNPRO_C
     626  #pragma error_messages (off,E_END_OF_LOOP_CODE_NOT_REACHED)
     627  #endif
     628  
     629  #ifndef Py_LL
     630  #define Py_LL(x) x##LL
     631  #endif
     632  
     633  #ifndef Py_ULL
     634  #define Py_ULL(x) Py_LL(x##U)
     635  #endif
     636  
     637  #define Py_VA_COPY va_copy
     638  
     639  /*
     640   * Convenient macros to deal with endianness of the platform. WORDS_BIGENDIAN is
     641   * detected by configure and defined in pyconfig.h. The code in pyconfig.h
     642   * also takes care of Apple's universal builds.
     643   */
     644  
     645  #ifdef WORDS_BIGENDIAN
     646  #  define PY_BIG_ENDIAN 1
     647  #  define PY_LITTLE_ENDIAN 0
     648  #else
     649  #  define PY_BIG_ENDIAN 0
     650  #  define PY_LITTLE_ENDIAN 1
     651  #endif
     652  
     653  #ifdef __ANDROID__
     654     /* The Android langinfo.h header is not used. */
     655  #  undef HAVE_LANGINFO_H
     656  #  undef CODESET
     657  #endif
     658  
     659  /* Maximum value of the Windows DWORD type */
     660  #define PY_DWORD_MAX 4294967295U
     661  
     662  /* This macro used to tell whether Python was built with multithreading
     663   * enabled.  Now multithreading is always enabled, but keep the macro
     664   * for compatibility.
     665   */
     666  #ifndef WITH_THREAD
     667  #  define WITH_THREAD
     668  #endif
     669  
     670  /* Check that ALT_SOABI is consistent with Py_TRACE_REFS:
     671     ./configure --with-trace-refs should must be used to define Py_TRACE_REFS */
     672  #if defined(ALT_SOABI) && defined(Py_TRACE_REFS)
     673  #  error "Py_TRACE_REFS ABI is not compatible with release and debug ABI"
     674  #endif
     675  
     676  #if defined(__ANDROID__) || defined(__VXWORKS__)
     677     // Use UTF-8 as the locale encoding, ignore the LC_CTYPE locale.
     678     // See _Py_GetLocaleEncoding(), PyUnicode_DecodeLocale()
     679     // and PyUnicode_EncodeLocale().
     680  #  define _Py_FORCE_UTF8_LOCALE
     681  #endif
     682  
     683  #if defined(_Py_FORCE_UTF8_LOCALE) || defined(__APPLE__)
     684     // Use UTF-8 as the filesystem encoding.
     685     // See PyUnicode_DecodeFSDefaultAndSize(), PyUnicode_EncodeFSDefault(),
     686     // Py_DecodeLocale() and Py_EncodeLocale().
     687  #  define _Py_FORCE_UTF8_FS_ENCODING
     688  #endif
     689  
     690  /* Mark a function which cannot return. Example:
     691     PyAPI_FUNC(void) _Py_NO_RETURN PyThread_exit_thread(void);
     692  
     693     XLC support is intentionally omitted due to bpo-40244 */
     694  #ifndef _Py_NO_RETURN
     695  #if defined(__clang__) || \
     696      (defined(__GNUC__) && \
     697       ((__GNUC__ >= 3) || \
     698        (__GNUC__ == 2) && (__GNUC_MINOR__ >= 5)))
     699  #  define _Py_NO_RETURN __attribute__((__noreturn__))
     700  #elif defined(_MSC_VER)
     701  #  define _Py_NO_RETURN __declspec(noreturn)
     702  #else
     703  #  define _Py_NO_RETURN
     704  #endif
     705  #endif
     706  
     707  
     708  // Preprocessor check for a builtin preprocessor function. Always return 0
     709  // if __has_builtin() macro is not defined.
     710  //
     711  // __has_builtin() is available on clang and GCC 10.
     712  #ifdef __has_builtin
     713  #  define _Py__has_builtin(x) __has_builtin(x)
     714  #else
     715  #  define _Py__has_builtin(x) 0
     716  #endif
     717  
     718  
     719  /* A convenient way for code to know if sanitizers are enabled. */
     720  #if defined(__has_feature)
     721  #  if __has_feature(memory_sanitizer)
     722  #    if !defined(_Py_MEMORY_SANITIZER)
     723  #      define _Py_MEMORY_SANITIZER
     724  #    endif
     725  #  endif
     726  #  if __has_feature(address_sanitizer)
     727  #    if !defined(_Py_ADDRESS_SANITIZER)
     728  #      define _Py_ADDRESS_SANITIZER
     729  #    endif
     730  #  endif
     731  #elif defined(__GNUC__)
     732  #  if defined(__SANITIZE_ADDRESS__)
     733  #    define _Py_ADDRESS_SANITIZER
     734  #  endif
     735  #endif
     736  
     737  #endif /* Py_PYPORT_H */