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 | |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 6 | #ifdef HAVE_STDINT_H |
| 7 | #include <stdint.h> |
| 8 | #endif |
| 9 | |
Tim Peters | 7d3a511 | 2000-07-08 04:17:21 +0000 | [diff] [blame] | 10 | /************************************************************************** |
| 11 | Symbols and macros to supply platform-independent interfaces to basic |
Tim Peters | 1be4684 | 2000-07-23 18:10:18 +0000 | [diff] [blame] | 12 | C language & library operations whose spellings vary across platforms. |
Tim Peters | 7d3a511 | 2000-07-08 04:17:21 +0000 | [diff] [blame] | 13 | |
| 14 | Please try to make documentation here as clear as possible: by definition, |
| 15 | the stuff here is trying to illuminate C's darkest corners. |
| 16 | |
| 17 | Config #defines referenced here: |
| 18 | |
| 19 | SIGNED_RIGHT_SHIFT_ZERO_FILLS |
| 20 | Meaning: To be defined iff i>>j does not extend the sign bit when i is a |
| 21 | signed integral type and i < 0. |
| 22 | Used in: Py_ARITHMETIC_RIGHT_SHIFT |
Tim Peters | 1be4684 | 2000-07-23 18:10:18 +0000 | [diff] [blame] | 23 | |
Tim Peters | 8315ea5 | 2000-07-23 19:28:35 +0000 | [diff] [blame] | 24 | Py_DEBUG |
| 25 | Meaning: Extra checks compiled in for debug mode. |
| 26 | Used in: Py_SAFE_DOWNCAST |
Barry Warsaw | fd847b2 | 2000-08-18 04:48:18 +0000 | [diff] [blame] | 27 | |
| 28 | HAVE_UINTPTR_T |
| 29 | Meaning: The C9X type uintptr_t is supported by the compiler |
| 30 | Used in: Py_uintptr_t |
| 31 | |
| 32 | HAVE_LONG_LONG |
| 33 | Meaning: The compiler supports the C type "long long" |
Martin v. Löwis | b9a0f91 | 2003-03-29 10:06:18 +0000 | [diff] [blame] | 34 | Used in: PY_LONG_LONG |
Barry Warsaw | fd847b2 | 2000-08-18 04:48:18 +0000 | [diff] [blame] | 35 | |
Tim Peters | 7d3a511 | 2000-07-08 04:17:21 +0000 | [diff] [blame] | 36 | **************************************************************************/ |
| 37 | |
Barry Warsaw | fd847b2 | 2000-08-18 04:48:18 +0000 | [diff] [blame] | 38 | /* typedefs for some C9X-defined synonyms for integral types. |
| 39 | * |
| 40 | * The names in Python are exactly the same as the C9X names, except with a |
| 41 | * Py_ prefix. Until C9X is universally implemented, this is the only way |
| 42 | * to ensure that Python gets reliable names that don't conflict with names |
| 43 | * in non-Python code that are playing their own tricks to define the C9X |
| 44 | * names. |
| 45 | * |
| 46 | * NOTE: don't go nuts here! Python has no use for *most* of the C9X |
| 47 | * integral synonyms. Only define the ones we actually need. |
| 48 | */ |
| 49 | |
| 50 | #ifdef HAVE_LONG_LONG |
Martin v. Löwis | b9a0f91 | 2003-03-29 10:06:18 +0000 | [diff] [blame] | 51 | #ifndef PY_LONG_LONG |
| 52 | #define PY_LONG_LONG long long |
Guido van Rossum | cd16bf6 | 2007-06-13 18:07:49 +0000 | [diff] [blame] | 53 | #if defined(LLONG_MAX) |
| 54 | /* If LLONG_MAX is defined in limits.h, use that. */ |
| 55 | #define PY_LLONG_MIN LLONG_MIN |
| 56 | #define PY_LLONG_MAX LLONG_MAX |
| 57 | #define PY_ULLONG_MAX ULLONG_MAX |
| 58 | #elif defined(__LONG_LONG_MAX__) |
| 59 | /* Otherwise, if GCC has a builtin define, use that. */ |
| 60 | #define PY_LLONG_MAX __LONG_LONG_MAX__ |
| 61 | #define PY_LLONG_MIN (-PY_LLONG_MAX-1) |
| 62 | #define PY_ULLONG_MAX (__LONG_LONG_MAX__*2ULL + 1ULL) |
| 63 | #else |
| 64 | /* Otherwise, rely on two's complement. */ |
| 65 | #define PY_ULLONG_MAX (~0ULL) |
| 66 | #define PY_LLONG_MAX ((long long)(PY_ULLONG_MAX>>1)) |
| 67 | #define PY_LLONG_MIN (-PY_LLONG_MAX-1) |
| 68 | #endif /* LLONG_MAX */ |
Barry Warsaw | fd847b2 | 2000-08-18 04:48:18 +0000 | [diff] [blame] | 69 | #endif |
| 70 | #endif /* HAVE_LONG_LONG */ |
| 71 | |
Mark Dickinson | bd79264 | 2009-03-18 20:06:12 +0000 | [diff] [blame^] | 72 | /* a build with 30-bit digits for Python long integers needs an exact-width |
| 73 | * 32-bit unsigned integer type to store those digits. (We could just use |
| 74 | * type 'unsigned long', but that would be wasteful on a system where longs |
| 75 | * are 64-bits.) On Unix systems, the autoconf macro AC_TYPE_UINT32_T defines |
| 76 | * uint32_t to be such a type unless stdint.h or inttypes.h defines uint32_t. |
| 77 | * However, it doesn't set HAVE_UINT32_T, so we do that here. |
| 78 | */ |
| 79 | #if (defined UINT32_MAX || defined uint32_t) |
| 80 | #ifndef PY_UINT32_T |
| 81 | #define HAVE_UINT32_T 1 |
| 82 | #define PY_UINT32_T uint32_t |
| 83 | #endif |
| 84 | #endif |
| 85 | |
| 86 | /* Macros for a 64-bit unsigned integer type; used for type 'twodigits' in the |
| 87 | * long integer implementation, when 30-bit digits are enabled. |
| 88 | */ |
| 89 | #if (defined UINT64_MAX || defined uint64_t) |
| 90 | #ifndef PY_UINT64_T |
| 91 | #define HAVE_UINT64_T 1 |
| 92 | #define PY_UINT64_T uint64_t |
| 93 | #endif |
| 94 | #endif |
| 95 | |
| 96 | /* Signed variants of the above */ |
| 97 | #if (defined INT32_MAX || defined int32_t) |
| 98 | #ifndef PY_INT32_T |
| 99 | #define HAVE_INT32_T 1 |
| 100 | #define PY_INT32_T int32_t |
| 101 | #endif |
| 102 | #endif |
| 103 | #if (defined INT64_MAX || defined int64_t) |
| 104 | #ifndef PY_INT64_T |
| 105 | #define HAVE_INT64_T 1 |
| 106 | #define PY_INT64_T int64_t |
| 107 | #endif |
| 108 | #endif |
| 109 | |
| 110 | /* If PYLONG_BITS_IN_DIGIT is not defined then we'll use 30-bit digits if all |
| 111 | the necessary integer types are available, and we're on a 64-bit platform |
| 112 | (as determined by SIZEOF_VOID_P); otherwise we use 15-bit digits. */ |
| 113 | |
| 114 | #ifndef PYLONG_BITS_IN_DIGIT |
| 115 | #if (defined HAVE_UINT64_T && defined HAVE_INT64_T && \ |
| 116 | defined HAVE_UINT32_T && defined HAVE_INT32_T && SIZEOF_VOID_P >= 8) |
| 117 | #define PYLONG_BITS_IN_DIGIT 30 |
| 118 | #else |
| 119 | #define PYLONG_BITS_IN_DIGIT 15 |
| 120 | #endif |
| 121 | #endif |
| 122 | |
Barry Warsaw | fd847b2 | 2000-08-18 04:48:18 +0000 | [diff] [blame] | 123 | /* uintptr_t is the C9X name for an unsigned integral type such that a |
| 124 | * 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] | 125 | * without loss of information. Similarly for intptr_t, wrt a signed |
| 126 | * integral type. |
Barry Warsaw | fd847b2 | 2000-08-18 04:48:18 +0000 | [diff] [blame] | 127 | */ |
| 128 | #ifdef HAVE_UINTPTR_T |
Tim Peters | 79248aa | 2001-08-29 21:37:10 +0000 | [diff] [blame] | 129 | typedef uintptr_t Py_uintptr_t; |
| 130 | typedef intptr_t Py_intptr_t; |
| 131 | |
Barry Warsaw | fd847b2 | 2000-08-18 04:48:18 +0000 | [diff] [blame] | 132 | #elif SIZEOF_VOID_P <= SIZEOF_INT |
Tim Peters | 79248aa | 2001-08-29 21:37:10 +0000 | [diff] [blame] | 133 | typedef unsigned int Py_uintptr_t; |
| 134 | typedef int Py_intptr_t; |
| 135 | |
Barry Warsaw | fd847b2 | 2000-08-18 04:48:18 +0000 | [diff] [blame] | 136 | #elif SIZEOF_VOID_P <= SIZEOF_LONG |
Tim Peters | 79248aa | 2001-08-29 21:37:10 +0000 | [diff] [blame] | 137 | typedef unsigned long Py_uintptr_t; |
| 138 | typedef long Py_intptr_t; |
| 139 | |
Barry Warsaw | fd847b2 | 2000-08-18 04:48:18 +0000 | [diff] [blame] | 140 | #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] | 141 | typedef unsigned PY_LONG_LONG Py_uintptr_t; |
| 142 | typedef PY_LONG_LONG Py_intptr_t; |
Tim Peters | 79248aa | 2001-08-29 21:37:10 +0000 | [diff] [blame] | 143 | |
Barry Warsaw | fd847b2 | 2000-08-18 04:48:18 +0000 | [diff] [blame] | 144 | #else |
| 145 | # error "Python needs a typedef for Py_uintptr_t in pyport.h." |
| 146 | #endif /* HAVE_UINTPTR_T */ |
| 147 | |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 148 | /* Py_ssize_t is a signed integral type such that sizeof(Py_ssize_t) == |
| 149 | * sizeof(size_t). C99 doesn't define such a thing directly (size_t is an |
| 150 | * unsigned integral type). See PEP 353 for details. |
| 151 | */ |
Martin v. Löwis | 18e1655 | 2006-02-15 17:27:45 +0000 | [diff] [blame] | 152 | #ifdef HAVE_SSIZE_T |
| 153 | typedef ssize_t Py_ssize_t; |
| 154 | #elif SIZEOF_VOID_P == SIZEOF_SIZE_T |
Martin v. Löwis | 2d65b55 | 2006-02-18 18:26:55 +0000 | [diff] [blame] | 155 | typedef Py_intptr_t Py_ssize_t; |
Martin v. Löwis | 18e1655 | 2006-02-15 17:27:45 +0000 | [diff] [blame] | 156 | #else |
| 157 | # error "Python needs a typedef for Py_ssize_t in pyport.h." |
| 158 | #endif |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 159 | |
Amaury Forgeot d'Arc | 9c74b14 | 2008-06-18 00:47:36 +0000 | [diff] [blame] | 160 | /* Largest possible value of size_t. |
| 161 | SIZE_MAX is part of C99, so it might be defined on some |
| 162 | platforms. If it is not defined, (size_t)-1 is a portable |
| 163 | definition for C89, due to the way signed->unsigned |
| 164 | conversion is defined. */ |
| 165 | #ifdef SIZE_MAX |
| 166 | #define PY_SIZE_MAX SIZE_MAX |
| 167 | #else |
| 168 | #define PY_SIZE_MAX ((size_t)-1) |
| 169 | #endif |
| 170 | |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 171 | /* Largest positive value of type Py_ssize_t. */ |
Martin v. Löwis | 18e1655 | 2006-02-15 17:27:45 +0000 | [diff] [blame] | 172 | #define PY_SSIZE_T_MAX ((Py_ssize_t)(((size_t)-1)>>1)) |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 173 | /* Smallest negative value of type Py_ssize_t. */ |
| 174 | #define PY_SSIZE_T_MIN (-PY_SSIZE_T_MAX-1) |
| 175 | |
Christian Heimes | 400adb0 | 2008-02-01 08:12:03 +0000 | [diff] [blame] | 176 | #if SIZEOF_PID_T > SIZEOF_LONG |
| 177 | # error "Python doesn't support sizeof(pid_t) > sizeof(long)" |
| 178 | #endif |
| 179 | |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 180 | /* PY_FORMAT_SIZE_T is a platform-specific modifier for use in a printf |
| 181 | * format to convert an argument with the width of a size_t or Py_ssize_t. |
| 182 | * C99 introduced "z" for this purpose, but not all platforms support that; |
| 183 | * e.g., MS compilers use "I" instead. |
| 184 | * |
| 185 | * These "high level" Python format functions interpret "z" correctly on |
| 186 | * all platforms (Python interprets the format string itself, and does whatever |
| 187 | * the platform C requires to convert a size_t/Py_ssize_t argument): |
| 188 | * |
Christian Heimes | 72b710a | 2008-05-26 13:28:38 +0000 | [diff] [blame] | 189 | * PyBytes_FromFormat |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 190 | * PyErr_Format |
Christian Heimes | 72b710a | 2008-05-26 13:28:38 +0000 | [diff] [blame] | 191 | * PyBytes_FromFormatV |
Walter Dörwald | 7696ed7 | 2007-05-31 15:51:35 +0000 | [diff] [blame] | 192 | * PyUnicode_FromFormatV |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 193 | * |
| 194 | * Lower-level uses require that you interpolate the correct format modifier |
| 195 | * yourself (e.g., calling printf, fprintf, sprintf, PyOS_snprintf); for |
| 196 | * example, |
| 197 | * |
| 198 | * Py_ssize_t index; |
| 199 | * fprintf(stderr, "index %" PY_FORMAT_SIZE_T "d sucks\n", index); |
| 200 | * |
| 201 | * That will expand to %ld, or %Id, or to something else correct for a |
| 202 | * Py_ssize_t on the platform. |
| 203 | */ |
| 204 | #ifndef PY_FORMAT_SIZE_T |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 205 | # if SIZEOF_SIZE_T == SIZEOF_INT && !defined(__APPLE__) |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 206 | # define PY_FORMAT_SIZE_T "" |
| 207 | # elif SIZEOF_SIZE_T == SIZEOF_LONG |
| 208 | # define PY_FORMAT_SIZE_T "l" |
| 209 | # elif defined(MS_WINDOWS) |
| 210 | # define PY_FORMAT_SIZE_T "I" |
| 211 | # else |
| 212 | # error "This platform's pyconfig.h needs to define PY_FORMAT_SIZE_T" |
| 213 | # endif |
| 214 | #endif |
Martin v. Löwis | 18e1655 | 2006-02-15 17:27:45 +0000 | [diff] [blame] | 215 | |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 216 | /* Py_LOCAL can be used instead of static to get the fastest possible calling |
| 217 | * convention for functions that are local to a given module. |
| 218 | * |
| 219 | * Py_LOCAL_INLINE does the same thing, and also explicitly requests inlining, |
| 220 | * for platforms that support that. |
| 221 | * |
| 222 | * If PY_LOCAL_AGGRESSIVE is defined before python.h is included, more |
| 223 | * "aggressive" inlining/optimizaion is enabled for the entire module. This |
| 224 | * may lead to code bloat, and may slow things down for those reasons. It may |
| 225 | * also lead to errors, if the code relies on pointer aliasing. Use with |
| 226 | * care. |
| 227 | * |
| 228 | * NOTE: You can only use this for functions that are entirely local to a |
| 229 | * module; functions that are exported via method tables, callbacks, etc, |
| 230 | * should keep using static. |
| 231 | */ |
| 232 | |
| 233 | #undef USE_INLINE /* XXX - set via configure? */ |
| 234 | |
| 235 | #if defined(_MSC_VER) |
| 236 | #if defined(PY_LOCAL_AGGRESSIVE) |
| 237 | /* enable more aggressive optimization for visual studio */ |
| 238 | #pragma optimize("agtw", on) |
| 239 | #endif |
| 240 | /* ignore warnings if the compiler decides not to inline a function */ |
| 241 | #pragma warning(disable: 4710) |
| 242 | /* fastest possible local call under MSVC */ |
| 243 | #define Py_LOCAL(type) static type __fastcall |
| 244 | #define Py_LOCAL_INLINE(type) static __inline type __fastcall |
| 245 | #elif defined(USE_INLINE) |
| 246 | #define Py_LOCAL(type) static type |
| 247 | #define Py_LOCAL_INLINE(type) static inline type |
| 248 | #else |
| 249 | #define Py_LOCAL(type) static type |
| 250 | #define Py_LOCAL_INLINE(type) static type |
| 251 | #endif |
| 252 | |
Thomas Wouters | 4d70c3d | 2006-06-08 14:42:34 +0000 | [diff] [blame] | 253 | /* Py_MEMCPY can be used instead of memcpy in cases where the copied blocks |
| 254 | * are often very short. While most platforms have highly optimized code for |
| 255 | * large transfers, the setup costs for memcpy are often quite high. MEMCPY |
| 256 | * solves this by doing short copies "in line". |
| 257 | */ |
| 258 | |
| 259 | #if defined(_MSC_VER) |
| 260 | #define Py_MEMCPY(target, source, length) do { \ |
| 261 | size_t i_, n_ = (length); \ |
| 262 | char *t_ = (void*) (target); \ |
| 263 | const char *s_ = (void*) (source); \ |
| 264 | if (n_ >= 16) \ |
| 265 | memcpy(t_, s_, n_); \ |
| 266 | else \ |
| 267 | for (i_ = 0; i_ < n_; i_++) \ |
| 268 | t_[i_] = s_[i_]; \ |
| 269 | } while (0) |
| 270 | #else |
| 271 | #define Py_MEMCPY memcpy |
| 272 | #endif |
| 273 | |
Peter Schneider-Kamp | 7e01890 | 2000-07-31 15:28:04 +0000 | [diff] [blame] | 274 | #include <stdlib.h> |
Peter Schneider-Kamp | 7e01890 | 2000-07-31 15:28:04 +0000 | [diff] [blame] | 275 | |
Vladimir Marangozov | 2c57e07 | 2000-08-11 11:48:33 +0000 | [diff] [blame] | 276 | #include <math.h> /* Moved here from the math section, before extern "C" */ |
| 277 | |
| 278 | /******************************************** |
| 279 | * WRAPPER FOR <time.h> and/or <sys/time.h> * |
| 280 | ********************************************/ |
| 281 | |
| 282 | #ifdef TIME_WITH_SYS_TIME |
| 283 | #include <sys/time.h> |
| 284 | #include <time.h> |
| 285 | #else /* !TIME_WITH_SYS_TIME */ |
| 286 | #ifdef HAVE_SYS_TIME_H |
| 287 | #include <sys/time.h> |
| 288 | #else /* !HAVE_SYS_TIME_H */ |
| 289 | #include <time.h> |
| 290 | #endif /* !HAVE_SYS_TIME_H */ |
| 291 | #endif /* !TIME_WITH_SYS_TIME */ |
| 292 | |
| 293 | |
| 294 | /****************************** |
| 295 | * WRAPPER FOR <sys/select.h> * |
| 296 | ******************************/ |
| 297 | |
| 298 | /* NB caller must include <sys/types.h> */ |
| 299 | |
| 300 | #ifdef HAVE_SYS_SELECT_H |
Vladimir Marangozov | 2c57e07 | 2000-08-11 11:48:33 +0000 | [diff] [blame] | 301 | #include <sys/select.h> |
Vladimir Marangozov | 2c57e07 | 2000-08-11 11:48:33 +0000 | [diff] [blame] | 302 | #endif /* !HAVE_SYS_SELECT_H */ |
| 303 | |
Tim Peters | 60f42b5 | 2001-01-18 03:03:16 +0000 | [diff] [blame] | 304 | /******************************* |
| 305 | * stat() and fstat() fiddling * |
| 306 | *******************************/ |
| 307 | |
| 308 | /* We expect that stat and fstat exist on most systems. |
| 309 | * It's confirmed on Unix, Mac and Windows. |
| 310 | * If you don't have them, add |
| 311 | * #define DONT_HAVE_STAT |
| 312 | * and/or |
| 313 | * #define DONT_HAVE_FSTAT |
Tim Peters | 76f373d | 2001-07-26 21:34:59 +0000 | [diff] [blame] | 314 | * 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] | 315 | * HAVE_FSTAT instead. |
| 316 | * Also |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 317 | * #define HAVE_SYS_STAT_H |
| 318 | * if <sys/stat.h> exists on your platform, and |
Tim Peters | 60f42b5 | 2001-01-18 03:03:16 +0000 | [diff] [blame] | 319 | * #define HAVE_STAT_H |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 320 | * if <stat.h> does. |
Tim Peters | 60f42b5 | 2001-01-18 03:03:16 +0000 | [diff] [blame] | 321 | */ |
| 322 | #ifndef DONT_HAVE_STAT |
| 323 | #define HAVE_STAT |
| 324 | #endif |
| 325 | |
| 326 | #ifndef DONT_HAVE_FSTAT |
| 327 | #define HAVE_FSTAT |
| 328 | #endif |
| 329 | |
Thomas Wouters | 0e3f591 | 2006-08-11 14:57:12 +0000 | [diff] [blame] | 330 | #ifdef HAVE_SYS_STAT_H |
Andrew MacIntyre | 5e090fc | 2002-02-26 11:20:01 +0000 | [diff] [blame] | 331 | #if defined(PYOS_OS2) && defined(PYCC_GCC) |
| 332 | #include <sys/types.h> |
| 333 | #endif |
Tim Peters | 60f42b5 | 2001-01-18 03:03:16 +0000 | [diff] [blame] | 334 | #include <sys/stat.h> |
| 335 | #elif defined(HAVE_STAT_H) |
| 336 | #include <stat.h> |
| 337 | #endif |
| 338 | |
Martin v. Löwis | f9836ba | 2001-08-08 10:28:06 +0000 | [diff] [blame] | 339 | #if defined(PYCC_VACPP) |
| 340 | /* VisualAge C/C++ Failed to Define MountType Field in sys/stat.h */ |
| 341 | #define S_IFMT (S_IFDIR|S_IFCHR|S_IFREG) |
| 342 | #endif |
| 343 | |
| 344 | #ifndef S_ISREG |
| 345 | #define S_ISREG(x) (((x) & S_IFMT) == S_IFREG) |
| 346 | #endif |
| 347 | |
| 348 | #ifndef S_ISDIR |
| 349 | #define S_ISDIR(x) (((x) & S_IFMT) == S_IFDIR) |
| 350 | #endif |
| 351 | |
Vladimir Marangozov | 2c57e07 | 2000-08-11 11:48:33 +0000 | [diff] [blame] | 352 | |
Tim Peters | 7d3a511 | 2000-07-08 04:17:21 +0000 | [diff] [blame] | 353 | #ifdef __cplusplus |
Peter Schneider-Kamp | 7e01890 | 2000-07-31 15:28:04 +0000 | [diff] [blame] | 354 | /* Move this down here since some C++ #include's don't like to be included |
| 355 | inside an extern "C" */ |
Tim Peters | 7d3a511 | 2000-07-08 04:17:21 +0000 | [diff] [blame] | 356 | extern "C" { |
| 357 | #endif |
| 358 | |
Vladimir Marangozov | 2c57e07 | 2000-08-11 11:48:33 +0000 | [diff] [blame] | 359 | |
Tim Peters | 7d3a511 | 2000-07-08 04:17:21 +0000 | [diff] [blame] | 360 | /* Py_ARITHMETIC_RIGHT_SHIFT |
| 361 | * C doesn't define whether a right-shift of a signed integer sign-extends |
| 362 | * or zero-fills. Here a macro to force sign extension: |
| 363 | * Py_ARITHMETIC_RIGHT_SHIFT(TYPE, I, J) |
| 364 | * Return I >> J, forcing sign extension. |
| 365 | * Requirements: |
| 366 | * I is of basic signed type TYPE (char, short, int, long, or long long). |
| 367 | * TYPE is one of char, short, int, long, or long long, although long long |
| 368 | * must not be used except on platforms that support it. |
| 369 | * J is an integer >= 0 and strictly less than the number of bits in TYPE |
| 370 | * (because C doesn't define what happens for J outside that range either). |
| 371 | * Caution: |
| 372 | * I may be evaluated more than once. |
| 373 | */ |
| 374 | #ifdef SIGNED_RIGHT_SHIFT_ZERO_FILLS |
| 375 | #define Py_ARITHMETIC_RIGHT_SHIFT(TYPE, I, J) \ |
| 376 | ((I) < 0 ? ~((~(unsigned TYPE)(I)) >> (J)) : (I) >> (J)) |
| 377 | #else |
| 378 | #define Py_ARITHMETIC_RIGHT_SHIFT(TYPE, I, J) ((I) >> (J)) |
| 379 | #endif |
| 380 | |
Tim Peters | 39dce29 | 2000-08-15 03:34:48 +0000 | [diff] [blame] | 381 | /* Py_FORCE_EXPANSION(X) |
Tim Peters | 1be4684 | 2000-07-23 18:10:18 +0000 | [diff] [blame] | 382 | * "Simply" returns its argument. However, macro expansions within the |
| 383 | * argument are evaluated. This unfortunate trickery is needed to get |
| 384 | * token-pasting to work as desired in some cases. |
| 385 | */ |
| 386 | #define Py_FORCE_EXPANSION(X) X |
| 387 | |
Tim Peters | 8315ea5 | 2000-07-23 19:28:35 +0000 | [diff] [blame] | 388 | /* Py_SAFE_DOWNCAST(VALUE, WIDE, NARROW) |
| 389 | * Cast VALUE to type NARROW from type WIDE. In Py_DEBUG mode, this |
| 390 | * assert-fails if any information is lost. |
| 391 | * Caution: |
| 392 | * VALUE may be evaluated more than once. |
| 393 | */ |
| 394 | #ifdef Py_DEBUG |
| 395 | #define Py_SAFE_DOWNCAST(VALUE, WIDE, NARROW) \ |
| 396 | (assert((WIDE)(NARROW)(VALUE) == (VALUE)), (NARROW)(VALUE)) |
| 397 | #else |
| 398 | #define Py_SAFE_DOWNCAST(VALUE, WIDE, NARROW) (NARROW)(VALUE) |
| 399 | #endif |
| 400 | |
Hye-Shik Chang | 77d9a3e | 2004-03-22 08:43:55 +0000 | [diff] [blame] | 401 | /* Py_SET_ERRNO_ON_MATH_ERROR(x) |
Tim Peters | a40c793 | 2001-09-05 22:36:56 +0000 | [diff] [blame] | 402 | * 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] | 403 | * overflowed or not-a-number, set errno to ERANGE or EDOM. Set errno |
| 404 | * to 0 before calling a libm function, and invoke this macro after, |
| 405 | * passing the function result. |
Tim Peters | a40c793 | 2001-09-05 22:36:56 +0000 | [diff] [blame] | 406 | * Caution: |
| 407 | * This isn't reliable. See Py_OVERFLOWED comments. |
| 408 | * X is evaluated more than once. |
| 409 | */ |
Guido van Rossum | 539c662 | 2005-09-14 17:49:54 +0000 | [diff] [blame] | 410 | #if defined(__FreeBSD__) || defined(__OpenBSD__) || (defined(__hpux) && defined(__ia64)) |
Hye-Shik Chang | 77d9a3e | 2004-03-22 08:43:55 +0000 | [diff] [blame] | 411 | #define _Py_SET_EDOM_FOR_NAN(X) if (isnan(X)) errno = EDOM; |
| 412 | #else |
| 413 | #define _Py_SET_EDOM_FOR_NAN(X) ; |
| 414 | #endif |
| 415 | #define Py_SET_ERRNO_ON_MATH_ERROR(X) \ |
Tim Peters | a40c793 | 2001-09-05 22:36:56 +0000 | [diff] [blame] | 416 | do { \ |
Hye-Shik Chang | 77d9a3e | 2004-03-22 08:43:55 +0000 | [diff] [blame] | 417 | if (errno == 0) { \ |
| 418 | if ((X) == Py_HUGE_VAL || (X) == -Py_HUGE_VAL) \ |
| 419 | errno = ERANGE; \ |
| 420 | else _Py_SET_EDOM_FOR_NAN(X) \ |
| 421 | } \ |
Tim Peters | a40c793 | 2001-09-05 22:36:56 +0000 | [diff] [blame] | 422 | } while(0) |
Tim Peters | 57f282a | 2001-09-05 05:38:10 +0000 | [diff] [blame] | 423 | |
Hye-Shik Chang | 77d9a3e | 2004-03-22 08:43:55 +0000 | [diff] [blame] | 424 | /* Py_SET_ERANGE_ON_OVERFLOW(x) |
| 425 | * An alias of Py_SET_ERRNO_ON_MATH_ERROR for backward-compatibility. |
| 426 | */ |
| 427 | #define Py_SET_ERANGE_IF_OVERFLOW(X) Py_SET_ERRNO_ON_MATH_ERROR(X) |
| 428 | |
Tim Peters | dc5a508 | 2002-03-09 04:58:24 +0000 | [diff] [blame] | 429 | /* Py_ADJUST_ERANGE1(x) |
| 430 | * Py_ADJUST_ERANGE2(x, y) |
| 431 | * Set errno to 0 before calling a libm function, and invoke one of these |
| 432 | * macros after, passing the function result(s) (Py_ADJUST_ERANGE2 is useful |
| 433 | * for functions returning complex results). This makes two kinds of |
| 434 | * adjustments to errno: (A) If it looks like the platform libm set |
| 435 | * errno=ERANGE due to underflow, clear errno. (B) If it looks like the |
| 436 | * platform libm overflowed but didn't set errno, force errno to ERANGE. In |
| 437 | * effect, we're trying to force a useful implementation of C89 errno |
| 438 | * behavior. |
| 439 | * Caution: |
| 440 | * This isn't reliable. See Py_OVERFLOWED comments. |
| 441 | * X and Y may be evaluated more than once. |
| 442 | */ |
| 443 | #define Py_ADJUST_ERANGE1(X) \ |
| 444 | do { \ |
| 445 | if (errno == 0) { \ |
| 446 | if ((X) == Py_HUGE_VAL || (X) == -Py_HUGE_VAL) \ |
| 447 | errno = ERANGE; \ |
| 448 | } \ |
| 449 | else if (errno == ERANGE && (X) == 0.0) \ |
| 450 | errno = 0; \ |
| 451 | } while(0) |
| 452 | |
| 453 | #define Py_ADJUST_ERANGE2(X, Y) \ |
| 454 | do { \ |
| 455 | if ((X) == Py_HUGE_VAL || (X) == -Py_HUGE_VAL || \ |
| 456 | (Y) == Py_HUGE_VAL || (Y) == -Py_HUGE_VAL) { \ |
| 457 | if (errno == 0) \ |
| 458 | errno = ERANGE; \ |
| 459 | } \ |
| 460 | else if (errno == ERANGE) \ |
| 461 | errno = 0; \ |
| 462 | } while(0) |
| 463 | |
Neal Norwitz | 8029264 | 2002-12-19 15:12:26 +0000 | [diff] [blame] | 464 | /* Py_DEPRECATED(version) |
Neal Norwitz | 93344ab | 2002-12-19 15:24:11 +0000 | [diff] [blame] | 465 | * Declare a variable, type, or function deprecated. |
Neal Norwitz | 8029264 | 2002-12-19 15:12:26 +0000 | [diff] [blame] | 466 | * Usage: |
| 467 | * extern int old_var Py_DEPRECATED(2.3); |
| 468 | * typedef int T1 Py_DEPRECATED(2.4); |
| 469 | * extern int x() Py_DEPRECATED(2.5); |
| 470 | */ |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 471 | #if defined(__GNUC__) && ((__GNUC__ >= 4) || \ |
| 472 | (__GNUC__ == 3) && (__GNUC_MINOR__ >= 1)) |
Neal Norwitz | 8029264 | 2002-12-19 15:12:26 +0000 | [diff] [blame] | 473 | #define Py_DEPRECATED(VERSION_UNUSED) __attribute__((__deprecated__)) |
| 474 | #else |
Tim Peters | 4643bd9 | 2002-12-28 21:56:08 +0000 | [diff] [blame] | 475 | #define Py_DEPRECATED(VERSION_UNUSED) |
Neal Norwitz | 8029264 | 2002-12-19 15:12:26 +0000 | [diff] [blame] | 476 | #endif |
| 477 | |
Thomas Wouters | 1e0c2f4 | 2000-07-24 16:06:23 +0000 | [diff] [blame] | 478 | /************************************************************************** |
| 479 | Prototypes that are missing from the standard include files on some systems |
| 480 | (and possibly only some versions of such systems.) |
| 481 | |
| 482 | Please be conservative with adding new ones, document them and enclose them |
| 483 | in platform-specific #ifdefs. |
| 484 | **************************************************************************/ |
| 485 | |
| 486 | #ifdef SOLARIS |
| 487 | /* Unchecked */ |
| 488 | extern int gethostname(char *, int); |
| 489 | #endif |
| 490 | |
Thomas Wouters | 1e0c2f4 | 2000-07-24 16:06:23 +0000 | [diff] [blame] | 491 | #ifdef HAVE__GETPTY |
Sjoerd Mullender | 0765fe3 | 2000-07-26 15:46:29 +0000 | [diff] [blame] | 492 | #include <sys/types.h> /* we need to import mode_t */ |
Thomas Wouters | 1e0c2f4 | 2000-07-24 16:06:23 +0000 | [diff] [blame] | 493 | extern char * _getpty(int *, int, mode_t, int); |
| 494 | #endif |
| 495 | |
Georg Brandl | f78e02b | 2008-06-10 17:40:04 +0000 | [diff] [blame] | 496 | /* On QNX 6, struct termio must be declared by including sys/termio.h |
| 497 | if TCGETA, TCSETA, TCSETAW, or TCSETAF are used. sys/termio.h must |
| 498 | be included before termios.h or it will generate an error. */ |
| 499 | #ifdef HAVE_SYS_TERMIO_H |
| 500 | #include <sys/termio.h> |
| 501 | #endif |
| 502 | |
Thomas Wouters | 1e0c2f4 | 2000-07-24 16:06:23 +0000 | [diff] [blame] | 503 | #if defined(HAVE_OPENPTY) || defined(HAVE_FORKPTY) |
| 504 | #if !defined(HAVE_PTY_H) && !defined(HAVE_LIBUTIL_H) |
| 505 | /* BSDI does not supply a prototype for the 'openpty' and 'forkpty' |
| 506 | functions, even though they are included in libutil. */ |
| 507 | #include <termios.h> |
| 508 | extern int openpty(int *, int *, char *, struct termios *, struct winsize *); |
Christian Heimes | 400adb0 | 2008-02-01 08:12:03 +0000 | [diff] [blame] | 509 | extern pid_t forkpty(int *, char *, struct termios *, struct winsize *); |
Thomas Wouters | 1e0c2f4 | 2000-07-24 16:06:23 +0000 | [diff] [blame] | 510 | #endif /* !defined(HAVE_PTY_H) && !defined(HAVE_LIBUTIL_H) */ |
| 511 | #endif /* defined(HAVE_OPENPTY) || defined(HAVE_FORKPTY) */ |
| 512 | |
| 513 | |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 514 | /* On 4.4BSD-descendants, ctype functions serves the whole range of |
| 515 | * wchar_t character set rather than single byte code points only. |
| 516 | * This characteristic can break some operations of string object |
| 517 | * including str.upper() and str.split() on UTF-8 locales. This |
| 518 | * workaround was provided by Tim Robbins of FreeBSD project. |
| 519 | */ |
Hye-Shik Chang | b5047fd | 2004-08-04 06:33:51 +0000 | [diff] [blame] | 520 | |
| 521 | #ifdef __FreeBSD__ |
| 522 | #include <osreldate.h> |
| 523 | #if __FreeBSD_version > 500039 |
| 524 | #include <ctype.h> |
| 525 | #include <wctype.h> |
| 526 | #undef isalnum |
| 527 | #define isalnum(c) iswalnum(btowc(c)) |
| 528 | #undef isalpha |
| 529 | #define isalpha(c) iswalpha(btowc(c)) |
| 530 | #undef islower |
| 531 | #define islower(c) iswlower(btowc(c)) |
| 532 | #undef isspace |
| 533 | #define isspace(c) iswspace(btowc(c)) |
| 534 | #undef isupper |
| 535 | #define isupper(c) iswupper(btowc(c)) |
| 536 | #undef tolower |
| 537 | #define tolower(c) towlower(btowc(c)) |
| 538 | #undef toupper |
| 539 | #define toupper(c) towupper(btowc(c)) |
| 540 | #endif |
| 541 | #endif |
| 542 | |
| 543 | |
Mark Hammond | 8235ea1 | 2002-07-19 06:55:41 +0000 | [diff] [blame] | 544 | /* Declarations for symbol visibility. |
| 545 | |
| 546 | PyAPI_FUNC(type): Declares a public Python API function and return type |
Tim Peters | 4643bd9 | 2002-12-28 21:56:08 +0000 | [diff] [blame] | 547 | PyAPI_DATA(type): Declares public Python data and its type |
Mark Hammond | 8235ea1 | 2002-07-19 06:55:41 +0000 | [diff] [blame] | 548 | PyMODINIT_FUNC: A Python module init function. If these functions are |
Tim Peters | 4643bd9 | 2002-12-28 21:56:08 +0000 | [diff] [blame] | 549 | inside the Python core, they are private to the core. |
| 550 | If in an extension module, it may be declared with |
Mark Hammond | 8235ea1 | 2002-07-19 06:55:41 +0000 | [diff] [blame] | 551 | external linkage depending on the platform. |
| 552 | |
| 553 | As a number of platforms support/require "__declspec(dllimport/dllexport)", |
| 554 | we support a HAVE_DECLSPEC_DLL macro to save duplication. |
| 555 | */ |
| 556 | |
Tim Peters | 4643bd9 | 2002-12-28 21:56:08 +0000 | [diff] [blame] | 557 | /* |
Michael W. Hudson | f163d10 | 2003-02-10 19:36:46 +0000 | [diff] [blame] | 558 | All windows ports, except cygwin, are handled in PC/pyconfig.h. |
| 559 | |
Skip Montanaro | eb33e5a | 2007-08-17 12:57:41 +0000 | [diff] [blame] | 560 | Cygwin is the only other autoconf platform requiring special |
| 561 | linkage handling and it uses __declspec(). |
Mark Hammond | 8235ea1 | 2002-07-19 06:55:41 +0000 | [diff] [blame] | 562 | */ |
Skip Montanaro | eb33e5a | 2007-08-17 12:57:41 +0000 | [diff] [blame] | 563 | #if defined(__CYGWIN__) |
Mark Hammond | 8235ea1 | 2002-07-19 06:55:41 +0000 | [diff] [blame] | 564 | # define HAVE_DECLSPEC_DLL |
Peter Schneider-Kamp | 7e01890 | 2000-07-31 15:28:04 +0000 | [diff] [blame] | 565 | #endif |
Mark Hammond | 8235ea1 | 2002-07-19 06:55:41 +0000 | [diff] [blame] | 566 | |
Jason Tishler | 3076559 | 2003-09-04 11:04:06 +0000 | [diff] [blame] | 567 | /* only get special linkage if built as shared or platform is Cygwin */ |
| 568 | #if defined(Py_ENABLE_SHARED) || defined(__CYGWIN__) |
Mark Hammond | 8235ea1 | 2002-07-19 06:55:41 +0000 | [diff] [blame] | 569 | # if defined(HAVE_DECLSPEC_DLL) |
| 570 | # ifdef Py_BUILD_CORE |
| 571 | # define PyAPI_FUNC(RTYPE) __declspec(dllexport) RTYPE |
Mark Hammond | a290527 | 2002-07-29 13:42:14 +0000 | [diff] [blame] | 572 | # define PyAPI_DATA(RTYPE) extern __declspec(dllexport) RTYPE |
Mark Hammond | 8235ea1 | 2002-07-19 06:55:41 +0000 | [diff] [blame] | 573 | /* module init functions inside the core need no external linkage */ |
Skip Montanaro | eb33e5a | 2007-08-17 12:57:41 +0000 | [diff] [blame] | 574 | /* except for Cygwin to handle embedding */ |
Jason Tishler | 6bc06ec | 2003-09-04 11:59:50 +0000 | [diff] [blame] | 575 | # if defined(__CYGWIN__) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 576 | # define PyMODINIT_FUNC __declspec(dllexport) PyObject* |
Jason Tishler | 6bc06ec | 2003-09-04 11:59:50 +0000 | [diff] [blame] | 577 | # else /* __CYGWIN__ */ |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 578 | # define PyMODINIT_FUNC PyObject* |
Jason Tishler | 6bc06ec | 2003-09-04 11:59:50 +0000 | [diff] [blame] | 579 | # endif /* __CYGWIN__ */ |
Mark Hammond | 8235ea1 | 2002-07-19 06:55:41 +0000 | [diff] [blame] | 580 | # else /* Py_BUILD_CORE */ |
| 581 | /* Building an extension module, or an embedded situation */ |
| 582 | /* public Python functions and data are imported */ |
Jason Tishler | fb8595d | 2003-01-06 12:41:26 +0000 | [diff] [blame] | 583 | /* Under Cygwin, auto-import functions to prevent compilation */ |
| 584 | /* failures similar to http://python.org/doc/FAQ.html#3.24 */ |
| 585 | # if !defined(__CYGWIN__) |
| 586 | # define PyAPI_FUNC(RTYPE) __declspec(dllimport) RTYPE |
| 587 | # endif /* !__CYGWIN__ */ |
Mark Hammond | a290527 | 2002-07-29 13:42:14 +0000 | [diff] [blame] | 588 | # define PyAPI_DATA(RTYPE) extern __declspec(dllimport) RTYPE |
Mark Hammond | 8235ea1 | 2002-07-19 06:55:41 +0000 | [diff] [blame] | 589 | /* module init functions outside the core must be exported */ |
| 590 | # if defined(__cplusplus) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 591 | # define PyMODINIT_FUNC extern "C" __declspec(dllexport) PyObject* |
Mark Hammond | 8235ea1 | 2002-07-19 06:55:41 +0000 | [diff] [blame] | 592 | # else /* __cplusplus */ |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 593 | # define PyMODINIT_FUNC __declspec(dllexport) PyObject* |
Mark Hammond | 8235ea1 | 2002-07-19 06:55:41 +0000 | [diff] [blame] | 594 | # endif /* __cplusplus */ |
| 595 | # endif /* Py_BUILD_CORE */ |
| 596 | # endif /* HAVE_DECLSPEC */ |
| 597 | #endif /* Py_ENABLE_SHARED */ |
| 598 | |
| 599 | /* If no external linkage macros defined by now, create defaults */ |
| 600 | #ifndef PyAPI_FUNC |
| 601 | # define PyAPI_FUNC(RTYPE) RTYPE |
| 602 | #endif |
| 603 | #ifndef PyAPI_DATA |
Mark Hammond | a290527 | 2002-07-29 13:42:14 +0000 | [diff] [blame] | 604 | # define PyAPI_DATA(RTYPE) extern RTYPE |
Mark Hammond | 8235ea1 | 2002-07-19 06:55:41 +0000 | [diff] [blame] | 605 | #endif |
| 606 | #ifndef PyMODINIT_FUNC |
| 607 | # if defined(__cplusplus) |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 608 | # define PyMODINIT_FUNC extern "C" PyObject* |
Mark Hammond | 8235ea1 | 2002-07-19 06:55:41 +0000 | [diff] [blame] | 609 | # else /* __cplusplus */ |
Martin v. Löwis | 1a21451 | 2008-06-11 05:26:20 +0000 | [diff] [blame] | 610 | # define PyMODINIT_FUNC PyObject* |
Mark Hammond | 8235ea1 | 2002-07-19 06:55:41 +0000 | [diff] [blame] | 611 | # endif /* __cplusplus */ |
| 612 | #endif |
| 613 | |
Fred Drake | d5fadf7 | 2000-09-26 05:46:01 +0000 | [diff] [blame] | 614 | /* limits.h constants that may be missing */ |
| 615 | |
| 616 | #ifndef INT_MAX |
| 617 | #define INT_MAX 2147483647 |
| 618 | #endif |
| 619 | |
| 620 | #ifndef LONG_MAX |
| 621 | #if SIZEOF_LONG == 4 |
| 622 | #define LONG_MAX 0X7FFFFFFFL |
| 623 | #elif SIZEOF_LONG == 8 |
| 624 | #define LONG_MAX 0X7FFFFFFFFFFFFFFFL |
| 625 | #else |
| 626 | #error "could not set LONG_MAX in pyport.h" |
| 627 | #endif |
| 628 | #endif |
| 629 | |
| 630 | #ifndef LONG_MIN |
| 631 | #define LONG_MIN (-LONG_MAX-1) |
| 632 | #endif |
| 633 | |
Tim Peters | d57731f | 2000-10-05 01:42:25 +0000 | [diff] [blame] | 634 | #ifndef LONG_BIT |
| 635 | #define LONG_BIT (8 * SIZEOF_LONG) |
| 636 | #endif |
| 637 | |
| 638 | #if LONG_BIT != 8 * SIZEOF_LONG |
| 639 | /* 04-Oct-2000 LONG_BIT is apparently (mis)defined as 64 on some recent |
| 640 | * 32-bit platforms using gcc. We try to catch that here at compile-time |
| 641 | * rather than waiting for integer multiplication to trigger bogus |
| 642 | * overflows. |
| 643 | */ |
Andrew M. Kuchling | 234fb63 | 2001-01-12 15:06:28 +0000 | [diff] [blame] | 644 | #error "LONG_BIT definition appears wrong for platform (bad gcc/glibc config?)." |
Tim Peters | d57731f | 2000-10-05 01:42:25 +0000 | [diff] [blame] | 645 | #endif |
| 646 | |
Tim Peters | 7d3a511 | 2000-07-08 04:17:21 +0000 | [diff] [blame] | 647 | #ifdef __cplusplus |
| 648 | } |
| 649 | #endif |
| 650 | |
Neil Schemenauer | 1569108 | 2001-10-23 02:20:37 +0000 | [diff] [blame] | 651 | /* |
| 652 | * Hide GCC attributes from compilers that don't support them. |
| 653 | */ |
Guido van Rossum | bd67d6f | 2001-10-27 21:16:16 +0000 | [diff] [blame] | 654 | #if (!defined(__GNUC__) || __GNUC__ < 2 || \ |
Skip Montanaro | 7a98be2 | 2007-08-16 14:35:24 +0000 | [diff] [blame] | 655 | (__GNUC__ == 2 && __GNUC_MINOR__ < 7) ) |
Neil Schemenauer | 96aa0ac | 2002-09-15 14:09:54 +0000 | [diff] [blame] | 656 | #define Py_GCC_ATTRIBUTE(x) |
| 657 | #else |
| 658 | #define Py_GCC_ATTRIBUTE(x) __attribute__(x) |
Neil Schemenauer | 1569108 | 2001-10-23 02:20:37 +0000 | [diff] [blame] | 659 | #endif |
| 660 | |
Thomas Wouters | 89f507f | 2006-12-13 04:49:30 +0000 | [diff] [blame] | 661 | /* |
| 662 | * Add PyArg_ParseTuple format where available. |
| 663 | */ |
| 664 | #ifdef HAVE_ATTRIBUTE_FORMAT_PARSETUPLE |
| 665 | #define Py_FORMAT_PARSETUPLE(func,p1,p2) __attribute__((format(func,p1,p2))) |
| 666 | #else |
| 667 | #define Py_FORMAT_PARSETUPLE(func,p1,p2) |
| 668 | #endif |
| 669 | |
Benjamin Peterson | 058e31e | 2009-01-16 03:54:08 +0000 | [diff] [blame] | 670 | /* |
| 671 | * Specify alignment on compilers that support it. |
| 672 | */ |
| 673 | #if defined(__GNUC__) && __GNUC__ >= 3 |
| 674 | #define Py_ALIGNED(x) __attribute__((aligned(x))) |
| 675 | #else |
| 676 | #define Py_ALIGNED(x) |
| 677 | #endif |
| 678 | |
Nicholas Bastin | 9ba301e | 2004-07-15 15:54:05 +0000 | [diff] [blame] | 679 | /* Eliminate end-of-loop code not reached warnings from SunPro C |
| 680 | * when using do{...}while(0) macros |
| 681 | */ |
| 682 | #ifdef __SUNPRO_C |
| 683 | #pragma error_messages (off,E_END_OF_LOOP_CODE_NOT_REACHED) |
| 684 | #endif |
| 685 | |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 686 | /* |
| 687 | * Older Microsoft compilers don't support the C99 long long literal suffixes, |
| 688 | * so these will be defined in PC/pyconfig.h for those compilers. |
| 689 | */ |
| 690 | #ifndef Py_LL |
| 691 | #define Py_LL(x) x##LL |
| 692 | #endif |
| 693 | |
| 694 | #ifndef Py_ULL |
| 695 | #define Py_ULL(x) Py_LL(x##U) |
| 696 | #endif |
| 697 | |
Tim Peters | 7d3a511 | 2000-07-08 04:17:21 +0000 | [diff] [blame] | 698 | #endif /* Py_PYPORT_H */ |