##// END OF EJS Templates
cext: use PyLong symbols...
Gregory Szorc -
r49673:13d705c9 default
parent child Browse files
Show More
@@ -23,16 +23,6 b''
23 #include "revlog.h"
23 #include "revlog.h"
24 #include "util.h"
24 #include "util.h"
25
25
26 #ifdef IS_PY3K
27 /* The mapping of Python types is meant to be temporary to get Python
28 * 3 to compile. We should remove this once Python 3 support is fully
29 * supported and proper types are used in the extensions themselves. */
30 #define PyInt_Check PyLong_Check
31 #define PyInt_FromLong PyLong_FromLong
32 #define PyInt_FromSsize_t PyLong_FromSsize_t
33 #define PyInt_AsLong PyLong_AsLong
34 #endif
35
36 typedef struct indexObjectStruct indexObject;
26 typedef struct indexObjectStruct indexObject;
37
27
38 typedef struct {
28 typedef struct {
@@ -802,7 +792,7 b' static PyObject *index_stats(indexObject'
802 #define istat(__n, __d) \
792 #define istat(__n, __d) \
803 do { \
793 do { \
804 s = PyBytes_FromString(__d); \
794 s = PyBytes_FromString(__d); \
805 t = PyInt_FromSsize_t(self->__n); \
795 t = PyLong_FromSsize_t(self->__n); \
806 if (!s || !t) \
796 if (!s || !t) \
807 goto bail; \
797 goto bail; \
808 if (PyDict_SetItem(obj, s, t) == -1) \
798 if (PyDict_SetItem(obj, s, t) == -1) \
@@ -953,7 +943,7 b' static PyObject *reachableroots2(indexOb'
953
943
954 l = PyList_GET_SIZE(roots);
944 l = PyList_GET_SIZE(roots);
955 for (i = 0; i < l; i++) {
945 for (i = 0; i < l; i++) {
956 revnum = PyInt_AsLong(PyList_GET_ITEM(roots, i));
946 revnum = PyLong_AsLong(PyList_GET_ITEM(roots, i));
957 if (revnum == -1 && PyErr_Occurred())
947 if (revnum == -1 && PyErr_Occurred())
958 goto bail;
948 goto bail;
959 /* If root is out of range, e.g. wdir(), it must be unreachable
949 /* If root is out of range, e.g. wdir(), it must be unreachable
@@ -966,7 +956,7 b' static PyObject *reachableroots2(indexOb'
966 /* Populate tovisit with all the heads */
956 /* Populate tovisit with all the heads */
967 l = PyList_GET_SIZE(heads);
957 l = PyList_GET_SIZE(heads);
968 for (i = 0; i < l; i++) {
958 for (i = 0; i < l; i++) {
969 revnum = PyInt_AsLong(PyList_GET_ITEM(heads, i));
959 revnum = PyLong_AsLong(PyList_GET_ITEM(heads, i));
970 if (revnum == -1 && PyErr_Occurred())
960 if (revnum == -1 && PyErr_Occurred())
971 goto bail;
961 goto bail;
972 if (revnum + 1 < 0 || revnum + 1 >= len + 1) {
962 if (revnum + 1 < 0 || revnum + 1 >= len + 1) {
@@ -986,7 +976,7 b' static PyObject *reachableroots2(indexOb'
986 revnum = tovisit[k++];
976 revnum = tovisit[k++];
987 if (revstates[revnum + 1] & RS_ROOT) {
977 if (revstates[revnum + 1] & RS_ROOT) {
988 revstates[revnum + 1] |= RS_REACHABLE;
978 revstates[revnum + 1] |= RS_REACHABLE;
989 val = PyInt_FromLong(revnum);
979 val = PyLong_FromLong(revnum);
990 if (val == NULL)
980 if (val == NULL)
991 goto bail;
981 goto bail;
992 r = PyList_Append(reachable, val);
982 r = PyList_Append(reachable, val);
@@ -1031,7 +1021,7 b' static PyObject *reachableroots2(indexOb'
1031 RS_REACHABLE) &&
1021 RS_REACHABLE) &&
1032 !(revstates[i + 1] & RS_REACHABLE)) {
1022 !(revstates[i + 1] & RS_REACHABLE)) {
1033 revstates[i + 1] |= RS_REACHABLE;
1023 revstates[i + 1] |= RS_REACHABLE;
1034 val = PyInt_FromSsize_t(i);
1024 val = PyLong_FromSsize_t(i);
1035 if (val == NULL)
1025 if (val == NULL)
1036 goto bail;
1026 goto bail;
1037 r = PyList_Append(reachable, val);
1027 r = PyList_Append(reachable, val);
@@ -1116,7 +1106,7 b' static PyObject *compute_phases_map_sets'
1116 }
1106 }
1117
1107
1118 for (i = 0; i < numphases; ++i) {
1108 for (i = 0; i < numphases; ++i) {
1119 PyObject *pyphase = PyInt_FromLong(trackedphases[i]);
1109 PyObject *pyphase = PyLong_FromLong(trackedphases[i]);
1120 PyObject *phaseroots = NULL;
1110 PyObject *phaseroots = NULL;
1121 if (pyphase == NULL)
1111 if (pyphase == NULL)
1122 goto release;
1112 goto release;
@@ -1175,7 +1165,7 b' static PyObject *compute_phases_map_sets'
1175 "bad phase number in internal list");
1165 "bad phase number in internal list");
1176 goto release;
1166 goto release;
1177 }
1167 }
1178 pyrev = PyInt_FromLong(rev);
1168 pyrev = PyLong_FromLong(rev);
1179 if (pyrev == NULL)
1169 if (pyrev == NULL)
1180 goto release;
1170 goto release;
1181 if (PySet_Add(pyphase, pyrev) == -1) {
1171 if (PySet_Add(pyphase, pyrev) == -1) {
@@ -1189,7 +1179,7 b' static PyObject *compute_phases_map_sets'
1189 if (phasesetsdict == NULL)
1179 if (phasesetsdict == NULL)
1190 goto release;
1180 goto release;
1191 for (i = 0; i < numphases; ++i) {
1181 for (i = 0; i < numphases; ++i) {
1192 PyObject *pyphase = PyInt_FromLong(trackedphases[i]);
1182 PyObject *pyphase = PyLong_FromLong(trackedphases[i]);
1193 if (pyphase == NULL)
1183 if (pyphase == NULL)
1194 goto release;
1184 goto release;
1195 if (PyDict_SetItem(phasesetsdict, pyphase, phasesets[i]) ==
1185 if (PyDict_SetItem(phasesetsdict, pyphase, phasesets[i]) ==
@@ -1247,7 +1237,7 b' static PyObject *index_headrevs(indexObj'
1247 if (heads == NULL)
1237 if (heads == NULL)
1248 goto bail;
1238 goto bail;
1249 if (len == 0) {
1239 if (len == 0) {
1250 PyObject *nullid = PyInt_FromLong(-1);
1240 PyObject *nullid = PyLong_FromLong(-1);
1251 if (nullid == NULL || PyList_Append(heads, nullid) == -1) {
1241 if (nullid == NULL || PyList_Append(heads, nullid) == -1) {
1252 Py_XDECREF(nullid);
1242 Py_XDECREF(nullid);
1253 goto bail;
1243 goto bail;
@@ -1296,7 +1286,7 b' static PyObject *index_headrevs(indexObj'
1296
1286
1297 if (nothead[i])
1287 if (nothead[i])
1298 continue;
1288 continue;
1299 head = PyInt_FromSsize_t(i);
1289 head = PyLong_FromSsize_t(i);
1300 if (head == NULL || PyList_Append(heads, head) == -1) {
1290 if (head == NULL || PyList_Append(heads, head) == -1) {
1301 Py_XDECREF(head);
1291 Py_XDECREF(head);
1302 goto bail;
1292 goto bail;
@@ -1442,7 +1432,7 b' static PyObject *index_findsnapshots(ind'
1442 assert(PyErr_Occurred());
1432 assert(PyErr_Occurred());
1443 goto bail;
1433 goto bail;
1444 }
1434 }
1445 key = PyInt_FromSsize_t(base);
1435 key = PyLong_FromSsize_t(base);
1446 allvalues = PyDict_GetItem(cache, key);
1436 allvalues = PyDict_GetItem(cache, key);
1447 if (allvalues == NULL && PyErr_Occurred()) {
1437 if (allvalues == NULL && PyErr_Occurred()) {
1448 goto bail;
1438 goto bail;
@@ -1459,7 +1449,7 b' static PyObject *index_findsnapshots(ind'
1459 goto bail;
1449 goto bail;
1460 }
1450 }
1461 }
1451 }
1462 value = PyInt_FromSsize_t(rev);
1452 value = PyLong_FromSsize_t(rev);
1463 if (PyList_Append(allvalues, value)) {
1453 if (PyList_Append(allvalues, value)) {
1464 goto bail;
1454 goto bail;
1465 }
1455 }
@@ -1486,8 +1476,8 b' static PyObject *index_deltachain(indexO'
1486 return NULL;
1476 return NULL;
1487 }
1477 }
1488
1478
1489 if (PyInt_Check(stoparg)) {
1479 if (PyLong_Check(stoparg)) {
1490 stoprev = (int)PyInt_AsLong(stoparg);
1480 stoprev = (int)PyLong_AsLong(stoparg);
1491 if (stoprev == -1 && PyErr_Occurred()) {
1481 if (stoprev == -1 && PyErr_Occurred()) {
1492 return NULL;
1482 return NULL;
1493 }
1483 }
@@ -1521,7 +1511,7 b' static PyObject *index_deltachain(indexO'
1521 iterrev = rev;
1511 iterrev = rev;
1522
1512
1523 while (iterrev != baserev && iterrev != stoprev) {
1513 while (iterrev != baserev && iterrev != stoprev) {
1524 PyObject *value = PyInt_FromLong(iterrev);
1514 PyObject *value = PyLong_FromLong(iterrev);
1525 if (value == NULL) {
1515 if (value == NULL) {
1526 goto bail;
1516 goto bail;
1527 }
1517 }
@@ -1560,7 +1550,7 b' static PyObject *index_deltachain(indexO'
1560 if (iterrev == stoprev) {
1550 if (iterrev == stoprev) {
1561 stopped = 1;
1551 stopped = 1;
1562 } else {
1552 } else {
1563 PyObject *value = PyInt_FromLong(iterrev);
1553 PyObject *value = PyLong_FromLong(iterrev);
1564 if (value == NULL) {
1554 if (value == NULL) {
1565 goto bail;
1555 goto bail;
1566 }
1556 }
@@ -1712,7 +1702,8 b' static PyObject *index_slicechunktodensi'
1712 goto bail;
1702 goto bail;
1713 }
1703 }
1714 for (i = 0; i < num_revs; i++) {
1704 for (i = 0; i < num_revs; i++) {
1715 Py_ssize_t revnum = PyInt_AsLong(PyList_GET_ITEM(list_revs, i));
1705 Py_ssize_t revnum =
1706 PyLong_AsLong(PyList_GET_ITEM(list_revs, i));
1716 if (revnum == -1 && PyErr_Occurred()) {
1707 if (revnum == -1 && PyErr_Occurred()) {
1717 goto bail;
1708 goto bail;
1718 }
1709 }
@@ -2118,7 +2109,7 b' static PyObject *ntobj_shortest(nodetree'
2118 raise_revlog_error();
2109 raise_revlog_error();
2119 return NULL;
2110 return NULL;
2120 }
2111 }
2121 return PyInt_FromLong(length);
2112 return PyLong_FromLong(length);
2122 }
2113 }
2123
2114
2124 static void nt_dealloc(nodetree *self)
2115 static void nt_dealloc(nodetree *self)
@@ -2266,7 +2257,7 b' static PyObject *index_getitem(indexObje'
2266 char *node;
2257 char *node;
2267 int rev;
2258 int rev;
2268
2259
2269 if (PyInt_Check(value)) {
2260 if (PyLong_Check(value)) {
2270 long idx;
2261 long idx;
2271 if (!pylong_to_long(value, &idx)) {
2262 if (!pylong_to_long(value, &idx)) {
2272 return NULL;
2263 return NULL;
@@ -2278,7 +2269,7 b' static PyObject *index_getitem(indexObje'
2278 return NULL;
2269 return NULL;
2279 rev = index_find_node(self, node);
2270 rev = index_find_node(self, node);
2280 if (rev >= -1)
2271 if (rev >= -1)
2281 return PyInt_FromLong(rev);
2272 return PyLong_FromLong(rev);
2282 if (rev == -2)
2273 if (rev == -2)
2283 raise_revlog_error();
2274 raise_revlog_error();
2284 return NULL;
2275 return NULL;
@@ -2377,7 +2368,7 b' static PyObject *index_shortest(indexObj'
2377 raise_revlog_error();
2368 raise_revlog_error();
2378 return NULL;
2369 return NULL;
2379 }
2370 }
2380 return PyInt_FromLong(length);
2371 return PyLong_FromLong(length);
2381 }
2372 }
2382
2373
2383 static PyObject *index_m_get(indexObject *self, PyObject *args)
2374 static PyObject *index_m_get(indexObject *self, PyObject *args)
@@ -2395,14 +2386,14 b' static PyObject *index_m_get(indexObject'
2395 return NULL;
2386 return NULL;
2396 if (rev == -2)
2387 if (rev == -2)
2397 Py_RETURN_NONE;
2388 Py_RETURN_NONE;
2398 return PyInt_FromLong(rev);
2389 return PyLong_FromLong(rev);
2399 }
2390 }
2400
2391
2401 static int index_contains(indexObject *self, PyObject *value)
2392 static int index_contains(indexObject *self, PyObject *value)
2402 {
2393 {
2403 char *node;
2394 char *node;
2404
2395
2405 if (PyInt_Check(value)) {
2396 if (PyLong_Check(value)) {
2406 long rev;
2397 long rev;
2407 if (!pylong_to_long(value, &rev)) {
2398 if (!pylong_to_long(value, &rev)) {
2408 return -1;
2399 return -1;
@@ -2440,7 +2431,7 b' static PyObject *index_m_rev(indexObject'
2440 return NULL;
2431 return NULL;
2441 rev = index_find_node(self, node);
2432 rev = index_find_node(self, node);
2442 if (rev >= -1)
2433 if (rev >= -1)
2443 return PyInt_FromLong(rev);
2434 return PyLong_FromLong(rev);
2444 if (rev == -2)
2435 if (rev == -2)
2445 raise_revlog_error();
2436 raise_revlog_error();
2446 return NULL;
2437 return NULL;
@@ -2493,7 +2484,7 b' static PyObject *find_gca_candidates(ind'
2493 if (sv < poison) {
2484 if (sv < poison) {
2494 interesting -= 1;
2485 interesting -= 1;
2495 if (sv == allseen) {
2486 if (sv == allseen) {
2496 PyObject *obj = PyInt_FromLong(v);
2487 PyObject *obj = PyLong_FromLong(v);
2497 if (obj == NULL)
2488 if (obj == NULL)
2498 goto bail;
2489 goto bail;
2499 if (PyList_Append(gca, obj) == -1) {
2490 if (PyList_Append(gca, obj) == -1) {
@@ -2561,7 +2552,7 b' static PyObject *find_deepest(indexObjec'
2561 }
2552 }
2562
2553
2563 for (i = 0; i < revcount; i++) {
2554 for (i = 0; i < revcount; i++) {
2564 int n = (int)PyInt_AsLong(PyList_GET_ITEM(revs, i));
2555 int n = (int)PyLong_AsLong(PyList_GET_ITEM(revs, i));
2565 if (n > maxrev)
2556 if (n > maxrev)
2566 maxrev = n;
2557 maxrev = n;
2567 }
2558 }
@@ -2586,7 +2577,7 b' static PyObject *find_deepest(indexObjec'
2586 goto bail;
2577 goto bail;
2587
2578
2588 for (i = 0; i < revcount; i++) {
2579 for (i = 0; i < revcount; i++) {
2589 int n = (int)PyInt_AsLong(PyList_GET_ITEM(revs, i));
2580 int n = (int)PyLong_AsLong(PyList_GET_ITEM(revs, i));
2590 long b = 1l << i;
2581 long b = 1l << i;
2591 depth[n] = 1;
2582 depth[n] = 1;
2592 seen[n] = b;
2583 seen[n] = b;
@@ -2716,13 +2707,13 b' static PyObject *index_commonancestorshe'
2716 bitmask x;
2707 bitmask x;
2717 long val;
2708 long val;
2718
2709
2719 if (!PyInt_Check(obj)) {
2710 if (!PyLong_Check(obj)) {
2720 PyErr_SetString(PyExc_TypeError,
2711 PyErr_SetString(PyExc_TypeError,
2721 "arguments must all be ints");
2712 "arguments must all be ints");
2722 Py_DECREF(obj);
2713 Py_DECREF(obj);
2723 goto bail;
2714 goto bail;
2724 }
2715 }
2725 val = PyInt_AsLong(obj);
2716 val = PyLong_AsLong(obj);
2726 Py_DECREF(obj);
2717 Py_DECREF(obj);
2727 if (val == -1) {
2718 if (val == -1) {
2728 ret = PyList_New(0);
2719 ret = PyList_New(0);
@@ -2763,7 +2754,7 b' static PyObject *index_commonancestorshe'
2763 ret = PyList_New(1);
2754 ret = PyList_New(1);
2764 if (ret == NULL)
2755 if (ret == NULL)
2765 goto bail;
2756 goto bail;
2766 obj = PyInt_FromLong(revs[0]);
2757 obj = PyLong_FromLong(revs[0]);
2767 if (obj == NULL)
2758 if (obj == NULL)
2768 goto bail;
2759 goto bail;
2769 PyList_SET_ITEM(ret, 0, obj);
2760 PyList_SET_ITEM(ret, 0, obj);
@@ -2925,7 +2916,7 b' static int index_assign_subscript(indexO'
2925 if (value == NULL)
2916 if (value == NULL)
2926 return self->ntinitialized ? nt_delete_node(&self->nt, node)
2917 return self->ntinitialized ? nt_delete_node(&self->nt, node)
2927 : 0;
2918 : 0;
2928 rev = PyInt_AsLong(value);
2919 rev = PyLong_AsLong(value);
2929 if (rev > INT_MAX || rev < 0) {
2920 if (rev > INT_MAX || rev < 0) {
2930 if (!PyErr_Occurred())
2921 if (!PyErr_Occurred())
2931 PyErr_SetString(PyExc_ValueError, "rev out of range");
2922 PyErr_SetString(PyExc_ValueError, "rev out of range");
General Comments 0
You need to be logged in to leave comments. Login now