python-2.7.6/include/pyport.h Source File
Go to the documentation of this file.
46 #ifdef HAVE_PROTOTYPES
49 #define Py_PROTO(x) ()
52 #define Py_FPROTO(x) Py_PROTO(x)
69 #define PY_LONG_LONG long long
70 #if defined(LLONG_MAX)
72 #define PY_LLONG_MIN LLONG_MIN
73 #define PY_LLONG_MAX LLONG_MAX
74 #define PY_ULLONG_MAX ULLONG_MAX
75 #elif defined(__LONG_LONG_MAX__)
77 #define PY_LLONG_MAX __LONG_LONG_MAX__
78 #define PY_LLONG_MIN (-PY_LLONG_MAX-1)
79 #define PY_ULLONG_MAX (__LONG_LONG_MAX__*2ULL + 1ULL)
82 #define PY_ULLONG_MAX (~0ULL)
83 #define PY_LLONG_MAX ((long long)(PY_ULLONG_MAX>>1))
84 #define PY_LLONG_MIN (-PY_LLONG_MAX-1)
97 #define HAVE_UINT32_T 1
102 #define PY_UINT32_T uint32_t
110 #define HAVE_UINT64_T 1
115 #define PY_UINT64_T uint64_t
121 #define HAVE_INT32_T 1
126 #define PY_INT32_T int32_t
131 #define HAVE_INT64_T 1
136 #define PY_INT64_T int64_t
144 #ifndef PYLONG_BITS_IN_DIGIT
145 #if (defined HAVE_UINT64_T && defined HAVE_INT64_T && \
146 defined HAVE_UINT32_T && defined HAVE_INT32_T && SIZEOF_VOID_P >= 8)
147 #define PYLONG_BITS_IN_DIGIT 30
149 #define PYLONG_BITS_IN_DIGIT 15
158 #ifdef HAVE_UINTPTR_T
162 #elif SIZEOF_VOID_P <= SIZEOF_INT
166 #elif SIZEOF_VOID_P <= SIZEOF_LONG
170 #elif defined(HAVE_LONG_LONG) && (SIZEOF_VOID_P <= SIZEOF_LONG_LONG)
175 # error "Python needs a typedef for Py_uintptr_t in pyport.h."
184 #elif SIZEOF_VOID_P == SIZEOF_SIZE_T
187 # error "Python needs a typedef for Py_ssize_t in pyport.h."
196 #define PY_SIZE_MAX SIZE_MAX
198 #define PY_SIZE_MAX ((size_t)-1)
202 #define PY_SSIZE_T_MAX ((Py_ssize_t)(((size_t)-1)>>1))
204 #define PY_SSIZE_T_MIN (-PY_SSIZE_T_MAX-1)
206 #if SIZEOF_PID_T > SIZEOF_LONG
207 # error "Python doesn't support sizeof(pid_t) > sizeof(long)"
233 #ifndef PY_FORMAT_SIZE_T
234 # if SIZEOF_SIZE_T == SIZEOF_INT && !defined(__APPLE__)
235 # define PY_FORMAT_SIZE_T ""
236 # elif SIZEOF_SIZE_T == SIZEOF_LONG
237 # define PY_FORMAT_SIZE_T "l"
238 # elif defined(MS_WINDOWS)
239 # define PY_FORMAT_SIZE_T "I"
241 # error "This platform's pyconfig.h needs to define PY_FORMAT_SIZE_T"
251 #ifdef HAVE_LONG_LONG
252 # ifndef PY_FORMAT_LONG_LONG
253 # if defined(MS_WIN64) || defined(MS_WINDOWS)
254 # define PY_FORMAT_LONG_LONG "I64"
256 # error "This platform's pyconfig.h needs to define PY_FORMAT_LONG_LONG"
280 #if defined(_MSC_VER)
281 #if defined(PY_LOCAL_AGGRESSIVE)
283 #pragma optimize("agtw", on)
286 #pragma warning(disable: 4710)
288 #define Py_LOCAL(type) static type __fastcall
289 #define Py_LOCAL_INLINE(type) static __inline type __fastcall
290 #elif defined(USE_INLINE)
291 #define Py_LOCAL(type) static type
292 #define Py_LOCAL_INLINE(type) static inline type
294 #define Py_LOCAL(type) static type
295 #define Py_LOCAL_INLINE(type) static type
304 #if defined(_MSC_VER)
305 #define Py_MEMCPY(target, source, length) do { \
306 size_t i_, n_ = (length); \
307 char *t_ = (void*) (target); \
308 const char *s_ = (void*) (source); \
310 memcpy(t_, s_, n_); \
312 for (i_ = 0; i_ < n_; i_++) \
316 #define Py_MEMCPY memcpy
331 #ifdef TIME_WITH_SYS_TIME
332 #include <sys/time.h>
335 #ifdef HAVE_SYS_TIME_H
336 #include <sys/time.h>
349 #ifdef HAVE_SYS_SELECT_H
351 #include <sys/select.h>
373 #ifndef DONT_HAVE_STAT
377 #ifndef DONT_HAVE_FSTAT
382 #include <sys/types.h>
383 #include "unixstuff.h"
386 #ifdef HAVE_SYS_STAT_H
387 #if defined(PYOS_OS2) && defined(PYCC_GCC)
388 #include <sys/types.h>
390 #include <sys/stat.h>
391 #elif defined(HAVE_STAT_H)
395 #if defined(PYCC_VACPP)
397 #define S_IFMT (S_IFDIR|S_IFCHR|S_IFREG)
401 #define S_ISREG(x) (((x) & S_IFMT) == S_IFREG)
405 #define S_ISDIR(x) (((x) & S_IFMT) == S_IFDIR)
434 #ifdef SIGNED_RIGHT_SHIFT_ZERO_FILLS
435 #define Py_ARITHMETIC_RIGHT_SHIFT(TYPE, I, J) \
436 ((I) < 0 ? -1-((-1-(I)) >> (J)) : (I) >> (J))
438 #define Py_ARITHMETIC_RIGHT_SHIFT(TYPE, I, J) ((I) >> (J))
446 #define Py_FORCE_EXPANSION(X) X
455 #define Py_SAFE_DOWNCAST(VALUE, WIDE, NARROW) \
456 (assert((WIDE)(NARROW)(VALUE) == (VALUE)), (NARROW)(VALUE))
458 #define Py_SAFE_DOWNCAST(VALUE, WIDE, NARROW) (NARROW)(VALUE)
470 #if defined(__FreeBSD__) || defined(__OpenBSD__) || (defined(__hpux) && defined(__ia64))
471 #define _Py_SET_EDOM_FOR_NAN(X) if (isnan(X)) errno = EDOM;
473 #define _Py_SET_EDOM_FOR_NAN(X) ;
475 #define Py_SET_ERRNO_ON_MATH_ERROR(X) \
478 if ((X) == Py_HUGE_VAL || (X) == -Py_HUGE_VAL) \
480 else _Py_SET_EDOM_FOR_NAN(X) \
487 #define Py_SET_ERANGE_IF_OVERFLOW(X) Py_SET_ERRNO_ON_MATH_ERROR(X)
503 #define Py_ADJUST_ERANGE1(X) \
506 if ((X) == Py_HUGE_VAL || (X) == -Py_HUGE_VAL) \
509 else if (errno == ERANGE && (X) == 0.0) \
513 #define Py_ADJUST_ERANGE2(X, Y) \
515 if ((X) == Py_HUGE_VAL || (X) == -Py_HUGE_VAL || \
516 (Y) == Py_HUGE_VAL || (Y) == -Py_HUGE_VAL) { \
520 else if (errno == ERANGE) \
548 #ifdef HAVE_GCC_ASM_FOR_X87
549 #define HAVE_PY_SET_53BIT_PRECISION 1
551 #define _Py_SET_53BIT_PRECISION_HEADER \
552 unsigned short old_387controlword, new_387controlword
553 #define _Py_SET_53BIT_PRECISION_START \
555 old_387controlword = _Py_get_387controlword(); \
556 new_387controlword = (old_387controlword & ~0x0f00) | 0x0200; \
557 if (new_387controlword != old_387controlword) \
558 _Py_set_387controlword(new_387controlword); \
560 #define _Py_SET_53BIT_PRECISION_END \
561 if (new_387controlword != old_387controlword) \
562 _Py_set_387controlword(old_387controlword)
566 #if defined(_MSC_VER) && !defined(_WIN64)
567 #define HAVE_PY_SET_53BIT_PRECISION 1
568 #define _Py_SET_53BIT_PRECISION_HEADER \
569 unsigned int old_387controlword, new_387controlword, out_387controlword
572 #define _Py_SET_53BIT_PRECISION_START \
574 __control87_2(0, 0, &old_387controlword, NULL); \
575 new_387controlword = \
576 (old_387controlword & ~(_MCW_PC | _MCW_RC)) | (_PC_53 | _RC_NEAR); \
577 if (new_387controlword != old_387controlword) \
578 __control87_2(new_387controlword, _MCW_PC | _MCW_RC, \
579 &out_387controlword, NULL); \
581 #define _Py_SET_53BIT_PRECISION_END \
583 if (new_387controlword != old_387controlword) \
584 __control87_2(old_387controlword, _MCW_PC | _MCW_RC, \
585 &out_387controlword, NULL); \
590 #ifndef HAVE_PY_SET_53BIT_PRECISION
591 #define _Py_SET_53BIT_PRECISION_HEADER
592 #define _Py_SET_53BIT_PRECISION_START
593 #define _Py_SET_53BIT_PRECISION_END
608 #if !defined(DOUBLE_IS_LITTLE_ENDIAN_IEEE754) && \
609 !defined(DOUBLE_IS_BIG_ENDIAN_IEEE754) && \
610 !defined(DOUBLE_IS_ARM_MIXED_ENDIAN_IEEE754)
611 #define PY_NO_SHORT_FLOAT_REPR
617 #if defined(X87_DOUBLE_ROUNDING) && !defined(HAVE_PY_SET_53BIT_PRECISION)
618 #define PY_NO_SHORT_FLOAT_REPR
628 #if defined(__GNUC__) && ((__GNUC__ >= 4) || \
629 (__GNUC__ == 3) && (__GNUC_MINOR__ >= 1))
630 #define Py_DEPRECATED(VERSION_UNUSED) __attribute__((__deprecated__))
632 #define Py_DEPRECATED(VERSION_UNUSED)
645 extern int gethostname(
char *,
int);
651 int shutdown(
int,
int );
655 #include <sys/types.h>
656 extern char * _getpty(
int *,
int, mode_t,
int);
662 #if defined(HAVE_SYS_TERMIO_H) && !defined(__hpux)
663 #include <sys/termio.h>
666 #if defined(HAVE_OPENPTY) || defined(HAVE_FORKPTY)
667 #if !defined(HAVE_PTY_H) && !defined(HAVE_LIBUTIL_H) && !defined(HAVE_UTIL_H)
671 extern int openpty(
int *,
int *,
char *,
struct termios *,
struct winsize *);
672 extern pid_t forkpty(
int *,
char *,
struct termios *,
struct winsize *);
685 extern int getrusage();
686 extern int getpagesize();
689 extern int fclose(
FILE *);
692 extern int fdatasync(
int);
704 #include <osreldate.h>
705 #if __FreeBSD_version > 500039
706 # define _PY_PORT_CTYPE_UTF8_ISSUE
711 #if defined(__APPLE__)
717 #ifdef _PY_PORT_CTYPE_UTF8_ISSUE
721 #define isalnum(c) iswalnum(btowc(c))
723 #define isalpha(c) iswalpha(btowc(c))
725 #define islower(c) iswlower(btowc(c))
727 #define isspace(c) iswspace(btowc(c))
729 #define isupper(c) iswupper(btowc(c))
731 #define tolower(c) towlower(btowc(c))
733 #define toupper(c) towupper(btowc(c))
756 #if defined(__CYGWIN__) || defined(__BEOS__)
757 # define HAVE_DECLSPEC_DLL
761 #if defined(Py_ENABLE_SHARED) || defined(__CYGWIN__)
762 # if defined(HAVE_DECLSPEC_DLL)
763 # ifdef Py_BUILD_CORE
764 # define PyAPI_FUNC(RTYPE) __declspec(dllexport) RTYPE
765 # define PyAPI_DATA(RTYPE) extern __declspec(dllexport) RTYPE
768 # if defined(__CYGWIN__)
769 # define PyMODINIT_FUNC __declspec(dllexport) void
771 # define PyMODINIT_FUNC void
779 # if !defined(__CYGWIN__)
780 # define PyAPI_FUNC(RTYPE) __declspec(dllimport) RTYPE
782 # define PyAPI_DATA(RTYPE) extern __declspec(dllimport) RTYPE
784 # if defined(__cplusplus)
785 # define PyMODINIT_FUNC extern "C" __declspec(dllexport) void
787 # define PyMODINIT_FUNC __declspec(dllexport) void
795 # define PyAPI_FUNC(RTYPE) RTYPE
798 # define PyAPI_DATA(RTYPE) extern RTYPE
800 #ifndef PyMODINIT_FUNC
801 # if defined(__cplusplus)
802 # define PyMODINIT_FUNC extern "C" void
804 # define PyMODINIT_FUNC void
809 #if defined(Py_ENABLE_SHARED) && defined (HAVE_DECLSPEC_DLL)
810 # if defined(Py_BUILD_CORE)
811 # define DL_IMPORT(RTYPE) __declspec(dllexport) RTYPE
812 # define DL_EXPORT(RTYPE) __declspec(dllexport) RTYPE
814 # define DL_IMPORT(RTYPE) __declspec(dllimport) RTYPE
815 # define DL_EXPORT(RTYPE) __declspec(dllexport) RTYPE
819 # define DL_EXPORT(RTYPE) RTYPE
822 # define DL_IMPORT(RTYPE) RTYPE
832 #define FD_SETSIZE 256
837 typedef long fd_mask;
839 #define NFDBITS (sizeof(fd_mask) * NBBY)
841 #define howmany(x, y) (((x)+((y)-1))/(y))
844 typedef struct fd_set {
845 fd_mask fds_bits[howmany(FD_SETSIZE, NFDBITS)];
848 #define FD_SET(n, p) ((p)->fds_bits[(n)/NFDBITS] |= (1 << ((n) % NFDBITS)))
849 #define FD_CLR(n, p) ((p)->fds_bits[(n)/NFDBITS] &= ~(1 << ((n) % NFDBITS)))
850 #define FD_ISSET(n, p) ((p)->fds_bits[(n)/NFDBITS] & (1 << ((n) % NFDBITS)))
851 #define FD_ZERO(p) memset((char *)(p), '\0', sizeof(*(p)))
861 #define INT_MAX 2147483647
866 #define LONG_MAX 0X7FFFFFFFL
867 #elif SIZEOF_LONG == 8
868 #define LONG_MAX 0X7FFFFFFFFFFFFFFFL
870 #error "could not set LONG_MAX in pyport.h"
875 #define LONG_MIN (-LONG_MAX-1)
879 #define LONG_BIT (8 * SIZEOF_LONG)
882 #if LONG_BIT != 8 * SIZEOF_LONG
888 #error "LONG_BIT definition appears wrong for platform (bad gcc/glibc config?)."
898 #if (!defined(__GNUC__) || __GNUC__ < 2 || \
899 (__GNUC__ == 2 && __GNUC_MINOR__ < 7) ) && \
901 #define Py_GCC_ATTRIBUTE(x)
903 #define Py_GCC_ATTRIBUTE(x) __attribute__(x)
909 #ifdef HAVE_ATTRIBUTE_FORMAT_PARSETUPLE
910 #define Py_FORMAT_PARSETUPLE(func,p1,p2) __attribute__((format(func,p1,p2)))
912 #define Py_FORMAT_PARSETUPLE(func,p1,p2)
918 #if defined(__GNUC__) && __GNUC__ >= 3
919 #define Py_ALIGNED(x) __attribute__((aligned(x)))
921 #define Py_ALIGNED(x)
928 #pragma error_messages (off,E_END_OF_LOOP_CODE_NOT_REACHED)
936 #define Py_LL(x) x##LL
940 #define Py_ULL(x) Py_LL(x##U)
unsigned int Py_uintptr_t