forked from QubesOS/qubes-vmm-xen
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpatch-0007-python-adjust-module-initalization-for-Python3.patch
175 lines (148 loc) · 4.55 KB
/
patch-0007-python-adjust-module-initalization-for-Python3.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
From 940aeb6a0d458367b615d08adc870e3058be53b4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?=
Date: Fri, 17 Feb 2017 04:33:00 +0100
Subject: [PATCH 7/7] python: adjust module initalization for 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, PyTypeObject looks slightly different, and also module
initialization is different. Instead of Py_InitModule, PyModule_Create
should be called on already defined PyModuleDef structure. And then
initialization function should return that module.
Additionally initialization function should be named PyInit_<name>,
instead of init<name>.
Signed-off-by: Marek Marczykowski-Górecki <[email protected]>
---
tools/python/xen/lowlevel/xc/xc.c | 35 ++++++++++++++++++++++++++++++++---
tools/python/xen/lowlevel/xs/xs.c | 34 +++++++++++++++++++++++++++++++---
2 files changed, 63 insertions(+), 6 deletions(-)
diff --git a/tools/python/xen/lowlevel/xc/xc.c b/tools/python/xen/lowlevel/xc/xc.c
index df31a1d..d09c45f 100644
--- a/tools/python/xen/lowlevel/xc/xc.c
+++ b/tools/python/xen/lowlevel/xc/xc.c
@@ -2685,7 +2685,11 @@ static void PyXc_dealloc(XcObject *self)
}
static PyTypeObject PyXcType = {
+#if PY_MAJOR_VERSION >= 3
+ .ob_base = { PyObject_HEAD_INIT(NULL) },
+#else
PyObject_HEAD_INIT(NULL)
+#endif
.tp_name = PKG "." CLS,
.tp_basicsize = sizeof(XcObject),
.tp_itemsize = 0,
@@ -2699,22 +2703,44 @@ static PyTypeObject PyXcType = {
static PyMethodDef xc_methods[] = { { NULL } };
+
+#if PY_MAJOR_VERSION >= 3
+static PyModuleDef xc_module = {
+ PyModuleDef_HEAD_INIT,
+ PKG, /* name */
+ NULL, /* docstring */
+ -1, /* size of per-interpreter state, -1 means the module use global
+ variables */
+ xc_methods
+};
+#endif
+
+#if PY_MAJOR_VERSION >= 3
+#define INITERROR return NULL
+PyMODINIT_FUNC PyInit_xc(void)
+#else
+#define INITERROR return
PyMODINIT_FUNC initxc(void)
+#endif
{
PyObject *m;
if (PyType_Ready(&PyXcType) < 0)
- return;
+ INITERROR;
+#if PY_MAJOR_VERSION >= 3
+ m = PyModule_Create(&xc_module);
+#else
m = Py_InitModule(PKG, xc_methods);
+#endif
if (m == NULL)
- return;
+ INITERROR;
xc_error_obj = PyErr_NewException(PKG ".Error", PyExc_RuntimeError, NULL);
if (xc_error_obj == NULL) {
Py_DECREF(m);
- return;
+ INITERROR;
}
zero = PyLongOrInt_FromLong(0);
@@ -2732,6 +2758,9 @@ PyMODINIT_FUNC initxc(void)
PyModule_AddIntConstant(m, "XEN_SCHEDULER_CREDIT", XEN_SCHEDULER_CREDIT);
PyModule_AddIntConstant(m, "XEN_SCHEDULER_CREDIT2", XEN_SCHEDULER_CREDIT2);
+#if PY_MAJOR_VERSION >= 3
+ return m;
+#endif
}
diff --git a/tools/python/xen/lowlevel/xs/xs.c b/tools/python/xen/lowlevel/xs/xs.c
index b37daa9..aba5a20 100644
--- a/tools/python/xen/lowlevel/xs/xs.c
+++ b/tools/python/xen/lowlevel/xs/xs.c
@@ -946,7 +946,11 @@ static void xshandle_dealloc(XsHandle *self)
}
static PyTypeObject xshandle_type = {
+#if PY_MAJOR_VERSION >= 3
+ .ob_base = { PyObject_HEAD_INIT(NULL) },
+#else
PyObject_HEAD_INIT(NULL)
+#endif
.tp_name = PKG "." CLS,
.tp_basicsize = sizeof(XsHandle),
.tp_itemsize = 0,
@@ -960,22 +964,43 @@ static PyTypeObject xshandle_type = {
static PyMethodDef xs_methods[] = { { NULL } };
+#if PY_MAJOR_VERSION >= 3
+static PyModuleDef xs_module = {
+ PyModuleDef_HEAD_INIT,
+ PKG, /* name */
+ NULL, /* docstring */
+ -1, /* size of per-interpreter state, -1 means the module use global
+ variables */
+ xs_methods
+};
+#endif
+
+#if PY_MAJOR_VERSION >= 3
+#define INITERROR return NULL
+PyMODINIT_FUNC PyInit_xs(void)
+#else
+#define INITERROR return
PyMODINIT_FUNC initxs(void)
+#endif
{
PyObject* m;
if (PyType_Ready(&xshandle_type) < 0)
- return;
+ INITERROR;
+#if PY_MAJOR_VERSION >= 3
+ m = PyModule_Create(&xs_module);
+#else
m = Py_InitModule(PKG, xs_methods);
+#endif
if (m == NULL)
- return;
+ INITERROR;
xs_error = PyErr_NewException(PKG ".Error", PyExc_RuntimeError, NULL);
if (xs_error == NULL) {
Py_DECREF(m);
- return;
+ INITERROR;
}
Py_INCREF(&xshandle_type);
@@ -983,6 +1008,9 @@ PyMODINIT_FUNC initxs(void)
Py_INCREF(xs_error);
PyModule_AddObject(m, "Error", xs_error);
+#if PY_MAJOR_VERSION >= 3
+ return m;
+#endif
}
--
2.7.4