Read about our upcoming Code of Conduct on this issue

commondefs.h 3.33 KB
Newer Older
Armin Rigo's avatar
Armin Rigo committed
1
2
3
4
5
6
7
8
9
10
11
12
13

/************************************************************/
 /***  C header subsection: common types and macros        ***/


/* We only support the following two kinds of platform:

                 int     long     long long     void*
   --32-bit--    32      32         64          32
   --64-bit--    32      64         64          64

   In particular, Win64 is not supported because it has sizeof(long) == 4.
   To fix this, find and review all the places that cast a pointer to a long.
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28

   Update:
   We are trying to lift this restriction for Win64:

   Win64         int     long     long long     void*
   --64-bit--    32      32         64          64

   The migration to this platform is complicated and tedious, because
   PyPy assumes that a void* fits into a long. Therefore, the created PyPy
   will (first) have a 64 bit int type. The dependency of sys.maxint must
   be removed in very many places, and the distinction between Python int
   and long must be changed in explicit range checks.

   This is work in progress with first successes.

Armin Rigo's avatar
Armin Rigo committed
29
30
*/

31
32
33
#if defined(__MINGW32__)
#   include <windows.h>
#endif
Armin Rigo's avatar
Armin Rigo committed
34
35
#include <limits.h>

36
37
38
39
40
41
42
#ifndef LLONG_MAX
#define LLONG_MAX __LONG_LONG_MAX__
#endif
#ifndef LLONG_MIN
#define LLONG_MIN (-LLONG_MAX - 1LL)
#endif

Armin Rigo's avatar
Armin Rigo committed
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#if INT_MAX != 2147483647
#  error "unsupported value for INT_MAX"
#endif
#if INT_MIN != -2147483647-1
#  error "unsupported value for INT_MIN"
#endif

#if LLONG_MAX != 9223372036854775807LL
#  error "unsupported value for LLONG_MAX"
#endif
#if LLONG_MIN != -9223372036854775807LL-1LL
#  error "unsupported value for LLONG_MIN"
#endif


/******************** 32-bit support ********************/
#if PYPY_LONG_BIT == 32

#  if LONG_MAX != 2147483647L
#    error "error in LONG_MAX (32-bit sources but a 64-bit compiler?)"
#  endif
#  if LONG_MIN != -2147483647L-1L
#    error "unsupported value for LONG_MIN"
#  endif

#  define SIZEOF_INT        4
#  define SIZEOF_LONG       4
Armin Rigo's avatar
Armin Rigo committed
70
#  define SIZEOF_SIGNED     4
Armin Rigo's avatar
Armin Rigo committed
71
72
73
74
75
#  define SIZEOF_LONG_LONG  8

/******************** 64-bit support ********************/
#else

76
77
78
79
80
81
82
83
84
85
#  ifndef _WIN64
#    if LONG_MAX != 9223372036854775807L
#      error "error in LONG_MAX (64-bit sources but a 32-bit compiler?)"
#    endif
#    if LONG_MIN != -9223372036854775807L-1L
#      error "unsupported value for LONG_MIN"
#    endif

#    define SIZEOF_INT        4
#    define SIZEOF_LONG       8
Armin Rigo's avatar
Armin Rigo committed
86
#    define SIZEOF_SIGNED     8
87
88
89
90
91
92
93
94
95
96
97
98
99
#    define SIZEOF_LONG_LONG  8

/******************** Win-64 support ********************/
#  else
#    if LONG_MAX != 2147483647L
#      error "error in LONG_MAX (64-bit sources but incompatible compiler?)"
#    endif
#    if LONG_MIN != -2147483647L-1L
#      error "unsupported value for LONG_MIN"
#    endif

#    define SIZEOF_INT        4
#    define SIZEOF_LONG       4
Armin Rigo's avatar
Armin Rigo committed
100
#    define SIZEOF_SIGNED     8
101
#    define SIZEOF_LONG_LONG  8
Armin Rigo's avatar
Armin Rigo committed
102

103
#  endif
Armin Rigo's avatar
Armin Rigo committed
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119

#endif

/********************************************************/

#if ((-1) >> 1) > 0
#  define Py_ARITHMETIC_RIGHT_SHIFT(TYPE, I, J) \
	  ((I) < 0 ? -1-((-1-(I)) >> (J)) : (I) >> (J))
#elif ((-1) >> 1) == -1
#  define Py_ARITHMETIC_RIGHT_SHIFT(TYPE, I, J) ((I) >> (J))
#else
#  error "uh? strange result"
#endif

#define HAVE_LONG_LONG 1
#define Py_HUGE_VAL HUGE_VAL
Armin Rigo's avatar
Armin Rigo committed
120
121

#ifdef _WIN32
122
#ifndef MS_WINDOWS
Armin Rigo's avatar
Armin Rigo committed
123
124
#  define MS_WINDOWS    /* a synonym */
#endif
125
#endif
126
127
128
129

/* stringify a constant */
#define Py_XSTR(x)   #x
#define Py_STR(x)  Py_XSTR(x)