annotate DEPENDENCIES/mingw32/Python27/include/pyport.h @ 118:770eb830ec19 emscripten

Typo fix
author Chris Cannam
date Wed, 18 May 2016 16:14:08 +0100
parents 2a2c65a20a8b
children
rev   line source
Chris@87 1 #ifndef Py_PYPORT_H
Chris@87 2 #define Py_PYPORT_H
Chris@87 3
Chris@87 4 #include "pyconfig.h" /* include for defines */
Chris@87 5
Chris@87 6 /* Some versions of HP-UX & Solaris need inttypes.h for int32_t,
Chris@87 7 INT32_MAX, etc. */
Chris@87 8 #ifdef HAVE_INTTYPES_H
Chris@87 9 #include <inttypes.h>
Chris@87 10 #endif
Chris@87 11
Chris@87 12 #ifdef HAVE_STDINT_H
Chris@87 13 #include <stdint.h>
Chris@87 14 #endif
Chris@87 15
Chris@87 16 /**************************************************************************
Chris@87 17 Symbols and macros to supply platform-independent interfaces to basic
Chris@87 18 C language & library operations whose spellings vary across platforms.
Chris@87 19
Chris@87 20 Please try to make documentation here as clear as possible: by definition,
Chris@87 21 the stuff here is trying to illuminate C's darkest corners.
Chris@87 22
Chris@87 23 Config #defines referenced here:
Chris@87 24
Chris@87 25 SIGNED_RIGHT_SHIFT_ZERO_FILLS
Chris@87 26 Meaning: To be defined iff i>>j does not extend the sign bit when i is a
Chris@87 27 signed integral type and i < 0.
Chris@87 28 Used in: Py_ARITHMETIC_RIGHT_SHIFT
Chris@87 29
Chris@87 30 Py_DEBUG
Chris@87 31 Meaning: Extra checks compiled in for debug mode.
Chris@87 32 Used in: Py_SAFE_DOWNCAST
Chris@87 33
Chris@87 34 HAVE_UINTPTR_T
Chris@87 35 Meaning: The C9X type uintptr_t is supported by the compiler
Chris@87 36 Used in: Py_uintptr_t
Chris@87 37
Chris@87 38 HAVE_LONG_LONG
Chris@87 39 Meaning: The compiler supports the C type "long long"
Chris@87 40 Used in: PY_LONG_LONG
Chris@87 41
Chris@87 42 **************************************************************************/
Chris@87 43
Chris@87 44
Chris@87 45 /* For backward compatibility only. Obsolete, do not use. */
Chris@87 46 #ifdef HAVE_PROTOTYPES
Chris@87 47 #define Py_PROTO(x) x
Chris@87 48 #else
Chris@87 49 #define Py_PROTO(x) ()
Chris@87 50 #endif
Chris@87 51 #ifndef Py_FPROTO
Chris@87 52 #define Py_FPROTO(x) Py_PROTO(x)
Chris@87 53 #endif
Chris@87 54
Chris@87 55 /* typedefs for some C9X-defined synonyms for integral types.
Chris@87 56 *
Chris@87 57 * The names in Python are exactly the same as the C9X names, except with a
Chris@87 58 * Py_ prefix. Until C9X is universally implemented, this is the only way
Chris@87 59 * to ensure that Python gets reliable names that don't conflict with names
Chris@87 60 * in non-Python code that are playing their own tricks to define the C9X
Chris@87 61 * names.
Chris@87 62 *
Chris@87 63 * NOTE: don't go nuts here! Python has no use for *most* of the C9X
Chris@87 64 * integral synonyms. Only define the ones we actually need.
Chris@87 65 */
Chris@87 66
Chris@87 67 #ifdef HAVE_LONG_LONG
Chris@87 68 #ifndef PY_LONG_LONG
Chris@87 69 #define PY_LONG_LONG long long
Chris@87 70 #if defined(LLONG_MAX)
Chris@87 71 /* If LLONG_MAX is defined in limits.h, use that. */
Chris@87 72 #define PY_LLONG_MIN LLONG_MIN
Chris@87 73 #define PY_LLONG_MAX LLONG_MAX
Chris@87 74 #define PY_ULLONG_MAX ULLONG_MAX
Chris@87 75 #elif defined(__LONG_LONG_MAX__)
Chris@87 76 /* Otherwise, if GCC has a builtin define, use that. */
Chris@87 77 #define PY_LLONG_MAX __LONG_LONG_MAX__
Chris@87 78 #define PY_LLONG_MIN (-PY_LLONG_MAX-1)
Chris@87 79 #define PY_ULLONG_MAX (__LONG_LONG_MAX__*2ULL + 1ULL)
Chris@87 80 #else
Chris@87 81 /* Otherwise, rely on two's complement. */
Chris@87 82 #define PY_ULLONG_MAX (~0ULL)
Chris@87 83 #define PY_LLONG_MAX ((long long)(PY_ULLONG_MAX>>1))
Chris@87 84 #define PY_LLONG_MIN (-PY_LLONG_MAX-1)
Chris@87 85 #endif /* LLONG_MAX */
Chris@87 86 #endif
Chris@87 87 #endif /* HAVE_LONG_LONG */
Chris@87 88
Chris@87 89 /* a build with 30-bit digits for Python long integers needs an exact-width
Chris@87 90 * 32-bit unsigned integer type to store those digits. (We could just use
Chris@87 91 * type 'unsigned long', but that would be wasteful on a system where longs
Chris@87 92 * are 64-bits.) On Unix systems, the autoconf macro AC_TYPE_UINT32_T defines
Chris@87 93 * uint32_t to be such a type unless stdint.h or inttypes.h defines uint32_t.
Chris@87 94 * However, it doesn't set HAVE_UINT32_T, so we do that here.
Chris@87 95 */
Chris@87 96 #ifdef uint32_t
Chris@87 97 #define HAVE_UINT32_T 1
Chris@87 98 #endif
Chris@87 99
Chris@87 100 #ifdef HAVE_UINT32_T
Chris@87 101 #ifndef PY_UINT32_T
Chris@87 102 #define PY_UINT32_T uint32_t
Chris@87 103 #endif
Chris@87 104 #endif
Chris@87 105
Chris@87 106 /* Macros for a 64-bit unsigned integer type; used for type 'twodigits' in the
Chris@87 107 * long integer implementation, when 30-bit digits are enabled.
Chris@87 108 */
Chris@87 109 #ifdef uint64_t
Chris@87 110 #define HAVE_UINT64_T 1
Chris@87 111 #endif
Chris@87 112
Chris@87 113 #ifdef HAVE_UINT64_T
Chris@87 114 #ifndef PY_UINT64_T
Chris@87 115 #define PY_UINT64_T uint64_t
Chris@87 116 #endif
Chris@87 117 #endif
Chris@87 118
Chris@87 119 /* Signed variants of the above */
Chris@87 120 #ifdef int32_t
Chris@87 121 #define HAVE_INT32_T 1
Chris@87 122 #endif
Chris@87 123
Chris@87 124 #ifdef HAVE_INT32_T
Chris@87 125 #ifndef PY_INT32_T
Chris@87 126 #define PY_INT32_T int32_t
Chris@87 127 #endif
Chris@87 128 #endif
Chris@87 129
Chris@87 130 #ifdef int64_t
Chris@87 131 #define HAVE_INT64_T 1
Chris@87 132 #endif
Chris@87 133
Chris@87 134 #ifdef HAVE_INT64_T
Chris@87 135 #ifndef PY_INT64_T
Chris@87 136 #define PY_INT64_T int64_t
Chris@87 137 #endif
Chris@87 138 #endif
Chris@87 139
Chris@87 140 /* If PYLONG_BITS_IN_DIGIT is not defined then we'll use 30-bit digits if all
Chris@87 141 the necessary integer types are available, and we're on a 64-bit platform
Chris@87 142 (as determined by SIZEOF_VOID_P); otherwise we use 15-bit digits. */
Chris@87 143
Chris@87 144 #ifndef PYLONG_BITS_IN_DIGIT
Chris@87 145 #if (defined HAVE_UINT64_T && defined HAVE_INT64_T && \
Chris@87 146 defined HAVE_UINT32_T && defined HAVE_INT32_T && SIZEOF_VOID_P >= 8)
Chris@87 147 #define PYLONG_BITS_IN_DIGIT 30
Chris@87 148 #else
Chris@87 149 #define PYLONG_BITS_IN_DIGIT 15
Chris@87 150 #endif
Chris@87 151 #endif
Chris@87 152
Chris@87 153 /* uintptr_t is the C9X name for an unsigned integral type such that a
Chris@87 154 * legitimate void* can be cast to uintptr_t and then back to void* again
Chris@87 155 * without loss of information. Similarly for intptr_t, wrt a signed
Chris@87 156 * integral type.
Chris@87 157 */
Chris@87 158 #ifdef HAVE_UINTPTR_T
Chris@87 159 typedef uintptr_t Py_uintptr_t;
Chris@87 160 typedef intptr_t Py_intptr_t;
Chris@87 161
Chris@87 162 #elif SIZEOF_VOID_P <= SIZEOF_INT
Chris@87 163 typedef unsigned int Py_uintptr_t;
Chris@87 164 typedef int Py_intptr_t;
Chris@87 165
Chris@87 166 #elif SIZEOF_VOID_P <= SIZEOF_LONG
Chris@87 167 typedef unsigned long Py_uintptr_t;
Chris@87 168 typedef long Py_intptr_t;
Chris@87 169
Chris@87 170 #elif defined(HAVE_LONG_LONG) && (SIZEOF_VOID_P <= SIZEOF_LONG_LONG)
Chris@87 171 typedef unsigned PY_LONG_LONG Py_uintptr_t;
Chris@87 172 typedef PY_LONG_LONG Py_intptr_t;
Chris@87 173
Chris@87 174 #else
Chris@87 175 # error "Python needs a typedef for Py_uintptr_t in pyport.h."
Chris@87 176 #endif /* HAVE_UINTPTR_T */
Chris@87 177
Chris@87 178 /* Py_ssize_t is a signed integral type such that sizeof(Py_ssize_t) ==
Chris@87 179 * sizeof(size_t). C99 doesn't define such a thing directly (size_t is an
Chris@87 180 * unsigned integral type). See PEP 353 for details.
Chris@87 181 */
Chris@87 182 #ifdef HAVE_SSIZE_T
Chris@87 183 typedef ssize_t Py_ssize_t;
Chris@87 184 #elif SIZEOF_VOID_P == SIZEOF_SIZE_T
Chris@87 185 typedef Py_intptr_t Py_ssize_t;
Chris@87 186 #else
Chris@87 187 # error "Python needs a typedef for Py_ssize_t in pyport.h."
Chris@87 188 #endif
Chris@87 189
Chris@87 190 /* Largest possible value of size_t.
Chris@87 191 SIZE_MAX is part of C99, so it might be defined on some
Chris@87 192 platforms. If it is not defined, (size_t)-1 is a portable
Chris@87 193 definition for C89, due to the way signed->unsigned
Chris@87 194 conversion is defined. */
Chris@87 195 #ifdef SIZE_MAX
Chris@87 196 #define PY_SIZE_MAX SIZE_MAX
Chris@87 197 #else
Chris@87 198 #define PY_SIZE_MAX ((size_t)-1)
Chris@87 199 #endif
Chris@87 200
Chris@87 201 /* Largest positive value of type Py_ssize_t. */
Chris@87 202 #define PY_SSIZE_T_MAX ((Py_ssize_t)(((size_t)-1)>>1))
Chris@87 203 /* Smallest negative value of type Py_ssize_t. */
Chris@87 204 #define PY_SSIZE_T_MIN (-PY_SSIZE_T_MAX-1)
Chris@87 205
Chris@87 206 #if SIZEOF_PID_T > SIZEOF_LONG
Chris@87 207 # error "Python doesn't support sizeof(pid_t) > sizeof(long)"
Chris@87 208 #endif
Chris@87 209
Chris@87 210 /* PY_FORMAT_SIZE_T is a platform-specific modifier for use in a printf
Chris@87 211 * format to convert an argument with the width of a size_t or Py_ssize_t.
Chris@87 212 * C99 introduced "z" for this purpose, but not all platforms support that;
Chris@87 213 * e.g., MS compilers use "I" instead.
Chris@87 214 *
Chris@87 215 * These "high level" Python format functions interpret "z" correctly on
Chris@87 216 * all platforms (Python interprets the format string itself, and does whatever
Chris@87 217 * the platform C requires to convert a size_t/Py_ssize_t argument):
Chris@87 218 *
Chris@87 219 * PyString_FromFormat
Chris@87 220 * PyErr_Format
Chris@87 221 * PyString_FromFormatV
Chris@87 222 *
Chris@87 223 * Lower-level uses require that you interpolate the correct format modifier
Chris@87 224 * yourself (e.g., calling printf, fprintf, sprintf, PyOS_snprintf); for
Chris@87 225 * example,
Chris@87 226 *
Chris@87 227 * Py_ssize_t index;
Chris@87 228 * fprintf(stderr, "index %" PY_FORMAT_SIZE_T "d sucks\n", index);
Chris@87 229 *
Chris@87 230 * That will expand to %ld, or %Id, or to something else correct for a
Chris@87 231 * Py_ssize_t on the platform.
Chris@87 232 */
Chris@87 233 #ifndef PY_FORMAT_SIZE_T
Chris@87 234 # if SIZEOF_SIZE_T == SIZEOF_INT && !defined(__APPLE__)
Chris@87 235 # define PY_FORMAT_SIZE_T ""
Chris@87 236 # elif SIZEOF_SIZE_T == SIZEOF_LONG
Chris@87 237 # define PY_FORMAT_SIZE_T "l"
Chris@87 238 # elif defined(MS_WINDOWS)
Chris@87 239 # define PY_FORMAT_SIZE_T "I"
Chris@87 240 # else
Chris@87 241 # error "This platform's pyconfig.h needs to define PY_FORMAT_SIZE_T"
Chris@87 242 # endif
Chris@87 243 #endif
Chris@87 244
Chris@87 245 /* PY_FORMAT_LONG_LONG is analogous to PY_FORMAT_SIZE_T above, but for
Chris@87 246 * the long long type instead of the size_t type. It's only available
Chris@87 247 * when HAVE_LONG_LONG is defined. The "high level" Python format
Chris@87 248 * functions listed above will interpret "lld" or "llu" correctly on
Chris@87 249 * all platforms.
Chris@87 250 */
Chris@87 251 #ifdef HAVE_LONG_LONG
Chris@87 252 # ifndef PY_FORMAT_LONG_LONG
Chris@87 253 # if defined(MS_WIN64) || defined(MS_WINDOWS)
Chris@87 254 # define PY_FORMAT_LONG_LONG "I64"
Chris@87 255 # else
Chris@87 256 # error "This platform's pyconfig.h needs to define PY_FORMAT_LONG_LONG"
Chris@87 257 # endif
Chris@87 258 # endif
Chris@87 259 #endif
Chris@87 260
Chris@87 261 /* Py_LOCAL can be used instead of static to get the fastest possible calling
Chris@87 262 * convention for functions that are local to a given module.
Chris@87 263 *
Chris@87 264 * Py_LOCAL_INLINE does the same thing, and also explicitly requests inlining,
Chris@87 265 * for platforms that support that.
Chris@87 266 *
Chris@87 267 * If PY_LOCAL_AGGRESSIVE is defined before python.h is included, more
Chris@87 268 * "aggressive" inlining/optimizaion is enabled for the entire module. This
Chris@87 269 * may lead to code bloat, and may slow things down for those reasons. It may
Chris@87 270 * also lead to errors, if the code relies on pointer aliasing. Use with
Chris@87 271 * care.
Chris@87 272 *
Chris@87 273 * NOTE: You can only use this for functions that are entirely local to a
Chris@87 274 * module; functions that are exported via method tables, callbacks, etc,
Chris@87 275 * should keep using static.
Chris@87 276 */
Chris@87 277
Chris@87 278 #undef USE_INLINE /* XXX - set via configure? */
Chris@87 279
Chris@87 280 #if defined(_MSC_VER)
Chris@87 281 #if defined(PY_LOCAL_AGGRESSIVE)
Chris@87 282 /* enable more aggressive optimization for visual studio */
Chris@87 283 #pragma optimize("agtw", on)
Chris@87 284 #endif
Chris@87 285 /* ignore warnings if the compiler decides not to inline a function */
Chris@87 286 #pragma warning(disable: 4710)
Chris@87 287 /* fastest possible local call under MSVC */
Chris@87 288 #define Py_LOCAL(type) static type __fastcall
Chris@87 289 #define Py_LOCAL_INLINE(type) static __inline type __fastcall
Chris@87 290 #elif defined(USE_INLINE)
Chris@87 291 #define Py_LOCAL(type) static type
Chris@87 292 #define Py_LOCAL_INLINE(type) static inline type
Chris@87 293 #else
Chris@87 294 #define Py_LOCAL(type) static type
Chris@87 295 #define Py_LOCAL_INLINE(type) static type
Chris@87 296 #endif
Chris@87 297
Chris@87 298 /* Py_MEMCPY can be used instead of memcpy in cases where the copied blocks
Chris@87 299 * are often very short. While most platforms have highly optimized code for
Chris@87 300 * large transfers, the setup costs for memcpy are often quite high. MEMCPY
Chris@87 301 * solves this by doing short copies "in line".
Chris@87 302 */
Chris@87 303
Chris@87 304 #if defined(_MSC_VER)
Chris@87 305 #define Py_MEMCPY(target, source, length) do { \
Chris@87 306 size_t i_, n_ = (length); \
Chris@87 307 char *t_ = (void*) (target); \
Chris@87 308 const char *s_ = (void*) (source); \
Chris@87 309 if (n_ >= 16) \
Chris@87 310 memcpy(t_, s_, n_); \
Chris@87 311 else \
Chris@87 312 for (i_ = 0; i_ < n_; i_++) \
Chris@87 313 t_[i_] = s_[i_]; \
Chris@87 314 } while (0)
Chris@87 315 #else
Chris@87 316 #define Py_MEMCPY memcpy
Chris@87 317 #endif
Chris@87 318
Chris@87 319 #include <stdlib.h>
Chris@87 320
Chris@87 321 #ifdef HAVE_IEEEFP_H
Chris@87 322 #include <ieeefp.h> /* needed for 'finite' declaration on some platforms */
Chris@87 323 #endif
Chris@87 324
Chris@87 325 #include <math.h> /* Moved here from the math section, before extern "C" */
Chris@87 326
Chris@87 327 /********************************************
Chris@87 328 * WRAPPER FOR <time.h> and/or <sys/time.h> *
Chris@87 329 ********************************************/
Chris@87 330
Chris@87 331 #ifdef TIME_WITH_SYS_TIME
Chris@87 332 #include <sys/time.h>
Chris@87 333 #include <time.h>
Chris@87 334 #else /* !TIME_WITH_SYS_TIME */
Chris@87 335 #ifdef HAVE_SYS_TIME_H
Chris@87 336 #include <sys/time.h>
Chris@87 337 #else /* !HAVE_SYS_TIME_H */
Chris@87 338 #include <time.h>
Chris@87 339 #endif /* !HAVE_SYS_TIME_H */
Chris@87 340 #endif /* !TIME_WITH_SYS_TIME */
Chris@87 341
Chris@87 342
Chris@87 343 /******************************
Chris@87 344 * WRAPPER FOR <sys/select.h> *
Chris@87 345 ******************************/
Chris@87 346
Chris@87 347 /* NB caller must include <sys/types.h> */
Chris@87 348
Chris@87 349 #ifdef HAVE_SYS_SELECT_H
Chris@87 350
Chris@87 351 #include <sys/select.h>
Chris@87 352
Chris@87 353 #endif /* !HAVE_SYS_SELECT_H */
Chris@87 354
Chris@87 355 /*******************************
Chris@87 356 * stat() and fstat() fiddling *
Chris@87 357 *******************************/
Chris@87 358
Chris@87 359 /* We expect that stat and fstat exist on most systems.
Chris@87 360 * It's confirmed on Unix, Mac and Windows.
Chris@87 361 * If you don't have them, add
Chris@87 362 * #define DONT_HAVE_STAT
Chris@87 363 * and/or
Chris@87 364 * #define DONT_HAVE_FSTAT
Chris@87 365 * to your pyconfig.h. Python code beyond this should check HAVE_STAT and
Chris@87 366 * HAVE_FSTAT instead.
Chris@87 367 * Also
Chris@87 368 * #define HAVE_SYS_STAT_H
Chris@87 369 * if <sys/stat.h> exists on your platform, and
Chris@87 370 * #define HAVE_STAT_H
Chris@87 371 * if <stat.h> does.
Chris@87 372 */
Chris@87 373 #ifndef DONT_HAVE_STAT
Chris@87 374 #define HAVE_STAT
Chris@87 375 #endif
Chris@87 376
Chris@87 377 #ifndef DONT_HAVE_FSTAT
Chris@87 378 #define HAVE_FSTAT
Chris@87 379 #endif
Chris@87 380
Chris@87 381 #ifdef RISCOS
Chris@87 382 #include <sys/types.h>
Chris@87 383 #include "unixstuff.h"
Chris@87 384 #endif
Chris@87 385
Chris@87 386 #ifdef HAVE_SYS_STAT_H
Chris@87 387 #if defined(PYOS_OS2) && defined(PYCC_GCC)
Chris@87 388 #include <sys/types.h>
Chris@87 389 #endif
Chris@87 390 #include <sys/stat.h>
Chris@87 391 #elif defined(HAVE_STAT_H)
Chris@87 392 #include <stat.h>
Chris@87 393 #endif
Chris@87 394
Chris@87 395 #if defined(PYCC_VACPP)
Chris@87 396 /* VisualAge C/C++ Failed to Define MountType Field in sys/stat.h */
Chris@87 397 #define S_IFMT (S_IFDIR|S_IFCHR|S_IFREG)
Chris@87 398 #endif
Chris@87 399
Chris@87 400 #ifndef S_ISREG
Chris@87 401 #define S_ISREG(x) (((x) & S_IFMT) == S_IFREG)
Chris@87 402 #endif
Chris@87 403
Chris@87 404 #ifndef S_ISDIR
Chris@87 405 #define S_ISDIR(x) (((x) & S_IFMT) == S_IFDIR)
Chris@87 406 #endif
Chris@87 407
Chris@87 408
Chris@87 409 #ifdef __cplusplus
Chris@87 410 /* Move this down here since some C++ #include's don't like to be included
Chris@87 411 inside an extern "C" */
Chris@87 412 extern "C" {
Chris@87 413 #endif
Chris@87 414
Chris@87 415
Chris@87 416 /* Py_ARITHMETIC_RIGHT_SHIFT
Chris@87 417 * C doesn't define whether a right-shift of a signed integer sign-extends
Chris@87 418 * or zero-fills. Here a macro to force sign extension:
Chris@87 419 * Py_ARITHMETIC_RIGHT_SHIFT(TYPE, I, J)
Chris@87 420 * Return I >> J, forcing sign extension. Arithmetically, return the
Chris@87 421 * floor of I/2**J.
Chris@87 422 * Requirements:
Chris@87 423 * I should have signed integer type. In the terminology of C99, this can
Chris@87 424 * be either one of the five standard signed integer types (signed char,
Chris@87 425 * short, int, long, long long) or an extended signed integer type.
Chris@87 426 * J is an integer >= 0 and strictly less than the number of bits in the
Chris@87 427 * type of I (because C doesn't define what happens for J outside that
Chris@87 428 * range either).
Chris@87 429 * TYPE used to specify the type of I, but is now ignored. It's been left
Chris@87 430 * in for backwards compatibility with versions <= 2.6 or 3.0.
Chris@87 431 * Caution:
Chris@87 432 * I may be evaluated more than once.
Chris@87 433 */
Chris@87 434 #ifdef SIGNED_RIGHT_SHIFT_ZERO_FILLS
Chris@87 435 #define Py_ARITHMETIC_RIGHT_SHIFT(TYPE, I, J) \
Chris@87 436 ((I) < 0 ? -1-((-1-(I)) >> (J)) : (I) >> (J))
Chris@87 437 #else
Chris@87 438 #define Py_ARITHMETIC_RIGHT_SHIFT(TYPE, I, J) ((I) >> (J))
Chris@87 439 #endif
Chris@87 440
Chris@87 441 /* Py_FORCE_EXPANSION(X)
Chris@87 442 * "Simply" returns its argument. However, macro expansions within the
Chris@87 443 * argument are evaluated. This unfortunate trickery is needed to get
Chris@87 444 * token-pasting to work as desired in some cases.
Chris@87 445 */
Chris@87 446 #define Py_FORCE_EXPANSION(X) X
Chris@87 447
Chris@87 448 /* Py_SAFE_DOWNCAST(VALUE, WIDE, NARROW)
Chris@87 449 * Cast VALUE to type NARROW from type WIDE. In Py_DEBUG mode, this
Chris@87 450 * assert-fails if any information is lost.
Chris@87 451 * Caution:
Chris@87 452 * VALUE may be evaluated more than once.
Chris@87 453 */
Chris@87 454 #ifdef Py_DEBUG
Chris@87 455 #define Py_SAFE_DOWNCAST(VALUE, WIDE, NARROW) \
Chris@87 456 (assert((WIDE)(NARROW)(VALUE) == (VALUE)), (NARROW)(VALUE))
Chris@87 457 #else
Chris@87 458 #define Py_SAFE_DOWNCAST(VALUE, WIDE, NARROW) (NARROW)(VALUE)
Chris@87 459 #endif
Chris@87 460
Chris@87 461 /* Py_SET_ERRNO_ON_MATH_ERROR(x)
Chris@87 462 * If a libm function did not set errno, but it looks like the result
Chris@87 463 * overflowed or not-a-number, set errno to ERANGE or EDOM. Set errno
Chris@87 464 * to 0 before calling a libm function, and invoke this macro after,
Chris@87 465 * passing the function result.
Chris@87 466 * Caution:
Chris@87 467 * This isn't reliable. See Py_OVERFLOWED comments.
Chris@87 468 * X is evaluated more than once.
Chris@87 469 */
Chris@87 470 #if defined(__FreeBSD__) || defined(__OpenBSD__) || (defined(__hpux) && defined(__ia64))
Chris@87 471 #define _Py_SET_EDOM_FOR_NAN(X) if (isnan(X)) errno = EDOM;
Chris@87 472 #else
Chris@87 473 #define _Py_SET_EDOM_FOR_NAN(X) ;
Chris@87 474 #endif
Chris@87 475 #define Py_SET_ERRNO_ON_MATH_ERROR(X) \
Chris@87 476 do { \
Chris@87 477 if (errno == 0) { \
Chris@87 478 if ((X) == Py_HUGE_VAL || (X) == -Py_HUGE_VAL) \
Chris@87 479 errno = ERANGE; \
Chris@87 480 else _Py_SET_EDOM_FOR_NAN(X) \
Chris@87 481 } \
Chris@87 482 } while(0)
Chris@87 483
Chris@87 484 /* Py_SET_ERANGE_ON_OVERFLOW(x)
Chris@87 485 * An alias of Py_SET_ERRNO_ON_MATH_ERROR for backward-compatibility.
Chris@87 486 */
Chris@87 487 #define Py_SET_ERANGE_IF_OVERFLOW(X) Py_SET_ERRNO_ON_MATH_ERROR(X)
Chris@87 488
Chris@87 489 /* Py_ADJUST_ERANGE1(x)
Chris@87 490 * Py_ADJUST_ERANGE2(x, y)
Chris@87 491 * Set errno to 0 before calling a libm function, and invoke one of these
Chris@87 492 * macros after, passing the function result(s) (Py_ADJUST_ERANGE2 is useful
Chris@87 493 * for functions returning complex results). This makes two kinds of
Chris@87 494 * adjustments to errno: (A) If it looks like the platform libm set
Chris@87 495 * errno=ERANGE due to underflow, clear errno. (B) If it looks like the
Chris@87 496 * platform libm overflowed but didn't set errno, force errno to ERANGE. In
Chris@87 497 * effect, we're trying to force a useful implementation of C89 errno
Chris@87 498 * behavior.
Chris@87 499 * Caution:
Chris@87 500 * This isn't reliable. See Py_OVERFLOWED comments.
Chris@87 501 * X and Y may be evaluated more than once.
Chris@87 502 */
Chris@87 503 #define Py_ADJUST_ERANGE1(X) \
Chris@87 504 do { \
Chris@87 505 if (errno == 0) { \
Chris@87 506 if ((X) == Py_HUGE_VAL || (X) == -Py_HUGE_VAL) \
Chris@87 507 errno = ERANGE; \
Chris@87 508 } \
Chris@87 509 else if (errno == ERANGE && (X) == 0.0) \
Chris@87 510 errno = 0; \
Chris@87 511 } while(0)
Chris@87 512
Chris@87 513 #define Py_ADJUST_ERANGE2(X, Y) \
Chris@87 514 do { \
Chris@87 515 if ((X) == Py_HUGE_VAL || (X) == -Py_HUGE_VAL || \
Chris@87 516 (Y) == Py_HUGE_VAL || (Y) == -Py_HUGE_VAL) { \
Chris@87 517 if (errno == 0) \
Chris@87 518 errno = ERANGE; \
Chris@87 519 } \
Chris@87 520 else if (errno == ERANGE) \
Chris@87 521 errno = 0; \
Chris@87 522 } while(0)
Chris@87 523
Chris@87 524 /* The functions _Py_dg_strtod and _Py_dg_dtoa in Python/dtoa.c (which are
Chris@87 525 * required to support the short float repr introduced in Python 3.1) require
Chris@87 526 * that the floating-point unit that's being used for arithmetic operations
Chris@87 527 * on C doubles is set to use 53-bit precision. It also requires that the
Chris@87 528 * FPU rounding mode is round-half-to-even, but that's less often an issue.
Chris@87 529 *
Chris@87 530 * If your FPU isn't already set to 53-bit precision/round-half-to-even, and
Chris@87 531 * you want to make use of _Py_dg_strtod and _Py_dg_dtoa, then you should
Chris@87 532 *
Chris@87 533 * #define HAVE_PY_SET_53BIT_PRECISION 1
Chris@87 534 *
Chris@87 535 * and also give appropriate definitions for the following three macros:
Chris@87 536 *
Chris@87 537 * _PY_SET_53BIT_PRECISION_START : store original FPU settings, and
Chris@87 538 * set FPU to 53-bit precision/round-half-to-even
Chris@87 539 * _PY_SET_53BIT_PRECISION_END : restore original FPU settings
Chris@87 540 * _PY_SET_53BIT_PRECISION_HEADER : any variable declarations needed to
Chris@87 541 * use the two macros above.
Chris@87 542 *
Chris@87 543 * The macros are designed to be used within a single C function: see
Chris@87 544 * Python/pystrtod.c for an example of their use.
Chris@87 545 */
Chris@87 546
Chris@87 547 /* get and set x87 control word for gcc/x86 */
Chris@87 548 #ifdef HAVE_GCC_ASM_FOR_X87
Chris@87 549 #define HAVE_PY_SET_53BIT_PRECISION 1
Chris@87 550 /* _Py_get/set_387controlword functions are defined in Python/pymath.c */
Chris@87 551 #define _Py_SET_53BIT_PRECISION_HEADER \
Chris@87 552 unsigned short old_387controlword, new_387controlword
Chris@87 553 #define _Py_SET_53BIT_PRECISION_START \
Chris@87 554 do { \
Chris@87 555 old_387controlword = _Py_get_387controlword(); \
Chris@87 556 new_387controlword = (old_387controlword & ~0x0f00) | 0x0200; \
Chris@87 557 if (new_387controlword != old_387controlword) \
Chris@87 558 _Py_set_387controlword(new_387controlword); \
Chris@87 559 } while (0)
Chris@87 560 #define _Py_SET_53BIT_PRECISION_END \
Chris@87 561 if (new_387controlword != old_387controlword) \
Chris@87 562 _Py_set_387controlword(old_387controlword)
Chris@87 563 #endif
Chris@87 564
Chris@87 565 /* get and set x87 control word for VisualStudio/x86 */
Chris@87 566 #if defined(_MSC_VER) && !defined(_WIN64) /* x87 not supported in 64-bit */
Chris@87 567 #define HAVE_PY_SET_53BIT_PRECISION 1
Chris@87 568 #define _Py_SET_53BIT_PRECISION_HEADER \
Chris@87 569 unsigned int old_387controlword, new_387controlword, out_387controlword
Chris@87 570 /* We use the __control87_2 function to set only the x87 control word.
Chris@87 571 The SSE control word is unaffected. */
Chris@87 572 #define _Py_SET_53BIT_PRECISION_START \
Chris@87 573 do { \
Chris@87 574 __control87_2(0, 0, &old_387controlword, NULL); \
Chris@87 575 new_387controlword = \
Chris@87 576 (old_387controlword & ~(_MCW_PC | _MCW_RC)) | (_PC_53 | _RC_NEAR); \
Chris@87 577 if (new_387controlword != old_387controlword) \
Chris@87 578 __control87_2(new_387controlword, _MCW_PC | _MCW_RC, \
Chris@87 579 &out_387controlword, NULL); \
Chris@87 580 } while (0)
Chris@87 581 #define _Py_SET_53BIT_PRECISION_END \
Chris@87 582 do { \
Chris@87 583 if (new_387controlword != old_387controlword) \
Chris@87 584 __control87_2(old_387controlword, _MCW_PC | _MCW_RC, \
Chris@87 585 &out_387controlword, NULL); \
Chris@87 586 } while (0)
Chris@87 587 #endif
Chris@87 588
Chris@87 589 /* default definitions are empty */
Chris@87 590 #ifndef HAVE_PY_SET_53BIT_PRECISION
Chris@87 591 #define _Py_SET_53BIT_PRECISION_HEADER
Chris@87 592 #define _Py_SET_53BIT_PRECISION_START
Chris@87 593 #define _Py_SET_53BIT_PRECISION_END
Chris@87 594 #endif
Chris@87 595
Chris@87 596 /* If we can't guarantee 53-bit precision, don't use the code
Chris@87 597 in Python/dtoa.c, but fall back to standard code. This
Chris@87 598 means that repr of a float will be long (17 sig digits).
Chris@87 599
Chris@87 600 Realistically, there are two things that could go wrong:
Chris@87 601
Chris@87 602 (1) doubles aren't IEEE 754 doubles, or
Chris@87 603 (2) we're on x86 with the rounding precision set to 64-bits
Chris@87 604 (extended precision), and we don't know how to change
Chris@87 605 the rounding precision.
Chris@87 606 */
Chris@87 607
Chris@87 608 #if !defined(DOUBLE_IS_LITTLE_ENDIAN_IEEE754) && \
Chris@87 609 !defined(DOUBLE_IS_BIG_ENDIAN_IEEE754) && \
Chris@87 610 !defined(DOUBLE_IS_ARM_MIXED_ENDIAN_IEEE754)
Chris@87 611 #define PY_NO_SHORT_FLOAT_REPR
Chris@87 612 #endif
Chris@87 613
Chris@87 614 /* double rounding is symptomatic of use of extended precision on x86. If
Chris@87 615 we're seeing double rounding, and we don't have any mechanism available for
Chris@87 616 changing the FPU rounding precision, then don't use Python/dtoa.c. */
Chris@87 617 #if defined(X87_DOUBLE_ROUNDING) && !defined(HAVE_PY_SET_53BIT_PRECISION)
Chris@87 618 #define PY_NO_SHORT_FLOAT_REPR
Chris@87 619 #endif
Chris@87 620
Chris@87 621 /* Py_DEPRECATED(version)
Chris@87 622 * Declare a variable, type, or function deprecated.
Chris@87 623 * Usage:
Chris@87 624 * extern int old_var Py_DEPRECATED(2.3);
Chris@87 625 * typedef int T1 Py_DEPRECATED(2.4);
Chris@87 626 * extern int x() Py_DEPRECATED(2.5);
Chris@87 627 */
Chris@87 628 #if defined(__GNUC__) && ((__GNUC__ >= 4) || \
Chris@87 629 (__GNUC__ == 3) && (__GNUC_MINOR__ >= 1))
Chris@87 630 #define Py_DEPRECATED(VERSION_UNUSED) __attribute__((__deprecated__))
Chris@87 631 #else
Chris@87 632 #define Py_DEPRECATED(VERSION_UNUSED)
Chris@87 633 #endif
Chris@87 634
Chris@87 635 /**************************************************************************
Chris@87 636 Prototypes that are missing from the standard include files on some systems
Chris@87 637 (and possibly only some versions of such systems.)
Chris@87 638
Chris@87 639 Please be conservative with adding new ones, document them and enclose them
Chris@87 640 in platform-specific #ifdefs.
Chris@87 641 **************************************************************************/
Chris@87 642
Chris@87 643 #ifdef SOLARIS
Chris@87 644 /* Unchecked */
Chris@87 645 extern int gethostname(char *, int);
Chris@87 646 #endif
Chris@87 647
Chris@87 648 #ifdef __BEOS__
Chris@87 649 /* Unchecked */
Chris@87 650 /* It's in the libs, but not the headers... - [cjh] */
Chris@87 651 int shutdown( int, int );
Chris@87 652 #endif
Chris@87 653
Chris@87 654 #ifdef HAVE__GETPTY
Chris@87 655 #include <sys/types.h> /* we need to import mode_t */
Chris@87 656 extern char * _getpty(int *, int, mode_t, int);
Chris@87 657 #endif
Chris@87 658
Chris@87 659 /* On QNX 6, struct termio must be declared by including sys/termio.h
Chris@87 660 if TCGETA, TCSETA, TCSETAW, or TCSETAF are used. sys/termio.h must
Chris@87 661 be included before termios.h or it will generate an error. */
Chris@87 662 #if defined(HAVE_SYS_TERMIO_H) && !defined(__hpux)
Chris@87 663 #include <sys/termio.h>
Chris@87 664 #endif
Chris@87 665
Chris@87 666 #if defined(HAVE_OPENPTY) || defined(HAVE_FORKPTY)
Chris@87 667 #if !defined(HAVE_PTY_H) && !defined(HAVE_LIBUTIL_H) && !defined(HAVE_UTIL_H)
Chris@87 668 /* BSDI does not supply a prototype for the 'openpty' and 'forkpty'
Chris@87 669 functions, even though they are included in libutil. */
Chris@87 670 #include <termios.h>
Chris@87 671 extern int openpty(int *, int *, char *, struct termios *, struct winsize *);
Chris@87 672 extern pid_t forkpty(int *, char *, struct termios *, struct winsize *);
Chris@87 673 #endif /* !defined(HAVE_PTY_H) && !defined(HAVE_LIBUTIL_H) */
Chris@87 674 #endif /* defined(HAVE_OPENPTY) || defined(HAVE_FORKPTY) */
Chris@87 675
Chris@87 676
Chris@87 677 /* These are pulled from various places. It isn't obvious on what platforms
Chris@87 678 they are necessary, nor what the exact prototype should look like (which
Chris@87 679 is likely to vary between platforms!) If you find you need one of these
Chris@87 680 declarations, please move them to a platform-specific block and include
Chris@87 681 proper prototypes. */
Chris@87 682 #if 0
Chris@87 683
Chris@87 684 /* From Modules/resource.c */
Chris@87 685 extern int getrusage();
Chris@87 686 extern int getpagesize();
Chris@87 687
Chris@87 688 /* From Python/sysmodule.c and Modules/posixmodule.c */
Chris@87 689 extern int fclose(FILE *);
Chris@87 690
Chris@87 691 /* From Modules/posixmodule.c */
Chris@87 692 extern int fdatasync(int);
Chris@87 693 #endif /* 0 */
Chris@87 694
Chris@87 695
Chris@87 696 /* On 4.4BSD-descendants, ctype functions serves the whole range of
Chris@87 697 * wchar_t character set rather than single byte code points only.
Chris@87 698 * This characteristic can break some operations of string object
Chris@87 699 * including str.upper() and str.split() on UTF-8 locales. This
Chris@87 700 * workaround was provided by Tim Robbins of FreeBSD project.
Chris@87 701 */
Chris@87 702
Chris@87 703 #ifdef __FreeBSD__
Chris@87 704 #include <osreldate.h>
Chris@87 705 #if __FreeBSD_version > 500039
Chris@87 706 # define _PY_PORT_CTYPE_UTF8_ISSUE
Chris@87 707 #endif
Chris@87 708 #endif
Chris@87 709
Chris@87 710
Chris@87 711 #if defined(__APPLE__)
Chris@87 712 # define _PY_PORT_CTYPE_UTF8_ISSUE
Chris@87 713 #endif
Chris@87 714
Chris@87 715 #ifdef _PY_PORT_CTYPE_UTF8_ISSUE
Chris@87 716 #include <ctype.h>
Chris@87 717 #include <wctype.h>
Chris@87 718 #undef isalnum
Chris@87 719 #define isalnum(c) iswalnum(btowc(c))
Chris@87 720 #undef isalpha
Chris@87 721 #define isalpha(c) iswalpha(btowc(c))
Chris@87 722 #undef islower
Chris@87 723 #define islower(c) iswlower(btowc(c))
Chris@87 724 #undef isspace
Chris@87 725 #define isspace(c) iswspace(btowc(c))
Chris@87 726 #undef isupper
Chris@87 727 #define isupper(c) iswupper(btowc(c))
Chris@87 728 #undef tolower
Chris@87 729 #define tolower(c) towlower(btowc(c))
Chris@87 730 #undef toupper
Chris@87 731 #define toupper(c) towupper(btowc(c))
Chris@87 732 #endif
Chris@87 733
Chris@87 734
Chris@87 735 /* Declarations for symbol visibility.
Chris@87 736
Chris@87 737 PyAPI_FUNC(type): Declares a public Python API function and return type
Chris@87 738 PyAPI_DATA(type): Declares public Python data and its type
Chris@87 739 PyMODINIT_FUNC: A Python module init function. If these functions are
Chris@87 740 inside the Python core, they are private to the core.
Chris@87 741 If in an extension module, it may be declared with
Chris@87 742 external linkage depending on the platform.
Chris@87 743
Chris@87 744 As a number of platforms support/require "__declspec(dllimport/dllexport)",
Chris@87 745 we support a HAVE_DECLSPEC_DLL macro to save duplication.
Chris@87 746 */
Chris@87 747
Chris@87 748 /*
Chris@87 749 All windows ports, except cygwin, are handled in PC/pyconfig.h.
Chris@87 750
Chris@87 751 BeOS and cygwin are the only other autoconf platform requiring special
Chris@87 752 linkage handling and both of these use __declspec().
Chris@87 753 */
Chris@87 754 #if defined(__CYGWIN__) || defined(__BEOS__)
Chris@87 755 # define HAVE_DECLSPEC_DLL
Chris@87 756 #endif
Chris@87 757
Chris@87 758 /* only get special linkage if built as shared or platform is Cygwin */
Chris@87 759 #if defined(Py_ENABLE_SHARED) || defined(__CYGWIN__)
Chris@87 760 # if defined(HAVE_DECLSPEC_DLL)
Chris@87 761 # ifdef Py_BUILD_CORE
Chris@87 762 # define PyAPI_FUNC(RTYPE) __declspec(dllexport) RTYPE
Chris@87 763 # define PyAPI_DATA(RTYPE) extern __declspec(dllexport) RTYPE
Chris@87 764 /* module init functions inside the core need no external linkage */
Chris@87 765 /* except for Cygwin to handle embedding (FIXME: BeOS too?) */
Chris@87 766 # if defined(__CYGWIN__)
Chris@87 767 # define PyMODINIT_FUNC __declspec(dllexport) void
Chris@87 768 # else /* __CYGWIN__ */
Chris@87 769 # define PyMODINIT_FUNC void
Chris@87 770 # endif /* __CYGWIN__ */
Chris@87 771 # else /* Py_BUILD_CORE */
Chris@87 772 /* Building an extension module, or an embedded situation */
Chris@87 773 /* public Python functions and data are imported */
Chris@87 774 /* Under Cygwin, auto-import functions to prevent compilation */
Chris@87 775 /* failures similar to those described at the bottom of 4.1: */
Chris@87 776 /* http://docs.python.org/extending/windows.html#a-cookbook-approach */
Chris@87 777 # if !defined(__CYGWIN__)
Chris@87 778 # define PyAPI_FUNC(RTYPE) __declspec(dllimport) RTYPE
Chris@87 779 # endif /* !__CYGWIN__ */
Chris@87 780 # define PyAPI_DATA(RTYPE) extern __declspec(dllimport) RTYPE
Chris@87 781 /* module init functions outside the core must be exported */
Chris@87 782 # if defined(__cplusplus)
Chris@87 783 # define PyMODINIT_FUNC extern "C" __declspec(dllexport) void
Chris@87 784 # else /* __cplusplus */
Chris@87 785 # define PyMODINIT_FUNC __declspec(dllexport) void
Chris@87 786 # endif /* __cplusplus */
Chris@87 787 # endif /* Py_BUILD_CORE */
Chris@87 788 # endif /* HAVE_DECLSPEC */
Chris@87 789 #endif /* Py_ENABLE_SHARED */
Chris@87 790
Chris@87 791 /* If no external linkage macros defined by now, create defaults */
Chris@87 792 #ifndef PyAPI_FUNC
Chris@87 793 # define PyAPI_FUNC(RTYPE) RTYPE
Chris@87 794 #endif
Chris@87 795 #ifndef PyAPI_DATA
Chris@87 796 # define PyAPI_DATA(RTYPE) extern RTYPE
Chris@87 797 #endif
Chris@87 798 #ifndef PyMODINIT_FUNC
Chris@87 799 # if defined(__cplusplus)
Chris@87 800 # define PyMODINIT_FUNC extern "C" void
Chris@87 801 # else /* __cplusplus */
Chris@87 802 # define PyMODINIT_FUNC void
Chris@87 803 # endif /* __cplusplus */
Chris@87 804 #endif
Chris@87 805
Chris@87 806 /* Deprecated DL_IMPORT and DL_EXPORT macros */
Chris@87 807 #if defined(Py_ENABLE_SHARED) && defined (HAVE_DECLSPEC_DLL)
Chris@87 808 # if defined(Py_BUILD_CORE)
Chris@87 809 # define DL_IMPORT(RTYPE) __declspec(dllexport) RTYPE
Chris@87 810 # define DL_EXPORT(RTYPE) __declspec(dllexport) RTYPE
Chris@87 811 # else
Chris@87 812 # define DL_IMPORT(RTYPE) __declspec(dllimport) RTYPE
Chris@87 813 # define DL_EXPORT(RTYPE) __declspec(dllexport) RTYPE
Chris@87 814 # endif
Chris@87 815 #endif
Chris@87 816 #ifndef DL_EXPORT
Chris@87 817 # define DL_EXPORT(RTYPE) RTYPE
Chris@87 818 #endif
Chris@87 819 #ifndef DL_IMPORT
Chris@87 820 # define DL_IMPORT(RTYPE) RTYPE
Chris@87 821 #endif
Chris@87 822 /* End of deprecated DL_* macros */
Chris@87 823
Chris@87 824 /* If the fd manipulation macros aren't defined,
Chris@87 825 here is a set that should do the job */
Chris@87 826
Chris@87 827 #if 0 /* disabled and probably obsolete */
Chris@87 828
Chris@87 829 #ifndef FD_SETSIZE
Chris@87 830 #define FD_SETSIZE 256
Chris@87 831 #endif
Chris@87 832
Chris@87 833 #ifndef FD_SET
Chris@87 834
Chris@87 835 typedef long fd_mask;
Chris@87 836
Chris@87 837 #define NFDBITS (sizeof(fd_mask) * NBBY) /* bits per mask */
Chris@87 838 #ifndef howmany
Chris@87 839 #define howmany(x, y) (((x)+((y)-1))/(y))
Chris@87 840 #endif /* howmany */
Chris@87 841
Chris@87 842 typedef struct fd_set {
Chris@87 843 fd_mask fds_bits[howmany(FD_SETSIZE, NFDBITS)];
Chris@87 844 } fd_set;
Chris@87 845
Chris@87 846 #define FD_SET(n, p) ((p)->fds_bits[(n)/NFDBITS] |= (1 << ((n) % NFDBITS)))
Chris@87 847 #define FD_CLR(n, p) ((p)->fds_bits[(n)/NFDBITS] &= ~(1 << ((n) % NFDBITS)))
Chris@87 848 #define FD_ISSET(n, p) ((p)->fds_bits[(n)/NFDBITS] & (1 << ((n) % NFDBITS)))
Chris@87 849 #define FD_ZERO(p) memset((char *)(p), '\0', sizeof(*(p)))
Chris@87 850
Chris@87 851 #endif /* FD_SET */
Chris@87 852
Chris@87 853 #endif /* fd manipulation macros */
Chris@87 854
Chris@87 855
Chris@87 856 /* limits.h constants that may be missing */
Chris@87 857
Chris@87 858 #ifndef INT_MAX
Chris@87 859 #define INT_MAX 2147483647
Chris@87 860 #endif
Chris@87 861
Chris@87 862 #ifndef LONG_MAX
Chris@87 863 #if SIZEOF_LONG == 4
Chris@87 864 #define LONG_MAX 0X7FFFFFFFL
Chris@87 865 #elif SIZEOF_LONG == 8
Chris@87 866 #define LONG_MAX 0X7FFFFFFFFFFFFFFFL
Chris@87 867 #else
Chris@87 868 #error "could not set LONG_MAX in pyport.h"
Chris@87 869 #endif
Chris@87 870 #endif
Chris@87 871
Chris@87 872 #ifndef LONG_MIN
Chris@87 873 #define LONG_MIN (-LONG_MAX-1)
Chris@87 874 #endif
Chris@87 875
Chris@87 876 #ifndef LONG_BIT
Chris@87 877 #define LONG_BIT (8 * SIZEOF_LONG)
Chris@87 878 #endif
Chris@87 879
Chris@87 880 #if LONG_BIT != 8 * SIZEOF_LONG
Chris@87 881 /* 04-Oct-2000 LONG_BIT is apparently (mis)defined as 64 on some recent
Chris@87 882 * 32-bit platforms using gcc. We try to catch that here at compile-time
Chris@87 883 * rather than waiting for integer multiplication to trigger bogus
Chris@87 884 * overflows.
Chris@87 885 */
Chris@87 886 #error "LONG_BIT definition appears wrong for platform (bad gcc/glibc config?)."
Chris@87 887 #endif
Chris@87 888
Chris@87 889 #ifdef __cplusplus
Chris@87 890 }
Chris@87 891 #endif
Chris@87 892
Chris@87 893 /*
Chris@87 894 * Hide GCC attributes from compilers that don't support them.
Chris@87 895 */
Chris@87 896 #if (!defined(__GNUC__) || __GNUC__ < 2 || \
Chris@87 897 (__GNUC__ == 2 && __GNUC_MINOR__ < 7) ) && \
Chris@87 898 !defined(RISCOS)
Chris@87 899 #define Py_GCC_ATTRIBUTE(x)
Chris@87 900 #else
Chris@87 901 #define Py_GCC_ATTRIBUTE(x) __attribute__(x)
Chris@87 902 #endif
Chris@87 903
Chris@87 904 /*
Chris@87 905 * Add PyArg_ParseTuple format where available.
Chris@87 906 */
Chris@87 907 #ifdef HAVE_ATTRIBUTE_FORMAT_PARSETUPLE
Chris@87 908 #define Py_FORMAT_PARSETUPLE(func,p1,p2) __attribute__((format(func,p1,p2)))
Chris@87 909 #else
Chris@87 910 #define Py_FORMAT_PARSETUPLE(func,p1,p2)
Chris@87 911 #endif
Chris@87 912
Chris@87 913 /*
Chris@87 914 * Specify alignment on compilers that support it.
Chris@87 915 */
Chris@87 916 #if defined(__GNUC__) && __GNUC__ >= 3
Chris@87 917 #define Py_ALIGNED(x) __attribute__((aligned(x)))
Chris@87 918 #else
Chris@87 919 #define Py_ALIGNED(x)
Chris@87 920 #endif
Chris@87 921
Chris@87 922 /* Eliminate end-of-loop code not reached warnings from SunPro C
Chris@87 923 * when using do{...}while(0) macros
Chris@87 924 */
Chris@87 925 #ifdef __SUNPRO_C
Chris@87 926 #pragma error_messages (off,E_END_OF_LOOP_CODE_NOT_REACHED)
Chris@87 927 #endif
Chris@87 928
Chris@87 929 /*
Chris@87 930 * Older Microsoft compilers don't support the C99 long long literal suffixes,
Chris@87 931 * so these will be defined in PC/pyconfig.h for those compilers.
Chris@87 932 */
Chris@87 933 #ifndef Py_LL
Chris@87 934 #define Py_LL(x) x##LL
Chris@87 935 #endif
Chris@87 936
Chris@87 937 #ifndef Py_ULL
Chris@87 938 #define Py_ULL(x) Py_LL(x##U)
Chris@87 939 #endif
Chris@87 940
Chris@87 941 #endif /* Py_PYPORT_H */