Where Online Learning is simpler!
The C and C++ Include Header Files
cat -n /usr/include/python3.14/pyport.h
1 #ifndef Py_PYPORT_H 2 #define Py_PYPORT_H 3 4 #ifndef UCHAR_MAX 5 # error "<limits.h> header must define UCHAR_MAX" 6 #endif 7 #if UCHAR_MAX != 255 8 # error "Python's source code assumes C's unsigned char is an 8-bit type" 9 #endif 10 11 12 // Preprocessor check for a builtin preprocessor function. Always return 0 13 // if __has_builtin() macro is not defined. 14 // 15 // __has_builtin() is available on clang and GCC 10. 16 #ifdef __has_builtin 17 # define _Py__has_builtin(x) __has_builtin(x) 18 #else 19 # define _Py__has_builtin(x) 0 20 #endif 21 22 // Preprocessor check for a compiler __attribute__. Always return 0 23 // if __has_attribute() macro is not defined. 24 #ifdef __has_attribute 25 # define _Py__has_attribute(x) __has_attribute(x) 26 #else 27 # define _Py__has_attribute(x) 0 28 #endif 29 30 // Macro to use C++ static_cast<> in the Python C API. 31 #ifdef __cplusplus 32 # define _Py_STATIC_CAST(type, expr) static_cast<type>(expr) 33 #else 34 # define _Py_STATIC_CAST(type, expr) ((type)(expr)) 35 #endif 36 // Macro to use the more powerful/dangerous C-style cast even in C++. 37 #define _Py_CAST(type, expr) ((type)(expr)) 38 39 // Cast a function to another function type T. 40 // 41 // The macro first casts the function to the "void func(void)" type 42 // to prevent compiler warnings. 43 // 44 // Note that using this cast only prevents the compiler from emitting 45 // warnings, but does not prevent an undefined behavior at runtime if 46 // the original function signature is not respected. 47 #define _Py_FUNC_CAST(T, func) _Py_CAST(T, _Py_CAST(void(*)(void), (func))) 48 49 // Static inline functions should use _Py_NULL rather than using directly NULL 50 // to prevent C++ compiler warnings. On C23 and newer and on C++11 and newer, 51 // _Py_NULL is defined as nullptr. 52 #if !defined(_MSC_VER) && \ 53 ((defined (__STDC_VERSION__) && __STDC_VERSION__ >= 202311L) \ 54 || (defined(__cplusplus) && __cplusplus >= 201103)) 55 # define _Py_NULL nullptr 56 #else 57 # define _Py_NULL NULL 58 #endif 59 60 61 /* Defines to build Python and its standard library: 62 * 63 * - Py_BUILD_CORE: Build Python core. Give access to Python internals, but 64 * should not be used by third-party modules. 65 * - Py_BUILD_CORE_BUILTIN: Build a Python stdlib module as a built-in module. 66 * - Py_BUILD_CORE_MODULE: Build a Python stdlib module as a dynamic library. 67 * 68 * Py_BUILD_CORE_BUILTIN and Py_BUILD_CORE_MODULE imply Py_BUILD_CORE. 69 * 70 * On Windows, Py_BUILD_CORE_MODULE exports "PyInit_xxx" symbol, whereas 71 * Py_BUILD_CORE_BUILTIN does not. 72 */ 73 #if defined(Py_BUILD_CORE_BUILTIN) && !defined(Py_BUILD_CORE) 74 # define Py_BUILD_CORE 75 #endif 76 #if defined(Py_BUILD_CORE_MODULE) && !defined(Py_BUILD_CORE) 77 # define Py_BUILD_CORE 78 #endif 79 80 81 /************************************************************************** 82 Symbols and macros to supply platform-independent interfaces to basic 83 C language & library operations whose spellings vary across platforms. 84 85 Please try to make documentation here as clear as possible: by definition, 86 the stuff here is trying to illuminate C's darkest corners. 87 88 Config #defines referenced here: 89 90 SIGNED_RIGHT_SHIFT_ZERO_FILLS 91 Meaning: To be defined iff i>>j does not extend the sign bit when i is a 92 signed integral type and i < 0. 93 Used in: Py_ARITHMETIC_RIGHT_SHIFT 94 95 Py_DEBUG 96 Meaning: Extra checks compiled in for debug mode. 97 Used in: Py_SAFE_DOWNCAST 98 99 **************************************************************************/ 100 101 /* typedefs for some C9X-defined synonyms for integral types. 102 * 103 * The names in Python are exactly the same as the C9X names, except with a 104 * Py_ prefix. Until C9X is universally implemented, this is the only way 105 * to ensure that Python gets reliable names that don't conflict with names 106 * in non-Python code that are playing their own tricks to define the C9X 107 * names. 108 * 109 * NOTE: don't go nuts here! Python has no use for *most* of the C9X 110 * integral synonyms. Only define the ones we actually need. 111 */ 112 113 /* long long is required. Ensure HAVE_LONG_LONG is defined for compatibility. */ 114 #ifndef HAVE_LONG_LONG 115 #define HAVE_LONG_LONG 1 116 #endif 117 #ifndef PY_LONG_LONG 118 #define PY_LONG_LONG long long 119 /* If LLONG_MAX is defined in limits.h, use that. */ 120 #define PY_LLONG_MIN LLONG_MIN 121 #define PY_LLONG_MAX LLONG_MAX 122 #define PY_ULLONG_MAX ULLONG_MAX 123 #endif 124 125 #define PY_UINT32_T uint32_t 126 #define PY_UINT64_T uint64_t 127 128 /* Signed variants of the above */ 129 #define PY_INT32_T int32_t 130 #define PY_INT64_T int64_t 131 132 /* PYLONG_BITS_IN_DIGIT describes the number of bits per "digit" (limb) in the 133 * PyLongObject implementation (longintrepr.h). It's currently either 30 or 15, 134 * defaulting to 30. The 15-bit digit option may be removed in the future. 135 */ 136 #ifndef PYLONG_BITS_IN_DIGIT 137 #define PYLONG_BITS_IN_DIGIT 30 138 #endif 139 140 /* uintptr_t is the C9X name for an unsigned integral type such that a 141 * legitimate void* can be cast to uintptr_t and then back to void* again 142 * without loss of information. Similarly for intptr_t, wrt a signed 143 * integral type. 144 */ 145 typedef uintptr_t Py_uintptr_t; 146 typedef intptr_t Py_intptr_t; 147 148 /* Py_ssize_t is a signed integral type such that sizeof(Py_ssize_t) == 149 * sizeof(size_t). C99 doesn't define such a thing directly (size_t is an 150 * unsigned integral type). See PEP 353 for details. 151 * PY_SSIZE_T_MAX is the largest positive value of type Py_ssize_t. 152 */ 153 #ifdef HAVE_PY_SSIZE_T 154 155 #elif HAVE_SSIZE_T 156 typedef ssize_t Py_ssize_t; 157 # define PY_SSIZE_T_MAX SSIZE_MAX 158 #elif SIZEOF_VOID_P == SIZEOF_SIZE_T 159 typedef Py_intptr_t Py_ssize_t; 160 # define PY_SSIZE_T_MAX INTPTR_MAX 161 #else 162 # error "Python needs a typedef for Py_ssize_t in pyport.h." 163 #endif 164 165 /* Smallest negative value of type Py_ssize_t. */ 166 #define PY_SSIZE_T_MIN (-PY_SSIZE_T_MAX-1) 167 168 /* Py_hash_t is the same size as a pointer. */ 169 #define SIZEOF_PY_HASH_T SIZEOF_SIZE_T 170 typedef Py_ssize_t Py_hash_t; 171 /* Py_uhash_t is the unsigned equivalent needed to calculate numeric hash. */ 172 #define SIZEOF_PY_UHASH_T SIZEOF_SIZE_T 173 typedef size_t Py_uhash_t; 174 175 /* Now PY_SSIZE_T_CLEAN is mandatory. This is just for backward compatibility. */ 176 typedef Py_ssize_t Py_ssize_clean_t; 177 178 /* Largest possible value of size_t. */ 179 #define PY_SIZE_MAX SIZE_MAX 180 181 /* Macro kept for backward compatibility: use directly "z" in new code. 182 * 183 * PY_FORMAT_SIZE_T is a modifier for use in a printf format to convert an 184 * argument with the width of a size_t or Py_ssize_t: "z" (C99). 185 */ 186 #ifndef PY_FORMAT_SIZE_T 187 # define PY_FORMAT_SIZE_T "z" 188 #endif 189 190 /* Py_LOCAL can be used instead of static to get the fastest possible calling 191 * convention for functions that are local to a given module. 192 * 193 * Py_LOCAL_INLINE does the same thing, and also explicitly requests inlining, 194 * for platforms that support that. 195 * 196 * NOTE: You can only use this for functions that are entirely local to a 197 * module; functions that are exported via method tables, callbacks, etc, 198 * should keep using static. 199 */ 200 201 #if defined(_MSC_VER) 202 /* ignore warnings if the compiler decides not to inline a function */ 203 # pragma warning(disable: 4710) 204 /* fastest possible local call under MSVC */ 205 # define Py_LOCAL(type) static type __fastcall 206 # define Py_LOCAL_INLINE(type) static __inline type __fastcall 207 #else 208 # define Py_LOCAL(type) static type 209 # define Py_LOCAL_INLINE(type) static inline type 210 #endif 211 212 // Soft deprecated since Python 3.14, use memcpy() instead. 213 #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 < 0x030b0000 214 # define Py_MEMCPY memcpy 215 #endif 216 217 #ifdef __cplusplus 218 /* Move this down here since some C++ #include's don't like to be included 219 inside an extern "C" */ 220 extern "C" { 221 #endif 222 223 224 /* Py_ARITHMETIC_RIGHT_SHIFT 225 * C doesn't define whether a right-shift of a signed integer sign-extends 226 * or zero-fills. Here a macro to force sign extension: 227 * Py_ARITHMETIC_RIGHT_SHIFT(TYPE, I, J) 228 * Return I >> J, forcing sign extension. Arithmetically, return the 229 * floor of I/2**J. 230 * Requirements: 231 * I should have signed integer type. In the terminology of C99, this can 232 * be either one of the five standard signed integer types (signed char, 233 * short, int, long, long long) or an extended signed integer type. 234 * J is an integer >= 0 and strictly less than the number of bits in the 235 * type of I (because C doesn't define what happens for J outside that 236 * range either). 237 * TYPE used to specify the type of I, but is now ignored. It's been left 238 * in for backwards compatibility with versions <= 2.6 or 3.0. 239 * Caution: 240 * I may be evaluated more than once. 241 */ 242 #ifdef SIGNED_RIGHT_SHIFT_ZERO_FILLS 243 #define Py_ARITHMETIC_RIGHT_SHIFT(TYPE, I, J) \ 244 ((I) < 0 ? -1-((-1-(I)) >> (J)) : (I) >> (J)) 245 #else 246 #define Py_ARITHMETIC_RIGHT_SHIFT(TYPE, I, J) ((I) >> (J)) 247 #endif 248 249 /* Py_FORCE_EXPANSION(X) 250 * "Simply" returns its argument. However, macro expansions within the 251 * argument are evaluated. This unfortunate trickery is needed to get 252 * token-pasting to work as desired in some cases. 253 */ 254 #define Py_FORCE_EXPANSION(X) X 255 256 /* Py_SAFE_DOWNCAST(VALUE, WIDE, NARROW) 257 * Cast VALUE to type NARROW from type WIDE. In Py_DEBUG mode, this 258 * assert-fails if any information is lost. 259 * Caution: 260 * VALUE may be evaluated more than once. 261 */ 262 #ifdef Py_DEBUG 263 # define Py_SAFE_DOWNCAST(VALUE, WIDE, NARROW) \ 264 (assert(_Py_STATIC_CAST(WIDE, _Py_STATIC_CAST(NARROW, (VALUE))) == (VALUE)), \ 265 _Py_STATIC_CAST(NARROW, (VALUE))) 266 #else 267 # define Py_SAFE_DOWNCAST(VALUE, WIDE, NARROW) _Py_STATIC_CAST(NARROW, (VALUE)) 268 #endif 269 270 271 /* Py_DEPRECATED(version) 272 * Declare a variable, type, or function deprecated. 273 * The macro must be placed before the declaration. 274 * Usage: 275 * Py_DEPRECATED(3.3) extern int old_var; 276 * Py_DEPRECATED(3.4) typedef int T1; 277 * Py_DEPRECATED(3.8) PyAPI_FUNC(int) Py_OldFunction(void); 278 */ 279 #if defined(__GNUC__) \ 280 && ((__GNUC__ >= 4) || (__GNUC__ == 3) && (__GNUC_MINOR__ >= 1)) 281 #define Py_DEPRECATED(VERSION_UNUSED) __attribute__((__deprecated__)) 282 #elif defined(_MSC_VER) 283 #define Py_DEPRECATED(VERSION) __declspec(deprecated( \ 284 "deprecated in " #VERSION)) 285 #else 286 #define Py_DEPRECATED(VERSION_UNUSED) 287 #endif 288 289 // _Py_DEPRECATED_EXTERNALLY(version) 290 // Deprecated outside CPython core. 291 #ifdef Py_BUILD_CORE 292 #define _Py_DEPRECATED_EXTERNALLY(VERSION_UNUSED) 293 #else 294 #define _Py_DEPRECATED_EXTERNALLY(version) Py_DEPRECATED(version) 295 #endif 296 297 298 #if defined(__clang__) 299 #define _Py_COMP_DIAG_PUSH _Pragma("clang diagnostic push") 300 #define _Py_COMP_DIAG_IGNORE_DEPR_DECLS \ 301 _Pragma("clang diagnostic ignored \"-Wdeprecated-declarations\"") 302 #define _Py_COMP_DIAG_POP _Pragma("clang diagnostic pop") 303 #elif defined(__GNUC__) \ 304 && ((__GNUC__ >= 5) || (__GNUC__ == 4) && (__GNUC_MINOR__ >= 6)) 305 #define _Py_COMP_DIAG_PUSH _Pragma("GCC diagnostic push") 306 #define _Py_COMP_DIAG_IGNORE_DEPR_DECLS \ 307 _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"") 308 #define _Py_COMP_DIAG_POP _Pragma("GCC diagnostic pop") 309 #elif defined(_MSC_VER) 310 #define _Py_COMP_DIAG_PUSH __pragma(warning(push)) 311 #define _Py_COMP_DIAG_IGNORE_DEPR_DECLS __pragma(warning(disable: 4996)) 312 #define _Py_COMP_DIAG_POP __pragma(warning(pop)) 313 #else 314 #define _Py_COMP_DIAG_PUSH 315 #define _Py_COMP_DIAG_IGNORE_DEPR_DECLS 316 #define _Py_COMP_DIAG_POP 317 #endif 318 319 /* _Py_HOT_FUNCTION 320 * The hot attribute on a function is used to inform the compiler that the 321 * function is a hot spot of the compiled program. The function is optimized 322 * more aggressively and on many target it is placed into special subsection of 323 * the text section so all hot functions appears close together improving 324 * locality. 325 * 326 * Usage: 327 * int _Py_HOT_FUNCTION x(void) { return 3; } 328 * 329 * Issue #28618: This attribute must not be abused, otherwise it can have a 330 * negative effect on performance. Only the functions were Python spend most of 331 * its time must use it. Use a profiler when running performance benchmark 332 * suite to find these functions. 333 */ 334 #if defined(__GNUC__) \ 335 && ((__GNUC__ >= 5) || (__GNUC__ == 4) && (__GNUC_MINOR__ >= 3)) 336 #define _Py_HOT_FUNCTION __attribute__((hot)) 337 #else 338 #define _Py_HOT_FUNCTION 339 #endif 340 341 // Ask the compiler to always inline a static inline function. The compiler can 342 // ignore it and decides to not inline the function. 343 // 344 // It can be used to inline performance critical static inline functions when 345 // building Python in debug mode with function inlining disabled. For example, 346 // MSC disables function inlining when building in debug mode. 347 // 348 // Marking blindly a static inline function with Py_ALWAYS_INLINE can result in 349 // worse performances (due to increased code size for example). The compiler is 350 // usually smarter than the developer for the cost/benefit analysis. 351 // 352 // If Python is built in debug mode (if the Py_DEBUG macro is defined), the 353 // Py_ALWAYS_INLINE macro does nothing. 354 // 355 // It must be specified before the function return type. Usage: 356 // 357 // static inline Py_ALWAYS_INLINE int random(void) { return 4; } 358 #if defined(Py_DEBUG) 359 // If Python is built in debug mode, usually compiler optimizations are 360 // disabled. In this case, Py_ALWAYS_INLINE can increase a lot the stack 361 // memory usage. For example, forcing inlining using gcc -O0 increases the 362 // stack usage from 6 KB to 15 KB per Python function call. 363 # define Py_ALWAYS_INLINE 364 #elif defined(__GNUC__) || defined(__clang__) || defined(__INTEL_COMPILER) 365 # define Py_ALWAYS_INLINE __attribute__((always_inline)) 366 #elif defined(_MSC_VER) 367 # define Py_ALWAYS_INLINE __forceinline 368 #else 369 # define Py_ALWAYS_INLINE 370 #endif 371 372 // Py_NO_INLINE 373 // Disable inlining on a function. For example, it reduces the C stack 374 // consumption: useful on LTO+PGO builds which heavily inline code (see 375 // bpo-33720). 376 // 377 // Usage: 378 // 379 // Py_NO_INLINE static int random(void) { return 4; } 380 #if defined(__GNUC__) || defined(__clang__) || defined(__INTEL_COMPILER) 381 # define Py_NO_INLINE __attribute__ ((noinline)) 382 #elif defined(_MSC_VER) 383 # define Py_NO_INLINE __declspec(noinline) 384 #else 385 # define Py_NO_INLINE 386 #endif 387 388 #include "exports.h" 389 390 #ifdef Py_LIMITED_API 391 // The internal C API must not be used with the limited C API: make sure 392 // that Py_BUILD_CORE macro is not defined in this case. These 3 macros are 393 // used by exports.h, so only undefine them afterwards. 394 # undef Py_BUILD_CORE 395 # undef Py_BUILD_CORE_BUILTIN 396 # undef Py_BUILD_CORE_MODULE 397 #endif 398 399 /* limits.h constants that may be missing */ 400 401 #ifndef INT_MAX 402 #define INT_MAX 2147483647 403 #endif 404 405 #ifndef LONG_MAX 406 #if SIZEOF_LONG == 4 407 #define LONG_MAX 0X7FFFFFFFL 408 #elif SIZEOF_LONG == 8 409 #define LONG_MAX 0X7FFFFFFFFFFFFFFFL 410 #else 411 #error "could not set LONG_MAX in pyport.h" 412 #endif 413 #endif 414 415 #ifndef LONG_MIN 416 #define LONG_MIN (-LONG_MAX-1) 417 #endif 418 419 #ifndef LONG_BIT 420 #define LONG_BIT (8 * SIZEOF_LONG) 421 #endif 422 423 #if LONG_BIT != 8 * SIZEOF_LONG 424 /* 04-Oct-2000 LONG_BIT is apparently (mis)defined as 64 on some recent 425 * 32-bit platforms using gcc. We try to catch that here at compile-time 426 * rather than waiting for integer multiplication to trigger bogus 427 * overflows. 428 */ 429 #error "LONG_BIT definition appears wrong for platform (bad gcc/glibc config?)." 430 #endif 431 432 #ifdef __cplusplus 433 } 434 #endif 435 436 /* 437 * Hide GCC attributes from compilers that don't support them. 438 */ 439 #if (!defined(__GNUC__) || __GNUC__ < 2 || \ 440 (__GNUC__ == 2 && __GNUC_MINOR__ < 7) ) 441 #define Py_GCC_ATTRIBUTE(x) 442 #else 443 #define Py_GCC_ATTRIBUTE(x) __attribute__(x) 444 #endif 445 446 /* 447 * Specify alignment on compilers that support it. 448 */ 449 #if defined(__GNUC__) && __GNUC__ >= 3 450 #define Py_ALIGNED(x) __attribute__((aligned(x))) 451 #else 452 #define Py_ALIGNED(x) 453 #endif 454 455 /* Eliminate end-of-loop code not reached warnings from SunPro C 456 * when using do{...}while(0) macros 457 */ 458 #ifdef __SUNPRO_C 459 #pragma error_messages (off,E_END_OF_LOOP_CODE_NOT_REACHED) 460 #endif 461 462 #ifndef Py_LL 463 #define Py_LL(x) x##LL 464 #endif 465 466 #ifndef Py_ULL 467 #define Py_ULL(x) Py_LL(x##U) 468 #endif 469 470 #define Py_VA_COPY va_copy 471 472 /* 473 * Convenient macros to deal with endianness of the platform. WORDS_BIGENDIAN is 474 * detected by configure and defined in pyconfig.h. The code in pyconfig.h 475 * also takes care of Apple's universal builds. 476 */ 477 478 #ifdef WORDS_BIGENDIAN 479 # define PY_BIG_ENDIAN 1 480 # define PY_LITTLE_ENDIAN 0 481 #else 482 # define PY_BIG_ENDIAN 0 483 # define PY_LITTLE_ENDIAN 1 484 #endif 485 486 #ifdef __ANDROID__ 487 /* The Android langinfo.h header is not used. */ 488 # undef HAVE_LANGINFO_H 489 # undef CODESET 490 #endif 491 492 /* Maximum value of the Windows DWORD type */ 493 #define PY_DWORD_MAX 4294967295U 494 495 /* This macro used to tell whether Python was built with multithreading 496 * enabled. Now multithreading is always enabled, but keep the macro 497 * for compatibility. 498 */ 499 #ifndef WITH_THREAD 500 # define WITH_THREAD 501 #endif 502 503 /* Some WebAssembly platforms do not provide a working pthread implementation. 504 * Thread support is stubbed and any attempt to create a new thread fails. 505 */ 506 #if (!defined(HAVE_PTHREAD_STUBS) && \ 507 (!defined(__EMSCRIPTEN__) || defined(__EMSCRIPTEN_PTHREADS__))) 508 # define Py_CAN_START_THREADS 1 509 #endif 510 511 #ifdef WITH_THREAD 512 # ifdef Py_BUILD_CORE 513 # ifdef HAVE_THREAD_LOCAL 514 # error "HAVE_THREAD_LOCAL is already defined" 515 # endif 516 # define HAVE_THREAD_LOCAL 1 517 # ifdef thread_local 518 # define _Py_thread_local thread_local 519 # elif __STDC_VERSION__ >= 201112L && !defined(__STDC_NO_THREADS__) 520 # define _Py_thread_local _Thread_local 521 # elif defined(_MSC_VER) /* AKA NT_THREADS */ 522 # define _Py_thread_local __declspec(thread) 523 # elif defined(__GNUC__) /* includes clang */ 524 # define _Py_thread_local __thread 525 # else 526 // fall back to the PyThread_tss_*() API, or ignore. 527 # undef HAVE_THREAD_LOCAL 528 # endif 529 # endif 530 #endif 531 532 #if defined(__ANDROID__) || defined(__VXWORKS__) 533 // Use UTF-8 as the locale encoding, ignore the LC_CTYPE locale. 534 // See _Py_GetLocaleEncoding(), PyUnicode_DecodeLocale() 535 // and PyUnicode_EncodeLocale(). 536 # define _Py_FORCE_UTF8_LOCALE 537 #endif 538 539 #if defined(_Py_FORCE_UTF8_LOCALE) || defined(__APPLE__) 540 // Use UTF-8 as the filesystem encoding. 541 // See PyUnicode_DecodeFSDefaultAndSize(), PyUnicode_EncodeFSDefault(), 542 // Py_DecodeLocale() and Py_EncodeLocale(). 543 # define _Py_FORCE_UTF8_FS_ENCODING 544 #endif 545 546 /* Mark a function which cannot return. Example: 547 PyAPI_FUNC(void) _Py_NO_RETURN PyThread_exit_thread(void); 548 549 XLC support is intentionally omitted due to bpo-40244 */ 550 #ifndef _Py_NO_RETURN 551 #if defined(__clang__) || \ 552 (defined(__GNUC__) && \ 553 ((__GNUC__ >= 3) || \ 554 (__GNUC__ == 2) && (__GNUC_MINOR__ >= 5))) 555 # define _Py_NO_RETURN __attribute__((__noreturn__)) 556 #elif defined(_MSC_VER) 557 # define _Py_NO_RETURN __declspec(noreturn) 558 #else 559 # define _Py_NO_RETURN 560 #endif 561 #endif 562 563 564 // _Py_TYPEOF(expr) gets the type of an expression. 565 // 566 // Example: _Py_TYPEOF(x) x_copy = (x); 567 // 568 // The macro is only defined if GCC or clang compiler is used. 569 #if defined(__GNUC__) || defined(__clang__) 570 # define _Py_TYPEOF(expr) __typeof__(expr) 571 #endif 572 573 574 /* A convenient way for code to know if sanitizers are enabled. */ 575 #if defined(__has_feature) 576 # if __has_feature(memory_sanitizer) 577 # if !defined(_Py_MEMORY_SANITIZER) 578 # define _Py_MEMORY_SANITIZER 579 # define _Py_NO_SANITIZE_MEMORY __attribute__((no_sanitize_memory)) 580 # endif 581 # endif 582 # if __has_feature(address_sanitizer) 583 # if !defined(_Py_ADDRESS_SANITIZER) 584 # define _Py_ADDRESS_SANITIZER 585 # define _Py_NO_SANITIZE_ADDRESS __attribute__((no_sanitize_address)) 586 # endif 587 # endif 588 # if __has_feature(thread_sanitizer) 589 # if !defined(_Py_THREAD_SANITIZER) 590 # define _Py_THREAD_SANITIZER 591 # define _Py_NO_SANITIZE_THREAD __attribute__((no_sanitize_thread)) 592 # endif 593 # endif 594 #elif defined(__GNUC__) 595 # if defined(__SANITIZE_ADDRESS__) 596 # define _Py_ADDRESS_SANITIZER 597 # define _Py_NO_SANITIZE_ADDRESS __attribute__((no_sanitize_address)) 598 # endif 599 # if defined(__SANITIZE_THREAD__) 600 # define _Py_THREAD_SANITIZER 601 # define _Py_NO_SANITIZE_THREAD __attribute__((no_sanitize_thread)) 602 # elif __GNUC__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1) 603 // TSAN is supported since GCC 5.1, but __SANITIZE_THREAD__ macro 604 // is provided only since GCC 7. 605 # define _Py_NO_SANITIZE_THREAD __attribute__((no_sanitize_thread)) 606 # endif 607 #endif 608 609 #ifndef _Py_NO_SANITIZE_ADDRESS 610 # define _Py_NO_SANITIZE_ADDRESS 611 #endif 612 #ifndef _Py_NO_SANITIZE_THREAD 613 # define _Py_NO_SANITIZE_THREAD 614 #endif 615 #ifndef _Py_NO_SANITIZE_MEMORY 616 # define _Py_NO_SANITIZE_MEMORY 617 #endif 618 619 /* AIX has __bool__ redefined in it's system header file. */ 620 #if defined(_AIX) && defined(__bool__) 621 #undef __bool__ 622 #endif 623 624 // Make sure we have maximum alignment, even if the current compiler 625 // does not support max_align_t. Note that: 626 // - Autoconf reports alignment of unknown types to 0. 627 // - 'long double' has maximum alignment on *most* platforms, 628 // looks like the best we can do for pre-C11 compilers. 629 // - The value is tested, see test_alignof_max_align_t 630 #if !defined(ALIGNOF_MAX_ALIGN_T) || ALIGNOF_MAX_ALIGN_T == 0 631 # undef ALIGNOF_MAX_ALIGN_T 632 # define ALIGNOF_MAX_ALIGN_T _Alignof(long double) 633 #endif 634 635 #ifndef PY_CXX_CONST 636 # ifdef __cplusplus 637 # define PY_CXX_CONST const 638 # else 639 # define PY_CXX_CONST 640 # endif 641 #endif 642 643 #if defined(__sgi) && !defined(_SGI_MP_SOURCE) 644 # define _SGI_MP_SOURCE 645 #endif 646 647 // Explicit fallthrough in switch case to avoid warnings 648 // with compiler flag -Wimplicit-fallthrough. 649 // 650 // Usage example: 651 // 652 // switch (value) { 653 // case 1: _Py_FALLTHROUGH; 654 // case 2: code; break; 655 // } 656 // 657 // __attribute__((fallthrough)) was introduced in GCC 7 and Clang 10 / 658 // Apple Clang 12.0. Earlier Clang versions support only the C++11 659 // style fallthrough attribute, not the GCC extension syntax used here, 660 // and __has_attribute(fallthrough) evaluates to 1. 661 #if _Py__has_attribute(fallthrough) && (!defined(__clang__) || \ 662 (!defined(__apple_build_version__) && __clang_major__ >= 10) || \ 663 (defined(__apple_build_version__) && __clang_major__ >= 12)) 664 # define _Py_FALLTHROUGH __attribute__((fallthrough)) 665 #else 666 # define _Py_FALLTHROUGH do { } while (0) 667 #endif 668 669 670 // _Py_NO_SANITIZE_UNDEFINED(): Disable Undefined Behavior sanitizer (UBsan) 671 // on a function. 672 // 673 // Clang and GCC 9.0+ use __attribute__((no_sanitize("undefined"))). 674 // GCC 4.9+ uses __attribute__((no_sanitize_undefined)). 675 #if defined(__has_feature) 676 # if __has_feature(undefined_behavior_sanitizer) 677 # define _Py_NO_SANITIZE_UNDEFINED __attribute__((no_sanitize("undefined"))) 678 # endif 679 #endif 680 #if !defined(_Py_NO_SANITIZE_UNDEFINED) && defined(__GNUC__) \ 681 && ((__GNUC__ >= 5) || (__GNUC__ == 4) && (__GNUC_MINOR__ >= 9)) 682 # define _Py_NO_SANITIZE_UNDEFINED __attribute__((no_sanitize_undefined)) 683 #endif 684 #ifndef _Py_NO_SANITIZE_UNDEFINED 685 # define _Py_NO_SANITIZE_UNDEFINED 686 #endif 687 688 689 // _Py_NONSTRING: The nonstring variable attribute specifies that an object or 690 // member declaration with type array of char, signed char, or unsigned char, 691 // or pointer to such a type is intended to store character arrays that do not 692 // necessarily contain a terminating NUL. 693 // 694 // Usage: 695 // 696 // char name [8] _Py_NONSTRING; 697 #if _Py__has_attribute(nonstring) 698 # define _Py_NONSTRING __attribute__((nonstring)) 699 #else 700 # define _Py_NONSTRING 701 #endif 702 703 704 // Assume the stack grows down unless specified otherwise 705 #ifndef _Py_STACK_GROWS_DOWN 706 # define _Py_STACK_GROWS_DOWN 1 707 #endif 708 709 710 #endif /* Py_PYPORT_H */