Show More
@@ -338,7 +338,6 b' static PyObject *bdiff(PyObject *self, P' | |||||
338 | PyObject *result = NULL; |
|
338 | PyObject *result = NULL; | |
339 | struct line *al, *bl; |
|
339 | struct line *al, *bl; | |
340 | struct hunk l, *h; |
|
340 | struct hunk l, *h; | |
341 | uint32_t encode[3]; |
|
|||
342 | int an, bn, len = 0, la, lb, count; |
|
341 | int an, bn, len = 0, la, lb, count; | |
343 |
|
342 | |||
344 | if (!PyArg_ParseTuple(args, "s#s#:bdiff", &sa, &la, &sb, &lb)) |
|
343 | if (!PyArg_ParseTuple(args, "s#s#:bdiff", &sa, &la, &sb, &lb)) | |
@@ -375,10 +374,9 b' static PyObject *bdiff(PyObject *self, P' | |||||
375 | for (h = l.next; h; h = h->next) { |
|
374 | for (h = l.next; h; h = h->next) { | |
376 | if (h->a1 != la || h->b1 != lb) { |
|
375 | if (h->a1 != la || h->b1 != lb) { | |
377 | len = bl[h->b1].l - bl[lb].l; |
|
376 | len = bl[h->b1].l - bl[lb].l; | |
378 |
|
|
377 | putbe32(al[la].l - al->l, rb); | |
379 |
|
|
378 | putbe32(al[h->a1].l - al->l, rb + 4); | |
380 | encode[2] = htonl(len); |
|
379 | putbe32(len, rb + 8); | |
381 | memcpy(rb, encode, 12); |
|
|||
382 | memcpy(rb + 12, bl[lb].l, len); |
|
380 | memcpy(rb + 12, bl[lb].l, len); | |
383 | rb += 12 + len; |
|
381 | rb += 12 + len; | |
384 | } |
|
382 | } |
@@ -202,7 +202,6 b' static struct flist *decode(const char *' | |||||
202 | struct flist *l; |
|
202 | struct flist *l; | |
203 | struct frag *lt; |
|
203 | struct frag *lt; | |
204 | const char *data = bin + 12, *end = bin + len; |
|
204 | const char *data = bin + 12, *end = bin + len; | |
205 | uint32_t decode[3]; /* for dealing with alignment issues */ |
|
|||
206 |
|
205 | |||
207 | /* assume worst case size, we won't have many of these lists */ |
|
206 | /* assume worst case size, we won't have many of these lists */ | |
208 | l = lalloc(len / 12); |
|
207 | l = lalloc(len / 12); | |
@@ -212,10 +211,9 b' static struct flist *decode(const char *' | |||||
212 | lt = l->tail; |
|
211 | lt = l->tail; | |
213 |
|
212 | |||
214 | while (data <= end) { |
|
213 | while (data <= end) { | |
215 | memcpy(decode, bin, 12); |
|
214 | lt->start = getbe32(bin); | |
216 | lt->start = ntohl(decode[0]); |
|
215 | lt->end = getbe32(bin + 4); | |
217 | lt->end = ntohl(decode[1]); |
|
216 | lt->len = getbe32(bin + 8); | |
218 | lt->len = ntohl(decode[2]); |
|
|||
219 | if (lt->start > lt->end) |
|
217 | if (lt->start > lt->end) | |
220 | break; /* sanity check */ |
|
218 | break; /* sanity check */ | |
221 | bin = data + lt->len; |
|
219 | bin = data + lt->len; | |
@@ -361,7 +359,6 b' patchedsize(PyObject *self, PyObject *ar' | |||||
361 | long orig, start, end, len, outlen = 0, last = 0; |
|
359 | long orig, start, end, len, outlen = 0, last = 0; | |
362 | int patchlen; |
|
360 | int patchlen; | |
363 | char *bin, *binend, *data; |
|
361 | char *bin, *binend, *data; | |
364 | uint32_t decode[3]; /* for dealing with alignment issues */ |
|
|||
365 |
|
362 | |||
366 | if (!PyArg_ParseTuple(args, "ls#", &orig, &bin, &patchlen)) |
|
363 | if (!PyArg_ParseTuple(args, "ls#", &orig, &bin, &patchlen)) | |
367 | return NULL; |
|
364 | return NULL; | |
@@ -370,10 +367,9 b' patchedsize(PyObject *self, PyObject *ar' | |||||
370 | data = bin + 12; |
|
367 | data = bin + 12; | |
371 |
|
368 | |||
372 | while (data <= binend) { |
|
369 | while (data <= binend) { | |
373 | memcpy(decode, bin, 12); |
|
370 | start = getbe32(bin); | |
374 | start = ntohl(decode[0]); |
|
371 | end = getbe32(bin + 4); | |
375 | end = ntohl(decode[1]); |
|
372 | len = getbe32(bin + 8); | |
376 | len = ntohl(decode[2]); |
|
|||
377 | if (start > end) |
|
373 | if (start > end) | |
378 | break; /* sanity check */ |
|
374 | break; /* sanity check */ | |
379 | bin = data + len; |
|
375 | bin = data + len; |
@@ -143,7 +143,6 b' static PyObject *parse_dirstate(PyObject' | |||||
143 | int state, mode, size, mtime; |
|
143 | int state, mode, size, mtime; | |
144 | unsigned int flen; |
|
144 | unsigned int flen; | |
145 | int len; |
|
145 | int len; | |
146 | uint32_t decode[4]; /* for alignment */ |
|
|||
147 |
|
146 | |||
148 | if (!PyArg_ParseTuple(args, "O!O!s#:parse_dirstate", |
|
147 | if (!PyArg_ParseTuple(args, "O!O!s#:parse_dirstate", | |
149 | &PyDict_Type, &dmap, |
|
148 | &PyDict_Type, &dmap, | |
@@ -166,11 +165,10 b' static PyObject *parse_dirstate(PyObject' | |||||
166 | while (cur < end - 17) { |
|
165 | while (cur < end - 17) { | |
167 | /* unpack header */ |
|
166 | /* unpack header */ | |
168 | state = *cur; |
|
167 | state = *cur; | |
169 | memcpy(decode, cur + 1, 16); |
|
168 | mode = getbe32(cur + 1); | |
170 | mode = ntohl(decode[0]); |
|
169 | size = getbe32(cur + 5); | |
171 | size = ntohl(decode[1]); |
|
170 | mtime = getbe32(cur + 9); | |
172 | mtime = ntohl(decode[2]); |
|
171 | flen = getbe32(cur + 13); | |
173 | flen = ntohl(decode[3]); |
|
|||
174 | cur += 17; |
|
172 | cur += 17; | |
175 | if (cur + flen > end || cur + flen < cur) { |
|
173 | if (cur + flen > end || cur + flen < cur) { | |
176 | PyErr_SetString(PyExc_ValueError, "overflow in dirstate"); |
|
174 | PyErr_SetString(PyExc_ValueError, "overflow in dirstate"); | |
@@ -308,7 +306,6 b' static const char *index_deref(indexObje' | |||||
308 | */ |
|
306 | */ | |
309 | static PyObject *index_get(indexObject *self, Py_ssize_t pos) |
|
307 | static PyObject *index_get(indexObject *self, Py_ssize_t pos) | |
310 | { |
|
308 | { | |
311 | uint32_t decode[8]; /* to enforce alignment with inline data */ |
|
|||
312 | uint64_t offset_flags; |
|
309 | uint64_t offset_flags; | |
313 | int comp_len, uncomp_len, base_rev, link_rev, parent_1, parent_2; |
|
310 | int comp_len, uncomp_len, base_rev, link_rev, parent_1, parent_2; | |
314 | const char *c_node_id; |
|
311 | const char *c_node_id; | |
@@ -351,22 +348,20 b' static PyObject *index_get(indexObject *' | |||||
351 | if (data == NULL) |
|
348 | if (data == NULL) | |
352 | return NULL; |
|
349 | return NULL; | |
353 |
|
350 | |||
354 | memcpy(decode, data, 8 * sizeof(uint32_t)); |
|
351 | offset_flags = getbe32(data + 4); | |
355 |
|
||||
356 | offset_flags = ntohl(decode[1]); |
|
|||
357 | if (pos == 0) /* mask out version number for the first entry */ |
|
352 | if (pos == 0) /* mask out version number for the first entry */ | |
358 | offset_flags &= 0xFFFF; |
|
353 | offset_flags &= 0xFFFF; | |
359 | else { |
|
354 | else { | |
360 |
uint32_t offset_high = |
|
355 | uint32_t offset_high = getbe32(data); | |
361 | offset_flags |= ((uint64_t)offset_high) << 32; |
|
356 | offset_flags |= ((uint64_t)offset_high) << 32; | |
362 | } |
|
357 | } | |
363 |
|
358 | |||
364 | comp_len = ntohl(decode[2]); |
|
359 | comp_len = getbe32(data + 8); | |
365 | uncomp_len = ntohl(decode[3]); |
|
360 | uncomp_len = getbe32(data + 12); | |
366 | base_rev = ntohl(decode[4]); |
|
361 | base_rev = getbe32(data + 16); | |
367 | link_rev = ntohl(decode[5]); |
|
362 | link_rev = getbe32(data + 20); | |
368 | parent_1 = ntohl(decode[6]); |
|
363 | parent_1 = getbe32(data + 24); | |
369 | parent_2 = ntohl(decode[7]); |
|
364 | parent_2 = getbe32(data + 28); | |
370 | c_node_id = data + 32; |
|
365 | c_node_id = data + 32; | |
371 |
|
366 | |||
372 | entry = Py_BuildValue(tuple_format, offset_flags, comp_len, |
|
367 | entry = Py_BuildValue(tuple_format, offset_flags, comp_len, | |
@@ -940,8 +935,8 b' static long inline_scan(indexObject *sel' | |||||
940 | uint32_t comp_len; |
|
935 | uint32_t comp_len; | |
941 | const char *old_data; |
|
936 | const char *old_data; | |
942 | /* 3rd element of header is length of compressed inline data */ |
|
937 | /* 3rd element of header is length of compressed inline data */ | |
943 | memcpy(&comp_len, data + 8, sizeof(uint32_t)); |
|
938 | comp_len = getbe32(data + 8); | |
944 |
incr = hdrsize + |
|
939 | incr = hdrsize + comp_len; | |
945 | if (incr < hdrsize) |
|
940 | if (incr < hdrsize) | |
946 | break; |
|
941 | break; | |
947 | if (offsets) |
|
942 | if (offsets) |
@@ -125,13 +125,6 b' typedef unsigned __int64 uint64_t;' | |||||
125 | #else |
|
125 | #else | |
126 | #include <stdint.h> |
|
126 | #include <stdint.h> | |
127 | #endif |
|
127 | #endif | |
128 | static uint32_t ntohl(uint32_t x) |
|
|||
129 | { |
|
|||
130 | return ((x & 0x000000ffUL) << 24) | |
|
|||
131 | ((x & 0x0000ff00UL) << 8) | |
|
|||
132 | ((x & 0x00ff0000UL) >> 8) | |
|
|||
133 | ((x & 0xff000000UL) >> 24); |
|
|||
134 | } |
|
|||
135 | #else |
|
128 | #else | |
136 | /* not windows */ |
|
129 | /* not windows */ | |
137 | #include <sys/types.h> |
|
130 | #include <sys/types.h> | |
@@ -151,4 +144,22 b' static uint32_t ntohl(uint32_t x)' | |||||
151 | #define inline __inline |
|
144 | #define inline __inline | |
152 | #endif |
|
145 | #endif | |
153 |
|
146 | |||
|
147 | static inline uint32_t getbe32(const char *c) | |||
|
148 | { | |||
|
149 | const unsigned char *d = (const unsigned char *)c; | |||
|
150 | ||||
|
151 | return ((d[0] << 24) | | |||
|
152 | (d[1] << 16) | | |||
|
153 | (d[2] << 8) | | |||
|
154 | (d[3])); | |||
|
155 | } | |||
|
156 | ||||
|
157 | static inline void putbe32(uint32_t x, char *c) | |||
|
158 | { | |||
|
159 | c[0] = (x >> 24) & 0xff; | |||
|
160 | c[1] = (x >> 16) & 0xff; | |||
|
161 | c[2] = (x >> 8) & 0xff; | |||
|
162 | c[3] = (x) & 0xff; | |||
|
163 | } | |||
|
164 | ||||
154 | #endif /* _HG_UTIL_H_ */ |
|
165 | #endif /* _HG_UTIL_H_ */ |
General Comments 0
You need to be logged in to leave comments.
Login now