Show More
@@ -24,7 +24,6 b'' | |||||
24 | #define PyInt_Check PyLong_Check |
|
24 | #define PyInt_Check PyLong_Check | |
25 | #define PyInt_FromLong PyLong_FromLong |
|
25 | #define PyInt_FromLong PyLong_FromLong | |
26 | #define PyInt_FromSsize_t PyLong_FromSsize_t |
|
26 | #define PyInt_FromSsize_t PyLong_FromSsize_t | |
27 | #define PyInt_AS_LONG PyLong_AS_LONG |
|
|||
28 | #define PyInt_AsLong PyLong_AsLong |
|
27 | #define PyInt_AsLong PyLong_AsLong | |
29 | #endif |
|
28 | #endif | |
30 |
|
29 | |||
@@ -161,10 +160,17 b' static inline int index_get_parents(inde' | |||||
161 | int maxrev) |
|
160 | int maxrev) | |
162 | { |
|
161 | { | |
163 | if (rev >= self->length) { |
|
162 | if (rev >= self->length) { | |
|
163 | long tmp; | |||
164 | PyObject *tuple = |
|
164 | PyObject *tuple = | |
165 | PyList_GET_ITEM(self->added, rev - self->length); |
|
165 | PyList_GET_ITEM(self->added, rev - self->length); | |
166 |
|
|
166 | if (!pylong_to_long(PyTuple_GET_ITEM(tuple, 5), &tmp)) { | |
167 | ps[1] = (int)PyInt_AS_LONG(PyTuple_GET_ITEM(tuple, 6)); |
|
167 | return -1; | |
|
168 | } | |||
|
169 | ps[0] = (int)tmp; | |||
|
170 | if (!pylong_to_long(PyTuple_GET_ITEM(tuple, 6), &tmp)) { | |||
|
171 | return -1; | |||
|
172 | } | |||
|
173 | ps[1] = (int)tmp; | |||
168 | } else { |
|
174 | } else { | |
169 | const char *data = index_deref(self, rev); |
|
175 | const char *data = index_deref(self, rev); | |
170 | ps[0] = getbe32(data + 24); |
|
176 | ps[0] = getbe32(data + 24); | |
@@ -464,7 +470,10 b' static Py_ssize_t add_roots_get_min(inde' | |||||
464 | if (iter == NULL) |
|
470 | if (iter == NULL) | |
465 | return -2; |
|
471 | return -2; | |
466 | while ((iter_item = PyIter_Next(iter))) { |
|
472 | while ((iter_item = PyIter_Next(iter))) { | |
467 | iter_item_long = PyInt_AS_LONG(iter_item); |
|
473 | if (!pylong_to_long(iter_item, &iter_item_long)) { | |
|
474 | Py_DECREF(iter_item); | |||
|
475 | return -2; | |||
|
476 | } | |||
468 | Py_DECREF(iter_item); |
|
477 | Py_DECREF(iter_item); | |
469 | if (iter_item_long < min_idx) |
|
478 | if (iter_item_long < min_idx) | |
470 | min_idx = iter_item_long; |
|
479 | min_idx = iter_item_long; | |
@@ -853,7 +862,11 b' static inline int index_baserev(indexObj' | |||||
853 | if (rev >= self->length) { |
|
862 | if (rev >= self->length) { | |
854 | PyObject *tuple = |
|
863 | PyObject *tuple = | |
855 | PyList_GET_ITEM(self->added, rev - self->length); |
|
864 | PyList_GET_ITEM(self->added, rev - self->length); | |
856 | return (int)PyInt_AS_LONG(PyTuple_GET_ITEM(tuple, 3)); |
|
865 | long ret; | |
|
866 | if (!pylong_to_long(PyTuple_GET_ITEM(tuple, 3), &ret)) { | |||
|
867 | return -2; | |||
|
868 | } | |||
|
869 | return (int)ret; | |||
857 | } else { |
|
870 | } else { | |
858 | data = index_deref(self, rev); |
|
871 | data = index_deref(self, rev); | |
859 | if (data == NULL) { |
|
872 | if (data == NULL) { | |
@@ -1384,8 +1397,13 b' static PyObject *index_getitem(indexObje' | |||||
1384 | char *node; |
|
1397 | char *node; | |
1385 | int rev; |
|
1398 | int rev; | |
1386 |
|
1399 | |||
1387 | if (PyInt_Check(value)) |
|
1400 | if (PyInt_Check(value)) { | |
1388 | return index_get(self, PyInt_AS_LONG(value)); |
|
1401 | long idx; | |
|
1402 | if (!pylong_to_long(value, &idx)) { | |||
|
1403 | return NULL; | |||
|
1404 | } | |||
|
1405 | return index_get(self, idx); | |||
|
1406 | } | |||
1389 |
|
1407 | |||
1390 | if (node_check(value, &node) == -1) |
|
1408 | if (node_check(value, &node) == -1) | |
1391 | return NULL; |
|
1409 | return NULL; | |
@@ -1516,7 +1534,10 b' static int index_contains(indexObject *s' | |||||
1516 | char *node; |
|
1534 | char *node; | |
1517 |
|
1535 | |||
1518 | if (PyInt_Check(value)) { |
|
1536 | if (PyInt_Check(value)) { | |
1519 | long rev = PyInt_AS_LONG(value); |
|
1537 | long rev; | |
|
1538 | if (!pylong_to_long(value, &rev)) { | |||
|
1539 | return -1; | |||
|
1540 | } | |||
1520 | return rev >= -1 && rev < index_length(self); |
|
1541 | return rev >= -1 && rev < index_length(self); | |
1521 | } |
|
1542 | } | |
1522 |
|
1543 | |||
@@ -2404,10 +2425,12 b' static PyObject *rustla_next(rustlazyanc' | |||||
2404 |
|
2425 | |||
2405 | static int rustla_contains(rustlazyancestorsObject *self, PyObject *rev) |
|
2426 | static int rustla_contains(rustlazyancestorsObject *self, PyObject *rev) | |
2406 | { |
|
2427 | { | |
2407 | if (!(PyInt_Check(rev))) { |
|
2428 | long lrev; | |
|
2429 | if (!pylong_to_long(rev, &lrev)) { | |||
|
2430 | PyErr_Clear(); | |||
2408 | return 0; |
|
2431 | return 0; | |
2409 | } |
|
2432 | } | |
2410 |
return rustlazyancestors_contains(self->iter, |
|
2433 | return rustlazyancestors_contains(self->iter, lrev); | |
2411 | } |
|
2434 | } | |
2412 |
|
2435 | |||
2413 | static PySequenceMethods rustla_sequence_methods = { |
|
2436 | static PySequenceMethods rustla_sequence_methods = { |
@@ -58,4 +58,17 b' static inline PyObject *_dict_new_presiz' | |||||
58 | return _PyDict_NewPresized(((1 + expected_size) / 2) * 3); |
|
58 | return _PyDict_NewPresized(((1 + expected_size) / 2) * 3); | |
59 | } |
|
59 | } | |
60 |
|
60 | |||
|
61 | /* Convert a PyInt or PyLong to a long. Returns false if there is an | |||
|
62 | error, in which case an exception will already have been set. */ | |||
|
63 | static inline bool pylong_to_long(PyObject *pylong, long *out) | |||
|
64 | { | |||
|
65 | *out = PyLong_AsLong(pylong); | |||
|
66 | /* Fast path to avoid hitting PyErr_Occurred if the value was obviously | |||
|
67 | * not an error. */ | |||
|
68 | if (*out != -1) { | |||
|
69 | return true; | |||
|
70 | } | |||
|
71 | return PyErr_Occurred() == NULL; | |||
|
72 | } | |||
|
73 | ||||
61 | #endif /* _HG_UTIL_H_ */ |
|
74 | #endif /* _HG_UTIL_H_ */ |
General Comments 0
You need to be logged in to leave comments.
Login now