forked from QubesOS/qubes-vmm-xen
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpatch-0006-python-use-PyLong_-for-constructing-int-type-in-Pyth.patch
229 lines (203 loc) · 8.07 KB
/
patch-0006-python-use-PyLong_-for-constructing-int-type-in-Pyth.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
From 51a71b075c89d2886a8d6e325dc40c669d384300 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?=
Date: Fri, 17 Feb 2017 04:25:46 +0100
Subject: [PATCH 6/7] python: use PyLong_* for constructing 'int' type in
Python3
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Organization: Invisible Things Lab
Cc: Marek Marczykowski-Górecki <[email protected]>
In Python3 'int' and 'long' types are the same, there are no longer
separate PyInt_* functions. Provide convenient #defines to limit #if in
code.
Signed-off-by: Marek Marczykowski-Górecki <[email protected]>
---
tools/python/xen/lowlevel/xc/xc.c | 51 ++++++++++++++++++++++++---------------
tools/python/xen/lowlevel/xs/xs.c | 8 ++++++
2 files changed, 39 insertions(+), 20 deletions(-)
diff --git a/tools/python/xen/lowlevel/xc/xc.c b/tools/python/xen/lowlevel/xc/xc.c
index ce87afb..df31a1d 100644
--- a/tools/python/xen/lowlevel/xc/xc.c
+++ b/tools/python/xen/lowlevel/xc/xc.c
@@ -34,6 +34,17 @@
#define FLASK_CTX_LEN 1024
+/* Python 2 compatibility */
+#if PY_MAJOR_VERSION >= 3
+#define PyLongOrInt_FromLong PyLong_FromLong
+#define PyLongOrInt_Check PyLong_Check
+#define PyLongOrInt_AsLong PyLong_AsLong
+#else
+#define PyLongOrInt_FromLong PyInt_FromLong
+#define PyLongOrInt_Check PyInt_Check
+#define PyLongOrInt_AsLong PyInt_AsLong
+#endif
+
static PyObject *xc_error_obj, *zero;
typedef struct {
@@ -127,9 +138,9 @@ static PyObject *pyxc_domain_create(XcObject *self,
for ( i = 0; i < sizeof(xen_domain_handle_t); i++ )
{
PyObject *p = PyList_GetItem(pyhandle, i);
- if ( !PyInt_Check(p) )
+ if ( !PyLongOrInt_Check(p) )
goto out_exception;
- handle[i] = (uint8_t)PyInt_AsLong(p);
+ handle[i] = (uint8_t)PyLongOrInt_AsLong(p);
}
}
@@ -142,7 +153,7 @@ static PyObject *pyxc_domain_create(XcObject *self,
return pyxc_error_to_exception(self->xc_handle);
- return PyInt_FromLong(dom);
+ return PyLongOrInt_FromLong(dom);
out_exception:
errno = EINVAL;
@@ -242,7 +253,7 @@ static PyObject *pyxc_vcpu_setaffinity(XcObject *self,
{
for ( i = 0; i < PyList_Size(cpulist); i++ )
{
- long cpu = PyInt_AsLong(PyList_GetItem(cpulist, i));
+ long cpu = PyLongOrInt_AsLong(PyList_GetItem(cpulist, i));
if ( cpu < 0 || cpu >= nr_cpus )
{
free(cpumap);
@@ -284,9 +295,9 @@ static PyObject *pyxc_domain_sethandle(XcObject *self, PyObject *args)
for ( i = 0; i < sizeof(xen_domain_handle_t); i++ )
{
PyObject *p = PyList_GetItem(pyhandle, i);
- if ( !PyInt_Check(p) )
+ if ( !PyLongOrInt_Check(p) )
goto out_exception;
- handle[i] = (uint8_t)PyInt_AsLong(p);
+ handle[i] = (uint8_t)PyLongOrInt_AsLong(p);
}
if (xc_domain_sethandle(self->xc_handle, dom, handle) < 0)
@@ -361,7 +372,7 @@ static PyObject *pyxc_domain_getinfo(XcObject *self,
return NULL;
}
for ( j = 0; j < sizeof(xen_domain_handle_t); j++ )
- PyList_SetItem(pyhandle, j, PyInt_FromLong(info[i].handle[j]));
+ PyList_SetItem(pyhandle, j, PyLongOrInt_FromLong(info[i].handle[j]));
PyDict_SetItemString(info_dict, "handle", pyhandle);
Py_DECREF(pyhandle);
PyList_SetItem(list, i, info_dict);
@@ -420,7 +431,7 @@ static PyObject *pyxc_vcpu_getinfo(XcObject *self,
for ( i = 0; i < nr_cpus; i++ )
{
if (*(cpumap + i / 8) & 1 ) {
- PyObject *pyint = PyInt_FromLong(i);
+ PyObject *pyint = PyLongOrInt_FromLong(i);
PyList_Append(cpulist, pyint);
Py_DECREF(pyint);
}
@@ -836,7 +847,7 @@ static PyObject *pyxc_evtchn_alloc_unbound(XcObject *self,
if ( (port = xc_evtchn_alloc_unbound(self->xc_handle, dom, remote_dom)) < 0 )
return pyxc_error_to_exception(self->xc_handle);
- return PyInt_FromLong(port);
+ return PyLongOrInt_FromLong(port);
}
static PyObject *pyxc_evtchn_reset(XcObject *self,
@@ -1063,7 +1074,7 @@ static PyObject *pyxc_topologyinfo(XcObject *self)
}
else
{
- PyObject *pyint = PyInt_FromLong(cputopo[i].core);
+ PyObject *pyint = PyLongOrInt_FromLong(cputopo[i].core);
PyList_Append(cpu_to_core_obj, pyint);
Py_DECREF(pyint);
}
@@ -1074,7 +1085,7 @@ static PyObject *pyxc_topologyinfo(XcObject *self)
}
else
{
- PyObject *pyint = PyInt_FromLong(cputopo[i].socket);
+ PyObject *pyint = PyLongOrInt_FromLong(cputopo[i].socket);
PyList_Append(cpu_to_socket_obj, pyint);
Py_DECREF(pyint);
}
@@ -1085,7 +1096,7 @@ static PyObject *pyxc_topologyinfo(XcObject *self)
}
else
{
- PyObject *pyint = PyInt_FromLong(cputopo[i].node);
+ PyObject *pyint = PyLongOrInt_FromLong(cputopo[i].node);
PyList_Append(cpu_to_node_obj, pyint);
Py_DECREF(pyint);
}
@@ -1139,18 +1150,18 @@ static PyObject *pyxc_numainfo(XcObject *self)
unsigned invalid_node;
/* Total Memory */
- pyint = PyInt_FromLong(meminfo[i].memsize >> 20); /* MB */
+ pyint = PyLongOrInt_FromLong(meminfo[i].memsize >> 20); /* MB */
PyList_Append(node_to_memsize_obj, pyint);
Py_DECREF(pyint);
/* Free Memory */
- pyint = PyInt_FromLong(meminfo[i].memfree >> 20); /* MB */
+ pyint = PyLongOrInt_FromLong(meminfo[i].memfree >> 20); /* MB */
PyList_Append(node_to_memfree_obj, pyint);
Py_DECREF(pyint);
/* DMA memory. */
xc_availheap(self->xc_handle, 0, 32, i, &free_heap);
- pyint = PyInt_FromLong(free_heap >> 20); /* MB */
+ pyint = PyLongOrInt_FromLong(free_heap >> 20); /* MB */
PyList_Append(node_to_dma32_mem_obj, pyint);
Py_DECREF(pyint);
@@ -1166,7 +1177,7 @@ static PyObject *pyxc_numainfo(XcObject *self)
}
else
{
- pyint = PyInt_FromLong(dist);
+ pyint = PyLongOrInt_FromLong(dist);
PyList_Append(node_to_node_dist_obj, pyint);
Py_DECREF(pyint);
}
@@ -1700,7 +1711,7 @@ static PyObject *cpumap_to_cpulist(XcObject *self, xc_cpumap_t cpumap)
{
if ( *cpumap & (1 << (i % 8)) )
{
- PyObject* pyint = PyInt_FromLong(i);
+ PyObject* pyint = PyLongOrInt_FromLong(i);
PyList_Append(cpulist, pyint);
Py_DECREF(pyint);
@@ -1726,7 +1737,7 @@ static PyObject *pyxc_cpupool_create(XcObject *self,
if ( xc_cpupool_create(self->xc_handle, &cpupool, sched) < 0 )
return pyxc_error_to_exception(self->xc_handle);
- return PyInt_FromLong(cpupool);
+ return PyLongOrInt_FromLong(cpupool);
}
static PyObject *pyxc_cpupool_destroy(XcObject *self,
@@ -1882,7 +1893,7 @@ static PyObject *pyflask_context_to_sid(PyObject *self, PyObject *args,
return PyErr_SetFromErrno(xc_error_obj);
}
- return PyInt_FromLong(sid);
+ return PyLongOrInt_FromLong(sid);
}
static PyObject *pyflask_sid_to_context(PyObject *self, PyObject *args,
@@ -2705,7 +2716,7 @@ PyMODINIT_FUNC initxc(void)
Py_DECREF(m);
return;
}
- zero = PyInt_FromLong(0);
+ zero = PyLongOrInt_FromLong(0);
/* KAF: This ensures that we get debug output in a timely manner. */
setbuf(stdout, NULL);
diff --git a/tools/python/xen/lowlevel/xs/xs.c b/tools/python/xen/lowlevel/xs/xs.c
index c2b4d87..b37daa9 100644
--- a/tools/python/xen/lowlevel/xs/xs.c
+++ b/tools/python/xen/lowlevel/xs/xs.c
@@ -43,6 +43,14 @@
#define PKG "xen.lowlevel.xs"
#define CLS "xs"
+#if PY_MAJOR_VERSION < 3
+/* Python 2 compatibility */
+#define PyLong_FromLong PyInt_FromLong
+#undef PyLong_Check
+#define PyLong_Check PyInt_Check
+#define PyLong_AsLong PyInt_AsLong
+#endif
+
static PyObject *xs_error;
/** Python wrapper round an xs handle.
--
2.7.4