File indexing completed on 2025-11-03 09:56:43
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 
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 
0024 #define _Py_CAST(type, expr) ((type)(expr))
0025 
0026 
0027 
0028 
0029 #if defined(__cplusplus) && __cplusplus >= 201103
0030 #  define _Py_NULL nullptr
0031 #else
0032 #  define _Py_NULL NULL
0033 #endif
0034 
0035 
0036 
0037 
0038 
0039 
0040 
0041 
0042 
0043 
0044 
0045 
0046 
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 
0058 
0059 
0060 
0061 
0062 
0063 
0064 
0065 
0066 
0067 
0068 
0069 
0070 
0071 
0072 
0073 
0074 
0075 
0076 
0077 
0078 
0079 
0080 
0081 
0082 
0083 
0084 
0085 
0086 
0087 
0088 
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 
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 
0104 #define PY_INT32_T int32_t
0105 #define PY_INT64_T int64_t
0106 
0107 
0108 
0109 
0110 
0111 #ifndef PYLONG_BITS_IN_DIGIT
0112 #define PYLONG_BITS_IN_DIGIT 30
0113 #endif
0114 
0115 
0116 
0117 
0118 
0119 
0120 typedef uintptr_t       Py_uintptr_t;
0121 typedef intptr_t        Py_intptr_t;
0122 
0123 
0124 
0125 
0126 
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 
0141 #define PY_SSIZE_T_MIN (-PY_SSIZE_T_MAX-1)
0142 
0143 
0144 #define SIZEOF_PY_HASH_T SIZEOF_SIZE_T
0145 typedef Py_ssize_t Py_hash_t;
0146 
0147 #define SIZEOF_PY_UHASH_T SIZEOF_SIZE_T
0148 typedef size_t Py_uhash_t;
0149 
0150 
0151 typedef Py_ssize_t Py_ssize_clean_t;
0152 
0153 
0154 #define PY_SIZE_MAX SIZE_MAX
0155 
0156 
0157 
0158 
0159 
0160 
0161 #ifndef PY_FORMAT_SIZE_T
0162 #   define PY_FORMAT_SIZE_T "z"
0163 #endif
0164 
0165 
0166 
0167 
0168 
0169 
0170 
0171 
0172 
0173 
0174 
0175 
0176 #if defined(_MSC_VER)
0177    
0178 #  pragma warning(disable: 4710)
0179    
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 
0199 
0200 
0201 #ifdef HAVE_SYS_TIME_H
0202 #include <sys/time.h>
0203 #endif
0204 #include <time.h>
0205 
0206 
0207 
0208 
0209 
0210 
0211 
0212 #ifdef HAVE_SYS_SELECT_H
0213 #include <sys/select.h>
0214 #endif 
0215 
0216 
0217 
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 
0228 #define S_IFMT 0170000
0229 #endif
0230 
0231 #ifndef S_IFLNK
0232 
0233 
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 
0255 
0256 extern "C" {
0257 #endif
0258 
0259 
0260 
0261 
0262 
0263 
0264 
0265 
0266 
0267 
0268 
0269 
0270 
0271 
0272 
0273 
0274 
0275 
0276 
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 
0286 
0287 
0288 
0289 
0290 #define Py_FORCE_EXPANSION(X) X
0291 
0292 
0293 
0294 
0295 
0296 
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 
0308 
0309 
0310 
0311 
0312 
0313 
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 
0326 
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 
0356 
0357 
0358 
0359 
0360 
0361 
0362 
0363 
0364 
0365 
0366 
0367 
0368 
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 
0378 
0379 
0380 
0381 
0382 
0383 
0384 
0385 
0386 
0387 
0388 
0389 
0390 
0391 
0392 
0393 
0394 #if defined(Py_DEBUG)
0395    
0396    
0397    
0398    
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 
0409 
0410 
0411 
0412 
0413 
0414 
0415 
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 
0426 
0427 
0428 
0429 
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 
0438 
0439 
0440 #if defined(HAVE_SYS_TERMIO_H) && !defined(__hpux)
0441 #include <sys/termio.h>
0442 #endif
0443 
0444 
0445 
0446 
0447 
0448 
0449 
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    
0459 
0460 
0461 
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 
0484 
0485 
0486 
0487 
0488 
0489 
0490 
0491 
0492 
0493 
0494 
0495 
0496 
0497 
0498 
0499 
0500 
0501 
0502 #if defined(__CYGWIN__)
0503 #       define HAVE_DECLSPEC_DLL
0504 #endif
0505 
0506 #include "exports.h"
0507 
0508 
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         
0515         
0516 #                       if defined(__CYGWIN__)
0517 #                               define PyMODINIT_FUNC Py_EXPORTED_SYMBOL PyObject*
0518 #                       else 
0519 #                               define PyMODINIT_FUNC PyObject*
0520 #                       endif 
0521 #               else 
0522         
0523         
0524         
0525         
0526         
0527 #                       if !defined(__CYGWIN__)
0528 #                               define PyAPI_FUNC(RTYPE) Py_IMPORTED_SYMBOL RTYPE
0529 #                       endif 
0530 #                       define PyAPI_DATA(RTYPE) extern Py_IMPORTED_SYMBOL RTYPE
0531         
0532 #                       if defined(__cplusplus)
0533 #                               define PyMODINIT_FUNC extern "C" Py_EXPORTED_SYMBOL PyObject*
0534 #                       else 
0535 #                               define PyMODINIT_FUNC Py_EXPORTED_SYMBOL PyObject*
0536 #                       endif 
0537 #               endif 
0538 #       endif 
0539 #endif 
0540 
0541 
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 
0552 #               define PyMODINIT_FUNC Py_EXPORTED_SYMBOL PyObject*
0553 #       endif 
0554 #endif
0555 
0556 
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 
0582 
0583 
0584 
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 
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 
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 
0613 
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 
0631 
0632 
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    
0645 #  undef HAVE_LANGINFO_H
0646 #  undef CODESET
0647 #endif
0648 
0649 
0650 #define PY_DWORD_MAX 4294967295U
0651 
0652 
0653 
0654 
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)  
0671 #      define _Py_thread_local __declspec(thread)
0672 #    elif defined(__GNUC__)  
0673 #      define _Py_thread_local __thread
0674 #    else
0675        
0676 #      undef HAVE_THREAD_LOCAL
0677 #    endif
0678 #  endif
0679 #endif
0680 
0681 
0682 
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    
0689    
0690    
0691 #  define _Py_FORCE_UTF8_LOCALE
0692 #endif
0693 
0694 #if defined(_Py_FORCE_UTF8_LOCALE) || defined(__APPLE__)
0695    
0696    
0697    
0698 #  define _Py_FORCE_UTF8_FS_ENCODING
0699 #endif
0700 
0701 
0702 
0703 
0704 
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 
0720 
0721 
0722 
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 
0730 
0731 
0732 
0733 
0734 #if defined(__GNUC__) || defined(__clang__)
0735 #  define _Py_TYPEOF(expr) __typeof__(expr)
0736 #endif
0737 
0738 
0739 
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 
0767 #if defined(_AIX) && defined(__bool__)
0768 #undef __bool__
0769 #endif
0770 
0771 
0772 
0773 
0774 
0775 
0776 
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