jpayne@69: #ifndef Py_PYPORT_H jpayne@69: #define Py_PYPORT_H jpayne@69: jpayne@69: #include "pyconfig.h" /* include for defines */ jpayne@69: jpayne@69: #include jpayne@69: jpayne@69: jpayne@69: /* Defines to build Python and its standard library: jpayne@69: * jpayne@69: * - Py_BUILD_CORE: Build Python core. Give access to Python internals, but jpayne@69: * should not be used by third-party modules. jpayne@69: * - Py_BUILD_CORE_BUILTIN: Build a Python stdlib module as a built-in module. jpayne@69: * - Py_BUILD_CORE_MODULE: Build a Python stdlib module as a dynamic library. jpayne@69: * jpayne@69: * Py_BUILD_CORE_BUILTIN and Py_BUILD_CORE_MODULE imply Py_BUILD_CORE. jpayne@69: * jpayne@69: * On Windows, Py_BUILD_CORE_MODULE exports "PyInit_xxx" symbol, whereas jpayne@69: * Py_BUILD_CORE_BUILTIN does not. jpayne@69: */ jpayne@69: #if defined(Py_BUILD_CORE_BUILTIN) && !defined(Py_BUILD_CORE) jpayne@69: # define Py_BUILD_CORE jpayne@69: #endif jpayne@69: #if defined(Py_BUILD_CORE_MODULE) && !defined(Py_BUILD_CORE) jpayne@69: # define Py_BUILD_CORE jpayne@69: #endif jpayne@69: jpayne@69: jpayne@69: /************************************************************************** jpayne@69: Symbols and macros to supply platform-independent interfaces to basic jpayne@69: C language & library operations whose spellings vary across platforms. jpayne@69: jpayne@69: Please try to make documentation here as clear as possible: by definition, jpayne@69: the stuff here is trying to illuminate C's darkest corners. jpayne@69: jpayne@69: Config #defines referenced here: jpayne@69: jpayne@69: SIGNED_RIGHT_SHIFT_ZERO_FILLS jpayne@69: Meaning: To be defined iff i>>j does not extend the sign bit when i is a jpayne@69: signed integral type and i < 0. jpayne@69: Used in: Py_ARITHMETIC_RIGHT_SHIFT jpayne@69: jpayne@69: Py_DEBUG jpayne@69: Meaning: Extra checks compiled in for debug mode. jpayne@69: Used in: Py_SAFE_DOWNCAST jpayne@69: jpayne@69: **************************************************************************/ jpayne@69: jpayne@69: /* typedefs for some C9X-defined synonyms for integral types. jpayne@69: * jpayne@69: * The names in Python are exactly the same as the C9X names, except with a jpayne@69: * Py_ prefix. Until C9X is universally implemented, this is the only way jpayne@69: * to ensure that Python gets reliable names that don't conflict with names jpayne@69: * in non-Python code that are playing their own tricks to define the C9X jpayne@69: * names. jpayne@69: * jpayne@69: * NOTE: don't go nuts here! Python has no use for *most* of the C9X jpayne@69: * integral synonyms. Only define the ones we actually need. jpayne@69: */ jpayne@69: jpayne@69: /* long long is required. Ensure HAVE_LONG_LONG is defined for compatibility. */ jpayne@69: #ifndef HAVE_LONG_LONG jpayne@69: #define HAVE_LONG_LONG 1 jpayne@69: #endif jpayne@69: #ifndef PY_LONG_LONG jpayne@69: #define PY_LONG_LONG long long jpayne@69: /* If LLONG_MAX is defined in limits.h, use that. */ jpayne@69: #define PY_LLONG_MIN LLONG_MIN jpayne@69: #define PY_LLONG_MAX LLONG_MAX jpayne@69: #define PY_ULLONG_MAX ULLONG_MAX jpayne@69: #endif jpayne@69: jpayne@69: #define PY_UINT32_T uint32_t jpayne@69: #define PY_UINT64_T uint64_t jpayne@69: jpayne@69: /* Signed variants of the above */ jpayne@69: #define PY_INT32_T int32_t jpayne@69: #define PY_INT64_T int64_t jpayne@69: jpayne@69: /* If PYLONG_BITS_IN_DIGIT is not defined then we'll use 30-bit digits if all jpayne@69: the necessary integer types are available, and we're on a 64-bit platform jpayne@69: (as determined by SIZEOF_VOID_P); otherwise we use 15-bit digits. */ jpayne@69: jpayne@69: #ifndef PYLONG_BITS_IN_DIGIT jpayne@69: #if SIZEOF_VOID_P >= 8 jpayne@69: #define PYLONG_BITS_IN_DIGIT 30 jpayne@69: #else jpayne@69: #define PYLONG_BITS_IN_DIGIT 15 jpayne@69: #endif jpayne@69: #endif jpayne@69: jpayne@69: /* uintptr_t is the C9X name for an unsigned integral type such that a jpayne@69: * legitimate void* can be cast to uintptr_t and then back to void* again jpayne@69: * without loss of information. Similarly for intptr_t, wrt a signed jpayne@69: * integral type. jpayne@69: */ jpayne@69: typedef uintptr_t Py_uintptr_t; jpayne@69: typedef intptr_t Py_intptr_t; jpayne@69: jpayne@69: /* Py_ssize_t is a signed integral type such that sizeof(Py_ssize_t) == jpayne@69: * sizeof(size_t). C99 doesn't define such a thing directly (size_t is an jpayne@69: * unsigned integral type). See PEP 353 for details. jpayne@69: */ jpayne@69: #ifdef HAVE_SSIZE_T jpayne@69: typedef ssize_t Py_ssize_t; jpayne@69: #elif SIZEOF_VOID_P == SIZEOF_SIZE_T jpayne@69: typedef Py_intptr_t Py_ssize_t; jpayne@69: #else jpayne@69: # error "Python needs a typedef for Py_ssize_t in pyport.h." jpayne@69: #endif jpayne@69: jpayne@69: /* Py_hash_t is the same size as a pointer. */ jpayne@69: #define SIZEOF_PY_HASH_T SIZEOF_SIZE_T jpayne@69: typedef Py_ssize_t Py_hash_t; jpayne@69: /* Py_uhash_t is the unsigned equivalent needed to calculate numeric hash. */ jpayne@69: #define SIZEOF_PY_UHASH_T SIZEOF_SIZE_T jpayne@69: typedef size_t Py_uhash_t; jpayne@69: jpayne@69: /* Only used for compatibility with code that may not be PY_SSIZE_T_CLEAN. */ jpayne@69: #ifdef PY_SSIZE_T_CLEAN jpayne@69: typedef Py_ssize_t Py_ssize_clean_t; jpayne@69: #else jpayne@69: typedef int Py_ssize_clean_t; jpayne@69: #endif jpayne@69: jpayne@69: /* Largest possible value of size_t. */ jpayne@69: #define PY_SIZE_MAX SIZE_MAX jpayne@69: jpayne@69: /* Largest positive value of type Py_ssize_t. */ jpayne@69: #define PY_SSIZE_T_MAX ((Py_ssize_t)(((size_t)-1)>>1)) jpayne@69: /* Smallest negative value of type Py_ssize_t. */ jpayne@69: #define PY_SSIZE_T_MIN (-PY_SSIZE_T_MAX-1) jpayne@69: jpayne@69: /* PY_FORMAT_SIZE_T is a platform-specific modifier for use in a printf jpayne@69: * format to convert an argument with the width of a size_t or Py_ssize_t. jpayne@69: * C99 introduced "z" for this purpose, but not all platforms support that; jpayne@69: * e.g., MS compilers use "I" instead. jpayne@69: * jpayne@69: * These "high level" Python format functions interpret "z" correctly on jpayne@69: * all platforms (Python interprets the format string itself, and does whatever jpayne@69: * the platform C requires to convert a size_t/Py_ssize_t argument): jpayne@69: * jpayne@69: * PyBytes_FromFormat jpayne@69: * PyErr_Format jpayne@69: * PyBytes_FromFormatV jpayne@69: * PyUnicode_FromFormatV jpayne@69: * jpayne@69: * Lower-level uses require that you interpolate the correct format modifier jpayne@69: * yourself (e.g., calling printf, fprintf, sprintf, PyOS_snprintf); for jpayne@69: * example, jpayne@69: * jpayne@69: * Py_ssize_t index; jpayne@69: * fprintf(stderr, "index %" PY_FORMAT_SIZE_T "d sucks\n", index); jpayne@69: * jpayne@69: * That will expand to %ld, or %Id, or to something else correct for a jpayne@69: * Py_ssize_t on the platform. jpayne@69: */ jpayne@69: #ifndef PY_FORMAT_SIZE_T jpayne@69: # if SIZEOF_SIZE_T == SIZEOF_INT && !defined(__APPLE__) jpayne@69: # define PY_FORMAT_SIZE_T "" jpayne@69: # elif SIZEOF_SIZE_T == SIZEOF_LONG jpayne@69: # define PY_FORMAT_SIZE_T "l" jpayne@69: # elif defined(MS_WINDOWS) jpayne@69: # define PY_FORMAT_SIZE_T "I" jpayne@69: # else jpayne@69: # error "This platform's pyconfig.h needs to define PY_FORMAT_SIZE_T" jpayne@69: # endif jpayne@69: #endif jpayne@69: jpayne@69: /* Py_LOCAL can be used instead of static to get the fastest possible calling jpayne@69: * convention for functions that are local to a given module. jpayne@69: * jpayne@69: * Py_LOCAL_INLINE does the same thing, and also explicitly requests inlining, jpayne@69: * for platforms that support that. jpayne@69: * jpayne@69: * If PY_LOCAL_AGGRESSIVE is defined before python.h is included, more jpayne@69: * "aggressive" inlining/optimization is enabled for the entire module. This jpayne@69: * may lead to code bloat, and may slow things down for those reasons. It may jpayne@69: * also lead to errors, if the code relies on pointer aliasing. Use with jpayne@69: * care. jpayne@69: * jpayne@69: * NOTE: You can only use this for functions that are entirely local to a jpayne@69: * module; functions that are exported via method tables, callbacks, etc, jpayne@69: * should keep using static. jpayne@69: */ jpayne@69: jpayne@69: #if defined(_MSC_VER) jpayne@69: # if defined(PY_LOCAL_AGGRESSIVE) jpayne@69: /* enable more aggressive optimization for visual studio */ jpayne@69: # pragma optimize("agtw", on) jpayne@69: #endif jpayne@69: /* ignore warnings if the compiler decides not to inline a function */ jpayne@69: # pragma warning(disable: 4710) jpayne@69: /* fastest possible local call under MSVC */ jpayne@69: # define Py_LOCAL(type) static type __fastcall jpayne@69: # define Py_LOCAL_INLINE(type) static __inline type __fastcall jpayne@69: #else jpayne@69: # define Py_LOCAL(type) static type jpayne@69: # define Py_LOCAL_INLINE(type) static inline type jpayne@69: #endif jpayne@69: jpayne@69: /* Py_MEMCPY is kept for backwards compatibility, jpayne@69: * see https://bugs.python.org/issue28126 */ jpayne@69: #define Py_MEMCPY memcpy jpayne@69: jpayne@69: #include jpayne@69: jpayne@69: #ifdef HAVE_IEEEFP_H jpayne@69: #include /* needed for 'finite' declaration on some platforms */ jpayne@69: #endif jpayne@69: jpayne@69: #include /* Moved here from the math section, before extern "C" */ jpayne@69: jpayne@69: /******************************************** jpayne@69: * WRAPPER FOR and/or * jpayne@69: ********************************************/ jpayne@69: jpayne@69: #ifdef TIME_WITH_SYS_TIME jpayne@69: #include jpayne@69: #include jpayne@69: #else /* !TIME_WITH_SYS_TIME */ jpayne@69: #ifdef HAVE_SYS_TIME_H jpayne@69: #include jpayne@69: #else /* !HAVE_SYS_TIME_H */ jpayne@69: #include jpayne@69: #endif /* !HAVE_SYS_TIME_H */ jpayne@69: #endif /* !TIME_WITH_SYS_TIME */ jpayne@69: jpayne@69: jpayne@69: /****************************** jpayne@69: * WRAPPER FOR * jpayne@69: ******************************/ jpayne@69: jpayne@69: /* NB caller must include */ jpayne@69: jpayne@69: #ifdef HAVE_SYS_SELECT_H jpayne@69: #include jpayne@69: #endif /* !HAVE_SYS_SELECT_H */ jpayne@69: jpayne@69: /******************************* jpayne@69: * stat() and fstat() fiddling * jpayne@69: *******************************/ jpayne@69: jpayne@69: #ifdef HAVE_SYS_STAT_H jpayne@69: #include jpayne@69: #elif defined(HAVE_STAT_H) jpayne@69: #include jpayne@69: #endif jpayne@69: jpayne@69: #ifndef S_IFMT jpayne@69: /* VisualAge C/C++ Failed to Define MountType Field in sys/stat.h */ jpayne@69: #define S_IFMT 0170000 jpayne@69: #endif jpayne@69: jpayne@69: #ifndef S_IFLNK jpayne@69: /* Windows doesn't define S_IFLNK but posixmodule.c maps jpayne@69: * IO_REPARSE_TAG_SYMLINK to S_IFLNK */ jpayne@69: # define S_IFLNK 0120000 jpayne@69: #endif jpayne@69: jpayne@69: #ifndef S_ISREG jpayne@69: #define S_ISREG(x) (((x) & S_IFMT) == S_IFREG) jpayne@69: #endif jpayne@69: jpayne@69: #ifndef S_ISDIR jpayne@69: #define S_ISDIR(x) (((x) & S_IFMT) == S_IFDIR) jpayne@69: #endif jpayne@69: jpayne@69: #ifndef S_ISCHR jpayne@69: #define S_ISCHR(x) (((x) & S_IFMT) == S_IFCHR) jpayne@69: #endif jpayne@69: jpayne@69: #ifdef __cplusplus jpayne@69: /* Move this down here since some C++ #include's don't like to be included jpayne@69: inside an extern "C" */ jpayne@69: extern "C" { jpayne@69: #endif jpayne@69: jpayne@69: jpayne@69: /* Py_ARITHMETIC_RIGHT_SHIFT jpayne@69: * C doesn't define whether a right-shift of a signed integer sign-extends jpayne@69: * or zero-fills. Here a macro to force sign extension: jpayne@69: * Py_ARITHMETIC_RIGHT_SHIFT(TYPE, I, J) jpayne@69: * Return I >> J, forcing sign extension. Arithmetically, return the jpayne@69: * floor of I/2**J. jpayne@69: * Requirements: jpayne@69: * I should have signed integer type. In the terminology of C99, this can jpayne@69: * be either one of the five standard signed integer types (signed char, jpayne@69: * short, int, long, long long) or an extended signed integer type. jpayne@69: * J is an integer >= 0 and strictly less than the number of bits in the jpayne@69: * type of I (because C doesn't define what happens for J outside that jpayne@69: * range either). jpayne@69: * TYPE used to specify the type of I, but is now ignored. It's been left jpayne@69: * in for backwards compatibility with versions <= 2.6 or 3.0. jpayne@69: * Caution: jpayne@69: * I may be evaluated more than once. jpayne@69: */ jpayne@69: #ifdef SIGNED_RIGHT_SHIFT_ZERO_FILLS jpayne@69: #define Py_ARITHMETIC_RIGHT_SHIFT(TYPE, I, J) \ jpayne@69: ((I) < 0 ? -1-((-1-(I)) >> (J)) : (I) >> (J)) jpayne@69: #else jpayne@69: #define Py_ARITHMETIC_RIGHT_SHIFT(TYPE, I, J) ((I) >> (J)) jpayne@69: #endif jpayne@69: jpayne@69: /* Py_FORCE_EXPANSION(X) jpayne@69: * "Simply" returns its argument. However, macro expansions within the jpayne@69: * argument are evaluated. This unfortunate trickery is needed to get jpayne@69: * token-pasting to work as desired in some cases. jpayne@69: */ jpayne@69: #define Py_FORCE_EXPANSION(X) X jpayne@69: jpayne@69: /* Py_SAFE_DOWNCAST(VALUE, WIDE, NARROW) jpayne@69: * Cast VALUE to type NARROW from type WIDE. In Py_DEBUG mode, this jpayne@69: * assert-fails if any information is lost. jpayne@69: * Caution: jpayne@69: * VALUE may be evaluated more than once. jpayne@69: */ jpayne@69: #ifdef Py_DEBUG jpayne@69: #define Py_SAFE_DOWNCAST(VALUE, WIDE, NARROW) \ jpayne@69: (assert((WIDE)(NARROW)(VALUE) == (VALUE)), (NARROW)(VALUE)) jpayne@69: #else jpayne@69: #define Py_SAFE_DOWNCAST(VALUE, WIDE, NARROW) (NARROW)(VALUE) jpayne@69: #endif jpayne@69: jpayne@69: /* Py_SET_ERRNO_ON_MATH_ERROR(x) jpayne@69: * If a libm function did not set errno, but it looks like the result jpayne@69: * overflowed or not-a-number, set errno to ERANGE or EDOM. Set errno jpayne@69: * to 0 before calling a libm function, and invoke this macro after, jpayne@69: * passing the function result. jpayne@69: * Caution: jpayne@69: * This isn't reliable. See Py_OVERFLOWED comments. jpayne@69: * X is evaluated more than once. jpayne@69: */ jpayne@69: #if defined(__FreeBSD__) || defined(__OpenBSD__) || (defined(__hpux) && defined(__ia64)) jpayne@69: #define _Py_SET_EDOM_FOR_NAN(X) if (isnan(X)) errno = EDOM; jpayne@69: #else jpayne@69: #define _Py_SET_EDOM_FOR_NAN(X) ; jpayne@69: #endif jpayne@69: #define Py_SET_ERRNO_ON_MATH_ERROR(X) \ jpayne@69: do { \ jpayne@69: if (errno == 0) { \ jpayne@69: if ((X) == Py_HUGE_VAL || (X) == -Py_HUGE_VAL) \ jpayne@69: errno = ERANGE; \ jpayne@69: else _Py_SET_EDOM_FOR_NAN(X) \ jpayne@69: } \ jpayne@69: } while(0) jpayne@69: jpayne@69: /* Py_SET_ERANGE_IF_OVERFLOW(x) jpayne@69: * An alias of Py_SET_ERRNO_ON_MATH_ERROR for backward-compatibility. jpayne@69: */ jpayne@69: #define Py_SET_ERANGE_IF_OVERFLOW(X) Py_SET_ERRNO_ON_MATH_ERROR(X) jpayne@69: jpayne@69: /* Py_ADJUST_ERANGE1(x) jpayne@69: * Py_ADJUST_ERANGE2(x, y) jpayne@69: * Set errno to 0 before calling a libm function, and invoke one of these jpayne@69: * macros after, passing the function result(s) (Py_ADJUST_ERANGE2 is useful jpayne@69: * for functions returning complex results). This makes two kinds of jpayne@69: * adjustments to errno: (A) If it looks like the platform libm set jpayne@69: * errno=ERANGE due to underflow, clear errno. (B) If it looks like the jpayne@69: * platform libm overflowed but didn't set errno, force errno to ERANGE. In jpayne@69: * effect, we're trying to force a useful implementation of C89 errno jpayne@69: * behavior. jpayne@69: * Caution: jpayne@69: * This isn't reliable. See Py_OVERFLOWED comments. jpayne@69: * X and Y may be evaluated more than once. jpayne@69: */ jpayne@69: #define Py_ADJUST_ERANGE1(X) \ jpayne@69: do { \ jpayne@69: if (errno == 0) { \ jpayne@69: if ((X) == Py_HUGE_VAL || (X) == -Py_HUGE_VAL) \ jpayne@69: errno = ERANGE; \ jpayne@69: } \ jpayne@69: else if (errno == ERANGE && (X) == 0.0) \ jpayne@69: errno = 0; \ jpayne@69: } while(0) jpayne@69: jpayne@69: #define Py_ADJUST_ERANGE2(X, Y) \ jpayne@69: do { \ jpayne@69: if ((X) == Py_HUGE_VAL || (X) == -Py_HUGE_VAL || \ jpayne@69: (Y) == Py_HUGE_VAL || (Y) == -Py_HUGE_VAL) { \ jpayne@69: if (errno == 0) \ jpayne@69: errno = ERANGE; \ jpayne@69: } \ jpayne@69: else if (errno == ERANGE) \ jpayne@69: errno = 0; \ jpayne@69: } while(0) jpayne@69: jpayne@69: /* The functions _Py_dg_strtod and _Py_dg_dtoa in Python/dtoa.c (which are jpayne@69: * required to support the short float repr introduced in Python 3.1) require jpayne@69: * that the floating-point unit that's being used for arithmetic operations jpayne@69: * on C doubles is set to use 53-bit precision. It also requires that the jpayne@69: * FPU rounding mode is round-half-to-even, but that's less often an issue. jpayne@69: * jpayne@69: * If your FPU isn't already set to 53-bit precision/round-half-to-even, and jpayne@69: * you want to make use of _Py_dg_strtod and _Py_dg_dtoa, then you should jpayne@69: * jpayne@69: * #define HAVE_PY_SET_53BIT_PRECISION 1 jpayne@69: * jpayne@69: * and also give appropriate definitions for the following three macros: jpayne@69: * jpayne@69: * _PY_SET_53BIT_PRECISION_START : store original FPU settings, and jpayne@69: * set FPU to 53-bit precision/round-half-to-even jpayne@69: * _PY_SET_53BIT_PRECISION_END : restore original FPU settings jpayne@69: * _PY_SET_53BIT_PRECISION_HEADER : any variable declarations needed to jpayne@69: * use the two macros above. jpayne@69: * jpayne@69: * The macros are designed to be used within a single C function: see jpayne@69: * Python/pystrtod.c for an example of their use. jpayne@69: */ jpayne@69: jpayne@69: /* get and set x87 control word for gcc/x86 */ jpayne@69: #ifdef HAVE_GCC_ASM_FOR_X87 jpayne@69: #define HAVE_PY_SET_53BIT_PRECISION 1 jpayne@69: /* _Py_get/set_387controlword functions are defined in Python/pymath.c */ jpayne@69: #define _Py_SET_53BIT_PRECISION_HEADER \ jpayne@69: unsigned short old_387controlword, new_387controlword jpayne@69: #define _Py_SET_53BIT_PRECISION_START \ jpayne@69: do { \ jpayne@69: old_387controlword = _Py_get_387controlword(); \ jpayne@69: new_387controlword = (old_387controlword & ~0x0f00) | 0x0200; \ jpayne@69: if (new_387controlword != old_387controlword) \ jpayne@69: _Py_set_387controlword(new_387controlword); \ jpayne@69: } while (0) jpayne@69: #define _Py_SET_53BIT_PRECISION_END \ jpayne@69: if (new_387controlword != old_387controlword) \ jpayne@69: _Py_set_387controlword(old_387controlword) jpayne@69: #endif jpayne@69: jpayne@69: /* get and set x87 control word for VisualStudio/x86 */ jpayne@69: #if defined(_MSC_VER) && !defined(_WIN64) && !defined(_M_ARM) /* x87 not supported in 64-bit or ARM */ jpayne@69: #define HAVE_PY_SET_53BIT_PRECISION 1 jpayne@69: #define _Py_SET_53BIT_PRECISION_HEADER \ jpayne@69: unsigned int old_387controlword, new_387controlword, out_387controlword jpayne@69: /* We use the __control87_2 function to set only the x87 control word. jpayne@69: The SSE control word is unaffected. */ jpayne@69: #define _Py_SET_53BIT_PRECISION_START \ jpayne@69: do { \ jpayne@69: __control87_2(0, 0, &old_387controlword, NULL); \ jpayne@69: new_387controlword = \ jpayne@69: (old_387controlword & ~(_MCW_PC | _MCW_RC)) | (_PC_53 | _RC_NEAR); \ jpayne@69: if (new_387controlword != old_387controlword) \ jpayne@69: __control87_2(new_387controlword, _MCW_PC | _MCW_RC, \ jpayne@69: &out_387controlword, NULL); \ jpayne@69: } while (0) jpayne@69: #define _Py_SET_53BIT_PRECISION_END \ jpayne@69: do { \ jpayne@69: if (new_387controlword != old_387controlword) \ jpayne@69: __control87_2(old_387controlword, _MCW_PC | _MCW_RC, \ jpayne@69: &out_387controlword, NULL); \ jpayne@69: } while (0) jpayne@69: #endif jpayne@69: jpayne@69: #ifdef HAVE_GCC_ASM_FOR_MC68881 jpayne@69: #define HAVE_PY_SET_53BIT_PRECISION 1 jpayne@69: #define _Py_SET_53BIT_PRECISION_HEADER \ jpayne@69: unsigned int old_fpcr, new_fpcr jpayne@69: #define _Py_SET_53BIT_PRECISION_START \ jpayne@69: do { \ jpayne@69: __asm__ ("fmove.l %%fpcr,%0" : "=g" (old_fpcr)); \ jpayne@69: /* Set double precision / round to nearest. */ \ jpayne@69: new_fpcr = (old_fpcr & ~0xf0) | 0x80; \ jpayne@69: if (new_fpcr != old_fpcr) \ jpayne@69: __asm__ volatile ("fmove.l %0,%%fpcr" : : "g" (new_fpcr)); \ jpayne@69: } while (0) jpayne@69: #define _Py_SET_53BIT_PRECISION_END \ jpayne@69: do { \ jpayne@69: if (new_fpcr != old_fpcr) \ jpayne@69: __asm__ volatile ("fmove.l %0,%%fpcr" : : "g" (old_fpcr)); \ jpayne@69: } while (0) jpayne@69: #endif jpayne@69: jpayne@69: /* default definitions are empty */ jpayne@69: #ifndef HAVE_PY_SET_53BIT_PRECISION jpayne@69: #define _Py_SET_53BIT_PRECISION_HEADER jpayne@69: #define _Py_SET_53BIT_PRECISION_START jpayne@69: #define _Py_SET_53BIT_PRECISION_END jpayne@69: #endif jpayne@69: jpayne@69: /* If we can't guarantee 53-bit precision, don't use the code jpayne@69: in Python/dtoa.c, but fall back to standard code. This jpayne@69: means that repr of a float will be long (17 sig digits). jpayne@69: jpayne@69: Realistically, there are two things that could go wrong: jpayne@69: jpayne@69: (1) doubles aren't IEEE 754 doubles, or jpayne@69: (2) we're on x86 with the rounding precision set to 64-bits jpayne@69: (extended precision), and we don't know how to change jpayne@69: the rounding precision. jpayne@69: */ jpayne@69: jpayne@69: #if !defined(DOUBLE_IS_LITTLE_ENDIAN_IEEE754) && \ jpayne@69: !defined(DOUBLE_IS_BIG_ENDIAN_IEEE754) && \ jpayne@69: !defined(DOUBLE_IS_ARM_MIXED_ENDIAN_IEEE754) jpayne@69: #define PY_NO_SHORT_FLOAT_REPR jpayne@69: #endif jpayne@69: jpayne@69: /* double rounding is symptomatic of use of extended precision on x86. If jpayne@69: we're seeing double rounding, and we don't have any mechanism available for jpayne@69: changing the FPU rounding precision, then don't use Python/dtoa.c. */ jpayne@69: #if defined(X87_DOUBLE_ROUNDING) && !defined(HAVE_PY_SET_53BIT_PRECISION) jpayne@69: #define PY_NO_SHORT_FLOAT_REPR jpayne@69: #endif jpayne@69: jpayne@69: jpayne@69: /* Py_DEPRECATED(version) jpayne@69: * Declare a variable, type, or function deprecated. jpayne@69: * The macro must be placed before the declaration. jpayne@69: * Usage: jpayne@69: * Py_DEPRECATED(3.3) extern int old_var; jpayne@69: * Py_DEPRECATED(3.4) typedef int T1; jpayne@69: * Py_DEPRECATED(3.8) PyAPI_FUNC(int) Py_OldFunction(void); jpayne@69: */ jpayne@69: #if defined(__GNUC__) \ jpayne@69: && ((__GNUC__ >= 4) || (__GNUC__ == 3) && (__GNUC_MINOR__ >= 1)) jpayne@69: #define Py_DEPRECATED(VERSION_UNUSED) __attribute__((__deprecated__)) jpayne@69: #elif defined(_MSC_VER) jpayne@69: #define Py_DEPRECATED(VERSION) __declspec(deprecated( \ jpayne@69: "deprecated in " #VERSION)) jpayne@69: #else jpayne@69: #define Py_DEPRECATED(VERSION_UNUSED) jpayne@69: #endif jpayne@69: jpayne@69: jpayne@69: /* _Py_HOT_FUNCTION jpayne@69: * The hot attribute on a function is used to inform the compiler that the jpayne@69: * function is a hot spot of the compiled program. The function is optimized jpayne@69: * more aggressively and on many target it is placed into special subsection of jpayne@69: * the text section so all hot functions appears close together improving jpayne@69: * locality. jpayne@69: * jpayne@69: * Usage: jpayne@69: * int _Py_HOT_FUNCTION x(void) { return 3; } jpayne@69: * jpayne@69: * Issue #28618: This attribute must not be abused, otherwise it can have a jpayne@69: * negative effect on performance. Only the functions were Python spend most of jpayne@69: * its time must use it. Use a profiler when running performance benchmark jpayne@69: * suite to find these functions. jpayne@69: */ jpayne@69: #if defined(__GNUC__) \ jpayne@69: && ((__GNUC__ >= 5) || (__GNUC__ == 4) && (__GNUC_MINOR__ >= 3)) jpayne@69: #define _Py_HOT_FUNCTION __attribute__((hot)) jpayne@69: #else jpayne@69: #define _Py_HOT_FUNCTION jpayne@69: #endif jpayne@69: jpayne@69: /* _Py_NO_INLINE jpayne@69: * Disable inlining on a function. For example, it helps to reduce the C stack jpayne@69: * consumption. jpayne@69: * jpayne@69: * Usage: jpayne@69: * int _Py_NO_INLINE x(void) { return 3; } jpayne@69: */ jpayne@69: #if defined(_MSC_VER) jpayne@69: # define _Py_NO_INLINE __declspec(noinline) jpayne@69: #elif defined(__GNUC__) || defined(__clang__) jpayne@69: # define _Py_NO_INLINE __attribute__ ((noinline)) jpayne@69: #else jpayne@69: # define _Py_NO_INLINE jpayne@69: #endif jpayne@69: jpayne@69: /************************************************************************** jpayne@69: Prototypes that are missing from the standard include files on some systems jpayne@69: (and possibly only some versions of such systems.) jpayne@69: jpayne@69: Please be conservative with adding new ones, document them and enclose them jpayne@69: in platform-specific #ifdefs. jpayne@69: **************************************************************************/ jpayne@69: jpayne@69: #ifdef SOLARIS jpayne@69: /* Unchecked */ jpayne@69: extern int gethostname(char *, int); jpayne@69: #endif jpayne@69: jpayne@69: #ifdef HAVE__GETPTY jpayne@69: #include /* we need to import mode_t */ jpayne@69: extern char * _getpty(int *, int, mode_t, int); jpayne@69: #endif jpayne@69: jpayne@69: /* On QNX 6, struct termio must be declared by including sys/termio.h jpayne@69: if TCGETA, TCSETA, TCSETAW, or TCSETAF are used. sys/termio.h must jpayne@69: be included before termios.h or it will generate an error. */ jpayne@69: #if defined(HAVE_SYS_TERMIO_H) && !defined(__hpux) jpayne@69: #include jpayne@69: #endif jpayne@69: jpayne@69: jpayne@69: /* On 4.4BSD-descendants, ctype functions serves the whole range of jpayne@69: * wchar_t character set rather than single byte code points only. jpayne@69: * This characteristic can break some operations of string object jpayne@69: * including str.upper() and str.split() on UTF-8 locales. This jpayne@69: * workaround was provided by Tim Robbins of FreeBSD project. jpayne@69: */ jpayne@69: jpayne@69: #if defined(__APPLE__) jpayne@69: # define _PY_PORT_CTYPE_UTF8_ISSUE jpayne@69: #endif jpayne@69: jpayne@69: #ifdef _PY_PORT_CTYPE_UTF8_ISSUE jpayne@69: #ifndef __cplusplus jpayne@69: /* The workaround below is unsafe in C++ because jpayne@69: * the defines these symbols as real functions, jpayne@69: * with a slightly different signature. jpayne@69: * See issue #10910 jpayne@69: */ jpayne@69: #include jpayne@69: #include jpayne@69: #undef isalnum jpayne@69: #define isalnum(c) iswalnum(btowc(c)) jpayne@69: #undef isalpha jpayne@69: #define isalpha(c) iswalpha(btowc(c)) jpayne@69: #undef islower jpayne@69: #define islower(c) iswlower(btowc(c)) jpayne@69: #undef isspace jpayne@69: #define isspace(c) iswspace(btowc(c)) jpayne@69: #undef isupper jpayne@69: #define isupper(c) iswupper(btowc(c)) jpayne@69: #undef tolower jpayne@69: #define tolower(c) towlower(btowc(c)) jpayne@69: #undef toupper jpayne@69: #define toupper(c) towupper(btowc(c)) jpayne@69: #endif jpayne@69: #endif jpayne@69: jpayne@69: jpayne@69: /* Declarations for symbol visibility. jpayne@69: jpayne@69: PyAPI_FUNC(type): Declares a public Python API function and return type jpayne@69: PyAPI_DATA(type): Declares public Python data and its type jpayne@69: PyMODINIT_FUNC: A Python module init function. If these functions are jpayne@69: inside the Python core, they are private to the core. jpayne@69: If in an extension module, it may be declared with jpayne@69: external linkage depending on the platform. jpayne@69: jpayne@69: As a number of platforms support/require "__declspec(dllimport/dllexport)", jpayne@69: we support a HAVE_DECLSPEC_DLL macro to save duplication. jpayne@69: */ jpayne@69: jpayne@69: /* jpayne@69: All windows ports, except cygwin, are handled in PC/pyconfig.h. jpayne@69: jpayne@69: Cygwin is the only other autoconf platform requiring special jpayne@69: linkage handling and it uses __declspec(). jpayne@69: */ jpayne@69: #if defined(__CYGWIN__) jpayne@69: # define HAVE_DECLSPEC_DLL jpayne@69: #endif jpayne@69: jpayne@69: /* only get special linkage if built as shared or platform is Cygwin */ jpayne@69: #if defined(Py_ENABLE_SHARED) || defined(__CYGWIN__) jpayne@69: # if defined(HAVE_DECLSPEC_DLL) jpayne@69: # if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) jpayne@69: # define PyAPI_FUNC(RTYPE) __declspec(dllexport) RTYPE jpayne@69: # define PyAPI_DATA(RTYPE) extern __declspec(dllexport) RTYPE jpayne@69: /* module init functions inside the core need no external linkage */ jpayne@69: /* except for Cygwin to handle embedding */ jpayne@69: # if defined(__CYGWIN__) jpayne@69: # define PyMODINIT_FUNC __declspec(dllexport) PyObject* jpayne@69: # else /* __CYGWIN__ */ jpayne@69: # define PyMODINIT_FUNC PyObject* jpayne@69: # endif /* __CYGWIN__ */ jpayne@69: # else /* Py_BUILD_CORE */ jpayne@69: /* Building an extension module, or an embedded situation */ jpayne@69: /* public Python functions and data are imported */ jpayne@69: /* Under Cygwin, auto-import functions to prevent compilation */ jpayne@69: /* failures similar to those described at the bottom of 4.1: */ jpayne@69: /* http://docs.python.org/extending/windows.html#a-cookbook-approach */ jpayne@69: # if !defined(__CYGWIN__) jpayne@69: # define PyAPI_FUNC(RTYPE) __declspec(dllimport) RTYPE jpayne@69: # endif /* !__CYGWIN__ */ jpayne@69: # define PyAPI_DATA(RTYPE) extern __declspec(dllimport) RTYPE jpayne@69: /* module init functions outside the core must be exported */ jpayne@69: # if defined(__cplusplus) jpayne@69: # define PyMODINIT_FUNC extern "C" __declspec(dllexport) PyObject* jpayne@69: # else /* __cplusplus */ jpayne@69: # define PyMODINIT_FUNC __declspec(dllexport) PyObject* jpayne@69: # endif /* __cplusplus */ jpayne@69: # endif /* Py_BUILD_CORE */ jpayne@69: # endif /* HAVE_DECLSPEC_DLL */ jpayne@69: #endif /* Py_ENABLE_SHARED */ jpayne@69: jpayne@69: /* If no external linkage macros defined by now, create defaults */ jpayne@69: #ifndef PyAPI_FUNC jpayne@69: # define PyAPI_FUNC(RTYPE) RTYPE jpayne@69: #endif jpayne@69: #ifndef PyAPI_DATA jpayne@69: # define PyAPI_DATA(RTYPE) extern RTYPE jpayne@69: #endif jpayne@69: #ifndef PyMODINIT_FUNC jpayne@69: # if defined(__cplusplus) jpayne@69: # define PyMODINIT_FUNC extern "C" PyObject* jpayne@69: # else /* __cplusplus */ jpayne@69: # define PyMODINIT_FUNC PyObject* jpayne@69: # endif /* __cplusplus */ jpayne@69: #endif jpayne@69: jpayne@69: /* limits.h constants that may be missing */ jpayne@69: jpayne@69: #ifndef INT_MAX jpayne@69: #define INT_MAX 2147483647 jpayne@69: #endif jpayne@69: jpayne@69: #ifndef LONG_MAX jpayne@69: #if SIZEOF_LONG == 4 jpayne@69: #define LONG_MAX 0X7FFFFFFFL jpayne@69: #elif SIZEOF_LONG == 8 jpayne@69: #define LONG_MAX 0X7FFFFFFFFFFFFFFFL jpayne@69: #else jpayne@69: #error "could not set LONG_MAX in pyport.h" jpayne@69: #endif jpayne@69: #endif jpayne@69: jpayne@69: #ifndef LONG_MIN jpayne@69: #define LONG_MIN (-LONG_MAX-1) jpayne@69: #endif jpayne@69: jpayne@69: #ifndef LONG_BIT jpayne@69: #define LONG_BIT (8 * SIZEOF_LONG) jpayne@69: #endif jpayne@69: jpayne@69: #if LONG_BIT != 8 * SIZEOF_LONG jpayne@69: /* 04-Oct-2000 LONG_BIT is apparently (mis)defined as 64 on some recent jpayne@69: * 32-bit platforms using gcc. We try to catch that here at compile-time jpayne@69: * rather than waiting for integer multiplication to trigger bogus jpayne@69: * overflows. jpayne@69: */ jpayne@69: #error "LONG_BIT definition appears wrong for platform (bad gcc/glibc config?)." jpayne@69: #endif jpayne@69: jpayne@69: #ifdef __cplusplus jpayne@69: } jpayne@69: #endif jpayne@69: jpayne@69: /* jpayne@69: * Hide GCC attributes from compilers that don't support them. jpayne@69: */ jpayne@69: #if (!defined(__GNUC__) || __GNUC__ < 2 || \ jpayne@69: (__GNUC__ == 2 && __GNUC_MINOR__ < 7) ) jpayne@69: #define Py_GCC_ATTRIBUTE(x) jpayne@69: #else jpayne@69: #define Py_GCC_ATTRIBUTE(x) __attribute__(x) jpayne@69: #endif jpayne@69: jpayne@69: /* jpayne@69: * Specify alignment on compilers that support it. jpayne@69: */ jpayne@69: #if defined(__GNUC__) && __GNUC__ >= 3 jpayne@69: #define Py_ALIGNED(x) __attribute__((aligned(x))) jpayne@69: #else jpayne@69: #define Py_ALIGNED(x) jpayne@69: #endif jpayne@69: jpayne@69: /* Eliminate end-of-loop code not reached warnings from SunPro C jpayne@69: * when using do{...}while(0) macros jpayne@69: */ jpayne@69: #ifdef __SUNPRO_C jpayne@69: #pragma error_messages (off,E_END_OF_LOOP_CODE_NOT_REACHED) jpayne@69: #endif jpayne@69: jpayne@69: #ifndef Py_LL jpayne@69: #define Py_LL(x) x##LL jpayne@69: #endif jpayne@69: jpayne@69: #ifndef Py_ULL jpayne@69: #define Py_ULL(x) Py_LL(x##U) jpayne@69: #endif jpayne@69: jpayne@69: #define Py_VA_COPY va_copy jpayne@69: jpayne@69: /* jpayne@69: * Convenient macros to deal with endianness of the platform. WORDS_BIGENDIAN is jpayne@69: * detected by configure and defined in pyconfig.h. The code in pyconfig.h jpayne@69: * also takes care of Apple's universal builds. jpayne@69: */ jpayne@69: jpayne@69: #ifdef WORDS_BIGENDIAN jpayne@69: #define PY_BIG_ENDIAN 1 jpayne@69: #define PY_LITTLE_ENDIAN 0 jpayne@69: #else jpayne@69: #define PY_BIG_ENDIAN 0 jpayne@69: #define PY_LITTLE_ENDIAN 1 jpayne@69: #endif jpayne@69: jpayne@69: #ifdef Py_BUILD_CORE jpayne@69: /* jpayne@69: * Macros to protect CRT calls against instant termination when passed an jpayne@69: * invalid parameter (issue23524). jpayne@69: */ jpayne@69: #if defined _MSC_VER && _MSC_VER >= 1900 jpayne@69: jpayne@69: extern _invalid_parameter_handler _Py_silent_invalid_parameter_handler; jpayne@69: #define _Py_BEGIN_SUPPRESS_IPH { _invalid_parameter_handler _Py_old_handler = \ jpayne@69: _set_thread_local_invalid_parameter_handler(_Py_silent_invalid_parameter_handler); jpayne@69: #define _Py_END_SUPPRESS_IPH _set_thread_local_invalid_parameter_handler(_Py_old_handler); } jpayne@69: jpayne@69: #else jpayne@69: jpayne@69: #define _Py_BEGIN_SUPPRESS_IPH jpayne@69: #define _Py_END_SUPPRESS_IPH jpayne@69: jpayne@69: #endif /* _MSC_VER >= 1900 */ jpayne@69: #endif /* Py_BUILD_CORE */ jpayne@69: jpayne@69: #ifdef __ANDROID__ jpayne@69: /* The Android langinfo.h header is not used. */ jpayne@69: # undef HAVE_LANGINFO_H jpayne@69: # undef CODESET jpayne@69: #endif jpayne@69: jpayne@69: /* Maximum value of the Windows DWORD type */ jpayne@69: #define PY_DWORD_MAX 4294967295U jpayne@69: jpayne@69: /* This macro used to tell whether Python was built with multithreading jpayne@69: * enabled. Now multithreading is always enabled, but keep the macro jpayne@69: * for compatibility. jpayne@69: */ jpayne@69: #ifndef WITH_THREAD jpayne@69: # define WITH_THREAD jpayne@69: #endif jpayne@69: jpayne@69: /* Check that ALT_SOABI is consistent with Py_TRACE_REFS: jpayne@69: ./configure --with-trace-refs should must be used to define Py_TRACE_REFS */ jpayne@69: #if defined(ALT_SOABI) && defined(Py_TRACE_REFS) jpayne@69: # error "Py_TRACE_REFS ABI is not compatible with release and debug ABI" jpayne@69: #endif jpayne@69: jpayne@69: #if defined(__ANDROID__) || defined(__VXWORKS__) jpayne@69: /* Ignore the locale encoding: force UTF-8 */ jpayne@69: # define _Py_FORCE_UTF8_LOCALE jpayne@69: #endif jpayne@69: jpayne@69: #if defined(_Py_FORCE_UTF8_LOCALE) || defined(__APPLE__) jpayne@69: /* Use UTF-8 as filesystem encoding */ jpayne@69: # define _Py_FORCE_UTF8_FS_ENCODING jpayne@69: #endif jpayne@69: jpayne@69: /* Mark a function which cannot return. Example: jpayne@69: jpayne@69: PyAPI_FUNC(void) _Py_NO_RETURN PyThread_exit_thread(void); */ jpayne@69: #if defined(__clang__) || \ jpayne@69: (defined(__GNUC__) && \ jpayne@69: ((__GNUC__ >= 3) || \ jpayne@69: (__GNUC__ == 2) && (__GNUC_MINOR__ >= 5))) jpayne@69: # define _Py_NO_RETURN __attribute__((__noreturn__)) jpayne@69: #elif defined(_MSC_VER) jpayne@69: # define _Py_NO_RETURN __declspec(noreturn) jpayne@69: #else jpayne@69: # define _Py_NO_RETURN jpayne@69: #endif jpayne@69: jpayne@69: #endif /* Py_PYPORT_H */