##// END OF EJS Templates
dirs: port PyInt code to work on Python 3...
Gregory Szorc -
r30106:cb304874 default
parent child Browse files
Show More
@@ -11,6 +11,12 b''
11 #include <Python.h>
11 #include <Python.h>
12 #include "util.h"
12 #include "util.h"
13
13
14 #ifdef IS_PY3K
15 #define PYLONG_VALUE(o) ((PyLongObject *)o)->ob_digit[1]
16 #else
17 #define PYLONG_VALUE(o) PyInt_AS_LONG(o)
18 #endif
19
14 /*
20 /*
15 * This is a multiset of directory names, built from the files that
21 * This is a multiset of directory names, built from the files that
16 * appear in a dirstate or manifest.
22 * appear in a dirstate or manifest.
@@ -66,17 +72,21 b' static int _addpath(PyObject *dirs, PyOb'
66
72
67 val = PyDict_GetItem(dirs, key);
73 val = PyDict_GetItem(dirs, key);
68 if (val != NULL) {
74 if (val != NULL) {
69 PyInt_AS_LONG(val) += 1;
75 PYLONG_VALUE(val) += 1;
70 break;
76 break;
71 }
77 }
72
78
73 /* Force Python to not reuse a small shared int. */
79 /* Force Python to not reuse a small shared int. */
80 #ifdef IS_PY3K
81 val = PyLong_FromLong(0x1eadbeef);
82 #else
74 val = PyInt_FromLong(0x1eadbeef);
83 val = PyInt_FromLong(0x1eadbeef);
84 #endif
75
85
76 if (val == NULL)
86 if (val == NULL)
77 goto bail;
87 goto bail;
78
88
79 PyInt_AS_LONG(val) = 1;
89 PYLONG_VALUE(val) = 1;
80 ret = PyDict_SetItem(dirs, key, val);
90 ret = PyDict_SetItem(dirs, key, val);
81 Py_DECREF(val);
91 Py_DECREF(val);
82 if (ret == -1)
92 if (ret == -1)
@@ -113,7 +123,7 b' static int _delpath(PyObject *dirs, PyOb'
113 goto bail;
123 goto bail;
114 }
124 }
115
125
116 if (--PyInt_AS_LONG(val) <= 0) {
126 if (--PYLONG_VALUE(val) <= 0) {
117 if (PyDict_DelItem(dirs, key) == -1)
127 if (PyDict_DelItem(dirs, key) == -1)
118 goto bail;
128 goto bail;
119 } else
129 } else
General Comments 0
You need to be logged in to leave comments. Login now