forked from QubesOS/qubes-vmm-xen
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpatch-0005-python-use-PyBytes-PyUnicode-instead-of-PyString.patch
111 lines (101 loc) · 3.95 KB
/
patch-0005-python-use-PyBytes-PyUnicode-instead-of-PyString.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
From d2433dc080eb1f2db9be980f6c14436060caf02e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?=
Date: Fri, 17 Feb 2017 03:21:47 +0100
Subject: [PATCH 5/7] python: use PyBytes/PyUnicode instead of PyString
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 Python2 PyBytes is the same as PyString, but in Python3 PyString is
gone and 'str' is really PyUnicode in C-API.
When handling arbitrary data, use PyBytes - which is the right thing to
do in Python3, and pose no API change in Python2. When handling
xenstore paths and transaction ids, which have well defined format, use
PyUnicode - to ease API usage - no need to prefix all xenstore paths
with 'b' when migrating scripts to Python3.
Signed-off-by: Marek Marczykowski-Górecki <[email protected]>
---
tools/python/xen/lowlevel/xc/xc.c | 6 +++---
tools/python/xen/lowlevel/xs/xs.c | 20 ++++++++++++++++----
2 files changed, 19 insertions(+), 7 deletions(-)
diff --git a/tools/python/xen/lowlevel/xc/xc.c b/tools/python/xen/lowlevel/xc/xc.c
index bcbb7b0..ce87afb 100644
--- a/tools/python/xen/lowlevel/xc/xc.c
+++ b/tools/python/xen/lowlevel/xc/xc.c
@@ -678,7 +678,7 @@ static void pyxc_dom_extract_cpuid(PyObject *config,
for ( i = 0; i < 4; i++ )
if ( (obj = PyDict_GetItemString(config, regs_extract[i])) != NULL )
- regs[i] = PyString_AS_STRING(obj);
+ regs[i] = PyBytes_AS_STRING(obj);
}
static PyObject *pyxc_create_cpuid_dict(char **regs)
@@ -693,7 +693,7 @@ static PyObject *pyxc_create_cpuid_dict(char **regs)
if ( regs[i] == NULL )
continue;
PyDict_SetItemString(dict, regs_extract[i],
- PyString_FromString(regs[i]));
+ PyBytes_FromString(regs[i]));
free(regs[i]);
regs[i] = NULL;
}
@@ -940,7 +940,7 @@ static PyObject *pyxc_readconsolering(XcObject *self,
str = ptr;
}
- obj = PyString_FromStringAndSize(str, count);
+ obj = PyBytes_FromStringAndSize(str, count);
free(str);
return obj;
}
diff --git a/tools/python/xen/lowlevel/xs/xs.c b/tools/python/xen/lowlevel/xs/xs.c
index 66ab08d..c2b4d87 100644
--- a/tools/python/xen/lowlevel/xs/xs.c
+++ b/tools/python/xen/lowlevel/xs/xs.c
@@ -103,7 +103,7 @@ static PyObject *xspy_read(XsHandle *self, PyObject *args)
xsval = xs_read(xh, th, path, &xsval_n);
Py_END_ALLOW_THREADS
if (xsval) {
- PyObject *val = PyString_FromStringAndSize(xsval, xsval_n);
+ PyObject *val = PyBytes_FromStringAndSize(xsval, xsval_n);
free(xsval);
return val;
}
@@ -179,7 +179,11 @@ static PyObject *xspy_ls(XsHandle *self, PyObject *args)
int i;
PyObject *val = PyList_New(xsval_n);
for (i = 0; i < xsval_n; i++)
- PyList_SetItem(val, i, PyString_FromString(xsval[i]));
+#if PY_MAJOR_VERSION >= 3
+ PyList_SetItem(val, i, PyUnicode_FromString(xsval[i]));
+#else
+ PyList_SetItem(val, i, PyBytes_FromString(xsval[i]));
+#endif
free(xsval);
return val;
}
@@ -550,7 +554,11 @@ static PyObject *xspy_transaction_start(XsHandle *self)
}
snprintf(thstr, sizeof(thstr), "%lX", (unsigned long)th);
- return PyString_FromString(thstr);
+#if PY_MAJOR_VERSION >= 3
+ return PyUnicode_FromString(thstr);
+#else
+ return PyBytes_FromString(thstr);
+#endif
}
#define xspy_transaction_end_doc "\n" \
@@ -773,7 +781,11 @@ static PyObject *xspy_get_domain_path(XsHandle *self, PyObject *args)
Py_END_ALLOW_THREADS
if (xsval) {
- PyObject *val = PyString_FromString(xsval);
+#if PY_MAJOR_VERSION >= 3
+ PyObject *val = PyUnicode_FromString(xsval);
+#else
+ PyObject *val = PyBytes_FromString(xsval);
+#endif
free(xsval);
return val;
}
--
2.7.4