]> git.proxmox.com Git - mirror_edk2.git/blobdiff - AppPkg/Applications/Python/PyMod-2.7.1/Include/pyport.h
Basic Core Python interpreter.
[mirror_edk2.git] / AppPkg / Applications / Python / PyMod-2.7.1 / Include / pyport.h
diff --git a/AppPkg/Applications/Python/PyMod-2.7.1/Include/pyport.h b/AppPkg/Applications/Python/PyMod-2.7.1/Include/pyport.h
new file mode 100644 (file)
index 0000000..4c6eef0
--- /dev/null
@@ -0,0 +1,905 @@
+#ifndef Py_PYPORT_H\r
+#define Py_PYPORT_H\r
+\r
+#include "pyconfig.h" /* include for defines */\r
+\r
+/* Some versions of HP-UX & Solaris need inttypes.h for int32_t,\r
+   INT32_MAX, etc. */\r
+#ifdef HAVE_INTTYPES_H\r
+#include <inttypes.h>\r
+#endif\r
+\r
+#ifdef HAVE_STDINT_H\r
+#include <stdint.h>\r
+#endif\r
+\r
+/**************************************************************************\r
+Symbols and macros to supply platform-independent interfaces to basic\r
+C language & library operations whose spellings vary across platforms.\r
+\r
+Please try to make documentation here as clear as possible:  by definition,\r
+the stuff here is trying to illuminate C's darkest corners.\r
+\r
+Config #defines referenced here:\r
+\r
+SIGNED_RIGHT_SHIFT_ZERO_FILLS\r
+Meaning:  To be defined iff i>>j does not extend the sign bit when i is a\r
+          signed integral type and i < 0.\r
+Used in:  Py_ARITHMETIC_RIGHT_SHIFT\r
+\r
+Py_DEBUG\r
+Meaning:  Extra checks compiled in for debug mode.\r
+Used in:  Py_SAFE_DOWNCAST\r
+\r
+HAVE_UINTPTR_T\r
+Meaning:  The C9X type uintptr_t is supported by the compiler\r
+Used in:  Py_uintptr_t\r
+\r
+HAVE_LONG_LONG\r
+Meaning:  The compiler supports the C type "long long"\r
+Used in:  PY_LONG_LONG\r
+\r
+**************************************************************************/\r
+\r
+\r
+/* For backward compatibility only. Obsolete, do not use. */\r
+#ifdef HAVE_PROTOTYPES\r
+#define Py_PROTO(x) x\r
+#else\r
+#define Py_PROTO(x) ()\r
+#endif\r
+#ifndef Py_FPROTO\r
+#define Py_FPROTO(x) Py_PROTO(x)\r
+#endif\r
+\r
+/* typedefs for some C9X-defined synonyms for integral types.\r
+ *\r
+ * The names in Python are exactly the same as the C9X names, except with a\r
+ * Py_ prefix.  Until C9X is universally implemented, this is the only way\r
+ * to ensure that Python gets reliable names that don't conflict with names\r
+ * in non-Python code that are playing their own tricks to define the C9X\r
+ * names.\r
+ *\r
+ * NOTE: don't go nuts here!  Python has no use for *most* of the C9X\r
+ * integral synonyms.  Only define the ones we actually need.\r
+ */\r
+\r
+#ifdef HAVE_LONG_LONG\r
+#ifndef PY_LONG_LONG\r
+#define PY_LONG_LONG long long\r
+#if defined(LLONG_MAX)\r
+/* If LLONG_MAX is defined in limits.h, use that. */\r
+#define PY_LLONG_MIN LLONG_MIN\r
+#define PY_LLONG_MAX LLONG_MAX\r
+#define PY_ULLONG_MAX ULLONG_MAX\r
+#elif defined(__LONG_LONG_MAX__)\r
+/* Otherwise, if GCC has a builtin define, use that. */\r
+#define PY_LLONG_MAX __LONG_LONG_MAX__\r
+#define PY_LLONG_MIN (-PY_LLONG_MAX-1)\r
+#define PY_ULLONG_MAX (__LONG_LONG_MAX__*2ULL + 1ULL)\r
+#else\r
+/* Otherwise, rely on two's complement. */\r
+#define PY_ULLONG_MAX (~0ULL)\r
+#define PY_LLONG_MAX  ((long long)(PY_ULLONG_MAX>>1))\r
+#define PY_LLONG_MIN (-PY_LLONG_MAX-1)\r
+#endif /* LLONG_MAX */\r
+#endif\r
+#endif /* HAVE_LONG_LONG */\r
+\r
+/* a build with 30-bit digits for Python long integers needs an exact-width\r
+ * 32-bit unsigned integer type to store those digits.  (We could just use\r
+ * type 'unsigned long', but that would be wasteful on a system where longs\r
+ * are 64-bits.)  On Unix systems, the autoconf macro AC_TYPE_UINT32_T defines\r
+ * uint32_t to be such a type unless stdint.h or inttypes.h defines uint32_t.\r
+ * However, it doesn't set HAVE_UINT32_T, so we do that here.\r
+ */\r
+#if (defined UINT32_MAX || defined uint32_t)\r
+#ifndef PY_UINT32_T\r
+#define HAVE_UINT32_T 1\r
+#define PY_UINT32_T uint32_t\r
+#endif\r
+#endif\r
+\r
+/* Macros for a 64-bit unsigned integer type; used for type 'twodigits' in the\r
+ * long integer implementation, when 30-bit digits are enabled.\r
+ */\r
+#if (defined UINT64_MAX || defined uint64_t)\r
+#ifndef PY_UINT64_T\r
+#define HAVE_UINT64_T 1\r
+#define PY_UINT64_T uint64_t\r
+#endif\r
+#endif\r
+\r
+/* Signed variants of the above */\r
+#if (defined INT32_MAX || defined int32_t)\r
+#ifndef PY_INT32_T\r
+#define HAVE_INT32_T 1\r
+#define PY_INT32_T int32_t\r
+#endif\r
+#endif\r
+#if (defined INT64_MAX || defined int64_t)\r
+#ifndef PY_INT64_T\r
+#define HAVE_INT64_T 1\r
+#define PY_INT64_T int64_t\r
+#endif\r
+#endif\r
+\r
+/* If PYLONG_BITS_IN_DIGIT is not defined then we'll use 30-bit digits if all\r
+   the necessary integer types are available, and we're on a 64-bit platform\r
+   (as determined by SIZEOF_VOID_P); otherwise we use 15-bit digits. */\r
+\r
+#ifndef PYLONG_BITS_IN_DIGIT\r
+#if (defined HAVE_UINT64_T && defined HAVE_INT64_T && \\r
+     defined HAVE_UINT32_T && defined HAVE_INT32_T && SIZEOF_VOID_P >= 8)\r
+#define PYLONG_BITS_IN_DIGIT 30\r
+#else\r
+#define PYLONG_BITS_IN_DIGIT 15\r
+#endif\r
+#endif\r
+\r
+/* uintptr_t is the C9X name for an unsigned integral type such that a\r
+ * legitimate void* can be cast to uintptr_t and then back to void* again\r
+ * without loss of information.  Similarly for intptr_t, wrt a signed\r
+ * integral type.\r
+ */\r
+#ifdef HAVE_UINTPTR_T\r
+typedef uintptr_t       Py_uintptr_t;\r
+typedef intptr_t        Py_intptr_t;\r
+\r
+#elif SIZEOF_VOID_P <= SIZEOF_INT\r
+typedef unsigned int    Py_uintptr_t;\r
+typedef int             Py_intptr_t;\r
+\r
+#elif SIZEOF_VOID_P <= SIZEOF_LONG\r
+typedef unsigned long   Py_uintptr_t;\r
+typedef long            Py_intptr_t;\r
+\r
+#elif defined(HAVE_LONG_LONG) && (SIZEOF_VOID_P <= SIZEOF_LONG_LONG)\r
+typedef unsigned PY_LONG_LONG   Py_uintptr_t;\r
+typedef PY_LONG_LONG            Py_intptr_t;\r
+\r
+#else\r
+#   error "Python needs a typedef for Py_uintptr_t in pyport.h."\r
+#endif /* HAVE_UINTPTR_T */\r
+\r
+/* Py_ssize_t is a signed integral type such that sizeof(Py_ssize_t) ==\r
+ * sizeof(size_t).  C99 doesn't define such a thing directly (size_t is an\r
+ * unsigned integral type).  See PEP 353 for details.\r
+ */\r
+#ifdef HAVE_SSIZE_T\r
+typedef ssize_t         Py_ssize_t;\r
+#elif SIZEOF_VOID_P == SIZEOF_SIZE_T\r
+typedef Py_intptr_t     Py_ssize_t;\r
+#else\r
+#   error "Python needs a typedef for Py_ssize_t in pyport.h."\r
+#endif\r
+\r
+/* Largest possible value of size_t.\r
+   SIZE_MAX is part of C99, so it might be defined on some\r
+   platforms. If it is not defined, (size_t)-1 is a portable\r
+   definition for C89, due to the way signed->unsigned\r
+   conversion is defined. */\r
+#ifdef SIZE_MAX\r
+#define PY_SIZE_MAX SIZE_MAX\r
+#else\r
+#define PY_SIZE_MAX ((size_t)-1)\r
+#endif\r
+\r
+/* Largest positive value of type Py_ssize_t. */\r
+#define PY_SSIZE_T_MAX ((Py_ssize_t)(((size_t)-1)>>1))\r
+/* Smallest negative value of type Py_ssize_t. */\r
+#define PY_SSIZE_T_MIN (-PY_SSIZE_T_MAX-1)\r
+\r
+#if SIZEOF_PID_T > SIZEOF_LONG\r
+#   error "Python doesn't support sizeof(pid_t) > sizeof(long)"\r
+#endif\r
+\r
+/* PY_FORMAT_SIZE_T is a platform-specific modifier for use in a printf\r
+ * format to convert an argument with the width of a size_t or Py_ssize_t.\r
+ * C99 introduced "z" for this purpose, but not all platforms support that;\r
+ * e.g., MS compilers use "I" instead.\r
+ *\r
+ * These "high level" Python format functions interpret "z" correctly on\r
+ * all platforms (Python interprets the format string itself, and does whatever\r
+ * the platform C requires to convert a size_t/Py_ssize_t argument):\r
+ *\r
+ *     PyString_FromFormat\r
+ *     PyErr_Format\r
+ *     PyString_FromFormatV\r
+ *\r
+ * Lower-level uses require that you interpolate the correct format modifier\r
+ * yourself (e.g., calling printf, fprintf, sprintf, PyOS_snprintf); for\r
+ * example,\r
+ *\r
+ *     Py_ssize_t index;\r
+ *     fprintf(stderr, "index %" PY_FORMAT_SIZE_T "d sucks\n", index);\r
+ *\r
+ * That will expand to %ld, or %Id, or to something else correct for a\r
+ * Py_ssize_t on the platform.\r
+ */\r
+#ifndef PY_FORMAT_SIZE_T\r
+#   if SIZEOF_SIZE_T == SIZEOF_INT && !defined(__APPLE__)\r
+#       define PY_FORMAT_SIZE_T ""\r
+#   elif SIZEOF_SIZE_T == SIZEOF_LONG\r
+#       define PY_FORMAT_SIZE_T "l"\r
+#   elif defined(MS_WINDOWS)\r
+#       define PY_FORMAT_SIZE_T "I"\r
+#   else\r
+#       error "This platform's pyconfig.h needs to define PY_FORMAT_SIZE_T"\r
+#   endif\r
+#endif\r
+\r
+/* PY_FORMAT_LONG_LONG is analogous to PY_FORMAT_SIZE_T above, but for\r
+ * the long long type instead of the size_t type.  It's only available\r
+ * when HAVE_LONG_LONG is defined. The "high level" Python format\r
+ * functions listed above will interpret "lld" or "llu" correctly on\r
+ * all platforms.\r
+ */\r
+#ifdef HAVE_LONG_LONG\r
+#   ifndef PY_FORMAT_LONG_LONG\r
+#       if defined(MS_WIN64) || defined(MS_WINDOWS)\r
+#           define PY_FORMAT_LONG_LONG "I64"\r
+#       else\r
+#           error "This platform's pyconfig.h needs to define PY_FORMAT_LONG_LONG"\r
+#       endif\r
+#   endif\r
+#endif\r
+\r
+/* Py_LOCAL can be used instead of static to get the fastest possible calling\r
+ * convention for functions that are local to a given module.\r
+ *\r
+ * Py_LOCAL_INLINE does the same thing, and also explicitly requests inlining,\r
+ * for platforms that support that.\r
+ *\r
+ * If PY_LOCAL_AGGRESSIVE is defined before python.h is included, more\r
+ * "aggressive" inlining/optimizaion is enabled for the entire module.  This\r
+ * may lead to code bloat, and may slow things down for those reasons.  It may\r
+ * also lead to errors, if the code relies on pointer aliasing.  Use with\r
+ * care.\r
+ *\r
+ * NOTE: You can only use this for functions that are entirely local to a\r
+ * module; functions that are exported via method tables, callbacks, etc,\r
+ * should keep using static.\r
+ */\r
+\r
+#undef USE_INLINE /* XXX - set via configure? */\r
+\r
+#if defined(_MSC_VER)\r
+#if defined(PY_LOCAL_AGGRESSIVE)\r
+/* enable more aggressive optimization for visual studio */\r
+//#pragma optimize("agtw", on)\r
+#pragma optimize("gt", on)    // a and w are not legal for VS2005\r
+#endif\r
+/* ignore warnings if the compiler decides not to inline a function */\r
+#pragma warning(disable: 4710)\r
+/* fastest possible local call under MSVC */\r
+#define Py_LOCAL(type) static type __fastcall\r
+#define Py_LOCAL_INLINE(type) static __inline type __fastcall\r
+#elif defined(USE_INLINE)\r
+#define Py_LOCAL(type) static type\r
+#define Py_LOCAL_INLINE(type) static inline type\r
+#else\r
+#define Py_LOCAL(type) static type\r
+#define Py_LOCAL_INLINE(type) static type\r
+#endif\r
+\r
+/* Py_MEMCPY can be used instead of memcpy in cases where the copied blocks\r
+ * are often very short.  While most platforms have highly optimized code for\r
+ * large transfers, the setup costs for memcpy are often quite high.  MEMCPY\r
+ * solves this by doing short copies "in line".\r
+ */\r
+\r
+#if defined(_MSC_VER)\r
+#define Py_MEMCPY(target, source, length) do {                          \\r
+        size_t i_, n_ = (length);                                       \\r
+        char *t_ = (void*) (target);                                    \\r
+        const char *s_ = (void*) (source);                              \\r
+        if (n_ >= 16)                                                   \\r
+            memcpy(t_, s_, n_);                                         \\r
+        else                                                            \\r
+            for (i_ = 0; i_ < n_; i_++)                                 \\r
+                t_[i_] = s_[i_];                                        \\r
+    } while (0)\r
+#else\r
+#define Py_MEMCPY memcpy\r
+#endif\r
+\r
+#include <stdlib.h>\r
+\r
+#ifdef HAVE_IEEEFP_H\r
+#include <ieeefp.h>  /* needed for 'finite' declaration on some platforms */\r
+#endif\r
+\r
+#include <math.h> /* Moved here from the math section, before extern "C" */\r
+\r
+/********************************************\r
+ * WRAPPER FOR <time.h> and/or <sys/time.h> *\r
+ ********************************************/\r
+\r
+#ifdef TIME_WITH_SYS_TIME\r
+#include <sys/time.h>\r
+#include <time.h>\r
+#else /* !TIME_WITH_SYS_TIME */\r
+#ifdef HAVE_SYS_TIME_H\r
+#include <sys/time.h>\r
+#else /* !HAVE_SYS_TIME_H */\r
+#include <time.h>\r
+#endif /* !HAVE_SYS_TIME_H */\r
+#endif /* !TIME_WITH_SYS_TIME */\r
+\r
+\r
+/******************************\r
+ * WRAPPER FOR <sys/select.h> *\r
+ ******************************/\r
+\r
+/* NB caller must include <sys/types.h> */\r
+\r
+#ifdef HAVE_SYS_SELECT_H\r
+\r
+#include <sys/select.h>\r
+\r
+#endif /* !HAVE_SYS_SELECT_H */\r
+\r
+/*******************************\r
+ * stat() and fstat() fiddling *\r
+ *******************************/\r
+\r
+/* We expect that stat and fstat exist on most systems.\r
+ *  It's confirmed on Unix, Mac and Windows.\r
+ *  If you don't have them, add\r
+ *      #define DONT_HAVE_STAT\r
+ * and/or\r
+ *      #define DONT_HAVE_FSTAT\r
+ * to your pyconfig.h. Python code beyond this should check HAVE_STAT and\r
+ * HAVE_FSTAT instead.\r
+ * Also\r
+ *      #define HAVE_SYS_STAT_H\r
+ * if <sys/stat.h> exists on your platform, and\r
+ *      #define HAVE_STAT_H\r
+ * if <stat.h> does.\r
+ */\r
+#ifndef DONT_HAVE_STAT\r
+#define HAVE_STAT\r
+#endif\r
+\r
+#ifndef DONT_HAVE_FSTAT\r
+#define HAVE_FSTAT\r
+#endif\r
+\r
+#ifdef RISCOS\r
+#include <sys/types.h>\r
+#include "unixstuff.h"\r
+#endif\r
+\r
+#ifdef HAVE_SYS_STAT_H\r
+#if defined(PYOS_OS2) && defined(PYCC_GCC)\r
+#include <sys/types.h>\r
+#endif\r
+#include <sys/stat.h>\r
+#elif defined(HAVE_STAT_H)\r
+#include <stat.h>\r
+#endif\r
+\r
+#if defined(PYCC_VACPP)\r
+/* VisualAge C/C++ Failed to Define MountType Field in sys/stat.h */\r
+#define S_IFMT (S_IFDIR|S_IFCHR|S_IFREG)\r
+#endif\r
+\r
+#ifndef S_ISREG\r
+#define S_ISREG(x) (((x) & S_IFMT) == S_IFREG)\r
+#endif\r
+\r
+#ifndef S_ISDIR\r
+#define S_ISDIR(x) (((x) & S_IFMT) == S_IFDIR)\r
+#endif\r
+\r
+\r
+#ifdef __cplusplus\r
+/* Move this down here since some C++ #include's don't like to be included\r
+   inside an extern "C" */\r
+extern "C" {\r
+#endif\r
+\r
+\r
+/* Py_ARITHMETIC_RIGHT_SHIFT\r
+ * C doesn't define whether a right-shift of a signed integer sign-extends\r
+ * or zero-fills.  Here a macro to force sign extension:\r
+ * Py_ARITHMETIC_RIGHT_SHIFT(TYPE, I, J)\r
+ *    Return I >> J, forcing sign extension.  Arithmetically, return the\r
+ *    floor of I/2**J.\r
+ * Requirements:\r
+ *    I should have signed integer type.  In the terminology of C99, this can\r
+ *    be either one of the five standard signed integer types (signed char,\r
+ *    short, int, long, long long) or an extended signed integer type.\r
+ *    J is an integer >= 0 and strictly less than the number of bits in the\r
+ *    type of I (because C doesn't define what happens for J outside that\r
+ *    range either).\r
+ *    TYPE used to specify the type of I, but is now ignored.  It's been left\r
+ *    in for backwards compatibility with versions <= 2.6 or 3.0.\r
+ * Caution:\r
+ *    I may be evaluated more than once.\r
+ */\r
+#ifdef SIGNED_RIGHT_SHIFT_ZERO_FILLS\r
+#define Py_ARITHMETIC_RIGHT_SHIFT(TYPE, I, J) \\r
+    ((I) < 0 ? -1-((-1-(I)) >> (J)) : (I) >> (J))\r
+#else\r
+#define Py_ARITHMETIC_RIGHT_SHIFT(TYPE, I, J) ((I) >> (J))\r
+#endif\r
+\r
+/* Py_FORCE_EXPANSION(X)\r
+ * "Simply" returns its argument.  However, macro expansions within the\r
+ * argument are evaluated.  This unfortunate trickery is needed to get\r
+ * token-pasting to work as desired in some cases.\r
+ */\r
+#define Py_FORCE_EXPANSION(X) X\r
+\r
+/* Py_SAFE_DOWNCAST(VALUE, WIDE, NARROW)\r
+ * Cast VALUE to type NARROW from type WIDE.  In Py_DEBUG mode, this\r
+ * assert-fails if any information is lost.\r
+ * Caution:\r
+ *    VALUE may be evaluated more than once.\r
+ */\r
+#ifdef Py_DEBUG\r
+#define Py_SAFE_DOWNCAST(VALUE, WIDE, NARROW) \\r
+    (assert((WIDE)(NARROW)(VALUE) == (VALUE)), (NARROW)(VALUE))\r
+#else\r
+#define Py_SAFE_DOWNCAST(VALUE, WIDE, NARROW) (NARROW)(VALUE)\r
+#endif\r
+\r
+/* Py_SET_ERRNO_ON_MATH_ERROR(x)\r
+ * If a libm function did not set errno, but it looks like the result\r
+ * overflowed or not-a-number, set errno to ERANGE or EDOM.  Set errno\r
+ * to 0 before calling a libm function, and invoke this macro after,\r
+ * passing the function result.\r
+ * Caution:\r
+ *    This isn't reliable.  See Py_OVERFLOWED comments.\r
+ *    X is evaluated more than once.\r
+ */\r
+#if defined(__FreeBSD__) || defined(__OpenBSD__) || (defined(__hpux) && defined(__ia64))\r
+#define _Py_SET_EDOM_FOR_NAN(X) if (isnan(X)) errno = EDOM;\r
+#else\r
+#define _Py_SET_EDOM_FOR_NAN(X) ;\r
+#endif\r
+#define Py_SET_ERRNO_ON_MATH_ERROR(X) \\r
+    do { \\r
+        if (errno == 0) { \\r
+            if ((X) == Py_HUGE_VAL || (X) == -Py_HUGE_VAL) \\r
+                errno = ERANGE; \\r
+            else _Py_SET_EDOM_FOR_NAN(X) \\r
+        } \\r
+    } while(0)\r
+\r
+/* Py_SET_ERANGE_ON_OVERFLOW(x)\r
+ * An alias of Py_SET_ERRNO_ON_MATH_ERROR for backward-compatibility.\r
+ */\r
+#define Py_SET_ERANGE_IF_OVERFLOW(X) Py_SET_ERRNO_ON_MATH_ERROR(X)\r
+\r
+/* Py_ADJUST_ERANGE1(x)\r
+ * Py_ADJUST_ERANGE2(x, y)\r
+ * Set errno to 0 before calling a libm function, and invoke one of these\r
+ * macros after, passing the function result(s) (Py_ADJUST_ERANGE2 is useful\r
+ * for functions returning complex results).  This makes two kinds of\r
+ * adjustments to errno:  (A) If it looks like the platform libm set\r
+ * errno=ERANGE due to underflow, clear errno. (B) If it looks like the\r
+ * platform libm overflowed but didn't set errno, force errno to ERANGE.  In\r
+ * effect, we're trying to force a useful implementation of C89 errno\r
+ * behavior.\r
+ * Caution:\r
+ *    This isn't reliable.  See Py_OVERFLOWED comments.\r
+ *    X and Y may be evaluated more than once.\r
+ */\r
+#define Py_ADJUST_ERANGE1(X)                                            \\r
+    do {                                                                \\r
+        if (errno == 0) {                                               \\r
+            if ((X) == Py_HUGE_VAL || (X) == -Py_HUGE_VAL)              \\r
+                errno = ERANGE;                                         \\r
+        }                                                               \\r
+        else if (errno == ERANGE && (X) == 0.0)                         \\r
+            errno = 0;                                                  \\r
+    } while(0)\r
+\r
+#define Py_ADJUST_ERANGE2(X, Y)                                         \\r
+    do {                                                                \\r
+        if ((X) == Py_HUGE_VAL || (X) == -Py_HUGE_VAL ||                \\r
+            (Y) == Py_HUGE_VAL || (Y) == -Py_HUGE_VAL) {                \\r
+                        if (errno == 0)                                 \\r
+                                errno = ERANGE;                         \\r
+        }                                                               \\r
+        else if (errno == ERANGE)                                       \\r
+            errno = 0;                                                  \\r
+    } while(0)\r
+\r
+/*  The functions _Py_dg_strtod and _Py_dg_dtoa in Python/dtoa.c (which are\r
+ *  required to support the short float repr introduced in Python 3.1) require\r
+ *  that the floating-point unit that's being used for arithmetic operations\r
+ *  on C doubles is set to use 53-bit precision.  It also requires that the\r
+ *  FPU rounding mode is round-half-to-even, but that's less often an issue.\r
+ *\r
+ *  If your FPU isn't already set to 53-bit precision/round-half-to-even, and\r
+ *  you want to make use of _Py_dg_strtod and _Py_dg_dtoa, then you should\r
+ *\r
+ *     #define HAVE_PY_SET_53BIT_PRECISION 1\r
+ *\r
+ *  and also give appropriate definitions for the following three macros:\r
+ *\r
+ *    _PY_SET_53BIT_PRECISION_START : store original FPU settings, and\r
+ *        set FPU to 53-bit precision/round-half-to-even\r
+ *    _PY_SET_53BIT_PRECISION_END : restore original FPU settings\r
+ *    _PY_SET_53BIT_PRECISION_HEADER : any variable declarations needed to\r
+ *        use the two macros above.\r
+ *\r
+ * The macros are designed to be used within a single C function: see\r
+ * Python/pystrtod.c for an example of their use.\r
+ */\r
+\r
+/* get and set x87 control word for gcc/x86 */\r
+#ifdef HAVE_GCC_ASM_FOR_X87\r
+#define HAVE_PY_SET_53BIT_PRECISION 1\r
+/* _Py_get/set_387controlword functions are defined in Python/pymath.c */\r
+#define _Py_SET_53BIT_PRECISION_HEADER                          \\r
+    unsigned short old_387controlword, new_387controlword\r
+#define _Py_SET_53BIT_PRECISION_START                                   \\r
+    do {                                                                \\r
+        old_387controlword = _Py_get_387controlword();                  \\r
+        new_387controlword = (old_387controlword & ~0x0f00) | 0x0200; \\r
+        if (new_387controlword != old_387controlword)                   \\r
+            _Py_set_387controlword(new_387controlword);                 \\r
+    } while (0)\r
+#define _Py_SET_53BIT_PRECISION_END                             \\r
+    if (new_387controlword != old_387controlword)               \\r
+        _Py_set_387controlword(old_387controlword)\r
+#endif\r
+\r
+/* default definitions are empty */\r
+#ifndef HAVE_PY_SET_53BIT_PRECISION\r
+#define _Py_SET_53BIT_PRECISION_HEADER\r
+#define _Py_SET_53BIT_PRECISION_START\r
+#define _Py_SET_53BIT_PRECISION_END\r
+#endif\r
+\r
+/* If we can't guarantee 53-bit precision, don't use the code\r
+   in Python/dtoa.c, but fall back to standard code.  This\r
+   means that repr of a float will be long (17 sig digits).\r
+\r
+   Realistically, there are two things that could go wrong:\r
+\r
+   (1) doubles aren't IEEE 754 doubles, or\r
+   (2) we're on x86 with the rounding precision set to 64-bits\r
+       (extended precision), and we don't know how to change\r
+       the rounding precision.\r
+ */\r
+\r
+#if !defined(DOUBLE_IS_LITTLE_ENDIAN_IEEE754) && \\r
+    !defined(DOUBLE_IS_BIG_ENDIAN_IEEE754) && \\r
+    !defined(DOUBLE_IS_ARM_MIXED_ENDIAN_IEEE754)\r
+#define PY_NO_SHORT_FLOAT_REPR\r
+#endif\r
+\r
+/* double rounding is symptomatic of use of extended precision on x86.  If\r
+   we're seeing double rounding, and we don't have any mechanism available for\r
+   changing the FPU rounding precision, then don't use Python/dtoa.c. */\r
+#if defined(X87_DOUBLE_ROUNDING) && !defined(HAVE_PY_SET_53BIT_PRECISION)\r
+#define PY_NO_SHORT_FLOAT_REPR\r
+#endif\r
+\r
+/* Py_DEPRECATED(version)\r
+ * Declare a variable, type, or function deprecated.\r
+ * Usage:\r
+ *    extern int old_var Py_DEPRECATED(2.3);\r
+ *    typedef int T1 Py_DEPRECATED(2.4);\r
+ *    extern int x() Py_DEPRECATED(2.5);\r
+ */\r
+#if defined(__GNUC__) && ((__GNUC__ >= 4) || \\r
+              (__GNUC__ == 3) && (__GNUC_MINOR__ >= 1))\r
+#define Py_DEPRECATED(VERSION_UNUSED) __attribute__((__deprecated__))\r
+#else\r
+#define Py_DEPRECATED(VERSION_UNUSED)\r
+#endif\r
+\r
+/**************************************************************************\r
+Prototypes that are missing from the standard include files on some systems\r
+(and possibly only some versions of such systems.)\r
+\r
+Please be conservative with adding new ones, document them and enclose them\r
+in platform-specific #ifdefs.\r
+**************************************************************************/\r
+\r
+#ifdef SOLARIS\r
+/* Unchecked */\r
+extern int gethostname(char *, int);\r
+#endif\r
+\r
+#ifdef __BEOS__\r
+/* Unchecked */\r
+/* It's in the libs, but not the headers... - [cjh] */\r
+int shutdown( int, int );\r
+#endif\r
+\r
+#ifdef HAVE__GETPTY\r
+#include <sys/types.h>          /* we need to import mode_t */\r
+extern char * _getpty(int *, int, mode_t, int);\r
+#endif\r
+\r
+/* On QNX 6, struct termio must be declared by including sys/termio.h\r
+   if TCGETA, TCSETA, TCSETAW, or TCSETAF are used.  sys/termio.h must\r
+   be included before termios.h or it will generate an error. */\r
+#ifdef HAVE_SYS_TERMIO_H\r
+#include <sys/termio.h>\r
+#endif\r
+\r
+#if defined(HAVE_OPENPTY) || defined(HAVE_FORKPTY)\r
+#if !defined(HAVE_PTY_H) && !defined(HAVE_LIBUTIL_H) && !defined(HAVE_UTIL_H)\r
+/* BSDI does not supply a prototype for the 'openpty' and 'forkpty'\r
+   functions, even though they are included in libutil. */\r
+#include <termios.h>\r
+extern int openpty(int *, int *, char *, struct termios *, struct winsize *);\r
+extern pid_t forkpty(int *, char *, struct termios *, struct winsize *);\r
+#endif /* !defined(HAVE_PTY_H) && !defined(HAVE_LIBUTIL_H) */\r
+#endif /* defined(HAVE_OPENPTY) || defined(HAVE_FORKPTY) */\r
+\r
+\r
+/* These are pulled from various places. It isn't obvious on what platforms\r
+   they are necessary, nor what the exact prototype should look like (which\r
+   is likely to vary between platforms!) If you find you need one of these\r
+   declarations, please move them to a platform-specific block and include\r
+   proper prototypes. */\r
+#if 0\r
+\r
+/* From Modules/resource.c */\r
+extern int getrusage();\r
+extern int getpagesize();\r
+\r
+/* From Python/sysmodule.c and Modules/posixmodule.c */\r
+extern int fclose(FILE *);\r
+\r
+/* From Modules/posixmodule.c */\r
+extern int fdatasync(int);\r
+#endif /* 0 */\r
+\r
+\r
+/* On 4.4BSD-descendants, ctype functions serves the whole range of\r
+ * wchar_t character set rather than single byte code points only.\r
+ * This characteristic can break some operations of string object\r
+ * including str.upper() and str.split() on UTF-8 locales.  This\r
+ * workaround was provided by Tim Robbins of FreeBSD project.\r
+ */\r
+\r
+#ifdef __FreeBSD__\r
+#include <osreldate.h>\r
+#if __FreeBSD_version > 500039\r
+# define _PY_PORT_CTYPE_UTF8_ISSUE\r
+#endif\r
+#endif\r
+\r
+\r
+#if defined(__APPLE__)\r
+# define _PY_PORT_CTYPE_UTF8_ISSUE\r
+#endif\r
+\r
+#ifdef _PY_PORT_CTYPE_UTF8_ISSUE\r
+#include <ctype.h>\r
+#include <wctype.h>\r
+#undef isalnum\r
+#define isalnum(c) iswalnum(btowc(c))\r
+#undef isalpha\r
+#define isalpha(c) iswalpha(btowc(c))\r
+#undef islower\r
+#define islower(c) iswlower(btowc(c))\r
+#undef isspace\r
+#define isspace(c) iswspace(btowc(c))\r
+#undef isupper\r
+#define isupper(c) iswupper(btowc(c))\r
+#undef tolower\r
+#define tolower(c) towlower(btowc(c))\r
+#undef toupper\r
+#define toupper(c) towupper(btowc(c))\r
+#endif\r
+\r
+\r
+/* Declarations for symbol visibility.\r
+\r
+  PyAPI_FUNC(type): Declares a public Python API function and return type\r
+  PyAPI_DATA(type): Declares public Python data and its type\r
+  PyMODINIT_FUNC:   A Python module init function.  If these functions are\r
+                    inside the Python core, they are private to the core.\r
+                    If in an extension module, it may be declared with\r
+                    external linkage depending on the platform.\r
+\r
+  As a number of platforms support/require "__declspec(dllimport/dllexport)",\r
+  we support a HAVE_DECLSPEC_DLL macro to save duplication.\r
+*/\r
+\r
+/*\r
+  All windows ports, except cygwin, are handled in PC/pyconfig.h.\r
+\r
+  BeOS and cygwin are the only other autoconf platform requiring special\r
+  linkage handling and both of these use __declspec().\r
+*/\r
+#if defined(__CYGWIN__) || defined(__BEOS__)\r
+#       define HAVE_DECLSPEC_DLL\r
+#endif\r
+\r
+/* only get special linkage if built as shared or platform is Cygwin */\r
+#if defined(Py_ENABLE_SHARED) || defined(__CYGWIN__)\r
+#       if defined(HAVE_DECLSPEC_DLL)\r
+#               ifdef Py_BUILD_CORE\r
+#                       define PyAPI_FUNC(RTYPE) __declspec(dllexport) RTYPE\r
+#                       define PyAPI_DATA(RTYPE) extern __declspec(dllexport) RTYPE\r
+        /* module init functions inside the core need no external linkage */\r
+        /* except for Cygwin to handle embedding (FIXME: BeOS too?) */\r
+#                       if defined(__CYGWIN__)\r
+#                               define PyMODINIT_FUNC __declspec(dllexport) void\r
+#                       else /* __CYGWIN__ */\r
+#                               define PyMODINIT_FUNC void\r
+#                       endif /* __CYGWIN__ */\r
+#               else /* Py_BUILD_CORE */\r
+        /* Building an extension module, or an embedded situation */\r
+        /* public Python functions and data are imported */\r
+        /* Under Cygwin, auto-import functions to prevent compilation */\r
+        /* failures similar to those described at the bottom of 4.1: */\r
+        /* http://docs.python.org/extending/windows.html#a-cookbook-approach */\r
+#                       if !defined(__CYGWIN__)\r
+#                               define PyAPI_FUNC(RTYPE) __declspec(dllimport) RTYPE\r
+#                       endif /* !__CYGWIN__ */\r
+#                       define PyAPI_DATA(RTYPE) extern __declspec(dllimport) RTYPE\r
+        /* module init functions outside the core must be exported */\r
+#                       if defined(__cplusplus)\r
+#                               define PyMODINIT_FUNC extern "C" __declspec(dllexport) void\r
+#                       else /* __cplusplus */\r
+#                               define PyMODINIT_FUNC __declspec(dllexport) void\r
+#                       endif /* __cplusplus */\r
+#               endif /* Py_BUILD_CORE */\r
+#       endif /* HAVE_DECLSPEC */\r
+#endif /* Py_ENABLE_SHARED */\r
+\r
+/* If no external linkage macros defined by now, create defaults */\r
+#ifndef PyAPI_FUNC\r
+#       define PyAPI_FUNC(RTYPE) RTYPE\r
+#endif\r
+#ifndef PyAPI_DATA\r
+#       define PyAPI_DATA(RTYPE) extern RTYPE\r
+#endif\r
+#ifndef PyMODINIT_FUNC\r
+#       if defined(__cplusplus)\r
+#               define PyMODINIT_FUNC extern "C" void\r
+#       else /* __cplusplus */\r
+#               define PyMODINIT_FUNC void\r
+#       endif /* __cplusplus */\r
+#endif\r
+\r
+/* Deprecated DL_IMPORT and DL_EXPORT macros */\r
+#if defined(Py_ENABLE_SHARED) && defined (HAVE_DECLSPEC_DLL)\r
+#       if defined(Py_BUILD_CORE)\r
+#               define DL_IMPORT(RTYPE) __declspec(dllexport) RTYPE\r
+#               define DL_EXPORT(RTYPE) __declspec(dllexport) RTYPE\r
+#       else\r
+#               define DL_IMPORT(RTYPE) __declspec(dllimport) RTYPE\r
+#               define DL_EXPORT(RTYPE) __declspec(dllexport) RTYPE\r
+#       endif\r
+#endif\r
+#ifndef DL_EXPORT\r
+#       define DL_EXPORT(RTYPE) RTYPE\r
+#endif\r
+#ifndef DL_IMPORT\r
+#       define DL_IMPORT(RTYPE) RTYPE\r
+#endif\r
+/* End of deprecated DL_* macros */\r
+\r
+/* If the fd manipulation macros aren't defined,\r
+   here is a set that should do the job */\r
+\r
+#if 0 /* disabled and probably obsolete */\r
+\r
+#ifndef FD_SETSIZE\r
+#define FD_SETSIZE      256\r
+#endif\r
+\r
+#ifndef FD_SET\r
+\r
+typedef long fd_mask;\r
+\r
+#define NFDBITS (sizeof(fd_mask) * NBBY)        /* bits per mask */\r
+#ifndef howmany\r
+#define howmany(x, y)   (((x)+((y)-1))/(y))\r
+#endif /* howmany */\r
+\r
+typedef struct fd_set {\r
+    fd_mask     fds_bits[howmany(FD_SETSIZE, NFDBITS)];\r
+} fd_set;\r
+\r
+#define FD_SET(n, p)    ((p)->fds_bits[(n)/NFDBITS] |= (1 << ((n) % NFDBITS)))\r
+#define FD_CLR(n, p)    ((p)->fds_bits[(n)/NFDBITS] &= ~(1 << ((n) % NFDBITS)))\r
+#define FD_ISSET(n, p)  ((p)->fds_bits[(n)/NFDBITS] & (1 << ((n) % NFDBITS)))\r
+#define FD_ZERO(p)      memset((char *)(p), '\0', sizeof(*(p)))\r
+\r
+#endif /* FD_SET */\r
+\r
+#endif /* fd manipulation macros */\r
+\r
+\r
+/* limits.h constants that may be missing */\r
+\r
+#ifndef INT_MAX\r
+#define INT_MAX 2147483647\r
+#endif\r
+\r
+#ifndef LONG_MAX\r
+#if SIZEOF_LONG == 4\r
+#define LONG_MAX 0X7FFFFFFFL\r
+#elif SIZEOF_LONG == 8\r
+#define LONG_MAX 0X7FFFFFFFFFFFFFFFL\r
+#else\r
+#error "could not set LONG_MAX in pyport.h"\r
+#endif\r
+#endif\r
+\r
+#ifndef LONG_MIN\r
+#define LONG_MIN (-LONG_MAX-1)\r
+#endif\r
+\r
+#ifndef LONG_BIT\r
+#define LONG_BIT (8 * SIZEOF_LONG)\r
+#endif\r
+\r
+#if LONG_BIT != 8 * SIZEOF_LONG\r
+/* 04-Oct-2000 LONG_BIT is apparently (mis)defined as 64 on some recent\r
+ * 32-bit platforms using gcc.  We try to catch that here at compile-time\r
+ * rather than waiting for integer multiplication to trigger bogus\r
+ * overflows.\r
+ */\r
+#error "LONG_BIT definition appears wrong for platform (bad gcc/glibc config?)."\r
+#endif\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+\r
+/*\r
+ * Hide GCC attributes from compilers that don't support them.\r
+ */\r
+#if (!defined(__GNUC__) || __GNUC__ < 2 || \\r
+     (__GNUC__ == 2 && __GNUC_MINOR__ < 7) ) && \\r
+    !defined(RISCOS)\r
+#define Py_GCC_ATTRIBUTE(x)\r
+#else\r
+#define Py_GCC_ATTRIBUTE(x) __attribute__(x)\r
+#endif\r
+\r
+/*\r
+ * Add PyArg_ParseTuple format where available.\r
+ */\r
+#ifdef HAVE_ATTRIBUTE_FORMAT_PARSETUPLE\r
+#define Py_FORMAT_PARSETUPLE(func,p1,p2) __attribute__((format(func,p1,p2)))\r
+#else\r
+#define Py_FORMAT_PARSETUPLE(func,p1,p2)\r
+#endif\r
+\r
+/*\r
+ * Specify alignment on compilers that support it.\r
+ */\r
+#if defined(__GNUC__) && __GNUC__ >= 3\r
+#define Py_ALIGNED(x) __attribute__((aligned(x)))\r
+#else\r
+#define Py_ALIGNED(x)\r
+#endif\r
+\r
+/* Eliminate end-of-loop code not reached warnings from SunPro C\r
+ * when using do{...}while(0) macros\r
+ */\r
+#ifdef __SUNPRO_C\r
+#pragma error_messages (off,E_END_OF_LOOP_CODE_NOT_REACHED)\r
+#endif\r
+\r
+/*\r
+ * Older Microsoft compilers don't support the C99 long long literal suffixes,\r
+ * so these will be defined in PC/pyconfig.h for those compilers.\r
+ */\r
+#ifndef Py_LL\r
+#define Py_LL(x) x##LL\r
+#endif\r
+\r
+#ifndef Py_ULL\r
+#define Py_ULL(x) Py_LL(x##U)\r
+#endif\r
+\r
+#endif /* Py_PYPORT_H */\r