##// END OF EJS Templates
revlog: replace PyInt_AS_LONG with a more portable helper function...
Augie Fackler -
r40634:fa331960 default
parent child Browse files
Show More
@@ -24,7 +24,6 b''
24 24 #define PyInt_Check PyLong_Check
25 25 #define PyInt_FromLong PyLong_FromLong
26 26 #define PyInt_FromSsize_t PyLong_FromSsize_t
27 #define PyInt_AS_LONG PyLong_AS_LONG
28 27 #define PyInt_AsLong PyLong_AsLong
29 28 #endif
30 29
@@ -161,10 +160,17 b' static inline int index_get_parents(inde'
161 160 int maxrev)
162 161 {
163 162 if (rev >= self->length) {
163 long tmp;
164 164 PyObject *tuple =
165 165 PyList_GET_ITEM(self->added, rev - self->length);
166 ps[0] = (int)PyInt_AS_LONG(PyTuple_GET_ITEM(tuple, 5));
167 ps[1] = (int)PyInt_AS_LONG(PyTuple_GET_ITEM(tuple, 6));
166 if (!pylong_to_long(PyTuple_GET_ITEM(tuple, 5), &tmp)) {
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 174 } else {
169 175 const char *data = index_deref(self, rev);
170 176 ps[0] = getbe32(data + 24);
@@ -464,7 +470,10 b' static Py_ssize_t add_roots_get_min(inde'
464 470 if (iter == NULL)
465 471 return -2;
466 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 477 Py_DECREF(iter_item);
469 478 if (iter_item_long < min_idx)
470 479 min_idx = iter_item_long;
@@ -853,7 +862,11 b' static inline int index_baserev(indexObj'
853 862 if (rev >= self->length) {
854 863 PyObject *tuple =
855 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 870 } else {
858 871 data = index_deref(self, rev);
859 872 if (data == NULL) {
@@ -1384,8 +1397,13 b' static PyObject *index_getitem(indexObje'
1384 1397 char *node;
1385 1398 int rev;
1386 1399
1387 if (PyInt_Check(value))
1388 return index_get(self, PyInt_AS_LONG(value));
1400 if (PyInt_Check(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 1408 if (node_check(value, &node) == -1)
1391 1409 return NULL;
@@ -1516,7 +1534,10 b' static int index_contains(indexObject *s'
1516 1534 char *node;
1517 1535
1518 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 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 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 2431 return 0;
2409 2432 }
2410 return rustlazyancestors_contains(self->iter, PyInt_AS_LONG(rev));
2433 return rustlazyancestors_contains(self->iter, lrev);
2411 2434 }
2412 2435
2413 2436 static PySequenceMethods rustla_sequence_methods = {
@@ -58,4 +58,17 b' static inline PyObject *_dict_new_presiz'
58 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 74 #endif /* _HG_UTIL_H_ */
General Comments 0
You need to be logged in to leave comments. Login now