(root)/
Python-3.12.0/
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 directly "z" in new code.
     157   *
     158   * PY_FORMAT_SIZE_T is a modifier for use in a printf format to convert an
     159   * argument with the width of a size_t or Py_ssize_t: "z" (C99).
     160   */
     161  #ifndef PY_FORMAT_SIZE_T
     162  #   define PY_FORMAT_SIZE_T "z"
     163  #endif
     164  
     165  /* Py_LOCAL can be used instead of static to get the fastest possible calling
     166   * convention for functions that are local to a given module.
     167   *
     168   * Py_LOCAL_INLINE does the same thing, and also explicitly requests inlining,
     169   * for platforms that support that.
     170   *
     171   * NOTE: You can only use this for functions that are entirely local to a
     172   * module; functions that are exported via method tables, callbacks, etc,
     173   * should keep using static.
     174   */
     175  
     176  #if defined(_MSC_VER)
     177     /* ignore warnings if the compiler decides not to inline a function */
     178  #  pragma warning(disable: 4710)
     179     /* fastest possible local call under MSVC */
     180  #  define Py_LOCAL(type) static type __fastcall
     181  #  define Py_LOCAL_INLINE(type) static __inline type __fastcall
     182  #else
     183  #  define Py_LOCAL(type) static type
     184  #  define Py_LOCAL_INLINE(type) static inline type
     185  #endif
     186  
     187  #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 < 0x030b0000
     188  #  define Py_MEMCPY memcpy
     189  #endif
     190  
     191  #ifdef HAVE_IEEEFP_H
     192  #include <ieeefp.h>  /* needed for 'finite' declaration on some platforms */
     193  #endif
     194  
     195  #include <math.h> /* Moved here from the math section, before extern "C" */
     196  
     197  /********************************************
     198   * WRAPPER FOR <time.h> and/or <sys/time.h> *
     199   ********************************************/
     200  
     201  #ifdef HAVE_SYS_TIME_H
     202  #include <sys/time.h>
     203  #endif
     204  #include <time.h>
     205  
     206  /******************************
     207   * WRAPPER FOR <sys/select.h> *
     208   ******************************/
     209  
     210  /* NB caller must include <sys/types.h> */
     211  
     212  #ifdef HAVE_SYS_SELECT_H
     213  #include <sys/select.h>
     214  #endif /* !HAVE_SYS_SELECT_H */
     215  
     216  /*******************************
     217   * stat() and fstat() fiddling *
     218   *******************************/
     219  
     220  #ifdef HAVE_SYS_STAT_H
     221  #include <sys/stat.h>
     222  #elif defined(HAVE_STAT_H)
     223  #include <stat.h>
     224  #endif
     225  
     226  #ifndef S_IFMT
     227  /* VisualAge C/C++ Failed to Define MountType Field in sys/stat.h */
     228  #define S_IFMT 0170000
     229  #endif
     230  
     231  #ifndef S_IFLNK
     232  /* Windows doesn't define S_IFLNK but posixmodule.c maps
     233   * IO_REPARSE_TAG_SYMLINK to S_IFLNK */
     234  #  define S_IFLNK 0120000
     235  #endif
     236  
     237  #ifndef S_ISREG
     238  #define S_ISREG(x) (((x) & S_IFMT) == S_IFREG)
     239  #endif
     240  
     241  #ifndef S_ISDIR
     242  #define S_ISDIR(x) (((x) & S_IFMT) == S_IFDIR)
     243  #endif
     244  
     245  #ifndef S_ISCHR
     246  #define S_ISCHR(x) (((x) & S_IFMT) == S_IFCHR)
     247  #endif
     248  
     249  #ifndef S_ISLNK
     250  #define S_ISLNK(x) (((x) & S_IFMT) == S_IFLNK)
     251  #endif
     252  
     253  #ifdef __cplusplus
     254  /* Move this down here since some C++ #include's don't like to be included
     255     inside an extern "C" */
     256  extern "C" {
     257  #endif
     258  
     259  
     260  /* Py_ARITHMETIC_RIGHT_SHIFT
     261   * C doesn't define whether a right-shift of a signed integer sign-extends
     262   * or zero-fills.  Here a macro to force sign extension:
     263   * Py_ARITHMETIC_RIGHT_SHIFT(TYPE, I, J)
     264   *    Return I >> J, forcing sign extension.  Arithmetically, return the
     265   *    floor of I/2**J.
     266   * Requirements:
     267   *    I should have signed integer type.  In the terminology of C99, this can
     268   *    be either one of the five standard signed integer types (signed char,
     269   *    short, int, long, long long) or an extended signed integer type.
     270   *    J is an integer >= 0 and strictly less than the number of bits in the
     271   *    type of I (because C doesn't define what happens for J outside that
     272   *    range either).
     273   *    TYPE used to specify the type of I, but is now ignored.  It's been left
     274   *    in for backwards compatibility with versions <= 2.6 or 3.0.
     275   * Caution:
     276   *    I may be evaluated more than once.
     277   */
     278  #ifdef SIGNED_RIGHT_SHIFT_ZERO_FILLS
     279  #define Py_ARITHMETIC_RIGHT_SHIFT(TYPE, I, J) \
     280      ((I) < 0 ? -1-((-1-(I)) >> (J)) : (I) >> (J))
     281  #else
     282  #define Py_ARITHMETIC_RIGHT_SHIFT(TYPE, I, J) ((I) >> (J))
     283  #endif
     284  
     285  /* Py_FORCE_EXPANSION(X)
     286   * "Simply" returns its argument.  However, macro expansions within the
     287   * argument are evaluated.  This unfortunate trickery is needed to get
     288   * token-pasting to work as desired in some cases.
     289   */
     290  #define Py_FORCE_EXPANSION(X) X
     291  
     292  /* Py_SAFE_DOWNCAST(VALUE, WIDE, NARROW)
     293   * Cast VALUE to type NARROW from type WIDE.  In Py_DEBUG mode, this
     294   * assert-fails if any information is lost.
     295   * Caution:
     296   *    VALUE may be evaluated more than once.
     297   */
     298  #ifdef Py_DEBUG
     299  #  define Py_SAFE_DOWNCAST(VALUE, WIDE, NARROW) \
     300         (assert(_Py_STATIC_CAST(WIDE, _Py_STATIC_CAST(NARROW, (VALUE))) == (VALUE)), \
     301          _Py_STATIC_CAST(NARROW, (VALUE)))
     302  #else
     303  #  define Py_SAFE_DOWNCAST(VALUE, WIDE, NARROW) _Py_STATIC_CAST(NARROW, (VALUE))
     304  #endif
     305  
     306  
     307  /* Py_DEPRECATED(version)
     308   * Declare a variable, type, or function deprecated.
     309   * The macro must be placed before the declaration.
     310   * Usage:
     311   *    Py_DEPRECATED(3.3) extern int old_var;
     312   *    Py_DEPRECATED(3.4) typedef int T1;
     313   *    Py_DEPRECATED(3.8) PyAPI_FUNC(int) Py_OldFunction(void);
     314   */
     315  #if defined(__GNUC__) \
     316      && ((__GNUC__ >= 4) || (__GNUC__ == 3) && (__GNUC_MINOR__ >= 1))
     317  #define Py_DEPRECATED(VERSION_UNUSED) __attribute__((__deprecated__))
     318  #elif defined(_MSC_VER)
     319  #define Py_DEPRECATED(VERSION) __declspec(deprecated( \
     320                                            "deprecated in " #VERSION))
     321  #else
     322  #define Py_DEPRECATED(VERSION_UNUSED)
     323  #endif
     324  
     325  // _Py_DEPRECATED_EXTERNALLY(version)
     326  // Deprecated outside CPython core.
     327  #ifdef Py_BUILD_CORE
     328  #define _Py_DEPRECATED_EXTERNALLY(VERSION_UNUSED)
     329  #else
     330  #define _Py_DEPRECATED_EXTERNALLY(version) Py_DEPRECATED(version)
     331  #endif
     332  
     333  
     334  #if defined(__clang__)
     335  #define _Py_COMP_DIAG_PUSH _Pragma("clang diagnostic push")
     336  #define _Py_COMP_DIAG_IGNORE_DEPR_DECLS \
     337      _Pragma("clang diagnostic ignored \"-Wdeprecated-declarations\"")
     338  #define _Py_COMP_DIAG_POP _Pragma("clang diagnostic pop")
     339  #elif defined(__GNUC__) \
     340      && ((__GNUC__ >= 5) || (__GNUC__ == 4) && (__GNUC_MINOR__ >= 6))
     341  #define _Py_COMP_DIAG_PUSH _Pragma("GCC diagnostic push")
     342  #define _Py_COMP_DIAG_IGNORE_DEPR_DECLS \
     343      _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
     344  #define _Py_COMP_DIAG_POP _Pragma("GCC diagnostic pop")
     345  #elif defined(_MSC_VER)
     346  #define _Py_COMP_DIAG_PUSH __pragma(warning(push))
     347  #define _Py_COMP_DIAG_IGNORE_DEPR_DECLS __pragma(warning(disable: 4996))
     348  #define _Py_COMP_DIAG_POP __pragma(warning(pop))
     349  #else
     350  #define _Py_COMP_DIAG_PUSH
     351  #define _Py_COMP_DIAG_IGNORE_DEPR_DECLS
     352  #define _Py_COMP_DIAG_POP
     353  #endif
     354  
     355  /* _Py_HOT_FUNCTION
     356   * The hot attribute on a function is used to inform the compiler that the
     357   * function is a hot spot of the compiled program. The function is optimized
     358   * more aggressively and on many target it is placed into special subsection of
     359   * the text section so all hot functions appears close together improving
     360   * locality.
     361   *
     362   * Usage:
     363   *    int _Py_HOT_FUNCTION x(void) { return 3; }
     364   *
     365   * Issue #28618: This attribute must not be abused, otherwise it can have a
     366   * negative effect on performance. Only the functions were Python spend most of
     367   * its time must use it. Use a profiler when running performance benchmark
     368   * suite to find these functions.
     369   */
     370  #if defined(__GNUC__) \
     371      && ((__GNUC__ >= 5) || (__GNUC__ == 4) && (__GNUC_MINOR__ >= 3))
     372  #define _Py_HOT_FUNCTION __attribute__((hot))
     373  #else
     374  #define _Py_HOT_FUNCTION
     375  #endif
     376  
     377  // Ask the compiler to always inline a static inline function. The compiler can
     378  // ignore it and decides to not inline the function.
     379  //
     380  // It can be used to inline performance critical static inline functions when
     381  // building Python in debug mode with function inlining disabled. For example,
     382  // MSC disables function inlining when building in debug mode.
     383  //
     384  // Marking blindly a static inline function with Py_ALWAYS_INLINE can result in
     385  // worse performances (due to increased code size for example). The compiler is
     386  // usually smarter than the developer for the cost/benefit analysis.
     387  //
     388  // If Python is built in debug mode (if the Py_DEBUG macro is defined), the
     389  // Py_ALWAYS_INLINE macro does nothing.
     390  //
     391  // It must be specified before the function return type. Usage:
     392  //
     393  //     static inline Py_ALWAYS_INLINE int random(void) { return 4; }
     394  #if defined(Py_DEBUG)
     395     // If Python is built in debug mode, usually compiler optimizations are
     396     // disabled. In this case, Py_ALWAYS_INLINE can increase a lot the stack
     397     // memory usage. For example, forcing inlining using gcc -O0 increases the
     398     // stack usage from 6 KB to 15 KB per Python function call.
     399  #  define Py_ALWAYS_INLINE
     400  #elif defined(__GNUC__) || defined(__clang__) || defined(__INTEL_COMPILER)
     401  #  define Py_ALWAYS_INLINE __attribute__((always_inline))
     402  #elif defined(_MSC_VER)
     403  #  define Py_ALWAYS_INLINE __forceinline
     404  #else
     405  #  define Py_ALWAYS_INLINE
     406  #endif
     407  
     408  // Py_NO_INLINE
     409  // Disable inlining on a function. For example, it reduces the C stack
     410  // consumption: useful on LTO+PGO builds which heavily inline code (see
     411  // bpo-33720).
     412  //
     413  // Usage:
     414  //
     415  //    Py_NO_INLINE static int random(void) { return 4; }
     416  #if defined(__GNUC__) || defined(__clang__) || defined(__INTEL_COMPILER)
     417  #  define Py_NO_INLINE __attribute__ ((noinline))
     418  #elif defined(_MSC_VER)
     419  #  define Py_NO_INLINE __declspec(noinline)
     420  #else
     421  #  define Py_NO_INLINE
     422  #endif
     423  
     424  /**************************************************************************
     425  Prototypes that are missing from the standard include files on some systems
     426  (and possibly only some versions of such systems.)
     427  
     428  Please be conservative with adding new ones, document them and enclose them
     429  in platform-specific #ifdefs.
     430  **************************************************************************/
     431  
     432  #ifdef HAVE__GETPTY
     433  #include <sys/types.h>          /* we need to import mode_t */
     434  extern char * _getpty(int *, int, mode_t, int);
     435  #endif
     436  
     437  /* On QNX 6, struct termio must be declared by including sys/termio.h
     438     if TCGETA, TCSETA, TCSETAW, or TCSETAF are used.  sys/termio.h must
     439     be included before termios.h or it will generate an error. */
     440  #if defined(HAVE_SYS_TERMIO_H) && !defined(__hpux)
     441  #include <sys/termio.h>
     442  #endif
     443  
     444  
     445  /* On 4.4BSD-descendants, ctype functions serves the whole range of
     446   * wchar_t character set rather than single byte code points only.
     447   * This characteristic can break some operations of string object
     448   * including str.upper() and str.split() on UTF-8 locales.  This
     449   * workaround was provided by Tim Robbins of FreeBSD project.
     450   */
     451  
     452  #if defined(__APPLE__)
     453  #  define _PY_PORT_CTYPE_UTF8_ISSUE
     454  #endif
     455  
     456  #ifdef _PY_PORT_CTYPE_UTF8_ISSUE
     457  #ifndef __cplusplus
     458     /* The workaround below is unsafe in C++ because
     459      * the <locale> defines these symbols as real functions,
     460      * with a slightly different signature.
     461      * See issue #10910
     462      */
     463  #include <ctype.h>
     464  #include <wctype.h>
     465  #undef isalnum
     466  #define isalnum(c) iswalnum(btowc(c))
     467  #undef isalpha
     468  #define isalpha(c) iswalpha(btowc(c))
     469  #undef islower
     470  #define islower(c) iswlower(btowc(c))
     471  #undef isspace
     472  #define isspace(c) iswspace(btowc(c))
     473  #undef isupper
     474  #define isupper(c) iswupper(btowc(c))
     475  #undef tolower
     476  #define tolower(c) towlower(btowc(c))
     477  #undef toupper
     478  #define toupper(c) towupper(btowc(c))
     479  #endif
     480  #endif
     481  
     482  
     483  /* Declarations for symbol visibility.
     484  
     485    PyAPI_FUNC(type): Declares a public Python API function and return type
     486    PyAPI_DATA(type): Declares public Python data and its type
     487    PyMODINIT_FUNC:   A Python module init function.  If these functions are
     488                      inside the Python core, they are private to the core.
     489                      If in an extension module, it may be declared with
     490                      external linkage depending on the platform.
     491  
     492    As a number of platforms support/require "__declspec(dllimport/dllexport)",
     493    we support a HAVE_DECLSPEC_DLL macro to save duplication.
     494  */
     495  
     496  /*
     497    All windows ports, except cygwin, are handled in PC/pyconfig.h.
     498  
     499    Cygwin is the only other autoconf platform requiring special
     500    linkage handling and it uses __declspec().
     501  */
     502  #if defined(__CYGWIN__)
     503  #       define HAVE_DECLSPEC_DLL
     504  #endif
     505  
     506  #include "exports.h"
     507  
     508  /* only get special linkage if built as shared or platform is Cygwin */
     509  #if defined(Py_ENABLE_SHARED) || defined(__CYGWIN__)
     510  #       if defined(HAVE_DECLSPEC_DLL)
     511  #               if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
     512  #                       define PyAPI_FUNC(RTYPE) Py_EXPORTED_SYMBOL RTYPE
     513  #                       define PyAPI_DATA(RTYPE) extern Py_EXPORTED_SYMBOL RTYPE
     514          /* module init functions inside the core need no external linkage */
     515          /* except for Cygwin to handle embedding */
     516  #                       if defined(__CYGWIN__)
     517  #                               define PyMODINIT_FUNC Py_EXPORTED_SYMBOL PyObject*
     518  #                       else /* __CYGWIN__ */
     519  #                               define PyMODINIT_FUNC PyObject*
     520  #                       endif /* __CYGWIN__ */
     521  #               else /* Py_BUILD_CORE */
     522          /* Building an extension module, or an embedded situation */
     523          /* public Python functions and data are imported */
     524          /* Under Cygwin, auto-import functions to prevent compilation */
     525          /* failures similar to those described at the bottom of 4.1: */
     526          /* http://docs.python.org/extending/windows.html#a-cookbook-approach */
     527  #                       if !defined(__CYGWIN__)
     528  #                               define PyAPI_FUNC(RTYPE) Py_IMPORTED_SYMBOL RTYPE
     529  #                       endif /* !__CYGWIN__ */
     530  #                       define PyAPI_DATA(RTYPE) extern Py_IMPORTED_SYMBOL RTYPE
     531          /* module init functions outside the core must be exported */
     532  #                       if defined(__cplusplus)
     533  #                               define PyMODINIT_FUNC extern "C" Py_EXPORTED_SYMBOL PyObject*
     534  #                       else /* __cplusplus */
     535  #                               define PyMODINIT_FUNC Py_EXPORTED_SYMBOL PyObject*
     536  #                       endif /* __cplusplus */
     537  #               endif /* Py_BUILD_CORE */
     538  #       endif /* HAVE_DECLSPEC_DLL */
     539  #endif /* Py_ENABLE_SHARED */
     540  
     541  /* If no external linkage macros defined by now, create defaults */
     542  #ifndef PyAPI_FUNC
     543  #       define PyAPI_FUNC(RTYPE) Py_EXPORTED_SYMBOL RTYPE
     544  #endif
     545  #ifndef PyAPI_DATA
     546  #       define PyAPI_DATA(RTYPE) extern Py_EXPORTED_SYMBOL RTYPE
     547  #endif
     548  #ifndef PyMODINIT_FUNC
     549  #       if defined(__cplusplus)
     550  #               define PyMODINIT_FUNC extern "C" Py_EXPORTED_SYMBOL PyObject*
     551  #       else /* __cplusplus */
     552  #               define PyMODINIT_FUNC Py_EXPORTED_SYMBOL PyObject*
     553  #       endif /* __cplusplus */
     554  #endif
     555  
     556  /* limits.h constants that may be missing */
     557  
     558  #ifndef INT_MAX
     559  #define INT_MAX 2147483647
     560  #endif
     561  
     562  #ifndef LONG_MAX
     563  #if SIZEOF_LONG == 4
     564  #define LONG_MAX 0X7FFFFFFFL
     565  #elif SIZEOF_LONG == 8
     566  #define LONG_MAX 0X7FFFFFFFFFFFFFFFL
     567  #else
     568  #error "could not set LONG_MAX in pyport.h"
     569  #endif
     570  #endif
     571  
     572  #ifndef LONG_MIN
     573  #define LONG_MIN (-LONG_MAX-1)
     574  #endif
     575  
     576  #ifndef LONG_BIT
     577  #define LONG_BIT (8 * SIZEOF_LONG)
     578  #endif
     579  
     580  #if LONG_BIT != 8 * SIZEOF_LONG
     581  /* 04-Oct-2000 LONG_BIT is apparently (mis)defined as 64 on some recent
     582   * 32-bit platforms using gcc.  We try to catch that here at compile-time
     583   * rather than waiting for integer multiplication to trigger bogus
     584   * overflows.
     585   */
     586  #error "LONG_BIT definition appears wrong for platform (bad gcc/glibc config?)."
     587  #endif
     588  
     589  #ifdef __cplusplus
     590  }
     591  #endif
     592  
     593  /*
     594   * Hide GCC attributes from compilers that don't support them.
     595   */
     596  #if (!defined(__GNUC__) || __GNUC__ < 2 || \
     597       (__GNUC__ == 2 && __GNUC_MINOR__ < 7) )
     598  #define Py_GCC_ATTRIBUTE(x)
     599  #else
     600  #define Py_GCC_ATTRIBUTE(x) __attribute__(x)
     601  #endif
     602  
     603  /*
     604   * Specify alignment on compilers that support it.
     605   */
     606  #if defined(__GNUC__) && __GNUC__ >= 3
     607  #define Py_ALIGNED(x) __attribute__((aligned(x)))
     608  #else
     609  #define Py_ALIGNED(x)
     610  #endif
     611  
     612  /* Eliminate end-of-loop code not reached warnings from SunPro C
     613   * when using do{...}while(0) macros
     614   */
     615  #ifdef __SUNPRO_C
     616  #pragma error_messages (off,E_END_OF_LOOP_CODE_NOT_REACHED)
     617  #endif
     618  
     619  #ifndef Py_LL
     620  #define Py_LL(x) x##LL
     621  #endif
     622  
     623  #ifndef Py_ULL
     624  #define Py_ULL(x) Py_LL(x##U)
     625  #endif
     626  
     627  #define Py_VA_COPY va_copy
     628  
     629  /*
     630   * Convenient macros to deal with endianness of the platform. WORDS_BIGENDIAN is
     631   * detected by configure and defined in pyconfig.h. The code in pyconfig.h
     632   * also takes care of Apple's universal builds.
     633   */
     634  
     635  #ifdef WORDS_BIGENDIAN
     636  #  define PY_BIG_ENDIAN 1
     637  #  define PY_LITTLE_ENDIAN 0
     638  #else
     639  #  define PY_BIG_ENDIAN 0
     640  #  define PY_LITTLE_ENDIAN 1
     641  #endif
     642  
     643  #ifdef __ANDROID__
     644     /* The Android langinfo.h header is not used. */
     645  #  undef HAVE_LANGINFO_H
     646  #  undef CODESET
     647  #endif
     648  
     649  /* Maximum value of the Windows DWORD type */
     650  #define PY_DWORD_MAX 4294967295U
     651  
     652  /* This macro used to tell whether Python was built with multithreading
     653   * enabled.  Now multithreading is always enabled, but keep the macro
     654   * for compatibility.
     655   */
     656  #ifndef WITH_THREAD
     657  #  define WITH_THREAD
     658  #endif
     659  
     660  #ifdef WITH_THREAD
     661  #  ifdef Py_BUILD_CORE
     662  #    ifdef HAVE_THREAD_LOCAL
     663  #      error "HAVE_THREAD_LOCAL is already defined"
     664  #    endif
     665  #    define HAVE_THREAD_LOCAL 1
     666  #    ifdef thread_local
     667  #      define _Py_thread_local thread_local
     668  #    elif __STDC_VERSION__ >= 201112L && !defined(__STDC_NO_THREADS__)
     669  #      define _Py_thread_local _Thread_local
     670  #    elif defined(_MSC_VER)  /* AKA NT_THREADS */
     671  #      define _Py_thread_local __declspec(thread)
     672  #    elif defined(__GNUC__)  /* includes clang */
     673  #      define _Py_thread_local __thread
     674  #    else
     675         // fall back to the PyThread_tss_*() API, or ignore.
     676  #      undef HAVE_THREAD_LOCAL
     677  #    endif
     678  #  endif
     679  #endif
     680  
     681  /* Check that ALT_SOABI is consistent with Py_TRACE_REFS:
     682     ./configure --with-trace-refs should must be used to define Py_TRACE_REFS */
     683  #if defined(ALT_SOABI) && defined(Py_TRACE_REFS)
     684  #  error "Py_TRACE_REFS ABI is not compatible with release and debug ABI"
     685  #endif
     686  
     687  #if defined(__ANDROID__) || defined(__VXWORKS__)
     688     // Use UTF-8 as the locale encoding, ignore the LC_CTYPE locale.
     689     // See _Py_GetLocaleEncoding(), PyUnicode_DecodeLocale()
     690     // and PyUnicode_EncodeLocale().
     691  #  define _Py_FORCE_UTF8_LOCALE
     692  #endif
     693  
     694  #if defined(_Py_FORCE_UTF8_LOCALE) || defined(__APPLE__)
     695     // Use UTF-8 as the filesystem encoding.
     696     // See PyUnicode_DecodeFSDefaultAndSize(), PyUnicode_EncodeFSDefault(),
     697     // Py_DecodeLocale() and Py_EncodeLocale().
     698  #  define _Py_FORCE_UTF8_FS_ENCODING
     699  #endif
     700  
     701  /* Mark a function which cannot return. Example:
     702     PyAPI_FUNC(void) _Py_NO_RETURN PyThread_exit_thread(void);
     703  
     704     XLC support is intentionally omitted due to bpo-40244 */
     705  #ifndef _Py_NO_RETURN
     706  #if defined(__clang__) || \
     707      (defined(__GNUC__) && \
     708       ((__GNUC__ >= 3) || \
     709        (__GNUC__ == 2) && (__GNUC_MINOR__ >= 5)))
     710  #  define _Py_NO_RETURN __attribute__((__noreturn__))
     711  #elif defined(_MSC_VER)
     712  #  define _Py_NO_RETURN __declspec(noreturn)
     713  #else
     714  #  define _Py_NO_RETURN
     715  #endif
     716  #endif
     717  
     718  
     719  // Preprocessor check for a builtin preprocessor function. Always return 0
     720  // if __has_builtin() macro is not defined.
     721  //
     722  // __has_builtin() is available on clang and GCC 10.
     723  #ifdef __has_builtin
     724  #  define _Py__has_builtin(x) __has_builtin(x)
     725  #else
     726  #  define _Py__has_builtin(x) 0
     727  #endif
     728  
     729  // _Py_TYPEOF(expr) gets the type of an expression.
     730  //
     731  // Example: _Py_TYPEOF(x) x_copy = (x);
     732  //
     733  // The macro is only defined if GCC or clang compiler is used.
     734  #if defined(__GNUC__) || defined(__clang__)
     735  #  define _Py_TYPEOF(expr) __typeof__(expr)
     736  #endif
     737  
     738  
     739  /* A convenient way for code to know if sanitizers are enabled. */
     740  #if defined(__has_feature)
     741  #  if __has_feature(memory_sanitizer)
     742  #    if !defined(_Py_MEMORY_SANITIZER)
     743  #      define _Py_MEMORY_SANITIZER
     744  #    endif
     745  #  endif
     746  #  if __has_feature(address_sanitizer)
     747  #    if !defined(_Py_ADDRESS_SANITIZER)
     748  #      define _Py_ADDRESS_SANITIZER
     749  #    endif
     750  #  endif
     751  #elif defined(__GNUC__)
     752  #  if defined(__SANITIZE_ADDRESS__)
     753  #    define _Py_ADDRESS_SANITIZER
     754  #  endif
     755  #endif
     756  
     757  
     758  /* AIX has __bool__ redefined in it's system header file. */
     759  #if defined(_AIX) && defined(__bool__)
     760  #undef __bool__
     761  #endif
     762  
     763  // Make sure we have maximum alignment, even if the current compiler
     764  // does not support max_align_t. Note that:
     765  // - Autoconf reports alignment of unknown types to 0.
     766  // - 'long double' has maximum alignment on *most* platforms,
     767  //   looks like the best we can do for pre-C11 compilers.
     768  // - The value is tested, see test_alignof_max_align_t
     769  #if !defined(ALIGNOF_MAX_ALIGN_T) || ALIGNOF_MAX_ALIGN_T == 0
     770  #   undef ALIGNOF_MAX_ALIGN_T
     771  #   define ALIGNOF_MAX_ALIGN_T _Alignof(long double)
     772  #endif
     773  
     774  #endif /* Py_PYPORT_H */