Mercurial > hg
comparison mercurial/util.h @ 29444:284d742e5611
internals: move the bitmanipulation routines into its own file
This is to allow more flexibility with the C sources -- now the
bitmanipulation routines can be safely imported without importing Python.h
author | Maciej Fijalkowski <fijall@gmail.com> |
---|---|
date | Mon, 06 Jun 2016 13:08:13 +0200 |
parents | 14bf7679fb68 |
children | d576b7394646 |
comparison
equal
deleted
inserted
replaced
29443:cf092a3d202a | 29444:284d742e5611 |
---|---|
5 the GNU General Public License, incorporated herein by reference. | 5 the GNU General Public License, incorporated herein by reference. |
6 */ | 6 */ |
7 | 7 |
8 #ifndef _HG_UTIL_H_ | 8 #ifndef _HG_UTIL_H_ |
9 #define _HG_UTIL_H_ | 9 #define _HG_UTIL_H_ |
10 | |
11 #include "compat.h" | |
10 | 12 |
11 #if PY_MAJOR_VERSION >= 3 | 13 #if PY_MAJOR_VERSION >= 3 |
12 | 14 |
13 #define IS_PY3K | 15 #define IS_PY3K |
14 #define PyInt_FromLong PyLong_FromLong | 16 #define PyInt_FromLong PyLong_FromLong |
55 /* #define PyString_AsStringAndSize */ | 57 /* #define PyString_AsStringAndSize */ |
56 #define _PyString_InsertThousandsGrouping _PyUnicode_InsertThousandsGrouping | 58 #define _PyString_InsertThousandsGrouping _PyUnicode_InsertThousandsGrouping |
57 | 59 |
58 #endif /* PY_MAJOR_VERSION */ | 60 #endif /* PY_MAJOR_VERSION */ |
59 | 61 |
60 #ifdef _WIN32 | |
61 #ifdef _MSC_VER | |
62 /* msvc 6.0 has problems */ | |
63 #define inline __inline | |
64 typedef signed char int8_t; | |
65 typedef short int16_t; | |
66 typedef long int32_t; | |
67 typedef __int64 int64_t; | |
68 typedef unsigned char uint8_t; | |
69 typedef unsigned short uint16_t; | |
70 typedef unsigned long uint32_t; | |
71 typedef unsigned __int64 uint64_t; | |
72 #else | |
73 #include <stdint.h> | |
74 #endif | |
75 #else | |
76 /* not windows */ | |
77 #include <sys/types.h> | |
78 #if defined __BEOS__ && !defined __HAIKU__ | |
79 #include <ByteOrder.h> | |
80 #else | |
81 #include <arpa/inet.h> | |
82 #endif | |
83 #include <inttypes.h> | |
84 #endif | |
85 | |
86 #if defined __hpux || defined __SUNPRO_C || defined _AIX | |
87 #define inline | |
88 #endif | |
89 | |
90 #ifdef __linux | |
91 #define inline __inline | |
92 #endif | |
93 | |
94 typedef struct { | 62 typedef struct { |
95 PyObject_HEAD | 63 PyObject_HEAD |
96 char state; | 64 char state; |
97 int mode; | 65 int mode; |
98 int size; | 66 int size; |
99 int mtime; | 67 int mtime; |
100 } dirstateTupleObject; | 68 } dirstateTupleObject; |
101 | 69 |
102 extern PyTypeObject dirstateTupleType; | 70 extern PyTypeObject dirstateTupleType; |
103 #define dirstate_tuple_check(op) (Py_TYPE(op) == &dirstateTupleType) | 71 #define dirstate_tuple_check(op) (Py_TYPE(op) == &dirstateTupleType) |
104 | |
105 static inline uint32_t getbe32(const char *c) | |
106 { | |
107 const unsigned char *d = (const unsigned char *)c; | |
108 | |
109 return ((d[0] << 24) | | |
110 (d[1] << 16) | | |
111 (d[2] << 8) | | |
112 (d[3])); | |
113 } | |
114 | |
115 static inline int16_t getbeint16(const char *c) | |
116 { | |
117 const unsigned char *d = (const unsigned char *)c; | |
118 | |
119 return ((d[0] << 8) | | |
120 (d[1])); | |
121 } | |
122 | |
123 static inline uint16_t getbeuint16(const char *c) | |
124 { | |
125 const unsigned char *d = (const unsigned char *)c; | |
126 | |
127 return ((d[0] << 8) | | |
128 (d[1])); | |
129 } | |
130 | |
131 static inline void putbe32(uint32_t x, char *c) | |
132 { | |
133 c[0] = (x >> 24) & 0xff; | |
134 c[1] = (x >> 16) & 0xff; | |
135 c[2] = (x >> 8) & 0xff; | |
136 c[3] = (x) & 0xff; | |
137 } | |
138 | |
139 static inline double getbefloat64(const char *c) | |
140 { | |
141 const unsigned char *d = (const unsigned char *)c; | |
142 double ret; | |
143 int i; | |
144 uint64_t t = 0; | |
145 for (i = 0; i < 8; i++) { | |
146 t = (t<<8) + d[i]; | |
147 } | |
148 memcpy(&ret, &t, sizeof(t)); | |
149 return ret; | |
150 } | |
151 | 72 |
152 /* This should be kept in sync with normcasespecs in encoding.py. */ | 73 /* This should be kept in sync with normcasespecs in encoding.py. */ |
153 enum normcase_spec { | 74 enum normcase_spec { |
154 NORMCASE_LOWER = -1, | 75 NORMCASE_LOWER = -1, |
155 NORMCASE_UPPER = 1, | 76 NORMCASE_UPPER = 1, |