Merged revisions 71627 via svnmerge from
[python/dscho.git] / Include / pyport.h
blobbf75d89982d6bc1eb7060ee9b283a9f982036662
1 #ifndef Py_PYPORT_H
2 #define Py_PYPORT_H
4 #include "pyconfig.h" /* include for defines */
6 #ifdef HAVE_STDINT_H
7 #include <stdint.h>
8 #endif
10 /**************************************************************************
11 Symbols and macros to supply platform-independent interfaces to basic
12 C language & library operations whose spellings vary across platforms.
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.
17 Config #defines referenced here:
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
24 Py_DEBUG
25 Meaning: Extra checks compiled in for debug mode.
26 Used in: Py_SAFE_DOWNCAST
28 HAVE_UINTPTR_T
29 Meaning: The C9X type uintptr_t is supported by the compiler
30 Used in: Py_uintptr_t
32 HAVE_LONG_LONG
33 Meaning: The compiler supports the C type "long long"
34 Used in: PY_LONG_LONG
36 **************************************************************************/
38 /* typedefs for some C9X-defined synonyms for integral types.
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.
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.
50 #ifdef HAVE_LONG_LONG
51 #ifndef PY_LONG_LONG
52 #define PY_LONG_LONG long long
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 */
69 #endif
70 #endif /* HAVE_LONG_LONG */
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.
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
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.
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
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
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. */
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
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
125 * without loss of information. Similarly for intptr_t, wrt a signed
126 * integral type.
128 #ifdef HAVE_UINTPTR_T
129 typedef uintptr_t Py_uintptr_t;
130 typedef intptr_t Py_intptr_t;
132 #elif SIZEOF_VOID_P <= SIZEOF_INT
133 typedef unsigned int Py_uintptr_t;
134 typedef int Py_intptr_t;
136 #elif SIZEOF_VOID_P <= SIZEOF_LONG
137 typedef unsigned long Py_uintptr_t;
138 typedef long Py_intptr_t;
140 #elif defined(HAVE_LONG_LONG) && (SIZEOF_VOID_P <= SIZEOF_LONG_LONG)
141 typedef unsigned PY_LONG_LONG Py_uintptr_t;
142 typedef PY_LONG_LONG Py_intptr_t;
144 #else
145 # error "Python needs a typedef for Py_uintptr_t in pyport.h."
146 #endif /* HAVE_UINTPTR_T */
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.
152 #ifdef HAVE_SSIZE_T
153 typedef ssize_t Py_ssize_t;
154 #elif SIZEOF_VOID_P == SIZEOF_SIZE_T
155 typedef Py_intptr_t Py_ssize_t;
156 #else
157 # error "Python needs a typedef for Py_ssize_t in pyport.h."
158 #endif
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
171 /* Largest positive value of type Py_ssize_t. */
172 #define PY_SSIZE_T_MAX ((Py_ssize_t)(((size_t)-1)>>1))
173 /* Smallest negative value of type Py_ssize_t. */
174 #define PY_SSIZE_T_MIN (-PY_SSIZE_T_MAX-1)
176 #if SIZEOF_PID_T > SIZEOF_LONG
177 # error "Python doesn't support sizeof(pid_t) > sizeof(long)"
178 #endif
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.
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):
189 * PyBytes_FromFormat
190 * PyErr_Format
191 * PyBytes_FromFormatV
192 * PyUnicode_FromFormatV
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,
198 * Py_ssize_t index;
199 * fprintf(stderr, "index %" PY_FORMAT_SIZE_T "d sucks\n", index);
201 * That will expand to %ld, or %Id, or to something else correct for a
202 * Py_ssize_t on the platform.
204 #ifndef PY_FORMAT_SIZE_T
205 # if SIZEOF_SIZE_T == SIZEOF_INT && !defined(__APPLE__)
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
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.
219 * Py_LOCAL_INLINE does the same thing, and also explicitly requests inlining,
220 * for platforms that support that.
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.
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.
233 #undef USE_INLINE /* XXX - set via configure? */
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
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".
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
274 #include <stdlib.h>
276 #include <math.h> /* Moved here from the math section, before extern "C" */
278 /********************************************
279 * WRAPPER FOR <time.h> and/or <sys/time.h> *
280 ********************************************/
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 */
294 /******************************
295 * WRAPPER FOR <sys/select.h> *
296 ******************************/
298 /* NB caller must include <sys/types.h> */
300 #ifdef HAVE_SYS_SELECT_H
301 #include <sys/select.h>
302 #endif /* !HAVE_SYS_SELECT_H */
304 /*******************************
305 * stat() and fstat() fiddling *
306 *******************************/
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
314 * to your pyconfig.h. Python code beyond this should check HAVE_STAT and
315 * HAVE_FSTAT instead.
316 * Also
317 * #define HAVE_SYS_STAT_H
318 * if <sys/stat.h> exists on your platform, and
319 * #define HAVE_STAT_H
320 * if <stat.h> does.
322 #ifndef DONT_HAVE_STAT
323 #define HAVE_STAT
324 #endif
326 #ifndef DONT_HAVE_FSTAT
327 #define HAVE_FSTAT
328 #endif
330 #ifdef HAVE_SYS_STAT_H
331 #if defined(PYOS_OS2) && defined(PYCC_GCC)
332 #include <sys/types.h>
333 #endif
334 #include <sys/stat.h>
335 #elif defined(HAVE_STAT_H)
336 #include <stat.h>
337 #endif
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
344 #ifndef S_ISREG
345 #define S_ISREG(x) (((x) & S_IFMT) == S_IFREG)
346 #endif
348 #ifndef S_ISDIR
349 #define S_ISDIR(x) (((x) & S_IFMT) == S_IFDIR)
350 #endif
353 #ifdef __cplusplus
354 /* Move this down here since some C++ #include's don't like to be included
355 inside an extern "C" */
356 extern "C" {
357 #endif
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. Arithmetically, return the
365 * floor of I/2**J.
366 * Requirements:
367 * I should have signed integer type. In the terminology of C99, this can
368 * be either one of the five standard signed integer types (signed char,
369 * short, int, long, long long) or an extended signed integer type.
370 * J is an integer >= 0 and strictly less than the number of bits in the
371 * type of I (because C doesn't define what happens for J outside that
372 * range either).
373 * TYPE used to specify the type of I, but is now ignored. It's been left
374 * in for backwards compatibility with versions <= 2.6 or 3.0.
375 * Caution:
376 * I may be evaluated more than once.
378 #ifdef SIGNED_RIGHT_SHIFT_ZERO_FILLS
379 #define Py_ARITHMETIC_RIGHT_SHIFT(TYPE, I, J) \
380 ((I) < 0 ? -1-((-1-(I)) >> (J)) : (I) >> (J))
381 #else
382 #define Py_ARITHMETIC_RIGHT_SHIFT(TYPE, I, J) ((I) >> (J))
383 #endif
385 /* Py_FORCE_EXPANSION(X)
386 * "Simply" returns its argument. However, macro expansions within the
387 * argument are evaluated. This unfortunate trickery is needed to get
388 * token-pasting to work as desired in some cases.
390 #define Py_FORCE_EXPANSION(X) X
392 /* Py_SAFE_DOWNCAST(VALUE, WIDE, NARROW)
393 * Cast VALUE to type NARROW from type WIDE. In Py_DEBUG mode, this
394 * assert-fails if any information is lost.
395 * Caution:
396 * VALUE may be evaluated more than once.
398 #ifdef Py_DEBUG
399 #define Py_SAFE_DOWNCAST(VALUE, WIDE, NARROW) \
400 (assert((WIDE)(NARROW)(VALUE) == (VALUE)), (NARROW)(VALUE))
401 #else
402 #define Py_SAFE_DOWNCAST(VALUE, WIDE, NARROW) (NARROW)(VALUE)
403 #endif
405 /* Py_SET_ERRNO_ON_MATH_ERROR(x)
406 * If a libm function did not set errno, but it looks like the result
407 * overflowed or not-a-number, set errno to ERANGE or EDOM. Set errno
408 * to 0 before calling a libm function, and invoke this macro after,
409 * passing the function result.
410 * Caution:
411 * This isn't reliable. See Py_OVERFLOWED comments.
412 * X is evaluated more than once.
414 #if defined(__FreeBSD__) || defined(__OpenBSD__) || (defined(__hpux) && defined(__ia64))
415 #define _Py_SET_EDOM_FOR_NAN(X) if (isnan(X)) errno = EDOM;
416 #else
417 #define _Py_SET_EDOM_FOR_NAN(X) ;
418 #endif
419 #define Py_SET_ERRNO_ON_MATH_ERROR(X) \
420 do { \
421 if (errno == 0) { \
422 if ((X) == Py_HUGE_VAL || (X) == -Py_HUGE_VAL) \
423 errno = ERANGE; \
424 else _Py_SET_EDOM_FOR_NAN(X) \
426 } while(0)
428 /* Py_SET_ERANGE_ON_OVERFLOW(x)
429 * An alias of Py_SET_ERRNO_ON_MATH_ERROR for backward-compatibility.
431 #define Py_SET_ERANGE_IF_OVERFLOW(X) Py_SET_ERRNO_ON_MATH_ERROR(X)
433 /* Py_ADJUST_ERANGE1(x)
434 * Py_ADJUST_ERANGE2(x, y)
435 * Set errno to 0 before calling a libm function, and invoke one of these
436 * macros after, passing the function result(s) (Py_ADJUST_ERANGE2 is useful
437 * for functions returning complex results). This makes two kinds of
438 * adjustments to errno: (A) If it looks like the platform libm set
439 * errno=ERANGE due to underflow, clear errno. (B) If it looks like the
440 * platform libm overflowed but didn't set errno, force errno to ERANGE. In
441 * effect, we're trying to force a useful implementation of C89 errno
442 * behavior.
443 * Caution:
444 * This isn't reliable. See Py_OVERFLOWED comments.
445 * X and Y may be evaluated more than once.
447 #define Py_ADJUST_ERANGE1(X) \
448 do { \
449 if (errno == 0) { \
450 if ((X) == Py_HUGE_VAL || (X) == -Py_HUGE_VAL) \
451 errno = ERANGE; \
453 else if (errno == ERANGE && (X) == 0.0) \
454 errno = 0; \
455 } while(0)
457 #define Py_ADJUST_ERANGE2(X, Y) \
458 do { \
459 if ((X) == Py_HUGE_VAL || (X) == -Py_HUGE_VAL || \
460 (Y) == Py_HUGE_VAL || (Y) == -Py_HUGE_VAL) { \
461 if (errno == 0) \
462 errno = ERANGE; \
464 else if (errno == ERANGE) \
465 errno = 0; \
466 } while(0)
468 /* Py_DEPRECATED(version)
469 * Declare a variable, type, or function deprecated.
470 * Usage:
471 * extern int old_var Py_DEPRECATED(2.3);
472 * typedef int T1 Py_DEPRECATED(2.4);
473 * extern int x() Py_DEPRECATED(2.5);
475 #if defined(__GNUC__) && ((__GNUC__ >= 4) || \
476 (__GNUC__ == 3) && (__GNUC_MINOR__ >= 1))
477 #define Py_DEPRECATED(VERSION_UNUSED) __attribute__((__deprecated__))
478 #else
479 #define Py_DEPRECATED(VERSION_UNUSED)
480 #endif
482 /**************************************************************************
483 Prototypes that are missing from the standard include files on some systems
484 (and possibly only some versions of such systems.)
486 Please be conservative with adding new ones, document them and enclose them
487 in platform-specific #ifdefs.
488 **************************************************************************/
490 #ifdef SOLARIS
491 /* Unchecked */
492 extern int gethostname(char *, int);
493 #endif
495 #ifdef HAVE__GETPTY
496 #include <sys/types.h> /* we need to import mode_t */
497 extern char * _getpty(int *, int, mode_t, int);
498 #endif
500 /* On QNX 6, struct termio must be declared by including sys/termio.h
501 if TCGETA, TCSETA, TCSETAW, or TCSETAF are used. sys/termio.h must
502 be included before termios.h or it will generate an error. */
503 #ifdef HAVE_SYS_TERMIO_H
504 #include <sys/termio.h>
505 #endif
507 #if defined(HAVE_OPENPTY) || defined(HAVE_FORKPTY)
508 #if !defined(HAVE_PTY_H) && !defined(HAVE_LIBUTIL_H)
509 /* BSDI does not supply a prototype for the 'openpty' and 'forkpty'
510 functions, even though they are included in libutil. */
511 #include <termios.h>
512 extern int openpty(int *, int *, char *, struct termios *, struct winsize *);
513 extern pid_t forkpty(int *, char *, struct termios *, struct winsize *);
514 #endif /* !defined(HAVE_PTY_H) && !defined(HAVE_LIBUTIL_H) */
515 #endif /* defined(HAVE_OPENPTY) || defined(HAVE_FORKPTY) */
518 /* On 4.4BSD-descendants, ctype functions serves the whole range of
519 * wchar_t character set rather than single byte code points only.
520 * This characteristic can break some operations of string object
521 * including str.upper() and str.split() on UTF-8 locales. This
522 * workaround was provided by Tim Robbins of FreeBSD project.
525 #ifdef __FreeBSD__
526 #include <osreldate.h>
527 #if __FreeBSD_version > 500039
528 #include <ctype.h>
529 #include <wctype.h>
530 #undef isalnum
531 #define isalnum(c) iswalnum(btowc(c))
532 #undef isalpha
533 #define isalpha(c) iswalpha(btowc(c))
534 #undef islower
535 #define islower(c) iswlower(btowc(c))
536 #undef isspace
537 #define isspace(c) iswspace(btowc(c))
538 #undef isupper
539 #define isupper(c) iswupper(btowc(c))
540 #undef tolower
541 #define tolower(c) towlower(btowc(c))
542 #undef toupper
543 #define toupper(c) towupper(btowc(c))
544 #endif
545 #endif
548 /* Declarations for symbol visibility.
550 PyAPI_FUNC(type): Declares a public Python API function and return type
551 PyAPI_DATA(type): Declares public Python data and its type
552 PyMODINIT_FUNC: A Python module init function. If these functions are
553 inside the Python core, they are private to the core.
554 If in an extension module, it may be declared with
555 external linkage depending on the platform.
557 As a number of platforms support/require "__declspec(dllimport/dllexport)",
558 we support a HAVE_DECLSPEC_DLL macro to save duplication.
562 All windows ports, except cygwin, are handled in PC/pyconfig.h.
564 Cygwin is the only other autoconf platform requiring special
565 linkage handling and it uses __declspec().
567 #if defined(__CYGWIN__)
568 # define HAVE_DECLSPEC_DLL
569 #endif
571 /* only get special linkage if built as shared or platform is Cygwin */
572 #if defined(Py_ENABLE_SHARED) || defined(__CYGWIN__)
573 # if defined(HAVE_DECLSPEC_DLL)
574 # ifdef Py_BUILD_CORE
575 # define PyAPI_FUNC(RTYPE) __declspec(dllexport) RTYPE
576 # define PyAPI_DATA(RTYPE) extern __declspec(dllexport) RTYPE
577 /* module init functions inside the core need no external linkage */
578 /* except for Cygwin to handle embedding */
579 # if defined(__CYGWIN__)
580 # define PyMODINIT_FUNC __declspec(dllexport) PyObject*
581 # else /* __CYGWIN__ */
582 # define PyMODINIT_FUNC PyObject*
583 # endif /* __CYGWIN__ */
584 # else /* Py_BUILD_CORE */
585 /* Building an extension module, or an embedded situation */
586 /* public Python functions and data are imported */
587 /* Under Cygwin, auto-import functions to prevent compilation */
588 /* failures similar to http://python.org/doc/FAQ.html#3.24 */
589 # if !defined(__CYGWIN__)
590 # define PyAPI_FUNC(RTYPE) __declspec(dllimport) RTYPE
591 # endif /* !__CYGWIN__ */
592 # define PyAPI_DATA(RTYPE) extern __declspec(dllimport) RTYPE
593 /* module init functions outside the core must be exported */
594 # if defined(__cplusplus)
595 # define PyMODINIT_FUNC extern "C" __declspec(dllexport) PyObject*
596 # else /* __cplusplus */
597 # define PyMODINIT_FUNC __declspec(dllexport) PyObject*
598 # endif /* __cplusplus */
599 # endif /* Py_BUILD_CORE */
600 # endif /* HAVE_DECLSPEC */
601 #endif /* Py_ENABLE_SHARED */
603 /* If no external linkage macros defined by now, create defaults */
604 #ifndef PyAPI_FUNC
605 # define PyAPI_FUNC(RTYPE) RTYPE
606 #endif
607 #ifndef PyAPI_DATA
608 # define PyAPI_DATA(RTYPE) extern RTYPE
609 #endif
610 #ifndef PyMODINIT_FUNC
611 # if defined(__cplusplus)
612 # define PyMODINIT_FUNC extern "C" PyObject*
613 # else /* __cplusplus */
614 # define PyMODINIT_FUNC PyObject*
615 # endif /* __cplusplus */
616 #endif
618 /* limits.h constants that may be missing */
620 #ifndef INT_MAX
621 #define INT_MAX 2147483647
622 #endif
624 #ifndef LONG_MAX
625 #if SIZEOF_LONG == 4
626 #define LONG_MAX 0X7FFFFFFFL
627 #elif SIZEOF_LONG == 8
628 #define LONG_MAX 0X7FFFFFFFFFFFFFFFL
629 #else
630 #error "could not set LONG_MAX in pyport.h"
631 #endif
632 #endif
634 #ifndef LONG_MIN
635 #define LONG_MIN (-LONG_MAX-1)
636 #endif
638 #ifndef LONG_BIT
639 #define LONG_BIT (8 * SIZEOF_LONG)
640 #endif
642 #if LONG_BIT != 8 * SIZEOF_LONG
643 /* 04-Oct-2000 LONG_BIT is apparently (mis)defined as 64 on some recent
644 * 32-bit platforms using gcc. We try to catch that here at compile-time
645 * rather than waiting for integer multiplication to trigger bogus
646 * overflows.
648 #error "LONG_BIT definition appears wrong for platform (bad gcc/glibc config?)."
649 #endif
651 #ifdef __cplusplus
653 #endif
656 * Hide GCC attributes from compilers that don't support them.
658 #if (!defined(__GNUC__) || __GNUC__ < 2 || \
659 (__GNUC__ == 2 && __GNUC_MINOR__ < 7) )
660 #define Py_GCC_ATTRIBUTE(x)
661 #else
662 #define Py_GCC_ATTRIBUTE(x) __attribute__(x)
663 #endif
666 * Add PyArg_ParseTuple format where available.
668 #ifdef HAVE_ATTRIBUTE_FORMAT_PARSETUPLE
669 #define Py_FORMAT_PARSETUPLE(func,p1,p2) __attribute__((format(func,p1,p2)))
670 #else
671 #define Py_FORMAT_PARSETUPLE(func,p1,p2)
672 #endif
675 * Specify alignment on compilers that support it.
677 #if defined(__GNUC__) && __GNUC__ >= 3
678 #define Py_ALIGNED(x) __attribute__((aligned(x)))
679 #else
680 #define Py_ALIGNED(x)
681 #endif
683 /* Eliminate end-of-loop code not reached warnings from SunPro C
684 * when using do{...}while(0) macros
686 #ifdef __SUNPRO_C
687 #pragma error_messages (off,E_END_OF_LOOP_CODE_NOT_REACHED)
688 #endif
691 * Older Microsoft compilers don't support the C99 long long literal suffixes,
692 * so these will be defined in PC/pyconfig.h for those compilers.
694 #ifndef Py_LL
695 #define Py_LL(x) x##LL
696 #endif
698 #ifndef Py_ULL
699 #define Py_ULL(x) Py_LL(x##U)
700 #endif
702 #endif /* Py_PYPORT_H */