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