##// END OF EJS Templates
util.h: kill no longer needed definitions for Python < 2.6...
Adrian Buehlmann -
r25076:14bf7679 default
parent child Browse files
Show More
@@ -1,213 +1,169 b''
1 1 /*
2 2 util.h - utility functions for interfacing with the various python APIs.
3 3
4 4 This software may be used and distributed according to the terms of
5 5 the GNU General Public License, incorporated herein by reference.
6 6 */
7 7
8 8 #ifndef _HG_UTIL_H_
9 9 #define _HG_UTIL_H_
10 10
11 11 #if PY_MAJOR_VERSION >= 3
12 12
13 13 #define IS_PY3K
14 14 #define PyInt_FromLong PyLong_FromLong
15 15 #define PyInt_AsLong PyLong_AsLong
16 16
17 17 /*
18 18 Mapping of some of the python < 2.x PyString* functions to py3k's PyUnicode.
19 19
20 20 The commented names below represent those that are present in the PyBytes
21 21 definitions for python < 2.6 (below in this file) that don't have a direct
22 22 implementation.
23 23 */
24 24
25 25 #define PyStringObject PyUnicodeObject
26 26 #define PyString_Type PyUnicode_Type
27 27
28 28 #define PyString_Check PyUnicode_Check
29 29 #define PyString_CheckExact PyUnicode_CheckExact
30 30 #define PyString_CHECK_INTERNED PyUnicode_CHECK_INTERNED
31 31 #define PyString_AS_STRING PyUnicode_AsLatin1String
32 32 #define PyString_GET_SIZE PyUnicode_GET_SIZE
33 33
34 34 #define PyString_FromStringAndSize PyUnicode_FromStringAndSize
35 35 #define PyString_FromString PyUnicode_FromString
36 36 #define PyString_FromFormatV PyUnicode_FromFormatV
37 37 #define PyString_FromFormat PyUnicode_FromFormat
38 38 /* #define PyString_Size PyUnicode_GET_SIZE */
39 39 /* #define PyString_AsString */
40 40 /* #define PyString_Repr */
41 41 #define PyString_Concat PyUnicode_Concat
42 42 #define PyString_ConcatAndDel PyUnicode_AppendAndDel
43 43 #define _PyString_Resize PyUnicode_Resize
44 44 /* #define _PyString_Eq */
45 45 #define PyString_Format PyUnicode_Format
46 46 /* #define _PyString_FormatLong */
47 47 /* #define PyString_DecodeEscape */
48 48 #define _PyString_Join PyUnicode_Join
49 49 #define PyString_Decode PyUnicode_Decode
50 50 #define PyString_Encode PyUnicode_Encode
51 51 #define PyString_AsEncodedObject PyUnicode_AsEncodedObject
52 52 #define PyString_AsEncodedString PyUnicode_AsEncodedString
53 53 #define PyString_AsDecodedObject PyUnicode_AsDecodedObject
54 54 #define PyString_AsDecodedString PyUnicode_AsDecodedUnicode
55 55 /* #define PyString_AsStringAndSize */
56 56 #define _PyString_InsertThousandsGrouping _PyUnicode_InsertThousandsGrouping
57 57
58 58 #endif /* PY_MAJOR_VERSION */
59 59
60 /* Backports from 2.6 */
61 #if PY_VERSION_HEX < 0x02060000
62
63 #define Py_TYPE(ob) (ob)->ob_type
64 #define Py_SIZE(ob) (ob)->ob_size
65 #define PyVarObject_HEAD_INIT(type, size) PyObject_HEAD_INIT(type) size,
66
67 /* Shamelessly stolen from bytesobject.h */
68 #define PyBytesObject PyStringObject
69 #define PyBytes_Type PyString_Type
70
71 #define PyBytes_Check PyString_Check
72 #define PyBytes_CheckExact PyString_CheckExact
73 #define PyBytes_CHECK_INTERNED PyString_CHECK_INTERNED
74 #define PyBytes_AS_STRING PyString_AS_STRING
75 #define PyBytes_GET_SIZE PyString_GET_SIZE
76 #define Py_TPFLAGS_BYTES_SUBCLASS Py_TPFLAGS_STRING_SUBCLASS
77
78 #define PyBytes_FromStringAndSize PyString_FromStringAndSize
79 #define PyBytes_FromString PyString_FromString
80 #define PyBytes_FromFormatV PyString_FromFormatV
81 #define PyBytes_FromFormat PyString_FromFormat
82 #define PyBytes_Size PyString_Size
83 #define PyBytes_AsString PyString_AsString
84 #define PyBytes_Repr PyString_Repr
85 #define PyBytes_Concat PyString_Concat
86 #define PyBytes_ConcatAndDel PyString_ConcatAndDel
87 #define _PyBytes_Resize _PyString_Resize
88 #define _PyBytes_Eq _PyString_Eq
89 #define PyBytes_Format PyString_Format
90 #define _PyBytes_FormatLong _PyString_FormatLong
91 #define PyBytes_DecodeEscape PyString_DecodeEscape
92 #define _PyBytes_Join _PyString_Join
93 #define PyBytes_Decode PyString_Decode
94 #define PyBytes_Encode PyString_Encode
95 #define PyBytes_AsEncodedObject PyString_AsEncodedObject
96 #define PyBytes_AsEncodedString PyString_AsEncodedString
97 #define PyBytes_AsDecodedObject PyString_AsDecodedObject
98 #define PyBytes_AsDecodedString PyString_AsDecodedString
99 #define PyBytes_AsStringAndSize PyString_AsStringAndSize
100 #define _PyBytes_InsertThousandsGrouping _PyString_InsertThousandsGrouping
101
102 #endif /* PY_VERSION_HEX */
103
104 60 #ifdef _WIN32
105 61 #ifdef _MSC_VER
106 62 /* msvc 6.0 has problems */
107 63 #define inline __inline
108 64 typedef signed char int8_t;
109 65 typedef short int16_t;
110 66 typedef long int32_t;
111 67 typedef __int64 int64_t;
112 68 typedef unsigned char uint8_t;
113 69 typedef unsigned short uint16_t;
114 70 typedef unsigned long uint32_t;
115 71 typedef unsigned __int64 uint64_t;
116 72 #else
117 73 #include <stdint.h>
118 74 #endif
119 75 #else
120 76 /* not windows */
121 77 #include <sys/types.h>
122 78 #if defined __BEOS__ && !defined __HAIKU__
123 79 #include <ByteOrder.h>
124 80 #else
125 81 #include <arpa/inet.h>
126 82 #endif
127 83 #include <inttypes.h>
128 84 #endif
129 85
130 86 #if defined __hpux || defined __SUNPRO_C || defined _AIX
131 87 #define inline
132 88 #endif
133 89
134 90 #ifdef __linux
135 91 #define inline __inline
136 92 #endif
137 93
138 94 typedef struct {
139 95 PyObject_HEAD
140 96 char state;
141 97 int mode;
142 98 int size;
143 99 int mtime;
144 100 } dirstateTupleObject;
145 101
146 102 extern PyTypeObject dirstateTupleType;
147 103 #define dirstate_tuple_check(op) (Py_TYPE(op) == &dirstateTupleType)
148 104
149 105 static inline uint32_t getbe32(const char *c)
150 106 {
151 107 const unsigned char *d = (const unsigned char *)c;
152 108
153 109 return ((d[0] << 24) |
154 110 (d[1] << 16) |
155 111 (d[2] << 8) |
156 112 (d[3]));
157 113 }
158 114
159 115 static inline int16_t getbeint16(const char *c)
160 116 {
161 117 const unsigned char *d = (const unsigned char *)c;
162 118
163 119 return ((d[0] << 8) |
164 120 (d[1]));
165 121 }
166 122
167 123 static inline uint16_t getbeuint16(const char *c)
168 124 {
169 125 const unsigned char *d = (const unsigned char *)c;
170 126
171 127 return ((d[0] << 8) |
172 128 (d[1]));
173 129 }
174 130
175 131 static inline void putbe32(uint32_t x, char *c)
176 132 {
177 133 c[0] = (x >> 24) & 0xff;
178 134 c[1] = (x >> 16) & 0xff;
179 135 c[2] = (x >> 8) & 0xff;
180 136 c[3] = (x) & 0xff;
181 137 }
182 138
183 139 static inline double getbefloat64(const char *c)
184 140 {
185 141 const unsigned char *d = (const unsigned char *)c;
186 142 double ret;
187 143 int i;
188 144 uint64_t t = 0;
189 145 for (i = 0; i < 8; i++) {
190 146 t = (t<<8) + d[i];
191 147 }
192 148 memcpy(&ret, &t, sizeof(t));
193 149 return ret;
194 150 }
195 151
196 152 /* This should be kept in sync with normcasespecs in encoding.py. */
197 153 enum normcase_spec {
198 154 NORMCASE_LOWER = -1,
199 155 NORMCASE_UPPER = 1,
200 156 NORMCASE_OTHER = 0
201 157 };
202 158
203 159 #define MIN(a, b) (((a)<(b))?(a):(b))
204 160 /* VC9 doesn't include bool and lacks stdbool.h based on my searching */
205 161 #if defined(_MSC_VER) || __STDC_VERSION__ < 199901L
206 162 #define true 1
207 163 #define false 0
208 164 typedef unsigned char bool;
209 165 #else
210 166 #include <stdbool.h>
211 167 #endif
212 168
213 169 #endif /* _HG_UTIL_H_ */
General Comments 0
You need to be logged in to leave comments. Login now