Tim Peters | 7d3a511 | 2000-07-08 04:17:21 +0000 | [diff] [blame] | 1 | #ifndef Py_PYPORT_H |
Vladimir Marangozov | 14a4d88 | 2000-07-10 04:59:49 +0000 | [diff] [blame] | 2 | #define Py_PYPORT_H |
Tim Peters | 7d3a511 | 2000-07-08 04:17:21 +0000 | [diff] [blame] | 3 | |
Martin v. Löwis | 4f1cd8b | 2001-07-26 13:41:06 +0000 | [diff] [blame] | 4 | #include "pyconfig.h" /* include for defines */ |
Peter Schneider-Kamp | 25f6894 | 2000-07-31 22:19:30 +0000 | [diff] [blame] | 5 | |
Tim Peters | 7d3a511 | 2000-07-08 04:17:21 +0000 | [diff] [blame] | 6 | /************************************************************************** |
| 7 | Symbols and macros to supply platform-independent interfaces to basic |
Tim Peters | 1be4684 | 2000-07-23 18:10:18 +0000 | [diff] [blame] | 8 | C language & library operations whose spellings vary across platforms. |
Tim Peters | 7d3a511 | 2000-07-08 04:17:21 +0000 | [diff] [blame] | 9 | |
| 10 | Please try to make documentation here as clear as possible: by definition, |
| 11 | the stuff here is trying to illuminate C's darkest corners. |
| 12 | |
| 13 | Config #defines referenced here: |
| 14 | |
| 15 | SIGNED_RIGHT_SHIFT_ZERO_FILLS |
| 16 | Meaning: To be defined iff i>>j does not extend the sign bit when i is a |
| 17 | signed integral type and i < 0. |
| 18 | Used in: Py_ARITHMETIC_RIGHT_SHIFT |
Tim Peters | 1be4684 | 2000-07-23 18:10:18 +0000 | [diff] [blame] | 19 | |
Tim Peters | 8315ea5 | 2000-07-23 19:28:35 +0000 | [diff] [blame] | 20 | Py_DEBUG |
| 21 | Meaning: Extra checks compiled in for debug mode. |
| 22 | Used in: Py_SAFE_DOWNCAST |
Barry Warsaw | fd847b2 | 2000-08-18 04:48:18 +0000 | [diff] [blame] | 23 | |
| 24 | HAVE_UINTPTR_T |
| 25 | Meaning: The C9X type uintptr_t is supported by the compiler |
| 26 | Used in: Py_uintptr_t |
| 27 | |
| 28 | HAVE_LONG_LONG |
| 29 | Meaning: The compiler supports the C type "long long" |
Martin v. Löwis | b9a0f91 | 2003-03-29 10:06:18 +0000 | [diff] [blame] | 30 | Used in: PY_LONG_LONG |
Barry Warsaw | fd847b2 | 2000-08-18 04:48:18 +0000 | [diff] [blame] | 31 | |
Tim Peters | 7d3a511 | 2000-07-08 04:17:21 +0000 | [diff] [blame] | 32 | **************************************************************************/ |
| 33 | |
| 34 | |
Vladimir Marangozov | e2bf7e6 | 2000-09-08 12:55:35 +0000 | [diff] [blame] | 35 | /* For backward compatibility only. Obsolete, do not use. */ |
Vladimir Marangozov | e2bf7e6 | 2000-09-08 12:55:35 +0000 | [diff] [blame] | 36 | #ifdef HAVE_PROTOTYPES |
| 37 | #define Py_PROTO(x) x |
| 38 | #else |
| 39 | #define Py_PROTO(x) () |
| 40 | #endif |
Marc-André Lemburg | 77317ca | 2000-10-05 17:25:45 +0000 | [diff] [blame] | 41 | #ifndef Py_FPROTO |
| 42 | #define Py_FPROTO(x) Py_PROTO(x) |
| 43 | #endif |
Peter Schneider-Kamp | 7e01890 | 2000-07-31 15:28:04 +0000 | [diff] [blame] | 44 | |
Barry Warsaw | fd847b2 | 2000-08-18 04:48:18 +0000 | [diff] [blame] | 45 | /* typedefs for some C9X-defined synonyms for integral types. |
| 46 | * |
| 47 | * The names in Python are exactly the same as the C9X names, except with a |
| 48 | * Py_ prefix. Until C9X is universally implemented, this is the only way |
| 49 | * to ensure that Python gets reliable names that don't conflict with names |
| 50 | * in non-Python code that are playing their own tricks to define the C9X |
| 51 | * names. |
| 52 | * |
| 53 | * NOTE: don't go nuts here! Python has no use for *most* of the C9X |
| 54 | * integral synonyms. Only define the ones we actually need. |
| 55 | */ |
| 56 | |
| 57 | #ifdef HAVE_LONG_LONG |
Martin v. Löwis | b9a0f91 | 2003-03-29 10:06:18 +0000 | [diff] [blame] | 58 | #ifndef PY_LONG_LONG |
| 59 | #define PY_LONG_LONG long long |
Barry Warsaw | fd847b2 | 2000-08-18 04:48:18 +0000 | [diff] [blame] | 60 | #endif |
| 61 | #endif /* HAVE_LONG_LONG */ |
| 62 | |
| 63 | /* uintptr_t is the C9X name for an unsigned integral type such that a |
| 64 | * legitimate void* can be cast to uintptr_t and then back to void* again |
Tim Peters | 79248aa | 2001-08-29 21:37:10 +0000 | [diff] [blame] | 65 | * without loss of information. Similarly for intptr_t, wrt a signed |
| 66 | * integral type. |
Barry Warsaw | fd847b2 | 2000-08-18 04:48:18 +0000 | [diff] [blame] | 67 | */ |
| 68 | #ifdef HAVE_UINTPTR_T |
Tim Peters | 79248aa | 2001-08-29 21:37:10 +0000 | [diff] [blame] | 69 | typedef uintptr_t Py_uintptr_t; |
| 70 | typedef intptr_t Py_intptr_t; |
| 71 | |
Barry Warsaw | fd847b2 | 2000-08-18 04:48:18 +0000 | [diff] [blame] | 72 | #elif SIZEOF_VOID_P <= SIZEOF_INT |
Tim Peters | 79248aa | 2001-08-29 21:37:10 +0000 | [diff] [blame] | 73 | typedef unsigned int Py_uintptr_t; |
| 74 | typedef int Py_intptr_t; |
| 75 | |
Barry Warsaw | fd847b2 | 2000-08-18 04:48:18 +0000 | [diff] [blame] | 76 | #elif SIZEOF_VOID_P <= SIZEOF_LONG |
Tim Peters | 79248aa | 2001-08-29 21:37:10 +0000 | [diff] [blame] | 77 | typedef unsigned long Py_uintptr_t; |
| 78 | typedef long Py_intptr_t; |
| 79 | |
Barry Warsaw | fd847b2 | 2000-08-18 04:48:18 +0000 | [diff] [blame] | 80 | #elif defined(HAVE_LONG_LONG) && (SIZEOF_VOID_P <= SIZEOF_LONG_LONG) |
Martin v. Löwis | b9a0f91 | 2003-03-29 10:06:18 +0000 | [diff] [blame] | 81 | typedef unsigned PY_LONG_LONG Py_uintptr_t; |
| 82 | typedef PY_LONG_LONG Py_intptr_t; |
Tim Peters | 79248aa | 2001-08-29 21:37:10 +0000 | [diff] [blame] | 83 | |
Barry Warsaw | fd847b2 | 2000-08-18 04:48:18 +0000 | [diff] [blame] | 84 | #else |
| 85 | # error "Python needs a typedef for Py_uintptr_t in pyport.h." |
| 86 | #endif /* HAVE_UINTPTR_T */ |
| 87 | |
Tim Peters | ae1d0c9 | 2006-03-17 03:29:34 +0000 | [diff] [blame] | 88 | /* Py_ssize_t is a signed integral type such that sizeof(Py_ssize_t) == |
| 89 | * sizeof(size_t). C99 doesn't define such a thing directly (size_t is an |
| 90 | * unsigned integral type). See PEP 353 for details. |
| 91 | */ |
Martin v. Löwis | 18e1655 | 2006-02-15 17:27:45 +0000 | [diff] [blame] | 92 | #ifdef HAVE_SSIZE_T |
| 93 | typedef ssize_t Py_ssize_t; |
| 94 | #elif SIZEOF_VOID_P == SIZEOF_SIZE_T |
Martin v. Löwis | 2d65b55 | 2006-02-18 18:26:55 +0000 | [diff] [blame] | 95 | typedef Py_intptr_t Py_ssize_t; |
Martin v. Löwis | 18e1655 | 2006-02-15 17:27:45 +0000 | [diff] [blame] | 96 | #else |
| 97 | # error "Python needs a typedef for Py_ssize_t in pyport.h." |
| 98 | #endif |
Tim Peters | ae1d0c9 | 2006-03-17 03:29:34 +0000 | [diff] [blame] | 99 | |
| 100 | /* Largest positive value of type Py_ssize_t. */ |
Martin v. Löwis | 18e1655 | 2006-02-15 17:27:45 +0000 | [diff] [blame] | 101 | #define PY_SSIZE_T_MAX ((Py_ssize_t)(((size_t)-1)>>1)) |
| 102 | |
Tim Peters | ae1d0c9 | 2006-03-17 03:29:34 +0000 | [diff] [blame] | 103 | /* PY_FORMAT_SIZE_T is a platform-specific modifier for use in a printf |
| 104 | * format to convert an argument with the width of a size_t or Py_ssize_t. |
| 105 | * C99 introduced "z" for this purpose, but not all platforms support that; |
| 106 | * e.g., MS compilers use "I" instead. |
| 107 | * |
| 108 | * These "high level" Python format functions interpret "z" correctly on |
| 109 | * all platforms (Python interprets the format string itself, and does whatever |
| 110 | * the platform C requires to convert a size_t/Py_ssize_t argument): |
| 111 | * |
| 112 | * PyString_FromFormat |
| 113 | * PyErr_Format |
| 114 | * PyString_FromFormatV |
| 115 | * |
| 116 | * Lower-level uses require that you interpolate the correct format modifier |
| 117 | * yourself (e.g., calling printf, fprintf, sprintf, PyOS_snprintf); for |
| 118 | * example, |
| 119 | * |
| 120 | * Py_ssize_t index; |
| 121 | * fprintf(stderr, "index %" PY_FORMAT_SIZE_T "d sucks\n", index); |
| 122 | * |
| 123 | * That will expand to %ld, or %Id, or to something else correct for a |
| 124 | * Py_ssize_t on the platform. |
| 125 | */ |
| 126 | #ifndef PY_FORMAT_SIZE_T |
| 127 | # if SIZEOF_SIZE_T == SIZEOF_LONG |
| 128 | # define PY_FORMAT_SIZE_T "l" |
| 129 | # elif defined(MS_WINDOWS) |
| 130 | # define PY_FORMAT_SIZE_T "I" |
| 131 | # else |
| 132 | # error "This platform's pyconfig.h needs to define PY_FORMAT_SIZE_T" |
| 133 | # endif |
| 134 | #endif |
| 135 | |
Peter Schneider-Kamp | 7e01890 | 2000-07-31 15:28:04 +0000 | [diff] [blame] | 136 | #include <stdlib.h> |
Peter Schneider-Kamp | 7e01890 | 2000-07-31 15:28:04 +0000 | [diff] [blame] | 137 | |
Vladimir Marangozov | 2c57e07 | 2000-08-11 11:48:33 +0000 | [diff] [blame] | 138 | #include <math.h> /* Moved here from the math section, before extern "C" */ |
| 139 | |
| 140 | /******************************************** |
| 141 | * WRAPPER FOR <time.h> and/or <sys/time.h> * |
| 142 | ********************************************/ |
| 143 | |
| 144 | #ifdef TIME_WITH_SYS_TIME |
| 145 | #include <sys/time.h> |
| 146 | #include <time.h> |
| 147 | #else /* !TIME_WITH_SYS_TIME */ |
| 148 | #ifdef HAVE_SYS_TIME_H |
| 149 | #include <sys/time.h> |
| 150 | #else /* !HAVE_SYS_TIME_H */ |
| 151 | #include <time.h> |
| 152 | #endif /* !HAVE_SYS_TIME_H */ |
| 153 | #endif /* !TIME_WITH_SYS_TIME */ |
| 154 | |
| 155 | |
| 156 | /****************************** |
| 157 | * WRAPPER FOR <sys/select.h> * |
| 158 | ******************************/ |
| 159 | |
| 160 | /* NB caller must include <sys/types.h> */ |
| 161 | |
| 162 | #ifdef HAVE_SYS_SELECT_H |
| 163 | |
| 164 | #include <sys/select.h> |
| 165 | |
Vladimir Marangozov | 2c57e07 | 2000-08-11 11:48:33 +0000 | [diff] [blame] | 166 | #endif /* !HAVE_SYS_SELECT_H */ |
| 167 | |
Tim Peters | 60f42b5 | 2001-01-18 03:03:16 +0000 | [diff] [blame] | 168 | /******************************* |
| 169 | * stat() and fstat() fiddling * |
| 170 | *******************************/ |
| 171 | |
| 172 | /* We expect that stat and fstat exist on most systems. |
| 173 | * It's confirmed on Unix, Mac and Windows. |
| 174 | * If you don't have them, add |
| 175 | * #define DONT_HAVE_STAT |
| 176 | * and/or |
| 177 | * #define DONT_HAVE_FSTAT |
Tim Peters | 76f373d | 2001-07-26 21:34:59 +0000 | [diff] [blame] | 178 | * to your pyconfig.h. Python code beyond this should check HAVE_STAT and |
Tim Peters | 60f42b5 | 2001-01-18 03:03:16 +0000 | [diff] [blame] | 179 | * HAVE_FSTAT instead. |
| 180 | * Also |
| 181 | * #define DONT_HAVE_SYS_STAT_H |
| 182 | * if <sys/stat.h> doesn't exist on your platform, and |
| 183 | * #define HAVE_STAT_H |
| 184 | * if <stat.h> does (don't look at me -- ths mess is inherited). |
| 185 | */ |
| 186 | #ifndef DONT_HAVE_STAT |
| 187 | #define HAVE_STAT |
| 188 | #endif |
| 189 | |
| 190 | #ifndef DONT_HAVE_FSTAT |
| 191 | #define HAVE_FSTAT |
| 192 | #endif |
| 193 | |
Guido van Rossum | e2ae77b | 2001-10-24 20:42:55 +0000 | [diff] [blame] | 194 | #ifdef RISCOS |
| 195 | #include <sys/types.h> |
Martin v. Löwis | a94568a | 2003-05-10 07:36:56 +0000 | [diff] [blame] | 196 | #include "unixstuff.h" |
Guido van Rossum | e2ae77b | 2001-10-24 20:42:55 +0000 | [diff] [blame] | 197 | #endif |
| 198 | |
Tim Peters | 60f42b5 | 2001-01-18 03:03:16 +0000 | [diff] [blame] | 199 | #ifndef DONT_HAVE_SYS_STAT_H |
Andrew MacIntyre | 5e090fc | 2002-02-26 11:20:01 +0000 | [diff] [blame] | 200 | #if defined(PYOS_OS2) && defined(PYCC_GCC) |
| 201 | #include <sys/types.h> |
| 202 | #endif |
Tim Peters | 60f42b5 | 2001-01-18 03:03:16 +0000 | [diff] [blame] | 203 | #include <sys/stat.h> |
| 204 | #elif defined(HAVE_STAT_H) |
| 205 | #include <stat.h> |
| 206 | #endif |
| 207 | |
Martin v. Löwis | f9836ba | 2001-08-08 10:28:06 +0000 | [diff] [blame] | 208 | #if defined(PYCC_VACPP) |
| 209 | /* VisualAge C/C++ Failed to Define MountType Field in sys/stat.h */ |
| 210 | #define S_IFMT (S_IFDIR|S_IFCHR|S_IFREG) |
| 211 | #endif |
| 212 | |
| 213 | #ifndef S_ISREG |
| 214 | #define S_ISREG(x) (((x) & S_IFMT) == S_IFREG) |
| 215 | #endif |
| 216 | |
| 217 | #ifndef S_ISDIR |
| 218 | #define S_ISDIR(x) (((x) & S_IFMT) == S_IFDIR) |
| 219 | #endif |
| 220 | |
Vladimir Marangozov | 2c57e07 | 2000-08-11 11:48:33 +0000 | [diff] [blame] | 221 | |
Tim Peters | 7d3a511 | 2000-07-08 04:17:21 +0000 | [diff] [blame] | 222 | #ifdef __cplusplus |
Peter Schneider-Kamp | 7e01890 | 2000-07-31 15:28:04 +0000 | [diff] [blame] | 223 | /* Move this down here since some C++ #include's don't like to be included |
| 224 | inside an extern "C" */ |
Tim Peters | 7d3a511 | 2000-07-08 04:17:21 +0000 | [diff] [blame] | 225 | extern "C" { |
| 226 | #endif |
| 227 | |
Vladimir Marangozov | 2c57e07 | 2000-08-11 11:48:33 +0000 | [diff] [blame] | 228 | |
Tim Peters | 7d3a511 | 2000-07-08 04:17:21 +0000 | [diff] [blame] | 229 | /* Py_ARITHMETIC_RIGHT_SHIFT |
| 230 | * C doesn't define whether a right-shift of a signed integer sign-extends |
| 231 | * or zero-fills. Here a macro to force sign extension: |
| 232 | * Py_ARITHMETIC_RIGHT_SHIFT(TYPE, I, J) |
| 233 | * Return I >> J, forcing sign extension. |
| 234 | * Requirements: |
| 235 | * I is of basic signed type TYPE (char, short, int, long, or long long). |
| 236 | * TYPE is one of char, short, int, long, or long long, although long long |
| 237 | * must not be used except on platforms that support it. |
| 238 | * J is an integer >= 0 and strictly less than the number of bits in TYPE |
| 239 | * (because C doesn't define what happens for J outside that range either). |
| 240 | * Caution: |
| 241 | * I may be evaluated more than once. |
| 242 | */ |
| 243 | #ifdef SIGNED_RIGHT_SHIFT_ZERO_FILLS |
| 244 | #define Py_ARITHMETIC_RIGHT_SHIFT(TYPE, I, J) \ |
| 245 | ((I) < 0 ? ~((~(unsigned TYPE)(I)) >> (J)) : (I) >> (J)) |
| 246 | #else |
| 247 | #define Py_ARITHMETIC_RIGHT_SHIFT(TYPE, I, J) ((I) >> (J)) |
| 248 | #endif |
| 249 | |
Tim Peters | 39dce29 | 2000-08-15 03:34:48 +0000 | [diff] [blame] | 250 | /* Py_FORCE_EXPANSION(X) |
Tim Peters | 1be4684 | 2000-07-23 18:10:18 +0000 | [diff] [blame] | 251 | * "Simply" returns its argument. However, macro expansions within the |
| 252 | * argument are evaluated. This unfortunate trickery is needed to get |
| 253 | * token-pasting to work as desired in some cases. |
| 254 | */ |
| 255 | #define Py_FORCE_EXPANSION(X) X |
| 256 | |
Tim Peters | 8315ea5 | 2000-07-23 19:28:35 +0000 | [diff] [blame] | 257 | /* Py_SAFE_DOWNCAST(VALUE, WIDE, NARROW) |
| 258 | * Cast VALUE to type NARROW from type WIDE. In Py_DEBUG mode, this |
| 259 | * assert-fails if any information is lost. |
| 260 | * Caution: |
| 261 | * VALUE may be evaluated more than once. |
| 262 | */ |
| 263 | #ifdef Py_DEBUG |
| 264 | #define Py_SAFE_DOWNCAST(VALUE, WIDE, NARROW) \ |
| 265 | (assert((WIDE)(NARROW)(VALUE) == (VALUE)), (NARROW)(VALUE)) |
| 266 | #else |
| 267 | #define Py_SAFE_DOWNCAST(VALUE, WIDE, NARROW) (NARROW)(VALUE) |
| 268 | #endif |
| 269 | |
Tim Peters | 862f059 | 2004-09-23 19:11:32 +0000 | [diff] [blame] | 270 | /* Py_IS_NAN(X) |
| 271 | * Return 1 if float or double arg is a NaN, else 0. |
| 272 | * Caution: |
| 273 | * X is evaluated more than once. |
| 274 | * This may not work on all platforms. Each platform has *some* |
| 275 | * way to spell this, though -- override in pyconfig.h if you have |
| 276 | * a platform where it doesn't work. |
| 277 | */ |
| 278 | #ifndef Py_IS_NAN |
| 279 | #define Py_IS_NAN(X) ((X) != (X)) |
| 280 | #endif |
| 281 | |
Tim Peters | 39dce29 | 2000-08-15 03:34:48 +0000 | [diff] [blame] | 282 | /* Py_IS_INFINITY(X) |
| 283 | * Return 1 if float or double arg is an infinity, else 0. |
| 284 | * Caution: |
| 285 | * X is evaluated more than once. |
| 286 | * This implementation may set the underflow flag if |X| is very small; |
| 287 | * it really can't be implemented correctly (& easily) before C99. |
Tim Peters | 862f059 | 2004-09-23 19:11:32 +0000 | [diff] [blame] | 288 | * Override in pyconfig.h if you have a better spelling on your platform. |
Tim Peters | 39dce29 | 2000-08-15 03:34:48 +0000 | [diff] [blame] | 289 | */ |
Tim Peters | 862f059 | 2004-09-23 19:11:32 +0000 | [diff] [blame] | 290 | #ifndef Py_IS_INFINITY |
Tim Peters | 1a2eefd | 2000-09-08 15:45:34 +0000 | [diff] [blame] | 291 | #define Py_IS_INFINITY(X) ((X) && (X)*0.5 == (X)) |
Tim Peters | 862f059 | 2004-09-23 19:11:32 +0000 | [diff] [blame] | 292 | #endif |
Thomas Wouters | 1e0c2f4 | 2000-07-24 16:06:23 +0000 | [diff] [blame] | 293 | |
Tim Peters | 1de41bf | 2002-07-03 03:31:20 +0000 | [diff] [blame] | 294 | /* HUGE_VAL is supposed to expand to a positive double infinity. Python |
| 295 | * uses Py_HUGE_VAL instead because some platforms are broken in this |
| 296 | * respect. We used to embed code in pyport.h to try to worm around that, |
| 297 | * but different platforms are broken in conflicting ways. If you're on |
| 298 | * a platform where HUGE_VAL is defined incorrectly, fiddle your Python |
| 299 | * config to #define Py_HUGE_VAL to something that works on your platform. |
Tim Peters | a40c793 | 2001-09-05 22:36:56 +0000 | [diff] [blame] | 300 | */ |
Tim Peters | 1de41bf | 2002-07-03 03:31:20 +0000 | [diff] [blame] | 301 | #ifndef Py_HUGE_VAL |
Tim Peters | a40c793 | 2001-09-05 22:36:56 +0000 | [diff] [blame] | 302 | #define Py_HUGE_VAL HUGE_VAL |
| 303 | #endif |
| 304 | |
Tim Peters | 57f282a | 2001-09-05 05:38:10 +0000 | [diff] [blame] | 305 | /* Py_OVERFLOWED(X) |
| 306 | * Return 1 iff a libm function overflowed. Set errno to 0 before calling |
| 307 | * a libm function, and invoke this macro after, passing the function |
| 308 | * result. |
| 309 | * Caution: |
| 310 | * This isn't reliable. C99 no longer requires libm to set errno under |
Tim Peters | d893fd6 | 2001-09-05 06:24:24 +0000 | [diff] [blame] | 311 | * any exceptional condition, but does require +- HUGE_VAL return |
| 312 | * values on overflow. A 754 box *probably* maps HUGE_VAL to a |
| 313 | * double infinity, and we're cool if that's so, unless the input |
| 314 | * was an infinity and an infinity is the expected result. A C89 |
| 315 | * system sets errno to ERANGE, so we check for that too. We're |
Tim Peters | 57f282a | 2001-09-05 05:38:10 +0000 | [diff] [blame] | 316 | * out of luck if a C99 754 box doesn't map HUGE_VAL to +Inf, or |
| 317 | * if the returned result is a NaN, or if a C89 box returns HUGE_VAL |
| 318 | * in non-overflow cases. |
| 319 | * X is evaluated more than once. |
Tim Peters | 4643bd9 | 2002-12-28 21:56:08 +0000 | [diff] [blame] | 320 | * Some platforms have better way to spell this, so expect some #ifdef'ery. |
Anthony Baxter | 83dd43f | 2003-09-30 14:58:59 +0000 | [diff] [blame] | 321 | * |
| 322 | * OpenBSD uses 'isinf()' because a compiler bug on that platform causes |
Tim Peters | 862f059 | 2004-09-23 19:11:32 +0000 | [diff] [blame] | 323 | * the longer macro version to be mis-compiled. This isn't optimal, and |
Anthony Baxter | 83dd43f | 2003-09-30 14:58:59 +0000 | [diff] [blame] | 324 | * should be removed once a newer compiler is available on that platform. |
| 325 | * The system that had the failure was running OpenBSD 3.2 on Intel, with |
| 326 | * gcc 2.95.3. |
| 327 | * |
Tim Peters | 862f059 | 2004-09-23 19:11:32 +0000 | [diff] [blame] | 328 | * According to Tim's checkin, the FreeBSD systems use isinf() to work |
Anthony Baxter | 83dd43f | 2003-09-30 14:58:59 +0000 | [diff] [blame] | 329 | * around a FPE bug on that platform. |
Tim Peters | 57f282a | 2001-09-05 05:38:10 +0000 | [diff] [blame] | 330 | */ |
Anthony Baxter | 83dd43f | 2003-09-30 14:58:59 +0000 | [diff] [blame] | 331 | #if defined(__FreeBSD__) || defined(__OpenBSD__) |
Tim Peters | 4643bd9 | 2002-12-28 21:56:08 +0000 | [diff] [blame] | 332 | #define Py_OVERFLOWED(X) isinf(X) |
| 333 | #else |
Tim Peters | a40c793 | 2001-09-05 22:36:56 +0000 | [diff] [blame] | 334 | #define Py_OVERFLOWED(X) ((X) != 0.0 && (errno == ERANGE || \ |
| 335 | (X) == Py_HUGE_VAL || \ |
| 336 | (X) == -Py_HUGE_VAL)) |
Tim Peters | 4643bd9 | 2002-12-28 21:56:08 +0000 | [diff] [blame] | 337 | #endif |
Tim Peters | a40c793 | 2001-09-05 22:36:56 +0000 | [diff] [blame] | 338 | |
Hye-Shik Chang | 77d9a3e | 2004-03-22 08:43:55 +0000 | [diff] [blame] | 339 | /* Py_SET_ERRNO_ON_MATH_ERROR(x) |
Tim Peters | a40c793 | 2001-09-05 22:36:56 +0000 | [diff] [blame] | 340 | * If a libm function did not set errno, but it looks like the result |
Hye-Shik Chang | 77d9a3e | 2004-03-22 08:43:55 +0000 | [diff] [blame] | 341 | * overflowed or not-a-number, set errno to ERANGE or EDOM. Set errno |
| 342 | * to 0 before calling a libm function, and invoke this macro after, |
| 343 | * passing the function result. |
Tim Peters | a40c793 | 2001-09-05 22:36:56 +0000 | [diff] [blame] | 344 | * Caution: |
| 345 | * This isn't reliable. See Py_OVERFLOWED comments. |
| 346 | * X is evaluated more than once. |
| 347 | */ |
Guido van Rossum | 539c662 | 2005-09-14 17:49:54 +0000 | [diff] [blame] | 348 | #if defined(__FreeBSD__) || defined(__OpenBSD__) || (defined(__hpux) && defined(__ia64)) |
Hye-Shik Chang | 77d9a3e | 2004-03-22 08:43:55 +0000 | [diff] [blame] | 349 | #define _Py_SET_EDOM_FOR_NAN(X) if (isnan(X)) errno = EDOM; |
| 350 | #else |
| 351 | #define _Py_SET_EDOM_FOR_NAN(X) ; |
| 352 | #endif |
| 353 | #define Py_SET_ERRNO_ON_MATH_ERROR(X) \ |
Tim Peters | a40c793 | 2001-09-05 22:36:56 +0000 | [diff] [blame] | 354 | do { \ |
Hye-Shik Chang | 77d9a3e | 2004-03-22 08:43:55 +0000 | [diff] [blame] | 355 | if (errno == 0) { \ |
| 356 | if ((X) == Py_HUGE_VAL || (X) == -Py_HUGE_VAL) \ |
| 357 | errno = ERANGE; \ |
| 358 | else _Py_SET_EDOM_FOR_NAN(X) \ |
| 359 | } \ |
Tim Peters | a40c793 | 2001-09-05 22:36:56 +0000 | [diff] [blame] | 360 | } while(0) |
Tim Peters | 57f282a | 2001-09-05 05:38:10 +0000 | [diff] [blame] | 361 | |
Hye-Shik Chang | 77d9a3e | 2004-03-22 08:43:55 +0000 | [diff] [blame] | 362 | /* Py_SET_ERANGE_ON_OVERFLOW(x) |
| 363 | * An alias of Py_SET_ERRNO_ON_MATH_ERROR for backward-compatibility. |
| 364 | */ |
| 365 | #define Py_SET_ERANGE_IF_OVERFLOW(X) Py_SET_ERRNO_ON_MATH_ERROR(X) |
| 366 | |
Tim Peters | dc5a508 | 2002-03-09 04:58:24 +0000 | [diff] [blame] | 367 | /* Py_ADJUST_ERANGE1(x) |
| 368 | * Py_ADJUST_ERANGE2(x, y) |
| 369 | * Set errno to 0 before calling a libm function, and invoke one of these |
| 370 | * macros after, passing the function result(s) (Py_ADJUST_ERANGE2 is useful |
| 371 | * for functions returning complex results). This makes two kinds of |
| 372 | * adjustments to errno: (A) If it looks like the platform libm set |
| 373 | * errno=ERANGE due to underflow, clear errno. (B) If it looks like the |
| 374 | * platform libm overflowed but didn't set errno, force errno to ERANGE. In |
| 375 | * effect, we're trying to force a useful implementation of C89 errno |
| 376 | * behavior. |
| 377 | * Caution: |
| 378 | * This isn't reliable. See Py_OVERFLOWED comments. |
| 379 | * X and Y may be evaluated more than once. |
| 380 | */ |
| 381 | #define Py_ADJUST_ERANGE1(X) \ |
| 382 | do { \ |
| 383 | if (errno == 0) { \ |
| 384 | if ((X) == Py_HUGE_VAL || (X) == -Py_HUGE_VAL) \ |
| 385 | errno = ERANGE; \ |
| 386 | } \ |
| 387 | else if (errno == ERANGE && (X) == 0.0) \ |
| 388 | errno = 0; \ |
| 389 | } while(0) |
| 390 | |
| 391 | #define Py_ADJUST_ERANGE2(X, Y) \ |
| 392 | do { \ |
| 393 | if ((X) == Py_HUGE_VAL || (X) == -Py_HUGE_VAL || \ |
| 394 | (Y) == Py_HUGE_VAL || (Y) == -Py_HUGE_VAL) { \ |
| 395 | if (errno == 0) \ |
| 396 | errno = ERANGE; \ |
| 397 | } \ |
| 398 | else if (errno == ERANGE) \ |
| 399 | errno = 0; \ |
| 400 | } while(0) |
| 401 | |
Neal Norwitz | 8029264 | 2002-12-19 15:12:26 +0000 | [diff] [blame] | 402 | /* Py_DEPRECATED(version) |
Neal Norwitz | 93344ab | 2002-12-19 15:24:11 +0000 | [diff] [blame] | 403 | * Declare a variable, type, or function deprecated. |
Neal Norwitz | 8029264 | 2002-12-19 15:12:26 +0000 | [diff] [blame] | 404 | * Usage: |
| 405 | * extern int old_var Py_DEPRECATED(2.3); |
| 406 | * typedef int T1 Py_DEPRECATED(2.4); |
| 407 | * extern int x() Py_DEPRECATED(2.5); |
| 408 | */ |
Neal Norwitz | 3dd8be4 | 2006-03-20 06:33:01 +0000 | [diff] [blame] | 409 | #if defined(__GNUC__) && ((__GNUC__ >= 4) || \ |
| 410 | (__GNUC__ == 3) && (__GNUC_MINOR__ >= 1)) |
Neal Norwitz | 8029264 | 2002-12-19 15:12:26 +0000 | [diff] [blame] | 411 | #define Py_DEPRECATED(VERSION_UNUSED) __attribute__((__deprecated__)) |
| 412 | #else |
Tim Peters | 4643bd9 | 2002-12-28 21:56:08 +0000 | [diff] [blame] | 413 | #define Py_DEPRECATED(VERSION_UNUSED) |
Neal Norwitz | 8029264 | 2002-12-19 15:12:26 +0000 | [diff] [blame] | 414 | #endif |
| 415 | |
Thomas Wouters | 1e0c2f4 | 2000-07-24 16:06:23 +0000 | [diff] [blame] | 416 | /************************************************************************** |
| 417 | Prototypes that are missing from the standard include files on some systems |
| 418 | (and possibly only some versions of such systems.) |
| 419 | |
| 420 | Please be conservative with adding new ones, document them and enclose them |
| 421 | in platform-specific #ifdefs. |
| 422 | **************************************************************************/ |
| 423 | |
| 424 | #ifdef SOLARIS |
| 425 | /* Unchecked */ |
| 426 | extern int gethostname(char *, int); |
| 427 | #endif |
| 428 | |
| 429 | #ifdef __BEOS__ |
| 430 | /* Unchecked */ |
| 431 | /* It's in the libs, but not the headers... - [cjh] */ |
Tim Peters | 60f42b5 | 2001-01-18 03:03:16 +0000 | [diff] [blame] | 432 | int shutdown( int, int ); |
Thomas Wouters | 1e0c2f4 | 2000-07-24 16:06:23 +0000 | [diff] [blame] | 433 | #endif |
| 434 | |
| 435 | #ifdef HAVE__GETPTY |
Sjoerd Mullender | 0765fe3 | 2000-07-26 15:46:29 +0000 | [diff] [blame] | 436 | #include <sys/types.h> /* we need to import mode_t */ |
Thomas Wouters | 1e0c2f4 | 2000-07-24 16:06:23 +0000 | [diff] [blame] | 437 | extern char * _getpty(int *, int, mode_t, int); |
| 438 | #endif |
| 439 | |
| 440 | #if defined(HAVE_OPENPTY) || defined(HAVE_FORKPTY) |
| 441 | #if !defined(HAVE_PTY_H) && !defined(HAVE_LIBUTIL_H) |
| 442 | /* BSDI does not supply a prototype for the 'openpty' and 'forkpty' |
| 443 | functions, even though they are included in libutil. */ |
| 444 | #include <termios.h> |
| 445 | extern int openpty(int *, int *, char *, struct termios *, struct winsize *); |
| 446 | extern int forkpty(int *, char *, struct termios *, struct winsize *); |
| 447 | #endif /* !defined(HAVE_PTY_H) && !defined(HAVE_LIBUTIL_H) */ |
| 448 | #endif /* defined(HAVE_OPENPTY) || defined(HAVE_FORKPTY) */ |
| 449 | |
| 450 | |
| 451 | /* These are pulled from various places. It isn't obvious on what platforms |
| 452 | they are necessary, nor what the exact prototype should look like (which |
| 453 | is likely to vary between platforms!) If you find you need one of these |
| 454 | declarations, please move them to a platform-specific block and include |
| 455 | proper prototypes. */ |
| 456 | #if 0 |
| 457 | |
| 458 | /* From Modules/resource.c */ |
| 459 | extern int getrusage(); |
| 460 | extern int getpagesize(); |
| 461 | |
| 462 | /* From Python/sysmodule.c and Modules/posixmodule.c */ |
| 463 | extern int fclose(FILE *); |
| 464 | |
| 465 | /* From Modules/posixmodule.c */ |
| 466 | extern int fdatasync(int); |
Thomas Wouters | 1e0c2f4 | 2000-07-24 16:06:23 +0000 | [diff] [blame] | 467 | #endif /* 0 */ |
| 468 | |
Peter Schneider-Kamp | 7e01890 | 2000-07-31 15:28:04 +0000 | [diff] [blame] | 469 | |
| 470 | /************************ |
| 471 | * WRAPPER FOR <math.h> * |
| 472 | ************************/ |
| 473 | |
Peter Schneider-Kamp | 7e01890 | 2000-07-31 15:28:04 +0000 | [diff] [blame] | 474 | #ifndef HAVE_HYPOT |
| 475 | extern double hypot(double, double); |
Tim Peters | 60f42b5 | 2001-01-18 03:03:16 +0000 | [diff] [blame] | 476 | #endif |
Peter Schneider-Kamp | 7e01890 | 2000-07-31 15:28:04 +0000 | [diff] [blame] | 477 | |
Hye-Shik Chang | b5047fd | 2004-08-04 06:33:51 +0000 | [diff] [blame] | 478 | |
Hye-Shik Chang | f303261 | 2006-03-22 08:52:43 +0000 | [diff] [blame^] | 479 | /* On 4.4BSD-descendants, ctype functions serves the whole range of |
| 480 | * wchar_t character set rather than single byte code points only. |
| 481 | * This characteristic can break some operations of string object |
| 482 | * including str.upper() and str.split() on UTF-8 locales. This |
| 483 | * workaround was provided by Tim Robbins of FreeBSD project. |
| 484 | */ |
Hye-Shik Chang | b5047fd | 2004-08-04 06:33:51 +0000 | [diff] [blame] | 485 | |
| 486 | #ifdef __FreeBSD__ |
| 487 | #include <osreldate.h> |
| 488 | #if __FreeBSD_version > 500039 |
| 489 | #include <ctype.h> |
| 490 | #include <wctype.h> |
| 491 | #undef isalnum |
| 492 | #define isalnum(c) iswalnum(btowc(c)) |
| 493 | #undef isalpha |
| 494 | #define isalpha(c) iswalpha(btowc(c)) |
| 495 | #undef islower |
| 496 | #define islower(c) iswlower(btowc(c)) |
| 497 | #undef isspace |
| 498 | #define isspace(c) iswspace(btowc(c)) |
| 499 | #undef isupper |
| 500 | #define isupper(c) iswupper(btowc(c)) |
| 501 | #undef tolower |
| 502 | #define tolower(c) towlower(btowc(c)) |
| 503 | #undef toupper |
| 504 | #define toupper(c) towupper(btowc(c)) |
| 505 | #endif |
| 506 | #endif |
| 507 | |
| 508 | |
Mark Hammond | 8235ea1 | 2002-07-19 06:55:41 +0000 | [diff] [blame] | 509 | /* Declarations for symbol visibility. |
| 510 | |
| 511 | PyAPI_FUNC(type): Declares a public Python API function and return type |
Tim Peters | 4643bd9 | 2002-12-28 21:56:08 +0000 | [diff] [blame] | 512 | PyAPI_DATA(type): Declares public Python data and its type |
Mark Hammond | 8235ea1 | 2002-07-19 06:55:41 +0000 | [diff] [blame] | 513 | PyMODINIT_FUNC: A Python module init function. If these functions are |
Tim Peters | 4643bd9 | 2002-12-28 21:56:08 +0000 | [diff] [blame] | 514 | inside the Python core, they are private to the core. |
| 515 | If in an extension module, it may be declared with |
Mark Hammond | 8235ea1 | 2002-07-19 06:55:41 +0000 | [diff] [blame] | 516 | external linkage depending on the platform. |
| 517 | |
| 518 | As a number of platforms support/require "__declspec(dllimport/dllexport)", |
| 519 | we support a HAVE_DECLSPEC_DLL macro to save duplication. |
| 520 | */ |
| 521 | |
Tim Peters | 4643bd9 | 2002-12-28 21:56:08 +0000 | [diff] [blame] | 522 | /* |
Michael W. Hudson | f163d10 | 2003-02-10 19:36:46 +0000 | [diff] [blame] | 523 | All windows ports, except cygwin, are handled in PC/pyconfig.h. |
| 524 | |
| 525 | BeOS and cygwin are the only other autoconf platform requiring special |
| 526 | linkage handling and both of these use __declspec(). |
Mark Hammond | 8235ea1 | 2002-07-19 06:55:41 +0000 | [diff] [blame] | 527 | */ |
| 528 | #if defined(__CYGWIN__) || defined(__BEOS__) |
| 529 | # define HAVE_DECLSPEC_DLL |
Peter Schneider-Kamp | 7e01890 | 2000-07-31 15:28:04 +0000 | [diff] [blame] | 530 | #endif |
Mark Hammond | 8235ea1 | 2002-07-19 06:55:41 +0000 | [diff] [blame] | 531 | |
Jason Tishler | 3076559 | 2003-09-04 11:04:06 +0000 | [diff] [blame] | 532 | /* only get special linkage if built as shared or platform is Cygwin */ |
| 533 | #if defined(Py_ENABLE_SHARED) || defined(__CYGWIN__) |
Mark Hammond | 8235ea1 | 2002-07-19 06:55:41 +0000 | [diff] [blame] | 534 | # if defined(HAVE_DECLSPEC_DLL) |
| 535 | # ifdef Py_BUILD_CORE |
| 536 | # define PyAPI_FUNC(RTYPE) __declspec(dllexport) RTYPE |
Mark Hammond | a290527 | 2002-07-29 13:42:14 +0000 | [diff] [blame] | 537 | # define PyAPI_DATA(RTYPE) extern __declspec(dllexport) RTYPE |
Mark Hammond | 8235ea1 | 2002-07-19 06:55:41 +0000 | [diff] [blame] | 538 | /* module init functions inside the core need no external linkage */ |
Jason Tishler | 6bc06ec | 2003-09-04 11:59:50 +0000 | [diff] [blame] | 539 | /* except for Cygwin to handle embedding (FIXME: BeOS too?) */ |
| 540 | # if defined(__CYGWIN__) |
| 541 | # define PyMODINIT_FUNC __declspec(dllexport) void |
| 542 | # else /* __CYGWIN__ */ |
| 543 | # define PyMODINIT_FUNC void |
| 544 | # endif /* __CYGWIN__ */ |
Mark Hammond | 8235ea1 | 2002-07-19 06:55:41 +0000 | [diff] [blame] | 545 | # else /* Py_BUILD_CORE */ |
| 546 | /* Building an extension module, or an embedded situation */ |
| 547 | /* public Python functions and data are imported */ |
Jason Tishler | fb8595d | 2003-01-06 12:41:26 +0000 | [diff] [blame] | 548 | /* Under Cygwin, auto-import functions to prevent compilation */ |
| 549 | /* failures similar to http://python.org/doc/FAQ.html#3.24 */ |
| 550 | # if !defined(__CYGWIN__) |
| 551 | # define PyAPI_FUNC(RTYPE) __declspec(dllimport) RTYPE |
| 552 | # endif /* !__CYGWIN__ */ |
Mark Hammond | a290527 | 2002-07-29 13:42:14 +0000 | [diff] [blame] | 553 | # define PyAPI_DATA(RTYPE) extern __declspec(dllimport) RTYPE |
Mark Hammond | 8235ea1 | 2002-07-19 06:55:41 +0000 | [diff] [blame] | 554 | /* module init functions outside the core must be exported */ |
| 555 | # if defined(__cplusplus) |
| 556 | # define PyMODINIT_FUNC extern "C" __declspec(dllexport) void |
| 557 | # else /* __cplusplus */ |
| 558 | # define PyMODINIT_FUNC __declspec(dllexport) void |
| 559 | # endif /* __cplusplus */ |
| 560 | # endif /* Py_BUILD_CORE */ |
| 561 | # endif /* HAVE_DECLSPEC */ |
| 562 | #endif /* Py_ENABLE_SHARED */ |
| 563 | |
| 564 | /* If no external linkage macros defined by now, create defaults */ |
| 565 | #ifndef PyAPI_FUNC |
| 566 | # define PyAPI_FUNC(RTYPE) RTYPE |
| 567 | #endif |
| 568 | #ifndef PyAPI_DATA |
Mark Hammond | a290527 | 2002-07-29 13:42:14 +0000 | [diff] [blame] | 569 | # define PyAPI_DATA(RTYPE) extern RTYPE |
Mark Hammond | 8235ea1 | 2002-07-19 06:55:41 +0000 | [diff] [blame] | 570 | #endif |
| 571 | #ifndef PyMODINIT_FUNC |
| 572 | # if defined(__cplusplus) |
| 573 | # define PyMODINIT_FUNC extern "C" void |
| 574 | # else /* __cplusplus */ |
| 575 | # define PyMODINIT_FUNC void |
| 576 | # endif /* __cplusplus */ |
| 577 | #endif |
| 578 | |
| 579 | /* Deprecated DL_IMPORT and DL_EXPORT macros */ |
| 580 | #if defined(Py_ENABLE_SHARED) && defined (HAVE_DECLSPEC_DLL) |
| 581 | # if defined(Py_BUILD_CORE) |
| 582 | # define DL_IMPORT(RTYPE) __declspec(dllexport) RTYPE |
| 583 | # define DL_EXPORT(RTYPE) __declspec(dllexport) RTYPE |
| 584 | # else |
| 585 | # define DL_IMPORT(RTYPE) __declspec(dllimport) RTYPE |
| 586 | # define DL_EXPORT(RTYPE) __declspec(dllexport) RTYPE |
| 587 | # endif |
| 588 | #endif |
| 589 | #ifndef DL_EXPORT |
| 590 | # define DL_EXPORT(RTYPE) RTYPE |
| 591 | #endif |
| 592 | #ifndef DL_IMPORT |
| 593 | # define DL_IMPORT(RTYPE) RTYPE |
| 594 | #endif |
| 595 | /* End of deprecated DL_* macros */ |
Peter Schneider-Kamp | 7e01890 | 2000-07-31 15:28:04 +0000 | [diff] [blame] | 596 | |
Peter Schneider-Kamp | 7e01890 | 2000-07-31 15:28:04 +0000 | [diff] [blame] | 597 | /* If the fd manipulation macros aren't defined, |
| 598 | here is a set that should do the job */ |
| 599 | |
Guido van Rossum | 367e46a | 2000-08-01 18:28:44 +0000 | [diff] [blame] | 600 | #if 0 /* disabled and probably obsolete */ |
Peter Schneider-Kamp | 1c2b178 | 2000-08-01 16:53:44 +0000 | [diff] [blame] | 601 | |
Peter Schneider-Kamp | 7e01890 | 2000-07-31 15:28:04 +0000 | [diff] [blame] | 602 | #ifndef FD_SETSIZE |
| 603 | #define FD_SETSIZE 256 |
| 604 | #endif |
| 605 | |
| 606 | #ifndef FD_SET |
| 607 | |
| 608 | typedef long fd_mask; |
| 609 | |
| 610 | #define NFDBITS (sizeof(fd_mask) * NBBY) /* bits per mask */ |
| 611 | #ifndef howmany |
| 612 | #define howmany(x, y) (((x)+((y)-1))/(y)) |
| 613 | #endif /* howmany */ |
| 614 | |
| 615 | typedef struct fd_set { |
| 616 | fd_mask fds_bits[howmany(FD_SETSIZE, NFDBITS)]; |
| 617 | } fd_set; |
| 618 | |
| 619 | #define FD_SET(n, p) ((p)->fds_bits[(n)/NFDBITS] |= (1 << ((n) % NFDBITS))) |
| 620 | #define FD_CLR(n, p) ((p)->fds_bits[(n)/NFDBITS] &= ~(1 << ((n) % NFDBITS))) |
| 621 | #define FD_ISSET(n, p) ((p)->fds_bits[(n)/NFDBITS] & (1 << ((n) % NFDBITS))) |
| 622 | #define FD_ZERO(p) memset((char *)(p), '\0', sizeof(*(p))) |
| 623 | |
| 624 | #endif /* FD_SET */ |
Peter Schneider-Kamp | 1c2b178 | 2000-08-01 16:53:44 +0000 | [diff] [blame] | 625 | |
| 626 | #endif /* fd manipulation macros */ |
| 627 | |
Vladimir Marangozov | 2c57e07 | 2000-08-11 11:48:33 +0000 | [diff] [blame] | 628 | |
Fred Drake | d5fadf7 | 2000-09-26 05:46:01 +0000 | [diff] [blame] | 629 | /* limits.h constants that may be missing */ |
| 630 | |
| 631 | #ifndef INT_MAX |
| 632 | #define INT_MAX 2147483647 |
| 633 | #endif |
| 634 | |
| 635 | #ifndef LONG_MAX |
| 636 | #if SIZEOF_LONG == 4 |
| 637 | #define LONG_MAX 0X7FFFFFFFL |
| 638 | #elif SIZEOF_LONG == 8 |
| 639 | #define LONG_MAX 0X7FFFFFFFFFFFFFFFL |
| 640 | #else |
| 641 | #error "could not set LONG_MAX in pyport.h" |
| 642 | #endif |
| 643 | #endif |
| 644 | |
| 645 | #ifndef LONG_MIN |
| 646 | #define LONG_MIN (-LONG_MAX-1) |
| 647 | #endif |
| 648 | |
Tim Peters | d57731f | 2000-10-05 01:42:25 +0000 | [diff] [blame] | 649 | #ifndef LONG_BIT |
| 650 | #define LONG_BIT (8 * SIZEOF_LONG) |
| 651 | #endif |
| 652 | |
| 653 | #if LONG_BIT != 8 * SIZEOF_LONG |
| 654 | /* 04-Oct-2000 LONG_BIT is apparently (mis)defined as 64 on some recent |
| 655 | * 32-bit platforms using gcc. We try to catch that here at compile-time |
| 656 | * rather than waiting for integer multiplication to trigger bogus |
| 657 | * overflows. |
| 658 | */ |
Andrew M. Kuchling | 234fb63 | 2001-01-12 15:06:28 +0000 | [diff] [blame] | 659 | #error "LONG_BIT definition appears wrong for platform (bad gcc/glibc config?)." |
Tim Peters | d57731f | 2000-10-05 01:42:25 +0000 | [diff] [blame] | 660 | #endif |
| 661 | |
Tim Peters | 7d3a511 | 2000-07-08 04:17:21 +0000 | [diff] [blame] | 662 | #ifdef __cplusplus |
| 663 | } |
| 664 | #endif |
| 665 | |
Neil Schemenauer | 1569108 | 2001-10-23 02:20:37 +0000 | [diff] [blame] | 666 | /* |
| 667 | * Hide GCC attributes from compilers that don't support them. |
| 668 | */ |
Guido van Rossum | bd67d6f | 2001-10-27 21:16:16 +0000 | [diff] [blame] | 669 | #if (!defined(__GNUC__) || __GNUC__ < 2 || \ |
Jack Jansen | 4892f24 | 2002-02-01 15:46:29 +0000 | [diff] [blame] | 670 | (__GNUC__ == 2 && __GNUC_MINOR__ < 7) ) && \ |
Guido van Rossum | bd67d6f | 2001-10-27 21:16:16 +0000 | [diff] [blame] | 671 | !defined(RISCOS) |
Neil Schemenauer | 96aa0ac | 2002-09-15 14:09:54 +0000 | [diff] [blame] | 672 | #define Py_GCC_ATTRIBUTE(x) |
| 673 | #else |
| 674 | #define Py_GCC_ATTRIBUTE(x) __attribute__(x) |
Neil Schemenauer | 1569108 | 2001-10-23 02:20:37 +0000 | [diff] [blame] | 675 | #endif |
| 676 | |
Nicholas Bastin | 9ba301e | 2004-07-15 15:54:05 +0000 | [diff] [blame] | 677 | /* Eliminate end-of-loop code not reached warnings from SunPro C |
| 678 | * when using do{...}while(0) macros |
| 679 | */ |
| 680 | #ifdef __SUNPRO_C |
| 681 | #pragma error_messages (off,E_END_OF_LOOP_CODE_NOT_REACHED) |
| 682 | #endif |
| 683 | |
Tim Peters | 7d3a511 | 2000-07-08 04:17:21 +0000 | [diff] [blame] | 684 | #endif /* Py_PYPORT_H */ |