File indexing completed on 2025-11-19 09:50:54
0001 #ifndef Py_PYPORT_H
0002 #define Py_PYPORT_H
0003
0004 #ifndef UCHAR_MAX
0005 # error "<limits.h> header must define UCHAR_MAX"
0006 #endif
0007 #if UCHAR_MAX != 255
0008 # error "Python's source code assumes C's unsigned char is an 8-bit type"
0009 #endif
0010
0011
0012
0013 #ifdef __cplusplus
0014 # define _Py_STATIC_CAST(type, expr) static_cast<type>(expr)
0015 #else
0016 # define _Py_STATIC_CAST(type, expr) ((type)(expr))
0017 #endif
0018
0019 #define _Py_CAST(type, expr) ((type)(expr))
0020
0021
0022
0023
0024 #if (defined (__STDC_VERSION__) && __STDC_VERSION__ > 201710L) \
0025 || (defined(__cplusplus) && __cplusplus >= 201103)
0026 # define _Py_NULL nullptr
0027 #else
0028 # define _Py_NULL NULL
0029 #endif
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044 #if defined(Py_BUILD_CORE_BUILTIN) && !defined(Py_BUILD_CORE)
0045 # define Py_BUILD_CORE
0046 #endif
0047 #if defined(Py_BUILD_CORE_MODULE) && !defined(Py_BUILD_CORE)
0048 # define Py_BUILD_CORE
0049 #endif
0050
0051
0052
0053
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 #ifndef HAVE_LONG_LONG
0086 #define HAVE_LONG_LONG 1
0087 #endif
0088 #ifndef PY_LONG_LONG
0089 #define PY_LONG_LONG long long
0090
0091 #define PY_LLONG_MIN LLONG_MIN
0092 #define PY_LLONG_MAX LLONG_MAX
0093 #define PY_ULLONG_MAX ULLONG_MAX
0094 #endif
0095
0096 #define PY_UINT32_T uint32_t
0097 #define PY_UINT64_T uint64_t
0098
0099
0100 #define PY_INT32_T int32_t
0101 #define PY_INT64_T int64_t
0102
0103
0104
0105
0106
0107 #ifndef PYLONG_BITS_IN_DIGIT
0108 #define PYLONG_BITS_IN_DIGIT 30
0109 #endif
0110
0111
0112
0113
0114
0115
0116 typedef uintptr_t Py_uintptr_t;
0117 typedef intptr_t Py_intptr_t;
0118
0119
0120
0121
0122
0123
0124 #ifdef HAVE_PY_SSIZE_T
0125
0126 #elif HAVE_SSIZE_T
0127 typedef ssize_t Py_ssize_t;
0128 # define PY_SSIZE_T_MAX SSIZE_MAX
0129 #elif SIZEOF_VOID_P == SIZEOF_SIZE_T
0130 typedef Py_intptr_t Py_ssize_t;
0131 # define PY_SSIZE_T_MAX INTPTR_MAX
0132 #else
0133 # error "Python needs a typedef for Py_ssize_t in pyport.h."
0134 #endif
0135
0136
0137 #define PY_SSIZE_T_MIN (-PY_SSIZE_T_MAX-1)
0138
0139
0140 #define SIZEOF_PY_HASH_T SIZEOF_SIZE_T
0141 typedef Py_ssize_t Py_hash_t;
0142
0143 #define SIZEOF_PY_UHASH_T SIZEOF_SIZE_T
0144 typedef size_t Py_uhash_t;
0145
0146
0147 typedef Py_ssize_t Py_ssize_clean_t;
0148
0149
0150 #define PY_SIZE_MAX SIZE_MAX
0151
0152
0153
0154
0155
0156
0157 #ifndef PY_FORMAT_SIZE_T
0158 # define PY_FORMAT_SIZE_T "z"
0159 #endif
0160
0161
0162
0163
0164
0165
0166
0167
0168
0169
0170
0171
0172 #if defined(_MSC_VER)
0173
0174 # pragma warning(disable: 4710)
0175
0176 # define Py_LOCAL(type) static type __fastcall
0177 # define Py_LOCAL_INLINE(type) static __inline type __fastcall
0178 #else
0179 # define Py_LOCAL(type) static type
0180 # define Py_LOCAL_INLINE(type) static inline type
0181 #endif
0182
0183 #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 < 0x030b0000
0184 # define Py_MEMCPY memcpy
0185 #endif
0186
0187 #ifdef __cplusplus
0188
0189
0190 extern "C" {
0191 #endif
0192
0193
0194
0195
0196
0197
0198
0199
0200
0201
0202
0203
0204
0205
0206
0207
0208
0209
0210
0211
0212 #ifdef SIGNED_RIGHT_SHIFT_ZERO_FILLS
0213 #define Py_ARITHMETIC_RIGHT_SHIFT(TYPE, I, J) \
0214 ((I) < 0 ? -1-((-1-(I)) >> (J)) : (I) >> (J))
0215 #else
0216 #define Py_ARITHMETIC_RIGHT_SHIFT(TYPE, I, J) ((I) >> (J))
0217 #endif
0218
0219
0220
0221
0222
0223
0224 #define Py_FORCE_EXPANSION(X) X
0225
0226
0227
0228
0229
0230
0231
0232 #ifdef Py_DEBUG
0233 # define Py_SAFE_DOWNCAST(VALUE, WIDE, NARROW) \
0234 (assert(_Py_STATIC_CAST(WIDE, _Py_STATIC_CAST(NARROW, (VALUE))) == (VALUE)), \
0235 _Py_STATIC_CAST(NARROW, (VALUE)))
0236 #else
0237 # define Py_SAFE_DOWNCAST(VALUE, WIDE, NARROW) _Py_STATIC_CAST(NARROW, (VALUE))
0238 #endif
0239
0240
0241
0242
0243
0244
0245
0246
0247
0248
0249 #if defined(__GNUC__) \
0250 && ((__GNUC__ >= 4) || (__GNUC__ == 3) && (__GNUC_MINOR__ >= 1))
0251 #define Py_DEPRECATED(VERSION_UNUSED) __attribute__((__deprecated__))
0252 #elif defined(_MSC_VER)
0253 #define Py_DEPRECATED(VERSION) __declspec(deprecated( \
0254 "deprecated in " #VERSION))
0255 #else
0256 #define Py_DEPRECATED(VERSION_UNUSED)
0257 #endif
0258
0259
0260
0261 #ifdef Py_BUILD_CORE
0262 #define _Py_DEPRECATED_EXTERNALLY(VERSION_UNUSED)
0263 #else
0264 #define _Py_DEPRECATED_EXTERNALLY(version) Py_DEPRECATED(version)
0265 #endif
0266
0267
0268 #if defined(__clang__)
0269 #define _Py_COMP_DIAG_PUSH _Pragma("clang diagnostic push")
0270 #define _Py_COMP_DIAG_IGNORE_DEPR_DECLS \
0271 _Pragma("clang diagnostic ignored \"-Wdeprecated-declarations\"")
0272 #define _Py_COMP_DIAG_POP _Pragma("clang diagnostic pop")
0273 #elif defined(__GNUC__) \
0274 && ((__GNUC__ >= 5) || (__GNUC__ == 4) && (__GNUC_MINOR__ >= 6))
0275 #define _Py_COMP_DIAG_PUSH _Pragma("GCC diagnostic push")
0276 #define _Py_COMP_DIAG_IGNORE_DEPR_DECLS \
0277 _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
0278 #define _Py_COMP_DIAG_POP _Pragma("GCC diagnostic pop")
0279 #elif defined(_MSC_VER)
0280 #define _Py_COMP_DIAG_PUSH __pragma(warning(push))
0281 #define _Py_COMP_DIAG_IGNORE_DEPR_DECLS __pragma(warning(disable: 4996))
0282 #define _Py_COMP_DIAG_POP __pragma(warning(pop))
0283 #else
0284 #define _Py_COMP_DIAG_PUSH
0285 #define _Py_COMP_DIAG_IGNORE_DEPR_DECLS
0286 #define _Py_COMP_DIAG_POP
0287 #endif
0288
0289
0290
0291
0292
0293
0294
0295
0296
0297
0298
0299
0300
0301
0302
0303
0304 #if defined(__GNUC__) \
0305 && ((__GNUC__ >= 5) || (__GNUC__ == 4) && (__GNUC_MINOR__ >= 3))
0306 #define _Py_HOT_FUNCTION __attribute__((hot))
0307 #else
0308 #define _Py_HOT_FUNCTION
0309 #endif
0310
0311
0312
0313
0314
0315
0316
0317
0318
0319
0320
0321
0322
0323
0324
0325
0326
0327
0328 #if defined(Py_DEBUG)
0329
0330
0331
0332
0333 # define Py_ALWAYS_INLINE
0334 #elif defined(__GNUC__) || defined(__clang__) || defined(__INTEL_COMPILER)
0335 # define Py_ALWAYS_INLINE __attribute__((always_inline))
0336 #elif defined(_MSC_VER)
0337 # define Py_ALWAYS_INLINE __forceinline
0338 #else
0339 # define Py_ALWAYS_INLINE
0340 #endif
0341
0342
0343
0344
0345
0346
0347
0348
0349
0350 #if defined(__GNUC__) || defined(__clang__) || defined(__INTEL_COMPILER)
0351 # define Py_NO_INLINE __attribute__ ((noinline))
0352 #elif defined(_MSC_VER)
0353 # define Py_NO_INLINE __declspec(noinline)
0354 #else
0355 # define Py_NO_INLINE
0356 #endif
0357
0358 #include "exports.h"
0359
0360 #ifdef Py_LIMITED_API
0361
0362
0363
0364 # undef Py_BUILD_CORE
0365 # undef Py_BUILD_CORE_BUILTIN
0366 # undef Py_BUILD_CORE_MODULE
0367 #endif
0368
0369
0370
0371 #ifndef INT_MAX
0372 #define INT_MAX 2147483647
0373 #endif
0374
0375 #ifndef LONG_MAX
0376 #if SIZEOF_LONG == 4
0377 #define LONG_MAX 0X7FFFFFFFL
0378 #elif SIZEOF_LONG == 8
0379 #define LONG_MAX 0X7FFFFFFFFFFFFFFFL
0380 #else
0381 #error "could not set LONG_MAX in pyport.h"
0382 #endif
0383 #endif
0384
0385 #ifndef LONG_MIN
0386 #define LONG_MIN (-LONG_MAX-1)
0387 #endif
0388
0389 #ifndef LONG_BIT
0390 #define LONG_BIT (8 * SIZEOF_LONG)
0391 #endif
0392
0393 #if LONG_BIT != 8 * SIZEOF_LONG
0394
0395
0396
0397
0398
0399 #error "LONG_BIT definition appears wrong for platform (bad gcc/glibc config?)."
0400 #endif
0401
0402 #ifdef __cplusplus
0403 }
0404 #endif
0405
0406
0407
0408
0409 #if (!defined(__GNUC__) || __GNUC__ < 2 || \
0410 (__GNUC__ == 2 && __GNUC_MINOR__ < 7) )
0411 #define Py_GCC_ATTRIBUTE(x)
0412 #else
0413 #define Py_GCC_ATTRIBUTE(x) __attribute__(x)
0414 #endif
0415
0416
0417
0418
0419 #if defined(__GNUC__) && __GNUC__ >= 3
0420 #define Py_ALIGNED(x) __attribute__((aligned(x)))
0421 #else
0422 #define Py_ALIGNED(x)
0423 #endif
0424
0425
0426
0427
0428 #ifdef __SUNPRO_C
0429 #pragma error_messages (off,E_END_OF_LOOP_CODE_NOT_REACHED)
0430 #endif
0431
0432 #ifndef Py_LL
0433 #define Py_LL(x) x##LL
0434 #endif
0435
0436 #ifndef Py_ULL
0437 #define Py_ULL(x) Py_LL(x##U)
0438 #endif
0439
0440 #define Py_VA_COPY va_copy
0441
0442
0443
0444
0445
0446
0447
0448 #ifdef WORDS_BIGENDIAN
0449 # define PY_BIG_ENDIAN 1
0450 # define PY_LITTLE_ENDIAN 0
0451 #else
0452 # define PY_BIG_ENDIAN 0
0453 # define PY_LITTLE_ENDIAN 1
0454 #endif
0455
0456 #ifdef __ANDROID__
0457
0458 # undef HAVE_LANGINFO_H
0459 # undef CODESET
0460 #endif
0461
0462
0463 #define PY_DWORD_MAX 4294967295U
0464
0465
0466
0467
0468
0469 #ifndef WITH_THREAD
0470 # define WITH_THREAD
0471 #endif
0472
0473
0474
0475
0476 #if (!defined(HAVE_PTHREAD_STUBS) && \
0477 (!defined(__EMSCRIPTEN__) || defined(__EMSCRIPTEN_PTHREADS__)))
0478 # define Py_CAN_START_THREADS 1
0479 #endif
0480
0481 #ifdef WITH_THREAD
0482 # ifdef Py_BUILD_CORE
0483 # ifdef HAVE_THREAD_LOCAL
0484 # error "HAVE_THREAD_LOCAL is already defined"
0485 # endif
0486 # define HAVE_THREAD_LOCAL 1
0487 # ifdef thread_local
0488 # define _Py_thread_local thread_local
0489 # elif __STDC_VERSION__ >= 201112L && !defined(__STDC_NO_THREADS__)
0490 # define _Py_thread_local _Thread_local
0491 # elif defined(_MSC_VER)
0492 # define _Py_thread_local __declspec(thread)
0493 # elif defined(__GNUC__)
0494 # define _Py_thread_local __thread
0495 # else
0496
0497 # undef HAVE_THREAD_LOCAL
0498 # endif
0499 # endif
0500 #endif
0501
0502 #if defined(__ANDROID__) || defined(__VXWORKS__)
0503
0504
0505
0506 # define _Py_FORCE_UTF8_LOCALE
0507 #endif
0508
0509 #if defined(_Py_FORCE_UTF8_LOCALE) || defined(__APPLE__)
0510
0511
0512
0513 # define _Py_FORCE_UTF8_FS_ENCODING
0514 #endif
0515
0516
0517
0518
0519
0520 #ifndef _Py_NO_RETURN
0521 #if defined(__clang__) || \
0522 (defined(__GNUC__) && \
0523 ((__GNUC__ >= 3) || \
0524 (__GNUC__ == 2) && (__GNUC_MINOR__ >= 5)))
0525 # define _Py_NO_RETURN __attribute__((__noreturn__))
0526 #elif defined(_MSC_VER)
0527 # define _Py_NO_RETURN __declspec(noreturn)
0528 #else
0529 # define _Py_NO_RETURN
0530 #endif
0531 #endif
0532
0533
0534
0535
0536
0537
0538 #ifdef __has_builtin
0539 # define _Py__has_builtin(x) __has_builtin(x)
0540 #else
0541 # define _Py__has_builtin(x) 0
0542 #endif
0543
0544
0545
0546 #ifdef __has_attribute
0547 # define _Py__has_attribute(x) __has_attribute(x)
0548 #else
0549 # define _Py__has_attribute(x) 0
0550 #endif
0551
0552
0553
0554
0555
0556
0557 #if defined(__GNUC__) || defined(__clang__)
0558 # define _Py_TYPEOF(expr) __typeof__(expr)
0559 #endif
0560
0561
0562
0563 #if defined(__has_feature)
0564 # if __has_feature(memory_sanitizer)
0565 # if !defined(_Py_MEMORY_SANITIZER)
0566 # define _Py_MEMORY_SANITIZER
0567 # endif
0568 # endif
0569 # if __has_feature(address_sanitizer)
0570 # if !defined(_Py_ADDRESS_SANITIZER)
0571 # define _Py_ADDRESS_SANITIZER
0572 # endif
0573 # endif
0574 # if __has_feature(thread_sanitizer)
0575 # if !defined(_Py_THREAD_SANITIZER)
0576 # define _Py_THREAD_SANITIZER
0577 # endif
0578 # endif
0579 #elif defined(__GNUC__)
0580 # if defined(__SANITIZE_ADDRESS__)
0581 # define _Py_ADDRESS_SANITIZER
0582 # endif
0583 # if defined(__SANITIZE_THREAD__)
0584 # define _Py_THREAD_SANITIZER
0585 # endif
0586 #endif
0587
0588
0589
0590 #if defined(_AIX) && defined(__bool__)
0591 #undef __bool__
0592 #endif
0593
0594
0595
0596
0597
0598
0599
0600 #if !defined(ALIGNOF_MAX_ALIGN_T) || ALIGNOF_MAX_ALIGN_T == 0
0601 # undef ALIGNOF_MAX_ALIGN_T
0602 # define ALIGNOF_MAX_ALIGN_T _Alignof(long double)
0603 #endif
0604
0605 #ifndef PY_CXX_CONST
0606 # ifdef __cplusplus
0607 # define PY_CXX_CONST const
0608 # else
0609 # define PY_CXX_CONST
0610 # endif
0611 #endif
0612
0613 #if defined(__sgi) && !defined(_SGI_MP_SOURCE)
0614 # define _SGI_MP_SOURCE
0615 #endif
0616
0617
0618
0619
0620
0621
0622
0623
0624
0625
0626 #if _Py__has_attribute(nonstring)
0627 # define _Py_NONSTRING __attribute__((nonstring))
0628 #else
0629 # define _Py_NONSTRING
0630 #endif
0631
0632
0633 #endif